1

I have a game which has different game types, i.e Time Trial, Infinite Game etc.

Each game type has different timing rules and potentially collision rules. Obviously in the Time Trial the game ends when the time runs out.

I am currently adding game types by 'hardcoding' them into the program, therefore each time I want to add a new game type I have to recompile the whole program.

Basically to make adding game types easier I don't want to have to recompile everything. So potentially new game types could be downloadable content and would work simply by putting the new type in the game folder.

How would one go about doing this? I assume it is with the use of libs or dlls or something (I have very little knowledge about that so I might be completely incorrect).

I hope that all makes sense and I hope you guys can help me out or atleast point me in the direction of a book or article that explains this methodology.

Thanks in advance.

Noviz
  • 59
  • 1
  • 8
  • It is hard to answer your question without more details. What platform are you developing for? Can you describe the architecture of the program? – Jørgen Fogh Feb 11 '11 at 12:48
  • Sorry I found it hard to explain so wasn't very detailed. I'm writing the game using OpenGL and the SDL. The end platform will be Windows however the possibility of being able to run the program on other platforms would be nice but not necessary. – Noviz Feb 11 '11 at 12:49
  • I'll try to explain the classes here: I have an abstract gametype class. The game types are then written as child classes of this overall gametype class as each game type has different rules. (Wow I'm terrible at explaining things lol, I hope that makes sense) – Noviz Feb 11 '11 at 12:54
  • That explanation makes sense, but your question is a little unclear. Do you want to avoid recompiling *everything*, or *anything*? That is, are you willing to recompile *some* old files when you add a new type? – Beta Feb 11 '11 at 14:20
  • The idea is that the game will be compiled and distributed. A new game type can then be added by simply adding a new file to the Game folder. – Noviz Feb 11 '11 at 17:31

1 Answers1

5

Using native DLL for game extensibility is IMO not a good idea, especially if the code is not designed for this from ground up.

You would best employ some scripting language like LUA or Python, so game modes can be added without writing and compiling C++ code. These are quite easy to implement (especially with if you use some binding/wrapper library), but require you to design a scripting API which can be a nontrivial task (depending on how much you want the game to be modifiable). This is now quite standard approach in game industry - most commercial games have some sort of scripting support these days.

Generally, the trend is to move as much code from core (C++) to scripts, because these scripts are easier to develop, maintain and modify. Many modern games have quite clean distinction between gameplay logic (written in scripting language) and game engine (written in C++ or another compiled language).

Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
  • While I agree with your suggestion, it also requires some design decisions, which would likely force him to redesign his current architecture. There are a lot of problems you can (and probably will) run into if you try adding scripting to an engine that wasn't designed with it in mind from the beginning. For his current architecture, using DLLs with a configuration file that lists the installed extensions would get him the functionality he wants with very little impact to his current design. – Zac Howland Feb 11 '11 at 13:59
  • OP didn't reveal size of his code base nor quality of his OOP design. I think if the code is well designed, objects can be exposed almost 1:1 to the scripts. Though I have never implemented LUA or Python, I use Squirrel in my project, the transition from C++ to scripts was quite straightforward . I just registered all the classes and methods, defined script entry point and that was it. – Matěj Zábský Feb 11 '11 at 14:07
  • Thanks for the replies. My class design, I would say, is of good quality and really the code is fairly small as the game itself is rather simple. I'll research into LUA and Python and see if I can implement them into my game. Frankly I don't have a huge amount of time to fully complete the development so I may have to go with the DLL approach. Zac, do you know of any tutorials or books that work with the DLL and config file method? – Noviz Feb 11 '11 at 17:35