Switching SceneItems to smarts

This commit is contained in:
2023-11-12 23:02:11 -06:00
parent 91a91a5404
commit 54da3733d7
124 changed files with 188 additions and 216 deletions

View File

@ -40,7 +40,7 @@ namespace Dawn {
}
public:
easefunction_t *easing = &easeLinear;
std::function<float_t(const float_t)> easing = easeLinear;
T *modifies;
std::vector<struct SimpleKeyframe<T>> keyframes;
@ -50,7 +50,7 @@ namespace Dawn {
* @param modifies Pointer to the value that will be modified.
*/
SimpleAnimation(T *modifies) {
assertNotNull(modifies, "SimpleAnimation::SimpleAnimation: Modifies cannot be null");
assertNotNull(modifies, "Modifies cannot be null");
this->modifies = modifies;
}
@ -61,7 +61,7 @@ namespace Dawn {
* @param value Value at this given time.
*/
void addKeyframe(float_t time, T value) {
assertTrue(time >= 0, "SimpleAnimation::addKeyframe: Time must be >= 0");
assertTrue(time >= 0, "Time must be >= 0");
struct SimpleKeyframe<T> keyframe;
keyframe.time = time;

View File

@ -12,7 +12,6 @@ target_sources(${DAWN_TARGET_NAME}
)
# Subdirs
add_subdirectory(animation)
add_subdirectory(font)
add_subdirectory(mesh)
add_subdirectory(shader)

View File

@ -105,7 +105,7 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr<Scene> scene, std::shared
// Update shader parameter buffers with current knowledge
struct RenderPipelineShaderBufferData shaderBufferData;
shaderBufferData.projection = camera->getProjection();
shaderBufferData.view = camera->item->getWorldTransform();
shaderBufferData.view = camera->item.lock()->getWorldTransform();
shaderBuffer.buffer(&shaderBufferData);
// Prepare a render context. This is just a nice way of letting renderables
@ -128,30 +128,6 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr<Scene> scene, std::shared
++itRenderables;
}
// Debug Lines
#if DAWN_DEBUG_BUILD
Mesh lineMesh;
if(scene->debugLines.size() > 0) {
int32_t lineIndex = 0;
lineMesh.createBuffers(
scene->debugLines.size() * SCENE_DEBUG_LINE_VERTICE_COUNT,
scene->debugLines.size() * SCENE_DEBUG_LINE_INDICE_COUNT
);
auto itDebugLine = scene->debugLines.begin();
while(itDebugLine != scene->debugLines.end()) {
auto item = itDebugLine->createShaderItem(
&lineMesh,
&lineIndex,
camera,
renderManager->simpleTexturedShader
);
shaderPassItems.push_back(item);
itDebugLine = scene->debugLines.erase(itDebugLine);
lineIndex++;
}
}
#endif
// Inject index into each item
itPassItem = shaderPassItems.begin();
while(itPassItem != shaderPassItems.end()) {

View File

@ -7,7 +7,7 @@
using namespace Dawn;
PokerGame::PokerGame(SceneItem *item) : SceneItemComponent(item) {
PokerGame::PokerGame(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
}

View File

@ -33,7 +33,7 @@ namespace Dawn {
std::vector<struct PokerPot> pots;
uint8_t betterIndex;
PokerGame(SceneItem *item);
PokerGame(std::weak_ptr<SceneItem> item);
void onStart() override;

View File

@ -8,7 +8,7 @@
using namespace Dawn;
PokerPlayer::PokerPlayer(SceneItem *item) : SceneItemComponent(item) {
PokerPlayer::PokerPlayer(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
}

View File

@ -43,7 +43,7 @@ namespace Dawn {
*
* @param item Item that this poker player belongs to.
*/
PokerPlayer(SceneItem *item);
PokerPlayer(std::weak_ptr<SceneItem> item);
/** Override for scene item component event for init */
void onStart() override;

View File

@ -8,7 +8,7 @@
using namespace Dawn;
VNManager::VNManager(SceneItem *item) :
VNManager::VNManager(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item),
defaultFont("<font font=\"font_main\">{{ text }}</font>")
{

View File

@ -31,7 +31,7 @@ namespace Dawn {
*
* @param item Item that the VN manager belongs to.
*/
VNManager(SceneItem *item);
VNManager(std::weak_ptr<SceneItem> item);
/**
* Creats an event for you to decide how to queue.

View File

@ -8,7 +8,7 @@
using namespace Dawn;
VNTextboxScroller::VNTextboxScroller(SceneItem *item) :
VNTextboxScroller::VNTextboxScroller(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item),
label(nullptr),
visibleLines(4)

View File

@ -28,7 +28,7 @@ namespace Dawn {
size_t lineCurrent = 0;
float_t timeCharacter = 0.0f;
VNTextboxScroller(SceneItem *item);
VNTextboxScroller(std::weak_ptr<SceneItem> item);
virtual void onStart() override;
/**

View File

@ -11,7 +11,7 @@
namespace Dawn {
class VNPositionEvent : public VNAnimateEvent<glm::vec3> {
public:
SceneItem *item = nullptr;
std::weak_ptr<SceneItem> item = nullptr;
VNPositionEvent() {
from = glm::vec3(

View File

@ -30,7 +30,7 @@ namespace Dawn {
* @param context Custom context that this prefab needs to initialize.
* @return The instance of the created prefab.
*/
static O * create(J *context) {
static std::shared_ptr<O> create(J *context) {
assertNotNull(context, "Prefab::create: Context cannot be null");
return P::prefabCreate(context);
}

View File

@ -20,8 +20,8 @@ namespace Dawn {
* @param scene Scene that this prefab is going to be added to.
* @return The created prefab instance.
*/
static O * prefabCreate(Scene *scene) {
O *item = scene->createSceneItemOfType<O>();
static std::shared_ptr<O> prefabCreate(Scene *scene) {
std::shared_ptr<O> item = scene->createSceneItemOfType<O>();
auto game = scene->game.lock();
assertNotNull(game, "Game cannot be null!");
item->prefabInit(&game->assetManager);

View File

@ -34,30 +34,17 @@ void Scene::update() {
if(!game->timeManager.isPaused) this->eventSceneUnpausedUpdate.invoke(game->timeManager.delta);
}
SceneItem * Scene::createSceneItem() {
std::shared_ptr<SceneItem> Scene::createSceneItem() {
return this->createSceneItemOfType<SceneItem>();
}
Scene::~Scene() {
delete this->physics;
// Early cleanup without disposing.
// Invoke cleanup.
auto it = this->items.begin();
while(it != this->items.end()) {
it->second->destroy();
++it;
}
// Now dispose everything.
it = this->items.begin();
while(it != this->items.end()) {
delete it->second;
++it;
}
auto it2 = this->itemsNotInitialized.begin();
while(it2 != this->itemsNotInitialized.end()) {
delete it2->second;
++it2;
}
}

View File

@ -20,16 +20,18 @@ namespace Dawn {
typedef int32_t sceneitemid_t;
template<class T>
std::shared_ptr<T> _sceneForwardGetComponent(SceneItem *item);
std::shared_ptr<T> _sceneForwardGetComponent(std::shared_ptr<SceneItem> item);
template<class T>
std::vector<std::shared_ptr<T>> _sceneForwardGetComponents(SceneItem *item);
std::vector<std::shared_ptr<T>> _sceneForwardGetComponents(
std::shared_ptr<SceneItem> item
);
class Scene : public StateOwner, public std::enable_shared_from_this<Scene> {
private:
sceneitemid_t nextId;
std::map<sceneitemid_t, SceneItem*> items;
std::map<sceneitemid_t, SceneItem*> itemsNotInitialized;
std::map<sceneitemid_t, std::shared_ptr<SceneItem>> items;
std::map<sceneitemid_t, std::shared_ptr<SceneItem>> itemsNotInitialized;
public:
std::weak_ptr<DawnGame> game;
@ -56,10 +58,10 @@ namespace Dawn {
* @return A shared pointer to the created SceneItem.
*/
template<class T>
T * createSceneItemOfType() {
std::shared_ptr<T> createSceneItemOfType() {
sceneitemid_t id = this->nextId++;
auto item = new T(weak_from_this(), id);
assertNotNull(item, "Scene::createSceneItemOfType: Failed to create SceneItem (Memory Filled?)");
auto item = std::make_shared<T>(weak_from_this(), id);
assertNotNull(item, "Failed to create SceneItem (Memory Filled?)");
this->itemsNotInitialized[id] = item;
return item;
}
@ -69,7 +71,7 @@ namespace Dawn {
*
* @return A shared pointer to the created SceneItem.
*/
SceneItem * createSceneItem();
std::shared_ptr<SceneItem> createSceneItem();
/**
* Returns the required assets for this scene. Assets required are meant

View File

@ -79,7 +79,7 @@ namespace Dawn {
*/
template<class T>
std::shared_ptr<T> addComponent() {
auto component = std::make_shared<T>(this);
auto component = std::make_shared<T>(weak_from_this());
this->components.push_back(component);
return component;
}

View File

@ -10,8 +10,7 @@
using namespace Dawn;
SceneItemComponent::SceneItemComponent(SceneItem *item) {
assertNotNull(item, "SceneItemComponent::SceneItemComponent: Item cannot be null");
SceneItemComponent::SceneItemComponent(std::weak_ptr<SceneItem> item) {
this->item = item;
}
@ -25,7 +24,7 @@ std::vector<std::shared_ptr<SceneItemComponent>> SceneItemComponent::getDependen
}
std::shared_ptr<Scene> SceneItemComponent::getScene() {
auto scene = this->item->scene.lock();
auto scene = this->item.lock()->scene.lock();
assertNotNull(scene, "Scene cannot be null!");
return scene;
}

View File

@ -13,7 +13,7 @@ namespace Dawn {
class SceneItemComponent : public StateOwner {
public:
SceneItem *item;
std::weak_ptr<SceneItem> item;
bool_t hasInitialized = false;
/**
@ -23,7 +23,7 @@ namespace Dawn {
*
* @param item Scene Item thsi component belongs to.
*/
SceneItemComponent(SceneItem *item);
SceneItemComponent(std::weak_ptr<SceneItem> item);
/**
* Requested on the first frame that the parent scene item has become
@ -78,12 +78,16 @@ namespace Dawn {
};
template<class T>
std::shared_ptr<T> _sceneForwardGetComponent(SceneItem *item) {
std::shared_ptr<T> _sceneForwardGetComponent(
std::shared_ptr<SceneItem> item
) {
return item->getComponent<T>();
}
template<class T>
std::shared_ptr<T> _sceneForwardGetComponents(SceneItem *item) {
std::shared_ptr<T> _sceneForwardGetComponents(
std::shared_ptr<SceneItem> item
) {
return item->getComponents<T>();
}
}

View File

@ -7,7 +7,7 @@
using namespace Dawn;
FPSLabelComponent::FPSLabelComponent(SceneItem *item) :
FPSLabelComponent::FPSLabelComponent(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item)
{

View File

@ -12,7 +12,7 @@ namespace Dawn {
/* @optional */
UILabel *label = nullptr;
FPSLabelComponent(SceneItem *item);
FPSLabelComponent(std::weak_ptr<SceneItem> item);
void onStart() override;
};
}

View File

@ -6,7 +6,6 @@
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
AnimationController.cpp
Camera.cpp
Material.cpp
PixelPerfectCamera.cpp

View File

@ -8,9 +8,9 @@
using namespace Dawn;
Camera::Camera(SceneItem *item) :
Camera::Camera(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item),
renderTarget(item->scene.lock()->game.lock()->renderManager->getBackBuffer()),
renderTarget(this->getGame()->renderManager->getBackBuffer()),
fov(0.785398f),// 45 degrees,
type(CAMERA_TYPE_PERSPECTIVE),
orthoLeft(-0.5f),
@ -66,7 +66,7 @@ glm::vec3 Camera::getRayDirectionFromScreenSpace(glm::vec2 screenSpace) {
glm::vec4 eyeCoords = inverseProjectionMatrix * clipCoords;
eyeCoords = glm::vec4(eyeCoords.x, eyeCoords.y, -1.0f, 0.0f);
glm::mat4 inverseViewMatrix = glm::inverse(item->getWorldTransform());
glm::mat4 inverseViewMatrix = glm::inverse(item.lock()->getWorldTransform());
glm::vec4 t = inverseViewMatrix * eyeCoords;
return glm::normalize(glm::vec3(t.x, t.y, t.z));

View File

@ -55,7 +55,7 @@ namespace Dawn {
*
* @param item SceneItem that this component belongs to.
*/
Camera(SceneItem *item);
Camera(std::weak_ptr<SceneItem> item);
/**
* Returns the current projection matrix.

View File

@ -7,7 +7,7 @@
using namespace Dawn;
CameraTexture::CameraTexture(SceneItem *item) :
CameraTexture::CameraTexture(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item),
camera(nullptr)
{
@ -15,7 +15,7 @@ CameraTexture::CameraTexture(SceneItem *item) :
}
void CameraTexture::onStart() {
if(this->camera == nullptr) this->camera = item->getComponent<Camera>();
if(this->camera == nullptr) this->camera = item.lock()->getComponent<Camera>();
useEffect([&]{
if(this->camera == nullptr) return;

View File

@ -14,7 +14,7 @@ namespace Dawn {
StateProperty<std::shared_ptr<Camera>> camera;
std::shared_ptr<TextureRenderTarget> renderTarget;
CameraTexture(SceneItem *item);
CameraTexture(std::weak_ptr<SceneItem> item);
void onStart() override;
};
}

View File

@ -8,7 +8,7 @@
using namespace Dawn;
Material::Material(SceneItem *item) : SceneItemComponent(item) {
Material::Material(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
}
ShaderManager & Material::getShaderManager() {

View File

@ -16,7 +16,7 @@ namespace Dawn {
*
* @param item Scene Item this component belongs to.
*/
Material(SceneItem *item);
Material(std::weak_ptr<SceneItem> item);
/**
* Returns the shader manager for the game.

View File

@ -8,8 +8,8 @@
using namespace Dawn;
PixelPerfectCamera::PixelPerfectCamera(SceneItem *i) :
SceneItemComponent(i),
PixelPerfectCamera::PixelPerfectCamera(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item),
scale(1.0f),
camera(nullptr)
{
@ -33,7 +33,7 @@ void PixelPerfectCamera::updateDimensions() {
break;
case CAMERA_TYPE_PERSPECTIVE:
item->lookAtPixelPerfect(
item.lock()->lookAtPixelPerfect(
glm::vec3(0, 0, 0),
glm::vec3(0, 0, 0),
target->getHeight() / this->scale,
@ -48,7 +48,7 @@ void PixelPerfectCamera::updateDimensions() {
}
void PixelPerfectCamera::onStart() {
if(camera == nullptr) camera = item->getComponent<Camera>();
if(camera == nullptr) camera = item.lock()->getComponent<Camera>();
useEffect([&]{
this->updateDimensions();

View File

@ -28,7 +28,7 @@ namespace Dawn {
*
* @param item Item that this component belongs to.
*/
PixelPerfectCamera(SceneItem *item);
PixelPerfectCamera(std::weak_ptr<SceneItem> item);
void onStart() override;
};

View File

@ -7,7 +7,7 @@
using namespace Dawn;
SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
SimpleRenderTargetQuad::SimpleRenderTargetQuad(std::weak_ptr<SceneItem> i) :
SceneItemComponent(i),
renderTarget(nullptr)
{
@ -15,7 +15,7 @@ SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
std::vector<std::shared_ptr<SceneItemComponent>> SimpleRenderTargetQuad::getDependencies() {
return {
(this->meshHost = this->item->getComponent<MeshHost>())
(this->meshHost = this->item.lock()->getComponent<MeshHost>())
};
}

View File

@ -25,7 +25,7 @@ namespace Dawn {
*
* @param item Item that this component is attached to.
*/
SimpleRenderTargetQuad(SceneItem *item);
SimpleRenderTargetQuad(std::weak_ptr<SceneItem> item);
std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
void onStart() override;

View File

@ -8,7 +8,7 @@
using namespace Dawn;
TiledSprite::TiledSprite(SceneItem *item) :
TiledSprite::TiledSprite(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item),
tile(-1),
tileset(nullptr),
@ -22,7 +22,7 @@ TiledSprite::TiledSprite(SceneItem *item) :
std::vector<std::shared_ptr<SceneItemComponent>> TiledSprite::getDependencies() {
if(this->meshHost == nullptr) {
this->meshHost = this->item->getComponent<QuadMeshHost>();
this->meshHost = item.lock()->getComponent<QuadMeshHost>();
}
return { this->meshHost._realValue };

View File

@ -32,7 +32,7 @@ namespace Dawn {
// @optional
StateProperty<float_t> size;
TiledSprite(SceneItem *item);
TiledSprite(std::weak_ptr<SceneItem> item);
std::vector<std::shared_ptr<SceneItemComponent>> getDependencies();
void onStart() override;
};

View File

@ -7,7 +7,7 @@
using namespace Dawn;
CapsuleMeshHost::CapsuleMeshHost(SceneItem *item) :
CapsuleMeshHost::CapsuleMeshHost(std::weak_ptr<SceneItem> item) :
MeshHost(item),
radius(0.5f),
height(1.0f)

View File

@ -15,7 +15,7 @@ namespace Dawn {
// @optional
StateProperty<float> height;
CapsuleMeshHost(SceneItem *item);
CapsuleMeshHost(std::weak_ptr<SceneItem> item);
void onStart() override;
};

View File

@ -7,7 +7,7 @@
using namespace Dawn;
CubeMeshHost::CubeMeshHost(SceneItem *item) :
CubeMeshHost::CubeMeshHost(std::weak_ptr<SceneItem> item) :
MeshHost(item),
size(glm::vec3(1,1,1))
{

View File

@ -13,7 +13,7 @@ namespace Dawn {
// @optional
StateProperty<glm::vec3> size;
CubeMeshHost(SceneItem *item);
CubeMeshHost(std::weak_ptr<SceneItem> item);
void onStart() override;
};

View File

@ -7,7 +7,7 @@
using namespace Dawn;
MeshHost::MeshHost(SceneItem *item) :
MeshHost::MeshHost(std::weak_ptr<SceneItem> item) :
mesh(),
SceneItemComponent(item)
{

View File

@ -12,6 +12,6 @@ namespace Dawn {
public:
Mesh mesh;
MeshHost(SceneItem *item);
MeshHost(std::weak_ptr<SceneItem> item);
};
}

View File

@ -9,12 +9,12 @@
using namespace Dawn;
MeshRenderer::MeshRenderer(SceneItem *item) : SceneItemComponent(item) {
MeshRenderer::MeshRenderer(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
}
std::vector<std::shared_ptr<SceneItemComponent>> MeshRenderer::getDependencies() {
return {
this->meshHost = this->item->getComponent<MeshHost>()
meshHost = item.lock()->getComponent<MeshHost>()
};
}

View File

@ -23,7 +23,7 @@ namespace Dawn {
*
* @param item Scene Item this mesh renderer belongs to.
*/
MeshRenderer(SceneItem *item);
MeshRenderer(std::weak_ptr<SceneItem> item);
std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
void onStart() override;

View File

@ -7,7 +7,7 @@
using namespace Dawn;
QuadMeshHost::QuadMeshHost(SceneItem *item) :
QuadMeshHost::QuadMeshHost(std::weak_ptr<SceneItem> item) :
xy0(glm::vec2(-0.5f, -0.5f)), xy1(glm::vec2(0.5f, 0.5f)),
uv0(glm::vec2(0, 0)), uv1(glm::vec2(1, 1)),
MeshHost(item)

View File

@ -19,7 +19,7 @@ namespace Dawn {
// @optional
StateProperty<glm::vec2> uv1;
QuadMeshHost(SceneItem *item);
QuadMeshHost(std::weak_ptr<SceneItem> item);
void onStart() override;
};
}

View File

@ -11,7 +11,7 @@
using namespace Dawn;
SceneItem * ExampleSpin::create(Scene *scene) {
std::shared_ptr<SceneItem> ExampleSpin::create(Scene *scene) {
auto item = scene->createSceneItem();
auto mr = item->addComponent<MeshRenderer>();
mr->mesh = new Mesh();
@ -22,17 +22,18 @@ SceneItem * ExampleSpin::create(Scene *scene) {
return item;
}
ExampleSpin::ExampleSpin(SceneItem *item) :
ExampleSpin::ExampleSpin(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item)
{
}
void ExampleSpin::onStart() {
useEvent([&](float_t delta){
auto quat = item->getLocalRotation();
auto i = item.lock();
auto quat = i->getLocalRotation();
quat = glm::rotate(quat, delta, glm::vec3(0, 1, 0));
quat = glm::rotate(quat, delta / 2.0f, glm::vec3(1, 0, 0));
quat = glm::rotate(quat, delta / 4.0f, glm::vec3(0, 0, 1));
item->setLocalRotation(quat);
i->setLocalRotation(quat);
}, getScene()->eventSceneUnpausedUpdate);
}

View File

@ -10,9 +10,9 @@
namespace Dawn {
class ExampleSpin : public SceneItemComponent {
public:
static SceneItem * create(Scene *scene);
static std::shared_ptr<SceneItem> create(Scene *scene);
ExampleSpin(SceneItem *item);
ExampleSpin(std::weak_ptr<SceneItem> item);
void onStart() override;
};
}

View File

@ -7,7 +7,7 @@
using namespace Dawn;
BoxCollider::BoxCollider(SceneItem *i) : Collider2D(i) {
BoxCollider::BoxCollider(std::weak_ptr<SceneItem> item) : Collider2D(item) {
}

View File

@ -16,7 +16,7 @@ namespace Dawn {
// @optional
glm::vec2 max = glm::vec2( 0.5f, 0.5f);
BoxCollider(SceneItem *item);
BoxCollider(std::weak_ptr<SceneItem> item);
enum Collider2DType getColliderType() override;
};
}

View File

@ -7,7 +7,7 @@
using namespace Dawn;
CharacterController2D::CharacterController2D(SceneItem *i) :
CharacterController2D::CharacterController2D(std::weak_ptr<SceneItem> i) :
SceneItemComponent(i)
{
}
@ -17,6 +17,7 @@ void CharacterController2D::onStart() {
// if(velocity == glm::vec2(0, 0)) return;
// Common variables
auto item = this->item.lock();
auto myCollider = item->getComponent<Collider2D>();
// Friction
@ -38,7 +39,8 @@ void CharacterController2D::onStart() {
while(itColliders != allColliders.end()) {
auto c = *itColliders;
++itColliders;
if(c->item == this->item || c->item->isChildOf(item->shared_from_this())) continue;
auto cItem = c->item.lock();
if(cItem == item || cItem->isChildOf(item)) continue;
result = c->getCollidingResult(
velocity,
myCollider,
@ -76,7 +78,8 @@ void CharacterController2D::onStart() {
while(itTriggers != allTriggers.end()) {
auto c = *itTriggers;
++itTriggers;
if(c->item == this->item || c->item->isChildOf(item->shared_from_this())) continue;
auto cItem = c->item.lock();
if(cItem == item || cItem->isChildOf(item)) continue;
if(c->getCollidingResult(myCollider)) {
c->eventTriggerEnter.invoke(this);
}

View File

@ -26,7 +26,7 @@ namespace Dawn {
StateEvent<struct CharacterController2DCollisionEventInfo> eventCollision;
CharacterController2D(SceneItem *i);
CharacterController2D(std::weak_ptr<SceneItem> i);
void onStart() override;
};
}

View File

@ -8,6 +8,6 @@
using namespace Dawn;
Collider2D::Collider2D(SceneItem *i) : SceneItemComponent(i) {
Collider2D::Collider2D(std::weak_ptr<SceneItem> i) : SceneItemComponent(i) {
}

View File

@ -22,7 +22,7 @@ namespace Dawn {
class Collider2D : public SceneItemComponent {
public:
Collider2D(SceneItem *item);
Collider2D(std::weak_ptr<SceneItem> item);
/**
* Returns which type of collider this is.

View File

@ -7,12 +7,12 @@
using namespace Dawn;
SolidController2D::SolidController2D(SceneItem *item) : SceneItemComponent(item) {
SolidController2D::SolidController2D(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
}
std::vector<std::shared_ptr<SceneItemComponent>> SolidController2D::getDependencies() {
return {
(this->collider = item->getComponent<Collider2D>())
(this->collider = item.lock()->getComponent<Collider2D>())
};
}
@ -29,7 +29,7 @@ bool_t SolidController2D::getCollidingResult(
assertNotNull(movingObject, "SolidController2D::getCollidingResult: Moving object cannot be null");
if(movement.x == 0 && movement.y == 0) return false;
auto myPos = physics3Dto2D(movingObject->item->getWorldPosition());
auto myPos = physics3Dto2D(movingObject->item.lock()->getWorldPosition());
// Check what the moving object is
switch(movingObject->getColliderType()) {
@ -42,7 +42,7 @@ bool_t SolidController2D::getCollidingResult(
case COLLIDER2D_TYPE_BOX: {
auto box2 = std::static_pointer_cast<BoxCollider>(this->collider);
assertNotNull(box2, "SolidController2D::getCollidingResult: Collider is not a BoxCollider");
auto otherPos = physics3Dto2D(box2->item->getWorldPosition());
auto otherPos = physics3Dto2D(box2->item.lock()->getWorldPosition());
return boxCheckCollision(
myPos, box1->min, box1->max,

View File

@ -12,7 +12,7 @@ namespace Dawn {
public:
std::shared_ptr<Collider2D> collider;
SolidController2D(SceneItem *item);
SolidController2D(std::weak_ptr<SceneItem> item);
std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
/**

View File

@ -7,13 +7,13 @@
using namespace Dawn;
TriggerController2D::TriggerController2D(SceneItem *i) : SceneItemComponent(i) {
TriggerController2D::TriggerController2D(std::weak_ptr<SceneItem> i) : SceneItemComponent(i) {
}
std::vector<std::shared_ptr<SceneItemComponent>> TriggerController2D::getDependencies() {
return {
(this->collider = this->item->getComponent<Collider2D>())
(this->collider = this->item.lock()->getComponent<Collider2D>())
};
}
@ -32,8 +32,8 @@ bool_t TriggerController2D::getCollidingResult(std::shared_ptr<Collider2D> movin
auto box2 = std::static_pointer_cast<BoxCollider>(collider);
assertNotNull(box2, "TriggerController2D::getCollidingResult: Collider is not a BoxCollider");
return boxIsBoxColliding(
physics3Dto2D(box1->item->getWorldPosition()), box1->min, box1->max,
physics3Dto2D(box2->item->getWorldPosition()), box2->min, box2->max
physics3Dto2D(box1->item.lock()->getWorldPosition()), box1->min, box1->max,
physics3Dto2D(box2->item.lock()->getWorldPosition()), box2->min, box2->max
);
}

View File

@ -15,7 +15,7 @@ namespace Dawn {
std::shared_ptr<Collider2D> collider;
StateEvent<CharacterController2D*> eventTriggerEnter;
TriggerController2D(SceneItem *i);
TriggerController2D(std::weak_ptr<SceneItem> i);
std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
/**

View File

@ -7,7 +7,7 @@
using namespace Dawn;
CapsuleCollider::CapsuleCollider(SceneItem *item) : Collider3D(item) {
CapsuleCollider::CapsuleCollider(std::weak_ptr<SceneItem> item) : Collider3D(item) {
}
@ -22,7 +22,7 @@ bool_t CapsuleCollider::performRaycast(
{
.height = this->height,
.radius = this->radius,
.origin = item->getWorldPosition()
.origin = item.lock()->getWorldPosition()
},
&result->point,
&result->normal,

View File

@ -21,7 +21,7 @@ namespace Dawn {
// @optional
float_t radius = 0.5f;
CapsuleCollider(SceneItem *item);
CapsuleCollider(std::weak_ptr<SceneItem> item);
enum Collider3DType getColliderType() override;
};

View File

@ -7,7 +7,7 @@
using namespace Dawn;
CharacterController3D::CharacterController3D(SceneItem *item) :
CharacterController3D::CharacterController3D(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item)
{
@ -15,6 +15,8 @@ CharacterController3D::CharacterController3D(SceneItem *item) :
void CharacterController3D::onStart() {
useEvent([&](float_t delta){
auto item = this->item.lock();
// Friction
velocity -= glm::vec3(velocity.x, 0, velocity.z) * friction * delta;

View File

@ -16,7 +16,7 @@ namespace Dawn {
// @optional
float_t friction = 12.0f;
CharacterController3D(SceneItem *item);
CharacterController3D(std::weak_ptr<SceneItem> item);
void onStart() override;
};

View File

@ -7,7 +7,7 @@
using namespace Dawn;
Collider3D::Collider3D(SceneItem *item) : SceneItemComponent(item) {
Collider3D::Collider3D(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
}

View File

@ -36,7 +36,7 @@ namespace Dawn {
) = 0;
public:
Collider3D(SceneItem *item);
Collider3D(std::weak_ptr<SceneItem> item);
/**
* Perform a raycast against this collider.

View File

@ -7,7 +7,7 @@
using namespace Dawn;
CubeCollider::CubeCollider(SceneItem *item) : Collider3D(item) {
CubeCollider::CubeCollider(std::weak_ptr<SceneItem> item) : Collider3D(item) {
}
@ -20,7 +20,7 @@ bool_t CubeCollider::performRaycast(
return Dawn::raytestCube(
ray,
{ .min = this->min, .max = this->max },
item->getWorldTransform(),
item.lock()->getWorldTransform(),
&result->point,
&result->normal,
&result->distance

View File

@ -21,7 +21,7 @@ namespace Dawn {
// @optional
glm::vec3 max = glm::vec3(0.5f, 0.5f, 0.5f);
CubeCollider(SceneItem *item);
CubeCollider(std::weak_ptr<SceneItem> item);
enum Collider3DType getColliderType() override;
};

View File

@ -7,7 +7,7 @@
using namespace Dawn;
SphereCollider::SphereCollider(SceneItem *item) : Collider3D(item) {
SphereCollider::SphereCollider(std::weak_ptr<SceneItem> item) : Collider3D(item) {
}
@ -23,7 +23,7 @@ bool_t SphereCollider::performRaycast(
return raytestSphere(
ray,
{ .center = item->getLocalPosition(), .radius = this->radius },
{ .center = item.lock()->getLocalPosition(), .radius = this->radius },
&result->point,
&result->normal,
&result->distance

View File

@ -18,7 +18,7 @@ namespace Dawn {
// @optional
float_t radius = 1.0f;
SphereCollider(SceneItem *item);
SphereCollider(std::weak_ptr<SceneItem> item);
enum Collider3DType getColliderType() override;
};

View File

@ -7,7 +7,7 @@
using namespace Dawn;
SubSceneCameraAlign::SubSceneCameraAlign(SceneItem *i) :
SubSceneCameraAlign::SubSceneCameraAlign(std::weak_ptr<SceneItem> i) :
SceneItemComponent(i),
camera(nullptr),
renderTarget(nullptr)
@ -23,7 +23,7 @@ void SubSceneCameraAlign::realign() {
float_t myRatio = this->camera->getAspect();
this->camera->type = CAMERA_TYPE_ORTHONOGRAPHIC;
this->camera->item->lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0));
this->camera->item.lock()->lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0));
if(ratio > myRatio) {
// My Ratio is narrower

View File

@ -31,7 +31,7 @@ namespace Dawn {
*
* @param item Scene Item that this component belongs to.
*/
SubSceneCameraAlign(SceneItem *item);
SubSceneCameraAlign(std::weak_ptr<SceneItem> item);
void onStart() override;
};

View File

@ -7,7 +7,7 @@
using namespace Dawn;
SubSceneController::SubSceneController(SceneItem *i) : SceneItemComponent(i) {
SubSceneController::SubSceneController(std::weak_ptr<SceneItem> i) : SceneItemComponent(i) {
}

View File

@ -14,7 +14,7 @@ namespace Dawn {
// @optional
bool_t onlyUpdateUnpaused = false;
SubSceneController(SceneItem *item);
SubSceneController(std::weak_ptr<SceneItem> item);
void onStart() override;
};

View File

@ -8,7 +8,7 @@
using namespace Dawn;
UIBorder::UIBorder(SceneItem *item) :
UIBorder::UIBorder(std::weak_ptr<SceneItem> item) :
texture(nullptr),
borderSize(glm::vec2(8, 8)),
UIComponentRenderable(item)
@ -37,7 +37,7 @@ std::vector<struct ShaderPassItem> UIBorder::getUIRenderPasses() {
item.shader = shader;
item.colorValues[shader->paramColor] = COLOR_WHITE;
item.parameterBuffers[shader->bufferUiCanvas] = &this->getCanvas()->shaderBuffer;
item.matrixValues[shader->paramModel] = this->item->getWorldTransform();
item.matrixValues[shader->paramModel] = this->item.lock()->getWorldTransform();
if(this->texture == nullptr) {
item.boolValues[shader->paramHasTexture] = false;
} else {
@ -45,7 +45,7 @@ std::vector<struct ShaderPassItem> UIBorder::getUIRenderPasses() {
item.textureSlots[0] = this->texture;
item.textureValues[shader->paramTexture] = 0;
}
item.w = this->item->getWorldPosition().z;
item.w = this->item.lock()->getWorldPosition().z;
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
item.mesh = &mesh;

View File

@ -20,7 +20,7 @@ namespace Dawn {
// @optional
StateProperty<Texture*> texture;
UIBorder(SceneItem *item);
UIBorder(std::weak_ptr<SceneItem> item);
float_t getContentWidth() override;
float_t getContentHeight() override;

View File

@ -14,7 +14,7 @@ std::shared_ptr<UICanvas> UICanvas::create(Scene *scene) {
return item->addComponent<UICanvas>();
}
UICanvas::UICanvas(SceneItem *item) :
UICanvas::UICanvas(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item),
camera(nullptr)
{
@ -26,7 +26,7 @@ void UICanvas::rebufferShaderParameters() {
switch(this->drawType) {
case UI_DRAW_TYPE_WORLD_ABSOLUTE:
data.projection = camera->getProjection();
data.view = camera->item->getWorldTransform();
data.view = camera->item.lock()->getWorldTransform();
break;
case UI_DRAW_TYPE_WORLD_CAMERA_RELATIVE:
@ -91,7 +91,7 @@ void UICanvas::onStart() {
this->h = h / this->getScale();
this->rebufferShaderParameters();
auto comps = this->item->findChildren<UIComponent>();
auto comps = this->item.lock()->findChildren<UIComponent>();
auto itComps = comps.begin();
while(itComps != comps.end()) {
(*itComps)->alignmentNeedsUpdating = true;

View File

@ -94,7 +94,7 @@ namespace Dawn {
*
* @param item Item that this canvas item belongs to.
*/
UICanvas(SceneItem *item);
UICanvas(std::weak_ptr<SceneItem> item);
/**
* Returns the scale of this canvas.

View File

@ -7,7 +7,7 @@
using namespace Dawn;
UIComponent::UIComponent(SceneItem *item) :
UIComponent::UIComponent(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item),
alignment(glm::vec4(0, 0, 128, 128)),
alignUnitLeft(UI_COMPONENT_ALIGN_UNIT_SCALE),
@ -22,7 +22,7 @@ UIComponent::UIComponent(SceneItem *item) :
}
std::shared_ptr<UIComponentDimensional> UIComponent::getParentDimensional() {
auto parent = item->getParent();
auto parent = item.lock()->getParent();
if(parent == nullptr) return nullptr;
auto dimensional = parent->getComponent<UIComponentDimensional>();
assertNotNull(dimensional, "UIComponent::getParentDimensional: Parent must have a UIComponentDimensional");
@ -34,7 +34,7 @@ void UIComponent::updateAlignment() {
auto align = (glm::vec4)this->alignment;
auto dimensional = this->getParentDimensional();
auto translate = item->getLocalPosition();
auto translate = item.lock()->getLocalPosition();
assertNotNull(dimensional, "UIComponent::updateAlignment: Parent must have a UIComponentDimensional");
@ -99,7 +99,7 @@ void UIComponent::updateAlignment() {
translate.x += dimensional->getChildOffsetX();
translate.y += dimensional->getChildOffsetY();
item->setLocalPosition(translate);
item.lock()->setLocalPosition(translate);
this->alignmentNeedsUpdating = false;
this->eventAlignmentUpdated.invoke();
}
@ -240,7 +240,7 @@ void UIComponent::calculateDimensions(
std::shared_ptr<UICanvas> UIComponent::getCanvas() {
// TODO: Cache this on first hit.
auto parent = item->getParent();
auto parent = item.lock()->getParent();
while(parent) {
auto canvas = parent->getComponent<UICanvas>();
if(canvas != nullptr) return canvas;
@ -274,7 +274,7 @@ void UIComponent::onStart() {
useEffect([&]{
this->updateAlignment();
auto child = this->item->findChildren<UIComponent>();
auto child = this->item.lock()->findChildren<UIComponent>();
auto itChild = child.begin();
while(itChild != child.end()) {
(*itChild)->alignmentNeedsUpdating = true;

View File

@ -123,7 +123,7 @@ namespace Dawn {
// @optional
StateProperty<glm::vec4> alignment;
UIComponent(SceneItem *item);
UIComponent(std::weak_ptr<SceneItem> item);
/**
* Returns the canvas that this UI element is belonging to.

View File

@ -7,7 +7,7 @@
using namespace Dawn;
UIComponentRenderable::UIComponentRenderable(SceneItem *i) : UIComponent(i) {
UIComponentRenderable::UIComponentRenderable(std::weak_ptr<SceneItem> i) : UIComponent(i) {
}

View File

@ -9,7 +9,7 @@
namespace Dawn {
class UIComponentRenderable : public UIComponent, public IRenderable {
public:
UIComponentRenderable(SceneItem *item);
UIComponentRenderable(std::weak_ptr<SceneItem> item);
std::vector<struct ShaderPassItem> getRenderPasses(
struct IRenderableContext &context

View File

@ -7,7 +7,7 @@
using namespace Dawn;
UIEmpty::UIEmpty(SceneItem *item) : UIComponent(item) { }
UIEmpty::UIEmpty(std::weak_ptr<SceneItem> item) : UIComponent(item) { }
float_t UIEmpty::getContentWidth() {
return this->getWidthFromAlignment();

View File

@ -9,7 +9,7 @@
namespace Dawn {
class UIEmpty : public UIComponent {
public:
UIEmpty(SceneItem *item);
UIEmpty(std::weak_ptr<SceneItem> item);
float_t getContentWidth() override;
float_t getContentHeight() override;
float_t getChildOffsetX() override;

View File

@ -8,7 +8,7 @@
using namespace Dawn;
UIImage::UIImage(SceneItem *item) :
UIImage::UIImage(std::weak_ptr<SceneItem> item) :
texture(nullptr),
UIComponentRenderable(item),
uvs(glm::vec4(0, 1, 1, 0))
@ -32,7 +32,7 @@ std::vector<struct ShaderPassItem> UIImage::getUIRenderPasses() {
item.shader = shader;
item.colorValues[shader->paramColor] = this->color;
item.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer;
item.matrixValues[shader->paramModel] = this->item->getWorldTransform();
item.matrixValues[shader->paramModel] = this->item.lock()->getWorldTransform();
if(this->texture == nullptr) {
item.boolValues[shader->paramHasTexture] = false;
} else {
@ -40,7 +40,7 @@ std::vector<struct ShaderPassItem> UIImage::getUIRenderPasses() {
item.textureSlots[0] = this->texture;
item.textureValues[shader->paramTexture] = 0;
}
item.w = this->item->getWorldPosition().z;
item.w = this->item.lock()->getWorldPosition().z;
item.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
item.mesh = &mesh;
return { item };

View File

@ -20,7 +20,7 @@ namespace Dawn {
// @optional
StateProperty<glm::vec4> uvs;
UIImage(SceneItem *item);
UIImage(std::weak_ptr<SceneItem> item);
float_t getContentWidth() override;
float_t getContentHeight() override;

View File

@ -8,7 +8,7 @@
using namespace Dawn;
UIMesh::UIMesh(SceneItem *i) :
UIMesh::UIMesh(std::weak_ptr<SceneItem> i) :
texture(nullptr),
UIComponentRenderable(i)
{
@ -31,7 +31,7 @@ std::vector<struct ShaderPassItem> UIMesh::getUIRenderPasses() {
shaderItem.shader = shader;
shaderItem.colorValues[shader->paramColor] = this->color;
shaderItem.parameterBuffers[shader->bufferUiCanvas] = &getCanvas()->shaderBuffer;
shaderItem.matrixValues[shader->paramModel] = item->getWorldTransform();
shaderItem.matrixValues[shader->paramModel] = item.lock()->getWorldTransform();
if(this->texture == nullptr) {
shaderItem.boolValues[shader->paramHasTexture] = false;
} else {
@ -39,7 +39,7 @@ std::vector<struct ShaderPassItem> UIMesh::getUIRenderPasses() {
shaderItem.textureSlots[0] = this->texture;
shaderItem.textureValues[shader->paramTexture] = 0;
}
shaderItem.w = item->getWorldPosition().z;
shaderItem.w = item.lock()->getWorldPosition().z;
shaderItem.renderFlags = RENDER_MANAGER_RENDER_FLAG_BLEND;
shaderItem.mesh = &mesh;
return { shaderItem };

View File

@ -22,7 +22,7 @@ namespace Dawn {
// @optional
StateProperty<Texture*> texture;
UIMesh(SceneItem *item);
UIMesh(std::weak_ptr<SceneItem> item);
float_t getContentWidth() override;
float_t getContentHeight() override;
std::vector<struct ShaderPassItem> getUIRenderPasses() override;

View File

@ -8,7 +8,7 @@
using namespace Dawn;
UIMenuController::UIMenuController(SceneItem *item) :
UIMenuController::UIMenuController(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item),
active(true),
menuX(0),

View File

@ -22,7 +22,7 @@ namespace Dawn {
StateEvent<int32_t, int32_t> eventItemSelected;
StateEvent<> eventMenuCancel;
UIMenuController(SceneItem *item);
UIMenuController(std::weak_ptr<SceneItem> item);
void onStart() override;
};
}

View File

@ -8,7 +8,7 @@
using namespace Dawn;
UISimpleMenu::UISimpleMenu(SceneItem *item) :
UISimpleMenu::UISimpleMenu(std::weak_ptr<SceneItem> item) :
SceneItemComponent(item)
{
@ -16,8 +16,8 @@ UISimpleMenu::UISimpleMenu(SceneItem *item) :
std::vector<std::shared_ptr<SceneItemComponent>> UISimpleMenu::getDependencies() {
return {
(this->menu = this->item->getComponent<UIMenuController>()),
(this->canvas == nullptr ? (this->canvas = this->item->getComponent<UICanvas>()) : nullptr)
(this->menu = this->item.lock()->getComponent<UIMenuController>()),
(this->canvas == nullptr ? (this->canvas = this->item.lock()->getComponent<UICanvas>()) : nullptr)
};
}
@ -26,7 +26,7 @@ void UISimpleMenu::onStart() {
assertNotNull(this->menu, "UISimpleMenu::onStart: Menu cannot be null");
assertNotNull(this->canvas, "UISimpleMenu::onStart: Canvas cannot be null");
menuItems = this->item->findChildren<UISimpleMenuItem>();
menuItems = this->item.lock()->findChildren<UISimpleMenuItem>();
auto updateSimpleMenuPos = [&](int32_t x, int32_t y) {
if(currentlySelected != nullptr) {
@ -75,7 +75,7 @@ void UISimpleMenu::onStart() {
case UI_DRAW_TYPE_WORLD_ABSOLUTE:
mouse *= 2.0f;
mouse -= glm::vec2(1, 1);
ray.origin = canvas->camera->item->getWorldPosition();
ray.origin = canvas->camera->item.lock()->getWorldPosition();
ray.direction = canvas->camera->getRayDirectionFromScreenSpace(mouse);
break;
@ -107,7 +107,7 @@ void UISimpleMenu::onStart() {
if(!raytestQuad(
ray,
glm::vec2(0, 0), size,
highlight->item->getWorldTransform(),
highlight->item.lock()->getWorldTransform(),
&point,
&normal,
&distance

View File

@ -16,7 +16,7 @@ namespace Dawn {
std::vector<std::shared_ptr<UISimpleMenuItem>> menuItems;
public:
UISimpleMenu(SceneItem *item);
UISimpleMenu(std::weak_ptr<SceneItem> item);
std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
void onStart() override;
};

View File

@ -7,11 +7,11 @@
using namespace Dawn;
UISimpleMenuItem::UISimpleMenuItem(SceneItem *item) : SceneItemComponent(item) {
UISimpleMenuItem::UISimpleMenuItem(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
}
std::shared_ptr<UIComponent> UISimpleMenuItem::getComponentForHighlighting() {
if(uiComponent == nullptr) uiComponent = item->getComponent<UIComponent>();
if(uiComponent == nullptr) uiComponent = item.lock()->getComponent<UIComponent>();
return uiComponent;
}

Some files were not shown because too many files have changed in this diff Show More