Skip to content

Commit

Permalink
Use SDL_TimerID properly.
Browse files Browse the repository at this point in the history
This involves a GARGLK_USESDL macro to conditionally include
SDL_timer.h and the SDL-specific members of glk_schannel_struct
only when compiling with SDL sound support.

Multi-line description of commit,
feel free to be detailed.
  • Loading branch information
angstsmurf committed Nov 11, 2019
1 parent 89848a8 commit 8ca9730
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions garglk/Jamfile
Expand Up @@ -20,6 +20,8 @@ if $(OS) = MINGW

if $(USESDL) = yes
{
SubDirCcFlags
-DGARGLK_USESDL ;
SubDirHdrs $(TOP) support sdl ;
SubDirHdrs $(TOP) support sdl_sound ;
}
Expand Down
9 changes: 8 additions & 1 deletion garglk/garglk.h
Expand Up @@ -32,6 +32,10 @@

#include "gi_dispa.h"

#ifdef GARGLK_USESDL
#include "SDL/SDL_timer.h"
#endif

/* First, we define our own TRUE and FALSE and NULL, because ANSI
* is a strange world.
*/
Expand Down Expand Up @@ -564,6 +568,8 @@ struct glk_schannel_struct
glui32 loop;
int notify;
int buffered;

#ifdef GARGLK_USESDL
int paused;

/* for volume fades */
Expand All @@ -572,7 +578,8 @@ struct glk_schannel_struct
int target_volume;
double float_volume;
double volume_delta;
int timer;
SDL_TimerID timer;
#endif

gidispatch_rock_t disprock;
channel_t *chain_next, *chain_prev;
Expand Down
8 changes: 4 additions & 4 deletions garglk/sndsdl.c
Expand Up @@ -190,7 +190,7 @@ static void cleanup_channel(schanid_t chan)
chan->music = 0;

if (chan->timer)
SDL_RemoveTimer((SDL_TimerID)chan->timer);
SDL_RemoveTimer(chan->timer);

chan->timer = 0;
}
Expand Down Expand Up @@ -321,7 +321,7 @@ Uint32 volume_timer_callback(Uint32 interval, void *param)
gli_strict_warning("volume_timer_callback: invalid timer.");
return 0;
}
SDL_RemoveTimer((SDL_TimerID)chan->timer);
SDL_RemoveTimer(chan->timer);
chan->timer = 0;

if (chan->volume != chan->target_volume)
Expand Down Expand Up @@ -358,9 +358,9 @@ void init_fade(schanid_t chan, int volume, int duration, int notify)
chan->volume_timeout = FADE_GRANULARITY;

if (chan->timer)
SDL_RemoveTimer((SDL_TimerID)chan->timer);
SDL_RemoveTimer(chan->timer);

chan->timer = (int)SDL_AddTimer((Uint32)(duration / FADE_GRANULARITY), volume_timer_callback, (void *)chan);
chan->timer = SDL_AddTimer((Uint32)(duration / FADE_GRANULARITY), volume_timer_callback, (void *)chan);

if (!chan->timer)
{
Expand Down

0 comments on commit 8ca9730

Please sign in to comment.