Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 13 Oct 2012
Offline Last Active Today, 12:50 AM

#5213714 I think I don't understand dynamic memory

Posted by ultramailman on 01 March 2015 - 02:16 PM

Maybe I can try using analogy to explain it.


automatic allocation:

Imagine there is a restaurant with many tables and seats. You and your family go in the restaurant. The mute receptionist sees that you have 5 people, and leads you to a table G, with 5 seats. Now table G is occupied by your family. When you are done eating, you leave the restaurant. The receptionist sees that and table G is unoccupied. The next family of 5 that comes are able to use table G. This whole time, you did not speak to the receptionist at all, because he is mute.


dynamic allocation:

Now Imagine there is another restaurant with many tables and seats. You and your family go in the restaurant. The blind receptionist asks "how many people"? and you tell him 5. The blind receptionist finds an unoccupied table E with enough seats for 5 people. He's blind so he doesn't want to talk and trip, so he tells you where the table is. Now table E is occupied by your family. When you are done eating, you leave the restaurant. However, you forgot to tell the blind receptionist that you left. He still thinks table E is occupied by you, so table E will not be given to any customers.


tables and seats = memory, since they are space.

customers = data, since they are the contents that occupy space.

the act of entering/leaving restaurant = entering and leaving a scope.

the act of being led to a table by the mute receptionist = automatic allocation.

the act of telling the blind receptionist how many seats you need at the minimum, and getting the location of the seats/tables = dynamic allocation.


This analogy omits some details, but I hope that helps.

#5211128 Initialize vector of vectors after declaration.

Posted by ultramailman on 17 February 2015 - 01:24 AM

What ^ said. If you want pretty code for the indexing logic, it's pretty easy to wrap around in a function.


You can also make a wrapper class that only contains the 1d vector and some methods or operator overloads. That'll allow you to write it like 2dArray.at(x, y) or even 2dArray(x, y).

#5157956 How to make a character fall off the block after it has been on it

Posted by ultramailman on 03 June 2014 - 04:39 PM

How to prevent the character from jumping again if it is already in a "jumping state"?


Your question kind of answers your question.

Make separate states for "initiating the jump" and "jumping" (I like to call it "falling").

if(spacePressed && (state != ActionState.JUMPING))
state = ActionState.JUMP;
else if(state == ActionState.JUMP) // .... and then in the next frame
state = ActionState.JUMPING;

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

Posted by ultramailman on 23 May 2014 - 10:11 PM

That sounds like a job for an array-like data structure. So I think a vector is suitable for this. When you remove the item, you mark that item's slot as unused.

#5153454 How do you know if you are not reinventing the wheel in your language

Posted by ultramailman on 13 May 2014 - 09:35 PM

Whatever you do, you are probably reinventing the wheel. I don't think there's anything wrong with it though. If you have a problem and you come up with a system to solve it, good for you, and you learned something, wheel or not.

#5150713 SDL audio callback buffer size

Posted by ultramailman on 01 May 2014 - 01:56 AM

@ LongPointer, you are right, using checkspec.wav is kind of silly. I don't use it anymore. As for filling the numbers in after OpenAudio, it doesn't work, because I already got the audio device.

#5148857 SDL 2.0 and String Constructor Errors

Posted by ultramailman on 22 April 2014 - 06:12 PM

Why isn't it guaranteed the prints will run? I know some people say some prints might break during certain situations but I don't really understand why. If the if statement is true, then the program has to run the print before it can return right?


The print function run, it's just that they might not actually print to the screen until you flush the buffer or the buffer gets full.

#5148658 2D physics, random line geometry, many balls, and jitter problem

Posted by ultramailman on 21 April 2014 - 11:48 PM

Another way is to perform your collision solving step multiple times per frame, because solving collision once could lead to new collisions. So think of it as a fixed point method, refining your physics world the more times you run it.

#5148655 2D physics, random line geometry, many balls, and jitter problem

Posted by ultramailman on 21 April 2014 - 11:16 PM

I don't understand the concept yet, but "speculative contacts" is one way to go.


#5148592 undefined reference to `SDL_main'

Posted by ultramailman on 21 April 2014 - 01:59 PM

Let me give this a shot.


When doing the linking step, you use:


g++ -o Main.o -LD:\SDL2\i686-w64-mingw32\lib -lmingw32 -lSDL2main -lSDL2


This looks like you want to link nothing to the libs, and output it to a file called Main.o. Try changing it to:


g++ Main.o -LD:\SDL2\i686-w64-mingw32\lib -lmingw32 -lSDL2main -lSDL2


instead. This means you want to link Main.o to the libs, and output it to "a.exe"

#5148411 SDL 2.0 and String Constructor Errors

Posted by ultramailman on 20 April 2014 - 03:58 PM

I don't see anything obvious, but try changing

test i = test(100,100); // creates temporary test object and assigns the temporary object to the object i



test i(100, 100); // this creates test object i, and calls constructor of i

#5148016 Keyboards that don't Key

Posted by ultramailman on 18 April 2014 - 05:51 PM

Since it's a hardware limitation, one way to go around that problem is to allow the player to customize key bindings. That way, if my keyboard can't accept key A and key B at the same time, I'll just change the keys until I'm satisfied with it.

#5147228 How to stop users from manipulating Game Save Data

Posted by ultramailman on 15 April 2014 - 05:42 PM

As long as the user has access to the file, it can be modified. You can stop the average user from being able to make sense of the file by obfuscation (encrypt it, or compress it).


I would just leave it in plain text, and just not bother with stopping the people from modifying the game saves.


If you must not allow it, you will have to store the game saves in a remote hard drive, so that users can't access it.

#5142116 SDL2, mingw64, and Code::Blocks

Posted by ultramailman on 25 March 2014 - 04:23 PM

Building SDL2 using mingw was pretty simple, it's just a cmake -G"MinGW Makefiles" followed by a mingw32-make.

#5139289 random generators

Posted by ultramailman on 15 March 2014 - 01:37 PM



I've just switched from int rand(void) to c++11's random library, with all the engines and the distributions.


So It's pretty convenient to be able to have the distribution objects to generate uniform floats or integers, but I wonder if there is the need to have multiple engine objects in one program.


Let's say I use randomness in three different ways, in the same game, in no particular order:

1. generate a uniform x position from 0.0 to 100.0 (enemy spawn location)

2. generate a uniform fraction [0.0, 1.0) (enemy spawn chance)

3. generate a uniform integer from 1 to 3 (randomly choose a power-up)


Is it "more correct" to use one generator with its own seed for each purpose, or it is fine to just use the same generator with different distributions?