Skip to content

Commit f3e3bb7

Browse files
committed
Docs: Effect managers
1 parent 84a26cc commit f3e3bb7

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

docs/source/effectmanagers.rst

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,68 @@
22
Effect Managers
33
===============
44

5-
Write stuff
5+
An effect manager is responsible of:
6+
7+
- Instantiating effects
8+
- Knowing what effect should be drawn based in some internal state
9+
- Reading keyboard events if this is needed (optional)
10+
11+
This is an example of the default ``SingleEffectManager``.
12+
13+
.. code-block:: python
14+
15+
class SingleEffectManager(BaseEffectManger):
16+
"""Run a single effect"""
17+
def __init__(self, effect_module=None):
18+
"""
19+
Initalize the manager telling it what effect should run.
20+
21+
:param effect_module: The effect module to run
22+
"""
23+
self.active_effect = None
24+
self.effect_module = effect_module
25+
26+
def pre_load(self):
27+
"""
28+
Initialize the effect that should run.
29+
"""
30+
# Instantiate all registered effects
31+
effect_list = [cfg.cls() for name, cfg in effects.effects.items()]
32+
# Find the single effect we are supposed to draw
33+
for effect in effect_list:
34+
if effect.name == self.effect_module:
35+
self.active_effect = effect
36+
37+
# Show some modest anger when we have been lied to
38+
if not self.active_effect:
39+
print("Cannot find effect '{}'".format(self.active_effect))
40+
print("Available effects:")
41+
print("\n".join(e.name for e in effect_list))
42+
return False
43+
return True
44+
45+
def post_load(self):
46+
return True
47+
48+
def draw(self, time, frametime, target):
49+
"""This is called every frame by the framework"""
50+
self.active_effect.draw(time, frametime, target)
51+
52+
def key_event(self, key, scancode, action, mods):
53+
"""Called on most key presses"""
54+
print("SingleEffectManager:key_event", key, scancode, action, mods)
55+
56+
It's important to understand that ``pre_load`` is called before resources are loaded
57+
and this is the correct place to instantiate effects. ``post_load`` is called right
58+
after loading is done.
59+
60+
The ``draw`` method is called every frame and you will have to send this to the effect
61+
you want to draw.
62+
63+
The ``key_events`` method will trigger on key presses.
64+
65+
BaseEffectManger
66+
^^^^^^^^^^^^^^^^
67+
68+
.. autoclass:: demosys.effects.managers.BaseEffectManger
69+
:members:

docs/source/effects.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ decides the effect should be active at least.
8585

8686
The standard effect example:
8787

88-
.. code-block:: bash
88+
.. code-block:: python
8989
9090
from demosys.effects import effect
9191
from demosys.opengl import geometry

0 commit comments

Comments
 (0)