blob: 6a48e57b9118ef3e4298bef86f26b6274550b63d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#include "hole.hpp"
#include "chunk.hpp"
#include "loader/loader.hpp"
#include "loader/vobj-cell.hpp"
#include "shaders/shader.hpp"
#include "tile-constants.hpp"
#include "compat/non-const.hpp"
namespace floormat {
namespace {
} // namespace
hole_proto::~hole_proto() noexcept = default;
hole_proto::hole_proto(const hole_proto&) = default;
hole_proto& hole_proto::operator=(const hole_proto&) = default;
hole_proto::hole_proto(hole_proto&&) noexcept = default;
hole_proto& hole_proto::operator=(hole_proto&&) noexcept = default;
bool hole_proto::flags::operator==(const struct flags&) const = default;
bool hole_proto::operator==(const object_proto& oʹ) const
{
if (type != oʹ.type)
return false;
if (!object_proto::operator==(oʹ))
return false;
const auto& o = static_cast<const hole_proto&>(oʹ);
return height == o.height && z_offset == o.z_offset && flags == o.flags;
}
hole_proto::hole_proto()
{
atlas = loader.vobj("hole"_s).atlas;
type = object_type::hole;
}
hole::hole(object_id id, floormat::chunk& c, const hole_proto& proto):
object{id, c, proto}, height{proto.height}, flags{proto.flags}
{
}
hole::~hole() noexcept
{
if (c->is_teardown()) [[unlikely]]
return;
mark_chunk_modified();
}
void hole::update(const std::shared_ptr<object>&, size_t&, const Ns&) {}
hole::operator hole_proto() const
{
hole_proto ret;
static_cast<object_proto&>(ret) = object_proto(*this);
ret.height = height;
ret.flags = flags;
return ret;
}
void hole::mark_chunk_modified()
{
c->mark_ground_modified(); // todo conditionalize
c->mark_walls_modified(); // todo conditionalize
c->mark_passability_modified();
}
float hole::depth_offset() const
{
constexpr auto ret = 4 / tile_shader::depth_tile_size;
return ret;
}
Vector2 hole::ordinal_offset(Vector2b) const
{
constexpr auto ret = Vector2(TILE_COUNT, TILE_COUNT) * TILE_SIZE2;
return ret;
}
void hole::set_height(uint8_t heightʹ)
{
if (height != heightʹ)
{
const_cast<uint8_t&>(height) = heightʹ;
mark_chunk_modified();
}
}
void hole::set_z_offset(uint8_t z)
{
if (z_offset != z)
{
const_cast<uint8_t&>(z_offset) = z;
mark_chunk_modified();
}
}
void hole::set_enabled(bool on_render, bool on_physics)
{
non_const(flags).on_render = on_render;
if (flags.on_physics != on_physics)
{
non_const(flags).on_physics = on_physics;
mark_chunk_modified();
}
}
object_type hole::type() const noexcept { return object_type::hole; }
bool hole::is_virtual() const { return true; }
bool hole::is_dynamic() const { return true; }
} // namespace floormat
|