Working on state for location

This commit is contained in:
Vladislav Khorev committed 2026-06-18 21:48:27 +03:00
1 parent e0968b5522
commit b01e970554
13 files changed
+494 -101

No files matched your search

+21 -23
View File
@@ -1,4 +1,4 @@
#pragma once
#pragma once
#include "render/Renderer.h"
#include "Environment.h"
@@ -14,6 +14,7 @@
#include "SparkEmitter.h"
#include "TeleportZone.h"
#include "LocationEditor.h"
#include "LocationState.h"
#include <functional>
#include <cstdint>
#include <unordered_map>
@@ -42,7 +43,7 @@ namespace ZL
float radius = 1.5f;
float hysteresis = 0.3f; // exit fires at radius + hysteresis to prevent flickering
bool enabled = true;
bool playerInside = false; // runtime tracking state, not serialized
bool playerInside = false; // runtime tracking state, not serialized (mirrored in LocationState)
};
struct LocationSetup
@@ -64,6 +65,9 @@ namespace ZL
public:
Location(Renderer& iRenderer, Inventory& iInventory);
// ---- All serialisable runtime state ----
LocationState state;
std::unordered_map<std::string, LoadedGameObject> gameObjects;
std::vector<InteractiveObject> interactiveObjects;
@@ -71,21 +75,11 @@ namespace ZL
std::unique_ptr<Character> player;
std::vector<std::unique_ptr<Character>> npcs;
float cameraAzimuth = -2.35;
float cameraInclination = 1.1036;//M_PI * 30.f / 180.f;
std::vector<PathFinder> navigationMaps;
PathFinder* navigation = nullptr;
int activeNavigationIndex = 0;
std::unique_ptr<ShadowMap> shadowMap;
Eigen::Matrix4f cameraViewMatrix = Eigen::Matrix4f::Identity();
InteractiveObject* targetInteractiveObject = nullptr;
// "Walk to NPC, then fire on_npc_interact" — mirrors targetInteractiveObject
// so a click from outside interactionRadius still leads to a Lua callback
// once the player gets close enough.
int targetInteractNpcIndex = -1;
std::unique_ptr<TextRenderer> npcNameText;
@@ -93,21 +87,12 @@ namespace ZL
Dialogue::DialogueSystem dialogueSystem;
std::vector<TeleportZone> teleportZones;
TeleportZone* targetTeleportZone = nullptr;
std::function<void(const std::string&, const Eigen::Vector3f&, float)> onTeleport;
std::vector<TriggerZone> triggerZones;
std::vector<PointLight> pointLights;
// Set by Game and kept in sync across location transitions.
// Read by draw functions and raycast — do not write from Location code.
bool isDarklands = false;
bool isNight = false;
bool isDawn = false;
bool tutorialInteractiveObjectsLocked = false;
// Called when the player successfully taps the ground and a floor walk target is set.
// Used by the tutorial system to detect the "tap to walk" gesture.
std::function<void()> onPlayerFloorWalk;
@@ -119,7 +104,7 @@ namespace ZL
std::function<bool()> requestDarklandsTransition;
std::function<void(bool, bool)> requestNightDayTransition;
// Set by Game after setup(). Lua calls this to advance the uni_interior HUD
// from step12 to step13 (trigger-zone encounter hint).
std::function<void()> requestAdvanceDarklandsHud;
@@ -146,7 +131,7 @@ namespace ZL
bool switchNavigation(int index);
InteractiveObject* raycastInteractiveObjects(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir);
Character* raycastNpcs(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir, float maxDistance = 100.0f);
void drawGame();
void drawShadowDepthPass();
void drawGameWithShadows();
@@ -168,12 +153,25 @@ namespace ZL
void setDialogueFlag(const std::string& flag, int value);
int getDialogueFlag(const std::string& flag) const;
// ---- Save / Load ----
// Serialises LocationState + all Character/InteractiveObject sub-states + Lua globals.
void saveFullState(nlohmann::json& out) const;
// Restores state from JSON written by saveFullState.
// Navigation pointer and triggerZone.playerInside are re-synced automatically.
void loadFullState(const nlohmann::json& in);
protected:
friend class LocationEditor;
Renderer& renderer;
Inventory& inventory;
private:
// ---- Pointer-to-index helpers ----
InteractiveObject* getTargetInteractiveObject();
TeleportZone* getTargetTeleportZone();
int findInteractiveObjectIndex(const InteractiveObject* obj) const;
int findTeleportZoneIndex(const TeleportZone* tz) const;
void resolveCharacterCollisions();
void updateDynamicReplans(int64_t deltaMs);
void loadTeleportZones(const std::string& jsonPath, const char* zipFile);