[Tux4kids-commits] r178 - in tuxtype/trunk: . tuxtype
David Bruce
dbruce-guest at alioth.debian.org
Mon May 7 15:31:43 UTC 2007
Author: dbruce-guest
Date: 2007-05-07 15:31:34 +0000 (Mon, 07 May 2007)
New Revision: 178
Modified:
tuxtype/trunk/ChangeLog
tuxtype/trunk/configure
tuxtype/trunk/configure.in
tuxtype/trunk/tuxtype/alphabet.c
tuxtype/trunk/tuxtype/funcs.h
tuxtype/trunk/tuxtype/globals.h
tuxtype/trunk/tuxtype/laser.c
tuxtype/trunk/tuxtype/laser.h
tuxtype/trunk/tuxtype/loaders.c
tuxtype/trunk/tuxtype/playgame.c
tuxtype/trunk/tuxtype/playgame.h
Log:
Converted internal word handling to wchar_t/Unicode
Modified: tuxtype/trunk/ChangeLog
===================================================================
--- tuxtype/trunk/ChangeLog 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/ChangeLog 2007-05-07 15:31:34 UTC (rev 178)
@@ -1,3 +1,14 @@
+v.1.5.9 07 May 2007
+
+[ David Bruce]
+ - Overhauled internal handling of word lists to handle UTF-8
+ correctly. Now WORDS_use() converts the UTF-8 to wchar_t
+ (i.e. Unicode) arrays for internal handling. The letters for
+ the fish and comets are now generated by black_outline_wchar(),
+ which is a modification of black_outline() that uses
+ TTF_RenderGlyph() instead of TTF_RenderUTF8(). It now seems
+ to work correctly, but for now is limited to the 0-255 range.
+
v.1.5.8 29 Apr 2007
[ Karl Ove Hufthammer ]
Modified: tuxtype/trunk/configure
===================================================================
--- tuxtype/trunk/configure 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/configure 2007-05-07 15:31:34 UTC (rev 178)
@@ -1,7 +1,9 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for tuxtype 1.5.7.
+# Generated by GNU Autoconf 2.61 for tuxtype 1.5.9.
#
+# Report bugs to <tuxmath-devel at lists.sourceforge.net>.
+#
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
# This configure script is free software; the Free Software Foundation
@@ -572,9 +574,9 @@
# Identity of this package.
PACKAGE_NAME='tuxtype'
PACKAGE_TARNAME='tuxtype'
-PACKAGE_VERSION='1.5.7'
-PACKAGE_STRING='tuxtype 1.5.7'
-PACKAGE_BUGREPORT=''
+PACKAGE_VERSION='1.5.9'
+PACKAGE_STRING='tuxtype 1.5.9'
+PACKAGE_BUGREPORT='tuxmath-devel at lists.sourceforge.net'
ac_unique_file="tuxtype/funcs.h"
ac_default_prefix=/usr/local
@@ -1230,7 +1232,7 @@
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures tuxtype 1.5.7 to adapt to many kinds of systems.
+\`configure' configures tuxtype 1.5.9 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1301,7 +1303,7 @@
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of tuxtype 1.5.7:";;
+ short | recursive ) echo "Configuration of tuxtype 1.5.9:";;
esac
cat <<\_ACEOF
@@ -1334,6 +1336,7 @@
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
+Report bugs to <tuxmath-devel at lists.sourceforge.net>.
_ACEOF
ac_status=$?
fi
@@ -1394,7 +1397,7 @@
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-tuxtype configure 1.5.7
+tuxtype configure 1.5.9
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1408,7 +1411,7 @@
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by tuxtype $as_me 1.5.7, which was
+It was created by tuxtype $as_me 1.5.9, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0 $@
@@ -2226,7 +2229,7 @@
# Define the identity of the package.
PACKAGE=tuxtype
- VERSION=1.5.7
+ VERSION=1.5.9
cat >>confdefs.h <<_ACEOF
@@ -4970,7 +4973,12 @@
echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
{ echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
-
+ ( cat <<\_ASBOX
+## -------------------------------------------------- ##
+## Report this to tuxmath-devel at lists.sourceforge.net ##
+## -------------------------------------------------- ##
+_ASBOX
+ ) | sed "s/^/$as_me: WARNING: /" >&2
;;
esac
{ echo "$as_me:$LINENO: checking for $ac_header" >&5
@@ -5781,7 +5789,7 @@
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by tuxtype $as_me 1.5.7, which was
+This file was extended by tuxtype $as_me 1.5.9, which was
generated by GNU Autoconf 2.61. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -5834,7 +5842,7 @@
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
-tuxtype config.status 1.5.7
+tuxtype config.status 1.5.9
configured by $0, generated by GNU Autoconf 2.61,
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
Modified: tuxtype/trunk/configure.in
===================================================================
--- tuxtype/trunk/configure.in 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/configure.in 2007-05-07 15:31:34 UTC (rev 178)
@@ -1,9 +1,9 @@
# Process this file with autoconf to produce a configure script.
-AC_INIT(tuxtype, 1.5.7, )
+AC_INIT(tuxtype, 1.5.9, tuxmath-devel at lists.sourceforge.net)
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(tuxtype, 1.5.7)
+AM_INIT_AUTOMAKE(tuxtype, 1.5.9)
AC_CONFIG_SRCDIR([tuxtype/funcs.h])
Modified: tuxtype/trunk/tuxtype/alphabet.c
===================================================================
--- tuxtype/trunk/tuxtype/alphabet.c 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/tuxtype/alphabet.c 2007-05-07 15:31:34 UTC (rev 178)
@@ -15,6 +15,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
+#include <locale.h>
#include "globals.h"
#include "funcs.h"
@@ -30,8 +31,11 @@
/* Used for word list functions (see below): */
static int WORD_qty;
-unsigned char WORDS[MAX_NUM_WORDS][MAX_WORD_SIZE+1];
+wchar_t WORDS[MAX_NUM_WORDS][MAX_WORD_SIZE + 1];
+/* Local function prototypes: */
+void WORDS_scan_chars(void);
+
/* --- setup the alphabet --- */
void set_letters(unsigned char *t) {
int i;
@@ -172,6 +176,66 @@
return out;
}
+/* This version takes a single wide character and renders it with the */
+/* Unicode glyph versions of the SDL_ttf functions: */
+SDL_Surface* black_outline_wchar(wchar_t t, TTF_Font *font, SDL_Color *c) {
+ SDL_Surface* out = NULL;
+ SDL_Surface* black_letters = NULL;
+ SDL_Surface* white_letters = NULL;
+ SDL_Surface* bg = NULL;
+ SDL_Rect dstrect;
+ Uint32 color_key;
+
+ if (!font || !c)
+ {
+ fprintf(stderr, "black_outline_wchar(): invalid ptr parameter, returning.");
+ return NULL;
+ }
+
+ black_letters = TTF_RenderGlyph_Blended(font, t, black);
+
+ if (!black_letters)
+ {
+ fprintf (stderr, "Warning - black_outline_wchar() could not create image for %lc\n", t);
+ return NULL;
+ }
+
+ bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
+ (black_letters->w) + 5,
+ (black_letters->h) + 5,
+ 32,
+ rmask, gmask, bmask, amask);
+ /* Use color key for eventual transparency: */
+ color_key = SDL_MapRGB(bg->format, 10, 10, 10);
+ SDL_FillRect(bg, NULL, color_key);
+
+ /* Now draw black outline/shadow 2 pixels on each side: */
+ dstrect.w = black_letters->w;
+ dstrect.h = black_letters->h;
+
+ /* NOTE: can make the "shadow" more or less pronounced by */
+ /* changing the parameters of these loops. */
+ for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
+ for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
+ SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
+
+ SDL_FreeSurface(black_letters);
+
+ /* --- Put the color version of the text on top! --- */
+ white_letters = TTF_RenderGlyph_Blended(font, t, *c);
+ dstrect.x = 1;
+ dstrect.y = 1;
+ SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
+ SDL_FreeSurface(white_letters);
+
+ /* --- Convert to the screen format for quicker blits --- */
+ SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
+ out = SDL_DisplayFormatAlpha(bg);
+ SDL_FreeSurface(bg);
+
+ return out;
+}
+
void show_letters( void ) {
int i, l=0;
SDL_Surface *abit;
@@ -274,7 +338,8 @@
/* WORDS_get: returns a random word that wasn't returned
* the previous time (unless there is only 1 word!!!)
*/
-unsigned char* WORDS_get( void ) {
+wchar_t* WORDS_get( void )
+{
static int last_choice = -1;
int choice;
@@ -325,68 +390,83 @@
* it ignores any words too long or that has bad
* character (such as #)
*/
-void WORDS_use( char *wordFn ) {
- int j;
- unsigned char temp_word[FNLEN];
- size_t length;
+/* FIXME changing to wchar_t to accommodate i18n */
- FILE *wordFile=NULL;
+void WORDS_use(char *wordFn)
+{
+ int j;
+ unsigned char temp_word[FNLEN];
+ size_t length;
- DEBUGCODE { fprintf(stderr, "Entering WORDS_use() for file: %s\n", wordFn); }
+ FILE* wordFile=NULL;
- WORD_qty = 0;
+ DEBUGCODE { fprintf(stderr, "Entering WORDS_use() for file: %s\n", wordFn); }
+ WORD_qty = 0;
+
+ /* We need to set the locale to something supporting UTF-8 - AFAIK, */
+ /* it can be any UTF-8 locale, not necessarily the specific one */
+ /* for the language being used (but I could be wrong - DSB) */
+ if (!setlocale(LC_CTYPE, "nn_NO.UTF-8")) /* temporary example */
+ {
+ fprintf(stderr, "Could not set requested UTF-8 locale, fallback to en_US.UTF-8\n");
+ if (!setlocale(LC_CTYPE, "en_US.UTF-8"))
+ fprintf(stderr, "Cannot support UTF-8, ASCII-only words will be used\n");
+ }
/* --- open the file --- */
- wordFile = fopen( wordFn, "r" );
+ wordFile = fopen( wordFn, "r" );
- if ( wordFile == NULL ) {
- fprintf(stderr, "ERROR: could not load wordlist: %s\n", wordFn );
- fprintf(stderr, "Using ALPHABET instead\n");
- WORDS_use_alphabet( );
- return;
- }
+ if ( wordFile == NULL )
+ {
+ fprintf(stderr, "ERROR: could not load wordlist: %s\n", wordFn );
+ fprintf(stderr, "Using ALPHABET instead\n");
+ WORDS_use_alphabet( );
+ return;
+ }
-
- /* --- load words for this curlevel --- */
+ /* --- load words from file named as argument: */
- DEBUGCODE { fprintf(stderr, "WORD FILE OPENNED @ %s\n", wordFn); }
+ DEBUGCODE { fprintf(stderr, "WORD FILE OPENNED @ %s\n", wordFn); }
- /* ignore the title */
- fscanf( wordFile, "%[^\n]\n", temp_word);
+ /* ignore the title (i.e. first line) */
+ fscanf( wordFile, "%[^\n]\n", temp_word);
- while (!feof(wordFile) && (WORD_qty < MAX_NUM_WORDS)) {
- fscanf( wordFile, "%[^\n]\n", temp_word);
+ while (!feof(wordFile) && (WORD_qty < MAX_NUM_WORDS))
+ {
+ fscanf( wordFile, "%[^\n]\n", temp_word);
- for (j = 0; j < strlen(temp_word); j++)
- if (temp_word[j] == '\n' || temp_word[j] == '\r')
- temp_word[j] = '\0';
+ for (j = 0; j < strlen(temp_word); j++)
+ {
+ if (temp_word[j] == '\n' || temp_word[j] == '\r')
+ temp_word[j] = '\0';
+ }
- /* Make sure word is usable: */
- /* NOTE we need to use mbstowcs() rather than just strlen() */
- /* now that we use UTF-8 to get correct length - DSB */
- length = mbstowcs(NULL, temp_word, 0);
+ /* Make sure word is usable: */
+ /* NOTE we need to use mbstowcs() rather than just strlen() */
+ /* now that we use UTF-8 to get correct length - DSB */
+ length = mbstowcs(NULL, temp_word, 0);
- DOUT(length);
+ DOUT(length);
- if (length == -1) /* Means invalid UTF-8 sequence */
- {
- fprintf(stderr, "Word '%s' not added - invalid UTF-8 sequence!\n");
- continue;
- }
+ if (length == -1) /* Means invalid UTF-8 sequence */
+ {
+ fprintf(stderr, "Word '%s' not added - invalid UTF-8 sequence!\n", temp_word);
+ continue;
+ }
- if (length == 0)
- continue;
- if (length > MAX_WORD_SIZE)
- continue;
- if (WORD_qty >= MAX_NUM_WORDS)
- continue;
+ if (length == 0)
+ continue;
+ if (length > MAX_WORD_SIZE)
+ continue;
+ if (WORD_qty >= MAX_NUM_WORDS)
+ continue;
- /* If we make it to here, OK to add word: */
- strcpy( WORDS[WORD_qty], temp_word );
- WORD_qty++;
- }
+ /* If we make it to here, OK to add word: */
+ mbstowcs(WORDS[WORD_qty], temp_word, strlen(temp_word));
+ WORD_qty++;
+ }
/* Make sure list is terminated with null character */
WORDS[WORD_qty][0] = '\0';
@@ -400,3 +480,40 @@
LOG("Leaving WORDS_use()\n");
}
+
+
+/* Returns number of UTF-8 characters rather than just size in */
+/* bytes like strlen(). mbstowcs(NULL, s, 0) should do this */
+/* but for some reason I haven't gotten it to work. */
+/* Returns -1 if any invalid characters encountered. */
+size_t UTF8_strlen(const char* s)
+{
+ size_t byte_length = 0;
+ size_t UTF8_length = 0;
+ int i = 0;
+ int char_width = 0;
+
+ byte_length = strlen(s);
+
+ DEBUGCODE{ fprintf(stderr, "String is: %s\nstrlen() = %d\n",
+ s, byte_length); }
+ while (i < byte_length)
+ {
+ /* look at the length of each UTF-8 char and jump ahead accordingly: */
+ char_width = mblen(&s[i], byte_length - i);
+ if (char_width == -1)
+ return -1;
+ i += mblen(&s[i], byte_length - i);
+ UTF8_length++;
+ }
+
+ DEBUGCODE{ fprintf(stderr, "UTF8_strlen() = %d\n", UTF8_length); }
+
+ return UTF8_length;
+}
+
+
+
+void WORDS_scan_chars(void)
+{
+}
Modified: tuxtype/trunk/tuxtype/funcs.h
===================================================================
--- tuxtype/trunk/tuxtype/funcs.h 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/tuxtype/funcs.h 2007-05-07 15:31:34 UTC (rev 178)
@@ -83,12 +83,14 @@
extern void custom_letter_setup( void );
extern void show_letters( void );
extern SDL_Surface* black_outline( unsigned char *t, TTF_Font* font, SDL_Color* c );
+extern SDL_Surface* black_outline_wchar(wchar_t t, TTF_Font* font, SDL_Color* c);
+extern size_t UTF8_strlen(const char* s);
/* WORD FUNCTIONS (also in alphabet.c) */
extern void WORDS_init( void );
extern void WORDS_use_alphabet( void );
extern void WORDS_use( char *wordFn );
-extern unsigned char* WORDS_get( void );
+extern wchar_t* WORDS_get(void);
/* in practice.c */
extern int Practice( void );
Modified: tuxtype/trunk/tuxtype/globals.h
===================================================================
--- tuxtype/trunk/tuxtype/globals.h 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/tuxtype/globals.h 2007-05-07 15:31:34 UTC (rev 178)
@@ -36,6 +36,7 @@
#define MAX_SPRITE_FRAMES 30
#include <string.h>
+#include <wchar.h>
#include <math.h>
#include <time.h>
#include <stdio.h>
Modified: tuxtype/trunk/tuxtype/laser.c
===================================================================
--- tuxtype/trunk/tuxtype/laser.c 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/tuxtype/laser.c 2007-05-07 15:31:34 UTC (rev 178)
@@ -71,16 +71,24 @@
pause_load_media();
- for (i=1; i<255; i++) {
- unsigned char t[2] = " ";
- t[0] = i;
- letters[i] = black_outline(t, font, &white);
- if (!letters[i])
- {
- fprintf(stderr, "For i = %d, could not render "
- "corresponding char = %s\n", i, t);
- }
- }
+ /* Now that the words are stored internally as wchars, we use the */
+ /* Unicode glyph version of black_outline(): */
+ {
+ wchar_t t;
+ int i;
+
+ for (i = 1; i < 255; i++)
+ {
+ t = (wchar_t)i;
+
+ DEBUGCODE
+ {
+ fprintf(stderr, "Creating SDL_Surface for int = %d, char = %lc\n", i, t);
+ }
+
+ letters[i] = black_outline_wchar(t, font, &white);
+ }
+ }
}
@@ -784,17 +792,17 @@
else /* Odd number of cities (is this a hack that means we are using words?) */
{
LOG("NUM_CITIES is odd\n");
- unsigned char *word = WORDS_get();
+ wchar_t* word = WORDS_get();
int i=0;
DEBUGCODE {fprintf(stderr, "word is: %s\n", word);}
do
{
- target = rand() % (NUM_CITIES - strlen(word) + 1);
+ target = rand() % (NUM_CITIES - wcslen(word) + 1);
} while (target == last);
last = target;
- for (i=0; i<strlen(word); i++)
+ for (i=0; i < wcslen(word); i++)
{
while ((comets[location].alive == 1) && (location < MAX_COMETS))
location++;
Modified: tuxtype/trunk/tuxtype/laser.h
===================================================================
--- tuxtype/trunk/tuxtype/laser.h 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/tuxtype/laser.h 2007-05-07 15:31:34 UTC (rev 178)
@@ -13,7 +13,7 @@
int expl;
int city;
int x, y;
- unsigned char ch;
+ wchar_t ch;
} comet_type;
typedef struct city_type {
Modified: tuxtype/trunk/tuxtype/loaders.c
===================================================================
--- tuxtype/trunk/tuxtype/loaders.c 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/tuxtype/loaders.c 2007-05-07 15:31:34 UTC (rev 178)
@@ -213,6 +213,7 @@
SDL_Surface *tmp_pic = NULL, *final_pic = NULL;
char fn[FNLEN];
+ debugOn = 0;
DEBUGCODE { fprintf(stderr, "LoadImage: loading %s\n", datafile ); }
/* truth table for start of loop, since we only use theme on those conditions!
@@ -233,7 +234,7 @@
if (tmp_pic != NULL)
break;
else
- fprintf(stderr, "Warning: graphics file %s is corrupt\n", fn);
+ DEBUGCODE { fprintf(stderr, "Warning: graphics file %s is corrupt\n", fn);}
}
}
@@ -275,7 +276,7 @@
}
LOG( "LOADIMAGE: Done\n" );
-
+ debugOn = 1;
return (final_pic);
}
Modified: tuxtype/trunk/tuxtype/playgame.c
===================================================================
--- tuxtype/trunk/tuxtype/playgame.c 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/tuxtype/playgame.c 2007-05-07 15:31:34 UTC (rev 178)
@@ -69,25 +69,35 @@
int check_word( int f ) {
int i;
- if (strlen(fish_object[f].word) > tux_object.wordlen)
+ if (wcslen(fish_object[f].word) > tux_object.wordlen)
return 0;
- for (i=0; i<strlen(fish_object[f].word); i++)
- if (KEYMAP[fish_object[f].word[i]] != KEYMAP[tux_object.word[tux_object.wordlen-strlen(fish_object[f].word)+i]])
+ for (i=0; i < wcslen(fish_object[f].word); i++)
+ if (KEYMAP[fish_object[f].word[i]] != KEYMAP[tux_object.word[tux_object.wordlen - wcslen(fish_object[f].word)+i]])
return 0;
return 1;
}
+
+/* Now that the words are stored internally as wchars, we use the */
+/* Unicode glyph version of black_outline(): */
void create_letters( void )
{
+ wchar_t t;
int i;
+
for (i = 1; i < 255; i++)
{
- unsigned char t[2] = " ";
- t[0] = i;
- letter[i] = black_outline(t, font, &white);
- red_letter[i] = black_outline(t, font, &red);;
+ t = (wchar_t)i;
+
+ DEBUGCODE
+ {
+ fprintf(stderr, "Creating SDL_Surface for int = %d, char = %lc\n", i, t);
+ }
+
+ letter[i] = black_outline_wchar(t, font, &white);
+ red_letter[i] = black_outline_wchar(t, font, &red);;
}
}
@@ -570,8 +580,7 @@
*****************************/
void SpawnFishies(int diflevel, int *fishies, int *frame ) {
int i, spacing;
- char* new_word;
- size_t new_word_len;
+ wchar_t* new_word;
switch (diflevel) {
case INF_PRACT:
@@ -592,19 +601,10 @@
LOG( "=>Spawning fishy\n" );
new_word = WORDS_get();
- new_word_len = mbstowcs(NULL, new_word, 0);
- if (new_word_len == -1)
- {
- fprintf(stderr, "Could not spawn fishy with word '%s'\n", new_word);
- fprintf(stderr, "Byte length is: %d\n", strlen(new_word));
- fprintf(stderr, "UTF-8 char length is: %d\n", new_word_len);
- return;
- }
-
/* If we get to here, it should be OK to actually spawn the fishy: */
fish_object[*fishies].word = new_word;
- fish_object[*fishies].len = new_word_len;
+ fish_object[*fishies].len = wcslen(new_word);
fish_object[*fishies].alive = 1;
fish_object[*fishies].can_eat = 0;
fish_object[*fishies].w = fishy->frame[0]->w * fish_object[*fishies].len;
@@ -636,7 +636,7 @@
DEBUGCODE {
fprintf(stderr, "Spawn fishy with word '%s'\n", fish_object[*fishies].word);
- fprintf(stderr, "Byte length is: %d\n", strlen(fish_object[*fishies].word));
+ fprintf(stderr, "Byte length is: %d\n", wcslen(fish_object[*fishies].word));
fprintf(stderr, "UTF-8 char length is: %d\n", fish_object[*fishies].len);
}
@@ -742,23 +742,40 @@
Mix_PlayChannel(SPLAT_WAV, sound[SPLAT_WAV], 0);
}
-void DrawFish( int which ) {
+
+
+
+void DrawFish( int which )
+{
LOG ("Entering DrawFish()\n");
- int j, red_letters, x_offset, y_offset;
+ int j = 0;
+ int red_letters = 0;
+ int x_offset = 0;
+ int y_offset = 0;
+ int letter_x = 0;
+ int letter_y = 0;
+ int current_letter;
+ /* Make sure needed pointers are valid - if not, return: */
+ if (!fishy || !fishy->frame[0])
+ {
+ fprintf(stderr, "DrawFish() - returning, needed pointer invalid\n");
+ return;
+ }
+
// To have letters more centered in fish:
x_offset = 10;
y_offset = 10;
/* Draw the fishies: */
- for ( j=0; j < fish_object[which].len; j++ )
+ for (j = 0; j < fish_object[which].len; j++)
{
- if (fishy && fishy->frame[0])
DrawSprite( fishy,
fish_object[which].x + (fishy->frame[0]->w*j),
- fish_object[which].y );
+ fish_object[which].y);
}
+
/* Now we draw the letters on top of the fish: */
/* we only draw the letter if tux cannot eat it yet */
if (!fish_object[which].can_eat)
@@ -766,28 +783,54 @@
red_letters = -1;
j = 0;
- while ( j < tux_object.wordlen && red_letters == -1 ) {
- int k;
- for ( k=0; k<tux_object.wordlen - j; k++)
- if ( KEYMAP[fish_object[which].word[k]] != KEYMAP[tux_object.word[j+k]] )
- k=100000;
+ /* figure out how many letters are red: */
+ while (j < tux_object.wordlen && red_letters == -1)
+ {
+ int k;
+ for (k = 0; k < tux_object.wordlen - j; k++)
+ {
+ if (KEYMAP[fish_object[which].word[k]] != KEYMAP[tux_object.word[j+k]])
+ k = 100000;
+ }
- if (k < 100000)
- red_letters = tux_object.wordlen - j;
- else
- j++;
+ if (k < 100000)
+ red_letters = tux_object.wordlen - j;
+ else
+ j++;
}
- for (j = 0; j < strlen(fish_object[which].word); j++)
- if (fish_object[which].word[j]!=32
- && fishy && fishy->frame[0]) //segfault protection
+ LOG ("Preparing to draw letters:\n");
- {
- if (j < red_letters)
- DrawObject(red_letter[(int)fish_object[which].word[j]], (fish_object[which].x + (j * fishy->frame[0]->w)) + x_offset, fish_object[which].y + y_offset);
- else
- DrawObject(letter[(int)fish_object[which].word[j]], (fish_object[which].x + (j * fishy->frame[0]->w)) + x_offset, fish_object[which].y + y_offset);
- }
+ /* Now draw each letter: */
+ for (j = 0; j < wcslen(fish_object[which].word); j++)
+ {
+ current_letter = (int)fish_object[which].word[j];
+
+ /* For now, we don't support wchars outside of 0-255: */
+ if (current_letter < 0 || current_letter > 255)
+ {
+ fprintf(stderr, "Character encountered with value '%d' - not supported",
+ current_letter);
+ continue;
+ }
+
+ letter_x = fish_object[which].x + (j * fishy->frame[0]->w) + x_offset;
+ letter_y = fish_object[which].y + y_offset;
+
+ DEBUGCODE
+ {
+ fprintf(stderr, "wchar is: %lc\n(int)wchar is: %d\n",
+ fish_object[which].word[j],
+ current_letter);
+ }
+ //if (fish_object[which].word[j] != 32) /* Don't understand this */
+ if (j < red_letters)
+ DrawObject(red_letter[current_letter],
+ letter_x, letter_y);
+ else
+ DrawObject(letter[current_letter],
+ letter_x, letter_y);
+ }
}
LOG ("Leaving DrawFish()\n");
}
Modified: tuxtype/trunk/tuxtype/playgame.h
===================================================================
--- tuxtype/trunk/tuxtype/playgame.h 2007-05-03 00:53:13 UTC (rev 177)
+++ tuxtype/trunk/tuxtype/playgame.h 2007-05-07 15:31:34 UTC (rev 178)
@@ -85,7 +85,7 @@
struct fishypoo {
int alive;
int can_eat;
- unsigned char *word;
+ wchar_t* word;
double x, y;
int w;
size_t len;
@@ -125,7 +125,7 @@
int endx, endy;
int state;
int wordlen;
- unsigned char word[MAX_WORD_SIZE + 1];
+ wchar_t word[MAX_WORD_SIZE + 1];
} tux_object;
struct splatter {
More information about the Tux4kids-commits
mailing list