I work on the state game engine and get what I'm happy with.
There is an abstract class GameState.hpp with virtual methods that I use (init, run, pause, etc.).
There is GameEngine.cpp / hpp, which is a class that contains a stack of GameState objects and sets up a game loop by running the corresponding current appropriate methods.
My test game TestGame.cpp creates a GameEngine object and pushes an instance of TestState and starts, etc. Everything works as I expect.
I want to structure the source tree, rather than compiling everything from the same directory, and thought about the following, since each game will have several states:
src/ +Engine/ +GameEngine.cpp +GameEngine.hpp +GameState.hpp +TestGame/ +States/ +TestState.cpp +TestState.hpp +TestGame.cpp
When creating, I'm not sure if I understand what needs to be compiled with and where the objects should be compiled.
So far my initial thoughts are:
Compiling GameEngine.cpp / hpp with GameState.hpp gives GameEngine.o
Compile each state of the game, for example. TestState.cpp / hpp with GameState.hpp, gives TestState.o
Compile TestGame.cpp / hpp with GameEngine.o / hpp, GameState.hpp, TestState.o / hpp (and any other states), gives TestGame.bin
Am I on the right track? Should GameEngine build a lib, or is it a normal .o normal? I'm still a little hazy about whether to include headers in every compilation. In addition, the ouput files for each compilation go in the same directory as the source, or should be in a structured bin /?
I will have a game and post some makefile attempts and output. Let me know if I should post code, maybe just 200 lines. No actual graphics implementation, etc. At the moment, this is just a framework.
Thanks guys, any help is much appreciated!
EDIT: Thanks for the quick replies of the people. I read the comments below and wanted to give an update and clarify some points.
Firstly, I look in autotools, but this is basically a training project, and part of this is grokking make files. I also come from the background of Java, so I really want to understand what exactly I create and how my project fits together. As above, I don’t even know if something should be a library or just point to compilation time.
Overview of my goal: I see the engine almost like a subproject. Despite its being simple (<10 files), it downloads what I think of as “states” and digitizes the methods [ handle events, update, display ] that determine the state. I have an algorithm that aims at a constant number of updates per second, changing the frame rate if necessary.
For example, being able to display a method, it uses SDL-enabled display functions with an engine support (perhaps a tile mechanism, a state can say “load these resources, display these fragments” or a library widget, whatever ...) to present a representation of the game world model . A method to handle events can use an abstract keyboard interface. I want to be able to add such functionality to the engine. The update will drive a model that represents the game world. He will track objects in the world (scene, player, and np), apply motion based on physics and collision detection, etc.
I think I want to be able to build this and just include the object (and the headers?) In the game I'm working on. Regardless, 'copy the source source directory to the root of the game project and add it to the main Makefile, put it all together' or 'run make on the engine whenever it changes, build a game project with a copy of the last object of the engine (, common an object, something else?) and headers, which will make it easier for me to work with several small game projects using one engine? How would I like to set myself up so that I can hit the ground with random game ideas, since I have them, for example p, 2-week encodings, etc.
States are any other kind and many interactions. The engine has a LIFO state stack, so a simple game can have the following states on the stack: DrivingMode - PauseMenu - Settings In a real game, there is an instance of GameEngine, and it would add DrivingMode to start the game. The user pauses, which pauses the DrivingMode state and pushes the PauseMenu state (starts its init, run, etc. When clicked). Here, the user selects settings that suspend the PauseMenu state and load the settings ... When they exit the system, the states are started (cleaning, etc.) are started first, and the upper state is resumed.
Wow, now heaps. I will add more or ask new questions as I move. Thank you so much for your help.