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

#5142116 SDL2, mingw64, and Code::Blocks

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

#5137586 Not able to implement classes to get Polymorphic Behavior

Posted by on 09 March 2014 - 12:47 PM

So it seems, Kanefa , that what you are are trying to do with the getString is not polymorphic behavior.

#5137362 Not able to implement classes to get Polymorphic Behavior

Posted by on 08 March 2014 - 11:57 AM

The base class is missing getString(). It'll need that if you want all Event types to provide some kind of info string. But if you only want getString in EventStr, then casting seems to be fine.

#5134600 Can you talk the programming techno talk?

Posted by on 25 February 2014 - 06:42 PM

(editor's note: SE/SO refers to "Stack Exchange" and "Stack Overflow")


Why not inline it?

#5134238 How to deal with Input Sequences?

Posted by on 24 February 2014 - 04:51 PM

So what exactly is your InputQueue type? Is it a queue?

From this snippet here



InputQueue* newInput = new InputQueue();

newInput->valueX = inputKeys[inputCode].valueX;

newInput->valueY = inputKeys[inputCode].valueY;

newInput->valueZ = inputKeys[inputCode].valueZ;

newInput->command = inputKeys[inputCode].command;

newInput->time = timeModule.GetRealTime();


I'm lead to believe your InputQueue object is not a queue, but an object that stores some input state for a particular input event.

#5133624 Implementing an Entity Component System in C++

Posted by on 22 February 2014 - 12:36 PM

I dont think you need to make them singletons. In my mind, systems are more like functions that do stuff given entity inputs, so even plain old functions are fine, no need for a class.

I cant say much about using OOP constructs approach though, Ive been using the "relational database" approach to ECS. Take a look at that, it might give you a different perspective on what ECS is.

#5133315 Another Component Entity System Question

Posted by on 21 February 2014 - 11:30 AM

Ok i see where i was confused now, need to look up on my bit wise anding :) When i broke down your code, and thought about it it made a lot more sense, Thanks ultramailman ;)
With that said, am i right in thinking that your if statement is slightly incorrect. By anding any statement with any component, they would be true.
So the if statment would be if( true && true ) render all
Im guessing it should be if( ( mask & position ) == position )
As for my other question, am I correct in thinking that if i had 100 components, and a particular entity - like Static above - uses only 3, that all 97 other components are just left blank?
Thanks for the Help !

You are right, it wouldnt work if position and image have more than one bit set. But they ate probabably single bit masks, unless you want to have x and y component separate for position, for example.
And yes, the other 97 component arrays would be left undefined. So far, I have 15 components in a game I'm working on, so I dont know what impact will 100 components have.

#5133161 C Programming - .h and .c file Question

Posted by on 20 February 2014 - 10:49 PM

So when you #include "Employee.h" you are telling the compiler/linker "this source file needs to be linked with the .o file generated by Employee.c".


Not exactly. #include is literally copying the contents of Employee.h and pasting it in the file that invokes it, it doesn't tell the compiler or the linker anything.


Using your example, your main.c should be:

#include <stdio.h>
// forward declaration, so that the compiler is informed that this function is defined somewhere.
void Employee_Initializer(Employee * emp);
int main(int argc, const char * argv[])
    Employee emp;
    Employee * emp_ptr = &emp;
    // since the function is declared up there, it is ok to call it.
    return 0;

When you compile, you compile each .c file separately, producing a .o file.

When compiling main.o, it will see that forward declaration, so it will know that Employee_Initializer is either not defined yet, or it is in another .o file, and it won't throw any errors at you.

(for example: cc -c main.c -o main.o -std=c99)


Then you compile Employee_def.c and get Employee_def.o.

(for example: cc -c Employee_def.c -o Employee_def.o -std=c99)


Then you link main.o and Employee_def.o together, and the linker should be able to find Employee_Initializer in Employee_def.o.

(for example: cc main.o Employee_def.o a.out)


But what if you have more than one forward declaration? What if you have hundreds of lines of these forward declarations? It's tedious to copy and paste that to every file that needs them, so that's why #include is used. It allows you to paste as much info as you want from another file, without making your own file looking cluttered with forward declarations.

#5133131 Another Component Entity System Question

Posted by on 20 February 2014 - 08:12 PM

Na, the point of the masks is so that you don't have to care what type of object it is. Don't render based on if your object is static of dynamic, but rather, render if it fits the requirements of being rendered.


something like this:

void cGraphics::Render( s_World *World ) {
for( int entity = 0; entity < ENTITY_MAX; entity++ ) {
unsigned mask = World->mask[entity];
if( (mask & POSITION) && (mask & IMAGE)) {
// Render Code
// this should render both static and dynamic objects

#5131501 RB-Tree or AVL trees

Posted by on 15 February 2014 - 03:04 AM

Go with hash tables if you don't need ordering.



The best way to find out is probably to just use each of them in your game, and see which one is better.

Theoretically, RB trees can have height that goes up to 2 * log(n), but it's still O(log(n)).

You can also look at AA trees, which are RB trees with the red nodes only on the right side (or left if you are left handed), so they have log(n) height on the left side and at most 2*log(n) height on the right side.

And also you can look into b-trees, a generalization of RB and AA trees.

#5130605 Examples of "SDL Game Development" in ANSI C?

Posted by on 11 February 2014 - 02:04 PM

Do you have to use three different kinds of textures in one program? If you must, you can use a void pointer + enum flag to indicate which kind of texture you are using.


Don't try to translate c++ idioms to c, it's not always easy to achieve it if you want elegant code.

#5125247 Are mutexes really fool-proof?

Posted by on 20 January 2014 - 11:53 PM

can't type anything ;-;


press ctrl-c to send interrupt signal, that will interrupt your program and let you look around. Then you will get a prompt "(gdb)", and you can type in "thread <thread number>" to look at different threads. When you are ready to continue the program, type in "c".

#5124070 Ugh! Your shorthand is too short!

Posted by on 15 January 2014 - 11:49 PM

I was trying to learn about b-trees, and so I looked around and found this implementation, full of one letter variable names:


#5123474 Help with making a struct please?

Posted by on 13 January 2014 - 09:40 PM

Hmmm, turns out that it doesn't like me initialising the struct outside of the main function.


Oh, well. All good now smile.png


Thanks guys.

You can do it, you need to initialize it with an initializing syntax:

struct color
     int r;
     int g;
     int b;
struct color c_aqua = {0, 255, 255};
// or if you use c99:
struct color c_yellow = {.r=255, .g=255, .b=0};
int main(void){
    return 0;