mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
feat: animation track as asset (WIP)
This commit is contained in:
parent
df5bc1f9fe
commit
104c74e653
10 changed files with 86 additions and 24 deletions
|
|
@ -279,7 +279,7 @@ end
|
|||
|
||||
local cached_tracks = {}
|
||||
|
||||
function this.load_vca(filepath)
|
||||
function this.load_vca(filepath, identifier)
|
||||
local track = cached_tracks[filepath]
|
||||
if track then
|
||||
return track
|
||||
|
|
@ -287,8 +287,16 @@ function this.load_vca(filepath)
|
|||
local source = file.read(filepath)
|
||||
local raw_track = parse_track(xml.parse_vcd(source, "track"))
|
||||
track = this.compile_track(raw_track, filepath)
|
||||
cached_tracks[filepath] = track
|
||||
cached_tracks[identifier] = track
|
||||
return track
|
||||
end
|
||||
|
||||
function this.get_track(identifier)
|
||||
return cached_tracks[identifier]
|
||||
end
|
||||
|
||||
function __vc_internals.load_vca_animation(filepath, identifier)
|
||||
this.load_vca(filepath, identifier)
|
||||
end
|
||||
|
||||
return this
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ local rig = entity.skeleton
|
|||
|
||||
local states = {}
|
||||
|
||||
function create_state(name, track, max_intencity)
|
||||
function create_state(name, track_id, max_intencity)
|
||||
states[name] = {
|
||||
track = track,
|
||||
track = nil,
|
||||
track_id = track_id,
|
||||
timer = 0.0,
|
||||
fade_time = 0.0,
|
||||
fade_timer = 0.0,
|
||||
|
|
@ -47,6 +48,7 @@ local function update(delta)
|
|||
end
|
||||
end
|
||||
|
||||
state.track = state.track or animation.get_track(state.track_id)
|
||||
if state.track and intensity > 0.0 then
|
||||
state.track.func(rig, state.timer, intensity * state.max_intencity)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -332,6 +332,8 @@ end
|
|||
world.raycast = entities.__world_raycast
|
||||
entities.__world_raycast = nil
|
||||
|
||||
animation = require "core:animation"
|
||||
|
||||
__vc_scripts_registry = require "core:internal/scripts_registry"
|
||||
|
||||
file.open = require "core:internal/stream_providers/file"
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
class Assets;
|
||||
|
||||
enum class AssetType {
|
||||
ANIMATION,
|
||||
TEXTURE,
|
||||
SHADER,
|
||||
FONT,
|
||||
|
|
|
|||
|
|
@ -26,17 +26,20 @@ namespace fs = std::filesystem;
|
|||
|
||||
static debug::Logger logger("assets-loader");
|
||||
|
||||
AssetsLoader::AssetsLoader(Engine& engine, Assets& assets, const ResPaths& paths)
|
||||
AssetsLoader::AssetsLoader(
|
||||
Engine& engine, Assets& assets, const ResPaths& paths
|
||||
)
|
||||
: engine(engine), assets(assets), paths(paths) {
|
||||
addLoader(AssetType::SHADER, assetload::shader);
|
||||
addLoader(AssetType::TEXTURE, assetload::texture);
|
||||
addLoader(AssetType::FONT, assetload::font);
|
||||
addLoader(AssetType::ANIMATION, assetload::animation);
|
||||
addLoader(AssetType::ATLAS, assetload::atlas);
|
||||
addLoader(AssetType::FONT, assetload::font);
|
||||
addLoader(AssetType::LAYOUT, assetload::layout);
|
||||
addLoader(AssetType::SOUND, assetload::sound);
|
||||
addLoader(AssetType::MODEL, assetload::model);
|
||||
addLoader(AssetType::POST_EFFECT, assetload::posteffect);
|
||||
addLoader(AssetType::SHADER, assetload::shader);
|
||||
addLoader(AssetType::SKELETON, assetload::skeleton);
|
||||
addLoader(AssetType::SOUND, assetload::sound);
|
||||
addLoader(AssetType::TEXTURE, assetload::texture);
|
||||
}
|
||||
|
||||
void AssetsLoader::addLoader(AssetType tag, aloader_func func) {
|
||||
|
|
@ -127,24 +130,26 @@ void AssetsLoader::tryAddSound(const std::string& name) {
|
|||
|
||||
static std::string assets_def_folder(AssetType tag) {
|
||||
switch (tag) {
|
||||
case AssetType::FONT:
|
||||
return FONTS_FOLDER;
|
||||
case AssetType::SHADER:
|
||||
return SHADERS_FOLDER;
|
||||
case AssetType::TEXTURE:
|
||||
return TEXTURES_FOLDER;
|
||||
case AssetType::ANIMATION:
|
||||
return ANIMATION_FOLDER;
|
||||
case AssetType::ATLAS:
|
||||
return TEXTURES_FOLDER;
|
||||
case AssetType::FONT:
|
||||
return FONTS_FOLDER;
|
||||
case AssetType::LAYOUT:
|
||||
return LAYOUTS_FOLDER;
|
||||
case AssetType::SOUND:
|
||||
return SOUNDS_FOLDER;
|
||||
case AssetType::MODEL:
|
||||
return MODELS_FOLDER;
|
||||
case AssetType::POST_EFFECT:
|
||||
return POST_EFFECTS_FOLDER;
|
||||
case AssetType::SHADER:
|
||||
return SHADERS_FOLDER;
|
||||
case AssetType::SKELETON:
|
||||
return SKELETONS_FOLDER;
|
||||
case AssetType::SOUND:
|
||||
return SOUNDS_FOLDER;
|
||||
case AssetType::TEXTURE:
|
||||
return TEXTURES_FOLDER;
|
||||
}
|
||||
return "<error>";
|
||||
}
|
||||
|
|
@ -221,14 +226,15 @@ void AssetsLoader::processPreloadList(AssetType tag, const dv::value& list) {
|
|||
|
||||
void AssetsLoader::processPreloadConfig(const io::path& file) {
|
||||
auto root = io::read_json(file);
|
||||
processPreloadList(AssetType::ANIMATION, root["animation"]);
|
||||
processPreloadList(AssetType::ATLAS, root["atlases"]);
|
||||
processPreloadList(AssetType::FONT, root["fonts"]);
|
||||
processPreloadList(AssetType::SHADER, root["shaders"]);
|
||||
processPreloadList(AssetType::TEXTURE, root["textures"]);
|
||||
processPreloadList(AssetType::SOUND, root["sounds"]);
|
||||
processPreloadList(AssetType::MODEL, root["models"]);
|
||||
processPreloadList(AssetType::POST_EFFECT, root["post-effects"]);
|
||||
processPreloadList(AssetType::SHADER, root["shaders"]);
|
||||
processPreloadList(AssetType::SKELETON, root["skeletons"]);
|
||||
processPreloadList(AssetType::SOUND, root["sounds"]);
|
||||
processPreloadList(AssetType::TEXTURE, root["textures"]);
|
||||
// layouts are loaded automatically
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include "graphics/core/Shader.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "graphics/core/TextureAnimation.hpp"
|
||||
#include "logic/scripting/scripting.hpp"
|
||||
#include "io/io.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
|
||||
|
|
@ -44,6 +45,20 @@ static bool load_animated_texture(
|
|||
Atlas* dstAtlas
|
||||
);
|
||||
|
||||
assetload::postfunc assetload::animation(
|
||||
AssetsLoader&,
|
||||
const ResPaths& paths,
|
||||
const std::string& filename,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<AssetCfg>&
|
||||
) {
|
||||
auto path = paths.find(filename + ".vca");
|
||||
if (io::is_regular_file(path)) {
|
||||
scripting::load_vca_animation(path, name);
|
||||
}
|
||||
return [](auto&) {};
|
||||
}
|
||||
|
||||
assetload::postfunc assetload::texture(
|
||||
AssetsLoader&,
|
||||
const ResPaths& paths,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@ struct AssetCfg;
|
|||
|
||||
/// @brief see AssetsLoader.h: aloader_func
|
||||
namespace assetload {
|
||||
postfunc animation(
|
||||
AssetsLoader&,
|
||||
const ResPaths& paths,
|
||||
const std::string& filename,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<AssetCfg>& settings
|
||||
);
|
||||
postfunc texture(
|
||||
AssetsLoader&,
|
||||
const ResPaths& paths,
|
||||
|
|
|
|||
|
|
@ -75,13 +75,14 @@ inline constexpr int DEFAULT_FONT_SIZE = 16;
|
|||
|
||||
inline constexpr int DEFAULT_PRE_RENDER_FONT_PAGES = 1; // must be at least 1
|
||||
|
||||
inline const std::string SHADERS_FOLDER = "shaders";
|
||||
inline const std::string TEXTURES_FOLDER = "textures";
|
||||
inline const std::string ANIMATION_FOLDER = "animation";
|
||||
inline const std::string FONTS_FOLDER = "fonts";
|
||||
inline const std::string LAYOUTS_FOLDER = "layouts";
|
||||
inline const std::string SOUNDS_FOLDER = "sounds";
|
||||
inline const std::string MODELS_FOLDER = "models";
|
||||
inline const std::string SKELETONS_FOLDER = "skeletons";
|
||||
inline const std::string POST_EFFECTS_FOLDER = "shaders/effects";
|
||||
inline const std::string SHADERS_FOLDER = "shaders";
|
||||
inline const std::string SKELETONS_FOLDER = "skeletons";
|
||||
inline const std::string SOUNDS_FOLDER = "sounds";
|
||||
inline const std::string TEXTURES_FOLDER = "textures";
|
||||
|
||||
inline const std::string FONT_DEFAULT = "normal";
|
||||
|
|
|
|||
|
|
@ -844,6 +844,21 @@ void scripting::load_layout_script(
|
|||
lua::pop(L);
|
||||
}
|
||||
|
||||
void scripting::load_vca_animation(
|
||||
const io::path& file,
|
||||
const std::string& identifier
|
||||
) {
|
||||
auto L = lua::get_main_state();
|
||||
if (lua::get_from_registry(L, "internals", "load_vca_animation", true)) {
|
||||
lua::pushlstring(L, file.string());
|
||||
lua::pushlstring(L, identifier);
|
||||
if (lua::call(L, 2, 0)) {
|
||||
lua::pop(L);
|
||||
}
|
||||
lua::pop(L);
|
||||
}
|
||||
}
|
||||
|
||||
void scripting::close() {
|
||||
lua::finalize();
|
||||
content = nullptr;
|
||||
|
|
|
|||
|
|
@ -251,6 +251,11 @@ namespace scripting {
|
|||
const std::string& fileName,
|
||||
UiDocScript& script
|
||||
);
|
||||
|
||||
void load_vca_animation(
|
||||
const io::path& file,
|
||||
const std::string& identifier
|
||||
);
|
||||
|
||||
/// @brief Finalize lua state. Using scripting after will lead to Lua panic
|
||||
void close();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue