colorized OSD text... wastes 32kB memory but in 2008 I don't think anyone really gives half a shit

git-svn-id: https://svn.eduke32.com/eduke32@864 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-07-18 09:50:44 +00:00
parent 564e00a3f2
commit 6374609c4d
6 changed files with 101 additions and 48 deletions

View file

@ -34,6 +34,8 @@ const char *stripcolorcodes(const char *t);
int OSD_ParsingScript(void);
int OSD_OSDKey(void);
int OSD_Exec(const char *szScript);
char *OSD_GetTextPtr(void);
char *OSD_GetFmtPtr(void);
// initializes things
void OSD_Init(void);
@ -99,5 +101,19 @@ int OSD_Dispatch(const char *cmd);
// func = the entry point to the function
int OSD_RegisterFunction(const char *name, const char *help, int (*func)(const osdfuncparm_t*));
// these correspond to the Duke palettes, so they shouldn't really be here
// ...but I don't care
#define OSDTEXT_BLUE "^00"
#define OSDTEXT_DARKRED "^10"
#define OSDTEXT_GREEN "^11"
#define OSDTEXT_GRAY "^12"
#define OSDTEXT_DARKGRAY "^13"
#define OSDTEXT_DARKGREEN "^14"
#define OSDTEXT_BROWN "^15"
#define OSDTEXT_DARKBLUE "^16"
#define OSDTEXT_RED "^21"
#define OSDTEXT_YELLOW "^23"
#endif // __osd_h__

View file

@ -35,6 +35,7 @@ static void _internal_onshowosd(int);
// history display
static char osdtext[TEXTSIZE];
static char osdfmt[TEXTSIZE];
static char osdversionstring[32];
static int osdversionstringlen;
static int osdversionstringshade;
@ -494,6 +495,7 @@ static int _internal_osdfunc_clear(const osdfuncparm_t *parm)
{
UNREFERENCED_PARAMETER(parm);
Bmemset(osdtext,0,sizeof(osdtext));
Bmemset(osdfmt,osdtextpal,sizeof(osdfmt));
osdlines = 1;
return OSDCMD_OK;
}
@ -538,6 +540,7 @@ void OSD_Cleanup(void)
void OSD_Init(void)
{
Bmemset(osdtext, 32, TEXTSIZE);
Bmemset(osdfmt, osdtextpal, TEXTSIZE);
osdlines=1;
osdinited=1;
@ -803,7 +806,7 @@ int OSD_HandleChar(char ch)
lastmatch = symb;
symb=findsymbol(osdedittmp, lastmatch->next);
}
OSD_Printf("Found %d possible completions for '%s':\n",num,osdedittmp);
OSD_Printf(OSDTEXT_GREEN "Found %d possible completions for '%s':\n",num,osdedittmp);
maxwidth += 3;
symb = tabc;
OSD_Printf(" ");
@ -858,6 +861,7 @@ int OSD_HandleChar(char ch)
else if (ch == 12) // control l, clear screen
{
Bmemset(osdtext,0,sizeof(osdtext));
Bmemset(osdfmt,osdtextpal,sizeof(osdfmt));
osdlines = 1;
}
else if (ch == 13) // control m, enter
@ -1140,6 +1144,7 @@ void OSD_ResizeDisplay(int w, int h)
int newcols;
int newmaxlines;
char newtext[TEXTSIZE];
char newfmt[TEXTSIZE];
int i,j,k;
newcols = getcolumnwidth(w);
@ -1152,9 +1157,11 @@ void OSD_ResizeDisplay(int w, int h)
for (i=0;i<j;i++)
{
memcpy(newtext+newcols*i, osdtext+osdcols*i, k);
memcpy(newfmt+newcols*i, osdfmt+osdcols*i, k);
}
memcpy(osdtext, newtext, TEXTSIZE);
memcpy(osdfmt, newfmt, TEXTSIZE);
osdcols = newcols;
osdmaxlines = newmaxlines;
osdmaxrows = getrowheight(h)-2;
@ -1281,13 +1288,14 @@ static inline void linefeed(void)
{
Bmemmove(osdtext+osdcols, osdtext, TEXTSIZE-osdcols);
Bmemset(osdtext, 32, osdcols);
Bmemmove(osdfmt+osdcols, osdfmt, TEXTSIZE-osdcols);
Bmemset(osdfmt, osdtextpal, osdcols);
if (osdlines < osdmaxlines) osdlines++;
}
void OSD_Printf(const char *fmt, ...)
{
char tmpstr[1024], *chp;
char tmpstr[1024], *chp, p=osdtextpal;
va_list va;
if (!osdinited) OSD_Init();
@ -1299,7 +1307,7 @@ void OSD_Printf(const char *fmt, ...)
if (linecnt<logcutoff)
{
if (osdlog&&(!logcutoff||linecnt<logcutoff))
Bfputs(tmpstr, osdlog);
Bfputs(stripcolorcodes(tmpstr), osdlog);
}
else if (linecnt==logcutoff)
{
@ -1310,7 +1318,25 @@ void OSD_Printf(const char *fmt, ...)
for (chp = tmpstr; *chp; chp++)
{
if (*chp == '\r') osdpos=0;
if (*chp == '^' && isdigit(*(chp+1)))
{
char smallbuf[4];
chp++;
if (isdigit(*(chp+1)))
{
smallbuf[0] = *(chp++);
smallbuf[1] = *(chp);
smallbuf[2] = '\0';
p = atol(smallbuf);
}
else
{
smallbuf[0] = *(chp);
smallbuf[1] = '\0';
p = atol(smallbuf);
}
}
else if (*chp == '\r') osdpos=0;
else if (*chp == '\n')
{
osdpos=0;
@ -1319,7 +1345,8 @@ void OSD_Printf(const char *fmt, ...)
}
else
{
osdtext[osdpos++] = *chp;
osdtext[osdpos] = *chp;
osdfmt[osdpos++] = p;
if (osdpos == osdcols)
{
osdpos = 0;
@ -1614,6 +1641,16 @@ int OSD_OSDKey(void)
return osdkey;
}
char *OSD_GetTextPtr(void)
{
return (&osdtext[0]);
}
char *OSD_GetFmtPtr(void)
{
return (&osdfmt[0]);
}
//
// addnewsymbol() -- Allocates space for a new symbol and attaches it
// appropriately to the lists, sorted.

View file

@ -464,7 +464,7 @@ void adduserquote(const char *daquote)
user_quote_time[i] = user_quote_time[i-1];
}
Bstrcpy(user_quote[0],daquote);
OSD_Printf("%s\n",stripcolorcodes(daquote));
OSD_Printf("%s\n",daquote);
user_quote_time[0] = ud.msgdisptime;
pub = NUMPAGES;
@ -487,7 +487,7 @@ void getpackets(void)
{
if (setgamemode(!ud.config.ScreenMode,ud.config.ScreenWidth,ud.config.ScreenHeight,ud.config.ScreenBPP))
{
OSD_Printf("Failed setting fullscreen video mode.\n");
OSD_Printf(OSDTEXT_DARKRED "Failed setting fullscreen video mode.\n");
if (setgamemode(ud.config.ScreenMode, ud.config.ScreenWidth, ud.config.ScreenHeight, ud.config.ScreenBPP))
gameexit("Failed to recover from failure to set fullscreen video mode.\n");
}
@ -2426,7 +2426,7 @@ static void operatefta(void)
if (fta_quotes[g_player[screenpeek].ps->ftq] == NULL)
{
OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,g_player[screenpeek].ps->ftq);
OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d\n",__FILE__,__LINE__,g_player[screenpeek].ps->ftq);
return;
}
@ -2473,7 +2473,7 @@ void FTA(int q,player_struct *p)
{
if (fta_quotes[p->ftq] == NULL)
{
OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,p->ftq);
OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d\n",__FILE__,__LINE__,p->ftq);
return;
}
@ -2490,7 +2490,7 @@ void FTA(int q,player_struct *p)
{
if (p->ftq != q)
if (p == g_player[screenpeek].ps)
OSD_Printf("%s\n",stripcolorcodes(fta_quotes[q]));
OSD_Printf(OSDTEXT_BLUE "%s\n",stripcolorcodes(fta_quotes[q]));
p->ftq = q;
pub = NUMPAGES;
@ -5324,7 +5324,7 @@ int spawn(int j, int pn)
if (sp->hitag && sp->picnum == WATERBUBBLEMAKER)
{
// JBF 20030913: Pisses off move(), eg. in bobsp2
OSD_Printf("WARNING: WATERBUBBLEMAKER %d @ %d,%d with hitag!=0. Applying fixup.\n",
OSD_Printf(OSDTEXT_DARKRED "WARNING: WATERBUBBLEMAKER %d @ %d,%d with hitag!=0. Applying fixup.\n",
i,sp->x,sp->y);
sp->hitag = 0;
}
@ -10139,6 +10139,7 @@ void app_main(int argc,const char **argv)
#endif
OSD_SetLogFile("eduke32.log");
OSD_SetParameters(10,0, 0,12, 4,12);
wm_setapptitle(HEAD2);

View file

@ -878,7 +878,7 @@ static void DoThisProjectile(int iSet, int lVar1, int lLabelID, int lVar2)
if (proj < 0 || proj >= MAXSPRITES)
{
// OSD_Printf("DoThisProjectile(): invalid projectile (%d)\n",proj);
OSD_Printf("DoThisProjectile(): tried to %s %s on invalid target projectile (%d) %d %d from %s\n",
OSD_Printf(OSDTEXT_DARKRED "DoThisProjectile(): tried to %s %s on invalid target projectile (%d) %d %d from %s\n",
iSet?"set":"get",projectilelabels[lLabelID].name,proj,g_i,g_sp->picnum,
(lVar1<MAXGAMEVARS)?aGameVars[lVar1].szLabel:"extended");
insptr += (lVar2 == MAXGAMEVARS);
@ -1159,7 +1159,7 @@ static void DoPlayer(int iSet, int lVar1, int lLabelID, int lVar2, int lParm2)
if (iPlayer<0 || iPlayer >= ud.multimode)
{
// OSD_Printf("DoPlayer(): invalid target player (%d) %d\n",iPlayer,g_i);
OSD_Printf("DoPlayer(): tried to %s %s on invalid target player (%d) %d from %s\n",
OSD_Printf(OSDTEXT_DARKRED "DoPlayer(): tried to %s %s on invalid target player (%d) %d from %s\n",
iSet?"set":"get",actorlabels[lLabelID].name,iPlayer,g_i,
(lVar1<MAXGAMEVARS)?aGameVars[lVar1].szLabel:"extended");
insptr += (lVar2 == MAXGAMEVARS);
@ -2506,7 +2506,7 @@ static void DoInput(int iSet, int lVar1, int lLabelID, int lVar2)
if (iPlayer<0 || iPlayer >= ud.multimode)
{
insptr += (lVar2 == MAXGAMEVARS);
OSD_Printf("DoInput(): invalid target player (%d) %d\n",iPlayer,g_i);
OSD_Printf(OSDTEXT_DARKRED "DoInput(): invalid target player (%d) %d\n",iPlayer,g_i);
return;
}
@ -2988,7 +2988,7 @@ static void DoActor(int iSet, int lVar1, int lLabelID, int lVar2, int lParm2)
if (iActor < 0 || iActor >= MAXSPRITES)
{
OSD_Printf("DoActor(): tried to %s %s on invalid target sprite (%d) %d %d from %s\n",
OSD_Printf(OSDTEXT_DARKRED "DoActor(): tried to %s %s on invalid target sprite (%d) %d %d from %s\n",
iSet?"set":"get",actorlabels[lLabelID].name,iActor,g_i,g_sp->picnum,
(lVar1<MAXGAMEVARS)?aGameVars[lVar1].szLabel:"extended");
insptr += (lVar2 == MAXGAMEVARS);
@ -3466,7 +3466,7 @@ static void DoTsprite(int iSet, int lVar1, int lLabelID, int lVar2)
if (iActor < 0 || iActor >= MAXSPRITES)
{
OSD_Printf("DoTsprite(): invalid target sprite (%d) %d %d\n",iActor,g_i,g_sp->picnum);
OSD_Printf(OSDTEXT_DARKRED "DoTsprite(): invalid target sprite (%d) %d %d\n",iActor,g_i,g_sp->picnum);
insptr += (lVar2 == MAXGAMEVARS);
return;
}
@ -3607,7 +3607,7 @@ static void DoProjectile(int iSet, int lVar1, int lLabelID, int lVar2)
if (lVar1 < 0 || lVar1 >= MAXTILES)
{
OSD_Printf("DoProjectile(): invalid tile (%d)\n",lVar1);
OSD_Printf(OSDTEXT_DARKRED "DoProjectile(): invalid tile (%d)\n",lVar1);
insptr += (lVar2 == MAXGAMEVARS);
return;
}
@ -3878,7 +3878,7 @@ void OnEvent(int iEventID, int iActor, int iPlayer, int lDist)
{
if (iEventID >= MAXGAMEEVENTS)
{
OSD_Printf("OnEvent(): invalid event ID");
OSD_Printf(OSDTEXT_DARKRED "OnEvent(): invalid event ID");
return;
}
@ -4471,7 +4471,7 @@ static int parse(void)
int q = *insptr++, i = *insptr++;
if (fta_quotes[q] == NULL || redefined_quotes[i] == NULL)
{
OSD_Printf("%s %d null quote %d %d\n",__FILE__,__LINE__,q,i);
OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d %d\n",__FILE__,__LINE__,q,i);
break;
}
Bstrcpy(fta_quotes[q],redefined_quotes[i]);
@ -5293,7 +5293,7 @@ static int parse(void)
Bstrcpy(fta_quotes[i],g_player[j].user_name);
else Bsprintf(fta_quotes[i],"%d",j);
}
else OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,i);
else OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d\n",__FILE__,__LINE__,i);
break;
case CON_QGETSYSSTR:
if (fta_quotes[i] != NULL)
@ -5315,19 +5315,19 @@ static int parse(void)
Bstrcpy(fta_quotes[i],gametype_names[ud.coop]);
break;
default:
OSD_Printf("%s %d unknown str ID %d %d\n",__FILE__,__LINE__,i,j);
OSD_Printf(OSDTEXT_DARKRED "%s %d unknown str ID %d %d\n",__FILE__,__LINE__,i,j);
}
else OSD_Printf("%s %d null quote %d %d\n",__FILE__,__LINE__,i,j);
else OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d %d\n",__FILE__,__LINE__,i,j);
break;
case CON_QSTRCAT:
if (fta_quotes[i] != NULL && fta_quotes[j] != NULL)
Bstrncat(fta_quotes[i],fta_quotes[j],(MAXQUOTELEN-1)-Bstrlen(fta_quotes[i]));
else OSD_Printf("%s %d null quote %d %d\n",__FILE__,__LINE__,i,j);
else OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d %d\n",__FILE__,__LINE__,i,j);
break;
case CON_QSTRCPY:
if (fta_quotes[i] != NULL && fta_quotes[j] != NULL)
Bstrcpy(fta_quotes[i],fta_quotes[j]);
else OSD_Printf("%s %d null quote %d %d\n",__FILE__,__LINE__,i,j);
else OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d %d\n",__FILE__,__LINE__,i,j);
break;
case CON_CHANGESPRITESTAT:
changespritestat(i,j);
@ -5347,13 +5347,13 @@ static int parse(void)
if (volnume > MAXVOLUMES-1 || volnume < 0)
{
OSD_Printf("parse():CON_STARTLEVEL: invalid volume (%d)\n",volnume);
OSD_Printf(OSDTEXT_DARKRED "CON_STARTLEVEL: invalid volume (%d)\n",volnume);
break;
}
if (levnume > MAXLEVELS-1 || levnume < 0)
{
OSD_Printf("parse():CON_STARTLEVEL: invalid level (%d)\n",levnume);
OSD_Printf(OSDTEXT_DARKRED "CON_STARTLEVEL: invalid level (%d)\n",levnume);
break;
}
@ -5512,7 +5512,7 @@ static int parse(void)
break;
}
}
else OSD_Printf("error: invalid sprite\n");
else OSD_Printf(OSDTEXT_DARKRED "CON_DIST/CON_LDIST: error: invalid sprite\n");
SetGameVarID(distvar, distx, g_i, g_p);
break;
@ -5849,7 +5849,7 @@ static int parse(void)
int z=65536;
if (fta_quotes[q] == NULL)
{
OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,q);
OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d\n",__FILE__,__LINE__,q);
break;
}
if (tw == CON_GAMETEXTZ)z=GetGameVarID(*insptr++,g_i,g_p);
@ -5863,7 +5863,7 @@ static int parse(void)
if (fta_quotes[q] == NULL)
{
OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,q);
OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d\n",__FILE__,__LINE__,q);
break;
}
minitextshade(x,y,fta_quotes[q],shade,pal,26);
@ -6420,8 +6420,7 @@ static int parse(void)
case CON_CLEARMAPSTATE:
if (map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate)
{
Bfree(map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate);
map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate = NULL;
FreeMapState(ud.volume_number*MAXLEVELS+ud.level_number);
}
insptr++;
return 0;
@ -6530,8 +6529,8 @@ static int parse(void)
Bsprintf(fta_quotes[dq],tempbuf,var1,var2,var3,var4);
break;
}
if (fta_quotes[sq] == NULL) OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,sq);
if (fta_quotes[dq] == NULL) OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,dq);
if (fta_quotes[sq] == NULL) OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d\n",__FILE__,__LINE__,sq);
if (fta_quotes[dq] == NULL) OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d\n",__FILE__,__LINE__,dq);
insptr += 4;
break;
}
@ -6539,7 +6538,7 @@ static int parse(void)
case CON_ADDLOG:
{
insptr++;
OSD_Printf("CONLOG: L=%d\n",*insptr++);
OSD_Printf(OSDTEXT_GREEN "CONLOG: L=%d\n",*insptr++);
break;
}
@ -6572,12 +6571,12 @@ static int parse(void)
index=GetGameVarID(*insptr++,g_i,g_p);
if ((index < aGameArrays[lVarID].size)&&(index>=0))
{
OSD_Printf("CONLOGVAR: L=%d %s[%d] =%d\n",l, aGameArrays[lVarID].szLabel,index,m*aGameArrays[lVarID].plValues[index]);
OSD_Printf(OSDTEXT_GREEN "CONLOGVAR: L=%d %s[%d] =%d\n",l, aGameArrays[lVarID].szLabel,index,m*aGameArrays[lVarID].plValues[index]);
break;
}
else
{
OSD_Printf("CONLOGVAR: L=%d INVALID ARRAY INDEX\n",l);
OSD_Printf(OSDTEXT_DARKRED "CONLOGVAR: L=%d INVALID ARRAY INDEX\n",l);
break;
}
}
@ -6590,7 +6589,7 @@ static int parse(void)
{
// invalid varID
insptr++;
OSD_Printf("CONLOGVAR: L=%d INVALID VARIABLE\n",l);
OSD_Printf(OSDTEXT_DARKRED "CONLOGVAR: L=%d INVALID VARIABLE\n",l);
break; // out of switch
}
}
@ -6617,7 +6616,7 @@ static int parse(void)
Bstrcat(g_szBuf,szBuf);
Bsprintf(szBuf," =%d\n", GetGameVarID(lVarID, g_i, g_p)*m);
Bstrcat(g_szBuf,szBuf);
OSD_Printf(g_szBuf);
OSD_Printf(OSDTEXT_GREEN "%s",g_szBuf);
insptr++;
break;
}
@ -7043,7 +7042,7 @@ static int parse(void)
int asize = GetGameVarID(*insptr++, g_i, g_p);
if (asize > 0)
{
OSD_Printf("resizing array %s, old size %d new size %d\n", aGameArrays[j].szLabel, aGameArrays[j].size, asize);
OSD_Printf(OSDTEXT_GREEN "resizing array %s, old size %d new size %d\n", aGameArrays[j].szLabel, aGameArrays[j].size, asize);
aGameArrays[j].plValues=Brealloc(aGameArrays[j].plValues, sizeof(int) * asize);
aGameArrays[j].size = asize;
}
@ -7476,14 +7475,14 @@ static int parse(void)
if (fta_quotes[*insptr] == NULL)
{
OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,*insptr);
OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d\n",__FILE__,__LINE__,*insptr);
insptr++;
break;
}
if (g_p < 0 || g_p >= MAXPLAYERS)
{
OSD_Printf("CON_QUOTE: bad player for quote %d: (%d)\n",*insptr,g_p);
OSD_Printf(OSDTEXT_DARKRED "CON_QUOTE: bad player for quote %d: (%d)\n",*insptr,g_p);
insptr++;
break;
}
@ -7498,7 +7497,7 @@ static int parse(void)
if (fta_quotes[i] == NULL)
{
OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,i);
OSD_Printf(OSDTEXT_DARKRED "%s %d null quote %d\n",__FILE__,__LINE__,i);
break;
}
adduserquote(fta_quotes[i]);

View file

@ -51,7 +51,7 @@ void GAME_drawosdstr(int x, int y, char *ch, int len, int shade, int pal)
ac = *ch-'!'+STARTALPHANUM;
if (ac < STARTALPHANUM || ac > ENDALPHANUM) return;
rotatesprite(x<<16, (y<<3)<<16, 65536l, 0, ac, shade, pal, 8|16, 0, 0, xdim-1, ydim-1);
rotatesprite(x<<16, (y<<3)<<16, 65536l, 0, ac, shade, *(ch-OSD_GetTextPtr()+OSD_GetFmtPtr()), 8|16, 0, 0, xdim-1, ydim-1);
/* if (*ch >= '0' && *ch <= '9') x+=8;
else x += tilesizx[ac]; */
x += OSDCHAR_WIDTH;

View file

@ -1298,7 +1298,7 @@ int getteampal(int team)
static void resetpspritevars(char g)
{
short i, j, nexti,circ;
int firstx,firsty;
// int firstx,firsty;
spritetype *s;
char aimmode[MAXPLAYERS],autoaim[MAXPLAYERS],weaponswitch[MAXPLAYERS];
STATUSBARTYPE tsbar[MAXPLAYERS];
@ -1379,11 +1379,11 @@ static void resetpspritevars(char g)
if (numplayersprites == MAXPLAYERS)
gameexit("\nToo many player sprites (max 16.)");
if (numplayersprites == 0)
/* if (numplayersprites == 0)
{
firstx = g_player[0].ps->posx;
firsty = g_player[0].ps->posy;
}
}*/
g_PlayerSpawnPoints[(unsigned char)numplayersprites].ox = s->x;
g_PlayerSpawnPoints[(unsigned char)numplayersprites].oy = s->y;
@ -1858,7 +1858,7 @@ int enterlevel(int g)
// variables are set by pointer...
OnEvent(EVENT_ENTERLEVEL, -1, -1, -1);
initprintf("E%dL%d: %s\n",ud.volume_number+1,ud.level_number+1,map[(ud.volume_number*MAXLEVELS)+ud.level_number].name);
initprintf("^21E%dL%d: %s\n",ud.volume_number+1,ud.level_number+1,map[(ud.volume_number*MAXLEVELS)+ud.level_number].name);
return 0;
}