So, I am not sure if this is too much to ask, but I was hoping that maybe someone would be interested in looking over a bit of code I have been working on recently to hopefully give me some pointers and just a general code review sort of thing. The project isn't very large but I want to build an actual game out of it, so I wanted to see if anyone could point out potential issues that would be easier to fix earlier rather than later.
As an overview of the inner workings:
I created a base object called GameNode, this is the highest level game state controller, similiar to how Xna provides an update and draw function, GameNodes must implement an Update, Draw, and ConsumeEvent function. Each game node has a parent and child game and the main game loop always has a pointer to the current game node (or root game node).
When drawing, the root is drawn first, followed by it's child and so on down the chain (I.E a start menu may be a child gamenode to a gameplay gamenode)
When updating the child is updated first and the root updated last
when consuming events the child has first dibs on the event and it bubbles up the chain.
As far as the component/Entity system:
This is the part that I am most concerned with as I have never implemented this type of system before and the one in the article was simplified for ease of explanation. One major question is that the Set of Entities live in the game node... so leaving a game node destroys all entity information... I suppose this would be the correct way to handle it, but I am not 100% certain. Imagine a game node that constitues Level-1, it would be correct for all level1 entities to be destroyed when transitioning to level2, but at level2 certain entities, most notably the player would need re-initialzied, which means they'd need to be serialized/stored/retreived/deserialzed <*Note* none of that is implemented>, but I suppose that would just be the trade-off and since it only happens when loading a level it wouldn't even be extreamly noticeable right?
The components are nearly identical to that in the article, merely structs containing only data... as far as I can tell this is the standard, correct way to do this?
The systems are where it seems to get tricky... the theory is pretty strait forward, check to see if a system is applicable to an entity, if so apply the system to the entity... but realizing the theory has all sorts of twists. For example, lets say I have an InputComponent, which allows an entity to react to user input... I might want to apply this system to both a player sprite to control the sprite X,Y cords and also a menu to control which selection is made... but while entity that has the players sprite has a position or velocity component that the input system should modify, the entity containing the menu does not...
I think I have it developed to an interesting point (architecturally) and there are no obvious bugs.
I have set up three entities which use, 3 components and two systems.
The first entity has a position and velocity component.
The second entity has only a position component.
The third entity has a position component and an InputComponent.
There are two systems acting on the entity. The MovementSystem acts of the first entity, no system acts on the second entity and the InputSystem acts on the third entity.
The output is sparse and non-graphical. printing out only the Updates per second, draws per second, elapsed time and position of each entity.
The input responds to the up/down/left/right arrows and the escape key
I am sorry for the long post, but I am really hoping for some constructive criticism and maybe some pointers on where to go from here.
The project is written in Visual C++ using Visual studio 2012 express (A Visual studio 2010 solution file is also included)
I have been reading a bunch of the articles on this site, most notably "Implementing Component-Entity-Systems".
I mainly use C# and have some XNA experience, but for this one I wanted to dive back into C++.
I used Allegro (The pre-buillt windows MSVC binaries: http://cdn.allegro.cc/file/library/allegro/5.0.10/allegro-5.0.10-msvc-11.0.7z)
If your on a windows machine, and create a folder C:\AA_Main\Dev\Allegro
then unzip the allegro files to allegro-5.0.10.-msvc-11.0 (default folder name)
and unzip the project to Project1
it should run pretty easily, otherwise you might have to change the project settings to point to allegro correctly...
ie. update the following configuration properties:
http://www.paragon.net84.net/CodeReviewRequest/CodeReviewRequest.7z