diff --git a/source/graphics/Color.cpp b/source/graphics/Color.cpp index 47fbf82e86..bb5efff4a7 100644 --- a/source/graphics/Color.cpp +++ b/source/graphics/Color.cpp @@ -1,8 +1,9 @@ #include "precompiled.h" -#include "maths/MathUtil.h" #include "graphics/Color.h" +#include "maths/MathUtil.h" +#include "graphics/SColor.h" static u32 fallback_ConvertRGBColorTo4ub(const RGBColor& src) { diff --git a/source/graphics/Color.h b/source/graphics/Color.h index 6ad9f69c4f..7eae8ea309 100644 --- a/source/graphics/Color.h +++ b/source/graphics/Color.h @@ -18,26 +18,6 @@ typedef CVector3D RGBColor; typedef CVector4D RGBAColor; -// SColor3ub: structure for packed RGB colors -struct SColor3ub -{ - u8 R; - u8 G; - u8 B; -}; - -// SColor4ub: structure for packed RGBA colors -struct SColor4ub -{ - u8 R; - u8 G; - u8 B; - u8 A; - - SColor4ub() { } - SColor4ub(u8 _r, u8 _g, u8 _b, u8 _a) : R(_r), G(_g), B(_b), A(_a) { } -}; - // exposed as function pointer because it is set at init-time to // one of several implementations depending on CPU caps. extern u32 (*ConvertRGBColorTo4ub)(const RGBColor& src); @@ -46,5 +26,4 @@ extern u32 (*ConvertRGBColorTo4ub)(const RGBColor& src); // possible codepath. extern void ColorActivateFastImpl(); - #endif diff --git a/source/graphics/SColor.h b/source/graphics/SColor.h new file mode 100644 index 0000000000..59db64d8ce --- /dev/null +++ b/source/graphics/SColor.h @@ -0,0 +1,24 @@ +#ifndef SCOLOR_H__ +#define SCOLOR_H__ + +// SColor3ub: structure for packed RGB colors +struct SColor3ub +{ + u8 R; + u8 G; + u8 B; +}; + +// SColor4ub: structure for packed RGBA colors +struct SColor4ub +{ + u8 R; + u8 G; + u8 B; + u8 A; + + SColor4ub() { } + SColor4ub(u8 _r, u8 _g, u8 _b, u8 _a) : R(_r), G(_g), B(_b), A(_a) { } +}; + +#endif diff --git a/source/graphics/Terrain.cpp b/source/graphics/Terrain.cpp index 52af1c285e..9263583aca 100644 --- a/source/graphics/Terrain.cpp +++ b/source/graphics/Terrain.cpp @@ -24,7 +24,9 @@ /////////////////////////////////////////////////////////////////////////////// // CTerrain constructor -CTerrain::CTerrain() : m_Heightmap(0), m_Patches(0), m_MapSize(0), m_MapSizePatches(0) +CTerrain::CTerrain() +: m_Heightmap(0), m_Patches(0), m_MapSize(0), m_MapSizePatches(0), +m_BaseColour(255, 255, 255, 255) { } diff --git a/source/graphics/Terrain.h b/source/graphics/Terrain.h index 722d74602d..3d0c088561 100644 --- a/source/graphics/Terrain.h +++ b/source/graphics/Terrain.h @@ -11,6 +11,7 @@ #define _TERRAIN_H #include "maths/Vector3D.h" +#include "graphics/SColor.h" class CEntity; class CPatch; @@ -111,6 +112,12 @@ public: // mark the entire map as dirty void MakeDirty(int dirtyFlags); + // get the base colour for the terrain (typically pure white - other colours + // will interact badly with LOS - but used by the Actor Viewer tool) + SColor4ub GetBaseColour() const { return m_BaseColour; } + // set the base colour for the terrain + void SetBaseColour(SColor4ub colour) { m_BaseColour = colour; } + private: // delete any data allocated by this terrain void ReleaseData(); @@ -124,7 +131,9 @@ private: // the patches comprising this terrain CPatch* m_Patches; // 16-bit heightmap data - u16* m_Heightmap; + u16* m_Heightmap; + // base colour (usually white) + SColor4ub m_BaseColour; }; #endif diff --git a/source/graphics/TerrainProperties.cpp b/source/graphics/TerrainProperties.cpp index 8843b24cf7..4b03a9ea2d 100644 --- a/source/graphics/TerrainProperties.cpp +++ b/source/graphics/TerrainProperties.cpp @@ -13,8 +13,6 @@ #include "ps/CLogger.h" #define LOG_CATEGORY "graphics" -using namespace std; - CTerrainProperties::CTerrainProperties(CTerrainPropertiesPtr parent): m_pParent(parent), m_BaseColor(0), @@ -131,7 +129,7 @@ void CTerrainProperties::LoadXML(XMBElement node, CXeromyces *pFile) m_Groups.clear(); for (size_t i=0;i CTextureEntry::m_LoadedTextures; +std::map CTextureEntry::m_LoadedTextures; ///////////////////////////////////////////////////////////////////////////////////// // CTextureEntry constructor @@ -51,7 +49,7 @@ CTextureEntry::CTextureEntry(CTerrainPropertiesPtr props, const CStr& path): // CTextureEntry destructor CTextureEntry::~CTextureEntry() { - map::iterator it=m_LoadedTextures.find(m_Handle); + std::map::iterator it=m_LoadedTextures.find(m_Handle); if (it != m_LoadedTextures.end()) m_LoadedTextures.erase(it); @@ -119,7 +117,7 @@ void CTextureEntry::BuildBaseColor() CTextureEntry *CTextureEntry::GetByHandle(Handle handle) { - map::iterator it=m_LoadedTextures.find(handle); + std::map::iterator it=m_LoadedTextures.find(handle); if (it != m_LoadedTextures.end()) return it->second; else diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index ef2123219e..3ad70a4278 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -17,8 +17,6 @@ #define LOG_CATEGORY "graphics" -using namespace std; - CTextureManager::CTextureManager(): m_LastGroupIndex(0) {} @@ -193,7 +191,7 @@ void CTerrainGroup::AddTerrain(CTextureEntry *pTerrain) void CTerrainGroup::RemoveTerrain(CTextureEntry *pTerrain) { - vector::iterator it; + std::vector::iterator it; it=find(m_Terrains.begin(), m_Terrains.end(), pTerrain); if (it != m_Terrains.end()) m_Terrains.erase(it); diff --git a/source/i18n/ScriptInterface.h b/source/i18n/ScriptInterface.h index f019b31126..eeb80f8171 100644 --- a/source/i18n/ScriptInterface.h +++ b/source/i18n/ScriptInterface.h @@ -90,7 +90,7 @@ namespace I18n jsval GetJsval(const std::vector& vars); private: - unsigned char ID; + unsigned char ID; void* GCVal; // something that's being garbage-collected }; } diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 07af3f8847..13ad01c9f0 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -595,35 +595,40 @@ static void InitVfs(const char* argv0) static void InitPs(bool setup_gui) { - // console - { - TIMER("ps_console"); - - g_Console->UpdateScreenSize(g_xres, g_yres); - - // Calculate and store the line spacing - CFont font("console"); - g_Console->m_iFontHeight = font.GetLineSpacing(); - g_Console->m_iFontWidth = font.GetCharacterWidth(L'C'); - g_Console->m_charsPerPage = (size_t)(g_xres / g_Console->m_iFontWidth); - // Offset by an arbitrary amount, to make it fit more nicely - g_Console->m_iFontOffset = 9; - } - - // language and hotkeys - { - TIMER("ps_lang_hotkeys"); - - std::string lang = "english"; - CFG_GET_SYS_VAL("language", String, lang); - I18n::LoadLanguage(lang.c_str()); - - loadHotkeys(); - } - - // GUI uses VFS, so this must come after VFS init. if (setup_gui) + { + // The things here aren't strictly GUI, but they're unnecessary when in Atlas + // because the game doesn't draw any text or handle keys of anything + + { + // console + TIMER("ps_console"); + + g_Console->UpdateScreenSize(g_xres, g_yres); + + // Calculate and store the line spacing + CFont font("console"); + g_Console->m_iFontHeight = font.GetLineSpacing(); + g_Console->m_iFontWidth = font.GetCharacterWidth(L'C'); + g_Console->m_charsPerPage = (size_t)(g_xres / g_Console->m_iFontWidth); + // Offset by an arbitrary amount, to make it fit more nicely + g_Console->m_iFontOffset = 9; + } + + // language and hotkeys + { + TIMER("ps_lang_hotkeys"); + + std::string lang = "english"; + CFG_GET_SYS_VAL("language", String, lang); + I18n::LoadLanguage(lang.c_str()); + + loadHotkeys(); + } + + // GUI uses VFS, so this must come after VFS init. GUI_Init(); + } } diff --git a/source/ps/XML/XeroXMB.cpp b/source/ps/XML/XeroXMB.cpp index 035453b7e5..91c4b05d7a 100644 --- a/source/ps/XML/XeroXMB.cpp +++ b/source/ps/XML/XeroXMB.cpp @@ -246,5 +246,5 @@ XMBAttribute XMBAttributeList::item(const int id) m_LastItemID = id; m_LastPointer = Pos; - return XMBAttribute(*(int*)Pos, utf16string( (const utf16_t*)(Pos+8) )); + return XMBAttribute(*(int*)Pos, utf16string( (const utf16_t*)(Pos+8) )); } diff --git a/source/ps/tests/test_test.h b/source/ps/tests/test_test.h index d443ac8eb0..9c6aaf831b 100644 --- a/source/ps/tests/test_test.h +++ b/source/ps/tests/test_test.h @@ -12,17 +12,17 @@ public: size_t b2 = b1; size_t c2 = c1; - TS_ASSERT_EQUALS(a2, a2); - TS_ASSERT_DIFFERS(a2, b2); - TS_ASSERT_DIFFERS(a2, c2); - - // These shouldn't cause warnings in CxxTest - TS_ASSERT_EQUALS(a1, a1); - TS_ASSERT_EQUALS(a1, a2); - TS_ASSERT_EQUALS(a2, a1); + TS_ASSERT_EQUALS(a2, a2); + TS_ASSERT_DIFFERS(a2, b2); + TS_ASSERT_DIFFERS(a2, c2); - // If TS_AS_STRING gives "{ 00 00 00 00 }", ValueTraits is failing - // to handle these types properly + // These shouldn't cause warnings in CxxTest + TS_ASSERT_EQUALS(a1, a1); + TS_ASSERT_EQUALS(a1, a2); + TS_ASSERT_EQUALS(a2, a1); + + // If TS_AS_STRING gives "{ 00 00 00 00 }", ValueTraits is failing + // to handle these types properly TS_ASSERT_STR_EQUALS(TS_AS_STRING((size_t)0), "0"); TS_ASSERT_STR_EQUALS(TS_AS_STRING((ssize_t)0), "0"); TS_ASSERT_STR_EQUALS(TS_AS_STRING((unsigned int)0), "0"); diff --git a/source/renderer/FixedFunctionModelRenderer.cpp b/source/renderer/FixedFunctionModelRenderer.cpp index 89092dbf60..118d0717ff 100644 --- a/source/renderer/FixedFunctionModelRenderer.cpp +++ b/source/renderer/FixedFunctionModelRenderer.cpp @@ -16,7 +16,7 @@ #include "ps/CLogger.h" -#include "graphics/Color.h" +#include "graphics/SColor.h" #include "graphics/Model.h" #include "graphics/ModelDef.h" diff --git a/source/renderer/ModelRenderer.h b/source/renderer/ModelRenderer.h index 58a00596dc..a30430dfa7 100644 --- a/source/renderer/ModelRenderer.h +++ b/source/renderer/ModelRenderer.h @@ -15,9 +15,9 @@ #include -#include "graphics/Color.h" #include "graphics/MeshManager.h" #include "graphics/RenderableObject.h" +#include "graphics/SColor.h" #include "renderer/VertexArray.h" class RenderModifier; diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index 20d80ab17f..de24ee45f4 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -413,6 +413,7 @@ void CPatchRData::Update() CTerrain* terrain=m_Patch->m_Parent; int mapSize=terrain->GetVerticesPerSide(); int vsize=PATCH_SIZE+1; + SColor4ub baseColour = terrain->GetBaseColour(); if (g_Game) { @@ -427,7 +428,7 @@ void CPatchRData::Update() const int DX[] = {1,1,0,0}; const int DZ[] = {0,1,1,0}; - SColor4ub losMod(255, 255, 255, 255); + SColor4ub losMod = baseColour; for(int k=0; k<4; k++) { @@ -455,7 +456,7 @@ void CPatchRData::Update() for (int i = 0; i < vsize; ++i) { int v = (j*vsize)+i; - m_Vertices[v].m_LOSColor = SColor4ub(255, 255, 255, 255); + m_Vertices[v].m_LOSColor = baseColour; } } diff --git a/source/renderer/PatchRData.h b/source/renderer/PatchRData.h index 867e5c88ab..94b7d81cdd 100644 --- a/source/renderer/PatchRData.h +++ b/source/renderer/PatchRData.h @@ -2,7 +2,7 @@ #define _PATCHRDATA_H #include -#include "graphics/Color.h" +#include "graphics/SColor.h" #include "maths/Vector3D.h" #include "graphics/RenderableObject.h" #include "VertexBufferManager.h" diff --git a/source/renderer/RenderModifiers.cpp b/source/renderer/RenderModifiers.cpp index 5b96e227b0..5ef5221f73 100644 --- a/source/renderer/RenderModifiers.cpp +++ b/source/renderer/RenderModifiers.cpp @@ -18,7 +18,6 @@ #include "ps/CLogger.h" -#include "graphics/Color.h" #include "graphics/LightEnv.h" #include "graphics/Model.h" diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index 7099bc60d8..0283f5e2e9 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -615,14 +615,14 @@ bool CRenderer::GetOptionBool(enum Option opt) const ////////////////////////////////////////////////////////////////////////////////////////// // SetOptionColor: set color renderer option -void CRenderer::SetOptionColor(Option UNUSED(opt),const RGBAColor& UNUSED(value)) -{ -// switch (opt) { -// default: - debug_warn("CRenderer::SetOptionColor: unknown option"); -// break; -// } -} +// void CRenderer::SetOptionColor(Option UNUSED(opt),const RGBAColor& UNUSED(value)) +// { +// // switch (opt) { +// // default: +// debug_warn("CRenderer::SetOptionColor: unknown option"); +// // break; +// // } +// } void CRenderer::SetOptionFloat(enum Option opt, float val) { @@ -639,18 +639,18 @@ void CRenderer::SetOptionFloat(enum Option opt, float val) ////////////////////////////////////////////////////////////////////////////////////////// // GetOptionColor: get color renderer option -const RGBAColor& CRenderer::GetOptionColor(Option UNUSED(opt)) const -{ - static const RGBAColor defaultColor(1.0f,1.0f,1.0f,1.0f); - -// switch (opt) { -// default: - debug_warn("CRenderer::GetOptionColor: unknown option"); -// break; -// } - - return defaultColor; -} +// const RGBAColor& CRenderer::GetOptionColor(Option UNUSED(opt)) const +// { +// static const RGBAColor defaultColor(1.0f,1.0f,1.0f,1.0f); +// +// // switch (opt) { +// // default: +// debug_warn("CRenderer::GetOptionColor: unknown option"); +// // break; +// // } +// +// return defaultColor; +// } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/renderer/Renderer.h b/source/renderer/Renderer.h index 45b49aff12..a5797d9a2a 100644 --- a/source/renderer/Renderer.h +++ b/source/renderer/Renderer.h @@ -13,14 +13,12 @@ #ifndef RENDERER_H #define RENDERER_H -#include -#include "lib/ogl.h" #include "graphics/Camera.h" +#include "lib/ogl.h" +#include "lib/res/handle.h" #include "ps/Singleton.h" - #include "scripting/ScriptableObject.h" -#include "renderer/ModelRenderer.h" #include "renderer/Scene.h" // necessary declarations @@ -34,7 +32,6 @@ class RenderPathVertexShader; class WaterManager; class SkyManager; - // rendering modes enum ERenderMode { WIREFRAME, SOLID, EDGED_FACES }; @@ -162,9 +159,9 @@ public: void SetOptionBool(enum Option opt,bool value); bool GetOptionBool(enum Option opt) const; // set/get RGBA color renderer option - void SetOptionColor(enum Option opt,const RGBAColor& value); +// void SetOptionColor(enum Option opt,const RGBAColor& value); void SetOptionFloat(enum Option opt, float val); - const RGBAColor& GetOptionColor(enum Option opt) const; +// const RGBAColor& GetOptionColor(enum Option opt) const; void SetRenderPath(RenderPath rp); RenderPath GetRenderPath() const { return m_Options.m_RenderPath; } static CStr GetRenderPathName(RenderPath rp); diff --git a/source/renderer/VertexArray.cpp b/source/renderer/VertexArray.cpp index 5ca044bb26..fe45c97ab0 100644 --- a/source/renderer/VertexArray.cpp +++ b/source/renderer/VertexArray.cpp @@ -3,7 +3,7 @@ #include "lib/ogl.h" #include "maths/Vector3D.h" #include "maths/Vector4D.h" -#include "graphics/Color.h" +#include "graphics/SColor.h" #include "renderer/VertexArray.h" #include "renderer/VertexBuffer.h" #include "renderer/VertexBufferManager.h" diff --git a/source/scripting/ScriptingHost.cpp b/source/scripting/ScriptingHost.cpp index ac4e7d5798..be0d5002ad 100644 --- a/source/scripting/ScriptingHost.cpp +++ b/source/scripting/ScriptingHost.cpp @@ -211,19 +211,15 @@ void ScriptingHost::DefineCustomObjectType(JSClass *clasp, JSNative constructor, ps, fs, // Properties, methods static_ps, static_fs); // Constructor properties, methods - if (obj != NULL) - { - CustomType type; - - type.m_Object = obj; - type.m_Class = clasp; - - m_CustomObjectTypes[typeName] = type; - } - else - { + if (obj == NULL) throw PSERROR_Scripting_DefineType_CreationFailed(); - } + + CustomType type; + + type.m_Object = obj; + type.m_Class = clasp; + + m_CustomObjectTypes[typeName] = type; } JSObject * ScriptingHost::CreateCustomObject(const std::string & typeName) diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 68597d4117..e9aeaea938 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -31,10 +31,9 @@ #include "TechnologyCollection.h" #include "TerritoryManager.h" -extern int g_xres, g_yres; - #include -using namespace std; + +extern int g_xres, g_yres; CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW* building ) { @@ -510,13 +509,13 @@ void CEntity::update( size_t timestep ) void CEntity::updateCollisionPatch() { - vector* newPatch = g_EntityManager.getCollisionPatch( this ); + std::vector* newPatch = g_EntityManager.getCollisionPatch( this ); if( newPatch != m_collisionPatch ) { if( m_collisionPatch ) { // remove ourselves from old patch - vector& old = *m_collisionPatch; + std::vector& old = *m_collisionPatch; if( old.size() == 1 ) { // we were the only ones there, just pop us @@ -925,7 +924,7 @@ float CEntity::getAnchorLevel( float x, float z ) } else { - return max( groundLevel, g_Renderer.GetWaterManager()->m_WaterHeight ); + return std::max( groundLevel, g_Renderer.GetWaterManager()->m_WaterHeight ); } } diff --git a/source/simulation/EntityRendering.cpp b/source/simulation/EntityRendering.cpp index e4394bae94..0c098b371c 100644 --- a/source/simulation/EntityRendering.cpp +++ b/source/simulation/EntityRendering.cpp @@ -6,6 +6,7 @@ #include "graphics/Terrain.h" #include "graphics/Unit.h" #include "graphics/UnitManager.h" +#include "lib/res/graphics/ogl_tex.h" #include "maths/MathUtil.h" #include "maths/scripting/JSInterface_Vector3D.h" #include "ps/Game.h" @@ -30,10 +31,9 @@ #include "TechnologyCollection.h" #include "TerritoryManager.h" -extern int g_xres, g_yres; - #include -using namespace std; + +extern int g_xres, g_yres; void CEntity::render() { diff --git a/source/simulation/EntityScriptInterface.cpp b/source/simulation/EntityScriptInterface.cpp index 7d0f07ec20..4bb52edb11 100644 --- a/source/simulation/EntityScriptInterface.cpp +++ b/source/simulation/EntityScriptInterface.cpp @@ -31,10 +31,9 @@ #include "TerritoryManager.h" #include "Stance.h" -extern int g_xres, g_yres; - #include -using namespace std; + +extern int g_xres, g_yres; /* @@ -545,7 +544,7 @@ jsval CEntity::AddAura( JSContext* cx, uintN argc, jsval* argv ) CStrW name = ToPrimitive( argv[0] ); float radius = ToPrimitive( argv[1] ); - size_t tickRate = max( 0, ToPrimitive( argv[2] ) ); // since it's a size_t we don't want it to be negative + size_t tickRate = std::max( 0, ToPrimitive( argv[2] ) ); // since it's a size_t we don't want it to be negative float r = ToPrimitive( argv[3] ); float g = ToPrimitive( argv[4] ); float b = ToPrimitive( argv[5] ); diff --git a/source/simulation/LOSManager.cpp b/source/simulation/LOSManager.cpp index 3397bd8d21..8eaca78510 100644 --- a/source/simulation/LOSManager.cpp +++ b/source/simulation/LOSManager.cpp @@ -14,8 +14,6 @@ #include "lib/allocators.h" #include "lib/timer.h" -using namespace std; - CLOSManager::CLOSManager() : m_LOSSetting(0) { @@ -112,7 +110,7 @@ void CLOSManager::Update() #endif // Set visibility for each entity - vector extant; + std::vector extant; g_Game->GetWorld()->GetEntityManager()->GetExtant(extant); for(size_t i=0; i -using namespace std; - // CProductionItem CProductionItem::CProductionItem( int type, const CStrW& name, float totalTime ) @@ -21,7 +19,7 @@ CProductionItem::~CProductionItem() void CProductionItem::Update( size_t timestep ) { - m_elapsedTime = min( m_totalTime, m_elapsedTime + timestep/1000.0f ); + m_elapsedTime = std::min( m_totalTime, m_elapsedTime + timestep/1000.0f ); } bool CProductionItem::IsComplete() diff --git a/source/simulation/Simulation.cpp b/source/simulation/Simulation.cpp index 9e7d03493a..1c7d20ab30 100644 --- a/source/simulation/Simulation.cpp +++ b/source/simulation/Simulation.cpp @@ -30,8 +30,6 @@ #include "gui/CGUI.h" -using namespace std; - CSimulation::CSimulation(CGame *pGame): m_pGame(pGame), m_pWorld(pGame->GetWorld()), @@ -145,9 +143,9 @@ void CSimulation::Simulate() // Task them all to a point within a radius of the target, radius depends upon // the number of units in the group. -void RandomizeLocations(CEntityOrder order, const vector &entities, bool isQueued) +void RandomizeLocations(CEntityOrder order, const std::vector &entities, bool isQueued) { - vector::const_iterator it; + std::vector::const_iterator it; float radius = 2.0f * sqrt( (float)entities.size() - 1 ); for (it = entities.begin(); it < entities.end(); it++) @@ -185,10 +183,10 @@ void RandomizeLocations(CEntityOrder order, const vector &entities, bo } } -void FormationLocations(CEntityOrder order, const vector &entities, bool isQueued) +void FormationLocations(CEntityOrder order, const std::vector &entities, bool isQueued) { CVector2D upvec(0.0f, 1.0f); - vector::const_iterator it = entities.begin(); + std::vector::const_iterator it = entities.begin(); CEntityFormation* formation = (*it)->GetFormation(); @@ -227,9 +225,9 @@ void FormationLocations(CEntityOrder order, const vector &entities, bo } } -void QueueOrder(CEntityOrder order, const vector &entities, bool isQueued) +void QueueOrder(CEntityOrder order, const std::vector &entities, bool isQueued) { - vector::const_iterator it; + std::vector::const_iterator it; for (it = entities.begin(); it < entities.end(); it++) { @@ -299,10 +297,10 @@ uint CSimulation::TranslateMessage(CNetMessage* pMsg, uint clientMask, void* UNU order.m_type=CEntityOrder::ORDER_LAST; order.m_data[0].location.x=(float)msg->m_TargetX; order.m_data[0].location.y=(float)msg->m_TargetY; - vector::iterator it = msg->m_Entities.begin(); + std::vector::iterator it = msg->m_Entities.begin(); for (;it != msg->m_Entities.end(); ++it) { - deque::const_iterator ord_it; + std::deque::const_iterator ord_it; ord_it=(*it)->m_orderQueue.end() - 1; for (;ord_it >= (*it)->m_orderQueue.begin();--ord_it) { diff --git a/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp b/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp index e9f9433a93..58dfaa210d 100644 --- a/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp +++ b/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.cpp @@ -5,11 +5,15 @@ #include "wx/treectrl.h" #include "General/Datafile.h" + #include "ScenarioEditor/Tools/Common/Tools.h" #include "ScenarioEditor/ScenarioEditor.h" #include "ScenarioEditor/Sections/Environment/LightControl.h" + #include "GameInterface/Messages.h" + #include "CustomControls/Canvas/Canvas.h" +#include "CustomControls/ColourDialog/ColourDialog.h" #include "CustomControls/SnapSplitterWindow/SnapSplitterWindow.h" #include "ActorEditor/ActorEditor.h" @@ -18,6 +22,12 @@ using namespace AtlasMessage; ////////////////////////////////////////////////////////////////////////// +wxWindow* Tooltipped(wxWindow* window, const wxString& tip) +{ + window->SetToolTip(tip); + return window; +} + class ActorCanvas : public Canvas { public: @@ -104,7 +114,10 @@ enum ID_Play, ID_Pause, ID_Slow, - ID_Edit + ID_Edit, + ID_Wireframe, + ID_Background, + ID_Walking }; BEGIN_EVENT_TABLE(ActorViewer, wxFrame) @@ -116,6 +129,9 @@ BEGIN_EVENT_TABLE(ActorViewer, wxFrame) EVT_BUTTON(ID_Pause, ActorViewer::OnSpeedButton) EVT_BUTTON(ID_Slow, ActorViewer::OnSpeedButton) EVT_BUTTON(ID_Edit, ActorViewer::OnEditButton) + EVT_BUTTON(ID_Wireframe, ActorViewer::OnWireframeButton) + EVT_BUTTON(ID_Background, ActorViewer::OnBackgroundButton) + EVT_BUTTON(ID_Walking, ActorViewer::OnWalkingButton) END_EVENT_TABLE() static void SendToGame(const AtlasMessage::sEnvironmentSettings& settings) @@ -125,7 +141,8 @@ static void SendToGame(const AtlasMessage::sEnvironmentSettings& settings) ActorViewer::ActorViewer(wxWindow* parent) : wxFrame(parent, wxID_ANY, _("Actor Viewer"), wxDefaultPosition, wxSize(800, 600)), - m_CurrentSpeed(0.f) + m_CurrentSpeed(0.f), m_Wireframe(false), m_BackgroundColour(wxColour(255, 255, 255)), + m_Walking(true) { SetIcon(wxIcon(_T("ICON_ActorEditor"))); @@ -230,6 +247,7 @@ ActorViewer::ActorViewer(wxWindow* parent) wxSizer* bottomSizer = new wxBoxSizer(wxHORIZONTAL); wxSizer* bottomRightSizer = new wxBoxSizer(wxVERTICAL); wxSizer* playButtonSizer = new wxBoxSizer(wxHORIZONTAL); + wxSizer* optionButtonSizer = new wxGridSizer(2); mainSizer->Add(m_TreeCtrl, wxSizerFlags().Expand().Proportion(1)); mainSizer->Add(bottomSizer, wxSizerFlags().Expand()); @@ -244,7 +262,12 @@ ActorViewer::ActorViewer(wxWindow* parent) bottomRightSizer->Add(m_AnimationBox, wxSizerFlags().Expand()); bottomRightSizer->Add(playButtonSizer, wxSizerFlags().Expand()); - bottomRightSizer->Add(new wxButton(sidePanel, ID_Edit, _("Edit actor")), wxSizerFlags().Expand()); + optionButtonSizer->Add(new wxButton(sidePanel, ID_Edit, _("Edit actor")), wxSizerFlags().Expand()); + optionButtonSizer->Add(Tooltipped(new wxButton(sidePanel, ID_Wireframe, _("Wireframe")), _("Toggle wireframe / solid rendering")), wxSizerFlags().Expand()); + optionButtonSizer->Add(Tooltipped(new wxButton(sidePanel, ID_Background, _("Background")), _("Change the background colour")), wxSizerFlags().Expand()); + optionButtonSizer->Add(Tooltipped(new wxButton(sidePanel, ID_Walking, _("Move")), _("Toggle movement along ground when playing walk/run animations")), wxSizerFlags().Expand()); + + bottomRightSizer->Add(optionButtonSizer, wxSizerFlags().Expand().Border(wxTOP, 4)); sidePanel->SetSizer(mainSizer); @@ -323,3 +346,31 @@ void ActorViewer::OnEditButton(wxCommandEvent& WXUNUSED(event)) boost::bind(std::mem_fun(&ActorViewer::OnActorEdited), this) )); } + +void ActorViewer::OnWireframeButton(wxCommandEvent& WXUNUSED(event)) +{ + m_Wireframe = !m_Wireframe; + POST_MESSAGE(SetViewParamB, (eRenderView::ACTOR, L"wireframe", m_Wireframe)); +} + +void ActorViewer::OnBackgroundButton(wxCommandEvent& WXUNUSED(event)) +{ + ColourDialog dlg (this, _T("Actor Viewer/BackgroundColour"), m_BackgroundColour); + + if (dlg.ShowModal() == wxID_OK) + { + wxColour& c = dlg.GetColourData().GetColour(); + m_BackgroundColour = c; + POST_MESSAGE(SetViewParamC, (eRenderView::ACTOR, L"background", + AtlasMessage::Colour(c.Red(), c.Green(), c.Blue()))); + } +} + +void ActorViewer::OnWalkingButton(wxCommandEvent& WXUNUSED(event)) +{ + wxToolTip::Enable(true); + SetToolTip(L"Hello world!"); + SetHelpText(L"Help text"); + m_Walking = !m_Walking; + POST_MESSAGE(SetViewParamB, (eRenderView::ACTOR, L"walk", m_Walking)); +} diff --git a/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.h b/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.h index 6b68246529..3bc2d206f8 100644 --- a/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.h +++ b/source/tools/atlas/AtlasUI/ActorViewer/ActorViewer.h @@ -17,6 +17,9 @@ private: void OnAnimationSelection(wxCommandEvent& event); void OnSpeedButton(wxCommandEvent& event); void OnEditButton(wxCommandEvent& event); + void OnWireframeButton(wxCommandEvent& event); + void OnBackgroundButton(wxCommandEvent& event); + void OnWalkingButton(wxCommandEvent& event); void OnActorEdited(); ObservableScopedConnections m_ActorConns; @@ -26,6 +29,10 @@ private: wxString m_CurrentActor; float m_CurrentSpeed; + bool m_Wireframe; + wxColour m_BackgroundColour; + bool m_Walking; + Observable m_EnvironmentSettings; ObservableScopedConnection m_EnvConn; diff --git a/source/tools/atlas/AtlasUI/General/Observable.h b/source/tools/atlas/AtlasUI/General/Observable.h index d9d9f39130..70d179706d 100644 --- a/source/tools/atlas/AtlasUI/General/Observable.h +++ b/source/tools/atlas/AtlasUI/General/Observable.h @@ -48,7 +48,7 @@ public: void NotifyObservers() { - m_Signal(*this); + m_Signal(*this); } // Use when an object is changing something that it's also observing, @@ -77,7 +77,7 @@ public: } private: - boost::signal m_Signal; + boost::signal m_Signal; }; class ObservableScopedConnections diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp index 3c630199ad..bc8f57c8d9 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.cpp @@ -202,7 +202,7 @@ protected: private: wxSizer* m_ButtonsSizer; - wxWindow* m_ContentWindow; + wxWindow* m_ContentWindow; SnapSplitterWindow* m_Splitter; std::vector m_Pages; @@ -267,7 +267,7 @@ void SectionLayout::Build() ADD_SIDEBAR(TerrainSidebar, _T("terrain.png"), _("Terrain")); ADD_SIDEBAR(ObjectSidebar, _T("object.png"), _("Object")); ADD_SIDEBAR(EnvironmentSidebar, _T("environment.png"), _("Environment")); - ADD_SIDEBAR(CinematicSidebar, _T("cinematic.png"), _("Cinematics")); + ADD_SIDEBAR(CinematicSidebar, _T("cinematic.png"), _("Cinematics")); #undef ADD_SIDEBAR diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.cpp index 5413f09757..456a5829ff 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/ObjectSettings.cpp @@ -123,7 +123,7 @@ void ObjectSettings::OnSelectionChange(const std::vector m_VariantGroups.push_back(variants); } - std::vector selections = *qry.settings->selections; + std::vector selections = *qry.settings->selections; for (std::vector::iterator sel = selections.begin(); sel != selections.end(); ++sel) diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index 9a3935e5b2..d84844d4dd 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -7,6 +7,8 @@ #include "graphics/Model.h" #include "graphics/ObjectManager.h" #include "graphics/Patch.h" +#include "graphics/SkeletonAnim.h" +#include "graphics/SkeletonAnimDef.h" #include "graphics/Terrain.h" #include "graphics/TextureEntry.h" #include "graphics/TextureManager.h" @@ -24,6 +26,9 @@ struct ActorViewerImpl : public Scene CStrW CurrentUnitID; CStrW CurrentUnitAnim; float CurrentSpeed; + bool WalkEnabled; + + SColor4ub Background; CTerrain Terrain; @@ -41,10 +46,13 @@ ActorViewer::ActorViewer() : m(*new ActorViewerImpl()) { m.Unit = NULL; + m.WalkEnabled = true; + m.Background = SColor4ub(255, 255, 255, 255); // Set up the renderer g_TexMan.LoadTerrainTextures(); g_Renderer.LoadAlphaMaps(); + g_Renderer.GetSkyManager()->m_RenderSky = false; // (TODO: should these be unloaded properly some time? and what should // happen if we want the actor viewer and scenario editor loaded at // the same time?) @@ -133,11 +141,22 @@ void ActorViewer::SetActor(const CStrW& id, const CStrW& animation) m.CurrentUnitAnim = animation; } +void ActorViewer::SetBackgroundColour(const SColor4ub& colour) +{ + m.Background = colour; + m.Terrain.SetBaseColour(colour); +} + +void ActorViewer::SetWalkEnabled(bool enabled) +{ + m.WalkEnabled = enabled; +} + void ActorViewer::Render() { m.Terrain.MakeDirty(RENDERDATA_UPDATE_COLOR); - g_Renderer.SetClearColor(0xFFFFFFFFu); + g_Renderer.SetClearColor(*(u32*)&m.Background); g_Renderer.BeginFrame(); @@ -169,16 +188,31 @@ void ActorViewer::Update(float dt) { m.Unit->GetModel()->Update(dt); - // Move the model by speed*dt forwards CMatrix3D mat = m.Unit->GetModel()->GetTransform(); - float z = mat.GetTranslation().Z; - z -= m.CurrentSpeed*dt; - // Wrap at the edges, so it doesn't run off into the horizon - if (z < CELL_SIZE*PATCH_SIZE * 0.4f) - z = CELL_SIZE*PATCH_SIZE * 0.6f; - mat.Translate(0.f, 0.f, z - mat.GetTranslation().Z); + if (m.WalkEnabled) + { + // Move the model by speed*dt forwards + float z = mat.GetTranslation().Z; + z -= m.CurrentSpeed*dt; + // Wrap at the edges, so it doesn't run off into the horizon + if (z < CELL_SIZE*PATCH_SIZE * 0.4f) + z = CELL_SIZE*PATCH_SIZE * 0.6f; + mat.Translate(0.f, 0.f, z - mat.GetTranslation().Z); + } + m.Unit->GetModel()->SetTransform(mat); m.Unit->GetModel()->ValidatePosition(); } } + +bool ActorViewer::HasAnimation() const +{ + if (m.Unit && + m.Unit->GetModel()->GetAnimation() && + m.Unit->GetModel()->GetAnimation()->m_AnimDef && + m.Unit->GetModel()->GetAnimation()->m_AnimDef->GetNumFrames() > 1) + return true; + + return false; +} diff --git a/source/tools/atlas/GameInterface/ActorViewer.h b/source/tools/atlas/GameInterface/ActorViewer.h index 59bde943a9..c3f4e59d68 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.h +++ b/source/tools/atlas/GameInterface/ActorViewer.h @@ -2,6 +2,7 @@ #define ACTORVIEWER_H__ struct ActorViewerImpl; +struct SColor4ub; class ActorViewer { @@ -10,8 +11,14 @@ public: ~ActorViewer(); void SetActor(const CStrW& id, const CStrW& animation); + void SetWalkEnabled(bool enabled); + void SetBackgroundColour(const SColor4ub& colour); void Render(); void Update(float dt); + + // Returns whether there is a selected actor which has more than one + // frame of animation + bool HasAnimation() const; private: ActorViewerImpl& m; diff --git a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp index 0b87eb6d03..69684845bc 100644 --- a/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/GraphicsSetupHandlers.cpp @@ -74,10 +74,19 @@ QUERYHANDLER(Exit) MESSAGEHANDLER(RenderEnable) { - if (msg->view == eRenderView::NONE) g_GameLoop->view = View::GetView_None(); - else if (msg->view == eRenderView::GAME) g_GameLoop->view = View::GetView_Game(); - else if (msg->view == eRenderView::ACTOR) g_GameLoop->view = View::GetView_Actor(); - else debug_warn("Invalid view type"); + g_GameLoop->view = View::GetView(msg->view); +} + +MESSAGEHANDLER(SetViewParamB) +{ + View* view = View::GetView(msg->view); + view->SetParam(*msg->name, msg->value); +} + +MESSAGEHANDLER(SetViewParamC) +{ + View* view = View::GetView(msg->view); + view->SetParam(*msg->name, msg->value); } MESSAGEHANDLER(SetActorViewer) diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index 01f6388957..f857b38189 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -21,6 +21,19 @@ MESSAGE(RenderEnable, ((int, view)) // eRenderView ); +// SetViewParam: used for hints to the renderer, e.g. to set wireframe mode; +// unrecognised param names are ignored +MESSAGE(SetViewParamB, + ((int, view)) // eRenderView + ((std::wstring, name)) + ((bool, value)) + ); +MESSAGE(SetViewParamC, + ((int, view)) // eRenderView + ((std::wstring, name)) + ((Colour, value)) + ); + ////////////////////////////////////////////////////////////////////////// QUERY(Ping, , ); diff --git a/source/tools/atlas/GameInterface/Shareable.h b/source/tools/atlas/GameInterface/Shareable.h index 1949cc424b..caa6967747 100644 --- a/source/tools/atlas/GameInterface/Shareable.h +++ b/source/tools/atlas/GameInterface/Shareable.h @@ -228,8 +228,8 @@ public: Unalloc(); size = rhs.size; array = static_cast (ShareableMallocFptr( sizeof(element_type)*size )); - for (size_t i = 0; i < size; ++i) - new (&array[i]) element_type (rhs.array[i]); + for (size_t i = 0; i < size; ++i) + new (&array[i]) element_type (rhs.array[i]); return *this; } diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index a16f4901b1..fdd8a79602 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -4,7 +4,10 @@ #include "ActorViewer.h" #include "GameLoop.h" +#include "Messages.h" +#include "graphics/SColor.h" +#include "renderer/Renderer.h" #include "ps/Game.h" #include "ps/GameSetup/GameSetup.h" #include "simulation/EntityManager.h" @@ -16,16 +19,13 @@ extern int g_xres, g_yres; ////////////////////////////////////////////////////////////////////////// -class ViewNone : public View +void View::SetParam(const std::wstring& UNUSED(name), bool UNUSED(value)) { -public: - virtual void Update(float) { } - virtual void Render() { } - virtual CCamera& GetCamera() { return dummyCamera; } - virtual bool WantsHighFramerate() { return false; } -private: - CCamera dummyCamera; -}; +} + +void View::SetParam(const std::wstring& UNUSED(name), const AtlasMessage::Colour& UNUSED(value)) +{ +} ////////////////////////////////////////////////////////////////////////// @@ -63,7 +63,7 @@ CCamera& ViewActor::GetCamera() bool ViewActor::WantsHighFramerate() { - if (m_SpeedMultiplier != 0.f) + if (m_SpeedMultiplier != 0.f && m_ActorViewer->HasAnimation()) return true; return false; @@ -79,6 +79,27 @@ ActorViewer& ViewActor::GetActorViewer() return *m_ActorViewer; } +void ViewActor::SetParam(const std::wstring& name, bool value) +{ + if (name == L"wireframe") + { + g_Renderer.SetModelRenderMode(value ? WIREFRAME : SOLID); + } + else if (name == L"walk") + { + m_ActorViewer->SetWalkEnabled(value); + } +} + +void ViewActor::SetParam(const std::wstring& name, const AtlasMessage::Colour& value) +{ + if (name == L"background") + { + m_ActorViewer->SetBackgroundColour(SColor4ub(value.r, value.g, value.b, 255)); + } +} + + ////////////////////////////////////////////////////////////////////////// namespace AtlasMessage @@ -136,6 +157,18 @@ View::~View() { } +View* View::GetView(int /*eRenderView*/ view) +{ + if (view == AtlasMessage::eRenderView::NONE) return View::GetView_None(); + else if (view == AtlasMessage::eRenderView::GAME) return View::GetView_Game(); + else if (view == AtlasMessage::eRenderView::ACTOR) return View::GetView_Actor(); + else + { + debug_warn("Invalid view type"); + return View::GetView_None(); + } +} + View* View::GetView_None() { if (! view_None) diff --git a/source/tools/atlas/GameInterface/View.h b/source/tools/atlas/GameInterface/View.h index 27c8be808e..82ccd8b005 100644 --- a/source/tools/atlas/GameInterface/View.h +++ b/source/tools/atlas/GameInterface/View.h @@ -12,8 +12,11 @@ public: virtual void Render() = 0; virtual CCamera& GetCamera() = 0; virtual bool WantsHighFramerate() = 0; + virtual void SetParam(const std::wstring& name, bool value); + virtual void SetParam(const std::wstring& name, const AtlasMessage::Colour& value); // These always return a valid (not NULL) object + static View* GetView(int /*eRenderView*/ view); static View* GetView_None(); static ViewGame* GetView_Game(); static ViewActor* GetView_Actor(); @@ -24,7 +27,16 @@ public: ////////////////////////////////////////////////////////////////////////// -class ActorViewer; +class ViewNone : public View +{ +public: + virtual void Update(float) { } + virtual void Render() { } + virtual CCamera& GetCamera() { return dummyCamera; } + virtual bool WantsHighFramerate() { return false; } +private: + CCamera dummyCamera; +}; class ViewGame : public View { @@ -38,6 +50,8 @@ public: private: }; +class ActorViewer; + class ViewActor : public View { public: @@ -48,6 +62,8 @@ public: virtual void Render(); virtual CCamera& GetCamera(); virtual bool WantsHighFramerate(); + virtual void SetParam(const std::wstring& name, bool value); + virtual void SetParam(const std::wstring& name, const AtlasMessage::Colour& value); void SetSpeedMultiplier(float speed); ActorViewer& GetActorViewer(); @@ -58,5 +74,4 @@ private: ActorViewer* m_ActorViewer; }; - #endif // VIEW_H__