Simulation Considerations

The kind of simulation game that I mean is the kind where you have things that you can build in different places, and workers / carriers that connect such places.

Something more like the Settlers series.

Suppose I do not want graphics at the moment , that I think I can handle.

So my doubts are as follows:

  • Should each object be a class, and each of them has a stream?
  • If objects are grouped into lists inside classes, and each of them has a stream?

If we take implementation 1, it will be very difficult to work on low-specialized machines and will not scale well for large numbers.

If we take implementation 2, it will be better in terms of resources, but then ...

How do I group objects?

  • Do you have a home class in general and have a list of interfaces for managing this?
  • Do you have a class for certain house groups and a list of objects to manage this?

what about threads?

  • Should I have a simplified main game loop?
  • Should I have a thread for each class group?
  • How do workers / conveyors fit the image?
+4
source share
6 answers

The usual approach does not use streaming at all, but rather implements objects as state machines. Then your mainloop looks like this:

while( 1 ) { foreach( entity in entlist ) { entity->update(); } render(); } 
+14
source

MMORPG Eve Online uses contactless python and an actor model to emulate a thread system for an entity without using a resource.

Check out this link for more information: http://harkal.sylphis3d.com/2005/08/10/multithreaded-game-scripting-with-stackless-python/

+4
source

I'm sure you want one thread to execute the game logic. Having multiple threads will not speed things up, and will only make the code confusing. The presence of the main game cycle is excellent, although the game is much more complicated than in the game.

I am a bit confused about the part of your question related to classes. If I understood your question correctly, my suggestion would be to have a class for each type of house (pig farm, windmill, etc.), based on the general abstract base class House . Then you save all the houses in the game world in the list of houses.

+2
source

Consider using Erlang. With Erlang you can create many processes (= light threads) than a regular system thread. Further its distribution, that is, if your system is not good enough, add one more node.

Another alternative might be unstable python (or the current python alternative), as it also supports some kind of light weight, which is very cool for game engines. Eve Online uses it for its servers. But it does not spread, but it can be easily done manually.

+1
source

While @Mike F's answer is mostly correct, you should keep in mind that iterating over objects in the foreach makes the evaluation process significantly deterministic, which has undesirable side effects. On the other hand, the introduction of flows opens up the potential for heisenbugs and concurrency problems, so the best way I have seen and used is based on combining two cycles: the first collects the actions of agents / workers based on the previous state, the second cycle compiles the results of the actions and updates the simulation state . To avoid possible bias, the evaluation order is randomized in each cycle. This BTW is scaled up to massive parallel estimation taking into account synchronization at the end of each cycle.

+1
source

I would not create a separate class for each object, because then you will have situations when you either repeat the code for common features, or you have a funky inheritance tree.

I would say that you only need one class and objects with the functionality compiled on it. I saw a blog article about this very concept in RTS ... wait, I think it was a tour of design patterns that someone wrote .

Use the Visitor template that creates a stream for each DoEvents object (due to the lack of a better word) so that each object can do what it is going to do during this cycle. Synchronize threads at the end of the loop because you do not want some objects with complex logic to still do their thing ten loops back when it was actually destroyed five loops back.

0
source

Source: https://habr.com/ru/post/1277383/


All Articles