[Tux4kids-commits] r1495 - in tuxmath/trunk: server src
David Bruce
dbruce-guest at alioth.debian.org
Tue Sep 8 12:22:21 UTC 2009
Author: dbruce-guest
Date: 2009-09-08 12:22:20 +0000 (Tue, 08 Sep 2009)
New Revision: 1495
Modified:
tuxmath/trunk/server/server.c
tuxmath/trunk/src/SDL_extras.c
tuxmath/trunk/src/game.c
tuxmath/trunk/src/highscore.c
tuxmath/trunk/src/highscore.h
tuxmath/trunk/src/menu.c
tuxmath/trunk/src/network.c
tuxmath/trunk/src/setup.c
Log:
working on lan play - still not handling questions properly
Modified: tuxmath/trunk/server/server.c
===================================================================
--- tuxmath/trunk/server/server.c 2009-09-07 21:56:03 UTC (rev 1494)
+++ tuxmath/trunk/server/server.c 2009-09-08 12:22:20 UTC (rev 1495)
@@ -16,9 +16,8 @@
* derivative works into a GPLv2+ project like TuxMath - David Bruce
*/
+#include "config.h"
-
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -40,6 +39,7 @@
// setup and cleanup:
int setup_server(void);
void cleanup_server(void);
+void handle_command_args(int argc, char* argv[]);
// top level functions in main loop:
void check_UDP(void);
@@ -84,6 +84,7 @@
/* ------------ "Local globals" for server.c: ---------- */
char server_name[NAME_SIZE]; /* User-visible name for server selection */
+int need_server_name = 1;
UDPsocket udpsock = NULL; /* Used to listen for client's server autodetection */
TCPsocket server_sock = NULL; /* Socket descriptor for server to accept client TCP sockets. */
IPaddress ip;
@@ -103,6 +104,8 @@
{
printf("Started tuxmathserver, waiting for client to connect:\n>\n");
+ handle_command_args(argc, argv);
+
/* ---------------- Setup: --------------------------- */
if (!setup_server())
{
@@ -192,14 +195,13 @@
{
fprintf(stderr, "Could not initialize MathCards\n");
return 0;
- }
+ }
-
/* Get server name: */
/* We use default name after 30 sec timeout if no name entered. */
/* FIXME we should save this to disc so it doesn't */
/* have to be entered every time. */
-
+ if(need_server_name)
{
Uint32 timeout = SDL_GetTicks() + SERVER_NAME_TIMEOUT;
int name_recvd = 0;
@@ -285,8 +287,55 @@
}
+/* Handle any arguments passed from command line */
+void handle_command_args(int argc, char* argv[])
+{
+ int i;
+ for (i = 1; i < argc; i++)
+ {
+ if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
+ {
+ /* Display help message: */
+ printf("\n");
+ cleanup_server();
+ exit(0);
+ }
+ else if (strcmp(argv[i], "--copyright") == 0 ||
+ strcmp(argv[i], "-c") == 0)
+ {
+ printf(
+ "\n\"Tux, of Math Command Server\" version " VERSION ", Copyright (C) 2009,\n"
+ "David Bruce, Akash Gangil, and the Tux4Kids Project.\n"
+ "This program is free software; you can redistribute it and/or\n"
+ "modify it under the terms of the GNU General Public License\n"
+ "as published by the Free Software Foundation. See COPYING.txt\n"
+ "\n"
+ "This program is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
+ "\n");
+ cleanup_server();
+ exit(0);
+ }
+ else if (strcmp(argv[i], "--usage") == 0 ||
+ strcmp(argv[i], "-u") == 0)
+ {
+ /* Display (happy) usage: */
+
+// usage(0, argv[0]);
+ }
+ else if ((strcmp(argv[i], "--name") == 0 || strcmp(argv[i], "-n") == 0)
+ && (i + 1 < argc))
+ {
+ strncpy(server_name, argv[i + 1], NAME_SIZE);
+ need_server_name = 0;
+ }
+ }
+}
+
+
// ----------- Top level functions in main loop ---------------:
//check_UDP() is the server side of the client-server autodetection system.
Modified: tuxmath/trunk/src/SDL_extras.c
===================================================================
--- tuxmath/trunk/src/SDL_extras.c 2009-09-07 21:56:03 UTC (rev 1494)
+++ tuxmath/trunk/src/SDL_extras.c 2009-09-08 12:22:20 UTC (rev 1495)
@@ -739,27 +739,27 @@
#ifdef HAVE_LIBSDL_PANGO
if (!context)
{
- fprintf(stderr, "BlackOutline(): invalid SDL_Pango context - returning.");
+ fprintf(stderr, "BlackOutline(): invalid SDL_Pango context - returning.\n");
return NULL;
}
#else
TTF_Font* font = get_font(size);
if (!font)
{
- fprintf(stderr, "BlackOutline(): could not load needed font - returning.");
+ fprintf(stderr, "BlackOutline(): could not load needed font - returning.\n");
return NULL;
}
#endif
if (!t || !c)
{
- fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
+ fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.\n");
return NULL;
}
if (t[0] == '\0')
{
- fprintf(stderr, "BlackOutline(): empty string, returning");
+ fprintf(stderr, "BlackOutline(): empty string, returning\n");
return NULL;
}
Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c 2009-09-07 21:56:03 UTC (rev 1494)
+++ tuxmath/trunk/src/game.c 2009-09-08 12:22:20 UTC (rev 1495)
@@ -104,7 +104,7 @@
static int tux_anim;
static int tux_anim_frame;
static int num_cities_alive;
-static int num_comets_alive;
+//static int num_comets_alive;
static int tux_img;
static int old_tux_img;
static int frame;
@@ -164,7 +164,7 @@
static void game_handle_user_events(void);
static void game_handle_demo(void);
static void game_handle_answer(void);
-static void game_handle_net_messages(char*,char*);
+static void game_handle_net_messages(char* buf);
static void game_countdown(void);
static void game_handle_tux(void);
static void game_handle_comets(void);
@@ -194,6 +194,8 @@
static int add_comet(void);
static void add_score(int inc);
static void reset_comets(void);
+static int num_comets_alive(void);
+
static void copy_card(MC_FlashCard* src, MC_FlashCard* dest);
static void game_mouse_event(SDL_Event event);
@@ -281,26 +283,37 @@
if(Opts_LanMode())
{
#ifdef HAVE_LIBSDL_NET
- int status = check_messages(buf);
- while(!status)
+ int done = 0;
+ while(!done)
{
- seperate_commmand_and_buf(command, buf);
- game_handle_net_messages(buf, command);
- status = check_messages(buf);
+ switch(LAN_NextMsg(buf))
+ {
+ case 1: //Message received:
+ game_handle_net_messages(buf);
+ break;
+ case 0: //No more messages:
+ done = 1;
+ break;
+ case -1: //Error in networking or server:
+ game_cleanup();
+ return GAME_OVER_ERROR;
+ default:
+ {}
+ }
}
-
- if(status == -1)
- {
- game_cleanup();
- return GAME_OVER_ERROR;
- }
#else
fprintf(stderr, "Warning - LAN mode selected but SDL_net not available!\n");
Opts_SetLanMode(0);
#endif
}
+ else
+ {
+ if (add_comet())
+ {
+ num_attackers--;
+ }
+ }
-
/* Most code now in smaller functions: */
// 1. Check for user input
@@ -349,6 +362,7 @@
while(GAME_IN_PROGRESS == game_status);
/* END OF MAIN GAME LOOP! */
+
DEBUGCODE(debug_game) print_exit_conditions();
/* TODO: need better "victory" screen with animation, special music, etc., */
@@ -524,7 +538,7 @@
comet_ques->x = 0;
comet_ques->y = 0;
comet_ques->answer = 0;
- num_comets_alive--;
+// num_comets_alive--;
erase_flashcard(&(comet_ques->flashcard));
return 1;
@@ -535,12 +549,21 @@
int add_quest_recvd(char* buf)
{
MC_FlashCard* fc = find_comet_by_id(-1);
+
+ DEBUGMSG(debug_game, "Enter add_quest_recvd(), buf is: %s\n", buf);
+
// if fc = NULL means no empty slot for question
- if(!fc || !buf)
+ if(!buf)
{
- printf("NULL fc or buf\n");
+ printf("NULL buf\n");
return 0;
}
+ if(!fc)
+ {
+ printf("NULL fc - no empty slot for question\n");
+ return 0;
+ }
+
/* function call to parse buffer and receive question */
if(!Make_Flashcard(buf, fc))
{
@@ -548,6 +571,8 @@
return 0;
}
+ DEBUGCODE(debug_game) print_current_quests();
+
return 1;
}
@@ -565,7 +590,9 @@
if(!p)
return 0;
+ p++;
id = atoi(p);
+ DEBUGMSG(debug_game, "remove_quest_recvd() for id = %d\n", id);
if(id < 1) // The question_id can never be negative or zero
return 0;
@@ -576,6 +603,7 @@
if(comet_screen)
{
+ DEBUGMSG(debug_game, "comet on screen found with question_id = %d\n", id);
erase_comet_on_screen(comet_screen);
playsound(SND_SIZZLE);
}
@@ -599,17 +627,21 @@
{
int i;
printf("\n------------ Current Questions: -----------\n");
- for(i = 0; i < MAX_COMETS; i ++)
+ for(i = 0; i < MAX_COMETS; i++)
{
- if(comets[i].alive==1)
+ if(comets[i].alive == 1)
printf("Comet %d - question %d:\t%s\n", i, comets[i].flashcard.question_id, comets[i].flashcard.formula_string);
-/* if(comets_questions[i].question_id != -1)
+ }
+ printf("--------------Test Comets-----------------\n");
+ for(i = 0; i < TEST_COMETS; i++)
+ {
+ if(comets_questions[i].question_id != -1)
printf("Comet %d - question %d:\t%s\n", i, comets_questions[i].question_id, comets_questions[i].formula_string);
else
printf("Comet %d:\tEmpty\n", i);
-*/}
- printf("-----------------------------------------------\n");
+ }
+ printf("------------------------------------------\n");
}
@@ -628,13 +660,14 @@
return NULL;
}
+
comet_type* finder(int id)
{
int i;
for (i = 0; i < MAX_COMETS; i++)
{
- if (comets[i].flashcard.question_id==id)
- {printf("the question id is id=%d\n",i);
+ if (comets[i].flashcard.question_id == id)
+ {printf("the question id is in slot %d\n",i);
return &comets[i];}
}
@@ -652,20 +685,22 @@
#ifdef HAVE_LIBSDL_NET
-void game_handle_net_messages(char buf[NET_BUF_LEN],char command[NET_BUF_LEN])
+void game_handle_net_messages(char* buf)
{
- if(strncmp(command,"PLAYER_MSG",strlen("PLAYER_MSG"))==0)
+ DEBUGMSG(debug_game, "Received server message: %s\n", buf);
+
+ if(strncmp(buf, "PLAYER_MSG", strlen("PLAYER_MSG")) == 0)
{
printf("buf is %s\n", buf);
}
- else if(strncmp(command,"SEND_QUESTION",strlen("SEND_QUESTION"))==0)
+ else if(strncmp(buf, "SEND_QUESTION", strlen("SEND_QUESTION")) == 0)
{
- if(!add_quest_recvd(buf))
- printf("SEND_QUESTION received but could not add question\n");
- else
- // If we successfully added question, show new questions to user:
- print_current_quests();
+ if(!add_quest_recvd(buf))
+ printf("SEND_QUESTION received but could not add question\n");
+ else
+ // If we successfully added question, show new questions to user:
+ print_current_quests();
}
else if(strncmp(buf, "REMOVE_QUESTION", strlen("REMOVE_QUESTION")) == 0)
@@ -684,19 +719,21 @@
print_current_quests();
}
- else if(strncmp(command,"TOTAL_QUESTIONS",strlen("TOTAL_QUESTIONS"))==0)
+ else if(strncmp(buf,"TOTAL_QUESTIONS", strlen("TOTAL_QUESTIONS"))==0)
{
sscanf(buf,"%*s %d", &total_questions_left);
if(!total_questions_left)
game_over_other=1;
}
- else if(strncmp(command,"GAME_OVER_WON",strlen("GAME_OVER_WON"))==0)
+ else if(strncmp(buf,"GAME_OVER_WON", strlen("GAME_OVER_WON"))==0)
{
game_over_won=1;
}
- /* FIXME need to handle unrecognized messages, maybe just printf()
- with a warning until they get implemented - DSB */
+ else
+ {
+ DEBUGMSG(debug_game, "Unrecognized message from server: %s\n", buf);
+ }
}
#endif
@@ -866,7 +903,7 @@
}
num_cities_alive = NUM_CITIES;
- num_comets_alive = 0;
+// num_comets_alive = 0;
igloo_vertical_offset = images[IMG_CITY_BLUE]->h - images[IMG_IGLOO_INTACT]->h;
@@ -1189,7 +1226,7 @@
comets[0].alive = 1;
comets[0].expl = -1;
comets[0].answer = atoi(ans_str);
- num_comets_alive = 1;
+// num_comets_alive = 1;
comets[0].city = 0;
comets[0].x = cities[0].x;
comets[0].y = 0;
@@ -1582,7 +1619,7 @@
int i, this_city;
Uint32 ctime;
- num_comets_alive = 0;
+// num_comets_alive = 0;
/* Clear the threatened flag on each city */
for (i = 0; i < NUM_CITIES; i++)
@@ -1592,7 +1629,7 @@
{
if (comets[i].alive)
{
- num_comets_alive++;
+// num_comets_alive++;
this_city = comets[i].city;
/* Update comet position */
@@ -1728,7 +1765,7 @@
/* num_attackers is how many comets are left in wave */
if (num_attackers > 0)
{
-// if ((rand() % 2) == 0 || num_comets_alive == 0) NOTE also caused timing issue
+// if ((rand() % 2) == 0 || num_comets_alive() == 0) NOTE also caused timing issue
{
if (add_comet())
{
@@ -1739,7 +1776,7 @@
}
else
{
- if (num_comets_alive == 0)
+ if (num_comets_alive() == 0)
{
if (!check_extra_life()) {
/* Time for the next wave! */
@@ -2584,18 +2621,25 @@
return GAME_OVER_OTHER;
}
}
-
+
+
+ //NOTE can't use this check in LAN mode because we don't know if the server has
+ //questions left
+
/* Need to get out if no comets alive and MathCards has no questions left in list, */
/* even though MathCards thinks there are still questions "in play". */
/* This SHOULD NOT HAPPEN and means we have a bug somewhere. */
- if (!MC_ListQuestionsLeft() && !num_comets_alive)
+ if (!Opts_LanMode())
{
- fprintf(stderr, "Error - no questions left but game not over\n");
- DEBUGMSG(debug_game, "ListQuestionsLeft() = %d ", MC_ListQuestionsLeft());
- DEBUGMSG(debug_game, "num_comets_alive = %d", num_comets_alive);
- return GAME_OVER_ERROR;
- }
-
+ if (!MC_ListQuestionsLeft() && !num_comets_alive())
+ {
+ fprintf(stderr, "Error - no questions left but game not over\n");
+ DEBUGMSG(debug_game, "ListQuestionsLeft() = %d ", MC_ListQuestionsLeft());
+ DEBUGMSG(debug_game, "num_comets_alive() = %d", num_comets_alive());
+ return GAME_OVER_ERROR;
+ }
+ }
+
/* If using demo mode, see if counter has run out: */
if (Opts_DemoMode())
{
@@ -2675,7 +2719,7 @@
{
comets[i].alive = 0;
}
- num_comets_alive = 0;
+// num_comets_alive = 0;
/* Clear LED F: */
@@ -2842,7 +2886,11 @@
{
if (comets[i].alive)
if (comets[i].y < y_spacing)
- return 0;
+ {
+// DEBUGMSG(debug_game, "add_comet() - returning because comet[%d] not"
+// " far enough down: %f\n", i, comets[i].y);
+// return 0;
+ }
}
/* Now look for a free comet slot: */
@@ -2858,6 +2906,8 @@
if (-1 == found)
{
/* free comet slot not found - no comet added: */
+ DEBUGMSG(debug_game, "add_comet() called but no free comet slot\n");
+ DEBUGCODE(debug_game) print_current_quests();
return 0;
}
@@ -2869,17 +2919,24 @@
if(Opts_LanMode())
{
#ifdef HAVE_LIBSDL_NET
+ int lan_quest_found = 0;
for (i = 0; i < TEST_COMETS; i++)
{
if(comets_questions[i].question_id != -1)
{
+ DEBUGMSG(debug_game, "Found question_id %d, %s\n",
+ comets_questions[i].question_id,
+ comets_questions[i].formula_string);
+ lan_quest_found = 1;
copy_card(&(comets_questions[i]), &(comets[found].flashcard));
erase_flashcard(&(comets_questions[i]));
break;
}
}
- if(i == TEST_COMETS)
+ DEBUGCODE(debug_game) print_current_quests();
+
+ if(!lan_quest_found)
{
DEBUGMSG(debug_game, "add_comet() called but no question available in queue\n");
return 0;
@@ -2920,7 +2977,7 @@
/* If we make it to here, create a new comet!*/
comets[found].answer = comets[found].flashcard.answer;
comets[found].alive = 1;
- num_comets_alive++;
+// num_comets_alive++;
/* Pick a city to attack that was not attacked last time */
/* (so formulas are less likely to overlap). */
@@ -2951,7 +3008,7 @@
DEBUGMSG(debug_game, "Created bonus comet");
}
- DEBUGMSG(debug_game, "add_comet(): formula string is: %s", comets[found].flashcard.formula_string);
+ DEBUGMSG(debug_game, "add_comet(): formula string is: %s\n", comets[found].flashcard.formula_string);
/* Record the time at which this comet was created */
comets[found].time_started = SDL_GetTicks();
@@ -3846,3 +3903,13 @@
// comets[i].y = comets[i].y * RES_Y / screen->h;
}
}
+
+static int num_comets_alive()
+{
+ int i = 0;
+ int living = 0;
+ for(i = 0; i < MAX_COMETS; i++)
+ if(comets[i].alive)
+ living++;
+ return living;
+}
\ No newline at end of file
Modified: tuxmath/trunk/src/highscore.c
===================================================================
--- tuxmath/trunk/src/highscore.c 2009-09-07 21:56:03 UTC (rev 1494)
+++ tuxmath/trunk/src/highscore.c 2009-09-08 12:22:20 UTC (rev 1495)
@@ -22,6 +22,7 @@
#include "convert_utf.h"
#include "transtruct.h"
#include "network.h"
+#include "throttle.h"
typedef struct high_score_entry {
@@ -314,6 +315,12 @@
DrawTitleScreen();
+ /* Red "Stop" circle in upper right corner to go back to main menu: */
+ if (stop_button)
+ {
+ SDL_BlitSurface(stop_button, NULL, screen, &stop_rect);
+ }
+
/* Draw translucent background for text: */
{
SDL_Rect bg_rect;
@@ -481,7 +488,7 @@
SDL_EnableUNICODE(SDL_DISABLE);
/* Now copy name into location pointed to by arg: */
- strncpy((char*)pl_name, (char*)UTF8_buf, HIGH_SCORE_NAME_LENGTH * 3);
+ strncpy(pl_name, UTF8_buf, HIGH_SCORE_NAME_LENGTH * 3);
}
@@ -718,58 +725,36 @@
}
-void Ready(const char* heading)
+int Ready(const char* heading)
{
SDL_Rect loc;
- SDL_Rect TuxRect,
- stopRect,
- okRect;
-
+ SDL_Rect okRect;
int finished = 0;
- int tux_frame = 0;
Uint32 frame = 0;
- Uint32 start = 0;
- sprite* Tux = LoadSprite("tux/bigtux", IMG_ALPHA);
+ const int BG_Y = 100;
+ const int BG_WIDTH = 400;
+ const int BG_HEIGHT = 200;
+ DEBUGMSG(debug_highscore, "Enter Ready()\n" );
- /* We need to get Unicode vals from SDL keysyms */
- SDL_EnableUNICODE(SDL_ENABLE);
+ DrawTitleScreen();
-
-
- /* Draw background: */
- if (current_bkg())
- SDL_BlitSurface(current_bkg(), NULL, screen, NULL);
-
- /* Red "Stop" circle in upper right corner to go back to main menu: */
- if (images[IMG_STOP])
+ /* Draw translucent background for text: */
{
- stopRect.w = images[IMG_STOP]->w;
- stopRect.h = images[IMG_STOP]->h;
- stopRect.x = screen->w - images[IMG_STOP]->w;
- stopRect.y = 0;
- SDL_BlitSurface(images[IMG_STOP], NULL, screen, &stopRect);
- }
+ SDL_Rect bg_rect;
+ bg_rect.x = (screen->w)/2 - BG_WIDTH/2;
+ bg_rect.y = BG_Y;
+ bg_rect.w = BG_WIDTH;
+ bg_rect.h = BG_HEIGHT;
+ DrawButton(&bg_rect, 15, REG_RGBA);
- if (images[IMG_RIGHT])
- {
- okRect.w = (images[IMG_RIGHT]->w)*2;
- okRect.h = (images[IMG_RIGHT]->h)*2;
- okRect.x = (screen->w)/2;
- okRect.y = 240;
- SDL_BlitSurface(images[IMG_RIGHT], NULL, screen, &okRect);
+ bg_rect.x += 10;
+ bg_rect.y += 10;
+ bg_rect.w -= 20;
+ bg_rect.h = 60;
+ DrawButton(&bg_rect, 10, SEL_RGBA);
}
-
- if (Tux && Tux->frame[0]) /* make sure sprite has at least one frame */
- {
- TuxRect.w = Tux->frame[0]->w;
- TuxRect.h = Tux->frame[0]->h;
- TuxRect.x = 0;
- TuxRect.y = screen->h - Tux->frame[0]->h;
- }
-
-
/* Draw heading: */
{
SDL_Surface* s = BlackOutline(_(heading),
@@ -781,19 +766,30 @@
SDL_BlitSurface(s, NULL, screen, &loc);
SDL_FreeSurface(s);
}
+ }
+ /* Red "Stop" circle in upper right corner to go back to main menu: */
+ if (stop_button)
+ {
+ SDL_BlitSurface(stop_button, NULL, screen, &stop_rect);
}
+ /* "Next_arrow" to indicate ready to proceed: */
+ if (next_arrow)
+ {
+ okRect.x = (screen->w)/2;
+ okRect.y = 240;
+ SDL_BlitSurface(next_arrow, NULL, screen, &okRect);
+ }
+
/* and update: */
SDL_UpdateRect(screen, 0, 0, 0, 0);
-
while (!finished)
{
- start = SDL_GetTicks();
-
- while (SDL_PollEvent(&event))
+ /* Handle user events: */
+ while (SDL_PollEvent(&event))
{
switch (event.type)
{
@@ -804,104 +800,90 @@
case SDL_MOUSEBUTTONDOWN:
/* "Stop" button - go to main menu: */
- {
- if (inRect(stopRect, event.button.x, event.button.y ))
+ {
+ if (inRect(stop_rect, event.button.x, event.button.y ))
{
- finished = 1;
+ finished = -1;
playsound(SND_TOCK);
break;
- }
-
- if (inRect(okRect, event.button.x, event.button.y ))
+ }
+ else if (inRect(okRect, event.button.x, event.button.y ))
{
finished = 1;
playsound(SND_TOCK);
break;
}
-
+
}
+ case SDL_KEYDOWN:
+ {
+ switch (event.key.keysym.sym)
+ {
+ case SDLK_ESCAPE:
+ case SDLK_BACKSPACE:
+ {
+ finished = -2;
+ playsound(SND_TOCK);
+ break;
+ }
+ case SDLK_RETURN:
+ case SDLK_KP_ENTER:
+ case SDLK_SPACE:
+ {
+ finished = 1;
+ playsound(SND_TOCK);
+ break;
+ }
+ default:
+ {
+ //Do nothing - event. add support for toggle fullscreen, etc.
+ }
+ }
+ }
}
}
-
- /* --- make tux blink --- */
- switch (frame % TUX6)
- {
- case 0: tux_frame = 1; break;
- case TUX1: tux_frame = 2; break;
- case TUX2: tux_frame = 3; break;
- case TUX3: tux_frame = 4; break;
- case TUX4: tux_frame = 3; break;
- case TUX5: tux_frame = 2; break;
- default: tux_frame = 0;
- }
- if (Tux && tux_frame)
- {
- SDL_BlitSurface(Tux->frame[tux_frame - 1], NULL, screen, &TuxRect);
- SDL_UpdateRect(screen, TuxRect.x, TuxRect.y, TuxRect.w, TuxRect.h);
- }
-
- /* Wait so we keep frame rate constant: */
- while ((SDL_GetTicks() - start) < 33)
- {
- SDL_Delay(20);
- }
+ HandleTitleScreenAnimations();
+ Throttle(20);
frame++;
} // End of while (!finished) loop
- FreeSprite(Tux);
+ DEBUGMSG(debug_highscore, "Leave Ready()\n" );
- /* Turn off SDL Unicode lookup (because has some overhead): */
- SDL_EnableUNICODE(SDL_DISABLE);
-
+ /* 1 means we start game, -1 means we go back to menu */
+ return finished;
}
int Standby(const char* heading, const char* sub)
{
-
SDL_Rect loc;
- SDL_Rect TuxRect,
- stopRect;
- char buf[NET_BUF_LEN];
-
int finished = 0;
- int tux_frame = 0;
Uint32 frame = 0;
- Uint32 start = 0;
+ const int BG_Y = 100;
+ const int BG_WIDTH = 400;
+ const int BG_HEIGHT = 200;
+ char buf[NET_BUF_LEN];
- sprite* Tux = LoadSprite("tux/bigtux", IMG_ALPHA);
+ DEBUGMSG(debug_highscore, "Enter Standby()\n" );
+ DrawTitleScreen();
- /* We need to get Unicode vals from SDL keysyms */
- SDL_EnableUNICODE(SDL_ENABLE);
-
-#ifdef TUXMATH_DEBUG
- fprintf(stderr, "\nEnter HighScoreNameEntry()\n" );
-#endif
-
-
- /* Draw background: */
- if (current_bkg())
- SDL_BlitSurface(current_bkg(), NULL, screen, NULL);
-
- /* Red "Stop" circle in upper right corner to go back to main menu: */
- if (images[IMG_STOP])
+ /* Draw translucent background for text: */
{
- stopRect.w = images[IMG_STOP]->w;
- stopRect.h = images[IMG_STOP]->h;
- stopRect.x = screen->w - images[IMG_STOP]->w;
- stopRect.y = 0;
- SDL_BlitSurface(images[IMG_STOP], NULL, screen, &stopRect);
- }
+ SDL_Rect bg_rect;
+ bg_rect.x = (screen->w)/2 - BG_WIDTH/2;
+ bg_rect.y = BG_Y;
+ bg_rect.w = BG_WIDTH;
+ bg_rect.h = BG_HEIGHT;
+ DrawButton(&bg_rect, 15, REG_RGBA);
- if (Tux && Tux->frame[0]) /* make sure sprite has at least one frame */
- {
- TuxRect.w = Tux->frame[0]->w;
- TuxRect.h = Tux->frame[0]->h;
- TuxRect.x = 0;
- TuxRect.y = screen->h - Tux->frame[0]->h;
+ bg_rect.x += 10;
+ bg_rect.y += 10;
+ bg_rect.w -= 20;
+ bg_rect.h = 60;
+ DrawButton(&bg_rect, 10, SEL_RGBA);
}
/* Draw heading: */
@@ -927,16 +909,20 @@
}
}
+ /* Red "Stop" circle in upper right corner to go back to main menu: */
+ if (stop_button)
+ {
+ SDL_BlitSurface(stop_button, NULL, screen, &stop_rect);
+ }
+
/* and update: */
SDL_UpdateRect(screen, 0, 0, 0, 0);
-
while (!finished)
{
- start = SDL_GetTicks();
-
- while (SDL_PollEvent(&event))
+ /* Handle user events: */
+ while (SDL_PollEvent(&event))
{
switch (event.type)
{
@@ -947,24 +933,39 @@
case SDL_MOUSEBUTTONDOWN:
/* "Stop" button - go to main menu: */
- {
- if (inRect(stopRect, event.button.x, event.button.y ))
+ {
+ if (inRect(stop_rect, event.button.x, event.button.y ))
{
- finished = -1;
+ finished = 1;
playsound(SND_TOCK);
break;
}
}
+ case SDL_KEYDOWN:
+ {
+ switch (event.key.keysym.sym)
+ {
+ case SDLK_ESCAPE:
+ case SDLK_BACKSPACE:
+ {
+ finished = -2;
+ playsound(SND_TOCK);
+ break;
+ }
+
+ default:
+ {
+ //Do nothing - event. add support for toggle fullscreen, etc.
+ }
+ }
+ }
}
}
- //FIXME - so we pull all the messages out of the socket and ignore anything
- //that isn't "GO_TO_GAME" - why are we ignoring them? We cannot assume the
- //server is going to send us what we expect. At a minimum, we need to
- //print any unrecognized messages to stderr with a warning - DSB
+ /* Handle server messages: */
while(!check_messages(buf))
{
- if(strncmp(buf,"GO_TO_GAME",strlen("GO_TO_GAME")) == 0)
+ if(strncmp(buf,"GO_TO_GAME", strlen("GO_TO_GAME")) == 0)
{
finished = 1;
playsound(SND_TOCK);
@@ -976,39 +977,20 @@
playsound(SND_TOCK);
break;
}
+ else
+ {
+ DEBUGMSG(debug_highscore, "Unrecognized message from server: %s\n", buf);
+ continue;
+ }
}
- /* --- make tux blink --- */
- switch (frame % TUX6)
- {
- case 0: tux_frame = 1; break;
- case TUX1: tux_frame = 2; break;
- case TUX2: tux_frame = 3; break;
- case TUX3: tux_frame = 4; break;
- case TUX4: tux_frame = 3; break;
- case TUX5: tux_frame = 2; break;
- default: tux_frame = 0;
- }
-
- if (Tux && tux_frame)
- {
- SDL_BlitSurface(Tux->frame[tux_frame - 1], NULL, screen, &TuxRect);
- SDL_UpdateRect(screen, TuxRect.x, TuxRect.y, TuxRect.w, TuxRect.h);
- }
-
- /* Wait so we keep frame rate constant: */
- while ((SDL_GetTicks() - start) < 33)
- {
- SDL_Delay(20);
- }
+ HandleTitleScreenAnimations();
+ Throttle(20);
frame++;
} // End of while (!finished) loop
- FreeSprite(Tux);
+ DEBUGMSG(debug_highscore, "Leave Standby()\n" );
- /* Turn off SDL Unicode lookup (because has some overhead): */
- SDL_EnableUNICODE(SDL_DISABLE);
-
/* 1 means we start game, -1 means we go back to menu */
return finished;
}
Modified: tuxmath/trunk/src/highscore.h
===================================================================
--- tuxmath/trunk/src/highscore.h 2009-09-07 21:56:03 UTC (rev 1494)
+++ tuxmath/trunk/src/highscore.h 2009-09-08 12:22:20 UTC (rev 1495)
@@ -22,7 +22,7 @@
void NameEntry(char* pl_name, const char* heading, const char* sub);
int Standby(const char* heading, const char* sub);
int detecting_servers(const char* heading, const char* sub);
-void Ready(const char* heading);
+int Ready(const char* heading);
int check_score_place(int diff_level, int new_score);
int insert_score(char* playername, int diff_level, int new_score);
Modified: tuxmath/trunk/src/menu.c
===================================================================
--- tuxmath/trunk/src/menu.c 2009-09-07 21:56:03 UTC (rev 1494)
+++ tuxmath/trunk/src/menu.c 2009-09-08 12:22:20 UTC (rev 1495)
@@ -103,6 +103,7 @@
void run_multiplayer(int mode, int difficulty);
int run_factoroids(int choice);
int run_lan_join(void);
+int run_lan_host(void);
int run_menu(MenuNode* menu, bool return_choice);
SDL_Surface** render_buttons(MenuNode* menu, bool selected);
@@ -314,6 +315,7 @@
break;
case RUN_LAN_HOST:
+ run_lan_host();
break;
case RUN_LAN_JOIN:
@@ -567,7 +569,25 @@
}
+/* FIXME this implementation starts the server as a separate program, which */
+/* keeps running after tuxmath itself exits. Do we want this?. Or should */
+/* we run the server as a separate process with fork(), or as a separate */
+/* thread with pthreads, realizing that each of these has portability issues? */
+int run_lan_host(void)
+{
+#ifdef HAVE_LIBSDL_NET
+ char buf[256];
+ char server_name[150];
+ NameEntry(server_name, _("Enter Server Name:"), _("(limit 50 characters)"));
+ snprintf(buf, 256, "tuxmathserver --name \"%s\" &", server_name);
+ system(buf);
+#endif
+ return 0;
+}
+
+
+
int run_lan_join(void)
{
#ifdef HAVE_LIBSDL_NET
Modified: tuxmath/trunk/src/network.c
===================================================================
--- tuxmath/trunk/src/network.c 2009-09-07 21:56:03 UTC (rev 1494)
+++ tuxmath/trunk/src/network.c 2009-09-08 12:22:20 UTC (rev 1495)
@@ -275,6 +275,7 @@
printf("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
//most of the time this is a system error, where perror might help you.
perror("SDLNet_CheckSockets");
+ return -1;
}
else if(numready > 0)
{
Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c 2009-09-07 21:56:03 UTC (rev 1494)
+++ tuxmath/trunk/src/setup.c 2009-09-08 12:22:20 UTC (rev 1495)
@@ -276,7 +276,8 @@
strcmp(argv[i], "-c") == 0)
{
printf(
- "\n\"Tux, of Math Command\" version " VERSION ", Copyright (C) 2001 Bill Kendrick\n"
+ "\n\"Tux, of Math Command\" version " VERSION ", Copyright (C) 2001-2009,\n"
+ "Bill Kendrick, David Bruce, Tim Holy, and the Tux4Kids Project.\n"
"This program is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU General Public License\n"
"as published by the Free Software Foundation. See COPYING.txt\n"
More information about the Tux4kids-commits
mailing list