Add Animation Table logic

This commit is contained in:
David Markowitz
2023-03-26 03:09:04 -07:00
parent 1e4e1b914c
commit 426bc963fe
40 changed files with 419 additions and 291 deletions

View File

@@ -2,7 +2,7 @@
#include "GeneralUtils.h"
#include "Game.h"
bool CDAnimationsTable::CacheData(CppSQLite3Statement queryToCache) {
bool CDAnimationsTable::CacheData(CppSQLite3Statement& queryToCache) {
auto tableData = queryToCache.execQuery();
// If we received a bad lookup, cache it anyways so we do not run the query again.
if (tableData.eof()) return false;
@@ -16,15 +16,15 @@ bool CDAnimationsTable::CacheData(CppSQLite3Statement queryToCache) {
CDAnimation entry;
entry.animation_name = tableData.getStringField("animation_name", "");
entry.chance_to_play = tableData.getFloatField("chance_to_play", 1.0f);
entry.min_loops = tableData.getIntField("min_loops", 0);
entry.max_loops = tableData.getIntField("max_loops", 0);
UNUSED_COLUMN(entry.min_loops = tableData.getIntField("min_loops", 0);)
UNUSED_COLUMN(entry.max_loops = tableData.getIntField("max_loops", 0);)
entry.animation_length = tableData.getFloatField("animation_length", 0.0f);
entry.hideEquip = tableData.getIntField("hideEquip", 0) == 1;
entry.ignoreUpperBody = tableData.getIntField("ignoreUpperBody", 0) == 1;
entry.restartable = tableData.getIntField("restartable", 0) == 1;
entry.face_animation_name = tableData.getStringField("face_animation_name", "");
entry.priority = tableData.getFloatField("priority", 0.0f);
entry.blendTime = tableData.getFloatField("blendTime", 0.0f);
UNUSED_COLUMN(entry.hideEquip = tableData.getIntField("hideEquip", 0) == 1;)
UNUSED_COLUMN(entry.ignoreUpperBody = tableData.getIntField("ignoreUpperBody", 0) == 1;)
UNUSED_COLUMN(entry.restartable = tableData.getIntField("restartable", 0) == 1;)
UNUSED_COLUMN(entry.face_animation_name = tableData.getStringField("face_animation_name", "");)
UNUSED_COLUMN(entry.priority = tableData.getFloatField("priority", 0.0f);)
UNUSED_COLUMN(entry.blendTime = tableData.getFloatField("blendTime", 0.0f);)
this->animations[CDAnimationKey(animation_type, animationGroupID)].push_back(entry);
tableData.nextRow();
@@ -61,18 +61,17 @@ void CDAnimationsTable::CacheAnimationGroup(AnimationGroupID animationGroupID) {
CDAnimationLookupResult CDAnimationsTable::GetAnimation(const AnimationID& animationType, const std::string& previousAnimationName, const AnimationGroupID animationGroupID) {
CDAnimationKey animationKey(animationType, animationGroupID);
auto randomAnimation = GeneralUtils::GenerateRandomNumber<float>(0, 1);
auto animationEntryCached = this->animations.find(animationKey);
if (animationEntryCached == this->animations.end()) {
this->CacheAnimations(animationKey);
}
auto animationEntry = this->animations.find(animationKey);
// If we have only one animation, return it regardless of the chance to play.
if (animationEntry->second.size() == 1) {
return CDAnimationLookupResult(animationEntry->second.front());
}
auto randomAnimation = GeneralUtils::GenerateRandomNumber<float>(0, 1);
for (auto& animationEntry : animationEntry->second) {
randomAnimation -= animationEntry.chance_to_play;