Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 15 May 2010
Offline Last Active Oct 22 2016 09:57 PM

#5259963 Singletons and Game Dev

Posted by on 01 November 2015 - 01:42 AM

Many successful products have shipped on terrible source code. A finished product built on a house of cards is always better than an unfinished product built on an ivory tower.


Heh, that reminds me of the lugaru source: http://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp#l7276


I guess it really comes down to a works or not result.



Global variables create hidden dependencies, which destorys your capacity to analyse access patterns and control their scheduling.
Hidden dependencies are also evil for countless other reasons too sad.png


I've been feeling this pain ever since I started working at my current job. It's a web application for which the client is written in Javascript. The way it behaves is really unpredictable. A lot of functions have really nasty side effects, and of course no dependencies are made obvious through the function interface because all data is stored in a global variable called "locals" (an oxymoron of the highest order). At least I can grep the source code to find instances of its use, but it's still not a very good "technique", merely kind of a means for brute-force debugging.

#5259960 Singletons and Game Dev

Posted by on 01 November 2015 - 01:22 AM


Ok, how is that not flagged as a bug? That's total bulls***. Is there a reason not to use the stack? I don't think "performance" is even applicable to this situation.


Meh. Dig through Android code sometime. You have to control every allocation to prevent the garbage collector from murdering you, so static float buffers abound.



Since we're dealing with an object reference, can't we encapsulate synchronization methods in the object's implementation, such as for instance using Java's "synchronized" modifiers on non-static methods?


You can make it thread-safe that way, yes. But you can't use it in parallel. Which is kind of the point of having multi-core machines in the first place.



I hear Android is supposed to have a "smart" way of managing memory, but I've never really dug into that. Kind of interesting to find out that even in simple cases like this it can be that troublesome.


I've got to really face-palm here. I very rarely need to work with concurrently executing code, so I somehow failed to realize the difference between just "multithreading" and actual parallel execution. That makes the problem a lot clearer. 



Ok, how is that not flagged as a bug? That's total bulls***. Is there a reason not to use the stack? I don't think "performance" is even applicable to this situation.


That was my first thought, but then I saw it's java. You can't allocate arrays on the stack in java, right? I've done this when using XNA/C# before, to avoid any memory allocations in the game loop... as long as I knew that section of code was not going to be called from multiple threads, or re-entered on the same thread.


That being said, if they really wanted they could just explicitly declare 16 float variables in each method  where this buffer was needed.



Well, you do have to use the "new" keyword when allocating one and in addition to that an array is actually a full object. As far as I'm aware, there's no way to declare member arrays of variable size without using the heap even in C++. If they do somehow manage to do that, I'd sure like to find out how.


> Does anyone how to get rid of this block?

#5250680 Best comment ever

Posted by on 05 September 2015 - 07:07 AM

def take_dump(self): # haha... I'm 8 years old

Here's something that resides in production code that I'm working on. The function takes a dump of a SQL database and saves it into a file.

#5237255 how to program A LOT of skills/spells?

Posted by on 28 June 2015 - 07:56 AM

You could employ a Prototype pattern: http://gameprogrammingpatterns.com/prototype.html

If you have a lot of if/else statements or a large switch, you should probably start thinking about how to alleviate all those checks. 


In addition, if you haven't read through some of those design patterns, I suggest you do. They're pretty awesome and they can make your code a lot more flexible.

#5226151 Random Number Generation

Posted by on 28 April 2015 - 03:06 PM

>Whatever you're trying to encrypt isn't nearly as important as you may think.


But it is, TO ME.


I'm sure the USA government thinks just as much of their own data, but not even they opt for such drastic measures. AES-128 and above are hard enough that even a super computer couldn't crack them within the lifespan of a human being. Unless you're storing the blueprints for Skynet-level AI, your methods are serious overkill.

#5225935 Spot the bug quiz.

Posted by on 27 April 2015 - 03:36 PM

A friend of mine posted this little quiz on Google+ not too long ago, and I thought you guys might get a kick out of it if you haven't seen it before. I haven't seen C++ code in ages (I'm a Java-based code monkey myself), but I was still able to get some of the questions right. Fair warning: some of the code present is a major eye sore. Not quite THAT bad though.



#5225676 Why Does Everyone Tell Newbies To Make Games?

Posted by on 26 April 2015 - 11:56 AM


It's because it is so much better to concentrate on small, really small, practical projects that you can actually stand a chance to complete than diving head first into making a game engine or a MMO.

If Pong seems like too much, then it would probably make sense to set the bar lower and pick a simpler project. smile.png

You learn more from finishing your projects, no matter how small/trivial they are.


Make games, not engines.

I try to tell Newbies to do that.

The simpler the game, the better.

No, I'm just saying that it's hard if you have no knowledge of a framework, and if there are no good tutorials tongue.png



Well, telling people to make games bares no influence on their choice of framework. Of course, the person giving this advice also has the option of suggesting frameworks with good and reliable resources. Besides, what else are you going to do? If you have no experience in doing something, what would you suggest a newbie should do to gain that experience? If you ask me, making a simple games gives fantastic insight and serves as a great stepping stone in the right direction.

#5132861 Better way to write this code

Posted by on 19 February 2014 - 10:22 PM

The second return statement is necessary because the compiler can't just assume the first return statement will execute. There is no guarantee that a node in the list matches the argument key.


Therefore, the return statement in question should return a value that one would expect if there was no entry matching the given key. If you can't return null, you could write it like this:

public Coordinates GetNodeCoordinates(int number)
            foreach(Node node in nodes)
                if (node.Number == number)
                    return node.Coordinates;
            return new Coordinates(); 

But you won't be able to tell if you actually found a valid set of Coordinates unless you save that state somewhere. The above code is pretty much the same as yourself, with the exception that it only creates a new Coordinates at the last minute and only when needed. Not a great improvement, but some start.


I don't know C# very well. I thought it would have a reference system more similar to Java, but in Java you can return a null value for just about anything that's not a primitive.

#5131458 Trouble with strings and chars with arrays and loops

Posted by on 14 February 2014 - 08:41 PM

I myself would prefer to use a simple table method although it really depends I guess. A HashMap will do the job and will probably be more straightforward (I guess it depends on what you're more used to), but if you are bound to using arrays, the following solution is probably what I'd use:

final char alphabet[] = "abcdefghijklmnopqrstuvwxyz".toCharArray(); // A little ugly over here, but, that's meh.

String str = "Some string text goes here";
char charArr[] = str.toLowerCase().toCharArray();

int charCounters[] = new int[alphabet.length];
for(char character: charArr) {
   for(int i = 0; i < alphabet.length; i++) {
      if(character == alphabet[i]) {

#5131455 Trouble with strings and chars with arrays and loops

Posted by on 14 February 2014 - 08:24 PM

charAt( int ) returns the primitive char, so you can't call functions on it. The mistake is obvious: you need to use == instead of =. Single equal sign assigns to variables (which is why your compiler is complaining about needing a variable), and double equal signs compare equality (which is what the if-statement is expecting).

#5128270 GDI+ How to redraw screen?

Posted by on 02 February 2014 - 05:13 PM

Thanks, but I don't know where in I have hand on "backbufferDC" to Graphics* m_pGraphics;

You create it yourself. You don't want the user to see you draw every piece of the UI manually, that's what creates the flicker. To solve this, you create a buffer off to the side, do all your drawing there, and when it's done, you show the results on screen.

#5126756 Figuring out normal force.

Posted by on 27 January 2014 - 11:52 AM

On inclined surfaces the normal force will be equal with the sine or cosine of the inclined surface angle * gravity . Am I right?



I always remember it as the negative projection of the gravity force onto the normal vector of the surface where the object is rested.

#5126623 Figuring out normal force.

Posted by on 26 January 2014 - 07:57 PM

It looks like you are making a step into the Continuous Collision Detection concept.

The idea is simple. You should first detect the collision between the two bodies, platform and player. When this type of collision is made, you mark it them as colliding, thus activating your continuous contact routines, which should apply the normal force. While they are marked as colliding, you should apply the normal, and keep in watch for a break of this contact, that could be caused by several things:

The player jumps

The player goes beyond the platform border

A new force is applied (a bomb, a bullet, a backflip kick from a rhino...)

Any force change (weakening gravity, variable magnetic force)


This is a simplified version of the theory, also notice that it is my own interpretation, but it is quite a complex algorithm and I am searching the Box2D code to understand its implementation myself; so I can't help you further, but if you like to read code, here is a link that can.

You could use a simpler but specialized version. It would probably perform even better.


This seems to be pretty much what I was looking for. I wasn't sure what to look up but I'll have a look at this when I have time and get back to you on that.


From your description, it sounds like the platform is not a collision object. If you make the platform a collision object, a collision will result (when appropriate) between the player and the platform, and provide the point of contact and the contact normal. (Many collision engines provide for a planar collision object with a normal, an extent, friction factors, etc.)


Am I understanding your question?


The platform is a collision object. The entire world in my game is actually made out of discrete objects. My question should have been "how do I know if I'm standing on a platform if I haven't detected collisions yet on this cycle." My physics simulator does things in the following order: sum forces, get acceleration, integrate acceleration and velocity, and with the resulting disposition, check collisions and respond. The problem with this is that I won't know if I'm standing on a platform until I check collisions, but I need to know that when I'm summing forces because of the normal force.



The normal force minus gravity equals 0 if you are standing on a platform.

N - G = 0 
N = G


The question isn't that simple I'm afraid. And I don't want to be a party pooper, but on an inclined surface, N != G.

#5126377 Figuring out normal force.

Posted by on 25 January 2014 - 03:57 PM

Hello everyone!


I have a question that pertains to figuring out normal force. I seem to have a predicament that involves collision detection.


At the start I first sum all the forces acting on the object at hand. All external forces come from input or collisions that were maybe applied last cycle. Then all the internal forces: friction, gravity, and normal force. Gravity I can figure out, but figure friction requires me to know the normal but for that I have to know if I'm standing on a platform or not. My question is, is there some elegant way to solve this? For example, is it plausible to just omit the normal force on the first cycle, check collisions and apply the normal force on the next? Or should I make a deliberate check if player is standing on a platform?

#5126250 "Oh God, Who Wrote This?", "You Did", "Wait? I wrote Thi...

Posted by on 24 January 2014 - 09:56 PM


Of course, everyone says I'm over reacting, but I've seen the effects of not caring, and I know how big of a benefit clarity and consistency carry.

There is definitely a balance to be struck there. Ideally you are able to write both sorts of code: the throwaway prototype you needed yesterday, and the carefully structured (and tested) code that is headed for production.



I agree that perhaps it's unnecessary to structure code with utmost care when prototyping, but even if prototyping I feel like there's still things one could do to write cleaner, albeit throwaway, code.


The poster in this thread is a prime example: http://www.gamedev.net/topic/652538-pathfinding-behaviour/


I wouldn't put code like this in production, but I would certainly not write it as throwaway either. I managed to fix an error in his adding function merely by giving the variables proper names, which, if he had done in the first place, he would have noticed the glaring logical error.