COMMON = array.o list.o map.o signal.o util.o types.o node.o queue.o
SERVER = $(COMMON) server.o servercommands.o servermap.o perlin.o facecache.o mapgen.o mapdb.o
-CLIENT = $(COMMON) camera.o client.o clientcommands.o clientmap.o clientnode.o input.o mesh.o scene.o shaders.o blockmesh.o texture.o
+CLIENT = $(COMMON) camera.o client.o clientcommands.o clientmap.o clientnode.o clientplayer.o input.o mesh.o scene.o shaders.o blockmesh.o texture.o
LIBRARIES = -lpthread -lm -lz
FLAGS = -g -fmax-errors=4
update_camera();
}
-void set_camera_angle(float yaw, float pitch)
+void set_camera_angle(f32 yaw, f32 pitch)
{
camera.front[0] = movement_dirs.front[0] = cos(yaw) * cos(pitch);
camera.front[1] = sin(pitch);
void init_camera(GLFWwindow *window, ShaderProgram *prog);
void set_camera_position(v3f pos);
-void set_camera_angle(float yaw, float pitch);
+void set_camera_angle(f32 yaw, f32 pitch);
void set_window_size(int width, int height);
extern struct movement_dirs
init_camera(window, prog);
- set_camera_position(client.pos);
- set_camera_angle(client.yaw, client.pitch);
+ set_camera_position(client.player.pos);
+ set_camera_angle(client.player.yaw, client.player.pitch);
set_window_size(width, height);
client.name = NULL;
client.map = map_create();
client.scene = scene_create();
- client.pos = (v3f) {0.0f, 0.0f, 0.0f};
- client.yaw = client.pitch = 0.0;
+ client.player.client = &client;
+ client.player.pos = (v3f) {0.0f, 0.0f, 0.0f};
+ client.player.yaw = client.player.pitch = 0.0;
clientmap_init(&client);
#include <pthread.h>
#include "servercommands.h"
#include "clientcommands.h"
+#include "clientplayer.h"
#include "map.h"
#include "network.h"
#include "scene.h"
char *name;
Map *map;
Scene *scene;
- v3f pos;
- double yaw, pitch;
+ ClientPlayer player;
} Client;
void client_disconnect(bool send, const char *detail);
--- /dev/null
+#include "client.h"
+#include "clientplayer.h"
+
+void clientplayer_send_pos(ClientPlayer *player)
+{
+ pthread_mutex_lock(&player->client->mtx);
+ (void) (write_u32(player->client->fd, SC_POS) && write_v3f32(player->client->fd, player->pos));
+ pthread_mutex_unlock(&player->client->mtx);
+}
--- /dev/null
+#ifndef _CLIENTPLAYER_H_
+#define _CLIENTPLAYER_H_
+
+#include "types.h"
+
+typedef struct
+{
+ struct Client *client;
+ v3f pos;
+ f32 yaw, pitch;
+} ClientPlayer;
+
+void clientplayer_send_pos(ClientPlayer *player);
+
+#endif
last_x = current_x;
last_y = current_y;
- input.client->yaw += (float) delta_x * M_PI / 180.0f / 8.0f;
- input.client->pitch -= (float) delta_y * M_PI / 180.0f / 8.0f;
+ input.client->player.yaw += (f32) delta_x * M_PI / 180.0f / 8.0f;
+ input.client->player.pitch -= (f32) delta_y * M_PI / 180.0f / 8.0f;
- input.client->pitch = fmax(fmin(input.client->pitch, 89.0f), -89.0f);
+ input.client->player.pitch = fmax(fmin(input.client->player.pitch, 89.0f), -89.0f);
- set_camera_angle(input.client->yaw, input.client->pitch);
+ set_camera_angle(input.client->player.yaw, input.client->player.pitch);
}
static bool move(int forward, int backward, vec3 speed)
{
- float sign;
+ f32 sign;
if (glfwGetKey(input.window, forward) == GLFW_PRESS)
sign = +1.0f;
else
return false;
- input.client->pos.x += speed[0] * sign;
- input.client->pos.y += speed[1] * sign;
- input.client->pos.z += speed[2] * sign;
+ input.client->player.pos.x += speed[0] * sign;
+ input.client->player.pos.y += speed[1] * sign;
+ input.client->player.pos.z += speed[2] * sign;
return true;
}
bool moved_right = move(GLFW_KEY_D, GLFW_KEY_A, movement_dirs.right);
if (moved_forward || moved_up || moved_right) {
- set_camera_position(input.client->pos);
-
- pthread_mutex_lock(&input.client->mtx);
- (void) (write_u32(input.client->fd, SC_POS) && write_v3f32(input.client->fd, input.client->pos));
- pthread_mutex_unlock(&input.client->mtx);
+ set_camera_position(input.client->player.pos);
+ clientplayer_send_pos(&input.client->player);
}
}
typedef struct
{
v3f pos, rot, scale;
- float angle;
+ f32 angle;
mat4x4 transform;
bool remove;
Mesh **meshes;
{
unsigned int r, g, b;
sscanf(html, "#%2x%2x%2x", &r, &g, &b);
- return (v3f) {(float) r / 255.0f, (float) g / 255.0f, (float) b / 255.0f};
+ return (v3f) {(f32) r / 255.0f, (f32) g / 255.0f, (f32) b / 255.0f};
}