Updating a few more things to state events, will probably stop here for now and revist the trailing things later.
This commit is contained in:
@ -4,9 +4,7 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "state/State.hpp"
|
||||||
#include "assert/assert.hpp"
|
|
||||||
#include "event/Event.hpp"
|
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class AssetManager;
|
class AssetManager;
|
||||||
@ -18,6 +16,7 @@ namespace Dawn {
|
|||||||
uint8_t state = 0x00;
|
uint8_t state = 0x00;
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
Event<> eventLoaded;
|
Event<> eventLoaded;
|
||||||
|
StateEvent<> event2Loaded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an abstract Asset object.
|
* Create an abstract Asset object.
|
||||||
|
@ -28,10 +28,12 @@ void AssetManager::queueLoad(Asset *asset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::queueUnload(std::vector<Asset*> assets) {
|
void AssetManager::queueUnload(std::vector<Asset*> assets) {
|
||||||
|
std::cout << "Asset list was queued to unload, but is not yet implemented" << std::endl;
|
||||||
vectorAppend(&this->assetsToUnload, &assets);
|
vectorAppend(&this->assetsToUnload, &assets);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetManager::queueUnload(Asset *asset) {
|
void AssetManager::queueUnload(Asset *asset) {
|
||||||
|
std::cout << "Asset was queued to unload, but is not yet implemented" << std::endl;
|
||||||
this->assetsToUnload.push_back(asset);
|
this->assetsToUnload.push_back(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +66,12 @@ void AssetManager::queueSwap(
|
|||||||
|
|
||||||
void AssetManager::syncTick() {
|
void AssetManager::syncTick() {
|
||||||
auto it = this->assetsToLoad.begin();
|
auto it = this->assetsToLoad.begin();
|
||||||
// auto it = this->assetsNotLoaded.begin();
|
|
||||||
while(it != this->assetsToLoad.end()) {
|
while(it != this->assetsToLoad.end()) {
|
||||||
auto asset = *it;
|
auto asset = *it;
|
||||||
if(asset->loaded) {
|
if(asset->loaded) {
|
||||||
it = this->assetsToLoad.erase(it);
|
it = this->assetsToLoad.erase(it);
|
||||||
asset->eventLoaded.invoke();
|
asset->eventLoaded.invoke();
|
||||||
|
asset->event2Loaded.invoke();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,12 +81,13 @@ void AssetManager::syncTick() {
|
|||||||
if(asset->loaded) {
|
if(asset->loaded) {
|
||||||
it = this->assetsToLoad.erase(it);
|
it = this->assetsToLoad.erase(it);
|
||||||
asset->eventLoaded.invoke();
|
asset->eventLoaded.invoke();
|
||||||
|
asset->event2Loaded.invoke();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
// auto it = this->assetsNotLoaded.begin();
|
||||||
// auto it2 = this->assetsToUnload.begin();
|
// auto it2 = this->assetsToUnload.begin();
|
||||||
// while(it2 != this->assetsToUnload.end()) {
|
// while(it2 != this->assetsToUnload.end()) {
|
||||||
// ++it2;
|
// ++it2;
|
||||||
|
@ -1,77 +1,76 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
// Copyright (c) 2023 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "AudioAsset.hpp"
|
#include "AudioAsset.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
AudioAsset::AudioAsset(AssetManager *man, std::string name) :
|
AudioAsset::AudioAsset(AssetManager *man, std::string name) :
|
||||||
Asset(man, name),
|
Asset(man, name),
|
||||||
loader(name + ".audio")
|
loader(name + ".audio")
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioAsset::updateSync() {
|
void AudioAsset::updateSync() {
|
||||||
if(this->state != 0x07) return;
|
if(this->state != 0x07) return;
|
||||||
|
|
||||||
// THIS WILL DEFINITELY CHANGE
|
// THIS WILL DEFINITELY CHANGE
|
||||||
this->state = 0x08;
|
this->state = 0x08;
|
||||||
this->loaded = true;
|
this->loaded = true;
|
||||||
this->eventLoaded.invoke();
|
}
|
||||||
}
|
|
||||||
|
void AudioAsset::updateAsync() {
|
||||||
void AudioAsset::updateAsync() {
|
if(this->state != 0x00) return;
|
||||||
if(this->state != 0x00) return;
|
char *start, *end;
|
||||||
char *start, *end;
|
char buffer[1024];
|
||||||
char buffer[1024];
|
|
||||||
|
// Open asset for reading
|
||||||
// Open asset for reading
|
this->state = 0x01;
|
||||||
this->state = 0x01;
|
this->loader.open();
|
||||||
this->loader.open();
|
|
||||||
|
// Parse header data.
|
||||||
// Parse header data.
|
this->state = 0x02;
|
||||||
this->state = 0x02;
|
this->loader.read((uint8_t *)buffer, 1024);
|
||||||
this->loader.read((uint8_t *)buffer, 1024);
|
|
||||||
|
// Channel count
|
||||||
// Channel count
|
this->state = 0x03;
|
||||||
this->state = 0x03;
|
start = buffer;
|
||||||
start = buffer;
|
end = strchr(start, '|');
|
||||||
end = strchr(start, '|');
|
*end = '\0';
|
||||||
*end = '\0';
|
this->channelCount = atoi(start);
|
||||||
this->channelCount = atoi(start);
|
assertTrue(this->channelCount > 0);
|
||||||
assertTrue(this->channelCount > 0);
|
|
||||||
|
// Sample Rate
|
||||||
// Sample Rate
|
this->state = 0x04;
|
||||||
this->state = 0x04;
|
start = end + 1;
|
||||||
start = end + 1;
|
end = strchr(start, '|');
|
||||||
end = strchr(start, '|');
|
*end = '\0';
|
||||||
*end = '\0';
|
this->sampleRate = (uint32_t)strtoul(start, NULL, 10);
|
||||||
this->sampleRate = (uint32_t)strtoul(start, NULL, 10);
|
assertTrue(this->sampleRate > 0);
|
||||||
assertTrue(this->sampleRate > 0);
|
|
||||||
|
// Number of samples per channel
|
||||||
// Number of samples per channel
|
this->state = 0x05;
|
||||||
this->state = 0x05;
|
start = end + 1;
|
||||||
start = end + 1;
|
end = strchr(start, '|');
|
||||||
end = strchr(start, '|');
|
*end = '\0';
|
||||||
*end = '\0';
|
this->samplesPerChannel = atoi(start);
|
||||||
this->samplesPerChannel = atoi(start);
|
assertTrue(this->samplesPerChannel > 0);
|
||||||
assertTrue(this->samplesPerChannel > 0);
|
|
||||||
|
// Total Data Length
|
||||||
// Total Data Length
|
this->state = 0x06;
|
||||||
this->state = 0x06;
|
start = end + 1;
|
||||||
start = end + 1;
|
end = strchr(start, '|');
|
||||||
end = strchr(start, '|');
|
*end = '\0';
|
||||||
*end = '\0';
|
this->bufferSize = (size_t)atoll(start);
|
||||||
this->bufferSize = (size_t)atoll(start);
|
assertTrue(this->bufferSize > 0);
|
||||||
assertTrue(this->bufferSize > 0);
|
|
||||||
|
// Determine frame size
|
||||||
// Determine frame size
|
this->frameSize = sizeof(int16_t) * this->channelCount;
|
||||||
this->frameSize = sizeof(int16_t) * this->channelCount;
|
|
||||||
|
// Indicated start of data
|
||||||
// Indicated start of data
|
this->state = 0x07;
|
||||||
this->state = 0x07;
|
this->bufferStart = end - buffer;
|
||||||
this->bufferStart = end - buffer;
|
|
||||||
}
|
}
|
@ -1,40 +1,41 @@
|
|||||||
// Copyright (c) 2022 Dominic Masters
|
// Copyright (c) 2022 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "event/Event.hpp"
|
#include "state/State.hpp"
|
||||||
#include "Easing.hpp"
|
#include "Easing.hpp"
|
||||||
#include "util/mathutils.hpp"
|
#include "util/mathutils.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
struct Animation {
|
struct Animation {
|
||||||
public:
|
public:
|
||||||
bool_t loop = false;
|
bool_t loop = false;
|
||||||
bool_t finished = false;
|
bool_t finished = false;
|
||||||
float_t time = 0;
|
float_t time = 0;
|
||||||
float_t duration = 0;
|
float_t duration = 0;
|
||||||
Event<> eventAnimationEnd;
|
Event<> eventAnimationEnd;
|
||||||
|
StateEvent<> event2AnimationEnd;
|
||||||
/**
|
|
||||||
* Ticks the animation along. Delta is whatever you want to update the
|
/**
|
||||||
* animation by (in seconds). Animations can overshoot if necessary and
|
* Ticks the animation along. Delta is whatever you want to update the
|
||||||
* will not be clamped (by default). Subclasses may interpret ticks in
|
* animation by (in seconds). Animations can overshoot if necessary and
|
||||||
* different ways.
|
* will not be clamped (by default). Subclasses may interpret ticks in
|
||||||
*
|
* different ways.
|
||||||
* @param delta Time delta (in seconds) to tick the animaiton by.
|
*
|
||||||
*/
|
* @param delta Time delta (in seconds) to tick the animaiton by.
|
||||||
virtual void tick(float_t delta) = 0;
|
*/
|
||||||
|
virtual void tick(float_t delta) = 0;
|
||||||
/**
|
|
||||||
* Restart a running animation.
|
/**
|
||||||
*/
|
* Restart a running animation.
|
||||||
virtual void restart();
|
*/
|
||||||
|
virtual void restart();
|
||||||
/**
|
|
||||||
* Clears an animaton of all its animation items and keyframes.
|
/**
|
||||||
*/
|
* Clears an animaton of all its animation items and keyframes.
|
||||||
virtual void clear();
|
*/
|
||||||
};
|
virtual void clear();
|
||||||
|
};
|
||||||
}
|
}
|
@ -1,205 +1,206 @@
|
|||||||
// Copyright (c) 2022 Dominic Masters
|
// Copyright (c) 2022 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Animation.hpp"
|
#include "Animation.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct SimpleKeyframe {
|
struct SimpleKeyframe {
|
||||||
float_t time;
|
float_t time;
|
||||||
T value;
|
T value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct SimpleAnimation : public Animation {
|
struct SimpleAnimation : public Animation {
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Function for subclasses to be "notified" when the value has been
|
* Function for subclasses to be "notified" when the value has been
|
||||||
* modified.
|
* modified.
|
||||||
*/
|
*/
|
||||||
virtual void onValueModified() {
|
virtual void onValueModified() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts internal keyframes by their time to make them conform correctly.
|
* Sorts internal keyframes by their time to make them conform correctly.
|
||||||
*/
|
*/
|
||||||
void sortKeyframes() {
|
void sortKeyframes() {
|
||||||
std::sort(
|
std::sort(
|
||||||
this->keyframes.begin(),
|
this->keyframes.begin(),
|
||||||
this->keyframes.end(),
|
this->keyframes.end(),
|
||||||
[](struct SimpleKeyframe<T> &a, struct SimpleKeyframe<T> &b) {
|
[](struct SimpleKeyframe<T> &a, struct SimpleKeyframe<T> &b) {
|
||||||
return a.time < b.time;
|
return a.time < b.time;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
easefunction_t *easing = &easeLinear;
|
easefunction_t *easing = &easeLinear;
|
||||||
T *modifies;
|
T *modifies;
|
||||||
std::vector<struct SimpleKeyframe<T>> keyframes;
|
std::vector<struct SimpleKeyframe<T>> keyframes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new Simple Animation instance.
|
* Constructs a new Simple Animation instance.
|
||||||
*
|
*
|
||||||
* @param modifies Pointer to the value that will be modified.
|
* @param modifies Pointer to the value that will be modified.
|
||||||
*/
|
*/
|
||||||
SimpleAnimation(T *modifies) {
|
SimpleAnimation(T *modifies) {
|
||||||
assertNotNull(modifies);
|
assertNotNull(modifies);
|
||||||
this->modifies = modifies;
|
this->modifies = modifies;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a keyframe that will be slerped to at a given time.
|
* Adds a keyframe that will be slerped to at a given time.
|
||||||
*
|
*
|
||||||
* @param time Time the keyframe occurs.
|
* @param time Time the keyframe occurs.
|
||||||
* @param value Value at this given time.
|
* @param value Value at this given time.
|
||||||
*/
|
*/
|
||||||
void addKeyframe(float_t time, T value) {
|
void addKeyframe(float_t time, T value) {
|
||||||
assertTrue(time >= 0);
|
assertTrue(time >= 0);
|
||||||
|
|
||||||
struct SimpleKeyframe<T> keyframe;
|
struct SimpleKeyframe<T> keyframe;
|
||||||
keyframe.time = time;
|
keyframe.time = time;
|
||||||
keyframe.value = value;
|
keyframe.value = value;
|
||||||
this->duration = mathMax<float_t>(this->duration, time);
|
this->duration = mathMax<float_t>(this->duration, time);
|
||||||
this->finished = false;
|
this->finished = false;
|
||||||
this->keyframes.push_back(keyframe);
|
this->keyframes.push_back(keyframe);
|
||||||
|
|
||||||
if(time < this->duration) this->sortKeyframes();
|
if(time < this->duration) this->sortKeyframes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quickly add a series of keyframes. For example, if you want to have a
|
* Quickly add a series of keyframes. For example, if you want to have a
|
||||||
* keyframe series of;
|
* keyframe series of;
|
||||||
* [ 1, 3, 5, 7, 9 ]
|
* [ 1, 3, 5, 7, 9 ]
|
||||||
*
|
*
|
||||||
* And occur at times
|
* And occur at times
|
||||||
* [ 0, 2, 4, 6, 8 ]
|
* [ 0, 2, 4, 6, 8 ]
|
||||||
*
|
*
|
||||||
* You would pass frameTime as 2, and step as 2.
|
* You would pass frameTime as 2, and step as 2.
|
||||||
*
|
*
|
||||||
* @param startTime When the first keyframe occurs.
|
* @param startTime When the first keyframe occurs.
|
||||||
* @param frameTime At what rate do keyframes occur.
|
* @param frameTime At what rate do keyframes occur.
|
||||||
* @param start Initial value (the value at startTime).
|
* @param start Initial value (the value at startTime).
|
||||||
* @param end The end value (for the last keyframe).
|
* @param end The end value (for the last keyframe).
|
||||||
* @param step How to step the value.
|
* @param step How to step the value.
|
||||||
*/
|
*/
|
||||||
void addSequentialKeyframes(
|
void addSequentialKeyframes(
|
||||||
float_t startTime,
|
float_t startTime,
|
||||||
float_t frameTime,
|
float_t frameTime,
|
||||||
T start,
|
T start,
|
||||||
T end,
|
T end,
|
||||||
T step
|
T step
|
||||||
) {
|
) {
|
||||||
T v = start;
|
T v = start;
|
||||||
float_t n = startTime;
|
float_t n = startTime;
|
||||||
while(v != end) {
|
while(v != end) {
|
||||||
this->addKeyframe(n, v);
|
this->addKeyframe(n, v);
|
||||||
n += frameTime;
|
n += frameTime;
|
||||||
v += step;
|
v += step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shorthand addSequentialKeyframes, assumes a step of 1 and a startTime
|
* Shorthand addSequentialKeyframes, assumes a step of 1 and a startTime
|
||||||
* of 0.
|
* of 0.
|
||||||
*
|
*
|
||||||
* @param frameTime Time between frames.
|
* @param frameTime Time between frames.
|
||||||
* @param start Initial value.
|
* @param start Initial value.
|
||||||
* @param end End value.
|
* @param end End value.
|
||||||
*/
|
*/
|
||||||
void addSequentialKeyframes(float_t frameTime, T start, T end) {
|
void addSequentialKeyframes(float_t frameTime, T start, T end) {
|
||||||
this->addSequentialKeyframes(0, frameTime, start, end, 1);
|
this->addSequentialKeyframes(0, frameTime, start, end, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immediately sets the value, bypassing keyframes and ticks. Useful for
|
* Immediately sets the value, bypassing keyframes and ticks. Useful for
|
||||||
* setting an initial value.
|
* setting an initial value.
|
||||||
*
|
*
|
||||||
* @param value Value to set.
|
* @param value Value to set.
|
||||||
*/
|
*/
|
||||||
void setValue(T value) {
|
void setValue(T value) {
|
||||||
*modifies = value;
|
*modifies = value;
|
||||||
this->onValueModified();
|
this->onValueModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
void tick(float_t delta) override {
|
void tick(float_t delta) override {
|
||||||
if(this->finished) return;
|
if(this->finished) return;
|
||||||
|
|
||||||
float_t newTime = this->time + delta;
|
float_t newTime = this->time + delta;
|
||||||
|
|
||||||
struct SimpleKeyframe<T> *keyframeNext = nullptr;
|
struct SimpleKeyframe<T> *keyframeNext = nullptr;
|
||||||
struct SimpleKeyframe<T> *keyframeCurrent = nullptr;
|
struct SimpleKeyframe<T> *keyframeCurrent = nullptr;
|
||||||
|
|
||||||
// Find current and next keyframe(s)
|
// Find current and next keyframe(s)
|
||||||
auto itKey = this->keyframes.begin();
|
auto itKey = this->keyframes.begin();
|
||||||
while(itKey != this->keyframes.end()) {
|
while(itKey != this->keyframes.end()) {
|
||||||
if(itKey->time > newTime) {
|
if(itKey->time > newTime) {
|
||||||
keyframeNext = &(*itKey);
|
keyframeNext = &(*itKey);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
keyframeCurrent = &(*itKey);
|
keyframeCurrent = &(*itKey);
|
||||||
++itKey;
|
++itKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update values
|
// Update values
|
||||||
if(keyframeCurrent != nullptr && keyframeNext == nullptr) {
|
if(keyframeCurrent != nullptr && keyframeNext == nullptr) {
|
||||||
// "End of animation"
|
// "End of animation"
|
||||||
*this->modifies = keyframeCurrent->value;
|
*this->modifies = keyframeCurrent->value;
|
||||||
this->onValueModified();
|
this->onValueModified();
|
||||||
} else if(keyframeNext != nullptr) {
|
} else if(keyframeNext != nullptr) {
|
||||||
T oldValue;
|
T oldValue;
|
||||||
float_t oldTime;
|
float_t oldTime;
|
||||||
|
|
||||||
if(keyframeCurrent == nullptr) {
|
if(keyframeCurrent == nullptr) {
|
||||||
// "Start of animation"
|
// "Start of animation"
|
||||||
oldValue = keyframeCurrent->value;
|
oldValue = keyframeCurrent->value;
|
||||||
oldTime = keyframeCurrent->time;
|
oldTime = keyframeCurrent->time;
|
||||||
} else {
|
} else {
|
||||||
// "Mid animation"
|
// "Mid animation"
|
||||||
oldTime = this->time;
|
oldTime = this->time;
|
||||||
oldValue = *this->modifies;
|
oldValue = *this->modifies;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slerp between keyframes
|
// Slerp between keyframes
|
||||||
float_t keyframeDelta = this->easing(
|
float_t keyframeDelta = this->easing(
|
||||||
(newTime - oldTime) / (keyframeNext->time - oldTime)
|
(newTime - oldTime) / (keyframeNext->time - oldTime)
|
||||||
);
|
);
|
||||||
*this->modifies = oldValue + (
|
*this->modifies = oldValue + (
|
||||||
(keyframeNext->value - oldValue) * keyframeDelta
|
(keyframeNext->value - oldValue) * keyframeDelta
|
||||||
);
|
);
|
||||||
this->onValueModified();
|
this->onValueModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
// First possible frame? I think this can be done cleaner
|
// First possible frame? I think this can be done cleaner
|
||||||
if(this->time == 0 && keyframeCurrent->time == 0) {
|
if(this->time == 0 && keyframeCurrent->time == 0) {
|
||||||
*this->modifies = keyframeCurrent->value;
|
*this->modifies = keyframeCurrent->value;
|
||||||
this->onValueModified();
|
this->onValueModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update time.
|
// Update time.
|
||||||
this->time = newTime;
|
this->time = newTime;
|
||||||
|
|
||||||
// Has the animation finished?
|
// Has the animation finished?
|
||||||
if(newTime < this->duration) return;
|
if(newTime < this->duration) return;
|
||||||
|
|
||||||
// Do we need to loop?
|
// Do we need to loop?
|
||||||
if(this->loop) {
|
if(this->loop) {
|
||||||
this->time = 0;
|
this->time = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animation end.
|
// Animation end.
|
||||||
this->finished = true;
|
this->finished = true;
|
||||||
this->eventAnimationEnd.invoke();
|
this->eventAnimationEnd.invoke();
|
||||||
}
|
this->event2AnimationEnd.invoke();
|
||||||
|
}
|
||||||
void clear() override {
|
|
||||||
Animation::clear();
|
void clear() override {
|
||||||
this->keyframes.clear();
|
Animation::clear();
|
||||||
}
|
this->keyframes.clear();
|
||||||
};
|
}
|
||||||
|
};
|
||||||
}
|
}
|
@ -7,6 +7,7 @@
|
|||||||
#include "dawnlibs.hpp"
|
#include "dawnlibs.hpp"
|
||||||
#include "util/mathutils.hpp"
|
#include "util/mathutils.hpp"
|
||||||
#include "assert/assert.hpp"
|
#include "assert/assert.hpp"
|
||||||
|
#include "state/StateEvent.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class DawnGame;
|
class DawnGame;
|
||||||
@ -32,6 +33,9 @@ namespace Dawn {
|
|||||||
public:
|
public:
|
||||||
DawnGame *game;
|
DawnGame *game;
|
||||||
|
|
||||||
|
StateEvent<inputbind_t> eventBindPressed;
|
||||||
|
StateEvent<inputbind_t> eventBindReleased;
|
||||||
|
|
||||||
IInputManager(DawnGame *game) {
|
IInputManager(DawnGame *game) {
|
||||||
assertNotNull(game);
|
assertNotNull(game);
|
||||||
this->game = game;
|
this->game = game;
|
||||||
@ -163,7 +167,7 @@ namespace Dawn {
|
|||||||
|
|
||||||
// For each bind...
|
// For each bind...
|
||||||
while(it != this->binds.end()) {
|
while(it != this->binds.end()) {
|
||||||
float_t value = 0.0f;
|
float_t value = 0.0f, valCurrent;
|
||||||
|
|
||||||
// For each input axis...
|
// For each input axis...
|
||||||
auto bindIt = it->second.begin();
|
auto bindIt = it->second.begin();
|
||||||
@ -176,10 +180,20 @@ namespace Dawn {
|
|||||||
|
|
||||||
// Set into current values
|
// Set into current values
|
||||||
if(this->currentIsLeft) {
|
if(this->currentIsLeft) {
|
||||||
|
valCurrent = this->valuesRight[it->first];
|
||||||
this->valuesLeft[it->first] = value;
|
this->valuesLeft[it->first] = value;
|
||||||
} else {
|
} else {
|
||||||
|
valCurrent = this->valuesLeft[it->first];
|
||||||
this->valuesRight[it->first] = value;
|
this->valuesRight[it->first] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fire events when necessary.
|
||||||
|
if(value == 0 && valCurrent == 1) {
|
||||||
|
eventBindReleased.invoke(it->first);
|
||||||
|
} else if(valCurrent == 0 && value == 1) {
|
||||||
|
eventBindPressed.invoke(it->first);
|
||||||
|
}
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "event/Event.hpp"
|
#include "state/State.hpp"
|
||||||
#include "asset/AssetManager.hpp"
|
#include "asset/AssetManager.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
@ -14,7 +14,7 @@ namespace Dawn {
|
|||||||
std::string language;
|
std::string language;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LocaleManager {
|
class LocaleManager : public StateOwner {
|
||||||
private:
|
private:
|
||||||
DawnGame *game;
|
DawnGame *game;
|
||||||
LanguageAsset *asset;
|
LanguageAsset *asset;
|
||||||
@ -26,8 +26,8 @@ namespace Dawn {
|
|||||||
void onLanguageLoaded();
|
void onLanguageLoaded();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Event<> eventLocaleChanged;
|
StateEvent<> eventLocaleChanged;
|
||||||
Event<> eventLanguageUpdated;
|
StateEvent<> eventLanguageUpdated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the Locale Manager Instance. Locale Manager is responsible
|
* Initializes the Locale Manager Instance. Locale Manager is responsible
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "util/array.hpp"
|
#include "util/array.hpp"
|
||||||
#include "util/mathutils.hpp"
|
#include "util/mathutils.hpp"
|
||||||
#include "display/shader/Shader.hpp"
|
#include "display/shader/Shader.hpp"
|
||||||
|
#include "state/State.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
enum UIComponentAlign {
|
enum UIComponentAlign {
|
||||||
@ -20,7 +21,7 @@ namespace Dawn {
|
|||||||
|
|
||||||
class UIGrid;
|
class UIGrid;
|
||||||
|
|
||||||
class UIComponent {
|
class UIComponent : public StateOwner {
|
||||||
protected:
|
protected:
|
||||||
// Calculated (and cached) values
|
// Calculated (and cached) values
|
||||||
float_t width = 1;
|
float_t width = 1;
|
||||||
|
@ -9,9 +9,12 @@
|
|||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
UILabel::UILabel(UICanvas *canvas) : UIComponent(canvas) {
|
UILabel::UILabel(UICanvas *canvas) : UIComponent(canvas) {
|
||||||
getGame()->localeManager.eventLanguageUpdated.addListener(
|
evtLangUpdated = useEvent([&]{
|
||||||
this, &UILabel::onLanguageUpdated
|
this->needsRebuffering = true;
|
||||||
);
|
if(key.size() > 0 && this->getGame()->localeManager.getString(key).size() > 0) {
|
||||||
|
this->hasText = true;
|
||||||
|
}
|
||||||
|
}, getGame()->localeManager.eventLanguageUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UILabel::updatePositions() {
|
void UILabel::updatePositions() {
|
||||||
@ -104,17 +107,4 @@ void UILabel::setTransform(
|
|||||||
) {
|
) {
|
||||||
this->needsRebuffering = true;
|
this->needsRebuffering = true;
|
||||||
UIComponent::setTransform(xAlign, yAlign, alignment, z);
|
UIComponent::setTransform(xAlign, yAlign, alignment, z);
|
||||||
}
|
|
||||||
|
|
||||||
void UILabel::onLanguageUpdated() {
|
|
||||||
this->needsRebuffering = true;
|
|
||||||
if(key.size() > 0 && this->getGame()->localeManager.getString(key).size()>0){
|
|
||||||
this->hasText = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UILabel::~UILabel() {
|
|
||||||
getGame()->localeManager.eventLanguageUpdated.removeListener(
|
|
||||||
this, &UILabel::onLanguageUpdated
|
|
||||||
);
|
|
||||||
}
|
}
|
@ -17,12 +17,10 @@ namespace Dawn {
|
|||||||
std::string key = "";
|
std::string key = "";
|
||||||
float_t fontSize = 10.0f;
|
float_t fontSize = 10.0f;
|
||||||
bool_t hasText = false;
|
bool_t hasText = false;
|
||||||
|
std::function<void()> evtLangUpdated;
|
||||||
|
|
||||||
void updatePositions() override;
|
void updatePositions() override;
|
||||||
|
|
||||||
/** Event for when the language strings are updated */
|
|
||||||
void onLanguageUpdated();
|
|
||||||
|
|
||||||
std::vector<struct ShaderPassItem> getSelfPassItems(
|
std::vector<struct ShaderPassItem> getSelfPassItems(
|
||||||
glm::mat4 projection,
|
glm::mat4 projection,
|
||||||
glm::mat4 view,
|
glm::mat4 view,
|
||||||
@ -79,7 +77,5 @@ namespace Dawn {
|
|||||||
* @return Font size of the label.
|
* @return Font size of the label.
|
||||||
*/
|
*/
|
||||||
float_t getFontSize();
|
float_t getFontSize();
|
||||||
|
|
||||||
~UILabel();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
# Copyright (c) 2022 Dominic Masters
|
# Copyright (c) 2022 Dominic Masters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
DawnHostWin32.cpp
|
DawnHostTux32.cpp
|
||||||
)
|
)
|
@ -3,7 +3,7 @@
|
|||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "DawnHostWin32.hpp"
|
#include "DawnHostTux32.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
@ -1,18 +1,18 @@
|
|||||||
// Copyright (c) 2022 Dominic Masters
|
// Copyright (c) 2022 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawnlibs.hpp"
|
||||||
#include "host/DawnHost.hpp"
|
#include "host/DawnHost.hpp"
|
||||||
#include "game/DawnGame.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry function received by parent Win32 Operating System.
|
* Main entry function received by parent Win32 Operating System.
|
||||||
*
|
*
|
||||||
* @param argc Count of arguments passed to the program.
|
* @param argc Count of arguments passed to the program.
|
||||||
* @param args Array of strings provided to the program.
|
* @param args Array of strings provided to the program.
|
||||||
* @return 0 for success, else for any issue/error.
|
* @return 0 for success, else for any issue/error.
|
||||||
*/
|
*/
|
||||||
int32_t main(int32_t argc, char **args);
|
int32_t main(int32_t argc, char **args);
|
@ -52,12 +52,12 @@ namespace Dawn {
|
|||||||
enum AudioSourceState state = AUDIO_SOURCE_STATE_STOPPED;
|
enum AudioSourceState state = AUDIO_SOURCE_STATE_STOPPED;
|
||||||
AudioSourcePlayMode playMode;
|
AudioSourcePlayMode playMode;
|
||||||
|
|
||||||
Event<> eventPlaying;
|
StateEvent<> eventPlaying;
|
||||||
Event<> eventResumed;
|
StateEvent<> eventResumed;
|
||||||
Event<> eventPaused;
|
StateEvent<> eventPaused;
|
||||||
Event<> eventStopped;
|
StateEvent<> eventStopped;
|
||||||
Event<> eventFinished;
|
StateEvent<> eventFinished;
|
||||||
Event<> eventLooped;
|
StateEvent<> eventLooped;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an Audio Source item component.
|
* Creates an Audio Source item component.
|
||||||
|
@ -23,32 +23,32 @@ namespace Dawn {
|
|||||||
|
|
||||||
class LanguageParser : public XmlParser<struct LanguageString> {
|
class LanguageParser : public XmlParser<struct LanguageString> {
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::string> getRequiredAttributes();
|
std::vector<std::string> getRequiredAttributes() override;
|
||||||
std::map<std::string, std::string> getOptionalAttributes();
|
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||||
int32_t onParse(
|
int32_t onParse(
|
||||||
Xml *node,
|
Xml *node,
|
||||||
std::map<std::string, std::string> values,
|
std::map<std::string, std::string> values,
|
||||||
struct LanguageString *out,
|
struct LanguageString *out,
|
||||||
std::string *error
|
std::string *error
|
||||||
);
|
) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LanguageGroupParser : public XmlParser<struct LanguageGroup> {
|
class LanguageGroupParser : public XmlParser<struct LanguageGroup> {
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::string> getRequiredAttributes();
|
std::vector<std::string> getRequiredAttributes() override;
|
||||||
std::map<std::string, std::string> getOptionalAttributes();
|
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||||
int32_t onParse(
|
int32_t onParse(
|
||||||
Xml *node,
|
Xml *node,
|
||||||
std::map<std::string, std::string> values,
|
std::map<std::string, std::string> values,
|
||||||
struct LanguageGroup *out,
|
struct LanguageGroup *out,
|
||||||
std::string *error
|
std::string *error
|
||||||
);
|
) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LanguageRootParser : public XmlParser<struct LanguageRoot> {
|
class LanguageRootParser : public XmlParser<struct LanguageRoot> {
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::string> getRequiredAttributes();
|
std::vector<std::string> getRequiredAttributes() override;
|
||||||
std::map<std::string, std::string> getOptionalAttributes();
|
std::map<std::string, std::string> getOptionalAttributes() override;
|
||||||
int32_t onParse(
|
int32_t onParse(
|
||||||
Xml *node,
|
Xml *node,
|
||||||
std::map<std::string, std::string> values,
|
std::map<std::string, std::string> values,
|
||||||
@ -60,18 +60,6 @@ namespace Dawn {
|
|||||||
class LanguageGen : public DawnTool {
|
class LanguageGen : public DawnTool {
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::string> getRequiredFlags() override;
|
std::vector<std::string> getRequiredFlags() override;
|
||||||
|
|
||||||
int32_t parseGroup(
|
|
||||||
Xml *node,
|
|
||||||
std::string key,
|
|
||||||
std::map<std::string, std::vector<struct LanguageString>> *strings
|
|
||||||
);
|
|
||||||
|
|
||||||
int32_t parseString(
|
|
||||||
Xml *node,
|
|
||||||
std::string key,
|
|
||||||
std::map<std::string, std::vector<struct LanguageString>> *strings
|
|
||||||
);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int32_t start() override;
|
int32_t start() override;
|
||||||
|
Reference in New Issue
Block a user