Game Engine Programming

Started by
36 comments, last by Spartan322 10 years, 5 months ago

As I said, I would put some code down. Here you go:
...
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.
I'd suggest using constructors/destructors and not using the singleton anti-pattern:int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow )
{
T_Engine engine;
T_Window window( hInstance, nCmdShow );
T_System system( engine, window );

StarBattle starBattle(engine, window, system);

// Run the Message loop
MSG msg = {};
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/engine.GetFramerate();
starBattle.GameUpdate();
starBattle.GameRender();
}
else
{
Sleep(1);
}
}
}

return TRUE;
}

Should release in the reverse order of allocation
This is good advice, and N.B. this happens automatically in the above re-write, when not over-engineering things wink.png
Advertisement
I've read the article of .obj completely! Yet, not a single sentence says how to link the smoothing groups with the faces.
But I've asked my docent at school and he told me a way to do it. So should work now.. When I've written the code. biggrin.png

About the singleton, yes I've already changed my framework for that. smile.png

So last thing I want to say is kinda off-topic.
I'm starting a journal so you guys can watch my progress! smile.png
Feel free to follow my blog.

http://www.gamedev.net/blog/1543/entry-2255042-creotex-engine-introduction/
I'll post Part 1 with some code this night. First I want to be sure everything runs smoothly so I don't show you bad code. wink.png
A tip when building your game engine, make sure you break your development down into small manageable chunks with clear goals at each stage. It is very easy to become unmotivated if you can't see progress from one day to the next. When I was making my engine I always started by defining a game that I wanted to make first. Then as I build the game, I would break things down into small pieces of reusable code that I would put into my engine for reuse on the next game that I was going to make. After creating 5 or more games, you start to see some structure in the engine.
Thanks, yes normally a better plan is just to write games and collect all the reusable code.

But for every game I need graphics, models, shaders, sounds, etc. So I can directly put all of those into my engine so I don't need to worry about them anymore later on.
But I'm putting all those piece of codes in small classes to have a nice overview of my engine. I love clean code. biggrin.png

My motivation breaks down sometime because I want to rewrite the whole framework when it's "bad". This is my 5th try to get a nice framework and it's already looking good so I think I have a good structure now. smile.png But then, when I have rewritten the framework I can continue even faster than the last framework so then I get motivated again. smile.png
Ah I have a question:

Everyone remembers this line of code?
static LRESULT CALLBACK WndProc(...)

When you got this method:
LRESULT CALLBACK Class::HandleEvents(...)
What did you do to be able of calling that method?

There are some possibilities.
- Using singleton design
- Using a global pointer
- Creating the pointer using WM_CREATE and then make calls when the pointer exists.

That's all what I can think of at the moment.
I've found something ,even better, you don't need anything of the three above!!

static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return ((Window*)GetWindow(hWnd, 0))->HandleEvents(hWnd, msg, wParam, lParam);
}

Now the strange part comes up.
This pointer that is returned is always nullptr. Never it will be allocated or initialized with an existing pointer. But.. The is not a single crash, he can call every method inside that class.


But does someone knows the disadvantage of this code? Because in all those years of programming I can't be the first one who noticed this? Is this an "unstable" line of code?


~EngineProgrammer

This is a good idea to read as it can be easy to write 2d engine if you want to waste about a year to make it good but you don't need to waste the reiventing the wheel just use previous libraries to shorten time, strain, and many other annoying stuff than you can design the game but for directx you may need some different libraries and for 3d you may need to search for 3d graphic and physic library

Seriously it's acutally not hard and can be short if you know what to do but if you are building a new unity or trying to build something with a UI than waste 2 years at least if you are new so I suggest the explaination

Dude this thread was over a year old...

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

When I was searching for game engine creation tutorials I was looking for how should I build it but unfortunately I could never find any thing I was looking for so what I'm trying to do is add to the internet as much information to the public as possible so people have an easier time finding it because seriously there seems to be a giant gap between people who know how to build game engines and people who don't like there isn't anyone who is learning how to by doing of which I am so now I will do my best to make a new class of people to learn how to build game engines as most people who try seem to only know bits and pieces until they finish but they don't think the same as before or anywhere near that before time so it is harder for people that want to learn to get clear information. I'm sorry if this was overexplained.

And if you ask have you been here before, yes it seems that you are always forced to the older stuff first than newer stuff comes up

What does one year matter if you get information to people who need it as this was one of the five game engine disscussions that came up of which barely helped

This topic is closed to new replies.

Advertisement