From c604e53328db964d392c6c3d11d7b20f6c8d89f3 Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Wed, 5 Jun 2024 23:22:35 +0200 Subject: [PATCH] Fix warnings that turned into errors in GCC 14 and some more Principia now compiles without needing to downgrade any errors again! --- CMakeLists.txt | 11 +---- src/luasocket/inet.c | 4 +- src/luasocket/socket.h | 2 + src/luasocket/udp.c | 4 +- src/luasocket/usocket.c | 2 +- src/luasocket/wsocket.c | 2 +- src/src/fxemitter.hh | 1 - src/src/game.cc | 4 ++ src/src/game.hh | 2 +- src/src/main.cc | 21 ++++------ src/src/noise.cc | 12 ------ src/src/pkgman.cc | 12 +++--- src/src/settings.cc | 11 ++--- src/src/simplebg.hh | 4 +- src/src/ui_gtk3.hh | 10 ++++- src/tms/core/framebuffer.c | 12 +++--- src/tms/core/gbuffer.c | 80 ++++++++++------------------------- src/tms/core/graph.c | 39 ++++++++--------- src/tms/core/hash.c | 4 +- src/tms/core/model.c | 8 ++-- src/tms/core/pipeline.c | 85 +++++++++++--------------------------- src/tms/core/shader.c | 2 +- src/tms/core/texture.c | 66 ++++++++++++++--------------- src/tms/modules/3ds.c | 4 +- 24 files changed, 151 insertions(+), 251 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4904f79c..9def915b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,16 +264,7 @@ endif() add_definitions(-DTMS_BACKEND_${TMS_FORMFACTOR} -DTMS_BACKEND_${TMS_BACKEND}) -# Downgrade int-conversion and incompatible(-function)-pointer-types, which are errors -# in both GCC and Clang now, into regular warnings. - -set(COMMON_FLAGS "-ffast-math -Wno-error=int-conversion") - -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(COMMON_FLAGS "${COMMON_FLAGS} -Wno-error=incompatible-function-pointer-types") -else() - set(COMMON_FLAGS "${COMMON_FLAGS} -Wno-error=incompatible-pointer-types") -endif() +set(COMMON_FLAGS "-ffast-math") set(COMMON_FLAGS_DEBUG "${COMMON_FLAGS} -O0 -ggdb -DDEBUG=1") set(COMMON_FLAGS_RELEASE "${COMMON_FLAGS} -DNDEBUG=1 -fomit-frame-pointer") diff --git a/src/luasocket/inet.c b/src/luasocket/inet.c index 1a411f65e..edf3766da 100644 --- a/src/luasocket/inet.c +++ b/src/luasocket/inet.c @@ -251,7 +251,7 @@ int inet_meth_getpeername(lua_State *L, p_socket ps, int family) port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); if (err) { lua_pushnil(L); - lua_pushstring(L, gai_strerror(err)); + lua_pushstring(L, LUA_GAI_STRERROR(err)); return 2; } lua_pushstring(L, name); @@ -285,7 +285,7 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family) name, INET6_ADDRSTRLEN, port, 6, NI_NUMERICHOST | NI_NUMERICSERV); if (err) { lua_pushnil(L); - lua_pushstring(L, gai_strerror(err)); + lua_pushstring(L, LUA_GAI_STRERROR(err)); return 2; } lua_pushstring(L, name); diff --git a/src/luasocket/socket.h b/src/luasocket/socket.h index 63573de5d..393efb319 100644 --- a/src/luasocket/socket.h +++ b/src/luasocket/socket.h @@ -16,8 +16,10 @@ \*=========================================================================*/ #ifdef _WIN32 #include "wsocket.h" +#define LUA_GAI_STRERROR gai_strerrorA #else #include "usocket.h" +#define LUA_GAI_STRERROR gai_strerror #endif /*=========================================================================*\ diff --git a/src/luasocket/udp.c b/src/luasocket/udp.c index a9f23930a..7a02b0e77 100644 --- a/src/luasocket/udp.c +++ b/src/luasocket/udp.c @@ -178,7 +178,7 @@ static int meth_sendto(lua_State *L) { err = getaddrinfo(ip, port, &aihint, &ai); if (err) { lua_pushnil(L); - lua_pushstring(L, gai_strerror(err)); + lua_pushstring(L, LUA_GAI_STRERROR(err)); return 2; } timeout_markstart(tm); @@ -248,7 +248,7 @@ static int meth_receivefrom(lua_State *L) INET6_ADDRSTRLEN, portstr, 6, NI_NUMERICHOST | NI_NUMERICSERV); if (err) { lua_pushnil(L); - lua_pushstring(L, gai_strerror(err)); + lua_pushstring(L, LUA_GAI_STRERROR(err)); return 2; } lua_pushlstring(L, buffer, got); diff --git a/src/luasocket/usocket.c b/src/luasocket/usocket.c index 8b789fc7e..536a0419f 100644 --- a/src/luasocket/usocket.c +++ b/src/luasocket/usocket.c @@ -444,7 +444,7 @@ const char *socket_gaistrerror(int err) { case EAI_SERVICE: return "service not supported for socket type"; case EAI_SOCKTYPE: return "ai_socktype not supported"; case EAI_SYSTEM: return strerror(errno); - default: return gai_strerror(err); + default: return LUA_GAI_STRERROR(err); } } #endif diff --git a/src/luasocket/wsocket.c b/src/luasocket/wsocket.c index 75ff3002a..c95e3b3bd 100644 --- a/src/luasocket/wsocket.c +++ b/src/luasocket/wsocket.c @@ -429,7 +429,7 @@ const char *socket_gaistrerror(int err) { #ifdef EAI_SYSTEM case EAI_SYSTEM: return strerror(errno); #endif - default: return gai_strerror(err); + default: return LUA_GAI_STRERROR(err); } } #endif diff --git a/src/src/fxemitter.hh b/src/src/fxemitter.hh index 1abad5e77..9f28d057f 100644 --- a/src/src/fxemitter.hh +++ b/src/src/fxemitter.hh @@ -219,7 +219,6 @@ class break_effect : public base_effect private: struct piece pieces[3]; b2Vec2 trigger_point; - bool played_sound; public: break_effect(b2Vec2 pos, int layer); diff --git a/src/src/game.cc b/src/src/game.cc index fec329563..7b30a2d08 100644 --- a/src/src/game.cc +++ b/src/src/game.cc @@ -11442,6 +11442,8 @@ update_entity_id_changed(uint32_t old_id, uint32_t new_id, std::map debug_lines; + void clamp_entities(); #endif void render_num(float x, float y, int iw, int ih, float num, int precision=2, float extra_scale=0.f, bool render_background=true); @@ -1162,7 +1163,6 @@ class game : public pscreen void restart_level(); void submit_score(); void destroy_possible_mover(entity *e); - void clamp_entities(); void render_help_icon(const std::set &set, float off_x, float off_y); bool check_click_help_icon(const std::set &set, float off_x, float off_y, b2Vec2 click_pos, struct principia_action click_action); diff --git a/src/src/main.cc b/src/src/main.cc index a58ce329e..d1c3468be 100644 --- a/src/src/main.cc +++ b/src/src/main.cc @@ -1,5 +1,6 @@ #include "game.hh" #include "main.hh" +#include "tms/core/err.h" #include "version.hh" #include "loading_screen.hh" #include "soundmanager.hh" @@ -89,7 +90,6 @@ static struct tms_fb *ao_fb; static char featured_data_path[1024]; static char featured_data_time_path[1024]; static char cookie_file[1024]; -static char username[256]; struct header_data { char *error_message; @@ -123,15 +123,17 @@ static uint32_t _publish_lvl_community_id; static uint32_t _publish_lvl_id; static bool _publish_lvl_with_pkg = false; static bool _publish_lvl_set_locked = false; -static uint8_t _publish_lvl_pkg_index = 0; static bool _publish_lvl_lock = false; static volatile bool _publish_lvl_uploading = false; static bool _publish_lvl_uploading_error = false; +#ifdef BUILD_PKGMGR /* Publish PKG variables */ +static uint8_t _publish_lvl_pkg_index = 0; static uint32_t _publish_pkg_id; static volatile bool _publish_pkg_done = false; static bool _publish_pkg_error = false; +#endif /* Submit score variables */ static bool _submit_score_done = false; @@ -314,7 +316,9 @@ static int edit_loader(int step); static int pkg_loader(int step); static int publish_loader(int step); static int submit_score_loader(int step); +#ifdef BUILD_PKGMGR static int publish_pkg_loader(int step); +#endif static int _publish_level(void *p); static int _download_level(void *p); static int _check_version_code(void *_unused); @@ -1841,8 +1845,6 @@ _download_level(void *p) _play_header_data.error_action = 0; CURLcode res; - uint32_t crc=0; - struct stat file_stat; int arg = (intptr_t)p; int type = LEVEL_DB; @@ -2221,7 +2223,6 @@ write_memory_cb(void *contents, size_t size, size_t nmemb, void *userp) static int _check_version_code(void *_unused) { - int res = T_OK; CURLcode r; struct MemoryStruct chunk; @@ -2258,11 +2259,9 @@ _check_version_code(void *_unused) } } else { tms_errorf("could not check for latest version: %s", curl_easy_strerror(r)); - res = 1; - } + } } else { tms_errorf("unable to initialize curl handle!"); - res = 1; } unlock_curl("check_version_code"); @@ -2719,7 +2718,6 @@ _publish_level(void *p) { uint32_t level_id = _publish_lvl_id; int community_id = 0; - int error = 0; _publish_lvl_community_id = 0; _publish_lvl_uploading_error = false; @@ -2843,8 +2841,6 @@ _submit_score(void *p) { tms_assertf(W->is_playing(), "submit score called when the level was paused"); - int error = 0; - CURLcode r; char data_path[1024]; @@ -3058,7 +3054,6 @@ _register(void *p) { struct register_data *data = static_cast(p); int res = T_OK; - int num_tries = 0; CURLcode r; @@ -3275,7 +3270,6 @@ submit_score_loader(int step) #endif static Uint32 loader_times[32] = {0,}; -static Uint32 total_load = 0; static const char *load_step_name[] = { /* 0 */ "Initialize atlases", @@ -3364,7 +3358,6 @@ initial_loader(int step) static uint32_t last_time = SDL_GetTicks(); char tmp[512]; - Uint32 ss = SDL_GetTicks(); int retval = LOAD_CONT; switch (step) { diff --git a/src/src/noise.cc b/src/src/noise.cc index 64214fa79..306e5b0a6 100644 --- a/src/src/noise.cc +++ b/src/src/noise.cc @@ -85,18 +85,6 @@ static float grad2( int hash, float x, float y ) { return ((h&1)? -u : u) + ((h&2)? -2.0f*v : 2.0f*v); } - /* A lookup table to traverse the simplex around a given point in 4D. */ - /* Details can be found where this table is used, in the 4D noise method. */ - /* TODO: This should not be required, backport it from Bill's GLSL code! */ - static unsigned char simplex[64][4] = { - {0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0}, - {0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0}, - {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}, - {1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0}, - {1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0}, - {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}, - {2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0}, - {2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}}; void _noise_init_perm(unsigned long seed) diff --git a/src/src/pkgman.cc b/src/src/pkgman.cc index d2620cccf..4445b1102 100644 --- a/src/src/pkgman.cc +++ b/src/src/pkgman.cc @@ -1269,10 +1269,10 @@ lvledit::print_gids() state_size = lb.r_uint32(); /* state size */ } - float posx = lb.r_float(); /* pos.x */ - float posy = lb.r_float(); /* pos.y */ - float angle = lb.r_float(); /* angle */ - uint8_t layer = (int)lb.r_uint8(); /* layer */ + (void)lb.r_float(); /* pos.x */ + (void)lb.r_float(); /* pos.y */ + (void)lb.r_float(); /* angle */ + (void)lb.r_uint8(); /* layer */ if (this->lvl.version >= LEVEL_VERSION_1_5) { lb.r_uint64(); /* state flags */ @@ -1286,9 +1286,9 @@ lvledit::print_gids() /* skip state buffer */ lb.rp += state_size; } else { - (bool)lb.r_uint8(); /* axisrot */ + (void)lb.r_uint8(); /* axisrot */ if (this->lvl.version >= 10) { - (bool)lb.r_uint8(); /* moveable */ + (void)lb.r_uint8(); /* moveable */ } } diff --git a/src/src/settings.cc b/src/src/settings.cc index 0ddfb66dd..e1d739c86 100644 --- a/src/src/settings.cc +++ b/src/src/settings.cc @@ -18,10 +18,6 @@ _settings::init() { this->_data.clear(); - /* calculate "optimal" shadow map resolution */ - double w2 = log2((double)_tms.window_width); - double h2 = log2((double)_tms.window_height); - /** -Graphics **/ this->add("debug", S_BOOL, false); this->add("postprocess", S_BOOL, false); @@ -32,6 +28,10 @@ _settings::init() this->add("blur_shadow_map", S_BOOL, false); this->add("swap_shadow_map", S_BOOL, false); #ifdef TMS_BACKEND_MOBILE + /* calculate "optimal" shadow map resolution */ + double w2 = log2((double)_tms.window_width); + double h2 = log2((double)_tms.window_height); + int rw = (int)exp2(roundf(w2)) / 2; int rh = (int)exp2(roundf(h2)) / 2; @@ -161,7 +161,6 @@ _settings::load(void) return false; } - int r; char buf[256]; while (fgets(buf, 256, fh) != NULL) { @@ -174,8 +173,6 @@ _settings::load(void) bool on_key = true; for (int i = 0; i < sz; ++i) { - char *c = &buf[i]; - if (buf[i] == '\n' || buf[i] == ' ') continue; if (k == 62) { diff --git a/src/src/simplebg.hh b/src/src/simplebg.hh index b6d570cb7..30260352c 100644 --- a/src/src/simplebg.hh +++ b/src/src/simplebg.hh @@ -2,7 +2,7 @@ #include "entity.hh" -static uint32_t +static inline uint32_t pack_rgba(float _r, float _g, float _b, float _a) { int r = _r * 255.f; @@ -13,7 +13,7 @@ pack_rgba(float _r, float _g, float _b, float _a) return (uint32_t)(r << 24 | g << 16 | b << 8 | a); } -static void +static inline void unpack_rgba(uint32_t color, float *r, float *g, float *b, float *a) { int _r = (color >> 24) & 0xFF; diff --git a/src/src/ui_gtk3.hh b/src/src/ui_gtk3.hh index c90109d0e..705b8e4fd 100644 --- a/src/src/ui_gtk3.hh +++ b/src/src/ui_gtk3.hh @@ -1,6 +1,10 @@ #ifdef TMS_BACKEND_PC +// fuckgtk3 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + #include #include @@ -572,7 +576,7 @@ struct gtk_level_property gtk_level_properties[] = { "Disable the roaming robots ability to change layer." }, { LVL_CHUNKED_LEVEL_LOADING, "Chunked level loading", - "" }, + "Splits up the level into chunks, leading to better performance for large levels." }, { LVL_DISABLE_CAVEVIEW, "Disable adventure caveview", "Disable the caveview which appears when the adventure robot is in layer two, with terrain in front of him in layer three." }, @@ -581,7 +585,7 @@ struct gtk_level_property gtk_level_properties[] = { "Disable the rocket from triggering any explosives when contact with its flames occurs." }, { LVL_STORE_SCORE_ON_GAME_OVER, "Store high score on game over", - "" }, + "Allow players to submit a high score even if they did not win the level." }, { LVL_ALLOW_HIGH_SCORE_SUBMISSIONS, "Allow high score submissions", "Allow players to submit their high scores to be displayed on your levels community page." }, @@ -11761,4 +11765,6 @@ ui::alert(const char *text, uint8_t alert_type/*=ALERT_INFORMATION*/) gdk_display_flush(gdk_display_get_default()); } +#pragma GCC diagnostic pop + #endif diff --git a/src/tms/core/framebuffer.c b/src/tms/core/framebuffer.c index c8911a0fe..e8a19d4ab 100644 --- a/src/tms/core/framebuffer.c +++ b/src/tms/core/framebuffer.c @@ -27,8 +27,6 @@ static struct tms_program *blur5x5v_512_program; static struct tms_program *blur5x5h_512_program; static struct tms_program *blur5x5v_256_program; static struct tms_program *blur5x5h_256_program; -static struct tms_program *blur5x5v_128_program; -static struct tms_program *blur5x5h_128_program; static struct tms_program *blur3x3v_program; static struct tms_program *blur3x3h_program; @@ -548,12 +546,12 @@ tms_fb_init(struct tms_fb* fb) tms_assertf((ierr = glGetError()) == 0, "gl error %d before tms_fb_init", ierr); #ifdef TMS_BACKEND_WINDOWS if (__glewGenFramebuffers) { - __glewGenFramebuffers(fb->double_buffering ? 2 : 1, &fb->fb_o); + __glewGenFramebuffers(fb->double_buffering ? 2 : 1, fb->fb_o); } else { - __glewGenFramebuffersEXT(fb->double_buffering ? 2 : 1, &fb->fb_o); + __glewGenFramebuffersEXT(fb->double_buffering ? 2 : 1, fb->fb_o); } #else - glGenFramebuffers(fb->double_buffering ? 2 : 1, &fb->fb_o); + glGenFramebuffers(fb->double_buffering ? 2 : 1, fb->fb_o); #endif tms_assertf((ierr = glGetError()) == 0, "gl error %d after tms_fb_init", ierr); } @@ -569,7 +567,7 @@ tms_fb_free(struct tms_fb *fb) glDeleteTextures(1, &fb->fb_texture[x][y]); } - glDeleteFramebuffers(fb->double_buffering ? 2 : 1, &fb->fb_o); + glDeleteFramebuffers(fb->double_buffering ? 2 : 1, fb->fb_o); free(fb); } @@ -856,7 +854,7 @@ tms_fb_add_texture(struct tms_fb *fb, int format, } #if !defined TMS_BACKEND_ANDROID && !defined TMS_BACKEND_IOS - glDrawBuffers(fb->num_textures+1, &bufs); + glDrawBuffers(fb->num_textures+1, bufs); tms_assertf((ierr = glGetError()) == 0, "gl error %d in tms_fb_add_texture %d 15", ierr, x); #endif } diff --git a/src/tms/core/gbuffer.c b/src/tms/core/gbuffer.c index 2235319ac..f19efdaa1 100644 --- a/src/tms/core/gbuffer.c +++ b/src/tms/core/gbuffer.c @@ -27,15 +27,7 @@ tms_gbuffer_init(struct tms_gbuffer *b, size_t size) b->usize = 0; b->target = GL_ARRAY_BUFFER; -#ifdef TMS_BACKEND_WINDOWS - if (GLEW_VERSION_1_5) { - glGenBuffers(1, &b->vbo); - } else { - glGenBuffersARB(1, &b->vbo); - } -#else - glGenBuffers(1, &b->vbo); -#endif + glGenBuffers(1, &b->vbo); } struct tms_gbuffer* @@ -66,66 +58,36 @@ tms_gbuffer_set_usage(struct tms_gbuffer *b, int usage) int tms_gbuffer_upload(struct tms_gbuffer *b) { -#ifdef TMS_BACKEND_WINDOWS - if (GLEW_VERSION_1_5) { - glBindBuffer(b->target, b->vbo); - glBufferData(b->target, b->size, b->buf, b->usage); - } else { - glBindBufferARB(b->target, b->vbo); - glBufferDataARB(b->target, b->size, b->buf, b->usage); - } -#else - glBindBuffer(b->target, b->vbo); - glBufferData(b->target, b->size, b->buf, b->usage); -#endif - - b->usize = b->size; - - //if (b->size > 24) { - //tms_infof("uploading : %d", b->size); - //} - - return T_OK; + glBindBuffer(b->target, b->vbo); + glBufferData(b->target, b->size, b->buf, b->usage); + + b->usize = b->size; + + //if (b->size > 24) { + //tms_infof("uploading : %d", b->size); + //} + + return T_OK; } int tms_gbuffer_upload_partial(struct tms_gbuffer *b, size_t size) { -#ifdef TMS_BACKEND_WINDOWS - if (GLEW_VERSION_1_5) { - glBindBuffer(b->target, b->vbo); - glBufferData(b->target, size, b->buf, b->usage); - } else { - glBindBufferARB(b->target, b->vbo); - glBufferDataARB(b->target, size, b->buf, b->usage); - } -#else - glBindBuffer(b->target, b->vbo); - glBufferData(b->target, size, b->buf, b->usage); -#endif - - b->usize = size; - - return T_OK; + glBindBuffer(b->target, b->vbo); + glBufferData(b->target, size, b->buf, b->usage); + + b->usize = size; + + return T_OK; } int tms_gbuffer_update(struct tms_gbuffer *b, size_t start_offs, size_t num_bytes) { -#ifdef TMS_BACKEND_WINDOWS - if (GLEW_VERSION_1_5) { - glBindBuffer(b->target, b->vbo); - glBufferData(b->target, start_offs, num_bytes, b->buf+start_offs); - } else { - glBindBufferARB(b->target, b->vbo); - glBufferDataARB(b->target, start_offs, num_bytes, b->buf+start_offs); - } -#else - glBindBuffer(b->target, b->vbo); - glBufferData(b->target, start_offs, num_bytes, b->buf+start_offs); -#endif - - return T_OK; + glBindBuffer(b->target, b->vbo); + glBufferData(b->target, num_bytes, b->buf + start_offs, GL_DYNAMIC_DRAW); + + return T_OK; } void diff --git a/src/tms/core/graph.c b/src/tms/core/graph.c index 1df51cdd5..c60273c16 100644 --- a/src/tms/core/graph.c +++ b/src/tms/core/graph.c @@ -7,33 +7,34 @@ #pragma GCC push_options #pragma GCC optimize ("O0") -static int flat(struct tms_rstate *state, void *); static int enable_blending(struct tms_rstate *state, void *blend); +static int bind_program(struct tms_rstate *state, struct tms_program *program); static int bind_texture0(struct tms_rstate *state, struct tms_texture *texture); static int bind_texture1(struct tms_rstate *state, struct tms_texture *texture); static int bind_texture2(struct tms_rstate *state, struct tms_texture *texture); static int bind_texture3(struct tms_rstate *state, struct tms_texture *texture); static int bind_varray(struct tms_rstate *state, struct tms_varray *va); static int bind_mesh(struct tms_rstate *state, struct tms_gbuffer *m); -static int bind_program(struct tms_rstate *state, struct tms_program *program) /*__attribute__((optimize("O0")))*/; +static int flat(struct tms_rstate *state, void *); static int bind_prio(struct tms_rstate *state, void *val); + static int render_entities(struct tms_rstate *state, struct tms_entity **ee, int count); -static int render_branch(struct tms_rstate *s, struct _branch *b, int *sort_v, int depth) /*__attribute__((optimize("O0")))*/; +static int render_branch(struct tms_rstate *s, struct _branch *b, int *sort_v, int depth); static void branch_remove_entity(struct tms_graph *g, struct _branch *b, struct tms_entity *e); static inline struct _branch * get_branch(struct tms_graph *g, struct tms_entity *e); static const int (*sort_fns[])(void*, void*) = { - enable_blending, - bind_program, - bind_texture0, - bind_texture1, - bind_texture2, - bind_texture3, - bind_varray, - bind_mesh, - flat, - bind_prio, - bind_prio, + (const int (*)(void*, void*)) enable_blending, + (const int (*)(void*, void*)) bind_program, + (const int (*)(void*, void*)) bind_texture0, + (const int (*)(void*, void*)) bind_texture1, + (const int (*)(void*, void*)) bind_texture2, + (const int (*)(void*, void*)) bind_texture3, + (const int (*)(void*, void*)) bind_varray, + (const int (*)(void*, void*)) bind_mesh, + (const int (*)(void*, void*)) flat, + (const int (*)(void*, void*)) bind_prio, + (const int (*)(void*, void*)) bind_prio, }; /* 1 or 0 depending on whether the sorting @@ -95,7 +96,7 @@ void tms_graph_set_sort_callback(struct tms_graph *g, int sort, int (*fun)(struct tms_rstate* rstate, void* value)) { - g->sort_fns[sort] = fun; + g->sort_fns[sort] = (int (*)(void *, void *))fun; } int @@ -175,7 +176,7 @@ get_branch(struct tms_graph *g, struct tms_entity *e) br->nodes.as_branch[0].next = calloc(1, sizeof(struct _branch)); br->nodes.as_branch[0].val = 0; br->nodes.as_branch[1].next = calloc(1, sizeof(struct _branch)); - br->nodes.as_branch[1].val = 1; + br->nodes.as_branch[1].val = (void *)(intptr_t)1; br->fixed = 1; br->num_nodes = 2; } @@ -190,9 +191,9 @@ get_branch(struct tms_graph *g, struct tms_entity *e) case TMS_SORT_TEXTURE3: refval = e->material->pipeline[g->p].texture[3]; break; case TMS_SORT_VARRAY: refval = e->mesh->vertex_array; break; case TMS_SORT_MESH: refval = e->mesh->indices; break; - case TMS_SORT_PRIO: refval = e->prio; break; - case TMS_SORT_PRIO_BIASED: refval = e->prio+e->prio_bias; break; - case TMS_SORT_BLENDING: refval = e->material->pipeline[g->p].blend_mode; break; + case TMS_SORT_PRIO: refval = (void *)(intptr_t)e->prio; break; + case TMS_SORT_PRIO_BIASED: refval = (void *)(intptr_t)e->prio+e->prio_bias; break; + case TMS_SORT_BLENDING: refval = (void *)(intptr_t)e->material->pipeline[g->p].blend_mode; break; default: tms_fatalf("invalid scene sorting"); } diff --git a/src/tms/core/hash.c b/src/tms/core/hash.c index 76905dfee..b4232744a 100644 --- a/src/tms/core/hash.c +++ b/src/tms/core/hash.c @@ -93,7 +93,7 @@ rm_ptrdata(struct thash *h, void *key) static void* get_ptrdata(struct thash *h, void *key) { - struct thash_entry_ptrdata **tbl = h->tbl; + struct thash_entry_ptrdata **tbl = (struct thash_entry_ptrdata **)h->tbl; uint32_t hash = h->hash_fn(&key, sizeof(void*)) & h->mask; struct thash_entry_ptrdata *e = tbl[hash]; @@ -109,7 +109,7 @@ get_ptrdata(struct thash *h, void *key) static int add_ptrdata(struct thash *h, void *key, void *data) { - struct thash_entry_ptrdata **tbl = h->tbl; + struct thash_entry_ptrdata **tbl = (struct thash_entry_ptrdata **)h->tbl; uint32_t hash = h->hash_fn(&key, sizeof(void*)) & h->mask; struct thash_entry_ptrdata *e = tbl[hash]; diff --git a/src/tms/core/model.c b/src/tms/core/model.c index 053b62327..f5035cb02 100644 --- a/src/tms/core/model.c +++ b/src/tms/core/model.c @@ -68,11 +68,11 @@ tms_model_shift_mesh_uv(struct tms_model *m, tms_gbuffer_realloc(m->indices, m->indices->size + mesh->i_count*sizeof(uint16_t)); tms_gbuffer_realloc(m->vertices, m->vertices->size + mesh->v_count*sizeof(struct vertex)); - struct vertex *v = m->vertices->buf+mesh->v_start; - uint16_t *i = m->indices->buf+mesh->i_start*sizeof(uint16_t); + struct vertex *v = (struct vertex *)(m->vertices->buf + mesh->v_start); + uint16_t *i = (uint16_t *)(m->indices->buf + mesh->i_start * sizeof(uint16_t)); - struct vertex *nv = m->vertices->buf+vsz; - uint16_t *ni = m->indices->buf+osz; + struct vertex *nv = (struct vertex *)(m->vertices->buf + vsz); + uint16_t *ni = (uint16_t *)(m->indices->buf + osz); for (int x=0; xi_count; x++) { ni[x] = (i[x] - last_base) + base; diff --git a/src/tms/core/pipeline.c b/src/tms/core/pipeline.c index 295defb34..6ebc0178c 100644 --- a/src/tms/core/pipeline.c +++ b/src/tms/core/pipeline.c @@ -60,10 +60,10 @@ tms_pipeline_init() uniform_fn[0] = 0; uniform_fn[1] = glUniform4fv; uniform_fn[2] = glUniform3fv; - uniform_fn[3] = glUniform1iv; + uniform_fn[3] = (TMS_UNIFORM_FN)glUniform1iv; uniform_fn[4] = glUniform2fv; uniform_fn[5] = glUniform1fv; - uniform_fn[6] = glUniform1iv; + uniform_fn[6] = (TMS_UNIFORM_FN)glUniform1iv; uniform_mat_fn[0] = glUniformMatrix4fv; uniform_mat_fn[1] = glUniformMatrix3fv; @@ -148,7 +148,6 @@ tms_pipeline_apply_combined_uniforms(int p, struct tms_rstate *state, struct tms_program *s, struct tms_entity *e) { -#ifdef TMS_COOL_PIPELINE float mat[16]; GLuint *locs = s->p_combined; for (int x=0; xdata)) + pipelines[p].combined[x].offs1); @@ -167,16 +167,7 @@ tms_pipeline_apply_combined_uniforms(int p, glUniformMatrix4fv(loc, 1, 0, mat); } - } #else - float mat[16]; - GLuint *locs = s->p_combined; - for (int x=0; xtype1 == TMS_MAT4 && u->type2 == TMS_MAT4) { @@ -189,8 +180,8 @@ tms_pipeline_apply_combined_uniforms(int p, glUniformMatrix4fv(loc, 1, 0, mat); } - } #endif + } } void apply_global_uniform(struct tms_pipeline *p, int x, struct tms_rstate *state, GLuint loc) @@ -202,9 +193,9 @@ void apply_global_uniform(struct tms_pipeline *p, int x, struct tms_rstate *stat if (p->global[x].type == TMS_P) { glUniformMatrix4fv(loc, 1, 0, state->projection); } else if (p->global[x].type >= 128) - (uniform_mat_fn[p->global[x].type - 128])(loc, 1, 0, ((char*)(state->data))+p->global[x].offs); + (uniform_mat_fn[p->global[x].type - 128])(loc, 1, 0, (const GLfloat *)(((char*)(state->data))+p->global[x].offs)); else { - (uniform_fn[p->global[x].type])(loc, 1, ((char*)(state->data))+p->global[x].offs); + (uniform_fn[p->global[x].type])(loc, 1, (const GLfloat *)(((char*)(state->data))+p->global[x].offs)); } return; @@ -216,29 +207,18 @@ tms_pipeline_apply_global_uniforms(int p, struct tms_program *s) { #ifdef TMS_COOL_PIPELINE - GLuint loc; - int x = (int64_t)(pipelines[p].num_global-1); - struct tms_pipeline *pl = tms_get_pipeline(p); + GLuint loc; + int x = pipelines[p].num_global - 1; - static int cooltable[] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}; + struct tms_pipeline *pl = tms_get_pipeline(p); -fuckgcc1: - if (x < 0) { - goto fuckgcc3; + while (x >= 0) { + loc = s->p_global[x]; + apply_global_uniform(pl, x, state, loc); + x--; } - loc = s->p_global[x]; - - apply_global_uniform(pl, x, state, loc); - -fuckgcc2: - x = cooltable[x]; - goto fuckgcc1; - -fuckgcc3: - return; - #else GLuint *locs = s->p_global; for (int x=0; xp_local[x]; - - if (loc == -1) - continue; - - n_local_uniforms ++; - - if (pipelines[p].local[x].type == TMS_MV) { - glUniformMatrix4fv(loc, 1, 0, state->modelview); - } else if (pipelines[p].local[x].type == TMS_MVP) { - float tmp[16]; - tmat4_copy(tmp, state->projection); - tmat4_multiply(tmp, state->modelview); - glUniformMatrix4fv(loc, 1, 0, tmp); - } else if (pipelines[p].local[x].type >= 128) { - if (pipelines[p].local[x].type == 129) - glUniformMatrix3fv(loc, 1, 0, ((char*)(e))+(pipelines[p].local[x].offs)); - else - glUniformMatrix4fv(loc, 1, 0, ((char*)(e))+(pipelines[p].local[x].offs)); - } else - (uniform_fn[pipelines[p].local[x].type])(loc, 1, ((char*)(e))+pipelines[p].local[x].offs); - } #else GLuint *locs = s->p_local; for (int x=0; xname); n_local_uniforms ++; @@ -313,12 +272,18 @@ tms_pipeline_apply_local_uniforms(int p, tmat4_multiply(tmp, state->modelview); glUniformMatrix4fv(loc, 1, 0, tmp); - } else if (u->type >= 128) - (uniform_mat_fn[u->type - 128])(loc, 1, 0, ((char*)(e))+u->offs); - else - (uniform_fn[u->type])(loc, 1, ((char*)(e))+u->offs); - } + } else if (u->type >= 128) { +#ifdef TMS_COOL_PIPELINE + if (u->type == TMS_MAT3) + glUniformMatrix3fv(loc, 1, 0, (const GLfloat *)((char *)(e) + (u->offs))); + else + glUniformMatrix4fv(loc, 1, 0, (const GLfloat *)((char *)(e) + (u->offs))); +#else + (uniform_mat_fn[u->type - 128])(loc, 1, 0, (const GLfloat *)((char *)(e) + (u->offs))); #endif + } else + (uniform_fn[u->type])(loc, 1, (const GLfloat *)((char*)(e))+u->offs); + } } void diff --git a/src/tms/core/shader.c b/src/tms/core/shader.c index 94638f126..9a5ceffb1 100644 --- a/src/tms/core/shader.c +++ b/src/tms/core/shader.c @@ -174,7 +174,7 @@ static GLint compile(struct tms_shader *sh, GLenum st, const char *src) tms_assertf(s != -1, "glCreateShader() failed"); - glShaderSource(s, num_src+1, sources, 0); + glShaderSource(s, num_src+1, (const GLchar *const *)sources, 0); glCompileShader(s); glGetShaderiv(s, GL_COMPILE_STATUS, &success); diff --git a/src/tms/core/texture.c b/src/tms/core/texture.c index 62e693336..a2015f2a6 100644 --- a/src/tms/core/texture.c +++ b/src/tms/core/texture.c @@ -192,54 +192,48 @@ tms_texture_load_etc1(struct tms_texture *tex, int tms_texture_load(struct tms_texture *tex, const char *filename) { - const char *ext = strrchr(filename, '.')+1; - - if (ext != 1) { - int status; + int status; - SDL_RWops *rw = SDL_RWFromFile(filename,"rb"); + SDL_RWops *rw = SDL_RWFromFile(filename,"rb"); - if (!rw) { - tms_infof("file not found: '%s'", SDL_GetError()); - return T_COULD_NOT_OPEN; - } + if (!rw) { + tms_infof("file not found: '%s'", SDL_GetError()); + return T_ERR; + } - SDL_Surface *s = IMG_Load_RW(rw, 1); + SDL_Surface *s = IMG_Load_RW(rw, 1); - if (!s) { - tms_errorf("could not open file: %s", filename); - return T_COULD_NOT_OPEN; - } + if (!s) { + tms_errorf("could not open file: %s", filename); + return T_ERR; + } - tex->is_buffered = 1; - tex->filename = strdup(filename); - tex->gamma_corrected = 0; - tex->width = s->w; - tex->height = s->h; - //tex->num_channels = 3 + s->format->Amask?1:0; - tex->num_channels = s->format->BytesPerPixel; + tex->is_buffered = 1; + tex->filename = strdup(filename); + tex->gamma_corrected = 0; + tex->width = s->w; + tex->height = s->h; + //tex->num_channels = 3 + s->format->Amask?1:0; + tex->num_channels = s->format->BytesPerPixel; - //tms_infof("bpp %d", s->format->BytesPerPixel); + //tms_infof("bpp %d", s->format->BytesPerPixel); - //tms_assertf(tex->num_channels == s->format->BytesPerPixel, "unsupported texture type BLAH"); + //tms_assertf(tex->num_channels == s->format->BytesPerPixel, "unsupported texture type BLAH"); - tex->data = malloc(tex->width*tex->height*tex->num_channels); + tex->data = malloc(tex->width*tex->height*tex->num_channels); - for (int y=0; yh; y++) { - for (int x=0; xw*tex->num_channels; x++) { - int o = y*s->pitch; - ((unsigned char*)tex->data)[(s->h-y-1)*s->w*tex->num_channels+x] = - ((unsigned char*)s->pixels)[o+x]; - } + for (int y=0; yh; y++) { + for (int x=0; xw*tex->num_channels; x++) { + int o = y*s->pitch; + ((unsigned char*)tex->data)[(s->h-y-1)*s->w*tex->num_channels+x] = + ((unsigned char*)s->pixels)[o+x]; } - - SDL_FreeSurface(s); - //SDL_RWclose(rw); - - return T_OK; } - return T_COULD_NOT_OPEN; + SDL_FreeSurface(s); + //SDL_RWclose(rw); + + return T_OK; } /** diff --git a/src/tms/modules/3ds.c b/src/tms/modules/3ds.c index ac817599b..d1e0a9346 100644 --- a/src/tms/modules/3ds.c +++ b/src/tms/modules/3ds.c @@ -77,7 +77,7 @@ load_3ds_model(struct tms_model *model, } //tms_infof("base index:%d", base_index); tms_gbuffer_realloc(model->vertices, sz + num_items * sizeof(struct vertex)); - vertex_buf = model->vertices->buf+sz; + vertex_buf = (struct vertex *)model->vertices->buf+sz; for (int x=0; xindices->size; tms_gbuffer_realloc(model->indices, sz+ num_indices * sizeof(uint16_t)); - index_buf = model->indices->buf+(sz); + index_buf = (uint16_t *)(model->indices->buf + sz); for (int x=0; x