Skip to content

Commit

Permalink
A few minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xtreme8000 committed Aug 27, 2020
1 parent 2a94f19 commit 4a92b1b
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/cameracontroller.c
Expand Up @@ -166,11 +166,11 @@ void cameracontroller_fps(float dt) {
}

float lx = players[local_player_id].orientation_smooth.x * pow(0.7F, dt * 60.0F)
+ (sin(camera_rot_x) * sin(camera_rot_y)) * pow(0.3F, dt * 60.0F);
+ (sin(camera_rot_x) * sin(camera_rot_y)) * (1.0F - pow(0.7F, dt * 60.0F));
float ly = players[local_player_id].orientation_smooth.y * pow(0.7F, dt * 60.0F)
+ (cos(camera_rot_y)) * pow(0.3F, dt * 60.0F);
+ (cos(camera_rot_y)) * (1.0F - pow(0.7F, dt * 60.0F));
float lz = players[local_player_id].orientation_smooth.z * pow(0.7F, dt * 60.0F)
+ (cos(camera_rot_x) * sin(camera_rot_y)) * pow(0.3F, dt * 60.0F);
+ (cos(camera_rot_x) * sin(camera_rot_y)) * (1.0F - pow(0.7F, dt * 60.0F));

players[local_player_id].orientation_smooth.x = lx;
players[local_player_id].orientation_smooth.y = ly;
Expand Down
3 changes: 3 additions & 0 deletions src/grenade.c
Expand Up @@ -142,6 +142,9 @@ void grenade_render() {
|| fabs(grenades[k].velocity.z) > 0.05F)
matrix_rotate(-window_time() * 720.0F, -grenades[k].velocity.z, 0.0F, grenades[k].velocity.x);
matrix_upload();

kv6_calclight(grenades[k].pos.x, grenades[k].pos.y, grenades[k].pos.z);

kv6_render(&model_grenade, TEAM_1);
matrix_pop();
}
Expand Down
70 changes: 66 additions & 4 deletions src/list.c
@@ -1,40 +1,96 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "common.h"
#include "list.h"

int list_created(struct list* l) {
assert(l != NULL);

return l->element_size > 0;
}

void list_create(struct list* l, int element_size) {
void list_create(struct list* l, size_t element_size) {
assert(l != NULL && element_size > 0);

l->data = NULL;
l->elements = 0;
l->element_size = element_size;
l->mem_size = 0;
}

void* list_get(struct list* l, int i) {
void list_free(struct list* l) {
assert(l != NULL);

if(l->data) {
free(l->data);
l->data = NULL;
}
}

void* list_find(struct list* l, void* ref, enum list_traverse_direction dir, int (*cmp)(void* obj, void* ref)) {
assert(l != NULL && cmp != NULL);

switch(dir) {
case LIST_TRAVERSE_FORWARD:
for(size_t k = 0; k < l->elements; k++) {
void* obj = l->data + l->element_size * k;

if(cmp(obj, ref))
return obj;
}
break;
case LIST_TRAVERSE_BACKWARD:
if(!l->elements)
break;

size_t k = l->elements - 1;

do {
void* obj = l->data + l->element_size * k;

if(cmp(obj, ref))
return obj;
} while((k--) > 0);

break;
}

return NULL;
}

void* list_get(struct list* l, size_t i) {
assert(l != NULL && i < l->elements);

return l->data + i * l->element_size;
}

void* list_add(struct list* l, void* e) {
assert(l != NULL);

if((l->elements + 1) * l->element_size > l->mem_size) {
l->mem_size += l->element_size * 64;
l->data = realloc(l->data, l->mem_size);
CHECK_ALLOCATION_ERROR(l->data)
}

if(e)
memcpy(l->data + l->elements * l->element_size, e, l->element_size);
else
memset(l->data + l->elements * l->element_size, 0, l->element_size);

return l->data + (l->elements++) * l->element_size;
}

void list_remove(struct list* l, int i) {
memmove(list_get(l, i), list_get(l, i + 1), (l->elements - (i + 1)) * l->element_size);
void list_remove(struct list* l, size_t i) {
assert(l != NULL && i < l->elements);

if(i < l->elements - 1)
memmove(list_get(l, i), list_get(l, i + 1), (l->elements - (i + 1)) * l->element_size);

l->elements--;

if(l->mem_size - 64 * l->element_size > 0
&& (l->elements + 1) * l->element_size < l->mem_size - 96 * l->element_size) {
l->mem_size -= l->element_size * 64;
Expand All @@ -44,14 +100,20 @@ void list_remove(struct list* l, int i) {
}

void list_clear(struct list* l) {
assert(l != NULL);

void* new = realloc(l->data, l->element_size * 64);

if(new) {
l->data = new;
l->mem_size = l->element_size * 64;
}

l->elements = 0;
}

int list_size(struct list* l) {
assert(l != NULL);

return l->elements;
}
15 changes: 11 additions & 4 deletions src/list.h
Expand Up @@ -3,14 +3,21 @@

struct list {
void* data;
int elements, element_size, mem_size;
size_t elements, element_size, mem_size;
};

enum list_traverse_direction {
LIST_TRAVERSE_FORWARD,
LIST_TRAVERSE_BACKWARD,
};

int list_created(struct list* l);
void list_create(struct list* l, int element_size);
void* list_get(struct list* l, int i);
void list_create(struct list* l, size_t element_size);
void list_free(struct list* l);
void* list_find(struct list* l, void* ref, enum list_traverse_direction dir, int (*cmp)(void* obj, void* ref));
void* list_get(struct list* l, size_t i);
void* list_add(struct list* l, void* e);
void list_remove(struct list* l, int i);
void list_remove(struct list* l, size_t i);
void list_clear(struct list* l);
int list_size(struct list* l);

Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Expand Up @@ -211,7 +211,7 @@ void display() {
matrix_select(matrix_projection);
matrix_identity();
matrix_perspective(camera_fov_scaled(), ((float)settings.window_width) / ((float)settings.window_height),
0.1F, settings.render_distance + CHUNK_SIZE * 4.0F + 128.0F);
0.1F, settings.render_distance + CHUNK_SIZE * 4.0F);
matrix_upload_p();

matrix_select(matrix_view);
Expand Down
3 changes: 1 addition & 2 deletions src/minheap.c
Expand Up @@ -39,10 +39,9 @@ void minheap_create(struct minheap* h) {
}

void minheap_clear(struct minheap* h) {
free(h->nodes);
h->index = 0;
h->length = 256;
h->nodes = malloc(sizeof(struct minheap_block) * h->length);
h->nodes = realloc(h->nodes, sizeof(struct minheap_block) * h->length);
}

void minheap_destroy(struct minheap* h) {
Expand Down
2 changes: 1 addition & 1 deletion src/ping.c
Expand Up @@ -127,7 +127,7 @@ void* ping_update(void* data) {

strcpy(e.country, "LAN");
e.ping = ceil((window_time() - ping_start) * 1000.0F);
snprintf(e.identifier, sizeof(e.identifier) - 1, "aos://%i:%i", from.host, from.port);
snprintf(e.identifier, sizeof(e.identifier) - 1, "aos://%u:%u", from.host, from.port);

JSON_Value* js = json_parse_string(tmp);
JSON_Object* root = json_value_get_object(js);
Expand Down
1 change: 1 addition & 0 deletions src/player.c
Expand Up @@ -502,6 +502,7 @@ void player_render(struct Player* p, int id, Ray* ray, char render, struct playe
kv6_boundingbox(&model_playerdead, &p->bb_2d);
matrix_pop();
}

return;
}

Expand Down
5 changes: 5 additions & 0 deletions src/tesselator.c
Expand Up @@ -19,6 +19,7 @@

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

#include "common.h"
#include "tesselator.h"
Expand Down Expand Up @@ -217,6 +218,8 @@ static void tesselator_emit_normals(struct tesselator* t, int8_t* normals) {
}

void tesselator_addi(struct tesselator* t, int16_t* coords, uint32_t* colors, int8_t* normals) {
assert(t->vertex_type == VERTEX_INT);

tesselator_check_space(t);
tesselator_emit_color(t, colors);
tesselator_emit_normals(t, normals);
Expand All @@ -235,6 +238,8 @@ void tesselator_addi(struct tesselator* t, int16_t* coords, uint32_t* colors, in
}

void tesselator_addf(struct tesselator* t, float* coords, uint32_t* colors, int8_t* normals) {
assert(t->vertex_type == VERTEX_FLOAT);

tesselator_check_space(t);
tesselator_emit_color(t, colors);
tesselator_emit_normals(t, normals);
Expand Down

0 comments on commit 4a92b1b

Please sign in to comment.