Little documentation update

This commit is contained in:
2022-12-14 06:27:10 -08:00
parent 850f4c227d
commit 6404f35b1c
17 changed files with 332 additions and 105 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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();
};
}

View File

@ -4,7 +4,8 @@
# https://opensource.org/licenses/MIT
# Sources
# target_sources(${DAWN_TARGET_NAME}
# PRIVATE
# Animation.cpp
# )
target_sources(${DAWN_TARGET_NAME}
PRIVATE
Animation.cpp
TiledSpriteAnimation.cpp
)

View File

@ -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<T> 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();

View File

@ -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);
}

View File

@ -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;
};
}

View File

@ -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<SceneItemComponent*> 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);
};
}

View File

@ -32,7 +32,8 @@ std::vector<SceneItemComponent*> 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;

View File

@ -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<SceneItemComponent*> 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);
};
}