Skip to content

Commit c343919

Browse files
authored
Merge branch 'themrdemonized:all-in-one-vs2022-wpo' into all-in-one-vs2022-wpo
2 parents c506f29 + 94b5917 commit c343919

34 files changed

+653
-182
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ How to compile exes:
188188
6. For successful compilation, **the latest build tools with MFC and ATL libraries is required**
189189
190190
## Changelog
191+
**2025.04.19**
192+
* Lucy: (https://github.com/themrdemonized/xray-monolith/pull/171)
193+
* Removal of Model Pool caused a lot of unpredictable crashes, so now it's back but with a small change to work in line with the set_shader lua methods :)
194+
* Added `get_default_shaders` and `reset_shader` to easily revert a model to its vanilla shaders without the need to store default values in a table
195+
* Added support for getting/setting/resetting Script Attachment model shaders/textures
196+
191197
**2025.04.18**
192198
* VodoXleb: Actor camera y offset (https://github.com/themrdemonized/xray-monolith/pull/170)
193199

gamedata/scripts/lua_help_ex.script

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,39 @@
385385
function add_attachment(number, string);
386386
function get_attachment(number);
387387
function remove_attachment(number);
388+
389+
// Shader/Textures
390+
function get_shaders(bool)
391+
function set_shader(number, string, string, bool)
392+
function get_default_shaders(bool)
393+
function reset_shader(number, bool)
394+
395+
get_shaders(hud_mode)
396+
hud_mode is optional and will default to false
397+
returns a table of submesh IDs with subtables containing the shader and texture names of all submeshes of a model, table looks like this for example:
398+
{
399+
1 =
400+
{
401+
texture = "act\act_face_mask_03",
402+
shader = "models\model_pn",
403+
},
404+
2 =
405+
{
406+
texture = "act\act_stalker_cskysun_2",
407+
shader = "models\model_pn",
408+
},
409+
},
410+
411+
get_default_shaders(hud_mode)
412+
returns similar table as get_shaders but containing the default shader and texture names, even after they were changed by set_shader
413+
414+
set_shader(id, shader, texture, hud_mode) can assign a new shader/texture to the submesh ID
415+
id can be -1 to apply the shader/texture to all submeshes at once
416+
shader/texture can be nil if you only want to apply one of them
417+
hud_mode is optional and will default to false
418+
419+
reset_shader(id, hud_mode)
420+
same as set_shader but resets to the default shader/texture values, so you don't need to store them in a table to reset them later
388421
}
389422

390423
class CArtefact : CGameObject {
@@ -626,6 +659,10 @@
626659
function set_ui_position();
627660
function set_ui_rotation(vector);
628661
function set_ui_rotation(number, number, number);
662+
function get_shaders()
663+
function get_default_shaders()
664+
function set_shader(number, string, string)
665+
function reset_shader(number)
629666
}
630667

631668
flags:

src/Include/xrRender/RenderVisual.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ class IKinematicsAnimated;
77
class IParticleCustom;
88
struct vis_data;
99

10+
enum IRenderVisualFlags
11+
{
12+
eIgnoreOptimization = (1 << 0),
13+
eNoShadow = (1 << 1),
14+
};
15+
1016
class IRenderVisual
1117
{
1218
public:
13-
IRenderVisual() { _ignore_optimization = false; }
19+
IRenderVisual() { flags.zero(); }
1420

1521
virtual ~IRenderVisual()
1622
{
@@ -19,15 +25,25 @@ class IRenderVisual
1925
virtual vis_data& _BCL getVisData() = 0;
2026
virtual u32 getType() = 0;
2127

22-
bool _ignore_optimization;
28+
Flags16 flags;
2329

2430
#ifdef DEBUG
2531
virtual shared_str _BCL getDebugName() = 0;
2632
#endif
33+
virtual LPCSTR _BCL getDebugShader() { return nullptr; }
34+
virtual LPCSTR _BCL getDebugTexture() { return nullptr; }
35+
36+
virtual LPCSTR _BCL getDebugShaderDef() { return nullptr; }
37+
virtual LPCSTR _BCL getDebugTextureDef() { return nullptr; }
38+
39+
virtual xr_vector<IRenderVisual*>* get_children() { return nullptr; };
2740

41+
virtual void SetShaderTexture(LPCSTR shader, LPCSTR texture) {};
42+
virtual void ResetShaderTexture() {};
2843
virtual void MarkAsHot(bool is_hot) {}; //--DSR-- HeatVision
2944
virtual void MarkAsGlowing(bool is_glowing) {}; //--DSR-- SilencerOverheat
3045

46+
virtual IRenderVisual* _BCL dcast_RenderVisual() { return this; }
3147
virtual IKinematics* _BCL dcast_PKinematics() { return 0; }
3248
virtual IKinematicsAnimated* dcast_PKinematicsAnimated() { return 0; }
3349
virtual IParticleCustom* dcast_ParticleCustom() { return 0; }

src/Layers/xrRender/FBasicVisual.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void dxRender_Visual::Release()
4343
void dxRender_Visual::Load(const char* N, IReader* data, u32)
4444
{
4545
dbg_name = N;
46+
skinning = ::Render->m_skinning;
4647

4748
// header
4849
VERIFY(data);
@@ -67,7 +68,9 @@ void dxRender_Visual::Load(const char* N, IReader* data, u32)
6768
string256 fnT, fnS;
6869
data->r_stringZ(fnT, sizeof(fnT));
6970
data->r_stringZ(fnS, sizeof(fnS));
70-
shader.create(fnS, fnT);
71+
dbg_shader_def = fnS;
72+
dbg_texture_def = fnT;
73+
ResetShaderTexture();
7174
}
7275

7376
// desc
@@ -116,6 +119,40 @@ void dxRender_Visual::MarkAsGlowing(bool is_glowing)
116119
}
117120
//--DSR-- SilencerOverheat_end
118121

122+
void dxRender_Visual::SetShaderTexture(LPCSTR s_shader, LPCSTR s_texture)
123+
{
124+
if (s_shader && strlen(s_shader))
125+
{
126+
char* shader = xr_strdup(s_shader);
127+
char* no_shadow = strstr(shader, "$no_shadows");
128+
129+
if (no_shadow)
130+
{
131+
flags.set(IRenderVisualFlags::eNoShadow, TRUE);
132+
*no_shadow = 0;
133+
}
134+
else
135+
flags.set(IRenderVisualFlags::eNoShadow, FALSE);
136+
137+
dbg_shader = shader;
138+
xr_delete(shader);
139+
}
140+
141+
if (s_texture && strlen(s_texture))
142+
{
143+
dbg_texture = s_texture;
144+
}
145+
146+
::Render->m_skinning = skinning;
147+
shader.create(*dbg_shader, *dbg_texture);
148+
}
149+
150+
void dxRender_Visual::ResetShaderTexture()
151+
{
152+
if (!dbg_shader.equal(dbg_shader_def) || !dbg_texture.equal(dbg_texture_def))
153+
SetShaderTexture(*dbg_shader_def, *dbg_texture_def);
154+
}
155+
119156
#define PCOPY(a) a = pFrom->a
120157

121158
void dxRender_Visual::Copy(dxRender_Visual* pFrom)
@@ -126,5 +163,11 @@ void dxRender_Visual::Copy(dxRender_Visual* pFrom)
126163
#ifdef _EDITOR
127164
PCOPY(desc);
128165
#endif
166+
PCOPY(flags);
129167
PCOPY(dbg_name);
168+
PCOPY(dbg_shader);
169+
PCOPY(dbg_shader_def);
170+
PCOPY(dbg_texture);
171+
PCOPY(dbg_texture_def);
172+
PCOPY(skinning);
130173
}

src/Layers/xrRender/FBasicVisual.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,21 @@ class ECORE_API dxRender_Visual : public IRenderVisual
4949
ogf_desc desc ;
5050
#endif
5151
shared_str dbg_name ;
52+
shared_str dbg_shader ;
53+
shared_str dbg_texture ;
54+
shared_str dbg_shader_def ;
55+
shared_str dbg_texture_def ;
5256
virtual shared_str _BCL getDebugName() { return dbg_name; }
57+
virtual LPCSTR _BCL getDebugShader() { return *dbg_shader; }
58+
virtual LPCSTR _BCL getDebugTexture() { return *dbg_texture; }
59+
virtual LPCSTR _BCL getDebugShaderDef() { return *dbg_shader_def; }
60+
virtual LPCSTR _BCL getDebugTextureDef() { return *dbg_texture_def; }
5361
public:
5462
// Common data for rendering
5563
u32 Type; // visual's type
5664
vis_data vis; // visibility-data
5765
ref_shader shader; // pipe state, shared
66+
s32 skinning;
5867

5968
virtual void Render(float LOD)
6069
{
@@ -75,6 +84,9 @@ class ECORE_API dxRender_Visual : public IRenderVisual
7584
// virtual CKinematicsAnimated*dcast_PKinematicsAnimated () { return 0; }
7685
// virtual IParticleCustom* dcast_ParticleCustom () { return 0; }
7786

87+
virtual void SetShaderTexture(LPCSTR shader, LPCSTR texture);
88+
virtual void ResetShaderTexture();
89+
7890
virtual vis_data& _BCL getVisData() { return vis; }
7991
virtual u32 getType() { return Type; }
8092

src/Layers/xrRender/FHierrarhyVisual.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void FHierrarhyVisual::Release()
3737
if (!bDontDelete)
3838
{
3939
for (u32 i = 0; i < children.size(); i++)
40-
children[i]->Release();
40+
((dxRender_Visual*)children[i])->Release();
4141
}
4242
}
4343

@@ -55,7 +55,7 @@ void FHierrarhyVisual::Load(const char* N, IReader* data, u32 dwFlags)
5555
THROW;
5656
#else
5757
u32 ID = data->r_u32();
58-
children[i] = (dxRender_Visual*)::Render->getVisual(ID);
58+
children[i] = ::Render->getVisual(ID);
5959
#endif
6060
}
6161
bDontDelete = TRUE;
@@ -75,7 +75,7 @@ void FHierrarhyVisual::Load(const char* N, IReader* data, u32 dwFlags)
7575
xr_strcpy(short_name, N);
7676
if (strext(short_name)) *strext(short_name) = 0;
7777
strconcat(sizeof(name_load), name_load, short_name, ":", itoa(count, num, 10));
78-
children.push_back((dxRender_Visual*)::Render->model_CreateChild(name_load, O));
78+
children.push_back(::Render->model_CreateChild(name_load, O));
7979
O->close();
8080
O = OBJ->open_chunk(count);
8181
}
@@ -109,7 +109,7 @@ void FHierrarhyVisual::Copy(dxRender_Visual* pSrc)
109109
children.reserve(pFrom->children.size());
110110
for (u32 i = 0; i < pFrom->children.size(); i++)
111111
{
112-
dxRender_Visual* p = (dxRender_Visual*)::Render->model_Duplicate(pFrom->children[i]);
112+
IRenderVisual* p = ::Render->model_Duplicate(pFrom->children[i]);
113113
children.push_back(p);
114114
}
115115
bDontDelete = FALSE;

src/Layers/xrRender/FHierrarhyVisual.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class FHierrarhyVisual : public dxRender_Visual
1313
{
1414
public:
15-
xr_vector<dxRender_Visual*> children;
15+
xr_vector<IRenderVisual*> children;
1616
BOOL bDontDelete;
1717
public:
1818
FHierrarhyVisual();
@@ -25,6 +25,8 @@ class FHierrarhyVisual : public dxRender_Visual
2525
//--DSR-- HeatVision_start
2626
virtual void MarkAsHot(bool is_hot);
2727
//--DSR-- HeatVision_end
28+
29+
virtual xr_vector<IRenderVisual*>* get_children() { return &children; };
2830
};
2931

3032
#endif //FHierrarhyVisualH

src/Layers/xrRender/ModelPool.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ dxRender_Visual* CModelPool::Create(const char* name, IReader* data)
239239
xr_strcpy(low_name, name);
240240
strlwr(low_name);
241241
if (strext(low_name)) *strext(low_name) = 0;
242-
// Msg ("-CREATE %s",low_name);
243-
242+
244243
// 0. Search POOL
245244
POOL_IT it = Pool.find(low_name);
246245
if (it != Pool.end())
@@ -260,8 +259,8 @@ dxRender_Visual* CModelPool::Create(const char* name, IReader* data)
260259
{
261260
// 2. If not found
262261
bAllowChildrenDuplicate = FALSE;
263-
if (data) Base = Instance_Load(low_name, data,TRUE);
264-
else Base = Instance_Load(low_name,TRUE);
262+
if (data) Base = Instance_Load(low_name, data, TRUE);
263+
else Base = Instance_Load(low_name, TRUE);
265264
bAllowChildrenDuplicate = TRUE;
266265
#ifdef _EDITOR
267266
if (!Base) return 0;
@@ -312,7 +311,14 @@ void CModelPool::DeleteInternal(dxRender_Visual* & V, BOOL bDiscard)
312311
REGISTRY_IT it = Registry.find(V);
313312
if (it != Registry.end())
314313
{
315-
// Registry entry found - move it to pool
314+
// Registry entry found - move it to pool and reset changed shader/texture if necessary
315+
xr_vector<IRenderVisual*>* children = V->get_children();
316+
if (children)
317+
for (auto* child : *children)
318+
child->ResetShaderTexture();
319+
else
320+
V->ResetShaderTexture();
321+
316322
Pool.insert(mk_pair(it->second, V));
317323
}
318324
else
@@ -352,8 +358,6 @@ void CModelPool::Discard(dxRender_Visual* & V, BOOL b_complete)
352358
REGISTRY_IT it = Registry.find(V);
353359
if (it != Registry.end())
354360
{
355-
// Pool - OK
356-
357361
// Base
358362
const shared_str& name = it->second;
359363
xr_vector<ModelDef>::iterator I = Models.begin();
@@ -387,7 +391,6 @@ void CModelPool::Discard(dxRender_Visual* & V, BOOL b_complete)
387391
}
388392
// Registry
389393
xr_delete(V);
390-
//. xr_free (name);
391394
Registry.erase(it);
392395
}
393396
else
@@ -420,17 +423,6 @@ void CModelPool::Prefetch_One(LPCSTR N)
420423
Delete(V,FALSE);
421424
}
422425

423-
void CModelPool::ClearPool(BOOL b_complete)
424-
{
425-
POOL_IT _I = Pool.begin();
426-
POOL_IT _E = Pool.end();
427-
for (; _I != _E; _I++)
428-
{
429-
Discard(_I->second, b_complete);
430-
}
431-
Pool.clear();
432-
}
433-
434426
dxRender_Visual* CModelPool::CreatePE(PS::CPEDef* source)
435427
{
436428
PS::CParticleEffect* V = (PS::CParticleEffect*)Instance_Create(MT_PARTICLE_EFFECT);
@@ -445,6 +437,17 @@ dxRender_Visual* CModelPool::CreatePG(PS::CPGDef* source)
445437
return V;
446438
}
447439

440+
void CModelPool::ClearPool(BOOL b_complete)
441+
{
442+
POOL_IT _I = Pool.begin();
443+
POOL_IT _E = Pool.end();
444+
for (; _I != _E; _I++)
445+
{
446+
Discard(_I->second, b_complete);
447+
}
448+
Pool.clear();
449+
}
450+
448451
void CModelPool::dump()
449452
{
450453
Log("--- model pool --- begin:");

src/Layers/xrRender/SkeletonCustom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ void CKinematics::Visibility_Update()
585585
if (!_c->has_visible_bones())
586586
{
587587
// move into invisible list
588-
children_invisible.push_back(children[c_it]);
588+
children_invisible.push_back((dxRender_Visual*)children[c_it]);
589589
swap(children[c_it], children.back());
590590
children.pop_back();
591591
Update_Visibility = TRUE;

0 commit comments

Comments
 (0)