1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific: |
---|
14 | main-programmer: Christian Meyer |
---|
15 | co-programmer: ... |
---|
16 | */ |
---|
17 | |
---|
18 | |
---|
19 | #include "levelfactory.h" |
---|
20 | |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | |
---|
24 | /* -------------------------------------------------- |
---|
25 | * LevelFactory |
---|
26 | * -------------------------------------------------- |
---|
27 | */ |
---|
28 | |
---|
29 | LevelFactory* LevelFactory::singletonRef = NULL; |
---|
30 | |
---|
31 | LevelFactory* LevelFactory::getInstance () |
---|
32 | { |
---|
33 | if (singletonRef == NULL) |
---|
34 | singletonRef = new LevelFactory(); |
---|
35 | return singletonRef; |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | \brief loads a level from an XMLFile and feeds it into the world |
---|
40 | \param filename the XML file to be parsed |
---|
41 | |
---|
42 | */ |
---|
43 | int LevelFactory::loadXMLFile( char* filename) |
---|
44 | { |
---|
45 | TiXMLDocument* XMLDoc = new TiXMLDocument( filename); |
---|
46 | // load the level document |
---|
47 | if( !XMLDoc.LoadFile()) |
---|
48 | { |
---|
49 | // report an error somehow |
---|
50 | printf("Error loading XML File: %s @ %d:%d\n", XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol()); |
---|
51 | delete( XMLDoc); |
---|
52 | return -1; |
---|
53 | } |
---|
54 | |
---|
55 | // get orxonox simpleton |
---|
56 | // find the world |
---|
57 | // start loading objects into world |
---|
58 | // free the XML data |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | \brief constructor |
---|
63 | |
---|
64 | set everything to zero |
---|
65 | */ |
---|
66 | LevelFactory::LevelFactory () |
---|
67 | { |
---|
68 | // clear the Factory Q |
---|
69 | first = NULL; |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | \brief deconstructor |
---|
74 | |
---|
75 | kills the Q and the singletonRef |
---|
76 | */ |
---|
77 | LevelFactory::LevelFactory () |
---|
78 | { |
---|
79 | singletonRef = NULL; |
---|
80 | delete first; |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | \brief register an ObjectFactory to the LevelFactory |
---|
85 | \param factory an ObjectFactory to be registered |
---|
86 | */ |
---|
87 | void LevelFactory::registerFactory( ObjectFactory* factory) |
---|
88 | { |
---|
89 | if( first == NULL) first = factory; |
---|
90 | else first->registerFactory( factory); |
---|
91 | } |
---|
92 | |
---|
93 | /* -------------------------------------------------- |
---|
94 | * ObjectFactory |
---|
95 | * -------------------------------------------------- |
---|
96 | */ |
---|
97 | |
---|
98 | /** |
---|
99 | \brief constructor |
---|
100 | |
---|
101 | set everything to zero and define classname |
---|
102 | */ |
---|
103 | ObjectFactory::ObjectFactory () |
---|
104 | { |
---|
105 | classname = "NULL" |
---|
106 | next = NULL; |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | \brief constructor |
---|
111 | |
---|
112 | clear the Q |
---|
113 | */ |
---|
114 | ObjectFactory::~ObjectFactory () |
---|
115 | { |
---|
116 | delete next; |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | \brief used to run through the Q to find a factory that can load the specified object |
---|
121 | */ |
---|
122 | BaseObject* ObjectFactory::loadObject( char* name, void* data) |
---|
123 | { |
---|
124 | if( !strcmp( name, classname)) return fabricateObject( data); |
---|
125 | else if( next != NULL) return next->loadObject( name, data); |
---|
126 | else return NULL; |
---|
127 | } |
---|
128 | |
---|
129 | /** |
---|
130 | \brief generates the associated object from data |
---|
131 | */ |
---|
132 | BaseObject* ObjectFactory::fabricateObject( void* data) |
---|
133 | { |
---|
134 | return NULL; |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | \brief add an ObjectFactory to the ObjectFactory Q |
---|
139 | \param factory an ObjectFactory to be registered |
---|
140 | */ |
---|
141 | void ObjectFactory::registerFactory( ObjectFactory* factory) |
---|
142 | { |
---|
143 | if( next == NULL) next = factory; |
---|
144 | else next->registerFactory( factory); |
---|
145 | } |
---|
146 | |
---|
147 | /** |
---|
148 | \brief make this particular factory known to the LevelFactory |
---|
149 | */ |
---|
150 | void ObjectFactory::initialize() |
---|
151 | { |
---|
152 | LevelFactory* fct = LevelFactory::getInstance(); |
---|
153 | fct.registerFactory( this); |
---|
154 | } |
---|