Fix some oversights

This commit is contained in:
mrkubax10 2023-05-18 18:32:28 +02:00
parent b43b69a749
commit de21aa399e
2 changed files with 7 additions and 22 deletions

View File

@ -38,17 +38,12 @@ SOFTWARE.
#include "server/server.hpp"
#endif
// greedy meshing debug test
//#include <iostream>
#include "../engine/greedy_meshing.hpp"
using namespace polygun::screens;
static int x_d, y_d, z_d;
static int id_d;
static std::vector<float> vertices;
static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) {
// limit from 0 to size of polygun::world::nodes array change to sizeof and use id_d as a current node id
if(yoffset > 0) {
@ -95,18 +90,7 @@ void GameSessionScreen::begin() {
m_chunk_shader->load_from_file("chunk");
m_node_mesh = m_engine->get_master_renderer().create_mesh();
/*
engine::greedy_meshing greedy;
engine::vertices_indices mesh = greedy.generate_mesh(greedy.merge(m_chnk), m_chnk);
m_node_mesh->load_from_memory(mesh.vertices, mesh.indices);
*/
engine::vertices_indices mesh = m_greedy.generate_mesh(m_greedy.merge(m_chnk), m_chnk);
for (int i = 0; i < mesh.vertices.size(); i++) {
vertices.push_back(mesh.vertices[i].x);
vertices.push_back(mesh.vertices[i].y);
vertices.push_back(mesh.vertices[i].z);
}
m_node_mesh->load_from_memory(vertices, mesh.indices);
update_mesh();
for(int i = 0; i< sizeof(world::nodes) / sizeof(world::nodes[0]); i++) {
m_texture_atlas[i] = m_engine->get_master_renderer().create_texture();
@ -208,9 +192,10 @@ void GameSessionScreen::render() {
// camera fov
ImGui::InputFloat(_("FOV"), &m_camera.m_fov);
if (ImGui::Button(_("Place Block")))
if (ImGui::Button(_("Place Block"))) {
m_chnk.add_node(id_d, glm::vec3(x_d, y_d, z_d));
update_mesh();
}
ImGui::NewLine();
@ -418,12 +403,12 @@ void GameSessionScreen::show_imgui_error_message(const std::string& title, const
}
void GameSessionScreen::update_mesh(){
std::vector<float> vertices;
engine::vertices_indices mesh = m_greedy.generate_mesh(m_greedy.merge(m_chnk), m_chnk);
m_node_mesh = m_engine->get_master_renderer().create_mesh();
for (int i = 0; i < mesh.vertices.size(); i++) {
vertices.push_back(mesh.vertices[i].x);
vertices.push_back(mesh.vertices[i].y);
vertices.push_back(mesh.vertices[i].z);
}
m_node_mesh->load_from_memory(vertices, mesh.indices);
}
}

View File

@ -34,7 +34,7 @@ SOFTWARE.
#include "game/engine/player_camera.hpp"
#include "game/world/chunk.hpp"
#include "../engine/greedy_meshing.hpp"
#include "game/engine/greedy_meshing.hpp"
namespace polygun::renderer {
class Shader;
@ -90,4 +90,4 @@ namespace polygun::screens {
};
}
#endif // POLYGUN_SCREENS_GAME_SESSION_SCREEN_HPP
#endif // POLYGUN_SCREENS_GAME_SESSION_SCREEN_HPP