Skip to content

Commit

Permalink
Some changes
Browse files Browse the repository at this point in the history
-Cut xrD3D9-Null
-Move SS shader cache to the separate folder
-Some optimizations
-Export Visual Memory Menager to lua
  • Loading branch information
OneMorePseudoCoder committed Feb 22, 2024
1 parent ce551c1 commit 1685dad
Show file tree
Hide file tree
Showing 49 changed files with 77 additions and 3,414 deletions.
16 changes: 16 additions & 0 deletions res/gamedata/scripts/visual_memory_manager.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Visual Memory Manager exports
-- by Alundaio

-- called from engine
-- This occurs during the visible check. If value >= visiblity_threshold then object is considered visible
-- warning npc and who can be nil sometimes
function get_visible_value(npc, who, time_delta, time_quant, luminocity, velocity_factor, velocity, distance, object_distance, always_visible_distance)
distance = distance <= 0 and 0.00001 or distance
luminocity = luminocity <= 0 and 0.0001 or luminocity

-- if (level_weathers.bLevelUnderground) then
-- luminocity = luminocity + 0.35
-- end

return time_delta / time_quant * luminocity * (1 + velocity_factor * velocity) * (distance - object_distance) / distance
end
12 changes: 4 additions & 8 deletions src/Layers/xrRenderPC_R2/r2_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include "xrCore/FileCRC32.h"

template <typename T>
static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name,
T*& result, bool const disasm)
static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name, T*& result, bool const disasm)
{
HRESULT _hr = ShaderTypeTraits<T>::CreateHWShader(buffer, buffer_size, result->sh);
if (FAILED(_hr))
Expand Down Expand Up @@ -46,8 +45,7 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
return _hr;
}

inline HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name,
void*& result, bool const disasm)
inline HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 const buffer_size, LPCSTR const file_name, void*& result, bool const disasm)
{
if (pTarget[0] == 'p')
return create_shader(pTarget, buffer, buffer_size, file_name, (SPS*&)result, disasm);
Expand All @@ -59,8 +57,7 @@ inline HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, u32 cons
return E_FAIL;
}

HRESULT CRender::shader_compile(
pcstr name, IReader* fs, pcstr pFunctionName, pcstr pTarget, u32 Flags, void*& result)
HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName, pcstr pTarget, u32 Flags, void*& result)
{
SHADER_MACRO defines[128];
int def_it = 0;
Expand Down Expand Up @@ -495,8 +492,7 @@ HRESULT CRender::shader_compile(
#ifdef DEBUG
Log("* Loading shader:", file_name);
#endif
_result =
create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), filename, result, o.disasm);
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), filename, result, o.disasm);
}
}
}
Expand Down
21 changes: 7 additions & 14 deletions src/Layers/xrRenderPC_R4/r4_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ void CRender::addShaderOption(const char* name, const char* value)
}

template <typename T>
static HRESULT create_shader(DWORD const* buffer, size_t const buffer_size, LPCSTR const file_name,
T*& result, bool const dx9compatibility)
static HRESULT create_shader(DWORD const* buffer, size_t const buffer_size, LPCSTR const file_name, T*& result, bool const dx9compatibility)
{
HRESULT _hr = ShaderTypeTraits<T>::CreateHWShader(buffer, buffer_size, result->sh);
if (!SUCCEEDED(_hr))
Expand Down Expand Up @@ -47,8 +46,7 @@ static HRESULT create_shader(DWORD const* buffer, size_t const buffer_size, LPCS
return _hr;
}

static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, size_t const buffer_size, LPCSTR const file_name,
void*& result, bool const disasm, bool dx9compatibility)
static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, size_t const buffer_size, LPCSTR const file_name, void*& result, bool const disasm, bool dx9compatibility)
{
HRESULT _result = E_FAIL;
pcstr extension = ".hlsl";
Expand Down Expand Up @@ -120,8 +118,7 @@ static HRESULT create_shader(LPCSTR const pTarget, DWORD const* buffer, size_t c
class includer : public ID3DInclude
{
public:
HRESULT __stdcall Open(
D3D10_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes)
HRESULT __stdcall Open(D3D10_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes)
{
string_path pname;
strconcat(pname, RImplementation.getShaderPath(), pFileName);
Expand Down Expand Up @@ -212,8 +209,7 @@ class shader_options_holder
D3D_SHADER_MACRO* data() { return m_options; }
};

HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName,
pcstr pTarget, u32 Flags, void*& result)
HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName, pcstr pTarget, u32 Flags, void*& result)
{
shader_options_holder options;
shader_name_holder sh_name;
Expand Down Expand Up @@ -516,7 +512,7 @@ HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName,

pcstr renderer;
if (HW.FeatureLevel >= D3D_FEATURE_LEVEL_11_0)
renderer = "r4" DELIMITER;
renderer = o.new_shader_support ? "r5" DELIMITER : "r4" DELIMITER;
else if (HW.FeatureLevel >= D3D_FEATURE_LEVEL_10_0)
renderer = "r3" DELIMITER;
else
Expand Down Expand Up @@ -560,9 +556,7 @@ HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName,
#ifdef DEBUG
Log("* Loading shader:", file_name);
#endif
_result =
create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(),
filename, result, o.disasm, dx9compatibility);
_result = create_shader(pTarget, (DWORD*)file->pointer(), file->elapsed(), filename, result, o.disasm, dx9compatibility);
}
}
}
Expand All @@ -584,8 +578,7 @@ HRESULT CRender::shader_compile(pcstr name, IReader* fs, pcstr pFunctionName,
{
pErrorBuf = nullptr;
Flags |= D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
_result = HW.D3DCompile(fs->pointer(), fs->length(), "", options.data(),
&Includer, pFunctionName, pTarget, Flags, 0, &pShaderBuf, &pErrorBuf);
_result = HW.D3DCompile(fs->pointer(), fs->length(), "", options.data(), &Includer, pFunctionName, pTarget, Flags, 0, &pShaderBuf, &pErrorBuf);
}
}

Expand Down
30 changes: 11 additions & 19 deletions src/Layers/xrRender_R2/r2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,15 @@ static class cl_pos_decompress_params : public R_constant_setup
#else
# error No graphics API selected or enabled!
#endif
cmd_list.set_c(
C, HorzTan, VertTan, (2.0f * HorzTan) / (float)Device.dwWidth, (2.0f * VertTan) / (float)Device.dwHeight);
cmd_list.set_c(C, HorzTan, VertTan, (2.0f * HorzTan) / (float)Device.dwWidth, (2.0f * VertTan) / (float)Device.dwHeight);
}
} binder_pos_decompress_params;

static class cl_pos_decompress_params2 : public R_constant_setup
{
void setup(CBackend& cmd_list, R_constant* C) override
{
cmd_list.set_c(C, (float)Device.dwWidth, (float)Device.dwHeight, 1.0f / (float)Device.dwWidth,
1.0f / (float)Device.dwHeight);
cmd_list.set_c(C, (float)Device.dwWidth, (float)Device.dwHeight, 1.0f / (float)Device.dwWidth, 1.0f / (float)Device.dwHeight);
}
} binder_pos_decompress_params2;

Expand Down Expand Up @@ -622,7 +620,6 @@ void CRender::create()
// TODO: OGL: Implement FluidManager.
#if defined(USE_DX11)
FluidManager.Initialize(70, 70, 70);
// FluidManager.Initialize( 100, 100, 100 );
FluidManager.SetScreenSize(Device.dwWidth, Device.dwHeight);
#endif
}
Expand Down Expand Up @@ -675,9 +672,7 @@ void CRender::reset_begin()
}

//AVO: let's reload details while changed details options on vid_restart
if (b_loaded && (dm_current_size != dm_size ||
!fsimilar(ps_r__Detail_density, ps_current_detail_density) ||
!fsimilar(ps_r__Detail_height, ps_current_detail_height)))
if (b_loaded && (dm_current_size != dm_size || !fsimilar(ps_r__Detail_density, ps_current_detail_density) || !fsimilar(ps_r__Detail_height, ps_current_detail_height)))
{
Details->Unload();
xr_delete(Details);
Expand All @@ -697,9 +692,7 @@ void CRender::reset_end()
Target = xr_new<CRenderTarget>();

//AVO: let's reload details while changed details options on vid_restart
if (b_loaded && (dm_current_size != dm_size ||
!fsimilar(ps_r__Detail_density, ps_current_detail_density) ||
!fsimilar(ps_r__Detail_height, ps_current_detail_height)))
if (b_loaded && (dm_current_size != dm_size || !fsimilar(ps_r__Detail_density, ps_current_detail_density) || !fsimilar(ps_r__Detail_height, ps_current_detail_height)))
{
Details = xr_new<CDetailManager>();
Details->Load();
Expand Down Expand Up @@ -733,8 +726,7 @@ void CRender::OnFrame()
if (ps_r2_ls_flags.test(R2FLAG_EXP_MT_CALC))
{
// MT-details (@front)
Device.seqParallel.insert(
Device.seqParallel.begin(), fastdelegate::FastDelegate0<>(Details, &CDetailManager::MT_CALC));
Device.seqParallel.insert(Device.seqParallel.begin(), fastdelegate::FastDelegate0<>(Details, &CDetailManager::MT_CALC));
}

if (Details)
Expand All @@ -749,8 +741,7 @@ IRender::RenderContext CRender::GetCurrentContext() const

void CRender::MakeContextCurrent(RenderContext context)
{
R_ASSERT3(HW.MakeContextCurrent(context) == 0,
"Failed to switch OpenGL context", SDL_GetError());
R_ASSERT3(HW.MakeContextCurrent(context) == 0, "Failed to switch OpenGL context", SDL_GetError());
}
#endif

Expand Down Expand Up @@ -803,13 +794,17 @@ IRenderVisual* CRender::model_CreateParticles(LPCSTR name)
R_ASSERT3(SG, "Particle effect or group doesn't exist", name);
return Models->CreatePG(SG);
}

void CRender::models_Prefetch() { Models->Prefetch(); }

void CRender::models_Clear(bool b_complete) { Models->ClearPool(b_complete); }

ref_shader CRender::getShader(int id)
{
VERIFY(id < int(Shaders.size()));
return Shaders[id];
}

IRenderVisual* CRender::getVisual(int id)
{
VERIFY(id < int(Visuals.size()));
Expand Down Expand Up @@ -929,10 +924,7 @@ void CRender::rmNormal(CBackend& cmd_list)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRender::CRender()
: Sectors_xrc("render")
{
}
CRender::CRender() : Sectors_xrc("render") {}

CRender::~CRender() {}

Expand Down
40 changes: 0 additions & 40 deletions src/engine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XR_3DA", "xr_3da\xr_3da.vcx
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "utils", "utils", "{89F6A7EE-3BBE-45D3-A8A8-5D9366CD987B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dedicated", "dedicated", "{3FC858CB-4888-42FF-ABC5-82DAECB59C2C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Externals", "Externals", "{2BFC806B-CE92-4EA4-8FE8-5F2EA54BA348}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ODE", "..\Externals\ODE.vcxproj", "{1BF75FEB-87DD-486C-880B-227987D191C2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xrD3D9-Null", "xrD3D9-Null\xrD3D9-Null.vcxproj", "{0899B131-F1D4-4876-9BA1-67AC821DB9E1}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CompressionTest", "utils\CompressionTest\CompressionTest.vcxproj", "{C961EA19-716C-4A6D-BB13-689F8FB78B01}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ctool", "utils\ctool\ctool.vcxproj", "{2FAAC8BA-369F-465E-B465-2235963FD377}"
Expand Down Expand Up @@ -54,9 +50,6 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xrParticles", "xrParticles\xrParticles.vcxproj", "{94A1C366-3D19-48E6-8170-4ADC2E70DF97}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xrRender_R1", "Layers\xrRenderPC_R1\xrRender_R1.vcxproj", "{57A498C9-A741-4DDF-8EFC-BFB9EB6B00E2}"
ProjectSection(ProjectDependencies) = postProject
{0899B131-F1D4-4876-9BA1-67AC821DB9E1} = {0899B131-F1D4-4876-9BA1-67AC821DB9E1}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xrRender_R2", "Layers\xrRenderPC_R2\xrRender_R2.vcxproj", "{963BA4E5-499A-454D-B002-1D5ECE0527A6}"
EndProject
Expand Down Expand Up @@ -238,38 +231,6 @@ Global
{1BF75FEB-87DD-486C-880B-227987D191C2}.Release|x64.Build.0 = Release|x64
{1BF75FEB-87DD-486C-880B-227987D191C2}.Release|x86.ActiveCfg = Release|Win32
{1BF75FEB-87DD-486C-880B-227987D191C2}.Release|x86.Build.0 = Release|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Debug|ARM.ActiveCfg = Debug|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Debug|ARM.Build.0 = Debug|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Debug|ARM64.ActiveCfg = Debug|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Debug|ARM64.Build.0 = Debug|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Debug|x64.ActiveCfg = Debug|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Debug|x64.Build.0 = Debug|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Debug|x86.ActiveCfg = Debug|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Debug|x86.Build.0 = Debug|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Mixed|ARM.ActiveCfg = Mixed|ARM
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Mixed|ARM.Build.0 = Mixed|ARM
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Mixed|ARM64.ActiveCfg = Mixed|ARM64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Mixed|ARM64.Build.0 = Mixed|ARM64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Mixed|x64.ActiveCfg = Mixed|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Mixed|x64.Build.0 = Mixed|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Mixed|x86.ActiveCfg = Mixed|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Mixed|x86.Build.0 = Mixed|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release Master Gold|ARM.ActiveCfg = Release Master Gold|ARM
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release Master Gold|ARM.Build.0 = Release Master Gold|ARM
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release Master Gold|ARM64.ActiveCfg = Release Master Gold|ARM64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release Master Gold|ARM64.Build.0 = Release Master Gold|ARM64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release Master Gold|x64.ActiveCfg = Release Master Gold|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release Master Gold|x64.Build.0 = Release Master Gold|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release Master Gold|x86.ActiveCfg = Release Master Gold|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release Master Gold|x86.Build.0 = Release Master Gold|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release|ARM.ActiveCfg = Release|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release|ARM.Build.0 = Release|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release|ARM64.ActiveCfg = Release|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release|ARM64.Build.0 = Release|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release|x64.ActiveCfg = Release|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release|x64.Build.0 = Release|x64
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release|x86.ActiveCfg = Release|Win32
{0899B131-F1D4-4876-9BA1-67AC821DB9E1}.Release|x86.Build.0 = Release|Win32
{C961EA19-716C-4A6D-BB13-689F8FB78B01}.Debug|ARM.ActiveCfg = Debug|Win32
{C961EA19-716C-4A6D-BB13-689F8FB78B01}.Debug|ARM.Build.0 = Debug|Win32
{C961EA19-716C-4A6D-BB13-689F8FB78B01}.Debug|ARM64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -2053,7 +2014,6 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{1BF75FEB-87DD-486C-880B-227987D191C2} = {2BFC806B-CE92-4EA4-8FE8-5F2EA54BA348}
{0899B131-F1D4-4876-9BA1-67AC821DB9E1} = {3FC858CB-4888-42FF-ABC5-82DAECB59C2C}
{C961EA19-716C-4A6D-BB13-689F8FB78B01} = {89F6A7EE-3BBE-45D3-A8A8-5D9366CD987B}
{2FAAC8BA-369F-465E-B465-2235963FD377} = {89F6A7EE-3BBE-45D3-A8A8-5D9366CD987B}
{65CBB9D0-FBC6-41A4-8316-F5E9B5D7FB33} = {89F6A7EE-3BBE-45D3-A8A8-5D9366CD987B}
Expand Down
5 changes: 3 additions & 2 deletions src/xrCDB/xrCDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ MODEL::MODEL() :
verts = 0;
verts_count = 0;
status = S_INIT;
version = 0;
}

MODEL::~MODEL()
{
syncronize(); // maybe model still in building
Expand Down Expand Up @@ -69,7 +71,6 @@ void MODEL::build_thread(void* params)
P.M->build_internal(P.V, P.Vcnt, P.T, P.Tcnt, P.BC, P.BCP);
P.M->status = S_READY;
P.M->pcs->Leave();
// Msg ("* xrCDB: cform build completed, memory usage: %d K",P.M->memory()/1024);
}

void MODEL::build(Fvector* V, int Vcnt, TRI* T, int Tcnt, build_callback* bc, void* bcp)
Expand Down Expand Up @@ -197,7 +198,7 @@ bool MODEL::serialize(pcstr fileName, serialize_callback callback /*= nullptr*/)
return true;
}

bool MODEL::deserialize(pcstr fileName, bool checkCrc32 /*= true*/, deserialize_callback callback /*= nullptr*/)
bool MODEL::deserialize(pcstr fileName, bool checkCrc32, deserialize_callback callback)
{
IReader* rstream = FS.r_open(fileName);
if (!rstream)
Expand Down
Loading

0 comments on commit 1685dad

Please sign in to comment.