entity destruction, etc.
This commit is contained in:
@@ -23,13 +23,14 @@ namespace Game::Object {
|
||||
Entity& operator=(const Entity&);
|
||||
Entity(Entity&&) noexcept;
|
||||
Entity& operator=(Entity&&) noexcept;
|
||||
virtual ~Entity() = 0;
|
||||
virtual ~Entity() = 0; // Destructor
|
||||
|
||||
// Start is called when the entity is spawned
|
||||
virtual void start() = 0;
|
||||
// Update is called every update cycle; deltaTime is the time (in seconds) since the last update call
|
||||
virtual void update(float deltaTime) = 0;
|
||||
virtual void onWindowResized(int newWidth, int newHeight) {} // Called when the window is resized, with the new width and height in pixels
|
||||
virtual void destroyed() {}; // Pre-destruction call
|
||||
void render(Game::Renderer::Renderer* renderer, Game::Renderer::RendererConfig config);
|
||||
|
||||
// Setters and getters
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace Game::State {
|
||||
}
|
||||
|
||||
void sort(); // Sort entities by zIndex for correct rendering order
|
||||
void wipe();
|
||||
Object::Entity* getEntityByName(const std::string& name); // Get an entity by name, returns nullptr if no entity with the name exists
|
||||
std::vector<Object::Entity*> getEntitiesSnapshot(bool sortByZIndex = false); // Get a stable snapshot of entity pointers for iteration outside the lock
|
||||
|
||||
@@ -27,6 +28,7 @@ namespace Game::State {
|
||||
Object::Entity* getAtIndex(size_t at);
|
||||
// Add an entity to the gamestate.
|
||||
void addEntity(std::unique_ptr<Object::Entity> entity);
|
||||
bool removeEntity(const std::string& name);
|
||||
|
||||
private:
|
||||
mutable std::mutex mMutex; // Shared mutex for thread safety
|
||||
|
||||
Reference in New Issue
Block a user