Working on game states

This commit is contained in:
Vladislav Khorev committed 2026-06-18 20:51:44 +03:00
1 parent 0ca00f965d
commit e0968b5522
10 files changed
+340 -251

No files matched your search

+11 -43
View File
@@ -6,62 +6,30 @@
#include <cstdint>
#include <Eigen/Core>
#include "render/Renderer.h"
#include "InteractiveObjectState.h"
namespace ZL {
class Renderer;
struct LoadedGameObject {
std::string name; // identity key — stays at top level
LoadedGameObjectState creationInfo; // paths + transforms for save/recreate
std::shared_ptr<Texture> texture;
std::shared_ptr<Texture> textureDarklands;
VertexRenderStruct mesh;
std::string name;
// Source paths and baked transform — populated by GameObjectLoader, used for serialization.
std::string texturePath;
std::string textureDarkandsPath;
std::string meshPath;
float meshRotationX = 0.f, meshRotationY = 0.f, meshRotationZ = 0.f;
float meshScale = 1.f;
};
struct InteractiveObject {
LoadedGameObject loadedObject; // name, texture, mesh
Eigen::Vector3f position;
Eigen::Vector3f pivot = Eigen::Vector3f::Zero(); // local-space offset to rotation pivot
float rotationY = 0.0f; // Y-axis rotation in radians
float scale = 1.0f; // uniform scale
float alpha = 1.0f; // opacity: 1=opaque, 0=fully transparent
float interactionRadius;
float approachRadius = 2.0f;
Eigen::Vector3f boundsMin = Eigen::Vector3f::Zero();
Eigen::Vector3f boundsMax = Eigen::Vector3f::Zero();
Eigen::Vector3f interactionPosition = Eigen::Vector3f::Zero();
// Original JSON position before mesh-centering offset applied at load time — needed for serialization.
float jsonPositionX = 0.f, jsonPositionY = 0.f, jsonPositionZ = 0.f;
LoadedGameObject loadedObject; // rendering assets
InteractiveObjectState state; // all mutable + creation state
bool hasInteractionPosition = false;
bool isActive = true;
bool isAnimating = false; // true while a timed animation is running
bool castShadow = true; // included in day shadow depth pass regardless of isActive
bool castShadowNight = true; // included in night shadow depth pass regardless of isActive
std::string activateFunctionName;
struct AnimTask {
enum class Type { Move, Rotate, Scale, Fade } type;
Eigen::Vector3f startPos;
float startRotY;
float startScale;
Eigen::Vector3f targetPos;
float targetRotY;
float targetScale;
float durationMs;
float elapsedMs = 0.f;
std::function<void()> onComplete;
};
std::optional<AnimTask> animTask;
InteractiveObject() : interactionRadius(2.0f) {}
// Factory: creates a fully-loaded InteractiveObject from a state descriptor.
// Loads textures and mesh from state.objectInfo, computes mesh centering,
// and sets state.position = jsonPosition + meshCenter.
static InteractiveObject createFromState(InteractiveObjectState st,
Renderer& renderer,
const std::string& zipPath = "");
void moveTo(const Eigen::Vector3f& target, float durationSec, std::function<void()> onComplete = {});
void rotateTo(float targetRotY, float durationSec, std::function<void()> onComplete = {});