# HG changeset patch # User jasoka@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1216647975 0 # Node ID 214e3eb81eb21b1dbd3d34ca5553eb8569107f32 # Parent 346738d09188fc9aa8f62a20005084d209328a42 better structure for techdemo scripts + svn:ignore fixes diff -r 346738d09188 -r 214e3eb81eb2 build/linux/KDevelop/FIFE.kdevelop --- a/build/linux/KDevelop/FIFE.kdevelop Sun Jul 20 20:08:11 2008 +0000 +++ b/build/linux/KDevelop/FIFE.kdevelop Mon Jul 21 13:46:15 2008 +0000 @@ -64,7 +64,6 @@ Makefile CMakeLists.txt - diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/run.py --- a/clients/rio_de_hola/run.py Sun Jul 20 20:08:11 2008 +0000 +++ b/clients/rio_de_hola/run.py Mon Jul 21 13:46:15 2008 +0000 @@ -13,7 +13,8 @@ sys.path.append(_jp(p)) import fife, fifelog -from scripts import world, eventlistenerbase +from scripts import world +from scripts.common import eventlistenerbase from basicapplication import ApplicationBase import pychan import pychan.widgets as widgets diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/agent.py --- a/clients/rio_de_hola/scripts/agent.py Sun Jul 20 20:08:11 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -import common, fife - -class Agent(fife.InstanceActionListener): - def __init__(self, model, agentName, layer, uniqInMap=True): - fife.InstanceActionListener.__init__(self) - self.model = model - self.agentName = agentName - self.layer = layer - if uniqInMap: - self.agent = layer.getInstance(agentName) - self.agent.addActionListener(self) - - def onInstanceActionFinished(self, instance, action): - raise ProgrammingError('No OnActionFinished defined for Agent') - - def start(self): - raise ProgrammingError('No start defined for Agent') - - -def create_anonymous_agents(model, objectName, layer, agentClass): - agents = [] - instances = [a for a in layer.getInstances() if a.getObject().getId() == objectName] - i = 0 - for a in instances: - agentName = '%s:i:%d' % (objectName, i) - i += 1 - agent = agentClass(model, agentName, layer, False) - agent.agent = a - a.addActionListener(agent) - agents.append(agent) - return agents diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/agents/__init__.py diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/agents/agent.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/rio_de_hola/scripts/agents/agent.py Mon Jul 21 13:46:15 2008 +0000 @@ -0,0 +1,32 @@ +import fife +from scripts.common.common import ProgrammingError + +class Agent(fife.InstanceActionListener): + def __init__(self, model, agentName, layer, uniqInMap=True): + fife.InstanceActionListener.__init__(self) + self.model = model + self.agentName = agentName + self.layer = layer + if uniqInMap: + self.agent = layer.getInstance(agentName) + self.agent.addActionListener(self) + + def onInstanceActionFinished(self, instance, action): + raise ProgrammingError('No OnActionFinished defined for Agent') + + def start(self): + raise ProgrammingError('No start defined for Agent') + + +def create_anonymous_agents(model, objectName, layer, agentClass): + agents = [] + instances = [a for a in layer.getInstances() if a.getObject().getId() == objectName] + i = 0 + for a in instances: + agentName = '%s:i:%d' % (objectName, i) + i += 1 + agent = agentClass(model, agentName, layer, False) + agent.agent = a + a.addActionListener(agent) + agents.append(agent) + return agents diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/agents/beekeeper.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/rio_de_hola/scripts/agents/beekeeper.py Mon Jul 21 13:46:15 2008 +0000 @@ -0,0 +1,24 @@ +from agent import Agent +import settings as TDS +import fife, random + +_STATE_NONE, _STATE_TALK = 0, 1 + +class Beekeeper(Agent): + def __init__(self, model, agentName, layer, uniqInMap=True): + super(Beekeeper, self).__init__(model, agentName, layer, uniqInMap) + self.state = _STATE_NONE + + def onInstanceActionFinished(self, instance, action): + self.talk() + + def start(self): + self.facingLoc = self.agent.getLocation() + c = self.facingLoc.getExactLayerCoordinatesRef() + c.x += random.randint(-1, 1) + c.y += random.randint(-1, 1) + self.talk() + + def talk(self): + self.state = _STATE_TALK + self.agent.act('talk', self.facingLoc, True) # never calls back diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/agents/cloud.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/rio_de_hola/scripts/agents/cloud.py Mon Jul 21 13:46:15 2008 +0000 @@ -0,0 +1,49 @@ +from agent import Agent +import settings as TDS +import fife +import random + +_STATE_NONE, _STATE_FLOATING, _STATE_DISAPPEAR, _STATE_APPEAR = 0, 1, 2, 3 + +class Cloud(Agent): + def __init__(self, model, agentName, layer, uniqInMap=False): + super(Cloud, self).__init__(model, agentName, layer, uniqInMap) + self.state = _STATE_NONE + + def isOutOfBounds(self, c): + return (c.x < 0) or (c.x > 100) or (c.y < 0) or (c.y > 100) + + def onInstanceActionFinished(self, instance, action): + if self.state == _STATE_APPEAR: + self.move() + elif self.state == _STATE_FLOATING: + c = self.agent.getLocationRef().getExactLayerCoordinatesRef() + c.x += self.x_dir + c.y += self.y_dir + if self.isOutOfBounds(c): + self.disappear() + else: + self.move() + elif self.state == _STATE_DISAPPEAR: + self.agent.getLocationRef().setExactLayerCoordinates(self.initialCoords) + self.appear() + + def start(self, x_dir, y_dir): + self.x_dir = x_dir + self.y_dir = y_dir + self.loc = self.agent.getLocation() + self.initialCoords = self.agent.getLocation().getExactLayerCoordinates() + self.appear() + + def appear(self): + self.state = _STATE_APPEAR + self.agent.act('appear', self.loc, False) + + def disappear(self): + self.state = _STATE_DISAPPEAR + self.agent.act('disappear', self.loc, False) + + def move(self): + self.state = _STATE_FLOATING + self.agent.act('default', self.loc, False) + \ No newline at end of file diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/agents/girl.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/rio_de_hola/scripts/agents/girl.py Mon Jul 21 13:46:15 2008 +0000 @@ -0,0 +1,46 @@ +from agent import Agent +import settings as TDS +import fife + +_STATE_NONE, _STATE_IDLE, _STATE_RUN, _STATE_FOLLOW = 0, 1, 2, 3 + +GIRL_SPEED = 3 * TDS.TestAgentSpeed +class Girl(Agent): + def __init__(self, model, agentName, layer, uniqInMap=True): + super(Girl, self).__init__(model, agentName, layer, uniqInMap) + self.state = _STATE_NONE + self.waypoints = ((67, 80), (75, 44)) + self.waypoint_counter = 0 + self.hero = self.layer.getInstance('PC') + + def onInstanceActionFinished(self, instance, action): + if self.state in (_STATE_RUN, _STATE_FOLLOW): + self.idle() + else: + if self.waypoint_counter % 3: + self.waypoint_counter += 1 + self.follow_hero() + else: + self.run(self.getNextWaypoint()) + + def getNextWaypoint(self): + self.waypoint_counter += 1 + l = fife.Location(self.layer) + l.setLayerCoordinates(fife.ModelCoordinate(*self.waypoints[self.waypoint_counter % len(self.waypoints)])) + return l + + def start(self): + self.follow_hero() + + def idle(self): + self.state = _STATE_IDLE + self.agent.act('stand', self.agent.getFacingLocation(), False) + + def follow_hero(self): + self.state = _STATE_FOLLOW + self.agent.follow('run', self.hero, GIRL_SPEED) + + def run(self, location): + self.state = _STATE_RUN + self.agent.move('run', location, GIRL_SPEED) + diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/agents/hero.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/rio_de_hola/scripts/agents/hero.py Mon Jul 21 13:46:15 2008 +0000 @@ -0,0 +1,40 @@ +import random +from agent import Agent +import settings as TDS + +_STATE_NONE, _STATE_IDLE, _STATE_RUN, _STATE_KICK, _STATE_TALK = xrange(5) + +class Hero(Agent): + def __init__(self, model, agentName, layer, uniqInMap=True): + super(Hero, self).__init__(model, agentName, layer, uniqInMap) + self.state = _STATE_NONE + self.idlecounter = 1 + + def onInstanceActionFinished(self, instance, action): + self.idle() + if action.getId() != 'stand': + self.idlecounter = 1 + else: + self.idlecounter += 1 + if self.idlecounter % 7 == 0: + txtindex = random.randint(0, len(TDS.heroTexts) - 1) + instance.say(TDS.heroTexts[txtindex], 2500) + + def start(self): + self.idle() + + def idle(self): + self.state = _STATE_IDLE + self.agent.act('stand', self.agent.getFacingLocation()) + + def run(self, location): + self.state = _STATE_RUN + self.agent.move('run', location, 4 * TDS.TestAgentSpeed) + + def kick(self, target): + self.state = _STATE_KICK + self.agent.act('kick', target) + + def talk(self, target): + self.state = _STATE_TALK + self.agent.act('talk', target) diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/beekeeper.py --- a/clients/rio_de_hola/scripts/beekeeper.py Sun Jul 20 20:08:11 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -from agent import Agent -import settings as TDS -import fife, random - -_STATE_NONE, _STATE_TALK = 0, 1 - -class Beekeeper(Agent): - def __init__(self, model, agentName, layer, uniqInMap=True): - super(Beekeeper, self).__init__(model, agentName, layer, uniqInMap) - self.state = _STATE_NONE - - def onInstanceActionFinished(self, instance, action): - self.talk() - - def start(self): - self.facingLoc = self.agent.getLocation() - c = self.facingLoc.getExactLayerCoordinatesRef() - c.x += random.randint(-1, 1) - c.y += random.randint(-1, 1) - self.talk() - - def talk(self): - self.state = _STATE_TALK - self.agent.act('talk', self.facingLoc, True) # never calls back diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/cloud.py --- a/clients/rio_de_hola/scripts/cloud.py Sun Jul 20 20:08:11 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -from agent import Agent -import settings as TDS -import fife -import random - -_STATE_NONE, _STATE_FLOATING, _STATE_DISAPPEAR, _STATE_APPEAR = 0, 1, 2, 3 - -class Cloud(Agent): - def __init__(self, model, agentName, layer, uniqInMap=False): - super(Cloud, self).__init__(model, agentName, layer, uniqInMap) - self.state = _STATE_NONE - - def isOutOfBounds(self, c): - return (c.x < 0) or (c.x > 100) or (c.y < 0) or (c.y > 100) - - def onInstanceActionFinished(self, instance, action): - if self.state == _STATE_APPEAR: - self.move() - elif self.state == _STATE_FLOATING: - c = self.agent.getLocationRef().getExactLayerCoordinatesRef() - c.x += self.x_dir - c.y += self.y_dir - if self.isOutOfBounds(c): - self.disappear() - else: - self.move() - elif self.state == _STATE_DISAPPEAR: - self.agent.getLocationRef().setExactLayerCoordinates(self.initialCoords) - self.appear() - - def start(self, x_dir, y_dir): - self.x_dir = x_dir - self.y_dir = y_dir - self.loc = self.agent.getLocation() - self.initialCoords = self.agent.getLocation().getExactLayerCoordinates() - self.appear() - - def appear(self): - self.state = _STATE_APPEAR - self.agent.act('appear', self.loc, False) - - def disappear(self): - self.state = _STATE_DISAPPEAR - self.agent.act('disappear', self.loc, False) - - def move(self): - self.state = _STATE_FLOATING - self.agent.act('default', self.loc, False) - \ No newline at end of file diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/common.py --- a/clients/rio_de_hola/scripts/common.py Sun Jul 20 20:08:11 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -class ProgrammingError(Exception): - pass - -class InitializationError(Exception): - pass \ No newline at end of file diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/common/__init__.py diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/common/common.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/rio_de_hola/scripts/common/common.py Mon Jul 21 13:46:15 2008 +0000 @@ -0,0 +1,5 @@ +class ProgrammingError(Exception): + pass + +class InitializationError(Exception): + pass diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/common/eventlistenerbase.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/rio_de_hola/scripts/common/eventlistenerbase.py Mon Jul 21 13:46:15 2008 +0000 @@ -0,0 +1,54 @@ +import fife + +class EventListenerBase(fife.IKeyListener, fife.ICommandListener, fife.IMouseListener, + fife.ConsoleExecuter, fife.IWidgetListener): + def __init__(self, engine, regKeys=False, regCmd=False, regMouse=False, regConsole=False, regWidget=False): + self.eventmanager = engine.getEventManager() + + fife.IKeyListener.__init__(self) + if regKeys: + self.eventmanager.addKeyListener(self) + fife.ICommandListener.__init__(self) + if regCmd: + self.eventmanager.addCommandListener(self) + fife.IMouseListener.__init__(self) + if regMouse: + self.eventmanager.addMouseListener(self) + fife.ConsoleExecuter.__init__(self) + if regConsole: + engine.getGuiManager().getConsole().setConsoleExecuter(self) + fife.IWidgetListener.__init__(self) + if regWidget: + self.eventmanager.addWidgetListener(self) + + + def mousePressed(self, evt): + pass + def mouseReleased(self, evt): + pass + def mouseEntered(self, evt): + pass + def mouseExited(self, evt): + pass + def mouseClicked(self, evt): + pass + def mouseWheelMovedUp(self, evt): + pass + def mouseWheelMovedDown(self, evt): + pass + def mouseMoved(self, evt): + pass + def mouseDragged(self, evt): + pass + def keyPressed(self, evt): + pass + def keyReleased(self, evt): + pass + def onCommand(self, command): + pass + def onToolsClick(self): + print "No tools set up yet" + def onConsoleCommand(self, command): + pass + def onWidgetAction(self, evt): + pass diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/eventlistenerbase.py --- a/clients/rio_de_hola/scripts/eventlistenerbase.py Sun Jul 20 20:08:11 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -import fife - -class EventListenerBase(fife.IKeyListener, fife.ICommandListener, fife.IMouseListener, - fife.ConsoleExecuter, fife.IWidgetListener): - def __init__(self, engine, regKeys=False, regCmd=False, regMouse=False, regConsole=False, regWidget=False): - self.eventmanager = engine.getEventManager() - - fife.IKeyListener.__init__(self) - if regKeys: - self.eventmanager.addKeyListener(self) - fife.ICommandListener.__init__(self) - if regCmd: - self.eventmanager.addCommandListener(self) - fife.IMouseListener.__init__(self) - if regMouse: - self.eventmanager.addMouseListener(self) - fife.ConsoleExecuter.__init__(self) - if regConsole: - engine.getGuiManager().getConsole().setConsoleExecuter(self) - fife.IWidgetListener.__init__(self) - if regWidget: - self.eventmanager.addWidgetListener(self) - - - def mousePressed(self, evt): - pass - def mouseReleased(self, evt): - pass - def mouseEntered(self, evt): - pass - def mouseExited(self, evt): - pass - def mouseClicked(self, evt): - pass - def mouseWheelMovedUp(self, evt): - pass - def mouseWheelMovedDown(self, evt): - pass - def mouseMoved(self, evt): - pass - def mouseDragged(self, evt): - pass - def keyPressed(self, evt): - pass - def keyReleased(self, evt): - pass - def onCommand(self, command): - pass - def onToolsClick(self): - print "No tools set up yet" - def onConsoleCommand(self, command): - pass - def onWidgetAction(self, evt): - pass diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/girl.py --- a/clients/rio_de_hola/scripts/girl.py Sun Jul 20 20:08:11 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -from agent import Agent -import settings as TDS -import fife - -_STATE_NONE, _STATE_IDLE, _STATE_RUN, _STATE_FOLLOW = 0, 1, 2, 3 - -GIRL_SPEED = 3 * TDS.TestAgentSpeed -class Girl(Agent): - def __init__(self, model, agentName, layer, uniqInMap=True): - super(Girl, self).__init__(model, agentName, layer, uniqInMap) - self.state = _STATE_NONE - self.waypoints = ((67, 80), (75, 44)) - self.waypoint_counter = 0 - self.hero = self.layer.getInstance('PC') - - def onInstanceActionFinished(self, instance, action): - if self.state in (_STATE_RUN, _STATE_FOLLOW): - self.idle() - else: - if self.waypoint_counter % 3: - self.waypoint_counter += 1 - self.follow_hero() - else: - self.run(self.getNextWaypoint()) - - def getNextWaypoint(self): - self.waypoint_counter += 1 - l = fife.Location(self.layer) - l.setLayerCoordinates(fife.ModelCoordinate(*self.waypoints[self.waypoint_counter % len(self.waypoints)])) - return l - - def start(self): - self.follow_hero() - - def idle(self): - self.state = _STATE_IDLE - self.agent.act('stand', self.agent.getFacingLocation(), False) - - def follow_hero(self): - self.state = _STATE_FOLLOW - self.agent.follow('run', self.hero, GIRL_SPEED) - - def run(self, location): - self.state = _STATE_RUN - self.agent.move('run', location, GIRL_SPEED) - diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/hero.py --- a/clients/rio_de_hola/scripts/hero.py Sun Jul 20 20:08:11 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -import random -from agent import Agent -import settings as TDS - -_STATE_NONE, _STATE_IDLE, _STATE_RUN, _STATE_KICK, _STATE_TALK = xrange(5) - -class Hero(Agent): - def __init__(self, model, agentName, layer, uniqInMap=True): - super(Hero, self).__init__(model, agentName, layer, uniqInMap) - self.state = _STATE_NONE - self.idlecounter = 1 - - def onInstanceActionFinished(self, instance, action): - self.idle() - if action.getId() != 'stand': - self.idlecounter = 1 - else: - self.idlecounter += 1 - if self.idlecounter % 7 == 0: - txtindex = random.randint(0, len(TDS.heroTexts) - 1) - instance.say(TDS.heroTexts[txtindex], 2500) - - def start(self): - self.idle() - - def idle(self): - self.state = _STATE_IDLE - self.agent.act('stand', self.agent.getFacingLocation()) - - def run(self, location): - self.state = _STATE_RUN - self.agent.move('run', location, 4 * TDS.TestAgentSpeed) - - def kick(self, target): - self.state = _STATE_KICK - self.agent.act('kick', target) - - def talk(self, target): - self.state = _STATE_TALK - self.agent.act('talk', target) diff -r 346738d09188 -r 214e3eb81eb2 clients/rio_de_hola/scripts/world.py --- a/clients/rio_de_hola/scripts/world.py Sun Jul 20 20:08:11 2008 +0000 +++ b/clients/rio_de_hola/scripts/world.py Mon Jul 21 13:46:15 2008 +0000 @@ -2,14 +2,14 @@ import pychan import pychan.widgets as widgets -from eventlistenerbase import EventListenerBase +from scripts.common.eventlistenerbase import EventListenerBase from loaders import loadMapFile from savers import saveMapFile -from hero import Hero -from girl import Girl -from cloud import Cloud -from beekeeper import Beekeeper -from agent import create_anonymous_agents +from agents.hero import Hero +from agents.girl import Girl +from agents.cloud import Cloud +from agents.beekeeper import Beekeeper +from agents.agent import create_anonymous_agents import settings as TDS class MapListener(fife.MapChangeListener): diff -r 346738d09188 -r 214e3eb81eb2 doc/dependencies/filedeps.dot --- a/doc/dependencies/filedeps.dot Sun Jul 20 20:08:11 2008 +0000 +++ b/doc/dependencies/filedeps.dot Mon Jul 21 13:46:15 2008 +0000 @@ -267,6 +267,7 @@ "engine/core/model/structures/layer.cpp" -> "instancetree.h" "engine/core/model/structures/layer.cpp" -> "layer.h" "engine/core/model/structures/layer.cpp" -> "map.h" + "engine/core/model/structures/layer.cpp" -> "util/log/logger.h" "engine/core/model/structures/layer.cpp" -> "util/structures/purge.h" "engine/core/model/structures/layer.h" -> "instance.h" "engine/core/model/structures/layer.h" -> "model/metamodel/modelcoords.h" @@ -518,6 +519,7 @@ "engine/core/video/opengl/glimage.h" -> "fife_opengl.h" "engine/core/video/opengl/glimage.h" -> "util/base/fife_stdint.h" "engine/core/video/opengl/glimage.h" -> "video/image.h" + "engine/core/video/opengl/renderbackendopengl.cpp" -> "SDL_image.h" "engine/core/video/opengl/renderbackendopengl.cpp" -> "fife_opengl.h" "engine/core/video/opengl/renderbackendopengl.cpp" -> "glimage.h" "engine/core/video/opengl/renderbackendopengl.cpp" -> "renderbackendopengl.h" @@ -529,6 +531,7 @@ "engine/core/video/renderbackend.h" -> "util/base/singleton.h" "engine/core/video/renderbackend.h" -> "util/structures/point.h" "engine/core/video/renderbackend.h" -> "util/structures/rect.h" + "engine/core/video/sdl/renderbackendsdl.cpp" -> "SDL_image.h" "engine/core/video/sdl/renderbackendsdl.cpp" -> "renderbackendsdl.h" "engine/core/video/sdl/renderbackendsdl.cpp" -> "sdlimage.h" "engine/core/video/sdl/renderbackendsdl.cpp" -> "util/base/exception.h"