Moved more files around, working on VN engine

This commit is contained in:
2023-04-20 14:08:02 -07:00
parent 6d86fc10bc
commit cacda495d3
5 changed files with 103 additions and 11 deletions

View File

@ -0,0 +1,31 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "SimpleAnimation.hpp"
namespace Dawn {
template<typename T>
struct SimplerCallbackAnimation : public SimpleAnimation<T> {
protected:
T value;
void onValueModified() override {
SimpleAnimation<T>::onValueModified();
this->callback(this->value);
}
public:
std::function<void(T)> callback = std::function<void(T)>();
/**
* Construct a new Simple Function Animation object
*/
SimplerCallbackAnimation() :
SimpleAnimation<T>(&value)
{
}
};
}

View File

@ -41,17 +41,11 @@ namespace Dawn {
*/
void setEvent(VNEvent *event);
/**
* Ends the current event, and moves to the next one.
*/
void nextEvent();
// template <class T>
// T * setEvent(T *event) {
// auto oldCurrent = this->currentEvent;
// this->currentEvent = event;
// if(this->hasInitialized && event != nullptr) event->start(oldCurrent);
// delete oldCurrent;
// return event;
// }
void onStart() override;
void onDispose() override;

View File

@ -0,0 +1,58 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "VNEvent.hpp"
#include "scene/SceneItem.hpp"
#include "display/animation/SimplerCallbackAnimation.hpp"
#define VN_POSITION_EVENT_VALUE_UNCHANGED -123456789
namespace Dawn {
class VNPositionEvent : public VNEvent {
public:
float_t x = VN_POSITION_EVENT_VALUE_UNCHANGED;
float_t y = VN_POSITION_EVENT_VALUE_UNCHANGED;
float_t z = VN_POSITION_EVENT_VALUE_UNCHANGED;
SceneItem *item = nullptr;
float_t duration;
protected:
SimplerCallbackAnimation<glm::vec3> animation;
void onStart() override {
assertNotNull(item);
auto start = item->transform.getLocalPosition();
auto destination = glm::vec3(
x == VN_POSITION_EVENT_VALUE_UNCHANGED ? start.x : x,
y == VN_POSITION_EVENT_VALUE_UNCHANGED ? start.y : y,
z == VN_POSITION_EVENT_VALUE_UNCHANGED ? start.z : z
);
if(duration > 0) {
animation.clear();
animation.addKeyframe(0, start);
animation.addKeyframe(duration, destination);
animation.callback = [&](glm::vec3 v){
this->item->transform.setLocalPosition(v);
};
useEvent([&]() {
this->next();
}, animation.event2AnimationEnd);
useEvent([&](float_t delta) {
animation.tick(delta);
}, getScene()->eventSceneUpdate);
} else {
this->item->transform.setLocalPosition(destination);
this->next();
}
}
};
}

View File

@ -39,8 +39,9 @@ namespace Dawn {
* @param args Arguments for this event to pass to the listeners.
*/
void invoke(A... args) {
auto it = this->_eventListeners.begin();
while(it != this->_eventListeners.end()) {
auto copy = this->_eventListeners;
auto it = copy.begin();
while(it != copy.end()) {
it->listener(args...);
++it;
}

View File

@ -9,6 +9,7 @@
#include "prefabs/SimpleSpinningCubePrefab.hpp"
#include "games/vn/components/VNManager.hpp"
#include "games/vn/events/VNDummyEvent.hpp"
#include "games/vn/events/VNPositionEvent.hpp"
namespace Dawn {
class HelloWorldScene : public Scene {
@ -29,7 +30,14 @@ namespace Dawn {
auto vnManager = vnItem->addComponent<VNManager>();
auto eventTest = vnManager->createEvent<VNDummyEvent>();
auto positionEvent = vnManager->createEvent<VNPositionEvent>();
positionEvent->x = 2.0f;
positionEvent->item = cube;
positionEvent->duration = 3.0f;
eventTest
->then(positionEvent)
->then(vnManager->createEvent<VNDummyEvent>())
->then(vnManager->createEvent<VNDummyEvent>())
;