return NULL;
}
+static void update_view_matrix(ShaderProgram *prog, mat4x4 view)
+{
+ mat4x4_translate(view, -client.pos.x, -client.pos.y, -client.pos.z);
+ glUniformMatrix4fv(prog->loc_view, 1, GL_FALSE, view[0]);
+}
+
static void client_loop()
{
if(! glfwInit()) {
return;
}
- v3f pos = {0.0f, 0.0f, 0.0f};
-
mat4x4 view, projection;
- mat4x4_translate(view, -pos.x, -pos.y, -pos.z);
+ update_view_matrix(prog, view);
mat4x4_perspective(projection, 86.1f / 180.0f * M_PI, (float) width / (float) height, 0.01f, 1000.0f);
glUseProgram(prog->id);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.52941176470588f, 0.8078431372549f, 0.92156862745098f, 1.0f);
- bool view_changed = false;
+ bool pos_changed = false;
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {
- view_changed = true;
- pos.z -= 1.0f;
+ pos_changed = true;
+ client.pos.z -= 1.0f;
} else if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {
- view_changed = true;
- pos.z += 1.0f;
+ pos_changed = true;
+ client.pos.z += 1.0f;
} if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
- view_changed = true;
- pos.x -= 1.0f;
+ pos_changed = true;
+ client.pos.x -= 1.0f;
} else if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
- view_changed = true;
- pos.x += 1.0f;
+ pos_changed = true;
+ client.pos.x += 1.0f;
} if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
- view_changed = true;
- pos.y -= 1.0f;
+ pos_changed = true;
+ client.pos.y -= 1.0f;
} else if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
- view_changed = true;
- pos.y += 1.0f;
+ pos_changed = true;
+ client.pos.y += 1.0f;
}
- if (view_changed) {
- mat4x4_translate(view, -pos.x, -pos.y, -pos.z);
- glUniformMatrix4fv(prog->loc_view, 1, GL_FALSE, view[0]);
+ if (pos_changed) {
+ update_view_matrix(prog, view);
+ pthread_mutex_lock(&client.mtx);
+ (void) (write_u32(client.fd, SC_POS) && write_v3f32(client.fd, client.pos));
+ pthread_mutex_unlock(&client.mtx);
}
scene_render(client.scene, prog);
client.name = NULL;
client.map = map_create();
client.scene = scene_create();
+ client.pos = (v3f) {0.0f, 0.0f, 0.0f};
mapblock_meshgen_init(client.map, client.scene);
server->map->on_block_create = &generate_block;
}
+#define RANGE 3
+
static void *mapgen_thread(void *cliptr)
{
Client *client = cliptr;
while (client->state != CS_DISCONNECTED) {
v3s32 pos = map_node_to_block_pos((v3s32) {client->pos.x, client->pos.y, client->pos.z}, NULL);
- for (s32 x = pos.x - 5; x < pos.x + 5; x++)
- for (s32 y = pos.y - 5; y < pos.y + 5; y++)
- for (s32 z = pos.z - 5; z < pos.z + 5; z++)
+ for (s32 x = pos.x - RANGE; x <= pos.x + RANGE; x++)
+ for (s32 y = pos.y - RANGE; y <= pos.y + RANGE; y++)
+ for (s32 z = pos.z - RANGE; z <= pos.z + RANGE; z++)
map_get_block(client->server->map, (v3s32) {x, y, z}, true);
}
return true;
}
+static bool pos_handler(Client *client, bool good)
+{
+ v3f pos;
+
+ if (! read_v3f32(client->fd, &pos))
+ return false;
+
+ if (good)
+ client->pos = pos;
+
+ return true;
+}
+
CommandHandler command_handlers[SERVER_COMMAND_COUNT] = {
{0},
{&disconnect_handler, "DISCONNECT", CS_CREATED | CS_ACTIVE},
{&auth_handler, "AUTH", CS_CREATED},
{&setnode_handler, "SETNODE", CS_ACTIVE},
{&kick_handler, "KICK", CS_ACTIVE},
+ {&pos_handler, "POS", CS_ACTIVE},
};