Jump to content

  • Log In with Google      Sign In   
  • Create Account


Game Engine *D Design


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
11 replies to this topic

#1 Xarles   Members   -  Reputation: 100

Like
0Likes
Like

Posted 12 March 2012 - 03:25 PM

I am currently working on my own Game Engine. I plan on making both 2D and 3D games (though as time goes on I think I will end up focusing more on 3D). What would be the best way to implement this?

Two separate engines: one 2D and the other 3D
or
One engine that can handle both

I am afraid of over-generalizing the engine and making it worse by trying to cram them both into one engine.
On the other hand, it would be a real duplication of effort. Worst of all, wasted if I abandon one or the other

But I am leaning toward the latter anyway. I think it would be easier to develop and to switch from one to the other. And a 3D engine needs 2D anyway for HUDs and stuff, so I'm not sure if a separate engine for it would even make sense.

What are your opinions on this?

Sponsor:

#2 Corefanatic   Members   -  Reputation: 129

Like
1Likes
Like

Posted 12 March 2012 - 06:06 PM

A 3D engine can handle both 2D and 3D without any problem. As you said, you will be drawing in 2D for your hud etc., so there isn't much of a problem with rendering.

However, engines are much more than rendering, and making a universal engine is no easy feat, especially when you are making your first. I recommend having a game in mind and create an engine for that. Then iterate or write a new engine.

#3 bollµ   Members   -  Reputation: 354

Like
1Likes
Like

Posted 12 March 2012 - 11:14 PM

I'm assuming you're using an object oriented programming language, such as C++ or Java. I have almost no idea how C# works, so I might be a little amiss here.

I'd say start with what you *need*, and then expand to what you want. Once you get the most basic classes up (states, renderers, physics classes), the sky's your limit. So I'd suggest begin by drawing a cube / a basic textured sprite, getting the core engine up and running, and then adding whatever you want :)

To answer your question, Build it as a 3d engine, because 2d is just 3d without the z-axis. I'd suggest keeping the base classes that do the rendering as abstract classes so that you can switch between 2d and 3d renderers easily.

At the risk of sounding cliched- "build games, not engines" (please don't flame me for bringing it up). It certainly is a valid point, and I'd say just build the engine as you go along. make mistakes. redesign the whole system. Refactor it again with comments and/or cool looking templates that don't serve a function ;) And also, most importantly, have fun while doing it.

Cheers!

a WIP 2d game engine: https://code.google.com/p/modulusengine/

English is not my first language, so do feel free to correct me :)


#4 Xarles   Members   -  Reputation: 100

Like
0Likes
Like

Posted 13 March 2012 - 01:13 PM


To answer your question, Build it as a 3d engine, because 2d is just 3d without the z-axis. I'd suggest keeping the base classes that do the rendering as abstract classes so that you can switch between 2d and 3d renderers easily.




A 3D engine can handle both 2D and 3D without any problem. As you said, you will be drawing in 2D for your hud etc., so there isn't much of a problem with rendering.


That's a relief.


I'm assuming you're using an object oriented programming language, such as C++ or Java. I have almost no idea how C# works, so I might be a little amiss here.


The topic title says "[C++]" Posted Image


However, engines are much more than rendering, and making a universal engine is no easy feat, especially when you are making your first. I recommend having a game in mind and create an engine for that. Then iterate or write a new engine.




I'd say start with what you *need*, and then expand to what you want. Once you get the most basic classes up (states, renderers, physics classes), the sky's your limit. So I'd suggest begin by drawing a cube / a basic textured sprite, getting the core engine up and running, and then adding whatever you want Posted Image

...

At the risk of sounding cliched- "build games, not engines" (please don't flame me for bringing it up). It certainly is a valid point, and I'd say just build the engine as you go along. make mistakes. redesign the whole system. Refactor it again with comments and/or cool looking templates that don't serve a function ;) And also, most importantly, have fun while doing it.

Cheers!



I totally agree with both of you.

At the moment I am just getting back into game programming (took about a year off writing websites, it was a shock to me that C++ doesn't have echo! Posted Image ) I did have an engine that could use DX9 or DX11 or SDL+OGL.* But I think I will abandon this and just pick one and focus on that. I think it would be better to have a decent engine using only, say, DX11 (which I could later port to other APIs anyway) compared to a useless engine able to run on everything. Right?

I am trying to build for games, as you both suggested. An engine by itself is unsatisfying, so to be productive I am planning on building the engine up "naturally" in steps:
2D Simple Platformer
3D SImple Platformer (2.5D maybe)
3D Slightly More Complex Platformer
Final 3D Platformer Game

(I don't know why platformer, guess I was feeling nostalgic. I do intend to work on a wider variety of genres, but I feel it would be detrimental to jump between them now.)

I don't even have an artist or an engine yet so to aim for the final thing is a bit unrealistic. Even if somehow I managed to keep interested (I wouldn't) the final product would probably be poor and full of hacks. So this way I just focus more on the features and slowly build up. If the games end up playable great, if not I still learned and gained something from it anyway. (I am going to try to make them at least complete, I haven't finished anything yet so that would also be some good experience for me I think.)

What do you guys think? Does it sound practical?

#5 Xarles   Members   -  Reputation: 100

Like
0Likes
Like

Posted 13 March 2012 - 01:22 PM

*By the way, while this thread is still fresh and relavant, if you don't mind

I'm trying to visualize how a multiAPI engine would work, or even how to build a "perfect" engine. There are so many possibilities.

Last time I tried creating three folders, one for each, and modding the classes to use the different APIs while trying to keep the function calls as similar as possible. That way It to change APIs all that is needed is to change the directory, libs and dlls. No code is actually changed because all three have a main engine class that is used the exactly the same way.

Next time I plan on build off of that. I'm looking at it like this: API->Graphics->Engine->Game. The directory would be organized like this:
Engine
DirectX9
DirectX11
OpenGL
Then in the "Engine" dir, could be placed Engine and possible Graphics as they should be exactly the same. The API class and some others would go in the folders. (this way I don't need to have three (or more) copies of Engine.h/.cpp that I need to keep updating. ( I would go nuts! )

What do you guys think? Is that a good plan? Am I (under/over)thinking it?

#6 swiftcoder   Senior Moderators   -  Reputation: 9883

Like
3Likes
Like

Posted 13 March 2012 - 02:34 PM

or even how to build a "perfect" engine.


No such thing as perfect. Only 'sufficient', and 'insufficient' - both of which depend entirely on the needs of the particular game you are creating.

Last time I tried creating three folders, one for each, and modding the classes to use the different APIs while trying to keep the function calls as similar as possible. That way It to change APIs all that is needed is to change the directory, libs and dlls. No code is actually changed because all three have a main engine class that is used the exactly the same way.


Gah. No. Abstraction is your friend.

What concepts do DX9, DX11 and OpenGL all have in common?
  • triangle meshes are stored in vertex buffers
  • VertexLayout/VAO maps vertex buffers to triangle data
  • textures
  • shaders
  • vertex buffer + vertex layout + textures + shader + (optional) index buffer = a draw operation
  • more...
If you look at just the similarities listed above, you can define a set of base-classes that will cover 95% of common rendering tasks (and there are many more similarities). The implement concrete subclasses for each rendering API, and presto, multi-API support.

You can use factory methods to choose which API at runtime, or preprocessor defines to choose at compile time.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#7 Xarles   Members   -  Reputation: 100

Like
0Likes
Like

Posted 16 March 2012 - 03:20 PM

You can use factory methods to choose which API at runtime, or preprocessor defines to choose at compile time.

Why "or"? The preprocessor defines means it can compile on Linux by ignoring the DX/Win32 stuff, the factory methods mean that Windows users can choose at anytime between the three. I'm just wondering if you think that it might be a bad idea somehow.

EDIT: If I don't hide the DX11 code stuff when I compile for Windows, then it won't run for XP users right?

The other problem is that it wouldn't be just rendering, Windows, sound and input are all using different APIs. Right now for Window creation I am using Win32/SFML, do you think I should just use SDL?

Also do you think it would be worth the effort (is it a good idea) to put the rendering code into a separate DLL?

EDIT: I have been trying to get it to work. So far it's been working but I have come across a problem:

Window *win = new W32Window(); or Window *win = new SFMLWindow();
That's how it works so far. But when I tried to get the DX11 rendering class to work I found a fault in the design. DX needs a window handle. So I thought I would just make a function to return the handle and pass it to the DX class:
HWND W32Window::getWindowHandle()
{
return hWnd;
}
But the current setup doesn't allow it. Because I am using /Window *win/ instead of /W32Window *win/ I can't use any classes not defined in the base class. But I don't want the base class to have this function because Linux/Mac/anything not Windows, wouldn't know what to do with the type HWND.I could use preprocessor definitions to hide it when compiling for Linux, but won't it start looking ugly when they are all over the place? I could just use W32/SFMLWindow and just manually change between them, but then it's impossible to change at runtime. What should I do?

#8 Xarles   Members   -  Reputation: 100

Like
0Likes
Like

Posted 20 March 2012 - 09:38 AM

bump?

#9 swiftcoder   Senior Moderators   -  Reputation: 9883

Like
0Likes
Like

Posted 20 March 2012 - 10:32 AM

You can use factory methods to choose which API at runtime, or preprocessor defines to choose at compile time.

Why "or"? The preprocessor defines means it can compile on Linux by ignoring the DX/Win32 stuff, the factory methods mean that Windows users can choose at anytime between the three.

I meant 'and/or'. Even if you do it all at compile time, the factories still keep the design cleaner.

The other problem is that it wouldn't be just rendering, Windows, sound and input are all using different APIs. Right now for Window creation I am using Win32/SFML, do you think I should just use SDL?

SFML should handle pretty much all of that for you.

Also do you think it would be worth the effort (is it a good idea) to put the rendering code into a separate DLL?

Not worth the effort, IMHO. Programming across DLLs comes with a whole slew of pitfalls, and you don't really want to have to test multiple backends for each shipping executable... Just compile in the backends you need.

But I don't want the base class to have this function because Linux/Mac/anything not Windows, wouldn't know what to do with the type HWND.

Just make it return a void pointer, and cast as needed on each platform (HWND* on Windows, NSWindow* on Mac, ...)

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#10 Xarles   Members   -  Reputation: 100

Like
0Likes
Like

Posted 26 March 2012 - 09:56 AM

The other problem is that it wouldn't be just rendering, Windows, sound and input are all using different APIs. Right now for Window creation I am using Win32/SFML, do you think I should just use SDL?

SFML should handle pretty much all of that for you.


Yea but it seems like it would be cheating to not use Win32 to handle DirectX. It wouldn't seem as natural I guess.

I think that's it. I finally understand it and I did get it working. So, thank you for your help.

#11 mdwh   Members   -  Reputation: 863

Like
0Likes
Like

Posted 27 March 2012 - 09:58 AM

I don't see it as cheating :) I'm happily using SDL at least with D3D9. Means the windowing/input/sound/etc is all nice and simple, and works also with OpenGL, and on other platforms.
http://erebusrpg.sourceforge.net/ - Erebus, Open Source RPG for Windows/Linux/Android
http://homepage.ntlworld.com/mark.harman/conquests.html - Conquests, Open Source Civ-like Game for Windows/Linux

#12 swiftcoder   Senior Moderators   -  Reputation: 9883

Like
0Likes
Like

Posted 27 March 2012 - 10:14 AM

Yea but it seems like it would be cheating to not use Win32 to handle DirectX. It wouldn't seem as natural I guess.

There are infinitely many ways to do something, and some are easier/quicker/less effort than others.

The guy who makes extra work for himself so as 'not to cheat', is at best seriously misguided.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]





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