Changes

Jump to navigation Jump to search
4,449 bytes added ,  17:39, 19 March 2009
no edit summary
Line 1: Line 1: −
I'd be interested in your ScreenFont class. --[[User:Beardface|Beardface]] 15:02, 5 September 2008 (UTC)
  −
  −
  −
   
=Wii Stuff by me=
 
=Wii Stuff by me=
 
*[[SpaceShooter]]
 
*[[SpaceShooter]]
 
* Code Snippets (see below)
 
* Code Snippets (see below)
 
+
* [http://code.google.com/p/pacemaker-productions/ PaceMaker Productions (code.google.com)]
 +
* [http://pacemaker-productions.googlecode.com/files/libwiisprite-30b-NoOverscanProt-DevKitPro16.a LibWiiSprite v3.0b with no Over Scan protection - Works with DevkitPro Release 16]
 +
* [http://pacemaker-productions.googlecode.com/files/libwiisprite-30b-NoOverscanProt.zip LibWiiSprite v3.0b with no Over Scan protection - For DevKitPro Release 15 and earlier]
 +
* [[YOG]] v0.1 - Golf the way a three-year-old might imagine it.
 +
* [[WiiCalc]] - A fully functional calculator for the Wii.
 +
* [[ChristmasCountdown]] - How much longer until Christmas?
 +
* [[DungeonCrawlStoneSoup]] - A port of the roguelike game Dungeon Crawl: Stone Soup http://crawl-ref.sourceforge.net
    
=Code Snippets=
 
=Code Snippets=
Line 104: Line 106:  
}
 
}
    +
</source>
 +
 +
==Printf With LibWiiSprite==
 +
 +
I found a need to support printf in my apps, while using LibWiiSprite.  The code below shows an example on how to do this.  One reason to do this is that asserts from Box2d (and presumably others) will do a printf.  This method should also work with other graphic libraries that use GX instead of framebuffers.  The majority of this code was taken from the libogc source.
 +
 +
It's easy to use.  Call InitConsole() once, and RenderConsole() each draw loop.  Also you'll need to provide a function that replaces my text drawing function: CourierNew_ScreenFont.DisplayText (int x, int y, char * szText); 
 +
Also, it's not optimized at all, but who wants an optimized printf function?
 +
 +
<source lang=cpp>
 +
// !!!! Should be put into a console class.
 +
// !!!! Idea to add console support when using LibWiiSprite
 +
#include <sys/iosupport.h>
 +
 +
#define MAX_CON_ROWS 24
 +
#define MAX_CON_COLS 80
 +
#define X_PIXELS_PER_CHAR (640/MAX_CON_COLS)
 +
#define Y_PIXELS_PER_CHAR (480/MAX_CON_ROWS)
 +
#define TAB_SIZE 4
 +
 +
static int cursor_row = 0;
 +
static int cursor_col = 0;
 +
static int con_rows = MAX_CON_ROWS;
 +
static int con_cols = MAX_CON_COLS;
 +
static char the_console [MAX_CON_ROWS] [MAX_CON_COLS];
 +
 +
int __console_write(struct _reent *r,int fd,const char *ptr,int len)
 +
{
 +
int i = 0;
 +
char *tmp = (char*)ptr;
 +
char chr;
 +
 +
if (!tmp || len<=0)
 +
return -1;
 +
 +
i = 0;
 +
while(*tmp!='\0' && i<len)
 +
{
 +
chr = *tmp++;
 +
i++;
 +
if ( (chr == 0x1b) && (*tmp == '[') )
 +
{
 +
/* escape sequence found */
 +
int k;
 +
 +
tmp++;
 +
i++;
 +
k = 0; //__console_parse_escsequence(tmp); //!!!! Ignore.
 +
tmp += k;
 +
i += k;
 +
}
 +
else
 +
{
 +
switch(chr)
 +
{
 +
case '\n':
 +
cursor_row++;
 +
cursor_col = 0;
 +
break;
 +
case '\r':
 +
cursor_col = 0;
 +
break;
 +
case '\b':
 +
cursor_col--;
 +
if(cursor_col < 0)
 +
{
 +
cursor_col = 0;
 +
}
 +
break;
 +
case '\f':
 +
cursor_row++;
 +
break;
 +
case '\t':
 +
if(cursor_col%TAB_SIZE)
 +
cursor_col += (cursor_col%TAB_SIZE);
 +
else
 +
cursor_col += TAB_SIZE;
 +
break;
 +
default:
 +
the_console [cursor_row] [cursor_col] = chr;
 +
cursor_col++;
 +
 +
if (cursor_col >= con_cols)
 +
{
 +
/* if right border reached wrap around */
 +
cursor_row++;
 +
cursor_col = 0;
 +
}
 +
}
 +
}
 +
 +
if( cursor_row >= con_rows)
 +
{
 +
// Copy data up after reaching bottom.
 +
for (int i = 0; i < MAX_CON_ROWS - 1; i ++)
 +
{
 +
for (int j = 0; j < MAX_CON_COLS; j ++)
 +
{
 +
the_console [i] [j] = the_console [i + 1] [j];
 +
}
 +
}
 +
 +
for (int j = 0; j < MAX_CON_COLS; j ++)
 +
{
 +
the_console [MAX_CON_ROWS - 1] [j] = 0;
 +
}
 +
 +
cursor_row--;
 +
}
 +
}
 +
 +
return i;
 +
}
 +
 +
 +
const devoptab_t dotab_stdout =
 +
{
 +
//---------------------------------------------------------------------------------
 +
"stdout", // device name
 +
0, // size of file structure
 +
NULL, // device open
 +
NULL, // device close
 +
__console_write, // device write
 +
NULL, // device read
 +
NULL, // device seek
 +
NULL, // device fstat
 +
NULL, // device stat
 +
NULL, // device link
 +
NULL, // device unlink
 +
NULL, // device chdir
 +
NULL, // device rename
 +
NULL, // device mkdir
 +
0, // dirStateSize
 +
NULL, // device diropen_r
 +
NULL, // device dirreset_r
 +
NULL, // device dirnext_r
 +
NULL, // device dirclose_r
 +
NULL // device statvfs_r
 +
};
 +
 +
void InitConsole (void)
 +
{
 +
    cursor_row = 0;
 +
    cursor_col = 0;
 +
   
 +
    devoptab_list[STD_OUT] = &dotab_stdout;
 +
    devoptab_list[STD_ERR] = &dotab_stdout;
 +
}
 +
 +
void RenderConsole (void)
 +
{
 +
int i, j;
 +
char twoBuf [2];
 +
 +
twoBuf [1] = 0;
 +
for (i = 0; i < MAX_CON_ROWS; i ++)
 +
{
 +
for (j = 0; j < MAX_CON_COLS; j ++)
 +
{
 +
if (the_console [i] [j])
 +
{
 +
twoBuf [0] = the_console [i] [j];
 +
CourierNew_ScreenFont.DisplayText (j * X_PIXELS_PER_CHAR, i * Y_PIXELS_PER_CHAR, twoBuf);
 +
}
 +
}
 +
}
 +
 +
}
 
</source>
 
</source>
137

edits

Navigation menu