Skip to content

Commit

Permalink
fix(Archive): add missing includes and remove reinterpret_pointer_cast
Browse files Browse the repository at this point in the history
... since the NDK does not seem to support it :(
  • Loading branch information
lmichaelis committed Dec 5, 2023
1 parent fed97b0 commit fd58eef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion include/zenkit/Archive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <memory>
#include <string>
#include <unordered_map>
#include <variant>

namespace phoenix {
Expand Down Expand Up @@ -153,7 +154,8 @@ namespace zenkit {
throw ParserError {"ReadArchive", "Read unexcected object!"};
}

return std::reinterpret_pointer_cast<T>(std::move(obj));
// NOTE(lmichaelis): The NDK does not seem to support `reinterpret_pointer_cast`.
return std::shared_ptr<T>(obj, reinterpret_cast<T*>(obj.get()));
}

std::shared_ptr<Object> read_object(GameVersion version);
Expand Down
12 changes: 8 additions & 4 deletions src/vobs/VirtualObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ namespace zenkit {
this->visual->type = it->second;

if (this->visual->type == VisualType::DECAL) {
this->visual_decal.emplace(*std::reinterpret_pointer_cast<VisualDecal>(this->visual));
this->visual_decal.emplace(*reinterpret_cast<VisualDecal*>(this->visual.get()));
}
}
}

if (has_ai_object) {
this->ai = std::reinterpret_pointer_cast<Ai>(r.read_object(version));
// NOTE(lmichaelis): The NDK does not seem to support `reinterpret_pointer_cast`.
auto obj = r.read_object(version);
this->ai = std::shared_ptr<Ai>(obj, reinterpret_cast<Ai*>(obj.get()));
}

if (has_event_manager_object) {
Expand Down Expand Up @@ -211,7 +213,9 @@ namespace zenkit {
}

void AiMove::load(ReadArchive& r, GameVersion version) {
vob = std::reinterpret_pointer_cast<VirtualObject>(r.read_object(version)); // vob
owner = r.read_object<VNpc>(version); // owner
// NOTE(lmichaelis): The NDK does not seem to support `reinterpret_pointer_cast`.
auto obj = r.read_object(version);
vob = std::shared_ptr<VirtualObject>(obj, reinterpret_cast<VirtualObject*>(obj.get())); // vob
owner = r.read_object<VNpc>(version); // owner
}
} // namespace zenkit
3 changes: 2 additions & 1 deletion src/world/VobTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace zenkit {
auto obj = in.read_object(version);
if (!is_vobject(obj->get_object_type())) return nullptr;

auto object = std::reinterpret_pointer_cast<VirtualObject>(obj);
// NOTE(lmichaelis): The NDK does not seem to support `reinterpret_pointer_cast`.
std::shared_ptr<VirtualObject> object {obj, reinterpret_cast<VirtualObject*>(obj.get())};

auto child_count = static_cast<size_t>(in.read_int());
if (object == nullptr) {
Expand Down

0 comments on commit fd58eef

Please sign in to comment.