Skip to content

Commit 5d63a89

Browse files
author
nitrocaster
committed
Clean GameMtlLib sources.
1 parent 4ddede6 commit 5d63a89

File tree

10 files changed

+239
-322
lines changed

10 files changed

+239
-322
lines changed

src/editors/ShaderEditor/GameMtlLib_Editor.cpp

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,26 @@ void SGameMtl::FillProp (PropItemVec& items, ListItem* owner)
5151
PHelper().CreateFloat (items, "Factors\\Density Factor", &fDensityFactor, 0.0f, 1000.0f, 1.0f, 1);
5252
}
5353

54-
void CGameMtlLibrary::CopyMtlPairs(SGameMtl* from, SGameMtl* to)
54+
SGameMtlPair::SGameMtlPair(const SGameMtlPair &src)
5555
{
56-
for (GameMtlIt m1_it=materials.begin(); m1_it!=materials.end(); ++m1_it)
57-
{
58-
SGameMtl* M1 = *m1_it;
59-
SGameMtlPair* p_from = GetMaterialPair(from->GetID(), M1->GetID());
60-
SGameMtlPair* p_to = GetMaterialPair(to->GetID(), M1->GetID());
56+
OwnProps = src.OwnProps;
57+
ID_parent = src.ID_parent;
58+
BreakingSounds = src.BreakingSounds;
59+
StepSounds = src.StepSounds;
60+
CollideSounds = src.CollideSounds;
61+
CollideParticles = src.CollideParticles;
62+
CollideMarks = src.CollideMarks;
63+
}
6164

62-
if(p_from && p_to)
63-
p_to->CopyFrom(p_from);
65+
void CGameMtlLibrary::CopyMtlPairs(SGameMtl *src, SGameMtl *dst)
66+
{
67+
for (auto &mtl : materials)
68+
{
69+
SGameMtlPair *srcPair = GetMaterialPair(src->GetID(), mtl->GetID());
70+
SGameMtlPair *dstPair = GetMaterialPair(dst->GetID(), mtl->GetID());
71+
if (srcPair && dstPair)
72+
new (dstPair)SGameMtlPair(*srcPair);
6473
}
65-
6674
}
6775

6876
BOOL CGameMtlLibrary::UpdateMtlPairs(SGameMtl* src)
@@ -126,6 +134,43 @@ void CGameMtlLibrary::RemoveMaterial(LPCSTR name)
126134
//------------------------------------------------------------------------------
127135
// material pair routines
128136
//------------------------------------------------------------------------------
137+
138+
static IC bool ValidateParent(const SGameMtlPair *who, const SGameMtlPair *parent)
139+
{
140+
if (!parent)
141+
return true;
142+
if (who == parent)
143+
return false;
144+
return ValidateParent(who, parent->m_Owner->GetMaterialPair(parent->GetParent()));
145+
}
146+
147+
bool SGameMtlPair::SetParent(int parentId)
148+
{
149+
int ID_parent_save = ID_parent;
150+
ID_parent = parentId;
151+
for (GameMtlPairIt it = m_Owner->FirstMaterialPair(); it != m_Owner->LastMaterialPair(); it++)
152+
{
153+
if (!ValidateParent(*it, m_Owner->GetMaterialPair((*it)->GetParent())))
154+
{
155+
ID_parent = ID_parent_save;
156+
return false;
157+
}
158+
}
159+
// all right
160+
if (GAMEMTL_NONE_ID == ID_parent)
161+
OwnProps.one();
162+
else
163+
{
164+
OwnProps.zero();
165+
OwnProps.set(flBreakingSounds, BreakingSounds.size());
166+
OwnProps.set(flStepSounds, StepSounds.size());
167+
OwnProps.set(flCollideSounds, CollideSounds.size());
168+
OwnProps.set(flCollideParticles, CollideParticles.size());
169+
OwnProps.set(flCollideMarks, CollideMarks.size());
170+
}
171+
return true;
172+
}
173+
129174
void __fastcall SGameMtlPair::OnFlagChange(PropValue* sender)
130175
{
131176
bool bChecked = sender->Owner()->m_Flags.is(PropItem::flCBChecked);
@@ -155,38 +200,6 @@ IC SGameMtlPair* GetLastParentValue(SGameMtlPair* who, u32 flag)
155200
else return GetLastParentValue(who->m_Owner->GetMaterialPair(who->GetParent()),flag);
156201
}
157202

158-
IC BOOL ValidateParent(SGameMtlPair* who, SGameMtlPair* parent)
159-
{
160-
if (!parent) return TRUE;
161-
if (who==parent) return FALSE;
162-
else return ValidateParent(who,parent->m_Owner->GetMaterialPair(parent->GetParent()));
163-
}
164-
165-
BOOL SGameMtlPair::SetParent(int parent)
166-
{
167-
int ID_parent_save = ID_parent;
168-
ID_parent = parent;
169-
170-
for (GameMtlPairIt it=m_Owner->FirstMaterialPair(); it!=m_Owner->LastMaterialPair(); it++){
171-
if (!ValidateParent(*it,m_Owner->GetMaterialPair((*it)->GetParent()))){
172-
ID_parent = ID_parent_save;
173-
return FALSE;
174-
}
175-
}
176-
// all right
177-
if (GAMEMTL_NONE_ID==ID_parent){
178-
OwnProps.one ();
179-
}else{
180-
OwnProps.zero ();
181-
OwnProps.set (flBreakingSounds, BreakingSounds.size());
182-
OwnProps.set (flStepSounds, StepSounds.size());
183-
OwnProps.set (flCollideSounds, CollideSounds.size());
184-
OwnProps.set (flCollideParticles,CollideParticles.size());
185-
OwnProps.set (flCollideMarks, CollideMarks.size());
186-
}
187-
return TRUE;
188-
}
189-
190203
void __fastcall SGameMtlPair::FillChooseMtl(ChooseItemVec& items, void* param)
191204
{
192205
for (GameMtlIt m0_it=m_Owner->FirstMaterial(); m0_it!=m_Owner->LastMaterial(); m0_it++){

src/xrEngine/GameMtlLib.cpp

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
//---------------------------------------------------------------------------
21
#include "stdafx.h"
3-
#pragma hdrstop
4-
52
#include "GameMtlLib.h"
63
#include "Common/FSMacros.hpp"
74

85
CGameMtlLibrary GMLib;
9-
//CSound_manager_interface* Sound = NULL;
10-
#ifdef _EDITOR
11-
CGameMtlLibrary* PGMLib = NULL;
12-
#endif
13-
CGameMtlLibrary::CGameMtlLibrary()
6+
CGameMtlLibrary *PGMLib = nullptr;
7+
8+
#ifdef DEBUG
9+
const char *SGameMtlPair::dbg_Name()
1410
{
15-
material_index = 0;
16-
material_pair_index = 0;
17-
#ifndef _EDITOR
18-
material_count = 0;
19-
#endif
20-
PGMLib = &GMLib;
11+
static string256 nm;
12+
SGameMtl* M0 = GMLib.GetMaterialByID(GetMtl0());
13+
SGameMtl* M1 = GMLib.GetMaterialByID(GetMtl1());
14+
xr_sprintf(nm, sizeof(nm), "Pair: %s - %s", *M0->m_Name, *M1->m_Name);
15+
return nm;
2116
}
17+
#endif
2218

2319
void SGameMtl::Load(IReader& fs)
2420
{
@@ -63,6 +59,13 @@ void SGameMtl::Load(IReader& fs)
6359
fDensityFactor = fs.r_float();
6460
}
6561

62+
CGameMtlLibrary::CGameMtlLibrary()
63+
{
64+
material_index = 0;
65+
material_pair_index = 0;
66+
PGMLib = &GMLib;
67+
}
68+
6669
void CGameMtlLibrary::Load()
6770
{
6871
string_path name;
@@ -119,38 +122,14 @@ void CGameMtlLibrary::Load()
119122
}
120123
OBJ->close();
121124
}
122-
123-
#ifndef _EDITOR
124-
material_count = (u32)materials.size();
125-
material_pairs_rt.resize(material_count*material_count, 0);
126-
for (GameMtlPairIt p_it = material_pairs.begin(); material_pairs.end() != p_it; ++p_it)
125+
u32 mtlCount = materials.size();
126+
material_pairs_rt.resize(mtlCount*mtlCount, 0);
127+
for (auto &mtlPair : material_pairs)
127128
{
128-
SGameMtlPair* S = *p_it;
129-
int idx0 = GetMaterialIdx(S->mtl0)*material_count + GetMaterialIdx(S->mtl1);
130-
int idx1 = GetMaterialIdx(S->mtl1)*material_count + GetMaterialIdx(S->mtl0);
131-
material_pairs_rt[idx0] = S;
132-
material_pairs_rt[idx1] = S;
129+
int idx0 = GetMaterialIdx(mtlPair->mtl0)*mtlCount + GetMaterialIdx(mtlPair->mtl1);
130+
int idx1 = GetMaterialIdx(mtlPair->mtl1)*mtlCount + GetMaterialIdx(mtlPair->mtl0);
131+
material_pairs_rt[idx0] = mtlPair;
132+
material_pairs_rt[idx1] = mtlPair;
133133
}
134-
#endif
135-
136-
/*
137-
for (GameMtlPairIt p_it=material_pairs.begin(); material_pairs.end() != p_it; ++p_it){
138-
SGameMtlPair* S = *p_it;
139-
for (int k=0; k<S->StepSounds.size(); k++){
140-
Msg("%40s - 0x%x", S->StepSounds[k].handle->file_name(), S->StepSounds[k].g_type);
141-
}
142-
}
143-
*/
144134
FS.r_close (F);
145135
}
146-
147-
#ifdef DEBUG
148-
LPCSTR SGameMtlPair::dbg_Name()
149-
{
150-
static string256 nm;
151-
SGameMtl* M0 = GMLib.GetMaterialByID(GetMtl0());
152-
SGameMtl* M1 = GMLib.GetMaterialByID(GetMtl1());
153-
xr_sprintf(nm, sizeof(nm), "Pair: %s - %s", *M0->m_Name, *M1->m_Name);
154-
return nm;
155-
}
156-
#endif

0 commit comments

Comments
 (0)