Skip to content

Commit

Permalink
General warning cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tek256 committed Dec 22, 2023
1 parent a3ef576 commit ac6318f
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 147 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Expand Up @@ -50,6 +50,11 @@ cmake_dependent_option(ASTERA_DEBUG_OUTPUT
"Enable Astera's internal debug output" ON
"CMAKE_BUILD_TYPE STREQUAL Debug" ON)

# Enables hardened compiler flags for astera
cmake_dependent_option(ASTERA_HARDEN_ENGINE
"Enable hardening compiler flags for astera " OFF
"CMAKE_BUILD_TYPE STREQUAL Release" ON)

# Enable the inclusion of pak writing in the library
cmake_dependent_option(ASTERA_PAK_WRITE
"Include pak writing functions in asset.c/h" ON
Expand All @@ -75,6 +80,7 @@ add_subdirectory(${PROJECT_SOURCE_DIR}/dep/glfw EXCLUDE_FROM_ALL)

# Get all of our source files into a list
file(GLOB sources CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/*.c)
#add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME} STATIC)

# Add our source files & nanovg
Expand All @@ -97,6 +103,7 @@ target_compile_definitions(${PROJECT_NAME}
PRIVATE
$<$<BOOL:${ASTERA_DEBUG_ENGINE}>:ASTERA_DEBUG_OUTPUT>
$<$<BOOL:${ASTERA_DEBUG_OUTPUT}>:ASTERA_DEBUG_OUTPUT>
$<$<BOOL:${ASTERA_HARDEN_ENGINE}>:ASTERA_HARDEN_ENGINE>
$<$<PLATFORM_ID:FreeBSD>:FreeBSD>
$<$<PLATFORM_ID:OpenBSD>:OpenBSD>
$<$<PLATFORM_ID:NetBSD>:NetBSD>
Expand Down Expand Up @@ -127,6 +134,12 @@ if(ASTERA_DEBUG_ENGINE)
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-g -fsanitize=address>)
endif()

if(ASTERA_HARDEN_ENGINE)
target_compile_options(${PROJECT_NAME}
PUBLIC
$<$<NOT:$<C_COMPILER_ID:MSVC>>: -O2 -Wall -Wformat=2 -Wconversion -Wtrampolines -Wimplicit-fallthrough -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS -fstrict-flex-arrays=3 -fstack-clash-protection -fstack-protector-strong -Wl,-z,nodlopen -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -fcf-protection=full>)
endif()

# Link against the various libraries we need
target_link_libraries(${PROJECT_NAME}
PUBLIC
Expand Down
12 changes: 8 additions & 4 deletions examples/CMakeLists.txt
Expand Up @@ -17,17 +17,21 @@ add_custom_target(${PROJECT_NAME}-examples-resources ALL
COMMENT "Copying resources directory"
VERBATIM)

find_package(OpenAL REQUIRED)

foreach(example IN LISTS entries)
get_filename_component(name "${example}" NAME_WLE)

set(BUILD_SHARED_LIBS OFF)



add_executable(${name})
target_sources(${name} PRIVATE ${example})
target_compile_definitions(${name}
PRIVATE
$<${opengl-deprecation}:GL_SILENCE_DEPRECATION>)

target_link_libraries(${name} PRIVATE ${PROJECT_NAME})
endforeach()
target_link_libraries(${name}
PRIVATE
${PROJECT_NAME})

endforeach()
37 changes: 37 additions & 0 deletions examples/config.c
@@ -0,0 +1,37 @@
/* CONFIG EXAMPLE: Using my terribly built ini reader/writer */

#include <astera/asset.h>
#include <astera/debug.h>
#include <astera/sys.h>
#include <time.h>

// add "INI:" to the start of debug outputs
char* log_prepend(void) {
return "INI: ";
}

int main(void) {
// add the prepend function to add before output lines
d_set_format_func(log_prepend);

s_table table = s_table_create(256, 32, 1);
s_table_add_int(&table, "souls", 42);

// Write to file
s_table_write(&table, "test.ini");
// Free in memory copy
s_table_free(&table);

// Get the file data
asset_t* table_data = asset_get("test.ini");

// Read file
table = s_table_get(table_data->data);

_l("souls: %s\n", s_table_find(&table, "souls"));

s_table_free(&table);
asset_free(table_data);

return 0;
}
8 changes: 7 additions & 1 deletion examples/debug.c
@@ -1,8 +1,14 @@
/* DEBUG EXAMPLE
This example is meant to show how to use the debug system within astera
*/

#include <astera/debug.h>
#include <time.h>

// add "YES:" to the start of debug outputs
char* log_prepend(void) { return "YES: "; }
char* log_prepend(void) {
return "YES: ";
}

int main(void) {
// enable timestampping in the log outputs
Expand Down
48 changes: 16 additions & 32 deletions examples/fighter.c
Expand Up @@ -15,8 +15,7 @@
#include <astera/input.h>
#include <astera/ui.h>

// If to draw hitboxes
//#define DRAW_HITBOXES
// #define DRAW_HITBOXES

#define USER_PREFS_FILE "user_prefs.ini"

Expand Down Expand Up @@ -149,14 +148,8 @@ typedef struct {
int health, is_idle, take_damage, allow_spawns, kill_count;
float damage_timer, damage_duration, attack_timer;
r_sprite sprite, sword, swoosh;
// I'm doing this bit for my friend dan so he can know what I'm talking about
// when I say most recent key press > standard if else statements for input
// direction
// What we're going to do is write out which key on each axis was most
// recently pressed, and if something was pressed sooner on that axis we
// switch to it instead of the old stale one
int hori, vert;
int left_priority, right_priority, up_priority, down_priority;
int hori, vert;
int left_priority, right_priority, up_priority, down_priority;
} player_t;

typedef struct {
Expand Down Expand Up @@ -252,7 +245,7 @@ r_shader load_shader(const char* vs, const char* fs) {
r_sheet load_sheet(const char* sheet_file, int sub_width, int sub_height) {
asset_t* sheet_data = asset_get(sheet_file);
r_sheet sheet = r_sheet_create_tiled(
sheet_data->data, sheet_data->data_length, sub_width, sub_height, 0, 0);
sheet_data->data, sheet_data->data_length, sub_width, sub_height, 0, 0);
asset_free(sheet_data);
return sheet;
}
Expand Down Expand Up @@ -331,12 +324,6 @@ int spawn_enemy(void) {
return 0;
}

// I think I might do a drop test/collision test for spawns and move them
// horizontally away from spawn if they collide with others, to prevent
// stacking on spawn, then once they're in the actual play area I'll probably
// do an enemy vs enemy collision test to keep it harder to kill giant mobs
// all at once

// up down left right
int dir = rand() % 4;

Expand Down Expand Up @@ -1388,9 +1375,6 @@ void clear_level(void) {
}
}

// brb -- water (also thinking about what equation I want to use for round
// number growth)

void init_level(void) {
// enemies
/*level.to_spawn =
Expand Down Expand Up @@ -1993,9 +1977,9 @@ void update(time_s delta) {
float move_factor = 0.0035f;
float dist_factor = 1.f / (30.f / (dist));
vec2 move_amount = {(level.player.center[0] - orb->center[0]) *
delta * dist_factor * move_factor,
(level.player.center[1] - orb->center[1]) *
delta * dist_factor * move_factor};
delta * dist_factor * move_factor,
(level.player.center[1] - orb->center[1]) *
delta * dist_factor * move_factor};
vec2_add(orb->center, orb->center, move_amount);
r_sprite_move(&orb->sprite, move_amount);
}
Expand Down Expand Up @@ -2025,7 +2009,7 @@ void update(time_s delta) {

float move_factor = 0.005f;
vec2 move = {level.player.center[0] - en->circle.center[0],
level.player.center[1] - en->circle.center[1]};
level.player.center[1] - en->circle.center[1]};
vec2_norm(move, move);
vec2_scale(move, move, en->move_speed * (delta * move_factor));
move_enemy(en, move);
Expand Down Expand Up @@ -2503,14 +2487,14 @@ int main(void) {

user_prefs = load_config();

a_ctx_info ctx_info = (a_ctx_info) {
.device = 0,
.max_layers = 2,
.max_buffers = 32,
.max_sfx = 32,
.max_fx = 2,
.max_filters = 2,
.pcm_size = 4096 * 4,
a_ctx_info ctx_info = (a_ctx_info){
.device = 0,
.max_layers = 2,
.max_buffers = 32,
.max_sfx = 32,
.max_fx = 2,
.max_filters = 2,
.pcm_size = 4096 * 4,
};

audio_ctx = a_ctx_create(ctx_info);
Expand Down
4 changes: 2 additions & 2 deletions examples/input.c
Expand Up @@ -146,7 +146,6 @@ void init_ui() {
ui_color_dup(text.color, white);
ui_color_dup(text.shadow, text_shadow_color);

// ok so use_box is obviously breaking something
text.use_box = 1;
vec2_clear(text.bounds);
text.bounds[0] = 0.7f;
Expand Down Expand Up @@ -450,7 +449,8 @@ void input(time_s delta) {
}
}

void update(time_s delta) {}
void update(time_s delta) {
}

int main(void) {
init();
Expand Down
8 changes: 4 additions & 4 deletions include/astera/asset.h
Expand Up @@ -46,8 +46,8 @@ typedef struct {
uint8_t is_mem;

union {
char* filepath;
void* ptr;
const char* filepath;
void* ptr;
} data;
} pak_wfile_t;

Expand Down Expand Up @@ -80,8 +80,8 @@ typedef struct {
uint32_t count;

union {
unsigned char* ptr;
const char* filepath;
const void* ptr;
const char* filepath;
} data;

/* data_size - the size of the pak file (bytes)
Expand Down
3 changes: 2 additions & 1 deletion include/astera/sys.h
Expand Up @@ -98,7 +98,8 @@ uint8_t s_table_add_float(s_table* table, char* key, float value);

/* Add a key/value to a table
* returns: 1 = success, 0 = fail */
uint8_t s_table_add(s_table* table, char* key, char* value);
uint8_t s_table_add(s_table* table, char* key, uint32_t key_len, char* value,
uint32_t value_len);

/* Remove the first key matched from table
* returns: 1 = success, 0 = fail */
Expand Down
8 changes: 4 additions & 4 deletions include/astera/ui.h
Expand Up @@ -389,9 +389,9 @@ typedef struct {
ui_leaf** draw_order;
uint16_t capacity, count;

uint32_t mouse_hover_id, cursor_id;
uint32_t mouse_hover_index, cursor_index, selected_index;
int loop;
int32_t mouse_hover_id, cursor_id;
int32_t mouse_hover_index, cursor_index, selected_index;
int loop;
} ui_tree;

typedef struct ui_ctx ui_ctx;
Expand Down Expand Up @@ -827,7 +827,7 @@ float ui_slider_prev_step(ui_slider* slider);
void ui_img_destroy(ui_ctx* ctx, ui_img* img);

/* Destroy a dropdown & its contents */
void ui_dropdown_destroy(ui_ctx* ctx, ui_dropdown* dropdown);
void ui_dropdown_destroy(ui_dropdown* dropdown);

void ui_button_destroy(ui_button* button);
void ui_option_destroy(ui_ctx* ctx, ui_option* option);
Expand Down
32 changes: 21 additions & 11 deletions src/audio.c
Expand Up @@ -14,7 +14,7 @@

#ifndef ASTERA_FUNC_DBG
#define ASTERA_FUNC_DBG(fmt, ...) \
printf("%s ", __func__); \
printf("%s ", __func__); \
printf(fmt, ##__VA_ARGS__);
#endif

Expand Down Expand Up @@ -439,7 +439,9 @@ const char* a_ctx_get_device(a_ctx* ctx, uint8_t* string_length) {
return name;
}

uint8_t a_can_play(a_ctx* ctx) { return ctx->allow; }
uint8_t a_can_play(a_ctx* ctx) {
return ctx->allow;
}

a_ctx_info a_ctx_info_default() {
return (a_ctx_info){
Expand Down Expand Up @@ -1159,7 +1161,7 @@ uint16_t a_song_create(a_ctx* ctx, unsigned char* data, uint32_t data_length,
song->req = 0;

ASTERA_FUNC_DBG("Unable to load vorbis, that sucks VORBIS Error: %i\n",
error);
error);

free(song->vorbis);

Expand All @@ -1172,8 +1174,8 @@ uint16_t a_song_create(a_ctx* ctx, unsigned char* data, uint32_t data_length,

if (max_buffer_size < (uint32_t)song->info.max_frame_size) {
ASTERA_FUNC_DBG("max_buffer_size is smaller than the listed max "
"frame size of this OGG file: %i vs %i\n",
max_buffer_size, song->info.max_frame_size);
"frame size of this OGG file: %i vs %i\n",
max_buffer_size, song->info.max_frame_size);

free(song->vorbis);
song->data = 0;
Expand Down Expand Up @@ -1202,7 +1204,7 @@ uint16_t a_song_create(a_ctx* ctx, unsigned char* data, uint32_t data_length,
free(song->vorbis);

ASTERA_FUNC_DBG("unable to allocate %i bytes for buffer IDs",
(buffers * sizeof(int32_t)));
(buffers * sizeof(int32_t)));

return 0;
}
Expand Down Expand Up @@ -1461,7 +1463,7 @@ uint8_t a_song_set_time(a_ctx* ctx, uint16_t song_id, time_s from_start) {

if (approx_sample > song->sample_count) {
ASTERA_FUNC_DBG("sample requested %i out of range of song %i\n",
approx_sample, song->sample_count);
approx_sample, song->sample_count);
return 0;
}

Expand Down Expand Up @@ -1680,7 +1682,9 @@ a_buf* a_buf_get_open(a_ctx* ctx) {
return 0;
}

float a_listener_get_gain(a_ctx* ctx) { return ctx->listener.gain; }
float a_listener_get_gain(a_ctx* ctx) {
return ctx->listener.gain;
}

void a_listener_get_pos(a_ctx* ctx, a_vec3 dst) {
a_vec3_dup(dst, ctx->listener.position);
Expand Down Expand Up @@ -2303,7 +2307,9 @@ a_timeline a_timeline_create(float* times, float* values,
return timeline;
}

void a_timeline_destroy(a_timeline* timeline) { free(timeline->keyframes); }
void a_timeline_destroy(a_timeline* timeline) {
free(timeline->keyframes);
}

a_timeline_view a_timeline_create_view(a_timeline* timeline) {
a_timeline_view view = (a_timeline_view){.timeline = timeline, 0};
Expand All @@ -2319,9 +2325,13 @@ a_timeline_view a_timeline_create_view(a_timeline* timeline) {
return view;
}

static float smooth_step(float t) { return t * t * (3.0f - 2.0f * t); }
static float smooth_step(float t) {
return t * t * (3.0f - 2.0f * t);
}

float a_timeline_get_value(a_timeline_view* view) { return view->value; }
float a_timeline_get_value(a_timeline_view* view) {
return view->value;
}

void a_timeline_update(a_timeline_view* view, float dt) {
if (view->output) {
Expand Down

0 comments on commit ac6318f

Please sign in to comment.