Skip to content

Commit

Permalink
pause game when steam overlay active
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Jan 23, 2019
1 parent 910311e commit 3ea0de3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ else
STEAMWORKS_LINK_OPT=-L$(BUILD_BIN_DIR) -lsteam_api
STEAMWORKS_LIB_DIR=$(THIRD_PARTY_DIR)/steamworks_sdk/redistributable_bin/osx32
STEAMWORKS_INC_DIR=$(THIRD_PARTY_DIR)/steamworks_sdk/public
# steamworks api triggers this warning
XCFLAGS += -Wno-invalid-offsetof
endif
endif

Expand Down
9 changes: 8 additions & 1 deletion src/am_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,14 @@ static void do_post_render(am_audio_context *context, int num_samples, am_audio_
void am_fill_audio_bus(am_audio_bus *bus) {
if (audio_context.root == NULL) return;
if (!am_conf_audio_mute) {
audio_context.root->render_audio(&audio_context, bus);
#if AM_STEAMWORKS
// mute audio if steam overlay shown
if (!am_steam_overlay_enabled) {
#endif
audio_context.root->render_audio(&audio_context, bus);
#if AM_STEAMWORKS
}
#endif
}
audio_context.render_id++;
do_post_render(&audio_context, bus->num_samples, audio_context.root);
Expand Down
12 changes: 12 additions & 0 deletions src/am_backend_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,13 @@ int main( int argc, char *argv[] )
if (am_conf_fixed_delta_time > 0.0) {
while (t_debt > 0.0) {
double t0 = am_get_current_time();
#ifdef AM_STEAMWORKS
if (!am_steam_overlay_enabled) {
#endif
am_execute_actions(L, am_conf_fixed_delta_time);
#ifdef AM_STEAMWORKS
}
#endif
double t = am_get_current_time() - t0;
t_debt -= am_max(t, am_conf_fixed_delta_time);
}
Expand All @@ -525,7 +531,13 @@ int main( int argc, char *argv[] )
if (am_conf_delta_time_step > 0.0) {
t_debt = floor(t_debt / am_conf_delta_time_step + 0.5) * am_conf_delta_time_step;
}
#ifdef AM_STEAMWORKS
if (!am_steam_overlay_enabled) {
#endif
am_execute_actions(L, t_debt);
#ifdef AM_STEAMWORKS
}
#endif
t_debt = 0.0;
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/am_steamworks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <list>

bool am_steam_overlay_enabled = false;

enum AMSteamLeaderboardQueryType {
AM_STEAM_GLOBAL,
AM_STEAM_GLOBAL_NEIGHBOURHOOD,
Expand Down Expand Up @@ -221,6 +223,20 @@ struct leaderboard_neighbourhood_request {
}
};

struct overlay_listener_t {
STEAM_CALLBACK( overlay_listener_t, OnGameOverlayActivated, GameOverlayActivated_t );
};

void overlay_listener_t::OnGameOverlayActivated( GameOverlayActivated_t* pCallback ) {
if ( pCallback->m_bActive ) {
am_steam_overlay_enabled = true;
} else {
am_steam_overlay_enabled = false;
}
}

static overlay_listener_t *overlay_listener = NULL;

static bool steam_initialized = false;

static void amSteamSubmitScore(lua_State *L, int func_ref, int score, const char *leaderboard) {
Expand Down Expand Up @@ -256,12 +272,17 @@ static void amSteamInit(lua_State *L) {
steam_initialized = false;
return;
}
overlay_listener = new overlay_listener_t();
g_L = L;
}
}

void am_steam_teardown() {
if (steam_initialized) {
if (overlay_listener != NULL) {
delete overlay_listener;
overlay_listener = NULL;
}
for (std::list<leaderboard_neighbourhood_request*>::iterator it = neightbourhood_requests.begin(); it != neightbourhood_requests.end(); ++it) {
(*it)->L = NULL;
}
Expand Down
1 change: 1 addition & 0 deletions src/am_steamworks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ void am_open_steamworks_module(lua_State *L);
void am_steam_teardown();
void am_steam_step();
const char* am_get_steam_lang();
extern bool am_steam_overlay_enabled;
#endif

0 comments on commit 3ea0de3

Please sign in to comment.