Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 859c15b

Browse files
committed
Refactor FrameMan::SwitchWindowMultiplier
1 parent 7693f04 commit 859c15b

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

Managers/FrameMan.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -321,53 +321,40 @@ namespace RTE {
321321

322322
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
323323

324-
int FrameMan::SwitchWindowMultiplier(int multiplier) {
325-
if (multiplier <= 0 || multiplier > 4 || multiplier == m_NxWindowed) {
324+
int FrameMan::SwitchResolutionMultiplier(unsigned char multiplier) {
325+
if (multiplier <= 0 || multiplier > 4 || multiplier == m_ResMultiplier) {
326326
return -1;
327327
}
328-
if (m_Fullscreen) {
329-
m_NxWindowed = multiplier;
330-
return 0;
328+
if (m_ResX > m_ScreenResX / multiplier) {
329+
return -1;
331330
}
332331

333-
// Refuse windowed multiplier if the resolution is too high
334-
if (m_ResX > 1024) { m_NxWindowed = 1; }
335-
336332
// Save the palette so we can re-set it after the switch.
337333
PALETTE pal;
338334
get_palette(pal);
335+
339336
// Need to save these first for recovery attempts to work (screen might be 0)
340337
int resX = m_ResX;
341338
int resY = m_ResY;
342339

343-
// Switch to new windowed mode
344-
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, resX * multiplier, resY * multiplier, 0, 0) != 0) {
340+
// Set the GFX_TEXT driver to hack around Allegro's window resizing limitations (specifically reducing window size) when switching from 2X mode to 1X mode.
341+
// This will force a state where this is no actual game window, and the next set_gfx_mode call will recreate it correctly.
342+
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
343+
344+
if (set_gfx_mode(m_GfxDriver, resX * multiplier, resY * multiplier, 0, 0) != 0) {
345345
// Oops, failed to set windowed mode, so go back to previous multiplier
346-
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, resX * m_NxWindowed, resY * m_NxWindowed, 0, 0) != 0) {
347-
// Can't go back to previous mode either! total fail
346+
if (set_gfx_mode(m_GfxDriver, resX * m_ResMultiplier, resY * m_ResMultiplier, 0, 0) != 0) {
348347
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
349348
allegro_message("Unable to set back to previous windowed mode multiplier because: %s!", allegro_error);
350349
return 1;
351350
}
352-
// Successfully reverted back to previous setting
353351
g_ConsoleMan.PrintString("ERROR: Failed to switch to new windowed mode multiplier, reverted back to previous setting!");
354-
// Reset the palette.
355352
set_palette(pal);
356-
// Make sure everything gets caught up after the switch
357-
rest(2000);
358353
return 1;
359354
}
360-
// Make sure everything gets caught up after the switch
361-
rest(2000);
362-
g_ConsoleMan.PrintString("SYSTEM: Switched to different windowed mode multiplier");
363-
364-
// Save the new multiplier
365-
m_NxWindowed = multiplier;
366-
m_Fullscreen = false;
367-
368-
// Reset the palette.
355+
g_ConsoleMan.PrintString("SYSTEM: Switched to different windowed mode multiplier.");
356+
m_ResMultiplier = multiplier;
369357
set_palette(pal);
370-
371358
return 0;
372359
}
373360

Managers/FrameMan.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ namespace RTE {
188188
int ResolutionMultiplier() const { return m_ResMultiplier; }
189189

190190
/// <summary>
191-
/// Sets and switches to a new windowed mode multiplier.
191+
/// Sets and switches to a new windowed mode resolution multiplier.
192192
/// </summary>
193193
/// <param name="multiplier">The multiplier to switch to.</param>
194194
/// <returns>Error code, anything other than 0 is error.</returns>
195-
int SwitchWindowMultiplier(int multiplier = 1);
195+
int SwitchResolutionMultiplier(unsigned char multiplier = 1);
196196
#pragma endregion
197197

198198
#pragma region Split-Screen Handling

0 commit comments

Comments
 (0)