Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 13 Oct 2012
Offline Last Active Dec 29 2015 02:28 AM

#5243323 How to initialize a reference variable in a Quadtree?

Posted by on 28 July 2015 - 10:55 PM

If you really don't want to keep a member reference variable to the entity manager, you could pass it as a function parameter to the functions that actually need it.


Another way is to make the entity manager a global variable.


Personally I think the member reference variable approach is fine, it's pretty simple. Passing the manager as a function parameter is more flexible, but you probably don't need it unless you are considering the possibility of using the same tree node on different entity managers . On the other side, you have the global entity manager approach. That's a fine approach if you will only ever use one manager.

#5215276 Trying to make 2D tile based game in Dart...2D array index confusion nightmar...

Posted by on 08 March 2015 - 10:46 AM

If you are having troubles with ordering of indices, you can make yourself a function that accepts indices in whatever order you want.


item = array.atXY(x, y)

#5213714 I think I don't understand dynamic memory

Posted by 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 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 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 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 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 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 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 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 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 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 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 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 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.