2004-07-27 14:00:53 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "CStr.h"
|
|
|
|
|
#include "CLogger.h"
|
2005-01-06 16:47:44 -08:00
|
|
|
#include "ps/Errors.h"
|
2004-07-27 14:00:53 -07:00
|
|
|
|
|
|
|
|
#include "World.h"
|
|
|
|
|
#include "MapReader.h"
|
|
|
|
|
#include "Game.h"
|
2005-07-03 09:25:48 -07:00
|
|
|
#include "GameAttributes.h"
|
2004-07-27 14:00:53 -07:00
|
|
|
#include "Terrain.h"
|
2004-07-31 08:57:18 -07:00
|
|
|
#include "LightEnv.h"
|
|
|
|
|
#include "BaseEntityCollection.h"
|
2004-08-05 06:07:51 -07:00
|
|
|
#include "EntityManager.h"
|
2005-03-18 14:02:20 -08:00
|
|
|
#include "timer.h"
|
2005-03-21 18:17:55 -08:00
|
|
|
#include "Loader.h"
|
2005-03-22 13:00:56 -08:00
|
|
|
#include "LoaderThunks.h"
|
2005-08-14 16:34:37 -07:00
|
|
|
#include "graphics/MapWriter.h"
|
2005-09-29 17:59:42 -07:00
|
|
|
#include "UnitManager.h"
|
|
|
|
|
#include "EntityManager.h"
|
|
|
|
|
#include "Projectile.h"
|
2005-10-08 20:43:03 -07:00
|
|
|
#include "LOSManager.h"
|
2004-07-27 14:00:53 -07:00
|
|
|
|
2004-08-15 13:57:31 -07:00
|
|
|
#define LOG_CATEGORY "world"
|
|
|
|
|
|
2005-08-14 16:34:37 -07:00
|
|
|
// global light settings. this is not a member of CWorld because it is
|
|
|
|
|
// passed to the renderer before CWorld exists.
|
2004-10-23 07:39:28 -07:00
|
|
|
CLightEnv g_LightEnv;
|
2004-07-27 14:00:53 -07:00
|
|
|
|
2005-09-29 17:59:42 -07:00
|
|
|
|
|
|
|
|
CWorld::CWorld(CGame *pGame):
|
|
|
|
|
m_pGame(pGame),
|
|
|
|
|
m_Terrain(),
|
|
|
|
|
m_UnitManager(g_UnitMan),
|
|
|
|
|
m_EntityManager(*(new CEntityManager())),
|
2005-10-08 20:43:03 -07:00
|
|
|
m_ProjectileManager(*(new CProjectileManager())),
|
|
|
|
|
m_LOSManager(*(new CLOSManager()))
|
2005-09-29 17:59:42 -07:00
|
|
|
{}
|
|
|
|
|
|
2004-07-27 14:00:53 -07:00
|
|
|
void CWorld::Initialize(CGameAttributes *pAttribs)
|
|
|
|
|
{
|
2005-02-20 15:55:07 -08:00
|
|
|
// TODO: Find a better way of handling these global things
|
2005-09-21 09:42:56 -07:00
|
|
|
ONCE(RegMemFun(CBaseEntityCollection::GetSingletonPtr(), &CBaseEntityCollection::loadTemplates, L"LoadTemplates", 6));
|
2004-07-31 08:57:18 -07:00
|
|
|
|
2005-02-11 04:57:19 -08:00
|
|
|
// Load the map, if one was specified
|
|
|
|
|
if (pAttribs->m_MapFile.Length())
|
|
|
|
|
{
|
|
|
|
|
CStr mapfilename("maps/scenarios/");
|
|
|
|
|
|
|
|
|
|
mapfilename += (CStr)pAttribs->m_MapFile;
|
|
|
|
|
|
2005-03-22 13:00:56 -08:00
|
|
|
CMapReader* reader = 0;
|
2005-03-30 08:14:19 -08:00
|
|
|
|
2005-02-11 04:57:19 -08:00
|
|
|
try {
|
2005-03-22 13:00:56 -08:00
|
|
|
reader = new CMapReader;
|
|
|
|
|
reader->LoadMap(mapfilename, &m_Terrain, &m_UnitManager, &g_LightEnv);
|
|
|
|
|
// fails immediately, or registers for delay loading
|
2005-10-30 13:30:52 -08:00
|
|
|
} catch (CFileUnpacker::CError) {
|
2005-03-22 13:00:56 -08:00
|
|
|
delete reader;
|
2005-02-11 04:57:19 -08:00
|
|
|
LOG(ERROR, LOG_CATEGORY, "Failed to load map %s", mapfilename.c_str());
|
|
|
|
|
throw PSERROR_Game_World_MapLoadFailed();
|
|
|
|
|
}
|
2004-07-27 14:00:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2004-08-05 06:07:51 -07:00
|
|
|
|
2005-03-21 18:17:55 -08:00
|
|
|
|
|
|
|
|
void CWorld::RegisterInit(CGameAttributes *pAttribs)
|
|
|
|
|
{
|
2005-03-22 13:00:56 -08:00
|
|
|
Initialize(pAttribs);
|
2005-03-21 18:17:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-08-05 06:07:51 -07:00
|
|
|
CWorld::~CWorld()
|
|
|
|
|
{
|
|
|
|
|
// The Entity Manager should perhaps be converted into a CWorld member..
|
|
|
|
|
// But for now, we'll just create and delete the global singleton instance
|
|
|
|
|
// following the creation and deletion of CWorld.
|
|
|
|
|
// The reason for not keeping the instance around is that we require a
|
|
|
|
|
// clean slate for each game start.
|
|
|
|
|
delete &m_EntityManager;
|
2005-05-10 00:13:25 -07:00
|
|
|
delete &m_ProjectileManager;
|
2005-10-08 21:29:58 -07:00
|
|
|
delete &m_LOSManager;
|
2004-08-05 06:07:51 -07:00
|
|
|
}
|
2005-08-14 16:34:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void CWorld::RewriteMap()
|
|
|
|
|
{
|
|
|
|
|
CMapWriter::RewriteAllMaps(&m_Terrain, &m_UnitManager, &g_LightEnv);
|
2005-08-16 12:51:18 -07:00
|
|
|
}
|