Game engine development

I am going to recreate the game engine that I created some time ago. This time I want to do it right, so I did some research in the field of design and tried to collect fragments to achieve my goal. The idea of ​​the game engine is simplicity, but at the same time I don’t want to sacrifice usability.

Here is a plan of what I think, let me know if you can see any drops, especially in extensibility:

class Object { public: string name; } class Object3D : public Object { public: int x; int y; int z; } class Object2D : public Object { public: int x; int y; } class cube : public Object3D { cube() : x(0), y(0), z(0), name("cube") {} } class square { ... } int main() { SGL Engine(paramters); c = cube(); s = square(); Engine->Lib3D->AddCube(&c, "cube"); Engine->Lib2D->AddSquare(&s, "square"); Engine->Input->keyboard(&kbevent); while(Engine->running()) { if (x) Engine->Draw("cube"); else Engine->Draw("square"); } } void kbevent(event-paramteres) { if (key.up) engineptr->objects["cube"]->move(x,y); } 

The final language is C ++.

-2
source share
4 answers

Read this first.

The only way to do this “right” is to turn the process upside down. Create an engine after you use it in the game.

Secondly. C ++ is not Java. C ++ does not have the base class Object , and it is not needed either. Do not try to fit everything into an inheritance hierarchy. If each object is polymorphic, you swear (everything should be selected in the form of a heap and passed by reference or pointer, for example, to avoid slicing, and does not even make the code more understandable)

The object in the world has a position . He is not alone . Therefore, do not inherit the x, y, z coordinates. Put them in a coordinate class that can be added as a member in the classes that need it.

Finding strings is slow, and you need to handle the case where strings are not unique. (What if I accidentally add two objects named "cube".

Why not rely on simple links or pointers as much as possible?

Why can't I just do Engine->Draw(c) to make the engine draw a cube?

But in fact, the most important tip is not to try to write a shrink game engine for later use. You will end up in exactly where you are now: you need to "rewrite it, and this time do it right." If you want to get something from this that works, you need to start with its use case. First write a game. When you do this, you can start refactoring the code to separate it. Thus, you get an engine that works.

+6
source

If you do not use hash mapping, string search is slow. In addition, once you have added objects to the engine, you can do something like:

 Engine->Draw(); 

What will go through all the objects added to the engine and draw them.

An object must have a virtual Draw function, and Object2d and Object3d must override this function. Then the Engine will simply skip all the objects and draw them.

Another thing is that you do not need the add function for different types. You should be able to do something like:

 Engine->AddObject(&c); Engine->AddObject(&s); 

And it turns out what to do with it. Now that you have it, you require the user to know what he wants to do, while he should be encapsulated so that you do not need it, but open enough so that it does not interfere with you if you want to do what something that is not supported by the engine, you can, so I would keep the leaders of Lib2d and Lib3d, although purists would say that the encapsulation was broken.

+2
source
  • I am sure you should use float instead of ints for the coordinates of the object. With floats, you can run the game at any frame rate. There will be problems with ints.
  • Ideally, class names should start with capital letters ( class Cube ) unless you use prefixes to indicate types ( class CCube ).
  • (most important) Before you create a hierarchy of objects, you need to know what exactly you want to create. Imagine the level of the game, think about what objects are present, classify them, and then try to create a hierarchy. You don't need to create a class for everything (and maybe you don’t even need a complex hierarchy, maybe you can write the whole thing without using inheritance), but you should be able to present the final product while writing the code. Do not introduce new concepts if you do not need them. Right, it looks like you have no idea what you want to do, and now there are several classes that may be completely unsuitable for the final product.
+2
source

First of all, try not to fit the design pattern into the problem. Read http://realtimecollisiondetection.net/blog/?p=44 and http://realtimecollisiondetection.net/blog/?p=81 regarding this kind of solutions.

Secondly, it is important that you look at what games you will make when writing the engine. Therefore, it is extremely important to tell what data you will process and how.

Thirdly, when it comes to developing a game engine, I would recommend reading the Bitsquid blog http://bitsquid.blogspot.com/ , which is currently writing some interesting topics regarding their new engine. I would also recommend watching / reading as much as possible from Mike Acton, who is the lead architecture at Insomniac Games. He often recommends first looking at the data and developing his own engine around what kind of data he will process. This is: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-multicore-programming-primer-january-iap-2007/lecture-notes-and-video/embed17/ - An interesting ground base walkthrough that Mike Acton makes regarding the development of his engine.

Link to Mike Acton's general blog http://www.insomniacgames.com/blogcast/blog/mike_acton . I also suggest reading a lot of my topics, as they are very good and interesting.

As for your code, I see no reason why you need your inheritance structure. Why is Cube a 3D object? Why does Cube inherit anything at all? A cube or box is just 3 floats that define extents (or half extents). I would suggest that you have an object that then uses the HAS-A relation to cubes or squares or squares. Insomniac has several topics about component-based game objects. I suggest you read: http://www.insomniacgames.com/assets/filesadynamiccomponentarchitectureforhighperformancegameplay.pdf (I think the link is correct).

Three big software development challenges: http://www.insomniacgames.com/blogcast/blog/all_categories/1500756

0
source

All Articles