Skip to content

Commit

Permalink
use proper include style
Browse files Browse the repository at this point in the history
  • Loading branch information
xtreme8000 committed Mar 8, 2020
1 parent 5772ca7 commit d01122b
Show file tree
Hide file tree
Showing 55 changed files with 492 additions and 82 deletions.
16 changes: 11 additions & 5 deletions src/aabb.c
Expand Up @@ -17,7 +17,13 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#include <float.h>
#include <stdlib.h>
#include <math.h>

#include "common.h"
#include "map.h"
#include "aabb.h"

void aabb_render(AABB* a) {}

Expand All @@ -28,8 +34,8 @@ float aabb_intersection_ray(AABB* a, Ray* r) {
float t_A = (a->min[coord] - r->origin.coords[coord]) / r->direction.coords[coord];
float t_B = (a->max[coord] - r->origin.coords[coord]) / r->direction.coords[coord];

float range_min = min(t_A, t_B);
float range_max = max(t_A, t_B);
float range_min = fmin(t_A, t_B);
float range_max = fmax(t_A, t_B);

// test if intervals don't intersect
if(total_max <= range_min && total_min <= range_min)
Expand All @@ -38,14 +44,14 @@ float aabb_intersection_ray(AABB* a, Ray* r) {
return -1;

// now calculate overlap of intervals/ranges
total_min = max(range_min, total_min);
total_max = min(range_max, total_max);
total_min = fmax(range_min, total_min);
total_max = fmin(range_max, total_max);
}

if(total_min < 0)
return -1;

return absf(total_min) * len3D(r->direction.x, r->direction.y, r->direction.z);
return fabs(total_min) * len3D(r->direction.x, r->direction.y, r->direction.z);
}

void aabb_set_center(AABB* a, float x, float y, float z) {
Expand Down
5 changes: 5 additions & 0 deletions src/aabb.h
Expand Up @@ -17,6 +17,9 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef AABB_H
#define AABB_H

typedef struct {
union {
struct {
Expand Down Expand Up @@ -53,3 +56,5 @@ unsigned char aabb_intersection_terrain(AABB* a, int miny);
void aabb_set_size(AABB* a, float x, float y, float z);
void aabb_set_center(AABB* a, float x, float y, float z);
void aabb_render(AABB* a);

#endif
9 changes: 9 additions & 0 deletions src/camera.c
Expand Up @@ -17,7 +17,16 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#include <math.h>
#include <string.h>
#include <float.h>

#include "common.h"
#include "cameracontroller.h"
#include "player.h"
#include "map.h"
#include "matrix.h"
#include "camera.h"

unsigned char camera_mode = CAMERAMODE_SPECTATOR;

Expand Down
5 changes: 5 additions & 0 deletions src/camera.h
Expand Up @@ -17,6 +17,9 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CAMERA_H
#define CAMERA_H

#define CAMERAMODE_SELECTION 0
#define CAMERAMODE_FPS 1
#define CAMERAMODE_SPECTATOR 2
Expand Down Expand Up @@ -63,3 +66,5 @@ int* camera_terrain_pickEx(unsigned char mode, float x, float y, float z, float
void camera_overflow_adjust(void);
void camera_apply(void);
void camera_update(float dt);

#endif
15 changes: 11 additions & 4 deletions src/cameracontroller.c
Expand Up @@ -17,7 +17,14 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#include "common.h"
#include <math.h>

#include "window.h"
#include "map.h"
#include "player.h"
#include "camera.h"
#include "matrix.h"
#include "cameracontroller.h"

int cameracontroller_bodyview_mode = 0;
int cameracontroller_bodyview_player = 0;
Expand Down Expand Up @@ -276,15 +283,15 @@ void cameracontroller_bodyview(float dt) {
+ player_height2(&players[cameracontroller_bodyview_player]),
players[cameracontroller_bodyview_player].pos.z - cos(camera_rot_x) * sin(camera_rot_y) * k);
if(aabb_intersection_terrain(&camera, 0) && traverse_lengths[0] < 0) {
traverse_lengths[0] = max(k - 0.1F, 0);
traverse_lengths[0] = fmax(k - 0.1F, 0);
}
aabb_set_center(&camera,
players[cameracontroller_bodyview_player].pos.x + sin(camera_rot_x) * sin(camera_rot_y) * k,
players[cameracontroller_bodyview_player].pos.y + cos(camera_rot_y) * k
+ player_height2(&players[cameracontroller_bodyview_player]),
players[cameracontroller_bodyview_player].pos.z + cos(camera_rot_x) * sin(camera_rot_y) * k);
if(!aabb_intersection_terrain(&camera, 0) && traverse_lengths[1] < 0) {
traverse_lengths[1] = max(k - 0.1F, 0);
traverse_lengths[1] = fmax(k - 0.1F, 0);
}
}
if(traverse_lengths[0] < 0)
Expand All @@ -295,7 +302,7 @@ void cameracontroller_bodyview(float dt) {
float tmp = (traverse_lengths[0] <= 0) ? (-traverse_lengths[1]) : traverse_lengths[0];

cameracontroller_bodyview_zoom
= (tmp < cameracontroller_bodyview_zoom) ? tmp : min(tmp, cameracontroller_bodyview_zoom + dt * 8.0F);
= (tmp < cameracontroller_bodyview_zoom) ? tmp : fmin(tmp, cameracontroller_bodyview_zoom + dt * 8.0F);

// this is needed to determine which chunks need/can be rendered and for sound, minimap etc...
camera_x = players[cameracontroller_bodyview_player].pos.x
Expand Down
5 changes: 5 additions & 0 deletions src/cameracontroller.h
Expand Up @@ -17,6 +17,9 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CAMERACONTROLLER_H
#define CAMERACONTROLLER_H

extern int cameracontroller_bodyview_mode;
extern int cameracontroller_bodyview_player;
extern float cameracontroller_bodyview_zoom;
Expand All @@ -30,3 +33,5 @@ void cameracontroller_fps_render(void);
void cameracontroller_spectator_render(void);
void cameracontroller_bodyview_render(void);
void cameracontroller_selection_render(void);

#endif
17 changes: 15 additions & 2 deletions src/chunk.c
Expand Up @@ -17,10 +17,23 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#include "tesselator.h"
#include "common.h"
#include <pthread.h>
#include <signal.h>
#include <math.h>
#include <stdlib.h>
#include <float.h>
#include <string.h>

#include "common.h"
#include "window.h"
#include "config.h"
#include "texture.h"
#include "log.h"
#include "matrix.h"
#include "map.h"
#include "camera.h"
#include "tesselator.h"
#include "chunk.h"

struct chunk chunks[CHUNKS_PER_DIM * CHUNKS_PER_DIM] = {0};

Expand Down
9 changes: 9 additions & 0 deletions src/chunk.h
Expand Up @@ -17,6 +17,13 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CHUNK_H
#define CHUNK_H

#include <stdint.h>
#include <pthread.h>

#include "glx.h"
#include "tesselator.h"

#define CHUNK_SIZE 16
Expand Down Expand Up @@ -74,3 +81,5 @@ void chunk_draw_visible(void);
void chunk_draw_shadow_volume(float* data, int max);
float chunk_face_light(float* data, int k, float lx, float ly, float lz);
int chunk_find_edge(float* data, int length, int exclude, float x1, float y1, float z1, float x2, float y2, float z2);

#endif
71 changes: 8 additions & 63 deletions src/common.h
Expand Up @@ -17,17 +17,16 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef COMMON_H
#define COMMON_H

#ifndef OPENGL_ES
#define GLEW_STATIC
#include <GL/glew.h>

#include <enet/enet.h>
#else
#ifdef USE_SDL
#include <SDL2/SDL_opengles.h>
#endif
#include <enet/enet.h>

void glColor3f(float r, float g, float b);
void glColor3ub(unsigned char r, unsigned char g, unsigned char b);
void glDepthRange(float near, float far);
Expand All @@ -42,31 +41,10 @@ void glClearDepth(float x);
#include <SDL2/SDL.h>
#endif

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <stdio.h>
#include <assert.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
#include <pthread.h>
#include <limits.h>
#include <dirent.h>

#ifdef USE_RPC
#include <discord_rpc.h>
#endif

#include "lodepng/lodepng.h"
#include "libdeflate.h"
#include "ini.h"
#include "log.h"
#include "hashtable.h"
#include "minheap.h"

#ifdef _WIN32
#define OS_WINDOWS
#endif
Expand Down Expand Up @@ -110,44 +88,6 @@ void glClearDepth(float x);

#define MOUSE_SENSITIVITY 0.002F

#include "utils.h"
#include "ping.h"
#include "glx.h"
#include "list.h"
#include "window.h"
#include "sound.h"
#include "texture.h"
#include "chunk.h"
#include "map.h"
#include "aabb.h"
#include "model.h"
#include "file.h"
#include "camera.h"
#include "network.h"
#include "player.h"
#include "particle.h"
#include "grenade.h"
#include "cameracontroller.h"
#include "font.h"
#include "weapon.h"
#include "matrix.h"
#include "tracer.h"
#include "config.h"
#include "hud.h"
#include "rpc.h"

void reshape(struct window_instance* window, int width, int height);
void text_input(struct window_instance* window, unsigned int codepoint);
void keys(struct window_instance* window, int key, int scancode, int action, int mods);
void mouse_click(struct window_instance* window, int button, int action, int mods);
void mouse(struct window_instance* window, double x, double y);
void mouse_scroll(struct window_instance* window, double xoffset, double yoffset);
void on_error(int i, const char* s);

unsigned char key_map[512];
unsigned char button_map[3];
unsigned char draw_outline;

#define CHAT_NO_INPUT 0
#define CHAT_ALL_INPUT 1
#define CHAT_TEAM_INPUT 2
Expand Down Expand Up @@ -175,8 +115,13 @@ const char* reason_disconnect(int code);
extern int ms_seed;
int ms_rand(void);

#include <stdlib.h>
#include "log.h"

#define CHECK_ALLOCATION_ERROR(ret) \
if(!ret) { \
log_fatal("Critical error: memory allocation failed (%s:%d)", __func__, __LINE__); \
exit(1); \
}

#endif
12 changes: 11 additions & 1 deletion src/config.c
Expand Up @@ -17,7 +17,17 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#include "common.h"
#include <stdlib.h>
#include <float.h>
#include <stdlib.h>
#include <string.h>

#include "window.h"
#include "file.h"
#include "ini.h"
#include "config.h"
#include "sound.h"
#include "model.h"

struct RENDER_OPTIONS settings, settings_tmp;
struct list config_keys;
Expand Down
9 changes: 8 additions & 1 deletion src/config.h
Expand Up @@ -17,6 +17,11 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef CONFIG_H
#define CONFIG_H

#include "list.h"

struct config_file_entry {
char section[32];
char name[32];
Expand All @@ -32,7 +37,7 @@ extern struct RENDER_OPTIONS {
float render_distance;
int window_width;
int window_height;
unsigned char multisamples;
int multisamples;
int player_arms;
int fullscreen;
int greedy_meshing;
Expand Down Expand Up @@ -81,3 +86,5 @@ struct config_key_pair* config_key(int key);
void config_key_reset_togglestates();
void config_reload(void);
void config_save(void);

#endif
7 changes: 7 additions & 0 deletions src/file.c
Expand Up @@ -17,7 +17,14 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>

#include "common.h"
#include "log.h"
#include "file.h"

struct file_handle {
void* internal;
Expand Down
5 changes: 5 additions & 0 deletions src/file.h
Expand Up @@ -17,6 +17,9 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef FILE_H
#define FILE_H

void* file_open(const char* name, const char* mode);
void file_printf(void* file, const char* fmt, ...);
void file_close(void* file);
Expand All @@ -30,3 +33,5 @@ unsigned int buffer_read32(unsigned char* buffer, int index);
unsigned short buffer_read16(unsigned char* buffer, int index);
unsigned char buffer_read8(unsigned char* buffer, int index);
void file_url(char* url);

#endif
6 changes: 6 additions & 0 deletions src/font.c
Expand Up @@ -17,7 +17,13 @@
along with BetterSpades. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdlib.h>
#include <string.h>

#include "common.h"
#include "file.h"
#include "list.h"
#include "font.h"
#include "stb_truetype.h"

short* font_vertex_buffer;
Expand Down

0 comments on commit d01122b

Please sign in to comment.