Sign in to follow this  
EngineProgrammer

Game Engine Programming

Recommended Posts

Hi everyone!

For the last 2 years I have been learning all basics of C++ Programming. Also I've tried to start writing a game engine but that didn't really worked out very well. ( It was a terrible framework you just want to kill when you look at it )

But now, after watching allot of open source engines and after looking at engine structures I'm going to restart with creating one.
But I have some questions though.

1) I want to have my final engine with DirectX implemented, is it smart to start with a full Win32 code and then later on starting to implement Dx?
2) How long ( make a guess ) will it take to write a little engine ( incl. Basic: graphics, sounds, network, shaders, 3D models, 3D animation ) for an un-experienced Programmer? I'm guessing around 4-5 months but I think I'll be the only one who thinks it is that easy? [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

I already know the hardest thing won't be writing the code itself, but finding the best structure/framework.
The structure of the engine I have in mind is this:

WinMain func. -> Initializes Engine class + Game class

Engine class -> Window class ( handles the window itself, fullscreen mode etc )
-> System class ( for input keyboard, mouse, controllers, etc )
-> Graphics class ( can load/create shaders, add effects )
-> Resources class ( to load images/sounds/videos )
-> Network class ( using RakNet )

I'm thinking to create a singleton design for each class above ( except the game class ).. Can't really think another way to make simple calls on them. I'll put some code down soon.

Also, does someone have any tips for me I can use to create an efficient engine?


Kind regards,
Jonathan

Share this post


Link to post
Share on other sites
As I said, I would put some code down. Here you go:

[CODE]
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
// Avoid Warnings
UNREFERENCED_PARAMETER( hPrevInstance );
UNREFERENCED_PARAMETER( lpCmdLine );

// Create Engine Objects
T_Engine::CreateInstance();
T_Window::CreateInstance();
T_System::CreateInstance();

// Return FALSE if an instance is corrupt
if( T_ENGINE->HasInstance() == false ) return FALSE;
if( T_WINDOW->HasInstance() == false ) return FALSE;
if( T_SYSTEM->HasInstance() == false ) return FALSE;

// Create The Game Object
StarBattle* pStarBattle = new StarBattle();

// Receive Properties from Game Object
pStarBattle->InitializeProperties();

// Initialize Engine Objects with Properties
T_WINDOW->Initialize( hInstance, nCmdShow );

// Startup the Game
pStarBattle->GameStart();

// Run the Message loop
MSG msg = {0};
int iTickCount = 0, iTickTrigger = 0;
while( msg.message != WM_QUIT )
{
if( PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
iTickCount = GetTickCount();
if( iTickCount > iTickTrigger )
{
iTickTrigger = iTickCount + 1000/T_ENGINE->GetFramerate();
// Update Game
pStarBattle->GameUpdate();
// Render Game
pStarBattle->GameRender();
}
else
{
Sleep(1);
}
}
}

// End the Game
pStarBattle->GameEnd();

// Deallocate all Engine Objects
T_Engine::ReleaseInstance();
T_Window::ReleaseInstance();
T_System::ReleaseInstance();
return TRUE;
}
[/CODE]

So this is a basic code of my WinMain.
Creating Engine objects using Singleton design.
Asking the Game class for the properties and initialize engine with it. Edited by EngineProgrammer

Share this post


Link to post
Share on other sites
Lucca    101
[quote name='saejox' timestamp='1345430973' post='4971308']
2 years minimum.
there are so many concepts you will need to tackle.
like scene management, skeletons, loading models, hlsl, etc..
and result wont be satisfactory. first projects almost never are.
i have been there.
[/quote]

I think a full 3D engine with network capabilities will take even longer than two years. An acquaintance of mine worked on his engine on his free time, and took a whole year on 3D "renderer" (I forget the word) alone.

But I'll reinforce the "result won't be satisfactory" part. I'm there, right now. I've been working on a 2D C++ game engine for about six months: I really think it sucks and want to throw it out the window. But I keep going. You should keep in mind that, even if it sucks, you're learning something from it.

I don't know any DX (I'm currently learning OpenGL), so sorry if I can't be of any help. I just thought I'd say this.

Share this post


Link to post
Share on other sites
2 years, damn [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] made a very wrong guess then.

I'm not planning to use skeletons in my engine yet. I just want to load a 3D model object, and I want to load its animation as well. ( for example a box moving up and down in 3Dsmax ).
I've already learned networking with RakNet. I'm able to make hosts and clients and make them communicate with each other. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

I didn't really get into DirectX yet so I don't really know anything about screen management. But I have 2 example engines from school, an engine with Win32 and an engine with DirectX. ( But The frameworks of those 2 engines are really bad. )


So.. Should I start with writing the engine in Win32 or in DirectX?
I think to start with Win32 because I already wrote a basic engine with it. ( bad framework but still ) I think I'll have a better framework now.
But I also think the implementing of DirectX in all the Win32 code will be a hell. [img]http://public.gamedev.net//public/style_emoticons/default/unsure.png[/img]


Lucca, good luck with your game! Do you have some graphic stuff to show? [img]http://public.gamedev.net//public/style_emoticons/default/happy.png[/img]

Share this post


Link to post
Share on other sites
krippy2k8    646
It really depends on the scope and complexity of the engine that you have in mind, your skill level, how fast you learn, how much help you have, how much money you have to throw at books and such, and how much time you have to commit to it.

As a relative beginner if you are looking to create a commercial quality game engine by yourself, then you're probably looking at 4-5 years. Maybe 2-3 years if you are a very quick study and can work at it full time. If you want to develop Unreal you could be at it for 20 years ;)

On the other hand, if you just want something simple to use yourself, without complex material systems, realistic physics systems or advanced AI systems and you're just targeting Windows with DirectX, then you can probably roll something out in a few months if you can put your head down and go at it full-time. Most of the things you would need are well solved problems with plenty of examples to be found in books and online.

Just figure out what you want up front and then do it. If you just want an engine to make some simple games or demos, then you don't need to over-analyze things and try to make the most perfectly elegant game engine framework design of all time. That's how things [i]don't[/i] get done Edited by krippy2k8

Share this post


Link to post
Share on other sites
AticAtac    335
Giving time estimates is almost impossible. Why? Cuz there are too many individual factors which depends on you:

factors:

- how good are you at programming? Here i also mean how well you know your tools and the enviroments, used SDKs, API's etc.
- how "special" will your engine be? If you use common concepts you don't need to reinvent the wheels and there will be tons of resources which you could use/adapt
- how much time will you spend for developing this? Also, consider that workng on something e.g. 3 days a row is much more efficient that spending 6 days spread over several weeks
- how good are your math skills?
- how well are you familar with concepts like 3D, Animations, Shader programming, etc.
- ...

Unfortunately, i don't have an equation for the above factors, so the only way is to find it out ;)
There is only one advice i can give you: just do it and don't think that you aren't doing the "perfect" way.
Its a matter of iteration, your 2nd engine will be better than the 1st , etc.
You could speed up development by looking at some existing engines. Edited by AticAtac

Share this post


Link to post
Share on other sites
nife87    520
[quote]1) I want to have my final engine with DirectX implemented, is it smart to start with a full Win32 code and then later on starting to implement Dx?[/quote]

Since you have looked at many open source engines, you will undoubtedly have noticed that most lean towards being cross-platform and that their hardware-/platform-interfacing systems, such as graphics (Direct3D, OpenGL), audio (DirectSound, OpenAL), input (Win32 RAW, XInput2), system-info (OS, CPU and RAM details) and window-handling (Win32, X-Window), are more-or-less platform-independent.
If you lean towards making a "clean" engine, separating the platform-details from the standard interface both looks extremely good (clean, standard source code) and makes it easier to port to other platforms in the future, even if you only intent to support Win32 for the time being (for rendering, both Direct3D and OpenGL can be used on Windows, as with DirectSound and OpenAL). Edited by nife87

Share this post


Link to post
Share on other sites
french_hustler    479
It takes an awfully long time just to get a basic framework that's reliable, consistent, and usable for simple demos. I have been doing work on my engine for around a year now, programming during my free time. It has just recently started to become decent enough to get some demo apps out of it. I have been focusing mostly on the 3d renderer so far. You need to make sure that your core architecture is solid and that it allows for simple and flexible expansion. Make sure to keep track of documentation, especially if you are working alone. This is one thing I regret a lot. Most of the time I add new features, I need to look over old code and try to remember how it works. I have not documented my code much and it is starting to bite me in the ass. Edited by french_hustler

Share this post


Link to post
Share on other sites
BornToCode    1185
I have to disagree with Phantom. If you have written a game before, you should be able to have some form of an idea on how you want the engine to be structured depending on the type of game you want to target. I have done exactly that and it work out pretty well for me. Now if you want the engine to handle all sorts of games then that is totally a different issue on his own, but that does not mean it is not possible.

Share this post


Link to post
Share on other sites
Radikalizm    4807
[quote name='BornToCode' timestamp='1345487638' post='4971567']
I have to disagree with Phantom. If you have written a game before, you should be able to have some form of an idea on how you want the engine to be structured depending on the type of game you want to target. I have done exactly that and it work out pretty well for me. Now if you want the engine to handle all sorts of games then that is totally a different issue on his own, but that does not mean it is not possible.
[/quote]

Well yes, if you've already made a decent game you'll be able to distill some components which could function as a basic engine, but the OP has only a minimum amount of C++ experience and is trying to write an engine from scratch, which is generally seen as a big don't.

@OP:

A decent general-purpose engine will take you years to implement, even if you were an experienced programmer. There are a huge amount of aspects to an engine which should be taken care of properly, I'd advise you to search the forum a bit for engine-related threads to get some more info on what it actually takes to build one.
There are 2 valuable "rules" which are quoted a lot around these forums when it comes to engine development:

1. Make games, not engines
2. If you have to ask how to build an engine, you're not ready to build an engine

Also as a general programming tip: Avoid the singleton pattern. I know it sounds like a very simple and good solution to some problems at first, but when your program grows somewhat it will pose [b]a lot[/b] of very annoying issues. Right now the singleton pattern could still work out for you if you're not writing anything too complex, but it's best not to teach yourself bad programming habits, trust me [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
I already have a game in mind: http://www.youtube.com/watch?v=bBbVqR3Euf4

Also I have written games before, ( re-written actually ). Our school projects were to rewrite an existing game.
The games written then was by using the Game Engine received from a docent.


Thanks everyone for the comments! I'll start out with designing a tiny engine for the game I have in mind, and try to expand it with making other games.
I disagree with:
[quote]"If you have to ask how to build an engine, you're not ready to build an engine" [/quote]
I can write an engine with the experience I have at the moment, but, the framework will be terrible. So I'm asking how to write an efficient engine, a whole other thing than just writing 'an' engine. ( example: the 2 engine's I have received from school [img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img] )
But the comments I've read say I better start out with creating the games first and try to expand the engine from that. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]


Is there somewhere I can post my progress on this site? To get feedback & to help others.

Kind regards,
Jonathan

Share this post


Link to post
Share on other sites
_the_phantom_    11250
[quote name='EngineProgrammer' timestamp='1345489813' post='4971582']
Is there somewhere I can post my progress on this site? To get feedback & to help others.
[/quote]

Start up a journal on here, that'll give a centralised place to track your progress and something you can look back over in the future :)

Share this post


Link to post
Share on other sites
serumas    796
I will suggest to take open sorce engine and start to make game, after some experience yuo could modificate engine to fit your needs closer...

Share this post


Link to post
Share on other sites
BraXi    197
I suggest you to start your work in following order:[list=1]
[*]Simple window with initialized DX renderer
[*]Image loader / Material Manager
[*]Timer
[*]Input
[*]Camera
[*]Model loader / Model Manager
[*]Shader Manager (load & compile hlsl shaders and use then im rendering)
[*]Collision detection/physics, i suggest You to use free physics library, Newton Physics is good and free for commercial products
[*]Entity manager to dynamicaly create and delete objects (for example. guns, medkits, enemies etc), this should be running at constant 30fps so it will be easier to update games over network
[*]User Interface (menus, huds...)
[*]Sound engine, OpenAL should be good enough to give it a try
[*]Particles & effects
[*]Post processing
[*]Networking and prediction
[/list]
This is enough to create a game, rest will depend on what else you need. I'm still creating engine for my game and so far it took me 5 months and im fighting with optimilizations and networking, networking is the worst thing you will have to deal with. Edited by BraXi

Share this post


Link to post
Share on other sites
Thanks guys for the help & motivation !! [img]http://public.gamedev.net//public/style_emoticons/default/happy.png[/img]

[quote]2. Image loader / Material Manager[/quote]
What do you mean? Is it like projecting an image on a Polygon?
And Materials, as in materials in 3DsMax?

[quote]Very much. Motivation is the most important basis you can have. But don't let it fly away. Fix it to something. I wrote myself a novel. What have you done?[/quote]
I have tons of game ideas so my motivation will keep going for quite a while. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Also I am active on concept artist websites which give me motivation to paint, which gives me even more motivation to program and use those own painted textures/sprites/models.
The only disadvantage I have is that I want too much at a time.

Share this post


Link to post
Share on other sites
omercan1993    370
[quote name='EngineProgrammer' timestamp='1345566691' post='4971881']
I have tons of game ideas so my motivation will keep going for quite a while. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Also I am active on concept artist websites which give me motivation to paint, which gives me even more motivation to program and use those own painted textures/sprites/models.
The only disadvantage I have is that I want too much at a time.
[/quote]

To paint is great! I also do that... but my paintings are... hmm.. "okey"... But I can draw very well :D
To have too much idea is normal :D

Share this post


Link to post
Share on other sites
GuyWithBeard    1890
[quote name='BraXi' timestamp='1345554241' post='4971806']
I suggest you to start your work in following order:[list=1]
[*]Simple window with initialized DX renderer
[*]Image loader / Material Manager
[*]Timer
[*]Input
[*]Camera
[*]Model loader / Model Manager
[*]Shader Manager (load & compile hlsl shaders and use then im rendering)
[*]Collision detection/physics, i suggest You to use free physics library, Newton Physics is good and free for commercial products
[*]Entity manager to dynamicaly create and delete objects (for example. guns, medkits, enemies etc), this should be running at constant 30fps so it will be easier to update games over network
[*]User Interface (menus, huds...)
[*]Sound engine, OpenAL should be good enough to give it a try
[*]Particles & effects
[*]Post processing
[*]Networking and prediction
[/list]
[/quote]

This probably does not affect the plans of the OP but still: Networking and prediction last? Yikes!

I'd say work your way through the list but leave all sorts of networking out of your first engine. Then, when you fell like you would like to add networking, start over again (probably using the parts of the first engine that you feel are working well) but plan the engine with networking in mind from day one.

I implemented things like NAT punch through, lobby servers and matchmaking before my engine could even create a window, and it has really payed off. I feel this is the only good way to create a networked game engine. This might be why you feel that "networking is the worst thing you will have to deal with".

That said, you can probably create a fully functional renderer and use it in a networked game engine just fine, as long as the renderer is separeted from the game logic, but only start create the GAME engine systems when you have your network layer figured out.

Just my two cents...

Share this post


Link to post
Share on other sites
darkleemar    111
[quote name='omercan' timestamp='1345561959' post='4971849']
To develop an engine you need at first and only: [b]Motivation[/b]
Without a game in mind which will use the game, you will lost your motivation very fast. Or why do you write it?

I myself started to develop an engine when I was 15 or 16... I had a game in mind... a big multiplayer first person shooter which was located in an open world. So I started... but don't find a good starting point... I really lost my motivation very fast. But this was not the end. After that I started to make an animation film... Again, I failed. Then I started a novel and understand that I really don't want to play or make a game.
I only wanted to tell a story. So I started my novel and continued to write it even today. I also continued my engine and it grew and grew... Today it is not finished, but this time my motivation is to make a game for my novel and to design huge software architectures. I really love design and this is the reason why my engine is alife even after 5 or 4 years.

[i]What does that have to do with engine development?[/i]
Very much. Motivation is the most important basis you can have. But don't let it fly away. Fix it to something. I wrote myself a novel. What have you done?

Also buy books... many books... ten is not enough [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
Like[url="http://www.amazon.com/Game-Engine-Architecture-Jason-Gregory/dp/1568814135"] Game Engine Architecture[/url]. Read all of them. Love them and of course understand them.

When you really only want to make a simple game you should use other available engines. Like Ogre, Irrlicht or maybe Unreal, Unity and if you really love high end, the CryEngine.
You have to invest a lot of time before you get something useful which you can call an engine. You will rewrite it many times. And everytime it will be easier. You will understand more and it will make you more fun. Of course there are also times where the motivation is down. Don't make you mad, you don't need pressure of time. I failed many times and I'm failing even today, but don't lost your motivation.

Maybe I've told a lot, but someday you will understand.

So at the end my suggestion to you:
[b]Do it! Start your game engine development adventure![/b]

Happy coding!

Ömercan
[/quote]
wow you just motivated me to make an account and get better at C++! Thanks!!

Share this post


Link to post
Share on other sites
omercan1993    370
[quote name='darkleemar' timestamp='1345734794' post='4972598']
wow you just motivated me to make an account and get better at C++! Thanks!!
[/quote]
Really? Cool [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] It makes me happy and proud when I could help one person.

[quote name='GuyWithBeard' timestamp='1345725926' post='4972557']This probably does not affect the plans of the OP but still: Networking and prediction last? Yikes!I'd say work your way through the list but leave all sorts of networking out of your first engine. Then, when you fell like you would like to add networking, start over again (probably using the parts of the first engine that you feel are working well) but plan the engine with networking in mind from day one.
I implemented things like NAT punch through, lobby servers and matchmaking before my engine could even create a window, and it has really payed off. I feel this is the only good way to create a networked game engine. This might be why you feel that "networking is the worst thing you will have to deal with".
That said, you can probably create a fully functional renderer and use it in a networked game engine just fine, as long as the renderer is separeted from the game logic, but only start create the GAME engine systems when you have your network layer figured out.
Just my two cents...
[/quote]

I also think that Network shouldn't be the last option. But it is also not the most important part. Design the framework with Network in mind.
You need at first a good object and class system. But please not a huge hierarchy tree. Also one root class like the QObject class in Qt is not really useful in game development (but in GUI developing).
My second suggestion: Don't make the underlying classes too general. You will lost much power and performance and in the end you will get spaghetti code because everything is done with the preprocessor and the template system.
To make a sophisticated design, I recommend UML tools.

Regards
Ömercan

PS: And on my mind don't use something like a signal slot system and over think the use of callbacks. But this all is up to you.

Share this post


Link to post
Share on other sites
Honestly, I Am following that given list. [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

Video of what I have written so far: [media]http://www.youtube.com/watch?v=WasDe6NUEso&feature=youtu.be[/media]

Now I'm implementing the converter into my program to win more development time.

I also have written a camera and system class so far. So I can check all input of the keyboard and mouse and change my camera with the input.

[b]Edit:[/b]
Hmmm strange, my video is shaking and I have no idea why.. Recorded it with CamStudio. Edited by EngineProgrammer

Share this post


Link to post
Share on other sites
caldiar    715
I might have missed this but, why do you want to make a game engine? What is your goal? Is this purely for education to help you learn programming as it's related to videogame development or is this to build an engine to use for a game you want to make?

There are plenty of existing solutions out there for game engines. If this is an educational experience I would say you would be better served downloading the source code to an existing game engine (idtech4's source was released recently) and modifying a piece at a time. You will see more immediate results and get a look at how things are typically done (with the idtech4 suggestion this applys to the way id software writes FPS games).

Writing an engine first with the intention of using it to build a game will only limit what you can do in the game later on. Perhaps you didn't forsee a certain condition in your game that your engine wasn't designed to handle. Changing that could mean a major refactor. Alternatively, if you focused on just building a game first, an engine will naturally develop as a consequence of developing games repeatedly and identifying chunks of code that you use over and over again which you can set aside and bundle into what would be your engine (a big hunk of reusable code).

Also be careful when trying to become familiar with a ton of different areas of programming at once. Don't mistake the notion of being familiar with a concept and actually truely knowing a concept. When I was first starting out I would focus on a ton of different concepts only to declare that I "know" an area of programming and can move on to the next. This was not the case. I had a shaky understanding of what is kind of going on. What I'm trying to say here is that you should pick an area that's interesting to you first to focus on. Put your time and energy into one area whether it be physics simulations, artificial intelligence, shader programming, particle systems, whatever. Keep building your programs around that specific subject and keep working on that until you truely know it. Simply glossing over the details will only be doing wrong by yourself. Don't cheat yourself out of properly learning the ideas.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this