1
0
forked from 0ad/0ad
0ad/source/ps/World.cpp
Matei 0ed2815c8b Added initial version of LOS, and updated minimap to show both LOS and water.
LOS issues still outstanding:
- LOS looks ugly because of quad tesselation into 2 triangles
- Quad tesselation is unspecified by OpenGL (in fact using GL_QUADS on
LOS quads seemed to give different tesselations than it did for the
underlying terrain quads, but terrain rendering also used GL_QUADS).
This should be fixed once we decide on the quad tesselation issue.
- Units with traits.vision.permanent set are visible through FOW even if
you havent seen them before; this should only be true when you have seen
them before. But it gets even more complicated - if a permanent unit
seen through FOW dies or gets upgraded or something, perhaps you should
remember the old version. I'm not completely sure how to do this
(probably involves cloning its actor somehow).

This was SVN commit r2876.
2005-10-09 03:43:03 +00:00

89 lines
2.2 KiB
C++
Executable File

#include "precompiled.h"
#include "CStr.h"
#include "CLogger.h"
#include "ps/Errors.h"
#include "World.h"
#include "MapReader.h"
#include "Game.h"
#include "GameAttributes.h"
#include "Terrain.h"
#include "LightEnv.h"
#include "BaseEntityCollection.h"
#include "EntityManager.h"
#include "timer.h"
#include "Loader.h"
#include "LoaderThunks.h"
#include "graphics/MapWriter.h"
#include "UnitManager.h"
#include "EntityManager.h"
#include "Projectile.h"
#include "LOSManager.h"
#define LOG_CATEGORY "world"
// global light settings. this is not a member of CWorld because it is
// passed to the renderer before CWorld exists.
CLightEnv g_LightEnv;
CWorld::CWorld(CGame *pGame):
m_pGame(pGame),
m_Terrain(),
m_UnitManager(g_UnitMan),
m_EntityManager(*(new CEntityManager())),
m_ProjectileManager(*(new CProjectileManager())),
m_LOSManager(*(new CLOSManager()))
{}
void CWorld::Initialize(CGameAttributes *pAttribs)
{
// TODO: Find a better way of handling these global things
ONCE(RegMemFun(CBaseEntityCollection::GetSingletonPtr(), &CBaseEntityCollection::loadTemplates, L"LoadTemplates", 6));
// Load the map, if one was specified
if (pAttribs->m_MapFile.Length())
{
CStr mapfilename("maps/scenarios/");
mapfilename += (CStr)pAttribs->m_MapFile;
CMapReader* reader = 0;
try {
reader = new CMapReader;
reader->LoadMap(mapfilename, &m_Terrain, &m_UnitManager, &g_LightEnv);
// fails immediately, or registers for delay loading
} catch (...) {
delete reader;
LOG(ERROR, LOG_CATEGORY, "Failed to load map %s", mapfilename.c_str());
throw PSERROR_Game_World_MapLoadFailed();
}
}
}
void CWorld::RegisterInit(CGameAttributes *pAttribs)
{
Initialize(pAttribs);
}
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;
delete &m_ProjectileManager;
}
void CWorld::RewriteMap()
{
CMapWriter::RewriteAllMaps(&m_Terrain, &m_UnitManager, &g_LightEnv);
}