From 8cdc87c2996c109dec5ad02bc7058b89498aada3 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 29 Aug 2018 14:03:18 +0200 Subject: [PATCH 01/28] Completed Steam api integration. - Next step is to actually trigger the achievements in the right places. --- .gitignore | 1 + CMakeLists.txt | 31 +++++-- src/defines.h | 2 + src/main.c | 17 +++- src/steam/steamworks_api_wrapper.c | 72 +++++++++++++++ src/steam/steamworks_api_wrapper.h | 32 +++++++ steam/steamworks_api_wrapper.c | 21 ----- steam/steamworks_api_wrapper.h | 20 ----- steamworks_c_wrapper/CMakeLists.txt | 14 +++ .../src/steamworks_c_wrapper.cpp | 89 ++++++++++++++++++- .../src/steamworks_c_wrapper.h | 71 ++++++++------- 11 files changed, 287 insertions(+), 83 deletions(-) create mode 100644 src/steam/steamworks_api_wrapper.c create mode 100644 src/steam/steamworks_api_wrapper.h delete mode 100644 steam/steamworks_api_wrapper.c delete mode 100644 steam/steamworks_api_wrapper.h diff --git a/.gitignore b/.gitignore index 4182d65..f64b1a7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /steamworks_c_wrapper/sdk *.swp *~ +/steam_appid.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 793ee43..4815b24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,10 @@ configure_file( ) if (EXISTS "${PROJECT_SOURCE_DIR}/steamworks_c_wrapper/sdk") + MESSAGE ( STATUS "Steam SDK located, Steam build enabled") set(STEAM 1) +else () + MESSAGE ( STATUS "Steam SDK not found, Steam build disabled") endif() if (STEAM) @@ -62,22 +65,22 @@ IF ( MSVC ) MESSAGE ( STATUS "Setting MSVC MT switches") SET ( CMAKE_C_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} /MTd" + "${CMAKE_C_FLAGS_DEBUG} /MTd" CACHE STRING "MSVC MT flags " FORCE ) SET ( CMAKE_C_FLAGS_RELEASE - "${CMAKE_CXX_FLAGS_RELEASE} /MT" + "${CMAKE_C_FLAGS_RELEASE} /MT" CACHE STRING "MSVC MT flags " FORCE ) ELSEIF ( WIN32 ) SET ( CMAKE_C_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} -mconsole" + "${CMAKE_C_FLAGS_DEBUG} -mconsole" ) SET ( CMAKE_C_FLAGS_RELEASE - "${CMAKE_CXX_FLAGS_RELEASE} -mwindows" + "${CMAKE_C_FLAGS_RELEASE} -mwindows" ) ENDIF () IF ( GCC OR CLANG ) @@ -101,6 +104,13 @@ else () ) endif () +if (STEAM) + include_directories( + ${STEAMWORKS_INCLUDE_DIR} + steamworks_c_wrapper/src + ) +endif () + include_directories( ${PROJECT_BINARY_DIR} ${LUA_INCLUDE_DIR} @@ -191,6 +201,7 @@ add_executable(breakhack src/object src/gui_util src/tooltip + src/steam/steamworks_api_wrapper ) # Sqlite has some warnings that I we don't need to see @@ -304,6 +315,7 @@ SET(CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT "Release") SET(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".") if (WIN32) SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS + ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} ${CMAKE_SOURCE_DIR}/bin/libFLAC-8.dll ${CMAKE_SOURCE_DIR}/bin/libfreetype-6.dll ${CMAKE_SOURCE_DIR}/bin/libmodplug-1.dll @@ -321,7 +333,8 @@ if (WIN32) if (STEAM) SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} - ${STEAMWORKS_LIBRARY} + steamworks_c_wrapper/sdk/redistributable_bin/steam_api.dll + build/steam/steam_appid.txt ) endif () endif (WIN32) @@ -346,11 +359,15 @@ set(CPACK_PACKAGE_VERSION_MAJOR ${breakhack_MAJOR_VERSION}) set(CPACK_PACKAGE_VERSION_MINOR ${breakhack_MINOR_VERSION}) set(CPACK_PACKAGE_VERSION_PATCH ${breakhack_PATCH_VERSION}) set(CPACK_PACKAGE_INSTALL_DIRECTORY "BreakHack") -set(CPACK_PACKAGE_FILE_NAME "breakhack-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +if (WIN32) + set(CPACK_PACKAGE_FILE_NAME "breakhack-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-win32") +else () + set(CPACK_PACKAGE_FILE_NAME "breakhack-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +endif () set(CPACK_PACKAGE_CHECKSUM "MD5") if(UNIX) - set(CPACK_GENERATOR STGZ TGZ TZ) + set(CPACK_GENERATOR TGZ) set(CPACK_STRIP_FILES breakhack) set(CPACK_SOURCE_STRIP_FILES "") elseif(WIN32) diff --git a/src/defines.h b/src/defines.h index d7db9f7..c465c0f 100644 --- a/src/defines.h +++ b/src/defines.h @@ -84,6 +84,8 @@ typedef int16_t Sint16; typedef uint16_t Uint16; typedef int32_t Sint32; typedef uint32_t Uint32; +typedef int64_t Sint64; +typedef uint64_t Uint64; typedef enum Direction_t { UP, DOWN, LEFT, RIGHT diff --git a/src/main.c b/src/main.c index a6264db..34b44d6 100644 --- a/src/main.c +++ b/src/main.c @@ -22,7 +22,6 @@ #include #include #include - #include "linkedlist.h" #include "player.h" #include "screenresolution.h" @@ -54,6 +53,10 @@ #include "io_util.h" #include "tooltip.h" +#ifdef STEAM_BUILD +#include "steam/steamworks_api_wrapper.h" +#endif // STEAM_BUILD + static char *artifacts_tooltip[] = { "CONGRATULATIONS!", "", @@ -520,6 +523,10 @@ init(void) return false; } +#ifdef STEAM_BUILD + steam_init(); +#endif // STEAM_BUILD + settings_init(); hiscore_init(); initMainMenu(); @@ -933,6 +940,10 @@ run(void) pointer_handle_input(gPointer, &input); #endif // DEBUG +#ifdef STEAM_BUILD + steam_run_callbacks(); +#endif // STEAM_BUILD + switch (gGameState) { case PLAYING: case IN_GAME_MENU: @@ -1019,6 +1030,10 @@ void close(void) settings_close(); hiscore_close(); +#ifdef STEAM_BUILD + steam_shutdown(); +#endif // STEAM_BUILD + SDL_DestroyRenderer(gRenderer); SDL_DestroyWindow(gWindow); gWindow = NULL; diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c new file mode 100644 index 0000000..022a647 --- /dev/null +++ b/src/steam/steamworks_api_wrapper.c @@ -0,0 +1,72 @@ +#include +#include "steamworks_api_wrapper.h" +#include "steamworks_c_wrapper.h" +#include "../util.h" +#include "../defines.h" + +static Achievement g_Achievements[] = { + _ACH_ID(BAD_DOG, "Bad Dog"), + _ACH_ID(THE_DOCTOR_IS_OUT, "The Doctor is Out"), + _ACH_ID(LIGHTS_ON, "Omnidirectional light"), + _ACH_ID(BACK_TO_WORK, "Back to work"), + _ACH_ID(DRAGON_SLAYER, "Platinum dragon slayer") +}; +static Uint8 numAchievements = 5; + +static bool m_Initiated = false; +static Sint64 m_AppID = 0; + +static bool +steam_request_stats() +{ + if (m_Initiated) + return c_SteamUserStats_RequestCurrentStats(); + return false; +} + +static void +stats_received(void) +{ + debug("Stats received"); + for (Uint8 i = 0; i < numAchievements; ++i) { + Achievement *a = &g_Achievements[i]; + c_SteamUserStats_GetAchievement(a->m_pchAchievementID, &a->m_bAchieved); + gui_log("You just earned the \"%s\" achievement", c_SteamUserStats_GetAchievementDisplayAttribute(a->m_pchAchievementID, "name")); + } +} + +static void +stats_stored(void) +{ + debug("Stats stored"); +} + +void +steam_init() +{ + m_AppID = c_SteamAPI_Init(); + m_Initiated = m_AppID != 0; + if (m_Initiated) { + c_SteamAPI_SetCallbacks(stats_received, stats_stored); + steam_request_stats(); + } +} + +void steam_shutdown(void) +{ + c_SteamAPI_Shutdown(); +} + +void steam_run_callbacks(void) +{ + if (m_Initiated) + c_SteamAPI_RunCallbacks(); +} + +void steam_set_achievement(EAchievement eAch) +{ + for (Uint8 i = 0; i < numAchievements; ++i) { + if (g_Achievements[i].m_eAchievementID == eAch) + c_SteamUserStats_SetAchievement(g_Achievements[i].m_pchAchievementID); + } +} diff --git a/src/steam/steamworks_api_wrapper.h b/src/steam/steamworks_api_wrapper.h new file mode 100644 index 0000000..a3ca8bc --- /dev/null +++ b/src/steam/steamworks_api_wrapper.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include "../defines.h" + +typedef enum EAchievement +{ + BAD_DOG = 0, + THE_DOCTOR_IS_OUT = 1, + LIGHTS_ON = 2, + BACK_TO_WORK = 5, + DRAGON_SLAYER = 6 +} EAchievement; + + +#define _ACH_ID( id, name ) { id, #id, name, "", 0, 0 } +typedef struct Achievement { + EAchievement m_eAchievementID; + const char *m_pchAchievementID; + char m_rgchName[128]; + char m_rgchDescription[256]; + bool m_bAchieved; + int m_iIconImage; +} Achievement; + +void steam_init(void); + +void steam_shutdown(void); + +void steam_run_callbacks(void); + +void steam_set_achievement(EAchievement eAch); \ No newline at end of file diff --git a/steam/steamworks_api_wrapper.c b/steam/steamworks_api_wrapper.c deleted file mode 100644 index 21060e3..0000000 --- a/steam/steamworks_api_wrapper.c +++ /dev/null @@ -1,21 +0,0 @@ -/* - * BreakHack - A dungeone crawler RPG - * Copyright (C) 2018 Linus Probert - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include "steamworks_api_wrapper.h" - diff --git a/steam/steamworks_api_wrapper.h b/steam/steamworks_api_wrapper.h deleted file mode 100644 index 121688b..0000000 --- a/steam/steamworks_api_wrapper.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * BreakHack - A dungeone crawler RPG - * Copyright (C) 2018 Linus Probert - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - diff --git a/steamworks_c_wrapper/CMakeLists.txt b/steamworks_c_wrapper/CMakeLists.txt index 4d10aea..127c2ee 100644 --- a/steamworks_c_wrapper/CMakeLists.txt +++ b/steamworks_c_wrapper/CMakeLists.txt @@ -30,3 +30,17 @@ add_library(steamworks_c_wrapper ) target_link_libraries(steamworks_c_wrapper ${STEAMWORKS_LIBRARY}) + +IF ( MSVC ) + MESSAGE ( STATUS "Setting MSVC MT switches") + SET ( + CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} /MTd" + CACHE STRING "MSVC MT flags " FORCE + ) + SET ( + CMAKE_CXX_FLAGS_RELEASE + "${CMAKE_CXX_FLAGS_RELEASE} /MT" + CACHE STRING "MSVC MT flags " FORCE + ) +endif () diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp index 16c0534..2596778 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -4,22 +4,105 @@ extern "C" { #include "steamworks_c_wrapper.h" } -extern "C" void c_SteamAPI_Init() +static bool m_Initiated = false; +static int64 m_AppId = 0; +static CallbackHandler *m_CallbackHandler = NULL; +static bool m_RecvCB = false; + +static void(*statsReceivedCb)(void) = NULL; +static void(*statsStoredCb)(void) = NULL; + + +extern "C" int64 c_SteamAPI_Init() { - SteamAPI_Init(); + if (SteamAPI_Init()) { + m_AppId = SteamUtils()->GetAppID(); + m_CallbackHandler = new CallbackHandler(); + m_Initiated = true; + return m_AppId; + } + return 0; +} + +extern "C" void c_SteamAPI_SetCallbacks(void(*recvCB)(void), void(*storCB)(void)) +{ + statsReceivedCb = recvCB; + statsStoredCb = storCB; +} + +extern "C" int64 c_SteamAPI_GetAppID() +{ + if (!m_Initiated) + return 0; + m_AppId = SteamUtils()->GetAppID(); + return m_AppId; +} + +void c_SteamAPI_RunCallbacks(void) +{ + if (m_Initiated) + SteamAPI_RunCallbacks(); } extern "C" void c_SteamAPI_Shutdown() { + delete m_CallbackHandler; SteamAPI_Shutdown(); } extern "C" bool c_SteamUserStats_RequestCurrentStats() { + if (NULL == SteamUserStats() || NULL == SteamUser()) + return false; + if (!SteamUser()->BLoggedOn()) + return false; + return SteamUserStats()->RequestCurrentStats(); } extern "C" bool c_SteamUserStats_SetAchievement(const char *pchName) { - return SteamUserStats()->SetAchievement(pchName); + if (!m_RecvCB) + return false; + + bool result = SteamUserStats()->SetAchievement(pchName); + if (result) + SteamUserStats()->StoreStats(); + return result; +} + +extern "C" void c_SteamUserStats_GetAchievement(const char *achId, bool *achieved) +{ + SteamUserStats()->GetAchievement(achId, achieved); +} + +extern "C" const char* c_SteamUserStats_GetAchievementDisplayAttribute(const char *achId, const char *attrName) +{ + return SteamUserStats()->GetAchievementDisplayAttribute(achId, attrName); +} + +CallbackHandler::CallbackHandler() : + m_CallbackUserStatsReceived(this, &CallbackHandler::OnUserStatsReceived), + m_CallbackUserStatsStored(this, &CallbackHandler::OnUserStatsStored) +{ +} + +void +CallbackHandler::OnUserStatsReceived(UserStatsReceived_t *pCallback) +{ + if (m_AppId != pCallback->m_nGameID) + return; + m_RecvCB = true; + if (statsReceivedCb && k_EResultOK == pCallback->m_eResult) + statsReceivedCb(); +} + +void +CallbackHandler::OnUserStatsStored(UserStatsStored_t *pCallback) +{ + if (m_AppId != pCallback->m_nGameID) + return; + + if (statsStoredCb && k_EResultOK == pCallback->m_eResult) + statsStoredCb(); } diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.h b/steamworks_c_wrapper/src/steamworks_c_wrapper.h index afd3161..c482ef3 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.h +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.h @@ -1,31 +1,40 @@ -#pragma once - -enum Achievements -{ - ACH_BAD_DOG = 0, - ACH_THE_DOCTOR_IS_OUT = 1, - ACH_LIGHTS_ON = 2, - ACH_BACK_TO_WORK = 5, -}; - -struct Achievement -{ - Achievements m_eAchievementID; - const char *m_pchAchievementID; - char m_rgchName[128]; - char m_rgchDescription[256]; - bool m_bAchieved; - int m_iIconImage; -}; - -void -c_SteamAPI_Init(); - -bool -c_steam_request_stats(); - -bool -c_steam_set_achievement(const char *id); - -void -c_SteamAPI_Shutdown(); +#pragma once + +#include + +int64_t +c_SteamAPI_Init(void); + +int64_t +c_SteamAPI_GetAppID(void); + +void +c_SteamAPI_RunCallbacks(void); + +void +c_SteamAPI_SetCallbacks(void(*)(void), void(*)(void)); + +bool +c_SteamUserStats_RequestCurrentStats(); + +bool +c_SteamUserStats_SetAchievement(const char *id); + +void +c_SteamUserStats_GetAchievement(const char *achId, bool *achieved); + +const char * +c_SteamUserStats_GetAchievementDisplayAttribute(const char *achId, const char *attrName); + +void +c_SteamAPI_Shutdown(); + +#ifdef __cplusplus +class CallbackHandler +{ +public: + CallbackHandler(); + STEAM_CALLBACK(CallbackHandler, OnUserStatsReceived, UserStatsReceived_t, m_CallbackUserStatsReceived); + STEAM_CALLBACK(CallbackHandler, OnUserStatsStored, UserStatsStored_t, m_CallbackUserStatsStored); +}; +#endif // __cplusplus \ No newline at end of file From 28b3980fe63ef6068cad9cf2b3e3b74542102812 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 29 Aug 2018 14:11:36 +0200 Subject: [PATCH 02/28] Fixed non-steam build, because I broke it :D --- CMakeLists.txt | 10 +++++++++- src/steam/steamworks_api_wrapper.c | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4815b24..25a9801 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,14 @@ else (NOT MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__FNAME__=__FILE__") endif (NOT MSVC) +if (STEAM) + set(STEAM_SOURCES + src/steam/steamworks_api_wrapper + ) +else () + set(STEAM_SOURCES "") +endif () + # PROGRAMS: add_executable(breakhack src/main @@ -201,7 +209,7 @@ add_executable(breakhack src/object src/gui_util src/tooltip - src/steam/steamworks_api_wrapper + ${STEAM_SOURCES} ) # Sqlite has some warnings that I we don't need to see diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c index 022a647..1eea76f 100644 --- a/src/steam/steamworks_api_wrapper.c +++ b/src/steam/steamworks_api_wrapper.c @@ -3,6 +3,7 @@ #include "steamworks_c_wrapper.h" #include "../util.h" #include "../defines.h" +#include "../gui.h" static Achievement g_Achievements[] = { _ACH_ID(BAD_DOG, "Bad Dog"), From d2ced6cef14acd91730e7e6f506192c6c9ad821d Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 29 Aug 2018 14:26:07 +0200 Subject: [PATCH 03/28] Adds hooks for all achievements --- src/main.c | 3 +++ src/player.c | 15 +++++++++++++++ src/steam/steamworks_api_wrapper.c | 14 ++++++-------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 34b44d6..36fdcac 100644 --- a/src/main.c +++ b/src/main.c @@ -866,6 +866,9 @@ run_game(void) gui_log("Your break is over!"); gui_event_message("Well done!"); end_game_details(); +#ifdef STEAM_BUILD + steam_set_achievement(BACK_TO_WORK); +#endif // STEAM_BUILD } } diff --git a/src/player.c b/src/player.c index 1e9f6e3..70f8e07 100644 --- a/src/player.c +++ b/src/player.c @@ -36,6 +36,10 @@ #include "animation.h" #include "trap.h" +#ifdef STEAM_BUILD +#include "steam/steamworks_api_wrapper.h" +#endif // STEAM_BUILD + #define ENGINEER_STATS { 12, 12, 5, 7, 2, 2, 1, false, false } #define MAGE_STATS { 12, 12, 5, 7, 1, 2, 1, false, false } #define PALADIN_STATS { 12, 12, 8, 9, 3, 1, 1, false, false } @@ -514,6 +518,17 @@ player_monster_kill_check(Player *player, Monster *monster) if (!monster) return; +#ifdef STEAM_BUILD + if (strcmp("The Shadow", monster->label) == 0) + steam_set_achievement(LIGHTS_ON); + else if (strcmp("The Hell Hound", monster->label) == 0) + steam_set_achievement(BAD_DOG); + else if (strcmp("Platino", monster->label) == 0) + steam_set_achievement(DRAGON_SLAYER); + else if (strcmp("The Cleric", monster->label) == 0) + steam_set_achievement(THE_DOCTOR_IS_OUT); +#endif // STEAM_BUILD + if (monster->stats.hp <= 0) { unsigned int gained_xp = 5 * monster->stats.lvl; player->stat_data.kills += 1; diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c index 1eea76f..6307f0f 100644 --- a/src/steam/steamworks_api_wrapper.c +++ b/src/steam/steamworks_api_wrapper.c @@ -28,18 +28,13 @@ steam_request_stats() static void stats_received(void) { - debug("Stats received"); - for (Uint8 i = 0; i < numAchievements; ++i) { - Achievement *a = &g_Achievements[i]; - c_SteamUserStats_GetAchievement(a->m_pchAchievementID, &a->m_bAchieved); - gui_log("You just earned the \"%s\" achievement", c_SteamUserStats_GetAchievementDisplayAttribute(a->m_pchAchievementID, "name")); - } + debug("Steam stats received"); } static void stats_stored(void) { - debug("Stats stored"); + debug("Steam stats stored"); } void @@ -67,7 +62,10 @@ void steam_run_callbacks(void) void steam_set_achievement(EAchievement eAch) { for (Uint8 i = 0; i < numAchievements; ++i) { - if (g_Achievements[i].m_eAchievementID == eAch) + Achievement *a = &g_Achievements[i]; + if (a->m_eAchievementID == eAch && !a->m_bAchieved) { c_SteamUserStats_SetAchievement(g_Achievements[i].m_pchAchievementID); + gui_log("You just earned the \"%s\" achievement", a->m_rgchName); + } } } From c7011efc309510088e50c992f58272bc5f5e7f07 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 29 Aug 2018 15:03:35 +0200 Subject: [PATCH 04/28] Version bump --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25a9801..8c968c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ project(breakhack C) set(breakhack_GAME_TITLE "BreakHack") set(breakhack_MAJOR_VERSION 0) -set(breakhack_MINOR_VERSION 2) +set(breakhack_MINOR_VERSION 3) set(breakhack_PATCH_VERSION 0) set(breakhack_RELEASE_TYPE "(beta)") From 316325b98dcf379b5984d30bcd5a11f2f632e376 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 29 Aug 2018 22:13:22 +0200 Subject: [PATCH 05/28] Implemented leaderboard updates --- CMakeLists.txt | 1 + src/main.c | 4 ++ src/steam/steamworks_api_wrapper.c | 17 ++++- src/steam/steamworks_api_wrapper.h | 4 +- .../src/steamworks_c_wrapper.cpp | 69 +++++++++++++++---- .../src/steamworks_c_wrapper.h | 11 ++- 6 files changed, 89 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c968c1..0ad95ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,6 +143,7 @@ endif (NOT MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG") if (STEAM) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSTEAM_BUILD") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DSTEAM_BUILD") endif () if (NOT MSVC) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D__FNAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") diff --git a/src/main.c b/src/main.c index 36fdcac..756241f 100644 --- a/src/main.c +++ b/src/main.c @@ -632,6 +632,7 @@ end_game_details(void) { gui_log("You earned %.2f gold", gPlayer->gold); gui_event_message("You earned %.2f gold", gPlayer->gold); + if (hiscore_get_top_gold() < gPlayer->gold) { gui_event_message("NEW HIGHSCORE"); gui_log("NEW HIGHSCORE"); @@ -854,6 +855,9 @@ run_game(void) gGameState = GAME_OVER; createInGameGameOverMenu(); hiscore_register(gPlayer, cLevel); +#ifdef STEAM_BUILD + steam_register_score((int)hiscore_get_top_gold()); +#endif // STEAM_BUILD } else { check_next_level(); diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c index 6307f0f..2f1e89f 100644 --- a/src/steam/steamworks_api_wrapper.c +++ b/src/steam/steamworks_api_wrapper.c @@ -16,6 +16,7 @@ static Uint8 numAchievements = 5; static bool m_Initiated = false; static Sint64 m_AppID = 0; +static Sint64 m_hLeaderboard = 0; static bool steam_request_stats() @@ -37,14 +38,21 @@ stats_stored(void) debug("Steam stats stored"); } +static void +leaderboard_received(Sint64 hLeaderboard) +{ + m_hLeaderboard = hLeaderboard; +} + void steam_init() { + c_SteamAPI_SetCallbacks(stats_received, stats_stored, leaderboard_received); m_AppID = c_SteamAPI_Init(); m_Initiated = m_AppID != 0; if (m_Initiated) { - c_SteamAPI_SetCallbacks(stats_received, stats_stored); steam_request_stats(); + c_SteamUserStats_FindLeaderboard("Highscore"); } } @@ -69,3 +77,10 @@ void steam_set_achievement(EAchievement eAch) } } } + +void steam_register_score(Sint32 nScore) +{ + if (!m_hLeaderboard) + return; + c_SteamUserStats_UploadLeaderboardScore(m_hLeaderboard, nScore); +} diff --git a/src/steam/steamworks_api_wrapper.h b/src/steam/steamworks_api_wrapper.h index a3ca8bc..42f0ba1 100644 --- a/src/steam/steamworks_api_wrapper.h +++ b/src/steam/steamworks_api_wrapper.h @@ -29,4 +29,6 @@ void steam_shutdown(void); void steam_run_callbacks(void); -void steam_set_achievement(EAchievement eAch); \ No newline at end of file +void steam_set_achievement(EAchievement eAch); + +void steam_register_score(Sint32 nScore); \ 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 2596778..957f078 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -11,9 +11,11 @@ static bool m_RecvCB = false; static void(*statsReceivedCb)(void) = NULL; static void(*statsStoredCb)(void) = NULL; +static void(*leaderBoardReceived)(int64) = NULL; -extern "C" int64 c_SteamAPI_Init() +extern "C" int64 +c_SteamAPI_Init() { if (SteamAPI_Init()) { m_AppId = SteamUtils()->GetAppID(); @@ -24,13 +26,8 @@ extern "C" int64 c_SteamAPI_Init() return 0; } -extern "C" void c_SteamAPI_SetCallbacks(void(*recvCB)(void), void(*storCB)(void)) -{ - statsReceivedCb = recvCB; - statsStoredCb = storCB; -} - -extern "C" int64 c_SteamAPI_GetAppID() +extern "C" int64 +c_SteamAPI_GetAppID() { if (!m_Initiated) return 0; @@ -38,19 +35,29 @@ extern "C" int64 c_SteamAPI_GetAppID() return m_AppId; } -void c_SteamAPI_RunCallbacks(void) +void +c_SteamAPI_RunCallbacks(void) { if (m_Initiated) SteamAPI_RunCallbacks(); } -extern "C" void c_SteamAPI_Shutdown() +extern "C" void c_SteamAPI_SetCallbacks(void(*recvCB)(void), void(*storCB)(void), void(*recvLB)(int64_t)) +{ + statsReceivedCb = recvCB; + statsStoredCb = storCB; + leaderBoardReceived = recvLB; +} + +extern "C" void +c_SteamAPI_Shutdown() { delete m_CallbackHandler; SteamAPI_Shutdown(); } -extern "C" bool c_SteamUserStats_RequestCurrentStats() +extern "C" bool +c_SteamUserStats_RequestCurrentStats() { if (NULL == SteamUserStats() || NULL == SteamUser()) return false; @@ -60,7 +67,8 @@ extern "C" bool c_SteamUserStats_RequestCurrentStats() return SteamUserStats()->RequestCurrentStats(); } -extern "C" bool c_SteamUserStats_SetAchievement(const char *pchName) +extern "C" bool +c_SteamUserStats_SetAchievement(const char *pchName) { if (!m_RecvCB) return false; @@ -71,20 +79,44 @@ extern "C" bool c_SteamUserStats_SetAchievement(const char *pchName) return result; } -extern "C" void c_SteamUserStats_GetAchievement(const char *achId, bool *achieved) +extern "C" void +c_SteamUserStats_GetAchievement(const char *achId, bool *achieved) { + if (!m_Initiated) + return; + SteamUserStats()->GetAchievement(achId, achieved); } -extern "C" const char* c_SteamUserStats_GetAchievementDisplayAttribute(const char *achId, const char *attrName) +extern "C" const char* +c_SteamUserStats_GetAchievementDisplayAttribute(const char *achId, const char *attrName) { return SteamUserStats()->GetAchievementDisplayAttribute(achId, attrName); } +extern "C" void +c_SteamUserStats_FindLeaderboard(const char * name) +{ + if (!m_Initiated) + return; + + SteamAPICall_t hSteamAPICall = SteamUserStats()->FindLeaderboard(name); + m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard); +} + +extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32 nScore) +{ + if (!hLeaderboard || !m_Initiated) + return; + + SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, nullptr, 0); +} + CallbackHandler::CallbackHandler() : m_CallbackUserStatsReceived(this, &CallbackHandler::OnUserStatsReceived), m_CallbackUserStatsStored(this, &CallbackHandler::OnUserStatsStored) { + // Nothing } void @@ -106,3 +138,12 @@ CallbackHandler::OnUserStatsStored(UserStatsStored_t *pCallback) if (statsStoredCb && k_EResultOK == pCallback->m_eResult) statsStoredCb(); } + +void CallbackHandler::OnFindLeaderboard(LeaderboardFindResult_t * pCallback, bool bIOFailiure) +{ + if (bIOFailiure || !pCallback->m_bLeaderboardFound) + return; + + if (leaderBoardReceived) + leaderBoardReceived(pCallback->m_hSteamLeaderboard); +} diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.h b/steamworks_c_wrapper/src/steamworks_c_wrapper.h index c482ef3..29a0b72 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.h +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.h @@ -12,7 +12,7 @@ void c_SteamAPI_RunCallbacks(void); void -c_SteamAPI_SetCallbacks(void(*)(void), void(*)(void)); +c_SteamAPI_SetCallbacks(void(*)(void), void(*)(void), void(*)(int64_t)); bool c_SteamUserStats_RequestCurrentStats(); @@ -26,6 +26,12 @@ c_SteamUserStats_GetAchievement(const char *achId, bool *achieved); const char * c_SteamUserStats_GetAchievementDisplayAttribute(const char *achId, const char *attrName); +void +c_SteamUserStats_FindLeaderboard(const char *name); + +void +c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore); + void c_SteamAPI_Shutdown(); @@ -36,5 +42,8 @@ public: CallbackHandler(); STEAM_CALLBACK(CallbackHandler, OnUserStatsReceived, UserStatsReceived_t, m_CallbackUserStatsReceived); STEAM_CALLBACK(CallbackHandler, OnUserStatsStored, UserStatsStored_t, m_CallbackUserStatsStored); + CCallResult m_FindLeaderboardCallResult; + + void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure); }; #endif // __cplusplus \ No newline at end of file From 0d1836a8ba3cc57c74171caf2699fa93f2fdc0a3 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 30 Aug 2018 00:09:55 +0200 Subject: [PATCH 06/28] Passable fullscreen mode - Centering is still a bit off --- src/input.c | 4 ++-- src/input.h | 1 + src/main.c | 47 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/input.c b/src/input.c index cb8182d..9625d83 100644 --- a/src/input.c +++ b/src/input.c @@ -109,6 +109,8 @@ get_event_modkey(SDL_Event *event) key = KEY_CTRL_M; break; case SDLK_d: key = KEY_CTRL_D; break; + case SDLK_f: + key = KEY_CTRL_F; break; } } else if (event->key.keysym.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) { switch (event->key.keysym.sym) { @@ -122,8 +124,6 @@ get_event_modkey(SDL_Event *event) key = KEY_SHIFT_NUM4; break; case SDLK_5: key = KEY_SHIFT_NUM5; break; - default: - key = 0; break; } } return key; diff --git a/src/input.h b/src/input.h index 78e3f1b..f08b438 100644 --- a/src/input.h +++ b/src/input.h @@ -47,6 +47,7 @@ #define KEY_SHIFT_NUM3 0x20 #define KEY_SHIFT_NUM4 0x40 #define KEY_SHIFT_NUM5 0x80 +#define KEY_CTRL_F 0x100 #define MBUTTON_LEFT 1 #define MBUTTON_MIDDLE 2 diff --git a/src/main.c b/src/main.c index 756241f..b5448a8 100644 --- a/src/main.c +++ b/src/main.c @@ -152,6 +152,7 @@ static float deltaTime = 1.0; static double renderScale = 1.0; static Turn currentTurn = PLAYER; static GameState gGameState; +static SDL_Rect mainViewport; static SDL_Rect gameViewport; static SDL_Rect skillBarViewport; static SDL_Rect bottomGuiViewport; @@ -250,26 +251,30 @@ bool initSDL(void) } static void -initViewports(void) +initViewports(Uint32 offset) { - gameViewport = (SDL_Rect) { 0, 0, + mainViewport = (SDL_Rect) { offset, 0, + SCREEN_HEIGHT, SCREEN_WIDTH + }; + + gameViewport = (SDL_Rect) { offset, 0, GAME_VIEW_WIDTH, GAME_VIEW_HEIGHT }; - skillBarViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT, + skillBarViewport = (SDL_Rect) { offset, GAME_VIEW_HEIGHT, SKILL_BAR_WIDTH, SKILL_BAR_HEIGHT }; - bottomGuiViewport = (SDL_Rect) { 0, GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT, + bottomGuiViewport = (SDL_Rect) { offset, GAME_VIEW_HEIGHT + SKILL_BAR_HEIGHT, BOTTOM_GUI_WIDTH, BOTTOM_GUI_WIDTH }; - statsGuiViewport = (SDL_Rect) { GAME_VIEW_WIDTH, 0, + statsGuiViewport = (SDL_Rect) { offset + GAME_VIEW_WIDTH, 0, RIGHT_GUI_WIDTH, STATS_GUI_HEIGHT }; - minimapViewport = (SDL_Rect) { GAME_VIEW_WIDTH, STATS_GUI_HEIGHT, + minimapViewport = (SDL_Rect) { offset + GAME_VIEW_WIDTH, STATS_GUI_HEIGHT, RIGHT_GUI_WIDTH, MINIMAP_GUI_HEIGHT }; menuViewport = (SDL_Rect) { - (SCREEN_WIDTH - GAME_VIEW_WIDTH)/2, - (SCREEN_HEIGHT - GAME_VIEW_HEIGHT)/2, + offset + ((SCREEN_WIDTH - GAME_VIEW_WIDTH) >> 1), + (SCREEN_HEIGHT - GAME_VIEW_HEIGHT) >> 1, GAME_VIEW_WIDTH, GAME_VIEW_HEIGHT }; @@ -278,7 +283,7 @@ initViewports(void) static bool initGame(void) { - initViewports(); + initViewports(0); input_init(&input); texturecache_init(gRenderer); gCamera = camera_create(gRenderer); @@ -585,6 +590,26 @@ handle_main_input(void) else gui_log("Tooltips disabled"); } + + if (input_modkey_is_pressed(&input, KEY_CTRL_F)) { + bool isFullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP; + if (isFullscreen) { + initViewports(0); + SDL_SetWindowFullscreen(gWindow, 0); + } + else { + int w, h; + SDL_RenderGetLogicalSize(gRenderer, &w, &h); + + SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN_DESKTOP); + + SDL_DisplayMode dMode; + SDL_GetWindowDisplayMode(gWindow, &dMode); + double ratio = (double) w / (double) dMode.w; + double offset = (double) (dMode.w - w) / 2; + initViewports((Uint32) (offset * ratio)); + } + } } static bool @@ -755,7 +780,7 @@ render_gui(void) skillbar_render(gSkillBar, gPlayer, gCamera); SDL_RenderSetViewport(gRenderer, &bottomGuiViewport); gui_render_log(gGui, gCamera); - SDL_RenderSetViewport(gRenderer, NULL); + SDL_RenderSetViewport(gRenderer, &mainViewport); } static void @@ -902,7 +927,7 @@ run_menu(void) map_render_top_layer(gMap, gRoomMatrix, gCamera); roommatrix_render_lightmap(gRoomMatrix, gCamera); - SDL_RenderSetViewport(gRenderer, NULL); + SDL_RenderSetViewport(gRenderer, &mainViewport); if (gGameState == MENU) menu_render(mainMenu, gCamera); From a75a0d9331369889e21f9ed235f536dd0abd279d Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 30 Aug 2018 08:54:21 +0200 Subject: [PATCH 07/28] Fixes nicer fullscreen rendering Also solves some compiler warnings on linux --- .clang_complete | 2 + src/main.c | 59 +++++++++++-------- src/settings.c | 7 +++ src/settings.h | 1 + src/steam/steamworks_api_wrapper.c | 2 +- steamworks_c_wrapper/CMakeLists.txt | 1 + .../src/steamworks_c_wrapper.cpp | 6 +- .../src/steamworks_c_wrapper.h | 6 +- 8 files changed, 54 insertions(+), 30 deletions(-) diff --git a/.clang_complete b/.clang_complete index 17b71c1..e1282ec 100644 --- a/.clang_complete +++ b/.clang_complete @@ -1,4 +1,6 @@ -DDEBUG +-I./steamworks_c_api/src/ +-I./src/steam/ -I./build/config.h -I/usr/include/SDL2/ -I/usr/include/lua5.2/ diff --git a/src/main.c b/src/main.c index b5448a8..0f682e8 100644 --- a/src/main.c +++ b/src/main.c @@ -254,7 +254,7 @@ static void initViewports(Uint32 offset) { mainViewport = (SDL_Rect) { offset, 0, - SCREEN_HEIGHT, SCREEN_WIDTH + SCREEN_WIDTH, SCREEN_HEIGHT }; gameViewport = (SDL_Rect) { offset, 0, @@ -547,6 +547,31 @@ init(void) return true; } +static void +toggle_fullscreen(void) +{ + bool isFullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP; + Settings *settings = settings_get(); + if (isFullscreen) { + initViewports(0); + SDL_SetWindowFullscreen(gWindow, 0); + settings->fullscreen_enabled = false; + } + else { + int w, h; + SDL_GetWindowSize(gWindow, &w, &h); + + SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN_DESKTOP); + + SDL_DisplayMode dMode; + SDL_GetWindowDisplayMode(gWindow, &dMode); + double ratio = (double) (dMode.w) / w; + double offset = ((dMode.w - w) / 2); + initViewports((Uint32)((offset)/(ratio*2))); + settings->fullscreen_enabled = true; + } +} + static void handle_main_input(void) { @@ -592,23 +617,7 @@ handle_main_input(void) } if (input_modkey_is_pressed(&input, KEY_CTRL_F)) { - bool isFullscreen = SDL_GetWindowFlags(gWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP; - if (isFullscreen) { - initViewports(0); - SDL_SetWindowFullscreen(gWindow, 0); - } - else { - int w, h; - SDL_RenderGetLogicalSize(gRenderer, &w, &h); - - SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN_DESKTOP); - - SDL_DisplayMode dMode; - SDL_GetWindowDisplayMode(gWindow, &dMode); - double ratio = (double) w / (double) dMode.w; - double offset = (double) (dMode.w - w) / 2; - initViewports((Uint32) (offset * ratio)); - } + toggle_fullscreen(); } } @@ -643,9 +652,6 @@ handle_events(void) static bool is_player_dead(void) { -#ifdef DEBUG - gPlayer->stats.hp = gPlayer->stats.hp > 0 ? gPlayer->stats.hp : 1; -#endif // DEBUG if (gPlayer->stats.hp <= 0) { return true; } @@ -731,9 +737,10 @@ run_game_update(void) if (skillActivated && settings->tooltips_enabled && playerLevel < 5) { gGui->activeTooltip = new_skill_tooltip; } - if (!artifactTooltipShown && gPlayer->equipment.hasArtifacts && settings->tooltips_enabled) { + if (!artifactTooltipShown && gPlayer->equipment.hasArtifacts) { artifactTooltipShown = true; - gGui->activeTooltip = new_artifact_tooltip; + if (settings->tooltips_enabled) + gGui->activeTooltip = new_artifact_tooltip; } if (gGameState == PLAYING && currentTurn == PLAYER) @@ -839,6 +846,7 @@ run_game_render(void) render_game(); render_gui(); + SDL_RenderSetViewport(gRenderer, &mainViewport); particle_engine_render_global(gCamera); gui_render_tooltip(gGui, gCamera); @@ -1090,6 +1098,11 @@ int main(int argc, char *argv[]) if (!init()) return 1; + if (settings_get()->fullscreen_enabled) { + // Game starts in windowed mode so this will + // change to fullscreen + toggle_fullscreen(); + } run(); close(); PHYSFS_deinit(); diff --git a/src/settings.c b/src/settings.c index 489e1b1..1c4f13f 100644 --- a/src/settings.c +++ b/src/settings.c @@ -31,6 +31,7 @@ static const char *KEY_MUSIC_ENABLED = "music_enabled"; static const char *KEY_SOUND_ENABLED = "sound_enabled"; static const char *KEY_TOOLTIPS_ENABLED = "tooltips_enabled"; static const char *KEY_HOW_TO_PLAY_SHOWN = "how_to_play_shown"; +static const char *KEY_FULLSCREEN_ENABLED = "fullscreen_enabled"; static DbQuery MIGRATE_COMMANDS[] = { @@ -53,6 +54,7 @@ set_default_settings(void) settings.sound_enabled = true; settings.tooltips_enabled = true; settings.howto_tooltip_shown = false; + settings.fullscreen_enabled = false; } static void @@ -90,6 +92,10 @@ load_settings_cb(void *unused, int count, char **values, char **colNames) settings.howto_tooltip_shown = (bool)atoi(values[i + 1]); i += 2; } + else if (!strcmp(KEY_FULLSCREEN_ENABLED, values[i])) { + settings.fullscreen_enabled = (bool)atoi(values[i + 1]); + i += 2; + } else if (!strcmp(KEY_TOOLTIPS_ENABLED, values[i])) { settings.tooltips_enabled = (bool)atoi(values[i + 1]); i += 2; @@ -141,6 +147,7 @@ settings_save(void) save_setting_int(KEY_MUSIC_ENABLED, settings.music_enabled); save_setting_int(KEY_TOOLTIPS_ENABLED, settings.tooltips_enabled); save_setting_int(KEY_HOW_TO_PLAY_SHOWN, settings.howto_tooltip_shown); + save_setting_int(KEY_FULLSCREEN_ENABLED, settings.fullscreen_enabled); } Settings * diff --git a/src/settings.h b/src/settings.h index 91d5a25..14f197e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -26,6 +26,7 @@ typedef struct Settings { bool sound_enabled; bool tooltips_enabled; bool howto_tooltip_shown; + bool fullscreen_enabled; } Settings; void diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c index 2f1e89f..0b1209f 100644 --- a/src/steam/steamworks_api_wrapper.c +++ b/src/steam/steamworks_api_wrapper.c @@ -19,7 +19,7 @@ static Sint64 m_AppID = 0; static Sint64 m_hLeaderboard = 0; static bool -steam_request_stats() +steam_request_stats(void) { if (m_Initiated) return c_SteamUserStats_RequestCurrentStats(); diff --git a/steamworks_c_wrapper/CMakeLists.txt b/steamworks_c_wrapper/CMakeLists.txt index 127c2ee..acf2d8a 100644 --- a/steamworks_c_wrapper/CMakeLists.txt +++ b/steamworks_c_wrapper/CMakeLists.txt @@ -26,6 +26,7 @@ endif () include_directories(${STEAMWORKS_INCLUDE_DIR}) add_library(steamworks_c_wrapper + SHARED src/steamworks_c_wrapper ) diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp index 957f078..45b13b2 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -11,10 +11,10 @@ static bool m_RecvCB = false; static void(*statsReceivedCb)(void) = NULL; static void(*statsStoredCb)(void) = NULL; -static void(*leaderBoardReceived)(int64) = NULL; +static void(*leaderBoardReceived)(int64_t) = NULL; -extern "C" int64 +extern "C" int64_t c_SteamAPI_Init() { if (SteamAPI_Init()) { @@ -26,7 +26,7 @@ c_SteamAPI_Init() return 0; } -extern "C" int64 +extern "C" int64_t c_SteamAPI_GetAppID() { if (!m_Initiated) diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.h b/steamworks_c_wrapper/src/steamworks_c_wrapper.h index 29a0b72..a0035d5 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.h +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.h @@ -15,7 +15,7 @@ void c_SteamAPI_SetCallbacks(void(*)(void), void(*)(void), void(*)(int64_t)); bool -c_SteamUserStats_RequestCurrentStats(); +c_SteamUserStats_RequestCurrentStats(void); bool c_SteamUserStats_SetAchievement(const char *id); @@ -33,7 +33,7 @@ void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore); void -c_SteamAPI_Shutdown(); +c_SteamAPI_Shutdown(void); #ifdef __cplusplus class CallbackHandler @@ -46,4 +46,4 @@ public: void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure); }; -#endif // __cplusplus \ No newline at end of file +#endif // __cplusplus From 5dc25c1e7997dad37a08930bf2c2f578c40ed8f1 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 30 Aug 2018 09:12:05 +0200 Subject: [PATCH 08/28] Fixed some more fullscreen There is still a slight offset. I need to practice maths I think --- src/main.c | 7 +++++-- steamworks_c_wrapper/CMakeLists.txt | 14 ++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 0f682e8..3aeda2d 100644 --- a/src/main.c +++ b/src/main.c @@ -558,16 +558,19 @@ toggle_fullscreen(void) settings->fullscreen_enabled = false; } else { - int w, h; + int w, h, lw, lh; + SDL_RenderGetLogicalSize(gRenderer, &lw, &lh); SDL_GetWindowSize(gWindow, &w, &h); + double lratio = w / lw; + SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN_DESKTOP); SDL_DisplayMode dMode; SDL_GetWindowDisplayMode(gWindow, &dMode); double ratio = (double) (dMode.w) / w; double offset = ((dMode.w - w) / 2); - initViewports((Uint32)((offset)/(ratio*2))); + initViewports((Uint32)((offset)/(ratio*lratio))); settings->fullscreen_enabled = true; } } diff --git a/steamworks_c_wrapper/CMakeLists.txt b/steamworks_c_wrapper/CMakeLists.txt index acf2d8a..4199e59 100644 --- a/steamworks_c_wrapper/CMakeLists.txt +++ b/steamworks_c_wrapper/CMakeLists.txt @@ -25,10 +25,16 @@ endif () include_directories(${STEAMWORKS_INCLUDE_DIR}) -add_library(steamworks_c_wrapper - SHARED - src/steamworks_c_wrapper - ) +if (WIN32) + add_library(steamworks_c_wrapper + src/steamworks_c_wrapper + ) +else () + add_library(steamworks_c_wrapper + SHARED + src/steamworks_c_wrapper + ) +endif() target_link_libraries(steamworks_c_wrapper ${STEAMWORKS_LIBRARY}) From ee8274038fbe5985bc80ec9bd277d640338f72ca Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 30 Aug 2018 09:55:04 +0200 Subject: [PATCH 09/28] Prevent stunned monsters from getting scared by player --- src/player.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/player.c b/src/player.c index 70f8e07..9dd432c 100644 --- a/src/player.c +++ b/src/player.c @@ -145,7 +145,8 @@ on_monster_collision(Player *player, if (get_random(10) < player_has_artifact(player, FEAR_INDUCING)) { gui_log("%s shivers with fear at the sight of you", monster->label); - monster_set_state(monster, SCARED, 3); + if (!monster->state.current == STUNNED) + monster_set_state(monster, SCARED, 3); } } From e1c154fc1ca7ffdcbbfd0ad70d65e93d8818b4d7 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 30 Aug 2018 11:13:50 +0200 Subject: [PATCH 10/28] Fixed charge - Prevent click sound from triggering - Prevent hovering on pits if you end charge on them - Trigger traps if you end charge on them --- CMakeLists.txt | 8 ++++---- src/player.c | 10 ++++++++-- src/player.h | 3 +++ src/skill.c | 9 ++++++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ad95ea..63997d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,10 +5,10 @@ SET(CMAKE_COLOR_MAKEFILE ON) project(breakhack C) set(breakhack_GAME_TITLE "BreakHack") -set(breakhack_MAJOR_VERSION 0) -set(breakhack_MINOR_VERSION 3) -set(breakhack_PATCH_VERSION 0) -set(breakhack_RELEASE_TYPE "(beta)") +set(breakhack_MAJOR_VERSION 1) +set(breakhack_MINOR_VERSION 0) +set(breakhack_PATCH_VERSION 1) +set(breakhack_RELEASE_TYPE "") include(FindLua) include(FindPhysFS) diff --git a/src/player.c b/src/player.c index 9dd432c..fecbecd 100644 --- a/src/player.c +++ b/src/player.c @@ -208,8 +208,7 @@ has_collided(Player *player, RoomMatrix *matrix, Vector2d direction) } if (space->lethal && !collided) { - mixer_play_effect(FALL0 + get_random(2) - 1); - player->state = FALLING; + player_set_falling(player); } if (space->trap && !collided) { @@ -697,3 +696,10 @@ player_add_artifact(Player *p, Artifact *a) gui_log("%s (%u)", ad->desc, ad->level); p->equipment.hasArtifacts = true; } + +void +player_set_falling(Player *player) +{ + mixer_play_effect(FALL0 + get_random(2) - 1); + player->state = FALLING; +} diff --git a/src/player.h b/src/player.h index 07d970d..d3a9765 100644 --- a/src/player.h +++ b/src/player.h @@ -123,3 +123,6 @@ player_has_artifact(Player *, MagicalEffect); void player_add_artifact(Player*, Artifact*); + +void +player_set_falling(Player*); diff --git a/src/skill.c b/src/skill.c index b512d0b..cd77d7d 100644 --- a/src/skill.c +++ b/src/skill.c @@ -393,7 +393,7 @@ skill_charge_check_path(SkillData *data, Monster *monster = matrix->spaces[itPos.x][itPos.y].monster; Stats tmpStats = player->stats; tmpStats.dmg *= steps > 0 ? steps : 1; - mixer_play_effect(SWING0 + get_random(3) - 1); + mixer_play_effect(SWING0 + get_random(2)); unsigned int dmg = stats_fight(&tmpStats, &monster->stats); if (dmg > 0) { gui_log("You charged %s for %u damage", monster->lclabel, dmg); @@ -492,6 +492,13 @@ skill_charge(Skill *skill, SkillData *data) skill_charge_check_path(data, playerStartPos, destination); + Position lastTilePos = position_to_matrix_coords(&playerDestinationPos); + RoomSpace *destSpace = &matrix->spaces[lastTilePos.x][lastTilePos.y]; + if (destSpace->lethal) + player_set_falling(player); + else if (destSpace->trap) + trap_activate(destSpace->trap, player); + return true; } From 40134498786299030030827c0f72d46e13f6d381 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 30 Aug 2018 11:32:09 +0200 Subject: [PATCH 11/28] Adds information to player - Fullscreen command is listed - ESC to go back from views is listed --- src/main.c | 16 +++++++++------- src/screen.c | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 3aeda2d..0615d28 100644 --- a/src/main.c +++ b/src/main.c @@ -99,19 +99,21 @@ static char *skills_tooltip[] = { static char *how_to_play_tooltip[] = { "HOW TO PLAY", "", - " NAVIGATION: Use ARROWS or WASD or HJKL to move", + " NAVIGATION: Use ARROWS or WASD or HJKL to move", "", - " ATTACK: Walk into a monster to attack it", + " ATTACK: Walk into a monster to attack it", "", - " THROW DAGGER: Press 4 then chose a direction (navigation keys)", + " THROW DAGGER: Press 4 then chose a direction (nav keys)", "", - " DRINK HEALTH: Press 5 (if you need health and have potions)", + " DRINK HEALTH: Press 5 (if you need health and have potions)", "", - " TOGGLE MUSIC: CTRL + M", + " TOGGLE MUSIC: CTRL + M", "", - " TOGGLE SOUND: CTRL + S", + " TOGGLE SOUND: CTRL + S", "", - " TOGGLE MENU: ESC", + " TOGGLE FULLSCREEN: CTRL + F", + "", + " TOGGLE MENU: ESC", "", " Your stats and inventory are listed in the right panel", "", diff --git a/src/screen.c b/src/screen.c index 4781535..7ebdb31 100644 --- a/src/screen.c +++ b/src/screen.c @@ -95,6 +95,7 @@ screen_create_credits(SDL_Renderer *renderer) linkedlist_push(&screen->sprites, credit_txt("ArtisticDuded", C_WHITE, x + columnOffset, y, renderer)); y += 20; linkedlist_push(&screen->sprites, credit_txt("opengameart.org/users/artisticdude", C_WHITE, x + columnOffset, y, renderer)); + linkedlist_push(&screen->sprites, score_txt("Press ESC to go back", C_RED, 15, SCREEN_HEIGHT - 25, renderer)); return screen; } @@ -164,6 +165,7 @@ screen_create_hiscore(SDL_Renderer *renderer) renderer)); hiscore_destroy(score); } + linkedlist_push(&screen->sprites, score_txt("Press ESC to go back", C_RED, 15, SCREEN_HEIGHT - 25, renderer)); return screen; } From 0ae8849323896e49c6faff939524e6fcde785a6b Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 30 Aug 2018 14:01:28 +0200 Subject: [PATCH 12/28] Removed a stupid mistake --- src/player.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/player.c b/src/player.c index fecbecd..9be7a7b 100644 --- a/src/player.c +++ b/src/player.c @@ -145,7 +145,7 @@ on_monster_collision(Player *player, if (get_random(10) < player_has_artifact(player, FEAR_INDUCING)) { gui_log("%s shivers with fear at the sight of you", monster->label); - if (!monster->state.current == STUNNED) + if (monster->state.current != STUNNED) monster_set_state(monster, SCARED, 3); } } From 41a2b1b8f8e9de529ef679a8b6fc064bd4e50882 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 30 Aug 2018 14:08:34 +0200 Subject: [PATCH 13/28] Fixes fullscreen centering on hirez screens --- src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 0615d28..d7ae48e 100644 --- a/src/main.c +++ b/src/main.c @@ -564,7 +564,7 @@ toggle_fullscreen(void) SDL_RenderGetLogicalSize(gRenderer, &lw, &lh); SDL_GetWindowSize(gWindow, &w, &h); - double lratio = w / lw; + double lratio = (double) w / (double) lw; SDL_SetWindowFullscreen(gWindow, SDL_WINDOW_FULLSCREEN_DESKTOP); @@ -572,7 +572,7 @@ toggle_fullscreen(void) SDL_GetWindowDisplayMode(gWindow, &dMode); double ratio = (double) (dMode.w) / w; double offset = ((dMode.w - w) / 2); - initViewports((Uint32)((offset)/(ratio*lratio))); + initViewports((Uint32)(offset/(ratio*lratio))); settings->fullscreen_enabled = true; } } From 0ca64fb882c9cf46a89d45443dd3f9feb1157552 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Fri, 31 Aug 2018 15:58:59 +0200 Subject: [PATCH 14/28] Added kills leaderboard - Restructured the code a bit to avoid c vs c++ conflicts. --- src/main.c | 1 + src/steam/steamworks_api_wrapper.c | 61 +++++++++++++++---- src/steam/steamworks_api_wrapper.h | 4 +- steamworks_c_wrapper/CMakeLists.txt | 1 + steamworks_c_wrapper/src/CallbackHandler.cpp | 44 +++++++++++++ steamworks_c_wrapper/src/CallbackHandler.h | 24 ++++++++ .../src/steamworks_c_wrapper.cpp | 59 +++--------------- .../src/steamworks_c_wrapper.h | 17 +----- 8 files changed, 134 insertions(+), 77 deletions(-) create mode 100644 steamworks_c_wrapper/src/CallbackHandler.cpp create mode 100644 steamworks_c_wrapper/src/CallbackHandler.h diff --git a/src/main.c b/src/main.c index d7ae48e..c4cf3da 100644 --- a/src/main.c +++ b/src/main.c @@ -895,6 +895,7 @@ run_game(void) hiscore_register(gPlayer, cLevel); #ifdef STEAM_BUILD steam_register_score((int)hiscore_get_top_gold()); + steam_register_kills((int) gPlayer->stat_data.kills); #endif // STEAM_BUILD } else { diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c index 0b1209f..ac597b6 100644 --- a/src/steam/steamworks_api_wrapper.c +++ b/src/steam/steamworks_api_wrapper.c @@ -1,9 +1,14 @@ #include +#include #include "steamworks_api_wrapper.h" #include "steamworks_c_wrapper.h" #include "../util.h" #include "../defines.h" #include "../gui.h" +#include "../timer.h" + +static const char *LB_HIGHSCORE = "Highscore"; +static const char *LB_KILLS = "Most Kills"; static Achievement g_Achievements[] = { _ACH_ID(BAD_DOG, "Bad Dog"), @@ -15,8 +20,12 @@ static Achievement g_Achievements[] = { static Uint8 numAchievements = 5; static bool m_Initiated = false; +static bool m_bStatsReceived = false; static Sint64 m_AppID = 0; -static Sint64 m_hLeaderboard = 0; +static Sint64 m_hHighscoreLeaderboard = 0; +static Sint64 m_hKillsLeaderboard = 0; + +static Timer *requestDataTimer = NULL; static bool steam_request_stats(void) @@ -30,6 +39,7 @@ static void stats_received(void) { debug("Steam stats received"); + m_bStatsReceived = true; } static void @@ -39,32 +49,54 @@ stats_stored(void) } static void -leaderboard_received(Sint64 hLeaderboard) +leaderboard_received(Sint64 hLeaderboard, const char *name) { - m_hLeaderboard = hLeaderboard; + debug("Leaderboard received: %s", name); + if (strcmp(LB_HIGHSCORE, name) == 0) + m_hHighscoreLeaderboard = hLeaderboard; + else if (strcmp(LB_KILLS, name) == 0) + m_hKillsLeaderboard = hLeaderboard; } void steam_init() { - c_SteamAPI_SetCallbacks(stats_received, stats_stored, leaderboard_received); m_AppID = c_SteamAPI_Init(); + c_SteamAPI_SetCallbacks(stats_received, stats_stored, leaderboard_received); m_Initiated = m_AppID != 0; - if (m_Initiated) { - steam_request_stats(); - c_SteamUserStats_FindLeaderboard("Highscore"); - } + requestDataTimer = timer_create(); } void steam_shutdown(void) { c_SteamAPI_Shutdown(); + timer_destroy(requestDataTimer); +} + +void +request_data_queue_run(void) +{ + if (!timer_started(requestDataTimer)) + timer_start(requestDataTimer); + + if (timer_get_ticks(requestDataTimer) > 1000) { + if (!m_bStatsReceived) + steam_request_stats(); + else if (!m_hHighscoreLeaderboard) + c_SteamUserStats_FindLeaderboard(LB_HIGHSCORE); + else if (!m_hKillsLeaderboard) + c_SteamUserStats_FindLeaderboard(LB_KILLS); + + timer_start(requestDataTimer); + } } void steam_run_callbacks(void) { - if (m_Initiated) + if (m_Initiated) { c_SteamAPI_RunCallbacks(); + request_data_queue_run(); + } } void steam_set_achievement(EAchievement eAch) @@ -80,7 +112,14 @@ void steam_set_achievement(EAchievement eAch) void steam_register_score(Sint32 nScore) { - if (!m_hLeaderboard) + if (!m_hHighscoreLeaderboard) return; - c_SteamUserStats_UploadLeaderboardScore(m_hLeaderboard, nScore); + c_SteamUserStats_UploadLeaderboardScore(m_hHighscoreLeaderboard, nScore); } + +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/src/steam/steamworks_api_wrapper.h b/src/steam/steamworks_api_wrapper.h index 42f0ba1..52ec293 100644 --- a/src/steam/steamworks_api_wrapper.h +++ b/src/steam/steamworks_api_wrapper.h @@ -31,4 +31,6 @@ void steam_run_callbacks(void); void steam_set_achievement(EAchievement eAch); -void steam_register_score(Sint32 nScore); \ No newline at end of file +void steam_register_score(Sint32 nScore); + +void steam_register_kills(Sint32 nKills); diff --git a/steamworks_c_wrapper/CMakeLists.txt b/steamworks_c_wrapper/CMakeLists.txt index 4199e59..731c097 100644 --- a/steamworks_c_wrapper/CMakeLists.txt +++ b/steamworks_c_wrapper/CMakeLists.txt @@ -28,6 +28,7 @@ include_directories(${STEAMWORKS_INCLUDE_DIR}) if (WIN32) add_library(steamworks_c_wrapper src/steamworks_c_wrapper + src/CallbackHandler ) else () add_library(steamworks_c_wrapper diff --git a/steamworks_c_wrapper/src/CallbackHandler.cpp b/steamworks_c_wrapper/src/CallbackHandler.cpp new file mode 100644 index 0000000..2750955 --- /dev/null +++ b/steamworks_c_wrapper/src/CallbackHandler.cpp @@ -0,0 +1,44 @@ +#include "CallbackHandler.h" + +CallbackHandler::CallbackHandler(int64 appId) : + m_CallbackUserStatsReceived(this, &CallbackHandler::OnUserStatsReceived), + m_CallbackUserStatsStored(this, &CallbackHandler::OnUserStatsStored), + m_AppId(appId) +{ + // Nothing +} + +void +CallbackHandler::OnUserStatsReceived(UserStatsReceived_t *pCallback) +{ + if (m_AppId != pCallback->m_nGameID) + return; + + m_bStatsCallbackReceived = true; + if (statsReceivedCb && k_EResultOK == pCallback->m_eResult) + statsReceivedCb(); +} + +void +CallbackHandler::OnUserStatsStored(UserStatsStored_t *pCallback) +{ + if (m_AppId != pCallback->m_nGameID) + return; + + if (statsStoredCb && k_EResultOK == pCallback->m_eResult) + statsStoredCb(); +} + +bool CallbackHandler::CallbackReceived() const +{ + return m_bStatsCallbackReceived; +} + +void CallbackHandler::OnFindLeaderboard(LeaderboardFindResult_t * pCallback, bool bIOFailiure) +{ + if (bIOFailiure || !pCallback->m_bLeaderboardFound) + return; + + if (leaderboardReceivedCb) + leaderboardReceivedCb(pCallback->m_hSteamLeaderboard, SteamUserStats()->GetLeaderboardName(pCallback->m_hSteamLeaderboard)); +} \ No newline at end of file diff --git a/steamworks_c_wrapper/src/CallbackHandler.h b/steamworks_c_wrapper/src/CallbackHandler.h new file mode 100644 index 0000000..2abba9b --- /dev/null +++ b/steamworks_c_wrapper/src/CallbackHandler.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +class CallbackHandler +{ +private: + int64 m_AppId = 0; + bool m_bStatsCallbackReceived = false; + +public: + CallbackHandler(int64 appId); + STEAM_CALLBACK(CallbackHandler, OnUserStatsReceived, UserStatsReceived_t, m_CallbackUserStatsReceived); + STEAM_CALLBACK(CallbackHandler, OnUserStatsStored, UserStatsStored_t, m_CallbackUserStatsStored); + CCallResult m_FindLeaderboardCallResult; + + void(*statsReceivedCb)() = nullptr; + void(*statsStoredCb)() = nullptr; + void(*leaderboardReceivedCb)(int64, 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 45b13b2..296a157 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -3,23 +3,18 @@ extern "C" { #include "steamworks_c_wrapper.h" } +#include "CallbackHandler.h" static bool m_Initiated = false; static int64 m_AppId = 0; static CallbackHandler *m_CallbackHandler = NULL; -static bool m_RecvCB = false; - -static void(*statsReceivedCb)(void) = NULL; -static void(*statsStoredCb)(void) = NULL; -static void(*leaderBoardReceived)(int64_t) = NULL; - extern "C" int64_t c_SteamAPI_Init() { if (SteamAPI_Init()) { m_AppId = SteamUtils()->GetAppID(); - m_CallbackHandler = new CallbackHandler(); + m_CallbackHandler = new CallbackHandler(m_AppId); m_Initiated = true; return m_AppId; } @@ -42,11 +37,11 @@ c_SteamAPI_RunCallbacks(void) SteamAPI_RunCallbacks(); } -extern "C" void c_SteamAPI_SetCallbacks(void(*recvCB)(void), void(*storCB)(void), void(*recvLB)(int64_t)) +extern "C" void c_SteamAPI_SetCallbacks(void(*recvCB)(void), void(*storCB)(void), void(*recvLB)(int64_t, const char *)) { - statsReceivedCb = recvCB; - statsStoredCb = storCB; - leaderBoardReceived = recvLB; + m_CallbackHandler->statsReceivedCb = recvCB; + m_CallbackHandler->statsStoredCb = storCB; + m_CallbackHandler->leaderboardReceivedCb = recvLB; } extern "C" void @@ -70,7 +65,7 @@ c_SteamUserStats_RequestCurrentStats() extern "C" bool c_SteamUserStats_SetAchievement(const char *pchName) { - if (!m_RecvCB) + if (m_CallbackHandler && !m_CallbackHandler->CallbackReceived()) return false; bool result = SteamUserStats()->SetAchievement(pchName); @@ -97,53 +92,17 @@ c_SteamUserStats_GetAchievementDisplayAttribute(const char *achId, const char *a extern "C" void c_SteamUserStats_FindLeaderboard(const char * name) { - if (!m_Initiated) + if (!m_Initiated || !m_CallbackHandler) return; SteamAPICall_t hSteamAPICall = SteamUserStats()->FindLeaderboard(name); m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard); } -extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32 nScore) +extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore) { if (!hLeaderboard || !m_Initiated) return; SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, nullptr, 0); } - -CallbackHandler::CallbackHandler() : - m_CallbackUserStatsReceived(this, &CallbackHandler::OnUserStatsReceived), - m_CallbackUserStatsStored(this, &CallbackHandler::OnUserStatsStored) -{ - // Nothing -} - -void -CallbackHandler::OnUserStatsReceived(UserStatsReceived_t *pCallback) -{ - if (m_AppId != pCallback->m_nGameID) - return; - m_RecvCB = true; - if (statsReceivedCb && k_EResultOK == pCallback->m_eResult) - statsReceivedCb(); -} - -void -CallbackHandler::OnUserStatsStored(UserStatsStored_t *pCallback) -{ - if (m_AppId != pCallback->m_nGameID) - return; - - if (statsStoredCb && k_EResultOK == pCallback->m_eResult) - statsStoredCb(); -} - -void CallbackHandler::OnFindLeaderboard(LeaderboardFindResult_t * pCallback, bool bIOFailiure) -{ - if (bIOFailiure || !pCallback->m_bLeaderboardFound) - return; - - if (leaderBoardReceived) - leaderBoardReceived(pCallback->m_hSteamLeaderboard); -} diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.h b/steamworks_c_wrapper/src/steamworks_c_wrapper.h index a0035d5..54b2a7c 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.h +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.h @@ -12,7 +12,7 @@ void c_SteamAPI_RunCallbacks(void); void -c_SteamAPI_SetCallbacks(void(*)(void), void(*)(void), void(*)(int64_t)); +c_SteamAPI_SetCallbacks(void(*recvCB)(void), void(*storCB)(void), void(*recvLB)(int64_t, const char *)); bool c_SteamUserStats_RequestCurrentStats(void); @@ -33,17 +33,4 @@ void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore); void -c_SteamAPI_Shutdown(void); - -#ifdef __cplusplus -class CallbackHandler -{ -public: - CallbackHandler(); - STEAM_CALLBACK(CallbackHandler, OnUserStatsReceived, UserStatsReceived_t, m_CallbackUserStatsReceived); - STEAM_CALLBACK(CallbackHandler, OnUserStatsStored, UserStatsStored_t, m_CallbackUserStatsStored); - CCallResult m_FindLeaderboardCallResult; - - void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure); -}; -#endif // __cplusplus +c_SteamAPI_Shutdown(void); \ No newline at end of file From ef0e418e961d52e2471780dd7781613f662172f1 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 2 Sep 2018 06:04:24 +0200 Subject: [PATCH 15/28] 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; } From 3acedb93dfa60ba85f9b7fc06ea410a1e32fca6c Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 2 Sep 2018 07:15:48 +0200 Subject: [PATCH 16/28] Lifted the patch version - The "infinite loop fix" merits a patch version increase. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63997d3..ca13619 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(breakhack C) set(breakhack_GAME_TITLE "BreakHack") set(breakhack_MAJOR_VERSION 1) set(breakhack_MINOR_VERSION 0) -set(breakhack_PATCH_VERSION 1) +set(breakhack_PATCH_VERSION 2) set(breakhack_RELEASE_TYPE "") include(FindLua) From a6d96da067b0e9ba69ecd10c32cd3950cc8f1d3d Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 2 Sep 2018 13:52:34 +0200 Subject: [PATCH 17/28] Removes packaging from CI Precompiled versions can be retrieved from STEAM from now on. But users are most welcome to compile the source if they want to. --- .appveyor.yml | 32 ++++++++++++++++---------------- .travis.yml | 29 ++++++++++++++--------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index d9675c9..8f67fe4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -91,24 +91,24 @@ build_script: - |- mingw32-make ctest -V - mingw32-make package +# mingw32-make package -artifacts: - - path: package/breakhack-*.zip - name: breakhack_zip +# artifacts: +# - path: package/breakhack-*.zip +# name: breakhack_zip - - path: package/breakhack-*.exe - name: breakhack_exe +# - path: package/breakhack-*.exe +# name: breakhack_exe -deploy: - provider: GitHub - description: 'Alpha pre-release' - auth_token: - secure: IlMEyGp0AuDI8/MkFAY2KpRr70c3p8eVEMdcqC1EcgyCCbvoMOppBQ0gY44ao0gq - draft: false - prerelease: true - on: - branch: master - appveyor_repo_tag: true +# deploy: +# provider: GitHub +# description: 'Alpha pre-release' +# auth_token: +# secure: IlMEyGp0AuDI8/MkFAY2KpRr70c3p8eVEMdcqC1EcgyCCbvoMOppBQ0gY44ao0gq +# draft: false +# prerelease: true +# on: +# branch: master +# appveyor_repo_tag: true diff --git a/.travis.yml b/.travis.yml index 0377e20..5f2d39b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,19 +52,18 @@ addons: build_command: "make" branch_pattern: coverity_scan -before_deploy: - - make package +# before_deploy: +# - make package -deploy: - provider: releases - api_key: - secure: "KeT/BC2ck2eqs1q4keoLe/Y9KIk+AR5shiAnA2oMQzbLWoZmxUx3Kol7rLPJ0Hfgb+aCpSpTM1njX6Kw7Nl8j4NrOkgadb3ZmfqRthFazzb93reRt+0dZZcurilHpWtMeteaZLWGWaG0j09xnI3CPPjmth6BB+/roGRsQyo1QKk0pZYsQD6ZKfGAUR1576dFyRzvsIrnfLd7rZVSNZ8HtPwN2rmSLD/cGxMCf+IafcBInPyv9p6bCoVLIDFnDdCr+kwBuSlGudT15EtDx3d9Abab3ZIS3NUpnXr2s0BmknCpyb59YsG9V0YXIQsIkwioEWiJskcAznXT/yB4XqDCq693b+0sxldsUVPw2JkMU+40V5ay2itH3SeP/LyXVFUARdWB+nn6avaFRVaZ1nHYP95CrBXC8JGB1bd7ejeEm9+cOvBOgvsZp71uRJ2OdEXN5Z3i373cyvWXPFHVbQRJS5l1dRBJR0sozYcPe8BMQ4Pv+xahFWIeyDAErUwJSiOf1Uv/x6PNxJaZTTZKCYGSRo6Ywb15bw4YnlOzDXllBxNg3IsJjJes1qFBJGR1eRMq/U9Ne+eHLk7cn2r7Fa77DtFsbONTDHftXDFHk46LDLF+HlL2wHIoTJVzLl/tXyBm3MJuaghGEvvZSwalWS3UnvMTQOBlDG0qC/ww6mlkv+Y=" - skip_cleanup: true - file_glob: true - file: - - "package/breakhack*.tar.gz" - - "package/breakhack*.tar.Z" - on: - tags: true - condition: $CC = gcc - condition: $BUILD_TYPE = Release +# deploy: +# provider: releases +# api_key: +# secure: "KeT/BC2ck2eqs1q4keoLe/Y9KIk+AR5shiAnA2oMQzbLWoZmxUx3Kol7rLPJ0Hfgb+aCpSpTM1njX6Kw7Nl8j4NrOkgadb3ZmfqRthFazzb93reRt+0dZZcurilHpWtMeteaZLWGWaG0j09xnI3CPPjmth6BB+/roGRsQyo1QKk0pZYsQD6ZKfGAUR1576dFyRzvsIrnfLd7rZVSNZ8HtPwN2rmSLD/cGxMCf+IafcBInPyv9p6bCoVLIDFnDdCr+kwBuSlGudT15EtDx3d9Abab3ZIS3NUpnXr2s0BmknCpyb59YsG9V0YXIQsIkwioEWiJskcAznXT/yB4XqDCq693b+0sxldsUVPw2JkMU+40V5ay2itH3SeP/LyXVFUARdWB+nn6avaFRVaZ1nHYP95CrBXC8JGB1bd7ejeEm9+cOvBOgvsZp71uRJ2OdEXN5Z3i373cyvWXPFHVbQRJS5l1dRBJR0sozYcPe8BMQ4Pv+xahFWIeyDAErUwJSiOf1Uv/x6PNxJaZTTZKCYGSRo6Ywb15bw4YnlOzDXllBxNg3IsJjJes1qFBJGR1eRMq/U9Ne+eHLk7cn2r7Fa77DtFsbONTDHftXDFHk46LDLF+HlL2wHIoTJVzLl/tXyBm3MJuaghGEvvZSwalWS3UnvMTQOBlDG0qC/ww6mlkv+Y=" +# skip_cleanup: true +# file_glob: true +# file: +# - "package/breakhack*.tar.gz" +# on: +# tags: true +# condition: $CC = gcc +# condition: $BUILD_TYPE = Release From 57b7831a458a4765abf92d9e91c1d251ddeed910 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 2 Sep 2018 17:21:43 +0200 Subject: [PATCH 18/28] Remove appid from git --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca13619..90d7315 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -343,7 +343,6 @@ if (WIN32) SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} steamworks_c_wrapper/sdk/redistributable_bin/steam_api.dll - build/steam/steam_appid.txt ) endif () endif (WIN32) From b962d55510d7a86cf576429921b7b242a7df544c Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 2 Sep 2018 17:39:43 +0200 Subject: [PATCH 19/28] Fixed stupid issue with steam sync --- steamworks_c_wrapper/src/steamworks_c_wrapper.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp index 3123c4f..2148dfe 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -12,13 +12,12 @@ 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_Initiated = true; - return m_AppId; } - return 0; + m_CallbackHandler = new CallbackHandler(m_AppId); + return m_AppId; } extern "C" int64_t From 9bcb398f94a10b05c494b2a9c0656e068d0f870d Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 2 Sep 2018 23:44:48 +0200 Subject: [PATCH 20/28] Includes player and dungeon level in steam leaderboards. - Intended for use in the in game leaderboard view once I make that. --- CMakeLists.txt | 2 +- src/main.c | 5 +++-- src/steam/steamworks_api_wrapper.c | 8 ++++---- src/steam/steamworks_api_wrapper.h | 4 ++-- steamworks_c_wrapper/src/steamworks_c_wrapper.cpp | 4 ++-- steamworks_c_wrapper/src/steamworks_c_wrapper.h | 4 ++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90d7315..34a594c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(breakhack C) set(breakhack_GAME_TITLE "BreakHack") set(breakhack_MAJOR_VERSION 1) set(breakhack_MINOR_VERSION 0) -set(breakhack_PATCH_VERSION 2) +set(breakhack_PATCH_VERSION 3) set(breakhack_RELEASE_TYPE "") include(FindLua) diff --git a/src/main.c b/src/main.c index c4cf3da..0fbadca 100644 --- a/src/main.c +++ b/src/main.c @@ -894,8 +894,9 @@ run_game(void) createInGameGameOverMenu(); hiscore_register(gPlayer, cLevel); #ifdef STEAM_BUILD - steam_register_score((int)hiscore_get_top_gold()); - steam_register_kills((int) gPlayer->stat_data.kills); + uint8_t details[4] = { (uint8_t) gPlayer->stats.lvl, (uint8_t) cLevel, 0, 0 }; + steam_register_score((int) gPlayer->gold, &details, 1); + steam_register_kills((int) gPlayer->stat_data.kills, (int32_t*) &details, 1); #endif // STEAM_BUILD } else { diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c index 716cdde..05f1a51 100644 --- a/src/steam/steamworks_api_wrapper.c +++ b/src/steam/steamworks_api_wrapper.c @@ -111,16 +111,16 @@ void steam_set_achievement(EAchievement eAch) } } -void steam_register_score(Sint32 nScore) +void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetails) { if (!m_hHighscoreLeaderboard) return; - c_SteamUserStats_UploadLeaderboardScore(m_hHighscoreLeaderboard, nScore); + c_SteamUserStats_UploadLeaderboardScore(m_hHighscoreLeaderboard, nScore, details, nDetails); } -void steam_register_kills(Sint32 nKills) +void steam_register_kills(Sint32 nKills, const int32_t *details, int32_t nDetails) { if (!m_hKillsLeaderboard) return; - c_SteamUserStats_UploadLeaderboardScore(m_hKillsLeaderboard, nKills); + c_SteamUserStats_UploadLeaderboardScore(m_hKillsLeaderboard, nKills, details, nDetails); } diff --git a/src/steam/steamworks_api_wrapper.h b/src/steam/steamworks_api_wrapper.h index 52ec293..9a3be52 100644 --- a/src/steam/steamworks_api_wrapper.h +++ b/src/steam/steamworks_api_wrapper.h @@ -31,6 +31,6 @@ void steam_run_callbacks(void); void steam_set_achievement(EAchievement eAch); -void steam_register_score(Sint32 nScore); +void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetails); -void steam_register_kills(Sint32 nKills); +void steam_register_kills(Sint32 nKills, const int32_t *details, int32_t nDetails); diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp index 3123c4f..66d2c2d 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -99,10 +99,10 @@ c_SteamUserStats_FindLeaderboard(const char * name) m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard); } -extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore) +extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, int32_t *details, int32_t nDetails) { if (!hLeaderboard || !m_Initiated) return; - SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, nullptr, 0); + SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, details, nDetails); } diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.h b/steamworks_c_wrapper/src/steamworks_c_wrapper.h index 54b2a7c..d99b565 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.h +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.h @@ -30,7 +30,7 @@ void c_SteamUserStats_FindLeaderboard(const char *name); void -c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore); +c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, int32_t *details, int32_t nDetails); void -c_SteamAPI_Shutdown(void); \ No newline at end of file +c_SteamAPI_Shutdown(void); From 37518c100d1b8748696e72c6529805e47c30f83e Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Sun, 2 Sep 2018 23:44:48 +0200 Subject: [PATCH 21/28] Includes player and dungeon level in steam leaderboards. - Intended for use in the in game leaderboard view once I make that. --- CMakeLists.txt | 2 +- src/main.c | 5 +++-- src/steam/steamworks_api_wrapper.c | 8 ++++---- src/steam/steamworks_api_wrapper.h | 4 ++-- steamworks_c_wrapper/src/steamworks_c_wrapper.cpp | 4 ++-- steamworks_c_wrapper/src/steamworks_c_wrapper.h | 4 ++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90d7315..34a594c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(breakhack C) set(breakhack_GAME_TITLE "BreakHack") set(breakhack_MAJOR_VERSION 1) set(breakhack_MINOR_VERSION 0) -set(breakhack_PATCH_VERSION 2) +set(breakhack_PATCH_VERSION 3) set(breakhack_RELEASE_TYPE "") include(FindLua) diff --git a/src/main.c b/src/main.c index c4cf3da..0fbadca 100644 --- a/src/main.c +++ b/src/main.c @@ -894,8 +894,9 @@ run_game(void) createInGameGameOverMenu(); hiscore_register(gPlayer, cLevel); #ifdef STEAM_BUILD - steam_register_score((int)hiscore_get_top_gold()); - steam_register_kills((int) gPlayer->stat_data.kills); + uint8_t details[4] = { (uint8_t) gPlayer->stats.lvl, (uint8_t) cLevel, 0, 0 }; + steam_register_score((int) gPlayer->gold, &details, 1); + steam_register_kills((int) gPlayer->stat_data.kills, (int32_t*) &details, 1); #endif // STEAM_BUILD } else { diff --git a/src/steam/steamworks_api_wrapper.c b/src/steam/steamworks_api_wrapper.c index 716cdde..05f1a51 100644 --- a/src/steam/steamworks_api_wrapper.c +++ b/src/steam/steamworks_api_wrapper.c @@ -111,16 +111,16 @@ void steam_set_achievement(EAchievement eAch) } } -void steam_register_score(Sint32 nScore) +void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetails) { if (!m_hHighscoreLeaderboard) return; - c_SteamUserStats_UploadLeaderboardScore(m_hHighscoreLeaderboard, nScore); + c_SteamUserStats_UploadLeaderboardScore(m_hHighscoreLeaderboard, nScore, details, nDetails); } -void steam_register_kills(Sint32 nKills) +void steam_register_kills(Sint32 nKills, const int32_t *details, int32_t nDetails) { if (!m_hKillsLeaderboard) return; - c_SteamUserStats_UploadLeaderboardScore(m_hKillsLeaderboard, nKills); + c_SteamUserStats_UploadLeaderboardScore(m_hKillsLeaderboard, nKills, details, nDetails); } diff --git a/src/steam/steamworks_api_wrapper.h b/src/steam/steamworks_api_wrapper.h index 52ec293..9a3be52 100644 --- a/src/steam/steamworks_api_wrapper.h +++ b/src/steam/steamworks_api_wrapper.h @@ -31,6 +31,6 @@ void steam_run_callbacks(void); void steam_set_achievement(EAchievement eAch); -void steam_register_score(Sint32 nScore); +void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetails); -void steam_register_kills(Sint32 nKills); +void steam_register_kills(Sint32 nKills, const int32_t *details, int32_t nDetails); diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp index 3123c4f..66d2c2d 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -99,10 +99,10 @@ c_SteamUserStats_FindLeaderboard(const char * name) m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard); } -extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore) +extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, int32_t *details, int32_t nDetails) { if (!hLeaderboard || !m_Initiated) return; - SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, nullptr, 0); + SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, details, nDetails); } diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.h b/steamworks_c_wrapper/src/steamworks_c_wrapper.h index 54b2a7c..d99b565 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.h +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.h @@ -30,7 +30,7 @@ void c_SteamUserStats_FindLeaderboard(const char *name); void -c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore); +c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, int32_t *details, int32_t nDetails); void -c_SteamAPI_Shutdown(void); \ No newline at end of file +c_SteamAPI_Shutdown(void); From 4a6422fc0943ead0c32acbd4a927f93131cfbba8 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 3 Sep 2018 08:43:05 +0200 Subject: [PATCH 22/28] Fixes non-existant treasure bug --- src/item_builder.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/item_builder.c b/src/item_builder.c index e4be90e..80b3e78 100644 --- a/src/item_builder.c +++ b/src/item_builder.c @@ -116,13 +116,14 @@ create_treasure(int current_level) unsigned int value; amt = (unsigned int) 1 + get_random(5*current_level) % 40; + amt = amt == 0 ? 1 : amt; if (current_level > 9) { - highest_treasure = TREASURE_COUNT; - } else if (current_level > 3) { highest_treasure = PLATINUM; - } else { + } else if (current_level > 3) { highest_treasure = GOLD; + } else { + highest_treasure = SILVER; } value = get_random(highest_treasure); From 6e7ce815fd6d8e63b57ebeb08ba01901368e51de Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 3 Sep 2018 12:53:12 +0200 Subject: [PATCH 23/28] Removes useless transfer function --- src/player.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/player.c b/src/player.c index 9be7a7b..fb9427d 100644 --- a/src/player.c +++ b/src/player.c @@ -105,12 +105,6 @@ action_spent(Player *p) } } -static void -player_step(Player *p) -{ - action_spent(p); -} - static void on_monster_collision(Player *player, Monster *monster, @@ -267,7 +261,7 @@ move(Player *player, RoomMatrix *matrix, Vector2d direction) player->sprite->pos.y += TILE_DIMENSION * (int) direction.y; if (!has_collided(player, matrix, direction)) { - player_step(player); + action_spent(player); } } @@ -340,7 +334,7 @@ use_skill(Skill *skill, SkillData *skillData) skill->active = false; skill->use(skill, skillData); if (skill->actionRequired) - player_step(skillData->player); + action_spent(skillData->player); skill->resetCountdown = skill->resetTime; } From 07d7d6e58bb2079a3fe6d57a08e1192f9b23ece5 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 3 Sep 2018 16:49:45 +0200 Subject: [PATCH 24/28] Added easteregg monsters and a funny achievement --- data/monstergen.lua | 18 ++++++++++++++++++ src/main.c | 2 +- src/player.c | 3 +++ src/steam/steamworks_api_wrapper.h | 3 ++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/data/monstergen.lua b/data/monstergen.lua index 719d705..9099b98 100644 --- a/data/monstergen.lua +++ b/data/monstergen.lua @@ -258,6 +258,20 @@ bosses[1] = concat({ texturePaths.dog0, texturePaths.dog1 }, bosses[1]) bosses[2] = concat({ texturePaths.humanoid0, texturePaths.humanoid1 }, bosses[2]) bosses[3] = concat({ texturePaths.undead0, texturePaths.undead1 }, bosses[3]) +local eastereggs = { + { stats.misc, 6*16, 1*16, "Linus, the Developer", behaviour.passive }, + { stats.misc, 4*16, 1*16, "Scanlan, the Bard", behaviour.passive }, + { stats.misc, 2*16, 4*16, "Vax, the Twin", behaviour.passive }, + { stats.misc, 2*16, 3*16, "Vex, the Twin", behaviour.passive }, + { stats.misc, 0*16,10*16, "Grog, the Barbarian", behaviour.passive }, + { stats.misc, 3*16, 4*16, "Percy, the Gunslinger", behaviour.passive }, + { stats.misc, 4*16, 0*16, "Pike, the Cleric", behaviour.passive }, + { stats.misc, 6*16, 7*16, "Keyleth, the Druid", behaviour.passive }, +} +for i=1,#eastereggs do + eastereggs[i] = concat({ texturePaths.player0, texturePaths.player1 }, eastereggs[i]) +end + local platino = { { texturePaths.reptile0, @@ -313,6 +327,10 @@ if(CURRENT_LEVEL > 0) then end end +if random(100) == 1 then + enemies[#enemies+1] = eastereggs[random(#eastereggs)] +end + if random(100) == 1 then enemies = concat(enemies, platino) end diff --git a/src/main.c b/src/main.c index 0fbadca..1f69e60 100644 --- a/src/main.c +++ b/src/main.c @@ -895,7 +895,7 @@ run_game(void) hiscore_register(gPlayer, cLevel); #ifdef STEAM_BUILD uint8_t details[4] = { (uint8_t) gPlayer->stats.lvl, (uint8_t) cLevel, 0, 0 }; - steam_register_score((int) gPlayer->gold, &details, 1); + steam_register_score((int) gPlayer->gold, (int32_t*) &details, 1); steam_register_kills((int) gPlayer->stat_data.kills, (int32_t*) &details, 1); #endif // STEAM_BUILD diff --git a/src/player.c b/src/player.c index fb9427d..afd60f8 100644 --- a/src/player.c +++ b/src/player.c @@ -521,6 +521,9 @@ player_monster_kill_check(Player *player, Monster *monster) steam_set_achievement(DRAGON_SLAYER); else if (strcmp("The Cleric", monster->label) == 0) steam_set_achievement(THE_DOCTOR_IS_OUT); + else if (strcmp("Linus, the Developer", monster->label) == 0) + steam_set_achievement(BUGGFIXER); + #endif // STEAM_BUILD if (monster->stats.hp <= 0) { diff --git a/src/steam/steamworks_api_wrapper.h b/src/steam/steamworks_api_wrapper.h index 9a3be52..98dcb9d 100644 --- a/src/steam/steamworks_api_wrapper.h +++ b/src/steam/steamworks_api_wrapper.h @@ -9,7 +9,8 @@ typedef enum EAchievement THE_DOCTOR_IS_OUT = 1, LIGHTS_ON = 2, BACK_TO_WORK = 5, - DRAGON_SLAYER = 6 + DRAGON_SLAYER = 6, + BUGGFIXER = 7 } EAchievement; From cb60a035dd37c9d3aff518cc97681d16252e8c37 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 3 Sep 2018 17:21:33 +0200 Subject: [PATCH 25/28] Fixes some compiler warnings --- steamworks_c_wrapper/src/steamworks_c_wrapper.cpp | 2 +- steamworks_c_wrapper/src/steamworks_c_wrapper.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp index 66d2c2d..6a34bcb 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.cpp @@ -99,7 +99,7 @@ c_SteamUserStats_FindLeaderboard(const char * name) m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard); } -extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, int32_t *details, int32_t nDetails) +extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, const int32_t *details, int32_t nDetails) { if (!hLeaderboard || !m_Initiated) return; diff --git a/steamworks_c_wrapper/src/steamworks_c_wrapper.h b/steamworks_c_wrapper/src/steamworks_c_wrapper.h index d99b565..be00cf0 100644 --- a/steamworks_c_wrapper/src/steamworks_c_wrapper.h +++ b/steamworks_c_wrapper/src/steamworks_c_wrapper.h @@ -30,7 +30,7 @@ void c_SteamUserStats_FindLeaderboard(const char *name); void -c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, int32_t *details, int32_t nDetails); +c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, const int32_t *details, int32_t nDetails); void c_SteamAPI_Shutdown(void); From a19a13e054d44565da7952950f95e831df2690a4 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 3 Sep 2018 20:21:54 +0200 Subject: [PATCH 26/28] The beginning of an idea for a global leaderboard view --- .clang_complete | 2 + .vimrc | 3 +- steamworks_c_wrapper/CMakeLists.txt | 1 + .../src/CSteamLeaderboard.cpp | 83 +++++++++++++++++++ steamworks_c_wrapper/src/CSteamLeaderboard.h | 29 +++++++ steamworks_c_wrapper/src/CallbackHandler.cpp | 2 +- 6 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 steamworks_c_wrapper/src/CSteamLeaderboard.cpp create mode 100644 steamworks_c_wrapper/src/CSteamLeaderboard.h diff --git a/.clang_complete b/.clang_complete index e1282ec..38a1e64 100644 --- a/.clang_complete +++ b/.clang_complete @@ -1,4 +1,6 @@ -DDEBUG +-DSTEAM_BUILD +-include ./steamworks_c_api/sdk/public/steam/steam_api.h -I./steamworks_c_api/src/ -I./src/steam/ -I./build/config.h diff --git a/.vimrc b/.vimrc index 4647378..ebf83fd 100644 --- a/.vimrc +++ b/.vimrc @@ -5,4 +5,5 @@ nnoremap :ter ++close ./_build/breakhack packadd termdebug let g:termdebug_wide = 1 -let g:syntastic_c_include_dirs = [ '_build', '/usr/include/SDL2', 'steamworks_c_wrapper/src', 'steamworks_c_wrapper/sdk/public/steam' ] +let g:syntastic_c_include_dirs = [ '_build', '/usr/include/SDL2', 'steamworks_c_wrapper/src' ] +let g:syntastic_cpp_include_dirs = [ 'steamworks_c_wrapper/sdk/public/steam' ] diff --git a/steamworks_c_wrapper/CMakeLists.txt b/steamworks_c_wrapper/CMakeLists.txt index f948ab6..9e30331 100644 --- a/steamworks_c_wrapper/CMakeLists.txt +++ b/steamworks_c_wrapper/CMakeLists.txt @@ -35,6 +35,7 @@ else () SHARED src/steamworks_c_wrapper src/CallbackHandler + src/CSteamLeaderboard ) endif() diff --git a/steamworks_c_wrapper/src/CSteamLeaderboard.cpp b/steamworks_c_wrapper/src/CSteamLeaderboard.cpp new file mode 100644 index 0000000..80f8a31 --- /dev/null +++ b/steamworks_c_wrapper/src/CSteamLeaderboard.cpp @@ -0,0 +1,83 @@ +#include +#include "CSteamLeaderboard.h" + +CSteamLeaderboard::CSteamLeaderboard() : m_hCurrentLeaderboard(0) +{ + // Nothing yet +} + +void +CSteamLeaderboard::SetCurrent(SteamLeaderboard_t hCurrentLeaderboard) +{ + m_hCurrentLeaderboard = hCurrentLeaderboard; +} + +void +CSteamLeaderboard::FindLeaderboard(const char *pchLeaderboardName ) +{ + + SteamAPICall_t hSteamAPICall = SteamUserStats()->FindLeaderboard(pchLeaderboardName); + m_callResultFindLeaderboard.Set(hSteamAPICall, + this, + &CSteamLeaderboard::OnFindLeaderboard); +} + +bool +CSteamLeaderboard::UploadScore(int score, const int *details, int nDetails) +{ + if (!m_hCurrentLeaderboard) + return false; + + SteamAPICall_t hSteamAPICall = SteamUserStats()->UploadLeaderboardScore(m_hCurrentLeaderboard, + k_ELeaderboardUploadScoreMethodKeepBest, + score, + details, + nDetails); + m_callResultUploadScore.Set(hSteamAPICall, this, &CSteamLeaderboard::OnUploadScore); + return true; +} + +bool +CSteamLeaderboard::DownloadScores() +{ + if (!m_hCurrentLeaderboard) return false; + SteamAPICall_t hSteamAPICall = SteamUserStats()->DownloadLeaderboardEntries( m_hCurrentLeaderboard, + k_ELeaderboardDataRequestGlobalAroundUser, + -4, + 5); + + m_callResultDownloadScores.Set(hSteamAPICall, this, &CSteamLeaderboard::OnDownloadScores); + return true; +} + +void +CSteamLeaderboard::OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure) +{ + if (!pCallback->m_bLeaderboardFound || bIOFailiure) { + std::cerr << "Leaderboard could not be found" << std::endl; + return; + } + m_hCurrentLeaderboard = pCallback->m_hSteamLeaderboard; +} + +void +CSteamLeaderboard::OnUploadScore(LeaderboardScoreUploaded_t *pCallback, bool bIOFailiure) +{ + if (!pCallback->m_bSuccess || bIOFailiure) + std::cerr << "Score could not be uploaded" << std::endl; +} + +void +CSteamLeaderboard::OnDownloadScores(LeaderboardScoresDownloaded_t *pCallback, bool bIOFailiure) +{ + if (!bIOFailiure) { + m_nLeaderboardEntries = std::min(pCallback->m_cEntryCount, 10); + for (int index = 0; index < m_nLeaderboardEntries; index++) { + SteamUserStats()->GetDownloadedLeaderboardEntry( pCallback->m_hSteamLeaderboardEntries, + index, + &m_leaderboardEntries[index], + NULL, + 0); + } + } +} diff --git a/steamworks_c_wrapper/src/CSteamLeaderboard.h b/steamworks_c_wrapper/src/CSteamLeaderboard.h new file mode 100644 index 0000000..3766bad --- /dev/null +++ b/steamworks_c_wrapper/src/CSteamLeaderboard.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +class CSteamLeaderboard +{ + private: + SteamLeaderboard_t m_hCurrentLeaderboard; + LeaderboardEntry_t m_leaderboardEntries[10]; + int m_nLeaderboardEntries = 0; + + public: + CSteamLeaderboard(); + + void SetCurrent(SteamLeaderboard_t hCurrentLeaderboard); + + void FindLeaderboard(const char *pchLeaderboardName ); + bool UploadScore(int score, const int *details, int nDetails); + bool DownloadScores(); + + void OnFindLeaderboard(LeaderboardFindResult_t *pCallback, bool bIOFailiure); + CCallResult m_callResultFindLeaderboard; + + void OnUploadScore(LeaderboardScoreUploaded_t *pCallback, bool bIOFailiure); + CCallResult m_callResultUploadScore; + + void OnDownloadScores(LeaderboardScoresDownloaded_t *pCallback, bool bIOFailiure); + CCallResult m_callResultDownloadScores; +}; diff --git a/steamworks_c_wrapper/src/CallbackHandler.cpp b/steamworks_c_wrapper/src/CallbackHandler.cpp index 2750955..7d1ea04 100644 --- a/steamworks_c_wrapper/src/CallbackHandler.cpp +++ b/steamworks_c_wrapper/src/CallbackHandler.cpp @@ -41,4 +41,4 @@ void CallbackHandler::OnFindLeaderboard(LeaderboardFindResult_t * pCallback, boo if (leaderboardReceivedCb) leaderboardReceivedCb(pCallback->m_hSteamLeaderboard, SteamUserStats()->GetLeaderboardName(pCallback->m_hSteamLeaderboard)); -} \ No newline at end of file +} From 280b073a8c304b0be4d4d822c54716f90b28171d Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 3 Sep 2018 20:27:34 +0200 Subject: [PATCH 27/28] Prevents kill achievments from being granted on first hit. --- src/player.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/player.c b/src/player.c index afd60f8..8570061 100644 --- a/src/player.c +++ b/src/player.c @@ -512,20 +512,6 @@ player_monster_kill_check(Player *player, Monster *monster) if (!monster) return; -#ifdef STEAM_BUILD - if (strcmp("The Shadow", monster->label) == 0) - steam_set_achievement(LIGHTS_ON); - else if (strcmp("The Hell Hound", monster->label) == 0) - steam_set_achievement(BAD_DOG); - else if (strcmp("Platino", monster->label) == 0) - steam_set_achievement(DRAGON_SLAYER); - else if (strcmp("The Cleric", monster->label) == 0) - steam_set_achievement(THE_DOCTOR_IS_OUT); - else if (strcmp("Linus, the Developer", monster->label) == 0) - steam_set_achievement(BUGGFIXER); - -#endif // STEAM_BUILD - if (monster->stats.hp <= 0) { unsigned int gained_xp = 5 * monster->stats.lvl; player->stat_data.kills += 1; @@ -533,6 +519,19 @@ player_monster_kill_check(Player *player, Monster *monster) gui_log("You killed %s and gained %d xp", monster->lclabel, gained_xp); player_gain_xp(player, gained_xp); + +#ifdef STEAM_BUILD + if (strcmp("The Shadow", monster->label) == 0) + steam_set_achievement(LIGHTS_ON); + else if (strcmp("The Hell Hound", monster->label) == 0) + steam_set_achievement(BAD_DOG); + else if (strcmp("Platino", monster->label) == 0) + steam_set_achievement(DRAGON_SLAYER); + else if (strcmp("The Cleric", monster->label) == 0) + steam_set_achievement(THE_DOCTOR_IS_OUT); + else if (strcmp("Linus, the Developer", monster->label) == 0) + steam_set_achievement(BUGGFIXER); +#endif // STEAM_BUILD } } From 9364fec1570627c6900b001cf52ed7ae787c6e8b Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 3 Sep 2018 20:28:42 +0200 Subject: [PATCH 28/28] Increases patch version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34a594c..36f5afc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(breakhack C) set(breakhack_GAME_TITLE "BreakHack") set(breakhack_MAJOR_VERSION 1) set(breakhack_MINOR_VERSION 0) -set(breakhack_PATCH_VERSION 3) +set(breakhack_PATCH_VERSION 4) set(breakhack_RELEASE_TYPE "") include(FindLua)