Jump to content

  • Log In with Google      Sign In   
  • Create Account

ultramailman

Member Since 13 Oct 2012
Online Last Active Today, 01:20 AM

#5134600 Can you talk the programming techno talk?

Posted by ultramailman 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 ultramailman 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 ultramailman 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 ultramailman 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 ultramailman 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.
    Employee_Initializer(emp_ptr);
 
    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 ultramailman 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:

unsigned STATIC_MASK = POSITION | IMAGE;
unsigned DYNAMIC_MASK = VELOCITY | POSITION | IMAGE;
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 ultramailman on 15 February 2014 - 03:04 AM

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

 

edit:

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 ultramailman 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 ultramailman 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 ultramailman 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:

http://attractivechaos.awardspace.com/kbtree.h.html




#5123474 Help with making a struct please?

Posted by ultramailman 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;
}



#5119985 Advice to lock frame rate

Posted by ultramailman on 30 December 2013 - 01:47 AM


I think I'm doing pretty much the same

 

I think yours and eduardo's are different. Your algo will update, render and wait some time as filler to make it 16 millisec per frame (1 update per render with waiting), while eduardo's will update multiple times until 16 millisecs or more has passed before rendering (one or more updates per render without waiting).

 

For more information, look at the article Fix your timestep! on the internet, it talks about various kinds of game loops.




#5119958 Advice to lock frame rate

Posted by ultramailman on 29 December 2013 - 10:33 PM

On any platform you could control the rate of update and render with this simple algorithm

...

Can somebody explain why this is downvoted?




#5115208 Did you know you can define functions like that in C?

Posted by ultramailman on 07 December 2013 - 03:14 PM

Yeah, it would be cool to be able to do closures in c. When i saw that function typedef (not the function pointer typedef), it almost looked like one could declare a variable of a function type, and assign some value to it. Then I recall variables need a size, and have no answer to that.

 

So in c, other than declaring a variable as a pointer to a function type, there doesn't seem to be much use for a function type (it does look nice though, I like function_type * more than function_type_ptr).

 

edit:

Seems like it can be used to replace a forward declaration too, like this

#include <stdio.h>
typedef int main_func_t(void);
main_func_t test_func;
int main(void) {
    main_func_t * test_func2 = &test_func;
    test_func();
    (*test_func2)();
    return 0;
}
int test_func(void){
    puts("hello");
    return 0;
}



#5115048 Did you know you can define functions like that in C?

Posted by ultramailman on 07 December 2013 - 12:39 AM

I've typedefed function pointers before, but never a function type. What can one do with the type of a function?






PARTNERS