Mercurial > fife-parpg
annotate engine/extensions/loaders.py @ 146:54b3984e1afc
The getIndex function was a hack that shadowed another bug
that caused the pools to misbehave.
AddResourceFromFile works now exactly as getIndex,
it's just faster.
Fixed GUIImage to not hold a reference, it uses the
index directly anyway.
Plus heaps of minor adjustments for
more informative debug output and statistics.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 09 Oct 2008 12:36:21 +0000 |
parents | e7a431577c95 |
children | 48c99636453e |
rev | line source |
---|---|
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # coding: utf-8 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 # Loader interface for FIFE's native xml format. |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 import fife |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 from serializers.xmlmap import XMLMapLoader |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 from serializers import WrongFileType, NameClash |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 |
141
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
9 from serializers.xmlobject import XMLObjectLoader |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
10 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 fileExtensions = ('xml',) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 |
141
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
13 def loadMapFile(path, engine, callback=None): |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
14 """ load map file and get (an optional) callback if major stuff is done: |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
15 - map creation |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
16 - parsed imports |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
17 - parsed layers |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
18 - parsed cameras |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
19 the callback will send both a string and a float (which shows |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
20 the overall process), callback(string, float) |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
21 |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
22 @return map : map object |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
23 """ |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
24 map_loader = XMLMapLoader(engine, callback) |
145
e7a431577c95
Cleaned the basic model up. Code is cleaner now and a bit faster.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
141
diff
changeset
|
25 map = map_loader.loadResource(fife.ResourceLocation(path)) |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
26 print "--- Loading map took: ", map_loader.time_to_load, " seconds." |
145
e7a431577c95
Cleaned the basic model up. Code is cleaner now and a bit faster.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
141
diff
changeset
|
27 return map |
e7a431577c95
Cleaned the basic model up. Code is cleaner now and a bit faster.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
141
diff
changeset
|
28 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 def loadImportFile(path, engine): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 object_loader = XMLObjectLoader(engine.getImagePool(), engine.getAnimationPool(), engine.getModel(), engine.getVFS()) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 res = None |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 try: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 res = object_loader.loadResource(fife.ResourceLocation(path)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 print 'imported object file ' + path |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 except WrongFileType: |
10
ab09325f901e
Camera was attached to instance on a different layer, resulting in strange scrolling. Fixed it, and added a check to prevent this happening again (attach-to-other-layer fails and logs a warning).
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
37 pass |
ab09325f901e
Camera was attached to instance on a different layer, resulting in strange scrolling. Fixed it, and added a check to prevent this happening again (attach-to-other-layer fails and logs a warning).
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
38 # print 'ignored non-object file ' + path |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 except NameClash: |
10
ab09325f901e
Camera was attached to instance on a different layer, resulting in strange scrolling. Fixed it, and added a check to prevent this happening again (attach-to-other-layer fails and logs a warning).
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
40 pass |
ab09325f901e
Camera was attached to instance on a different layer, resulting in strange scrolling. Fixed it, and added a check to prevent this happening again (attach-to-other-layer fails and logs a warning).
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
41 # print 'ignored already loaded file ' + path |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 return res |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 def loadImportDir(path, engine): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 for file in filter(lambda f: f.split('.')[-1] == 'xml', engine.getVFS().listFiles(path)): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 loadImportFile('/'.join([path, file]), engine) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 def loadImportDirRec(path, engine): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 loadImportDir(path, engine) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 for dir in filter(lambda d: not d.startswith('.'), engine.getVFS().listDirectories(path)): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 loadImportDirRec('/'.join([path, dir]), engine) |