rename spine_model to spine

This commit is contained in:
2019-09-05 14:09:55 +07:00
parent 2507753ac6
commit b965094d14
12 changed files with 135 additions and 132 deletions

View File

@@ -21,7 +21,7 @@
#include "assets/shader_asset.hpp" #include "assets/shader_asset.hpp"
#include "assets/shape_asset.hpp" #include "assets/shape_asset.hpp"
#include "assets/sound_asset.hpp" #include "assets/sound_asset.hpp"
#include "assets/spine_model_asset.hpp" #include "assets/spine_asset.hpp"
#include "assets/sprite_asset.hpp" #include "assets/sprite_asset.hpp"
#include "assets/text_asset.hpp" #include "assets/text_asset.hpp"
#include "assets/texture_asset.hpp" #include "assets/texture_asset.hpp"
@@ -59,6 +59,7 @@
#include "node.hpp" #include "node.hpp"
#include "node.inl" #include "node.inl"
#include "prefab.hpp" #include "prefab.hpp"
#include "spine.hpp"
#include "sprite.hpp" #include "sprite.hpp"
#include "starter.hpp" #include "starter.hpp"
#include "world.hpp" #include "world.hpp"

View File

@@ -33,7 +33,7 @@ namespace e2d
class shader_asset; class shader_asset;
class shape_asset; class shape_asset;
class sound_asset; class sound_asset;
class spine_model_asset; class spine_asset;
class sprite_asset; class sprite_asset;
class text_asset; class text_asset;
class texture_asset; class texture_asset;
@@ -74,6 +74,7 @@ namespace e2d
class model; class model;
class node; class node;
class prefab; class prefab;
class spine;
class sprite; class sprite;
class starter; class starter;
class world; class world;

View File

@@ -9,13 +9,13 @@
#include "../_high.hpp" #include "../_high.hpp"
#include "../library.hpp" #include "../library.hpp"
#include "../spine_model.hpp" #include "../spine.hpp"
namespace e2d namespace e2d
{ {
class spine_model_asset final : public content_asset<spine_model_asset, spine_model> { class spine_asset final : public content_asset<spine_asset, spine> {
public: public:
static const char* type_name() noexcept { return "spine_model_asset"; } static const char* type_name() noexcept { return "spine_asset"; }
static load_async_result load_async(const library& library, str_view address); static load_async_result load_async(const library& library, str_view address);
}; };
} }

View File

@@ -9,8 +9,8 @@
#include "../_high.hpp" #include "../_high.hpp"
#include "../factory.hpp" #include "../factory.hpp"
#include "../assets/spine_asset.hpp"
#include "../assets/material_asset.hpp" #include "../assets/material_asset.hpp"
#include "../assets/spine_model_asset.hpp"
struct spSkeleton; struct spSkeleton;
struct spSkeletonClipping; struct spSkeletonClipping;
@@ -32,13 +32,14 @@ namespace e2d
using animation_ptr = std::shared_ptr<spAnimationState>; using animation_ptr = std::shared_ptr<spAnimationState>;
public: public:
spine_player() = default; spine_player() = default;
spine_player(const spine_model_asset::ptr& model); spine_player(const spine_asset::ptr& spine);
spine_player& model( spine_player& spine(
const spine_model_asset::ptr& value); const spine_asset::ptr& value);
spine_player& materials( spine_player& materials(
flat_map<str_hash, material_asset::ptr>&& value) noexcept; flat_map<str_hash, material_asset::ptr>&& value) noexcept;
spine_player& materials( spine_player& materials(
const flat_map<str_hash, material_asset::ptr>& value); const flat_map<str_hash, material_asset::ptr>& value);
@@ -48,18 +49,18 @@ namespace e2d
bool has_skin(const str& name) const noexcept; bool has_skin(const str& name) const noexcept;
bool has_animation(const str& name) const noexcept; bool has_animation(const str& name) const noexcept;
const spine_asset::ptr& spine() const noexcept;
const clipping_ptr& clipper() const noexcept; const clipping_ptr& clipper() const noexcept;
const skeleton_ptr& skeleton() const noexcept; const skeleton_ptr& skeleton() const noexcept;
const animation_ptr& animation() const noexcept; const animation_ptr& animation() const noexcept;
const spine_model_asset::ptr& model() const noexcept;
material_asset::ptr find_material(str_hash name) const noexcept; material_asset::ptr find_material(str_hash name) const noexcept;
const flat_map<str_hash, material_asset::ptr>& materials() const noexcept; const flat_map<str_hash, material_asset::ptr>& materials() const noexcept;
private: private:
spine_asset::ptr spine_;
clipping_ptr clipping_; clipping_ptr clipping_;
skeleton_ptr skeleton_; skeleton_ptr skeleton_;
animation_ptr animation_; animation_ptr animation_;
spine_model_asset::ptr model_;
flat_map<str_hash, material_asset::ptr> materials_; flat_map<str_hash, material_asset::ptr> materials_;
}; };
@@ -71,7 +72,7 @@ namespace e2d
bool operator()( bool operator()(
spine_player& component, spine_player& component,
const fill_context& ctx) const; const fill_context& ctx) const;
bool operator()( bool operator()(
asset_dependencies& dependencies, asset_dependencies& dependencies,
const collect_context& ctx) const; const collect_context& ctx) const;

View File

@@ -14,39 +14,39 @@ struct spAnimationStateData;
namespace e2d namespace e2d
{ {
class bad_spine_model_access final : public exception { class bad_spine_access final : public exception {
public: public:
const char* what() const noexcept final { const char* what() const noexcept final {
return "bad spine model access"; return "bad spine access";
} }
}; };
class spine_model final { class spine final {
public: public:
using atlas_ptr = std::shared_ptr<spAtlas>; using atlas_ptr = std::shared_ptr<spAtlas>;
using skeleton_data_ptr = std::shared_ptr<spSkeletonData>; using skeleton_data_ptr = std::shared_ptr<spSkeletonData>;
using animation_data_ptr = std::shared_ptr<spAnimationStateData>; using animation_data_ptr = std::shared_ptr<spAnimationStateData>;
public: public:
spine_model() = default; spine() = default;
~spine_model() noexcept = default; ~spine() noexcept = default;
spine_model(spine_model&& other) noexcept; spine(spine&& other) noexcept;
spine_model& operator=(spine_model&& other) noexcept; spine& operator=(spine&& other) noexcept;
spine_model(const spine_model& other); spine(const spine& other);
spine_model& operator=(const spine_model& other); spine& operator=(const spine& other);
void clear() noexcept; void clear() noexcept;
void swap(spine_model& other) noexcept; void swap(spine& other) noexcept;
spine_model& assign(spine_model&& other) noexcept; spine& assign(spine&& other) noexcept;
spine_model& assign(const spine_model& other); spine& assign(const spine& other);
spine_model& set_atlas(atlas_ptr atlas); spine& set_atlas(atlas_ptr atlas);
spine_model& set_skeleton(skeleton_data_ptr skeleton); spine& set_skeleton(skeleton_data_ptr skeleton);
spine_model& set_default_mix(secf duration); spine& set_default_mix(secf duration);
spine_model& set_animation_mix( spine& set_animation_mix(
const str& from, const str& from,
const str& to, const str& to,
secf duration); secf duration);
@@ -60,7 +60,7 @@ namespace e2d
animation_data_ptr animation_; animation_data_ptr animation_;
}; };
void swap(spine_model& l, spine_model& r) noexcept; void swap(spine& l, spine& r) noexcept;
bool operator==(const spine_model& l, const spine_model& r) noexcept; bool operator==(const spine& l, const spine& r) noexcept;
bool operator!=(const spine_model& l, const spine_model& r) noexcept; bool operator!=(const spine& l, const spine& r) noexcept;
} }

View File

@@ -2,7 +2,7 @@
"prototype" : "spine_prefab.json", "prototype" : "spine_prefab.json",
"components" : { "components" : {
"spine_player" : { "spine_player" : {
"model" : "../spines/coin_spine.json" "spine" : "../spines/coin_spine.json"
}, },
"spine_player_cmd" : { "spine_player_cmd" : {
"commands" : [{ "commands" : [{

View File

@@ -2,7 +2,7 @@
"prototype" : "spine_prefab.json", "prototype" : "spine_prefab.json",
"components" : { "components" : {
"spine_player" : { "spine_player" : {
"model" : "../spines/dragon_spine.json" "spine" : "../spines/dragon_spine.json"
}, },
"spine_player_cmd" : { "spine_player_cmd" : {
"commands" : [{ "commands" : [{

View File

@@ -2,7 +2,7 @@
"prototype" : "spine_prefab.json", "prototype" : "spine_prefab.json",
"components" : { "components" : {
"spine_player" : { "spine_player" : {
"model" : "../spines/raptor_spine.json" "spine" : "../spines/raptor_spine.json"
}, },
"spine_player_cmd" : { "spine_player_cmd" : {
"commands" : [{ "commands" : [{

View File

@@ -4,7 +4,7 @@
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/ ******************************************************************************/
#include <enduro2d/high/assets/spine_model_asset.hpp> #include <enduro2d/high/assets/spine_asset.hpp>
#include <enduro2d/high/assets/json_asset.hpp> #include <enduro2d/high/assets/json_asset.hpp>
#include <enduro2d/high/assets/binary_asset.hpp> #include <enduro2d/high/assets/binary_asset.hpp>
@@ -17,13 +17,13 @@ namespace
{ {
using namespace e2d; using namespace e2d;
class spine_model_asset_loading_exception final : public asset_loading_exception { class spine_asset_loading_exception final : public asset_loading_exception {
const char* what() const noexcept final { const char* what() const noexcept final {
return "spine model asset loading exception"; return "spine asset loading exception";
} }
}; };
const char* spine_model_asset_schema_source = R"json({ const char* spine_asset_schema_source = R"json({
"type" : "object", "type" : "object",
"required" : [ "atlas", "skeleton" ], "required" : [ "atlas", "skeleton" ],
"additionalProperties" : false, "additionalProperties" : false,
@@ -52,16 +52,16 @@ namespace
} }
})json"; })json";
const rapidjson::SchemaDocument& spine_model_asset_schema() { const rapidjson::SchemaDocument& spine_asset_schema() {
static std::mutex mutex; static std::mutex mutex;
static std::unique_ptr<rapidjson::SchemaDocument> schema; static std::unique_ptr<rapidjson::SchemaDocument> schema;
std::lock_guard<std::mutex> guard(mutex); std::lock_guard<std::mutex> guard(mutex);
if ( !schema ) { if ( !schema ) {
rapidjson::Document doc; rapidjson::Document doc;
if ( doc.Parse(spine_model_asset_schema_source).HasParseError() ) { if ( doc.Parse(spine_asset_schema_source).HasParseError() ) {
the<debug>().error("SPINE: Failed to parse spine model asset schema"); the<debug>().error("ASSETS: Failed to parse spine asset schema");
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
json_utils::add_common_schema_definitions(doc); json_utils::add_common_schema_definitions(doc);
schema = std::make_unique<rapidjson::SchemaDocument>(doc); schema = std::make_unique<rapidjson::SchemaDocument>(doc);
@@ -82,19 +82,19 @@ namespace
E2D_ASSERT(root.HasMember("from") && root["from"].IsString()); E2D_ASSERT(root.HasMember("from") && root["from"].IsString());
if ( !json_utils::try_parse_value(root["from"], mix.from) ) { if ( !json_utils::try_parse_value(root["from"], mix.from) ) {
the<debug>().error("SPINE: Incorrect formating of 'from' property"); the<debug>().error("SPINE: Incorrect formating of 'from' property");
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
E2D_ASSERT(root.HasMember("to") && root["to"].IsString()); E2D_ASSERT(root.HasMember("to") && root["to"].IsString());
if ( !json_utils::try_parse_value(root["to"], mix.to) ) { if ( !json_utils::try_parse_value(root["to"], mix.to) ) {
the<debug>().error("SPINE: Incorrect formating of 'to' property"); the<debug>().error("SPINE: Incorrect formating of 'to' property");
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
E2D_ASSERT(root.HasMember("duration") && root["duration"].IsNumber()); E2D_ASSERT(root.HasMember("duration") && root["duration"].IsNumber());
if ( !json_utils::try_parse_value(root["duration"], mix.duration) ) { if ( !json_utils::try_parse_value(root["duration"], mix.duration) ) {
the<debug>().error("SPINE: Incorrect formating of 'duration' property"); the<debug>().error("SPINE: Incorrect formating of 'duration' property");
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
return mix; return mix;
@@ -105,7 +105,7 @@ namespace
asset_dependencies loading; asset_dependencies loading;
}; };
stdex::promise<spine_model::atlas_ptr> load_atlas( stdex::promise<spine::atlas_ptr> load_atlas(
const library& library, const library& library,
const str& parent_address, const str& parent_address,
const str& atlas_address) const str& atlas_address)
@@ -120,7 +120,7 @@ namespace
](const binary_asset::load_result& atlas_data){ ](const binary_asset::load_result& atlas_data){
auto atlas_internal = std::make_unique<atlas_internal_state>(); auto atlas_internal = std::make_unique<atlas_internal_state>();
spine_model::atlas_ptr atlas( spine::atlas_ptr atlas(
spAtlas_create( spAtlas_create(
reinterpret_cast<const char*>(atlas_data->content().data()), reinterpret_cast<const char*>(atlas_data->content().data()),
math::numeric_cast<int>(atlas_data->content().size()), math::numeric_cast<int>(atlas_data->content().size()),
@@ -130,7 +130,7 @@ namespace
if ( !atlas ) { if ( !atlas ) {
the<debug>().error("SPINE: Failed to create preload atlas"); the<debug>().error("SPINE: Failed to create preload atlas");
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
return stdex::make_tuple_promise(std::make_tuple( return stdex::make_tuple_promise(std::make_tuple(
@@ -146,7 +146,7 @@ namespace
auto atlas_internal = std::make_unique<atlas_internal_state>(); auto atlas_internal = std::make_unique<atlas_internal_state>();
atlas_internal->loaded = std::get<0>(results); atlas_internal->loaded = std::get<0>(results);
spine_model::atlas_ptr atlas( spine::atlas_ptr atlas(
spAtlas_create( spAtlas_create(
reinterpret_cast<const char*>(std::get<1>(results)->content().data()), reinterpret_cast<const char*>(std::get<1>(results)->content().data()),
math::numeric_cast<int>(std::get<1>(results)->content().size()), math::numeric_cast<int>(std::get<1>(results)->content().size()),
@@ -156,13 +156,13 @@ namespace
if ( !atlas ) { if ( !atlas ) {
the<debug>().error("SPINE: Failed to create preloaded atlas"); the<debug>().error("SPINE: Failed to create preloaded atlas");
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
for ( const spAtlasPage* page = atlas->pages; page; page = page->next ) { for ( const spAtlasPage* page = atlas->pages; page; page = page->next ) {
if ( !page->rendererObject ) { if ( !page->rendererObject ) {
the<debug>().error("SPINE: Failed to create preloaded atlas"); the<debug>().error("SPINE: Failed to create preloaded atlas");
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
} }
@@ -171,12 +171,12 @@ namespace
}); });
} }
stdex::promise<spine_model::skeleton_data_ptr> load_skeleton_data( stdex::promise<spine::skeleton_data_ptr> load_skeleton_data(
const library& library, const library& library,
const str& parent_address, const str& parent_address,
const str& skeleton_address, const str& skeleton_address,
f32 skeleton_scale, f32 skeleton_scale,
const spine_model::atlas_ptr& atlas) const spine::atlas_ptr& atlas)
{ {
return library.load_asset_async<binary_asset>( return library.load_asset_async<binary_asset>(
path::combine(parent_address, skeleton_address)) path::combine(parent_address, skeleton_address))
@@ -196,12 +196,12 @@ namespace
if ( !binary_skeleton ) { if ( !binary_skeleton ) {
the<debug>().error("SPINE: Failed to create binary skeleton"); the<debug>().error("SPINE: Failed to create binary skeleton");
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
binary_skeleton->scale = skeleton_scale; binary_skeleton->scale = skeleton_scale;
spine_model::skeleton_data_ptr data_skeleton( spine::skeleton_data_ptr data_skeleton(
spSkeletonBinary_readSkeletonData( spSkeletonBinary_readSkeletonData(
binary_skeleton.get(), binary_skeleton.get(),
reinterpret_cast<const unsigned char*>(skeleton_data->content().data()), reinterpret_cast<const unsigned char*>(skeleton_data->content().data()),
@@ -212,7 +212,7 @@ namespace
the<debug>().error("SPINE: Failed to read binary skeleton data:\n" the<debug>().error("SPINE: Failed to read binary skeleton data:\n"
"--> Error: %0", "--> Error: %0",
binary_skeleton->error); binary_skeleton->error);
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
return data_skeleton; return data_skeleton;
@@ -227,12 +227,12 @@ namespace
if ( !json_skeleton ) { if ( !json_skeleton ) {
the<debug>().error("SPINE: Failed to create json skeleton"); the<debug>().error("SPINE: Failed to create json skeleton");
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
json_skeleton->scale = skeleton_scale; json_skeleton->scale = skeleton_scale;
spine_model::skeleton_data_ptr data_skeleton( spine::skeleton_data_ptr data_skeleton(
spSkeletonJson_readSkeletonData( spSkeletonJson_readSkeletonData(
json_skeleton.get(), json_skeleton.get(),
reinterpret_cast<const char*>(skeleton_data->content().data())), reinterpret_cast<const char*>(skeleton_data->content().data())),
@@ -242,7 +242,7 @@ namespace
the<debug>().error("SPINE: Failed to read json skeleton data:\n" the<debug>().error("SPINE: Failed to read json skeleton data:\n"
"--> Error: %0", "--> Error: %0",
json_skeleton->error); json_skeleton->error);
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
} }
return data_skeleton; return data_skeleton;
@@ -250,7 +250,7 @@ namespace
}); });
} }
stdex::promise<spine_model> parse_spine_model( stdex::promise<spine> parse_spine(
const library& library, const library& library,
const str& parent_address, const str& parent_address,
const rapidjson::Value& root) const rapidjson::Value& root)
@@ -297,7 +297,7 @@ namespace
atlas_address, atlas_address,
skeleton_scale, skeleton_scale,
skeleton_address skeleton_address
](const spine_model::atlas_ptr& atlas){ ](const spine::atlas_ptr& atlas){
return stdex::make_tuple_promise(std::make_tuple( return stdex::make_tuple_promise(std::make_tuple(
stdex::make_resolved_promise(atlas), stdex::make_resolved_promise(atlas),
load_skeleton_data( load_skeleton_data(
@@ -311,10 +311,10 @@ namespace
default_animation_mix, default_animation_mix,
animation_mixes = std::move(animation_mixes) animation_mixes = std::move(animation_mixes)
](const std::tuple< ](const std::tuple<
spine_model::atlas_ptr, spine::atlas_ptr,
spine_model::skeleton_data_ptr spine::skeleton_data_ptr
>& results){ >& results){
spine_model content; spine content;
content.set_atlas(std::get<0>(results)); content.set_atlas(std::get<0>(results));
content.set_skeleton(std::get<1>(results)); content.set_skeleton(std::get<1>(results));
content.set_default_mix(default_animation_mix); content.set_default_mix(default_animation_mix);
@@ -328,7 +328,7 @@ namespace
namespace e2d namespace e2d
{ {
spine_model_asset::load_async_result spine_model_asset::load_async( spine_asset::load_async_result spine_asset::load_async(
const library& library, str_view address) const library& library, str_view address)
{ {
return library.load_asset_async<json_asset>(address) return library.load_asset_async<json_asset>(address)
@@ -339,7 +339,7 @@ namespace e2d
](const json_asset::load_result& spine_data){ ](const json_asset::load_result& spine_data){
return the<deferrer>().do_in_worker_thread([address, spine_data](){ return the<deferrer>().do_in_worker_thread([address, spine_data](){
const rapidjson::Document& doc = *spine_data->content(); const rapidjson::Document& doc = *spine_data->content();
rapidjson::SchemaValidator validator(spine_model_asset_schema()); rapidjson::SchemaValidator validator(spine_asset_schema());
if ( doc.Accept(validator) ) { if ( doc.Accept(validator) ) {
return; return;
@@ -358,14 +358,14 @@ namespace e2d
the<debug>().error("ASSET: Failed to validate asset json"); the<debug>().error("ASSET: Failed to validate asset json");
} }
throw spine_model_asset_loading_exception(); throw spine_asset_loading_exception();
}) })
.then([&library, parent_address, spine_data](){ .then([&library, parent_address, spine_data](){
return parse_spine_model( return parse_spine(
library, parent_address, *spine_data->content()); library, parent_address, *spine_data->content());
}) })
.then([](auto&& content){ .then([](auto&& content){
return spine_model_asset::create( return spine_asset::create(
std::forward<decltype(content)>(content)); std::forward<decltype(content)>(content));
}); });
}); });

View File

@@ -10,11 +10,11 @@
namespace e2d namespace e2d
{ {
spine_player::spine_player(const spine_model_asset::ptr& model) { spine_player::spine_player(const spine_asset::ptr& spine) {
this->model(model); this->spine(spine);
} }
spine_player& spine_player::model(const spine_model_asset::ptr& value) { spine_player& spine_player::spine(const spine_asset::ptr& value) {
clipping_ptr new_clipping = clipping_ptr( clipping_ptr new_clipping = clipping_ptr(
spSkeletonClipping_create(), spSkeletonClipping_create(),
spSkeletonClipping_dispose); spSkeletonClipping_dispose);
@@ -42,7 +42,7 @@ namespace e2d
} }
} }
model_ = value; spine_ = value;
clipping_ = std::move(new_clipping); clipping_ = std::move(new_clipping);
skeleton_ = std::move(new_skeleton); skeleton_ = std::move(new_skeleton);
animation_ = std::move(new_animation); animation_ = std::move(new_animation);
@@ -69,7 +69,7 @@ namespace e2d
} }
return *this; return *this;
} }
spine_player& spine_player::attachment(const str& slot, const str& name) noexcept { spine_player& spine_player::attachment(const str& slot, const str& name) noexcept {
if ( !spSkeleton_setAttachment(skeleton_.get(), slot.c_str(), name.c_str()) ) { if ( !spSkeleton_setAttachment(skeleton_.get(), slot.c_str(), name.c_str()) ) {
the<debug>().error("SPINE_PLAYER: can't set attachment '%0' to slot '%1'", name, slot); the<debug>().error("SPINE_PLAYER: can't set attachment '%0' to slot '%1'", name, slot);
@@ -78,17 +78,21 @@ namespace e2d
} }
bool spine_player::has_skin(const str& name) const noexcept { bool spine_player::has_skin(const str& name) const noexcept {
return model_ return spine_
&& model()->content().skeleton() && spine()->content().skeleton()
&& spSkeletonData_findSkin(model()->content().skeleton().get(), name.c_str()); && spSkeletonData_findSkin(spine()->content().skeleton().get(), name.c_str());
}
bool spine_player::has_animation(const str& name) const noexcept {
return model_
&& model()->content().skeleton()
&& spSkeletonData_findAnimation(model()->content().skeleton().get(), name.c_str());
} }
bool spine_player::has_animation(const str& name) const noexcept {
return spine_
&& spine()->content().skeleton()
&& spSkeletonData_findAnimation(spine()->content().skeleton().get(), name.c_str());
}
const spine_asset::ptr& spine_player::spine() const noexcept {
return spine_;
}
const spine_player::clipping_ptr& spine_player::clipper() const noexcept { const spine_player::clipping_ptr& spine_player::clipper() const noexcept {
return clipping_; return clipping_;
} }
@@ -100,10 +104,6 @@ namespace e2d
const spine_player::animation_ptr& spine_player::animation() const noexcept { const spine_player::animation_ptr& spine_player::animation() const noexcept {
return animation_; return animation_;
} }
const spine_model_asset::ptr& spine_player::model() const noexcept {
return model_;
}
material_asset::ptr spine_player::find_material(str_hash name) const noexcept { material_asset::ptr spine_player::find_material(str_hash name) const noexcept {
const auto iter = materials_.find(name); const auto iter = materials_.find(name);
@@ -124,7 +124,7 @@ namespace e2d
"required" : [], "required" : [],
"additionalProperties" : false, "additionalProperties" : false,
"properties" : { "properties" : {
"model" : { "$ref": "#/common_definitions/address" }, "spine" : { "$ref": "#/common_definitions/address" },
"materials" : { "$ref": "#/definitions/materials" }, "materials" : { "$ref": "#/definitions/materials" },
"skin" : { "$ref": "#/common_definitions/name" }, "skin" : { "$ref": "#/common_definitions/name" },
"attachments" : { "$ref": "#/definitions/attachments" } "attachments" : { "$ref": "#/definitions/attachments" }
@@ -156,23 +156,23 @@ namespace e2d
} }
} }
})json"; })json";
bool factory_loader<spine_player>::operator()( bool factory_loader<spine_player>::operator()(
spine_player& component, spine_player& component,
const fill_context& ctx) const const fill_context& ctx) const
{ {
if ( ctx.root.HasMember("model") ) { if ( ctx.root.HasMember("spine") ) {
auto model = ctx.dependencies.find_asset<spine_model_asset>( auto spine = ctx.dependencies.find_asset<spine_asset>(
path::combine(ctx.parent_address, ctx.root["model"].GetString())); path::combine(ctx.parent_address, ctx.root["spine"].GetString()));
if ( !model ) { if ( !spine ) {
the<debug>().error("SPINE_PLAYER: Dependency 'model' is not found:\n" the<debug>().error("SPINE_PLAYER: Dependency 'spine' is not found:\n"
"--> Parent address: %0\n" "--> Parent address: %0\n"
"--> Dependency address: %1", "--> Dependency address: %1",
ctx.parent_address, ctx.parent_address,
ctx.root["model"].GetString()); ctx.root["spine"].GetString());
return false; return false;
} }
component.model(model); component.spine(spine);
} }
if ( ctx.root.HasMember("materials") ) { if ( ctx.root.HasMember("materials") ) {
@@ -209,7 +209,7 @@ namespace e2d
} }
component.materials(std::move(materials)); component.materials(std::move(materials));
} }
if ( ctx.root.HasMember("skin") ) { if ( ctx.root.HasMember("skin") ) {
str skin; str skin;
if ( !json_utils::try_parse_value(ctx.root["skin"], skin) ) { if ( !json_utils::try_parse_value(ctx.root["skin"], skin) ) {
@@ -222,7 +222,7 @@ namespace e2d
if ( ctx.root.HasMember("attachments") ) { if ( ctx.root.HasMember("attachments") ) {
const auto& attachments_json = ctx.root["attachments"]; const auto& attachments_json = ctx.root["attachments"];
E2D_ASSERT(attachments_json.IsArray()); E2D_ASSERT(attachments_json.IsArray());
for ( rapidjson::SizeType i = 0; i < attachments_json.Size(); ++i ) { for ( rapidjson::SizeType i = 0; i < attachments_json.Size(); ++i ) {
E2D_ASSERT(attachments_json[i].IsObject()); E2D_ASSERT(attachments_json[i].IsObject());
const auto& attachment_json = attachments_json[i]; const auto& attachment_json = attachments_json[i];
@@ -247,14 +247,14 @@ namespace e2d
return true; return true;
} }
bool factory_loader<spine_player>::operator()( bool factory_loader<spine_player>::operator()(
asset_dependencies& dependencies, asset_dependencies& dependencies,
const collect_context& ctx) const const collect_context& ctx) const
{ {
if ( ctx.root.HasMember("model") ) { if ( ctx.root.HasMember("spine") ) {
dependencies.add_dependency<spine_model_asset>( dependencies.add_dependency<spine_asset>(
path::combine(ctx.parent_address, ctx.root["model"].GetString())); path::combine(ctx.parent_address, ctx.root["spine"].GetString()));
} }
if ( ctx.root.HasMember("materials") ) { if ( ctx.root.HasMember("materials") ) {

View File

@@ -4,52 +4,52 @@
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/ ******************************************************************************/
#include <enduro2d/high/spine_model.hpp> #include <enduro2d/high/spine.hpp>
#include <spine/spine.h> #include <spine/spine.h>
namespace e2d namespace e2d
{ {
spine_model::spine_model(spine_model&& other) noexcept { spine::spine(spine&& other) noexcept {
assign(std::move(other)); assign(std::move(other));
} }
spine_model& spine_model::operator=(spine_model&& other) noexcept { spine& spine::operator=(spine&& other) noexcept {
return assign(std::move(other)); return assign(std::move(other));
} }
spine_model::spine_model(const spine_model& other) { spine::spine(const spine& other) {
assign(other); assign(other);
} }
spine_model& spine_model::operator=(const spine_model& other) { spine& spine::operator=(const spine& other) {
return assign(other); return assign(other);
} }
void spine_model::clear() noexcept { void spine::clear() noexcept {
atlas_.reset(); atlas_.reset();
skeleton_.reset(); skeleton_.reset();
animation_.reset(); animation_.reset();
} }
void spine_model::swap(spine_model& other) noexcept { void spine::swap(spine& other) noexcept {
using std::swap; using std::swap;
swap(atlas_, other.atlas_); swap(atlas_, other.atlas_);
swap(skeleton_, other.skeleton_); swap(skeleton_, other.skeleton_);
swap(animation_, other.animation_); swap(animation_, other.animation_);
} }
spine_model& spine_model::assign(spine_model&& other) noexcept { spine& spine::assign(spine&& other) noexcept {
if ( this != &other ) { if ( this != &other ) {
swap(other); swap(other);
other.clear(); other.clear();
} }
return *this; return *this;
} }
spine_model& spine_model::assign(const spine_model& other) { spine& spine::assign(const spine& other) {
if ( this != &other ) { if ( this != &other ) {
spine_model m; spine m;
m.atlas_ = other.atlas_; m.atlas_ = other.atlas_;
m.skeleton_ = other.skeleton_; m.skeleton_ = other.skeleton_;
m.animation_ = other.animation_; m.animation_ = other.animation_;
@@ -58,12 +58,12 @@ namespace e2d
return *this; return *this;
} }
spine_model& spine_model::set_atlas(atlas_ptr atlas) { spine& spine::set_atlas(atlas_ptr atlas) {
atlas_ = std::move(atlas); atlas_ = std::move(atlas);
return *this; return *this;
} }
spine_model& spine_model::set_skeleton(skeleton_data_ptr skeleton) { spine& spine::set_skeleton(skeleton_data_ptr skeleton) {
animation_data_ptr animation; animation_data_ptr animation;
if ( skeleton ) { if ( skeleton ) {
animation.reset( animation.reset(
@@ -78,15 +78,15 @@ namespace e2d
return *this; return *this;
} }
spine_model& spine_model::set_default_mix(secf duration) { spine& spine::set_default_mix(secf duration) {
if ( !animation_ ) { if ( !animation_ ) {
throw bad_spine_model_access(); throw bad_spine_access();
} }
animation_->defaultMix = duration.value; animation_->defaultMix = duration.value;
return *this; return *this;
} }
spine_model& spine_model::set_animation_mix( spine& spine::set_animation_mix(
const str& from, const str& from,
const str& to, const str& to,
secf duration) secf duration)
@@ -100,39 +100,39 @@ namespace e2d
: nullptr; : nullptr;
if ( !from_anim || !to_anim ) { if ( !from_anim || !to_anim ) {
throw bad_spine_model_access(); throw bad_spine_access();
} }
spAnimationStateData_setMix(animation_.get(), from_anim, to_anim, duration.value); spAnimationStateData_setMix(animation_.get(), from_anim, to_anim, duration.value);
return *this; return *this;
} }
const spine_model::atlas_ptr& spine_model::atlas() const noexcept { const spine::atlas_ptr& spine::atlas() const noexcept {
return atlas_; return atlas_;
} }
const spine_model::skeleton_data_ptr& spine_model::skeleton() const noexcept { const spine::skeleton_data_ptr& spine::skeleton() const noexcept {
return skeleton_; return skeleton_;
} }
const spine_model::animation_data_ptr& spine_model::animation() const noexcept { const spine::animation_data_ptr& spine::animation() const noexcept {
return animation_; return animation_;
} }
} }
namespace e2d namespace e2d
{ {
void swap(spine_model& l, spine_model& r) noexcept { void swap(spine& l, spine& r) noexcept {
l.swap(r); l.swap(r);
} }
bool operator==(const spine_model& l, const spine_model& r) noexcept { bool operator==(const spine& l, const spine& r) noexcept {
return l.atlas() == r.atlas() return l.atlas() == r.atlas()
&& l.skeleton() == r.skeleton() && l.skeleton() == r.skeleton()
&& l.animation() == r.animation(); && l.animation() == r.animation();
} }
bool operator!=(const spine_model& l, const spine_model& r) noexcept { bool operator!=(const spine& l, const spine& r) noexcept {
return !(l == r); return !(l == r);
} }
} }

View File

@@ -35,10 +35,10 @@ TEST_CASE("render"){
} }
{ {
const auto ss = render::sampler_state() const auto ss = render::sampler_state()
.wrap(render::sampler_wrap::clamp) .wrap(render::sampler_wrap::clamp, render::sampler_wrap::mirror)
.filter(render::sampler_min_filter::linear, render::sampler_mag_filter::nearest); .filter(render::sampler_min_filter::linear, render::sampler_mag_filter::nearest);
REQUIRE(ss.s_wrap() == render::sampler_wrap::clamp); REQUIRE(ss.s_wrap() == render::sampler_wrap::clamp);
REQUIRE(ss.t_wrap() == render::sampler_wrap::clamp); REQUIRE(ss.t_wrap() == render::sampler_wrap::mirror);
REQUIRE(ss.min_filter() == render::sampler_min_filter::linear); REQUIRE(ss.min_filter() == render::sampler_min_filter::linear);
REQUIRE(ss.mag_filter() == render::sampler_mag_filter::nearest); REQUIRE(ss.mag_filter() == render::sampler_mag_filter::nearest);
} }