Moved Scene implementation around

This commit is contained in:
2023-02-21 20:59:42 -08:00
parent fc14618f38
commit 38527a7de6
42 changed files with 540 additions and 459 deletions

View File

@ -1,38 +1,37 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "AnimationController.hpp"
#include "scene/Scene.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
AnimationController::AnimationController(SceneItem *item) :
SceneItemComponent(item)
{
}
void AnimationController::addAnimation(Animation *animation) {
assertNotNull(animation);
this->animations.push_back(animation);
}
void AnimationController::onSceneUpdate() {
auto it = this->animations.begin();
while(it != this->animations.end()) {
(*it)->tick(this->getGame()->timeManager.delta);
++it;
}
}
void AnimationController::onStart() {
SceneItemComponent::onStart();
getScene()->eventSceneUnpausedUpdate.addListener(this, &AnimationController::onSceneUpdate);
}
void AnimationController::onDispose() {
getScene()->eventSceneUnpausedUpdate.removeListener(this, &AnimationController::onSceneUpdate);
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "AnimationController.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
AnimationController::AnimationController(SceneItem *item) :
SceneItemComponent(item)
{
}
void AnimationController::addAnimation(Animation *animation) {
assertNotNull(animation);
this->animations.push_back(animation);
}
void AnimationController::onSceneUpdate() {
auto it = this->animations.begin();
while(it != this->animations.end()) {
(*it)->tick(this->getGame()->timeManager.delta);
++it;
}
}
void AnimationController::onStart() {
SceneItemComponent::onStart();
getScene()->eventSceneUnpausedUpdate.addListener(this, &AnimationController::onSceneUpdate);
}
void AnimationController::onDispose() {
getScene()->eventSceneUnpausedUpdate.removeListener(this, &AnimationController::onSceneUpdate);
}

View File

@ -4,7 +4,6 @@
// https://opensource.org/licenses/MIT
#include "Camera.hpp"
#include "scene/Scene.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;

View File

@ -4,7 +4,6 @@
// https://opensource.org/licenses/MIT
#include "Material.hpp"
#include "scene/Scene.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;

View File

@ -1,81 +1,80 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SimpleRenderTargetQuad.hpp"
#include "scene/Scene.hpp"
using namespace Dawn;
SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
SceneItemComponent(i)
{
}
void SimpleRenderTargetQuad::onRenderTargetResized(
RenderTarget *target, float_t w, float_t h
) {
assertTrue(target == this->renderTarget);
// Update mesh
QuadMesh::bufferQuadMesh(
&this->meshHost->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(w, h), glm::vec2(1, 1),
0, 0
);
}
void SimpleRenderTargetQuad::setRenderTarget(RenderTarget *rt) {
assertTrue(rt != this->renderTarget);
// Remove old event listener
if(this->renderTarget != nullptr) {
this->renderTarget->eventRenderTargetResized.removeListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
this->renderTarget = rt;
// Add new event listener.
if(rt != nullptr) {
rt->eventRenderTargetResized.addListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
}
std::vector<SceneItemComponent*> SimpleRenderTargetQuad::getDependencies() {
return std::vector<SceneItemComponent*>{
(this->meshHost = this->item->getComponent<MeshHost>())
};
}
void SimpleRenderTargetQuad::onStart() {
assertNotNull(this->meshHost);
// Create quad mesh
this->meshHost->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
// Perform first resize.
if(this->renderTarget != nullptr) {
QuadMesh::bufferQuadMesh(
&this->meshHost->mesh,
glm::vec2(0, 0),
glm::vec2(0, 0),
glm::vec2(this->renderTarget->getWidth(), this->renderTarget->getHeight()),
glm::vec2(1,1),
0, 0
);
}
}
void SimpleRenderTargetQuad::onDispose() {
if(this->renderTarget != nullptr) {
this->renderTarget->eventRenderTargetResized.removeListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SimpleRenderTargetQuad.hpp"
using namespace Dawn;
SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
SceneItemComponent(i)
{
}
void SimpleRenderTargetQuad::onRenderTargetResized(
RenderTarget *target, float_t w, float_t h
) {
assertTrue(target == this->renderTarget);
// Update mesh
QuadMesh::bufferQuadMesh(
&this->meshHost->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(w, h), glm::vec2(1, 1),
0, 0
);
}
void SimpleRenderTargetQuad::setRenderTarget(RenderTarget *rt) {
assertTrue(rt != this->renderTarget);
// Remove old event listener
if(this->renderTarget != nullptr) {
this->renderTarget->eventRenderTargetResized.removeListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
this->renderTarget = rt;
// Add new event listener.
if(rt != nullptr) {
rt->eventRenderTargetResized.addListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
}
std::vector<SceneItemComponent*> SimpleRenderTargetQuad::getDependencies() {
return std::vector<SceneItemComponent*>{
(this->meshHost = this->item->getComponent<MeshHost>())
};
}
void SimpleRenderTargetQuad::onStart() {
assertNotNull(this->meshHost);
// Create quad mesh
this->meshHost->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
// Perform first resize.
if(this->renderTarget != nullptr) {
QuadMesh::bufferQuadMesh(
&this->meshHost->mesh,
glm::vec2(0, 0),
glm::vec2(0, 0),
glm::vec2(this->renderTarget->getWidth(), this->renderTarget->getHeight()),
glm::vec2(1,1),
0, 0
);
}
}
void SimpleRenderTargetQuad::onDispose() {
if(this->renderTarget != nullptr) {
this->renderTarget->eventRenderTargetResized.removeListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
}