-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send sound to players which comes to hear distance. #14342
base: master
Are you sure you want to change the base?
Conversation
|
I do not know how many sounds are common there per player.
So, I should not do this Sounds like a good solution?
Done.
I will update doc and features. |
You could at least do the iteration through the sounds in the outer loop, and early ignore non-max-hear-distance sounds.
Link pasted by mistake? If non-looped sounds don't appear if no player is near, I'd get very confused as modder and consider it as bug. This and the change in behavior would be enough conceptual issues for me to give up, tbh. |
Question for core developers: Situation:
|
The server does currently not have any media library dependencies (PNG, OGG), and I think that's OK for simplicity. Option 2 would IMO be the most reasonable approach because the sound could not be played to anyone. |
One more thought: Imagine 2 players. One with low latency (< 10 ms), another with more than a server tick. To reduce this issue, adding an additional time offset of the player's RTT could be considered. A better solution would be to no longer play back sounds after the first "done" packet is received. |
@SmallJoker There will probably have to be added some field to sound parameters to say, how long should sound wait before allow removeal. |
Please rebase. Now that #14341 is merged, I will dedicate some time to reviewing this, so that we can properly fix this. |
f043788
to
24c7d00
Compare
806c14f
to
72f9d3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar, documentation.
I did yet not have the chance to test the PR's functionality but overall the code seems to make sense.
@@ -5435,6 +5440,9 @@ Utilities | |||
-- Allow passing an optional "actor" ObjectRef to the following functions: | |||
-- minetest.place_node, minetest.dig_node, minetest.punch_node (5.9.0) | |||
node_interaction_actor = true, | |||
-- Sounds can be send to players which comes to hear distance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- Sounds can be send to players which comes to hear distance. | |
-- Sounds can be sent to players who come within hearing distance. |
max_hear_distance = 32,
- -- Only play for players that are at most this far away when the sound
- -- starts playing.
+ -- Only play for players that are at most this far away.
+ -- bla bla bla, see `sounds_updating` Please don't return 0 to indicate failure. If mods compare handles to Edit: |
if (pos.getDistanceFrom(plrsao->getBasePosition()) <= psound.max_hear_distance) { | ||
/* If client remove sound in hear distance, | ||
we are sure, that sound has been fully played. */ | ||
psound.done_clients.insert(peer_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic seems brittle to me: The positions on server and client may not be perfectly in sync, for example due to attached sounds, meaning that this check can't accurately match what the client is doing.
The straightforward fix might be to have the client additionally tell us why a sound was removed (whether it was removed for going out of range or for reaching the end of playback) by extending the packet. For older clients, we could still keep this hack as a decent approximation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no packet sent when the client comes out of the sound range. The Sound continues playing.
Clients generate stop sound packets only if the playing sound is finished on the client side. When sound is removed due to server request, no stop sound packet is generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More testing is needed to remove this condition because I see unexpected changes in behaviors after removing it.
BTW: Before #14341, sound removal after object delete was not processed on the server side and there was a packet sent from client to server.
src/server.h
Outdated
// used for update spec.start_time when sending sound to new client | ||
float start_time; | ||
// hold time limit for sound sending to new clients | ||
float keep_time; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am slightly worried about this being a float
due to potential precision issues (quick back of the napkin math suggests after 2^24 / 60 / 60 / 24 / 30
, so approximately seven months, you will lose a second of precision). I'd bump this (and m_playing_sound_time
) to a double
, or perhaps even a std::chrono::duration
just to be sure. I'm also not sure how accurate dtime
is, so I would consider using the system clock via std::chrono
to get more accurate timestamps. Thoughts?
(Side note: This is tangentially related to the more general question of how we want to synchronize client and server.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I would suggest the use of m_game_time
and m_game_time_fraction_counter
from the ServerEnvironment
class.
Does it look fine for you?
6e8cb50
to
72f9d3b
Compare
Oh, I haven't looked well enough what
What is new is that it now makes a difference if it fails. In master, you don't have to check if it failed, because it makes no difference if you call API functions with -1, and you don't have any effects if a sound exists server side or not.
If Maybe rename
They can manually send the sound to the nearby players, and manage it themselves.
(I consider #3559 a missing feature, not a bug.) |
@appgurueu @Desour If you play a long sound without To prevent this, I added So from my side of view Or do you have a different idea of how to fix this? |
doc/lua_api.md
Outdated
@@ -1099,6 +1099,11 @@ Table used to specify how a sound is played: | |||
|
|||
-- Available since feature `sound_params_start_time`. | |||
|
|||
keep_time = 0.0, | |||
-- Define time window which allow sound to be sent to players |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a good suggestion but it feels like we're trading one hack¹ for another by adding this parameter.
Maybe the server should just track all sounds for a duration of 10 minutes and automatically re-send them? It would be up to the client to skip sounds where start_time >= sound_length
¹: max_hear_distance
is the previous hack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used 600s as the default keep_time
value in the last version.
Please see: #14342 (comment) Maybe it needs to be discussed more between core developers to find a good solution with the consensus. |
See #14342 (comment), No problem with changing this behavior. But I have to know what core developers want. Now there is one core developer vote for returning failure and one vote for adding sound to sounds for at least |
Note that this is barely possible. If a server doesn't have a sound, the client can still get it from the user's sound pack. The server never sees the sound in this case.
This here.
Pros/Goals:
Idk if my gibberish makes sense to you. |
Don't look like a supported solution, because without some actions, bug #3559 does not disappear.
I prefer this solution, but there are also opposite opinions.
What is the expected situation when this can be used?
|
If the mod uses inf, the server would never itself drop the sound. It will live until you call (We could also have an API, where only the values 0 and inf are allowed (or false and true). Instead of providing a time limit, the modder can user core.after.) |
The looped sound behaves like |
I've seen mods that add a music player where the sound is not looped. With un-automatically-removable sounds, you could just stop the sound when the music player is stopped, or it's unloaded. The modder wouldn't have to take the sound length into account. |
You can stop every sound manually if you do not start it as With that information in the packet, it can be possible to use |
Re #14342 (comment): Like appgurueu and Desour seem to do, I support the "Don't let minetest.sound_play fail if nobody is in hear distance. Add the sound anyway and play it if someone comes into hear distance, obviously with an appropriate time offset." side in this discussion. Re the "nothing changes by default proposal" in #14342 (comment): I think we need to resend sounds attached to objects when they come back into hear distance without any modder intervention. Otherwise the behavior introduced by #14436 doesn't make any sense and becomes a breaking change by itself. |
hey @sfence , any updates? |
c71c9de
to
07738c4
Compare
@Zughy I leave this to get more feedback. @appgurueu Why merge 'master' to this branch instead of rebase? |
|
I think this change
contradicts this request
for non-looped sounds attached to objects. |
@grorp I changed the default value of |
Fix Positional sound not playing if you walk into range #3559.
Check if some player comes to the hearing distance of sound and send him a sound if the sound is not known by the player.
Fix Positional sound not playing if you walk into range #3559.
To do
This PR is a Ready for Review.
How to test
Attach looped sound via Junkeox in devtest to object/location in distance bigger than heart distance and come to the area.