def initialize(self): Controller.initialize(self) self.log("Initializing %s" %(self.__name__)) # get the GUI and load the chat View self._gui = Engine().getGUI() self._gui.loadView(self._params["layout"])
def list(self): procs = Engine().getHookMGR().list() map = { False: { True : "Running", False : "Stopped"}, True : { True: "Running*", False : "Stopped*"}} for p in procs.keys(): autostart, running = procs[p] self._chatapp.addMsg("%s - %s" %(p, map[autostart][running]))
def run(self): try: self._options['global']['_window.name'] = self.getAppVersion() print "Startup...." e = Engine(self._options) print "Run..." e.run() print "END OK" except ImportError, e: raise e
def setVisible(self,vis = None): if vis is not None: self._visible = vis else: self._visible = not self._visible self._gui.getObject("Chat/ChatWindow").setVisible(self._visible) if self._visible: bi = Engine().getHookMGR().findController("basicInput") if bi: bi.toggleGUIFocus(self._visible) self._textBox.activate()
def onAction(self, name, down): if down and name == "shot" and time.time() - self._last_shot > 0.5: self._last_shot = time.time() #pos = (20, 70, 500) pos = Engine().getRenderer().getCamera().getRealPosition() ori = Engine().getRenderer().getCamera().getRealDirection() ball = self._worldMGR.createBall("ball%i" % (self._balli), pos, 15, 4) self._balli += 1 ball.addForce(ori * 100000)
class GUI(Controller): __name__ = "GUI" _params = {} def __init__(self,params): Controller.__init__(self,params) self._params = params def initialize(self): Controller.initialize(self) self.log("Initializing %s" %(self.__name__)) # get the GUI and load the chat View self._gui = Engine().getGUI() self._gui.loadView(self._params["layout"])
def onAction(self, name, down): if down: if name == "console": self.setVisible() return True elif name == "reload": self.addMsg("Reloading world...") Engine().getHookMGR().restart("world3") return True
def initialize(self): Controller.initialize(self) # get the GUI and load the chat View self._gui = Engine().getGUI() self._gui.loadView("stats.layout") # Watch for input events #self._gui.subscribeEvent("Chat/ChatWindow/ChatOkBtn", # self._gui.getEvent("PushButton/EventClicked"),self.onInput) self._textObject = self._gui.getObject("StatsWindow/Msg") self._winstats = self._gui.getObject("StatsWindow") self.setText("...") self._window = Engine().getRenderer().getRenderWindow() if self._params.has_key("visible") \ and self._params["visible"].lower() != "true": self._vis = False else: self._vis = True self._winstats.setVisible(self._vis)
class World2(Controller): _balli = 0 _last_shot = 0 def __init__(self, params): Controller.__init__(self, params, "World") self._worldMGR = Engine().getWorldMGR() def initialize(self): Controller.initialize(self) self.loadScene() print "World was initialized" def terminate(self): self.destroyScene() def loadScene(self): self._worldMGR.setAmbientLight((0.25, 0.25, 0.25)) #self._worldMGR.loadScene("test.xml") #World ground self._worldMGR.createPlane("ground", (0, 1, 0), 0) for i in range(5): for j in range(5): self._worldMGR.createBox("box%ix%i" % (i, j), (j * 20, i * 25 + 10, 100), (20, 20, 20), 5) def destroyScene(self): #self._worldMGR.destroyObject("ground") self._worldMGR.destroyAllObjects() def onAction(self, name, down): if down and name == "shot" and time.time() - self._last_shot > 0.5: self._last_shot = time.time() #pos = (20, 70, 500) pos = Engine().getRenderer().getCamera().getRealPosition() ori = Engine().getRenderer().getCamera().getRealDirection() ball = self._worldMGR.createBall("ball%i" % (self._balli), pos, 15, 4) self._balli += 1 ball.addForce(ori * 100000)
def initialize(self): Controller.initialize(self) # get the GUI and load the chat View self._gui = Engine().getGUI() self._gui.loadView("chat.layout") # Watch for input events self._gui.subscribeEvent("Chat/ChatWindow/ChatOkBtn", "PushButton/EventClicked", self.onInput) self._gui.subscribeEvent("Chat/ChatWindow/ChatInput", "Editbox/EventTextAccepted", self.onInput) self._gui.subscribeEvent("Chat/ChatWindow/ChatInput", "Editbox/EventActivated", self.onFocus) self._textBox = self._gui.getObject("Chat/ChatWindow/ChatInput") self._chatBox = self._gui.getObject("Chat/ChatWindow/ChatBox") #.setText("Connection code is missing") # get Net and watch for incomming messages #self._net = wathever #self._net.subscribeMsg("chat,",self.onMsg) self.setVisible(False)
def loadScene(self): self._worldMGR.setAmbientLight((0.25, 0.25, 0.25)) #self._worldMGR.loadScene("test.xml") #World ground self._worldMGR.createPlane("ground", (0, 1, 0), 0) for i in range(5): for j in range(5): self._worldMGR.createBox("box%ix%i" % (i, j), (j * 20, i * 25 + 10, 100), (20, 20, 20), 5) self.createTank("me", (10, 10, 10)) Engine().getHookMGR().findController("Cam").setTarget("me")
class Camera(Controller): _mouse = False _rotateX = 0 _rotateY = 0 _moveZ = 0 _moveX = 0 _movementMap = { "rotate_up": { True: 1, False: 0 }, "rotate_down": { True: -1, False: 0 }, "rotate_left": { True: 1, False: 0 }, "rotate_right": { True: -1, False: 0 }, "up": { True: -1, False: 0 }, "down": { True: 1, False: 0 }, "right": { True: 1, False: 0 }, "left": { True: -1, False: 0 }, } def __init__(self, params): Controller.__init__(self, params) self._renderer = Engine().getRenderer() self._camera = self._renderer.getCamera() self._updateMetrics() def _updateMetrics(self): w, h, c, l, t = self._renderer.getRenderWindow().getMetrics() wd = w / 3 hd = h / 3 self._frontier = [wd, 2 * wd, hd, 2 * hd] def initialize(self): Controller.initialize(self) self.log("Initializing %s" % (self.__class__.__name__)) def onFrame(self, evt): time = evt.timeSinceLastFrame if time == 0: rotateScaleX = 0.1 * self._rotateX rotateScaleY = 0.1 * self._rotateY moveScaleZ = 1 * self._moveZ moveScaleX = 1 * self._moveX else: rotateScaleX = 2 * time * self._rotateX rotateScaleY = 2 * time * self._rotateY moveScaleZ = 100 * time * self._moveZ moveScaleX = 70 * time * self._moveX if rotateScaleX != 0: self._camera.pitch(rotateScaleX) if rotateScaleY != 0: self._camera.yaw(rotateScaleY) if moveScaleZ != 0 or moveScaleX != 0: #vector = self._renderer.getRendererFactory().createVector3() self._camera.moveRelative((moveScaleX, 0, moveScaleZ)) #self._mouse += time #if self._mouse >= 0.2: # self._rotateX = 0 # self._rotateY = 0 # self._mouse = False def onAction(self, name, down): if name in ("rotate_up", "rotate_down"): self._rotateX = self._movementMap[name][down] return True elif name in ("rotate_left", "rotate_right"): self._rotateY = self._movementMap[name][down] return True elif name in ("up", "down"): self._moveZ = self._movementMap[name][down] return True elif name in ("right", "left"): self._moveX = self._movementMap[name][down] return True return False def onAxis(self, name, abs, rel, type): return False #self._mouse = 0 x1, x2, y1, y2 = self._frontier neg = 1 if abs < 0: neg = -1 abs = neg * abs speed = 0.0013 if name == "x": if abs < x1: self._rotateY = (x1 - abs) * speed * neg elif abs > x2: self._rotateY = (abs - x2) * speed * -neg else: self._rotateY = 0 return True if name == "y": if abs < x1: self._rotateX = (y1 - abs) * speed * neg elif abs > x2: self._rotateX = (abs - y2) * speed * -neg else: self._rotateX = 0 return True return False
class Stats(Controller): def __init__(self, params): Controller.__init__(self, params, "stats") self._msg2 = "" self._msg1 = "" self._markee = "sd7 Engine -Canvi - Demostration" self._i = 0 self._time = 0 def initialize(self): Controller.initialize(self) # get the GUI and load the chat View self._gui = Engine().getGUI() self._gui.loadView("stats.layout") # Watch for input events #self._gui.subscribeEvent("Chat/ChatWindow/ChatOkBtn", # self._gui.getEvent("PushButton/EventClicked"),self.onInput) self._textObject = self._gui.getObject("StatsWindow/Msg") self._winstats = self._gui.getObject("StatsWindow") self.setText("...") self._window = Engine().getRenderer().getRenderWindow() if self._params.has_key("visible") \ and self._params["visible"].lower() != "true": self._vis = False else: self._vis = True self._winstats.setVisible(self._vis) def terminate(self): self._gui.destroyObject("StatsWindow") Controller.terminate(self) def writeMsg(self, msg): self._msg1 = msg def setText(self, msg): self._textObject.setText(msg) def onAction(self, name, down): if down and name == "stats": self._vis = not self._vis self._winstats.setVisible(self._vis) return True def onFrame(self, evt): time = evt.timeSinceLastFrame self._time += time if self._i <= len(self._markee) and self._time > 0.123: self._msg2 = self._markee[0:self._i] self._i += 1 self._time = 0 #print self._msg2 elif self._time > 1.5: self._i = 0 self._msg2 = "" self._time = -0.434 s = self._window.getStatistics() self.setText("FPS %.2f (%.2f) B/W:%.2f/%.2f t,b : %i , %i\n%s\n%s"\ %(s.avgFPS, s.lastFPS, s.bestFrameTime, s.worstFrameTime, s.triangleCount, s.batchCount, self._msg1, self._msg2))
def setTarget(self, name): self._targetName = name self._target = Engine().getWorldMGR().findObject("tank_%s" % (name, ))
def __init__(self, params): Controller.__init__(self, params) self._renderer = Engine().getRenderer() self._camera = self._renderer.getCamera() self._updateMetrics() self._target = None
class CameraObject(Controller): _mouse = False _rotateX = 0 _rotateY = 0 _moveZ = 0 _moveX = 0 _movementMap = { "rotate_up": { True: 1, False: 0 }, "rotate_down": { True: -1, False: 0 }, "rotate_left": { True: 1, False: 0 }, "rotate_right": { True: -1, False: 0 }, "up": { True: -1, False: 0 }, "down": { True: 1, False: 0 }, "right": { True: 1, False: 0 }, "left": { True: -1, False: 0 }, } def __init__(self, params): Controller.__init__(self, params) self._renderer = Engine().getRenderer() self._camera = self._renderer.getCamera() self._updateMetrics() self._target = None def _updateMetrics(self): w, h, c, l, t = self._renderer.getRenderWindow().getMetrics() wd = w / 3 hd = h / 3 self._frontier = [wd, 2 * wd, hd, 2 * hd] def initialize(self): Controller.initialize(self) self.log("Initializing %s" % (self.__class__.__name__)) def setTarget(self, name): self._targetName = name self._target = Engine().getWorldMGR().findObject("tank_%s" % (name, )) def onFrame(self, evt): time = evt.timeSinceLastFrame if time == 0: rotateScaleX = 0.1 * self._rotateX rotateScaleY = 0.1 * self._rotateY moveScaleZ = 1 * self._moveZ moveScaleX = 1 * self._moveX else: rotateScaleX = 2 * time * self._rotateX rotateScaleY = 2 * time * self._rotateY moveScaleZ = 100 * time * self._moveZ moveScaleX = 70 * time * self._moveX if rotateScaleX != 0: self._camera.pitch(rotateScaleX) if rotateScaleY != 0: self._camera.yaw(rotateScaleY) if moveScaleZ != 0 or moveScaleX != 0: #vector = self._renderer.getRendererFactory().createVector3() self._camera.moveRelative((moveScaleX, 0, moveScaleZ)) if self._target != None: b = self._target.physical.getBody() if moveScaleZ != 0: #self._target.addForce((0, 0 , moveScaleZ * 8000)) #self._target.physical.getBody().addRelForceAtRelPos((0, 0, moveScaleZ * 80000), (0, -10, -30)) x, y, z = b.vectorFromWorld(b.getPosition()) z += moveScaleZ x, y, z = b.vectorToWorld((x, y, z)) b.setPosition((x, y, z)) x, y, z = b.getPosition() self._camera.setPosition((x, y, z)) self._camera.lookAt((x, y, z)) #else: # self._target.physical.getBody().addForce((0, -100000, 0)) #self._mouse += time #if self._mouse >= 0.2: # self._rotateX = 0 # self._rotateY = 0 # self._mouse = False def onAction(self, name, down): if name in ("rotate_up", "rotate_down"): self._rotateX = self._movementMap[name][down] return True elif name in ("rotate_left", "rotate_right"): self._rotateY = self._movementMap[name][down] return True elif name in ("up", "down"): self._moveZ = self._movementMap[name][down] return True elif name in ("right", "left"): self._moveX = self._movementMap[name][down] return True return False def onAxis(self, name, abs, rel, type): return False #self._mouse = 0 x1, x2, y1, y2 = self._frontier neg = 1 if abs < 0: neg = -1 abs = neg * abs speed = 0.0013 if name == "x": if abs < x1: self._rotateY = (x1 - abs) * speed * neg elif abs > x2: self._rotateY = (abs - x2) * speed * -neg else: self._rotateY = 0 return True if name == "y": if abs < x1: self._rotateX = (y1 - abs) * speed * neg elif abs > x2: self._rotateX = (abs - y2) * speed * -neg else: self._rotateX = 0 return True return False
def destroyobject(self, name): Engine().getWorldMGR().destroyObject(name)
def __init__(self, params): Controller.__init__(self, params, "World") self._worldMGR = Engine().getWorldMGR()
class World(Controller): def __init__(self, params): Controller.__init__(self, params, "World") self._worldMGR = Engine().getWorldMGR() def initialize(self): Controller.initialize(self) self.loadScene() print "World was initialized" def terminate(self): self.destroyScene() def loadScene(self): self._worldMGR.setAmbientLight((0.25, 0.25, 0.25)) #self._worldMGR.loadScene("test.xml") #World ground self._worldMGR.createPlane("ground", (0, 1, 0), 0) #self._worldMGR.createBox("box01",(200,300,200), (15,15,15), 200) self._worldMGR.createBall("ball01", (10, 100, 0), 20, 10) self._worldMGR.createBall("ball02", (40, 120, 0), 10, 100) self._worldMGR.createBall("ball03", (80, 220, 10), 25, 150) self._worldMGR.createBall("ball04", (120, 400, -20), 5, 12) for i in range(50): self._worldMGR.createBall("random%i" % (i), (-20 * random.uniform(0, 0.1), i * 42 + 150, 20 * random.uniform(0, 0.1)), 15, 50) self._worldMGR.createBall( "randoma%i" % (i), (-180 * random.uniform(0, 0.1), i * 40 * random.uniform(1, 5) + 150, 120 * random.uniform(0, 0.1)), 5, 50) def destroyScene(self): #self._worldMGR.destroyObject("ground") self._worldMGR.destroyAllObjects()
class ChatApp(Controller): _history = [] _maxlines = 20 _retardedmsg = [] _time = 0 _wtime = random.uniform(1.8,6.2) def __init__(self,params): Controller.__init__(self,params,"console") self._visible = True self._cmds = Commands(self) def initialize(self): Controller.initialize(self) # get the GUI and load the chat View self._gui = Engine().getGUI() self._gui.loadView("chat.layout") # Watch for input events self._gui.subscribeEvent("Chat/ChatWindow/ChatOkBtn", "PushButton/EventClicked", self.onInput) self._gui.subscribeEvent("Chat/ChatWindow/ChatInput", "Editbox/EventTextAccepted", self.onInput) self._gui.subscribeEvent("Chat/ChatWindow/ChatInput", "Editbox/EventActivated", self.onFocus) self._textBox = self._gui.getObject("Chat/ChatWindow/ChatInput") self._chatBox = self._gui.getObject("Chat/ChatWindow/ChatBox") #.setText("Connection code is missing") # get Net and watch for incomming messages #self._net = wathever #self._net.subscribeMsg("chat,",self.onMsg) self.setVisible(False) def terminate(self): self._gui.destroyObject("Chat/ChatWindow") Controller.terminate(self) def setVisible(self,vis = None): if vis is not None: self._visible = vis else: self._visible = not self._visible self._gui.getObject("Chat/ChatWindow").setVisible(self._visible) if self._visible: bi = Engine().getHookMGR().findController("basicInput") if bi: bi.toggleGUIFocus(self._visible) self._textBox.activate() def onFocus(self,e): self._textBox.setText("") def processCommand(self,cmd): try: args = cmd.split() cmd = args.pop(0).lower() if hasattr(self._cmds, cmd): getattr(self._cmds, cmd)(*args) else: self.addMsg("I'm sorry, I'm afraid I can't do that") self.addRetardedMsg("yet!") except TestCrash: raise except Exception,e: self.addMsg("Exception: %s" %(e,)) self.addRetardedMsg("System: Perhaps you should think about something different")
def quit(self): Engine().terminate()
def bind(self, name, path): Engine().getHookMGR().bind(name, path)
def restart(self, name): Engine().getHookMGR().restart(name) try: self._chatapp.addMsg("%s restarted..." %(name)) except: pass
def stop(self, name): Engine().getHookMGR().stop(name) try: self._chatapp.addMsg("%s stopped..." %(name)) except: pass
def start(self, name): Engine().getHookMGR().start(name) self._chatapp.addMsg("%s started..." %(name))