diff --git a/.gitignore b/.gitignore index 80f9c5d0..a0b7b544 100644 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,6 @@ node_modules yarn.lock *.log -assets/borrowed \ No newline at end of file +assets/borrowed + +.~lock* \ No newline at end of file diff --git a/src/dawn/asset/assets/TilesetAsset.hpp b/src/dawn/asset/assets/TilesetAsset.hpp index 1d36f6d0..d771a8d0 100644 --- a/src/dawn/asset/assets/TilesetAsset.hpp +++ b/src/dawn/asset/assets/TilesetAsset.hpp @@ -16,7 +16,13 @@ namespace Dawn { public: struct TilesetGrid tileset; - + + /** + * Creates a new TilesetAsset Loader. + * + * @param assMan Asset Manager this tileset asset belongs to. + * @param name Tileset asset name. + */ TilesetAsset(AssetManager *assMan, std::string name); void updateSync() override; diff --git a/src/dawn/display/animation/Animation.cpp b/src/dawn/display/animation/Animation.cpp new file mode 100644 index 00000000..8f630258 --- /dev/null +++ b/src/dawn/display/animation/Animation.cpp @@ -0,0 +1,17 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "Animation.hpp" + +using namespace Dawn; + +void Animation::restart() { + this->time = 0; + this->finished = false; +} + +void Animation::clear() { + this->duration = 0; +} \ No newline at end of file diff --git a/src/dawn/display/animation/Animation.hpp b/src/dawn/display/animation/Animation.hpp index d700091e..fb155b91 100644 --- a/src/dawn/display/animation/Animation.hpp +++ b/src/dawn/display/animation/Animation.hpp @@ -17,21 +17,24 @@ namespace Dawn { float_t duration = 0; Event<> eventAnimationEnd; + /** + * Ticks the animation along. Delta is whatever you want to update the + * animation by (in seconds). Animations can overshoot if necessary and + * will not be clamped (by default). Subclasses may interpret ticks in + * different ways. + * + * @param delta Time delta (in seconds) to tick the animaiton by. + */ virtual void tick(float_t delta) = 0; /** * Restart a running animation. */ - virtual void restart() { - this->time = 0; - this->finished = false; - } + virtual void restart(); /** * Clears an animaton of all its animation items and keyframes. */ - virtual void clear() { - this->duration = 0; - } + virtual void clear(); }; } \ No newline at end of file diff --git a/src/dawn/display/animation/CMakeLists.txt b/src/dawn/display/animation/CMakeLists.txt index a4262361..bc1c7a77 100644 --- a/src/dawn/display/animation/CMakeLists.txt +++ b/src/dawn/display/animation/CMakeLists.txt @@ -4,7 +4,8 @@ # https://opensource.org/licenses/MIT # Sources -# target_sources(${DAWN_TARGET_NAME} -# PRIVATE -# Animation.cpp -# ) \ No newline at end of file +target_sources(${DAWN_TARGET_NAME} + PRIVATE + Animation.cpp + TiledSpriteAnimation.cpp +) \ No newline at end of file diff --git a/src/dawn/display/animation/SimpleAnimation.hpp b/src/dawn/display/animation/SimpleAnimation.hpp index af18c763..297bd3c4 100644 --- a/src/dawn/display/animation/SimpleAnimation.hpp +++ b/src/dawn/display/animation/SimpleAnimation.hpp @@ -24,6 +24,12 @@ namespace Dawn { this->modifies = modifies; } + /** + * Adds a keyframe that will be slerped to at a given time. + * + * @param time Time the keyframe occurs. + * @param value Value at this given time. + */ void addKeyframe(float_t time, T value) { struct SimpleKeyframe keyframe; keyframe.time = time; @@ -33,6 +39,22 @@ namespace Dawn { this->keyframes.push_back(keyframe); } + /** + * Quickly add a series of keyframes. For example, if you want to have a + * keyframe series of; + * [ 1, 3, 5, 7, 9 ] + * + * And occur at times + * [ 0, 2, 4, 6, 8 ] + * + * You would pass frameTime as 2, and step as 2. + * + * @param startTime When the first keyframe occurs. + * @param frameTime At what rate do keyframes occur. + * @param start Initial value (the value at startTime). + * @param end The end value (for the last keyframe). + * @param step How to step the value. + */ void addSequentialKeyframes( float_t startTime, float_t frameTime, @@ -49,6 +71,14 @@ namespace Dawn { } } + /** + * Shorthand addSequentialKeyframes, assumes a step of 1 and a startTime + * of 0. + * + * @param frameTime Time between frames. + * @param start Initial value. + * @param end End value. + */ void addSequentialKeyframes(float_t frameTime, T start, T end) { this->addSequentialKeyframes(0, frameTime, start, end, 1); } @@ -115,7 +145,7 @@ namespace Dawn { this->finished = true; this->eventAnimationEnd.invoke(); } - + void clear() override { Animation::clear(); this->keyframes.clear(); diff --git a/src/dawn/display/animation/TiledSpriteAnimation.cpp b/src/dawn/display/animation/TiledSpriteAnimation.cpp new file mode 100644 index 00000000..a4722fad --- /dev/null +++ b/src/dawn/display/animation/TiledSpriteAnimation.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "TiledSpriteAnimation.hpp" + +using namespace Dawn; + +TiledSpriteAnimation::TiledSpriteAnimation(TiledSprite *sprite) : + SimpleAnimation(&frame), + sprite(sprite) +{ +} + +void TiledSpriteAnimation::tick(float_t delta) { + SimpleAnimation::tick(delta); + this->sprite->setTile(frame); +} \ No newline at end of file diff --git a/src/dawn/display/animation/TiledSpriteAnimation.hpp b/src/dawn/display/animation/TiledSpriteAnimation.hpp index 9a172939..db5dd507 100644 --- a/src/dawn/display/animation/TiledSpriteAnimation.hpp +++ b/src/dawn/display/animation/TiledSpriteAnimation.hpp @@ -13,15 +13,13 @@ namespace Dawn { int32_t frame = 0; TiledSprite *sprite = nullptr; - TiledSpriteAnimation(TiledSprite *sprite) : - SimpleAnimation(&frame), - sprite(sprite) - { - } + /** + * Construct a new Tiled Sprite Animation. + * + * @param sprite Sprite that this animation will control. + */ + TiledSpriteAnimation(TiledSprite *sprite); - void tick(float_t delta) override { - SimpleAnimation::tick(delta); - this->sprite->setTile(frame); - } + void tick(float_t delta) override; }; } \ No newline at end of file diff --git a/src/dawn/scene/components/display/TiledSprite.hpp b/src/dawn/scene/components/display/TiledSprite.hpp index 92edd8a7..e61aa4c7 100644 --- a/src/dawn/scene/components/display/TiledSprite.hpp +++ b/src/dawn/scene/components/display/TiledSprite.hpp @@ -29,15 +29,60 @@ namespace Dawn { public: TiledSprite(SceneItem *item); - void setTileset(Tileset *tileset); - void setTilesetAndSize(TilesetGrid *gridTileset, glm::vec2 center); - void setTilesetAndSize(TilesetGrid *gridTileset); - void setTile(int32_t tile); - void setFlippedState(flag_t flippedState); - void setSize(glm::vec2 size, glm::vec2 center); - void setSize(glm::vec2 size); - std::vector getDependencies() override; void onStart() override; + + /** + * Sets which tileset to use for this sprite. + * + * @param tileset Tileset to use. + */ + void setTileset(Tileset *tileset); + + /** + * Sets the tileset for the sprite, and autosizes the sprite based on + * this tileset. + * + * @param gridTileset Tileset to use. + * @param center The center offset of the sprite. + */ + void setTilesetAndSize(TilesetGrid *gridTileset, glm::vec2 center); + + /** + * Sets the tileset for the sprite, and autosizes the sprite based on + * this tileset. This will put the sprite centered on its origin. + * + * @param gridTileset Tileset to use. + */ + void setTilesetAndSize(TilesetGrid *gridTileset); + + /** + * Updates the selected tile. + * + * @param tile Tile to use. + */ + void setTile(int32_t tile); + + /** + * Adjust how the sprite is flippxed. + * + * @param flippedState Flipped axis flags. + */ + void setFlippedState(flag_t flippedState); + + /** + * Sets the dimensions of this tiled sprite. + * + * @param size Size of the sprite. + * @param center Negative center offset. + */ + void setSize(glm::vec2 size, glm::vec2 center); + + /** + * Sets the size of this sprite. This will center the sprite on its origin + * + * @param size Size of the sprite. + */ + void setSize(glm::vec2 size); }; } \ No newline at end of file diff --git a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp index 9c0f9470..08907621 100644 --- a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp +++ b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp @@ -32,7 +32,8 @@ std::vector SimpleVisualNovelBackground::getDependencies(){ void SimpleVisualNovelBackground::setTexture(Texture *texture) { auto param = this->material->getShader()->getParameterByName("u_Text"); this->material->textureValues[param] = texture; - + + // Since we go both negative and positive, actual height is doubled float_t aspect = (float_t)texture->getWidth() / (float_t)texture->getHeight(); float_t height = 0.5f; diff --git a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp index a4aef513..43a70e7e 100644 --- a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp +++ b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp @@ -12,11 +12,32 @@ namespace Dawn { Material *material; MeshHost *meshHost; + /** + * Create a simple Visual Novel Background prefab. + * + * @param scene Scene to add this background to. + * @return Created background Scene Item. + */ static SimpleVisualNovelBackground * create(Scene *scene); + /** + * Construct a Simple Visual Novel Background. Simple Background is used + * for a quick up and running Visual Novel scene, but does not have any + * special effects or controls beyond updating a texture and mesh. + * + * @param item Scene Item this background belongs to. + */ SimpleVisualNovelBackground(SceneItem *item); + std::vector getDependencies() override; void onStart() override; + + /** + * Set the texture for the background. Auto updates the material and the + * dimensions of the internal quad. + * + * @param texture Texture to use. + */ void setTexture(Texture *texture); }; } \ No newline at end of file diff --git a/src/dawnpokergame/CMakeLists.txt b/src/dawnpokergame/CMakeLists.txt index 1716b66e..402ade03 100644 --- a/src/dawnpokergame/CMakeLists.txt +++ b/src/dawnpokergame/CMakeLists.txt @@ -20,6 +20,7 @@ add_subdirectory(game) add_subdirectory(prefabs) add_subdirectory(ui) add_subdirectory(visualnovel) +add_subdirectory(scenes) # Assets tool_texture(texture_test texture_test.png) diff --git a/src/dawnpokergame/prefabs/VNPenny.hpp b/src/dawnpokergame/prefabs/VNPenny.hpp index 630a13ef..c3aa20a0 100644 --- a/src/dawnpokergame/prefabs/VNPenny.hpp +++ b/src/dawnpokergame/prefabs/VNPenny.hpp @@ -25,27 +25,24 @@ namespace Dawn { auto textureAsset = scene->game->assetManager.get("texture_penny"); auto tilesetAsset = scene->game->assetManager.get("tileset_penny"); - // auto meshRenderer = item->addComponent(); - // auto material = item->addComponent(); - // auto meshHost = item->addComponent(); - // auto tiledSprite = item->addComponent(); - // auto animation = item->addComponent(); + auto meshRenderer = item->addComponent(); + auto material = item->addComponent(); + auto meshHost = item->addComponent(); + auto tiledSprite = item->addComponent(); + auto animation = item->addComponent(); auto pokerPlayer = item->addComponent(); - return item; - - // auto param = material->getShader()->getParameterByName("u_Text"); - // material->textureValues[param] = &textureAsset->texture; + auto param = material->getShader()->getParameterByName("u_Text"); + material->textureValues[param] = &textureAsset->texture; - // tiledSprite->setTileset(&tilesetAsset->tileset); - // tiledSprite->setSize(glm::vec2(tilesetAsset->tileset.divX, tilesetAsset->tileset.divY)); + tiledSprite->setTilesetAndSize(&tilesetAsset->tileset); - // auto anim = new TiledSpriteAnimation(tiledSprite); - // anim->addSequentialKeyframes(0.1f, 0, 22); - // anim->loop = true; - // animation->animation = anim; + auto anim = new TiledSpriteAnimation(tiledSprite); + anim->addSequentialKeyframes(0.1f, 0, 22); + anim->loop = true; + animation->animation = anim; - // return item; + return item; } }; } \ No newline at end of file diff --git a/src/dawnpokergame/scenes/CMakeLists.txt b/src/dawnpokergame/scenes/CMakeLists.txt new file mode 100644 index 00000000..7aa8a484 --- /dev/null +++ b/src/dawnpokergame/scenes/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 + SimpleVNScene.cpp +) \ No newline at end of file diff --git a/src/dawnpokergame/scenes/SimpleVNScene.cpp b/src/dawnpokergame/scenes/SimpleVNScene.cpp new file mode 100644 index 00000000..c3b2549e --- /dev/null +++ b/src/dawnpokergame/scenes/SimpleVNScene.cpp @@ -0,0 +1,57 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "SimpleVNScene.hpp" + +using namespace Dawn; + +SimpleVNScene::SimpleVNScene(DawnGame *game) : Scene(game) { + +} + + +std::vector SimpleVNScene::getRequiredAssets() { + auto assMan = &this->game->assetManager; + std::vector assets; + + vectorAppend(&assets, &PokerGameTextbox::getAssets(assMan)); + vectorAppend(&assets, &PokerPlayerDisplay::getAssets(assMan)); + vectorAppend(&assets, &VNPenny::getAssets(assMan)); + + return assets; +} + +void SimpleVNScene::stage() { + // Camera + this->camera = Camera::create(this); + this->camera->transform->lookAtPixelPerfect( + glm::vec3(0, 0, 0), + glm::vec3(0, 0, 0), + 1.0f, + camera->fov + ); + + // UI + this->canvas = UICanvas::createCanvas(this); + this->textbox = PokerGameTextbox::create(canvas); + this->background = SimpleVisualNovelBackground::create(this); + + // VN Manager + auto vnManagerItem = this->createSceneItem(); + this->vnManager = vnManagerItem->addComponent(); + + // Stage VN Items + this->vnStage(); + + // Fader (Drawn over the top of everything else) + this->vnFader = VisualNovelFader::create(canvas); + + // Begin VN. + this->vnManager->setEvent(this->getVNEvent()); +} + +void SimpleVNScene::vnStage() { + +} \ No newline at end of file diff --git a/src/dawnpokergame/scenes/SimpleVNScene.hpp b/src/dawnpokergame/scenes/SimpleVNScene.hpp new file mode 100644 index 00000000..e1548c05 --- /dev/null +++ b/src/dawnpokergame/scenes/SimpleVNScene.hpp @@ -0,0 +1,48 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "scene/Scene.hpp" +#include "game/DawnGame.hpp" +#include "util/array.hpp" +#include "scene/components/Components.hpp" +#include "ui/PokerGameTextbox.hpp" +#include "visualnovel/VisualNovelManager.hpp" +#include "visualnovel/events/VisualNovelTextboxEvent.hpp" +#include "visualnovel/events/VisualNovelPauseEvent.hpp" +#include "visualnovel/events/VisualNovelFadeEvent.hpp" +#include "visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp" +#include "poker/PokerGame.hpp" +#include "visualnovel/events/PokerBetLoopEvent.hpp" +#include "visualnovel/events/PokerInitialEvent.hpp" +#include "ui/PokerPlayerDisplay.hpp" +#include "prefabs/VNPenny.hpp" + +namespace Dawn { + class SimpleVNScene : public Scene { + protected: + Camera *camera = nullptr; + UICanvas *canvas = nullptr; + VisualNovelTextbox *textbox = nullptr; + SimpleVisualNovelBackground *background = nullptr; + VisualNovelFader *vnFader = nullptr; + VisualNovelManager *vnManager = nullptr; + + virtual void vnStage(); + virtual IVisualNovelEvent * getVNEvent() = 0; + + public: + /** + * Constructs a new Simple VN Scene. Custom class that implements the most + * common VN Things. + * + * @param game + */ + SimpleVNScene(DawnGame *game); + + std::vector getRequiredAssets() override; + void stage() override; + }; +} \ No newline at end of file diff --git a/src/dawnpokergame/scenes/TestScene.hpp b/src/dawnpokergame/scenes/TestScene.hpp index e93236f1..1be66994 100644 --- a/src/dawnpokergame/scenes/TestScene.hpp +++ b/src/dawnpokergame/scenes/TestScene.hpp @@ -4,60 +4,13 @@ // https://opensource.org/licenses/MIT #pragma once -#include "scene/Scene.hpp" -#include "game/DawnGame.hpp" -#include "util/array.hpp" -#include "scene/components/Components.hpp" -#include "ui/PokerGameTextbox.hpp" -#include "visualnovel/VisualNovelManager.hpp" -#include "visualnovel/events/VisualNovelTextboxEvent.hpp" -#include "visualnovel/events/VisualNovelPauseEvent.hpp" -#include "visualnovel/events/VisualNovelFadeEvent.hpp" -#include "visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp" -#include "poker/PokerGame.hpp" -#include "visualnovel/events/PokerBetLoopEvent.hpp" -#include "visualnovel/events/PokerInitialEvent.hpp" -#include "ui/PokerPlayerDisplay.hpp" -#include "prefabs/VNPenny.hpp" +#include "SimpleVNScene.hpp" namespace Dawn { - class TestScene : public Scene { - public: - TestScene(DawnGame *game) : Scene(game) { - - } - - std::vector getRequiredAssets() override { - auto assMan = &this->game->assetManager; - std::vector assets; - - vectorAppend(&assets, &PokerGameTextbox::getAssets(assMan)); - vectorAppend(&assets, &PokerPlayerDisplay::getAssets(assMan)); - vectorAppend(&assets, &VNPenny::getAssets(assMan)); - - assets.push_back(assMan->get("texture_tavern_night")); - - return assets; - } - - void stage() override { - // Camera - auto camera = Camera::create(this); - camera->transform->lookAtPixelPerfect( - glm::vec3(0, 0, 0), - glm::vec3(0, 0, 0), - 1.0f, - camera->fov - ); - - // UI - auto canvas = UICanvas::createCanvas(this); - auto textbox = PokerGameTextbox::create(canvas); - auto background = SimpleVisualNovelBackground::create(this); - - // VN Manager - auto vnManagerItem = this->createSceneItem(); - auto vnManager = vnManagerItem->addComponent(); + class TestScene : public SimpleVNScene { + protected: + void vnStage() override { + SimpleVNScene::vnStage(); // Poker Test auto pokerGameItem = this->createSceneItem(); @@ -71,14 +24,17 @@ namespace Dawn { uiPlayer->setPlayer(player->getComponent()); } - auto vnFader = VisualNovelFader::create(canvas); + } + + IVisualNovelEvent * getVNEvent() override { auto texture = this->game->assetManager.get("texture_tavern_night"); - auto betting = vnManager - ->setEvent(new VisualNovelChangeSimpleBackgroundEvent( - vnManager, &texture->texture - )) + auto start = new VisualNovelChangeSimpleBackgroundEvent( + vnManager, &texture->texture + ); + + start ->then(new VisualNovelPauseEvent(vnManager, 1.0f)) ->then(new VisualNovelFadeEvent( vnManager, COLOR_BLACK, false, &easeOutCubic, 1.0f @@ -88,6 +44,21 @@ namespace Dawn { ->then(new VisualNovelTextboxEvent(vnManager, "Game Started")) ->then(new PokerInitialEvent(vnManager)) ; + + return start; + } + + public: + TestScene(DawnGame *game) : SimpleVNScene(game) { + + } + + std::vector getRequiredAssets() override { + auto assMan = &this->game->assetManager; + std::vector assets; + vectorAppend(&assets, &SimpleVNScene::getRequiredAssets()); + assets.push_back(assMan->get("texture_tavern_night")); + return assets; } }; } \ No newline at end of file