-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split scenery-proto into its own file
- Loading branch information
Showing
13 changed files
with
126 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "scenery-proto.hpp" | ||
#include "compat/overloaded.hpp" | ||
|
||
namespace floormat { | ||
|
||
// ---------- generic_scenery_proto ---------- | ||
|
||
bool generic_scenery_proto::operator==(const generic_scenery_proto& p) const = default; | ||
enum scenery_type generic_scenery_proto::scenery_type() { return scenery_type::generic; } | ||
|
||
// ---------- door_scenery_proto ---------- | ||
|
||
bool door_scenery_proto::operator==(const door_scenery_proto& p) const = default; | ||
enum scenery_type door_scenery_proto::scenery_type() { return scenery_type::door; } | ||
|
||
// --- scenery_proto --- | ||
|
||
scenery_proto::scenery_proto() noexcept { type = object_type::scenery; } | ||
scenery_proto::~scenery_proto() noexcept = default; | ||
scenery_proto::operator bool() const { return atlas != nullptr; } | ||
|
||
scenery_proto& scenery_proto::operator=(const scenery_proto&) noexcept = default; | ||
scenery_proto::scenery_proto(const scenery_proto&) noexcept = default; | ||
scenery_proto& scenery_proto::operator=(scenery_proto&&) noexcept = default; | ||
scenery_proto::scenery_proto(scenery_proto&&) noexcept = default; | ||
|
||
enum scenery_type scenery_proto::scenery_type() const | ||
{ | ||
return std::visit(overloaded { | ||
[](std::monostate) { return scenery_type::none; }, | ||
[]<typename T>(const T&) { return T::scenery_type(); }, | ||
}, subtype | ||
); | ||
} | ||
|
||
bool scenery_proto::operator==(const object_proto& e0) const | ||
{ | ||
if (type != e0.type) | ||
return false; | ||
|
||
if (!object_proto::operator==(e0)) | ||
return false; | ||
|
||
const auto& sc = static_cast<const scenery_proto&>(e0); | ||
|
||
if (subtype.index() != sc.subtype.index()) | ||
return false; | ||
|
||
return std::visit( | ||
[](const auto& a, const auto& b) -> bool { | ||
if constexpr(std::is_same_v<std::decay_t<decltype(a)>, std::decay_t<decltype(b)>>) | ||
return a == b; | ||
else | ||
fm_assert(false); | ||
}, | ||
subtype, sc.subtype | ||
); | ||
} | ||
|
||
} // namespace floormat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
#include "scenery-type.hpp" | ||
#include "object.hpp" | ||
#include <variant> | ||
|
||
namespace floormat { | ||
|
||
struct generic_scenery_proto | ||
{ | ||
bool active : 1 = false; | ||
bool interactive : 1 = false; | ||
|
||
bool operator==(const generic_scenery_proto& p) const; | ||
static enum scenery_type scenery_type(); | ||
}; | ||
|
||
struct door_scenery_proto | ||
{ | ||
bool active : 1 = false; | ||
bool interactive : 1 = true; | ||
bool closing : 1 = false; | ||
|
||
bool operator==(const door_scenery_proto& p) const; | ||
static enum scenery_type scenery_type(); | ||
}; | ||
|
||
using scenery_proto_variants = std::variant<std::monostate, generic_scenery_proto, door_scenery_proto>; | ||
|
||
struct scenery_proto : object_proto | ||
{ | ||
scenery_proto_variants subtype; // todo! add std::monostate | ||
|
||
scenery_proto() noexcept; | ||
~scenery_proto() noexcept override; | ||
explicit operator bool() const; | ||
bool operator==(const object_proto& proto) const override; | ||
enum scenery_type scenery_type() const; | ||
scenery_proto(const scenery_proto&) noexcept; | ||
scenery_proto& operator=(const scenery_proto&) noexcept; | ||
scenery_proto(scenery_proto&&) noexcept; | ||
scenery_proto& operator=(scenery_proto&&) noexcept; | ||
}; | ||
|
||
} // namespace floormat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
namespace floormat { | ||
|
||
enum class scenery_type : unsigned char { | ||
none, generic, door, COUNT, | ||
}; | ||
|
||
} // namespace floormat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters