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

@@ -4,7 +4,7 @@
* 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/binary_asset.hpp>
@@ -17,13 +17,13 @@ namespace
{
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 {
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",
"required" : [ "atlas", "skeleton" ],
"additionalProperties" : false,
@@ -52,16 +52,16 @@ namespace
}
})json";
const rapidjson::SchemaDocument& spine_model_asset_schema() {
const rapidjson::SchemaDocument& spine_asset_schema() {
static std::mutex mutex;
static std::unique_ptr<rapidjson::SchemaDocument> schema;
std::lock_guard<std::mutex> guard(mutex);
if ( !schema ) {
rapidjson::Document doc;
if ( doc.Parse(spine_model_asset_schema_source).HasParseError() ) {
the<debug>().error("SPINE: Failed to parse spine model asset schema");
throw spine_model_asset_loading_exception();
if ( doc.Parse(spine_asset_schema_source).HasParseError() ) {
the<debug>().error("ASSETS: Failed to parse spine asset schema");
throw spine_asset_loading_exception();
}
json_utils::add_common_schema_definitions(doc);
schema = std::make_unique<rapidjson::SchemaDocument>(doc);
@@ -82,19 +82,19 @@ namespace
E2D_ASSERT(root.HasMember("from") && root["from"].IsString());
if ( !json_utils::try_parse_value(root["from"], mix.from) ) {
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());
if ( !json_utils::try_parse_value(root["to"], mix.to) ) {
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());
if ( !json_utils::try_parse_value(root["duration"], mix.duration) ) {
the<debug>().error("SPINE: Incorrect formating of 'duration' property");
throw spine_model_asset_loading_exception();
throw spine_asset_loading_exception();
}
return mix;
@@ -105,7 +105,7 @@ namespace
asset_dependencies loading;
};
stdex::promise<spine_model::atlas_ptr> load_atlas(
stdex::promise<spine::atlas_ptr> load_atlas(
const library& library,
const str& parent_address,
const str& atlas_address)
@@ -120,7 +120,7 @@ namespace
](const binary_asset::load_result& atlas_data){
auto atlas_internal = std::make_unique<atlas_internal_state>();
spine_model::atlas_ptr atlas(
spine::atlas_ptr atlas(
spAtlas_create(
reinterpret_cast<const char*>(atlas_data->content().data()),
math::numeric_cast<int>(atlas_data->content().size()),
@@ -130,7 +130,7 @@ namespace
if ( !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(
@@ -146,7 +146,7 @@ namespace
auto atlas_internal = std::make_unique<atlas_internal_state>();
atlas_internal->loaded = std::get<0>(results);
spine_model::atlas_ptr atlas(
spine::atlas_ptr atlas(
spAtlas_create(
reinterpret_cast<const char*>(std::get<1>(results)->content().data()),
math::numeric_cast<int>(std::get<1>(results)->content().size()),
@@ -156,13 +156,13 @@ namespace
if ( !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 ) {
if ( !page->rendererObject ) {
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 str& parent_address,
const str& skeleton_address,
f32 skeleton_scale,
const spine_model::atlas_ptr& atlas)
const spine::atlas_ptr& atlas)
{
return library.load_asset_async<binary_asset>(
path::combine(parent_address, skeleton_address))
@@ -196,12 +196,12 @@ namespace
if ( !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;
spine_model::skeleton_data_ptr data_skeleton(
spine::skeleton_data_ptr data_skeleton(
spSkeletonBinary_readSkeletonData(
binary_skeleton.get(),
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"
"--> Error: %0",
binary_skeleton->error);
throw spine_model_asset_loading_exception();
throw spine_asset_loading_exception();
}
return data_skeleton;
@@ -227,12 +227,12 @@ namespace
if ( !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;
spine_model::skeleton_data_ptr data_skeleton(
spine::skeleton_data_ptr data_skeleton(
spSkeletonJson_readSkeletonData(
json_skeleton.get(),
reinterpret_cast<const char*>(skeleton_data->content().data())),
@@ -242,7 +242,7 @@ namespace
the<debug>().error("SPINE: Failed to read json skeleton data:\n"
"--> Error: %0",
json_skeleton->error);
throw spine_model_asset_loading_exception();
throw spine_asset_loading_exception();
}
return data_skeleton;
@@ -250,7 +250,7 @@ namespace
});
}
stdex::promise<spine_model> parse_spine_model(
stdex::promise<spine> parse_spine(
const library& library,
const str& parent_address,
const rapidjson::Value& root)
@@ -297,7 +297,7 @@ namespace
atlas_address,
skeleton_scale,
skeleton_address
](const spine_model::atlas_ptr& atlas){
](const spine::atlas_ptr& atlas){
return stdex::make_tuple_promise(std::make_tuple(
stdex::make_resolved_promise(atlas),
load_skeleton_data(
@@ -311,10 +311,10 @@ namespace
default_animation_mix,
animation_mixes = std::move(animation_mixes)
](const std::tuple<
spine_model::atlas_ptr,
spine_model::skeleton_data_ptr
spine::atlas_ptr,
spine::skeleton_data_ptr
>& results){
spine_model content;
spine content;
content.set_atlas(std::get<0>(results));
content.set_skeleton(std::get<1>(results));
content.set_default_mix(default_animation_mix);
@@ -328,7 +328,7 @@ namespace
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)
{
return library.load_asset_async<json_asset>(address)
@@ -339,7 +339,7 @@ namespace e2d
](const json_asset::load_result& spine_data){
return the<deferrer>().do_in_worker_thread([address, spine_data](){
const rapidjson::Document& doc = *spine_data->content();
rapidjson::SchemaValidator validator(spine_model_asset_schema());
rapidjson::SchemaValidator validator(spine_asset_schema());
if ( doc.Accept(validator) ) {
return;
@@ -358,14 +358,14 @@ namespace e2d
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](){
return parse_spine_model(
return parse_spine(
library, parent_address, *spine_data->content());
})
.then([](auto&& content){
return spine_model_asset::create(
return spine_asset::create(
std::forward<decltype(content)>(content));
});
});

View File

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

View File

@@ -4,52 +4,52 @@
* 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>
namespace e2d
{
spine_model::spine_model(spine_model&& other) noexcept {
spine::spine(spine&& other) noexcept {
assign(std::move(other));
}
spine_model& spine_model::operator=(spine_model&& other) noexcept {
spine& spine::operator=(spine&& other) noexcept {
return assign(std::move(other));
}
spine_model::spine_model(const spine_model& other) {
spine::spine(const spine& other) {
assign(other);
}
spine_model& spine_model::operator=(const spine_model& other) {
spine& spine::operator=(const spine& other) {
return assign(other);
}
void spine_model::clear() noexcept {
void spine::clear() noexcept {
atlas_.reset();
skeleton_.reset();
animation_.reset();
}
void spine_model::swap(spine_model& other) noexcept {
void spine::swap(spine& other) noexcept {
using std::swap;
swap(atlas_, other.atlas_);
swap(skeleton_, other.skeleton_);
swap(animation_, other.animation_);
}
spine_model& spine_model::assign(spine_model&& other) noexcept {
spine& spine::assign(spine&& other) noexcept {
if ( this != &other ) {
swap(other);
other.clear();
}
return *this;
}
spine_model& spine_model::assign(const spine_model& other) {
spine& spine::assign(const spine& other) {
if ( this != &other ) {
spine_model m;
spine m;
m.atlas_ = other.atlas_;
m.skeleton_ = other.skeleton_;
m.animation_ = other.animation_;
@@ -58,12 +58,12 @@ namespace e2d
return *this;
}
spine_model& spine_model::set_atlas(atlas_ptr atlas) {
spine& spine::set_atlas(atlas_ptr atlas) {
atlas_ = std::move(atlas);
return *this;
}
spine_model& spine_model::set_skeleton(skeleton_data_ptr skeleton) {
spine& spine::set_skeleton(skeleton_data_ptr skeleton) {
animation_data_ptr animation;
if ( skeleton ) {
animation.reset(
@@ -78,15 +78,15 @@ namespace e2d
return *this;
}
spine_model& spine_model::set_default_mix(secf duration) {
spine& spine::set_default_mix(secf duration) {
if ( !animation_ ) {
throw bad_spine_model_access();
throw bad_spine_access();
}
animation_->defaultMix = duration.value;
return *this;
}
spine_model& spine_model::set_animation_mix(
spine& spine::set_animation_mix(
const str& from,
const str& to,
secf duration)
@@ -100,39 +100,39 @@ namespace e2d
: nullptr;
if ( !from_anim || !to_anim ) {
throw bad_spine_model_access();
throw bad_spine_access();
}
spAnimationStateData_setMix(animation_.get(), from_anim, to_anim, duration.value);
return *this;
}
const spine_model::atlas_ptr& spine_model::atlas() const noexcept {
const spine::atlas_ptr& spine::atlas() const noexcept {
return atlas_;
}
const spine_model::skeleton_data_ptr& spine_model::skeleton() const noexcept {
const spine::skeleton_data_ptr& spine::skeleton() const noexcept {
return skeleton_;
}
const spine_model::animation_data_ptr& spine_model::animation() const noexcept {
const spine::animation_data_ptr& spine::animation() const noexcept {
return animation_;
}
}
namespace e2d
{
void swap(spine_model& l, spine_model& r) noexcept {
void swap(spine& l, spine& r) noexcept {
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()
&& l.skeleton() == r.skeleton()
&& 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);
}
}