Skip to content

Commit fe36671

Browse files
authored
Miscelaneous fixes (#103)
* Fixes SDL_SetMetadata call * Enables and fixes compiler warnings
1 parent 8e3b412 commit fe36671

16 files changed

+77
-88
lines changed

CMakeLists.txt

+17-26
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ get_version_from_git()
1919
set(breakhack_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
2020
set(breakhack_MINOR_VERSION ${PROJECT_VERSION_MINOR})
2121
set(breakhack_PATCH_VERSION ${PROJECT_VERSION_PATCH})
22+
set(breakhack_VERSION ${PROJECT_VERSION})
23+
set(breakhack_FULL_VERSION ${FULL_VERSION})
2224
set(breakhack_RELEASE_TYPE "")
2325

2426
configure_file(
@@ -144,30 +146,27 @@ set(SDLIMAGE_WEBP OFF)
144146
set(SDLIMAGE_XCF OFF)
145147
set(SDLIMAGE_XPM OFF)
146148
set(SDLIMAGE_XV OFF)
147-
add_subdirectory(external/SDL_image)
148-
set(SDL_IMAGE_INCLUDE_DIR lib/SDL_image/include)
149+
add_subdirectory(external/SDL_image SYSTEM)
149150
set(SDL_IMAGE_LIBRARY SDL3_image-static)
150151

151152
# opusfile caused issues in macos build and we don't need it anyways
152153
set(SDLMIXER_OPUS OFF)
153-
add_subdirectory(external/SDL_mixer)
154-
set(SDL_MIXER_INCLUDE_DIR lib/SDL_mixer/include)
154+
add_subdirectory(external/SDL_mixer SYSTEM)
155155
set(SDL_MIXER_LIBRARY SDL3_mixer-static)
156156

157157
set(SDLTTF_VENDORED ON)
158-
add_subdirectory(external/SDL_ttf)
159-
set(SDL_TTF_INCLUDE_DIR lib/SDL_ttf/include)
158+
add_subdirectory(external/SDL_ttf SYSTEM)
160159
set(SDL_TTF_LIBRARY SDL3_ttf-static)
161160

162161
# Include lua lib
163-
add_subdirectory(lib/lua-5.3.5)
162+
add_subdirectory(lib/lua-5.3.5 SYSTEM)
164163
set(LUA_LIBRARIES lua)
165164
set(LUA_INCLUDE_DIR lib/lua-5.3.5/src)
166165

167166
# Include PHYSFS lib
168167
set(PHYSFS_BUILD_SHARED off CACHE INTERNAL "" FORCE)
169168
set(PHYSFS_BUILD_TEST off CACHE INTERNAL "" FORCE)
170-
add_subdirectory(lib/physfs-3.0)
169+
add_subdirectory(lib/physfs-3.0 SYSTEM)
171170
include_directories(lib/physfs-3.0/src)
172171
set(PHYSFS_LIBRARY physfs-static)
173172
set(PHYSFS_INCLUDE_DIR physfs-3.0/src)
@@ -195,16 +194,12 @@ else ()
195194
endif ()
196195

197196
set(INCLUDE_DIRS
198-
${PROJECT_BINARY_DIR}
199-
${SDL_INCLUDE_DIR}
200-
${SDL_IMAGE_INCLUDE_DIR}
201-
${SDL_TTF_INCLUDE_DIR}
202-
${SDL_MIXER_INCLUDE_DIR}
203-
${PHYSFS_INCLUDE_DIR}
204-
${LUA_INCLUDE_DIR}
205-
lib/sqlite3
206-
lib/bh_random/src
207-
lib/checksum/src
197+
PRIVATE ${PROJECT_BINARY_DIR}
198+
PRIVATE lib/sqlite3
199+
PRIVATE lib/bh_random/src
200+
PRIVATE lib/checksum/src
201+
SYSTEM ${PHYSFS_INCLUDE_DIR}
202+
SYSTEM ${LUA_INCLUDE_DIR}
208203
)
209204
# PROGRAMS:
210205
add_executable(${PROJECT_NAME})
@@ -214,11 +209,7 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)
214209
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIRS})
215210

216211
if (NOT MSVC)
217-
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS
218-
-std=gnu11 -pedantic -Wall -Wextra -Wshadow
219-
-Wpointer-arith -Wcast-qual -Wstrict-prototypes
220-
-Wmissing-prototypes -Wconversion -Wno-sign-conversion
221-
)
212+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wconversion -Wno-sign-conversion")
222213
if (NOT APPLE)
223214
add_definitions(-static -static-libgcc -static-libstdc++)
224215
endif ()
@@ -235,15 +226,15 @@ set_source_files_properties(lib/sqlite3/sqlite3.c COMPILE_FLAGS -w)
235226

236227
target_link_libraries(${PROJECT_NAME}
237228
${CMAKE_DL_LIBS} # Sqlite needs DL libs
229+
bh_random
230+
checksum
238231
${SDL_LIBRARY}
239232
${SDL_IMAGE_LIBRARY}
240233
${SDL_TTF_LIBRARY}
241234
${SDL_MIXER_LIBRARY}
242235
${LUA_LIBRARIES}
243236
${PHYSFS_LIBRARY}
244-
bh_random
245-
checksum
246-
)
237+
)
247238

248239
if (STEAM)
249240
target_link_libraries(${PROJECT_NAME}

src/config.h.in

+10-8
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@
1717
*/
1818

1919
#ifndef CONFIG_H_
20-
#define CONFIG_H_
20+
#define CONFIG_H_
2121

2222
#cmakedefine _WIN32 ${WIN32}
2323

24-
#define GAME_TITLE "@breakhack_GAME_TITLE@"
25-
#define MAJOR_VERSION @breakhack_MAJOR_VERSION@
26-
#define MINOR_VERSION @breakhack_MINOR_VERSION@
27-
#define PATCH_VERSION @breakhack_PATCH_VERSION@
28-
#define RELEASE_TYPE "@breakhack_RELEASE_TYPE@"
24+
#define GAME_TITLE "@breakhack_GAME_TITLE@"
25+
#define MAJOR_VERSION @breakhack_MAJOR_VERSION@
26+
#define MINOR_VERSION @breakhack_MINOR_VERSION@
27+
#define PATCH_VERSION @breakhack_PATCH_VERSION@
28+
#define VERSION_STR "@breakhack_VERSION@"
29+
#define VERSION_STR_FULL "@breakhack_FULL_VERSION@"
30+
#define RELEASE_TYPE "@breakhack_RELEASE_TYPE@"
2931

3032

3133
/* Checksums */
32-
#define SO_LIBSTEAM_CHECKSUM @breakhack_STEAMAPI_SO_CHECKSUM@
33-
#define DLL_LIBSTEAM_CHECKSUM @breakhack_STEAMAPI_DLL_CHECKSUM@
34+
#define SO_LIBSTEAM_CHECKSUM @breakhack_STEAMAPI_SO_CHECKSUM@
35+
#define DLL_LIBSTEAM_CHECKSUM @breakhack_STEAMAPI_DLL_CHECKSUM@
3436

3537
#endif // CONFIG_H_

src/item_builder.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ item_builder_build_key(unsigned int type)
199199
static void
200200
pickup_bloodlust(Item *item, Player *player)
201201
{
202+
(void) item;
203+
202204
gui_log("You drink a bloodlust potion. Rage pulses through your veins.");
203205
player->effects.effect = POTION_BLOODLUST;
204206
player->effects.damage_multiplier = 4;
@@ -208,9 +210,11 @@ pickup_bloodlust(Item *item, Player *player)
208210
static void
209211
pickup_frost(Item *item, Player *player)
210212
{
213+
(void) item;
214+
211215
gui_log("You drink a frost potion. Your skin is ice.");
212216
player->effects.effect = POTION_FROST;
213-
player->effects.damage_reduction = 2 * player->stats.lvl;
217+
player->effects.damage_reduction = (uint8_t)(2 * player->stats.lvl);
214218
sprite_set_color_mod(player->sprite, 94, 156, 255);
215219
}
216220

src/loot.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,23 @@ get_drop_callback(DropType type)
9999
}
100100

101101

102-
static inline void drop_item(Sprite *sprite, Position *drop_positions, size_t
103-
num_drop_positions, DropType type)
102+
static inline void drop_item(Sprite *sprite, Position *drop_positions,
103+
size_t num_drop_positions, DropType type)
104104
{
105105
/* Avoid FPE (division by zero) */
106106
Position drop_pos;
107107
if (num_drop_positions == 0) {
108108
drop_pos = sprite->pos;
109109
} else {
110-
drop_pos = drop_positions[get_random(num_drop_positions - 1)];
110+
drop_pos = drop_positions[get_random((uint32_t) num_drop_positions - 1)];
111111
}
112112

113113
/* Create an interpolation dest */
114114
Destination dest = {
115115
.pos = drop_pos,
116116
.angle = 0,
117117
.dim = DIM(32, 32),
118-
.time_ms = ITEM_DROP_TIME_MS + get_random(50),
118+
.time_ms = (float)(ITEM_DROP_TIME_MS + get_random(50)),
119119
.on_complete = get_drop_callback(type),
120120
};
121121

src/main.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,13 @@ static
122122
bool initSDL(void)
123123
{
124124
debug("Initializing SDL");
125+
SDL_SetAppMetadata(GAME_TITLE, VERSION_STR, "com.oliveshark.breakhack");
125126
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD | SDL_INIT_HAPTIC))
126127
{
127128
error("Could not initiate SDL3: %s", SDL_GetError());
128129
return false;
129130
}
130131

131-
Dimension dim = getScreenDimensions();
132-
133132
debug("Initializing SDL_ttf");
134133
if (!TTF_Init()) {
135134
error("Unable to initiate ttf library: %s",
@@ -144,7 +143,11 @@ bool initSDL(void)
144143
mixer_init();
145144

146145
char buffer[100] = { '\0' };
147-
m_sprintf(buffer, 100, "%s %d.%d.%d %s", GAME_TITLE, MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, RELEASE_TYPE);
146+
#ifdef DEBUG
147+
m_sprintf(buffer, 100, "%s %s %s", GAME_TITLE, VERSION_STR_FULL, RELEASE_TYPE);
148+
#else
149+
m_sprintf(buffer, 100, "%s %s %s", GAME_TITLE, VERSION_STR, RELEASE_TYPE);
150+
#endif
148151
gWindow = SDL_CreateWindow(buffer,
149152
SCREEN_WIDTH,
150153
SCREEN_HEIGHT, 0);
@@ -204,10 +207,6 @@ bool initSDL(void)
204207
SDL_StopTextInput(gWindow);
205208
}
206209

207-
memset(buffer, '\0', 100);
208-
sprintf(buffer, "%d.%d.%d", MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);
209-
SDL_SetAppMetadata(GAME_TITLE, buffer, "com.oliveshark.breakhack");
210-
211210
return true;
212211
}
213212

src/monster.c

+5-10
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#include "monster.h"
2727
#include "random.h"
2828
#include "gui.h"
29-
#include "item.h"
30-
#include "item_builder.h"
3129
#include "map.h"
3230
#include "particle_engine.h"
3331
#include "defines.h"
@@ -38,7 +36,6 @@
3836
#include "object.h"
3937
#include "mixer.h"
4038
#include "pos_heap.h"
41-
#include "loot.h"
4239

4340
static void
4441
monster_set_sprite_clip_for_current_state(Monster *m)
@@ -390,7 +387,7 @@ find_first_in_path(const Position *from, const Position *dest, const Position *s
390387
next = from[current.x + current.y * MAP_ROOM_WIDTH];
391388
}
392389

393-
Vector2d dir = { current.x - next.x, current.y - next.y };
390+
Vector2d dir = { (float)(current.x - next.x), (float)(current.y - next.y) };
394391
if (dir.x > 0)
395392
return RIGHT;
396393
else if (dir.x < 0)
@@ -402,7 +399,7 @@ find_first_in_path(const Position *from, const Position *dest, const Position *s
402399
}
403400

404401
/* Manhattan distance */
405-
#define MDIST(p1, p2) abs(p1.x - p2.x) + abs(p1.y - p2.y)
402+
#define MDIST(p1, p2) (uint16_t)(abs(p1.x - p2.x) + abs(p1.y - p2.y))
406403

407404
/**
408405
* \brief A* path finding algorithm
@@ -415,7 +412,6 @@ static Direction
415412
get_optimal_move_towards(Monster *m, RoomMatrix *rm, const Position dest)
416413
{
417414
Direction ret_val = INVALID;
418-
int x_dist, y_dist;
419415
const Position start = position_to_matrix_coords(&m->sprite->pos);
420416
const Vector2d directions[] = {
421417
VECTOR2D_UP,
@@ -453,8 +449,8 @@ get_optimal_move_towards(Monster *m, RoomMatrix *rm, const Position dest)
453449

454450
for (size_t i = 0; i < 4; i++) {
455451
Position next = {
456-
current.x + directions[i].x,
457-
current.y + directions[i].y,
452+
current.x + (int) directions[i].x,
453+
current.y + (int) directions[i].y,
458454
};
459455

460456
if (!position_equals(&next, &dest)) {
@@ -465,7 +461,7 @@ get_optimal_move_towards(Monster *m, RoomMatrix *rm, const Position dest)
465461
}
466462
}
467463

468-
uint32_t temp_score = 1 + gScore[current.x + current.y * WIDTH];
464+
uint16_t temp_score = 1 + gScore[current.x + current.y * WIDTH];
469465
if (temp_score < gScore[next.x + next.y * WIDTH]) {
470466
from[next.x + next.y * WIDTH] = current;
471467
gScore[next.x + next.y * WIDTH] = temp_score;
@@ -661,7 +657,6 @@ monster_move(Monster *m, RoomMatrix *rm, Map *map)
661657
}
662658

663659
Position originalMPos = position_to_matrix_coords(&m->sprite->pos);
664-
665660
SPACE_CLEAR_FLAG(&rm->spaces[originalMPos.x][originalMPos.y], TILE_OCCUPIED);
666661
rm->spaces[originalMPos.x][originalMPos.y].monster = NULL;
667662

src/particle_engine.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,10 @@ render_rect_particle(Particle *p, Camera *cam)
454454
SDL_SetRenderDrawBlendMode(cam->renderer, p->blend_mode);
455455

456456
SDL_FRect box = {
457-
pos.x,
458-
pos.y,
459-
p->particle.rect.dim.width,
460-
p->particle.rect.dim.height
457+
(float) pos.x,
458+
(float) pos.y,
459+
(float) p->particle.rect.dim.width,
460+
(float) p->particle.rect.dim.height
461461
};
462462
SDL_SetRenderDrawColor(cam->renderer,
463463
p->color.r,

src/physfsrwops.c

-13
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,6 @@ static SDL_IOStream *create_rwops(PHYSFS_File *handle)
155155
return retval;
156156
}
157157

158-
159-
SDL_IOStream *PHYSFSIO_makeRWops(PHYSFS_File *handle)
160-
{
161-
SDL_IOStream *retval = NULL;
162-
if (handle == NULL)
163-
SDL_SetError("NULL pointer passed to PHYSFSIO_makeRWops().");
164-
else
165-
retval = create_rwops(handle);
166-
167-
return retval;
168-
}
169-
170-
171158
SDL_IOStream *PHYSFSIO_openRead(const char *fname)
172159
{
173160
return create_rwops(PHYSFS_openRead(fname));

src/player.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void
6868
player_particle_bleed(Position pos, Dimension dim, void *userdata)
6969
{
7070
Player *p = userdata;
71-
float perc = (float) p->stats.hp / p->stats.maxhp;
71+
float perc = (float) p->stats.hp / (float) p->stats.maxhp;
7272
Uint32 particle_count = (Uint32) (20.0f * perc);
7373
particle_engine_bloodspray(pos, dim, particle_count);
7474
}
@@ -568,9 +568,9 @@ player_create(class_t class, Camera *cam)
568568
player->stateData.shopOwnerKiller = false;
569569

570570
ParticleEmitter *emitter = particle_emitter_create();
571-
emitter->timestep = 2000;
571+
emitter->timestep = 1000;
572572
emitter->enabled = false;
573-
emitter->particle_func = particle_engine_bleed;
573+
emitter->particle_func = player_particle_bleed;
574574
emitter->userdata = player;
575575
player->bleed_emitter = emitter;
576576

@@ -790,7 +790,7 @@ player_update(UpdateData *data)
790790
animation_update(player->swordAnimation);
791791

792792
uint32_t damage_taken = player->stats.maxhp - player->stats.hp;
793-
player->bleed_emitter->enabled = damage_taken >= player->stats.maxhp / 2;
793+
player->bleed_emitter->enabled = (int) damage_taken >= player->stats.maxhp / 2;
794794
}
795795

796796
static void

src/pos_heap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void swap(Node *a, Node *b) {
3636
*b = tmp;
3737
}
3838

39-
static void heapify(PHeap *ph, int i)
39+
static void heapify(PHeap *ph, size_t i)
4040
{
4141
if (ph->size <= 0) {
4242
return;

src/roommatrix.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef struct RoomSpace {
6565
#define SPACE_IS_LIGHTSOURCE(space) ((space) && (space->flags & TILE_LIGHTSOURCE))
6666
#define SPACE_IS_DAMAGING(space) ((space) && (space->flags & TILE_DAMAGE))
6767
#define SPACE_SET_FLAG(space, flag) ((space) && ((space)->flags |= flag))
68-
#define SPACE_CLEAR_FLAG(space, flag) ((space) && ((space)->flags &= ~flag))
68+
#define SPACE_CLEAR_FLAG(space, flag) ((space)->flags &= ~flag)
6969
#define SPACE_TOGGLE_FLAG(space, flag) ((space) && ((space)->flags ^= flag))
7070

7171
#define SPACE_IS_BLOCKED(space) (SPACE_IS_OCCUPIED(space) || (space)->monster)

src/skill.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ skill_backstab(Skill *skill, SkillData *data)
640640

641641
mixer_play_effect(SWING0 + get_random(2));
642642

643-
player_update_pos(data->player, data->direction.x * TILE_DIMENSION,
644-
data->direction.y * TILE_DIMENSION);
643+
player_update_pos(data->player, (uint32_t) data->direction.x * TILE_DIMENSION,
644+
(uint32_t) data->direction.y * TILE_DIMENSION);
645645
player_turn(data->player, &reverseDirection);
646646
animation_run(data->player->swordAnimation);
647647

0 commit comments

Comments
 (0)