Major refactoring
This commit is contained in:
1 parent
92ba3f2b60
commit
a1dda3fd50
8 files changed
+75
-487
No files matched your search
+23
-330
@@ -164,21 +164,7 @@ namespace ZL
|
||||
renderer.shaderManager.AddShaderFromFiles("skinning_shadow", "resources/shaders/skinning_shadow.vertex", "resources/shaders/default_shadow_desktop.fragment", CONST_ZIP_FILE);
|
||||
#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,215 +238,7 @@ 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);
|
||||
if (!loadingCompleted) {
|
||||
@@ -465,11 +246,19 @@ namespace ZL
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentLocation->shadowMap) {
|
||||
currentLocation->drawShadowDepthPass();
|
||||
currentLocation->drawGameWithShadows();
|
||||
} else {
|
||||
currentLocation->drawGame();
|
||||
if (currentLocation)
|
||||
{
|
||||
if (currentLocation->shadowMap) {
|
||||
currentLocation->drawShadowDepthPass();
|
||||
currentLocation->drawGameWithShadows();
|
||||
}
|
||||
else {
|
||||
currentLocation->drawGame();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ??? Main menu???
|
||||
}
|
||||
drawUI();
|
||||
}
|
||||
@@ -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
|
||||
Reference in new issue
Block a user