🔒 Locked
Modularizing Game Code?
Advertisement
Original Post
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
*=======================*
Could you expand a little?
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
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
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.
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.
You cant include .cpp''s
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]
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.
Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.
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
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
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.
Advertisement