Tag Info

New answers tagged

0

I am working on an OpenGL Shader Engine from www.MarekKnows.com and the framework is setup as follows: An Engine Class that is part of a static library with other helpful and important classes. Then there is the main startup project where the Game Class resides along with Game Properties. This structure is to keep all Engine code separate from Game code. The ...


0

I'm using SDL-2 also. Your code, at a basic reading, looks all correct to me. To help debug it, you could put a switch or printf right in the main loop, like while(GameState == RUNNING) { while(SDL_PollEvent(&Event)) { printTheEventIfItsKeyUpOrKeyDown(&Event); // as needed Handle(&Event); } A modifier key down also ...


0

Looks like you have some problems with references. Strictly saying, you cannot return local object as a reference, nor you can bind non-const reference to a temp object like this: Add("something", GameObject()); I wonder how did you get it to compile... If you want to remove references be sure that they are not destroyed (e.g. by goingout of scope). ...


0

It seems that you have used different types in it->second.Update(ev) (ev - SDL_Event&). And in it second type is GameObject&.


1

Another way you could go about it by using a "generic" map for your parameters: int HashStringToInt(const std::string& aStringToHash) { // Hash your string here } union Value { int _int; double _double; bool _bool; }; struc Event { int _id; std::map<int, Value> _parameters; }; void boom() { static const int EVENT_EXPLOSION = ...


3

Don't shove all the events into one type. You are using C++, a language that supports Abstract Data Types. Use them! Inheritance/Interfaces struct Event { TYPE type; virtual void Handle() = 0; }; struct DamageEvent : Event { float damage; int target; void Handle() final { FindTarget(target).TakeDamage(damage); } }; void ...



Top 50 recent answers are included