sdl.c File Reference

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <math.h>
#include <signal.h>
#include <memory.h>
#include <SDL.h>
#include "Buzz_inc.h"
#include "macros.h"
#include "options.h"
#include "utils.h"
#include "logging.h"
#include "av.h"

Go to the source code of this file.

Data Structures

struct  fade_information

Defines

#define ASSIGN
#define KEYBUF_SIZE   256
#define MAX_X   320
#define MAX_Y   200
#define TYPE   (uint32_t *)
#define TYPE   (uint8_t *)
#define TYPE   (uint16_t *)
#define TYPE   (uint8_t *)

Functions

static void alloc_dirty_tree (void)
char AnimSoundCheck (void)
 Check if animation sound playback is in progress.
static void audio_callback (void *userdata, Uint8 *stream, int len)
void av_block (void)
 Block until an SDL event comes in.
void av_need_update (SDL_Rect *r)
 Notify graphic subsystem that rectangle has to be redrawn.
void av_need_update_xy (int x1, int y1, int x2, int y2)
 Notify graphic subsystem that rectangle has to be redrawn.
static void av_process_event (SDL_Event *evp)
void av_set_fading (int type, int from, int to, int steps, int preserve)
 Set up screen fade effect.
void av_setup (void)
 Setup SDL audio, video and window subsystems.
void av_silence (int channel)
void av_step (void)
void av_sync (void)
int bioskey (int peek)
static void fill_rect_list (SDL_Rect *arr, int *len, int x, int y, int w, int h, int idx, int level)
static int get_dirty_rect_list ()
static int intersect_area (SDL_Rect *first, SDL_Rect *second)
 compute area of intersection of rectangles
int IsChannelMute (int channel)
 LOG_DEFAULT_CATEGORY (sdl)
void MuteChannel (int channel, int mute)
void NUpdateVoice (void)
void play (struct audio_chunk *new_chunk, int channel)
static SDL_Surface * SDL_Scale2x (SDL_Surface *src, SDL_Surface *dst)
Uint32 sdl_timer_callback (Uint32 interval, void *param)
static void transform_palette (void)
static void update_rect (SDL_Rect *fill, int x, int y, int w, int h, int idx, int level)
void UpdateAudio (void)

Variables

static SDL_AudioSpec audio_desired
int av_mouse_cur_x
int av_mouse_cur_y
int av_mouse_pressed_cur
int av_mouse_pressed_latched
int av_mouse_pressed_x
int av_mouse_pressed_y
static struct
audio_channel 
Channels [AV_NUM_CHANNELS]
static SDL_Rect * dirty_rect_list
static unsigned char * dirty_tree
static unsigned dirty_tree_length
SDL_Surface * display
static int do_fading
static struct
fade_information 
fade_info
static int have_audio
static int keybuf [KEYBUF_SIZE]
static int keybuf_in_idx
static int keybuf_out_idx
SDL_Overlay * news_overlay
SDL_Rect news_rect
unsigned char pal [3 *256]
 RGB color palette.
static SDL_Color pal_colors [256]
unsigned char * screen
int screen_dirty
 Indicates that screen redraw is required.
static SDL_Surface * screen_surf
static SDL_Surface * screen_surf2x
SDL_Overlay * video_overlay
SDL_Rect video_rect


Define Documentation

#define ASSIGN

Value:

do { \
                    *(TYPE (to)) = *(TYPE from); \
                    *(TYPE (to+bpp)) = *(TYPE from); \
                    *(TYPE (to+dst->pitch)) = *(TYPE from); \
                    *(TYPE (to+dst->pitch+bpp)) = *(TYPE from); \
                } while (0)

Referenced by SDL_Scale2x().

#define KEYBUF_SIZE   256

Definition at line 22 of file sdl.c.

Referenced by av_process_event(), and bioskey().

#define MAX_X   320

Definition at line 17 of file sdl.c.

#define MAX_Y   200

Definition at line 18 of file sdl.c.

#define TYPE   (uint32_t *)

#define TYPE   (uint8_t *)

#define TYPE   (uint16_t *)

#define TYPE   (uint8_t *)


Function Documentation

static void alloc_dirty_tree ( void   )  [static]

Definition at line 73 of file sdl.c.

References AV_DTREE_DEPTH, dirty_rect_list, dirty_tree, dirty_tree_length, and xcalloc().

Referenced by av_setup().

char AnimSoundCheck ( void   ) 

Check if animation sound playback is in progress.

Currently AV_SOUND_CHANNEL is used only for animation sounds.

Returns:
0 means busy playing audio; 1 means idle

Definition at line 147 of file sdl.c.

References AV_SOUND_CHANNEL, av_step(), and Channels.

static void audio_callback ( void userdata,
Uint8 *  stream,
int  len 
) [static]

Definition at line 93 of file sdl.c.

References AV_NUM_CHANNELS, Channels, audio_channel::chunk, audio_channel::chunk_tailp, audio_chunk::data, audio_chunk::loop, min, audio_channel::mute, audio_chunk::next, audio_channel::offset, audio_chunk::size, and audio_channel::volume.

Referenced by av_setup(), and main().

void av_block ( void   ) 

Block until an SDL event comes in.

We have a 30ms timer going, so that is the maximum wait time.

Definition at line 510 of file sdl.c.

References av_process_event(), and av_step().

void av_need_update ( SDL_Rect *  r  ) 

Notify graphic subsystem that rectangle has to be redrawn.

Parameters:
r rectangle coordinates

Definition at line 925 of file sdl.c.

References MAX_X, MAX_Y, screen_dirty, and update_rect().

void av_need_update_xy ( int  x1,
int  y1,
int  x2,
int  y2 
)

Notify graphic subsystem that rectangle has to be redrawn.

Parameters:
x1 x screen coord. of upper left corner
y1 y screen coord. of upper left corner
x2 x screen coord. of bottom right corner
y2 y screen coord. of bottom right corner

Definition at line 939 of file sdl.c.

References av_need_update().

static void av_process_event ( SDL_Event *  evp  )  [static]

Definition at line 390 of file sdl.c.

References av_mouse_cur_x, av_mouse_cur_y, av_mouse_pressed_cur, av_mouse_pressed_latched, av_mouse_pressed_x, av_mouse_pressed_y, c, DEBUG2, key, keybuf, keybuf_in_idx, KEYBUF_SIZE, and TRACE4.

Referenced by av_block(), and av_step().

void av_set_fading ( int  type,
int  from,
int  to,
int  steps,
int  preserve 
)

Set up screen fade effect.

Fading applies only to a range of palette color indexes. Rest of colors in the palette can be preserved or forced to black.

Parameters:
type AV_FADE_IN or AV_FADE_OUT
from index of first affected color
to index of last affected color
steps how many color change steps to perform
preserve whether preserve rest of palette colors or not

Definition at line 784 of file sdl.c.

References AV_FADE_IN, av_need_update(), av_sync(), do_fading, fade_information::end, fade_info, fade_information::force_black, fade_information::from, fade_information::inc, MAX_X, MAX_Y, fade_information::step, fade_information::steps, and fade_information::to.

void av_setup ( void   ) 

Setup SDL audio, video and window subsystems.

Definition at line 232 of file sdl.c.

References alloc_dirty_tree(), audio_callback(), audio_desired, AV_MAX_VOLUME, AV_NUM_CHANNELS, Channels, audio_channel::chunk, audio_channel::chunk_tailp, CRITICAL2, display, do_fading, ERROR2, fade_info, FT_IMAGE, have_audio, INFO1, INFO2, locate_file(), MAX_X, MAX_Y, audio_channel::mute, news_overlay, NOTICE1, audio_channel::offset, options, PACKAGE_NAME, PACKAGE_STRING, PACKAGE_VERSION, screen, screen_surf, screen_surf2x, sdl_timer_callback(), fade_information::step, fade_information::steps, video_overlay, audio_channel::volume, game_options::want_audio, game_options::want_fullscreen, and xcalloc().

void av_silence ( int  channel  ) 

Definition at line 195 of file sdl.c.

References AV_ALL_CHANNELS, AV_NUM_CHANNELS, av_silence(), Channels, audio_channel::chunk, audio_channel::chunk_tailp, and audio_channel::offset.

void av_step ( void   ) 

Definition at line 492 of file sdl.c.

References av_process_event(), and music_pump().

void av_sync ( void   ) 

Definition at line 703 of file sdl.c.

References av_need_update(), dirty_rect_list, display, get_dirty_rect_list(), MAX_X, MAX_Y, news_overlay, news_rect, pal_colors, screen_dirty, screen_surf, screen_surf2x, SDL_Scale2x(), TRACE4, transform_palette(), video_overlay, and video_rect.

int bioskey ( int  peek  ) 

Definition at line 522 of file sdl.c.

References av_step(), c, keybuf, keybuf_in_idx, keybuf_out_idx, and KEYBUF_SIZE.

static void fill_rect_list ( SDL_Rect *  arr,
int *  len,
int  x,
int  y,
int  w,
int  h,
int  idx,
int  level 
) [static]

Definition at line 883 of file sdl.c.

References AV_DTREE_DEPTH, dirty_tree, and dirty_tree_length.

Referenced by get_dirty_rect_list().

static int get_dirty_rect_list ( void   )  [static]

Definition at line 912 of file sdl.c.

References dirty_rect_list, dirty_tree, dirty_tree_length, fill_rect_list(), MAX_X, and MAX_Y.

Referenced by av_sync().

static int intersect_area ( SDL_Rect *  first,
SDL_Rect *  second 
) [inline, static]

compute area of intersection of rectangles

Definition at line 819 of file sdl.c.

References min.

Referenced by update_rect().

int IsChannelMute ( int  channel  ) 

Definition at line 157 of file sdl.c.

References AV_NUM_CHANNELS, Channels, have_audio, and audio_channel::mute.

LOG_DEFAULT_CATEGORY ( sdl   ) 

void MuteChannel ( int  channel,
int  mute 
)

Definition at line 750 of file sdl.c.

References AV_ALL_CHANNELS, AV_NUM_CHANNELS, Channels, audio_channel::mute, and MuteChannel().

void NUpdateVoice ( void   ) 

Definition at line 551 of file sdl.c.

void play ( struct audio_chunk new_chunk,
int  channel 
)

Definition at line 166 of file sdl.c.

References AV_NUM_CHANNELS, av_silence(), Channels, audio_channel::chunk, audio_channel::chunk_tailp, DEBUG1, have_audio, and audio_chunk::next.

static SDL_Surface* SDL_Scale2x ( SDL_Surface *  src,
SDL_Surface *  dst 
) [static]

Definition at line 557 of file sdl.c.

References ASSIGN, x, and y.

Referenced by av_sync().

Uint32 sdl_timer_callback ( Uint32  interval,
void param 
)

Definition at line 219 of file sdl.c.

Referenced by av_setup().

static void transform_palette ( void   )  [static]

Definition at line 655 of file sdl.c.

References ARRAY_LENGTH, fade_info, fade_information::force_black, fade_information::from, pal, pal_colors, fade_information::step, fade_information::steps, steps, and fade_information::to.

Referenced by av_sync().

static void update_rect ( SDL_Rect *  fill,
int  x,
int  y,
int  w,
int  h,
int  idx,
int  level 
) [static]

Definition at line 849 of file sdl.c.

References AV_DTREE_DEPTH, AV_DTREE_FILL_RATIO, dirty_tree, dirty_tree_length, and intersect_area().

Referenced by av_need_update().

void UpdateAudio ( void   ) 

Definition at line 545 of file sdl.c.


Variable Documentation

SDL_AudioSpec audio_desired [static]

Definition at line 66 of file sdl.c.

Referenced by av_setup(), and main().

int av_mouse_cur_x

Definition at line 26 of file sdl.c.

int av_mouse_cur_y

Definition at line 26 of file sdl.c.

int av_mouse_pressed_cur

Definition at line 28 of file sdl.c.

int av_mouse_pressed_latched

Definition at line 29 of file sdl.c.

int av_mouse_pressed_x

Definition at line 27 of file sdl.c.

int av_mouse_pressed_y

Definition at line 27 of file sdl.c.

struct audio_channel Channels[AV_NUM_CHANNELS] [static]

Definition at line 43 of file sdl.c.

Referenced by AnimSoundCheck(), audio_callback(), av_setup(), av_silence(), IsChannelMute(), MuteChannel(), and play().

SDL_Rect* dirty_rect_list [static]

Definition at line 70 of file sdl.c.

Referenced by alloc_dirty_tree(), av_sync(), and get_dirty_rect_list().

unsigned char* dirty_tree [static]

Definition at line 68 of file sdl.c.

Referenced by alloc_dirty_tree(), fill_rect_list(), get_dirty_rect_list(), and update_rect().

unsigned dirty_tree_length [static]

Definition at line 69 of file sdl.c.

Referenced by alloc_dirty_tree(), fill_rect_list(), get_dirty_rect_list(), and update_rect().

SDL_Surface* display

Definition at line 33 of file sdl.c.

Referenced by av_setup(), av_sync(), and main().

int do_fading [static]

Definition at line 64 of file sdl.c.

Referenced by av_set_fading(), and av_setup().

struct fade_information fade_info [static]

Referenced by av_set_fading(), av_setup(), and transform_palette().

int have_audio [static]

Definition at line 62 of file sdl.c.

Referenced by av_setup(), IsChannelMute(), main(), and play().

int keybuf[KEYBUF_SIZE] [static]

Definition at line 23 of file sdl.c.

Referenced by av_process_event(), and bioskey().

int keybuf_in_idx [static]

Definition at line 24 of file sdl.c.

Referenced by av_process_event(), and bioskey().

int keybuf_out_idx [static]

Definition at line 24 of file sdl.c.

Referenced by bioskey().

SDL_Overlay* news_overlay

Definition at line 35 of file sdl.c.

SDL_Rect news_rect

Definition at line 37 of file sdl.c.

unsigned char pal[3 *256]

RGB color palette.

Definition at line 46 of file sdl.c.

SDL_Color pal_colors[256] [static]

Definition at line 41 of file sdl.c.

Referenced by av_sync(), and transform_palette().

unsigned char* screen

Definition at line 31 of file sdl.c.

int screen_dirty

Indicates that screen redraw is required.

Definition at line 60 of file sdl.c.

SDL_Surface* screen_surf [static]

Definition at line 38 of file sdl.c.

Referenced by av_setup(), and av_sync().

SDL_Surface* screen_surf2x [static]

Definition at line 39 of file sdl.c.

Referenced by av_setup(), and av_sync().

SDL_Overlay* video_overlay

Definition at line 34 of file sdl.c.

SDL_Rect video_rect

Definition at line 36 of file sdl.c.


Generated on Fri Sep 28 00:35:47 2007 for raceintospace by  doxygen 1.5.3