Skip to content

Commit

Permalink
Merge branch 'OpenXRay:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alsed authored Dec 28, 2024
2 parents 7ad00a2 + 94b1f25 commit 06f74a9
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/xrEngine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void CEngine::Initialize(GameModule* game)
Device.seqFrame.Add(&g_sound_processor, REG_PRIORITY_NORMAL - 1000); // Place it after Level update
Device.seqFrameMT.Add(&g_sound_renderer);

External.CreateRendererList();
CheckAndSetupRenderer();

External.Initialize(game);
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/EngineAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ENGINE_API CEngineAPI
CEngineAPI();
~CEngineAPI();

void CreateRendererList();
void CreateRendererList(); // Better to call it in the main thread
void Initialize(GameModule* game);
void Destroy();
};
Expand Down
7 changes: 7 additions & 0 deletions src/xrEngine/key_binding_registrator_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ SCRIPT_EXPORT(KeyBindings, (),
value("kCUSTOM14", int(kCUSTOM14)),
value("kCUSTOM15", int(kCUSTOM15)),

value("kPDA_TAB1", int(kPDA_TAB1)),
value("kPDA_TAB2", int(kPDA_TAB2)),
value("kPDA_TAB3", int(kPDA_TAB3)),
value("kPDA_TAB4", int(kPDA_TAB4)),
value("kPDA_TAB5", int(kPDA_TAB5)),
value("kPDA_TAB6", int(kPDA_TAB6)),

value("kKICK", int(kKICK)),

value("kEDITOR", int(kEDITOR)),
Expand Down
12 changes: 0 additions & 12 deletions src/xrEngine/x_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,6 @@ CApplication::CApplication(pcstr commandLine, GameModule* game)
Engine.Sound.CreateDevicesList();
});

#ifdef XR_PLATFORM_WINDOWS
const auto& createRendererList = TaskManager::AddTask([]
{
Engine.External.CreateRendererList();
});
#endif

pcstr fsltx = "-fsltx ";
string_path fsgame = "";
if (strstr(commandLine, fsltx))
Expand All @@ -270,11 +263,6 @@ CApplication::CApplication(pcstr commandLine, GameModule* game)
TaskScheduler->Wait(inputTask);
InitConsole();

#ifdef XR_PLATFORM_WINDOWS
TaskScheduler->Wait(createRendererList);
#else
Engine.External.CreateRendererList();
#endif
Engine.Initialize(game);
Device.Initialize();

Expand Down
7 changes: 7 additions & 0 deletions src/xrEngine/xr_level_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ game_action actions[] =
{ "custom14", kCUSTOM14, _sp },
{ "custom15", kCUSTOM15, _sp },

{ "pda_tab1", kPDA_TAB1, _sp },
{ "pda_tab2", kPDA_TAB2, _sp },
{ "pda_tab3", kPDA_TAB3, _sp },
{ "pda_tab4", kPDA_TAB4, _sp },
{ "pda_tab5", kPDA_TAB5, _sp },
{ "pda_tab6", kPDA_TAB6, _sp },

{ "kick", kKICK, _sp },

{ "editor", kEDITOR, _both },
Expand Down
7 changes: 7 additions & 0 deletions src/xrEngine/xr_level_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ enum EGameActions : u32
kCUSTOM14,
kCUSTOM15,

kPDA_TAB1,
kPDA_TAB2,
kPDA_TAB3,
kPDA_TAB4,
kPDA_TAB5,
kPDA_TAB6,

kKICK, // alpet: kick dynamic objects

kEDITOR,
Expand Down
12 changes: 6 additions & 6 deletions src/xrGame/HudSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ void HUD_SOUND_COLLECTION_LAYERED::LoadSound(pcstr section, pcstr line, pcstr al
{
ZoneScoped;

if (!pSettings->line_exist(section, line))
return;

pcstr str = pSettings->r_string(section, line);
string256 buf_str;

int count = _GetItemCount(str);
R_ASSERT(count);

_GetItem(str, 0, buf_str);

if (pSettings->section_exist(buf_str))
Expand Down Expand Up @@ -271,12 +271,12 @@ void HUD_SOUND_COLLECTION_LAYERED::LoadSound(CInifile const *ini, pcstr section,
{
ZoneScoped;

if (!pSettings->line_exist(section, line))
return;

pcstr str = ini->r_string(section, line);
string256 buf_str;

int count = _GetItemCount(str);
R_ASSERT(count);

_GetItem(str, 0, buf_str);

if (ini->section_exist(buf_str))
Expand Down
18 changes: 13 additions & 5 deletions src/xrGame/WeaponMagazined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ void CWeaponMagazined::Load(LPCSTR section)
if (WeaponSoundExist(section, "snd_reload_misfire"))
m_sounds.LoadSound(section, "snd_reload_misfire", "sndReloadMisfire", true, m_eSoundReloadMisfire);

m_sSndShotCurrent = IsSilencerAttached() ? "sndSilencerShot" : "sndShot";

//звуки и партиклы глушителя, если такой есть
if (m_eSilencerStatus == ALife::eAddonAttachable || m_eSilencerStatus == ALife::eAddonPermanent)
{
Expand All @@ -101,6 +99,11 @@ void CWeaponMagazined::Load(LPCSTR section)
//-Alundaio
}

if (IsSilencerAttached() && m_layered_sounds.FindSoundItem("sndSilencerShot", false))
m_sSndShotCurrent = "sndSilencerShot";
else
m_sSndShotCurrent = "sndShot";

m_iBaseDispersionedBulletsCount = READ_IF_EXISTS(pSettings, r_u8, section, "base_dispersioned_bullets_count", 0);
m_fBaseDispersionedBulletsSpeed =
READ_IF_EXISTS(pSettings, r_float, section, "base_dispersioned_bullets_speed", m_fStartBulletSpeed);
Expand Down Expand Up @@ -1064,15 +1067,16 @@ void CWeaponMagazined::InitAddons()
}
}

if (IsSilencerAttached() /* && SilencerAttachable() */)
const bool silencer = IsSilencerAttached();

if (silencer && m_layered_sounds.FindSoundItem("sndSilencerShot", false))
{
m_sFlameParticlesCurrent = m_sSilencerFlameParticles;
m_sSmokeParticlesCurrent = m_sSilencerSmokeParticles;
m_sSndShotCurrent = "sndSilencerShot";

//подсветка от выстрела
LoadLights(*cNameSect(), "silencer_");
ApplySilencerKoeffs();
}
else
{
Expand All @@ -1082,9 +1086,13 @@ void CWeaponMagazined::InitAddons()

//подсветка от выстрела
LoadLights(*cNameSect(), "");
ResetSilencerKoeffs();
}

if (silencer)
ApplySilencerKoeffs();
else
ResetSilencerKoeffs();

inherited::InitAddons();
}

Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/quadtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CQuadTree
virtual ~CFixedStorage() { xr_free(m_objects); }
IC T* get_object()
{
VERIFY(m_free);
R_ASSERT1_CURE(m_free, { return nullptr; });
T* node = m_free;
m_free = m_free->next();
ZeroMemory(node, sizeof(T));
Expand Down
41 changes: 25 additions & 16 deletions src/xrGame/script_game_object3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ void CScriptGameObject::set_desired_direction(const Fvector* desired_direction)
if (fsimilar(desired_direction->magnitude(), 0.f))
GEnv.ScriptEngine->script_log(LuaMessageType::Error,
"CAI_Stalker : [%s] set_desired_direction - you passed zero direction!", stalker->cName().c_str());
else if (!ClearSkyMode && !ShadowOfChernobylMode)
else if (!ShadowOfChernobylMode)
{
if (!fsimilar(desired_direction->magnitude(), 1.f))
GEnv.ScriptEngine->script_log(LuaMessageType::Error,
Expand All @@ -601,7 +601,7 @@ void CScriptGameObject::set_desired_direction(const Fvector* desired_direction)
}

Fvector direction = *desired_direction;
if (!ClearSkyMode && !ShadowOfChernobylMode)
if (!ShadowOfChernobylMode)
direction.normalize_safe();
stalker->movement().set_desired_direction(&direction);
}
Expand Down Expand Up @@ -767,12 +767,15 @@ void CScriptGameObject::set_sight(SightManager::ESightType sight_type, Fvector*
}
else
{
if ((sight_type == SightManager::eSightTypeDirection) && vector3d && (_abs(vector3d->magnitude() - 1.f) > .01f))
const bool check_for_norm = sight_type == SightManager::eSightTypeDirection && vector3d &&
!ClearSkyMode && !ShadowOfChernobylMode;
if (check_for_norm)
{
#ifndef MASTER_GOLD
Msg("~ CSightManager : non-normalized direction passed [%f][%f][%f]", VPUSH(*vector3d));
#endif
vector3d->normalize();
if (_abs(vector3d->magnitude() - 1.f) > .01f)
{
VERIFY2(false, make_string("non-normalized direction passed [%f][%f][%f]", VPUSH(*vector3d)));
vector3d->normalize();
}
}

stalker->sight().setup(sight_type, vector3d);
Expand All @@ -798,12 +801,15 @@ void CScriptGameObject::set_sight(SightManager::ESightType sight_type, Fvector&
}
else
{
if ((sight_type == SightManager::eSightTypeDirection) && (_abs(vector3d.magnitude() - 1.f) > .01f))
const bool check_for_norm = sight_type == SightManager::eSightTypeDirection &&
!ClearSkyMode && !ShadowOfChernobylMode;
if (check_for_norm)
{
#ifndef MASTER_GOLD
Msg("~ CSightManager : non-normalized direction passed [%f][%f][%f]", VPUSH(vector3d));
#endif
if (_abs(vector3d.magnitude() - 1.f) > .01f)
{
VERIFY2(false, make_string("non-normalized direction passed [%f][%f][%f]", VPUSH(vector3d)));
vector3d.normalize();
}
}

stalker->sight().setup(sight_type, vector3d, torso_look);
Expand All @@ -819,12 +825,15 @@ void CScriptGameObject::set_sight(SightManager::ESightType sight_type, Fvector*
}
else
{
if ((sight_type == SightManager::eSightTypeDirection) && vector3d && (_abs(vector3d->magnitude() - 1.f) > .01f))
const bool check_for_norm = sight_type == SightManager::eSightTypeDirection && vector3d &&
!ClearSkyMode && !ShadowOfChernobylMode;
if (check_for_norm)
{
#ifndef MASTER_GOLD
Msg("~ CSightManager : non-normalized direction passed [%f][%f][%f]", VPUSH(*vector3d));
#endif
vector3d->normalize();
if (_abs(vector3d->magnitude() - 1.f) > .01f)
{
VERIFY2(false, make_string("non-normalized direction passed [%f][%f][%f]", VPUSH(*vector3d)));
vector3d->normalize();
}
}

stalker->sight().setup(sight_type, vector3d);
Expand Down
15 changes: 15 additions & 0 deletions src/xrScriptEngine/script_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,21 @@ void CScriptEngine::init(ExporterFunc exporterFunc, bool loadGlobalNamespace)
luaL_dostring(lua(), mathRandom);
}

// Adds gamedata folder as module root for lua `require` and allows usage of built-in lua module system.
// Notes:
// - Does not resolve files inside archived game files
// Example:
// `local example = require("scripts.folder.file")` tries to import `gamedata\scripts\folder\file.script`
{
string_path gamedataPath;
string_path packagePath;

FS.update_path(gamedataPath, "$game_data$", "?.script;");
xr_sprintf(packagePath, "package.path = package.path .. [[%s]]", gamedataPath);

luaL_dostring(lua(), packagePath);
}

// XXX nitrocaster: with vanilla scripts, '-nojit' option requires script profiler to be disabled. The reason
// is that lua hooks somehow make 'super' global unavailable (is's used all over the vanilla scripts).
// You can disable script profiler by commenting out the following lines in the beginning of _g.script:
Expand Down

0 comments on commit 06f74a9

Please sign in to comment.