From edc3b4f650b67533baac8b08368df2a830b65276 Mon Sep 17 00:00:00 2001 From: cecilkorik Date: Mon, 20 Jun 2011 21:37:55 -0600 Subject: [PATCH] adding phases and roles --- enums.py | 15 +++++++-- gameobj.py | 96 +++++++++++++++++++++++++++++++++++------------------ physics.py | 10 ++++++ pipeline.py | 11 ++++-- 4 files changed, 95 insertions(+), 37 deletions(-) diff --git a/enums.py b/enums.py index 0a101cd..a733ca4 100755 --- a/enums.py +++ b/enums.py @@ -66,9 +66,20 @@ pl.sprite = 5 pl.composite1 = 6 pl.composite2 = 7 +# phases +phase = enum() +phase.handle_input = 0 +phase.ai = 1 +phase.animate = 2 +phase.move = 3 +phase.collide = 4 +phase.prerender = 5 +phase.render = 6 + +# texture types + tt = enum() tt.diffuse = 0 # the diffuse texture sets the colors and general brightness of the texture. if the same texture is used as the emissive texture, the model is effectively "fullbright" tt.emissive = 1 # this texture is blended with the diffuse texture as the light level drops (this can be used to add running lights or glow to a ship, or light up the dark side of a planet, otherwise pure "black" is a good choice) tt.specular = 2 # adding a specular map allows you to add areas of low or high reflectivity to your texture -tt.normal = 3 # normal maps allow bump mapping and other tweaks, with each channel representing the direction of the normal (red = -1x to 1x, green = -1y to 1y, blue = 0z to 1z) - +tt.normal = 3 # normal maps allow bump mapping and other tweaks, with each channel representing the direction of the normal (red = -1x to 1x, green = -1y to 1y, blue = 0z to 1z) \ No newline at end of file diff --git a/gameobj.py b/gameobj.py index 0f9adaf..ba44292 100755 --- a/gameobj.py +++ b/gameobj.py @@ -1,27 +1,32 @@ +import enums class gameobj(object): - role_factory = {} - - @staticmethod - def create_role_factory(role, factory): - gameobj.role_factory[role] = factory - def __init__(self, self.pos): self.pos = pos self.roles = [] self.effects = [] - def add_role(self, role): - assert not type(role) in [type(x) for x in self.roles] + def add_role(self, ro): for i, r in enumerate(self.roles): - if role is r: + if ro is r: break - if role.order < r.order: - self.roles.insert(i, role) + if ro.order < r.order: + self.roles.insert(i, ro) break - def remove_role(self, role): - for + def remove_role(self, ro): + deleted = [] + for ir, r in enumerate(reversed(self.roles)): + i = len(self.roles) - ir - 1 + if isinstance(ro, type) and isinstance(r, ro): + del self.roles[i] + deleted.append(r) + elif ro is r: + del self.roles[i] + deleted.append(r) + + return deleted + def ai(self): pass @@ -40,43 +45,68 @@ class gameobj(object): def prerender(self): pass + + def render(self): + pass -gameobj.create_role_factory('ai', ai_role) - class role(object): order = 1000 + phases = () def __init__(self): pass - + class ai_role(role): - order = 200 - pass + order = 2000 + phases = (enums.phase.ai,) + def update(self, owner, phase): + "we have no AI yet..." + class visible_role(role): order = 10000 - pass - + phases = (enums.phase.render,) + def update(self, owner, phase): + "we have no AI yet..." + class corporeal_role(role): - order = 500 - pass + order = 5000 + phases = (enums.phase.collide,) + def update(self, owner, phase): + "we have no AI yet..." class animated_role(role): - order = 400 - pass + order = 4000 + phases = (enums.phase.animate,) + def update(self, owner, phase): + "we have no AI yet..." class movable_role(role): - order = 300 - pass + order = 3500 + phases = (enums.phase.move,) + def update(self, owner, phase): + "we have no AI yet..." -class player_role(role): - order = 100 - pass +class input_role(role): + order = 1000 + phases = (enums.phase.handle_input,) + def update(self, owner, phase): + "we have no AI yet..." class light_role(role): order = 9000 - pass - -class _role(role): - pass + phases = (enums.phase.prerender,) + def update(self, owner, phase): + "we have no AI yet..." +class rotation_role(role): + order = 3000 + phases = (enums.phase.move,) + def update(self, owner, phase): + "we have no AI yet..." + +class billboard_role(role): + order = 3000 + phases = (enums.phase.move,) + def update(self, owner, phase): + "we have no AI yet..." \ No newline at end of file diff --git a/physics.py b/physics.py index 7e22bfd..8bdfb41 100755 --- a/physics.py +++ b/physics.py @@ -4,6 +4,16 @@ import math floor = math.floor +class motion(object): + def __init__(self): + + def turn(self, dir): + pass + + + + + class physics_manager(object): def __init__(self): self.cellsize = 100.0 diff --git a/pipeline.py b/pipeline.py index 40eb2c9..c40f79a 100755 --- a/pipeline.py +++ b/pipeline.py @@ -15,7 +15,8 @@ class pipeline_manager(object): ('animate', {}), ('move', {}), ('collide', {'func': physics.mgr.postcollide}), - ('prerender', {}) + ('prerender', {}), + ('render', {}) ] self.pipelines = [ ('camera', {}), @@ -143,7 +144,13 @@ def register_direct(obj, update_pipes, render_pipes): i = mgr.pipeline_index[pipe] mgr.renders[i].append(obj) -def register(obj, update_pipes): +def register_auto(obj): + for role in obj.roles: + + +def register(obj, update_pipes=None): + if update_pipes == None: + register_auto(obj) obj._pipeline_update = tuple(update_pipes) for phase in update_pipes: