Skip to content

Commit

Permalink
Engine: updated Multitasking setting
Browse files Browse the repository at this point in the history
* Added `[misc] multitasking=[0,1]` to config, acting as a *starting* setting, which may be changed by runtime call to `SetMultitaskingMode`;
* Ensure multitasking mode is overridden by connected external debugger (always on, if possible);
* Let multitasking mode work in "fullscreen desktop" gfx mode (still disabled in exclusive fullscreen);
* Now correctly reset multitasking mode if gfx mode changes.
  • Loading branch information
ivan-mogilko committed Jun 20, 2022
1 parent 408f139 commit 9f09192
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 13 deletions.
3 changes: 0 additions & 3 deletions Engine/ac/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,9 +1303,6 @@ void display_switch_out_suspend()
}
}

// restore the callbacks
SetMultitasking(0);

switching_away_from_game--;
}

Expand Down
1 change: 1 addition & 0 deletions Engine/ac/gamesetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct GameSetup
bool load_latest_save; // load latest saved game on launch
ScreenRotation rotation;
bool show_fps;
bool multitasking = false; // whether run on background, when game is switched out

DisplayModeSetup Screen;
String software_render_driver;
Expand Down
21 changes: 15 additions & 6 deletions Engine/ac/global_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,21 +677,30 @@ void SetMultitasking (int mode) {
if ((mode < 0) | (mode > 1))
quit("!SetMultitasking: invalid mode parameter");

if (usetup.override_multitasking >= 0)
// Account for the override config option (must be checked first!)
if ((usetup.override_multitasking >= 0) && (mode != usetup.override_multitasking))
{
Debug::Printf("SetMultitasking: overridden by user config: %d -> %d", mode, usetup.override_multitasking);
Debug::Printf("SetMultitasking: overridden by user config: %d -> %d",
mode, usetup.override_multitasking);
mode = usetup.override_multitasking;
}

// Don't allow background running if full screen
if ((mode == 1) && (!scsystem.windowed))
// Must run on background if debugger is connected
if ((mode == 0) && (editor_debugging_initialized != 0))
{
Debug::Printf("SetMultitasking: overridden by fullscreen: %d -> %d", mode, 0);
Debug::Printf("SetMultitasking: overridden by the external debugger: %d -> 1", mode);
mode = 1;
}

// Regardless, don't allow background running if exclusive full screen
if ((mode == 1) && gfxDriver->GetDisplayMode().IsRealFullscreen())
{
Debug::Printf("SetMultitasking: overridden by fullscreen: %d -> 0", mode);
mode = 0;
}

// Install engine callbacks for switching in and out the window
Debug::Printf("SetMultitasking: mode %d", mode);
Debug::Printf(kDbgMsg_Info, "Multitasking mode set: %d", mode);
if (mode == 0)
{
sys_set_background_mode(false);
Expand Down
3 changes: 3 additions & 0 deletions Engine/main/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ void apply_config(const ConfigTree &cfg)
usetup.mouse_speed_def = StrUtil::ParseEnum<MouseSpeedDef>(
mouse_str, CstrArr<kNumMouseSpeedDefs>{ "absolute", "current_display" }, usetup.mouse_speed_def);

// Various system options
usetup.multitasking = CfgReadInt(cfg, "misc", "multitasking", 0) != 0;

// User's overrides and hacks
usetup.override_multitasking = CfgReadInt(cfg, "override", "multitasking", -1);
String override_os = CfgReadString(cfg, "override", "os");
Expand Down
2 changes: 1 addition & 1 deletion Engine/main/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ int initialize_engine(const ConfigTree &startup_opts)
// Configure game window after renderer was initialized
engine_setup_window();

SetMultitasking(0);
SetMultitasking(usetup.multitasking);

sys_window_show_cursor(false); // hide the system cursor

Expand Down
5 changes: 4 additions & 1 deletion Engine/main/engine_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// http://www.opensource.org/licenses/artistic-license-2.0.php
//
//=============================================================================

#include "core/platform.h"
#include "ac/common.h"
#include "ac/display.h"
Expand All @@ -20,6 +19,7 @@
#include "ac/gamesetup.h"
#include "ac/gamesetupstruct.h"
#include "ac/gamestate.h"
#include "ac/global_game.h"
#include "ac/mouse.h"
#include "ac/runtime_defines.h"
#include "ac/walkbehind.h"
Expand Down Expand Up @@ -287,6 +287,9 @@ void engine_post_gfxmode_setup(const Size &init_desktop)
}
engine_post_gfxmode_mouse_setup(init_desktop);

// reset multitasking (may be overridden by the current display mode)
SetMultitasking(usetup.multitasking);

video_on_gfxmode_changed();
invalidate_screen();
}
Expand Down
2 changes: 2 additions & 0 deletions Engine/main/game_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ac/common.h"
#include "ac/characterinfo.h"
#include "ac/game.h"
#include "ac/gamesetup.h"
#include "ac/gamesetupstruct.h"
#include "ac/gamestate.h"
#include "ac/global_game.h"
Expand Down Expand Up @@ -55,6 +56,7 @@ void start_game_init_editor_debugging()
return;

// Debugger expects strict multitasking
usetup.multitasking = true;
usetup.override_multitasking = -1;
SetMultitasking(1);

Expand Down
5 changes: 3 additions & 2 deletions Engine/main/graphics_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,9 @@ bool graphics_mode_set_dm(const DisplayMode &dm)
SavedWindowedSetting.Dm = rdm;
else
SavedFullscreenSetting.Dm = rdm;
Debug::Printf("Succeeded. Using gfx mode %d x %d (%d-bit) %s",
rdm.Width, rdm.Height, rdm.ColorDepth, rdm.IsWindowed() ? "windowed" : "fullscreen");
Debug::Printf(kDbgMsg_Info, "Graphics mode set: %d x %d (%d-bit) %s",
rdm.Width, rdm.Height, rdm.ColorDepth,
rdm.IsWindowed() ? "windowed" : (rdm.IsRealFullscreen() ? "fullscreen" : "fullscreen desktop"));
return true;
}

Expand Down

0 comments on commit 9f09192

Please sign in to comment.