1
1
forked from 0ad/0ad

Small changes to ScEd, to remove some hacky bits and to make it not crash with player-colours

This was SVN commit r1899.
This commit is contained in:
Ykkrosh 2005-02-04 23:16:42 +00:00
parent 4ddc8b1c1d
commit 880634b598
24 changed files with 141 additions and 173 deletions

View File

@ -289,11 +289,7 @@ void CMapReader::ReadXML(const char* filename)
HEntity ent = g_EntityManager.create(g_EntityTemplateCollection.getTemplate(TemplateName), Position, Orientation);
#ifdef SCED // HACK: ScEd doesn't have a g_Game, so we can't use its CPlayers
ent->SetPlayer( (CPlayer*)(intptr_t)PlayerID );
#else
ent->SetPlayer( g_Game->GetPlayer( PlayerID ) );
#endif
ent->SetPlayer(g_Game->GetPlayer(PlayerID));
}
}
else

View File

@ -279,11 +279,7 @@ void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan)
XML_Setting("Template", entity->m_base->m_Tag);
#ifdef SCED // HACK: ScEd doesn't have a g_Game, so we can't use its CPlayers
XML_Setting( "Player", (int)(intptr_t)entity->GetPlayer() );
#else
XML_Setting( "Player", entity->GetPlayer() );
#endif
XML_Setting("Player", entity->GetPlayer());
{
CVector3D position = entity->m_position;

View File

@ -71,7 +71,11 @@
#endif
#if defined(_MSC_VER) && defined(HAVE_PCH) && !( defined(NDEBUG) || defined(TESTING) )
// # define HAVE_DEBUGALLOC
# ifdef SCED
# define HAVE_DEBUGALLOC
# else
//# define HAVE_DEBUGALLOC // <-- enable this if you want to use it instead of mmgr
# endif
#endif
#ifdef OS_UNIX

View File

@ -991,7 +991,7 @@ static void Init(int argc, char* argv[], bool setup_gfx = true)
MICROLOG(L"In init");
// If you ever want to catch a particular allocation:
//_CrtSetBreakAlloc(14246);
//_CrtSetBreakAlloc(187);
#ifdef _MSC_VER
u64 TSC=rdtsc();
@ -1023,7 +1023,7 @@ PREVTSC=TSC;
// and will mess up the error reporting if anything
// crashes before the working directory is set.
MICROLOG(L"init vfs");
InitVfs(argv[0]);
InitVfs(argc?argv[0]:NULL);
// Set up the console early, so that debugging
// messages can be logged to it. (The console's size

View File

@ -1,9 +1,9 @@
#include "precompiled.h"
#include "nommgr.h"
#include "XML.h"
#include "nommgr.h"
#include "CStr.h"
#include "CLogger.h"
#include "posix.h" // ptrdiff_t

View File

@ -8,7 +8,7 @@
#include "res/res.h"
#ifdef _WIN32
# include "float.h" // <- MT: Just for _finite(), converting certain strings was causing wierd bugs.
# include "float.h" // <- MT: Just for _finite(), converting certain strings was causing weird bugs.
# define finite _finite
#else
# define finite __finite // PT: Need to use _finite in MSVC, __finite in gcc

View File

@ -19,9 +19,6 @@
#include "scripting/JSInterface_Vector3D.h"
// TODO: don't hardcode player-colours
static const float PlayerColours[9][3] = { {1,1,1}, {1,0,0}, {0,1,0}, {0,0,1}, {1,1,0}, {1,0,1}, {0,1,1}, {1,0.5,0}, {1,0,0.5} };
CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
{
m_position = position;
@ -71,11 +68,7 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
m_grouped = -1;
#ifdef SCED // HACK: ScEd doesn't have a g_Game, so we can't use its CPlayers
m_player = (CPlayer*)0;
#else
m_player = g_Game->GetPlayer( 0 );
#endif
}
CEntity::~CEntity()
@ -166,13 +159,7 @@ void CEntity::updateActorTransforms()
void CEntity::snapToGround()
{
CTerrain *pTerrain = g_Game->GetWorld()->GetTerrain();
#ifdef SCED
extern CTerrain g_Terrain;
m_graphics_position.Y = g_Terrain.getExactGroundLevel( m_graphics_position.X, m_graphics_position.Z );
#else
m_graphics_position.Y = pTerrain->getExactGroundLevel( m_graphics_position.X, m_graphics_position.Z );
#endif
}
void CEntity::update( size_t timestep )
@ -513,12 +500,7 @@ void CEntity::render()
void CEntity::renderSelectionOutline( float alpha )
{
#ifdef SCED
extern CTerrain g_Terrain;
CTerrain *pTerrain = &g_Terrain;
#else
CTerrain *pTerrain = g_Game->GetWorld()->GetTerrain();
#endif
if( !m_bounds ) return;
@ -526,12 +508,8 @@ void CEntity::renderSelectionOutline( float alpha )
glColor4f( 1.0f, 0.5f, 0.5f, alpha );
else
{
#ifdef SCED // HACK: ScEd doesn't have a g_Game, so we can't use its CPlayers
glColor3fv(PlayerColours[ (intptr_t)m_player ]);
#else
const SPlayerColour& col = m_player->GetColour();
glColor3f( col.r, col.g, col.b );
#endif
}
glBegin( GL_LINE_LOOP );

View File

@ -3,9 +3,7 @@
#include "AlterElevationCommand.h"
#include "ui/UIGlobals.h"
#include "MiniMap.h"
#include "Terrain.h"
extern CTerrain g_Terrain;
#include "Game.h"
inline int clamp(int x,int min,int max)
{
@ -29,8 +27,10 @@ CAlterElevationCommand::~CAlterElevationCommand()
void CAlterElevationCommand::Execute()
{
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
int r=m_BrushSize;
u32 mapSize=g_Terrain.GetVerticesPerSide();
u32 mapSize=terrain->GetVerticesPerSide();
// get range of vertices affected by brush
int x0=clamp(m_SelectionCentre[0]-r,0,mapSize-1);
@ -46,7 +46,7 @@ void CAlterElevationCommand::Execute()
int i,j;
for (j=z0;j<=z1;j++) {
for (i=x0;i<=x1;i++) {
u16 input=g_Terrain.GetHeightMap()[j*mapSize+i];
u16 input=terrain->GetHeightMap()[j*mapSize+i];
m_DataIn(i-x0,j-z0)=input;
}
}
@ -61,7 +61,9 @@ void CAlterElevationCommand::Execute()
void CAlterElevationCommand::ApplyDataToSelection(const CArray2D<u16>& data)
{
u32 mapSize=g_Terrain.GetVerticesPerSide();
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
u32 mapSize=terrain->GetVerticesPerSide();
int r=m_BrushSize;
int x0=clamp(m_SelectionCentre[0]-r,0,mapSize-1);
@ -77,19 +79,19 @@ void CAlterElevationCommand::ApplyDataToSelection(const CArray2D<u16>& data)
int idx=j*mapSize+i;
u16 height=data(i-x0,j-z0);
// update heightmap
g_Terrain.GetHeightMap()[idx]=height;
terrain->GetHeightMap()[idx]=height;
}
}
// flag vertex data as dirty for affected patches, and rebuild bounds of these patches
u32 patchesPerSide=g_Terrain.GetPatchesPerSide();
u32 patchesPerSide=terrain->GetPatchesPerSide();
int px0=clamp(-1+(x0/PATCH_SIZE),0,patchesPerSide);
int px1=clamp(1+(x1/PATCH_SIZE),0,patchesPerSide);
int pz0=clamp(-1+(z0/PATCH_SIZE),0,patchesPerSide);
int pz1=clamp(1+(z1/PATCH_SIZE),0,patchesPerSide);
for (j=pz0;j<pz1;j++) {
for (int i=px0;i<px1;i++) {
CPatch* patch=g_Terrain.GetPatch(i,j);
CPatch* patch=terrain->GetPatch(i,j);
patch->CalcBounds();
patch->SetDirty(RENDERDATA_UPDATE_VERTICES);
}

View File

@ -5,9 +5,8 @@
#include "ObjectManager.h"
#include "Model.h"
#include "Unit.h"
#include "Terrain.h"
#include "Game.h"
extern CTerrain g_Terrain;
extern CLightEnv g_LightEnv;
@ -34,12 +33,14 @@ void CAlterLightEnvCommand::ApplyData(const CLightEnv& env)
// copy given lighting environment to global environment
g_LightEnv=env;
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
// dirty the vertices on all patches
u32 patchesPerSide=g_Terrain.GetPatchesPerSide();
u32 patchesPerSide=terrain->GetPatchesPerSide();
u32 i,j;
for (j=0;j<patchesPerSide;j++) {
for (i=0;i<patchesPerSide;i++) {
CPatch* patch=g_Terrain.GetPatch(i,j);
CPatch* patch=terrain->GetPatch(i,j);
patch->SetDirty(RENDERDATA_UPDATE_VERTICES);
}
}

View File

@ -17,6 +17,11 @@ CBrushShapeEditorTool::CBrushShapeEditorTool() : m_BrushSize(5), m_BrushData(0)
memset(m_BrushData,0,sizeof(bool)*m_BrushSize*m_BrushSize);
}
CBrushShapeEditorTool::~CBrushShapeEditorTool()
{
delete[] m_BrushData;
}
void CBrushShapeEditorTool::OnDraw()
{
g_Renderer.SetTexture(0,0);

View File

@ -14,6 +14,7 @@ public:
public:
CBrushShapeEditorTool();
~CBrushShapeEditorTool();
// draw the visual representation of this tool
void OnDraw();

View File

@ -6,13 +6,12 @@
#include "NaviCam.h"
#include "TextureManager.h"
#include "Camera.h"
#include "Terrain.h"
#include "Game.h"
#include "Renderer.h"
#include "ogl.h"
#include <list>
extern CCamera g_Camera;
extern CTerrain g_Terrain;
CBrushTool::CBrushTool() : m_BrushSize(1), m_LButtonDown(false), m_RButtonDown(false)
@ -22,16 +21,18 @@ CBrushTool::CBrushTool() : m_BrushSize(1), m_LButtonDown(false), m_RButtonDown(f
static void RenderTileOutline(int gx,int gz)
{
CMiniPatch* mpatch=g_Terrain.GetTile(gx,gz);
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
CMiniPatch* mpatch=terrain->GetTile(gx,gz);
if (!mpatch) return;
u32 mapSize=g_Terrain.GetVerticesPerSide();
u32 mapSize=terrain->GetVerticesPerSide();
CVector3D V[4];
g_Terrain.CalcPosition(gx,gz,V[0]);
g_Terrain.CalcPosition(gx+1,gz,V[1]);
g_Terrain.CalcPosition(gx+1,gz+1,V[2]);
g_Terrain.CalcPosition(gx,gz+1,V[3]);
terrain->CalcPosition(gx,gz,V[0]);
terrain->CalcPosition(gx+1,gz,V[1]);
terrain->CalcPosition(gx+1,gz+1,V[2]);
terrain->CalcPosition(gx,gz+1,V[3]);
glLineWidth(2);
glColor4f(0.05f,0.95f,0.1f,0.75f);
@ -135,7 +136,7 @@ void CBrushTool::OnMouseMove(unsigned int flags,int px,int py)
// intersect with terrain
CVector3D ipt;
CHFTracer hftracer(&g_Terrain);
CHFTracer hftracer(g_Game->GetWorld()->GetTerrain());
if (hftracer.RayIntersect(rayorigin,raydir,m_SelectionCentre[0],m_SelectionCentre[1],m_SelectionPoint)) {
// drag trigger supported?
if (SupportDragTrigger()) {

View File

@ -23,10 +23,11 @@
#include "XML.h"
#include "Game.h"
const int NUM_ALPHA_MAPS = 14;
Handle AlphaMaps[NUM_ALPHA_MAPS];
CTerrain g_Terrain;
extern CLightEnv g_LightEnv;
CMiniMap g_MiniMap;
CEditorData g_EditorData;
@ -66,12 +67,14 @@ bool CEditorData::InitScene()
}
}
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
// cover entire terrain with default texture
u32 patchesPerSide=g_Terrain.GetPatchesPerSide();
u32 patchesPerSide=terrain->GetPatchesPerSide();
for (uint pj=0; pj<patchesPerSide; pj++) {
for (uint pi=0; pi<patchesPerSide; pi++) {
CPatch* patch=g_Terrain.GetPatch(pi,pj);
CPatch* patch=terrain->GetPatch(pi,pj);
for (int j=0;j<PATCH_SIZE;j++) {
for (int i=0;i<PATCH_SIZE;i++) {
@ -86,7 +89,7 @@ bool CEditorData::InitScene()
// build the terrain plane
float h=128*HEIGHT_SCALE;
u32 mapSize=g_Terrain.GetVerticesPerSide();
u32 mapSize=terrain->GetVerticesPerSide();
CVector3D pt0(0,h,0),pt1(float(CELL_SIZE*mapSize),h,0),pt2(0,h,float(CELL_SIZE*mapSize));
m_TerrainPlane.Set(pt0,pt1,pt2);
m_TerrainPlane.Normalize();
@ -154,51 +157,20 @@ static bool saveTGA(const char* filename,int width,int height,unsigned char* dat
return true;
}
void CEditorData::LoadAlphaMaps()
{
const char* fns[CRenderer::NumAlphaMaps] = {
"art/textures/terrain/alphamaps/special/blendcircle.png",
"art/textures/terrain/alphamaps/special/blendlshape.png",
"art/textures/terrain/alphamaps/special/blendedge.png",
"art/textures/terrain/alphamaps/special/blendedgecorner.png",
"art/textures/terrain/alphamaps/special/blendedgetwocorners.png",
"art/textures/terrain/alphamaps/special/blendfourcorners.png",
"art/textures/terrain/alphamaps/special/blendtwooppositecorners.png",
"art/textures/terrain/alphamaps/special/blendlshapecorner.png",
"art/textures/terrain/alphamaps/special/blendtwocorners.png",
"art/textures/terrain/alphamaps/special/blendcorner.png",
"art/textures/terrain/alphamaps/special/blendtwoedges.png",
"art/textures/terrain/alphamaps/special/blendthreecorners.png",
"art/textures/terrain/alphamaps/special/blendushape.png",
"art/textures/terrain/alphamaps/special/blendbad.png"
};
g_Renderer.LoadAlphaMaps(fns);
}
void CEditorData::InitResources()
{
g_TexMan.LoadTerrainTextures();
LoadAlphaMaps();
g_ObjMan.LoadObjects();
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// InitSingletons: create and initialise required singletons
void CEditorData::InitSingletons()
{
new CEntityManager;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// Init: perform one time initialisation of the editor
bool CEditorData::Init()
{
// create and initialise singletons
InitSingletons();
// load default textures
InitResources();
// Set up the actual game
g_Game = new CGame();
PSRETURN ret = g_Game->StartGame(&g_GameAttributes);
if (ret != PSRETURN_OK)
{
// Failed to start the game
delete g_Game;
g_Game = NULL;
return false;
}
// create the scene - terrain, camera, light environment etc
if (!InitScene()) return false;
@ -209,8 +181,6 @@ bool CEditorData::Init()
// set up the info box
m_InfoBox.Initialise();
g_EntityTemplateCollection.loadTemplates();
return true;
}
@ -218,7 +188,6 @@ bool CEditorData::Init()
// Terminate: close down the editor (destroy singletons in reverse order to construction)
void CEditorData::Terminate()
{
delete &g_EntityManager;
}
void CEditorData::InitCamera()
@ -301,22 +270,26 @@ void CEditorData::OnCameraChanged()
m_TerrainPlane.FindRayIntersection(rayOrigin,rayDir,&hitPt[i]);
}
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
for (i=0;i<4;i++) {
// convert to minimap space
float px=hitPt[i].X;
float pz=hitPt[i].Z;
g_MiniMap.m_ViewRect[i][0]=(197*px/float(CELL_SIZE*g_Terrain.GetVerticesPerSide()));
g_MiniMap.m_ViewRect[i][1]=197*pz/float(CELL_SIZE*g_Terrain.GetVerticesPerSide());
g_MiniMap.m_ViewRect[i][0]=(197*px/float(CELL_SIZE*terrain->GetVerticesPerSide()));
g_MiniMap.m_ViewRect[i][1]=197*pz/float(CELL_SIZE*terrain->GetVerticesPerSide());
}
}
void CEditorData::RenderTerrain()
{
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
CFrustum frustum=g_NaviCam.GetCamera().GetFrustum();
u32 patchesPerSide=g_Terrain.GetPatchesPerSide();
u32 patchesPerSide= g_Game->GetWorld()->GetTerrain()->GetPatchesPerSide();
for (uint j=0; j<patchesPerSide; j++) {
for (uint i=0; i<patchesPerSide; i++) {
CPatch* patch=g_Terrain.GetPatch(i,j);
CPatch* patch=terrain->GetPatch(i,j);
if (frustum.IsBoxVisible (CVector3D(0,0,0),patch->GetBounds())) {
g_Renderer.Submit(patch);
}
@ -373,10 +346,12 @@ void CEditorData::RenderNoCull()
SubmitModelRecursive(units[i]->GetModel());
}
u32 patchesPerSide=g_Terrain.GetPatchesPerSide();
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
u32 patchesPerSide=terrain->GetPatchesPerSide();
for (j=0; j<patchesPerSide; j++) {
for (i=0; i<patchesPerSide; i++) {
CPatch* patch=g_Terrain.GetPatch(i,j);
CPatch* patch=terrain->GetPatch(i,j);
g_Renderer.Submit(patch);
}
}
@ -598,8 +573,8 @@ bool CEditorData::LoadTerrain(const char* filename)
}
// rebuild terrain
g_Terrain.Resize(mapsize);
g_Terrain.SetHeightMap(heightmap);
g_Game->GetWorld()->GetTerrain()->Resize(mapsize);
g_Game->GetWorld()->GetTerrain()->SetHeightMap(heightmap);
// clean up
delete[] data;

View File

@ -50,16 +50,12 @@ public:
private:
bool InitScene();
void LoadAlphaMaps();
void InitResources();
void InitCamera();
void RenderTerrain();
void RenderModels();
void RenderWorld();
void RenderObEdGrid();
void InitSingletons();
void StartTestMode();
void StopTestMode();
@ -76,7 +72,6 @@ private:
};
extern CEditorData g_EditorData;
extern CTerrain g_Terrain;
extern CLightEnv g_LightEnv;
#endif

View File

@ -2,12 +2,10 @@
#include "MiniMap.h"
#include "ui/UIGlobals.h"
#include "TextureManager.h"
#include "Terrain.h"
#include "Game.h"
#include "Renderer.h"
#include "ogl.h"
extern CTerrain g_Terrain;
struct TGAHeader {
// header stuff
unsigned char iif_size;
@ -91,6 +89,11 @@ CMiniMap::CMiniMap() : m_Handle(0), m_Data(0), m_Size(0)
{
}
CMiniMap::~CMiniMap()
{
delete m_Data;
}
void CMiniMap::Initialise()
{
// get rid of existing texture, if we've got one
@ -103,9 +106,11 @@ void CMiniMap::Initialise()
glGenTextures(1,(GLuint*) &m_Handle);
g_Renderer.BindTexture(0,m_Handle);
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
// allocate an image big enough to fit the entire map into
m_Size=RoundUpToPowerOf2(g_Terrain.GetVerticesPerSide());
u32 mapSize=g_Terrain.GetVerticesPerSide();
m_Size=RoundUpToPowerOf2(terrain->GetVerticesPerSide());
u32 mapSize=terrain->GetVerticesPerSide();
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,m_Size,m_Size,0,GL_BGRA_EXT,GL_UNSIGNED_BYTE,0);
// allocate local copy
@ -144,7 +149,7 @@ void CMiniMap::Render()
g_Renderer.BindTexture(0,m_Handle);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
float tclimit=float(g_Terrain.GetVerticesPerSide()-1)/float(m_Size);
float tclimit=float(g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)/float(m_Size);
// render minimap as quad
glBegin(GL_QUADS);
@ -202,13 +207,15 @@ void CMiniMap::Render()
void CMiniMap::Update(int x,int y,unsigned int color)
{
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
// get height at this pixel
int hmap=(int) g_Terrain.GetHeightMap()[y*g_Terrain.GetVerticesPerSide() + x]>>8;
int hmap=(int) terrain->GetHeightMap()[y*terrain->GetVerticesPerSide() + x]>>8;
// shift from 0-255 to 170-255
int val=(hmap/3)+170;
// get modulated color
u32 mapSize=g_Terrain.GetVerticesPerSide();
u32 mapSize=terrain->GetVerticesPerSide();
*(m_Data+(y*(mapSize-1)+x))=ScaleColor(color,float(val)/255.0f);
UpdateTexture();
@ -216,13 +223,15 @@ void CMiniMap::Update(int x,int y,unsigned int color)
void CMiniMap::Update(int x,int y,int w,int h,unsigned int color)
{
u32 mapSize=g_Terrain.GetVerticesPerSide();
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
u32 mapSize=terrain->GetVerticesPerSide();
for (int j=0;j<h;j++) {
u32* dataptr=m_Data+((y+j)*(mapSize-1))+x;
for (int i=0;i<w;i++) {
// get height at this pixel
int hmap=int(g_Terrain.GetHeightMap()[(y+j)*mapSize + x+i])>>8;
int hmap=int(terrain->GetHeightMap()[(y+j)*mapSize + x+i])>>8;
// shift from 0-255 to 170-255
int val=(hmap/3)+170;
// load scaled color into data pointer
@ -235,7 +244,7 @@ void CMiniMap::Update(int x,int y,int w,int h,unsigned int color)
void CMiniMap::Rebuild()
{
u32 mapSize=g_Terrain.GetVerticesPerSide();
u32 mapSize=g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide();
Rebuild(0,0,mapSize-1,mapSize-1);
}
@ -246,23 +255,25 @@ void CMiniMap::UpdateTexture()
// bind to the minimap
g_Renderer.BindTexture(0,m_Handle);
// subimage to update pixels
u32 mapSize=g_Terrain.GetVerticesPerSide();
u32 mapSize=g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide();
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,mapSize-1,mapSize-1,GL_BGRA_EXT,GL_UNSIGNED_BYTE,m_Data);
}
void CMiniMap::Rebuild(int x,int y,int w,int h)
{
u32 mapSize=g_Terrain.GetVerticesPerSide();
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
u32 mapSize=terrain->GetVerticesPerSide();
for (int j=0;j<h;j++) {
u32* dataptr=m_Data+((y+j)*(mapSize-1))+x;
for (int i=0;i<w;i++) {
// get height at this pixel
int hmap=int(g_Terrain.GetHeightMap()[(y+j)*mapSize + x+i])>>8;
int hmap=int(terrain->GetHeightMap()[(y+j)*mapSize + x+i])>>8;
// shift from 0-255 to 170-255
int val=(hmap/3)+170;
CMiniPatch* mp=g_Terrain.GetTile(x+i,y+j);
CMiniPatch* mp=terrain->GetTile(x+i,y+j);
unsigned int color;
if (mp) {

View File

@ -7,6 +7,7 @@ class CMiniMap
{
public:
CMiniMap();
~CMiniMap();
void Initialise();
void Render();

View File

@ -5,6 +5,7 @@
#include "ObjectEntry.h"
#include "Model.h"
#include "Unit.h"
#include "Game.h"
#include "BaseEntity.h"
#include "BaseEntityCollection.h"
@ -42,7 +43,7 @@ void CPaintObjectCommand::Finalize()
CVector3D position = m_Unit->GetModel()->GetTransform().GetTranslation();
g_UnitMan.RemoveUnit(m_Unit);
HEntity ent = g_EntityManager.create( templateObject, position, atan2( -orient.X, -orient.Z ) );
ent->m_player = (CPlayer*)1;
ent->SetPlayer(g_Game->GetPlayer(1));
}
}

View File

@ -4,9 +4,7 @@
#include "ui/UIGlobals.h"
#include "MiniMap.h"
#include "textureEntry.h"
#include "Terrain.h"
extern CTerrain g_Terrain;
#include "Game.h"
inline int clamp(int x,int min,int max)
{
@ -32,9 +30,11 @@ CPaintTextureCommand::~CPaintTextureCommand()
void CPaintTextureCommand::Execute()
{
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
int r=m_BrushSize;
u32 patchesPerSide=g_Terrain.GetPatchesPerSide();
u32 mapSize=g_Terrain.GetVerticesPerSide();
u32 patchesPerSide=terrain->GetPatchesPerSide();
u32 mapSize=terrain->GetVerticesPerSide();
// get range of tiles affected by brush
int x0=clamp(m_SelectionCentre[0]-r,0,mapSize-1);
@ -47,7 +47,7 @@ void CPaintTextureCommand::Execute()
for (int i=m_SelectionCentre[0]-r;i<=m_SelectionCentre[0]+r;i++) {
// try and get minipatch, if there is one
CMiniPatch* nmp=g_Terrain.GetTile(i,j);
CMiniPatch* nmp=terrain->GetTile(i,j);
if (nmp) {
nmp->Tex1=m_Texture ? m_Texture->GetHandle() : 0;
@ -63,7 +63,7 @@ void CPaintTextureCommand::Execute()
int pz1=clamp(1+(z1/PATCH_SIZE),0,patchesPerSide);
for (j=pz0;j<pz1;j++) {
for (int i=px0;i<px1;i++) {
CPatch* patch=g_Terrain.GetPatch(i,j);
CPatch* patch=terrain->GetPatch(i,j);
patch->SetDirty(RENDERDATA_UPDATE_INDICES);
}
}

View File

@ -1,9 +1,7 @@
#include "precompiled.h"
#include "RaiseElevationCommand.h"
#include "Terrain.h"
extern CTerrain g_Terrain;
#include "Game.h"
inline int clamp(int x,int min,int max)
{
@ -25,12 +23,14 @@ CRaiseElevationCommand::~CRaiseElevationCommand()
void CRaiseElevationCommand::CalcDataOut(int x0,int x1,int z0,int z1)
{
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
// fill output data
u32 mapSize=g_Terrain.GetVerticesPerSide();
u32 mapSize=terrain->GetVerticesPerSide();
int i,j;
for (j=z0;j<=z1;j++) {
for (i=x0;i<=x1;i++) {
u32 input=g_Terrain.GetHeightMap()[j*mapSize+i];
u32 input=terrain->GetHeightMap()[j*mapSize+i];
u16 output=clamp(input+m_DeltaHeight,0,65535);
m_DataOut(i-x0,j-z0)=output;
}

View File

@ -1,12 +1,10 @@
#include "precompiled.h"
#include "SmoothElevationCommand.h"
#include "Terrain.h"
#include "Game.h"
#include <math.h>
extern CTerrain g_Terrain;
inline int clamp(int x,int min,int max)
{
if (x<min) return min;
@ -27,7 +25,9 @@ CSmoothElevationCommand::~CSmoothElevationCommand()
void CSmoothElevationCommand::CalcDataOut(int x0,int x1,int z0,int z1)
{
u32 mapSize=g_Terrain.GetVerticesPerSide();
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
u32 mapSize=terrain->GetVerticesPerSide();
// get valid filter vertex indices
int fxmin=clamp(x0-2,0,mapSize-1);
@ -49,7 +49,7 @@ void CSmoothElevationCommand::CalcDataOut(int x0,int x1,int z0,int z1)
if (i+m>=fxmin && i+m<=fxmax && j+k>=fzmin && j+k<=fzmax) {
float dist=sqrt(float((k*k)+(m*m)));
float weight=1-(dist/(r+1));
accum+=weight*g_Terrain.GetHeightMap()[(j+k)*mapSize+(i+m)];
accum+=weight*terrain->GetHeightMap()[(j+k)*mapSize+(i+m)];
totalWeight+=weight;
}
}
@ -57,11 +57,11 @@ void CSmoothElevationCommand::CalcDataOut(int x0,int x1,int z0,int z1)
if (1 || totalWeight>0) {
float t=0.5f;//m_SmoothPower/32.0f;
float inputHeight=g_Terrain.GetHeightMap()[j*mapSize+i];
float inputHeight=terrain->GetHeightMap()[j*mapSize+i];
accum/=totalWeight;
m_DataOut(i-x0,j-z0)=clamp(int((inputHeight*(1-t))+accum*t),0,65535);
} else {
m_DataOut(i-x0,j-z0)=g_Terrain.GetHeightMap()[j*mapSize+i];
m_DataOut(i-x0,j-z0)=terrain->GetHeightMap()[j*mapSize+i];
}
}
}

View File

@ -15,9 +15,6 @@
#include "AlterLightEnvCommand.h"
extern CTerrain g_Terrain;
/////////////////////////////////////////////////////////////////////////////
// CLightSettingsDlg dialog

View File

@ -36,7 +36,7 @@
#include "AlterLightEnvCommand.h"
#include "LightEnv.h"
#include "Terrain.h"
#include "Game.h"
#include "PaintTextureTool.h"
#include "PaintObjectTool.h"
@ -46,7 +46,6 @@
#include "SelectObjectTool.h"
#include "simulation/Entity.h"
extern CTerrain g_Terrain;
extern CLightEnv g_LightEnv;
/////////////////////////////////////////////////////////////////////////////
@ -496,7 +495,7 @@ void CMainFrame::OnResizeMap()
CMapSizeDlg dlg;
if (dlg.DoModal()==IDOK) {
// resize terrain to selected size
g_Terrain.Resize(dlg.m_MapSize);
g_Game->GetWorld()->GetTerrain()->Resize(dlg.m_MapSize);
// reinitialise minimap to cope with terrain of different size
g_MiniMap.Initialise();
@ -577,7 +576,7 @@ void CMainFrame::OnFileSaveMap()
CMapWriter writer;
try {
writer.SaveMap(savename, &g_Terrain, &g_LightEnv, &g_UnitMan);
writer.SaveMap(savename, g_Game->GetWorld()->GetTerrain(), &g_LightEnv, &g_UnitMan);
CStr filetitle=savedlg.m_ofn.lpstrFileTitle;
int index=filetitle.ReverseFind(CStr("."));
@ -619,7 +618,7 @@ void CMainFrame::OnFileLoadMap()
CMapReader reader;
try {
reader.LoadMap(loadname, &g_Terrain, &g_UnitMan, &g_LightEnv);
reader.LoadMap(loadname, g_Game->GetWorld()->GetTerrain(), &g_UnitMan, &g_LightEnv);
CStr filetitle=loaddlg.m_ofn.lpstrFileTitle;
int index=filetitle.ReverseFind(CStr("."));
@ -753,8 +752,10 @@ static float getExactGroundLevel( float x, float y )
float xf = x - (float)xi;
float yf = y - (float)yi;
u16* heightmap = g_Terrain.GetHeightMap();
unsigned long mapsize = g_Terrain.GetVerticesPerSide();
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
u16* heightmap = terrain->GetHeightMap();
unsigned long mapsize = terrain->GetVerticesPerSide();
float h00 = heightmap[yi*mapsize + xi];
float h01 = heightmap[yi*mapsize + xi + mapsize];
@ -826,7 +827,7 @@ void CMainFrame::OnRandomMap()
const u32 unitsPerDir=u32(sqrt(float(count)));
u32 i,j;
u32 vsize=g_Terrain.GetVerticesPerSide()-1;
u32 vsize=g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1;
for (i=0;i<unitsPerDir;i++) {
for (j=0;j<unitsPerDir;j++) {
@ -852,10 +853,11 @@ void CMainFrame::OnRandomMap()
}
/*
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
for (i=0;i<vsize;i++) {
for (j=0;j<vsize;j++) {
CTextureEntry* tex=GetRandomTexture();
CMiniPatch* mp=g_Terrain.GetTile(i,j);
CMiniPatch* mp=terrain->GetTile(i,j);
mp->Tex1=tex->GetHandle();
mp->Tex1Priority=tex->GetType();
mp->m_Parent->SetDirty(RENDERDATA_UPDATE_VERTICES | RENDERDATA_UPDATE_INDICES);
@ -873,5 +875,5 @@ void CMainFrame::OnEntityPlayerX(int x)
{
CEntity* entity = CSelectObjectTool::GetTool()->GetFirstEntity();
if (entity)
entity->m_player = (CPlayer*)(intptr_t)x; // HACK: ScEd doesn't have a g_Game, so we can't use its CPlayers
entity->SetPlayer(g_Game->GetPlayer(x));
}

View File

@ -25,7 +25,7 @@ END_MESSAGE_MAP()
CScEdDoc::CScEdDoc()
{
// TODO: add one-time construction code here
m_bAutoDelete = FALSE;
// m_bAutoDelete = FALSE; // (PT: Is this needed? All it seems to do is create memory leaks...)
}
CScEdDoc::~CScEdDoc()

View File

@ -17,6 +17,8 @@
#include "ogl.h"
#undef _IGNORE_WGL_H_
#include "Game.h"
#include "res/vfs.h"
int g_ClickMode=0;
@ -392,12 +394,12 @@ void CScEdView::OnLButtonDown(UINT nFlags, CPoint point)
void CScEdView::AdjustCameraViaMinimapClick(CPoint point)
{
// convert from screen space point back to world space point representating intersection of
// convert from screen space point back to world space point representing intersection of
// ray with terrain plane
CVector3D pos;
pos.X=float(CELL_SIZE*g_Terrain.GetVerticesPerSide())*float(point.x+200-m_Width)/200.0f;
pos.X=float(CELL_SIZE * g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()) * float(point.x+200-m_Width)/200.0f;
pos.Y=-g_EditorData.m_TerrainPlane.m_Dist;
pos.Z=float(CELL_SIZE*g_Terrain.GetVerticesPerSide())*float(m_Height-point.y)/197.0f;
pos.Z=float(CELL_SIZE * g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()) * float(m_Height-point.y)/197.0f;
// calculate desired camera point from this
CVector3D startpos=g_NaviCam.GetCamera().m_Orientation.GetTranslation();