Rotated various things (terrain texture UVs, default light and camera angles) by 45 degrees.

Map XML: Store camera position. Stopped using DTDs (because they make it
too hard to change the XML structure without breaking all the old XML
files).
Game.h: Include fewer files, to make compilation sometimes faster.
World: Changed some things to not be singletons, since they were
(ab)used as CWorld members.

This was SVN commit r3670.
This commit is contained in:
Ykkrosh 2006-03-21 20:55:45 +00:00
parent ccc8055226
commit f45c44ca09
38 changed files with 224 additions and 130 deletions

View file

@ -17,6 +17,7 @@
#include "HFTracer.h"
#include "Game.h"
#include "ogl.h"
#include "ps/World.h"
CCamera::CCamera ()
{

View file

@ -48,6 +48,10 @@ static CVector3D cameraBookmarks[10];
static bool bookmarkInUse[10] = { false, false, false, false, false, false, false, false, false, false };
static i8 currentBookmark = -1;
const float CGameView::defaultFOV = DEGTORAD(20.f);
const float CGameView::defaultNear = 1.f;
const float CGameView::defaultFar = 5000.f;
CGameView::CGameView(CGame *pGame):
m_pGame(pGame),
m_pWorld(pGame->GetWorld()),
@ -75,9 +79,9 @@ CGameView::CGameView(CGame *pGame):
vp.m_Height=g_yres;
m_ViewCamera.SetViewPort(&vp);
m_ViewCamera.SetProjection (1, 5000, DEGTORAD(20));
m_ViewCamera.SetProjection (defaultNear, defaultFar, defaultFOV);
m_ViewCamera.m_Orientation.SetXRotation(DEGTORAD(30));
m_ViewCamera.m_Orientation.RotateY(DEGTORAD(-45));
m_ViewCamera.m_Orientation.RotateY(DEGTORAD(0));
m_ViewCamera.m_Orientation.Translate (100, 150, -100);
m_CullCamera = m_ViewCamera;
g_Renderer.SetCamera(m_ViewCamera, m_CullCamera);

View file

@ -25,6 +25,10 @@ class CEntity;
class CGameView: public CJSObject<CGameView>
{
public:
static const float defaultFOV, defaultNear, defaultFar;
private:
CGame *m_pGame;
CWorld *m_pWorld;

View file

@ -17,7 +17,7 @@
CLightEnv::CLightEnv()
: m_Elevation(DEGTORAD(45)),
m_Rotation(DEGTORAD(270)),
m_Rotation(DEGTORAD(315)),
m_TerrainShadowTransparency(0.0),
m_SunColor(1,1,1),
m_TerrainAmbientColor(0.4f,0.4f,0.4f),

View file

@ -11,6 +11,7 @@
#include "EntityManager.h"
#include "CLogger.h"
#include "MathUtil.h"
#include "Camera.h"
#include "Model.h"
#include "Terrain.h"
@ -31,12 +32,14 @@ CMapReader::CMapReader()
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
void CMapReader::LoadMap(const char* filename, CTerrain *pTerrain_, CUnitManager *pUnitMan_, CLightEnv *pLightEnv_)
void CMapReader::LoadMap(const char* filename, CTerrain *pTerrain_, CUnitManager *pUnitMan_,
CLightEnv *pLightEnv_, CCamera *pCamera_)
{
// latch parameters (held until DelayedLoadFinished)
pTerrain = pTerrain_;
pUnitMan = pUnitMan_;
pLightEnv = pLightEnv_;
pCamera = pCamera_;
// [25ms]
unpacker.Read(filename,"PSMP");
@ -267,6 +270,7 @@ private:
void Init(const CStr& xml_filename);
void ReadEnvironment(XMBElement parent);
void ReadCamera(XMBElement parent);
int ReadEntities(XMBElement parent, double end_time);
int ReadNonEntities(XMBElement parent, double end_time);
@ -368,12 +372,57 @@ void CXMLReader::ReadEnvironment(XMBElement parent)
m_MapReader.m_LightEnv.SetTerrainShadowTransparency(CStr(element.getText()).ToFloat());
}
else
debug_warn("Invalid XML data - DTD shouldn't allow this");
debug_warn("Invalid map XML data");
}
m_MapReader.m_LightEnv.CalculateSunDirection();
}
void CXMLReader::ReadCamera(XMBElement parent)
{
#define EL(x) int el_##x = xmb_file.getElementID(#x)
#define AT(x) int at_##x = xmb_file.getAttributeID(#x)
EL(declination);
EL(rotation);
EL(position);
AT(angle);
AT(x); AT(y); AT(z);
#undef AT
#undef EL
float declination = DEGTORAD(30.f), rotation = DEGTORAD(-45.f);
CVector3D translation = CVector3D(100, 150, -100);
XERO_ITER_EL(parent, element)
{
int element_name = element.getNodeName();
XMBAttributeList attrs = element.getAttributes();
if (element_name == el_declination)
{
declination = CStr(attrs.getNamedItem(at_angle)).ToFloat();
}
else if (element_name == el_rotation)
{
rotation = CStr(attrs.getNamedItem(at_angle)).ToFloat();
}
else if (element_name == el_position)
{
translation = CVector3D(
CStr(attrs.getNamedItem(at_x)).ToFloat(),
CStr(attrs.getNamedItem(at_y)).ToFloat(),
CStr(attrs.getNamedItem(at_z)).ToFloat());
}
else
debug_warn("Invalid map XML data");
}
m_MapReader.pCamera->m_Orientation.SetXRotation(declination);
m_MapReader.pCamera->m_Orientation.RotateY(rotation);
m_MapReader.pCamera->m_Orientation.Translate(translation);
m_MapReader.pCamera->UpdateFrustum();
}
int CXMLReader::ReadEntities(XMBElement parent, double end_time)
{
@ -421,7 +470,7 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time)
Orientation = CStr(attrs.getNamedItem(at_angle)).ToFloat();
}
else
debug_warn("Invalid XML data - DTD shouldn't allow this");
debug_warn("Invalid map XML data");
}
CBaseEntity* base = g_EntityTemplateCollection.getTemplate(TemplateName);
@ -492,7 +541,7 @@ int CXMLReader::ReadNonEntities(XMBElement parent, double end_time)
Orientation = CStr(attrs.getNamedItem(at_angle)).ToFloat();
}
else
debug_warn("Invalid XML data - DTD shouldn't allow this");
debug_warn("Invalid map XML data");
}
std::set<CStrW> selections; // TODO: read from file
@ -540,6 +589,10 @@ int CXMLReader::ProgressiveRead()
{
ReadEnvironment(node);
}
else if (name == "camera")
{
ReadCamera(node);
}
else if (name == "entities")
{
ret = ReadEntities(node, end_time);
@ -553,7 +606,7 @@ int CXMLReader::ProgressiveRead()
return ret;
}
else
debug_warn("Invalid XML data - DTD shouldn't allow this");
debug_warn("Invalid map XML data");
node_idx++;
}

View file

@ -11,6 +11,7 @@ class CObjectEntry;
class CTerrain;
class CUnitManager;
class CLightEnv;
class CCamera;
class CXMLReader;
@ -22,7 +23,7 @@ public:
// constructor
CMapReader();
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
void LoadMap(const char* filename, CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv);
void LoadMap(const char* filename, CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera);
private:
// UnpackTerrain: unpack the terrain from the input stream
@ -64,6 +65,7 @@ private:
CTerrain* pTerrain;
CUnitManager* pUnitMan;
CLightEnv* pLightEnv;
CCamera* pCamera;
CStr filename_xml;
// UnpackTerrain generator state

View file

@ -17,6 +17,7 @@
#include "VFSUtil.h"
#include "Loader.h"
#include "MathUtil.h"
#include "graphics/Camera.h"
#include "ps/XML/XMLWriter.h"
#include "simulation/Entity.h"
@ -31,19 +32,19 @@ CMapWriter::CMapWriter()
///////////////////////////////////////////////////////////////////////////////////////////////////
// SaveMap: try to save the current map to the given file
void CMapWriter::SaveMap(const char* filename, CTerrain *pTerrain, CLightEnv *pLightEnv, CUnitManager *pUnitMan)
void CMapWriter::SaveMap(const char* filename, CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera)
{
CFilePacker packer(FILE_VERSION, "PSMP");
// build necessary data
PackMap(packer, pTerrain, pLightEnv, pUnitMan);
PackMap(packer, pTerrain, pUnitMan, pLightEnv);
// write it out
packer.Write(filename);
CStr filename_xml (filename);
filename_xml = filename_xml.Left(filename_xml.Length()-4) + ".xml";
WriteXML(filename_xml, pUnitMan, pLightEnv);
WriteXML(filename_xml, pUnitMan, pLightEnv, pCamera);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -114,7 +115,7 @@ void CMapWriter::EnumTerrainTextures(CTerrain *pTerrain,
///////////////////////////////////////////////////////////////////////////////////////////////////
// PackMap: pack the current world into a raw data stream
void CMapWriter::PackMap(CFilePacker& packer, CTerrain* pTerrain,
CLightEnv* UNUSED(pLightEnv), CUnitManager* UNUSED(pUnitMan))
CUnitManager* UNUSED(pUnitMan), CLightEnv* UNUSED(pLightEnv))
{
// now pack everything up
PackTerrain(packer, pTerrain);
@ -153,7 +154,7 @@ void CMapWriter::PackTerrain(CFilePacker& packer, CTerrain *pTerrain)
void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEnv *pLightEnv)
void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera)
{
Handle h = vfs_open(filename, FILE_WRITE|FILE_NO_AIO);
if (h <= 0)
@ -163,14 +164,6 @@ void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEn
}
XML_Start("utf-8");
// DTDs are rather annoying. They ought to be strict in what they accept,
// else they serve no purpose (given that the only purpose is complaining
// nicely when someone provides invalid input). But then it can't be
// backwards-compatible, because the old data files don't follow the new
// format, and there's no way we're going to rebuild all the old data
// files. So, just create an entirely new DTD for each revision of the
// format:
XML_Doctype("Scenario", "/maps/scenario_v4.dtd");
{
XML_Element("Scenario");
@ -206,6 +199,32 @@ void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEn
}
}
{
XML_Element("Camera");
{
XML_Element("Position");
CVector3D pos = pCamera->m_Orientation.GetTranslation();
XML_Attribute("x", pos.X);
XML_Attribute("y", pos.Y);
XML_Attribute("z", pos.Z);
}
CVector3D in = pCamera->m_Orientation.GetIn();
// Convert to spherical coordinates
float rotation = atan2(in.X, in.Z);
float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - M_PI_2;
{
XML_Element("Rotation");
XML_Attribute("angle", rotation);
}
{
XML_Element("Declination");
XML_Attribute("angle", declination);
}
}
{
XML_Element("Entities");
@ -285,7 +304,7 @@ void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEn
///////////////////////////////////////////////////////////////////////////////////////////////////
// RewriteAllMaps
void CMapWriter::RewriteAllMaps(CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv)
void CMapWriter::RewriteAllMaps(CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera)
{
VFSUtil::FileList files;
VFSUtil::FindFiles("maps/scenarios", "*.pmp", files);
@ -294,13 +313,13 @@ void CMapWriter::RewriteAllMaps(CTerrain *pTerrain, CUnitManager *pUnitMan, CLig
{
CMapReader* reader = new CMapReader;
LDR_BeginRegistering();
reader->LoadMap(*it, pTerrain, pUnitMan, pLightEnv);
reader->LoadMap(*it, pTerrain, pUnitMan, pLightEnv, pCamera);
LDR_EndRegistering();
LDR_NonprogressiveLoad();
CStr n (*it);
n.Replace("scenarios/", "scenarios/new/");
CMapWriter writer;
writer.SaveMap(n, pTerrain, pLightEnv, pUnitMan);
writer.SaveMap(n, pTerrain, pUnitMan, pLightEnv, pCamera);
}
}

View file

@ -9,6 +9,7 @@
class CLightEnv;
class CTerrain;
class CUnitManager;
class CCamera;
class CMapWriter : public CMapIO
{
@ -16,15 +17,15 @@ public:
// constructor
CMapWriter();
// SaveMap: try to save the current map to the given file
void SaveMap(const char* filename, CTerrain *pTerr, CLightEnv *pLightEnv, CUnitManager *pUnitMan);
void SaveMap(const char* filename, CTerrain *pTerr, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera);
// RewriteAllMaps: for use during development: load/save all maps, to
// update them to the newest format.
static void RewriteAllMaps(CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv);
static void RewriteAllMaps(CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera);
private:
// PackMap: pack the current world into a raw data stream
void PackMap(CFilePacker& packer, CTerrain *pTerr, CLightEnv *pLightEnv, CUnitManager *pUnitMan);
void PackMap(CFilePacker& packer, CTerrain *pTerr, CUnitManager *pUnitMan, CLightEnv *pLightEnv);
// PackTerrain: pack the terrain onto the end of the data stream
void PackTerrain(CFilePacker& packer, CTerrain *pTerrain);
@ -34,7 +35,7 @@ private:
std::vector<STileDesc>& tileIndices);
// WriteXML: output some other data (entities, etc) in XML format
void WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEnv *pLightEnv);
void WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera);
};
#endif

View file

@ -8,6 +8,7 @@
#include "MathUtil.h"
#include "Terrain.h"
#include "Game.h"
#include "graphics/GameView.h"
JSClass JSI_Camera::JSI_class = {

View file

@ -30,6 +30,7 @@ that of Atlas depending on commandline parameters.
#include "ps/Globals.h"
#include "ps/Interact.h"
#include "ps/Network/SessionManager.h"
#include "graphics/GameView.h"
#include "simulation/Scheduler.h"
#include "sound/CMusicPlayer.h"
#include "gui/GUI.h"

View file

@ -13,6 +13,10 @@
#include "EntityManager.h"
#include "CConsole.h"
#include "ps/World.h"
#include "simulation/Simulation.h"
#include "graphics/GameView.h"
extern CConsole* g_Console;
CGame *g_Game=NULL;
@ -28,9 +32,9 @@ CGame *g_Game=NULL;
#endif
CGame::CGame():
m_World(this),
m_Simulation(this),
m_GameView(this),
m_World(new CWorld(this)),
m_Simulation(new CSimulation(this)),
m_GameView(new CGameView(this)),
m_pLocalPlayer(NULL),
m_GameStarted(false),
m_Paused(false),
@ -47,6 +51,11 @@ CGame::~CGame()
{
// Again, the in-game call tree is going to be different to the main menu one.
g_Profiler.StructuralReset();
delete m_GameView;
delete m_Simulation;
delete m_World;
debug_printf("CGame::~CGame(): Game object DESTROYED\n");
}
@ -61,9 +70,9 @@ PSRETURN CGame::RegisterInit(CGameAttributes* pAttribs)
// values. At the minute, it's just lighting settings, but could be extended to store camera position.
// Storing lighting settings in the gameview seems a little odd, but it's no big deal; maybe move it at
// some point to be stored in the world object?
m_GameView.RegisterInit(pAttribs);
m_World.RegisterInit(pAttribs);
m_Simulation.RegisterInit(pAttribs);
m_GameView->RegisterInit(pAttribs);
m_World->RegisterInit(pAttribs);
m_Simulation->RegisterInit(pAttribs);
LDR_EndRegistering();
return 0;
@ -134,19 +143,20 @@ void CGame::Update(double deltaTime)
m_Time += deltaTime;
m_Simulation.Update(deltaTime);
m_Simulation->Update(deltaTime);
// TODO Detect game over and bring up the summary screen or something
// ^ Quick game over hack is implemented, no summary screen however
if ( m_World.GetEntityManager()->GetDeath() )
if ( m_World->GetEntityManager()->GetDeath() )
{
UpdateGameStatus();
if (GameStatus != 0)
EndGame();
}
//reset death event flag
m_World.GetEntityManager()->SetDeath(false);
m_World->GetEntityManager()->SetDeath(false);
}
void CGame::UpdateGameStatus()
{
bool EOG_lose = true;
@ -155,7 +165,7 @@ void CGame::UpdateGameStatus()
for (int i=0; i<MAX_HANDLES; i++)
{
CHandle *handle = m_World.GetEntityManager()->getHandle(i);
CHandle *handle = m_World->GetEntityManager()->getHandle(i);
if ( !handle )
continue;
CPlayer *tmpPlayer = handle->m_entity->GetPlayer();

View file

@ -6,24 +6,24 @@
#include "ps/Errors.h"
ERROR_GROUP(Game);
#include "World.h"
#include "Simulation.h"
#include "GameView.h"
#include <vector>
class CWorld;
class CSimulation;
class CGameView;
class CSimulation;
class CPlayer;
class CGameAttributes;
// Default player limit (not counting the Gaia player)
// This may be overriden by system.cfg ("max_players")
// This may be overridden by system.cfg ("max_players")
#define PS_MAX_PLAYERS 6
class CGame
{
CWorld m_World;
CSimulation m_Simulation;
CGameView m_GameView;
CWorld *m_World;
CSimulation *m_Simulation;
CGameView *m_GameView;
CPlayer *m_pLocalPlayer;
std::vector<CPlayer *> m_Players;
@ -86,11 +86,11 @@ public:
}
inline CWorld *GetWorld()
{ return &m_World; }
{ return m_World; }
inline CGameView *GetView()
{ return &m_GameView; }
{ return m_GameView; }
inline CSimulation *GetSimulation()
{ return &m_Simulation; }
{ return m_Simulation; }
inline float GetTime()
{ return m_Time; }

View file

@ -42,6 +42,7 @@
#include "graphics/UnitManager.h"
#include "graphics/MaterialManager.h"
#include "graphics/MeshManager.h"
#include "graphics/GameView.h"
#include "renderer/Renderer.h"
#include "renderer/VertexBufferManager.h"
#include "maths/MathUtil.h"

View file

@ -21,6 +21,7 @@
#include "scripting/GameEvents.h"
#include "UnitManager.h"
#include "MathUtil.h"
#include "graphics/GameView.h"
extern CConsole* g_Console;
extern CStr g_CursorName;

View file

@ -2,16 +2,17 @@
#include "lib.h"
#include <scripting/DOMEvent.h>
#include <scripting/JSConversions.h>
#include <scripting/ScriptableObject.h>
#include <Network/Client.h>
#include <Network/JSEvents.h>
#include <CStr.h>
#include <CLogger.h>
#include <CConsole.h>
#include <Game.h>
#include <GameAttributes.h>
#include "scripting/DOMEvent.h"
#include "scripting/JSConversions.h"
#include "scripting/ScriptableObject.h"
#include "Network/Client.h"
#include "Network/JSEvents.h"
#include "CStr.h"
#include "CLogger.h"
#include "CConsole.h"
#include "Game.h"
#include "GameAttributes.h"
#include "Simulation.h"
#define LOG_CAT_NET "net"

View file

@ -10,6 +10,7 @@
#include "scripting/ScriptableObject.h"
#include "Game.h"
#include "Simulation.h"
#include "Player.h"
#include "CLogger.h"
#include "CConsole.h"

View file

@ -13,6 +13,7 @@
#include "ps/Game.h"
#include "renderer/Renderer.h"
#include "maths/MathUtil.h"
#include "graphics/GameView.h"
static std::string SplitExts(const char *exts)
{
@ -260,7 +261,7 @@ void WriteBigScreenshot(const char* extension, int tiles)
g_Renderer.Resize(tile_w, tile_h);
SViewPort vp = { 0, 0, tile_w, tile_h };
g_Game->GetView()->GetCamera()->SetViewPort(&vp);
g_Game->GetView()->GetCamera()->SetProjection (1, 5000, DEGTORAD(20));
g_Game->GetView()->GetCamera()->SetProjection (CGameView::defaultNear, CGameView::defaultFar, CGameView::defaultFOV);
}
// Temporarily move everything onto the front buffer, so the user can

View file

@ -20,6 +20,7 @@
#include "EntityManager.h"
#include "Projectile.h"
#include "LOSManager.h"
#include "graphics/GameView.h"
#define LOG_CATEGORY "world"
@ -31,10 +32,10 @@ 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()))
m_UnitManager(&g_UnitMan),
m_EntityManager(new CEntityManager()),
m_ProjectileManager(new CProjectileManager()),
m_LOSManager(new CLOSManager())
{}
void CWorld::Initialize(CGameAttributes *pAttribs)
@ -53,7 +54,7 @@ void CWorld::Initialize(CGameAttributes *pAttribs)
try {
reader = new CMapReader;
reader->LoadMap(mapfilename, &m_Terrain, &m_UnitManager, &g_LightEnv);
reader->LoadMap(mapfilename, &m_Terrain, m_UnitManager, &g_LightEnv, m_pGame->GetView()->GetCamera());
// fails immediately, or registers for delay loading
} catch (CFileUnpacker::CError) {
delete reader;
@ -72,18 +73,13 @@ void CWorld::RegisterInit(CGameAttributes *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;
delete &m_LOSManager;
delete m_EntityManager;
delete m_ProjectileManager;
delete m_LOSManager;
}
void CWorld::RewriteMap()
{
CMapWriter::RewriteAllMaps(&m_Terrain, &m_UnitManager, &g_LightEnv);
CMapWriter::RewriteAllMaps(&m_Terrain, m_UnitManager, &g_LightEnv, m_pGame->GetView()->GetCamera());
}

View file

@ -15,13 +15,11 @@ class CWorld
CGame *m_pGame;
CTerrain m_Terrain;
// These all point to the respective g_* globals - the plan is to remove
// the globals and move them into CWorld members as soon as all code has
// been converted
CUnitManager &m_UnitManager;
CEntityManager &m_EntityManager;
CProjectileManager &m_ProjectileManager;
CLOSManager &m_LOSManager;
CUnitManager *m_UnitManager;
CEntityManager *m_EntityManager;
CProjectileManager *m_ProjectileManager;
CLOSManager *m_LOSManager;
public:
CWorld(CGame *pGame);
@ -39,13 +37,13 @@ public:
inline CTerrain *GetTerrain()
{ return &m_Terrain; }
inline CUnitManager *GetUnitManager()
{ return &m_UnitManager; }
{ return m_UnitManager; }
inline CEntityManager *GetEntityManager()
{ return &m_EntityManager; }
{ return m_EntityManager; }
inline CProjectileManager *GetProjectileManager()
{ return &m_ProjectileManager; }
{ return m_ProjectileManager; }
inline CLOSManager *GetLOSManager()
{ return &m_LOSManager; }
{ return m_LOSManager; }
private:
// squelch "unable to generate" warnings

View file

@ -56,20 +56,12 @@ static Handle GetTerrainTileTexture(CTerrain* terrain,int gx,int gz)
return mp ? mp->Tex1 : 0;
}
bool QueryAdjacency(int x,int y,Handle h,Handle* texgrid)
const float uvFactor = 0.125f / sqrt(2.f);
static void CalculateUV(float uv[2], int x, int z)
{
for (int j=y-1;j<=y+1;j++) {
for (int i=x-1;i<=x+1;i++) {
if (i<0 || i>PATCH_SIZE+1 || j<0 || j>PATCH_SIZE+1) {
continue;
}
if (texgrid[j*(PATCH_SIZE+2)+i]==h) {
return true;
}
}
}
return false;
// The UV axes are offset 45 degrees from XZ
uv[0] = ( x-z)*uvFactor;
uv[1] = (-x-z)*uvFactor;
}
struct STmpSplat {
@ -84,10 +76,6 @@ void CPatchRData::BuildBlends()
m_BlendVertices.clear();
m_BlendVertexIndices.clear();
// get index of this patch (unused)
//int px=m_Patch->m_X;
//int pz=m_Patch->m_Z;
CTerrain* terrain=m_Patch->m_Parent;
// temporary list of splats
@ -192,8 +180,7 @@ void CPatchRData::BuildBlends()
int vindex=(int)m_BlendVertices.size();
const SBaseVertex& vtx0=m_Vertices[(j*vsize)+i];
dst.m_UVs[0]=i*0.125f;
dst.m_UVs[1]=j*0.125f;
CalculateUV(dst.m_UVs, gx, gz);
dst.m_AlphaUVs[0]=vtx[0].m_AlphaUVs[0];
dst.m_AlphaUVs[1]=vtx[0].m_AlphaUVs[1];
dst.m_LOSColor=vtx0.m_LOSColor;
@ -202,8 +189,7 @@ void CPatchRData::BuildBlends()
m_BlendVertexIndices.push_back((j*vsize)+i);
const SBaseVertex& vtx1=m_Vertices[(j*vsize)+i+1];
dst.m_UVs[0]=(i+1)*0.125f;
dst.m_UVs[1]=j*0.125f;
CalculateUV(dst.m_UVs, gx+1, gz);
dst.m_AlphaUVs[0]=vtx[1].m_AlphaUVs[0];
dst.m_AlphaUVs[1]=vtx[1].m_AlphaUVs[1];
dst.m_LOSColor=vtx1.m_LOSColor;
@ -212,8 +198,7 @@ void CPatchRData::BuildBlends()
m_BlendVertexIndices.push_back((j*vsize)+i+1);
const SBaseVertex& vtx2=m_Vertices[((j+1)*vsize)+i+1];
dst.m_UVs[0]=(i+1)*0.125f;
dst.m_UVs[1]=(j+1)*0.125f;
CalculateUV(dst.m_UVs, gx+1, gz+1);
dst.m_AlphaUVs[0]=vtx[2].m_AlphaUVs[0];
dst.m_AlphaUVs[1]=vtx[2].m_AlphaUVs[1];
dst.m_LOSColor=vtx2.m_LOSColor;
@ -222,8 +207,7 @@ void CPatchRData::BuildBlends()
m_BlendVertexIndices.push_back(((j+1)*vsize)+i+1);
const SBaseVertex& vtx3=m_Vertices[((j+1)*vsize)+i];
dst.m_UVs[0]=i*0.125f;
dst.m_UVs[1]=(j+1)*0.125f;
CalculateUV(dst.m_UVs, gx, gz+1);
dst.m_AlphaUVs[0]=vtx[3].m_AlphaUVs[0];
dst.m_AlphaUVs[1]=vtx[3].m_AlphaUVs[1];
dst.m_LOSColor=vtx3.m_LOSColor;
@ -380,8 +364,7 @@ void CPatchRData::BuildVertices()
// calculate vertex data
terrain->CalcPosition(ix,iz,vertices[v].m_Position);
*(uint32_t*)&vertices[v].m_LOSColor = 0; // will be set to the proper value in Update()
vertices[v].m_UVs[0]=i*0.125f;
vertices[v].m_UVs[1]=1 - j*0.125f;
CalculateUV(vertices[v].m_UVs, ix, iz);
// Calculate diffuse lighting for this vertex
// Ambient is added by the lighting pass (since ambient is the same
@ -563,8 +546,6 @@ void CPatchRData::RenderOutline()
{
int i;
uint vsize=PATCH_SIZE+1;
u8* base=m_VBBase->m_Owner->Bind(); //TODO: this makes no sense, get rid of it
UNUSED2(base);
glBegin(GL_LINES);
for (i=0;i<PATCH_SIZE;i++) {

View file

@ -15,6 +15,7 @@
#include "graphics/LightEnv.h"
#include "graphics/Patch.h"
#include "graphics/Terrain.h"
#include "graphics/GameView.h"
#include "maths/MathUtil.h"

View file

@ -35,6 +35,8 @@
#include "scripting/JSInterface_Camera.h"
#include "scripting/JSInterface_Console.h"
#include "scripting/JSInterface_VFS.h"
#include "simulation/Simulation.h"
#include "graphics/GameView.h"
#include "graphics/scripting/JSInterface_LightEnv.h"
#include "scripting/JSConversions.h"
#include "renderer/WaterManager.h"

View file

@ -21,6 +21,7 @@
#include "MathUtil.h"
#include "CConsole.h"
#include "renderer/WaterManager.h"
#include "graphics/GameView.h"
extern CConsole* g_Console;
extern int g_xres, g_yres;

View file

@ -23,15 +23,17 @@
#include "EntityHandles.h"
#include "EntityPredicate.h"
#include "EntityMessage.h"
#include "ps/Game.h"
#include "ps/World.h"
#define MAX_HANDLES 4096
// collision patch size, in graphics units, not tiles (1 tile = 4 units)
#define COLLISION_PATCH_SIZE 8
#define g_EntityManager CEntityManager::GetSingleton()
#define g_EntityManager (*(g_Game->GetWorld()->GetEntityManager()))
class CEntityManager : public Singleton<CEntityManager>
class CEntityManager
{
friend class HEntity;
friend class CHandle;

View file

@ -15,7 +15,8 @@
#include "PathfindEngine.h"
#include "Terrain.h"
#include "Game.h"
#include "ps/Game.h"
#include "ps/World.h"
enum EGotoSituation
{

View file

@ -42,7 +42,7 @@ enum EUnitLOSStatus
extern uint LOS_GetTokenFor(uint player_id);
class CLOSManager : public Singleton<CLOSManager>
class CLOSManager
{
#ifdef _2_los
int** m_Explored; // (m_Explored[x][z] & (1<<p) says whether player p has explored tile (x,z),

View file

@ -2,7 +2,8 @@
#include "PathfindSparse.h"
#include "Terrain.h"
#include "Game.h"
#include "ps/Game.h"
#include "ps/World.h"
int SPF_RECURSION_DEPTH = 10;

View file

@ -13,6 +13,8 @@
#include "scripting/ScriptableObject.h"
#include "scripting/DOMEvent.h"
#include "ScriptObject.h"
#include "ps/Game.h"
#include "ps/World.h"
class CProjectileManager;
class CModel;
@ -78,7 +80,7 @@ public:
// Initially this had g_UnitMan managing the models and g_EntityManager holding the
// projectiles themselves. This way may be less confusing - I'm not sure.
class CProjectileManager : public Singleton<CProjectileManager>
class CProjectileManager
{
friend class CProjectile;
public:
@ -102,6 +104,6 @@ private:
std::vector<CProjectile*> m_Projectiles;
};
#define g_ProjectileManager CProjectileManager::GetSingleton()
#define g_ProjectileManager (*(g_Game->GetWorld()->GetProjectileManager()))
#endif

View file

@ -110,11 +110,6 @@ protected:
m_CurrentState->OnEnter(static_cast<T*>(this));
}
State* GetState() const
{
return m_CurrentState;
}
private:
State* m_CurrentState;

View file

@ -3,6 +3,7 @@
#include "Brushes.h"
#include "ps/Game.h"
#include "ps/World.h"
#include "graphics/Terrain.h"
#include "lib/ogl.h"
#include "maths/MathUtil.h"

View file

@ -16,6 +16,7 @@
#include "ps/CLogger.h"
#include "ps/GameSetup/GameSetup.h"
#include "ps/Game.h"
#include "ps/World.h"
#include "simulation/Simulation.h"
#include "simulation/EntityManager.h"

View file

@ -7,6 +7,7 @@
#include "maths/Quaternion.h"
#include "ps/Game.h"
#include "renderer/Renderer.h"
#include "graphics/GameView.h"
#include <assert.h>

View file

@ -6,6 +6,7 @@
#include "graphics/Terrain.h"
#include "ps/Game.h"
#include "ps/World.h"
#include "maths/MathUtil.h"
#include "simulation/EntityManager.h"

View file

@ -5,6 +5,7 @@
#include "../CommandProc.h"
#include "renderer/Renderer.h"
#include "graphics/GameView.h"
#include "gui/GUI.h"
#include "ps/CConsole.h"
#include "ps/Game.h"

View file

@ -7,10 +7,12 @@
#include "graphics/TextureManager.h"
#include "graphics/TextureEntry.h"
#include "graphics/MapWriter.h"
#include "graphics/GameView.h"
#include "ps/Game.h"
#include "ps/GameAttributes.h"
#include "ps/Loader.h"
#include "simulation/LOSManager.h"
#include "simulation/Simulation.h"
namespace AtlasMessage {
@ -103,7 +105,9 @@ MESSAGEHANDLER(LoadMap)
MESSAGEHANDLER(SaveMap)
{
CMapWriter writer;
writer.SaveMap(CStr(L"maps/scenarios/" + msg->filename), g_Game->GetWorld()->GetTerrain(), &g_LightEnv, g_Game->GetWorld()->GetUnitManager());
writer.SaveMap(CStr(L"maps/scenarios/" + msg->filename),
g_Game->GetWorld()->GetTerrain(), g_Game->GetWorld()->GetUnitManager(),
&g_LightEnv, g_Game->GetView()->GetCamera());
}
}

View file

@ -15,6 +15,8 @@
#include "maths/MathUtil.h"
#include "ps/CLogger.h"
#include "ps/Game.h"
#include "ps/World.h"
#include "graphics/GameView.h"
#include "lib/ogl.h"
#define LOG_CATEGORY "editor"

View file

@ -4,6 +4,7 @@
#include "ps/Game.h"
#include "graphics/Camera.h"
#include "graphics/GameView.h"
static float g_ViewZoomSmoothness = 0.02f; // TODO: configurable, like GameView

View file

@ -4,8 +4,9 @@
#include "Messages.h"
#include "Vector3D.h"
#include "Game.h"
#include "maths/Vector3D.h"
#include "ps/Game.h"
#include "graphics/GameView.h"
void AtlasMessage::Position::GetWorldSpace(CVector3D& vec) const
{