I created a really basic game class. A game has GameObject instances, which currently have a position only.This code is running on the client, and in each loop iteration:The client receives the updates from the serverIt executes the received eventsThe client updates the game stateI created a map to store game objects. The reason why I chose std::map is because I need to access game objects by their index, to update them. And sometimes an object may be deleted, so there would be holes in the std::vector if I would use it.I created an Updateable class, so when I execute events, and one of them is affected by the properties of the other objects, then the execution order does not matter (it may be parallelized later).The classes were originally in separate files, and have header files and a namespace too. I just put it together, to show them:#include <iostream>#include <queue>#include <map>/* Vec2 struct */struct Vec2 {    double x;    double y;    Vec2() {        x=0.0;        y=0.0;    }    Vec2(double x, double y) :         x(x),        y(y)    {}    friend Vec2 operator+(const Vec2 &v1, const Vec2 &v2) {        return Vec2(v1.x+v2.x, v1.y + v2.y);    }};/* Updateable class */template<class T>class Updateable {    T current;    T next;public:    void setNext(T val) {        next = val;    }    T getCurrent() const {        return current;    }    T getNext() const {        return next;    }    void update() {        current = next;        next = T();    }};/* GameObj class */class GameObj {    const int obj_id;public:    Updateable<Vec2> position;    GameObj(int obj_id) : obj_id(obj_id) {    }    virtual ~GameObj() {}};/* Event class */class Game;class Event {public:    virtual void do_event(Game* game) const = 0;    virtual ~Event() {}};/* Game class */class Game {    std::queue<Event*> events;    std::map<int, GameObj*> objects;public:    GameObj* findObj(int id) {        auto it = objects.find(id);        if ( it != objects.end() ) {            return it->second;        }        return nullptr;    }    GameObj* addObj(int id) {        GameObj* obj = new GameObj(id);        auto it = objects.find(id);        if ( it != objects.end() ) {            delete it->second;            it->second = obj;        } else {            objects[id] = obj;        }        return obj;    }    void addEvent(Event* event) {        events.push(event);    }    void update() {        // process events        while(!events.empty()) {            Event* event = events.front();            event->do_event(this);            events.pop();            delete event;        }        // update objects        for(auto iterator = objects.begin(); iterator != objects.end(); iterator++) {            iterator->second->position.update();        }    }    ~Game() {        while(!events.empty()) {            Event* event = events.front();            events.pop();            delete event;        }        for(auto iterator = objects.begin(); iterator != objects.end(); iterator++) {            delete iterator->second;        }        objects.clear();    }};/* MoveObjEvent class */class MoveObjEvent : public Event {    const int obj_id;    const Vec2 move_vec;public:    MoveObjEvent(int obj_id, Vec2 move_vec) :        obj_id(obj_id),        move_vec(move_vec)    {}    virtual void do_event(Game* game) const override {        GameObj* obj = game->findObj(obj_id);        if(obj != nullptr) {            obj->position.setNext(obj->position.getNext() + move_vec);        }    }};/* CreateObjEvent class */class CreateObjEvent : public Event {    const int obj_id;public:    CreateObjEvent(int obj_id) :        obj_id(obj_id)    {}    virtual void do_event(Game* game) const override {        game->addObj(obj_id);    }};int main() {    // create a game object    Game game;    /*     * Example of one iteration:     */    // recive events from server    game.addEvent(new CreateObjEvent(1));    game.addEvent(new MoveObjEvent(1, Vec2(5, 6)));    // update game    game.update();    /*     * One iteration ends here     */    // test    std::cout << game.findObj(1)->position.getCurrent().x << std::endl;    return 0;}
Multiplayer GameObject design
c++;object oriented;c++11;game;pointers