ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/loader.C
(Generate patch)

Comparing deliantra/server/common/loader.C (file contents):
Revision 1.51 by root, Thu Feb 1 17:29:16 2007 UTC vs.
Revision 1.52 by root, Thu Feb 1 19:15:38 2007 UTC

28 28
29#include <global.h> 29#include <global.h>
30#include <loader.h> 30#include <loader.h>
31#include <sproto.h> 31#include <sproto.h>
32 32
33// resource loader pure base class 33/////////////////////////////////////////////////////////////////////////////
34struct loader_base
35{
36 const char *filename;
37 virtual const char *type () const = 0;
38
39 virtual archetype *get_arch (const char *name);
40 virtual void put_arch (archetype *arch);
41
42 virtual object *get_object (const char *name);
43 virtual void put_object (object *op);
44
45 virtual player *get_player ();
46 virtual void put_player (player *pl);
47
48 virtual region *get_region (const char *name);
49 virtual void put_region (region *region);
50
51 virtual facetile *get_face (const char *name);
52 virtual void put_face (facetile *face);
53
54 virtual treasurelist *get_treasure (const char *name, bool one = false);
55 virtual void put_treasure (treasurelist *treasure);
56
57 virtual animation *get_animation (const char *name);
58 virtual void put_animation (animation *anim);
59};
60
61// pure base class for default archetype loader
62struct loader_arch : virtual loader_base {
63 archetype *get_arch (const char *name);
64 void put_arch (archetype *arch);
65};
66
67// pure base class for default object loader
68struct loader_object : virtual loader_base {
69 object *get_object (const char *name);
70 void put_object (object *op);
71};
72
73// pure base class for default player loader
74struct loader_player : virtual loader_base {
75 virtual player *get_player ();
76 virtual void put_player (player *pl);
77};
78
79// pure base class for default region loader
80struct loader_region : virtual loader_base {
81 region *get_region ();
82 void put_region (region *region);
83};
84
85// pure base class for default face loader
86struct loader_face : virtual loader_base {
87 facetile *get_face (const char *name);
88 void put_face (facetile *face);
89};
90
91// pure base class for default treasure loader
92struct loader_treasure : virtual loader_base {
93 treasurelist *get_treasure (const char *name, bool one = false);
94 void put_treasure (treasurelist *treasure);
95};
96
97// pure base class for default animation loader
98struct loader_animation : virtual loader_base {
99 animation *get_animation (const char *name);
100 void put_animation (animation *anim);
101};
102
103// future generic resource loader
104// handles generic stuff valid in most files, such as
105// animations, treasures, faces and so on
106struct loader_generic
107: virtual loader_base,
108 loader_object, loader_player,
109 loader_region, loader_face,
110 loader_treasure, loader_animation
111{
112 const char *type () const = 0;
113};
114 34
115// the base class warns about and skips everything 35// the base class warns about and skips everything
116archetype * 36archetype *
117loader_base::get_arch (const char *name) 37loader_base::get_arch (const char *name)
118{ 38{
119 LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of type %s.\n", 39 LOG (llevError, "%s: found archetype definition '%s', which is not allowed in files of this type.\n",
120 filename, name, type ()); 40 filename, name);
121 41
122 return new archetype; 42 return new archetype;
123} 43}
124 44
125object * 45object *
126loader_base::get_object (const char *name) 46loader_base::get_object (const char *name)
127{ 47{
128 LOG (llevError, "%s: found object definition '%s', which is not allowed in files of type %s.\n", 48 LOG (llevError, "%s: found object definition '%s', which is not allowed in files of this type.\n",
129 filename, name, type ()); 49 filename, name);
130 50
131 return object::create (); 51 return object::create ();
132} 52}
133 53
134player * 54player *
135loader_base::get_player () 55loader_base::get_player ()
136{ 56{
137 LOG (llevError, "%s: found player definition, which is not allowed in files of type %s.\n", 57 LOG (llevError, "%s: found player definition, which is not allowed in files of this type.\n",
138 filename, type ()); 58 filename);
139 59
140 return player::create (); 60 return player::create ();
141} 61}
142 62
143region * 63region *
144loader_base::get_region (const char *name) 64loader_base::get_region (const char *name)
145{ 65{
146 LOG (llevError, "%s: found region definition '%s', which is not allowed in files of type %s.\n", 66 LOG (llevError, "%s: found region definition '%s', which is not allowed in files of this type.\n",
147 filename, name, type ()); 67 filename, name);
148 68
149 return new region; 69 return new region;
150} 70}
151 71
152facetile * 72facetile *
153loader_base::get_face (const char *name) 73loader_base::get_face (const char *name)
154{ 74{
155 LOG (llevError, "%s: found face definition '%s', which is not allowed in files of type %s.\n", 75 LOG (llevError, "%s: found face definition '%s', which is not allowed in files of this type.\n",
156 filename, name, type ()); 76 filename, name);
157 77
158 return new facetile; 78 return new facetile;
159} 79}
160 80
161treasurelist * 81treasurelist *
162loader_base::get_treasure (const char *name, bool one) 82loader_base::get_treasure (const char *name, bool one)
163{ 83{
164 LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of type %s.\n", 84 LOG (llevError, "%s: found treasure definition '%s', which is not allowed in files of this type.\n",
165 filename, name, type ()); 85 filename, name);
166 86
167 return new treasurelist;//D 87 return new treasurelist;//D
168} 88}
169 89
170animation * 90animation *
171loader_base::get_animation (const char *name) 91loader_base::get_animation (const char *name)
172{ 92{
173 LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of type %s.\n", 93 LOG (llevError, "%s: found animation definition '%s', which is not allowed in files of this type.\n",
174 filename, name, type ()); 94 filename, name);
175 95
176 return new animation; 96 return new animation;
177} 97}
178 98
179void 99void
215void 135void
216loader_base::put_animation (animation *anim) 136loader_base::put_animation (animation *anim)
217{ 137{
218 delete anim; 138 delete anim;
219} 139}
140
141/////////////////////////////////////////////////////////////////////////////
142
143bool loader_base::parse (object_thawer &thawer)
144{
145 for (;;)
146 {
147 keyword kw = thawer.get_kv ();
148
149 switch (kw)
150 {
151 case KW_region:
152 {
153 region *rgn = get_region (thawer.get_str ());
154
155 if (!parse_region (thawer, rgn))
156 {
157 delete rgn;
158 return false;
159 }
160
161 put_region (rgn);
162 }
163 break;
164
165 case KW_EOF:
166 return true;
167
168 default:
169 if (!thawer.parse_error (kw, "resource file"))
170 return false;
171 }
172 }
173}
174
175bool loader_base::load (const char *filename)
176{
177 this->filename = filename;
178
179 object_thawer fp (filename);
180
181 if (!fp)
182 return false;
183
184 return parse (fp);
185}
186
187/////////////////////////////////////////////////////////////////////////////
220 188
221/* Maps the MOVE_* values to names */ 189/* Maps the MOVE_* values to names */
222static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL }; 190static const char *const move_name[] = { "walk", "fly_low", "fly_high", "swim", "boat", NULL };
223 191
224/* This table is only necessary to convert objects that existed before the 192/* This table is only necessary to convert objects that existed before the
1222 set_ob_key_value (op, thawer.last_keyword, thawer.last_value, true); 1190 set_ob_key_value (op, thawer.last_keyword, thawer.last_value, true);
1223 //fprintf (stderr, "addkv(%s,%s)\n", thawer.last_keyword, thawer.last_value);//D 1191 //fprintf (stderr, "addkv(%s,%s)\n", thawer.last_keyword, thawer.last_value);//D
1224 break; 1192 break;
1225 1193
1226 default: 1194 default:
1227 LOG (llevError, "UNSUPPORTED KEYWORD IN MAP: \"%s\", bug in normaliser. skipping.\n", keyword_str[kw]); 1195 if (!thawer.parse_error (kw, "object", op->name))
1196 return false;
1228 break; 1197 break;
1229 } 1198 }
1230 } 1199 }
1231} 1200}
1232 1201

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines