Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 12 Oct 2004
Offline Last Active Today, 11:41 AM

#5206545 Is it a very bad idea for a class to pass (*this) into a function? Strange bu...

Posted by on 25 January 2015 - 08:53 AM

There's nothing wrong with dereferencing the this pointer, your error has most likely something to do with your code(I'm guessing the second parameter is of type ClassA&).



Also, I know that "this" is a pointer... and since * is used to dereference a pointer, does that mean passing (*this) is pass-by-value?

That depends on the argument type in functionB, it could be by value, reference, const reference etc.

#5188057 Deciding on a Game Engine?

Posted by on 19 October 2014 - 07:14 PM

If licensing is your biggest hurdle, you'll want to check out the C4 engine by Terathon. It just had it's licensing model changed, there was a post about this on this forum here. No royalties, single payment of $88, 1 year of free updates. It doesn't get any better than that.

#5187583 Acceptable resolution for character turning?

Posted by on 16 October 2014 - 10:31 PM

I'm using 2 bytes for orientation of players in my multiplayer game, this gives you a resolution of 1/182 of a degree, which is more than plenty.

#5181615 Temporal coherence and render queue sorting

Posted by on 19 September 2014 - 02:50 PM

Wouldn't it be faster to just remove the no-longer present sub-meshes and leave the existing sub-meshes sorted?

Try to imagine what steps need to be taken to remove existing indices or to build a new array without these indices. Now compare that to creating an array from 1, 2, ... N.

#5176484 Welcome your new Visual Arts forum moderator

Posted by on 27 August 2014 - 01:07 PM

Welcome and good luck on your endeavors!

#5156774 Calculating healthbar percentage

Posted by on 29 May 2014 - 12:40 PM

Your currentHealth and maxHealth variables are integers, meaning that the result of currentHealth / maxHealth will also be an integer, which means the result of that operation will either be either 0 or 1. Integers are always rounded down, so you'll end up with 0 if currentHealth < maxHealth. You can go two ways here, cast the numbers to floating point numbers and cast back to an integer in the end, or simply multiply by 177 before you divide.

#5155749 Need help with 2D puddle

Posted by on 24 May 2014 - 05:09 PM

I'm not an artist, but maybe something like this?


#5155742 A list that does not disturb the order when pushed/popped?

Posted by on 24 May 2014 - 04:27 PM

I don't understand this new trend against new and delete. In a simple scenario like this, there's no reason not to use new and delete, it's ABC of programming with c++. If you can't handle a simple array of pointers, you have no hope with c++. It's a good exercise for the OP and understanding why he gets an error when deleting a player will save him a lot of troubles in the future.

It's the other way round, there's no reason to use new and delete here.

#5144646 Amusing glitch gallery

Posted by on 05 April 2014 - 06:25 PM

It seems that my vertex buffer stride was off-by-one. I call it "Origami World"...

I would drop all my plans and head into a new direction, that looks freaking awesome biggrin.png.

#5140275 Scoring system

Posted by on 19 March 2014 - 04:24 AM

Example: If both players started at 100 points and A wins 5 games straight, the scores would be 143 for A and 57 for B. After that, if B and A only win alternately, the scores will not equalize. A's score will fluctuate between 136 and 128, and B's score will fluctuate between 64 and 72. For B to bring A's score down to 100, B has to win 4 additional times to cancel A's lead in the beginning.

So if player B loses 10 games initially and then plays a 1000 games winning alternately the difference between player A and B is still the same as 1000 games ago? If so, those 10 games, which are a tiny fraction of the total amount of games, weigh more than the 1000 after that. Is that the behavior you're looking for? What are the scores supposed to represent?

#5139666 Assets for tech demos

Posted by on 17 March 2014 - 03:41 AM

Imrod is frequently used in tech demos:




The files can be found here: http://www.parkparkin.com/gallery/imrod_dw.html

#5138144 Are some people not cut out for programming?

Posted by on 11 March 2014 - 11:24 AM

The only people that aren't cut out for programming are the ones that don't enjoy programming. It takes years, dare I say decades, to become an expert programmer. Even then, you'll look at your code and think you could do better. In the end, the best code is code that works.

#5128405 c++11 move constructor question

Posted by on 03 February 2014 - 06:52 AM

That depends on the implementation of the move constructor and the data you're trying to access. The variable a has not been 'moved', it still resides in the same memory location occupying the same space. The variable that's been constructed in the vector can steal contents from a. If for example a holds a pointer to an array, this pointer could be copied and then set to null for a, accessing the pointer through a would then result in a nullpointer error.

#5120114 When to use polymorphism

Posted by on 30 December 2013 - 02:53 PM

Lets say you want all your mammals to run, with polymorphism you can put all your mammals in a single mammal array and call their run function. Without polymorphism you'll have to keep a list of dogs, cats etc. and call their run function.

#5118105 SDL Pong paddle issues

Posted by on 19 December 2013 - 07:29 AM

Instead of trying to keep your fps constant(which is not what's happening) you should move your paddle in proportion to the frame time.


Some problems I saw by glancing over your code:

  • You're frames per second calculation calculates the average fps for the entire duration of the game, you probably want to reset your frames counter when at least a second has passed. To correctly estimate the fps, you should divide your frames by currentTime - lastTime.
  • Your condition to call SDL_Delay is always true, SDL_GetTicks() - currenTime will practically always be 0.
  • 1000 / MAX_FRAMES will result in an integer instead of a float, resulting in 16 instead of 16.66.., this is a significant loss of accuracy.
  • Don't use the #define preprocessor to define constants, use const values instead.

Keeping fps constant is not easy if not impossible and what happens when a device can't make it past 30 fps? Your game will run at half the speed.

In order to move the paddles and the ball at constant speeds on varying frame rates you simply multiply the movement by the delta frame time(time difference between current and previous frame).


There is another thing you need to be aware of, most timers aren't nearly as accurate as you might think. Depending on your frame rate and the accuracy of the timer, you might not be able to detect a difference in time between two frames, i.e. delta time becomes 0. I'm not familiar with SDL so I don't know how accurate SDL_GetTicks() is(a quick search indicates it's about a millisecond), so you might have to use a more accurate timer.