logging now shuts off after a bad write
colormapping made more generic (more with that later) small stat fix git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1663 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
20da7c41cd
commit
87d4c83abe
10 changed files with 114 additions and 58 deletions
|
@ -211,7 +211,7 @@ int Sys_FileRead (int handle, void *dest, int count)
|
|||
return read (handle, dest, count);
|
||||
}
|
||||
|
||||
void Sys_DebugLog(char *file, char *fmt, ...)
|
||||
int Sys_DebugLog(char *file, char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
static char data[1024];
|
||||
|
@ -226,8 +226,13 @@ void Sys_DebugLog(char *file, char *fmt, ...)
|
|||
|
||||
// fd = open(file, O_WRONLY | O_BINARY | O_CREAT | O_APPEND, 0666);
|
||||
fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
|
||||
write(fd, data, strlen(data));
|
||||
close(fd);
|
||||
if (fd)
|
||||
{
|
||||
write(fd, data, strlen(data));
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Sys_EnumerateFiles (char *gpath, char *match, int (*func)(char *, int, void *), void *parm)
|
||||
|
|
|
@ -149,7 +149,7 @@ void Sys_Init(void)
|
|||
|
||||
|
||||
|
||||
void VARGS Sys_DebugLog(char *file, char *fmt, ...)
|
||||
int VARGS Sys_DebugLog(char *file, char *fmt, ...)
|
||||
{
|
||||
FILE *fd;
|
||||
va_list argptr;
|
||||
|
@ -181,8 +181,13 @@ void VARGS Sys_DebugLog(char *file, char *fmt, ...)
|
|||
}
|
||||
#endif
|
||||
fd = fopen(file, "wt");
|
||||
fwrite(data, 1, strlen(data), fd);
|
||||
fclose(fd);
|
||||
if (fd)
|
||||
{
|
||||
fwrite(data, 1, strlen(data), fd);
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ void VARGS MaskExceptions (void);
|
|||
void Sys_PopFPCW (void);
|
||||
void Sys_PushFPCW_SetHigh (void);
|
||||
|
||||
void VARGS Sys_DebugLog(char *file, char *fmt, ...)
|
||||
int VARGS Sys_DebugLog(char *file, char *fmt, ...)
|
||||
{
|
||||
FILE *fd;
|
||||
va_list argptr;
|
||||
|
@ -205,7 +205,10 @@ void VARGS Sys_DebugLog(char *file, char *fmt, ...)
|
|||
{
|
||||
fprintf(fd, "%s", data);
|
||||
fclose(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
};
|
||||
|
||||
int *debug;
|
||||
|
|
|
@ -159,7 +159,7 @@ void Con_Log (char *s)
|
|||
FILE *fi;
|
||||
|
||||
// check file size, use x as temp
|
||||
if (fi = fopen(f, "rb"))
|
||||
if ((fi = fopen(f, "rb")))
|
||||
{
|
||||
x = COM_filelength(fi);
|
||||
fclose(fi);
|
||||
|
@ -185,7 +185,7 @@ void Con_Log (char *s)
|
|||
_snprintf(oldf, sizeof(oldf)-1, "%s.%i", f, x);
|
||||
|
||||
// check if file exists, otherwise skip
|
||||
if (fi = fopen(oldf, "rb"))
|
||||
if ((fi = fopen(oldf, "rb")))
|
||||
fclose(fi);
|
||||
else
|
||||
continue; // skip nonexistant files
|
||||
|
@ -212,7 +212,13 @@ void Con_Log (char *s)
|
|||
}
|
||||
|
||||
// write to log file
|
||||
Sys_DebugLog(f, "%s", logbuf);
|
||||
if (Sys_DebugLog(f, "%s", logbuf))
|
||||
{
|
||||
// write failed, bug out
|
||||
Cvar_ForceSet(&log_enable, "0");
|
||||
Con_Printf("Unable to write to log file. Logging disabled.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Log_Init(void)
|
||||
|
|
|
@ -45,7 +45,7 @@ void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length);
|
|||
//
|
||||
// system IO
|
||||
//
|
||||
void VARGS Sys_DebugLog(char *file, char *fmt, ...);
|
||||
int VARGS Sys_DebugLog(char *file, char *fmt, ...);
|
||||
|
||||
void VARGS Sys_Error (const char *error, ...);
|
||||
// an error will cause the entire program to exit
|
||||
|
|
|
@ -564,7 +564,6 @@ void PR_LoadGlabalStruct(void)
|
|||
SV_QCStat(ev_float, "cnt_invincibility", STAT_H2_CNT_INVINCIBILITY);
|
||||
SV_QCStat(ev_float, "artifact_active", STAT_H2_ARTIFACT_ACTIVE);
|
||||
SV_QCStat(ev_float, "artifact_low", STAT_H2_ARTIFACT_LOW);
|
||||
SV_QCStat(ev_float, "artifact_low", STAT_H2_ARTIFACT_LOW);
|
||||
SV_QCStat(ev_float, "movetype", STAT_H2_MOVETYPE);
|
||||
SV_QCStat(ev_entity, "cameramode", STAT_H2_CAMERAMODE);
|
||||
SV_QCStat(ev_float, "hasted", STAT_H2_HASTED);
|
||||
|
|
|
@ -113,7 +113,7 @@ int Sys_EnumerateFiles (char *gpath, char *match, int (*func)(char *, int, void
|
|||
}
|
||||
#endif
|
||||
|
||||
void Sys_DebugLog(char *file, char *fmt, ...)
|
||||
int Sys_DebugLog(char *file, char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char data[1024];
|
||||
|
@ -127,8 +127,13 @@ void Sys_DebugLog(char *file, char *fmt, ...)
|
|||
Sys_Error("Sys_DebugLog was stomped\n");
|
||||
|
||||
fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
|
||||
write(fd, data, strlen(data));
|
||||
close(fd);
|
||||
if (fd)
|
||||
{
|
||||
write(fd, data, strlen(data));
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
================
|
||||
|
|
|
@ -163,7 +163,7 @@ cvar_t sys_colorconsole = {"sys_colorconsole", "1"};
|
|||
HWND consolewindowhandle;
|
||||
HWND hiddenwindowhandler;
|
||||
|
||||
void Sys_DebugLog(char *file, char *fmt, ...)
|
||||
int void Sys_DebugLog(char *file, char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
static char data[1024];
|
||||
|
@ -173,8 +173,13 @@ void Sys_DebugLog(char *file, char *fmt, ...)
|
|||
_vsnprintf(data, sizeof(data)-1, fmt, argptr);
|
||||
va_end(argptr);
|
||||
fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
|
||||
write(fd, data, strlen(data));
|
||||
close(fd);
|
||||
if (fd)
|
||||
{
|
||||
write(fd, data, strlen(data));
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
return 1; // error
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -211,6 +211,68 @@ void MakeFullbrightRemap(void)
|
|||
nofbremap[i] = FindIndexFromRGBNoFB(host_basepal[i*3], host_basepal[i*3+1], host_basepal[i*3+2]);
|
||||
}
|
||||
|
||||
// colormap functions
|
||||
void BuildModulatedColormap(qbyte *indexes, int red, int green, int blue, qboolean desaturate, qboolean fullbrights)
|
||||
{
|
||||
qbyte *rgb = host_basepal;
|
||||
unsigned int r, g, b, x, invmask = 0;
|
||||
|
||||
if (red < 0 || green < 0 || blue < 0)
|
||||
invmask = 0xff;
|
||||
|
||||
// generate colormap
|
||||
|
||||
if (desaturate)
|
||||
{
|
||||
int s;
|
||||
|
||||
for (x = 0; x < 256; x++)
|
||||
{
|
||||
s = rgb[0]*76 + rgb[1]*151 + rgb[2]*29 + 128;
|
||||
r = abs((127*256 + s*red) >> 16);
|
||||
g = abs((127*256 + s*green) >> 16);
|
||||
b = abs((127*256 + s*blue) >> 16);
|
||||
|
||||
if (r > 255)
|
||||
r = 255;
|
||||
if (g > 255)
|
||||
g = 255;
|
||||
if (b > 255)
|
||||
b = 255;
|
||||
|
||||
if (fullbrights) // relying on branch prediction here...
|
||||
indexes[x] = GetPalette(r^invmask, g^invmask, b^invmask);
|
||||
else
|
||||
indexes[x] = GetPaletteNoFB(r^invmask, g^invmask, b^invmask);
|
||||
rgb += 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (x = 0; x < 256; x++)
|
||||
{
|
||||
// modulus math
|
||||
r = abs((127 + rgb[0]*red) >> 8);
|
||||
g = abs((127 + rgb[1]*green) >> 8);
|
||||
b = abs((127 + rgb[2]*blue) >> 8);
|
||||
|
||||
if (r > 255)
|
||||
r = 255;
|
||||
if (g > 255)
|
||||
g = 255;
|
||||
if (b > 255)
|
||||
b = 255;
|
||||
|
||||
if (fullbrights) // relying on branch prediction here...
|
||||
indexes[x] = GetPalette(r^invmask, g^invmask, b^invmask);
|
||||
else
|
||||
indexes[x] = GetPaletteNoFB(r^invmask, g^invmask, b^invmask);
|
||||
rgb += 3;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MediaSW_ShowFrame8bit(qbyte *framedata, int inwidth, int inheight, qbyte *palette)
|
||||
{
|
||||
int y, x;
|
||||
|
|
|
@ -2389,64 +2389,30 @@ void SWDraw_FadeScreen (void)
|
|||
if (fsmodified != r_menutint.modified)
|
||||
{
|
||||
char *t;
|
||||
int s;
|
||||
float r, g, b;
|
||||
qbyte invmask = 0;
|
||||
int r, g, b;
|
||||
|
||||
qbyte *rgb = (qbyte *)host_basepal;
|
||||
|
||||
// parse r_menutint
|
||||
fsnodraw = 0;
|
||||
r = r_menutint.value;
|
||||
r = 255*r_menutint.value;
|
||||
g = 0;
|
||||
b = 0;
|
||||
t = strstr(r_menutint.string, " ");
|
||||
if (t)
|
||||
{
|
||||
g = atof(t+1);
|
||||
g = 255*atof(t+1);
|
||||
t = strstr(t+1, " ");
|
||||
if (t)
|
||||
b = atof(t+1);
|
||||
b = 255*atof(t+1);
|
||||
else
|
||||
fsnodraw = 1;
|
||||
}
|
||||
else
|
||||
fsnodraw = 1;
|
||||
|
||||
// bounds check and inverse check
|
||||
if (r < 0)
|
||||
{
|
||||
invmask = 0xff;
|
||||
r = -r;
|
||||
}
|
||||
if (r > 1)
|
||||
r = 1;
|
||||
|
||||
if (g < 0)
|
||||
{
|
||||
invmask = 0xff;
|
||||
g = -g;
|
||||
}
|
||||
if (g > 1)
|
||||
g = 1;
|
||||
|
||||
if (b < 0)
|
||||
{
|
||||
invmask = 0xff;
|
||||
b = -b;
|
||||
}
|
||||
if (b > 1)
|
||||
b = 1;
|
||||
|
||||
// generate colormap
|
||||
for (x = 0; x < 256; x++)
|
||||
{
|
||||
// convert to grayscale value
|
||||
s = rgb[0]*0.299 + rgb[1]*0.587 + rgb[2]*0.114;
|
||||
|
||||
fscolormap[x] = GetPalette((int)(s*r)^invmask, (int)(s*g)^invmask, (int)(s*b)^invmask);
|
||||
rgb += 3;
|
||||
}
|
||||
// rebuild colormap here
|
||||
BuildModulatedColormap(fscolormap, r, g, b, true, true);
|
||||
|
||||
fsmodified = r_menutint.modified;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue