diff --git a/include/worldupdatemessage.h b/include/worldupdatemessage.h index 200f8d9..3c9275e 100644 --- a/include/worldupdatemessage.h +++ b/include/worldupdatemessage.h @@ -4,6 +4,8 @@ #include #include +#include "block.hpp" + enum class WorldUpdateMsgType{ BLOCKPICK_PLACE, BLOCKPICK_BREAK @@ -14,6 +16,7 @@ typedef struct WorldUpdateMsg{ glm::vec3 cameraPos; glm::vec3 cameraFront; float time; + Block block; } WorldUpdateMsg; typedef oneapi::tbb::concurrent_queue WorldUpdateMsgQueue; diff --git a/src/chunkmanager.cpp b/src/chunkmanager.cpp index 5983d5b..9204e38 100644 --- a/src/chunkmanager.cpp +++ b/src/chunkmanager.cpp @@ -43,9 +43,6 @@ namespace chunkmanager // Queue of chunks to be meshed ChunkPriorityQueue chunks_to_mesh_queue; - /* Block picking */ - int block_to_place{2}; - WorldUpdateMsgQueue& getWorldUpdateQueue(){ return WorldUpdateQueue; } // Init chunkmanager. Chunk indices and start threads @@ -66,8 +63,6 @@ namespace chunkmanager update_thread = std::thread(update); gen_thread = std::thread(generate); mesh_thread = std::thread(mesh); - - debug::window::set_parameter("block_type_return", &block_to_place); } // Method for world generation thread(s) @@ -327,15 +322,14 @@ namespace chunkmanager if(!chunks.find(a1, Chunk::calculateIndex(px1, py1, pz1))) return; Chunk::Chunk* c1 = a1->second; // place the new block (only stone for now) - c1->setBlock((Block)block_to_place, bx1, by1, bz1); + c1->setBlock(msg.block, bx1, by1, bz1); // mark the mesh of the chunk the be updated chunks_to_mesh_queue.push(std::make_pair(c1, MESHING_PRIORITY_PLAYER_EDIT)); chunks_to_mesh_queue.push(std::make_pair(c, MESHING_PRIORITY_PLAYER_EDIT)); - debug::window::set_parameter("block_last_action", (int)msg.msg_type); - debug::window::set_parameter("block_last_action_block_type", - (int)(block_to_place)); + debug::window::set_parameter("block_last_action", true); + debug::window::set_parameter("block_last_action_block_type", (int)(msg.block)); debug::window::set_parameter("block_last_action_x", px1*CHUNK_SIZE + bx1); debug::window::set_parameter("block_last_action_y", px1*CHUNK_SIZE + by1); debug::window::set_parameter("block_last_action_z", px1*CHUNK_SIZE + bz1); @@ -360,7 +354,7 @@ namespace chunkmanager if(bz == CHUNK_SIZE - 1 && pz +1 < 1024 && chunks.find(c2, Chunk::calculateIndex(px, py, pz +1))) chunkmesher::mesh(c2->second); - debug::window::set_parameter("block_last_action", (int)msg.msg_type); + debug::window::set_parameter("block_last_action", false); debug::window::set_parameter("block_last_action_block_type", (int) (Block::AIR)); debug::window::set_parameter("block_last_action_x", px*CHUNK_SIZE + bx); debug::window::set_parameter("block_last_action_y", py*CHUNK_SIZE + by); diff --git a/src/controls.cpp b/src/controls.cpp index 2b2b82d..27ba313 100644 --- a/src/controls.cpp +++ b/src/controls.cpp @@ -2,15 +2,21 @@ #include "camera.hpp" #include "chunkmanager.hpp" +#include "debugwindow.hpp" #include "globals.hpp" #include "renderer.hpp" namespace controls{ + /* Block picking */ + int block_to_place{2}; float lastBlockPick=0.0; bool blockpick = false; + + /* Cursor */ bool cursor = false; void init(){ + debug::window::set_parameter("block_type_return", &block_to_place); } void update(GLFWwindow* window){ @@ -43,6 +49,7 @@ namespace controls{ msg.time = current_time; msg.msg_type = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS ? WorldUpdateMsgType::BLOCKPICK_PLACE : WorldUpdateMsgType::BLOCKPICK_BREAK; + msg.block = (Block)(block_to_place); // Send to chunk manager chunkmanager::getWorldUpdateQueue().push(msg); diff --git a/src/debugwindow.cpp b/src/debugwindow.cpp index 256dd2e..1db0880 100644 --- a/src/debugwindow.cpp +++ b/src/debugwindow.cpp @@ -79,6 +79,11 @@ namespace debug{ ImGui::Text("Pointing in direction: %f, %f, %f", std::any_cast(parameters.at("lx")),std::any_cast(parameters.at("ly")),std::any_cast(parameters.at("lz")) ); + ImGui::SliderInt("Crosshair type", + std::any_cast(parameters.at("crosshair_type_return")), 0, 1); + ImGui::SliderInt("Block to place", + std::any_cast(parameters.at("block_type_return")), 2, 6); + if(parameters.find("block_last_action") != parameters.end()){ ImGui::Text("Last Block action: %s", std::any_cast(parameters.at("block_last_action")) ? "place" : "destroy"); @@ -87,11 +92,6 @@ namespace debug{ ImGui::Text("Last Block action position: X: %d, Y: %d, Z: %d", std::any_cast(parameters.at("block_last_action_x")),std::any_cast(parameters.at("block_last_action_y")),std::any_cast(parameters.at("block_last_action_z")) ); } - - ImGui::SliderInt("Crosshair type", - std::any_cast(parameters.at("crosshair_type_return")), 0, 1); - ImGui::SliderInt("Block to place", - std::any_cast(parameters.at("block_type_return")), 2, 6); } if(ImGui::CollapsingHeader("Mesh")){