From 2b1b25806596e0549e26909cdb787abb5207258d Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 18 Jan 2023 23:53:39 -0800 Subject: [PATCH] Example character level animations. --- .../display/animation/SimpleAnimation.hpp | 36 ++++++++++ .../animation/SimpleCallbackAnimation.hpp | 51 ++++++++++++++ .../display/AnimationController.cpp | 12 +++- .../display/AnimationController.hpp | 5 +- .../components/VisualNovelCharacter.cpp | 16 ++++- .../components/VisualNovelCharacter.hpp | 8 +++ src/dawn/visualnovel/events/CMakeLists.txt | 9 ++- .../events/VisualNovelFadeEvent.cpp | 2 +- .../events/VisualNovelFadeEvent.hpp | 2 +- .../events/animation/CMakeLists.txt | 10 +++ .../VisualNovelAnimationEvent.cpp | 0 .../VisualNovelAnimationEvent.hpp | 0 .../VisualNovelSimpleAnimationEvent.hpp | 0 ...isualNovelSimpleCallbackAnimationEvent.hpp | 24 +++++++ .../events/characters/CMakeLists.txt | 10 +++ .../VisualNovelFadeCharacterEvent.cpp | 29 ++++++++ .../VisualNovelFadeCharacterEvent.hpp | 24 +++++++ .../visualnovel/events/timing/CMakeLists.txt | 11 ++++ .../events/timing/VisualNovelBatchEvent.cpp | 66 +++++++++++++++++++ .../events/timing/VisualNovelBatchEvent.hpp | 27 ++++++++ .../{ => timing}/VisualNovelPauseEvent.cpp | 0 .../{ => timing}/VisualNovelPauseEvent.hpp | 0 src/dawn/visualnovel/scene/SimpleVNScene.hpp | 2 +- .../scene/components/audio/AudioSource.cpp | 2 +- .../shader/SimpleTexturedShaderInterface.cpp | 4 ++ .../shader/SimpleTexturedShaderInterface.hpp | 7 ++ src/dawnpokergame/CMakeLists.txt | 4 +- .../prefabs/characters/DeathPrefab.hpp | 23 ++++--- src/dawnpokergame/scenes/Scene_1.hpp | 48 ++++++++------ 29 files changed, 388 insertions(+), 44 deletions(-) create mode 100644 src/dawn/display/animation/SimpleCallbackAnimation.hpp create mode 100644 src/dawn/visualnovel/events/animation/CMakeLists.txt rename src/dawn/visualnovel/events/{ => animation}/VisualNovelAnimationEvent.cpp (100%) rename src/dawn/visualnovel/events/{ => animation}/VisualNovelAnimationEvent.hpp (100%) rename src/dawn/visualnovel/events/{ => animation}/VisualNovelSimpleAnimationEvent.hpp (100%) create mode 100644 src/dawn/visualnovel/events/animation/VisualNovelSimpleCallbackAnimationEvent.hpp create mode 100644 src/dawn/visualnovel/events/characters/CMakeLists.txt create mode 100644 src/dawn/visualnovel/events/characters/VisualNovelFadeCharacterEvent.cpp create mode 100644 src/dawn/visualnovel/events/characters/VisualNovelFadeCharacterEvent.hpp create mode 100644 src/dawn/visualnovel/events/timing/CMakeLists.txt create mode 100644 src/dawn/visualnovel/events/timing/VisualNovelBatchEvent.cpp create mode 100644 src/dawn/visualnovel/events/timing/VisualNovelBatchEvent.hpp rename src/dawn/visualnovel/events/{ => timing}/VisualNovelPauseEvent.cpp (100%) rename src/dawn/visualnovel/events/{ => timing}/VisualNovelPauseEvent.hpp (100%) diff --git a/src/dawn/display/animation/SimpleAnimation.hpp b/src/dawn/display/animation/SimpleAnimation.hpp index 297bd3c4..2917f284 100644 --- a/src/dawn/display/animation/SimpleAnimation.hpp +++ b/src/dawn/display/animation/SimpleAnimation.hpp @@ -15,12 +15,27 @@ namespace Dawn { template struct SimpleAnimation : public Animation { + protected: + /** + * Function for subclasses to be "notified" when the value has been + * modified. + */ + virtual void onValueModified() { + + } + public: easefunction_t *easing = &easeLinear; T *modifies; std::vector> keyframes; + /** + * Constructs a new Simple Animation instance. + * + * @param modifies Pointer to the value that will be modified. + */ SimpleAnimation(T *modifies) { + assertNotNull(modifies); this->modifies = modifies; } @@ -31,6 +46,8 @@ namespace Dawn { * @param value Value at this given time. */ void addKeyframe(float_t time, T value) { + assertTrue(time >= 0); + struct SimpleKeyframe keyframe; keyframe.time = time; keyframe.value = value; @@ -83,6 +100,17 @@ namespace Dawn { this->addSequentialKeyframes(0, frameTime, start, end, 1); } + /** + * Immediately sets the value, bypassing keyframes and ticks. Useful for + * setting an initial value. + * + * @param value Value to set. + */ + void setValue(T value) { + *modifies = value; + this->onValueModified(); + } + void tick(float_t delta) override { if(this->finished) return; @@ -106,6 +134,7 @@ namespace Dawn { if(keyframeCurrent != nullptr && keyframeNext == nullptr) { // "End of animation" *this->modifies = keyframeCurrent->value; + this->onValueModified(); } else if(keyframeNext != nullptr) { T oldValue; float_t oldTime; @@ -127,6 +156,13 @@ namespace Dawn { *this->modifies = oldValue + ( (keyframeNext->value - oldValue) * keyframeDelta ); + this->onValueModified(); + } + + // First possible frame? I think this can be done cleaner + if(this->time == 0 && keyframeCurrent->time == 0) { + *this->modifies = keyframeCurrent->value; + this->onValueModified(); } // Update time. diff --git a/src/dawn/display/animation/SimpleCallbackAnimation.hpp b/src/dawn/display/animation/SimpleCallbackAnimation.hpp new file mode 100644 index 00000000..8c15b5d4 --- /dev/null +++ b/src/dawn/display/animation/SimpleCallbackAnimation.hpp @@ -0,0 +1,51 @@ +// 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 + struct SimpleCallbackAnimation : public SimpleAnimation { + protected: + I *instance; + void (I::*callback)(T arg); + T value; + + /** + * Internally invoke the function that this animation is owning. + */ + void invoke() { + assertNotNull(this->instance); + ((*this->instance).*(this->callback))(this->value); + } + + void onValueModified() override { + SimpleAnimation::onValueModified(); + this->invoke(); + } + + public: + /** + * Construct a new Simple Function Animation object + */ + SimpleCallbackAnimation() : + SimpleAnimation(&value) + { + } + + /** + * Sets the callback for the animation to use. + * + * @param instance Instance of the object that has the callback. + * @param callback Callback method to be invoked. + */ + void setCallback(I *instance, void (I::*callback)(T arg)) { + assertNotNull(instance); + this->instance = instance; + this->callback = callback; + } + }; +} \ No newline at end of file diff --git a/src/dawn/scene/components/display/AnimationController.cpp b/src/dawn/scene/components/display/AnimationController.cpp index efec17da..76948266 100644 --- a/src/dawn/scene/components/display/AnimationController.cpp +++ b/src/dawn/scene/components/display/AnimationController.cpp @@ -15,9 +15,17 @@ AnimationController::AnimationController(SceneItem *item) : } +void AnimationController::addAnimation(Animation *animation) { + assertNotNull(animation); + this->animations.push_back(animation); +} + void AnimationController::onSceneUpdate() { - if(this->animation == nullptr) return; - this->animation->tick(this->getGame()->timeManager.delta); + auto it = this->animations.begin(); + while(it != this->animations.end()) { + (*it)->tick(this->getGame()->timeManager.delta); + ++it; + } } void AnimationController::onStart() { diff --git a/src/dawn/scene/components/display/AnimationController.hpp b/src/dawn/scene/components/display/AnimationController.hpp index a8af9bf3..c138482c 100644 --- a/src/dawn/scene/components/display/AnimationController.hpp +++ b/src/dawn/scene/components/display/AnimationController.hpp @@ -10,13 +10,14 @@ namespace Dawn { class AnimationController : public SceneItemComponent { private: + std::vector animations; void onSceneUpdate(); public: - Animation *animation = nullptr; - AnimationController(SceneItem *item); + void addAnimation(Animation *animation); + void onStart() override; void onDispose() override; }; diff --git a/src/dawn/visualnovel/components/VisualNovelCharacter.cpp b/src/dawn/visualnovel/components/VisualNovelCharacter.cpp index 5ab7a711..a43274f8 100644 --- a/src/dawn/visualnovel/components/VisualNovelCharacter.cpp +++ b/src/dawn/visualnovel/components/VisualNovelCharacter.cpp @@ -10,5 +10,19 @@ using namespace Dawn; VisualNovelCharacter::VisualNovelCharacter(SceneItem *item) : SceneItemComponent(item) { - +} + +void VisualNovelCharacter::setOpacity(float_t opacity) { + auto interface = this->item->getComponent(); + assertNotNull(interface); + auto color = interface->getColor(); + color.a = opacity; + interface->setColor(color); +} + +float_t VisualNovelCharacter::getOpacity() { + auto interface = this->item->getComponent(); + assertNotNull(interface); + auto color = interface->getColor(); + return color.a; } \ No newline at end of file diff --git a/src/dawn/visualnovel/components/VisualNovelCharacter.hpp b/src/dawn/visualnovel/components/VisualNovelCharacter.hpp index e5f7b3cd..d3bd243a 100644 --- a/src/dawn/visualnovel/components/VisualNovelCharacter.hpp +++ b/src/dawn/visualnovel/components/VisualNovelCharacter.hpp @@ -5,10 +5,12 @@ #pragma once #include "scene/SceneItemComponent.hpp" +#include "scene/components/display/shader/SimpleTexturedShaderInterface.hpp" namespace Dawn { class VisualNovelCharacter : public SceneItemComponent { protected: + SimpleTexturedShaderInterface *shaderInterface = nullptr; public: std::string nameKey = "character.unknown"; @@ -20,5 +22,11 @@ namespace Dawn { * @param item Item that this component belongs to. */ VisualNovelCharacter(SceneItem *item); + + SimpleTexturedShaderInterface * getShaderInterface(); + + void setOpacity(float_t opacity); + + float_t getOpacity(); }; } \ No newline at end of file diff --git a/src/dawn/visualnovel/events/CMakeLists.txt b/src/dawn/visualnovel/events/CMakeLists.txt index c3a8c6b5..a4129f27 100644 --- a/src/dawn/visualnovel/events/CMakeLists.txt +++ b/src/dawn/visualnovel/events/CMakeLists.txt @@ -6,9 +6,12 @@ # Sources target_sources(${DAWN_TARGET_NAME} PRIVATE - VisualNovelAnimationEvent.cpp VisualNovelFadeEvent.cpp - VisualNovelPauseEvent.cpp VisualNovelTextboxEvent.cpp VisualNovelChangeSimpleBackgroundEvent.cpp -) \ No newline at end of file +) + +# Subdirs +add_subdirectory(animation) +add_subdirectory(characters) +add_subdirectory(timing) \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelFadeEvent.cpp b/src/dawn/visualnovel/events/VisualNovelFadeEvent.cpp index defae717..3ffdf18b 100644 --- a/src/dawn/visualnovel/events/VisualNovelFadeEvent.cpp +++ b/src/dawn/visualnovel/events/VisualNovelFadeEvent.cpp @@ -19,7 +19,7 @@ VisualNovelFadeEvent::VisualNovelFadeEvent( this->duration = duration; this->simpleAnimation.easing = ease; } - + void VisualNovelFadeEvent::onStart(IVisualNovelEvent *previous) { VisualNovelSimpleAnimationEvent::onStart(previous); diff --git a/src/dawn/visualnovel/events/VisualNovelFadeEvent.hpp b/src/dawn/visualnovel/events/VisualNovelFadeEvent.hpp index b6a57800..4939a21e 100644 --- a/src/dawn/visualnovel/events/VisualNovelFadeEvent.hpp +++ b/src/dawn/visualnovel/events/VisualNovelFadeEvent.hpp @@ -4,7 +4,7 @@ // https://opensource.org/licenses/MIT #pragma once -#include "VisualNovelSimpleAnimationEvent.hpp" +#include "visualnovel/events/animation/VisualNovelSimpleAnimationEvent.hpp" namespace Dawn { class VisualNovelFadeEvent : public VisualNovelSimpleAnimationEvent { diff --git a/src/dawn/visualnovel/events/animation/CMakeLists.txt b/src/dawn/visualnovel/events/animation/CMakeLists.txt new file mode 100644 index 00000000..73cd7e52 --- /dev/null +++ b/src/dawn/visualnovel/events/animation/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2022 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + VisualNovelAnimationEvent.cpp +) \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelAnimationEvent.cpp b/src/dawn/visualnovel/events/animation/VisualNovelAnimationEvent.cpp similarity index 100% rename from src/dawn/visualnovel/events/VisualNovelAnimationEvent.cpp rename to src/dawn/visualnovel/events/animation/VisualNovelAnimationEvent.cpp diff --git a/src/dawn/visualnovel/events/VisualNovelAnimationEvent.hpp b/src/dawn/visualnovel/events/animation/VisualNovelAnimationEvent.hpp similarity index 100% rename from src/dawn/visualnovel/events/VisualNovelAnimationEvent.hpp rename to src/dawn/visualnovel/events/animation/VisualNovelAnimationEvent.hpp diff --git a/src/dawn/visualnovel/events/VisualNovelSimpleAnimationEvent.hpp b/src/dawn/visualnovel/events/animation/VisualNovelSimpleAnimationEvent.hpp similarity index 100% rename from src/dawn/visualnovel/events/VisualNovelSimpleAnimationEvent.hpp rename to src/dawn/visualnovel/events/animation/VisualNovelSimpleAnimationEvent.hpp diff --git a/src/dawn/visualnovel/events/animation/VisualNovelSimpleCallbackAnimationEvent.hpp b/src/dawn/visualnovel/events/animation/VisualNovelSimpleCallbackAnimationEvent.hpp new file mode 100644 index 00000000..658b77a3 --- /dev/null +++ b/src/dawn/visualnovel/events/animation/VisualNovelSimpleCallbackAnimationEvent.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "VisualNovelAnimationEvent.hpp" +#include "display/animation/SimpleCallbackAnimation.hpp" + +namespace Dawn { + template + class VisualNovelSimpleCallbackAnimationEvent : + public VisualNovelAnimationEvent + { + public: + struct SimpleCallbackAnimation callbackAnimation; + + VisualNovelSimpleCallbackAnimationEvent(VisualNovelManager *man) : + VisualNovelAnimationEvent(man) + { + this->animation = &callbackAnimation; + } + }; +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/characters/CMakeLists.txt b/src/dawn/visualnovel/events/characters/CMakeLists.txt new file mode 100644 index 00000000..cc223e7d --- /dev/null +++ b/src/dawn/visualnovel/events/characters/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2022 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + VisualNovelFadeCharacterEvent.cpp +) \ No newline at end of file diff --git a/src/dawn/visualnovel/events/characters/VisualNovelFadeCharacterEvent.cpp b/src/dawn/visualnovel/events/characters/VisualNovelFadeCharacterEvent.cpp new file mode 100644 index 00000000..7ca22dce --- /dev/null +++ b/src/dawn/visualnovel/events/characters/VisualNovelFadeCharacterEvent.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "VisualNovelFadeCharacterEvent.hpp" + +using namespace Dawn; + +VisualNovelFadeCharacterEvent::VisualNovelFadeCharacterEvent( + VisualNovelManager *man, + VisualNovelCharacter *character, + bool_t fadeIn, + easefunction_t *ease, + float_t duration +) : VisualNovelSimpleCallbackAnimationEvent(man) +{ + this->callbackAnimation.easing = ease; + this->callbackAnimation.setCallback( + character, &VisualNovelCharacter::setOpacity + ); + if(fadeIn) { + this->callbackAnimation.addKeyframe(0.0f, 0.0f); + this->callbackAnimation.addKeyframe(duration, 1.0f); + } else { + this->callbackAnimation.addKeyframe(0.0f, 1.0f); + this->callbackAnimation.addKeyframe(duration, 0.0f); + } +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/characters/VisualNovelFadeCharacterEvent.hpp b/src/dawn/visualnovel/events/characters/VisualNovelFadeCharacterEvent.hpp new file mode 100644 index 00000000..8b8b9480 --- /dev/null +++ b/src/dawn/visualnovel/events/characters/VisualNovelFadeCharacterEvent.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "visualnovel/events/animation/VisualNovelSimpleCallbackAnimationEvent.hpp" +#include "visualnovel/components/VisualNovelCharacter.hpp" +#include "scene/components/display/Material.hpp" + +namespace Dawn { + class VisualNovelFadeCharacterEvent : + public VisualNovelSimpleCallbackAnimationEvent + { + public: + VisualNovelFadeCharacterEvent( + VisualNovelManager *man, + VisualNovelCharacter *character, + bool_t fadeIn, + easefunction_t *ease, + float_t duration + ); + }; +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/timing/CMakeLists.txt b/src/dawn/visualnovel/events/timing/CMakeLists.txt new file mode 100644 index 00000000..c633123e --- /dev/null +++ b/src/dawn/visualnovel/events/timing/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2022 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + VisualNovelBatchEvent.cpp + VisualNovelPauseEvent.cpp +) \ No newline at end of file diff --git a/src/dawn/visualnovel/events/timing/VisualNovelBatchEvent.cpp b/src/dawn/visualnovel/events/timing/VisualNovelBatchEvent.cpp new file mode 100644 index 00000000..0c4e26e9 --- /dev/null +++ b/src/dawn/visualnovel/events/timing/VisualNovelBatchEvent.cpp @@ -0,0 +1,66 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "VisualNovelBatchEvent.hpp" + +using namespace Dawn; + +VisualNovelBatchEvent::VisualNovelBatchEvent( + VisualNovelManager *man, + std::vector events +) : IVisualNovelEvent(man) { + this->activeEvents = events; +} + +void VisualNovelBatchEvent::onStart(IVisualNovelEvent *previous) { + auto it = this->activeEvents.begin(); + while(it != this->activeEvents.end()) { + auto evt = *it; + evt->start(previous); + ++it; + } +} + +bool_t VisualNovelBatchEvent::onUpdate() { + bool_t result; + auto it = this->activeEvents.begin(); + while(it != this->activeEvents.end()) { + auto evt = *it; + result = evt->update(); + if(result) { + ++it; + continue; + } + + auto subNext = evt->end(); + + // In future I may remove this and instead immediately queue the next thing. + assertNull(subNext); + + it = this->activeEvents.erase(it); + this->inactiveEvents.push_back(evt); + } + return this->activeEvents.size() > 0; +} + +void VisualNovelBatchEvent::onEnd() { + +} + +VisualNovelBatchEvent::~VisualNovelBatchEvent() { + auto itActive = this->activeEvents.begin(); + while(itActive != this->activeEvents.end()) { + auto evt = *itActive; + delete evt; + ++itActive; + } + + auto itInactive = this->inactiveEvents.begin(); + while(itInactive != this->inactiveEvents.end()) { + auto evt = *itInactive; + delete evt; + ++itInactive; + } +} diff --git a/src/dawn/visualnovel/events/timing/VisualNovelBatchEvent.hpp b/src/dawn/visualnovel/events/timing/VisualNovelBatchEvent.hpp new file mode 100644 index 00000000..6699052e --- /dev/null +++ b/src/dawn/visualnovel/events/timing/VisualNovelBatchEvent.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "visualnovel/VisualNovelManager.hpp" + +namespace Dawn { + class VisualNovelBatchEvent : public IVisualNovelEvent { + protected: + std::vector activeEvents; + std::vector inactiveEvents; + + void onStart(IVisualNovelEvent *previous) override; + bool_t onUpdate() override; + void onEnd() override; + + public: + VisualNovelBatchEvent( + VisualNovelManager *man, + std::vector events + ); + + ~VisualNovelBatchEvent(); + }; +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelPauseEvent.cpp b/src/dawn/visualnovel/events/timing/VisualNovelPauseEvent.cpp similarity index 100% rename from src/dawn/visualnovel/events/VisualNovelPauseEvent.cpp rename to src/dawn/visualnovel/events/timing/VisualNovelPauseEvent.cpp diff --git a/src/dawn/visualnovel/events/VisualNovelPauseEvent.hpp b/src/dawn/visualnovel/events/timing/VisualNovelPauseEvent.hpp similarity index 100% rename from src/dawn/visualnovel/events/VisualNovelPauseEvent.hpp rename to src/dawn/visualnovel/events/timing/VisualNovelPauseEvent.hpp diff --git a/src/dawn/visualnovel/scene/SimpleVNScene.hpp b/src/dawn/visualnovel/scene/SimpleVNScene.hpp index 895e739f..ee36268a 100644 --- a/src/dawn/visualnovel/scene/SimpleVNScene.hpp +++ b/src/dawn/visualnovel/scene/SimpleVNScene.hpp @@ -11,7 +11,7 @@ #include "scene/components/audio/AudioListener.hpp" #include "visualnovel/VisualNovelManager.hpp" #include "visualnovel/events/VisualNovelTextboxEvent.hpp" -#include "visualnovel/events/VisualNovelPauseEvent.hpp" +#include "visualnovel/events/timing/VisualNovelPauseEvent.hpp" #include "visualnovel/events/VisualNovelFadeEvent.hpp" #include "visualnovel/events/VisualNovelCAllbackEvent.hpp" #include "visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp" diff --git a/src/dawnopenal/scene/components/audio/AudioSource.cpp b/src/dawnopenal/scene/components/audio/AudioSource.cpp index 85f03f2b..440aa186 100644 --- a/src/dawnopenal/scene/components/audio/AudioSource.cpp +++ b/src/dawnopenal/scene/components/audio/AudioSource.cpp @@ -95,7 +95,7 @@ void AudioSource::onStart() { alGenBuffers((ALuint)AUDIO_SOURCE_BUFFER_COUNT, this->buffers); // Set up the source positions - glm::vec3 position = this->transform->getLocalPosition(); + glm::vec3 position = this->transform->getWorldPosition(); alSource3f(this->source, AL_POSITION, position.x, position.y, position.z); alSource3f(this->source, AL_VELOCITY, 0, 0, 0); diff --git a/src/dawnopengl/scene/components/display/shader/SimpleTexturedShaderInterface.cpp b/src/dawnopengl/scene/components/display/shader/SimpleTexturedShaderInterface.cpp index e000ecb2..92846719 100644 --- a/src/dawnopengl/scene/components/display/shader/SimpleTexturedShaderInterface.cpp +++ b/src/dawnopengl/scene/components/display/shader/SimpleTexturedShaderInterface.cpp @@ -19,4 +19,8 @@ void SimpleTexturedShaderInterface::setTexture(Texture *texture) { void SimpleTexturedShaderInterface::setColor(struct Color color) { this->getMaterial()->colorValues[this->getShader()->paramColor] = color; +} + +struct Color SimpleTexturedShaderInterface::getColor() { + return this->getMaterial()->colorValues[this->getShader()->paramColor]; } \ No newline at end of file diff --git a/src/dawnopengl/scene/components/display/shader/SimpleTexturedShaderInterface.hpp b/src/dawnopengl/scene/components/display/shader/SimpleTexturedShaderInterface.hpp index 3cc62532..ee9162db 100644 --- a/src/dawnopengl/scene/components/display/shader/SimpleTexturedShaderInterface.hpp +++ b/src/dawnopengl/scene/components/display/shader/SimpleTexturedShaderInterface.hpp @@ -32,5 +32,12 @@ namespace Dawn { * @param color Color to be used. */ void setColor(struct Color color); + + /** + * Returns the current color from the shader. + * + * @return Current color. + */ + struct Color getColor(); }; } \ No newline at end of file diff --git a/src/dawnpokergame/CMakeLists.txt b/src/dawnpokergame/CMakeLists.txt index 70b1f645..2845dc1a 100644 --- a/src/dawnpokergame/CMakeLists.txt +++ b/src/dawnpokergame/CMakeLists.txt @@ -32,11 +32,11 @@ tool_texture(texture_test texture_test.png) tool_language(language_en ${DIR_GAME_ASSETS}/locale/en.csv) tool_language(language_jp ${DIR_GAME_ASSETS}/locale/jp.csv) -tool_tileset(tileset_death texture_death ${DIR_GAME_ASSETS}/characters/death/sheet.png 1 2) +tool_tileset(tileset_death texture_death ${DIR_GAME_ASSETS}/characters/death/sheet.png 1 3) tool_truetype(truetype_alice ${DIR_GAME_ASSETS}/font/Alice-Regular.ttf truetype_alice 2048 2048 120) -tool_audio(audio_test borrowed/sample.wav) +tool_audio(audio_test borrowed/sample_long.wav) add_dependencies(${DAWN_TARGET_NAME} language_en diff --git a/src/dawnpokergame/prefabs/characters/DeathPrefab.hpp b/src/dawnpokergame/prefabs/characters/DeathPrefab.hpp index 5767a8fe..81009475 100644 --- a/src/dawnpokergame/prefabs/characters/DeathPrefab.hpp +++ b/src/dawnpokergame/prefabs/characters/DeathPrefab.hpp @@ -17,6 +17,7 @@ namespace Dawn { public: VisualNovelCharacter *vnCharacter; SimpleTexturedShaderInterface *shaderInterface; + AnimationController *animation; static std::vector prefabAssets(AssetManager *assMan) { return std::vector{ @@ -25,7 +26,10 @@ namespace Dawn { }; } - DeathPrefab(Scene *scene, sceneitemid_t id) : SceneItemPrefab(scene, id){} + DeathPrefab(Scene *scene, sceneitemid_t id) : SceneItemPrefab(scene, id) + { + + } void prefabInit(AssetManager *man) override { auto textureAsset = man->get("texture_death"); @@ -34,17 +38,18 @@ namespace Dawn { auto meshRenderer = this->addComponent(); auto material = this->addComponent(); auto meshHost = this->addComponent(); - auto animation = this->addComponent(); - - auto tiledSprite = this->addComponent(); - tiledSprite->setTilesetAndSize(&tilesetAsset->tileset); - tiledSprite->setTile(0); - - vnCharacter = this->addComponent(); - vnCharacter->nameKey = "character.death.name"; shaderInterface = this->addComponent(); shaderInterface->setTexture(&textureAsset->texture); + + vnCharacter = this->addComponent(); + vnCharacter->nameKey = "character.death.name"; + + animation = this->addComponent(); + + auto tiledSprite = this->addComponent(); + tiledSprite->setTilesetAndSize(&tilesetAsset->tileset); + tiledSprite->setTile(0); this->transform.setLocalPosition(glm::vec3(0, 0, 0)); } diff --git a/src/dawnpokergame/scenes/Scene_1.hpp b/src/dawnpokergame/scenes/Scene_1.hpp index 77a86439..6e436537 100644 --- a/src/dawnpokergame/scenes/Scene_1.hpp +++ b/src/dawnpokergame/scenes/Scene_1.hpp @@ -9,34 +9,23 @@ #include "prefabs/characters/DeathPrefab.hpp" #include "scene/components/audio/AudioListener.hpp" #include "scene/components/audio/AudioSource.hpp" +#include "visualnovel/events/characters/VisualNovelFadeCharacterEvent.hpp" +#include "visualnovel/events/timing/VisualNovelBatchEvent.hpp" namespace Dawn { class Scene_1 : public PixelVNScene { protected: DeathPrefab *death; - AudioSource *source; - - void onFinished() { - std::cout << "Finished" << std::endl; - source->rewind(); - } + DeathPrefab *death2; void vnStage() override { PixelVNScene::vnStage(); this->death = DeathPrefab::create(this); - // this->death->vnCharacter.setOpacity(0); + this->death->vnCharacter->setOpacity(0); - auto sourceItem = this->createSceneItem(); - source = sourceItem->addComponent(); - source->transform->setLocalPosition(glm::vec3(1, 0, 0)); - source->eventFinished.addListener(this, &Scene_1::onFinished); - - auto audio = this->game->assetManager.get("audio_test"); - - source->setAudioData(audio); - source->loop = true; - source->state = AUDIO_SOURCE_STATE_PLAYING; + this->death2 = DeathPrefab::create(this); + this->death2->transform.setLocalPosition(glm::vec3(100, 0, 0)); } void onSceneEnded() { @@ -51,12 +40,29 @@ namespace Dawn { IVisualNovelEvent * getVNEvent() override { auto start = new VisualNovelPauseEvent(vnManager, 1.0f); - start - // ->then(new VisualNovelTextboxEvent(vnManager, nullptr, "scene.1.1")) - // ->then(new VisualNovelCallbackEvent(vnManager, this, &Scene_1::onSceneEnded)) + ->then(new VisualNovelBatchEvent( + vnManager, + std::vector{ + new VisualNovelFadeCharacterEvent( + vnManager, + this->death->vnCharacter, + true, + &easeLinear, + 2.0f + ), + new VisualNovelFadeCharacterEvent( + vnManager, + this->death2->vnCharacter, + false, + &easeLinear, + 2.0f + ) + } + )) + ->then(new VisualNovelTextboxEvent(vnManager, nullptr, "scene.1.1")) + ->then(new VisualNovelCallbackEvent(vnManager, this, &Scene_1::onSceneEnded)) ; - return start; }