Skip to content

Model-View Coding and Multithreading #44

@fabianschuiki

Description

@fabianschuiki

I think it desirable to completely separate the game logic and state from the actual rendering. We may accomplish this through the Model View Controller coding scheme in use widely in UI programming. I started experimenting with this idea in the "Settlement" repository (that also contains some OpenGL tampering).

We should separate the whole game logic into a Model tree that contains all the simulation-specific information. This information is serialized upon load/save and is modified in a separate simulation thread.

The rendering moves into the View tree that is created/destroyed on-the-fly as the player moves through the world. Controller classes check what portions of the game world are visible and maintain a view tree that render all the model information that is currently visible on the screen. This means that a view::Office object is created for each model::Office object that comes into view, and is also destroyed as soon as the object drops out of view.

This ensures maximum separation between rendering and simulating, making it particularly easy to parallelize the two: Each model object has a mutex that is unique-locked when a simulation step occurs and unlocked after that, which is a fairly short period of time.

For this to work, a notification system must be in place through which model objects signal themselves as changed, with the system properly dispatching these signals on the rendering thread through the controllers and the view tree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions