2 fegdk: FE Game Development Kit
3 Copyright (C) 2001-2008 Alexey "waker" Yakovenko
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 waker@users.sourceforge.net
25 #include "f_texture.h"
27 #include "f_material.h"
28 #include "f_animation.h"
31 #include "f_cgshader.h"
33 #include "f_ps14shader.h"
35 #include "f_resourcemgr.h"
42 resourceMgr::resourceMgr (void)
44 setName ("resource mgr");
47 resourceMgr::~resourceMgr (void)
51 resource
<texture
> *resourceMgr::getTextureMgr (void)
56 resource
<material
> *resourceMgr::getMaterialMgr (void)
61 resource
<fontFT
> *resourceMgr::getFontFTMgr (void)
66 resource
<sceneObject
> *resourceMgr::getModelMgr (void)
71 resource
<animation
> *resourceMgr::getAnimationMgr (void)
73 return &mAnimationMgr
;
76 resource
<cgShader
> *resourceMgr::getCGShaderMgr (void)
85 resource
<ps14Shader
> *resourceMgr::getPS14ShaderMgr (void)
87 return &mPS14ShaderMgr
;
90 resource
<effect
> *resourceMgr::getEffectMgr (void)
95 texture
* resourceMgr::createTexture (const char *name
)
97 texture
*t
= mTextureMgr
.create (name
);
99 return mTextureMgr
.create ("textures/common/notfound.png");
103 texture
* resourceMgr::createTexture (charParser
&parser
)
105 texture
*t
= mTextureMgr
.create (parser
);
107 return mTextureMgr
.create ("textures/common/notfound.png");
111 material
* resourceMgr::createMaterial (const char *name
)
113 return mMaterialMgr
.create (name
);
116 material
* resourceMgr::createMaterial (charParser
&parser
)
118 return mMaterialMgr
.create (parser
);
121 fontFT
* resourceMgr::createFontFT (const char *name
)
123 return mFontMgr
.create (name
);
126 fontFT
* resourceMgr::createFontFT (charParser
&parser
)
128 return mFontMgr
.create (parser
);
133 std::vector
<materialPtr
> mMtlList
;
135 void add (const materialPtr
&mtl
) { mMtlList
.push_back (mtl
); }
136 int numMtls (void) const { return (int)mMtlList
.size (); }
137 materialPtr
getMtl (int i
) { return mMtlList
[i
]; }
141 f
->readUINT32 (&sp
, 1);
144 mMtlList
.resize (sp
);
145 for (uint32 i
= 0; i
< sp
; i
++)
149 char *str
= new char[ln
+1];
152 mMtlList
[i
] = g_engine
->getResourceMgr ()->createMaterial (str
);
158 static void loadModelFromFile (file
*f
, int majorver
, int minorver
, sceneObject
*node
, mtlBlock
*mtls
)
163 f
->read (&nsz
, sizeof (char));
177 f
->readMatrix4 (&mtx
, 1);
178 matrix4 worldMtx
= node
->getParent () ? mtx
* node
->getParent ()->getWorldMatrix() : mtx
;
179 node
->setRelativeMatrix (mtx
);
180 node
->setWorldMatrix (worldMtx
);
183 // ok, try mesh subsets
184 f
->readUINT32 (&sp
, 1);
188 renderable
*rend
= new renderable (mdl
);
189 node
->attachRenderable (rend
);
190 mdl
->loadMesh (f
, majorver
, minorver
, mtls
->mMtlList
, sp
, rend
);
198 f
->read (&tangents
, sizeof (uchar
));
203 f
->read (&lightmaps
, sizeof(uchar
));
206 f
->readUINT32 (&sp
, 1);
209 f
->readUINT32 (&sp
, 1);
211 // old version animation flag
215 f
->read (&b
, sizeof (b
));
220 f
->readUINT32 (&sp
, 1);
223 for (uint32 i
= 0; i
< nChildren
; i
++)
225 sceneObject
*c
= new sceneObject (node
);
226 loadModelFromFile (f
, majorver
, minorver
, c
, mtls
);
231 static sceneObject
*loadModelFromFile (const char *fname
)
233 // sceneobject must be created for each node
234 // model must be created only where mesh exists
235 file
*f
= g_engine
->getFileSystem ()->openFile (fname
, FS_MODE_READ
);
239 sceneObject
*node
= new sceneObject (NULL
);
244 // for now i support only 1.1
245 if (!strcmp (mgc
, "FEMDL0101"))
250 else if (!strcmp (mgc
, "FEMDL0102"))
256 sys_error("Invalid model file signature (%s).\n", f
->name());
262 loadModelFromFile (f
, majorver
, minorver
, node
, &mtls
);
268 sceneObject
* resourceMgr::createModel (const char *name
, animContainer
*anim
)
270 // model is created specially, cause we need instancing
271 sceneObject
*obj
= mModelMgr
.getResource (name
);
275 obj
= loadModelFromFile (name
);
276 // model *mdl = new model ();
277 // obj = mdl->load (name);
278 mModelMgr
.addResource (name
, obj
);
281 // create from template
282 sceneObject
*newModel
= obj
->getNewInstance ();
284 newModel
->initAnimData (anim
);
288 sceneObject
* resourceMgr::createModel (charParser
&parser
)
293 animation
* resourceMgr::createAnimation (const char *name
)
295 return mAnimationMgr
.create (name
);
298 animation
* resourceMgr::createAnimation (charParser
&parser
)
300 return mAnimationMgr
.create (parser
);
304 cgShader
* resourceMgr::createCGShader (const char *name
)
306 return mCGShaderMgr
.create (name
);
309 cgShader
* resourceMgr::createCGShader (charParser
&parser
)
311 return mCGShaderMgr
.create (parser
);
315 ps14Shader
* resourceMgr::createPS14Shader (const char *name
)
317 return mPS14ShaderMgr
.create (name
);
319 ps14Shader
* resourceMgr::createPS14Shader (charParser
&parser
)
321 return mPS14ShaderMgr
.create (parser
);
324 effect
* resourceMgr::createEffect (const char *name
)
326 return mEffectMgr
.create (name
);
329 effect
* resourceMgr::createEffect (charParser
&parser
)
331 return mEffectMgr
.create (parser
);