| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
from OpenGL import GL |
|---|
| 27 |
from RBFoundation.Aspects import Aspect |
|---|
| 28 |
from RBRapier.Renderer.AttributeMgr import AttributeChangeElement, ClientAttributeChangeElement |
|---|
| 29 |
|
|---|
| 30 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 31 |
#~ Definitions |
|---|
| 32 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 33 |
|
|---|
| 34 |
class StateManagerBase(object): |
|---|
| 35 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 36 |
#~ Definitions |
|---|
| 37 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 38 |
|
|---|
| 39 |
def __init__(self, statevector=None): |
|---|
| 40 |
if statevector is not None: |
|---|
| 41 |
self._statevector = statevector |
|---|
| 42 |
else: self._statevector = {} |
|---|
| 43 |
|
|---|
| 44 |
def _UpdateState(self, state, enabled): |
|---|
| 45 |
self._statevector[state] = enabled |
|---|
| 46 |
|
|---|
| 47 |
def GetState(self, state): |
|---|
| 48 |
return self._statevector.get(state, None) |
|---|
| 49 |
def SetState(self, state, enabled): |
|---|
| 50 |
current = self._statevector.get(state, None) |
|---|
| 51 |
if current != enabled: |
|---|
| 52 |
self._SetState(state, enabled) |
|---|
| 53 |
self._UpdateState(state, enabled) |
|---|
| 54 |
def DelState(self, state): |
|---|
| 55 |
try: del self._statevector[state] |
|---|
| 56 |
except KeyError: pass |
|---|
| 57 |
|
|---|
| 58 |
def Reset(self, state=None): |
|---|
| 59 |
if state is None: |
|---|
| 60 |
self._statevector.clear() |
|---|
| 61 |
else: self.DelState(state) |
|---|
| 62 |
|
|---|
| 63 |
def IsEnabled(self, state): |
|---|
| 64 |
return self.GetState(state) == 1 |
|---|
| 65 |
def IsNotEnabled(self, state): |
|---|
| 66 |
return self.GetState(state) != 1 |
|---|
| 67 |
def Enable(self, state): |
|---|
| 68 |
self.SetState(state, 1) |
|---|
| 69 |
|
|---|
| 70 |
def IsDisabled(self, state): |
|---|
| 71 |
return self.GetState(state) == 0 |
|---|
| 72 |
def IsNotDisabled(self, state): |
|---|
| 73 |
return self.GetState(state) != 0 |
|---|
| 74 |
def Disable(self, state): |
|---|
| 75 |
self.SetState(state, 0) |
|---|
| 76 |
|
|---|
| 77 |
def IsKnown(self, state): |
|---|
| 78 |
return self.GetState(state) != None |
|---|
| 79 |
def IsUnknown(self, state): |
|---|
| 80 |
return self.GetState(state) == None |
|---|
| 81 |
|
|---|
| 82 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 83 |
|
|---|
| 84 |
class StateManagerStatsAspect(Aspect): |
|---|
| 85 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 86 |
#~ Constants / Variables / Etc. |
|---|
| 87 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 88 |
|
|---|
| 89 |
_statechanges = None |
|---|
| 90 |
|
|---|
| 91 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 92 |
#~ Definitions |
|---|
| 93 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 94 |
|
|---|
| 95 |
def _UpdateState(self, state, enabled): |
|---|
| 96 |
sc = self._statechanges |
|---|
| 97 |
if sc is None: self._statechanges = {state: 1} |
|---|
| 98 |
else: sc[state] = sc.get(state, 0) + 1 |
|---|
| 99 |
|
|---|
| 100 |
self._statevector[state] = enabled |
|---|
| 101 |
|
|---|
| 102 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 103 |
|
|---|
| 104 |
class StateManager(StateManagerBase): |
|---|
| 105 |
AttributeChange = AttributeChangeElement(GL.GL_ENABLE_BIT) |
|---|
| 106 |
|
|---|
| 107 |
def _SetState(self, state, enabled): |
|---|
| 108 |
if enabled: GL.glEnable(state) |
|---|
| 109 |
else: GL.glDisable(state) |
|---|
| 110 |
|
|---|
| 111 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 112 |
|
|---|
| 113 |
class ClientStateManager(StateManagerBase): |
|---|
| 114 |
ClientAttributeChange = ClientAttributeChangeElement(GL.GL_CLIENT_VERTEX_ARRAY_BIT) |
|---|
| 115 |
|
|---|
| 116 |
def _SetState(self, state, enabled): |
|---|
| 117 |
if enabled: GL.glEnableClientState(state) |
|---|
| 118 |
else: GL.glDisableClientState(state) |
|---|
| 119 |
|
|---|