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; | ||||||
|   | |||||||
| @@ -20,7 +20,6 @@ void AudioAsset::updateSync() { | |||||||
|   // 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() { | ||||||
|   | |||||||
| @@ -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 "Easing.hpp" | #include "Easing.hpp" | ||||||
| #include "util/mathutils.hpp" | #include "util/mathutils.hpp" | ||||||
|  |  | ||||||
| @@ -16,6 +16,7 @@ namespace Dawn { | |||||||
|       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 |        * Ticks the animation along. Delta is whatever you want to update the | ||||||
|   | |||||||
| @@ -195,6 +195,7 @@ namespace Dawn { | |||||||
|         // Animation end. |         // Animation end. | ||||||
|         this->finished = true; |         this->finished = true; | ||||||
|         this->eventAnimationEnd.invoke(); |         this->eventAnimationEnd.invoke(); | ||||||
|  |         this->event2AnimationEnd.invoke(); | ||||||
|       } |       } | ||||||
|        |        | ||||||
|       void clear() override { |       void clear() override { | ||||||
|   | |||||||
| @@ -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() { | ||||||
| @@ -105,16 +108,3 @@ 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(); |  | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
| @@ -6,5 +6,5 @@ | |||||||
| # 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; | ||||||
| 
 | 
 | ||||||
| @@ -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, | ||||||
| @@ -61,18 +61,6 @@ namespace Dawn { | |||||||
|     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