1
0
forked from 0ad/0ad

Actor Viewer: Added controls for wireframe, background colour, move-when-walking. Reduced CPU usage when 'playing' things with no animation.

Color: Moved SColor* structs into SColor.h, so they can be used without
indirectly including CVector[34]D.
Terrain: Added 'base colour', for the Actor Viewer to be able to
modulate the colour of normally-white terrain.
Removed some "using namespace std" (because it doesn't make the code
easier to read, and it defeats the point of namespaces, and the rest of
the code doesn't do it).

This was SVN commit r4392.
This commit is contained in:
Ykkrosh 2006-09-26 01:44:20 +00:00
parent 39c7143a1d
commit 2f53eea71a
39 changed files with 351 additions and 183 deletions

View File

@ -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)
{

View File

@ -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

24
source/graphics/SColor.h Normal file
View File

@ -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

View File

@ -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)
{
}

View File

@ -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

View File

@ -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<parserLine.GetArgCount();i++)
{
string value;
std::string value;
if (!parserLine.GetArgString(i, value))
continue;
CTerrainGroup *pType = g_TexMan.FindGroup(value);

View File

@ -15,9 +15,7 @@
#define LOG_CATEGORY "graphics"
using namespace std;
map<Handle, CTextureEntry *> CTextureEntry::m_LoadedTextures;
std::map<Handle, CTextureEntry *> CTextureEntry::m_LoadedTextures;
/////////////////////////////////////////////////////////////////////////////////////
// CTextureEntry constructor
@ -51,7 +49,7 @@ CTextureEntry::CTextureEntry(CTerrainPropertiesPtr props, const CStr& path):
// CTextureEntry destructor
CTextureEntry::~CTextureEntry()
{
map<Handle,CTextureEntry *>::iterator it=m_LoadedTextures.find(m_Handle);
std::map<Handle,CTextureEntry *>::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<Handle, CTextureEntry *>::iterator it=m_LoadedTextures.find(handle);
std::map<Handle, CTextureEntry *>::iterator it=m_LoadedTextures.find(handle);
if (it != m_LoadedTextures.end())
return it->second;
else

View File

@ -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<CTextureEntry *>::iterator it;
std::vector<CTextureEntry *>::iterator it;
it=find(m_Terrains.begin(), m_Terrains.end(), pTerrain);
if (it != m_Terrains.end())
m_Terrains.erase(it);

View File

@ -90,7 +90,7 @@ namespace I18n
jsval GetJsval(const std::vector<BufferVariable*>& vars);
private:
unsigned char ID;
unsigned char ID;
void* GCVal; // something that's being garbage-collected
};
}

View File

@ -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();
}
}

View File

@ -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) ));
}

View File

@ -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");

View File

@ -16,7 +16,7 @@
#include "ps/CLogger.h"
#include "graphics/Color.h"
#include "graphics/SColor.h"
#include "graphics/Model.h"
#include "graphics/ModelDef.h"

View File

@ -15,9 +15,9 @@
#include <boost/shared_ptr.hpp>
#include "graphics/Color.h"
#include "graphics/MeshManager.h"
#include "graphics/RenderableObject.h"
#include "graphics/SColor.h"
#include "renderer/VertexArray.h"
class RenderModifier;

View File

@ -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;
}
}

View File

@ -2,7 +2,7 @@
#define _PATCHRDATA_H
#include <vector>
#include "graphics/Color.h"
#include "graphics/SColor.h"
#include "maths/Vector3D.h"
#include "graphics/RenderableObject.h"
#include "VertexBufferManager.h"

View File

@ -18,7 +18,6 @@
#include "ps/CLogger.h"
#include "graphics/Color.h"
#include "graphics/LightEnv.h"
#include "graphics/Model.h"

View File

@ -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;
// }
//////////////////////////////////////////////////////////////////////////////////////////

View File

@ -13,14 +13,12 @@
#ifndef RENDERER_H
#define RENDERER_H
#include <vector>
#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);

View File

@ -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"

View File

@ -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)

View File

@ -31,10 +31,9 @@
#include "TechnologyCollection.h"
#include "TerritoryManager.h"
extern int g_xres, g_yres;
#include <algorithm>
using namespace std;
extern int g_xres, g_yres;
CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set<CStr8>& actorSelections, const CStrW* building )
{
@ -510,13 +509,13 @@ void CEntity::update( size_t timestep )
void CEntity::updateCollisionPatch()
{
vector<CEntity*>* newPatch = g_EntityManager.getCollisionPatch( this );
std::vector<CEntity*>* newPatch = g_EntityManager.getCollisionPatch( this );
if( newPatch != m_collisionPatch )
{
if( m_collisionPatch )
{
// remove ourselves from old patch
vector<CEntity*>& old = *m_collisionPatch;
std::vector<CEntity*>& 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 );
}
}

View File

@ -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 <algorithm>
using namespace std;
extern int g_xres, g_yres;
void CEntity::render()
{

View File

@ -31,10 +31,9 @@
#include "TerritoryManager.h"
#include "Stance.h"
extern int g_xres, g_yres;
#include <algorithm>
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<CStrW>( argv[0] );
float radius = ToPrimitive<float>( argv[1] );
size_t tickRate = max( 0, ToPrimitive<int>( argv[2] ) ); // since it's a size_t we don't want it to be negative
size_t tickRate = std::max( 0, ToPrimitive<int>( argv[2] ) ); // since it's a size_t we don't want it to be negative
float r = ToPrimitive<float>( argv[3] );
float g = ToPrimitive<float>( argv[4] );
float b = ToPrimitive<float>( argv[5] );

View File

@ -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<CEntity*> extant;
std::vector<CEntity*> extant;
g_Game->GetWorld()->GetEntityManager()->GetExtant(extant);
for(size_t i=0; i<extant.size(); i++)
{

View File

@ -5,8 +5,6 @@
#include "Entity.h"
#include <algorithm>
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()

View File

@ -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 <HEntity> &entities, bool isQueued)
void RandomizeLocations(CEntityOrder order, const std::vector<HEntity> &entities, bool isQueued)
{
vector<HEntity>::const_iterator it;
std::vector<HEntity>::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 <HEntity> &entities, bo
}
}
void FormationLocations(CEntityOrder order, const vector <HEntity> &entities, bool isQueued)
void FormationLocations(CEntityOrder order, const std::vector<HEntity> &entities, bool isQueued)
{
CVector2D upvec(0.0f, 1.0f);
vector<HEntity>::const_iterator it = entities.begin();
std::vector<HEntity>::const_iterator it = entities.begin();
CEntityFormation* formation = (*it)->GetFormation();
@ -227,9 +225,9 @@ void FormationLocations(CEntityOrder order, const vector <HEntity> &entities, bo
}
}
void QueueOrder(CEntityOrder order, const vector <HEntity> &entities, bool isQueued)
void QueueOrder(CEntityOrder order, const std::vector<HEntity> &entities, bool isQueued)
{
vector<HEntity>::const_iterator it;
std::vector<HEntity>::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<HEntity>::iterator it = msg->m_Entities.begin();
std::vector<HEntity>::iterator it = msg->m_Entities.begin();
for (;it != msg->m_Entities.end(); ++it)
{
deque<CEntityOrder>::const_iterator ord_it;
std::deque<CEntityOrder>::const_iterator ord_it;
ord_it=(*it)->m_orderQueue.end() - 1;
for (;ord_it >= (*it)->m_orderQueue.begin();--ord_it)
{

View File

@ -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));
}

View File

@ -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<AtlasMessage::sEnvironmentSettings> m_EnvironmentSettings;
ObservableScopedConnection m_EnvConn;

View File

@ -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<void (const T&)> m_Signal;
boost::signal<void (const T&)> m_Signal;
};
class ObservableScopedConnections

View File

@ -202,7 +202,7 @@ protected:
private:
wxSizer* m_ButtonsSizer;
wxWindow* m_ContentWindow;
wxWindow* m_ContentWindow;
SnapSplitterWindow* m_Splitter;
std::vector<SidebarPage> 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

View File

@ -123,7 +123,7 @@ void ObjectSettings::OnSelectionChange(const std::vector<AtlasMessage::ObjectID>
m_VariantGroups.push_back(variants);
}
std::vector<std::wstring> selections = *qry.settings->selections;
std::vector<std::wstring> selections = *qry.settings->selections;
for (std::vector<std::wstring>::iterator sel = selections.begin();
sel != selections.end();
++sel)

View File

@ -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;
}

View File

@ -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;

View File

@ -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)

View File

@ -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, , );

View File

@ -228,8 +228,8 @@ public:
Unalloc();
size = rhs.size;
array = static_cast<element_type*> (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;
}

View File

@ -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)

View File

@ -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__