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
119
120
121
|
#pragma once
#include "pass-mode.hpp"
#include "tile-defs.hpp"
#include "rotation.hpp"
#include "object.hpp"
#include <type_traits>
#include <variant>
#include <Corrade/Containers/Optional.h>
#include <Magnum/Math/Vector2.h>
#include <Magnum/Magnum.h>
namespace floormat {
template<typename... Ts> struct [[maybe_unused]] overloaded : Ts... { using Ts::operator()...; };
template<typename... Ts> overloaded(Ts...) -> overloaded<Ts...>;
class chunk;
class anim_atlas;
class world;
enum class scenery_type : unsigned char {
none, generic, door,
};
struct generic_scenery_proto
{
unsigned char active : 1 = false;
unsigned char interactive : 1 = false;
bool operator==(const generic_scenery_proto& p) const;
enum scenery_type scenery_type() const;
};
struct door_scenery_proto
{
unsigned char active : 1 = false;
unsigned char interactive : 1 = true;
unsigned char closing : 1 = false;
bool operator==(const door_scenery_proto& p) const;
enum scenery_type scenery_type() const;
};
using scenery_proto_variants = std::variant<generic_scenery_proto, door_scenery_proto>;
struct scenery_proto : object_proto
{
scenery_proto_variants subtype;
scenery_proto() noexcept;
scenery_proto(const scenery_proto&) noexcept;
~scenery_proto() noexcept override;
scenery_proto& operator=(const scenery_proto&) noexcept;
bool operator==(const object_proto& proto) const override;
explicit operator bool() const;
enum scenery_type scenery_type() const;
};
struct scenery;
struct generic_scenery
{
unsigned char active : 1 = false;
unsigned char interactive : 1 = false;
void update(scenery& sc, size_t& i, Ns dt);
Vector2 ordinal_offset(const scenery& sc, Vector2b offset) const;
bool can_activate(const scenery& sc, size_t i) const;
bool activate(scenery& sc, size_t i);
enum scenery_type scenery_type() const;
explicit operator generic_scenery_proto() const;
generic_scenery(object_id id, class chunk& c, const generic_scenery_proto& p);
};
struct door_scenery
{
unsigned char closing : 1 = false;
unsigned char active : 1 = false;
unsigned char interactive : 1 = false;
void update(scenery& sc, size_t& i, Ns dt);
Vector2 ordinal_offset(const scenery& sc, Vector2b offset) const;
bool can_activate(const scenery& sc, size_t i) const;
bool activate(scenery& sc, size_t i);
enum scenery_type scenery_type() const;
explicit operator door_scenery_proto() const;
door_scenery(object_id id, class chunk& c, const door_scenery_proto& p);
};
using scenery_variants = std::variant<generic_scenery, door_scenery>;
struct scenery final : object
{
scenery_variants subtype;
void update(size_t& i, const Ns& dt) override;
Vector2 ordinal_offset(Vector2b offset) const override;
float depth_offset() const override;
bool can_activate(size_t i) const override;
bool activate(size_t i) override;
object_type type() const noexcept override;
explicit operator scenery_proto() const;
enum scenery_type scenery_type() const;
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, class chunk& c, const scenery_proto& proto);
};
template<> struct object_type_<scenery> : std::integral_constant<object_type, object_type::scenery> {};
template<> struct object_type_<scenery_proto> : std::integral_constant<object_type, object_type::scenery> {};
} // namespace floormat
|