Skip to main content
gamedev.net
🔒 Locked

Modularizing Game Code?

Started by Gf11speed Feb 17, 2003 at 4:40 PM 12 replies 800+ views
Original Post
Gf11speed
Gf11speed
Hello, I was just wondering if there are any good tips on how to modularize code for a game. I understand the concept but find it hard to modularize it properly because I can''t seem to catagorize it all. Any tips? Thanks. *====================* http://www.syntasoft.com *=======================*
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
skillfreak
skillfreak
Could you expand a little?
Gf11speed
Gf11speed
Well, I guess I am looking for an example of how to break a big game down into modules. Maybe like sounds.cpp/h, gameplay.cpp/h, etc. What is good way to do this?
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
SinnDarin
SinnDarin
I think a good way to do this could be dll usage...
Use one dll for each of your module :
- 3dengine.dll
- sound.dll
... and whatever you want...
It allows a very easy way to maintain your code and is very
flexible

Have a look on LoadLibrary and GetProcAddress functions...
It can be also a nice way to introduce thread in your app

Sinn
Gf11speed
Gf11speed
I''ll have to look into DLLs, I don''t know anything about them.
Greg FieldsSyntasoft Gameswww.syntasoft.comPost-Time Horse Racing (Available Now)
Peon
Peon
Can you <#include> .cpp files? I never tried it, lol. But assuming you can, it seems easy. I keep my classes as a .h and just include them. It seems to work fine that way. .dll''s have always seemed hard to me, but what do I know
Peon
Alexandre Brien
Alexandre Brien
I would keep away from dlls at first and just take advantage of C++ classes. Basically you will want a class for your engine, which would hold as member variables an object to your Input class, your audio Class and a renderer class. With those you would essentially have the core of an engine.

So in your game loop (prolly a CEngine function)
you could do in order

inputSystem->GetInput();
AnimateGame(); (move objects according to input and ther inputs, could be Ai, another player etc...)
renderer->DrawScene();


Of course its a lot more complicated than that. You would prolly have a CEntity base class, and a lot of class deriving from it for all your game objects. You would have font system, gui system, menu system, etc...

And it will always be very easy for your class to interact together via pointers.
For example, you would only have one occurence of your Audio system in the whole program, but nothing stops you from having a pointer to that audio object in each of your entities objects.
In Construction : http://www.gdev.org
fartocci
fartocci
quote:
Original post by Alexandre Brien
You cant include .cpp's





sure you can....

template (class Item) class LinkNode {

yadda yadda yadda
};

#include "LinkNode.cpp"


edit: didn't like my greater than less than around "class Item"

[edited by - fartocci on February 18, 2003 1:18:55 AM]
Nacho
Nacho
quote:
Original post by Peon
Can you <#include> .cpp files?


Yes you can, but as far as I know it´s a horrible habit and you must avoid it.
CpMan
CpMan
Under the C++ standard, .h files are only compiled if they are included in a cpp file, but cpp files are compiled all the time. So including a cpp file is not considered good practice. If you wish to do something like that, put you stuff in an h file, include it in a cpp file, and then include the header file. Furthermore, putting things like templates in cpp files is also not allowed. The level of sytax/semantic checking on a templated class is lower than that of a non-templated class, so templated classes much be defined and declared in a header. Finally, including cpp''s can incur problems because a cpp''s source could be compiled twice, leading to multiply defined symbols.



Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
Gyzmo
Gyzmo
Of couse you can include .h file, you can also include .jpeg files, .foobar files or whatever, the extension .h is just a (widely accepted) convention. They''re all just files the compiler understands. Header files are an abstraction to help divide your code into understandable blocks.

Gyzmo
==============================
"Well is the world standard" - The Alchemist
"Not in Canada!" - jonnyfish
Gyzmo=============================="Well is the world standard" - The Alchemist"Not in Canada!" - jonnyfish
Arild Fines
Arild Fines
quote:
Original post by Alexandre Brien
You cant include .cpp''s


You can include an Excel spreadsheet if you want. You may not like the results, though.



"I know very well who Satan is: He is freedom. He is the uncontrolled, the incalculable, the antithesis of order and discipline, the antithesis of the legalism of outer space.... We know where a planet will be in twelve years, four months and nine days. But we don''t know where a butterfly will have flown one minute hence. Therefore the butterfly is of Satan."
-- Jens Bjørneboe
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
fartocci
fartocci
quote:
Original post by CpMan
Furthermore, putting things like templates in cpp files is also not allowed.


You can do it... do I do it personally? No, I put everything in the header... but:

#ifndef LINKNODE_H
#define LINKNODE_H

template (class Item) class LinkNode {

yadda yadda yadda
};

#include "LinkNode.cpp"

#endif


is allowed. It was in my notes for CS 2704 when we went over templates for the first time and I''ve seen it other places as well... google it if you don''t believe me. Some compilers will complain though... I just took my old stack template, separated it and tried it under .NET and no dice. My only point was that you can do it though... should you? thats another question

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.