[Tux4kids-commits] r66 - in tuxmath/trunk: . src
dbruce at alioth.debian.org
dbruce at alioth.debian.org
Thu Mar 8 21:26:44 CET 2007
Author: dbruce
Date: 2006-12-07 20:20:06 +0000 (Thu, 07 Dec 2006)
New Revision: 66
Added:
tuxmath/trunk/src/audio.c
Modified:
tuxmath/trunk/configure.in
tuxmath/trunk/src/Makefile.am
tuxmath/trunk/src/pause.c
tuxmath/trunk/src/titlescreen.c
tuxmath/trunk/src/titlescreen.h
Log:
audio.c from tuxtype added; program compiles again
Modified: tuxmath/trunk/configure.in
===================================================================
--- tuxmath/trunk/configure.in 2006-12-02 00:34:38 UTC (rev 65)
+++ tuxmath/trunk/configure.in 2006-12-07 20:20:06 UTC (rev 66)
@@ -50,19 +50,28 @@
LIBS="$LIBS $SDL_LIBS"
# Checks for libraries.
-dnl Checks for libraries.
+dnl Check for SDL_image:
AC_CHECK_LIB([SDL_image],
[IMG_Load],
LIBS="$LIBS -lSDL_image",
[AC_MSG_ERROR([*** SDL_image library not found!])]
)
-dnl Checks for libraries.
+
+dnl Check for SDL_mixer:.
AC_CHECK_LIB([SDL_mixer],
[Mix_OpenAudio],
LIBS="$LIBS -lSDL_mixer",
[AC_MSG_ERROR([*** SDL_mixer library not found!])]
)
+dnl Check for SDL_ttf:
+AC_CHECK_LIB([SDL_ttf],
+ [TTF_Init],
+ LIBS="$LIBS -lSDL_ttf",
+ [AC_MSG_ERROR([SDL_ttf not found! http://www.libsdl.org/projects/SDL_ttf])]
+)
+
+
# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
Modified: tuxmath/trunk/src/Makefile.am
===================================================================
--- tuxmath/trunk/src/Makefile.am 2006-12-02 00:34:38 UTC (rev 65)
+++ tuxmath/trunk/src/Makefile.am 2006-12-07 20:20:06 UTC (rev 66)
@@ -7,12 +7,12 @@
TuxMath_SOURCES = tuxmath.c setup.c title.c titlescreen.c game.c \
options.c credits.c playsound.c \
- theme.c loaders.c alphabet.c pause.c \
+ theme.c loaders.c alphabet.c pause.c gettext.c audio.c \
mathcards.c fileops.c tuxmathrc.c
tuxmath_SOURCES = tuxmath.c setup.c title.c titlescreen.c game.c \
options.c credits.c playsound.c \
- theme.c loaders.c alphabet.c pause.c \
+ theme.c loaders.c alphabet.c pause.c gettext.c audio.c \
mathcards.c fileops.c
Added: tuxmath/trunk/src/audio.c
===================================================================
--- tuxmath/trunk/src/audio.c 2006-12-02 00:34:38 UTC (rev 65)
+++ tuxmath/trunk/src/audio.c 2006-12-07 20:20:06 UTC (rev 66)
@@ -0,0 +1,70 @@
+/***************************************************************************
+ - file: audio.c
+ - description: this file contains audio related functions
+ -------------------
+ begin : Jan 22, 2003
+ copyright : Sam Hart, Jesse Andrews (C) 2003
+ email : tuxtype-dev at tux4kids.net
+***************************************************************************/
+
+/***************************************************************************
+* *
+* This program is free software; you can redistribute it and/or modify *
+* it under the terms of the GNU General Public License as published by *
+* the Free Software Foundation; either version 2 of the License, or *
+* (at your option) any later version. *
+* *
+***************************************************************************/
+
+//Needed for Opts_UsingSound():
+#include "options.h"
+
+#include "titlescreen.h"
+
+
+Mix_Chunk *sound[NUM_WAVES];
+Mix_Music *music;
+
+void tuxtype_playsound(Mix_Chunk *snd) {
+ if (!Opts_UsingSound()) return;
+
+ Mix_PlayChannel(-1, snd, 0);
+}
+
+Mix_Music *defaultMusic = NULL; // holds music for audioMusicLoad/unload
+
+/* audioMusicLoad attempts to load and play the music file
+ * Note: loops == -1 means forever
+ */
+void audioMusicLoad( char *musicFilename, int loops ) {
+ if (!Opts_UsingSound()) return;
+
+ audioMusicUnload(); // make sure defaultMusic is clear
+
+ defaultMusic = LoadMusic( musicFilename );
+ Mix_PlayMusic( defaultMusic, loops );
+}
+
+/* audioMusicUnload attempts to unload any music data that was
+ * loaded using the audioMusicLoad function
+ */
+void audioMusicUnload( void ) {
+ if (!Opts_UsingSound()) return;
+
+ if ( defaultMusic )
+ Mix_FreeMusic( defaultMusic );
+
+ defaultMusic=NULL;
+}
+
+/* audioMusicPlay attempts to play the passed music data.
+ * if a music file was loaded using the audioMusicLoad
+ * it will be stopped and unloaded
+ * Note: loops == -1 means forever
+ */
+void audioMusicPlay( Mix_Music *musicData, int loops ) {
+ if (!Opts_UsingSound()) return;
+
+ audioMusicUnload();
+ Mix_PlayMusic( musicData, loops );
+}
Modified: tuxmath/trunk/src/pause.c
===================================================================
--- tuxmath/trunk/src/pause.c 2006-12-02 00:34:38 UTC (rev 65)
+++ tuxmath/trunk/src/pause.c 2006-12-07 20:20:06 UTC (rev 66)
@@ -16,8 +16,13 @@
* *
***************************************************************************/
+// For tuxtype-related stuff:
#include "titlescreen.h"
+// For Opts_UseSound()
+#include "options.h"
+
+
Mix_Chunk *pause_sfx;
SDL_Surface *up, *down, *left, *right;
SDL_Rect rectUp, rectDown, rectLeft, rectRight;
@@ -25,7 +30,7 @@
extern settings localsettings;
void pause_load_media(void) {
- if (sys_sound)
+ if (Opts_UseSound())
pause_sfx = LoadSound( "tock.wav" );
up = LoadImage("up.png", IMG_ALPHA);
@@ -45,7 +50,7 @@
}
void pause_unload_media(void) {
- if (sys_sound)
+ if (Opts_UseSound())
Mix_FreeChunk(pause_sfx);
SDL_FreeSurface(up);
SDL_FreeSurface(down);
@@ -65,7 +70,7 @@
rectLeft.x = rectDown.x = 320 - (7*16) - rectLeft.w - 4;
rectRight.x = rectUp.x = 320 + (7*16) + 4;
- if (sys_sound) {
+ if (Opts_UseSound()) {
SDL_BlitSurface(left, NULL, screen, &rectLeft);
SDL_BlitSurface(right, NULL, screen, &rectRight);
@@ -74,7 +79,7 @@
SDL_BlitSurface(up, NULL, screen, &rectUp);
}
- if (sys_sound) {
+ if (Opts_UseSound()) {
t = black_outline(_("Sound Effects Volume"), f1, &white);
s.y = 160;
@@ -187,7 +192,7 @@
/* --- stop all sounds, play pause noise --- */
- if (sys_sound) {
+ if (Opts_UseSound()) {
Mix_Pause(-1);
Mix_PlayChannel(-1, pause_sfx, 0);
sfx_volume = Mix_Volume(-1, -1); // get sfx volume w/o changing it
@@ -202,7 +207,7 @@
darkenscreen();
pause_draw_info();
- if (sys_sound) {
+ if (Opts_UseSound()) {
draw_vols(sfx_volume, mus_volume);
}
@@ -221,7 +226,7 @@
exit(0);
break;
case SDL_KEYUP:
- if (sys_sound &&
+ if (Opts_UseSound() &&
((event.key.keysym.sym == SDLK_RIGHT) ||
(event.key.keysym.sym == SDLK_LEFT)))
tocks = 0;
@@ -233,7 +238,7 @@
paused = 0;
quit = 1;
}
- if (sys_sound) {
+ if (Opts_UseSound()) {
if (event.key.keysym.sym == SDLK_RIGHT)
sfx_volume += 4;
if (event.key.keysym.sym == SDLK_LEFT)
@@ -254,7 +259,7 @@
break;
}
- if (sys_sound && mousePressed) {
+ if (Opts_UseSound() && mousePressed) {
int x, y;
SDL_GetMouseState(&x, &y);
@@ -284,7 +289,7 @@
}
}
- if (sys_sound) {
+ if (Opts_UseSound()) {
if (sfx_volume > MIX_MAX_VOLUME)
sfx_volume = MIX_MAX_VOLUME;
@@ -324,7 +329,7 @@
SDL_ShowCursor(0);
- if (sys_sound) {
+ if (Opts_UseSound()) {
Mix_PlayChannel(-1, pause_sfx, 0);
Mix_Resume(-1);
}
Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c 2006-12-02 00:34:38 UTC (rev 65)
+++ tuxmath/trunk/src/titlescreen.c 2006-12-07 20:20:06 UTC (rev 66)
@@ -18,11 +18,31 @@
***************************************************************************/
-
+// titlescreen.h has all of the tuxtype-related stuff:
#include "titlescreen.h"
+// tuxmath includes:
+#include "options.h"
+
+
+/* --- Data Structure for Dirty Blitting --- */
+SDL_Rect srcupdate[MAX_UPDATES];
+SDL_Rect dstupdate[MAX_UPDATES];
+int numupdates = 0; // tracks how many blits to be done
+
+// Type needed for Transwipe():
+struct blit {
+ SDL_Surface *src;
+ SDL_Rect *srcrect;
+ SDL_Rect *dstrect;
+ unsigned char type;
+} blits[MAX_UPDATES];
+
// globals from tuxtype's globals.h defined outside of titlescreen.c (in tuxtype):
+int show_tux4kids;
int debugOn; //FIXME switch to TUXMATH_DEBUG
+
+
TTF_Font *font;
SDL_Event event;
SDL_Surface *bkg;
@@ -95,9 +115,11 @@
void TitleScreen_load_media(void);
void TitleScreen_unload_media(void);
void NotImplemented(void);
+void TransWipe(SDL_Surface* newbkg, int type, int var1, int var2);
+void UpdateScreen(int *frame);
+void AddRect(SDL_Rect * src, SDL_Rect * dst);
-
void draw_button( int id, sprite *s ) {
SDL_Rect button;
@@ -354,8 +376,9 @@
char phrase[128];
debugOn = 1; //for now
+ show_tux4kids = 1; //for now
- if (sys_sound)
+ if (Opts_UseSound())
{
menu_sound=1;
menu_music=localsettings.menu_music;
@@ -523,7 +546,7 @@
menu_opt = menu_item[j][menu_depth];
if (menu_sound)
{
- playsound(snd_select);
+ tuxtype_playsound(snd_select);
}
DEBUGCODE
{
@@ -575,7 +598,7 @@
menu_opt = QUIT_GAME;
if (menu_sound)
- playsound(snd_select);
+ tuxtype_playsound(snd_select);
break;
}
@@ -621,7 +644,7 @@
case SDLK_UP:
{
if (menu_sound)
- playsound(snd_move);
+ tuxtype_playsound(snd_move);
key_menu--;
if (key_menu < 1)
key_menu = 5;
@@ -633,7 +656,7 @@
{
key_menu++;
if (menu_sound)
- playsound(snd_move);
+ tuxtype_playsound(snd_move);
if (key_menu > 5)
key_menu = 1;
break;
@@ -646,7 +669,7 @@
{
menu_opt = menu_item[key_menu][menu_depth];
if (menu_sound)
- playsound(snd_select);
+ tuxtype_playsound(snd_select);
}
break;
}
@@ -731,7 +754,7 @@
if (menu_opt == PROJECT_INFO)
{
- projectInfo();
+// projectInfo();
redraw = 1;
}
@@ -745,7 +768,7 @@
if (menu_music)
audioMusicUnload( );
- testLesson();
+// testLesson();
TitleScreen_load_media();
redraw = 1;
@@ -777,8 +800,8 @@
switch (sub_menu)
{
- case CASCADE: PlayCascade( EASY ); break;
- case LASER: laser_game( EASY ); break;
+// case CASCADE: PlayCascade( EASY ); break;
+// case LASER: laser_game( EASY ); break;
}
TitleScreen_load_media();
@@ -799,8 +822,8 @@
switch (sub_menu)
{
- case CASCADE: PlayCascade( MEDIUM ); break;
- case LASER: laser_game( MEDIUM ); break;
+// case CASCADE: PlayCascade( MEDIUM ); break;
+// case LASER: laser_game( MEDIUM ); break;
}
TitleScreen_load_media();
@@ -822,8 +845,8 @@
switch (sub_menu)
{
- case CASCADE: PlayCascade( HARD ); break;
- case LASER: laser_game( HARD ); break;
+// case CASCADE: PlayCascade( HARD ); break;
+// case LASER: laser_game( HARD ); break;
}
TitleScreen_load_media();
@@ -845,8 +868,8 @@
switch (sub_menu)
{
- case CASCADE: PlayCascade( INSANE ); break;
- case LASER: laser_game( INSANE ); break;
+// case CASCADE: PlayCascade( INSANE ); break;
+// case LASER: laser_game( INSANE ); break;
}
TitleScreen_load_media();
@@ -866,8 +889,8 @@
switch (sub_menu)
{
- case CASCADE: InstructCascade(); break;
- case LASER: InstructLaser(); break;
+// case CASCADE: InstructCascade(); break;
+// case LASER: InstructLaser(); break;
}
TitleScreen_load_media();
@@ -883,7 +906,7 @@
if (menu_opt == FREETYPE)
{
TitleScreen_unload_media();
- Phrases( phrase );
+// Phrases( phrase );
//Practice();
TitleScreen_load_media();
redraw = 1;
@@ -993,7 +1016,7 @@
if (key_menu != old_key_menu)
{
rewind(menu_gfx[key_menu][menu_depth]);
- playsound(snd_move);
+ tuxtype_playsound(snd_move);
}
SDL_BlitSurface(bkg, &menu_button[key_menu], screen, &menu_button[key_menu]);
@@ -1316,3 +1339,215 @@
}
+
+// Was in playgame.c in tuxtype:
+
+/*************************************************/
+/* TransWipe: Performs various wipes to new bkgs */
+/*************************************************/
+/*
+ * Given a wipe request type, and any variables
+ * that wipe requires, will perform a wipe from
+ * the current screen image to a new one.
+ */
+void TransWipe(SDL_Surface* newbkg, int type, int var1, int var2)
+{
+ int i, j, x1, x2, y1, y2;
+ int step1, step2, step3, step4;
+ int frame;
+ SDL_Rect src;
+ SDL_Rect dst;
+
+ LOG("->TransWipe(): START\n");
+
+ numupdates = 0;
+ frame = 0;
+
+ if(newbkg->w == screen->w && newbkg->h == screen->h) {
+ if( type == RANDOM_WIPE )
+ type = (RANDOM_WIPE* ((float) rand()) / (RAND_MAX+1.0));
+
+ switch( type ) {
+ case WIPE_BLINDS_VERT: {
+ LOG("--+ Doing 'WIPE_BLINDS_VERT'\n");
+ /* var1 is num of divisions
+ var2 is how many frames animation should take */
+ if( var1 < 1 ) var1 = 1;
+ if( var2 < 1 ) var2 = 1;
+ step1 = screen->w / var1;
+ step2 = step1 / var2;
+
+ for(i = 0; i <= var2; i++) {
+ for(j = 0; j <= var1; j++) {
+ x1 = step1 * (j - 0.5) - i * step2 + 1;
+ x2 = step1 * (j - 0.5) + i * step2 + 1;
+ src.x = x1;
+ src.y = 0;
+ src.w = step2;
+ src.h = screen->h;
+ dst.x = x2;
+ dst.y = 0;
+ dst.w = step2;
+ dst.h = screen->h;
+ SDL_BlitSurface(newbkg, &src, screen, &src);
+ SDL_BlitSurface(newbkg, &dst, screen, &dst);
+ AddRect(&src, &src);
+ AddRect(&dst, &dst);
+ }
+ UpdateScreen(&frame);
+ }
+
+ src.x = 0;
+ src.y = 0;
+ src.w = screen->w;
+ src.h = screen->h;
+ SDL_BlitSurface(newbkg, NULL, screen, &src);
+ SDL_Flip(screen);
+
+ break;
+ } case WIPE_BLINDS_HORIZ: {
+ LOG("--+ Doing 'WIPE_BLINDS_HORIZ'\n");
+ /* var1 is num of divisions
+ var2 is how many frames animation should take */
+ if( var1 < 1 ) var1 = 1;
+ if( var2 < 1 ) var2 = 1;
+ step1 = screen->h / var1;
+ step2 = step1 / var2;
+
+ for(i = 0; i <= var2; i++) {
+ for(j = 0; j <= var1; j++) {
+ y1 = step1 * (j - 0.5) - i * step2 + 1;
+ y2 = step1 * (j - 0.5) + i * step2 + 1;
+ src.x = 0;
+ src.y = y1;
+ src.w = screen->w;
+ src.h = step2;
+ dst.x = 0;
+ dst.y = y2;
+ dst.w = screen->w;
+ dst.h = step2;
+ SDL_BlitSurface(newbkg, &src, screen, &src);
+ SDL_BlitSurface(newbkg, &dst, screen, &dst);
+ AddRect(&src, &src);
+ AddRect(&dst, &dst);
+ }
+ UpdateScreen(&frame);
+ }
+
+ src.x = 0;
+ src.y = 0;
+ src.w = screen->w;
+ src.h = screen->h;
+ SDL_BlitSurface(newbkg, NULL, screen, &src);
+ SDL_Flip(screen);
+
+ break;
+ } case WIPE_BLINDS_BOX: {
+ LOG("--+ Doing 'WIPE_BLINDS_BOX'\n");
+ /* var1 is num of divisions
+ var2 is how many frames animation should take */
+ if( var1 < 1 ) var1 = 1;
+ if( var2 < 1 ) var2 = 1;
+ step1 = screen->w / var1;
+ step2 = step1 / var2;
+ step3 = screen->h / var1;
+ step4 = step1 / var2;
+
+ for(i = 0; i <= var2; i++) {
+ for(j = 0; j <= var1; j++) {
+ x1 = step1 * (j - 0.5) - i * step2 + 1;
+ x2 = step1 * (j - 0.5) + i * step2 + 1;
+ src.x = x1;
+ src.y = 0;
+ src.w = step2;
+ src.h = screen->h;
+ dst.x = x2;
+ dst.y = 0;
+ dst.w = step2;
+ dst.h = screen->h;
+ SDL_BlitSurface(newbkg, &src, screen, &src);
+ SDL_BlitSurface(newbkg, &dst, screen, &dst);
+ AddRect(&src, &src);
+ AddRect(&dst, &dst);
+ y1 = step3 * (j - 0.5) - i * step4 + 1;
+ y2 = step3 * (j - 0.5) + i * step4 + 1;
+ src.x = 0;
+ src.y = y1;
+ src.w = screen->w;
+ src.h = step4;
+ dst.x = 0;
+ dst.y = y2;
+ dst.w = screen->w;
+ dst.h = step4;
+ SDL_BlitSurface(newbkg, &src, screen, &src);
+ SDL_BlitSurface(newbkg, &dst, screen, &dst);
+ AddRect(&src, &src);
+ AddRect(&dst, &dst);
+ }
+ UpdateScreen(&frame);
+ }
+
+ src.x = 0;
+ src.y = 0;
+ src.w = screen->w;
+ src.h = screen->h;
+ SDL_BlitSurface(newbkg, NULL, screen, &src);
+ SDL_Flip(screen);
+
+ break;
+ } default:
+ break;
+ }
+ }
+}
+
+/************************
+UpdateScreen : Update the screen and increment the frame num
+***************************/
+void UpdateScreen(int *frame) {
+ int i;
+
+ /* -- First erase everything we need to -- */
+ for (i = 0; i < numupdates; i++)
+ if (blits[i].type == 'E')
+ SDL_LowerBlit(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
+// SNOW_erase();
+
+ /* -- then draw -- */
+ for (i = 0; i < numupdates; i++)
+ if (blits[i].type == 'D')
+ SDL_BlitSurface(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
+// SNOW_draw();
+
+ /* -- update the screen only where we need to! -- */
+// if (SNOW_on)
+// SDL_UpdateRects(screen, SNOW_add( (SDL_Rect*)&dstupdate, numupdates ), SNOW_rects);
+// else
+ SDL_UpdateRects(screen, numupdates, dstupdate);
+
+ numupdates = 0;
+ *frame = *frame + 1;
+}
+
+
+/******************************
+AddRect : Dont actually blit a surface,
+ but add a rect to be updated next
+ update
+*******************************/
+void AddRect(SDL_Rect * src, SDL_Rect * dst) {
+ /*borrowed from SL's alien (and modified)*/
+ struct blit *update;
+
+ update = &blits[numupdates++];
+
+ update->srcrect->x = src->x;
+ update->srcrect->y = src->y;
+ update->srcrect->w = src->w;
+ update->srcrect->h = src->h;
+ update->dstrect->x = dst->x;
+ update->dstrect->y = dst->y;
+ update->dstrect->w = dst->w;
+ update->dstrect->h = dst->h;
+ update->type = 'I';
+}
Modified: tuxmath/trunk/src/titlescreen.h
===================================================================
--- tuxmath/trunk/src/titlescreen.h 2006-12-02 00:34:38 UTC (rev 65)
+++ tuxmath/trunk/src/titlescreen.h 2006-12-07 20:20:06 UTC (rev 66)
@@ -104,6 +104,10 @@
#define MAX_NUM_WORDS 500
#define MAX_WORD_SIZE 8
+//MAX_UPDATES needed for TransWipe() and friends:
+#define MAX_UPDATES 180
+
+
#define WAIT_MS 2500
#define FRAMES_PER_SEC 50
#define FULL_CIRCLE 140
@@ -260,4 +264,10 @@
extern void pause_unload_media( void );
extern int inRect( SDL_Rect r, int x, int y);
+/* in audio.c (from tuxtype): */
+extern void tuxtype_playsound( Mix_Chunk *snd );
+extern void audioMusicLoad( char *musicFilename, int repeatQty );
+extern void audioMusicUnload( void );
+extern void audioMusicPlay( Mix_Music *musicData, int repeatQty );
+
#endif //TITLESCREEN_H
More information about the Tux4kids-commits
mailing list