diff --git a/.vimrc b/.vimrc index d43583d..2af4747 100644 --- a/.vimrc +++ b/.vimrc @@ -3,4 +3,4 @@ nnoremap :Make clean nnoremap :Make test nnoremap :!./build/breakhack -let g:syntastic_c_include_dirs = [ 'build' ] +let g:syntastic_c_include_dirs = [ 'build', '/usr/include/SDL2' ] diff --git a/CMakeLists.txt b/CMakeLists.txt index 34b4e2e..bd86a9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ if (NOT WIN32) -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes + -Wconversion -Wno-sign-conversion ) endif (NOT WIN32) diff --git a/src/gui.c b/src/gui.c index d29c1b1..7a72744 100644 --- a/src/gui.c +++ b/src/gui.c @@ -245,10 +245,11 @@ update_xp_bar(Gui *gui, ExperienceData *data) unsigned int xp_from_levelup = data->current - data->previousLevel; unsigned int xp_required_from_last_level = data->nextLevel - data->previousLevel; float xp_step = ((float)xp_required_from_last_level) / 32; // 4 * 8 - float xp_current_step = xp_from_levelup / xp_step; + float xp_current_step = (float) xp_from_levelup / xp_step; unsigned int partial_xp_block = ((unsigned int) xp_current_step) % 4; - unsigned int full_xp_blocks = (unsigned int) ((xp_current_step - partial_xp_block) / 4); + unsigned int full_xp_blocks = + (unsigned int) ((xp_current_step - (float) partial_xp_block) / 4); LinkedList *xp_bars = gui->xp_bar; unsigned int i = 0; diff --git a/src/hashtable.c b/src/hashtable.c index 19ae2fe..bdfa6d3 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -35,7 +35,7 @@ ht_create(unsigned int size) table = ec_malloc(sizeof(Hashtable)); table->size = size; - table->entries = ec_malloc(sizeof(Entry) * size); + table->entries = ec_malloc((unsigned int) sizeof(Entry) * size); for (i = 0; i < size; ++i) { table->entries[i] = NULL; @@ -73,12 +73,12 @@ entry_create(const char *key, void *value) void ht_set(Hashtable *table, const char *key, void *val) { - int hashkey = 0; + unsigned int hashkey = 0; Entry *newEntry = NULL; Entry *next; Entry *last = NULL; - hashkey = hash(table, key); + hashkey = hash(table, key); next = table->entries[hashkey]; @@ -117,7 +117,7 @@ ht_set(Hashtable *table, const char *key, void *val) void* ht_get(Hashtable *table, const char *key) { - int hashkey = 0; + unsigned int hashkey = 0; Entry *entry; hashkey = hash(table, key); diff --git a/src/main.c b/src/main.c index 9150505..1ac56f1 100644 --- a/src/main.c +++ b/src/main.c @@ -236,7 +236,7 @@ createMenu(Menu **menu, struct MENU_ITEM menu_items[], unsigned int size) *menu = menu_create(); for (unsigned int i = 0; i < size; ++i) { - int hcenter; + unsigned int hcenter; Sprite *s1 = sprite_create(); sprite_load_text_texture(s1, "assets/GUI/SDS_8x8.ttf", 0, 25); @@ -244,7 +244,7 @@ createMenu(Menu **menu, struct MENU_ITEM menu_items[], unsigned int size) C_MENU_DEFAULT, gRenderer); hcenter = (SCREEN_WIDTH/2) - (s1->textures[0]->dim.width/2); - s1->pos = (Position) { hcenter, 200 + (i*50) }; + s1->pos = (Position) { (int) hcenter, (int) 200 + (i*50) }; s1->fixed = true; Sprite *s2 = sprite_create(); @@ -252,7 +252,7 @@ createMenu(Menu **menu, struct MENU_ITEM menu_items[], unsigned int size) texture_load_from_text(s2->textures[0], menu_items[i].label, C_MENU_HOVER, gRenderer); - s2->pos = (Position) { hcenter, 200 + (i*50) }; + s2->pos = (Position) { (int) hcenter, (int) 200 + (i*50) }; s2->fixed = true; menu_item_add(*menu, s1, s2, menu_items[i].callback); @@ -562,7 +562,7 @@ void run(void) break; } - int ticks = timer_get_ticks(fpsTimer); + unsigned int ticks = timer_get_ticks(fpsTimer); if (ticks < 1000/60) SDL_Delay((1000/60) - ticks); timer_stop(fpsTimer); @@ -572,7 +572,7 @@ void run(void) else { oldTime = currentTime; currentTime = SDL_GetTicks(); - deltaTime = (currentTime - oldTime) / 1000.0; + deltaTime = (float) ((currentTime - oldTime) / 1000.0); } } diff --git a/src/map_lua.c b/src/map_lua.c index 00e2c3b..aacc3b0 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -185,11 +185,11 @@ lua_checkstats(lua_State *L, int index) lua_getfield(L, tableIndex, "def"); lua_getfield(L, tableIndex, "speed"); - int hp = luaL_checkinteger(L, -5); - int dmg = luaL_checkinteger(L, -4); - int atk = luaL_checkinteger(L, -3); - int def = luaL_checkinteger(L, -2); - int speed = luaL_checkinteger(L, -1); + int hp = (int) luaL_checkinteger(L, -5); + int dmg = (int) luaL_checkinteger(L, -4); + int atk = (int) luaL_checkinteger(L, -3); + int def = (int) luaL_checkinteger(L, -2); + int speed = (int) luaL_checkinteger(L, -1); // Reset the stack lua_pop(L, 6); diff --git a/src/particle_engine.c b/src/particle_engine.c index e30395f..e1d0ee9 100644 --- a/src/particle_engine.c +++ b/src/particle_engine.c @@ -84,7 +84,7 @@ particle_engine_bloodspray(Position pos, Dimension dim, unsigned int count) p = ec_malloc(sizeof(Particle)); p->pos = (Position) { x, y }; - p->velocity = (Vector2d) { xv, yv }; + p->velocity = (Vector2d) { (float) xv, (float) yv }; p->movetime = mt; p->lifetime = lt; p->dim = (Dimension) { w, h }; @@ -120,11 +120,11 @@ create_explosion(Position pos, Dimension dim, size_t c_count, ...) p = ec_malloc(sizeof(Particle)); p->pos = (Position) { x, y }; - p->velocity = (Vector2d) { xv, yv }; + p->velocity = (Vector2d) { (float) xv, (float) yv }; p->movetime = lt; p->lifetime = lt; p->dim = (Dimension) { 2, 2 }; - p->color = colors[get_random(c_count-1)]; + p->color = colors[get_random((unsigned int) c_count-1)]; linkedlist_append(&engine->particles, p); } } @@ -154,8 +154,8 @@ move_particle(Particle *particle, float deltaTime) if (!particle->movetime) return; - particle->pos.x += particle->velocity.x * deltaTime; - particle->pos.y += particle->velocity.y * deltaTime; + particle->pos.x += (int) (particle->velocity.x * deltaTime); + particle->pos.y += (int) (particle->velocity.y * deltaTime); } void diff --git a/src/roommatrix.c b/src/roommatrix.c index 4d46c08..3374977 100644 --- a/src/roommatrix.c +++ b/src/roommatrix.c @@ -239,7 +239,7 @@ roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam) }; SDL_SetRenderDrawColor(cam->renderer, - 0, 0, 0, light); + 0, 0, 0, (Uint8) light); SDL_RenderFillRect(cam->renderer, &box); #ifdef LIGHTMAPDEBUG diff --git a/src/util.c b/src/util.c index d98ff7c..9c73f42 100644 --- a/src/util.c +++ b/src/util.c @@ -134,7 +134,7 @@ fatal(const char *fmt, ...) } void -*ec_malloc(unsigned int size) +*ec_malloc(unsigned long size) { void *ptr; ptr = malloc(size); @@ -170,10 +170,10 @@ to_lower(const char *str) char *lcstr; unsigned int i; - lcstr = ec_malloc((strlen(str) + 1) * sizeof(char)); + lcstr = ec_malloc(((unsigned int) strlen(str) + 1) * sizeof(char)); for (i = 0; i < strlen(str); ++i) { - lcstr[i] = tolower(str[i]); + lcstr[i] = (char) tolower(str[i]); } lcstr[i] = '\0'; diff --git a/src/util.h b/src/util.h index 80bc5ce..a1940a3 100644 --- a/src/util.h +++ b/src/util.h @@ -32,7 +32,7 @@ void info(const char *fmt, ...); void * -ec_malloc(unsigned int size); +ec_malloc(unsigned long size); void m_strcpy(char *dest, size_t destsz, char *src);