From f45c44ca09f6c74e51dbfa462328ea670d0c81a6 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Tue, 21 Mar 2006 20:55:45 +0000 Subject: [PATCH] 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. --- source/graphics/Camera.cpp | 1 + source/graphics/GameView.cpp | 8 ++- source/graphics/GameView.h | 4 ++ source/graphics/LightEnv.cpp | 2 +- source/graphics/MapReader.cpp | 63 +++++++++++++++++-- source/graphics/MapReader.h | 4 +- source/graphics/MapWriter.cpp | 51 ++++++++++----- source/graphics/MapWriter.h | 9 +-- .../graphics/scripting/JSInterface_Camera.cpp | 1 + source/main.cpp | 1 + source/ps/Game.cpp | 30 ++++++--- source/ps/Game.h | 22 +++---- source/ps/GameSetup/GameSetup.cpp | 1 + source/ps/Interact.cpp | 1 + source/ps/Network/Client.cpp | 21 ++++--- source/ps/Network/Server.cpp | 1 + source/ps/Util.cpp | 3 +- source/ps/World.cpp | 24 +++---- source/ps/World.h | 20 +++--- source/renderer/PatchRData.cpp | 39 +++--------- source/renderer/TerrainRenderer.cpp | 1 + source/scripting/ScriptGlue.cpp | 2 + source/simulation/Entity.cpp | 1 + source/simulation/EntityManager.h | 6 +- source/simulation/EntityStateProcessing.cpp | 3 +- source/simulation/LOSManager.h | 2 +- source/simulation/PathfindSparse.cpp | 3 +- source/simulation/Projectile.h | 6 +- .../ScenarioEditor/Tools/Common/Tools.h | 5 -- source/tools/atlas/GameInterface/Brushes.cpp | 1 + source/tools/atlas/GameInterface/GameLoop.cpp | 1 + .../GameInterface/Handlers/CameraCtrl.cpp | 1 + .../GameInterface/Handlers/Elevation.cpp | 1 + .../GameInterface/Handlers/GraphicsSetup.cpp | 1 + .../atlas/GameInterface/Handlers/Map.cpp | 6 +- .../GameInterface/Handlers/ObjectHandlers.cpp | 2 + .../atlas/GameInterface/InputProcessor.cpp | 1 + source/tools/atlas/GameInterface/Misc.cpp | 5 +- 38 files changed, 224 insertions(+), 130 deletions(-) diff --git a/source/graphics/Camera.cpp b/source/graphics/Camera.cpp index 6efa071dd0..9fa5dfade1 100755 --- a/source/graphics/Camera.cpp +++ b/source/graphics/Camera.cpp @@ -17,6 +17,7 @@ #include "HFTracer.h" #include "Game.h" #include "ogl.h" +#include "ps/World.h" CCamera::CCamera () { diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index f54e05f3bd..66e70820ab 100755 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -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); diff --git a/source/graphics/GameView.h b/source/graphics/GameView.h index b359c929af..33d97015dd 100755 --- a/source/graphics/GameView.h +++ b/source/graphics/GameView.h @@ -25,6 +25,10 @@ class CEntity; class CGameView: public CJSObject { +public: + static const float defaultFOV, defaultNear, defaultFar; + +private: CGame *m_pGame; CWorld *m_pWorld; diff --git a/source/graphics/LightEnv.cpp b/source/graphics/LightEnv.cpp index 1d24e4e3a7..5f822ac02f 100644 --- a/source/graphics/LightEnv.cpp +++ b/source/graphics/LightEnv.cpp @@ -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), diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 3a9ebf7fb9..c04e1fc3d3 100755 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -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 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++; } diff --git a/source/graphics/MapReader.h b/source/graphics/MapReader.h index 8b76d4a28b..ef4e4d52f4 100755 --- a/source/graphics/MapReader.h +++ b/source/graphics/MapReader.h @@ -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 diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index ed1c481003..22dc1c49ba 100755 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -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); } } diff --git a/source/graphics/MapWriter.h b/source/graphics/MapWriter.h index 06b8b054ee..de032bb883 100755 --- a/source/graphics/MapWriter.h +++ b/source/graphics/MapWriter.h @@ -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& 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 diff --git a/source/graphics/scripting/JSInterface_Camera.cpp b/source/graphics/scripting/JSInterface_Camera.cpp index 3b67574b66..7961937938 100755 --- a/source/graphics/scripting/JSInterface_Camera.cpp +++ b/source/graphics/scripting/JSInterface_Camera.cpp @@ -8,6 +8,7 @@ #include "MathUtil.h" #include "Terrain.h" #include "Game.h" +#include "graphics/GameView.h" JSClass JSI_Camera::JSI_class = { diff --git a/source/main.cpp b/source/main.cpp index b737c29f28..3669ea4958 100755 --- a/source/main.cpp +++ b/source/main.cpp @@ -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" diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index 28830c1a7b..4bd767148c 100755 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -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; igetHandle(i); + CHandle *handle = m_World->GetEntityManager()->getHandle(i); if ( !handle ) continue; CPlayer *tmpPlayer = handle->m_entity->GetPlayer(); diff --git a/source/ps/Game.h b/source/ps/Game.h index afb5e55e46..f0d2a9bcdf 100755 --- a/source/ps/Game.h +++ b/source/ps/Game.h @@ -6,24 +6,24 @@ #include "ps/Errors.h" ERROR_GROUP(Game); -#include "World.h" -#include "Simulation.h" -#include "GameView.h" - #include +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 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; } diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index a8260423a6..c7a17e3cb3 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -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" diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index a42bed5b97..423ae3f623 100755 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -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; diff --git a/source/ps/Network/Client.cpp b/source/ps/Network/Client.cpp index 57bf676d47..0cce18cc38 100755 --- a/source/ps/Network/Client.cpp +++ b/source/ps/Network/Client.cpp @@ -2,16 +2,17 @@ #include "lib.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#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" diff --git a/source/ps/Network/Server.cpp b/source/ps/Network/Server.cpp index 40a5e926cf..e19f11e150 100755 --- a/source/ps/Network/Server.cpp +++ b/source/ps/Network/Server.cpp @@ -10,6 +10,7 @@ #include "scripting/ScriptableObject.h" #include "Game.h" +#include "Simulation.h" #include "Player.h" #include "CLogger.h" #include "CConsole.h" diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp index 9d00035509..bfc87c2927 100644 --- a/source/ps/Util.cpp +++ b/source/ps/Util.cpp @@ -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 diff --git a/source/ps/World.cpp b/source/ps/World.cpp index 5b5d1d4f44..defdb633fb 100755 --- a/source/ps/World.cpp +++ b/source/ps/World.cpp @@ -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()); } diff --git a/source/ps/World.h b/source/ps/World.h index 6088d776bd..e1d3985051 100755 --- a/source/ps/World.h +++ b/source/ps/World.h @@ -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 diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index 32b2f789b9..74036403af 100755 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -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;iGetWorld()->GetEntityManager())) -class CEntityManager : public Singleton +class CEntityManager { friend class HEntity; friend class CHandle; diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 1a3d7c30d2..0754e7494b 100755 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -15,7 +15,8 @@ #include "PathfindEngine.h" #include "Terrain.h" -#include "Game.h" +#include "ps/Game.h" +#include "ps/World.h" enum EGotoSituation { diff --git a/source/simulation/LOSManager.h b/source/simulation/LOSManager.h index 0b5ab24731..f2163220c9 100644 --- a/source/simulation/LOSManager.h +++ b/source/simulation/LOSManager.h @@ -42,7 +42,7 @@ enum EUnitLOSStatus extern uint LOS_GetTokenFor(uint player_id); -class CLOSManager : public Singleton +class CLOSManager { #ifdef _2_los int** m_Explored; // (m_Explored[x][z] & (1< +class CProjectileManager { friend class CProjectile; public: @@ -102,6 +104,6 @@ private: std::vector m_Projectiles; }; -#define g_ProjectileManager CProjectileManager::GetSingleton() +#define g_ProjectileManager (*(g_Game->GetWorld()->GetProjectileManager())) #endif diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h index 01f6e6a248..afc877337c 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h @@ -110,11 +110,6 @@ protected: m_CurrentState->OnEnter(static_cast(this)); } - State* GetState() const - { - return m_CurrentState; - } - private: State* m_CurrentState; diff --git a/source/tools/atlas/GameInterface/Brushes.cpp b/source/tools/atlas/GameInterface/Brushes.cpp index 735bc9bb5b..70b743cf55 100644 --- a/source/tools/atlas/GameInterface/Brushes.cpp +++ b/source/tools/atlas/GameInterface/Brushes.cpp @@ -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" diff --git a/source/tools/atlas/GameInterface/GameLoop.cpp b/source/tools/atlas/GameInterface/GameLoop.cpp index 977a936ad3..145c1e2918 100644 --- a/source/tools/atlas/GameInterface/GameLoop.cpp +++ b/source/tools/atlas/GameInterface/GameLoop.cpp @@ -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" diff --git a/source/tools/atlas/GameInterface/Handlers/CameraCtrl.cpp b/source/tools/atlas/GameInterface/Handlers/CameraCtrl.cpp index 6ee1ce8e27..e81cd97aa1 100644 --- a/source/tools/atlas/GameInterface/Handlers/CameraCtrl.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CameraCtrl.cpp @@ -7,6 +7,7 @@ #include "maths/Quaternion.h" #include "ps/Game.h" #include "renderer/Renderer.h" +#include "graphics/GameView.h" #include diff --git a/source/tools/atlas/GameInterface/Handlers/Elevation.cpp b/source/tools/atlas/GameInterface/Handlers/Elevation.cpp index 76f4876a77..a050234695 100644 --- a/source/tools/atlas/GameInterface/Handlers/Elevation.cpp +++ b/source/tools/atlas/GameInterface/Handlers/Elevation.cpp @@ -6,6 +6,7 @@ #include "graphics/Terrain.h" #include "ps/Game.h" +#include "ps/World.h" #include "maths/MathUtil.h" #include "simulation/EntityManager.h" diff --git a/source/tools/atlas/GameInterface/Handlers/GraphicsSetup.cpp b/source/tools/atlas/GameInterface/Handlers/GraphicsSetup.cpp index 1b848a72f3..453b9565f3 100644 --- a/source/tools/atlas/GameInterface/Handlers/GraphicsSetup.cpp +++ b/source/tools/atlas/GameInterface/Handlers/GraphicsSetup.cpp @@ -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" diff --git a/source/tools/atlas/GameInterface/Handlers/Map.cpp b/source/tools/atlas/GameInterface/Handlers/Map.cpp index 2371240f49..d92b56e7a5 100644 --- a/source/tools/atlas/GameInterface/Handlers/Map.cpp +++ b/source/tools/atlas/GameInterface/Handlers/Map.cpp @@ -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()); } } diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index 6fba9788f9..e55f7286c4 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -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" diff --git a/source/tools/atlas/GameInterface/InputProcessor.cpp b/source/tools/atlas/GameInterface/InputProcessor.cpp index a6a856d2db..4d183b9c9b 100644 --- a/source/tools/atlas/GameInterface/InputProcessor.cpp +++ b/source/tools/atlas/GameInterface/InputProcessor.cpp @@ -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 diff --git a/source/tools/atlas/GameInterface/Misc.cpp b/source/tools/atlas/GameInterface/Misc.cpp index 2831a5450a..4486cb9606 100644 --- a/source/tools/atlas/GameInterface/Misc.cpp +++ b/source/tools/atlas/GameInterface/Misc.cpp @@ -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 {