Game Engine Programming

Started by
36 comments, last by Spartan322 10 years, 5 months ago
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? biggrin.png

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
Advertisement
As I said, I would put some code down. Here you go:


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;
}


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.


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? biggrin.png



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.

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.


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.
2 years, damn sad.png 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. smile.png

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. unsure.png


Lucca, good luck with your game! Do you have some graphic stuff to show? happy.png
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 don't get done
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.
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).
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.

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


Yes; don't write an engine.

Write a game, extract parts from it, reuse those parts in another game and repeat. In time the reusable parts will form an 'engine' as you become more experianced.

Attempting to sit down and write an engine without a game to focus it will result in unusable junk which you will just end up re-writing as soon as you want to use it in any real sense. Lack of experiance making games will just make this problem even worse.

EVERY good game engine out there has grown out of being used in a game (or series of games) first and then recycled. This is the only way to ensure you get something usable.

This topic is closed to new replies.

Advertisement