1 #ifndef MSP_GAME_COMPONENT_H_
2 #define MSP_GAME_COMPONENT_H_
4 #include <msp/time/timedelta.h>
14 Handle<Entity> entity;
16 Component(Handle<Entity>);
18 virtual ~Component() = default;
20 Handle<Entity> get_entity() const { return entity; }
24 class BufferedComponent: public Component
31 uint8_t read_index = 0;
32 uint8_t write_index = 0;
35 BufferedComponent(Handle<Entity> e): Component(e) { }
37 const T &read() const { return data[read_index]; }
41 virtual void prepare_tick() { write_index = 1-read_index; written = false; }
42 virtual void commit_tick() { if(written) read_index = write_index; }
46 T &BufferedComponent<T>::write()
48 if(!written && write_index!=read_index)
50 data[write_index] = data[read_index];
53 return data[write_index];
56 } // namespace Msp::Game