Skip to content

Commit 18637a7

Browse files
committed
Support generic timer loading
1 parent 8770b7d commit 18637a7

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

demosys/conf/default_settings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
# What attributes should be used when generating a settings file
6-
__ORDER__ = ('DEBUG', 'SCREENSHOT_PATH', 'OPENGL', 'WINDOW', 'EFFECTS', 'EFFECT_MANAGER', 'MUSIC',
6+
__ORDER__ = ('DEBUG', 'SCREENSHOT_PATH', 'OPENGL', 'WINDOW', 'MUSIC', 'TIMER', 'EFFECTS', 'EFFECT_MANAGER',
77
'SHADER_DIRS', 'SHADER_FINDERS', 'TEXTURE_DIRS', 'TEXTURE_FINDERS')
88

99
DEBUG = False
@@ -30,12 +30,15 @@
3030
"cursor": False,
3131
}
3232

33+
MUSIC = None
34+
35+
TIMER = 'demosys.timers.Timer'
36+
3337
# Empty effects tuple
3438
EFFECTS = ()
3539

3640
EFFECT_MANAGER = 'demosys.effects.managers.single.SingleEffectManager'
3741

38-
MUSIC = None
3942

4043
# Additional directories shaders can be found
4144
SHADER_DIRS = ()

demosys/timers/music.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import glfw
22
from pygame import mixer
33
from .base import Timer
4+
from demosys.conf import settings
45

56

67
class MusicTimer(Timer):
78
"""Timer based on music"""
89
def __init__(self, **kwargs):
910
mixer.init()
10-
mixer.music.load(kwargs['source'])
11+
mixer.music.load(settings.MUSIC)
1112
self.paused = True
1213
# Reported time is not accurate when pausing or unpausing. We hack around it.
1314
self.pause_time = 0

demosys/view/controller.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from demosys import timers
1313
from demosys.conf import settings
1414
from demosys.scene import camera
15+
from demosys.utils import module_loading
1516
from . import screenshot
1617

1718
WINDOW = None
@@ -56,10 +57,8 @@ def run(manager=None):
5657

5758
# Initialize timer
5859
global TIMER
59-
if settings.MUSIC:
60-
TIMER = timers.MusicTimer(source=settings.MUSIC)
61-
else:
62-
TIMER = timers.Timer()
60+
timer_cls = module_loading.import_string(settings.TIMER)
61+
TIMER = timer_cls()
6362
TIMER.start()
6463

6564
frames, ft = 0, 0

demosys_test/settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
DEBUG = False
66

7-
# SCREENSHOT_PATH = os.path.join(PROJECT_DIR, 'screenshots')
7+
SCREENSHOT_PATH = os.path.join(PROJECT_DIR, 'screenshots')
88

99
# Profile: any, core, compat
1010
OPENGL = {
@@ -24,7 +24,8 @@
2424
"cursor": False,
2525
}
2626

27-
# MUSIC = os.path.join(PROJECT_DIR, 'resources/music/tg2035.mp3')
27+
MUSIC = os.path.join(PROJECT_DIR, 'resources/music/tg2035.mp3')
28+
TIMER = 'demosys.timers.MusicTimer'
2829

2930
# What effects to load
3031
EFFECTS = (

0 commit comments

Comments
 (0)