So, ScEd updated to comply with terrain XML's (and it seems to work fine too!)

This was SVN commit r2414.
This commit is contained in:
Simon Brenner 2005-06-20 17:34:17 +00:00
parent 1975a047c5
commit 32772dbf71
11 changed files with 73 additions and 50 deletions

View File

@ -41,6 +41,8 @@ public:
return m_BaseColor;
}
int GetType() const
{ return m_Groups[0]->GetIndex(); }
const GroupVector &GetGroups() const
{ return m_Groups; }

View File

@ -19,9 +19,9 @@
using namespace std;
CTextureManager::CTextureManager()
{
}
CTextureManager::CTextureManager():
m_LastGroupIndex(0)
{}
CTextureManager::~CTextureManager()
{
@ -192,7 +192,19 @@ CTerrainTypeGroup *CTextureManager::FindGroup(CStr name)
if (it != m_TerrainTypeGroups.end())
return it->second;
else
return m_TerrainTypeGroups[name] = new CTerrainTypeGroup(name);
return m_TerrainTypeGroups[name] = new CTerrainTypeGroup(name, ++m_LastGroupIndex);
}
/* There was a GetRandomTexture in MainFrm.cpp (sced) previously that gave compile errors...
So I thought "better fix it up and put it in CTextureManager instead".. well, it is never used
except for one *comment* in MainFrm.cpp - d'oh */
CTextureEntry* CTextureManager::GetRandomTexture()
{
if (!m_TextureEntries.size())
return NULL;
u32 type=rand()%(u32)m_TextureEntries.size();
return m_TextureEntries[type];
}
void CTerrainTypeGroup::AddTerrain(CTextureEntry *pTerrain)

View File

@ -18,34 +18,50 @@ class CTextureEntry;
class CTerrainTypeGroup
{
// name of this terrain type (as referenced in terrain xmls)
CStr m_Name;
// "index".. basically a bogus integer that can be used by ScEd to set texture
// priorities
int m_Index;
// list of textures of this type (found from the texture directory)
std::vector<CTextureEntry*> m_Terrains;
public:
CTerrainTypeGroup(CStr name):
m_Name(name)
CTerrainTypeGroup(CStr name, int index):
m_Name(name),
m_Index(index)
{}
// Add a texture entry to this terrain type
void AddTerrain(CTextureEntry *);
// Remove a texture entry
void RemoveTerrain(CTextureEntry *);
int GetIndex() const
{ return m_Index; }
CStr GetName() const
{ return m_Name; }
const std::vector<CTextureEntry*> &GetTerrains() const
{ return m_Terrains; }
};
///////////////////////////////////////////////////////////////////////////////////////////
// CTextureManager : manager class for all terrain texture objects
class CTextureManager : public Singleton<CTextureManager>
{
public:
typedef std::map<CStr, CTerrainTypeGroup *> TerrainTypeGroupMap;
private:
// All texture entries created by this class, for easy freeing now that
// textures may be in several STextureType's
std::vector<CTextureEntry *> m_TextureEntries;
typedef std::map<CStr, CTerrainTypeGroup *> TerrainTypeGroupMap;
TerrainTypeGroupMap m_TerrainTypeGroups;
uint m_LastGroupIndex;
// Find all XML's in the directory (with subdirs) and try to load them as
// terrain XML's
void RecurseDirectory(CStr path);
@ -60,6 +76,7 @@ public:
CTextureEntry* FindTexture(CStr tag);
CTextureEntry* FindTexture(Handle handle);
CTextureEntry* GetRandomTexture();
// TODO How do Atlas/ScEd want to create new terrain types?
// CTextureEntry* AddTexture(const char* filename,int type);
void DeleteTexture(CTextureEntry* entry);
@ -67,6 +84,13 @@ public:
// Find or create a new texture group. All terrain groups are owned by the
// texturemanager (TerrainTypeManager)
CTerrainTypeGroup *FindGroup(CStr name);
// Use the default group for all terrain types that don't have their own
// ScEd currently relies on every texture having one group (and is happy ignorant of any
// extra groups that might exist)
CTerrainTypeGroup *GetDefaultGroup();
const TerrainTypeGroupMap &GetGroups() const
{ return m_TerrainTypeGroups; }
};

View File

@ -1505,8 +1505,6 @@ debug_printf("MAIN &argc=%p &argv=%p\n", &argc, &argv);
void ScEd_Init()
{
new CProfileManager;
g_Quickstart = true;
Init(0, NULL, false);

View File

@ -48,7 +48,7 @@ static void RenderTileOutline(int gx,int gz)
glBegin (GL_QUADS);
for(i = 0; i < 4; i++)
for(int i = 0; i < 4; i++)
glVertex3fv(&V[i].X);
glEnd ();

View File

@ -6,6 +6,7 @@
#include "ObjectManager.h"
#include "UnitManager.h"
#include "TextureManager.h"
#include "TextureEntry.h"
#include "Model.h"
#include "SkeletonAnimManager.h"
#include "Unit.h"
@ -60,13 +61,7 @@ bool CEditorData::InitScene()
if (!LoadTerrain("temp/terrain.png")) return false;
// get default texture to apply to terrain
CTextureEntry* texture=0;
for (uint i=0;i<g_TexMan.m_TerrainTextures.size();i++) {
if (g_TexMan.m_TerrainTextures[i].m_Textures.size()) {
texture=g_TexMan.m_TerrainTextures[i].m_Textures[0];
break;
}
}
CTextureEntry* texture=g_TexMan.FindTexture("aaa.dds");
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
@ -271,7 +266,7 @@ void CEditorData::OnCameraChanged()
CVector3D rayDir=g_NaviCam.GetCamera().m_Orientation.GetIn();
CVector3D hitPt[4];
for (i=0;i<4;i++) {
for (int i=0;i<4;i++) {
CVector3D rayDir=wPts[i]-rayOrigin;
rayDir.Normalize();
@ -281,7 +276,7 @@ void CEditorData::OnCameraChanged()
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
for (i=0;i<4;i++) {
for (int i=0;i<4;i++) {
// convert to minimap space
float px=hitPt[i].X;
float pz=hitPt[i].Z;

View File

@ -2,6 +2,7 @@
#include "MiniMap.h"
#include "ui/UIGlobals.h"
#include "TextureManager.h"
#include "TextureEntry.h"
#include "Game.h"
#include "Renderer.h"
#include "ogl.h"

View File

@ -61,7 +61,7 @@ void CPaintTextureCommand::Execute()
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 j=pz0;j<pz1;j++) {
for (int i=px0;i<px1;i++) {
CPatch* patch=terrain->GetPatch(i,j);
patch->SetDirty(RENDERDATA_UPDATE_INDICES);

View File

@ -810,22 +810,6 @@ static CObjectEntry* GetRandomActorTemplate()
// return found;
}
static CTextureEntry* GetRandomTexture()
{
if (g_TexMan.m_TerrainTextures.size()==0) return 0;
CTextureEntry* found=0;
do {
u32 type=rand()%(u32)g_TexMan.m_TerrainTextures.size();
u32 texturesoftype=(u32)g_TexMan.m_TerrainTextures[type].m_Textures.size();
if (texturesoftype>0) {
found=g_TexMan.m_TerrainTextures[type].m_Textures[rand()%texturesoftype];
}
} while (!found);
return found;
}
void CMainFrame::OnRandomMap()
{
const u32 count=5000;
@ -861,7 +845,7 @@ void CMainFrame::OnRandomMap()
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
for (i=0;i<vsize;i++) {
for (j=0;j<vsize;j++) {
CTextureEntry* tex=GetRandomTexture();
CTextureEntry* tex=g_TexMan.GetRandomTexture();
CMiniPatch* mp=terrain->GetTile(i,j);
mp->Tex1=tex->GetHandle();
mp->Tex1Priority=tex->GetType();

View File

@ -95,10 +95,14 @@ static void ConvertColor(const Color8888* src,Color888* dst)
dst->b=src->b;
}
int CTexToolsDlgBar::GetCurrentTerrainType()
CTerrainTypeGroup *CTexToolsDlgBar::GetCurrentTerrainType()
{
CComboBox* terraintypes=(CComboBox*) GetDlgItem(IDC_COMBO_TERRAINTYPES);
return terraintypes->GetCurSel();
int nIndex=terraintypes->GetCurSel();
if (nIndex != CB_ERR)
return (CTerrainTypeGroup *)terraintypes->GetItemDataPtr(nIndex);
else
return NULL;
}
BOOL CTexToolsDlgBar::BuildImageListIcon(CTextureEntry* texentry)
@ -196,9 +200,12 @@ BOOL CTexToolsDlgBar::OnInitDialog()
// build combo box for terrain types
CComboBox* terraintypes=(CComboBox*) GetDlgItem(IDC_COMBO_TERRAINTYPES);
const std::vector<CTextureManager::STextureType>& ttypes=g_TexMan.m_TerrainTextures;
for (uint i=0;i<ttypes.size();i++) {
terraintypes->AddString((const char*) ttypes[i].m_Name);
const CTextureManager::TerrainTypeGroupMap &ttypes=g_TexMan.GetGroups();
CTextureManager::TerrainTypeGroupMap::const_iterator it;
for (it=ttypes.begin();it!=ttypes.end();++it) {
int nIndex=terraintypes->AddString(it->second->GetName().c_str());
if (nIndex != CB_ERR)
terraintypes->SetItemDataPtr(nIndex, it->second);
}
if (ttypes.size()>0) {
// select first type
@ -211,14 +218,14 @@ BOOL CTexToolsDlgBar::OnInitDialog()
// build icons for existing textures
if (ttypes.size()) {
const std::vector<CTextureEntry*>& textures=ttypes[0].m_Textures;
const std::vector<CTextureEntry*>& textures=ttypes.begin()->second->GetTerrains();
for (uint i=0;i<textures.size();i++) {
// add image icon for this
AddImageListIcon(textures[i]);
// add to list ctrl
int index=listctrl->GetItemCount();
listctrl->InsertItem(index,(const char*) textures[i]->GetName(),index);
listctrl->InsertItem(index,(const char*) textures[i]->GetTag(),index);
}
// select first entry if we've got any entries
@ -253,7 +260,7 @@ void CTexToolsDlgBar::OnClickListTextureBrowser(NMHDR* pNMHDR, LRESULT* pResult)
if (!pos) return;
int index=listctrl->GetNextSelectedItem(pos);
Select(g_TexMan.m_TerrainTextures[GetCurrentTerrainType()].m_Textures[index]);
Select(GetCurrentTerrainType()->GetTerrains()[index]);
*pResult = 0;
}
@ -280,15 +287,15 @@ void CTexToolsDlgBar::OnSelChangeTerrainTypes()
listctrl->DeleteAllItems();
// add icons to image list from new selected terrain types
if (GetCurrentTerrainType()!=CB_ERR)
if (GetCurrentTerrainType()!=NULL)
{
std::vector<CTextureEntry*>& textures=g_TexMan.m_TerrainTextures[GetCurrentTerrainType()].m_Textures;
const std::vector<CTextureEntry*>& textures=GetCurrentTerrainType()->GetTerrains();
for (uint j=0;j<textures.size();j++) {
// add image icon for this
AddImageListIcon(textures[j]);
// add to list ctrl
listctrl->InsertItem(j,(const char*) textures[j]->GetName(),j);
listctrl->InsertItem(j,(const char*) textures[j]->GetTag(),j);
}
}
}

View File

@ -17,7 +17,7 @@ public:
protected:
CImageList m_ImageList;
int GetCurrentTerrainType();
CTerrainTypeGroup *GetCurrentTerrainType();
void Select(CTextureEntry* entry);
BOOL BuildImageListIcon(CTextureEntry* texentry);