Dawn/src/dawn/scene/SceneItemComponent.hpp
2023-02-28 22:18:26 -08:00

88 lines
2.4 KiB
C++

// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "display/Transform.hpp"
#include "scene/SceneItem.hpp"
#include "state/State.hpp"
namespace Dawn {
class DawnGame;
class SceneItemComponent : public StateOwner {
public:
SceneItem *item;
Transform *transform;
bool_t hasInitialized = false;
/**
* Constructs a new SceneItemComponent. Components are attached to
* SceneItems and will be individual responsibility components, and must
* communicate to other items/components using methods and events.
*
* @param item Scene Item thsi component belongs to.
*/
SceneItemComponent(SceneItem *item);
/**
* Requested on the first frame that the parent scene item has become
* active, after all of my dependencies are ready.
*/
void init();
/**
* Optionally return all dependencies for this component to wait for init
* for before the component will be initialized.
*
* @return Array of dependencies.
*/
virtual std::vector<SceneItemComponent*> getDependencies();
/**
* Shorthand to return the scene that this component's item belongs to.
* @return The current scene.
*/
Scene * getScene();
/**
* Shorthand to return the game that this scene belongs to.
* @return The current game.
*/
DawnGame * getGame();
/**
* Shorthand to return the physics manager that the scene this item
* belongs to, belongs to.
* @return The scene physics manager.
*/
ScenePhysicsManager * getPhysics();
/**
* Same as init, but intended for your subclass to override.
*/
virtual void onStart();
/**
* Intended for subclasses to detect when they need to clean themselves up
* but before anything has been completely free'd from memory.
*/
virtual void onDispose();
virtual void onStateUpdate();
/**
* Cleanup the SceneItemComponent.
*/
virtual ~SceneItemComponent();
};
template<class T>
T * _sceneForwardGetComponent(SceneItem *item) {
return item->getComponent<T>();
}
}