Skip to content

Commit

Permalink
See desc
Browse files Browse the repository at this point in the history
* use libvxl for map access
* much faster chunk generation
* cleaned up chunk code a bit, still wip
* death camera effect
* fix some includes
* NOTE: greedy meshing not working yet
  • Loading branch information
xtreme8000 committed Mar 25, 2020
1 parent d01122b commit eae6b6c
Show file tree
Hide file tree
Showing 17 changed files with 528 additions and 427 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -28,6 +28,8 @@ download_file_if_it_doesnt_exist(hashtable.c https://raw.githubusercontent.com/g
download_file_if_it_doesnt_exist(hashtable.h https://raw.githubusercontent.com/goldsborough/hashtable/master/hashtable.h)
download_file_if_it_doesnt_exist(../deps/libdeflate.h https://raw.githubusercontent.com/ebiggers/libdeflate/master/libdeflate.h)
download_file_if_it_doesnt_exist(../bsresources.zip http://aos.party/bsresources.zip)
download_file_if_it_doesnt_exist(libvxl.c https://raw.githubusercontent.com/xtreme8000/libvxl/master/libvxl.c)
download_file_if_it_doesnt_exist(libvxl.h https://raw.githubusercontent.com/xtreme8000/libvxl/master/libvxl.h)

list(APPEND CLIENT_SOURCES aabb.c)
list(APPEND CLIENT_SOURCES camera.c)
Expand Down Expand Up @@ -64,6 +66,7 @@ list(APPEND CLIENT_SOURCES minheap.c)
list(APPEND CLIENT_SOURCES hashtable.c)
list(APPEND CLIENT_SOURCES rpc.c)
list(APPEND CLIENT_SOURCES tesselator.c)
list(APPEND CLIENT_SOURCES libvxl.c)
list(APPEND CLIENT_SOURCES ${BetterSpades_SOURCE_DIR}/resources/icon.rc)

add_executable(client ${CLIENT_SOURCES})
Expand Down
4 changes: 3 additions & 1 deletion src/camera.c
Expand Up @@ -28,7 +28,7 @@
#include "matrix.h"
#include "camera.h"

unsigned char camera_mode = CAMERAMODE_SPECTATOR;
enum camera_mode camera_mode = CAMERAMODE_SPECTATOR;

float frustum[6][4];
float camera_rot_x = 2.04F, camera_rot_y = 1.79F;
Expand Down Expand Up @@ -77,6 +77,7 @@ void camera_apply() {
case CAMERAMODE_BODYVIEW: cameracontroller_bodyview_render(); break;
case CAMERAMODE_SPECTATOR: cameracontroller_spectator_render(); break;
case CAMERAMODE_SELECTION: cameracontroller_selection_render(); break;
case CAMERAMODE_DEATH: cameracontroller_death_render(); break;
}
}

Expand All @@ -86,6 +87,7 @@ void camera_update(float dt) {
case CAMERAMODE_BODYVIEW: cameracontroller_bodyview(dt); break;
case CAMERAMODE_SPECTATOR: cameracontroller_spectator(dt); break;
case CAMERAMODE_SELECTION: cameracontroller_selection(dt); break;
case CAMERAMODE_DEATH: cameracontroller_death(dt); break;
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/camera.h
Expand Up @@ -20,14 +20,17 @@
#ifndef CAMERA_H
#define CAMERA_H

#define CAMERAMODE_SELECTION 0
#define CAMERAMODE_FPS 1
#define CAMERAMODE_SPECTATOR 2
#define CAMERAMODE_BODYVIEW 3
enum camera_mode {
CAMERAMODE_SELECTION,
CAMERAMODE_FPS,
CAMERAMODE_SPECTATOR,
CAMERAMODE_BODYVIEW,
CAMERAMODE_DEATH,
};

#define CAMERA_DEFAULT_FOV 70.0F

extern unsigned char camera_mode;
extern enum camera_mode camera_mode;

extern float frustum[6][4];
extern float camera_rot_x, camera_rot_y;
Expand Down
46 changes: 46 additions & 0 deletions src/cameracontroller.c
Expand Up @@ -30,6 +30,52 @@ int cameracontroller_bodyview_mode = 0;
int cameracontroller_bodyview_player = 0;
float cameracontroller_bodyview_zoom = 0.0F;

float cameracontroller_death_velocity_x, cameracontroller_death_velocity_y, cameracontroller_death_velocity_z;

void cameracontroller_death_init(int player, float x, float y, float z) {
camera_mode = CAMERAMODE_DEATH;
float len = len3D(camera_x - x, camera_y - y, camera_z - z);
cameracontroller_death_velocity_x = (camera_x - x) / len * 3;
cameracontroller_death_velocity_y = (camera_y - y) / len * 3;
cameracontroller_death_velocity_z = (camera_z - z) / len * 3;

cameracontroller_bodyview_player = player;
cameracontroller_bodyview_zoom = 0.0F;
}

void cameracontroller_death(float dt) {
cameracontroller_death_velocity_y -= dt * 32.0F;

AABB box;
aabb_set_size(&box, camera_size, camera_height, camera_size);
aabb_set_center(&box, camera_x + cameracontroller_death_velocity_x * dt,
camera_y + cameracontroller_death_velocity_y * dt,
camera_z + cameracontroller_death_velocity_z * dt);

if(!aabb_intersection_terrain(&box, 0)) {
cameracontroller_death_velocity_y -= dt * 32.0F;
camera_x += cameracontroller_death_velocity_x * dt;
camera_y += cameracontroller_death_velocity_y * dt;
camera_z += cameracontroller_death_velocity_z * dt;
} else {
cameracontroller_death_velocity_x *= 0.5F;
cameracontroller_death_velocity_y *= -0.5F;
cameracontroller_death_velocity_z *= 0.5F;

if(len3D(cameracontroller_death_velocity_x, cameracontroller_death_velocity_y,
cameracontroller_death_velocity_z)
< 0.05F) {
camera_mode = CAMERAMODE_BODYVIEW;
}
}
}

void cameracontroller_death_render() {
matrix_lookAt(camera_x, camera_y, camera_z, camera_x + players[local_player_id].orientation.x,
camera_y + players[local_player_id].orientation.y, camera_z + players[local_player_id].orientation.z,
0.0F, 1.0F, 0.0F);
}

float last_cy;
void cameracontroller_fps(float dt) {
players[local_player_id].connected = 1;
Expand Down
4 changes: 4 additions & 0 deletions src/cameracontroller.h
Expand Up @@ -24,14 +24,18 @@ extern int cameracontroller_bodyview_mode;
extern int cameracontroller_bodyview_player;
extern float cameracontroller_bodyview_zoom;

void cameracontroller_death_init(int player, float x, float y, float z);

void cameracontroller_fps(float dt);
void cameracontroller_spectator(float dt);
void cameracontroller_bodyview(float dt);
void cameracontroller_selection(float dt);
void cameracontroller_death(float dt);

void cameracontroller_fps_render(void);
void cameracontroller_spectator_render(void);
void cameracontroller_bodyview_render(void);
void cameracontroller_selection_render(void);
void cameracontroller_death_render(void);

#endif

0 comments on commit eae6b6c

Please sign in to comment.