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

+29 -29
View File
@@ -456,7 +456,7 @@ namespace ZL
for (auto& intObj : interactiveObjects) {
//std::cout << "[RAYCAST] Checking object: " << intObj.loadedObject.name << " (active: " << intObj.isActive << ")" << std::endl;
if (!intObj.isActive || intObj.isAnimating) {
if (!intObj.state.isActive || intObj.state.isAnimating) {
//std::cout << "[RAYCAST] -> Object inactive or animating, skipping" << std::endl;
continue;
}
@@ -470,10 +470,10 @@ namespace ZL
//std::cout << "[RAYCAST] Position: (" << intObj.position.x() << ", " << intObj.position.y() << ", "
// << intObj.position.z() << "), Radius: " << intObj.interactionRadius << std::endl;
const bool hasBox = !(intObj.boundsMin.isZero() && intObj.boundsMax.isZero());
const bool hasBox = !(intObj.state.boundsMin.isZero() && intObj.state.boundsMax.isZero());
if (hasBox) {
const Eigen::Vector3f worldMin = intObj.position + intObj.boundsMin;
const Eigen::Vector3f worldMax = intObj.position + intObj.boundsMax;
const Eigen::Vector3f worldMin = intObj.state.position + intObj.state.boundsMin;
const Eigen::Vector3f worldMax = intObj.state.position + intObj.state.boundsMax;
float tMin = 0.1f;
float tMax = FLT_MAX;
bool miss = false;
@@ -498,7 +498,7 @@ namespace ZL
closestObject = &intObj;
}
} else {
Eigen::Vector3f toObject = intObj.position - rayOrigin;
Eigen::Vector3f toObject = intObj.state.position - rayOrigin;
float distanceAlongRay = toObject.dot(rayDir);
@@ -507,9 +507,9 @@ namespace ZL
}
Eigen::Vector3f closestPointOnRay = rayOrigin + rayDir * distanceAlongRay;
float distToObject = (closestPointOnRay - intObj.position).norm();
float distToObject = (closestPointOnRay - intObj.state.position).norm();
if (distToObject <= intObj.interactionRadius && distanceAlongRay < closestDistance) {
if (distToObject <= intObj.state.interactionRadius && distanceAlongRay < closestDistance) {
closestDistance = distanceAlongRay;
closestObject = &intObj;
}
@@ -632,7 +632,7 @@ namespace ZL
}
for (auto& intObj : interactiveObjects) {
if (intObj.isActive) {
if (intObj.state.isActive) {
intObj.draw(renderer);
}
}
@@ -724,9 +724,9 @@ namespace ZL
}
for (auto& intObj : interactiveObjects) {
if (intObj.castShadow && intObj.loadedObject.texture) {
if (intObj.state.castShadow && intObj.loadedObject.texture) {
renderer.PushMatrix();
renderer.TranslateMatrix(intObj.position);
renderer.TranslateMatrix(intObj.state.position);
renderer.DrawVertexRenderStruct(intObj.loadedObject.mesh);
renderer.PopMatrix();
}
@@ -818,7 +818,7 @@ namespace ZL
CheckGlError(__FILE__, __LINE__);
for (auto& intObj : interactiveObjects) {
if (intObj.isActive) {
if (intObj.state.isActive) {
intObj.draw(renderer);
}
}
@@ -911,7 +911,7 @@ namespace ZL
}
for (auto& intObj : interactiveObjects) {
if (intObj.isActive) {
if (intObj.state.isActive) {
intObj.drawDarklands(renderer);
}
}
@@ -971,9 +971,9 @@ namespace ZL
renderer.DrawVertexRenderStruct(gameObj.mesh);
}
for (auto& intObj : interactiveObjects) {
if (intObj.castShadowNight && intObj.loadedObject.texture) {
if (intObj.state.castShadowNight && intObj.loadedObject.texture) {
renderer.PushMatrix();
renderer.TranslateMatrix(intObj.position);
renderer.TranslateMatrix(intObj.state.position);
renderer.DrawVertexRenderStruct(intObj.loadedObject.mesh);
renderer.PopMatrix();
}
@@ -1144,7 +1144,7 @@ namespace ZL
}
for (auto& intObj : interactiveObjects) {
if (intObj.isActive) {
if (intObj.state.isActive) {
intObj.draw(renderer);
}
}
@@ -1492,22 +1492,22 @@ namespace ZL
for (auto& [idx, t] : npcBumpsPlayerCooldown) t -= deltaS;
// Check if player reached target interactive object
if (!tutorialInteractiveObjectsLocked && targetInteractiveObject && player && !targetInteractiveObject->isAnimating) {
const Eigen::Vector3f& approachTarget = targetInteractiveObject->hasInteractionPosition
? targetInteractiveObject->interactionPosition
: targetInteractiveObject->position;
if (!tutorialInteractiveObjectsLocked && targetInteractiveObject && player && !targetInteractiveObject->state.isAnimating) {
const Eigen::Vector3f& approachTarget = targetInteractiveObject->state.hasInteractionPosition
? targetInteractiveObject->state.interactionPosition
: targetInteractiveObject->state.position;
float distToObject = (player->state.position - approachTarget).norm();
// If player is close enough to pick up the item
if (distToObject <= targetInteractiveObject->approachRadius) {
if (distToObject <= targetInteractiveObject->state.approachRadius) {
std::cout << "[PICKUP] Player reached object! Distance: " << distToObject << std::endl;
std::cout << "[PICKUP] Calling Lua callback for: " << targetInteractiveObject->loadedObject.name << std::endl;
// Call custom activate function if specified, otherwise use fallback
try {
if (!targetInteractiveObject->activateFunctionName.empty()) {
std::cout << "[PICKUP] Using custom function: " << targetInteractiveObject->activateFunctionName << std::endl;
scriptEngine.callActivateFunction(targetInteractiveObject->activateFunctionName);
if (!targetInteractiveObject->state.activateFunctionName.empty()) {
std::cout << "[PICKUP] Using custom function: " << targetInteractiveObject->state.activateFunctionName << std::endl;
scriptEngine.callActivateFunction(targetInteractiveObject->state.activateFunctionName);
}
else {
std::cout << "[PICKUP] Using fallback callback" << std::endl;
@@ -1632,19 +1632,19 @@ namespace ZL
// First check if we clicked on interactive object
InteractiveObject* clickedObject = raycastInteractiveObjects(camPos, rayDir);
if (clickedObject && player && clickedObject->isActive) {
if (clickedObject && player && clickedObject->state.isActive) {
std::cout << "[CLICK] *** SUCCESS: Clicked on interactive object: " << clickedObject->loadedObject.name << " ***" << std::endl;
std::cout << "[CLICK] Object position: (" << clickedObject->position.x() << ", "
<< clickedObject->position.y() << ", " << clickedObject->position.z() << ")" << std::endl;
std::cout << "[CLICK] Object position: (" << clickedObject->state.position.x() << ", "
<< clickedObject->state.position.y() << ", " << clickedObject->state.position.z() << ")" << std::endl;
std::cout << "[CLICK] Player position: (" << player->state.position.x() << ", "
<< player->state.position.y() << ", " << player->state.position.z() << ")" << std::endl;
targetInteractiveObject = clickedObject;
targetInteractNpcIndex = -1;
targetTeleportZone = nullptr;
player->setTarget(clickedObject->hasInteractionPosition
? clickedObject->interactionPosition
: clickedObject->position);
player->setTarget(clickedObject->state.hasInteractionPosition
? clickedObject->state.interactionPosition
: clickedObject->state.position);
player->state.attackTargetIndex = CharacterState::kNoTarget;
std::cout << "[CLICK] Player moving to object..." << std::endl;
}