Created
May 5, 2020 21:12
-
-
Save Francesco149/1e0be6105e9fd1612a54680ac857d6db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69c69 | |
< # Main loop for standard, non-continuous sound effects | |
--- | |
> // Main loop for standard, non-continuous sound effects | |
83c83 | |
< # keep looping until layer 0 finishes or we are told to stop or to play something else | |
--- | |
> // keep looping until layer 0 finishes or we are told to stop or to play something else | |
87,89c87,89 | |
< chan_bltz .skip_023589 # if we have a signal: | |
< chan_beqz .force_stop_023589 # told to stop | |
< chan_jump .start_playing_023589 # told to play something else | |
--- | |
> chan_bltz .skip_023589 // if we have a signal: | |
> chan_beqz .force_stop_023589 // told to stop | |
> chan_jump .start_playing_023589 // told to play something else | |
92,93c92,93 | |
< chan_beqz .poll_023589 # if layer 0 hasn't finished, keep polling | |
< chan_jump .main_loop_023589 # otherwise go back to the main loop | |
--- | |
> chan_beqz .poll_023589 // if layer 0 hasn't finished, keep polling | |
> chan_jump .main_loop_023589 // otherwise go back to the main loop | |
136c136 | |
< # Main loop for moving, env and air sound effects, which play continuously | |
--- | |
> // Main loop for moving, env and air sound effects, which play continuously | |
151c151 | |
< # keep looping until we are told to stop or to play something else | |
--- | |
> // keep looping until we are told to stop or to play something else | |
173c173 | |
< # Loop for menu sound effects | |
--- | |
> // Loop for menu sound effects | |
190c190 | |
< # keep looping until layer 0 finishes or we are told to stop or to play something else | |
--- | |
> // keep looping until layer 0 finishes or we are told to stop or to play something else | |
194,195c194,195 | |
< chan_bltz .skip_7 # if we have a signal: | |
< chan_beqz .force_stop_7 # told to stop | |
--- | |
> chan_bltz .skip_7 // if we have a signal: | |
> chan_beqz .force_stop_7 // told to stop | |
197c197 | |
< chan_jump .start_playing_7 # told to play something else | |
--- | |
> chan_jump .start_playing_7 // told to play something else | |
200c200 | |
< chan_beqz .poll_7 # if layer 0 hasn't finished, keep polling | |
--- | |
> chan_beqz .poll_7 // if layer 0 hasn't finished, keep polling | |
202c202 | |
< chan_jump .main_loop_7 # otherwise go back to the main loop | |
--- | |
> chan_jump .main_loop_7 // otherwise go back to the main loop | |
210c210 | |
< # Delay for a number of ticks (1-255) in an interruptible manner. | |
--- | |
> // Delay for a number of ticks (1-255) in an interruptible manner. | |
225c225 | |
< chan_ioreadval 1 # IO slots 0-3 are reset to -1 when read; restore the value | |
--- | |
> chan_ioreadval 1 // IO slots 0-3 are reset to -1 when read; restore the value | |
227,228c227,228 | |
< chan_break # break out of the loop | |
< chan_break # force the caller to return immediately | |
--- | |
> chan_break // break out of the loop | |
> chan_break // force the caller to return immediately | |
231,233c231,233 | |
< # Set reverb in way that takes area echo level and volume into account. This | |
< # is done by writing to IO slot 5 and letting get_sound_reverb in external.c | |
< # do the necessary math. | |
--- | |
> // Set reverb in way that takes area echo level and volume into account. This | |
> // is done by writing to IO slot 5 and letting get_sound_reverb in external.c | |
> // do the necessary math. | |
980c980 | |
< .sound_action_climb_down_tree: # unused | |
--- | |
> .sound_action_climb_down_tree: // unused | |
991c991 | |
< .chan_582: # unused | |
--- | |
> .chan_582: // unused | |
1411c1411 | |
< .chan_828: # unused | |
--- | |
> .chan_828: // unused | |
7990c7990 | |
< # padding | |
--- | |
> // padding | |
21,53d20 | |
< Bool glXGetSyncValuesOML(Display* dpy, | |
< GLXDrawable drawable, | |
< int64_t* ust, | |
< int64_t* msc, | |
< int64_t* sbc); | |
< | |
< Bool glXGetMscRateOML(Display* dpy, | |
< GLXDrawable drawable, | |
< int32_t* numerator, | |
< int32_t* denominator); | |
< | |
< int64_t glXSwapBuffersMscOML(Display* dpy, | |
< GLXDrawable drawable, | |
< int64_t target_msc, | |
< int64_t divisor, | |
< int64_t remainder); | |
< | |
< Bool glXWaitForMscOML(Display* dpy, | |
< GLXDrawable drawable, | |
< int64_t target_msc, | |
< int64_t divisor, | |
< int64_t remainder, | |
< int64_t* ust, | |
< int64_t* msc, | |
< int64_t* sbc); | |
< | |
< Bool glXWaitForSbcOML(Display* dpy, | |
< GLXDrawable drawable, | |
< int64_t target_sbc, | |
< int64_t* ust, | |
< int64_t* msc, | |
< int64_t* sbc); | |
< | |
186,193d152 | |
< | |
< uint64_t ust0; | |
< int64_t last_msc; | |
< uint64_t wanted_ust; // multiplied by 3 | |
< uint64_t vsync_interval; | |
< uint64_t last_ust; | |
< int64_t target_msc; | |
< bool dropped_frame; | |
250,254d208 | |
< | |
< int64_t ust, msc, sbc; | |
< glXGetSyncValuesOML(glx.dpy, glx.win, &ust, &msc, &sbc); | |
< glx.ust0 = (uint64_t)ust; | |
< glx.vsync_interval = 16666; | |
315,355c269 | |
< glx.wanted_ust += 100000; // advance 1/30 second | |
< | |
< double vsyncs_to_wait = (int64_t)(glx.wanted_ust / 3 - glx.last_ust) / (double)glx.vsync_interval; | |
< if (vsyncs_to_wait <= 0) { | |
< printf("Dropping frame\n"); | |
< // Drop frame | |
< glx.dropped_frame = true; | |
< return; | |
< } | |
< if (floor(vsyncs_to_wait) != vsyncs_to_wait) { | |
< uint64_t left_ust = glx.last_ust + floor(vsyncs_to_wait) * glx.vsync_interval; | |
< uint64_t right_ust = glx.last_ust + ceil(vsyncs_to_wait) * glx.vsync_interval; | |
< uint64_t adjusted_wanted_ust = glx.wanted_ust / 3 + (glx.last_ust + 33333 > glx.wanted_ust / 3 ? 2000 : -2000); | |
< int64_t diff_left = adjusted_wanted_ust - left_ust; | |
< int64_t diff_right = right_ust - adjusted_wanted_ust; | |
< if (diff_left < 0) { | |
< diff_left = -diff_left; | |
< } | |
< if (diff_right < 0) { | |
< diff_right = -diff_right; | |
< } | |
< if (diff_left < diff_right) { | |
< vsyncs_to_wait = floor(vsyncs_to_wait); | |
< } else { | |
< vsyncs_to_wait = ceil(vsyncs_to_wait); | |
< } | |
< if (vsyncs_to_wait == 0) { | |
< printf("vsyncs_to_wait became 0 so dropping frame\n"); | |
< glx.dropped_frame = true; | |
< return; | |
< } | |
< } | |
< glx.dropped_frame = false; | |
< //printf("Vsyncs to wait: %d, diff: %d\n", (int)vsyncs_to_wait, (int)(glx.last_ust + (int64_t)vsyncs_to_wait * glx.vsync_interval - glx.wanted_ust / 3)); | |
< if (vsyncs_to_wait > 30) { | |
< // Unreasonable, so change to 2 | |
< vsyncs_to_wait = 2; | |
< } | |
< glx.target_msc = glx.last_msc + vsyncs_to_wait; | |
< | |
< glXSwapBuffersMscOML(glx.dpy, glx.win, glx.target_msc, 0, 0); | |
--- | |
> glXSwapBuffers(glx.dpy, glx.win); | |
359,385c273 | |
< if (glx.dropped_frame) { | |
< return; | |
< } | |
< | |
< int64_t ust, msc, sbc; | |
< if (!glXWaitForSbcOML(glx.dpy, glx.win, 0, &ust, &msc, &sbc)) { | |
< // X connection broke or something? | |
< glx.last_ust += (glx.target_msc - glx.last_msc) * glx.vsync_interval; | |
< glx.last_msc = glx.target_msc; | |
< return; | |
< } | |
< uint64_t this_ust = ust - glx.ust0; | |
< uint64_t vsyncs_passed = msc - glx.last_msc; | |
< if (glx.last_ust != 0 && vsyncs_passed != 0) { | |
< glx.vsync_interval = (this_ust - glx.last_ust) / vsyncs_passed; | |
< //printf("glx.vsync_interval: %d\n", (int)glx.vsync_interval); | |
< } | |
< glx.last_ust = this_ust; | |
< glx.last_msc = msc; | |
< if (msc != glx.target_msc) { | |
< printf("Frame too late by %d vsyncs\n", (int)(msc - glx.target_msc)); | |
< } | |
< if (msc - glx.target_msc >= 2) { | |
< // Frame arrived way too late, so reset timer from here | |
< printf("Reseting timer\n"); | |
< glx.wanted_ust = this_ust * 3; | |
< } | |
--- | |
> /* no OML shit on rpi */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment