Subversion Repositories eduke32

Compare Revisions

Ignore whitespace Rev 869 → Rev 870

/polymer/build/include/baselayer.h
129,7 → 129,8
 
int setpalette(int start, int num, char *dapal);
//int getpalette(int start, int num, char *dapal);
int setgamma(float ro, float go, float bo);
int setgamma(void);
float vid_gamma, vid_contrast, vid_brightness;
 
int switchrendermethod(int,int); // 0 = software, 1 = opengl | bool = reinit
 
/polymer/build/src/baselayer.c
208,6 → 208,45
return OSDCMD_SHOWHELP;
}
 
static int osdcmd_vid_gamma(const osdfuncparm_t *parm)
{
if (parm->numparms != 1)
{
OSD_Printf("\"vid_gamma\" is \"%.1f\"\n",vid_gamma);
return OSDCMD_SHOWHELP;
}
vid_gamma = atof(parm->parms[0]);
OSD_Printf("%s\n",parm->raw);
setgamma();
return OSDCMD_OK;
}
 
static int osdcmd_vid_brightness(const osdfuncparm_t *parm)
{
if (parm->numparms != 1)
{
OSD_Printf("\"vid_brightness\" is \"%.1f\"\n",vid_brightness);
return OSDCMD_SHOWHELP;
}
vid_brightness = atof(parm->parms[0]);
OSD_Printf("%s\n",parm->raw);
setgamma();
return OSDCMD_OK;
}
 
static int osdcmd_vid_contrast(const osdfuncparm_t *parm)
{
if (parm->numparms != 1)
{
OSD_Printf("\"vid_contrast\" is \"%.1f\"\n",vid_contrast);
return OSDCMD_SHOWHELP;
}
vid_contrast = atof(parm->parms[0]);
OSD_Printf("%s\n",parm->raw);
setgamma();
return OSDCMD_OK;
}
 
int baselayer_init(void)
{
#ifdef POLYMOST
234,7 → 273,9
#endif
OSD_RegisterFunction("glinfo","glinfo: shows OpenGL information about the current OpenGL mode",osdcmd_glinfo);
#endif
 
OSD_RegisterFunction("vid_gamma","vid_gamma <gamma>: adjusts gamma ramp",osdcmd_vid_gamma);
OSD_RegisterFunction("vid_contrast","vid_contrast <gamma>: adjusts gamma ramp",osdcmd_vid_contrast);
OSD_RegisterFunction("vid_brightness","vid_brightness <gamma>: adjusts gamma ramp",osdcmd_vid_brightness);
return 0;
}
 
/polymer/build/src/engine.c
78,6 → 78,7
static int oxdimen = -1, oviewingrange = -1, oxyaspect = -1;
 
int curbrightness = 0, gammabrightness = 0;
float vid_gamma = 1.0, vid_contrast = 1.0, vid_brightness = 0.0;
 
//Textured Map variables
static char globalpolytype;
9985,7 → 9986,6
void setbrightness(char dabrightness, char *dapal, char noapply)
{
int i, k, j;
float f;
unsigned int newpalettesum, lastbright;
 
lastbright = curbrightness;
9992,8 → 9992,8
if (!(noapply&4))
curbrightness = min(max((int)dabrightness,0),15);
 
f = 1.0 + ((float)curbrightness / 10.0);
if (setgamma(f,f,f)) j = curbrightness; else j = 0;
vid_gamma = 1.0 + ((float)curbrightness / 10.0);
if (setgamma()) j = curbrightness; else j = 0;
 
for (k=i=0;i<256;i++)
{
/polymer/build/src/osd.c
814,7 → 814,7
lastmatch = symb;
symb=findsymbol(osdedittmp, lastmatch->next);
}
OSD_Printf(OSDTEXT_GREEN "Found %d possible completions for '%s':\n",num,osdedittmp);
OSD_Printf(OSDTEXT_RED "Found %d possible completions for '%s':\n",num,osdedittmp);
maxwidth += 3;
symb = tabc;
OSD_Printf(" ");
/polymer/build/src/sdlayer.c
57,7 → 57,7
char nofog=0;
static unsigned short sysgamma[3][256];
extern int curbrightness, gammabrightness;
 
extern float vid_gamma, vid_contrast, vid_brightness;
#ifdef USE_OPENGL
// OpenGL stuff
static char nogl=0;
1160,12 → 1160,12
// save the current system gamma to determine if gamma is available
if (!gammabrightness)
{
float f = 1.0 + ((float)curbrightness / 10.0);
// float f = 1.0 + ((float)curbrightness / 10.0);
if (SDL_GetGammaRamp(sysgamma[0], sysgamma[1], sysgamma[2]) >= 0)
gammabrightness = 1;
 
// see if gamma really is working by trying to set the brightness
if (gammabrightness && SDL_SetGamma(f,f,f) < 0)
if (gammabrightness && setgamma() < 0)
gammabrightness = 0; // nope
}
 
1363,9 → 1363,28
//
// setgamma
//
int setgamma(float ro, float go, float bo)
int setgamma(void)
{
return SDL_SetGamma(ro,go,bo);
int i;
unsigned short gammaTable[768];
float gamma = max(0.1f,min(4.f,vid_gamma));
float contrast = max(0.1f,min(3.f,vid_contrast));
float bright = max(-0.8f,min(0.8f,vid_brightness));
 
double invgamma = 1 / gamma;
double norm = pow(255., invgamma - 1);
 
// This formula is taken from Doomsday
 
for (i = 0; i < 256; i++)
{
double val = i * contrast - (contrast - 1) * 127;
if (gamma != 1) val = pow(val, invgamma) / norm;
val += bright * 128;
 
gammaTable[i] = gammaTable[i + 256] = gammaTable[i + 512] = (unsigned short)max(0.f,(double)min(0xffff,val*256));
}
return SDL_SetGammaRamp(&gammaTable[0],&gammaTable[256],&gammaTable[512]);
}
 
#ifndef __APPLE__
/polymer/build/src/winlayer.c
62,6 → 62,7
 
static WORD sysgamma[3][256];
extern int curbrightness, gammabrightness;
extern float vid_gamma, vid_contrast, vid_brightness;
 
#if defined(USE_OPENGL) && defined(POLYMOST)
// OpenGL stuff
2104,9 → 2105,9
 
if (!gammabrightness)
{
float f = 1.0 + ((float)curbrightness / 10.0);
// float f = 1.0 + ((float)curbrightness / 10.0);
if (getgammaramp(sysgamma) >= 0) gammabrightness = 1;
if (gammabrightness && setgamma(f,f,f) < 0) gammabrightness = 0;
if (gammabrightness && setgamma() < 0) gammabrightness = 0;
}
 
for (i=0;i<NUM_INPUTS;i++) if (inp[i]) AcquireInputDevices(1,i);
2657,22 → 2658,30
}
}
 
int setgamma(float ro, float go, float bo)
int setgamma(void)
{
int i;
WORD gt[3][256];
WORD gammaTable[768];
float gamma = max(0.1f,min(4.f,vid_gamma));
float contrast = max(0.1f,min(3.f,vid_contrast));
float bright = max(-0.8f,min(0.8f,vid_brightness));
 
double invgamma = 1 / gamma;
double norm = pow(255., invgamma - 1);
 
if (!hWindow) return -1;
 
ro = 1.0 / ro; go = 1.0 / go; bo = 1.0 / bo;
for (i=0;i<256;i++)
{
gt[0][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, ro) * 65535.0 + 0.5)));
gt[1][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, go) * 65535.0 + 0.5)));
gt[2][i] = (WORD)min(65535, max(0, (int)(pow((double)i / 256.0, go) * 65535.0 + 0.5)));
}
 
return setgammaramp(gt);
// This formula is taken from Doomsday
 
for (i = 0; i < 256; i++)
{
double val = i * contrast - (contrast - 1) * 127;
if (gamma != 1) val = pow(val, invgamma) / norm;
val += bright * 128;
 
gammaTable[i] = gammaTable[i + 256] = gammaTable[i + 512] = (WORD)max(0.f,(double)min(0xffff,val*256));
}
return setgammaramp(gammaTable);
}
 
static int getgammaramp(WORD gt[3][256])
/polymer/eduke32/source/game.c
2517,8 → 2517,8
if (p->ftq != q)
if (p == g_player[screenpeek].ps)
{
if (cq) OSD_Printf(OSDTEXT_BLUE OSDTEXT_BRIGHT "%s\n",stripcolorcodes(fta_quotes[q]));
else OSD_Printf("%s\n",stripcolorcodes(fta_quotes[q]));
if (cq) OSD_Printf(OSDTEXT_BLUE "%s\n",fta_quotes[q]);
else OSD_Printf("%s\n",fta_quotes[q]);
}
 
p->ftq = q;
/polymer/eduke32/source/gamedef.c
555,7 → 555,7
{ "htbposx", ACTOR_HTBPOSX, 0, 0 },
{ "htbposy", ACTOR_HTBPOSY, 0, 0 },
{ "htbposz", ACTOR_HTBPOSZ, 0, 0 },
{ "htg_t", ACTOR_HTG_T, LABEL_HASPARM2, 9 },
{ "htg_t", ACTOR_HTG_T, LABEL_HASPARM2, 10 },
 
// model flags
 
598,8 → 598,8
{ "zoom", PLAYER_ZOOM, 0, 0 },
{ "exitx", PLAYER_EXITX, 0, 0 },
{ "exity", PLAYER_EXITY, 0, 0 },
{ "loogiex", PLAYER_LOOGIEX, LABEL_HASPARM2, 63 },
{ "loogiey", PLAYER_LOOGIEY, LABEL_HASPARM2, 63 },
{ "loogiex", PLAYER_LOOGIEX, LABEL_HASPARM2, 64 },
{ "loogiey", PLAYER_LOOGIEY, LABEL_HASPARM2, 64 },
{ "numloogs", PLAYER_NUMLOOGS, 0, 0 },
{ "loogcnt", PLAYER_LOOGCNT, 0, 0 },
{ "posx", PLAYER_POSX, 0, 0 },
/polymer/eduke32/source/gameexec.c
1165,7 → 1165,7
return;
}
 
if (lParm2 < 0 || lParm2 > playerlabels[lLabelID].maxParm2)
if (lParm2 < 0 || lParm2 >= playerlabels[lLabelID].maxParm2)
{
OSD_Printf(OSDTEXT_DARKRED OSDTEXT_BRIGHT "DoPlayer(): tried to %s invalid %s position %d on player (%d) from spr %d\n",
iSet?"set":"get",playerlabels[lLabelID].name,lParm2,iPlayer,g_i);
2995,7 → 2995,7
return;
}
 
if (lParm2 < 0 || lParm2 > actorlabels[lLabelID].maxParm2)
if (lParm2 < 0 || lParm2 >= actorlabels[lLabelID].maxParm2)
{
OSD_Printf(OSDTEXT_DARKRED OSDTEXT_BRIGHT "DoActor(): tried to %s invalid %s position %d on sprite (%d) from spr %d\n",
iSet?"set":"get",actorlabels[lLabelID].name,lParm2,iActor,g_i);
/polymer/eduke32/source/osdcmds.c
766,16 → 766,16
return OSDCMD_OK;
}
 
static int osdcmd_gamma(const osdfuncparm_t *parm)
static int osdcmd_setbrightness(const osdfuncparm_t *parm)
{
if (parm->numparms != 1)
{
OSD_Printf("\"gamma\" \"%d\"\n",ud.brightness>>2);
// OSD_Printf("\"setbri\" \"%d\"\n",ud.brightness>>2);
return OSDCMD_SHOWHELP;
}
ud.brightness = atoi(parm->parms[0])<<2;
setbrightness(ud.brightness>>2,&g_player[screenpeek].ps->palette[0],0);
OSD_Printf("gamma %d\n",ud.brightness>>2);
OSD_Printf("setbrightness %d\n",ud.brightness>>2);
return OSDCMD_OK;
}
 
1215,7 → 1215,7
extern void savemapstate(mapstate_t *save);
extern void restoremapstate(mapstate_t *save);
 
int osdcmd_savestate(const osdfuncparm_t *parm)
static int osdcmd_savestate(const osdfuncparm_t *parm)
{
UNREFERENCED_PARAMETER(parm);
if (map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate == NULL)
1224,7 → 1224,7
return OSDCMD_OK;
}
 
int osdcmd_restorestate(const osdfuncparm_t *parm)
static int osdcmd_restorestate(const osdfuncparm_t *parm)
{
UNREFERENCED_PARAMETER(parm);
if (map[ud.volume_number*MAXLEVELS+ud.level_number].savedstate)
1271,7 → 1271,7
OSD_RegisterFunction(t,Bstrdup(tempbuf),osdcmd_button);
}
 
OSD_RegisterFunction("gamma","gamma <value>: changes brightness", osdcmd_gamma);
OSD_RegisterFunction("setbrightness","setbrightness <value>: changes brightness", osdcmd_setbrightness);
OSD_RegisterFunction("give","give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item", osdcmd_give);
OSD_RegisterFunction("god","god: toggles god mode", osdcmd_god);
 
/polymer/eduke32/source/player.c
3583,7 → 3583,7
Bsprintf(tempbuf,fta_quotes[PPDEATHSTRINGS+i+(mulscale(krand(), 3, 16)*10)],name1,name2);
if (ud.config.ScreenWidth >= 800)
adduserquote(tempbuf);
else OSD_Printf("%s\n",stripcolorcodes(tempbuf));
else OSD_Printf("%s\n",tempbuf);
}
}
else
3604,7 → 3604,7
{
if (ud.config.ScreenWidth >= 800)
adduserquote(tempbuf);
else OSD_Printf("%s\n",stripcolorcodes(tempbuf));
else OSD_Printf("%s\n",tempbuf);
}
}