From: Remi B. <els...@us...> - 2004-08-29 16:10:59
|
Update of /cvsroot/once/oncecode/src/common In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18570/src/common Added Files: Tag: cel-switch ocentityfact.cpp ocentityfact.h Log Message: Another shoot of missing files, as reported by TheWizzard. --- NEW FILE: ocentityfact.h --- /* * ocentityfact.h * Copyright (C) 2003-2004 by The Once developement team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef OCENTIY_FACT_H #define OCENTIY_FACT_H #include "csutil/hash.h" #include "csutil/hashhandlers.h" /** * A factory for CEL entities. This class takes care of creating entities * according to an "entity name". */ class ocEntityFactory { private: /// This function is used to create an entity. typedef csRef<iCelEntity> (*CreateFunc)(iCelPlLayer*, iCelBlLayer*); private: /// Link to the physical layer iCelPlLayer* pl; /// The internal hash csHash<CreateFunc, const char*, csConstCharHashKeyHandler> reg; private: /** * Register an entity type, with the create and destroy function. */ void Register(const char* classname, CreateFunc create); //--------------------- Static create functions ------------------------- static csRef<iCelEntity> CreatePlayer(iCelPlLayer* pl, iCelBlLayer* bl); static csRef<iCelEntity> CreateArea(iCelPlLayer* pl, iCelBlLayer* bl); static csRef<iCelEntity> CreateSelf(iCelPlLayer* pl, iCelBlLayer* bl); public: /** * Create the factory. This requires the link to the physical layer. */ ocEntityFactory(iCelPlLayer* pl); /** * Create an entity. This function doesn't register the entity anywhere */ iCelEntity* CreateEntity(const char* name, iCelBlLayer* bl); }; #endif --- NEW FILE: ocentityfact.cpp --- /* * ocentityfact.cpp * Copyright (C) 2003-2004 by The Once developement team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include "physicallayer/pl.h" #include "physicallayer/entity.h" #include "behaviourlayer/bl.h" #include "common/ocentityfact.h" //------------------------ ocEntityFactory ---------------------------------- ocEntityFactory::ocEntityFactory(iCelPlLayer* _pl) : pl(_pl) { Register("Player", CreatePlayer); Register("Area", CreateArea); Register("Self", CreateSelf); } csRef<iCelEntity> ocEntityFactory::CreatePlayer(iCelPlLayer* pl, iCelBlLayer* bl) { return pl->CreateEntity("player", bl, "ocPlayerBehaviour", "pcmesh", "pclinearmovement", 0); } csRef<iCelEntity> ocEntityFactory::CreateArea(iCelPlLayer* pl, iCelBlLayer* bl) { return pl->CreateEntity("area", bl, "ocAreaBehaviour", "pcregion", 0); } csRef<iCelEntity> ocEntityFactory::CreateSelf(iCelPlLayer* pl, iCelBlLayer* bl) { // Camera is created into ocDisplay. return pl->CreateEntity("player", bl, "ocSelfBehaviour", "pcmesh", "pclinearmovement", 0); } void ocEntityFactory::Register(const char* classname, CreateFunc create) { CS_ASSERT(reg.DeleteAll(classname) == false); reg.Put(classname, create); } iCelEntity* ocEntityFactory::CreateEntity(const char* name, iCelBlLayer* bl) { CreateFunc create = reg.Get(name, 0); if (!create) return 0; return create(pl, bl); } |