summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-04 13:14:25 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-04 13:14:25 +0100
commit22c0347382db21803cbeaf599a473b1d13b009a3 (patch)
treee700d33fa247600f69d2016405109aabae15ab71 /src
parentf8af6aadbf67bd2ff459d3e8fb09364342a8d080 (diff)
b
Diffstat (limited to 'src')
-rw-r--r--src/chunk-collision.cpp4
-rw-r--r--src/chunk-render.cpp2
-rw-r--r--src/chunk-walls.cpp8
-rw-r--r--src/chunk.hpp3
-rw-r--r--src/critter.cpp2
-rw-r--r--src/critter.hpp2
-rw-r--r--src/light.cpp2
-rw-r--r--src/light.hpp2
-rw-r--r--src/object.cpp8
-rw-r--r--src/object.hpp8
-rw-r--r--src/path-search.hpp2
-rw-r--r--src/raycast.cpp3
-rw-r--r--src/scenery.cpp10
-rw-r--r--src/scenery.hpp12
-rw-r--r--src/tile.cpp2
-rw-r--r--src/tile.hpp10
16 files changed, 41 insertions, 39 deletions
diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp
index 5ffbf0ec..cfb157a9 100644
--- a/src/chunk-collision.cpp
+++ b/src/chunk-collision.cpp
@@ -53,13 +53,13 @@ void chunk::ensure_passability() noexcept
auto tile = operator[](i);
if (const auto* atlas = tile.wall_north_atlas().get())
{
- auto [min, max] = wall_north(i, atlas->info().depth);
+ auto [min, max] = wall_north(i, (float)atlas->info().depth);
auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT+i+1);
_rtree->Insert(min.data(), max.data(), id);
}
if (const auto* atlas = tile.wall_west_atlas().get())
{
- auto [min, max] = wall_west(i, atlas->info().depth);
+ auto [min, max] = wall_west(i, (float)atlas->info().depth);
auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT*2+i+1);
_rtree->Insert(min.data(), max.data(), id);
}
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index c5dd068a..b445eff9 100644
--- a/src/chunk-render.cpp
+++ b/src/chunk-render.cpp
@@ -55,7 +55,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
return _ground->atlases[a] < _ground->atlases[b];
});
- float hack_offset = _coord.z <= 0 ? -16 : 0; // XXX hack
+ float hack_offset = _coord.z <= 0 ? -16.f : 0.f; // XXX hack
auto& vertexes = static_vertexes;
for (auto k = 0uz; k < count; k++)
diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp
index 6f17fc06..674d0a65 100644
--- a/src/chunk-walls.cpp
+++ b/src/chunk-walls.cpp
@@ -245,7 +245,7 @@ GL::Mesh chunk::make_wall_mesh()
const auto depth_offset = depth_offset_for_group(Group_::corner, is_west);
const auto pos_x = !is_west ? (float)pos.x : (float)pos.x - 1;
const auto depth = tile_shader::depth_value(pos_x, pos.y, depth_offset);
- variant += !is_west ? frames.size() - 1 : 1;
+ variant += variant_t(!is_west ? frames.size() - 1 : 1);
fm_assert((size_t)(variant_t)frames.size() == frames.size());
variant = variant % (variant_t)frames.size();
const auto& frame = frames[variant];
@@ -254,7 +254,7 @@ GL::Mesh chunk::make_wall_mesh()
fm_assert(i < vertexes.size());
_walls->mesh_indexes[i] = (uint16_t)k;
auto& v = vertexes[i];
- auto quad = get_quad(D, Group_::corner, Depth);
+ auto quad = get_quad(D, Group_::corner, (float)Depth);
for (auto& v : quad)
v += center;
for (uint8_t j = 0; j < 4; j++)
@@ -266,7 +266,7 @@ GL::Mesh chunk::make_wall_mesh()
auto variant = (variant_ != (uint8_t)-1 ? variant_ : vpos);
const auto depth_offset = depth_offset_for_group(Group_::corner, is_west);
const auto depth = tile_shader::depth_value(!is_west ? (float)pos.x : (float)pos.x - 1, depth_offset);
- variant += !is_west ? frames.size() - 1 : 1;
+ variant += variant_t(!is_west ? frames.size() - 1 : 1);
variant %= frames.size();
const auto& frame = frames[variant];
fm_assert(frame.size.x() > Depth);
@@ -299,7 +299,7 @@ GL::Mesh chunk::make_wall_mesh()
const auto texcoords = Quads::texcoords_at(frame.offset, frame.size, atlas->image_size());
const auto depth_offset = depth_offset_for_group(G, is_west);
const auto depth = tile_shader::depth_value(pos, depth_offset);
- auto quad = get_quad(D, G, Depth);
+ auto quad = get_quad(D, G, (float)Depth);
for (auto& v : quad)
v += center;
auto& v = vertexes[i];
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 75fe4bc7..3e142abf 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -21,8 +21,9 @@ struct object_proto;
class tile_iterator;
class tile_const_iterator;
-struct chunk final
+class chunk final
{
+public:
friend struct tile_ref;
friend struct object;
friend class world;
diff --git a/src/critter.cpp b/src/critter.cpp
index 3615589e..97a0850f 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -226,7 +226,7 @@ critter::operator critter_proto() const
return ret;
}
-critter::critter(object_id id, struct chunk& c, const critter_proto& proto) :
+critter::critter(object_id id, class chunk& c, const critter_proto& proto) :
object{id, c, proto},
name{proto.name},
playable{proto.playable}
diff --git a/src/critter.hpp b/src/critter.hpp
index 29b29a84..00e01cd1 100644
--- a/src/critter.hpp
+++ b/src/critter.hpp
@@ -40,7 +40,7 @@ private:
int allocate_frame_time(float dt);
friend class world;
- critter(object_id id, struct chunk& c, const critter_proto& proto);
+ critter(object_id id, class chunk& c, const critter_proto& proto);
};
template<> struct object_type_<struct critter> : std::integral_constant<object_type, object_type::critter> {};
diff --git a/src/light.cpp b/src/light.cpp
index ec4a5cb1..878a5f19 100644
--- a/src/light.cpp
+++ b/src/light.cpp
@@ -17,7 +17,7 @@ light_proto& light_proto::operator=(const light_proto&) = default;
light_proto::~light_proto() noexcept = default;
bool light_proto::operator==(const light_proto&) const = default;
-light::light(object_id id, struct chunk& c, const light_proto& proto) :
+light::light(object_id id, class chunk& c, const light_proto& proto) :
object{id, c, proto},
max_distance{proto.max_distance},
color{proto.color},
diff --git a/src/light.hpp b/src/light.hpp
index 7fc429ea..92da2a19 100644
--- a/src/light.hpp
+++ b/src/light.hpp
@@ -28,7 +28,7 @@ struct light final : object
light_falloff falloff : 2;
uint8_t enabled : 1;
- light(object_id id, struct chunk& c, const light_proto& proto);
+ light(object_id id, class chunk& c, const light_proto& proto);
Vector2 ordinal_offset(Vector2b offset) const override;
float depth_offset() const override;
diff --git a/src/object.cpp b/src/object.cpp
index ce3bb51f..b079c9ef 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -49,7 +49,7 @@ object_proto::object_proto() = default;
object_proto::object_proto(const object_proto&) = default;
object_type object_proto::type_of() const noexcept { return type; }
-object::object(object_id id, struct chunk& c, const object_proto& proto) :
+object::object(object_id id, class chunk& c, const object_proto& proto) :
id{id}, c{&c}, atlas{proto.atlas},
offset{proto.offset}, bbox_offset{proto.bbox_offset},
bbox_size{proto.bbox_size}, delta{proto.delta},
@@ -87,7 +87,7 @@ float object::ordinal(local_coords xy, Vector2b offset, Vector2s z_offset) const
return vec[0] + vec[1] + Vector2(z_offset).sum();
}
-struct chunk& object::chunk() const
+class chunk& object::chunk() const
{
return *c;
}
@@ -159,7 +159,7 @@ point object::normalize_coords(const point& pt, Vector2i delta)
}
template<bool neighbor = true>
-static bool do_search(struct chunk* c, chunk_coords_ coord,
+static bool do_search(class chunk* c, chunk_coords_ coord,
object_id id, Vector2 min, Vector2 max, Vector2b off = {})
{
if constexpr(neighbor)
@@ -259,7 +259,7 @@ void object::move_to(size_t& i, Vector2i delta, rotation new_r)
const_cast<global_coords&>(coord) = coord_;
set_bbox_(offset_, bb_offset, bb_size, pass);
const_cast<rotation&>(r) = new_r;
- const_cast<struct chunk*&>(c) = &c2;
+ const_cast<class chunk*&>(c) = &c2;
i = (size_t)std::distance(es.cbegin(), it);
arrayInsert(es, i, std::move(e_));
}
diff --git a/src/object.hpp b/src/object.hpp
index 7d9ce9f0..6db9d8bc 100644
--- a/src/object.hpp
+++ b/src/object.hpp
@@ -13,7 +13,7 @@ namespace floormat {
template<typename T> struct object_type_;
class anim_atlas;
class world;
-struct chunk;
+class chunk;
struct object_proto
{
@@ -41,7 +41,7 @@ struct object
fm_DECLARE_DELETED_COPY_ASSIGNMENT(object);
const object_id id = 0;
- struct chunk* const c;
+ class chunk* const c;
const std::shared_ptr<anim_atlas> atlas;
const global_coords coord;
const Vector2b offset, bbox_offset;
@@ -57,7 +57,7 @@ struct object
virtual float depth_offset() const = 0;
float ordinal() const;
float ordinal(local_coords xy, Vector2b offset, Vector2s z_offset) const;
- struct chunk& chunk() const;
+ class chunk& chunk() const;
size_t index() const;
virtual bool is_virtual() const;
point position() const;
@@ -84,7 +84,7 @@ struct object
void move_to(Vector2i delta);
protected:
- object(object_id id, struct chunk& c, const object_proto& proto);
+ object(object_id id, class chunk& c, const object_proto& proto);
void set_bbox_(Vector2b offset, Vector2b bbox_offset, Vector2ub bbox_size, pass_mode pass);
};
diff --git a/src/path-search.hpp b/src/path-search.hpp
index 512a507f..42d99d4d 100644
--- a/src/path-search.hpp
+++ b/src/path-search.hpp
@@ -19,7 +19,7 @@ namespace floormat {
class world;
struct object;
-struct chunk;
+class chunk;
// todo add pathfinding sub-namespace
diff --git a/src/raycast.cpp b/src/raycast.cpp
index dc04291a..eb3fb094 100644
--- a/src/raycast.cpp
+++ b/src/raycast.cpp
@@ -4,6 +4,7 @@
#include "src/object.hpp"
#include "src/RTree-search.hpp"
#include <cfloat>
+#include <bit>
#include <Corrade/Containers/StructuredBindings.h>
#include <Corrade/Containers/GrowableArray.h>
#include <Magnum/Math/Functions.h>
@@ -17,7 +18,7 @@ template<typename T> constexpr inline auto tile_size = Math::Vector2<T>{iTILE_SI
template<typename T> constexpr inline auto chunk_size = Math::Vector2<T>{TILE_MAX_DIM} * tile_size<T>;
using floormat::detail_rc::bbox;
-using RTree = std::decay_t<decltype(*std::declval<struct chunk>().rtree())>;
+using RTree = std::decay_t<decltype(*std::declval<class chunk>().rtree())>;
using Rect = typename RTree::Rect;
template<class T> constexpr inline T sign_(auto&& x) {
diff --git a/src/scenery.cpp b/src/scenery.cpp
index e384036d..9adae347 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -65,7 +65,7 @@ enum scenery_type scenery_proto::scenery_type() const
generic_scenery::operator generic_scenery_proto() const { return { .active = active, .interactive = interactive, }; }
-generic_scenery::generic_scenery(object_id, struct chunk&, const generic_scenery_proto& p) :
+generic_scenery::generic_scenery(object_id, class chunk&, const generic_scenery_proto& p) :
active{p.active}, interactive{p.interactive}
{}
@@ -75,7 +75,7 @@ enum scenery_type door_scenery_proto::scenery_type() const { return scenery_type
enum scenery_type door_scenery::scenery_type() const { return scenery_type::door; }
door_scenery::operator door_scenery_proto() const { return { .active = active, .interactive = interactive, .closing = closing, }; }
-door_scenery::door_scenery(object_id, struct chunk&, const door_scenery_proto& p) :
+door_scenery::door_scenery(object_id, class chunk&, const door_scenery_proto& p) :
closing{p.closing}, active{p.active}, interactive{p.interactive}
{}
@@ -237,7 +237,7 @@ enum scenery_type scenery::scenery_type() const
);
}
-scenery_variants scenery::subtype_from_proto(object_id id, struct chunk& c, const scenery_proto_variants& variant)
+scenery_variants scenery::subtype_from_proto(object_id id, class chunk& c, const scenery_proto_variants& variant)
{
return std::visit(
[&]<typename T>(const T& p) {
@@ -247,7 +247,7 @@ scenery_variants scenery::subtype_from_proto(object_id id, struct chunk& c, cons
);
}
-scenery_variants scenery::subtype_from_scenery_type(object_id id, struct chunk& c, enum scenery_type type)
+scenery_variants scenery::subtype_from_scenery_type(object_id id, class chunk& c, enum scenery_type type)
{
switch (type)
{
@@ -261,7 +261,7 @@ scenery_variants scenery::subtype_from_scenery_type(object_id id, struct chunk&
fm_throw("invalid scenery type"_cf, (int)type);
}
-scenery::scenery(object_id id, struct chunk& c, const scenery_proto& proto) :
+scenery::scenery(object_id id, class chunk& c, const scenery_proto& proto) :
object{id, c, proto}, subtype{ subtype_from_proto(id, c, proto.subtype) }
{
#ifndef FM_NO_DEBUG
diff --git a/src/scenery.hpp b/src/scenery.hpp
index c462a433..e6e483fa 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -14,7 +14,7 @@ namespace floormat {
template<typename... Ts> struct [[maybe_unused]] overloaded : Ts... { using Ts::operator()...; };
template<typename... Ts> overloaded(Ts...) -> overloaded<Ts...>;
-struct chunk;
+class chunk;
class anim_atlas;
class world;
@@ -71,7 +71,7 @@ struct generic_scenery
enum scenery_type scenery_type() const;
explicit operator generic_scenery_proto() const;
- generic_scenery(object_id id, struct chunk& c, const generic_scenery_proto& p);
+ generic_scenery(object_id id, class chunk& c, const generic_scenery_proto& p);
};
struct door_scenery
@@ -88,7 +88,7 @@ struct door_scenery
enum scenery_type scenery_type() const;
explicit operator door_scenery_proto() const;
- door_scenery(object_id id, struct chunk& c, const door_scenery_proto& p);
+ door_scenery(object_id id, class chunk& c, const door_scenery_proto& p);
};
using scenery_variants = std::variant<generic_scenery, door_scenery>;
@@ -107,12 +107,12 @@ struct scenery final : object
explicit operator scenery_proto() const;
enum scenery_type scenery_type() const;
- static scenery_variants subtype_from_proto(object_id id, struct chunk& c, const scenery_proto_variants& variants);
- static scenery_variants subtype_from_scenery_type(object_id id, struct chunk& c, enum scenery_type type);
+ static scenery_variants subtype_from_proto(object_id id, class chunk& c, const scenery_proto_variants& variants);
+ static scenery_variants subtype_from_scenery_type(object_id id, class chunk& c, enum scenery_type type);
private:
friend class world;
- scenery(object_id id, struct chunk& c, const scenery_proto& proto);
+ scenery(object_id id, class chunk& c, const scenery_proto& proto);
};
template<> struct object_type_<scenery> : std::integral_constant<object_type, object_type::scenery> {};
diff --git a/src/tile.cpp b/src/tile.cpp
index 91fb73aa..1f36d5b4 100644
--- a/src/tile.cpp
+++ b/src/tile.cpp
@@ -21,7 +21,7 @@ tile_image_proto tile_proto::ground() const noexcept { return { ground_atlas
wall_image_proto tile_proto::wall_north() const noexcept { return { wall_north_atlas, wall_north_variant }; }
wall_image_proto tile_proto::wall_west() const noexcept { return { wall_west_atlas, wall_west_variant }; }
-tile_ref::tile_ref(struct chunk& c, uint8_t i) noexcept : _chunk{&c}, i{i} {}
+tile_ref::tile_ref(class chunk& c, uint8_t i) noexcept : _chunk{&c}, i{i} {}
std::shared_ptr<class ground_atlas> tile_ref::ground_atlas() noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; }
std::shared_ptr<class wall_atlas> tile_ref::wall_north_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; }
diff --git a/src/tile.hpp b/src/tile.hpp
index 3f691567..43170fe7 100644
--- a/src/tile.hpp
+++ b/src/tile.hpp
@@ -3,7 +3,7 @@
namespace floormat {
-struct chunk;
+class chunk;
class anim_atlas;
struct tile_proto final
@@ -21,7 +21,7 @@ struct tile_proto final
struct tile_ref final
{
- tile_ref(struct chunk& c, uint8_t i) noexcept;
+ tile_ref(class chunk& c, uint8_t i) noexcept;
tile_image_ref ground() noexcept;
wall_image_ref wall_north() noexcept;
@@ -41,14 +41,14 @@ struct tile_ref final
explicit operator tile_proto() const noexcept;
- struct chunk& chunk() noexcept { return *_chunk; }
- const struct chunk& chunk() const noexcept { return *_chunk; }
+ class chunk& chunk() noexcept { return *_chunk; }
+ const class chunk& chunk() const noexcept { return *_chunk; }
size_t index() const noexcept { return i; }
friend bool operator==(const tile_ref& a, const tile_ref& b) noexcept;
private:
- struct chunk* _chunk;
+ class chunk* _chunk;
uint8_t i;
};