adding phases and roles

This commit is contained in:
cecilkorik 2011-06-20 21:37:55 -06:00
parent c7dc57aca3
commit edc3b4f650
4 changed files with 95 additions and 37 deletions

View file

@ -66,9 +66,20 @@ pl.sprite = 5
pl.composite1 = 6 pl.composite1 = 6
pl.composite2 = 7 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 = 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.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.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.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)

View file

@ -1,27 +1,32 @@
import enums
class gameobj(object): class gameobj(object):
role_factory = {}
@staticmethod
def create_role_factory(role, factory):
gameobj.role_factory[role] = factory
def __init__(self, self.pos): def __init__(self, self.pos):
self.pos = pos self.pos = pos
self.roles = [] self.roles = []
self.effects = [] self.effects = []
def add_role(self, role): def add_role(self, ro):
assert not type(role) in [type(x) for x in self.roles]
for i, r in enumerate(self.roles): for i, r in enumerate(self.roles):
if role is r: if ro is r:
break break
if role.order < r.order: if ro.order < r.order:
self.roles.insert(i, role) self.roles.insert(i, ro)
break break
def remove_role(self, role): def remove_role(self, ro):
for 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): def ai(self):
pass pass
@ -40,43 +45,68 @@ class gameobj(object):
def prerender(self): def prerender(self):
pass pass
def render(self):
pass
gameobj.create_role_factory('ai', ai_role)
class role(object): class role(object):
order = 1000 order = 1000
phases = ()
def __init__(self): def __init__(self):
pass pass
class ai_role(role): class ai_role(role):
order = 200 order = 2000
pass phases = (enums.phase.ai,)
def update(self, owner, phase):
"we have no AI yet..."
class visible_role(role): class visible_role(role):
order = 10000 order = 10000
pass phases = (enums.phase.render,)
def update(self, owner, phase):
"we have no AI yet..."
class corporeal_role(role): class corporeal_role(role):
order = 500 order = 5000
pass phases = (enums.phase.collide,)
def update(self, owner, phase):
"we have no AI yet..."
class animated_role(role): class animated_role(role):
order = 400 order = 4000
pass phases = (enums.phase.animate,)
def update(self, owner, phase):
"we have no AI yet..."
class movable_role(role): class movable_role(role):
order = 300 order = 3500
pass phases = (enums.phase.move,)
def update(self, owner, phase):
"we have no AI yet..."
class player_role(role): class input_role(role):
order = 100 order = 1000
pass phases = (enums.phase.handle_input,)
def update(self, owner, phase):
"we have no AI yet..."
class light_role(role): class light_role(role):
order = 9000 order = 9000
pass phases = (enums.phase.prerender,)
def update(self, owner, phase):
class _role(role): "we have no AI yet..."
pass
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..."

View file

@ -4,6 +4,16 @@ import math
floor = math.floor floor = math.floor
class motion(object):
def __init__(self):
def turn(self, dir):
pass
class physics_manager(object): class physics_manager(object):
def __init__(self): def __init__(self):
self.cellsize = 100.0 self.cellsize = 100.0

View file

@ -15,7 +15,8 @@ class pipeline_manager(object):
('animate', {}), ('animate', {}),
('move', {}), ('move', {}),
('collide', {'func': physics.mgr.postcollide}), ('collide', {'func': physics.mgr.postcollide}),
('prerender', {}) ('prerender', {}),
('render', {})
] ]
self.pipelines = [ self.pipelines = [
('camera', {}), ('camera', {}),
@ -143,7 +144,13 @@ def register_direct(obj, update_pipes, render_pipes):
i = mgr.pipeline_index[pipe] i = mgr.pipeline_index[pipe]
mgr.renders[i].append(obj) 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) obj._pipeline_update = tuple(update_pipes)
for phase in update_pipes: for phase in update_pipes: