From ef0e418e961d52e2471780dd7781613f662172f1 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 2 Sep 2018 06:04:24 +0200 Subject: [PATCH] Fixes infinite loop issue in trapgen Vertical coridoors before level 4 wouldn't leave enough space to place 4 traps since there is only 10 rows of tiles eligible for a trap and every trap ocupies 3 rows and requires at least 2 spare rows. This could cause an infinite loop situation. * Also fixes linux build warnings and other stuff. --- .vimrc | 2 +- data/trapgen.lua | 3 +++ src/steam/steamworks_api_wrapper.c | 7 ++++--- steamworks_c_wrapper/CMakeLists.txt | 1 + steamworks_c_wrapper/src/CallbackHandler.h | 5 +++-- steamworks_c_wrapper/src/steamworks_c_wrapper.cpp | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.vimrc b/.vimrc index 579fddc..4647378 100644 --- a/.vimrc +++ b/.vimrc @@ -5,4 +5,4 @@ nnoremap :ter ++close ./_build/breakhack packadd termdebug let g:termdebug_wide = 1 -let g:syntastic_c_include_dirs = [ '_build', '/usr/include/SDL2' ] +let g:syntastic_c_include_dirs = [ '_build', '/usr/include/SDL2', 'steamworks_c_wrapper/src', 'steamworks_c_wrapper/sdk/public/steam' ] diff --git a/data/trapgen.lua b/data/trapgen.lua index 8edbd1c..8e47892 100644 --- a/data/trapgen.lua +++ b/data/trapgen.lua @@ -31,6 +31,7 @@ function module.add_traps_to_room(room) end local count = random(4) + local attempts = 0; local i = 0 while i < count do local rx = random(13) + 1 @@ -55,6 +56,8 @@ function module.add_traps_to_room(room) i = i + 1 end end + attempts = attempts + 1 + if attempts > 100 then break end end end diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c index ac597b6..716cdde 100644 --- a/src/steam/steamworks_api_wrapper.c +++ b/src/steam/steamworks_api_wrapper.c @@ -62,8 +62,9 @@ void steam_init() { m_AppID = c_SteamAPI_Init(); - c_SteamAPI_SetCallbacks(stats_received, stats_stored, leaderboard_received); m_Initiated = m_AppID != 0; + if (m_Initiated) + c_SteamAPI_SetCallbacks(stats_received, stats_stored, leaderboard_received); requestDataTimer = timer_create(); } @@ -73,7 +74,7 @@ void steam_shutdown(void) timer_destroy(requestDataTimer); } -void +static void request_data_queue_run(void) { if (!timer_started(requestDataTimer)) @@ -122,4 +123,4 @@ void steam_register_kills(Sint32 nKills) if (!m_hKillsLeaderboard) return; c_SteamUserStats_UploadLeaderboardScore(m_hKillsLeaderboard, nKills); -} \ No newline at end of file +} diff --git a/steamworks_c_wrapper/CMakeLists.txt b/steamworks_c_wrapper/CMakeLists.txt index 731c097..f948ab6 100644 --- a/steamworks_c_wrapper/CMakeLists.txt +++ b/steamworks_c_wrapper/CMakeLists.txt @@ -34,6 +34,7 @@ else () add_library(steamworks_c_wrapper SHARED src/steamworks_c_wrapper + src/CallbackHandler ) endif() diff --git a/steamworks_c_wrapper/src/CallbackHandler.h b/steamworks_c_wrapper/src/CallbackHandler.h index 2abba9b..1cb8ebc 100644 --- a/steamworks_c_wrapper/src/CallbackHandler.h +++ b/steamworks_c_wrapper/src/CallbackHandler.h @@ -1,6 +1,7 @@ #pragma once #include +#include class CallbackHandler { @@ -16,9 +17,9 @@ public: void(*statsReceivedCb)() = nullptr; void(*statsStoredCb)() = nullptr; - void(*leaderboardReceivedCb)(int64, const char*) = nullptr; + void(*leaderboardReceivedCb)(int64_t, const char*) = nullptr; bool CallbackReceived() const; void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure); -}; \ No newline at end of file +}; diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp index 296a157..3123c4f 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -12,9 +12,9 @@ static CallbackHandler *m_CallbackHandler = NULL; extern "C" int64_t c_SteamAPI_Init() { + m_CallbackHandler = new CallbackHandler(m_AppId); if (SteamAPI_Init()) { m_AppId = SteamUtils()->GetAppID(); - m_CallbackHandler = new CallbackHandler(m_AppId); m_Initiated = true; return m_AppId; }