Skip to content

Commit

Permalink
fix: Remove some video modes (#86)
Browse files Browse the repository at this point in the history
On the Mac, some non-4:3 modes were causing serious flickering (only on some
Macs). This is bad enough to pull fullscreen for now. Hasn't happened on
Windows that I can test, but pulling there too.
  • Loading branch information
matatk authored Jun 22, 2021
1 parent 7d6c2d1 commit 69dd796
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 145 deletions.
4 changes: 1 addition & 3 deletions audioquake/launcherlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
'_validation': '', # This will be set by code.
'first_game_run': 'yes',
'warning_acknowledged_flickering': 'no',
'warning_acknowledged_flickering_mode_test': 'no',
'fullscreen': 'no',
'resolution': '' # The platform default will be inserted.
'resolution': '' # The default will be inserted.
}

_config_file_path = None
Expand Down
15 changes: 4 additions & 11 deletions audioquake/launcherlib/game_controller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""AudioQuake & LDL Launcher - Game controller"""
import enum

import launcherlib.config as config
from launcherlib import dirs
from launcherlib.utils import have_registered_data, LaunchState
from launcherlib.game_controller.engine_wrapper import EngineWrapper
from launcherlib.resolutions import resolution_size_from_config, \
DEFAULT_WIDTH, DEFAULT_HEIGHT
from launcherlib.resolutions import resolution_from_config


class RootGame(enum.Enum):
Expand Down Expand Up @@ -38,15 +36,10 @@ def _launch_core(self, options=(), game=RootGame.ANY):
if self._is_running():
return LaunchState.ALREADY_RUNNING

screen_mode = ('-fullscreen',) if config.fullscreen() else ('-window',)
x, y = resolution_from_config()
screen_mode = ('-window', '-width', str(x), '-height', str(y))

xstr, ystr, _ = resolution_size_from_config()
if xstr == DEFAULT_WIDTH and ystr == DEFAULT_HEIGHT:
resolution = ()
else:
resolution = ('-width', xstr, '-height', ystr)

parameters = self.opts_default + options + screen_mode + resolution
parameters = self.opts_default + options + screen_mode

if game is RootGame.ANY:
if have_registered_data():
Expand Down
95 changes: 10 additions & 85 deletions audioquake/launcherlib/resolutions.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,17 @@
"""AudioQuake & LDL Launcher - Customise tab"""
# FIXME: enforce min and max resolutions
from buildlib import doset
import launcherlib.config as config

RESOLUTIONS = [
'640x400 (16:10)', # Default on macOS
'640x480 (4:3)', # Default on Windows
'800x600 (4:3)',
'1152x720 (16:10)',
'1280x720 (16:9)',
'1024x768 (4:3)']
RESOLUTIONS = [(640, 480), (800, 600), (1024, 768)]
DEFAULT_RESOLUTION_INDEX = 0

DEFAULT_RESOLUTION_INDEX = doset(mac=0, windows=1)

RESOLUTIONS[DEFAULT_RESOLUTION_INDEX] += ' [default]'


def width_and_height(resolution_string):
"""Given a string, extract the width and height of the corresponding
resolution
Raises ValueError if the string doesn't describe a resolution"""
if ' ' in resolution_string:
dimensions = resolution_string.split(' ')[0]
else:
dimensions = resolution_string
xstr, ystr = dimensions.split('x') # may raise ValueError
return xstr, ystr


DEFAULT_WIDTH, DEFAULT_HEIGHT = \
width_and_height(RESOLUTIONS[DEFAULT_RESOLUTION_INDEX])


def resolution_index_and_size(partial_resolution_string):
"""Given a resolution string, find the index of the matching preset
resolution, if it exists
Returns
(index, x, y) if the string matches a preset resolution
( -1, x, y) if the string's resolution doesn't match a preset
( -2, None, None) if the string's resolution is invalid"""
def resolution_from_config():
try:
given_xstr, given_ystr = width_and_height(partial_resolution_string)
except ValueError:
return -2, None, None

for index, resolution_string in enumerate(RESOLUTIONS):
res_xstr, res_ystr = width_and_height(resolution_string)
if given_xstr == res_xstr and given_ystr == res_ystr:
return index, given_xstr, given_ystr

return -1, given_xstr, given_ystr


def resolution_details_from_config():
"""Gets and updates info about the resolution string stored in the
launcher's INI file.
If the resolution is valid syntactically, works out if it's one of the
preset ones and finds its index if so.
Also finds the x and y sizes of the resultion.
If the resolution in the INI file is not syntactically correct, replace it
with the default resolution string for the current platform, then return
the info on the default resolution.
Returns
index - int/None depending on whether the current res is a preset
x - width of current resolution
y - height of current resolution
was_valid - Whether the INI file res was syntactically correct."""
index, x, y = resolution_index_and_size(config.resolution())
if index >= 0:
return index, x, y, True
elif index == -1:
return None, x, y, True
else:
config.resolution(RESOLUTIONS[DEFAULT_RESOLUTION_INDEX])
return DEFAULT_RESOLUTION_INDEX, DEFAULT_WIDTH, DEFAULT_HEIGHT, False


def resolution_index_from_config():
index, _, _, was_valid = resolution_details_from_config()
return index, was_valid


def resolution_size_from_config():
_, x, y, was_valid = resolution_details_from_config()
return x, y, was_valid
index = int(config.resolution())
x, y = RESOLUTIONS[index]
return x, y
except: # noqa 722
x, y = RESOLUTIONS[DEFAULT_RESOLUTION_INDEX]
config.resolution(DEFAULT_RESOLUTION_INDEX)
return x, y
69 changes: 23 additions & 46 deletions audioquake/launcherlib/ui/tabs/customise.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@
from launcherlib.utils import have_registered_data
from launcherlib.ui.helpers import associate_controls, \
add_opener_buttons, add_widget, pick_directory, Info, Error, \
platform_appropriate_grouping, does_user_confirm, game_flickering_check
platform_appropriate_grouping, game_flickering_check, \
first_time_windows_firewall_info
from launcherlib.ui.munging import copy_paks_and_create_textures_wad
from launcherlib.resolutions import resolution_index_from_config, \
RESOLUTIONS, DEFAULT_RESOLUTION_INDEX
from launcherlib.resolutions import RESOLUTIONS, DEFAULT_RESOLUTION_INDEX


def get_resolution_strings(resolutions):
out = []
for x, y in resolutions:
out.append(str(x) + 'x' + str(y))
return out


class CustomiseTab(wx.Panel):
def __init__(self, parent, game_controller):
wx.Panel.__init__(self, parent)
sizer = wx.BoxSizer(wx.VERTICAL)

resolution_strings = get_resolution_strings(RESOLUTIONS)

# Settings

add_opener_buttons(self, sizer, {
Expand All @@ -40,51 +49,29 @@ def __init__(self, parent, game_controller):

add_widget(sizer, wx.StaticLine(self, -1))

box = platform_appropriate_grouping(self, 'Video mode settings')

fullscreen = wx.CheckBox(
self, -1, 'Run full-screen (instead of windowed)')

fullscreen.SetValue(config.fullscreen())
fullscreen.Bind(
wx.EVT_CHECKBOX,
lambda event: config.fullscreen(event.IsChecked()))
add_widget(box, fullscreen)
box = platform_appropriate_grouping(self, 'Video mode')

res_label = wx.StaticText(self, label='Resolution:')
res_pick = wx.Choice(self, -1, choices=RESOLUTIONS)
res_pick = wx.Choice(self, -1, choices=resolution_strings)

index, _ = resolution_index_from_config()
if index >= 0:
res_pick.SetSelection(index)
else:
res_pick.Disable()
try:
index = int(config.resolution())
except: # noqa 722
index = DEFAULT_RESOLUTION_INDEX
res_pick.SetSelection(index)

res_pick.Bind(
wx.EVT_CHOICE,
lambda event: config.resolution(RESOLUTIONS[event.GetSelection()]))
lambda event: config.resolution(event.GetSelection()))

add_widget(box, associate_controls(res_label, res_pick))

doset_only(windows=lambda: add_widget(box, wx.StaticText(
self, -1, "Some modes may not be available full-screen.")))
doset_only(windows=lambda: add_widget(box, wx.StaticText(
self, -1, "Modes may be cropped when Windows' UI is scaled.")))

def mode_test(event):
if fullscreen.GetValue() is True:
if not config.warning_acknowledged_flickering_mode_test():
if does_user_confirm(
parent,
'Full-screen flickering warning',
fullscreen_warning_message):
config.warning_acknowledged_flickering_mode_test(True)
else:
fullscreen.SetValue(False)
config.fullscreen(False)
return
else:
if not game_flickering_check(parent):
doset_only(windows=lambda: first_time_windows_firewall_info(parent))
if not game_flickering_check(parent):
return
game_controller.launch_tutorial()

Expand All @@ -93,15 +80,13 @@ def mode_test(event):
add_widget(box, quick_test)

def reset_to_defaults(event):
fullscreen.SetValue(False)
wx.PostEvent(fullscreen, wx.CommandEvent(wx.wxEVT_CHECKBOX))
res_pick.SetSelection(DEFAULT_RESOLUTION_INDEX)
choice_event = wx.CommandEvent(wx.wxEVT_CHOICE)
choice_event.SetInt(DEFAULT_RESOLUTION_INDEX)
wx.PostEvent(res_pick, choice_event)
res_pick.Enable()

reset = wx.Button(self, -1, 'Reset video mode to defaults')
reset = wx.Button(self, -1, 'Reset video mode to default')
reset.Bind(wx.EVT_BUTTON, reset_to_defaults)
add_widget(box, reset)

Expand Down Expand Up @@ -140,11 +125,3 @@ def install_data_handler(self, event):
Error(self, (
'One or both of the registered data files could '
'not be found in the chosen directory.'))


fullscreen_warning_message = (
'Please note that on some systems, there may be flickering\n'
'graphical bugs in some full-screen modes (particularly if\n'
'you set custom modes in the config file). Also Quake does\n'
'use flickering lighting effects, and the screen may flicker\n'
'when the mode is changed.\n')
4 changes: 4 additions & 0 deletions giants/zq-repo/zquake/source/vid_glsdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ static void uninstall_grabs(void)

void HotKey_ToggleFullScreen(void)
{
#ifndef AGRIP
SDL_Surface *screen;

screen = SDL_GetVideoSurface();
Expand All @@ -310,6 +311,7 @@ void HotKey_ToggleFullScreen(void)
flags ^= SDL_FULLSCREEN;
screen = SDL_SetVideoMode(screen->w, screen->h, bpp, flags);
}
#endif
}

void HotKey_ToggleGrab(void)
Expand Down Expand Up @@ -493,8 +495,10 @@ void VID_Init(unsigned char *palette)

vid.colormap = host_colormap;

#ifndef AGRIP
if (!(COM_CheckParm("-window")) )
flags |= SDL_FULLSCREEN;
#endif

if ((i = COM_CheckParm("-bpp")) != 0)
bpp = atoi(com_argv[i+1]);
Expand Down
4 changes: 4 additions & 0 deletions giants/zq-repo/zquake/source/vid_wgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1611,8 +1611,10 @@ void VID_Init (unsigned char *palette)

VID_InitFullDIB (global_hInstance);

#ifndef AGRIP
if (COM_CheckParm("-window") || COM_CheckParm("-startwindowed"))
{
#endif
hdc = GetDC (NULL);

if (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
Expand All @@ -1625,6 +1627,7 @@ void VID_Init (unsigned char *palette)
windowed = true;

vid_default = MODE_WINDOWED;
#ifndef AGRIP
}
else
{
Expand Down Expand Up @@ -1781,6 +1784,7 @@ void VID_Init (unsigned char *palette)
}
}
}
#endif

vid_initialized = true;

Expand Down

0 comments on commit 69dd796

Please sign in to comment.