Major refactoring
This commit is contained in:
parent
92ba3f2b60
commit
a1dda3fd50
@ -33,12 +33,11 @@ end
|
||||
|
||||
function on_npc_interact(npc_index)
|
||||
print("[Lua] NPC interaction! Index: " .. tostring(npc_index))
|
||||
--[[
|
||||
if npc_index == 1 then
|
||||
game_api.start_dialogue("test_line_dialogue")
|
||||
else
|
||||
game_api.receive_npc_gift(npc_index)
|
||||
end]]
|
||||
end
|
||||
end
|
||||
|
||||
print("Lua script loaded successfully!")
|
||||
@ -758,64 +758,7 @@ namespace ZL
|
||||
|
||||
prepared = true;
|
||||
}
|
||||
/*
|
||||
void BoneSystem::ComputeSkinningMatrices(int frame, std::vector<Matrix4f>& outMatrices) const
|
||||
{
|
||||
int startingKeyFrame = -1;
|
||||
for (size_t i = 0; i < animations[0].keyFrames.size() - 1; i++)
|
||||
{
|
||||
int oldFrame = animations[0].keyFrames[i].frame;
|
||||
int nextFrame = animations[0].keyFrames[i + 1].frame;
|
||||
if (frame >= oldFrame && frame < nextFrame)
|
||||
{
|
||||
startingKeyFrame = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (startingKeyFrame == -1)
|
||||
{
|
||||
outMatrices.resize(startBones.size());
|
||||
for (auto& m : outMatrices) m = Matrix4f::Identity();
|
||||
return;
|
||||
}
|
||||
|
||||
int modifiedFrameNumber = frame - animations[0].keyFrames[startingKeyFrame].frame;
|
||||
int diffFrames = animations[0].keyFrames[startingKeyFrame + 1].frame - animations[0].keyFrames[startingKeyFrame].frame;
|
||||
float t = (modifiedFrameNumber + 0.f) / diffFrames;
|
||||
|
||||
const std::vector<Bone>& oneFrameBones = animations[0].keyFrames[startingKeyFrame].bones;
|
||||
const std::vector<Bone>& nextFrameBones = animations[0].keyFrames[startingKeyFrame + 1].bones;
|
||||
|
||||
outMatrices.resize(startBones.size());
|
||||
|
||||
for (size_t i = 0; i < startBones.size(); i++)
|
||||
{
|
||||
Vector3f interpPos;
|
||||
interpPos(0) = oneFrameBones[i].boneStartWorld(0) + t * (nextFrameBones[i].boneStartWorld(0) - oneFrameBones[i].boneStartWorld(0));
|
||||
interpPos(1) = oneFrameBones[i].boneStartWorld(1) + t * (nextFrameBones[i].boneStartWorld(1) - oneFrameBones[i].boneStartWorld(1));
|
||||
interpPos(2) = oneFrameBones[i].boneStartWorld(2) + t * (nextFrameBones[i].boneStartWorld(2) - oneFrameBones[i].boneStartWorld(2));
|
||||
|
||||
Matrix3f oneFrameBonesMatrix = oneFrameBones[i].boneMatrixWorld.block<3, 3>(0, 0);
|
||||
Matrix3f nextFrameBonesMatrix = nextFrameBones[i].boneMatrixWorld.block<3, 3>(0, 0);
|
||||
|
||||
Eigen::Quaternionf q1 = Eigen::Quaternionf(oneFrameBonesMatrix).normalized();
|
||||
Eigen::Quaternionf q2 = Eigen::Quaternionf(nextFrameBonesMatrix).normalized();
|
||||
Eigen::Quaternionf result = q1.slerp(t, q2);
|
||||
|
||||
Matrix3f boneMatrixWorld3 = result.toRotationMatrix();
|
||||
|
||||
Matrix4f currentBoneMatrixWorld4 = Eigen::Matrix4f::Identity();
|
||||
currentBoneMatrixWorld4.block<3, 3>(0, 0) = boneMatrixWorld3;
|
||||
currentBoneMatrixWorld4.block<3, 1>(0, 3) = interpPos;
|
||||
|
||||
Matrix4f startBoneMatrixWorld4 = animations[0].keyFrames[0].bones[i].boneMatrixWorld;
|
||||
Matrix4f invertedStartBoneMatrixWorld4 = startBoneMatrixWorld4.inverse();
|
||||
|
||||
outMatrices[i] = currentBoneMatrixWorld4 * invertedStartBoneMatrixWorld4;
|
||||
}
|
||||
}
|
||||
*/
|
||||
void BoneSystem::Interpolate(int frame)
|
||||
{
|
||||
int startingFrame = -1;
|
||||
|
||||
343
src/Game.cpp
343
src/Game.cpp
@ -165,20 +165,6 @@ namespace ZL
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
dialogueSystem.init(renderer, CONST_ZIP_FILE);
|
||||
dialogueSystem.loadDatabase("resources/dialogue/sample_dialogues.json");
|
||||
/*dialogueSystem.addTriggerZone({
|
||||
"ghost_room_trigger",
|
||||
"test_line_dialogue",
|
||||
Eigen::Vector3f(0.0f, 0.0f, -8.5f),
|
||||
2.0f,
|
||||
true,
|
||||
false
|
||||
});*/
|
||||
|
||||
|
||||
std::cout << "Load resurces step 13" << std::endl;
|
||||
|
||||
// Load UI with inventory button
|
||||
@ -239,7 +225,10 @@ namespace ZL
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
menuManager.uiManager.draw(renderer);
|
||||
dialogueSystem.draw(renderer);
|
||||
if (currentLocation)
|
||||
{
|
||||
currentLocation->dialogueSystem.draw(renderer);
|
||||
}
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
renderer.shaderManager.PopShader();
|
||||
@ -249,214 +238,6 @@ namespace ZL
|
||||
|
||||
CheckGlError();
|
||||
}
|
||||
/*
|
||||
void Game::drawGame()
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
|
||||
renderer.shaderManager.PushShader(defaultShaderName);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
|
||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||
renderer.PushMatrix();
|
||||
|
||||
renderer.LoadIdentity();
|
||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||
//renderer.TranslateMatrix({ 0, -6.f, 0 });
|
||||
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraInclination, Eigen::Vector3f::UnitX())).toRotationMatrix());
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
|
||||
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, roomTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(roomMesh);
|
||||
|
||||
for (auto& [name, gameObj] : gameObjects) {
|
||||
glBindTexture(GL_TEXTURE_2D, gameObj.texture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(gameObj.mesh);
|
||||
}
|
||||
|
||||
for (auto& intObj : interactiveObjects) {
|
||||
if (intObj.isActive) {
|
||||
intObj.draw(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
if (player) player->draw(renderer);
|
||||
for (auto& npc : npcs) npc->draw(renderer);
|
||||
|
||||
#ifdef SHOW_PATH
|
||||
drawDebugNavigation();
|
||||
#endif
|
||||
|
||||
renderer.PopMatrix();
|
||||
|
||||
renderer.PopProjectionMatrix();
|
||||
|
||||
renderer.shaderManager.PopShader();
|
||||
|
||||
}
|
||||
|
||||
void Game::drawShadowDepthPass()
|
||||
{
|
||||
if (!shadowMap) return;
|
||||
|
||||
const Eigen::Vector3f& sceneCenter = player ? player->position : Eigen::Vector3f::Zero();
|
||||
shadowMap->updateLightSpaceMatrix(sceneCenter);
|
||||
|
||||
shadowMap->bind();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
// Use front-face culling during depth pass to reduce shadow acne on lit faces
|
||||
//glCullFace(GL_FRONT);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
renderer.shaderManager.PushShader("shadow_depth");
|
||||
|
||||
// Set up light's orthographic projection
|
||||
const Eigen::Matrix4f& lightProj = shadowMap->getLightProjectionMatrix();
|
||||
const Eigen::Matrix4f& lightView = shadowMap->getLightViewMatrix();
|
||||
|
||||
// Push the light's projection matrix via the 6-param ortho overload won't
|
||||
// match our pre-computed matrix. Instead, use the raw stack approach:
|
||||
// push a dummy projection then overwrite via PushSpecialMatrix-style.
|
||||
// Simpler: push ortho then push the light view as modelview.
|
||||
renderer.PushProjectionMatrix(
|
||||
-40.0f, 40.0f,
|
||||
-40.0f, 40.0f,
|
||||
0.1f, 100.0f);
|
||||
|
||||
const Eigen::Vector3f& lightDir = shadowMap->getLightDirection();
|
||||
Eigen::Vector3f lightPos = sceneCenter - lightDir * 50.0f;
|
||||
Eigen::Vector3f up(0.0f, 1.0f, 0.0f);
|
||||
if (std::abs(lightDir.dot(up)) > 0.99f) {
|
||||
up = Eigen::Vector3f(0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
// Build the light view matrix and push it
|
||||
renderer.PushSpecialMatrix(lightView);
|
||||
|
||||
// Draw static geometry
|
||||
renderer.DrawVertexRenderStruct(roomMesh);
|
||||
|
||||
for (auto& [name, gameObj] : gameObjects) {
|
||||
renderer.DrawVertexRenderStruct(gameObj.mesh);
|
||||
}
|
||||
|
||||
for (auto& intObj : interactiveObjects) {
|
||||
if (intObj.isActive && intObj.texture) {
|
||||
renderer.PushMatrix();
|
||||
renderer.TranslateMatrix(intObj.position);
|
||||
renderer.DrawVertexRenderStruct(intObj.mesh);
|
||||
renderer.PopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
// Draw characters (they handle their own skinning shader switch internally)
|
||||
if (player) player->drawShadowDepth(renderer);
|
||||
for (auto& npc : npcs) npc->drawShadowDepth(renderer);
|
||||
|
||||
renderer.PopMatrix(); // light view
|
||||
renderer.PopProjectionMatrix();
|
||||
renderer.shaderManager.PopShader();
|
||||
|
||||
//glCullFace(GL_BACK);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
shadowMap->unbind();
|
||||
}
|
||||
|
||||
void Game::drawGameWithShadows()
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
#ifdef DEBUG_LIGHT
|
||||
// Debug mode: render from the light's point of view using the plain
|
||||
// textured shader so we can see what the shadow map "sees".
|
||||
renderer.shaderManager.PushShader(defaultShaderName);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
|
||||
renderer.PushProjectionMatrix(
|
||||
-40.0f, 40.0f,
|
||||
-40.0f, 40.0f,
|
||||
0.1f, 1000.0f);
|
||||
|
||||
renderer.PushSpecialMatrix(shadowMap->getLightViewMatrix());
|
||||
|
||||
#else
|
||||
static const std::string shadowShaderName = "default_shadow";
|
||||
|
||||
renderer.shaderManager.PushShader(shadowShaderName);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
renderer.RenderUniform1i("uShadowMap", 1);
|
||||
|
||||
// Bind shadow map texture to unit 1
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, shadowMap->getDepthTexture());
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 1.5,
|
||||
static_cast<float>(Environment::width) / static_cast<float>(Environment::height),
|
||||
Environment::CONST_Z_NEAR, Environment::CONST_Z_FAR);
|
||||
renderer.PushMatrix();
|
||||
|
||||
renderer.LoadIdentity();
|
||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraInclination, Eigen::Vector3f::UnitX())).toRotationMatrix());
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
|
||||
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
|
||||
|
||||
// Capture the camera view matrix and compute uLightFromCamera
|
||||
cameraViewMatrix = renderer.GetCurrentModelViewMatrix();
|
||||
Eigen::Matrix4f cameraViewInverse = cameraViewMatrix.inverse();
|
||||
Eigen::Matrix4f lightFromCamera = shadowMap->getLightSpaceMatrix() * cameraViewInverse;
|
||||
renderer.RenderUniformMatrix4fv("uLightFromCamera", false, lightFromCamera.data());
|
||||
|
||||
// Light direction in camera space for diffuse lighting
|
||||
Eigen::Vector3f lightDirCamera = cameraViewMatrix.block<3,3>(0,0) * shadowMap->getLightDirection();
|
||||
renderer.RenderUniform3fv("uLightDir", lightDirCamera.data());
|
||||
#endif
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, roomTexture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(roomMesh);
|
||||
|
||||
for (auto& [name, gameObj] : gameObjects) {
|
||||
glBindTexture(GL_TEXTURE_2D, gameObj.texture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(gameObj.mesh);
|
||||
}
|
||||
|
||||
for (auto& intObj : interactiveObjects) {
|
||||
if (intObj.isActive) {
|
||||
intObj.draw(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_LIGHT
|
||||
// In debug-light mode characters use the plain shaders (draw normally
|
||||
// but from the light's viewpoint — projection/view already on stack).
|
||||
if (player) player->draw(renderer);
|
||||
for (auto& npc : npcs) npc->draw(renderer);
|
||||
#else
|
||||
// Characters use their own shadow-aware shaders
|
||||
if (player) player->drawWithShadow(renderer, lightFromCamera, shadowMap->getDepthTexture(), lightDirCamera);
|
||||
for (auto& npc : npcs) npc->drawWithShadow(renderer, lightFromCamera, shadowMap->getDepthTexture(), lightDirCamera);
|
||||
#endif
|
||||
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
renderer.shaderManager.PopShader();
|
||||
}
|
||||
*/
|
||||
|
||||
void Game::drawScene() {
|
||||
glViewport(0, 0, Environment::width, Environment::height);
|
||||
@ -464,13 +245,21 @@ namespace ZL
|
||||
drawLoading();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentLocation)
|
||||
{
|
||||
if (currentLocation->shadowMap) {
|
||||
currentLocation->drawShadowDepthPass();
|
||||
currentLocation->drawGameWithShadows();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
currentLocation->drawGame();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ??? Main menu???
|
||||
}
|
||||
drawUI();
|
||||
}
|
||||
CheckGlError();
|
||||
@ -534,49 +323,6 @@ namespace ZL
|
||||
if (currentLocation)
|
||||
{
|
||||
currentLocation->update(delta);
|
||||
|
||||
if (currentLocation->player) {
|
||||
dialogueSystem.update(static_cast<int>(delta), currentLocation->player->position);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if (player) {
|
||||
player->update(delta);
|
||||
dialogueSystem.update(static_cast<int>(delta), player->position);
|
||||
}
|
||||
for (auto& npc : npcs) npc->update(delta);
|
||||
|
||||
|
||||
|
||||
// Check if player reached target interactive object
|
||||
if (targetInteractiveObject && player) {
|
||||
float distToObject = (player->position - targetInteractiveObject->position).norm();
|
||||
|
||||
// If player is close enough to pick up the item
|
||||
if (distToObject <= targetInteractiveObject->interactionRadius + 1.0f) {
|
||||
std::cout << "[PICKUP] Player reached object! Distance: " << distToObject << std::endl;
|
||||
std::cout << "[PICKUP] Calling Lua callback for: " << targetInteractiveObject->id << 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);
|
||||
}
|
||||
else {
|
||||
std::cout << "[PICKUP] Using fallback callback" << std::endl;
|
||||
scriptEngine.callItemPickupCallback(targetInteractiveObject->id);
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "[PICKUP] Error calling function: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
targetInteractiveObject = nullptr;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
@ -671,15 +417,9 @@ namespace ZL
|
||||
continue;
|
||||
}
|
||||
|
||||
// Calculate ray for picking
|
||||
if (dialogueSystem.blocksGameplayInput()) {
|
||||
dialogueSystem.handlePointerReleased(static_cast<float>(mx), Environment::projectionHeight - static_cast<float>(my));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentLocation)
|
||||
{
|
||||
currentLocation->handleDown(ZL::UiManager::MOUSE_FINGER_ID, event.button.x, event.button.y);
|
||||
currentLocation->handleDown(ZL::UiManager::MOUSE_FINGER_ID, event.button.x, event.button.y, mx, my);
|
||||
}
|
||||
///.....
|
||||
} else {
|
||||
@ -732,36 +472,24 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type == SDL_KEYDOWN && dialogueSystem.handleKeyDown(event.key.keysym.sym)) {
|
||||
if (event.type == SDL_KEYDOWN/* && dialogueSystem.handleKeyDown(event.key.keysym.sym)*/) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event.type == SDL_KEYDOWN && event.key.repeat == 0) {
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_f:
|
||||
dialogueSystem.startDialogue("test_cutscene_pan_dialogue_silent");
|
||||
currentLocation->dialogueSystem.startDialogue("test_cutscene_pan_dialogue_silent");
|
||||
break;
|
||||
|
||||
case SDLK_e:
|
||||
dialogueSystem.startDialogue("test_cutscene_pan_dialogue");
|
||||
currentLocation->dialogueSystem.startDialogue("test_cutscene_pan_dialogue");
|
||||
break;
|
||||
|
||||
case SDLK_p:
|
||||
/*if (player->battle_state == 0)
|
||||
{
|
||||
player->battle_state = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
player->battle_state = 0;
|
||||
}*/
|
||||
break;
|
||||
|
||||
case SDLK_l:
|
||||
/*if (player->attack == 0)
|
||||
{
|
||||
player->attack = 1;
|
||||
}*/
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
|
||||
@ -791,21 +519,7 @@ namespace ZL
|
||||
}
|
||||
|
||||
if (event.type == SDL_KEYUP) {
|
||||
/*benchMesh.data.Move({-x, -y, 0});
|
||||
if (event.key.keysym.sym == SDLK_a) {
|
||||
x = x - 0.1;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_d) {
|
||||
x = x + 0.1;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_w) {
|
||||
y = y - 0.1;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_s) {
|
||||
y = y + 0.1;
|
||||
}
|
||||
benchMesh.data.Move({ x, y, 0 });
|
||||
benchMesh.RefreshVBO();*/
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -850,25 +564,4 @@ namespace ZL
|
||||
|
||||
}
|
||||
|
||||
bool Game::requestDialogueStart(const std::string& dialogueId)
|
||||
{
|
||||
return dialogueSystem.startDialogue(dialogueId);
|
||||
}
|
||||
|
||||
void Game::setDialogueFlag(const std::string& flag, int value)
|
||||
{
|
||||
dialogueSystem.setFlag(flag, value);
|
||||
}
|
||||
|
||||
int Game::getDialogueFlag(const std::string& flag) const
|
||||
{
|
||||
return dialogueSystem.getFlag(flag);
|
||||
}
|
||||
|
||||
bool Game::setNavigationAreaAvailable(const std::string& areaName, bool available)
|
||||
{
|
||||
return currentLocation->setNavigationAreaAvailable(areaName, available);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ZL
|
||||
|
||||
56
src/Game.h
56
src/Game.h
@ -17,11 +17,7 @@
|
||||
#include <cstdint>
|
||||
#include <render/TextRenderer.h>
|
||||
#include "MenuManager.h"
|
||||
#include "ScriptEngine.h"
|
||||
#include <unordered_map>
|
||||
#include "dialogue/DialogueSystem.h"
|
||||
//#include "render/ShadowMap.h"
|
||||
//#include "navigation/PathFinder.h"
|
||||
#include <unordered_set>
|
||||
#include "Location.h"
|
||||
|
||||
@ -38,16 +34,10 @@ namespace ZL {
|
||||
void render();
|
||||
|
||||
bool shouldExit() const { return Environment::exitGameLoop; }
|
||||
bool requestDialogueStart(const std::string& dialogueId);
|
||||
void setDialogueFlag(const std::string& flag, int value);
|
||||
int getDialogueFlag(const std::string& flag) const;
|
||||
bool setNavigationAreaAvailable(const std::string& areaName, bool available);
|
||||
|
||||
Renderer renderer;
|
||||
TaskManager taskManager;
|
||||
MainThreadHandler mainThreadHandler;
|
||||
//std::unique_ptr<INetworkClient> networkClient;
|
||||
|
||||
|
||||
std::shared_ptr<Texture> loadingTexture;
|
||||
VertexRenderStruct loadingMesh;
|
||||
@ -55,64 +45,28 @@ namespace ZL {
|
||||
|
||||
std::shared_ptr<Location> currentLocation;
|
||||
|
||||
/*
|
||||
std::shared_ptr<Texture> roomTexture;
|
||||
VertexRenderStruct roomMesh;
|
||||
|
||||
std::unordered_map<std::string, LoadedGameObject> gameObjects;
|
||||
|
||||
std::vector<InteractiveObject> interactiveObjects;*/
|
||||
Inventory inventory;
|
||||
InteractiveObject* pickedUpObject = nullptr;
|
||||
|
||||
// Interactive object targeting
|
||||
//InteractiveObject* targetInteractiveObject = nullptr;
|
||||
bool inventoryOpen = false;
|
||||
|
||||
/*
|
||||
std::unique_ptr<Character> player;
|
||||
std::vector<std::unique_ptr<Character>> npcs;
|
||||
|
||||
float cameraAzimuth = 0.0f;
|
||||
float cameraInclination = M_PI * 30.f / 180.f;
|
||||
*/
|
||||
// Public access for ScriptEngine
|
||||
MenuManager menuManager;
|
||||
|
||||
/*
|
||||
PathFinder navigation;
|
||||
|
||||
#ifdef SHOW_PATH
|
||||
std::vector<VertexRenderStruct> debugNavMeshes;
|
||||
#endif
|
||||
*/
|
||||
private:
|
||||
bool rightMouseDown = false;
|
||||
int lastMouseX = 0;
|
||||
int lastMouseY = 0;
|
||||
|
||||
//static constexpr float CAMERA_FOV_Y = 1.0f / 1.5f;
|
||||
|
||||
int64_t getSyncTimeMs();
|
||||
void processTickCount();
|
||||
void drawScene();
|
||||
void drawUI();
|
||||
//void drawGame();
|
||||
|
||||
void drawLoading();
|
||||
//void drawShadowDepthPass();
|
||||
//void drawGameWithShadows();
|
||||
//void setupNavigation();
|
||||
|
||||
void handleDown(int64_t fingerId, int mx, int my);
|
||||
void handleUp(int64_t fingerId, int mx, int my);
|
||||
void handleMotion(int64_t fingerId, int mx, int my);
|
||||
/*InteractiveObject* raycastInteractiveObjects(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir);
|
||||
Character* raycastNpcs(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir, float maxDistance = 100.0f);
|
||||
|
||||
#ifdef SHOW_PATH
|
||||
void buildDebugNavMeshes();
|
||||
void drawDebugNavigation();
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
static Game* s_instance;
|
||||
@ -122,15 +76,9 @@ namespace ZL {
|
||||
|
||||
int64_t newTickCount;
|
||||
int64_t lastTickCount;
|
||||
uint32_t connectingStartTicks = 0;
|
||||
static constexpr uint32_t CONNECTING_TIMEOUT_MS = 10000;
|
||||
|
||||
static const size_t CONST_TIMER_INTERVAL = 10;
|
||||
static const size_t CONST_MAX_TIME_INTERVAL = 1000;
|
||||
|
||||
Dialogue::DialogueSystem dialogueSystem;
|
||||
//std::unique_ptr<ShadowMap> shadowMap;
|
||||
//Eigen::Matrix4f cameraViewMatrix = Eigen::Matrix4f::Identity();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -100,6 +100,19 @@ namespace ZL
|
||||
|
||||
scriptEngine.init(this, &inventory);
|
||||
|
||||
|
||||
dialogueSystem.init(renderer, CONST_ZIP_FILE);
|
||||
dialogueSystem.loadDatabase("resources/dialogue/sample_dialogues.json");
|
||||
/*dialogueSystem.addTriggerZone({
|
||||
"ghost_room_trigger",
|
||||
"test_line_dialogue",
|
||||
Eigen::Vector3f(0.0f, 0.0f, -8.5f),
|
||||
2.0f,
|
||||
true,
|
||||
false
|
||||
});*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Location::setupNavigation()
|
||||
@ -475,7 +488,7 @@ namespace ZL
|
||||
{
|
||||
if (player) {
|
||||
player->update(delta);
|
||||
//dialogueSystem.update(static_cast<int>(delta), player->position);
|
||||
dialogueSystem.update(static_cast<int>(delta), player->position);
|
||||
}
|
||||
for (auto& npc : npcs) npc->update(delta);
|
||||
|
||||
@ -510,13 +523,19 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
|
||||
void Location::handleDown(int64_t fingerId, int mx, int my)
|
||||
void Location::handleDown(int64_t fingerId, int eventX, int eventY, int mx, int my)
|
||||
{
|
||||
// Calculate ray for picking
|
||||
if (dialogueSystem.blocksGameplayInput()) {
|
||||
dialogueSystem.handlePointerReleased(static_cast<float>(mx), Environment::projectionHeight - static_cast<float>(my));
|
||||
return;
|
||||
}
|
||||
|
||||
player->attackTarget = nullptr;
|
||||
|
||||
// Unproject click to ground plane (y=0) for Viola's walk target
|
||||
float ndcX = 2.0f * mx / Environment::width - 1.0f;
|
||||
float ndcY = 1.0f - 2.0f * my / Environment::height;
|
||||
float ndcX = 2.0f * eventX / Environment::width - 1.0f;
|
||||
float ndcY = 1.0f - 2.0f * eventY / Environment::height;
|
||||
float aspect = (float)Environment::width / (float)Environment::height;
|
||||
float tanHalfFov = tan(CAMERA_FOV_Y * 0.5f);
|
||||
|
||||
@ -616,5 +635,20 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
|
||||
bool Location::requestDialogueStart(const std::string& dialogueId)
|
||||
{
|
||||
return dialogueSystem.startDialogue(dialogueId);
|
||||
}
|
||||
|
||||
void Location::setDialogueFlag(const std::string& flag, int value)
|
||||
{
|
||||
dialogueSystem.setFlag(flag, value);
|
||||
}
|
||||
|
||||
int Location::getDialogueFlag(const std::string& flag) const
|
||||
{
|
||||
return dialogueSystem.getFlag(flag);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ZL
|
||||
@ -9,7 +9,7 @@
|
||||
#include "render/ShadowMap.h"
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
#include "dialogue/DialogueSystem.h"
|
||||
namespace ZL
|
||||
{
|
||||
|
||||
@ -40,7 +40,7 @@ namespace ZL
|
||||
InteractiveObject* targetInteractiveObject = nullptr;
|
||||
|
||||
ScriptEngine scriptEngine;
|
||||
|
||||
Dialogue::DialogueSystem dialogueSystem;
|
||||
|
||||
#ifdef SHOW_PATH
|
||||
std::vector<VertexRenderStruct> debugNavMeshes;
|
||||
@ -65,16 +65,17 @@ namespace ZL
|
||||
|
||||
void update(int64_t deltaMs);
|
||||
|
||||
void handleDown(int64_t fingerId, int mx, int my);
|
||||
void handleDown(int64_t fingerId, int eventX, int eventY, int mx, int my);
|
||||
void handleUp(int64_t fingerId, int mx, int my);
|
||||
void handleMotion(int64_t fingerId, int mx, int my);
|
||||
|
||||
bool requestDialogueStart(const std::string& dialogueId);
|
||||
void setDialogueFlag(const std::string& flag, int value);
|
||||
int getDialogueFlag(const std::string& flag) const;
|
||||
|
||||
protected:
|
||||
Renderer& renderer;
|
||||
Inventory& inventory;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace ZL
|
||||
@ -110,20 +110,19 @@ namespace ZL {
|
||||
|
||||
api.set_function("start_dialogue",
|
||||
[game](const std::string& dialogueId) {
|
||||
/*----r
|
||||
if (!game->requestDialogueStart(dialogueId)) {
|
||||
std::cerr << "[script] start_dialogue failed for id: " << dialogueId << "\n";
|
||||
}*/
|
||||
}
|
||||
});
|
||||
|
||||
api.set_function("set_dialogue_flag",
|
||||
[game](const std::string& flag, int value) {
|
||||
//game->setDialogueFlag(flag, value); ---rrr
|
||||
game->setDialogueFlag(flag, value);
|
||||
});
|
||||
|
||||
api.set_function("get_dialogue_flag",
|
||||
[game](const std::string& flag) {
|
||||
//return game->getDialogueFlag(flag); ---rrr
|
||||
return game->getDialogueFlag(flag);
|
||||
});
|
||||
|
||||
api.set_function("set_navigation_area_available",
|
||||
@ -255,32 +254,4 @@ namespace ZL {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void ScriptEngine::showInventory(Game* game) {
|
||||
std::cout << "[script] toggle_inventory called" << std::endl;
|
||||
|
||||
bool isVisible = game->menuManager.uiManager.getNodeVisible("inventory_items_panel");
|
||||
game->menuManager.uiManager.setNodeVisible("inventory_items_panel", !isVisible);
|
||||
game->menuManager.uiManager.setNodeVisible("close_inventory_button", !isVisible);
|
||||
|
||||
game->inventoryOpen = !isVisible;
|
||||
|
||||
if (!isVisible) {
|
||||
const auto& items = game->inventory.getItems();
|
||||
std::string itemText;
|
||||
|
||||
if (items.empty()) {
|
||||
itemText = "Inventory (Empty)";
|
||||
}
|
||||
else {
|
||||
itemText = "Inventory (" + std::to_string(items.size()) + " items)\n\n";
|
||||
for (size_t i = 0; i < items.size(); ++i) {
|
||||
itemText += std::to_string(i + 1) + ". " + items[i].name + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
game->menuManager.uiManager.setText("inventory_items_text", itemText);
|
||||
}
|
||||
}*/
|
||||
|
||||
} // namespace ZL
|
||||
|
||||
@ -22,7 +22,6 @@ public:
|
||||
|
||||
void callActivateFunction(const std::string& functionName);
|
||||
|
||||
//void showInventory(Game* game);
|
||||
void callNpcInteractCallback(int npcIndex);
|
||||
|
||||
private:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user