Skip to content

Added the new "volume_mult" property for HUD sound call back. Removed all indoor framework related engine side code#338

Merged
themrdemonized merged 7 commits intothemrdemonized:kutezfrom
Kutez:all-in-one-vs2022-wpo
Aug 19, 2025
Merged

Added the new "volume_mult" property for HUD sound call back. Removed all indoor framework related engine side code#338
themrdemonized merged 7 commits intothemrdemonized:kutezfrom
Kutez:all-in-one-vs2022-wpo

Conversation

@Kutez
Copy link
Contributor

@Kutez Kutez commented Aug 16, 2025

Add the new volume_mult for on_before_play_hud_sound callback. You can use it to change the volume of any hud sound, with or without replacing the sound itself. (more info in the callbacks_gameobject.script)
Example:

	if alias == "sndShot" and parent and parent:id() == AC_ID then
		result.section = "wpn_l96a1_sounds"
		result.line = "snd_shoot"
		result.volume_mult = 0.75 -- Multiply the new fire sound's volume by 0.75
	end

Or:

	if alias == "sndShot" and parent and parent:id() == AC_ID then
		result.volume_mult = 0.5 -- Multiply the old fire sound's volume by 0.5
	end

Also removed all indoor framework related engine side code become the project the move to Lua and rely on the callback.

Removed all indoor sound's related engine side code, the project will move to Lua now.
@Kutez Kutez changed the title Added the new volume_mult property to control hud sound's volume_mult. Removed all indoor framework related engine side code Added the new volume_mult property for on_before_play_hud_soun call back. Removed all indoor framework related engine side code Aug 16, 2025
@Kutez Kutez changed the title Added the new volume_mult property for on_before_play_hud_soun call back. Removed all indoor framework related engine side code Added the new volume_mult property for on_before_play_hud_sound call back. Removed all indoor framework related engine side code Aug 16, 2025
@Kutez
Copy link
Contributor Author

Kutez commented Aug 16, 2025

Sorry for the long ass title lol

@Kutez Kutez force-pushed the all-in-one-vs2022-wpo branch from 78ab047 to 60dd34f Compare August 16, 2025 12:57
@Kutez
Copy link
Contributor Author

Kutez commented Aug 16, 2025

Known bug, ::luabind::object_cast<float> return nil when the value is 0 for some reason, others worked fine.

@Kutez Kutez closed this Aug 16, 2025
@themrdemonized
Copy link
Owner

By the looks of it should work fine. Maybe you can set the default value of volume multiplier to 1 instead of nil, that way you wouldn't need a nil check

@Kutez
Copy link
Contributor Author

Kutez commented Aug 17, 2025

It still doesn't solve the problem of when the property is 0, ::luabind::object_cast<float> will just return nil. I will do some hack to see if it works

@Kutez Kutez changed the title Added the new volume_mult property for on_before_play_hud_sound call back. Removed all indoor framework related engine side code Added the new "volume_mult" property for HUD sound call back. Removed all indoor framework related engine side code Aug 17, 2025
@Kutez Kutez reopened this Aug 17, 2025
@Kutez
Copy link
Contributor Author

Kutez commented Aug 17, 2025

Ok I was wrong, it does return 0 but idk that in C++, not (a 0 float value) return true

@Kutez Kutez force-pushed the all-in-one-vs2022-wpo branch 2 times, most recently from 0b1751f to 04ac146 Compare August 17, 2025 13:18
@Kutez
Copy link
Contributor Author

Kutez commented Aug 17, 2025

Apparently, a 0.f is the same as NULL, so there is no way afaik I can distinct them, I will just put a notice. God this driving me crazy.

Copy link
Contributor

@Xottab-DUTY Xottab-DUTY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing floats with 0 directly is potentially erroneous/inaccurate due to how floats work in hardware.
X-Ray has a special function fis_zero to check if a float is zero and it's always better to use it.

0.f is the same as NULL

It is not, but luabind automatically converts nil to 0.f. It's possible to avoid that.

{
Msg("!_G.COnBeforePlayHudSound callback, HUD_SOUND_COLLECTION_LAYERED::PlaySound, failed to override sound item %s, no section specified", alias);
}
if (!volume_mult_ex) {
Copy link
Contributor

@Xottab-DUTY Xottab-DUTY Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!volume_mult_ex) {
if (fis_zero(volume_mult_ex))
{

{
Msg("!_G.COnBeforePlayHudSound callback, HUD_SOUND_COLLECTION_LAYERED::PlaySound, failed to override sound item %s, no line specified", alias);
}
if (!volume_mult_ex) {
Copy link
Contributor

@Xottab-DUTY Xottab-DUTY Aug 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!volume_mult_ex) {
if (fis_zero(volume_mult_ex))
{

m_sounds.LoadSound(section, "snd_shoot_actor", "sndShotActor", false, m_eSoundShot);

//-Alundaio

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@Xottab-DUTY
Copy link
Contributor

Xottab-DUTY commented Aug 17, 2025

It's possible to avoid that.

To detect if Lua's volume_mult is actually nil, don't do luabind::object_cast immediately.
Here's an example:

auto volume_mult_ex_obj = output["volume_mult"]; // receive Lua object
bool volume_mult_ex_is_nil = luabind::type(volume_mult_ex_obj) == LUA_TNIL; // the actual check for nil
float volume_mult_ex = ::luabind::object_cast<float>(volume_mult_ex_obj); // receive the actual value. nil will be converted to 0.f automatically

Then, you can use volume_mult_ex_is_nil in places where fis_zero is not enough and you need exactly nil checking.

@Kutez Kutez force-pushed the all-in-one-vs2022-wpo branch from 08abb20 to da8e2c6 Compare August 17, 2025 14:12
@themrdemonized themrdemonized marked this pull request as draft August 17, 2025 21:58
@themrdemonized
Copy link
Owner

let me know when its ready for review

Test Fix

Solved by Xottab_DUTY

Co-Authored-By: Sultan Luchezarniy <Xottab-DUTY@users.noreply.github.com>
@Kutez Kutez force-pushed the all-in-one-vs2022-wpo branch from 8731483 to 6f3006b Compare August 18, 2025 01:16
@Kutez
Copy link
Contributor Author

Kutez commented Aug 18, 2025

@themrdemonized ready for review, thanks

@themrdemonized themrdemonized changed the base branch from all-in-one-vs2022-wpo to kutez August 19, 2025 00:40
@themrdemonized themrdemonized marked this pull request as ready for review August 19, 2025 00:40
@themrdemonized themrdemonized merged commit be0f2f0 into themrdemonized:kutez Aug 19, 2025
9 of 10 checks passed
@themrdemonized
Copy link
Owner

I made a commit that simplifies the volume_mult logic b39e5c5

themrdemonized added a commit that referenced this pull request Jan 24, 2026
Added the new "volume_mult" property for HUD sound call back. Removed all indoor framework related engine side code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants