blockpick control belongs to control, not chunkmgr
parent
afdd622ec2
commit
255460892d
|
@ -4,6 +4,8 @@
|
|||
#include <glm/glm.hpp>
|
||||
#include <oneapi/tbb/concurrent_queue.h>
|
||||
|
||||
#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<WorldUpdateMsg> WorldUpdateMsgQueue;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -79,6 +79,11 @@ namespace debug{
|
|||
ImGui::Text("Pointing in direction: %f, %f, %f",
|
||||
std::any_cast<float>(parameters.at("lx")),std::any_cast<float>(parameters.at("ly")),std::any_cast<float>(parameters.at("lz")) );
|
||||
|
||||
ImGui::SliderInt("Crosshair type",
|
||||
std::any_cast<int*>(parameters.at("crosshair_type_return")), 0, 1);
|
||||
ImGui::SliderInt("Block to place",
|
||||
std::any_cast<int*>(parameters.at("block_type_return")), 2, 6);
|
||||
|
||||
if(parameters.find("block_last_action") != parameters.end()){
|
||||
ImGui::Text("Last Block action: %s",
|
||||
std::any_cast<bool>(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<int>(parameters.at("block_last_action_x")),std::any_cast<int>(parameters.at("block_last_action_y")),std::any_cast<int>(parameters.at("block_last_action_z")) );
|
||||
}
|
||||
|
||||
ImGui::SliderInt("Crosshair type",
|
||||
std::any_cast<int*>(parameters.at("crosshair_type_return")), 0, 1);
|
||||
ImGui::SliderInt("Block to place",
|
||||
std::any_cast<int*>(parameters.at("block_type_return")), 2, 6);
|
||||
}
|
||||
|
||||
if(ImGui::CollapsingHeader("Mesh")){
|
||||
|
|
Loading…
Reference in New Issue