Skip to main content
gamedev.net
🔒 Locked

Game engine design

Started by DividedByZero Mar 25, 2009 at 4:47 PM 0 replies 800+ views
Original Post
DividedByZero
DividedByZero
Hi there, I am in the process of making a basic graphics and sound engine (in DirectX) that I can use as the basis for a game I want to program. I am wondering what the best way is of designing my code to keep things simple, clean, and easy to use. Is it best to keep it all in a big class and instance things when needed? At the moment I have put the window and DX initialisation code into its own .h & .cpp files and have a camera class and have a pre-requisite file that includes these files, libs, and other required stuff. So, currently I can initialise a render window and setup a camera by doing the following

#include "Engine.h"

int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nCmdShow)
{
	initGraphics(hInstance);

	// Create Camera
	Camera *mCamera1=new Camera();
	mCamera1->CameraPosition(30,50,-50);
	mCamera1->CameraTarget(0,0,0);

The only thing wrapped up in a class at the moment is the camera system. Should everything be in a class or do you think I am on the right track? Any opinions on design approach would be greatly appreciated.
dmatter
dmatter
Quote:
Original post by lonewolff
The only thing wrapped up in a class at the moment is the camera system.
Should everything be in a class or do you think I am on the right track?
C++ is a multi-paradigm language so it's expected that any sizable program would have a mixture of classes and non-classes. Decided on when to use plain functions and when to use a class is part of what determines the skill of a programmer; it's a design decision pure and simple.

What you have there looks fine to me, if that's all you need to satisfy your requirements; in the future your requirements might change so your design might need to change. For example, calling initGraphics(hInstance) isn't enough for your engine to determine what resolution the user wants, what title they want to give to the window, which and how many monitors they want to span, etc. If the user doesn't require this then a simple function is perfect, if they do require this then you might find that you want a class to model a monitor, a class to hold video settings, a class to represent a window, and so on.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.