mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-16 22:16:53 +07:00
remove atlas per pixels per unit property
This commit is contained in:
@@ -44,9 +44,6 @@ namespace e2d
|
|||||||
atlas& set_texture(const texture_asset::ptr& texture) noexcept;
|
atlas& set_texture(const texture_asset::ptr& texture) noexcept;
|
||||||
const texture_asset::ptr& texture() const noexcept;
|
const texture_asset::ptr& texture() const noexcept;
|
||||||
|
|
||||||
atlas& set_pixels_per_unit(f32 pixels_per_unit) noexcept;
|
|
||||||
f32 pixels_per_unit() const noexcept;
|
|
||||||
|
|
||||||
atlas& set_regions(vector<region>&& regions) noexcept;
|
atlas& set_regions(vector<region>&& regions) noexcept;
|
||||||
atlas& set_regions(const vector<region>& regions);
|
atlas& set_regions(const vector<region>& regions);
|
||||||
const vector<region>& regions() const noexcept;
|
const vector<region>& regions() const noexcept;
|
||||||
@@ -58,7 +55,6 @@ namespace e2d
|
|||||||
const shape_region* find_shape_region(str_hash name) const noexcept;
|
const shape_region* find_shape_region(str_hash name) const noexcept;
|
||||||
private:
|
private:
|
||||||
texture_asset::ptr texture_;
|
texture_asset::ptr texture_;
|
||||||
f32 pixels_per_unit_{1.f};
|
|
||||||
vector<region> regions_;
|
vector<region> regions_;
|
||||||
vector<shape_region> shape_regions_;
|
vector<shape_region> shape_regions_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,11 +21,10 @@ namespace
|
|||||||
const char* atlas_asset_schema_source = R"json(
|
const char* atlas_asset_schema_source = R"json(
|
||||||
{
|
{
|
||||||
"type" : "object",
|
"type" : "object",
|
||||||
"required" : [ "texture", "pixels_per_unit" ],
|
"required" : [ "texture" ],
|
||||||
"additionalProperties" : false,
|
"additionalProperties" : false,
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"texture" : { "$ref": "#/common_definitions/address" },
|
"texture" : { "$ref": "#/common_definitions/address" },
|
||||||
"pixels_per_unit" : { "type" : "number" },
|
|
||||||
"regions" : { "$ref": "#/definitions/regions" },
|
"regions" : { "$ref": "#/definitions/regions" },
|
||||||
"shape_regions" : { "$ref": "#/definitions/shape_regions" }
|
"shape_regions" : { "$ref": "#/definitions/shape_regions" }
|
||||||
},
|
},
|
||||||
@@ -154,13 +153,6 @@ namespace
|
|||||||
auto texture_p = library.load_asset_async<texture_asset>(
|
auto texture_p = library.load_asset_async<texture_asset>(
|
||||||
path::combine(parent_address, root["texture"].GetString()));
|
path::combine(parent_address, root["texture"].GetString()));
|
||||||
|
|
||||||
f32 pixels_per_unit = 1.f;
|
|
||||||
E2D_ASSERT(root.HasMember("pixels_per_unit"));
|
|
||||||
if ( !json_utils::try_parse_value(root["pixels_per_unit"], pixels_per_unit) ) {
|
|
||||||
return stdex::make_rejected_promise<atlas>(
|
|
||||||
atlas_asset_loading_exception());
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<atlas::region> regions;
|
vector<atlas::region> regions;
|
||||||
if ( root.HasMember("regions") ) {
|
if ( root.HasMember("regions") ) {
|
||||||
E2D_ASSERT(root["regions"].IsArray());
|
E2D_ASSERT(root["regions"].IsArray());
|
||||||
@@ -182,13 +174,11 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
return texture_p.then([
|
return texture_p.then([
|
||||||
pixels_per_unit,
|
|
||||||
regions = std::move(regions),
|
regions = std::move(regions),
|
||||||
shape_regions = std::move(shape_regions)
|
shape_regions = std::move(shape_regions)
|
||||||
](const texture_asset::load_result& texture) mutable {
|
](const texture_asset::load_result& texture) mutable {
|
||||||
atlas content;
|
atlas content;
|
||||||
content.set_texture(texture);
|
content.set_texture(texture);
|
||||||
content.set_pixels_per_unit(pixels_per_unit);
|
|
||||||
content.set_regions(std::move(regions));
|
content.set_regions(std::move(regions));
|
||||||
content.set_shape_regions(std::move(shape_regions));
|
content.set_shape_regions(std::move(shape_regions));
|
||||||
return content;
|
return content;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ namespace e2d
|
|||||||
|
|
||||||
void atlas::clear() noexcept {
|
void atlas::clear() noexcept {
|
||||||
texture_.reset();
|
texture_.reset();
|
||||||
pixels_per_unit_ = 1.f;
|
|
||||||
regions_.clear();
|
regions_.clear();
|
||||||
shape_regions_.clear();
|
shape_regions_.clear();
|
||||||
}
|
}
|
||||||
@@ -37,7 +36,6 @@ namespace e2d
|
|||||||
void atlas::swap(atlas& other) noexcept {
|
void atlas::swap(atlas& other) noexcept {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap(texture_, other.texture_);
|
swap(texture_, other.texture_);
|
||||||
swap(pixels_per_unit_, other.pixels_per_unit_);
|
|
||||||
swap(regions_, other.regions_);
|
swap(regions_, other.regions_);
|
||||||
swap(shape_regions_, other.shape_regions_);
|
swap(shape_regions_, other.shape_regions_);
|
||||||
}
|
}
|
||||||
@@ -54,7 +52,6 @@ namespace e2d
|
|||||||
if ( this != &other ) {
|
if ( this != &other ) {
|
||||||
atlas s;
|
atlas s;
|
||||||
s.texture_ = other.texture_;
|
s.texture_ = other.texture_;
|
||||||
s.pixels_per_unit_ = other.pixels_per_unit_;
|
|
||||||
s.regions_ = other.regions_;
|
s.regions_ = other.regions_;
|
||||||
s.shape_regions_ = other.shape_regions_;
|
s.shape_regions_ = other.shape_regions_;
|
||||||
swap(s);
|
swap(s);
|
||||||
@@ -71,15 +68,6 @@ namespace e2d
|
|||||||
return texture_;
|
return texture_;
|
||||||
}
|
}
|
||||||
|
|
||||||
atlas& atlas::set_pixels_per_unit(f32 pixels_per_unit) noexcept {
|
|
||||||
pixels_per_unit_ = pixels_per_unit;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
f32 atlas::pixels_per_unit() const noexcept {
|
|
||||||
return pixels_per_unit_;
|
|
||||||
}
|
|
||||||
|
|
||||||
atlas& atlas::set_regions(vector<region>&& regions) noexcept {
|
atlas& atlas::set_regions(vector<region>&& regions) noexcept {
|
||||||
regions_ = std::move(regions);
|
regions_ = std::move(regions);
|
||||||
std::sort(
|
std::sort(
|
||||||
@@ -147,7 +135,6 @@ namespace e2d
|
|||||||
|
|
||||||
bool operator==(const atlas& l, const atlas& r) noexcept {
|
bool operator==(const atlas& l, const atlas& r) noexcept {
|
||||||
return l.texture() == r.texture()
|
return l.texture() == r.texture()
|
||||||
&& math::approximately(l.pixels_per_unit(), r.pixels_per_unit())
|
|
||||||
&& l.regions() == r.regions()
|
&& l.regions() == r.regions()
|
||||||
&& l.shape_regions() == r.shape_regions();
|
&& l.shape_regions() == r.shape_regions();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"texture" : "image.png",
|
"texture" : "image.png",
|
||||||
"pixels_per_unit" : 2,
|
|
||||||
"regions" : [{
|
"regions" : [{
|
||||||
"name" : "sprite",
|
"name" : "sprite",
|
||||||
"pivot" : { "x" : 1, "y" : 2 },
|
"pivot" : { "x" : 1, "y" : 2 },
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ TEST_CASE("library"){
|
|||||||
auto atlas_res = l.load_asset<atlas_asset>("atlas.json");
|
auto atlas_res = l.load_asset<atlas_asset>("atlas.json");
|
||||||
REQUIRE(atlas_res);
|
REQUIRE(atlas_res);
|
||||||
REQUIRE(atlas_res->content().texture() == texture_res);
|
REQUIRE(atlas_res->content().texture() == texture_res);
|
||||||
REQUIRE(math::approximately(atlas_res->content().pixels_per_unit(), 2.f));
|
|
||||||
REQUIRE(atlas_res->content().regions().size() == 1);
|
REQUIRE(atlas_res->content().regions().size() == 1);
|
||||||
REQUIRE(atlas_res->content().find_region("sprite"));
|
REQUIRE(atlas_res->content().find_region("sprite"));
|
||||||
REQUIRE(atlas_res->content().find_region("sprite")->name == make_hash("sprite"));
|
REQUIRE(atlas_res->content().find_region("sprite")->name == make_hash("sprite"));
|
||||||
|
|||||||
Reference in New Issue
Block a user