Skip to content

Commit

Permalink
refactor(VObject): finalize migration to compliant archives
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Dec 5, 2023
1 parent 2122d85 commit 987c307
Show file tree
Hide file tree
Showing 41 changed files with 1,420 additions and 1,296 deletions.
2 changes: 2 additions & 0 deletions docs/library/misc/v1.2-to-v1.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ been polished up a bit. This is what you should do:
* `atomic_message` is now `CutsceneMessage`
* `script` is now `DaedalusScript` (other related classes and structs have been prefixed with `Daedalus` too)
* `vm` is now `DaedalusVm` (other related classes and structs have been prefixed with `Daedalus` too)
* All classes in `phoenix::vobs` have been moved into the `zenkit` namespace and prefixed with a `V` (e.g.
`phoenix::vobs::Light` becomes `zenkit::VLight`)
4. Change all enum member accesses from their `snake_case` names to the new `SCREAMING_SNAKE_CASE` names.

The deprecation warnings from your compiler should tell you these changes too. Alternatively, you can look into the old
Expand Down
6 changes: 3 additions & 3 deletions examples/run_interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ int main(int argc, char** argv) {
return true;
});

auto xardas = vm.init_instance<phoenix::c_npc>("NONE_100_XARDAS");
auto hero = vm.init_instance<phoenix::c_npc>("PC_HERO");
auto gold = vm.init_instance<phoenix::c_item>("ITMI_GOLD");
auto xardas = vm.init_instance<zenkit::INpc>("NONE_100_XARDAS");
auto hero = vm.init_instance<zenkit::INpc>("PC_HERO");
auto gold = vm.init_instance<zenkit::IItem>("ITMI_GOLD");

vm.register_external("NPC_ISPLAYER", [&hero](std::shared_ptr<phoenix::c_npc> npc) { return npc->id == hero->id; });

Expand Down
5 changes: 2 additions & 3 deletions include/phoenix/vobs/camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

namespace phoenix {
namespace vobs {
using camera_trj_frame
ZKREM("renamed to zenkit::vobs::CameraTrajectoryFrame") = zenkit::vobs::CameraTrajectoryFrame;
using cs_camera ZKREM("renamed to zenkit::vobs::CutsceneCamera") = zenkit::vobs::CutsceneCamera;
using camera_trj_frame ZKREM("renamed to zenkit::VCameraTrajectoryFrame") = zenkit::VCameraTrajectoryFrame;
using cs_camera ZKREM("renamed to zenkit::VCutsceneCamera") = zenkit::VCutsceneCamera;
} // namespace vobs

using camera_motion ZKREM("renamed to zenkit::CameraMotion") = zenkit::CameraMotion;
Expand Down
4 changes: 2 additions & 2 deletions include/phoenix/vobs/light.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace phoenix {
namespace vobs {
using light_preset ZKREM("renamed to zenkit::vobs::LightPreset") = zenkit::vobs::LightPreset;
using light ZKREM("renamed to zenkit::vobs::Light") = zenkit::vobs::Light;
using light_preset ZKREM("renamed to zenkit::VLightPreset") = zenkit::VLightPreset;
using light ZKREM("renamed to zenkit::VLight") = zenkit::VLight;
} // namespace vobs

using light_mode ZKREM("renamed to zenkit::LightType") = zenkit::LightType;
Expand Down
21 changes: 10 additions & 11 deletions include/phoenix/vobs/misc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@

namespace phoenix {
namespace vobs {
using animate ZKREM("renamed to zenkit::vobs::Animate") = zenkit::vobs::Animate;
using item ZKREM("renamed to zenkit::vobs::Item") = zenkit::vobs::Item;
using lens_flare ZKREM("renamed to zenkit::vobs::LensFlare") = zenkit::vobs::LensFlare;
using pfx_controller
ZKREM("renamed to zenkit::vobs::ParticleEffectController") = zenkit::vobs::ParticleEffectController;
using code_master ZKREM("renamed to zenkit::vobs::CodeMaster") = zenkit::vobs::CodeMaster;
using message_filter ZKREM("renamed to zenkit::vobs::MessageFilter") = zenkit::vobs::MessageFilter;
using mover_controller ZKREM("renamed to zenkit::vobs::MoverController") = zenkit::vobs::MoverController;
using touch_damage ZKREM("renamed to zenkit::vobs::TouchDamage") = zenkit::vobs::TouchDamage;
using earthquake ZKREM("renamed to zenkit::vobs::Earthquake") = zenkit::vobs::Earthquake;
using npc ZKREM("renamed to zenkit::vobs::Npc") = zenkit::vobs::Npc;
using animate ZKREM("renamed to zenkit::VAnimate") = zenkit::VAnimate;
using item ZKREM("renamed to zenkit::VItem") = zenkit::VItem;
using lens_flare ZKREM("renamed to zenkit::VLensFlare") = zenkit::VLensFlare;
using pfx_controller ZKREM("renamed to zenkit::VParticleEffectController") = zenkit::VParticleEffectController;
using code_master ZKREM("renamed to zenkit::VCodeMaster") = zenkit::VCodeMaster;
using message_filter ZKREM("renamed to zenkit::VMessageFilter") = zenkit::VMessageFilter;
using mover_controller ZKREM("renamed to zenkit::VMoverController") = zenkit::VMoverController;
using touch_damage ZKREM("renamed to zenkit::VTouchDamage") = zenkit::VTouchDamage;
using earthquake ZKREM("renamed to zenkit::VEarthquake") = zenkit::VEarthquake;
using npc ZKREM("renamed to zenkit::VNpc") = zenkit::VNpc;
} // namespace vobs

using message_filter_action ZKREM("renamed to zenkit::MessageFilterAction") = zenkit::MessageFilterAction;
Expand Down
10 changes: 5 additions & 5 deletions include/phoenix/vobs/mob.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace phoenix {
namespace vobs {
using mob ZKREM("renamed to zenkit::vobs::MovableObject") = zenkit::vobs::MovableObject;
using mob_inter ZKREM("renamed to zenkit::vobs::InteractiveObject") = zenkit::vobs::InteractiveObject;
using mob_fire ZKREM("renamed to zenkit::vobs::Fire") = zenkit::vobs::Fire;
using mob_container ZKREM("renamed to zenkit::vobs::Container") = zenkit::vobs::Container;
using mob_door ZKREM("renamed to zenkit::vobs::Door") = zenkit::vobs::Door;
using mob ZKREM("renamed to zenkit::VMovableObject") = zenkit::VMovableObject;
using mob_inter ZKREM("renamed to zenkit::VInteractiveObject") = zenkit::VInteractiveObject;
using mob_fire ZKREM("renamed to zenkit::VFire") = zenkit::VFire;
using mob_container ZKREM("renamed to zenkit::VContainer") = zenkit::VContainer;
using mob_door ZKREM("renamed to zenkit::VDoor") = zenkit::VDoor;
} // namespace vobs

using sound_material ZKREM("renamed to zenkit::SoundMaterialType") = zenkit::SoundMaterialType;
Expand Down
4 changes: 2 additions & 2 deletions include/phoenix/vobs/sound.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace phoenix {
namespace vobs {
using sound ZKREM("renamed to zenkit::vobs::Sound") = zenkit::vobs::Sound;
using sound_daytime ZKREM("renamed to zenkit::vobs::SoundDaytime") = zenkit::vobs::SoundDaytime;
using sound ZKREM("renamed to zenkit::VSound") = zenkit::VSound;
using sound_daytime ZKREM("renamed to zenkit::VSoundDaytime") = zenkit::VSoundDaytime;
} // namespace vobs

using sound_mode ZKREM("renamed to zenkit::SoundMode") = zenkit::SoundMode;
Expand Down
15 changes: 7 additions & 8 deletions include/phoenix/vobs/trigger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@

namespace phoenix {
namespace vobs {
using trigger ZKREM("renamed to zenkit::vobs::Trigger") = zenkit::vobs::Trigger;
using trigger_mover ZKREM("renamed to zenkit::vobs::Mover") = zenkit::vobs::Mover;
using trigger_list ZKREM("renamed to zenkit::vobs::TriggerList") = zenkit::vobs::TriggerList;
using trigger_script ZKREM("renamed to zenkit::vobs::TriggerScript") = zenkit::vobs::TriggerScript;
using trigger_change_level
ZKREM("renamed to zenkit::vobs::TriggerChangeLevel") = zenkit::vobs::TriggerChangeLevel;
using trigger_world_start ZKREM("renamed to zenkit::vobs::TriggerWorldStart") = zenkit::vobs::TriggerWorldStart;
using trigger_untouch ZKREM("renamed to zenkit::vobs::TriggerUntouch") = zenkit::vobs::TriggerUntouch;
using trigger ZKREM("renamed to zenkit::VTrigger") = zenkit::VTrigger;
using trigger_mover ZKREM("renamed to zenkit::VMover") = zenkit::VMover;
using trigger_list ZKREM("renamed to zenkit::VTriggerList") = zenkit::VTriggerList;
using trigger_script ZKREM("renamed to zenkit::VTriggerScript") = zenkit::VTriggerScript;
using trigger_change_level ZKREM("renamed to zenkit::VTriggerChangeLevel") = zenkit::VTriggerChangeLevel;
using trigger_world_start ZKREM("renamed to zenkit::VTriggerWorldStart") = zenkit::VTriggerWorldStart;
using trigger_untouch ZKREM("renamed to zenkit::VTriggerUntouch") = zenkit::VTriggerUntouch;
} // namespace vobs

using mover_behavior ZKREM("renamed to zenkit::MoverBehavior") = zenkit::MoverBehavior;
Expand Down
2 changes: 1 addition & 1 deletion include/phoenix/vobs/vob.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "zenkit/vobs/VirtualObject.hh"

namespace phoenix {
using vob_type ZKREM("renamed to zenkit::ObjectType") = zenkit::ObjectType;
using vob_type ZKREM("renamed to zenkit::VirtualObjectType") = zenkit::VirtualObjectType;
using shadow_mode ZKREM("renamed to zenkit::ShadowType") = zenkit::ShadowType;
using visual_type ZKREM("renamed to zenkit::VisualType") = zenkit::VisualType;
using sprite_alignment ZKREM("renamed to zenkit::SpriteAlignment") = zenkit::SpriteAlignment;
Expand Down
6 changes: 3 additions & 3 deletions include/phoenix/vobs/zone.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "zenkit/vobs/Zone.hh"

namespace phoenix::vobs {
using zone_music ZKREM("renamed to zenkit::vobs::ZoneMusic") = zenkit::vobs::ZoneMusic;
using zone_far_plane ZKREM("renamed to zenkit::vobs::ZoneFarPlane") = zenkit::vobs::ZoneFarPlane;
using zone_fog ZKREM("renamed to zenkit::vobs::ZoneFog") = zenkit::vobs::ZoneFog;
using zone_music ZKREM("renamed to zenkit::VZoneMusic") = zenkit::VZoneMusic;
using zone_far_plane ZKREM("renamed to zenkit::VZoneFarPlane") = zenkit::VZoneFarPlane;
using zone_fog ZKREM("renamed to zenkit::VZoneFog") = zenkit::VZoneFog;
} // namespace phoenix::vobs
2 changes: 1 addition & 1 deletion include/zenkit/Archive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ namespace zenkit {
std::enable_if_t<std::is_base_of_v<Object, T>, std::shared_ptr<T>> //
read_object(GameVersion version) {
auto obj = this->read_object(version);
if (obj != nullptr && obj->get_type() != T::TYPE) {
if (obj != nullptr && obj->get_object_type() != T::TYPE) {
throw ParserError {"ReadArchive", "Read unexcected object!"};
}

Expand Down
4 changes: 4 additions & 0 deletions include/zenkit/Boxes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ namespace zenkit {

/// \brief Represents a axis-aligned bounding box (AABB)
struct AxisAlignedBoundingBox {
static constexpr AxisAlignedBoundingBox zero() {
return {glm::vec3 {0}, glm::vec3 {0}};
}

/// \brief The coordinates of the minimum corner of the bounding box.
glm::vec3 min;

Expand Down
13 changes: 12 additions & 1 deletion include/zenkit/Object.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,22 @@ namespace zenkit {
zCSkyControler_Outdoor
};

constexpr bool is_vobject(ObjectType type) {
return type < ObjectType::ignored;
}

#define ZK_OBJECT(s) \
static constexpr ObjectType TYPE = s; \
ObjectType get_object_type() const override { \
return s; \
}

class Object ZKAPI {
public:
Object() = default;
virtual ~Object() noexcept = default;
[[nodiscard]] virtual ObjectType get_type() const = 0;

[[nodiscard]] virtual ObjectType get_object_type() const;

virtual void load(ReadArchive& r, GameVersion version);
};
Expand Down
12 changes: 5 additions & 7 deletions include/zenkit/World.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ namespace phoenix {
}

namespace zenkit {
namespace vobs {
struct Npc;
}
struct VNpc;

struct CutscenePlayer : Object {
static constexpr ObjectType TYPE = ObjectType::oCCSPlayer;
Expand All @@ -28,7 +26,7 @@ namespace zenkit {
int32_t last_process_hour;
int32_t play_list_count;

[[nodiscard]] ObjectType get_type() const override {
[[nodiscard]] ObjectType get_object_type() const override {
return TYPE;
}

Expand All @@ -52,15 +50,15 @@ namespace zenkit {
bool is_raining;
int rain_ctr;

[[nodiscard]] ObjectType get_type() const override {
[[nodiscard]] ObjectType get_object_type() const override {
return TYPE;
}

void load(ReadArchive& r, GameVersion version) override;
};

struct SpawnLocation {
std::shared_ptr<vobs::Npc> npc;
std::shared_ptr<VNpc> npc;
glm::vec3 position;
float timer;
};
Expand Down Expand Up @@ -136,7 +134,7 @@ namespace zenkit {
WayNet world_way_net;

// \note Only available in save-games, otherwise empty.
std::vector<std::shared_ptr<vobs::Npc>> npcs {};
std::vector<std::shared_ptr<VNpc>> npcs {};
std::vector<SpawnLocation> npc_spawns {};
bool npc_spawn_enabled = false;
int npc_spawn_flags = 0;
Expand Down
138 changes: 65 additions & 73 deletions include/zenkit/vobs/Camera.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,77 +67,69 @@ namespace zenkit {
pingpong ZKREM("renamed to CameraLoop::PINGPONG") = PINGPONG,
};

namespace vobs {
/// \brief A VOb which describes the trajectory of a camera during a cutscene.
struct CameraTrajectoryFrame : VirtualObject {
static constexpr ObjectType TYPE = ObjectType::zCCamTrj_KeyFrame;

float time;
float roll_angle;
float fov_scale;
CameraMotion motion_type;
CameraMotion motion_type_fov;
CameraMotion motion_type_roll;
CameraMotion motion_type_time_scale;
float tension;
float cam_bias;
float continuity;
float time_scale;
bool time_fixed;
glm::mat4 original_pose;

/// \brief Parses a camera trajectory VOb the given *ZenGin* archive.
/// \param[out] obj The object to read.
/// \param[in,out] ctx The archive reader to read from.
/// \note After this function returns the position of \p ctx will be at the end of the parsed object.
/// \throws ParserError if parsing fails.
/// \see vob::parse
ZKREM("use ::load()")
ZKAPI static std::unique_ptr<CameraTrajectoryFrame> parse(ReadArchive& ctx, GameVersion version);

[[nodiscard]] ObjectType get_type() const override {
return TYPE;
}

ZKAPI void load(ReadArchive& r, GameVersion version) override;
};

/// \brief A VOb which defined the movement of the camera during a cutscene.
struct CutsceneCamera : VirtualObject {
CameraTrajectory trajectory_for;
CameraTrajectory target_trajectory_for;
CameraLoop loop_mode;
CameraLerpType lerp_mode;
bool ignore_for_vob_rotation;
bool ignore_for_vob_rotation_target;
bool adapt;
bool ease_first;
bool ease_last;
float total_duration;
std::string auto_focus_vob;
bool auto_player_movable;
bool auto_untrigger_last;
float auto_untrigger_last_delay;
std::int32_t position_count;
std::int32_t target_count;

std::vector<std::shared_ptr<CameraTrajectoryFrame>> frames;

// Save-game only variables
bool s_paused {false};
bool s_started {false};
bool s_goto_time_mode {false};
float s_cs_time {0};

/// \brief Parses a cutscene camera VOb the given *ZenGin* archive.
/// \param[out] obj The object to read.
/// \param[in,out] ctx The archive reader to read from.
/// \note After this function returns the position of \p ctx will be at the end of the parsed object.
/// \throws ParserError if parsing fails.
/// \see vob::parse
ZKREM("use ::load()") ZKAPI static void parse(CutsceneCamera& obj, ReadArchive& ctx, GameVersion version);

ZKAPI void load(ReadArchive& r, GameVersion version) override;
};
} // namespace vobs
/// \brief A VOb which describes the trajectory of a camera during a cutscene.
struct VCameraTrajectoryFrame : VirtualObject {
ZK_OBJECT(ObjectType::zCCamTrj_KeyFrame);

public:
float time;
float roll_angle;
float fov_scale;
CameraMotion motion_type;
CameraMotion motion_type_fov;
CameraMotion motion_type_roll;
CameraMotion motion_type_time_scale;
float tension;
float cam_bias;
float continuity;
float time_scale;
bool time_fixed;
glm::mat4 original_pose;

/// \brief Parses a camera trajectory VOb the given *ZenGin* archive.
/// \param[out] obj The object to read.
/// \param[in,out] ctx The archive reader to read from.
/// \note After this function returns the position of \p ctx will be at the end of the parsed object.
/// \throws ParserError if parsing fails.
/// \see vob::parse
ZKREM("use ::load()")
ZKAPI static std::unique_ptr<VCameraTrajectoryFrame> parse(ReadArchive& ctx, GameVersion version);

ZKAPI void load(ReadArchive& r, GameVersion version) override;
};

/// \brief A VOb which defined the movement of the camera during a cutscene.
struct VCutsceneCamera : VirtualObject {
ZK_OBJECT(ObjectType::zCCSCamera);

public:
CameraTrajectory trajectory_for;
CameraTrajectory target_trajectory_for;
CameraLoop loop_mode;
CameraLerpType lerp_mode;
bool ignore_for_vob_rotation;
bool ignore_for_vob_rotation_target;
bool adapt;
bool ease_first;
bool ease_last;
float total_duration;
std::string auto_focus_vob;
bool auto_player_movable;
bool auto_untrigger_last;
float auto_untrigger_last_delay;
std::int32_t position_count;
std::int32_t target_count;

std::vector<std::shared_ptr<VCameraTrajectoryFrame>> frames;

// Save-game only variables
bool paused {false};
bool started {false};
bool goto_time_mode {false};
float cs_time {0};

ZKREM("use ::load()") ZKAPI static void parse(VCutsceneCamera& obj, ReadArchive& ctx, GameVersion version);

ZKAPI void load(ReadArchive& r, GameVersion version) override;
};
} // namespace zenkit
Loading

0 comments on commit 987c307

Please sign in to comment.