Mercurial > fife-parpg
annotate clients/rio_de_hola/run.py @ 131:6b4bb57f3abb
Compatibility patch for boost 1.36.0
author | m64@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 23 Aug 2008 21:43:21 +0000 |
parents | ae3b8139c7c7 |
children | bb9902910067 |
rev | line source |
---|---|
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 #!/usr/bin/env python |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 # coding: utf-8 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # This is the rio de hola client for FIFE. |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
5 import sys, os, re, math, random, shutil |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 def _jp(path): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 return os.path.sep.join(path.split('/')) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 _paths = ('../../engine/swigwrappers/python', '../../engine/extensions') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 for p in _paths: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 if p not in sys.path: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 sys.path.append(_jp(p)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
15 if not os.path.exists('settings.xml'): |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
16 shutil.copyfile('settings-dist.xml', 'settings.xml') |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
17 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 import fife, fifelog |
98
214e3eb81eb2
better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
19 from scripts import world |
214e3eb81eb2
better structure for techdemo scripts + svn:ignore fixes
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
20 from scripts.common import eventlistenerbase |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 from basicapplication import ApplicationBase |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 import pychan |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 import pychan.widgets as widgets |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
24 from settings import Setting |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
26 TDS = Setting() |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 class ApplicationListener(eventlistenerbase.EventListenerBase): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 def __init__(self, engine, world): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 self.engine = engine |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 self.world = world |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 engine.getEventManager().setNonConsumableKeys([ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 fife.Key.ESCAPE, |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 fife.Key.F10, |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 fife.Key.LEFT, |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 fife.Key.RIGHT, |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 fife.Key.UP, |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 fife.Key.DOWN]) |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
40 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 self.quit = False |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 self.aboutWindow = None |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
43 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 self.rootpanel = pychan.loadXML('gui/rootpanel.xml') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 self.rootpanel.mapEvents({ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 'quitButton' : self.onQuitButtonPress, |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 'aboutButton' : self.onAboutButtonPress, |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
48 'optionsButton' : TDS.onOptionsPress |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 }) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 self.rootpanel.show() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 def keyPressed(self, evt): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 keyval = evt.getKey().getValue() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 keystr = evt.getKey().getAsString().lower() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 consumed = False |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 if keyval == fife.Key.ESCAPE: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 self.quit = True |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 evt.consume() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 elif keyval == fife.Key.F10: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 self.engine.getGuiManager().getConsole().toggleShowHide() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 evt.consume() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 elif keystr == 'p': |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 self.engine.getRenderBackend().captureScreen('screenshot.png') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 evt.consume() |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
65 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 def onCommand(self, command): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 if self.quit: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 command.consume() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 def onConsoleCommand(self, command): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 result = '' |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 if command.lower() in ('quit', 'exit'): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 self.quit = True |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 result = 'quitting' |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 elif command.lower() in ( 'help', 'help()' ): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 self.engine.getGuiManager().getConsole().println( open( 'misc/infotext.txt', 'r' ).read() ) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 result = "-- End of help --" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 result = self.world.onConsoleCommand(command) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 if not result: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 try: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 result = str(eval(command)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 except: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 pass |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 if not result: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
87 result = 'no result' |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 return result |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 def onQuitButtonPress(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 cmd = fife.Command() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 cmd.setSource(None) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 cmd.setCommandType(fife.CMD_QUIT_GAME) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 self.engine.getEventManager().dispatchCommand(cmd) |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
95 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 def onAboutButtonPress(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 if not self.aboutWindow: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 self.aboutWindow = pychan.loadXML('gui/help.xml') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 self.aboutWindow.mapEvents({ 'closeButton' : self.aboutWindow.hide }) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 self.aboutWindow.distributeData({ 'helpText' : open("misc/infotext.txt").read() }) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 self.aboutWindow.show() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 class IslandDemo(ApplicationBase): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 def __init__(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 super(IslandDemo,self).__init__() |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
106 pychan.init(self.engine, debug=TDS.readSetting("PychanDebug", type='bool')) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 self.world = world.World(self.engine) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 self.listener = ApplicationListener(self.engine, self.world) |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
109 self.world.load(str(TDS.readSetting("MapFile"))) |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
110 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 self.soundmanager = self.engine.getSoundManager() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 self.soundmanager.init() |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
113 |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
114 if int(TDS.readSetting("PlaySounds")): |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 # play track as background music |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 emitter = self.soundmanager.createEmitter() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 id = self.engine.getSoundClipPool().addResourceFromFile('music/rio_de_hola.ogg') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
118 emitter.setSoundClip(id) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 emitter.setLooping(True) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 emitter.play() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
122 def loadSettings(self): |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
123 """ |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
124 Load the settings from a python file and load them into the engine. |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
125 Called in the ApplicationBase constructor. |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
126 """ |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
127 import settings |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
128 self.settings = settings |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
129 |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
130 engineSetting = self.engine.getSettings() |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
131 engineSetting.setDefaultFontGlyphs(str(TDS.readSetting("FontGlyphs", strip=False))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
132 engineSetting.setDefaultFontPath(str(TDS.readSetting("Font"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
133 engineSetting.setDefaultFontSize(12) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
134 engineSetting.setBitsPerPixel(int(TDS.readSetting("BitsPerPixel"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
135 engineSetting.setInitialVolume(float(TDS.readSetting("InitialVolume"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
136 engineSetting.setSDLRemoveFakeAlpha(int(TDS.readSetting("SDLRemoveFakeAlpha"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
137 engineSetting.setScreenWidth(int(TDS.readSetting("ScreenWidth"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
138 engineSetting.setScreenHeight(int(TDS.readSetting("ScreenHeight"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
139 engineSetting.setRenderBackend(str(TDS.readSetting("RenderBackend"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
140 engineSetting.setFullScreen(int(TDS.readSetting("FullScreen"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
141 |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
142 try: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
143 engineSetting.setWindowTitle(str(TDS.readSetting("WindowTitle"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
144 engineSetting.setWindowIcon(str(TDS.readSetting("WindowIcon"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
145 except: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
146 pass |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
147 try: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
148 engineSetting.setImageChunkingSize(int(TDS.readSetting("ImageChunkSize"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
149 except: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
150 pass |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
151 |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
152 def initLogging(self): |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
153 """ |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
154 Initialize the LogManager. |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
155 """ |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
156 LogModules = TDS.readSetting("LogModules", type='list') |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
157 self.log = fifelog.LogManager(self.engine, int(TDS.readSetting("LogToPrompt")), int(TDS.readSetting("LogToFile"))) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
158 if LogModules: |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
159 self.log.setVisibleModules(*LogModules) |
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
160 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
161 def createListener(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
162 pass # already created in constructor |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
163 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 def _pump(self): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
165 if self.listener.quit: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 self.breakRequested = True |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 self.world.save('maps/savefile.xml') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 self.world.pump() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 def main(): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
172 app = IslandDemo() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 app.run() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
174 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
175 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
176 if __name__ == '__main__': |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
177 if TDS.readSetting("ProfilingOn", type='bool'): |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
178 import hotshot, hotshot.stats |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
179 print "Starting profiler" |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
180 prof = hotshot.Profile("fife.prof") |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
181 prof.runcall(main) |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
182 prof.close() |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
183 print "analysing profiling results" |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
184 stats = hotshot.stats.load("fife.prof") |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
185 stats.strip_dirs() |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
186 stats.sort_stats('time', 'calls') |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
187 stats.print_stats(20) |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
188 else: |
121
ae3b8139c7c7
* Applying settings patch by greyghost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
117
diff
changeset
|
189 if TDS.readSetting("UsePsyco", type='bool'): |
116
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
190 # Import Psyco if available |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
191 try: |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
192 import psyco |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
193 psyco.full() |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
194 print "Psyco acceleration in use" |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
195 except ImportError: |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
196 print "Psyco acceleration not used" |
c6b9e63a51d8
* Profiling support for Rio de hola by jasoka
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
98
diff
changeset
|
197 else: |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
198 print "Psyco acceleration not used" |
117
5f32bfdc4232
fix for profiling crash
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
116
diff
changeset
|
199 main() |