summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/RTree.cpp2
-rw-r--r--src/RTree.h3
-rw-r--r--src/RTree.hpp2
-rw-r--r--src/anim-atlas.cpp34
-rw-r--r--src/anim-atlas.hpp10
-rw-r--r--src/anim.hpp2
-rw-r--r--src/character.cpp6
-rw-r--r--src/character.hpp4
-rw-r--r--src/chunk-collision.cpp12
-rw-r--r--src/chunk-render.cpp32
-rw-r--r--src/chunk.cpp14
-rw-r--r--src/chunk.hpp33
-rw-r--r--src/entity-type.hpp2
-rw-r--r--src/entity.cpp30
-rw-r--r--src/entity.hpp21
-rw-r--r--src/global-coords.hpp36
-rw-r--r--src/local-coords.hpp22
-rw-r--r--src/object-id.hpp8
-rw-r--r--src/precomp.hpp2
-rw-r--r--src/random.cpp16
-rw-r--r--src/random.hpp10
-rw-r--r--src/rotation.hpp5
-rw-r--r--src/rotation.inl2
-rw-r--r--src/scenery.cpp18
-rw-r--r--src/scenery.hpp11
-rw-r--r--src/tile-atlas.cpp10
-rw-r--r--src/tile-atlas.hpp10
-rw-r--r--src/tile-defs.hpp3
-rw-r--r--src/tile-image.hpp3
-rw-r--r--src/tile-iterator.cpp8
-rw-r--r--src/tile-iterator.hpp17
-rw-r--r--src/tile.cpp2
-rw-r--r--src/tile.hpp6
-rw-r--r--src/world.cpp8
-rw-r--r--src/world.hpp43
35 files changed, 225 insertions, 222 deletions
diff --git a/src/RTree.cpp b/src/RTree.cpp
index 32323e69..81677922 100644
--- a/src/RTree.cpp
+++ b/src/RTree.cpp
@@ -1,3 +1,3 @@
#include "RTree.hpp"
-template class RTree<std::uint64_t, float, 2, float>;
+template class RTree<floormat::uint64_t, float, 2, float>;
diff --git a/src/RTree.h b/src/RTree.h
index 04d84863..9ef66f34 100644
--- a/src/RTree.h
+++ b/src/RTree.h
@@ -278,8 +278,7 @@ public:
void ListTree(std::vector<Rect>& vec, std::vector<Node*>& temp) const;
};
-#include <cinttypes>
-extern template class RTree<std::uint64_t, float, 2, float>;
+extern template class RTree<floormat::uint64_t, float, 2, float>;
//#undef RTREE_TEMPLATE
//#undef RTREE_QUAL
diff --git a/src/RTree.hpp b/src/RTree.hpp
index 12b55157..da60a76f 100644
--- a/src/RTree.hpp
+++ b/src/RTree.hpp
@@ -1329,7 +1329,7 @@ void RTREE_QUAL::ListTree(std::vector<Rect>& treeList, std::vector<Node*>& toVis
ASSERT(m_root);
ASSERT(m_root->m_level >= 0);
- std::size_t count = (std::size_t)Count();
+ size_t count = (size_t)Count();
treeList.clear();
treeList.reserve(count);
toVisit.clear();
diff --git a/src/anim-atlas.cpp b/src/anim-atlas.cpp
index 4c94a7af..73ce5995 100644
--- a/src/anim-atlas.cpp
+++ b/src/anim-atlas.cpp
@@ -10,14 +10,14 @@
namespace floormat {
static constexpr const char name_array[][3] = { "n", "ne", "e", "se", "s", "sw", "w", "nw", };
-static constexpr inline auto rot_count = std::size_t(rotation_COUNT);
+static constexpr inline auto rot_count = size_t(rotation_COUNT);
static_assert(std::size(name_array) == rot_count);
static_assert(rot_count == 8);
-std::uint8_t anim_atlas::rotation_to_index(StringView name) noexcept
+uint8_t anim_atlas::rotation_to_index(StringView name) noexcept
{
- for (std::uint8_t i = 0; i < rot_count; i++)
+ for (uint8_t i = 0; i < rot_count; i++)
if (name == StringView{name_array[i]})
return i;
fm_abort("can't parse rotation name '%s'", name.data());
@@ -25,12 +25,12 @@ std::uint8_t anim_atlas::rotation_to_index(StringView name) noexcept
decltype(anim_atlas::_group_indices) anim_atlas::make_group_indices(const anim_def& a) noexcept
{
- std::array<std::uint8_t, rot_count> array = {
+ std::array<uint8_t, rot_count> array = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
const auto ngroups = a.groups.size();
for (auto i = 0_uz; i < ngroups; i++)
- array[rotation_to_index(a.groups[i].name)] = std::uint8_t(i);
+ array[rotation_to_index(a.groups[i].name)] = uint8_t(i);
return array;
}
@@ -73,19 +73,19 @@ const anim_def& anim_atlas::info() const noexcept { return _info; }
auto anim_atlas::group(rotation r) const noexcept -> const anim_group&
{
- const auto group_idx = _group_indices[std::size_t(r)];
+ const auto group_idx = _group_indices[size_t(r)];
fm_assert(group_idx != 0xff);
return _info.groups[group_idx];
}
-auto anim_atlas::frame(rotation r, std::size_t frame) const noexcept -> const anim_frame&
+auto anim_atlas::frame(rotation r, size_t frame) const noexcept -> const anim_frame&
{
const anim_group& g = group(r);
fm_assert(frame < g.frames.size());
return g.frames[frame];
}
-auto anim_atlas::texcoords_for_frame(rotation r, std::size_t i, bool mirror) const noexcept -> texcoords
+auto anim_atlas::texcoords_for_frame(rotation r, size_t i, bool mirror) const noexcept -> texcoords
{
const auto f = frame(r, i);
const Vector2 p0(f.offset), p1(f.size);
@@ -107,9 +107,9 @@ auto anim_atlas::texcoords_for_frame(rotation r, std::size_t i, bool mirror) con
}};
}
-auto anim_atlas::frame_quad(const Vector3& center, rotation r, std::size_t i) const noexcept -> quad
+auto anim_atlas::frame_quad(const Vector3& center, rotation r, size_t i) const noexcept -> quad
{
- enum : std::size_t { x, y, z };
+ enum : size_t { x, y, z };
const auto f = frame(r, i);
const auto gx = (float)f.ground[x]*.5f, gy = (float)f.ground[y]*.5f;
const auto size = Vector2d(f.size);
@@ -132,7 +132,7 @@ void anim_atlas::make_bitmask_(const ImageView2D& tex, BitArray& array)
const auto pixels = tex.pixels();
const auto size = pixels.size();
const auto width = size[1], height = size[0],
- stride = (std::size_t)pixels.stride()[0], width0 = width & ~7u;
+ stride = (size_t)pixels.stride()[0], width0 = width & ~7u;
const auto* const data = (const unsigned char*)pixels.data();
auto* const dest = (unsigned char*)array.data();
@@ -184,8 +184,8 @@ BitArrayView anim_atlas::bitmask() const
rotation anim_atlas::next_rotation_from(rotation r) const noexcept
{
- constexpr auto count = std::size_t(rotation_COUNT);
- for (auto i = std::size_t(r)+1; i < count; i++)
+ constexpr auto count = size_t(rotation_COUNT);
+ for (auto i = size_t(r)+1; i < count; i++)
if (_group_indices[i] != 0xff)
return rotation(i);
for (auto i = 0_uz; i < count; i++)
@@ -196,21 +196,21 @@ rotation anim_atlas::next_rotation_from(rotation r) const noexcept
rotation anim_atlas::prev_rotation_from(rotation r) const noexcept
{
- using ssize = std::make_signed_t<std::size_t>;
+ using ssize = std::make_signed_t<size_t>;
constexpr auto count = ssize(rotation_COUNT);
if (r < rotation_COUNT)
for (auto i = ssize(r)-1; i >= 0; i--)
- if (_group_indices[std::size_t(i)] != 0xff)
+ if (_group_indices[size_t(i)] != 0xff)
return rotation(i);
for (auto i = count-1; i >= 0; i--)
- if (_group_indices[std::size_t(i)] != 0xff)
+ if (_group_indices[size_t(i)] != 0xff)
return rotation(i);
fm_abort("where did the rotations go?!");
}
bool anim_atlas::check_rotation(rotation r) const noexcept
{
- return r < rotation_COUNT && _group_indices[std::size_t(r)] < 0xff;
+ return r < rotation_COUNT && _group_indices[size_t(r)] < 0xff;
}
rotation anim_atlas::first_rotation() const noexcept
diff --git a/src/anim-atlas.hpp b/src/anim-atlas.hpp
index e84faf70..ff690efd 100644
--- a/src/anim-atlas.hpp
+++ b/src/anim-atlas.hpp
@@ -35,9 +35,9 @@ struct anim_atlas final
const anim_def& info() const noexcept;
const anim_group& group(rotation r) const noexcept;
- const anim_frame& frame(rotation r, std::size_t frame) const noexcept;
- texcoords texcoords_for_frame(rotation r, std::size_t frame, bool mirror) const noexcept;
- quad frame_quad(const Vector3& center, rotation r, std::size_t frame) const noexcept;
+ const anim_frame& frame(rotation r, size_t frame) const noexcept;
+ texcoords texcoords_for_frame(rotation r, size_t frame, bool mirror) const noexcept;
+ quad frame_quad(const Vector3& center, rotation r, size_t frame) const noexcept;
BitArrayView bitmask() const;
@@ -55,13 +55,13 @@ private:
String _name;
BitArray _bitmask;
anim_def _info;
- std::array<std::uint8_t, (std::size_t)rotation_COUNT> _group_indices = {
+ std::array<uint8_t, (size_t)rotation_COUNT> _group_indices = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
GL::Texture2D _tex;
static decltype(_group_indices) make_group_indices(const anim_def& anim) noexcept;
- static std::uint8_t rotation_to_index(StringView name) noexcept;
+ static uint8_t rotation_to_index(StringView name) noexcept;
};
} // namespace floormat
diff --git a/src/anim.hpp b/src/anim.hpp
index 8d5e6d27..c6315bcf 100644
--- a/src/anim.hpp
+++ b/src/anim.hpp
@@ -56,7 +56,7 @@ struct anim_def final
std::vector<anim_group> groups;
Vector2ui pixel_size;
anim_scale scale = anim_scale{1};
- std::size_t nframes = 0, fps = 0, actionframe = 0;
+ size_t nframes = 0, fps = 0, actionframe = 0;
};
} // namespace floormat
diff --git a/src/character.cpp b/src/character.cpp
index 7cded2ba..84289f01 100644
--- a/src/character.cpp
+++ b/src/character.cpp
@@ -79,7 +79,7 @@ int character::allocate_frame_time(float dt)
constexpr int framerate_ = 65535/framerate;
static_assert(framerate_ > 0);
auto ret = d / framerate_;
- delta = (std::uint16_t)std::clamp(d - ret*65535, 0, 65535);
+ delta = (uint16_t)std::clamp(d - ret*65535, 0, 65535);
return ret;
}
@@ -97,7 +97,7 @@ void character::set_keys(bool L, bool R, bool U, bool D)
b_D = D;
}
-bool character::update(std::size_t i, float dt)
+bool character::update(size_t i, float dt)
{
auto [lr, ud, new_r] = arrows_to_dir(b_L, b_R, b_U, b_D);
@@ -141,7 +141,7 @@ character::operator character_proto() const
return ret;
}
-character::character(std::uint64_t id, struct chunk& c, entity_type type, const character_proto& proto) :
+character::character(object_id id, struct chunk& c, entity_type type, const character_proto& proto) :
entity{id, c, type, proto},
name{proto.name},
playable{proto.playable}
diff --git a/src/character.hpp b/src/character.hpp
index 751fc42e..f4c934fa 100644
--- a/src/character.hpp
+++ b/src/character.hpp
@@ -27,7 +27,7 @@ struct character final : entity
explicit operator character_proto() const;
void set_keys(bool L, bool R, bool U, bool D);
- bool update(std::size_t i, float dt) override;
+ bool update(size_t i, float dt) override;
String name;
Vector2s offset_frac;
@@ -39,7 +39,7 @@ private:
static Vector2 move_vec(int left_right, int top_bottom);
friend struct world;
- character(std::uint64_t id, struct chunk& c, entity_type type, const character_proto& proto);
+ character(object_id id, struct chunk& c, entity_type type, const character_proto& proto);
};
template<> struct entity_type_<struct character> : std::integral_constant<entity_type, entity_type::character> {};
diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp
index fc7ab92a..fedfd877 100644
--- a/src/chunk-collision.cpp
+++ b/src/chunk-collision.cpp
@@ -11,7 +11,7 @@ chunk::RTree* chunk::rtree() noexcept { ensure_passability(); return &_rtree; }
namespace {
-constexpr Vector2 tile_start(std::size_t k)
+constexpr Vector2 tile_start(size_t k)
{
constexpr auto half_tile = Vector2(TILE_SIZE2)/2;
const local_coords coord{k};
@@ -26,27 +26,27 @@ Pair<Vector2i, Vector2i> scenery_tile(local_coords local, Vector2b offset, Vecto
return { min, min + size, };
}
-constexpr Pair<Vector2, Vector2> whole_tile(std::size_t k)
+constexpr Pair<Vector2, Vector2> whole_tile(size_t k)
{
auto min = tile_start(k);
return { min, min + TILE_SIZE2, };
}
-constexpr Pair<Vector2, Vector2> wall_north(std::size_t k)
+constexpr Pair<Vector2, Vector2> wall_north(size_t k)
{
auto min = tile_start(k) - Vector2(0, 1);
return { min, min + Vector2(TILE_SIZE2[0], 2), };
}
-constexpr Pair<Vector2, Vector2> wall_west(std::size_t k)
+constexpr Pair<Vector2, Vector2> wall_west(size_t k)
{
auto min = tile_start(k) - Vector2(1, 0);
return { min, min + Vector2(2, TILE_SIZE2[1]), };
}
-constexpr std::uint64_t make_id(collision_type type, pass_mode p, std::uint64_t id)
+constexpr object_id make_id(collision_type type, pass_mode p, uint64_t id)
{
- return std::bit_cast<std::uint64_t>(collision_data { (std::uint64_t)type, (std::uint64_t)p, id });
+ return std::bit_cast<object_id>(collision_data { (object_id)type, (object_id)p, id });
}
} // namespace
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index b5e14926..7f4761e0 100644
--- a/src/chunk-render.cpp
+++ b/src/chunk-render.cpp
@@ -9,8 +9,8 @@
namespace floormat {
-template<std::size_t N = 1>
-static auto make_index_array(std::size_t max)
+template<size_t N = 1>
+static auto make_index_array(size_t max)
{
std::array<std::array<UnsignedShort, 6>, N*TILE_COUNT> array; // NOLINT(cppcoreguidelines-pro-type-member-init)
for (auto i = 0_uz; i < max; i++)
@@ -21,23 +21,23 @@ static auto make_index_array(std::size_t max)
auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
{
if (!_ground_modified)
- return { ground_mesh, ground_indexes, std::size_t(ground_mesh.count()/6) };
+ return { ground_mesh, ground_indexes, size_t(ground_mesh.count()/6) };
_ground_modified = false;
- std::size_t count = 0;
+ size_t count = 0;
for (auto i = 0_uz; i < TILE_COUNT; i++)
if (_ground_atlases[i])
- ground_indexes[count++] = std::uint8_t(i);
+ ground_indexes[count++] = uint8_t(i);
std::sort(ground_indexes.begin(), ground_indexes.begin() + count,
- [this](std::uint8_t a, std::uint8_t b) {
+ [this](uint8_t a, uint8_t b) {
return _ground_atlases[a] < _ground_atlases[b];
});
std::array<std::array<vertex, 4>, TILE_COUNT> vertexes;
for (auto k = 0_uz; k < count; k++)
{
- const std::uint8_t i = ground_indexes[k];
+ const uint8_t i = ground_indexes[k];
const auto& atlas = _ground_atlases[i];
const local_coords pos{i};
const auto quad = atlas->floor_quad(Vector3(pos) * TILE_SIZE, TILE_SIZE2);
@@ -55,7 +55,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
GL::Mesh mesh{GL::MeshPrimitive::Triangles};
mesh.addVertexBuffer(GL::Buffer{vertex_view}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{})
.setIndexBuffer(GL::Buffer{vert_index_view}, 0, GL::MeshIndexType::UnsignedShort)
- .setCount(std::int32_t(6 * count));
+ .setCount(int32_t(6 * count));
ground_mesh = Utility::move(mesh);
return { ground_mesh, ground_indexes, count };
}
@@ -63,23 +63,23 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple
{
if (!_walls_modified)
- return { wall_mesh, wall_indexes, std::size_t(wall_mesh.count()/6) };
+ return { wall_mesh, wall_indexes, size_t(wall_mesh.count()/6) };
_walls_modified = false;
- std::size_t count = 0;
+ size_t count = 0;
for (auto i = 0_uz; i < TILE_COUNT*2; i++)
if (_wall_atlases[i])
- wall_indexes[count++] = std::uint16_t(i);
+ wall_indexes[count++] = uint16_t(i);
std::sort(wall_indexes.begin(), wall_indexes.begin() + count,
- [this](std::uint16_t a, std::uint16_t b) {
+ [this](uint16_t a, uint16_t b) {
return _wall_atlases[a] < _wall_atlases[b];
});
std::array<std::array<vertex, 4>, TILE_COUNT*2> vertexes;
for (auto k = 0_uz; k < count; k++)
{
- const std::uint16_t i = wall_indexes[k];
+ const uint16_t i = wall_indexes[k];
const auto& atlas = _wall_atlases[i];
const auto& variant = _wall_variants[i];
const local_coords pos{i / 2u};
@@ -99,7 +99,7 @@ auto chunk::ensure_wall_mesh() noexcept -> wall_mesh_tuple
GL::Mesh mesh{GL::MeshPrimitive::Triangles};
mesh.addVertexBuffer(GL::Buffer{vertex_view}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{})
.setIndexBuffer(GL::Buffer{vert_index_view}, 0, GL::MeshIndexType::UnsignedShort)
- .setCount(std::int32_t(6 * count));
+ .setCount(int32_t(6 * count));
wall_mesh = Utility::move(mesh);
return { wall_mesh, wall_indexes, count };
}
@@ -113,7 +113,7 @@ auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple
_scenery_modified = false;
const auto count = fm_begin(
- std::size_t ret = 0;
+ size_t ret = 0;
for (const auto& e : _entities)
ret += !e->is_dynamic();
return ret;
@@ -149,7 +149,7 @@ auto chunk::ensure_scenery_mesh() noexcept -> scenery_mesh_tuple
GL::Mesh mesh{GL::MeshPrimitive::Triangles};
mesh.addVertexBuffer(GL::Buffer{scenery_vertexes}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{})
.setIndexBuffer(GL::Buffer{scenery_indexes}, 0, GL::MeshIndexType::UnsignedShort)
- .setCount(std::int32_t(6 * count));
+ .setCount(int32_t(6 * count));
scenery_mesh = Utility::move(mesh);
}
return { scenery_mesh, };
diff --git a/src/chunk.cpp b/src/chunk.cpp
index 3adce5de..d660d2c8 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -8,7 +8,7 @@ namespace floormat {
namespace {
-std::size_t _reload_no_ = 0;
+size_t _reload_no_ = 0;
bool is_log_quiet()
{
@@ -31,11 +31,11 @@ bool chunk::empty(bool force) const noexcept
return true;
}
-tile_atlas* chunk::ground_atlas_at(std::size_t i) const noexcept { return _ground_atlases[i].get(); }
-tile_atlas* chunk::wall_atlas_at(std::size_t i) const noexcept { return _wall_atlases[i].get(); }
+tile_atlas* chunk::ground_atlas_at(size_t i) const noexcept { return _ground_atlases[i].get(); }
+tile_atlas* chunk::wall_atlas_at(size_t i) const noexcept { return _wall_atlases[i].get(); }
-tile_ref chunk::operator[](std::size_t idx) noexcept { return { *this, std::uint8_t(idx) }; }
-tile_proto chunk::operator[](std::size_t idx) const noexcept { return tile_proto(tile_ref { *const_cast<chunk*>(this), std::uint8_t(idx) }); }
+tile_ref chunk::operator[](size_t idx) noexcept { return { *this, uint8_t(idx) }; }
+tile_proto chunk::operator[](size_t idx) const noexcept { return tile_proto(tile_ref { *const_cast<chunk*>(this), uint8_t(idx) }); }
tile_ref chunk::operator[](local_coords xy) noexcept { return operator[](xy.to_index()); }
tile_proto chunk::operator[](local_coords xy) const noexcept { return operator[](xy.to_index()); }
@@ -142,7 +142,7 @@ void chunk::add_entity(const std::shared_ptr<entity>& e)
_entities.insert(it, e);
}
-void chunk::remove_entity(std::size_t i)
+void chunk::remove_entity(size_t i)
{
fm_assert(_entities_sorted);
fm_debug_assert(i < _entities.size());
@@ -152,7 +152,7 @@ void chunk::remove_entity(std::size_t i)
if (bbox bb; _bbox_for_scenery(*e, bb))
_remove_bbox(bb);
- _entities.erase(_entities.cbegin() + std::ptrdiff_t(i));
+ _entities.erase(_entities.cbegin() + ptrdiff_t(i));
}
const std::vector<std::shared_ptr<entity>>& chunk::entities() const
diff --git a/src/chunk.hpp b/src/chunk.hpp
index d22ce7fe..f279433e 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include "object-id.hpp"
#include "tile.hpp"
#include "tile-iterator.hpp"
#include <type_traits>
@@ -22,9 +23,9 @@ enum class collision_type : unsigned char {
};
struct collision_data final {
- std::uint64_t tag : 2;
- std::uint64_t pass : 2;
- std::uint64_t data : 60;
+ uint64_t tag : 2;
+ uint64_t pass : 2;
+ uint64_t data : 60;
};
struct chunk final
@@ -33,8 +34,8 @@ struct chunk final
friend struct entity;
friend struct world;
- tile_ref operator[](std::size_t idx) noexcept;
- tile_proto operator[](std::size_t idx) const noexcept;
+ tile_ref operator[](size_t idx) noexcept;
+ tile_proto operator[](size_t idx) const noexcept;
tile_ref operator[](local_coords xy) noexcept;
tile_proto operator[](local_coords xy) const noexcept;
@@ -68,13 +69,13 @@ struct chunk final
struct ground_mesh_tuple final {
GL::Mesh& mesh;
- const ArrayView<const std::uint8_t> ids;
- const std::size_t size;
+ const ArrayView<const uint8_t> ids;
+ const size_t size;
};
struct wall_mesh_tuple final {
GL::Mesh& mesh;
- const ArrayView<const std::uint16_t> ids;
- const std::size_t size;
+ const ArrayView<const uint16_t> ids;
+ const size_t size;
};
struct scenery_mesh_tuple final {
@@ -87,12 +88,12 @@ struct chunk final
float depth = -1;
};
- using RTree = ::RTree<std::uint64_t, float, 2, float>;
+ using RTree = ::RTree<object_id, float, 2, float>;
ground_mesh_tuple ensure_ground_mesh() noexcept;
- tile_atlas* ground_atlas_at(std::size_t i) const noexcept;
+ tile_atlas* ground_atlas_at(size_t i) const noexcept;
wall_mesh_tuple ensure_wall_mesh() noexcept;
- tile_atlas* wall_atlas_at(std::size_t i) const noexcept;
+ tile_atlas* wall_atlas_at(size_t i) const noexcept;
scenery_mesh_tuple ensure_scenery_mesh() noexcept;
void ensure_passability() noexcept;
@@ -104,15 +105,15 @@ struct chunk final
void add_entity(const std::shared_ptr<entity>& e);
void add_entity_unsorted(const std::shared_ptr<entity>& e);
void sort_entities();
- void remove_entity(std::size_t i);
+ void remove_entity(size_t i);
const std::vector<std::shared_ptr<entity>>& entities() const;
private:
std::array<std::shared_ptr<tile_atlas>, TILE_COUNT> _ground_atlases;
- std::array<std::uint8_t, TILE_COUNT> ground_indexes = {};
+ std::array<uint8_t, TILE_COUNT> ground_indexes = {};
std::array<variant_t, TILE_COUNT> _ground_variants = {};
std::array<std::shared_ptr<tile_atlas>, TILE_COUNT*2> _wall_atlases;
- std::array<std::uint16_t, TILE_COUNT*2> wall_indexes = {};
+ std::array<uint16_t, TILE_COUNT*2> wall_indexes = {};
std::array<variant_t, TILE_COUNT*2> _wall_variants = {};
std::vector<std::shared_ptr<entity>> _entities;
@@ -134,7 +135,7 @@ private:
struct bbox final // NOLINT(cppcoreguidelines-pro-type-member-init)
{
- std::uint64_t id;
+ object_id id;
Vector2i start, end;
bool operator==(const bbox& other) const noexcept;
diff --git a/src/entity-type.hpp b/src/entity-type.hpp
index e1ed8fcc..70490645 100644
--- a/src/entity-type.hpp
+++ b/src/entity-type.hpp
@@ -5,6 +5,6 @@ namespace floormat {
enum class entity_type : unsigned char {
none, character, scenery,
};
-constexpr inline std::size_t entity_type_BITS = 3;
+constexpr inline size_t entity_type_BITS = 3;
} // namespace floormat
diff --git a/src/entity.cpp b/src/entity.cpp
index efa4655f..820d0456 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -13,7 +13,7 @@ entity_proto::~entity_proto() noexcept = default;
entity_proto::entity_proto() = default;
entity_proto::entity_proto(const entity_proto&) = default;
-entity::entity(std::uint64_t id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept :
+entity::entity(object_id id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept :
id{id}, c{&c}, atlas{proto.atlas},
offset{proto.offset}, bbox_offset{proto.bbox_offset},
bbox_size{proto.bbox_size}, delta{proto.delta},
@@ -35,7 +35,7 @@ entity::~entity() noexcept
if (chunk::bbox bb; c->_bbox_for_scenery(*this, bb))
c->_remove_bbox(bb);
c->_world->do_kill_entity(id);
- const_cast<std::uint64_t&>(id) = 0;
+ const_cast<object_id&>(id) = 0;
}
Vector2b entity::ordinal_offset_for_type(entity_type type, Vector2b offset)
@@ -43,7 +43,7 @@ Vector2b entity::ordinal_offset_for_type(entity_type type, Vector2b offset)
switch (type)
{
default:
- fm_warn_once("unknown entity type '%zu'", std::size_t(type));
+ fm_warn_once("unknown entity type '%zu'", size_t(type));
[[fallthrough]];
case entity_type::scenery:
return offset;
@@ -76,7 +76,7 @@ struct chunk& entity::chunk() const
return *c;
}
-std::size_t entity::index() const
+size_t entity::index() const
{
auto& c = chunk();
auto& es = c._entities;
@@ -84,10 +84,10 @@ std::size_t entity::index() const
fm_assert(it != es.cend());
it = std::find_if(it, es.cend(), [id = id](const auto& x) { return x->id == id; });
fm_assert(it != es.cend());
- return (std::size_t)std::distance(es.cbegin(), it);
+ return (size_t)std::distance(es.cbegin(), it);
}
-void entity::rotate(std::size_t, rotation new_r)
+void entity::rotate(size_t, rotation new_r)
{
fm_assert(atlas->check_rotation(new_r));
set_bbox(offset, rotate_point(bbox_offset, r, new_r), rotate_size(bbox_size, r, new_r), pass);
@@ -129,7 +129,7 @@ bool entity::can_move_to(Vector2i delta)
min = center - half_bbox, max = min + Vector2(bbox_size);
bool ret = true;
- c_.rtree()->Search(min.data(), max.data(), [&](std::uint64_t data, const auto&) {
+ c_.rtree()->Search(min.data(), max.data(), [&](object_id data, const auto&) {
auto id2 = std::bit_cast<collision_data>(data).data;
if (id2 != id)
return ret = false;
@@ -139,7 +139,7 @@ bool entity::can_move_to(Vector2i delta)
return ret;
}
-std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r)
+size_t entity::move(size_t i, Vector2i delta, rotation new_r)
{
auto& es = c->_entities;
fm_debug_assert(i < es.size());
@@ -171,16 +171,16 @@ std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r)
set_bbox_(offset_, bb_offset, bb_size, pass);
const_cast<rotation&>(r) = new_r;
auto pos1 = std::distance(es.cbegin(), it_);
- if ((std::size_t)pos1 > i)
+ if ((size_t)pos1 > i)
pos1--;
//for (auto i = 0_uz; const auto& x : es) fm_debug("%zu %s %f", i++, x->atlas->name().data(), x->ordinal());
- if ((std::size_t)pos1 != i)
+ if ((size_t)pos1 != i)
{
//fm_debug("insert (%hd;%hd|%hhd;%hhd) %td -> %zu | %f", coord_.chunk().x, coord_.chunk().y, coord_.local().x, coord_.local().y, pos1, es.size(), e.ordinal());
- es.erase(es.cbegin() + (std::ptrdiff_t)i);
+ es.erase(es.cbegin() + (ptrdiff_t)i);
es.insert(es.cbegin() + pos1, std::move(e_));
}
- return std::size_t(pos1);
+ return size_t(pos1);
}
else
{
@@ -192,7 +192,7 @@ std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r)
c->remove_entity(i);
auto& es = c2._entities;
auto it = std::lower_bound(es.cbegin(), es.cend(), e_, [=](const auto& a, const auto&) { return a->ordinal() < ord; });
- auto ret = (std::size_t)std::distance(es.cbegin(), it);
+ auto ret = (size_t)std::distance(es.cbegin(), it);
e_->coord = coord_;
set_bbox_(offset_, bb_offset, bb_size, pass);
const_cast<rotation&>(r) = new_r;
@@ -237,8 +237,8 @@ void entity::set_bbox(Vector2b offset_, Vector2b bbox_offset_, Vector2ub bbox_si
c->_replace_bbox(bb0, bb, b0, b);
}
-bool entity::can_activate(std::size_t) const { return false; }
-bool entity::activate(std::size_t) { return false; }
+bool entity::can_activate(size_t) const { return false; }
+bool entity::activate(size_t) { return false; }
bool entity::is_dynamic() const
{
diff --git a/src/entity.hpp b/src/entity.hpp
index 96e5477f..2ede577b 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -4,6 +4,7 @@
#include "src/rotation.hpp"
#include "src/pass-mode.hpp"
#include "src/entity-type.hpp"
+#include "src/object-id.hpp"
#include <memory>
#include <vector>
@@ -19,7 +20,7 @@ struct entity_proto
std::shared_ptr<anim_atlas> atlas;
Vector2b offset, bbox_offset;
Vector2ub bbox_size = Vector2ub(iTILE_SIZE2);
- std::uint16_t delta = 0, frame = 0;
+ uint16_t delta = 0, frame = 0;
entity_type type : 3 = entity_type::none;
rotation r : rotation_BITS = rotation::N;
pass_mode pass : pass_mode_BITS = pass_mode::see_through;
@@ -37,13 +38,13 @@ struct entity
{
fm_DECLARE_DELETED_COPY_ASSIGNMENT(entity);
- const std::uint64_t id = 0;
+ const object_id id = 0;
struct chunk* const c;
std::shared_ptr<anim_atlas> atlas;
global_coords coord;
const Vector2b offset, bbox_offset;
const Vector2ub bbox_size;
- std::uint16_t delta = 0, frame = 0;
+ uint16_t delta = 0, frame = 0;
const entity_type type;
const rotation r = rotation::N;
const pass_mode pass = pass_mode::see_through;
@@ -54,25 +55,25 @@ struct entity
float ordinal() const;
static float ordinal(local_coords xy, Vector2b offset, entity_type type);
struct chunk& chunk() const;
- std::size_t index() const;
+ size_t index() const;
explicit operator entity_proto() const;
- virtual bool can_activate(std::size_t i) const;
- virtual bool activate(std::size_t i);
- virtual bool update(std::size_t i, float dt) = 0;
- virtual void rotate(std::size_t i, rotation r);
+ virtual bool can_activate(size_t i) const;
+ virtual bool activate(size_t i);
+ virtual bool update(size_t i, float dt) = 0;
+ virtual void rotate(size_t i, rotation r);
static Pair<global_coords, Vector2b> normalize_coords(global_coords coord, Vector2b cur_offset, Vector2i delta);
[[nodiscard]] virtual bool can_move_to(Vector2i delta);
- std::size_t move(std::size_t i, Vector2i delta, rotation new_r);
+ size_t move(size_t i, Vector2i delta, rotation new_r);
virtual void set_bbox(Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, pass_mode pass);
bool is_dynamic() const;
friend struct world;
protected:
- entity(std::uint64_t id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept;
+ entity(object_id id, struct chunk& c, entity_type type, const entity_proto& proto) noexcept;
void set_bbox_(Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, pass_mode pass);
};
diff --git a/src/global-coords.hpp b/src/global-coords.hpp
index 46ef1514..b48a18d1 100644
--- a/src/global-coords.hpp
+++ b/src/global-coords.hpp
@@ -8,7 +8,7 @@
namespace floormat {
struct chunk_coords final {
- std::int16_t x = 0, y = 0;
+ int16_t x = 0, y = 0;
constexpr bool operator==(const chunk_coords& other) const noexcept = default;
constexpr Vector2i operator-(chunk_coords other) const noexcept;
@@ -28,18 +28,18 @@ constexpr Vector2i chunk_coords::operator-(chunk_coords other) const noexcept
}
struct global_coords final {
- using u0 = std::integral_constant<std::uint32_t, (1<<15)>;
- using s0 = std::integral_constant<std::int32_t, std::int32_t(u0::value)>;
- std::uint32_t x = u0::value<<4, y = u0::value<<4;
+ using u0 = std::integral_constant<uint32_t, (1<<15)>;
+ using s0 = std::integral_constant<int32_t, int32_t(u0::value)>;
+ uint32_t x = u0::value<<4, y = u0::value<<4;
constexpr global_coords() noexcept = default;
constexpr global_coords(chunk_coords c, local_coords xy) :
- x{ std::uint32_t((c.x + s0::value) << 4) | (xy.x & 0x0f) },
- y{ std::uint32_t((c.y + s0::value) << 4) | (xy.y & 0x0f) }
+ x{ uint32_t((c.x + s0::value) << 4) | (xy.x & 0x0f) },
+ y{ uint32_t((c.y + s0::value) << 4) | (xy.y & 0x0f) }
{}
- constexpr global_coords(std::uint32_t x, std::uint32_t y) noexcept : x{x}, y{y} {}
- constexpr global_coords(std::int32_t x, std::int32_t y) noexcept :
- x{std::uint32_t(x + (s0::value<<4))}, y{std::uint32_t(y + (s0::value<<4))}
+ constexpr global_coords(uint32_t x, uint32_t y) noexcept : x{x}, y{y} {}
+ constexpr global_coords(int32_t x, int32_t y) noexcept :
+ x{uint32_t(x + (s0::value<<4))}, y{uint32_t(y + (s0::value<<4))}
{}
constexpr local_coords local() const noexcept;
@@ -58,17 +58,17 @@ struct global_coords final {
constexpr local_coords global_coords::local() const noexcept
{
- return { std::uint8_t(x & 0x0f), std::uint8_t(y & 0x0f), };
+ return { uint8_t(x & 0x0f), uint8_t(y & 0x0f), };
}
constexpr chunk_coords global_coords::chunk() const noexcept
{
- return { std::int16_t(std::int32_t((x>>4) - u0::value)), std::int16_t(std::int32_t((y>>4) - u0::value)), };
+ return { int16_t(int32_t((x>>4) - u0::value)), int16_t(int32_t((y>>4) - u0::value)), };
}
constexpr Vector2i global_coords::to_signed() const noexcept
{
- return { std::int32_t(x - (s0::value<<4)), std::int32_t(y - (s0::value<<4)), };
+ return { int32_t(x - (s0::value<<4)), int32_t(y - (s0::value<<4)), };
}
constexpr Vector3i global_coords::to_signed3() const noexcept
@@ -78,25 +78,25 @@ constexpr Vector3i global_coords::to_signed3() const noexcept
constexpr global_coords global_coords::operator+(Vector2i vec) const noexcept
{
- return { std::uint32_t((std::int64_t)x+vec[0]), std::uint32_t((std::int64_t)y+vec[1]) };
+ return { uint32_t((int64_t)x+vec[0]), uint32_t((int64_t)y+vec[1]) };
}
constexpr global_coords& global_coords::operator+=(Vector2i vec) noexcept
{
- x = std::uint32_t((std::int64_t)x+vec[0]);
- y = std::uint32_t((std::int64_t)y+vec[1]);
+ x = uint32_t((int64_t)x+vec[0]);
+ y = uint32_t((int64_t)y+vec[1]);
return *this;
}
constexpr global_coords global_coords::operator-(Vector2i vec) const noexcept
{
- return { std::uint32_t((std::int64_t)x-vec[0]), std::uint32_t((std::int64_t)y-vec[1]) };
+ return { uint32_t((int64_t)x-vec[0]), uint32_t((int64_t)y-vec[1]) };
}
constexpr global_coords& global_coords::operator-=(Vector2i vec) noexcept
{
- x = std::uint32_t((std::int64_t)x-vec[0]);
- y = std::uint32_t((std::int64_t)y-vec[1]);
+ x = uint32_t((int64_t)x-vec[0]);
+ y = uint32_t((int64_t)y-vec[1]);
return *this;
}
diff --git a/src/local-coords.hpp b/src/local-coords.hpp
index eef511d6..cb7a5c24 100644
--- a/src/local-coords.hpp
+++ b/src/local-coords.hpp
@@ -8,32 +8,32 @@
namespace floormat {
struct local_coords final {
- std::uint8_t x : 4 = 0, y : 4 = 0;
- explicit constexpr local_coords(std::size_t idx) noexcept;
+ uint8_t x : 4 = 0, y : 4 = 0;
+ explicit constexpr local_coords(size_t idx) noexcept;
constexpr local_coords() noexcept = default;
- template<typename T> requires (std::is_integral_v<T> && sizeof(T) <= sizeof(std::size_t))
+ template<typename T> requires (std::is_integral_v<T> && sizeof(T) <= sizeof(size_t))
constexpr local_coords(T x, T y) noexcept;
- constexpr local_coords(std::uint8_t x, std::uint8_t y) noexcept : x{x}, y{y} {}
- constexpr std::uint8_t to_index() const noexcept { return y*TILE_MAX_DIM + x; }
+ constexpr local_coords(uint8_t x, uint8_t y) noexcept : x{x}, y{y} {}
+ constexpr uint8_t to_index() const noexcept { return y*TILE_MAX_DIM + x; }
constexpr bool operator==(const local_coords&) const noexcept = default;
template<typename T> explicit constexpr operator Math::Vector2<T>() const noexcept { return Math::Vector2<T>(T(x), T(y)); }
template<typename T> explicit constexpr operator Math::Vector3<T>() const noexcept { return Math::Vector3<T>(T(x), T(y), T(0)); }
};
-constexpr local_coords::local_coords(std::size_t index) noexcept :
- x{(std::uint8_t)(index % TILE_MAX_DIM)},
- y{(std::uint8_t)(index / TILE_MAX_DIM)}
+constexpr local_coords::local_coords(size_t index) noexcept :
+ x{(uint8_t)(index % TILE_MAX_DIM)},
+ y{(uint8_t)(index / TILE_MAX_DIM)}
{
fm_assert(index < TILE_COUNT);
}
template<typename T>
-requires (std::is_integral_v<T> && sizeof(T) <= sizeof(std::size_t))
+requires (std::is_integral_v<T> && sizeof(T) <= sizeof(size_t))
constexpr local_coords::local_coords(T x, T y) noexcept
- : x{(std::uint8_t)x}, y{(std::uint8_t)y}
+ : x{(uint8_t)x}, y{(uint8_t)y}
{
- fm_assert((std::size_t)x < TILE_MAX_DIM && (std::size_t)y < TILE_MAX_DIM);
+ fm_assert((size_t)x < TILE_MAX_DIM && (size_t)y < TILE_MAX_DIM);
}
} // namespace floormat
diff --git a/src/object-id.hpp b/src/object-id.hpp
new file mode 100644
index 00000000..f88aed53
--- /dev/null
+++ b/src/object-id.hpp
@@ -0,0 +1,8 @@
+#pragma once
+#include "compat/integer-types.hpp"
+
+namespace floormat {
+
+using object_id = uint64_t;
+
+} // namespace floormat
diff --git a/src/precomp.hpp b/src/precomp.hpp
index 0abb304a..fe97f0a1 100644
--- a/src/precomp.hpp
+++ b/src/precomp.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include "compat/prelude.hpp"
+#include "compat/integer-types.hpp"
#include "compat/defs.hpp"
#include "compat/assert.hpp"
diff --git a/src/random.cpp b/src/random.cpp
index 7888dbaa..6bb70808 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -4,31 +4,31 @@
namespace floormat {
-static thread_local auto g = std::independent_bits_engine<decltype(std::ranlux48{}), 32, std::uint32_t>{std::ranlux48{}};
+static thread_local auto g = std::independent_bits_engine<decltype(std::ranlux48{}), 32, uint32_t>{std::ranlux48{}};
random_engine::~random_engine() = default;
struct random_engine_impl final : random_engine {
- std::size_t operator()() override;
+ size_t operator()() override;
float operator()(float min, float max) override;
};
-std::size_t random_engine_impl::operator()()
+size_t random_engine_impl::operator()()
{
- if constexpr(sizeof(std::size_t) > sizeof(std::uint32_t))
+ if constexpr(sizeof(size_t) > sizeof(uint32_t))
{
- constexpr auto N = (sizeof(std::size_t) + sizeof(std::uint32_t)-1) / sizeof(std::uint32_t);
+ constexpr auto N = (sizeof(size_t) + sizeof(uint32_t)-1) / sizeof(uint32_t);
static_assert(N >= 1);
union {
- std::size_t x;
- std::uint32_t a[N];
+ size_t x;
+ uint32_t a[N];
} ret;
for (auto i = 0_uz; i < N; i++)
ret.a[i] = g();
return ret.x;
}
else
- return (std::size_t)g();
+ return (size_t)g();
}
float random_engine_impl::operator()(float min, float max)
diff --git a/src/random.hpp b/src/random.hpp
index e8e462e8..6f1ef7ee 100644
--- a/src/random.hpp
+++ b/src/random.hpp
@@ -1,7 +1,5 @@
#pragma once
-#include <cstddef>
-#include <cstdint>
#include <concepts>
#include <type_traits>
@@ -10,16 +8,16 @@ namespace floormat {
struct random_engine
{
virtual ~random_engine();
- virtual std::common_type_t<std::size_t, std::uintptr_t, std::ptrdiff_t> operator()() = 0;
+ virtual std::common_type_t<size_t, uintptr_t, ptrdiff_t> operator()() = 0;
template<std::integral T>
- requires (sizeof(T) <= sizeof(std::size_t))
+ requires (sizeof(T) <= sizeof(size_t))
T operator()(T max) {
- return static_cast<T>(operator()() % static_cast<std::size_t>(max));
+ return static_cast<T>(operator()() % static_cast<size_t>(max));
}
template<std::integral T>
- requires (sizeof(T) <= sizeof(std::size_t))
+ requires (sizeof(T) <= sizeof(size_t))
T operator()(T min, T max) {
return min + operator()(max-min);
}
diff --git a/src/rotation.hpp b/src/rotation.hpp
index 39694336..471007c3 100644
--- a/src/rotation.hpp
+++ b/src/rotation.hpp
@@ -1,5 +1,4 @@
#pragma once
-#include <cstddef>
namespace floormat {
@@ -7,8 +6,8 @@ enum class rotation : unsigned char {
N, NE, E, SE, S, SW, W, NW,
};
-constexpr inline std::size_t rotation_BITS = 3;
-constexpr inline std::size_t rotation_MASK = (1 << rotation_BITS)-1;
+constexpr inline size_t rotation_BITS = 3;
+constexpr inline size_t rotation_MASK = (1 << rotation_BITS)-1;
constexpr inline rotation rotation_COUNT = rotation{1 << rotation_BITS};
} // namespace floormat
diff --git a/src/rotation.inl b/src/rotation.inl
index 8f9e6012..fb5cefca 100644
--- a/src/rotation.inl
+++ b/src/rotation.inl
@@ -18,7 +18,7 @@ constexpr Triple<Vector2b, Vector2ub, Vector2ub> rotation_symmetry(rotation r)
};
fm_assert(r < rotation_COUNT);
- auto idx = (std::size_t)r / 2;
+ auto idx = (size_t)r / 2;
const auto& [r1, sym] = rotation_symmetries[idx];
return sym;
}
diff --git a/src/scenery.cpp b/src/scenery.cpp
index 14bf691b..a424351f 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -17,12 +17,12 @@ scenery_proto::scenery_proto(const scenery_proto&) = default;
scenery_proto::~scenery_proto() noexcept = default;
scenery_proto::operator bool() const { return atlas != nullptr; }
-bool scenery::can_activate(std::size_t) const
+bool scenery::can_activate(size_t) const
{
return atlas && interactive;
}
-bool scenery::update(std::size_t, float dt)
+bool scenery::update(size_t, float dt)
{
auto& s = *this;
if (!s.active)
@@ -37,17 +37,17 @@ bool scenery::update(std::size_t, float dt)
case scenery_type::door:
fm_assert(atlas);
auto& anim = *atlas;
- const auto hz = std::uint8_t(atlas->info().fps);
+ const auto hz = uint8_t(atlas->info().fps);
const auto nframes = (int)anim.info().nframes;
fm_debug_assert(anim.info().fps > 0 && anim.info().fps <= 0xff);
auto delta_ = int(s.delta) + int(65535u * dt);
delta_ = std::min(65535, delta_);
const auto frame_time = int(1.f/hz * 65535);
- const auto n = (std::uint8_t)std::clamp(delta_ / frame_time, 0, 255);
- s.delta = (std::uint16_t)std::clamp(delta_ - frame_time*n, 0, 65535);
+ const auto n = (uint8_t)std::clamp(delta_ / frame_time, 0, 255);
+ s.delta = (uint16_t)std::clamp(delta_ - frame_time*n, 0, 65535);
fm_debug_assert(s.delta >= 0);
- const std::int8_t dir = s.closing ? 1 : -1;
+ const int8_t dir = s.closing ? 1 : -1;
const int fr = s.frame + dir*n;
s.active = fr > 0 && fr < nframes-1;
pass_mode p;
@@ -58,14 +58,14 @@ bool scenery::update(std::size_t, float dt)
else
p = pass_mode::see_through;
set_bbox(offset, bbox_offset, bbox_size, p);
- s.frame = (std::uint16_t)std::clamp(fr, 0, nframes-1);
+ s.frame = (uint16_t)std::clamp(fr, 0, nframes-1);
if (!s.active)
s.delta = s.closing = 0;
return true;
}
}
-bool scenery::activate(std::size_t)
+bool scenery::activate(size_t)
{
auto& s = *this;
if (s.active)
@@ -111,7 +111,7 @@ scenery::operator scenery_proto() const
return ret;
}
-scenery::scenery(std::uint64_t id, struct chunk& c, entity_type type_, const scenery_proto& proto) :
+scenery::scenery(object_id id, struct chunk& c, entity_type type_, const scenery_proto& proto) :
entity{id, c, type_, proto}, sc_type{proto.sc_type}, active{proto.active},
closing{proto.closing}, interactive{proto.interactive}
{
diff --git a/src/scenery.hpp b/src/scenery.hpp
index 0c074e5e..a985d7d7 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -3,7 +3,6 @@
#include "tile-defs.hpp"
#include "rotation.hpp"
#include "entity.hpp"
-#include <cstdint>
#include <memory>
#include <type_traits>
#include <Magnum/Math/Vector2.h>
@@ -18,7 +17,7 @@ struct world;
enum class scenery_type : unsigned char {
none, generic, door,
};
-constexpr inline std::size_t scenery_type_BITS = 3;
+constexpr inline size_t scenery_type_BITS = 3;
struct scenery_proto : entity_proto
{
@@ -42,14 +41,14 @@ struct scenery final : entity
unsigned char closing : 1 = false;
unsigned char interactive : 1 = false;
- bool can_activate(std::size_t i) const override;
- bool activate(std::size_t i) override;
- bool update(std::size_t i, float dt) override;
+ bool can_activate(size_t i) const override;
+ bool activate(size_t i) override;
+ bool update(size_t i, float dt) override;
explicit operator scenery_proto() const;
private:
friend struct world;
- scenery(std::uint64_t id, struct chunk& c, entity_type type, const scenery_proto& proto);
+ scenery(object_id id, struct chunk& c, entity_type type, const scenery_proto& proto);
};
template<> struct entity_type_<scenery> : std::integral_constant<entity_type, entity_type::scenery> {};
diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp
index 68feb77b..3438e6a1 100644
--- a/src/tile-atlas.cpp
+++ b/src/tile-atlas.cpp
@@ -26,16 +26,16 @@ tile_atlas::tile_atlas(StringView name, const ImageView2D& image, Vector2ub tile
.setSubImage(0, {}, image);
}
-std::array<Vector2, 4> tile_atlas::texcoords_for_id(std::size_t i) const
+std::array<Vector2, 4> tile_atlas::texcoords_for_id(size_t i) const
{
fm_assert(i < num_tiles());
return texcoords_[i];
}
-auto tile_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, std::size_t i) -> texcoords
+auto tile_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i) -> texcoords
{
const auto sz = pixel_size/Vector2ui{tile_count};
- const Vector2ui id = { std::uint32_t(i % tile_count[0]), std::uint32_t(i / tile_count[0]) };
+ const Vector2ui id = { uint32_t(i % tile_count[0]), uint32_t(i / tile_count[0]) };
const Vector2 p0(id * sz), p1(sz);
const auto x0 = p0.x()+.5f, x1 = p1.x()-1, y0 = p0.y()+.5f, y1 = p1.y()-1;
return {{
@@ -48,14 +48,14 @@ auto tile_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, std:
auto tile_atlas::make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count) -> std::unique_ptr<const texcoords[]>
{
- const std::size_t N = Vector2ui{tile_count}.product();
+ const size_t N = Vector2ui{tile_count}.product();
auto ptr = std::make_unique<std::array<Vector2, 4>[]>(N);
for (auto i = 0_uz; i < N; i++)
ptr[i] = make_texcoords(pixel_size, tile_count, i);
return ptr;
}
-std::size_t tile_atlas::num_tiles() const { return Vector2ui{dims_}.product(); }
+size_t tile_atlas::num_tiles() const { return Vector2ui{dims_}.product(); }
Optional<enum pass_mode> tile_atlas::pass_mode() const { return passability; }
enum pass_mode tile_atlas::pass_mode(enum pass_mode p) const { return passability ? *passability : p; }
diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp
index e4ac8412..4ea2c67d 100644
--- a/src/tile-atlas.hpp
+++ b/src/tile-atlas.hpp
@@ -17,13 +17,13 @@ struct tile_atlas final
tile_atlas(StringView name, const ImageView2D& img, Vector2ub tile_count, Optional<enum pass_mode> pass_mode);
- texcoords texcoords_for_id(std::size_t id) const;
+ texcoords texcoords_for_id(size_t id) const;
static constexpr quad floor_quad(Vector3 center, Vector2 size);
static constexpr quad wall_quad_N(Vector3 center, Vector3 size);
static constexpr quad wall_quad_W(Vector3 center, Vector3 size);
- static constexpr std::array<UnsignedShort, 6> indices(std::size_t N);
+ static constexpr std::array<UnsignedShort, 6> indices(size_t N);
[[maybe_unused]] Vector2ui pixel_size() const { return size_; }
- std::size_t num_tiles() const;
+ size_t num_tiles() const;
Vector2ub num_tiles2() const { return dims_; }
GL::Texture2D& texture() { return tex_; }
StringView name() const { return name_; }
@@ -33,7 +33,7 @@ struct tile_atlas final
private:
static std::unique_ptr<const texcoords[]> make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count);
- static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, std::size_t i);
+ static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i);
std::unique_ptr<const texcoords[]> texcoords_;
GL::Texture2D tex_;
@@ -43,7 +43,7 @@ private:
Optional<enum pass_mode> passability;
};
-constexpr std::array<UnsignedShort, 6> tile_atlas::indices(std::size_t N)
+constexpr std::array<UnsignedShort, 6> tile_atlas::indices(size_t N)
{
using u16 = UnsignedShort;
return { /* 3--1 1 */
diff --git a/src/tile-defs.hpp b/src/tile-defs.hpp
index b8ea0387..b260fe8a 100644
--- a/src/tile-defs.hpp
+++ b/src/tile-defs.hpp
@@ -1,12 +1,11 @@
#pragma once
-#include <cstddef>
#include <Magnum/Math/Vector2.h>
#include <Magnum/Math/Vector3.h>
namespace floormat {
constexpr inline unsigned char TILE_MAX_DIM = 16;
-constexpr inline std::size_t TILE_COUNT = TILE_MAX_DIM*TILE_MAX_DIM;
+constexpr inline size_t TILE_COUNT = TILE_MAX_DIM*TILE_MAX_DIM;
constexpr inline auto TILE_MAX_DIM20d = Magnum::Math::Vector3<double> { TILE_MAX_DIM, TILE_MAX_DIM, 0 };
constexpr inline auto iTILE_SIZE = Magnum::Math::Vector3<Int> { 64, 64, 64 };
diff --git a/src/tile-image.hpp b/src/tile-image.hpp
index 77424c62..3227dc6b 100644
--- a/src/tile-image.hpp
+++ b/src/tile-image.hpp
@@ -1,12 +1,11 @@
#pragma once
-#include <cstdint>
#include <memory>
namespace floormat {
struct tile_atlas;
-using variant_t = std::uint8_t;
+using variant_t = uint8_t;
struct tile_image_proto final
{
diff --git a/src/tile-iterator.cpp b/src/tile-iterator.cpp
index 9214faa9..ac0fff67 100644
--- a/src/tile-iterator.cpp
+++ b/src/tile-iterator.cpp
@@ -3,24 +3,24 @@
namespace floormat {
-tile_iterator::tile_iterator(chunk& c, std::size_t pos) noexcept : c{&c}, pos{pos} {}
+tile_iterator::tile_iterator(chunk& c, size_t pos) noexcept : c{&c}, pos{pos} {}
tile_iterator::tile_iterator(const tile_iterator&) noexcept = default;
tile_iterator& tile_iterator::operator=(const tile_iterator&) noexcept = default;
tile_iterator& tile_iterator::operator++() noexcept { pos++; return *this; }
tile_iterator tile_iterator::operator++(int) noexcept { auto it = *this; pos++; return it; }
void tile_iterator::swap(tile_iterator& other) noexcept { std::swap(c, other.c); std::swap(pos, other.pos); }
bool operator==(const tile_iterator& a, const tile_iterator& b) noexcept { return a.c == b.c && a.pos == b.pos; }
-tile_iterator_tuple tile_iterator::operator->() noexcept { return { tile_ref{*c, std::uint8_t(pos)}, pos, local_coords{pos} }; }
+tile_iterator_tuple tile_iterator::operator->() noexcept { return { tile_ref{*c, uint8_t(pos)}, pos, local_coords{pos} }; }
tile_iterator_tuple tile_iterator::operator*() noexcept { return operator->(); }
-tile_const_iterator::tile_const_iterator(const chunk& c, std::size_t pos) noexcept : c{&c}, pos{pos} {}
+tile_const_iterator::tile_const_iterator(const chunk& c, size_t pos) noexcept : c{&c}, pos{pos} {}
tile_const_iterator::tile_const_iterator(const tile_const_iterator& x) noexcept = default;
tile_const_iterator& tile_const_iterator::operator=(const tile_const_iterator& x) noexcept { if (this != &x) { c = x.c; pos = x.pos; } return *this; }
tile_const_iterator& tile_const_iterator::operator++() noexcept { pos++; return *this; }
tile_const_iterator tile_const_iterator::operator++(int) noexcept { auto it = *this; pos++; return it; }
void tile_const_iterator::swap(tile_const_iterator& other) noexcept { std::swap(c, other.c); std::swap(pos, other.pos); }
bool operator==(const tile_const_iterator& a, const tile_const_iterator& b) noexcept { return a.c == b.c && a.pos == b.pos; }
-tile_const_iterator_tuple tile_const_iterator::operator->() noexcept { return { tile_proto(tile_ref{*const_cast<chunk*>(c), std::uint8_t(pos)}), pos, local_coords{pos}, }; }
+tile_const_iterator_tuple tile_const_iterator::operator->() noexcept { return { tile_proto(tile_ref{*const_cast<chunk*>(c), uint8_t(pos)}), pos, local_coords{pos}, }; }
tile_const_iterator_tuple tile_const_iterator::operator*() noexcept { return operator->(); }
} // namespace floormat
diff --git a/src/tile-iterator.hpp b/src/tile-iterator.hpp
index f5f717f6..f3b19dfc 100644
--- a/src/tile-iterator.hpp
+++ b/src/tile-iterator.hpp
@@ -3,7 +3,6 @@
#include "local-coords.hpp"
#include "tile.hpp"
-#include <cstddef>
#include <iterator>
namespace floormat {
@@ -13,7 +12,7 @@ struct tile_iterator_tuple final { // NOLINT(cppcoreguidelines-pro-type-member-i
tile_iterator_tuple* operator->() noexcept { return this; }
tile_ref x;
- std::size_t k;
+ size_t k;
local_coords pt;
};
@@ -22,18 +21,18 @@ struct tile_const_iterator_tuple final { // NOLINT(cppcoreguidelines-pro-type-me
tile_const_iterator_tuple* operator->() noexcept { return this; }
tile_proto x;
- std::size_t k;
+ size_t k;
local_coords pt;
};
class tile_iterator final {
chunk* c;
- std::size_t pos;
+ size_t pos;
friend bool operator==(const tile_iterator&, const tile_iterator&) noexcept;
public:
- explicit tile_iterator(chunk& c, std::size_t pos) noexcept;
+ explicit tile_iterator(chunk& c, size_t pos) noexcept;
tile_iterator(const tile_iterator&) noexcept;
tile_iterator& operator=(const tile_iterator&) noexcept;
@@ -44,7 +43,7 @@ public:
tile_iterator_tuple operator->() noexcept;
tile_iterator_tuple operator*() noexcept;
- using difference_type = std::ptrdiff_t;
+ using difference_type = ptrdiff_t;
using value_type = tile_iterator_tuple;
using pointer = value_type;
using reference = value_type;
@@ -53,12 +52,12 @@ public:
class tile_const_iterator final {
const chunk* c;
- std::size_t pos;
+ size_t pos;
friend bool operator==(const tile_const_iterator&, const tile_const_iterator&) noexcept;
public:
- explicit tile_const_iterator(const chunk& c, std::size_t pos) noexcept;
+ explicit tile_const_iterator(const chunk& c, size_t pos) noexcept;
tile_const_iterator(const tile_const_iterator&) noexcept;
tile_const_iterator& operator=(const tile_const_iterator&) noexcept;
@@ -69,7 +68,7 @@ public:
tile_const_iterator_tuple operator->() noexcept;
tile_const_iterator_tuple operator*() noexcept;
- using difference_type = std::ptrdiff_t;
+ using difference_type = ptrdiff_t;
using value_type = tile_const_iterator_tuple;
using pointer = value_type;
using reference = value_type;
diff --git a/src/tile.cpp b/src/tile.cpp
index 75ef71e7..5a85a09c 100644
--- a/src/tile.cpp
+++ b/src/tile.cpp
@@ -13,7 +13,7 @@ tile_image_proto tile_proto::ground() const noexcept { return { ground_atlas
tile_image_proto tile_proto::wall_north() const noexcept { return { wall_north_atlas, wall_north_variant }; }
tile_image_proto tile_proto::wall_west() const noexcept { return { wall_west_atlas, wall_west_variant }; }
-tile_ref::tile_ref(struct chunk& c, std::uint8_t i) noexcept : _chunk{&c}, i{i} {}
+tile_ref::tile_ref(struct chunk& c, uint8_t i) noexcept : _chunk{&c}, i{i} {}
std::shared_ptr<tile_atlas> tile_ref::ground_atlas() noexcept { return _chunk->_ground_atlases[i]; }
std::shared_ptr<tile_atlas> tile_ref::wall_north_atlas() noexcept { return _chunk->_wall_atlases[i*2+0]; }
diff --git a/src/tile.hpp b/src/tile.hpp
index 5eed7633..f9d6adc8 100644
--- a/src/tile.hpp
+++ b/src/tile.hpp
@@ -20,7 +20,7 @@ struct tile_proto final
struct tile_ref final
{
- tile_ref(struct chunk& c, std::uint8_t i) noexcept;
+ tile_ref(struct chunk& c, uint8_t i) noexcept;
tile_image_ref ground() noexcept;
tile_image_ref wall_north() noexcept;
@@ -42,13 +42,13 @@ struct tile_ref final
struct chunk& chunk() noexcept { return *_chunk; }
const struct chunk& chunk() const noexcept { return *_chunk; }
- std::size_t index() const noexcept { return i; }
+ size_t index() const noexcept { return i; }
friend bool operator==(const tile_ref& a, const tile_ref& b) noexcept;
private:
struct chunk* _chunk;
- std::uint8_t i;
+ uint8_t i;
};
} //namespace floormat
diff --git a/src/world.cpp b/src/world.cpp
index d6099302..7dab8dee 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -49,7 +49,7 @@ world::~world() noexcept
_entities.clear();
}
-world::world(std::size_t capacity) : _chunks{capacity, hasher}
+world::world(size_t capacity) : _chunks{capacity, hasher}
{
_chunks.max_load_factor(max_load_factor);
}
@@ -126,14 +126,14 @@ void world::do_make_entity(const std::shared_ptr<entity>& e, global_coords pos,
e->c->add_entity_unsorted(e);
}
-void world::do_kill_entity(std::uint64_t id)
+void world::do_kill_entity(object_id id)
{
fm_debug_assert(id > 0);
auto cnt = _entities.erase(id);
fm_debug_assert(cnt > 0);
}
-std::shared_ptr<entity> world::find_entity_(std::uint64_t id)
+std::shared_ptr<entity> world::find_entity_(object_id id)
{
auto it = _entities.find(id);
auto ret = it == _entities.end() ? nullptr : it->second.lock();
@@ -141,7 +141,7 @@ std::shared_ptr<entity> world::find_entity_(std::uint64_t id)
return ret;
}
-void world::set_entity_counter(std::uint64_t value)
+void world::set_entity_counter(object_id value)
{
fm_assert(value >= _entity_counter);
_entity_counter = value;
diff --git a/src/world.hpp b/src/world.hpp
index 29d5a8dd..589bbd67 100644
--- a/src/world.hpp
+++ b/src/world.hpp
@@ -4,7 +4,6 @@
#include "chunk.hpp"
#include "global-coords.hpp"
#include "entity-type.hpp"
-#include <cstddef>
#include <unordered_map>
#include <memory>
@@ -22,24 +21,24 @@ private:
chunk_coords pos = invalid_coords;
} _last_chunk;
- static constexpr std::size_t initial_capacity = 64;
+ static constexpr size_t initial_capacity = 64;
static constexpr float max_load_factor = .5;
- static constexpr auto hasher = [](chunk_coords c) constexpr -> std::size_t {
- return int_hash((std::size_t)c.y << 16 | (std::size_t)c.x);
+ static constexpr auto hasher = [](chunk_coords c) constexpr -> size_t {
+ return int_hash((size_t)c.y << 16 | (size_t)c.x);
};
std::unordered_map<chunk_coords, chunk, decltype(hasher)> _chunks;
- std::unordered_map<std::uint64_t, std::weak_ptr<entity>> _entities;
- std::size_t _last_collection = 0;
- std::size_t _collect_every = 64;
+ std::unordered_map<object_id, std::weak_ptr<entity>> _entities;
+ size_t _last_collection = 0;
+ size_t _collect_every = 64;
std::shared_ptr<char> _unique_id = std::make_shared<char>('A');
- std::uint64_t _entity_counter = 0;
+ object_id _entity_counter = 0;
bool _teardown : 1 = false;
- explicit world(std::size_t capacity);
+ explicit world(size_t capacity);
void do_make_entity(const std::shared_ptr<entity>& e, global_coords pos, bool sorted);
- void do_kill_entity(std::uint64_t id);
- std::shared_ptr<entity> find_entity_(std::uint64_t id);
+ void do_kill_entity(object_id id);
+ std::shared_ptr<entity> find_entity_(object_id id);
friend struct entity;
@@ -58,18 +57,18 @@ public:
void clear();
void collect(bool force = false);
void maybe_collect();
- std::size_t size() const noexcept { return _chunks.size(); }
+ size_t size() const noexcept { return _chunks.size(); }
const auto& chunks() const noexcept { return _chunks; }
void serialize(StringView filename);
static world deserialize(StringView filename);
- void set_collect_threshold(std::size_t value) { _collect_every = value; }
- std::size_t collect_threshold() const noexcept { return _collect_every; }
+ void set_collect_threshold(size_t value) { _collect_every = value; }
+ size_t collect_threshold() const noexcept { return _collect_every; }
template<typename T, bool sorted = true, typename... Xs>
- requires requires(chunk& c) { T{std::uint64_t(), c, entity_type(), std::declval<Xs>()...}; }
- std::shared_ptr<T> make_entity(std::uint64_t id, global_coords pos, Xs&&... xs)
+ requires requires(chunk& c) { T{object_id(), c, entity_type(), std::declval<Xs>()...}; }
+ std::shared_ptr<T> make_entity(object_id id, global_coords pos, Xs&&... xs)
{
static_assert(std::is_base_of_v<entity, T>);
auto ret = std::shared_ptr<T>(new T{id, operator[](pos.chunk()), entity_type_<T>::value, std::forward<Xs>(xs)...});
@@ -77,12 +76,12 @@ public:
return ret;
}
- template<typename T = entity> std::shared_ptr<T> find_entity(std::uint64_t id);
+ template<typename T = entity> std::shared_ptr<T> find_entity(object_id id);
bool is_teardown() const { return _teardown; }
- std::uint64_t entity_counter() const { return _entity_counter; }
- [[nodiscard]] std::uint64_t make_id() { return ++_entity_counter; }
- void set_entity_counter(std::uint64_t value);
+ object_id entity_counter() const { return _entity_counter; }
+ [[nodiscard]] object_id make_id() { return ++_entity_counter; }
+ void set_entity_counter(object_id value);
world& operator=(world&& w) noexcept;
world(world&& w) noexcept;
@@ -92,14 +91,14 @@ public:
template<typename Hash, typename Alloc, typename Pred>
world::world(std::unordered_map<chunk_coords, chunk, Hash, Alloc, Pred>&& chunks) :
- world{std::max(initial_capacity, std::size_t(1/max_load_factor * 2 * chunks.size()))}
+ world{std::max(initial_capacity, size_t(1/max_load_factor * 2 * chunks.size()))}
{
for (auto&& [coord, c] : chunks)
operator[](coord) = std::move(c);
}
template<typename T>
-std::shared_ptr<T> world::find_entity(std::uint64_t id)
+std::shared_ptr<T> world::find_entity(object_id id)
{
static_assert(std::is_base_of_v<entity, T>);
// make it a dependent name so that including "src/entity.hpp" isn't needed