开发者

How to organize a game engine

I'm working on a small game engine and I've encountered a problem.

So far, I have a window class that is a wrapper for a Win32 window. I also have a Window Manager class (it's a singleton class) that manages the creation of windows and the handling of windows messages. I then have an engine class, which is so far the most important class, as it is the interface for the engine. This engine class contains the main loop, and the direct3d device, as well as the code to create and destroy it. This engine class also contains a Window class object, which acts as the main/host window开发者_如何学编程 for the direct3d device.

My problem is that the engine needs to react to some of the windows messages (such as WM_SIZE or WM_ACTIVATEAPP), but the message handler is part of the Widnow class, which is a "level" below the Engine class. I also think that I should create another class to encapsulate the rendering/graphics of the engine, and then add that class to the main engine class.

So I'm not sure whether I should have a Graphics class inside a Window class, or a Window class inside a Graphics class, or have them side by side in a main Engine class.


You're living in an event-driven world, so use events. Have your window wrapper provide events that the game engine can hook and react to.


Do not make the object that controls how your game engine interacts with the underlying operating system a child of the engine object. The OS layer should drive the engine, not vice versa.

(Most engines and programmers get this wrong, incidentally.)


Will you ever have multiple Windows? Increasingly, multi-monitor is getting more use for a variety of games.

Will you ever run multiple Graphics on one Window? Pretty unlikely. That suggests to me that Window should be in Graphics, not the other way around.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜