C ++ - instance of a single local class for the entire duration of the program

I am working on the lil 'engine in C ++ and decided to do all this OOPily (heavy use of classes). It should be (theoretically) cross-platform, so I have a class "Engine", an instance of which is created by the "OS module", which is WinMain for Windows (the platform for which I am developing it for the first).

I have three main questions:

  • Is it considered bad practice to create a class that will be created only once in the entire application? Perhaps because there is some kind of performance hit or added overhead associated with using the class rather than a bunch of functions?

  • I planned that WinMain would create an instance of Engine as a local variable. The Engine class will be quite large, containing classes for rendering, a parsing script, a file system, etc. In principle, the entire game engine, in addition to OS-specific code, will be contained in the Engine class in some form (possibly as an instance of another class.) Does the local instance of my very large Engine class in the WinMain function have a bad idea? Does the local instance create a bad idea when the class will be created when the program starts and ends when the program ends? Maybe a new one would be better?

  • My plan (i / wa) s is to divide the engine into "modules", each of which is represented by a class. The Engine class will contain an instance of almost all other modules, for example, as mentioned above, rendering, file system interaction, etc. Is using classes as containers for huge modules bad ideas from a certain point of view (performance, readability?)

Thanks for any help :)

+5
source share
4 answers

Game engines are not the first candidates for cross-platform, as they are usually associated with efficient interaction with low-level APIs (which are not cross-platform).

-, .

(http://msdn.microsoft.com/en-us/library/ms686774%28v=vs.85%29.aspx), . , - , ( ).

"": . , , , -... , , - .

: 1. , , . 2. . "" " " . 3. , , , , / "". , :)

+4

, ? , , - , ?

. , , . .

WinMain Engine . , , script , .. , , , (, class.) WinMain - ? , , ? , ?

- , . ? . , , RAII , . , sizeof(), .

(i/wa) s "", . , , , , .. (, , ?)

, - , , , , - - . , , , . .

, , ( ). .

+2
  • , , .
  • , , (.. new, )
  • . # 1
+1
  • , . , , Singleton ( , )

  • , . , . , ( , , 99 100 , STL, )

  • What difference does it make if you put them in a data segment, like an auto on the stack or members of a class? I think that the class emphesizes modularity and can allow you to do something more easily (for example, unit testing or reusing the engine for the network version, etc.).

+1
source

All Articles