Browse Source

Remove hard-coded language manifest. Update model loader to load bone keys rather than strings

master
C. J. Howard 1 year ago
parent
commit
b6b77012fe
7 changed files with 19 additions and 39 deletions
  1. +3
    -8
      src/engine/render/model.cpp
  2. +0
    -12
      src/game/game.cpp
  3. +2
    -5
      src/game/game.hpp
  4. +1
    -1
      src/game/menu.cpp
  5. +1
    -1
      src/game/menu.hpp
  6. +10
    -11
      src/game/states/language-menu-state.cpp
  7. +2
    -1
      src/game/states/language-menu-state.hpp

+ 3
- 8
src/engine/render/model.cpp View File

@ -293,14 +293,9 @@ std::unique_ptr resource_loader::load(::resource_m
// Read bones // Read bones
for (std::uint16_t i = 0; i < bone_count; ++i) for (std::uint16_t i = 0; i < bone_count; ++i)
{ {
// Read bone name length
std::uint8_t bone_name_length = 0;
ctx.read8(reinterpret_cast<std::byte*>(&bone_name_length), 1);
// Read and hash bone name
std::string bone_name(static_cast<std::size_t>(bone_name_length), '\0');
ctx.read8(reinterpret_cast<std::byte*>(bone_name.data()), bone_name_length);
hash::fnv1a32_t bone_key = hash::fnv1a32<char>(bone_name);
// Read bone key
hash::fnv1a32_t bone_key = {};
ctx.read32<std::endian::little>(reinterpret_cast<std::byte*>(&bone_key), 1);
// Read parent bone index // Read parent bone index
std::uint16_t parent_bone_index = i; std::uint16_t parent_bone_index = i;

+ 0
- 12
src/game/game.cpp View File

@ -1274,18 +1274,6 @@ void game::setup_loop()
function_queue.pop(); function_queue.pop();
} }
// Update processes
std::for_each
(
std::execution::par,
processes.begin(),
processes.end(),
[t, dt](const auto& process)
{
process.second(t, dt);
}
);
// Advance timeline // Advance timeline
timeline->advance(dt); timeline->advance(dt);

+ 2
- 5
src/game/game.hpp View File

@ -178,7 +178,7 @@ public:
std::shared_ptr<i18n::string_map> string_map; std::shared_ptr<i18n::string_map> string_map;
// Fonts // Fonts
std::unordered_map<std::string, std::shared_ptr<type::typeface>> typefaces;
std::unordered_map<hash::fnv1a32_t, std::shared_ptr<type::typeface>> typefaces;
type::bitmap_font debug_font; type::bitmap_font debug_font;
type::bitmap_font menu_font; type::bitmap_font menu_font;
type::bitmap_font title_font; type::bitmap_font title_font;
@ -232,9 +232,6 @@ public:
// Queue for scheduling "next frame" function calls // Queue for scheduling "next frame" function calls
std::queue<std::function<void()>> function_queue; std::queue<std::function<void()>> function_queue;
// Parallel processes
std::unordered_map<std::string, std::function<void(double, double)>> processes;
bool mouse_look; bool mouse_look;
/// Game loop /// Game loop
@ -305,7 +302,7 @@ public:
std::vector<std::function<void()>> menu_right_callbacks; std::vector<std::function<void()>> menu_right_callbacks;
std::function<void()> menu_back_callback; std::function<void()> menu_back_callback;
std::vector<std::tuple<scene::text*, scene::text*>> menu_item_texts; std::vector<std::tuple<scene::text*, scene::text*>> menu_item_texts;
std::unordered_map<std::string, int> menu_item_indices;
std::unordered_map<hash::fnv1a32_t, int> menu_item_indices;
int* menu_item_index; int* menu_item_index;
// Scene // Scene

+ 1
- 1
src/game/menu.cpp View File

@ -30,7 +30,7 @@ using namespace math::glsl;
namespace menu { namespace menu {
void init_menu_item_index(::game& ctx, const std::string& menu_name)
void init_menu_item_index(::game& ctx, hash::fnv1a32_t menu_name)
{ {
if (auto it = ctx.menu_item_indices.find(menu_name); it != ctx.menu_item_indices.end()) if (auto it = ctx.menu_item_indices.find(menu_name); it != ctx.menu_item_indices.end())
{ {

+ 1
- 1
src/game/menu.hpp View File

@ -24,7 +24,7 @@
namespace menu { namespace menu {
void init_menu_item_index(::game& ctx, const std::string& menu_name);
void init_menu_item_index(::game& ctx, hash::fnv1a32_t menu_name);
void setup_animations(::game& ctx); void setup_animations(::game& ctx);
void clear_callbacks(::game& ctx); void clear_callbacks(::game& ctx);

+ 10
- 11
src/game/states/language-menu-state.cpp View File

@ -37,19 +37,18 @@ language_menu_state::language_menu_state(::game& ctx):
{ {
debug::log::trace("Entering language menu state..."); debug::log::trace("Entering language menu state...");
/// @TODO Don't hardcode this
language_tags =
// Load language manifest
language_manifest = ctx.resource_manager->load<text_file>("languages.txt");
if (!language_manifest)
{ {
"en",
"zh-Hans",
"zh-Hant"
};
throw std::runtime_error("Failed to load language manifest");
}
// Determine index of current language // Determine index of current language
language_index = 0; language_index = 0;
for (std::size_t i = 0; i < language_tags.size(); ++i)
for (std::size_t i = 0; i < language_manifest->lines.size(); ++i)
{ {
if (ctx.language_tag == language_tags[i])
if (ctx.language_tag == language_manifest->lines[i])
{ {
language_index = i; language_index = i;
break; break;
@ -80,7 +79,7 @@ language_menu_state::language_menu_state(::game& ctx):
auto change_language = [this, &ctx]() auto change_language = [this, &ctx]()
{ {
const std::string& language_tag = this->language_tags[this->language_index];
const std::string& language_tag = this->language_manifest->lines[this->language_index];
// Slugify language tag // Slugify language tag
std::string language_slug = language_tag; std::string language_slug = language_tag;
@ -121,7 +120,7 @@ language_menu_state::language_menu_state(::game& ctx):
// Construct menu item callbacks // Construct menu item callbacks
auto next_language_callback = [this, &ctx, change_language]() auto next_language_callback = [this, &ctx, change_language]()
{ {
this->language_index = (this->language_index + 1) % this->language_tags.size();
this->language_index = (this->language_index + 1) % this->language_manifest->lines.size();
change_language(); change_language();
}; };
auto previous_language_callback = [this, &ctx, change_language]() auto previous_language_callback = [this, &ctx, change_language]()
@ -132,7 +131,7 @@ language_menu_state::language_menu_state(::game& ctx):
} }
else else
{ {
this->language_index = this->language_tags.size() - 1;
this->language_index = this->language_manifest->lines.size() - 1;
} }
change_language(); change_language();

+ 2
- 1
src/game/states/language-menu-state.hpp View File

@ -22,6 +22,7 @@
#include "game/states/game-state.hpp" #include "game/states/game-state.hpp"
#include <engine/scene/text.hpp> #include <engine/scene/text.hpp>
#include <engine/utility/text-file.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -36,7 +37,7 @@ public:
private: private:
void update_text_content(); void update_text_content();
std::vector<std::string> language_tags;
std::shared_ptr<text_file> language_manifest;
std::size_t language_index; std::size_t language_index;
std::unique_ptr<scene::text> language_name_text; std::unique_ptr<scene::text> language_name_text;

Loading…
Cancel
Save