Jump to content

  • Log In with Google      Sign In   
  • Create Account


Game Engine Programming


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
37 replies to this topic

#1 EngineProgrammer   Members   -  Reputation: 295

Like
0Likes
Like

Posted 19 August 2012 - 08:28 PM

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? Posted Image

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

Sponsor:

#2 EngineProgrammer   Members   -  Reputation: 295

Like
0Likes
Like

Posted 19 August 2012 - 08:41 PM

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.

Edited by EngineProgrammer, 19 August 2012 - 08:42 PM.


#3 saejox   Members   -  Reputation: 714

Like
5Likes
Like

Posted 19 August 2012 - 08:49 PM

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? Posted Image


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.

#4 Lucca   Members   -  Reputation: 101

Like
0Likes
Like

Posted 19 August 2012 - 09:14 PM

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.

#5 EngineProgrammer   Members   -  Reputation: 295

Like
0Likes
Like

Posted 19 August 2012 - 09:38 PM

2 years, damn Posted Image 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. Posted Image

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. Posted Image


Lucca, good luck with your game! Do you have some graphic stuff to show? Posted Image

#6 krippy2k8   Members   -  Reputation: 642

Like
0Likes
Like

Posted 19 August 2012 - 10:31 PM

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

Edited by krippy2k8, 19 August 2012 - 10:40 PM.


#7 AticAtac   Members   -  Reputation: 309

Like
4Likes
Like

Posted 20 August 2012 - 07:28 AM

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, 20 August 2012 - 07:29 AM.


#8 nife87   Members   -  Reputation: 516

Like
0Likes
Like

Posted 20 August 2012 - 09:42 AM

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?


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, 20 August 2012 - 09:43 AM.


#9 french_hustler   Members   -  Reputation: 339

Like
2Likes
Like

Posted 20 August 2012 - 10:07 AM

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, 20 August 2012 - 10:08 AM.


#10 phantom   Moderators   -  Reputation: 6710

Like
14Likes
Like

Posted 20 August 2012 - 10:50 AM

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.

#11 BornToCode   Members   -  Reputation: 892

Like
-5Likes
Like

Posted 20 August 2012 - 12:33 PM

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.

#12 Radikalizm   Crossbones+   -  Reputation: 2766

Like
0Likes
Like

Posted 20 August 2012 - 12:56 PM

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.


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 a lot 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 Posted Image

#13 EngineProgrammer   Members   -  Reputation: 295

Like
0Likes
Like

Posted 20 August 2012 - 01:10 PM

I already have a game in mind:

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:

"If you have to ask how to build an engine, you're not ready to build an engine"

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 Posted Image )
But the comments I've read say I better start out with creating the games first and try to expand the engine from that. Posted Image


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

Kind regards,
Jonathan

#14 phantom   Moderators   -  Reputation: 6710

Like
0Likes
Like

Posted 20 August 2012 - 01:23 PM

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


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 :)

#15 serumas   Members   -  Reputation: 708

Like
0Likes
Like

Posted 21 August 2012 - 06:14 AM

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

#16 BraXi   Members   -  Reputation: 187

Like
2Likes
Like

Posted 21 August 2012 - 07:04 AM

I suggest you to start your work in following order:
  • 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
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, 21 August 2012 - 07:05 AM.


#17 omercan   Members   -  Reputation: 370

Like
5Likes
Like

Posted 21 August 2012 - 09:12 AM

To develop an engine you need at first and only: Motivation
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.

What does that have to do with engine development?
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 Posted Image
Like Game Engine Architecture. 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:
Do it! Start your game engine development adventure!

Happy coding!

Ömercan
Reading, Reading, Reading... why do you read not more?
I have a blog: omercan1993.wordpress.com look there for more content :)
And I also do some art: omercan1993.deviantart.com
And whats about the Pear3DEngine? Never heard of it? Go and look!
Yeah, and currently I do this: SimuWorld

PS: Please look at this poll on my blog about scripting languages: A opinion poll about scripting language

#18 EngineProgrammer   Members   -  Reputation: 295

Like
2Likes
Like

Posted 21 August 2012 - 10:31 AM

Thanks guys for the help & motivation !! Posted Image

2. Image loader / Material Manager

What do you mean? Is it like projecting an image on a Polygon?
And Materials, as in materials in 3DsMax?

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?

I have tons of game ideas so my motivation will keep going for quite a while. Posted Image 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.

#19 omercan   Members   -  Reputation: 370

Like
0Likes
Like

Posted 21 August 2012 - 10:36 AM

I have tons of game ideas so my motivation will keep going for quite a while. Posted Image 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.


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
Reading, Reading, Reading... why do you read not more?
I have a blog: omercan1993.wordpress.com look there for more content :)
And I also do some art: omercan1993.deviantart.com
And whats about the Pear3DEngine? Never heard of it? Go and look!
Yeah, and currently I do this: SimuWorld

PS: Please look at this poll on my blog about scripting languages: A opinion poll about scripting language

#20 GuyWithBeard   Members   -  Reputation: 764

Like
0Likes
Like

Posted 23 August 2012 - 06:45 AM

I suggest you to start your work in following order:

  • 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


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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS