2 #include "entclasses.h"
4 #include "entitymanager.h"
5 #include "f_resourcemgr.h"
6 #include "f_material.h"
12 * editorname: worldspawn
15 entWorld::~entWorld (void)
19 void entWorld::init (void)
32 std::vector
<vertex_t
> verts
;
36 struct cmpPolygons
: public std::binary_function
<polygon_t
, polygon_t
, bool>
38 bool operator() (const polygon_t
&a
, const polygon_t
&b
)
40 return (a
.mtl
< b
.mtl
);
44 void entWorld::load (const char *fname
)
46 std::vector
<cStr
> mtlNameList
;
47 std::vector
<materialPtr
> mtlList
;
48 std::vector
<polygon_t
> polygons
;
52 charParser
p (g_engine
->getFileSystem (), fname
);
56 if (!p
.cmptoken ("polygons"))
62 if (!p
.cmptoken ("}"))
64 else if (!p
.cmptoken ("{"))
70 std::vector
<cStr
>::iterator m
= std::find (mtlNameList
.begin (), mtlNameList
.end (), p
.token ());
71 if (m
== mtlNameList
.end ())
73 mtlNameList
.push_back (p
.token ());
74 poly
.mtl
= mtlNameList
.size ();
78 poly
.mtl
= m
- mtlNameList
.begin ();
82 int nverts
= atoi (p
.token ());
84 for (int v
= 0; v
< nverts
; v
++)
88 vx
.x
= atof (p
.token ());
90 vx
.y
= atof (p
.token ());
92 vx
.z
= atof (p
.token ());
94 vx
.u
= atof (p
.token ());
96 vx
.v
= atof (p
.token ());
97 poly
.verts
.push_back (vx
);
102 vector3 a
= (vector3
&)(poly
.verts
[0].x
) - (vector3
&)(poly
.verts
[1].x
);
103 vector3 b
= (vector3
&)(poly
.verts
[2].x
) - (vector3
&)(poly
.verts
[1].x
);
104 poly
.normal
= a
.cross (b
);
105 poly
.normal
.normalize ();
106 polygons
.push_back (poly
);
109 p
.generalSyntaxError ();
112 else if (!p
.cmptoken ("entity"))
117 std::map
<cStr
, cStr
> parms
;
119 if (!p
.cmptoken ("}"))
121 std::map
<cStr
, cStr
>::iterator it
= parms
.find ("classname");
122 if (it
== parms
.end ())
124 fprintf (stderr
, "WARNING: entity without classname in mapfile\n");
127 uint32 id
= g_engine
->getEntManager ()->getEClassForClassName ((*it
).second
);
128 entityPtr ent
= g_engine
->getEntManager ()->createEntity (id
);
129 // ent->setParms (parms);
130 mEnts
.push_back (ent
);
136 cStr key
= p
.token ();
138 cStr value
= p
.token ();
144 p
.generalSyntaxError ();
147 catch (parserException e
)
152 sort (polygons
.begin (), polygons
.end (), cmpPolygons());
155 size_t sz
= mtlNameList
.size ();
156 for (size_t m
= 0; m
< sz
; m
++)
158 mtlList
.push_back (g_engine
->getResourceMgr ()->createMaterial (mtlNameList
[m
]));
161 // create vertex&index buffers, and create model
162 std::vector
<drawVertex_t
> verts
;
163 std::vector
<ushort
> inds
;
164 std::vector
<modelSubset_t
> subs
;
166 sz
= polygons
.size ();
168 modelSubset_t
*sub
= NULL
;
169 for (size_t pp
= 0; pp
< sz
; pp
++)
171 polygon_t
&p
= polygons
[pp
];
176 subs
.resize (subs
.size () + 1);
178 sub
->mtl
= mtlList
[mtl
];
179 sub
->firstVertex
= verts
.size ();
180 sub
->firstFace
= inds
.size ()/3;
185 // add polygon as a set of verts and indexes
186 size_t nverts
= p
.verts
.size ();
187 for (size_t v
= 0; v
< nverts
; v
++)
189 verts
.resize (verts
.size () + 1);
190 drawVertex_t
&vx
= verts
.back ();
191 vx
.pos
.x
= p
.verts
[v
].x
;
192 vx
.pos
.y
= p
.verts
[v
].y
;
193 vx
.pos
.z
= p
.verts
[v
].z
;
195 vx
.uv
.x
= p
.verts
[v
].u
;
196 vx
.uv
.y
= p
.verts
[v
].v
;
197 vx
.uvLightmap
.x
= p
.verts
[v
].u
;
198 vx
.uvLightmap
.y
= p
.verts
[v
].v
;
204 // poly is a triangle fan, convert it to indexed trilist
205 size_t nfaces
= nverts
-2;
206 for (size_t f
= 1; f
< nfaces
-1; f
++)
208 inds
.push_back (0+sub
->numVerts
);
209 inds
.push_back (f
+sub
->numVerts
);
210 inds
.push_back (f
+1+sub
->numVerts
);
212 sub
->numVerts
+= nverts
;
213 sub
->numFaces
+= nfaces
;
217 // mpModel = new model (fname, NULL, mtx, verts, inds, subs, mtlList);
221 smartPtr
<model
> entWorld::getModel (void) const
227 * editorname: info_playerstart
230 void entSpawnSpot::init (void)
235 * editorname: info_physx
237 void entPhysXObj::init (void)