19 Nov 2007

This commit is contained in:
g-cont 2007-11-19 00:00:00 +03:00 committed by Alibek Omarov
parent 3954a9880c
commit a10a6b77a6
51 changed files with 2830 additions and 981 deletions

View File

@ -24,23 +24,11 @@ widthInChars = visible_length
maxchars = length
scroll = visible_offset
Варианты развития событий:
1. пути к движку нету вообще, лаунчер хз где - "unable to load launch.dll"
2. лаунчер лежит в корневой папке движка, пути нету - нормальный запуск, с записью в реестр
3. лаунчер лежит в папке bin, пути нету - нормальный запуск, с записью в реестр
4. лаунчер в папке bin, но путь заведомо ложный - нормальный запуск с исправлением пути
5. путь ложный и лаунчер лежит именно там - "unable to load launch.dll"
1. какие-то глюки отсечения визлифов (новый протокол глючит?)
2. автокомплит для имен ресурсов OK
3. переписать этот идиотский автокомплит, чтобы было красиво OK
4. Нормальные команды для проигрывания демок и видео OK
5. Привести команды в порядок (162 штуки) OK
6. избавиться от appactivate
7. расширить мышиную функциональность
8. Имплементировать сохранялки
9. Избавиться от VID_GetModeInfo, VID_NewWindow, VID_AppActivate и VID_MenuInit
работа над ошибками
1. доделать сохранялки
2. исправить глюки отсечения визлифов
3. имплементация простой зип-системы для виртуальной файловой
4. переписать qcclib для работы с новой зип-машиной
//==================================================
// то, что уже готово

View File

@ -113,16 +113,19 @@ WriteSPRFile
*/
void WriteSPRFile (void)
{
vfile_t *f;
vfile_t *vf;
file_t *file;
if(sprite.numframes == 0) Sys_Error ("%s have no frames\n", spriteoutname );
if((plump - lumpbuffer) > MAX_BUFFER_SIZE)
Sys_Error ("Can't write %s, sprite package too big", spriteoutname );
f = VFS_Open(spriteoutname, "wb" );
file = FS_Open( spriteoutname, "wb" );
vf = VFS_Open( file, "wb" );
Msg("writing %s\n", spriteoutname);
WriteSprite( f );
VFS_Close( f );
WriteSprite( vf );
file = VFS_Close( vf );
FS_Close( file );
Msg("%d frame%s\n", sprite.numframes, sprite.numframes > 1 ? "s" : "" );
spriteoutname[0] = 0;// clear for a new sprite

View File

@ -549,6 +549,7 @@ void PR_WriteLNOfile(char *destname)
{
dlno_t lno;
vfile_t *h;
file_t *f;
char filename[MAX_QPATH];
if(!opt_writelinenums) return;
@ -564,18 +565,21 @@ void PR_WriteLNOfile(char *destname)
lno.numfielddefs = numfielddefs;
lno.numstatements = numstatements;
h = VFS_Open ( filename, "w" );
VFS_Write (h, &lno, sizeof(dlno_t)); // header
VFS_Write (h, statement_linenums, numstatements * sizeof(int));
f = FS_Open( filename, "w" );
h = VFS_Open( f, "w" );
VFS_Write(h, &lno, sizeof(dlno_t)); // header
VFS_Write(h, statement_linenums, numstatements * sizeof(int));
MsgDev(D_INFO, "Writing %s, total size %d bytes\n", filename, ((VFS_Tell(h)+3) & ~3));
VFS_Close (h);
f = VFS_Close( h );
FS_Close( f );
}
void PR_WriteDAT( void )
{
ddef_t *dd;
vfile_t *h;
file_t *f;
dprograms_t progs; // header
char element[MAX_NAME];
int i, progsize, num_ref;
@ -749,11 +753,12 @@ void PR_WriteDAT( void )
MsgDev (D_INFO, "%6i numfielddefs (%i unique) (of %i)\n", numfielddefs, pr.size_fields, MAX_FIELDS);
MsgDev (D_INFO, "%6i numpr_globals (of %i)\n", numpr_globals, MAX_REGS);
h = VFS_Open ( progsoutname, "w" );
VFS_Write (h, &progs, sizeof(progs));
VFS_Write (h, "\r\n\r\n", 4);
VFS_Write (h, v_copyright, strlen(v_copyright) + 1);
VFS_Write (h, "\r\n\r\n", 4);
f = FS_Open( progsoutname, "wb" );
h = VFS_Open( f, "w" );
VFS_Write(h, &progs, sizeof(progs));
VFS_Write(h, "\r\n\r\n", 4);
VFS_Write(h, v_copyright, strlen(v_copyright) + 1);
VFS_Write(h, "\r\n\r\n", 4);
progs.ofs_strings = VFS_Tell(h);
progs.numstrings = strofs;
@ -933,7 +938,8 @@ void PR_WriteDAT( void )
if (asmfile) FS_Close(asmfile);
MsgDev(D_INFO, "Writing %s, total size %i bytes\n", progsoutname, progsize );
VFS_Close (h); // write real file into disk
f = VFS_Close(h); // write real file into disk
FS_Close(f);
}
/*

View File

@ -450,9 +450,9 @@ void Con_DrawSolidConsole (float frac)
vec4_t color;
char curtime[MAX_QPATH];
lines = viddef.height * frac;
lines = scr_height->integer * frac;
if (lines <= 0) return;
if (lines > viddef.height) lines = viddef.height;
if (lines > scr_height->integer) lines = scr_height->integer;
con.xadjust = 0; // on wide screens, we will center the text
SCR_AdjustSize( &con.xadjust, NULL, NULL, NULL );
@ -470,7 +470,7 @@ void Con_DrawSolidConsole (float frac)
std.snprintf( curtime, MAX_QPATH, "%s ", timestamp( TIME_TIME_ONLY));
i = strlen( curtime );
for (x = 0; x < i; x++)
SCR_DrawSmallChar( viddef.width - ( i - x ) * SMALLCHAR_WIDTH, (lines - (SMALLCHAR_HEIGHT+SMALLCHAR_HEIGHT/2)), curtime[x]);
SCR_DrawSmallChar(scr_width->integer - ( i - x ) * SMALLCHAR_WIDTH, (lines - (SMALLCHAR_HEIGHT+SMALLCHAR_HEIGHT/2)), curtime[x]);
re->SetColor(NULL);
// draw the text

View File

@ -27,8 +27,6 @@ cvar_t *v_centerspeed;
cvar_t *m_filter; // mouse sensetivity
cvar_t *m_mouse;
bool in_appactive;
uint frame_msec;
uint old_sys_frame_time;
@ -95,7 +93,6 @@ void IN_ActivateMouse (void)
}
if(mouseactive) return;
mouseactive = true;
if( mouseparmsvalid ) restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
@ -161,32 +158,27 @@ void IN_StartupMouse (void)
/*
===========
IN_MouseEvent
M_Event
===========
*/
void IN_MouseEvent (int mstate)
void M_Event( int mstate )
{
int i;
if (!mouseinitialized)
return;
if(!mouseinitialized) return;
// perform button actions
for (i=0 ; i<mouse_buttons ; i++)
for (i = 0; i < mouse_buttons; i++)
{
if ( (mstate & (1<<i)) &&
!(mouse_oldbuttonstate & (1<<i)) )
if((mstate & (1<<i)) && !(mouse_oldbuttonstate & (1<<i)) )
{
Key_Event (K_MOUSE1 + i, true, host.sv_timer);
}
if ( !(mstate & (1<<i)) &&
(mouse_oldbuttonstate & (1<<i)) )
if ( !(mstate & (1<<i)) && (mouse_oldbuttonstate & (1<<i)) )
{
Key_Event (K_MOUSE1 + i, false, host.sv_timer);
Key_Event (K_MOUSE1 + i, false, host.sv_timer);
}
}
mouse_oldbuttonstate = mstate;
}
@ -200,8 +192,7 @@ void CL_MouseMove (usercmd_t *cmd)
{
int mx, my;
if (!mouseactive)
return;
if (!mouseactive) return;
// find mouse movement
if (!GetCursorPos (&current_pos))
@ -263,17 +254,19 @@ VIEW CENTERING
/*
===========
IN_Activate
M_Activate
Called when the main window gains or loses focus.
The window may have been destroyed and recreated
between a deactivate and an activate.
===========
*/
void IN_Activate (bool active)
void M_Activate( void )
{
in_appactive = active;
mouseactive = !active; // force a new window check or turn off
// force a new window check or turn off
if(host.state == HOST_FRAME)
mouseactive = false;
else mouseactive = true;
}
@ -288,22 +281,22 @@ void CL_UpdateMouse( void )
{
if(!mouseinitialized) return;
if(!m_mouse || !in_appactive)
if(!m_mouse || host.state != HOST_FRAME)
{
IN_DeactivateMouse ();
IN_DeactivateMouse();
return;
}
if( !cl.refresh_prepped || cls.key_dest == key_console || cls.key_dest == key_menu )
{
// temporarily deactivate if in fullscreen
if(!Cvar_VariableValue ("r_fullscreen"))
if(!Cvar_VariableValue ("fullscreen"))
{
IN_DeactivateMouse ();
IN_DeactivateMouse();
return;
}
}
IN_ActivateMouse ();
IN_ActivateMouse();
}
/*
@ -594,18 +587,13 @@ void CL_ClampPitch (void)
float pitch;
pitch = SHORT2ANGLE(cl.frame.playerstate.pmove.delta_angles[PITCH]);
if (pitch > 180)
pitch -= 360;
if (pitch > 180) pitch -= 360;
if (cl.viewangles[PITCH] + pitch < -360)
cl.viewangles[PITCH] += 360; // wrapped
if (cl.viewangles[PITCH] + pitch > 360)
cl.viewangles[PITCH] -= 360; // wrapped
if (cl.viewangles[PITCH] + pitch < -360) cl.viewangles[PITCH] += 360; // wrapped
if (cl.viewangles[PITCH] + pitch > 360) cl.viewangles[PITCH] -= 360; // wrapped
if (cl.viewangles[PITCH] + pitch > 89)
cl.viewangles[PITCH] = 89 - pitch;
if (cl.viewangles[PITCH] + pitch < -89)
cl.viewangles[PITCH] = -89 - pitch;
if (cl.viewangles[PITCH] + pitch > 89) cl.viewangles[PITCH] = 89 - pitch;
if (cl.viewangles[PITCH] + pitch < -89) cl.viewangles[PITCH] = -89 - pitch;
}
/*

View File

@ -1652,8 +1652,8 @@ void CL_Init (void)
M_Init ();
SCR_Init ();
CL_InitLocal ();
SCR_Init();
CL_InitLocal();
}

View File

@ -203,15 +203,13 @@ void CL_PredictMovement (void)
int step;
int oldz;
if (cls.state != ca_active)
return;
if (cl_paused->value)
return;
if(cls.state != ca_active) return;
if(cl_paused->value) return;
if (!cl_predict->value || (cl.frame.playerstate.pmove.pm_flags & PMF_NO_PREDICTION))
{ // just set angles
for (i=0 ; i<3 ; i++)
{
// just set angles
for (i = 0; i < 3; i++)
{
cl.predicted_angles[i] = cl.viewangles[i] + SHORT2ANGLE(cl.frame.playerstate.pmove.delta_angles[i]);
}

View File

@ -13,6 +13,8 @@ cvar_t *scr_centertime;
cvar_t *scr_showpause;
cvar_t *scr_printspeed;
cvar_t *scr_loading;
cvar_t *scr_width;
cvar_t *scr_height;
cvar_t *cl_levelshot_name;
void SCR_TimeRefresh_f( void );
@ -31,8 +33,8 @@ void SCR_AdjustSize( float *x, float *y, float *w, float *h )
float yscale;
// scale for screen sizes
xscale = viddef.width / 640.0f;
yscale = viddef.height / 480.0f;
xscale = scr_width->integer / 640.0f;
yscale = scr_height->integer / 480.0f;
if(x) *x *= xscale;
if(y) *y *= yscale;

View File

@ -91,9 +91,9 @@ Sets scr_vrect, the coordinates of the rendered window
*/
void V_CalcRect( void )
{
scr_vrect.width = viddef.width;
scr_vrect.width = scr_width->integer;
scr_vrect.width &= ~7;
scr_vrect.height = viddef.height;
scr_vrect.height = scr_height->integer;
scr_vrect.height &= ~1;
scr_vrect.y = scr_vrect.x = 0;
}

View File

@ -23,7 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define CLIENT_H
#include "engine.h"
#include "vid.h"
#include "screen.h"
#include "sound.h"
#include "net_msg.h"
@ -467,8 +466,6 @@ void CL_Quit_f (void);
void CL_ScreenShot_f( void );
void CL_LevelShot_f( void );
void CL_SetSky_f( void );
void IN_Accumulate (void);
void CL_ParseLayout (void);

View File

@ -21,7 +21,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef SCREEN_H
#define SCREEN_H
#include "vid.h"
typedef struct vrect_s
{
int x;
int y;
int width;
int height;
} vrect_t;
// all drawing is done to a 640*480 virtual screen size
// and will be automatically scaled to the real resolution
@ -62,18 +68,22 @@ typedef enum
#define COLOR_208 GetRGBA(0.0f, 0.4f, 0.0f, 1.0f)
#define COLOR_223 GetRGBA(0.5f, 0.2f, 1.0f, 1.0f)
void SCR_Init (void);
void SCR_UpdateScreen (void);
void SCR_Init (void);
void SCR_UpdateScreen (void);
void SCR_SizeUp (void);
void SCR_SizeDown (void);
void SCR_CenterPrint (char *str);
void VID_Init( void );
void VID_MenuInit( void );
void VID_MenuDraw( void );
const char *VID_MenuKey( int );
extern cvar_t *crosshair;
extern cvar_t *scr_loading;
extern vrect_t scr_vrect; // position of render window
extern cvar_t *scr_width;
extern cvar_t *scr_height;
void SCR_AdjustSize( float *x, float *y, float *w, float *h );
void SCR_DrawPic( float x, float y, float width, float height, char *picname );
@ -87,7 +97,7 @@ void SCR_DrawFPS( void );
void SCR_DrawNet( void );
//
// cl_user.c
// cg_user.c
//
void CG_DrawCenterString( void );
void CG_CenterPrint( const char *str, int y, int charWidth );

View File

@ -1,46 +0,0 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// vid.h -- video driver defs
#ifndef VID_H
#define VID_H
typedef struct vrect_s
{
int x,y,width,height;
} vrect_t;
typedef struct
{
int width, height; // coordinates from main game
} viddef_t;
extern viddef_t viddef; // global video state
// Video module initialisation etc
void VID_Init (void);
void VID_InitRender(void);
void VID_FreeRender(void);
void VID_CheckChanges(void);
void VID_MenuInit( void );
void VID_MenuDraw( void );
const char *VID_MenuKey( int );
#endif//VID_H

View File

@ -735,7 +735,7 @@ void Cmd_AddCommand (const char *cmd_name, xcommand_t function, const char *cmd_
Cmd_RemoveCommand
============
*/
void Cmd_RemoveCommand (char *cmd_name)
void Cmd_RemoveCommand (const char *cmd_name)
{
cmd_function_t *cmd, **back;

View File

@ -801,7 +801,7 @@ int *leaf_list;
float *leaf_mins, *leaf_maxs;
int leaf_topnode;
void CM_BoxLeafnums_r (int nodenum)
void CM_BoxLeafnums_r( int nodenum )
{
cplane_t *plane;
cnode_t *node;
@ -838,7 +838,7 @@ void CM_BoxLeafnums_r (int nodenum)
}
}
int CM_BoxLeafnums_headnode (vec3_t mins, vec3_t maxs, int *list, int listsize, int headnode, int *topnode)
int CM_BoxLeafnums_headnode (vec3_t mins, vec3_t maxs, int *list, int listsize, int headnode, int *topnode)
{
leaf_list = list;
leaf_count = 0;
@ -856,10 +856,9 @@ int CM_BoxLeafnums_headnode (vec3_t mins, vec3_t maxs, int *list, int listsize,
return leaf_count;
}
int CM_BoxLeafnums (vec3_t mins, vec3_t maxs, int *list, int listsize, int *topnode)
int CM_BoxLeafnums(vec3_t mins, vec3_t maxs, int *list, int listsize, int *topnode)
{
return CM_BoxLeafnums_headnode (mins, maxs, list,
listsize, map_cmodels[0].headnode, topnode);
return CM_BoxLeafnums_headnode (mins, maxs, list, listsize, map_cmodels[0].headnode, topnode);
}

View File

@ -551,7 +551,7 @@ cvar_t *Cvar_Set2 (const char *var_name, const char *value, bool force)
var->string = copystring(value);
var->value = atof (var->string);
var->integer = atoi (var->string);
var->integer = atoi(var->string);
return var;
}

View File

@ -1549,11 +1549,11 @@ void Game_MenuInit( void )
s_game_menu.x = SCREEN_WIDTH * 0.50;
s_game_menu.nitems = 0;
s_easy_game_action.generic.type = MTYPE_ACTION;
s_easy_game_action.generic.flags = QMF_LEFT_JUSTIFY;
s_easy_game_action.generic.x = 0;
s_easy_game_action.generic.y = 0;
s_easy_game_action.generic.name = "easy";
s_easy_game_action.generic.type = MTYPE_ACTION;
s_easy_game_action.generic.flags = QMF_LEFT_JUSTIFY;
s_easy_game_action.generic.x = 0;
s_easy_game_action.generic.y = 0;
s_easy_game_action.generic.name = "easy";
s_easy_game_action.generic.callback = EasyGameFunc;
s_medium_game_action.generic.type = MTYPE_ACTION;
@ -1582,14 +1582,14 @@ void Game_MenuInit( void )
s_save_game_action.generic.type = MTYPE_ACTION;
s_save_game_action.generic.flags = QMF_LEFT_JUSTIFY;
s_save_game_action.generic.x = 0;
s_save_game_action.generic.y = 100;
s_save_game_action.generic.y = 96;
s_save_game_action.generic.name = "save game";
s_save_game_action.generic.callback = SaveGameFunc;
s_credits_action.generic.type = MTYPE_ACTION;
s_credits_action.generic.flags = QMF_LEFT_JUSTIFY;
s_credits_action.generic.x = 0;
s_credits_action.generic.y = 120;
s_credits_action.generic.y = 112;
s_credits_action.generic.name = "credits";
s_credits_action.generic.callback = CreditsFunc;
@ -1640,7 +1640,7 @@ static menuframework_s s_savegame_menu;
static menuframework_s s_loadgame_menu;
static menuaction_s s_loadgame_actions[MAX_SAVEGAMES];
char m_savestrings[MAX_SAVEGAMES][32];
char m_savestrings[MAX_SAVEGAMES][MAX_QPATH];
bool m_savevalid[MAX_SAVEGAMES];
void Create_Savestrings (void)
@ -1658,16 +1658,20 @@ void LoadGameCallback( void *self )
menuaction_s *a = ( menuaction_s * ) self;
if ( m_savevalid[ a->generic.localdata[0] ] )
Cbuf_AddText (va("load save%i\n", a->generic.localdata[0] ) );
Cbuf_AddText(va("load save%i\n", a->generic.localdata[0] ) );
M_ForceMenuOff ();
}
void LoadGame_MenuInit( void )
{
int i;
float x = (SCREEN_WIDTH / 2) - 120;
float y = (SCREEN_HEIGHT /2) - 58;
s_loadgame_menu.x = SCREEN_WIDTH / 2 - 120;
s_loadgame_menu.y = SCREEN_HEIGHT / 2 - 58;
SCR_AdjustSize( &x, &y, NULL, NULL );
s_loadgame_menu.x = x;
s_loadgame_menu.y = y;
s_loadgame_menu.nitems = 0;
Create_Savestrings();
@ -1680,9 +1684,9 @@ void LoadGame_MenuInit( void )
s_loadgame_actions[i].generic.callback = LoadGameCallback;
s_loadgame_actions[i].generic.x = 0;
s_loadgame_actions[i].generic.y = ( i ) * 10;
if (i>0) // separate from autosave
s_loadgame_actions[i].generic.y += 10;
s_loadgame_actions[i].generic.y = ( i ) * 17;
if (i > 0) // separate from autosave
s_loadgame_actions[i].generic.y += 17;
s_loadgame_actions[i].generic.type = MTYPE_ACTION;
Menu_AddItem( &s_loadgame_menu, &s_loadgame_actions[i] );
@ -1742,9 +1746,13 @@ void SaveGame_MenuDraw( void )
void SaveGame_MenuInit( void )
{
int i;
float x = (SCREEN_WIDTH / 2) - 120;
float y = (SCREEN_HEIGHT /2) - 58;
s_savegame_menu.x = SCREEN_WIDTH / 2 - 120;
s_savegame_menu.y = SCREEN_HEIGHT / 2 - 58;
SCR_AdjustSize( &x, &y, NULL, NULL );
s_savegame_menu.x = x;
s_savegame_menu.y = y;
s_savegame_menu.nitems = 0;
Create_Savestrings();
@ -1757,9 +1765,8 @@ void SaveGame_MenuInit( void )
s_savegame_actions[i].generic.flags = QMF_LEFT_JUSTIFY;
s_savegame_actions[i].generic.callback = SaveGameCallback;
s_savegame_actions[i].generic.x = 0;
s_savegame_actions[i].generic.y = ( i ) * 10;
s_savegame_actions[i].generic.y = ( i ) * 17;
s_savegame_actions[i].generic.type = MTYPE_ACTION;
Menu_AddItem( &s_savegame_menu, &s_savegame_actions[i] );
}
}
@ -3206,6 +3213,207 @@ void M_Menu_PlayerConfig_f (void)
M_PushMenu( PlayerConfig_MenuDraw, PlayerConfig_MenuKey );
}
/*
====================================================================
VIDEO CONFIG MENU
====================================================================
*/
static menuframework_s s_video_menu;
static menulist_s s_mode_list;
static menuslider_s s_brightness_slider;
static menulist_s s_fs_box;
static menulist_s s_finish_box;
static menuaction_s s_cancel_action;
static menuaction_s s_defaults_action;
extern cvar_t *r_fullscreen;
extern cvar_t *vid_gamma;
static cvar_t *gl_finish;
static void BrightnessCallback( void *s )
{
menuslider_s *slider = (menuslider_s *)s;
float gamma = (0.8 - ( slider->curvalue / 10.0 - 0.5 )) + 0.5;
Cvar_SetValue( "vid_gamma", gamma );
}
static void ResetDefaults( void *unused )
{
VID_MenuInit();
}
static void ApplyChanges( void *unused )
{
int needs_restart = 0;
if(s_fs_box.curvalue != r_fullscreen->value)
needs_restart++;
if(s_finish_box.curvalue != gl_finish->value)
needs_restart++;
if(s_mode_list.curvalue != Cvar_VariableValue( "r_mode" ))
needs_restart++;
Cvar_SetValue( "fullscreen", s_fs_box.curvalue );
Cvar_SetValue( "gl_finish", s_finish_box.curvalue );
Cvar_SetValue( "r_mode", s_mode_list.curvalue );
// restart render if needed
if(needs_restart) Cbuf_AddText("vid_restart\n");
M_ForceMenuOff();
}
static void CancelChanges( void *unused )
{
M_PopMenu();
}
/*
** VID_MenuInit
*/
void VID_MenuInit( void )
{
static const char *resolutions[] =
{
"[640 480 ]",
"[800 600 ]",
"[1024 768 ]",
0,
};
static const char *yesno_names[] =
{
"no",
"yes",
0,
};
if ( !gl_finish ) gl_finish = Cvar_Get( "gl_finish", "0", CVAR_ARCHIVE );
s_mode_list.curvalue = Cvar_VariableValue( "r_mode" );
s_video_menu.x = SCREEN_WIDTH * 0.50;
s_video_menu.y = SCREEN_HEIGHT / 2 - 58;
s_video_menu.nitems = 0;
s_mode_list.generic.type = MTYPE_SPINCONTROL;
s_mode_list.generic.name = "video mode";
s_mode_list.generic.x = 0;
s_mode_list.generic.y = 0;
s_mode_list.itemnames = resolutions;
s_brightness_slider.generic.type = MTYPE_SLIDER;
s_brightness_slider.generic.x = 0;
s_brightness_slider.generic.y = 10;
s_brightness_slider.generic.name = "brightness";
s_brightness_slider.generic.callback = BrightnessCallback;
s_brightness_slider.minvalue = 5;
s_brightness_slider.maxvalue = 13;
s_brightness_slider.curvalue = ( 1.3 - vid_gamma->value + 0.5 ) * 10;
s_fs_box.generic.type = MTYPE_SPINCONTROL;
s_fs_box.generic.x = 0;
s_fs_box.generic.y = 20;
s_fs_box.generic.name = "fullscreen";
s_fs_box.itemnames = yesno_names;
s_fs_box.curvalue = r_fullscreen->value;
s_finish_box.generic.type = MTYPE_SPINCONTROL;
s_finish_box.generic.x = 0;
s_finish_box.generic.y = 30;
s_finish_box.generic.name = "sync every frame";
s_finish_box.curvalue = gl_finish->value;
s_finish_box.itemnames = yesno_names;
s_defaults_action.generic.type = MTYPE_ACTION;
s_defaults_action.generic.name = "reset to defaults";
s_defaults_action.generic.x = 0;
s_defaults_action.generic.y = 50;
s_defaults_action.generic.callback = ResetDefaults;
s_cancel_action.generic.type = MTYPE_ACTION;
s_cancel_action.generic.name = "cancel";
s_cancel_action.generic.x = 0;
s_cancel_action.generic.y = 60;
s_cancel_action.generic.callback = CancelChanges;
Menu_AddItem( &s_video_menu, ( void * ) &s_mode_list );
Menu_AddItem( &s_video_menu, ( void * ) &s_brightness_slider );
Menu_AddItem( &s_video_menu, ( void * ) &s_fs_box );
Menu_AddItem( &s_video_menu, ( void * ) &s_finish_box );
Menu_AddItem( &s_video_menu, ( void * ) &s_defaults_action );
Menu_AddItem( &s_video_menu, ( void * ) &s_cancel_action );
Menu_Center( &s_video_menu );
s_video_menu.x -= 8;
}
/*
================
VID_MenuDraw
================
*/
void VID_MenuDraw (void)
{
int w, h;
// draw the banner
re->DrawGetPicSize( &w, &h, "menu/m_banner_video" );
SCR_DrawPic( SCREEN_WIDTH / 2 - w / 2, SCREEN_HEIGHT /2 - 110, -1, -1, "menu/m_banner_video" );
// move cursor to a reasonable starting position
Menu_AdjustCursor( &s_video_menu, 1 );
// draw the menu
Menu_Draw( &s_video_menu );
}
/*
================
VID_MenuKey
================
*/
const char *VID_MenuKey( int key )
{
menuframework_s *m = &s_video_menu;
static const char *sound = "misc/menu1.wav";
switch ( key )
{
case K_ESCAPE:
ApplyChanges( 0 );
return NULL;
case K_KP_UPARROW:
case K_UPARROW:
m->cursor--;
Menu_AdjustCursor( m, -1 );
break;
case K_KP_DOWNARROW:
case K_DOWNARROW:
m->cursor++;
Menu_AdjustCursor( m, 1 );
break;
case K_KP_LEFTARROW:
case K_LEFTARROW:
Menu_SlideItem( m, -1 );
break;
case K_KP_RIGHTARROW:
case K_RIGHTARROW:
Menu_SlideItem( m, 1 );
break;
case K_KP_ENTER:
case K_ENTER:
if( !Menu_SelectItem( m ))
ApplyChanges( NULL );
break;
}
return sound;
}
/*
=======================================================================

View File

@ -522,7 +522,4 @@ void Netchan_OutOfBandPrint (int net_socket, netadr_t adr, char *format, ...);
bool Netchan_Process (netchan_t *chan, sizebuf_t *msg);
bool Netchan_CanReliable (netchan_t *chan);
void IN_Activate( bool active );
void IN_MouseEvent( int mstate );
#endif//NET_MSG_H

View File

@ -1029,7 +1029,7 @@ PM_ClampAngles
void PM_ClampAngles (void)
{
short temp;
int i;
int i;
if (pm->s.pm_flags & PMF_TIME_TELEPORT)
{
@ -1040,12 +1040,11 @@ void PM_ClampAngles (void)
else
{
// circularly clamp the angles with deltas
for (i=0 ; i<3 ; i++)
for (i = 0; i < 3; i++)
{
temp = pm->cmd.angles[i] + pm->s.delta_angles[i];
pm->viewangles[i] = SHORT2ANGLE(temp);
}
// don't let the player look up or down more than 90 degrees
if (pm->viewangles[PITCH] > 89 && pm->viewangles[PITCH] < 180)
pm->viewangles[PITCH] = 89;

View File

@ -296,11 +296,11 @@ void PRVM_ED_ClearEdict (edict_t *e);
void PRVM_PrintFunctionStatements (const char *name);
void PRVM_ED_Print(edict_t *ed);
void PRVM_ED_Write (file_t *f, edict_t *ed);
void PRVM_ED_Write (vfile_t *f, edict_t *ed);
char *PRVM_ED_Info(edict_t *ent);
const char *PRVM_ED_ParseEdict (const char *data, edict_t *ent);
void PRVM_ED_WriteGlobals (file_t *f);
void PRVM_ED_WriteGlobals (vfile_t *f);
void PRVM_ED_ParseGlobals (const char *data);
void PRVM_ED_LoadFromFile (const char *data);

View File

@ -38,9 +38,6 @@ static void SpinControl_DoSlide( menulist_s *s, int dir );
#define RCOLUMN_OFFSET 16
#define LCOLUMN_OFFSET -16
extern render_exp_t *re;
extern viddef_t viddef;
void Action_DoEnter( menuaction_s *a )
{
if ( a->generic.callback )

View File

@ -667,7 +667,7 @@ PRVM_ED_Write
For savegames
=============
*/
void PRVM_ED_Write (file_t *f, edict_t *ed)
void PRVM_ED_Write(vfile_t *f, edict_t *ed)
{
ddef_t *d;
int *v;
@ -675,15 +675,15 @@ void PRVM_ED_Write (file_t *f, edict_t *ed)
const char *name;
int type;
FS_Print(f, "{\n");
VFS_Print(f, "{\n");
if (ed->priv.ed->free)
{
FS_Print(f, "}\n");
VFS_Print(f, "}\n");
return;
}
for (i=1 ; i<prog->progs->numfielddefs ; i++)
for (i = 1; i < prog->progs->numfielddefs; i++)
{
d = &prog->fielddefs[i];
name = PRVM_GetString(d->s_name);
@ -692,19 +692,17 @@ void PRVM_ED_Write (file_t *f, edict_t *ed)
v = (int *)((char *)ed->progs.vp + d->ofs*4);
// if the value is still all 0, skip the field
// if the value is still all 0, skip the field
type = d->type & ~DEF_SAVEGLOBAL;
for (j=0 ; j<prvm_type_size[type] ; j++)
if (v[j])
break;
for (j = 0; j < prvm_type_size[type]; j++)
if(v[j]) break;
if (j == prvm_type_size[type])
continue;
FS_Printf(f,"\"%s\" ",name);
FS_Printf(f,"\"%s\"\n", PRVM_UglyValueString((etype_t)d->type, (prvm_eval_t *)v));
VFS_Printf(f,"\"%s\" ",name);
VFS_Printf(f,"\"%s\"\n", PRVM_UglyValueString((etype_t)d->type, (prvm_eval_t *)v));
}
FS_Print(f, "}\n");
VFS_Print(f, "}\n");
}
void PRVM_ED_PrintNum (int ent)
@ -825,25 +823,23 @@ void PRVM_ED_Count_f (void)
FIXME: need to tag constants, doesn't really work
==============================================================================
*/
/*
=============
PRVM_ED_WriteGlobals
=============
*/
void PRVM_ED_WriteGlobals (file_t *f)
void PRVM_ED_WriteGlobals( vfile_t *f )
{
ddef_t *def;
int i;
const char *name;
int type;
const char *name;
int i, type;
FS_Print(f,"{\n");
for (i=0 ; i<prog->progs->numglobaldefs ; i++)
VFS_Print(f,"{\n");
for (i = 0; i < prog->progs->numglobaldefs; i++)
{
def = &prog->globaldefs[i];
type = def->type;
if ( !(def->type & DEF_SAVEGLOBAL) )
if(!(def->type & DEF_SAVEGLOBAL) )
continue;
type &= ~DEF_SAVEGLOBAL;
@ -851,10 +847,10 @@ void PRVM_ED_WriteGlobals (file_t *f)
continue;
name = PRVM_GetString(def->s_name);
FS_Printf(f,"\"%s\" ", name);
FS_Printf(f,"\"%s\"\n", PRVM_UglyValueString((etype_t)type, (prvm_eval_t *)&prog->globals.gp[def->ofs]));
VFS_Printf(f,"\"%s\" ", name);
VFS_Printf(f,"\"%s\"\n", PRVM_UglyValueString((etype_t)type, (prvm_eval_t *)&prog->globals.gp[def->ofs]));
}
FS_Print(f,"}\n");
VFS_Print(f,"}\n");
}
/*
@ -871,18 +867,20 @@ void PRVM_ED_ParseGlobals (const char *data)
{
// parse key
if (!Com_ParseToken(&data))
PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace");
if (com_token[0] == '}')
break;
PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace\n");
if (com_token[0] == '}') break;
if (com_token[0] == '{') continue;
strncpy (keyname, com_token, sizeof(keyname));
Msg("com_token %s\n", keyname );
// parse value
if (!Com_ParseToken(&data))
PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace");
PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace\n");
if (com_token[0] == '}')
PRVM_ERROR ("PRVM_ED_ParseGlobals: closing brace without data");
PRVM_ERROR ("PRVM_ED_ParseGlobals: closing brace without data\n");
key = PRVM_ED_FindGlobal (keyname);
if (!key)
@ -892,7 +890,7 @@ void PRVM_ED_ParseGlobals (const char *data)
}
if (!PRVM_ED_ParseEpair(NULL, key, com_token))
PRVM_ERROR ("PRVM_ED_ParseGlobals: parse error");
PRVM_ERROR ("PRVM_ED_ParseGlobals: parse error\n");
}
}
@ -1047,20 +1045,20 @@ Used for initial level load and for savegames.
*/
const char *PRVM_ED_ParseEdict (const char *data, edict_t *ent)
{
ddef_t *key;
bool init, newline, anglehack;
char keyname[256];
size_t n;
ddef_t *key;
bool init, newline, anglehack;
char keyname[256];
size_t n;
init = false;
// go through all the dictionary pairs
while (1)
while( 1 )
{
// parse key
if (!Com_ParseToken(&data))
PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
if(!Com_ParseToken(&data)) PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
// just format console messages
newline = (com_token[0] == '}') ? true : false;
if(!newline) MsgDev(D_NOTE, "Key: \"%s\"", com_token);
else break;
@ -1074,35 +1072,30 @@ const char *PRVM_ED_ParseEdict (const char *data, edict_t *ent)
}
else anglehack = false;
strncpy (keyname, com_token, sizeof(keyname));
std.strncpy (keyname, com_token, sizeof(keyname));
// another hack to fix keynames with trailing spaces
n = strlen(keyname);
while (n && keyname[n-1] == ' ')
n = std.strlen(keyname);
while(n && keyname[n-1] == ' ')
{
keyname[n-1] = 0;
n--;
}
// parse value
if (!Com_ParseToken(&data))
PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
if (!Com_ParseToken(&data)) PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
MsgDev(D_NOTE, " \"%s\"\n", com_token);
if (com_token[0] == '}')
PRVM_ERROR ("PRVM_ED_ParseEdict: closing brace without data");
if(com_token[0] == '}') PRVM_ERROR ("PRVM_ED_ParseEdict: closing brace without data");
init = true;
// ignore attempts to set key "" (this problem occurs in nehahra neh1m8.bsp)
if (!keyname[0])
continue;
if (!keyname[0]) continue;
// keynames with a leading underscore are used for utility comments,
// and are immediately discarded by quake
if (keyname[0] == '_') continue;
key = PRVM_ED_FindField (keyname);
key = PRVM_ED_FindField( keyname );
if (!key)
{
MsgDev(D_WARN, "%s: '%s' is not a field\n", PRVM_NAME, keyname);
@ -1112,16 +1105,13 @@ const char *PRVM_ED_ParseEdict (const char *data, edict_t *ent)
if (anglehack)
{
char temp[32];
strncpy (temp, com_token, sizeof(temp));
sprintf (com_token, "0 %s 0", temp);
std.strncpy( temp, com_token, sizeof(temp));
std.sprintf( com_token, "0 %s 0", temp );
}
if (!PRVM_ED_ParseEpair(ent, key, com_token))
PRVM_ERROR ("PRVM_ED_ParseEdict: parse error");
if(!PRVM_ED_ParseEpair(ent, key, com_token)) PRVM_ERROR ("PRVM_ED_ParseEdict: parse error");
}
if (!init) ent->priv.ed->free = true;
if(!init) ent->priv.ed->free = true;
return data;
}
@ -1171,7 +1161,7 @@ void PRVM_ED_LoadFromFile (const char *data)
else ent = PRVM_ED_Alloc();
// HACKHACK: clear it
if (ent != prog->edicts) memset (ent->progs.vp, 0, prog->progs->entityfields * 4);
if (ent != prog->edicts) memset(ent->progs.vp, 0, prog->progs->entityfields * 4);
data = PRVM_ED_ParseEdict (data, ent);
parsed++;
@ -1219,10 +1209,8 @@ void PRVM_ED_LoadFromFile (const char *data)
}
spawned++;
if (ent->priv.ed->free)
died++;
if (ent->priv.ed->free) died++;
}
MsgDev(D_INFO, "%s: %i new entities parsed, %i new inhibited, %i (%i new) spawned (whereas %i removed self, %i stayed)\n", PRVM_NAME, parsed, inhibited, prog->num_edicts, spawned, died, spawned - died);
}

View File

@ -298,10 +298,6 @@ SOURCE=.\system.c
# End Source File
# Begin Source File
SOURCE=.\vid_menu.c
# End Source File
# Begin Source File
SOURCE=.\common\vm_cmds.c
# End Source File
# Begin Source File
@ -370,10 +366,6 @@ SOURCE=.\sound.h
# End Source File
# Begin Source File
SOURCE=.\screen\vid.h
# End Source File
# Begin Source File
SOURCE=.\common\vm_cmds.h
# End Source File
# End Group

View File

@ -81,8 +81,6 @@ typedef struct host_parm_s
} host_parm_t;
stdlib_api_t Host_GetStdio( bool crash_on_error );
/*
===========================================
memory manager
@ -136,6 +134,8 @@ void Sys_Error( const char *msg, ... );
void Sys_SendKeyEvents( void );
// mouse support
void M_Activate( void );
void M_Event( int mstate );
#define WM_MOUSEWHEEL (WM_MOUSELAST + 1) // message that will be supported by the OS
extern int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
@ -210,7 +210,7 @@ char *Cmd_Args( void );
char *Cmd_Argv( int arg );
void Cmd_Init( int argc, char **argv );
void Cmd_AddCommand(const char *cmd_name, xcommand_t function, const char *cmd_desc);
void Cmd_RemoveCommand (char *cmd_name);
void Cmd_RemoveCommand(const char *cmd_name);
bool Cmd_Exists (const char *cmd_name);
void Cmd_CommandCompletion( void(*callback)(const char *s, const char *m));
bool Cmd_GetMapList( const char *s, char *completedname, int length );

View File

@ -11,15 +11,12 @@
physic_exp_t *Phys;
render_exp_t *re;
host_parm_t host; // host parms
stdlib_api_t std;
stdlib_api_t std, newstd;
byte *zonepool;
int ActiveApp;
bool Minimized;
char *buildstring = __TIME__ " " __DATE__;
viddef_t viddef;
void Key_Init (void);
//void Key_Init (void);
dll_info_t physic_dll = { "physic.dll", NULL, "CreateAPI", NULL, NULL, true, sizeof(physic_exp_t) };
dll_info_t render_dll = { "render.dll", NULL, "CreateAPI", NULL, NULL, true, sizeof(render_exp_t) };
@ -27,13 +24,12 @@ dll_info_t render_dll = { "render.dll", NULL, "CreateAPI", NULL, NULL, true, siz
cvar_t *timescale;
cvar_t *fixedtime;
cvar_t *dedicated;
cvar_t *host_serverstate;
cvar_t *host_frametime;
cvar_t *r_fullscreen;
cvar_t *vid_gamma;
cvar_t *r_xpos; // X coordinate of window position
cvar_t *r_ypos; // Y coordinate of window position
cvar_t *r_fullscreen;
/*
=======
@ -85,26 +81,25 @@ static int Host_MapKey( int key )
}
}
stdlib_api_t Host_GetStdio( bool crash_on_error )
{
static stdlib_api_t io;
io = std;
// overload some funcs
io.print = Host_Print;
io.printf = Host_Printf;
io.dprintf = Host_DPrintf;
io.wprintf = Host_DWarnf;
if(crash_on_error) io.error = Sys_Error;
else io.error = Host_Error;
return io;
}
void Host_InitCommon( uint funcname, int argc, char **argv )
{
newstd = std;
// overload some funcs
newstd.print = Host_Print;
newstd.printf = Host_Printf;
newstd.dprintf = Host_DPrintf;
newstd.wprintf = Host_DWarnf;
newstd.Com_AddCommand = Cmd_AddCommand;
newstd.Com_DelCommand = Cmd_RemoveCommand;
newstd.Com_Argc = Cmd_Argc;
newstd.Com_Argv = Cmd_Argv;
newstd.Com_AddText = Cbuf_AddText;
newstd.Com_GetCvar = _Cvar_Get;
newstd.Com_CvarSetValue = Cvar_SetValue;
newstd.Com_CvarSetString = Cvar_Set;
newstd.error = Host_Error;
// TODO: init basedir here
FS_LoadGameInfo("gameinfo.txt");
zonepool = Mem_AllocPool("Zone Engine");
@ -119,7 +114,6 @@ void Host_InitPhysic( void )
{
static physic_imp_t pi;
launch_t CreatePhysic;
stdlib_api_t io = Host_GetStdio( false );
// phys callback
pi.api_size = sizeof(physic_imp_t);
@ -128,7 +122,7 @@ void Host_InitPhysic( void )
Sys_LoadLibrary( &physic_dll );
CreatePhysic = (void *)physic_dll.main;
Phys = CreatePhysic( &io, &pi );
Phys = CreatePhysic( &newstd, &pi );
Phys->Init();
}
@ -143,73 +137,21 @@ void Host_FreePhysic( void )
Sys_FreeLibrary( &physic_dll );
}
typedef struct vidmode_s
{
const char *description;
int width, height;
int mode;
} vidmode_t;
vidmode_t vid_modes[] =
{
{ "Mode 0: 640x480", 640, 480, 1 },
{ "Mode 1: 800x600", 800, 600, 2 },
{ "Mode 2: 1024x768", 1024, 768, 3 },
{ "Mode 3: 1280x960", 1280, 960, 4 },
{ "Mode 4: 1280x1024", 1280, 1024, 5 },
{ "Mode 5: 1600x1200", 1600, 1200, 6 },
{ "Mode 6: 2048x1536", 2048, 1536, 7 }
};
bool VID_GetModeInfo( int *width, int *height, int mode )
{
if ( mode < 0 || mode >= VID_NUM_MODES )
return false;
*width = vid_modes[mode].width;
*height = vid_modes[mode].height;
return true;
}
void VID_NewWindow ( int width, int height)
{
viddef.width = width;
viddef.height = height;
cl.force_refdef = true; // can't use a paused refdef
}
void Host_InitRender( void )
{
static render_imp_t ri;
stdlib_api_t io = Host_GetStdio( false );
launch_t CreateRender;
ri.api_size = sizeof(render_imp_t);
// console interaction
ri.Cmd_AddCommand = Cmd_AddCommand;
ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
ri.Cmd_Argc = Cmd_Argc;
ri.Cmd_Argv = Cmd_Argv;
ri.Cmd_ExecuteText = Cbuf_ExecuteText;
ri.Cvar_Get = _Cvar_Get;
ri.Cvar_Set = Cvar_Set;
ri.Cvar_SetValue = Cvar_SetValue;
// studio callbacks
ri.StudioEvent = CL_StudioEvent;
ri.ShowCollision = Phys->ShowCollision;
ri.Vid_GetModeInfo = VID_GetModeInfo;
ri.Vid_MenuInit = VID_MenuInit;
ri.Vid_NewWindow = VID_NewWindow;
Sys_LoadLibrary( &render_dll );
CreateRender = (void *)render_dll.main;
re = CreateRender( &io, &ri );
re = CreateRender( &newstd, &ri );
if(!re->Init(GetModuleHandle(NULL), Host_WndProc ))
Sys_Error("VID_InitRender: can't init render.dll\nUpdate your opengl drivers\n");
@ -283,30 +225,14 @@ VID_Init
*/
void VID_Init( void )
{
scr_width = Cvar_Get("width", "640", 0 );
scr_height = Cvar_Get("height", "480", 0 );
vid_gamma = Cvar_Get( "vid_gamma", "1", CVAR_ARCHIVE );
Cmd_AddCommand ("vid_restart", Host_VidRestart_f, "restarts video system" );
Host_InitRender();
}
/*
==================
VID_AppActivate
==================
*/
void VID_AppActivate(BOOL fActive, BOOL minimize)
{
Minimized = minimize;
Key_ClearStates(); // FIXME!!!
if (fActive && !Minimized ) ActiveApp = true;
else ActiveApp = false;
if (!ActiveApp ) IN_Activate( false );
else IN_Activate( true );
}
/*
=================
Host_Frame
@ -316,7 +242,7 @@ void Host_Frame( double time )
{
char *s;
if (setjmp(host.abortframe)) return;
if(setjmp(host.abortframe)) return;
rand(); // keep the random time dependent
@ -330,9 +256,9 @@ void Host_Frame( double time )
Cbuf_Execute();
// if at a full screen console, don't update unless needed
if (Minimized || host.type == HOST_DEDICATED )
if( host.state != HOST_FRAME || host.type == HOST_DEDICATED )
{
Sys_Sleep (1);
Sys_Sleep( 20 );
}
SV_Frame (time);
@ -343,45 +269,34 @@ void Host_Frame( double time )
/*
====================
MainWndProc
Host_WndProc
main window procedure
====================
*/
long _stdcall Host_WndProc( HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
{
int i, zDelta, temp = 0;
int temp = 0;
switch (uMsg)
{
case WM_MOUSEWHEEL:
//if(m_mouse->integer != 1 || (!r_fullscreen->integer && (cls.key_dest == key_console)))
if((short)HIWORD(wParam) > 0)
{
zDelta = (short)HIWORD( wParam ) / 120;
if( zDelta > 0 )
{
for(i = 0; i < zDelta; i++)
{
Key_Event( K_MWHEELUP, true, host.sv_timer );
Key_Event( K_MWHEELUP, false, host.sv_timer );
}
}
else
{
for(i = 0; i < -zDelta; i++)
{
Key_Event( K_MWHEELDOWN, true, host.sv_timer );
Key_Event( K_MWHEELDOWN, false, host.sv_timer );
}
}
return 0;
Key_Event( K_MWHEELUP, true, host.sv_timer );
Key_Event( K_MWHEELUP, false, host.sv_timer );
}
else
{
Key_Event( K_MWHEELDOWN, true, host.sv_timer );
Key_Event( K_MWHEELDOWN, false, host.sv_timer );
}
break;
case WM_CREATE:
host.hWnd = hWnd;
r_xpos = Cvar_Get ("r_xpos", "3", CVAR_ARCHIVE );
r_ypos = Cvar_Get ("r_ypos", "22", CVAR_ARCHIVE );
r_fullscreen = Cvar_Get ("r_fullscreen", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_xpos = Cvar_Get("r_xpos", "3", CVAR_ARCHIVE );
r_ypos = Cvar_Get("r_ypos", "22", CVAR_ARCHIVE );
r_fullscreen = Cvar_Get("fullscreen", "0", CVAR_ARCHIVE | CVAR_LATCH );
break;
case WM_DESTROY:
host.hWnd = NULL;
@ -390,9 +305,23 @@ long _stdcall Host_WndProc( HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
Cbuf_ExecuteText( EXEC_APPEND, "quit" );
break;
case WM_ACTIVATE:
VID_AppActivate(LOWORD(wParam) != WA_INACTIVE, (BOOL) HIWORD(wParam));
if(LOWORD(wParam) != WA_INACTIVE && HIWORD(wParam)) host.state = HOST_SLEEP;
else if(LOWORD(wParam) == WA_INACTIVE) host.state = HOST_NOFOCUS;
else host.state = HOST_FRAME;
Key_ClearStates(); // FIXME!!!
SNDDMA_Activate();
if( render_dll.link ) re->AppActivate( LOWORD(wParam) != WA_INACTIVE);
if( host.state == HOST_FRAME )
{
M_Activate();
SetForegroundWindow( hWnd );
ShowWindow( hWnd, SW_RESTORE );
}
else if( r_fullscreen->integer )
{
ShowWindow( hWnd, SW_MINIMIZE );
}
break;
case WM_MOVE:
if (!r_fullscreen->integer )
@ -412,7 +341,7 @@ long _stdcall Host_WndProc( HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
Cvar_SetValue( "r_ypos", yPos + r.top);
r_xpos->modified = false;
r_ypos->modified = false;
if (ActiveApp) IN_Activate( true );
M_Activate();
}
break;
case WM_LBUTTONDOWN:
@ -425,15 +354,15 @@ long _stdcall Host_WndProc( HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
if(wParam & MK_LBUTTON) temp |= 1;
if(wParam & MK_RBUTTON) temp |= 2;
if(wParam & MK_MBUTTON) temp |= 4;
IN_MouseEvent( temp );
M_Event( temp );
break;
case WM_SYSCOMMAND:
if( wParam == SC_SCREENSAVE ) return 0;
break;
case WM_SYSKEYDOWN:
if( wParam == 13 )
if( wParam == 13 && r_fullscreen)
{
if( r_fullscreen ) Cvar_SetValue( "r_fullscreen", !r_fullscreen->value );
Cvar_SetValue( "fullscreen", !r_fullscreen->value );
return 0;
}
// intentional fallthrough

View File

@ -1,41 +0,0 @@
//=======================================================================
// Copyright XashXT Group 2007 ©
// savefile.h - game save file
//=======================================================================
#ifndef SAVEFILE_H
#define SAVEFILE_H
/*
==============================================================================
SAVE FILE
==============================================================================
*/
//header
#define SAVE_VERSION 2
#define IDSAVEHEADER (('E'<<24)+('V'<<16)+('A'<<8)+'S') // little-endian "SAVE"
#define LUMP_COMMENTS 0 // map comments
#define LUMP_CFGSTRING 1 // client info strings
#define LUMP_AREASTATE 2 // area portals state
#define LUMP_GAMELEVEL 3 // server.dll game_locals_t struct and players info
#define LUMP_MAPCMDS 4 // map commands
#define LUMP_GAMECVARS 5 // contain game comment and all cvar state
#define LUMP_GAMELOCAL 6 // server.dll game_locals_t struct and players info
#define LUMP_SNAPSHOT 7 // dxt image snapshot
#define LUMP_HEADER 8 // header
typedef struct
{
int ident;
int version;
lump_t lumps[LUMP_HEADER];
} dsavehdr_t;
typedef struct
{
char name[64];
char value[64];
} dsavecvar_t;
#endif//SAVEFILE_H

View File

@ -5,7 +5,6 @@
#include "engine.h"
#include "server.h"
#include "savefile.h"
/*
====================

View File

@ -5,9 +5,6 @@
#ifndef SV_EDICT_H
#define SV_EDICT_H
// game.h -- game dll information visible to server
#include "savefile.h"
#define MAX_ENT_CLUSTERS 16
#define AI_FLY (1<<0) // monster is flying

View File

@ -356,8 +356,8 @@ void SV_FatPVS (vec3_t org)
int leafs[64];
int i, j, count;
int longs;
byte *src;
vec3_t mins, maxs;
byte *src;
vec3_t mins, maxs;
for (i = 0; i < 3; i++)
{

View File

@ -123,22 +123,14 @@ SV_CheckForSavegame
*/
void SV_CheckForSavegame (char *savename )
{
char name[MAX_SYSPATH];
sv.loadgame = true; // predicting state
if(sv_noreload->value) return;
if(Cvar_VariableValue ("deathmatch")) return;
if(!savename) return;
sprintf (name, "save/%s", savename );
if(!FS_FileExists(name))
{
Msg("can't find %s\n", savename );
return;
}
if(sv_noreload->value) sv.loadgame = false;
if(Cvar_VariableValue("deathmatch")) sv.loadgame = false;
if(!savename) sv.loadgame = false;
if(!FS_FileExists(va("save/%s", savename )))
sv.loadgame = false;
SV_ClearWorld();
// get configstrings and areaportals
SV_ReadLevelFile ( savename );
}
@ -230,12 +222,15 @@ void SV_SpawnServer (char *server, char *savename, sv_state_t serverstate )
sv.state = ss_loading;
Host_SetServerState (sv.state);
// load and spawn all other entities
SV_SpawnEntities ( sv.name, CM_EntityString());
// check for a savegame
SV_CheckForSavegame( savename );
if(sv.loadgame) SV_ReadLevelFile( savename );
else SV_SpawnEntities ( sv.name, CM_EntityString());
// run two frames to allow everything to settle
SV_RunFrame ();
SV_RunFrame ();
SV_RunFrame();
SV_RunFrame();
// all precaches are complete
sv.state = serverstate;
@ -244,9 +239,6 @@ void SV_SpawnServer (char *server, char *savename, sv_state_t serverstate )
// create a baseline for more efficient communications
SV_CreateBaseline ();
// check for a savegame
SV_CheckForSavegame ( savename );
// set serverinfo variable
Cvar_FullSet ("mapname", sv.name, CVAR_SERVERINFO | CVAR_INIT);

View File

@ -3,10 +3,8 @@
// sv_save.c - server save files
//=======================================================================
#include "engine.h"
#include "server.h"
#include "savefile.h"
byte *sav_base;
@ -72,6 +70,48 @@ void SV_AddCStrLump( dsavehdr_t *hdr, file_t *f )
Z_Free( csbuffer ); // free memory
}
void SV_WriteGlobal( dsavehdr_t *hdr, file_t *f )
{
vfile_t *h = VFS_Open( f, "wz" );
lump_t *lump;
int len, pos;
lump = &hdr->lumps[LUMP_GAMESTATE];
lump->fileofs = LittleLong( FS_Tell(f));
SV_VM_Begin();
PRVM_ED_WriteGlobals( h );
SV_VM_End();
pos = VFS_Tell(h);
FS_Write(f, &pos, sizeof(int)); // first four bytes is real filelength
f = VFS_Close(h);
len = LittleLong(FS_Tell(f));
lump->filelen = LittleLong( len - lump->fileofs );
}
void SV_WriteLocals( dsavehdr_t *hdr, file_t *f )
{
vfile_t *h = VFS_Open( f, "wz" );
lump_t *lump;
int i, len, pos;
lump = &hdr->lumps[LUMP_GAMEENTS];
lump->fileofs = LittleLong( FS_Tell(f));
SV_VM_Begin();
for(i = 0; i < prog->num_edicts; i++)
{
PRVM_ED_Write(h, PRVM_EDICT_NUM(i));
}
SV_VM_End();
pos = VFS_Tell(h);
FS_Write(f, &pos, sizeof(int)); // first four bytes is real filelength
f = VFS_Close(h);
len = LittleLong(FS_Tell(f));
lump->filelen = LittleLong( len - lump->fileofs );
}
/*
=============
@ -120,10 +160,10 @@ void SV_WriteSaveFile( char *name )
SV_AddSaveLump( header, savfile, LUMP_COMMENTS, comment, sizeof(comment));
SV_AddCStrLump( header, savfile );
SV_AddSaveLump( header, savfile, LUMP_AREASTATE, portalopen, sizeof(portalopen));
//ge->WriteLump ( header, savfile, LUMP_GAMELEVEL, autosave );
SV_AddSaveLump( header, savfile, LUMP_MAPCMDS, svs.mapcmd, sizeof(svs.mapcmd));
SV_WriteGlobal( header, savfile );
SV_AddSaveLump( header, savfile, LUMP_MAPNAME, svs.mapcmd, sizeof(svs.mapcmd));
SV_AddCvarLump( header, savfile );
//ge->WriteLump ( header, savfile, LUMP_GAMELOCAL, autosave );
SV_WriteLocals( header, savfile );
// merge header
FS_Seek( savfile, 0, SEEK_SET );
@ -183,7 +223,7 @@ void Sav_LoadCfgString( lump_t *l )
in = (void *)(sav_base + l->fileofs);
if (l->filelen % sizeof(*in)) Host_Error("Sav_LoadCfgString: funny lump size\n" );
//unpack the cfg string data
// unpack the cfg string data
for(i = 0; i < MAX_CONFIGSTRINGS; i++)
{
pos = std.strunpack( in, pos, sv.configstrings[i] );
@ -204,6 +244,60 @@ void Sav_LoadAreaPortals( lump_t *l )
CM_FloodAreaConnections ();
}
void Sav_LoadGlobal( lump_t *l )
{
byte *in, *globals, *ptr;
int size, realsize;
in = (void *)(sav_base + l->fileofs);
if (l->filelen % sizeof(*in)) Host_Error("Sav_LoadGlobal: funny lump size\n" );
size = l->filelen / sizeof(*in);
realsize = LittleLong(((int *)in)[0]);
ptr = globals = Z_Malloc( realsize );
VFS_Unpack( in+4, size, &globals, realsize );
PRVM_ED_ParseGlobals( globals );
Mem_Free( ptr ); // free globals
}
void Sav_LoadLocals( lump_t *l )
{
byte *in, *ents, *ptr;
int size, realsize, entnum = 0;
in = (void *)(sav_base + l->fileofs);
if (l->filelen % sizeof(*in)) Host_Error("Sav_LoadLocals: funny lump size\n" );
size = l->filelen / sizeof(*in);
realsize = LittleLong(((int *)in)[0]);
ptr = ents = Z_Malloc( realsize );
VFS_Unpack( in + 4, size, &ents, realsize );
while(Com_ParseToken(&ents))
{
edict_t *ent;
if(com_token[0] == '{')
{
if (entnum >= MAX_EDICTS)
Host_Error("Sav_LoadLocals: too many edicts in save file\n" );
while(entnum >= prog->max_edicts) PRVM_MEM_IncreaseEdicts();
ent = PRVM_EDICT_NUM( entnum );
memset(ent->progs.sv, 0, prog->progs->entityfields * 4);
ent->priv.sv->free = false;
// parse an edict
PRVM_ED_ParseEdict(ents, ent);
// link it into the bsp tree
if (!ent->priv.sv->free) SV_LinkEdict( ent );
entnum++;
}
}
prog->num_edicts = entnum;
Mem_Free( ptr ); // free ents
}
/*
=============
SV_ReadSaveFile
@ -232,8 +326,7 @@ void SV_ReadSaveFile( char *name )
Sav_LoadCvars(&header->lumps[LUMP_GAMECVARS]);
SV_InitGame (); // start a new game fresh with new cvars
Sav_LoadMapCmds(&header->lumps[LUMP_MAPCMDS]);
//ge->ReadLump( sav_base, &header->lumps[LUMP_GAMELOCAL], LUMP_GAMELOCAL );
Sav_LoadMapCmds(&header->lumps[LUMP_MAPNAME]);
}
/*
@ -265,10 +358,10 @@ void SV_ReadLevelFile( char *name )
if (i != SAVE_VERSION) Host_Error("file %s from an older save version\n", path );
sav_base = (byte *)header;
Sav_LoadCfgString(&header->lumps[LUMP_CFGSTRING]);
Sav_LoadAreaPortals(&header->lumps[LUMP_AREASTATE]);
//ge->ReadLump( sav_base, &header->lumps[LUMP_GAMELEVEL], LUMP_GAMELEVEL );
Sav_LoadGlobal(&header->lumps[LUMP_GAMESTATE]);
Sav_LoadLocals(&header->lumps[LUMP_GAMEENTS]);
}
bool Menu_ReadComment( char *comment, int savenum )
@ -282,7 +375,7 @@ bool Menu_ReadComment( char *comment, int savenum )
if(!savfile)
{
strncpy( comment, "<EMPTY>", 32 );
strncpy( comment, "<empty>", MAX_QPATH );
return false;
}
@ -292,13 +385,13 @@ bool Menu_ReadComment( char *comment, int savenum )
if(id != IDSAVEHEADER || i != SAVE_VERSION)
{
strncpy( comment, "<CORRUPTED>", 32 );
strncpy( comment, "<corrupted>", MAX_QPATH );
return false;
}
sav_base = (byte *)header;
Sav_LoadComment(&header->lumps[LUMP_COMMENTS]);
std.strncpy( comment, svs.comment, 32 );
std.strncpy( comment, svs.comment, MAX_QPATH );
return true;
}

View File

@ -24,13 +24,17 @@ void SV_PutClientInServer (edict_t *ent)
int index;
gclient_t *client;
int i;
index = PRVM_NUM_FOR_EDICT(ent) - 1;
client = ent->priv.sv->client;
prog->globals.sv->time = sv.time;
prog->globals.sv->pev = PRVM_EDICT_TO_PROG(ent);
PRVM_ExecuteProgram (prog->globals.sv->PutClientInServer, "QC function PutClientInServer is missing");
prog->globals.sv->pev = PRVM_EDICT_TO_PROG( ent );
if(sv.loadgame)
{
}
else PRVM_ExecuteProgram (prog->globals.sv->PutClientInServer, "QC function PutClientInServer is missing");
ent->priv.sv->client = svs.gclients + index;
ent->priv.sv->free = false;
@ -46,18 +50,16 @@ void SV_PutClientInServer (edict_t *ent)
client->ps.fov = bound(1, client->ps.fov, 160);
client->ps.gunindex = SV_ModelIndex(PRVM_GetString(ent->progs.sv->weaponmodel));
// clear entity state values
ent->progs.sv->effects = 0;
ent->progs.sv->modelindex = MAX_MODELS - 1; // will use the skin specified model
ent->progs.sv->weaponmodel = MAX_MODELS - 1; // custom gun model
if(sv.loadgame)
{
}
else
{
ent->progs.sv->frame = 0;
ent->progs.sv->origin[2] += 1; // make sure off ground
}
// sknum is player num and weapon number
// weapon number will be added in changeweapon
ent->progs.sv->skin = PRVM_NUM_FOR_EDICT(ent) - 1;
ent->progs.sv->frame = 0;
ent->progs.sv->origin[2] += 1; // make sure off ground
VectorCopy (ent->progs.sv->origin, ent->progs.sv->old_origin);
VectorCopy(ent->progs.sv->origin, ent->progs.sv->old_origin);
// set the delta angle
for (i = 0; i < 3; i++)
@ -65,11 +67,17 @@ void SV_PutClientInServer (edict_t *ent)
client->ps.pmove.delta_angles[i] = ANGLE2SHORT(ent->progs.sv->angles[i]);
}
ent->progs.sv->angles[PITCH] = ent->progs.sv->angles[ROLL] = 0;
ent->progs.sv->angles[YAW] = ent->progs.sv->angles[YAW];
if(sv.loadgame)
{
}
else
{
ent->progs.sv->angles[PITCH] = ent->progs.sv->angles[ROLL] = 0;
ent->progs.sv->angles[YAW] = ent->progs.sv->angles[YAW];
}
VectorCopy(ent->progs.sv->angles, client->ps.viewangles);
VectorCopy (client->ps.viewangles, client->v_angle);
SV_LinkEdict(ent);
}
@ -114,7 +122,7 @@ void SV_SpawnEntities (char *mapname, char *entities)
ent->priv.sv->client = svs.gclients + i - 1; // make links
}
PRVM_ED_LoadFromFile ( entities );
PRVM_ED_LoadFromFile( entities );
prog->protect_world = true;// make world read-only
}

View File

@ -1,256 +0,0 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "client.h"
#include "qmenu.h"
extern cvar_t *r_fullscreen;
extern cvar_t *vid_gamma;
static cvar_t *gl_mode;
static cvar_t *gl_picmip;
static cvar_t *gl_ext_palettedtexture;
static cvar_t *gl_finish;
extern void M_ForceMenuOff( void );
/*
====================================================================
MENU INTERACTION
====================================================================
*/
static menuframework_s s_video_menu;
static menulist_s s_mode_list;
static menuslider_s s_tq_slider;
static menuslider_s s_brightness_slider;
static menulist_s s_fs_box;
static menulist_s s_stipple_box;
static menulist_s s_paletted_texture_box;
static menulist_s s_finish_box;
static menuaction_s s_cancel_action;
static menuaction_s s_defaults_action;
static void ScreenSizeCallback( void *s )
{
menuslider_s *slider = (menuslider_s *)s;
Cvar_SetValue( "viewsize", slider->curvalue * 10 );
}
static void BrightnessCallback( void *s )
{
menuslider_s *slider = (menuslider_s *)s;
float gamma = ( 0.8 - ( slider->curvalue / 10.0 - 0.5 ) ) + 0.5;
Cvar_SetValue( "vid_gamma", gamma );
}
static void ResetDefaults( void *unused )
{
VID_MenuInit();
}
static void ApplyChanges( void *unused )
{
Cvar_SetValue( "gl_picmip", 3 - s_tq_slider.curvalue );
Cvar_SetValue( "r_fullscreen", s_fs_box.curvalue );
Cvar_SetValue( "gl_ext_palettedtexture", s_paletted_texture_box.curvalue );
Cvar_SetValue( "gl_finish", s_finish_box.curvalue );
Cvar_SetValue( "gl_mode", s_mode_list.curvalue );
Cbuf_AddText("vid_restart\n"); // restart render
M_ForceMenuOff();
}
static void CancelChanges( void *unused )
{
extern void M_PopMenu( void );
M_PopMenu();
}
/*
** VID_MenuInit
*/
void VID_MenuInit( void )
{
static const char *resolutions[] =
{
"[640 480 ]",
"[800 600 ]",
"[1024 768 ]",
"[1280 960 ]",
"[1280 1024]",
"[1600 1200]",
"[2048 1536]",
0,
};
static const char *yesno_names[] =
{
"no",
"yes",
0,
};
if ( !gl_picmip ) gl_picmip = Cvar_Get( "gl_picmip", "0", 0 );
if ( !gl_mode ) gl_mode = Cvar_Get( "gl_mode", "3", 0 );
if ( !gl_finish ) gl_finish = Cvar_Get( "gl_finish", "0", CVAR_ARCHIVE );
if ( !gl_ext_palettedtexture ) gl_ext_palettedtexture = Cvar_Get( "gl_ext_palettedtexture", "1", CVAR_ARCHIVE );
s_mode_list.curvalue = gl_mode->value;
s_video_menu.x = viddef.width * 0.50;
s_video_menu.y = viddef.height / 2 - 58;
s_video_menu.nitems = 0;
s_mode_list.generic.type = MTYPE_SPINCONTROL;
s_mode_list.generic.name = "video mode";
s_mode_list.generic.x = 0;
s_mode_list.generic.y = 0;
s_mode_list.itemnames = resolutions;
s_brightness_slider.generic.type = MTYPE_SLIDER;
s_brightness_slider.generic.x = 0;
s_brightness_slider.generic.y = 10;
s_brightness_slider.generic.name = "brightness";
s_brightness_slider.generic.callback = BrightnessCallback;
s_brightness_slider.minvalue = 5;
s_brightness_slider.maxvalue = 13;
s_brightness_slider.curvalue = ( 1.3 - vid_gamma->value + 0.5 ) * 10;
s_fs_box.generic.type = MTYPE_SPINCONTROL;
s_fs_box.generic.x = 0;
s_fs_box.generic.y = 20;
s_fs_box.generic.name = "fullscreen";
s_fs_box.itemnames = yesno_names;
s_fs_box.curvalue = r_fullscreen->value;
s_tq_slider.generic.type = MTYPE_SLIDER;
s_tq_slider.generic.x = 0;
s_tq_slider.generic.y = 30;
s_tq_slider.generic.name = "texture quality";
s_tq_slider.minvalue = 0;
s_tq_slider.maxvalue = 3;
s_tq_slider.curvalue = 3 - gl_picmip->value;
s_paletted_texture_box.generic.type = MTYPE_SPINCONTROL;
s_paletted_texture_box.generic.x = 0;
s_paletted_texture_box.generic.y = 40;
s_paletted_texture_box.generic.name = "8-bit textures";
s_paletted_texture_box.itemnames = yesno_names;
s_paletted_texture_box.curvalue = gl_ext_palettedtexture->value;
s_finish_box.generic.type = MTYPE_SPINCONTROL;
s_finish_box.generic.x = 0;
s_finish_box.generic.y = 50;
s_finish_box.generic.name = "sync every frame";
s_finish_box.curvalue = gl_finish->value;
s_finish_box.itemnames = yesno_names;
s_defaults_action.generic.type = MTYPE_ACTION;
s_defaults_action.generic.name = "reset to defaults";
s_defaults_action.generic.x = 0;
s_defaults_action.generic.y = 70;
s_defaults_action.generic.callback = ResetDefaults;
s_cancel_action.generic.type = MTYPE_ACTION;
s_cancel_action.generic.name = "cancel";
s_cancel_action.generic.x = 0;
s_cancel_action.generic.y = 80;
s_cancel_action.generic.callback = CancelChanges;
Menu_AddItem( &s_video_menu, ( void * ) &s_mode_list );
Menu_AddItem( &s_video_menu, ( void * ) &s_brightness_slider );
Menu_AddItem( &s_video_menu, ( void * ) &s_fs_box );
Menu_AddItem( &s_video_menu, ( void * ) &s_tq_slider );
Menu_AddItem( &s_video_menu, ( void * ) &s_paletted_texture_box );
Menu_AddItem( &s_video_menu, ( void * ) &s_finish_box );
Menu_AddItem( &s_video_menu, ( void * ) &s_defaults_action );
Menu_AddItem( &s_video_menu, ( void * ) &s_cancel_action );
Menu_Center( &s_video_menu );
s_video_menu.x -= 8;
}
/*
================
VID_MenuDraw
================
*/
void VID_MenuDraw (void)
{
int w, h;
// draw the banner
re->DrawGetPicSize( &w, &h, "menu/m_banner_video" );
SCR_DrawPic( SCREEN_WIDTH / 2 - w / 2, SCREEN_HEIGHT /2 - 110, -1, -1, "menu/m_banner_video" );
// move cursor to a reasonable starting position
Menu_AdjustCursor( &s_video_menu, 1 );
// draw the menu
Menu_Draw( &s_video_menu );
}
/*
================
VID_MenuKey
================
*/
const char *VID_MenuKey( int key )
{
menuframework_s *m = &s_video_menu;
static const char *sound = "misc/menu1.wav";
switch ( key )
{
case K_ESCAPE:
ApplyChanges( 0 );
return NULL;
case K_KP_UPARROW:
case K_UPARROW:
m->cursor--;
Menu_AdjustCursor( m, -1 );
break;
case K_KP_DOWNARROW:
case K_DOWNARROW:
m->cursor++;
Menu_AdjustCursor( m, 1 );
break;
case K_KP_LEFTARROW:
case K_LEFTARROW:
Menu_SlideItem( m, -1 );
break;
case K_KP_RIGHTARROW:
case K_RIGHTARROW:
Menu_SlideItem( m, 1 );
break;
case K_KP_ENTER:
case K_ENTER:
if( !Menu_SelectItem( m ))
ApplyChanges( NULL );
break;
}
return sound;
}

880
launch/common/cmd.c Normal file
View File

@ -0,0 +1,880 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// cmd.c -- Quake script command processing module
#include "engine.h"
void Cmd_ForwardToServer (void);
//=============================================================================
#define MAX_CMD_BUFFER 16384
#define MAX_CMD_LINE 1024
typedef struct
{
byte *data;
int maxsize;
int cursize;
} cmd_t;
int cmd_wait;
cmd_t cmd_text;
byte cmd_text_buf[MAX_CMD_BUFFER];
char **fs_argv;
int fs_argc;
/*
=============================================================================
COMMAND BUFFER
=============================================================================
*/
/*
============
Cbuf_Init
============
*/
void Cbuf_Init (int argc, char **argv )
{
cmd_text.data = cmd_text_buf;
cmd_text.maxsize = MAX_CMD_BUFFER;
cmd_text.cursize = 0;
fs_argc = argc;
fs_argv = argv;
}
/*
============
Cbuf_AddText
Adds command text at the end of the buffer
============
*/
void Cbuf_AddText(const char *text)
{
int len;
len = strlen(text);
if (cmd_text.cursize + len >= cmd_text.maxsize)
{
MsgDev(D_WARN, "Cbuf_AddText: overflow\n");
return;
}
Mem_Copy(&cmd_text.data[cmd_text.cursize], (char *)text, len);
cmd_text.cursize += len;
}
/*
============
Cbuf_InsertText
Adds command text immediately after the current command
Adds a \n to the text
FIXME: actually change the command buffer to do less copying
============
*/
void Cbuf_InsertText (const char *text)
{
int i, len;
len = strlen( text ) + 1;
if ( len + cmd_text.cursize > cmd_text.maxsize )
{
MsgDev(D_WARN,"Cbuf_InsertText overflowed\n" );
return;
}
// move the existing command text
for( i = cmd_text.cursize - 1; i >= 0; i-- )
{
cmd_text.data[i + len] = cmd_text.data[i];
}
// copy the new text in
Mem_Copy( cmd_text.data, (char *)text, len - 1 );
cmd_text.data[ len - 1 ] = '\n'; // add a \n
cmd_text.cursize += len;
}
/*
============
Cbuf_ExecuteText
============
*/
void Cbuf_ExecuteText (int exec_when, const char *text)
{
switch (exec_when)
{
case EXEC_NOW:
if (text && strlen(text))
Cmd_ExecuteString(text);
else Cbuf_Execute();
break;
case EXEC_INSERT:
Cbuf_InsertText (text);
break;
case EXEC_APPEND:
Cbuf_AddText (text);
break;
default:
MsgWarn("Cbuf_ExecuteText: bad execute target\n");
break;
}
}
/*
============
Cbuf_Execute
============
*/
void Cbuf_Execute( void )
{
int i;
char *text;
char line[MAX_CMD_LINE];
int quotes;
while (cmd_text.cursize)
{
if( cmd_wait )
{
// skip out while text still remains in buffer, leaving it for next frame
cmd_wait--;
break;
}
// find a \n or ; line break
text = (char *)cmd_text.data;
quotes = 0;
for (i = 0; i < cmd_text.cursize; i++)
{
if (text[i] == '"') quotes++;
if ( !(quotes&1) && text[i] == ';')
break; // don't break if inside a quoted string
if (text[i] == '\n' || text[i] == '\r' ) break;
}
if( i >= (MAX_CMD_LINE - 1)) i = MAX_CMD_LINE - 1;
Mem_Copy (line, text, i);
line[i] = 0;
// delete the text from the command buffer and move remaining commands down
// this is necessary because commands (exec) can insert data at the
// beginning of the text buffer
if (i == cmd_text.cursize) cmd_text.cursize = 0;
else
{
i++;
cmd_text.cursize -= i;
memmove (text, text+i, cmd_text.cursize);
}
// execute the command line
Cmd_ExecuteString (line);
}
}
/*
==============================================================================
SCRIPT COMMANDS
==============================================================================
*/
/*
===============
Cmd_StuffCmds_f
Adds command line parameters as script statements
Commands lead with a +, and continue until a - or another +
quake +prog jctest.qp +cmd amlev1
quake -nosound +cmd amlev1
===============
*/
void Cmd_StuffCmds_f( void )
{
int i, j, l = 0;
char build[MAX_INPUTLINE]; // this is for all commandline options combined (and is bounds checked)
if(Cmd_Argc() != 1)
{
Msg("stuffcmds : execute command line parameters\n");
return;
}
// no reason to run the commandline arguments twice
if(host.stuffcmdsrun) return;
host.stuffcmdsrun = true;
build[0] = 0;
for (i = 0; i < fs_argc; i++)
{
if (fs_argv[i] && fs_argv[i][0] == '+' && (fs_argv[i][1] < '0' || fs_argv[i][1] > '9') && l + strlen(fs_argv[i]) - 1 <= sizeof(build) - 1)
{
j = 1;
while (fs_argv[i][j]) build[l++] = fs_argv[i][j++];
i++;
for ( ; i < fs_argc; i++)
{
if (!fs_argv[i]) continue;
if ((fs_argv[i][0] == '+' || fs_argv[i][0] == '-') && (fs_argv[i][1] < '0' || fs_argv[i][1] > '9'))
break;
if (l + strlen(fs_argv[i]) + 4 > sizeof(build) - 1)
break;
build[l++] = ' ';
if (strchr(fs_argv[i], ' ')) build[l++] = '\"';
for (j = 0; fs_argv[i][j]; j++) build[l++] = fs_argv[i][j];
if (strchr(fs_argv[i], ' ')) build[l++] = '\"';
}
build[l++] = '\n';
i--;
}
}
// now terminate the combined string and prepend it to the command buffer
// we already reserved space for the terminator
build[l++] = 0;
Cbuf_InsertText(build);
}
/*
============
Cmd_Wait_f
Causes execution of the remainder of the command buffer to be delayed until
next frame. This allows commands like:
bind g "cmd use rocket ; +attack ; wait ; -attack ; cmd use blaster"
============
*/
void Cmd_Wait_f (void)
{
if(Cmd_Argc() == 1) cmd_wait = 1;
else cmd_wait = atoi(Cmd_Argv( 1 ));
}
/*
===============
Cmd_Exec_f
===============
*/
void Cmd_Exec_f (void)
{
char *f, rcpath[MAX_QPATH];
int len;
if (Cmd_Argc () != 2)
{
Msg("exec <filename> : execute a script file\n");
return;
}
sprintf(rcpath, "scripts/config/%s", Cmd_Argv(1));
FS_DefaultExtension(rcpath, ".rc" ); // append as default
f = FS_LoadFile(rcpath, &len );
if (!f)
{
MsgWarn("couldn't exec %s\n", Cmd_Argv(1));
return;
}
MsgDev(D_INFO, "execing %s\n",Cmd_Argv(1));
Cbuf_InsertText(f);
Z_Free (f);
}
/*
===============
Cmd_Echo_f
Just prints the rest of the line to the console
===============
*/
void Cmd_Echo_f (void)
{
int i;
for(i = 1; i < Cmd_Argc(); i++)
Msg ("%s ",Cmd_Argv(i));
Msg ("\n");
}
/*
=====================================
Cmd_GetMapList
Prints or complete map filename
=====================================
*/
bool Cmd_GetMapList (const char *s, char *completedname, int length )
{
search_t *t;
file_t *f;
char message[MAX_QPATH];
char matchbuf[MAX_QPATH];
byte buf[MAX_SYSPATH]; // 1 kb
int i, nummaps;
t = FS_Search(va("maps/%s*.bsp", s), true );
if( !t ) return false;
FS_FileBase(t->filenames[0], matchbuf );
strncpy( completedname, matchbuf, length );
if(t->numfilenames == 1) return true;
for(i = 0, nummaps = 0; i < t->numfilenames; i++)
{
const char *data = NULL;
char *entities = NULL;
char entfilename[MAX_QPATH];
int ver = -1, lumpofs = 0, lumplen = 0;
const char *ext = FS_FileExtension( t->filenames[i] );
if( std.stricmp(ext, "bsp" )) continue;
strncpy(message, "^1error^7", sizeof(message));
f = FS_Open(t->filenames[i], "rb" );
if( f )
{
memset(buf, 0, 1024);
FS_Read(f, buf, 1024);
if(!memcmp(buf, "IBSP", 4))
{
dheader_t *header = (dheader_t *)buf;
ver = LittleLong(((int *)buf)[1]);
switch(ver)
{
case 38: // quake2 (xash)
case 46: // quake3
case 47: // return to castle wolfenstein
lumpofs = LittleLong(header->lumps[LUMP_ENTITIES].fileofs);
lumplen = LittleLong(header->lumps[LUMP_ENTITIES].filelen);
break;
}
}
else
{
lump_t ents; // quake1 entity lump
memcpy(&ents, buf + 4, sizeof(lump_t)); // skip first four bytes (version)
ver = LittleLong(((int *)buf)[0]);
switch( ver )
{
case 28: // quake 1 beta
case 29: // quake 1 regular
case 30: // Half-Life regular
lumpofs = LittleLong(ents.fileofs);
lumplen = LittleLong(ents.filelen);
break;
default:
ver = 0;
break;
}
}
std.strncpy(entfilename, t->filenames[i], sizeof(entfilename));
FS_StripExtension( entfilename );
FS_DefaultExtension( entfilename, ".ent" );
entities = (char *)FS_LoadFile(entfilename, NULL);
if( !entities && lumplen >= 10 )
{
FS_Seek(f, lumpofs, SEEK_SET);
entities = (char *)Z_Malloc(lumplen + 1);
FS_Read(f, entities, lumplen);
}
if( entities )
{
// if there are entities to parse, a missing message key just
// means there is no title, so clear the message string now
message[0] = 0;
data = entities;
while(Com_ParseToken(&data))
{
if(!strcmp(com_token, "{" )) continue;
else if(!strcmp(com_token, "}" )) break;
else if(!strcmp(com_token, "message" ))
{
// get the message contents
Com_ParseToken(&data);
strncpy(message, com_token, sizeof(message));
}
else if(!strcmp(com_token, "mapversion" ))
{
// get map version
Com_ParseToken(&data);
// old xash maps are Half-Life, so don't overwrite version
if(ver > 30) ver = atoi(com_token);
}
}
}
}
if( entities )Z_Free(entities);
if( f )FS_Close(f);
FS_FileBase(t->filenames[i], matchbuf );
switch(ver)
{
case 28: strncpy((char *)buf, "Quake1 beta", sizeof(buf)); break;
case 29: strncpy((char *)buf, "Quake1", sizeof(buf)); break;
case 30: strncpy((char *)buf, "Half-Life", sizeof(buf)); break;
case 38: strncpy((char *)buf, "Quake 2", sizeof(buf)); break;
case 46: strncpy((char *)buf, "Quake 3", sizeof(buf)); break;
case 47: strncpy((char *)buf, "RTCW", sizeof(buf)); break;
case 220: strncpy((char *)buf, "Xash 3D", sizeof(buf)); break;
default: strncpy((char *)buf, "??", sizeof(buf)); break;
}
Msg("%16s (%s) ^3%s^7\n", matchbuf, buf, message);
nummaps++;
}
Msg("\n^3 %i maps found.\n", nummaps );
Z_Free( t );
// cut shortestMatch to the amount common with s
for( i = 0; matchbuf[i]; i++ )
{
if(tolower(completedname[i]) != tolower(matchbuf[i]))
completedname[i] = 0;
}
return true;
}
/*
=====================================
Cmd_GetDemoList
Prints or complete demo filename
=====================================
*/
bool Cmd_GetDemoList (const char *s, char *completedname, int length )
{
search_t *t;
char matchbuf[MAX_QPATH];
int i, numdems;
t = FS_Search(va("demos/%s*.dem", s ), true);
if(!t) return false;
FS_FileBase(t->filenames[0], matchbuf );
if(completedname && length) strncpy( completedname, matchbuf, length );
if(t->numfilenames == 1) return true;
for(i = 0, numdems = 0; i < t->numfilenames; i++)
{
const char *ext = FS_FileExtension( t->filenames[i] );
if( std.stricmp(ext, "dem" )) continue;
FS_FileBase(t->filenames[i], matchbuf );
Msg("%16s\n", matchbuf );
numdems++;
}
Msg("\n^3 %i demos found.\n", numdems );
Z_Free(t);
// cut shortestMatch to the amount common with s
if(completedname && length)
{
for( i = 0; matchbuf[i]; i++ )
{
if(tolower(completedname[i]) != tolower(matchbuf[i]))
completedname[i] = 0;
}
}
return true;
}
/*
=====================================
Cmd_GetMovieList
Prints or complete movie filename
=====================================
*/
bool Cmd_GetMovieList (const char *s, char *completedname, int length )
{
search_t *t;
char matchbuf[MAX_QPATH];
int i, nummovies;
t = FS_Search(va("video/%s*.roq", s ), true);
if(!t) return false;
FS_FileBase(t->filenames[0], matchbuf );
if(completedname && length) strncpy( completedname, matchbuf, length );
if(t->numfilenames == 1) return true;
for(i = 0, nummovies = 0; i < t->numfilenames; i++)
{
const char *ext = FS_FileExtension( t->filenames[i] );
if( std.stricmp(ext, "roq" )) continue;
FS_FileBase(t->filenames[i], matchbuf );
Msg("%16s\n", matchbuf );
nummovies++;
}
Msg("\n^3 %i movies found.\n", nummovies );
Z_Free(t);
// cut shortestMatch to the amount common with s
if(completedname && length)
{
for( i = 0; matchbuf[i]; i++ )
{
if(tolower(completedname[i]) != tolower(matchbuf[i]))
completedname[i] = 0;
}
}
return true;
}
/*
=============================================================================
COMMAND EXECUTION
=============================================================================
*/
typedef struct cmd_function_s
{
struct cmd_function_s *next;
char *name;
char *desc;
xcommand_t function;
} cmd_function_t;
static int cmd_argc;
static char *cmd_argv[MAX_STRING_TOKENS];
static char cmd_tokenized[MAX_INPUTLINE+MAX_STRING_TOKENS]; // will have 0 bytes inserted
static cmd_function_t *cmd_functions; // possible commands to execute
/*
============
Cmd_Argc
============
*/
int Cmd_Argc (void)
{
return cmd_argc;
}
/*
============
Cmd_Argv
============
*/
char *Cmd_Argv (int arg)
{
if((uint)arg >= cmd_argc )
return "";
return cmd_argv[arg];
}
/*
============
Cmd_Args
Returns a single string containing argv(1) to argv(argc()-1)
============
*/
char *Cmd_Args (void)
{
static char cmd_args[MAX_STRING_CHARS];
int i;
cmd_args[0] = 0;
// build only for current call
for ( i = 1; i < cmd_argc; i++ )
{
strcat( cmd_args, cmd_argv[i] );
if ( i != cmd_argc-1 )
strcat( cmd_args, " " );
}
return cmd_args;
}
/*
============
Cmd_TokenizeString
Parses the given string into command line tokens.
The text is copied to a seperate buffer and 0 characters
are inserted in the apropriate place, The argv array
will point into this temporary buffer.
============
*/
void Cmd_TokenizeString (const char *text_in)
{
const char *text;
char *textOut;
cmd_argc = 0; // clear previous args
if(!text_in ) return;
text = text_in;
textOut = cmd_tokenized;
while( 1 )
{
// this is usually something malicious
if ( cmd_argc == MAX_STRING_TOKENS ) return;
while ( 1 )
{
// skip whitespace
while ( *text && *text <= ' ' ) text++;
if ( !*text ) return; // all tokens parsed
// skip // comments
if ( text[0] == '/' && text[1] == '/' ) return; // all tokens parsed
// skip /* */ comments
if ( text[0] == '/' && text[1] =='*' )
{
while(*text && ( text[0] != '*' || text[1] != '/' )) text++;
if ( !*text ) return; // all tokens parsed
text += 2;
}
else break; // we are ready to parse a token
}
// handle quoted strings
if ( *text == '"' )
{
cmd_argv[cmd_argc] = textOut;
cmd_argc++;
text++;
while ( *text && *text != '"' ) *textOut++ = *text++;
*textOut++ = 0;
if ( !*text ) return; // all tokens parsed
text++;
continue;
}
// regular token
cmd_argv[cmd_argc] = textOut;
cmd_argc++;
// skip until whitespace, quote, or command
while ( *text > ' ' )
{
if ( text[0] == '"' ) break;
if ( text[0] == '/' && text[1] == '/' ) break;
// skip /* */ comments
if ( text[0] == '/' && text[1] =='*' ) break;
*textOut++ = *text++;
}
*textOut++ = 0;
if( !*text ) return; // all tokens parsed
}
}
/*
============
Cmd_AddCommand
============
*/
void Cmd_AddCommand (const char *cmd_name, xcommand_t function, const char *cmd_desc)
{
cmd_function_t *cmd;
// fail if the command already exists
if(Cmd_Exists( cmd_name ))
{
MsgDev(D_INFO, "Cmd_AddCommand: %s already defined\n", cmd_name);
return;
}
// use a small malloc to avoid zone fragmentation
cmd = Z_Malloc (sizeof(cmd_function_t));
cmd->name = copystring( cmd_name );
cmd->desc = copystring( cmd_desc );
cmd->function = function;
cmd->next = cmd_functions;
cmd_functions = cmd;
}
/*
============
Cmd_RemoveCommand
============
*/
void Cmd_RemoveCommand (const char *cmd_name)
{
cmd_function_t *cmd, **back;
back = &cmd_functions;
while( 1 )
{
cmd = *back;
if (!cmd ) return;
if (!strcmp( cmd_name, cmd->name ))
{
*back = cmd->next;
if(cmd->name) Z_Free(cmd->name);
if(cmd->desc) Z_Free(cmd->desc);
Z_Free(cmd);
return;
}
back = &cmd->next;
}
}
/*
============
Cmd_CommandCompletion
============
*/
void Cmd_CommandCompletion( void(*callback)(const char *s, const char *m))
{
cmd_function_t *cmd;
for (cmd = cmd_functions; cmd; cmd = cmd->next)
callback( cmd->name, cmd->desc );
}
/*
============
Cmd_Exists
============
*/
bool Cmd_Exists (const char *cmd_name)
{
cmd_function_t *cmd;
for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
{
if (!strcmp (cmd_name,cmd->name))
return true;
}
return false;
}
/*
============
Cmd_ExecuteString
A complete command line has been parsed, so try to execute it
============
*/
void Cmd_ExecuteString( const char *text )
{
cmd_function_t *cmd, **prev;
// execute the command line
Cmd_TokenizeString( text );
if( !Cmd_Argc()) return; // no tokens
// check registered command functions
for ( prev = &cmd_functions; *prev; prev = &cmd->next )
{
cmd = *prev;
if(!stricmp( cmd_argv[0], cmd->name ))
{
// rearrange the links so that the command will be
// near the head of the list next time it is used
*prev = cmd->next;
cmd->next = cmd_functions;
cmd_functions = cmd;
// perform the action
if(!cmd->function )
{ // forward to server command
Cmd_ExecuteString(va("cmd %s", text));
}
else cmd->function();
return;
}
}
// check cvars
if(Cvar_Command()) return;
// send it as a server command if we are connected
Cmd_ForwardToServer();
}
/*
============
Cmd_List_f
============
*/
void Cmd_List_f (void)
{
cmd_function_t *cmd;
int i = 0;
char *match;
if(Cmd_Argc() > 1) match = Cmd_Argv( 1 );
else match = NULL;
for (cmd = cmd_functions; cmd; cmd = cmd->next)
{
if (match && !Com_Filter(match, cmd->name, false))
continue;
Msg("%s\n", cmd->name);
i++;
}
Msg("%i commands\n", i);
}
/*
============
Cmd_Init
============
*/
void Cmd_Init( int argc, char **argv )
{
char dev_level[4];
Cbuf_Init( argc, argv );
// register our commands
Cmd_AddCommand ("exec", Cmd_Exec_f, "execute a script file" );
Cmd_AddCommand ("echo", Cmd_Echo_f, "print a message to the console (useful in scripts)" );
Cmd_AddCommand ("wait", Cmd_Wait_f, "make script execution wait for some rendered frames" );
Cmd_AddCommand ("cmdlist", Cmd_List_f, "display all console commands beginning with the specified prefix" );
Cmd_AddCommand ("stuffcmds", Cmd_StuffCmds_f, "execute commandline parameters (must be present in init.rc script)" );
// determine debug and developer mode
if(FS_CheckParm ("-debug")) host.debug = true;
if(FS_GetParmFromCmdLine("-dev", dev_level ))
host.developer = atoi(dev_level);
}

999
launch/common/cvar.c Normal file
View File

@ -0,0 +1,999 @@
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// cvar.c -- dynamic variable tracking
#include "engine.h"
cvar_t *cvar_vars;
cvar_t *host_cheats;
#define MAX_CVARS 1024
#define FILE_HASH_SIZE 256
int cvar_numIndexes;
int cvar_modifiedFlags;
bool userinfo_modified;
cvar_t cvar_indexes[MAX_CVARS];
static cvar_t* hashTable[FILE_HASH_SIZE];
//=======================================================================
// INFOSTRING STUFF
//=======================================================================
/*
===============
Info_Print
printing current key-value pair
===============
*/
void Info_Print (char *s)
{
char key[512];
char value[512];
char *o;
int l;
if (*s == '\\') s++;
while (*s)
{
o = key;
while (*s && *s != '\\') *o++ = *s++;
l = o - key;
if (l < 20)
{
memset (o, ' ', 20-l);
key[20] = 0;
}
else *o = 0;
Msg ("%s", key);
if (!*s)
{
Msg ("MISSING VALUE\n");
return;
}
o = value;
s++;
while (*s && *s != '\\') *o++ = *s++;
*o = 0;
if (*s) s++;
Msg ("%s\n", value);
}
}
/*
===============
Info_ValueForKey
Searches the string for the given
key and returns the associated value, or an empty string.
===============
*/
char *Info_ValueForKey (char *s, char *key)
{
char pkey[512];
static char value[2][512]; // use two buffers so compares work without stomping on each other
static int valueindex;
char *o;
valueindex ^= 1;
if (*s == '\\') s++;
while (1)
{
o = pkey;
while (*s != '\\')
{
if (!*s) return "";
*o++ = *s++;
}
*o = 0;
s++;
o = value[valueindex];
while (*s != '\\' && *s)
{
if (!*s) return "";
*o++ = *s++;
}
*o = 0;
if (!strcmp (key, pkey) ) return value[valueindex];
if (!*s) return "";
s++;
}
}
void Info_RemoveKey (char *s, char *key)
{
char *start;
char pkey[512];
char value[512];
char *o;
if (strstr (key, "\\")) return;
while (1)
{
start = s;
if (*s == '\\') s++;
o = pkey;
while (*s != '\\')
{
if (!*s) return;
*o++ = *s++;
}
*o = 0;
s++;
o = value;
while (*s != '\\' && *s)
{
if (!*s) return;
*o++ = *s++;
}
*o = 0;
if (!strcmp (key, pkey) )
{
strcpy (start, s); // remove this part
return;
}
if (!*s) return;
}
}
/*
==================
Info_Validate
Some characters are illegal in info strings because they
can mess up the server's parsing
==================
*/
bool Info_Validate (char *s)
{
if (strstr (s, "\"")) return false;
if (strstr (s, ";")) return false;
return true;
}
void Info_SetValueForKey (char *s, char *key, char *value)
{
char newi[MAX_INFO_STRING], *v;
int c, maxsize = MAX_INFO_STRING;
if (strstr (key, "\\") || strstr (value, "\\") )
{
Msg ("Can't use keys or values with a \\\n");
return;
}
if (strstr (key, ";") )
{
Msg ("Can't use keys or values with a semicolon\n");
return;
}
if (strstr (key, "\"") || strstr (value, "\"") )
{
Msg ("Can't use keys or values with a \"\n");
return;
}
if (strlen(key) > MAX_INFO_KEY - 1 || strlen(value) > MAX_INFO_KEY-1)
{
Msg ("Keys and values must be < 64 characters.\n");
return;
}
Info_RemoveKey (s, key);
if (!value || !strlen(value)) return;
sprintf (newi, "\\%s\\%s", key, value);
if (strlen(newi) + strlen(s) > maxsize)
{
Msg ("Info string length exceeded\n");
return;
}
// only copy ascii values
s += strlen(s);
v = newi;
while (*v)
{
c = *v++;
c &= 127; // strip high bits
if (c >= 32 && c < 127) *s++ = c;
}
*s = 0;
}
/*
================
return a hash value for the filename
================
*/
static long Cvar_GetHashValue( const char *fname )
{
int i = 0;
long hash = 0;
char letter;
while (fname[i] != '\0')
{
letter = tolower(fname[i]);
hash += (long)(letter)*(i + 119);
i++;
}
hash &= (FILE_HASH_SIZE - 1);
return hash;
}
/*
============
Cvar_InfoValidate
============
*/
static bool Cvar_ValidateString(const char *s, bool isvalue )
{
if ( !s ) return false;
if (strstr(s, "\\") && !isvalue)
return false;
if (strstr(s, "\"")) return false;
if (strstr(s, ";")) return false;
return true;
}
/*
============
Cvar_FindVar
============
*/
cvar_t *Cvar_FindVar (const char *var_name)
{
cvar_t *var;
long hash;
hash = Cvar_GetHashValue(var_name);
for (var = hashTable[hash]; var; var = var->hash)
{
if (!stricmp(var_name, var->name))
return var;
}
return NULL;
}
/*
============
Cvar_VariableValue
============
*/
float Cvar_VariableValue(const char *var_name)
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var) return 0;
return var->value;
}
/*
============
Cvar_VariableIntegerValue
============
*/
int Cvar_VariableInteger( const char *var_name )
{
cvar_t *var;
var = Cvar_FindVar(var_name);
if (!var) return 0;
return var->integer;
}
/*
============
Cvar_VariableString
============
*/
char *Cvar_VariableString (const char *var_name)
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var) return "";
return var->string;
}
/*
============
Cvar_VariableStringBuffer
place variable into buffer
============
*/
void Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize )
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var) *buffer = 0;
else strncpy( buffer, var->string, bufsize );
}
/*
============
Cvar_CommandCompletion
============
*/
void Cvar_CommandCompletion( void(*callback)(const char *s, const char *m))
{
cvar_t *cvar;
for( cvar = cvar_vars; cvar; cvar = cvar->next )
callback( cvar->name, cvar->description );
}
/*
============
Cvar_Get
If the variable already exists, the value will not be set
The flags will be or'ed in if the variable exists.
============
*/
cvar_t *_Cvar_Get(const char *var_name, const char *var_value, int flags, const char *var_desc )
{
cvar_t *var;
long hash;
if(!var_name || !var_value)
{
MsgDev( D_ERROR, "Cvar_Get: NULL parameter" );
return NULL;
}
if (!Cvar_ValidateString(var_name, false))
{
MsgDev(D_WARN, "invalid info cvar name string %s\n", var_name );
var_value = "noname";
}
if(!Cvar_ValidateString( var_value, true ))
{
MsgDev(D_WARN, "invalid cvar value string: %s\n", var_value );
var_value = "default";
}
var = Cvar_FindVar (var_name);
if ( var )
{
// if the C code is now specifying a variable that the user already
// set a value for, take the new value as the reset value
if(( var->flags & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED ) && var_value[0])
{
var->flags &= ~CVAR_USER_CREATED;
Z_Free( var->reset_string );
var->reset_string = copystring( var_value );
cvar_modifiedFlags |= flags;
}
var->flags |= flags;
// only allow one non-empty reset string without a warning
if( !var->reset_string[0] )
{
// we don't have a reset string yet
Z_Free( var->reset_string );
var->reset_string = copystring( var_value );
}
else if ( var_value[0] && strcmp( var->reset_string, var_value ))
{
MsgDev(D_WARN, "cvar \"%s\" given initial values: \"%s\" and \"%s\"\n", var_name, var->reset_string, var_value );
}
// if we have a latched string, take that value now
if ( var->latched_string )
{
char *s;
s = var->latched_string;
var->latched_string = NULL; // otherwise cvar_set2 would free it
Cvar_Set2( var_name, s, true );
Z_Free( s );
}
return var;
}
// allocate a new cvar
if( cvar_numIndexes >= MAX_CVARS )
{
MsgWarn("Cvar_Get: MAX_CVARS limit exceeded\n" );
return NULL;
}
var = &cvar_indexes[cvar_numIndexes];
cvar_numIndexes++;
var->name = copystring(var_name);
var->string = copystring(var_value);
var->description = copystring(var_desc);
var->modified = true;
var->modificationCount = 1;
var->value = atof(var->string);
var->integer = atoi(var->string);
var->reset_string = copystring( var_value );
// link the variable in
var->next = cvar_vars;
cvar_vars = var;
var->flags = flags;
hash = Cvar_GetHashValue(var_name);
var->hash = hashTable[hash];
hashTable[hash] = var;
return var;
}
/*
============
Cvar_Set2
============
*/
cvar_t *Cvar_Set2 (const char *var_name, const char *value, bool force)
{
cvar_t *var;
if( !Cvar_ValidateString( var_name, false ))
{
MsgDev(D_WARN, "invalid cvar name string: %s\n", var_name );
var_name = "unknown";
}
if ( value && !Cvar_ValidateString( value, true ))
{
MsgDev(D_WARN, "invalid cvar value string: %s\n", value );
value = "default";
}
var = Cvar_FindVar (var_name);
if (!var)
{
if( !value ) return NULL;
// create it
if ( !force ) return Cvar_Get( var_name, value, CVAR_USER_CREATED );
else return Cvar_Get (var_name, value, 0 );
}
if(!value ) value = var->reset_string;
if(!strcmp(value, var->string)) return var;
// note what types of cvars have been modified (userinfo, archive, serverinfo, systeminfo)
cvar_modifiedFlags |= var->flags;
if (!force)
{
if (var->flags & CVAR_READ_ONLY)
{
MsgDev(D_INFO, "%s is read only.\n", var_name);
return var;
}
if (var->flags & CVAR_INIT)
{
MsgDev(D_INFO, "%s is write protected.\n", var_name);
return var;
}
if (var->flags & CVAR_LATCH)
{
if (var->latched_string)
{
if (!strcmp(value, var->latched_string))
return var;
Z_Free (var->latched_string);
}
else
{
if (!strcmp(value, var->string))
return var;
}
MsgDev(D_INFO, "%s will be changed after restarting.\n", var_name);
var->latched_string = copystring(value);
var->modified = true;
var->modificationCount++;
return var;
}
if ( (var->flags & CVAR_CHEAT) && !host_cheats->integer )
{
MsgDev(D_INFO, "%s is cheat protected.\n", var_name);
return var;
}
}
else
{
if (var->latched_string)
{
Z_Free(var->latched_string);
var->latched_string = NULL;
}
}
if (!strcmp(value, var->string))
return var; // not changed
var->modified = true;
var->modificationCount++;
Z_Free (var->string); // free the old value string
var->string = copystring(value);
var->value = atof (var->string);
var->integer = atoi(var->string);
return var;
}
/*
============
Cvar_Set
============
*/
void Cvar_Set( const char *var_name, const char *value)
{
Cvar_Set2 (var_name, value, true);
}
/*
============
Cvar_SetLatched
============
*/
void Cvar_SetLatched( const char *var_name, const char *value)
{
Cvar_Set2 (var_name, value, false);
}
/*
============
Cvar_FullSet
============
*/
void Cvar_FullSet (char *var_name, char *value, int flags)
{
cvar_t *var;
var = Cvar_FindVar (var_name);
if (!var)
{
// create it
Cvar_Get (var_name, value, flags);
return;
}
var->modified = true;
if (var->flags & CVAR_USERINFO)
userinfo_modified = true; // transmit at next oportunity
Z_Free (var->string); // free the old value string
var->string = copystring(value);
var->value = atof(var->string);
var->integer = atoi(var->string);
var->flags = flags;
}
/*
============
Cvar_SetValue
============
*/
void Cvar_SetValue( const char *var_name, float value)
{
char val[32];
if( value == (int)value ) sprintf (val, "%i", (int)value);
else sprintf (val, "%f", value);
Cvar_Set (var_name, val);
}
/*
============
Cvar_Reset
============
*/
void Cvar_Reset( const char *var_name )
{
Cvar_Set2( var_name, NULL, false );
}
/*
============
Cvar_SetCheatState
Any testing variables will be reset to the safe values
============
*/
void Cvar_SetCheatState( void )
{
cvar_t *var;
// set all default vars to the safe value
for ( var = cvar_vars ; var ; var = var->next )
{
if( var->flags & CVAR_CHEAT )
{
// the CVAR_LATCHED|CVAR_CHEAT vars might escape the reset here
// because of a different var->latched_string
if (var->latched_string)
{
Z_Free(var->latched_string);
var->latched_string = NULL;
}
if (strcmp(var->reset_string, var->string))
{
Cvar_Set( var->name, var->reset_string );
}
}
}
}
/*
============
Cvar_Command
Handles variable inspection and changing from the console
============
*/
bool Cvar_Command( void )
{
cvar_t *v;
// check variables
v = Cvar_FindVar (Cmd_Argv(0));
if (!v) return false;
// perform a variable print or set
if ( Cmd_Argc() == 1 )
{
if(v->flags & CVAR_INIT) Msg("%s: %s\n", v->name, v->string );
else Msg("%s: %s ( ^3%s^7 )\n", v->name, v->string, v->reset_string );
if ( v->latched_string ) Msg( "%s: %s\n", v->name, v->latched_string );
return true;
}
// set the value if forcing isn't required
Cvar_Set2 (v->name, Cmd_Argv(1), false);
return true;
}
/*
============
Cvar_Toggle_f
Toggles a cvar for easy single key binding
============
*/
void Cvar_Toggle_f( void )
{
int v;
if( Cmd_Argc() != 2 )
{
Msg("usage: toggle <variable>\n");
return;
}
v = Cvar_VariableValue( Cmd_Argv( 1 ));
v = !v;
Cvar_Set2 (Cmd_Argv(1), va("%i", v), false);
}
/*
============
Cvar_Set_f
Allows setting and defining of arbitrary cvars from console, even if they
weren't declared in C code.
============
*/
void Cvar_Set_f( void )
{
int i, c, l = 0, len;
char combined[MAX_STRING_TOKENS];
c = Cmd_Argc();
if ( c < 3 )
{
Msg("usage: set <variable> <value>\n");
return;
}
combined[0] = 0;
for ( i = 2; i < c; i++ )
{
len = strlen( Cmd_Argv(i) + 1 );
if ( l + len >= MAX_STRING_TOKENS - 2 )
break;
strcat( combined, Cmd_Argv(i));
if ( i != c-1 ) strcat( combined, " " );
l += len;
}
Cvar_Set2 (Cmd_Argv(1), combined, false);
}
/*
============
Cvar_SetU_f
As Cvar_Set, but also flags it as userinfo
============
*/
void Cvar_SetU_f( void )
{
cvar_t *v;
if ( Cmd_Argc() != 3 )
{
Msg("usage: setu <variable> <value>\n");
return;
}
Cvar_Set_f();
v = Cvar_FindVar( Cmd_Argv(1));
if( !v ) return;
v->flags |= CVAR_USERINFO;
}
/*
============
Cvar_SetS_f
As Cvar_Set, but also flags it as userinfo
============
*/
void Cvar_SetS_f( void )
{
cvar_t *v;
if ( Cmd_Argc() != 3 )
{
Msg("usage: sets <variable> <value>\n");
return;
}
Cvar_Set_f();
v = Cvar_FindVar( Cmd_Argv(1));
if ( !v ) return;
v->flags |= CVAR_SERVERINFO;
}
/*
============
Cvar_SetA_f
As Cvar_Set, but also flags it as archived
============
*/
void Cvar_SetA_f( void )
{
cvar_t *v;
if ( Cmd_Argc() != 3 )
{
Msg("usage: seta <variable> <value>\n");
return;
}
Cvar_Set_f();
v = Cvar_FindVar( Cmd_Argv( 1 ) );
if ( !v ) return;
v->flags |= CVAR_ARCHIVE;
}
/*
============
Cvar_Reset_f
============
*/
void Cvar_Reset_f( void )
{
if ( Cmd_Argc() != 2 )
{
Msg("usage: reset <variable>\n");
return;
}
Cvar_Reset( Cmd_Argv( 1 ));
}
/*
============
Cvar_WriteVariables
Appends lines containing "set variable value" for all variables
with the archive flag set to true.
============
*/
void Cvar_WriteVariables( file_t *f )
{
cvar_t *var;
char buffer[1024];
for(var = cvar_vars; var; var = var->next)
{
if( var->flags & CVAR_ARCHIVE )
{
// write the latched value, even if it hasn't taken effect yet
if (!var->latched_string ) sprintf(buffer, "seta %s \"%s\"\n", var->name, var->string);
else sprintf(buffer, "seta %s \"%s\"\n", var->name, var->latched_string);
FS_Printf (f, "%s", buffer);
}
}
}
/*
============
Cvar_List_f
============
*/
void Cvar_List_f( void )
{
cvar_t *var;
char *match;
int i = 0;
if ( Cmd_Argc() > 1 ) match = Cmd_Argv(1);
else match = NULL;
for (var = cvar_vars; var; var = var->next, i++)
{
if (match && !Com_Filter(match, var->name, false))
continue;
if (var->flags & CVAR_SERVERINFO) Msg("S");
else Msg(" ");
if (var->flags & CVAR_USERINFO) Msg("U");
else Msg(" ");
if (var->flags & CVAR_READ_ONLY) Msg("R");
else Msg(" ");
if (var->flags & CVAR_INIT) Msg("I");
else Msg(" ");
if (var->flags & CVAR_ARCHIVE) Msg("A");
else Msg(" ");
if (var->flags & CVAR_LATCH) Msg("L");
else Msg(" ");
if (var->flags & CVAR_CHEAT) Msg("C");
else Msg(" ");
Msg (" %s \"%s\"\n", var->name, var->string);
}
Msg ("\n%i total cvars\n", i);
Msg ("%i cvar indexes\n", cvar_numIndexes);
}
/*
============
Cvar_Restart_f
Resets all cvars to their hardcoded values
============
*/
void Cvar_Restart_f( void )
{
cvar_t *var;
cvar_t **prev;
prev = &cvar_vars;
while ( 1 )
{
var = *prev;
if ( !var ) break;
// don't mess with rom values, or some inter-module
// communication will get broken (com_cl_running, etc)
if ( var->flags & ( CVAR_READ_ONLY | CVAR_INIT ))
{
prev = &var->next;
continue;
}
// throw out any variables the user created
if ( var->flags & CVAR_USER_CREATED )
{
*prev = var->next;
if( var->name ) Z_Free( var->name );
if ( var->string ) Z_Free( var->string );
if ( var->latched_string ) Z_Free( var->latched_string );
if ( var->reset_string ) Z_Free( var->reset_string );
if ( var->description ) Z_Free( var->description );
// clear the var completely, since we
// can't remove the index from the list
memset( var, 0, sizeof( var ));
continue;
}
Cvar_Set( var->name, var->reset_string );
prev = &var->next;
}
}
char *Cvar_BitInfo (int bit)
{
static char info[MAX_INFO_STRING];
cvar_t *var;
info[0] = 0;
for (var = cvar_vars; var; var = var->next)
{
if (var->flags & bit)
Info_SetValueForKey (info, var->name, var->string);
}
return info;
}
// returns an info string containing all the CVAR_USERINFO cvars
char *Cvar_Userinfo (void)
{
return Cvar_BitInfo (CVAR_USERINFO);
}
// returns an info string containing all the CVAR_SERVERINFO cvars
char *Cvar_Serverinfo (void)
{
return Cvar_BitInfo (CVAR_SERVERINFO);
}
/*
============
Cvar_Init
Reads in all archived cvars
============
*/
void Cvar_Init (void)
{
host_cheats = Cvar_Get("host_cheats", "1", CVAR_READ_ONLY | CVAR_SYSTEMINFO );
Cmd_AddCommand ("toggle", Cvar_Toggle_f, "toggles a console variable's values (use for more info)" );
Cmd_AddCommand ("set", Cvar_Set_f, "create or change the value of a console variable" );
Cmd_AddCommand ("sets", Cvar_SetS_f, "create or change the value of a serverinfo variable");
Cmd_AddCommand ("setu", Cvar_SetU_f, "create or change the value of a userinfo variable");
Cmd_AddCommand ("seta", Cvar_SetA_f, "create or change the value of a console variable that will be saved to vars.rc");
Cmd_AddCommand ("reset", Cvar_Reset_f, "reset any type variable to initial value" );
Cmd_AddCommand ("cvarlist", Cvar_List_f, "display all console variables beginning with the specified prefix" );
Cmd_AddCommand ("unsetall", Cvar_Restart_f, "reset all console variables to their default values" );
}

View File

@ -56,9 +56,10 @@ struct file_s
typedef struct vfile_s
{
byte *buff;
char filename[MAX_QPATH];
char mode[4];
file_t *handle;
int mode;
bool compress;
fs_offset_t buffsize;
fs_offset_t length;
fs_offset_t offset;
@ -2418,46 +2419,45 @@ vfile_t *VFS_Create(byte *buffer, size_t buffsize)
file->length = file->buffsize = buffsize;
file->buff = Mem_Alloc(fs_mempool, (file->buffsize));
file->offset = 0;
com_strncpy(file->mode, "r", 4 );
file->mode = O_RDONLY;
Mem_Copy(file->buff, buffer, buffsize );
return file;
}
vfile_t *VFS_Open(const char *filename, const char* mode)
vfile_t *VFS_Open(file_t *handle, const char* mode)
{
vfile_t *file = (vfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
file_t *real_file;
com_strncpy(file->filename, filename, MAX_QPATH );
com_strncpy(file->mode, mode, 4 );
vfile_t *file = (vfile_t *)Mem_Alloc (fs_mempool, sizeof (vfile_t));
// If the file is opened in "write", "append", or "read/write" mode
if (mode[0] == 'w')
{
file->compress = (mode[1] == 'z') ? true : false;
file->handle = handle;
file->buffsize = (64 * 1024); // will be resized if need
file->buff = Mem_Alloc(fs_mempool, (file->buffsize));
file->length = 0;
file->offset = 0;
file->mode = O_WRONLY;
}
else if (mode[0] == 'r')
{
int curpos, endpos;
real_file = FS_Open( file->filename, file->mode );
curpos = FS_Tell(real_file);
FS_Seek(real_file, 0, SEEK_END);
endpos = FS_Tell(real_file);
FS_Seek(real_file, curpos, SEEK_SET);
file->compress = false;
file->handle = handle;
curpos = FS_Tell(file->handle);
FS_Seek(file->handle, 0, SEEK_END);
endpos = FS_Tell(file->handle);
FS_Seek(file->handle, curpos, SEEK_SET);
file->buffsize = endpos - curpos;
file->buff = Mem_Alloc(fs_mempool, (file->buffsize));
FS_Read (real_file, file->buff, file->buffsize);
FS_Read(file->handle, file->buff, file->buffsize);
file->length = file->buffsize;
file->offset = 0;
FS_Close( real_file );
file->mode = O_RDONLY;
}
else
{
@ -2547,6 +2547,65 @@ fs_offset_t VFS_Write2( vfile_t *handle, byte *buffer, size_t size )
return i;
}
/*
====================
FS_Print
Print a string into a file
====================
*/
int VFS_Print(vfile_t* file, const char *msg)
{
return (int)VFS_Write(file, msg, com_strlen(msg));
}
/*
====================
VFS_VPrintf
Print a string into a buffer
====================
*/
int VFS_VPrintf(vfile_t* file, const char* format, va_list ap)
{
int len;
fs_offset_t buff_size = MAX_INPUTLINE;
char *tempbuff;
while( true )
{
tempbuff = (char *)Malloc(buff_size);
len = com_vsprintf(tempbuff, format, ap);
if (len >= 0 && len < buff_size) break;
Mem_Free(tempbuff);
buff_size *= 2;
}
len = VFS_Write(file, tempbuff, len);
Mem_Free( tempbuff );
return len;
}
/*
====================
VFS_Printf
Print a string into a buffer
====================
*/
int VFS_Printf(vfile_t* file, const char* format, ...)
{
int result;
va_list args;
va_start(args, format);
result = VFS_VPrintf(file, format, args);
va_end (args);
return result;
}
fs_offset_t VFS_Tell (vfile_t* file)
{
if (!file) return -1;
@ -2594,18 +2653,34 @@ bool VFS_Unpack( void* compbuf, size_t compsize, void **dst, size_t size )
return true;
}
int VFS_Close( vfile_t *file )
file_t *VFS_Close( vfile_t *file )
{
if(!file) return -1;
char out[8192]; // chunk size
z_stream strm = {file->buff,file->length,0,out,sizeof(out),0,NULL,NULL,NULL,NULL,NULL,0,0,0};
file_t *handle;
if(!file) return NULL;
if(file->mode[0] == 'w' && com_strlen(file->filename))
if(file->mode == O_WRONLY)
{
// write real file into disk
FS_WriteFile (file->filename, file->buff, (file->length + 3) & ~3);// align
if( file->compress ) // deflate before writing
{
deflateInit( &strm, 9 ); // Z_BEST_COMPRESSION
while(deflate(&strm, Z_FINISH) == Z_OK)
{
FS_Write( file->handle, out, sizeof(out) - strm.avail_out);
strm.next_out = out;
strm.avail_out = sizeof(out);
}
FS_Write( file->handle, out, sizeof(out) - strm.avail_out );
deflateEnd( &strm );
}
else FS_Write(file->handle, file->buff, (file->length + 3) & ~3); // align
}
handle = file->handle; // keep real handle
Mem_Free( file->buff );
Mem_Free( file ); //himself
Mem_Free( file ); // himself
return 0;
return handle;
}

View File

@ -19,17 +19,49 @@ dll_info_t editor_dll = { "editor.dll", NULL, "CreateAPI", NULL, NULL, true, siz
static const char *show_credits = "\n\n\n\n\tCopyright XashXT Group 2007 ©\n\t\
All Rights Reserved\n\n\t Visit www.xash.ru\n";
void NullInit ( uint funcname, int argc, char **argv )
// stubs
void NullInit( uint funcname, int argc, char **argv ) {}
void NullFunc( void ) {}
void Com_AddCommand( const char *name, xcommand_t cmd, const char *cmd_desc )
{
MsgDev(D_NOTE, "Warning: cmd %s not added - too early\n", name );
}
void NullFunc( void )
void Com_DelCommand( const char *name )
{
MsgDev(D_NOTE, "Warning: cmd %s not removed - too early\n", name );
}
gameinfo_t Sys_GameInfo( void )
uint Com_Argc( void )
{
return GI;
return fs_argc;
}
char *Com_Argv( int num )
{
return fs_argv[num];
}
void Com_AddText(const char *text)
{
Sys_Print( text );
}
void Com_CvarSetValue( const char *name, float value )
{
MsgDev(D_NOTE, "Warning: cvar %s not found - too early\n", name );
}
void Com_CvarSetString( const char *name, const char *value )
{
MsgDev(D_NOTE, "Warning: cvar %s not found - too early\n", name );
}
cvar_t *Com_GetCvar( const char *name, const char *value, int flags, const char *desc )
{
MsgDev(D_NOTE, "Warning: cvar %s can't created - too early\n", name );
return NULL;
}
void Sys_GetStdAPI( void )
@ -118,6 +150,8 @@ void Sys_GetStdAPI( void )
std.vfwrite = VFS_Write; // write into buffer
std.vfwrite2 = VFS_Write2; // deflate buffer, then write
std.vfread = VFS_Read; // read from buffer
std.vfprint = VFS_Print; // write message
std.vfprintf = VFS_Printf; // write formatted message
std.vfseek = VFS_Seek; // fseek, can seek in packfiles too
std.vfunpack = VFS_Unpack; // inflate zipped buffer
std.vftell = VFS_Tell; // like a ftell
@ -134,6 +168,16 @@ void Sys_GetStdAPI( void )
std.Com_GetProcAddress = Sys_GetProcAddress; // gpa
std.Com_DoubleTime = Sys_DoubleTime; // hi-res timer
// console commands and variables
std.Com_AddCommand = Com_AddCommand;
std.Com_DelCommand = Com_DelCommand;
std.Com_Argc = Com_Argc;
std.Com_Argv = Com_Argv;
std.Com_AddText = Com_AddText;
std.Com_CvarSetValue = Com_CvarSetValue;
std.Com_CvarSetString = Com_CvarSetString;
std.Com_GetCvar = Com_GetCvar;
// stdlib.c funcs
std.strnupr = com_strnupr;
std.strnlwr = com_strnlwr;

View File

@ -235,14 +235,16 @@ bool FS_Eof( file_t* file);
// virtual files managment
vfile_t *VFS_Create(byte *buffer, size_t buffsize);
vfile_t *VFS_Open(const char *filename, const char* mode);
vfile_t *VFS_Open(file_t *handle, const char* mode);
fs_offset_t VFS_Write( vfile_t *file, const void *buf, size_t size );
fs_offset_t VFS_Write2( vfile_t *handle, byte *buffer, size_t size );
fs_offset_t VFS_Read(vfile_t* file, void* buffer, size_t buffersize);
int VFS_Print(vfile_t* file, const char *msg);
int VFS_Printf(vfile_t* file, const char* format, ...);
int VFS_Seek( vfile_t *file, fs_offset_t offset, int whence );
bool VFS_Unpack( void* compbuf, size_t compsize, void **buf, size_t size );
fs_offset_t VFS_Tell (vfile_t* file);
int VFS_Close( vfile_t *file );
file_t *VFS_Close( vfile_t *file );
//
// crclib.c

View File

@ -28,6 +28,11 @@ void Phys_RemoveBOX( NewtonBody *body );
#define MsgDev std.dprintf
#define MsgWarn std.wprintf
#define Host_Error std.error
#define Cvar_Get(name, value, flags) std.Com_GetCvar(name, value, flags, "render variable" )
#define Cvar_SetValue(name, value) std.Com_CvarSetValue(name, value )
#define Cvar_SetString(name, value) std.Com_CvarSetString(name, value )
#define Cmd_AddCommand(name, cmd) std.Com_AddCommand(name, cmd, "render command" )
#define Cmd_RemoveCommand(name) std.Com_DelCommand(name )
typedef struct NewtonUserMeshCollisionCollideDescTag
{

View File

@ -707,4 +707,36 @@ typedef struct trace_s
edict_t *ent; // not set by CM_*() functions
} trace_t;
/*
==============================================================================
SAVE FILE
==============================================================================
*/
#define SAVE_VERSION 3
#define IDSAVEHEADER (('E'<<24)+('V'<<16)+('A'<<8)+'S') // little-endian "SAVE"
#define LUMP_COMMENTS 0 // map comments
#define LUMP_CFGSTRING 1 // client info strings
#define LUMP_AREASTATE 2 // area portals state
#define LUMP_GAMESTATE 3 // progs global state (deflated)
#define LUMP_MAPNAME 4 // map name
#define LUMP_GAMECVARS 5 // contain game comment and all cvar state
#define LUMP_GAMEENTS 6 // ents state (deflated)
#define LUMP_SNAPSHOT 7 // tga image snapshot (128x128)
#define SAVE_NUMLUMPS 8 // header size
typedef struct
{
int ident;
int version;
lump_t lumps[SAVE_NUMLUMPS];
} dsavehdr_t;
typedef struct
{
char name[MAX_QPATH];
char value[MAX_QPATH];
} dsavecvar_t;
#endif//REF_FORMAT_H

View File

@ -89,6 +89,8 @@ virtual filesystem manager
#define VFS_Write std.vfwrite
#define VFS_Write2 std.vfwrite2
#define VFS_Read std.vfread
#define VFS_Print std.vfprint
#define VFS_Printf std.vfprintf
#define VFS_Seek std.vfseek
#define VFS_Tell std.vftell
#define VFS_Close std.vfclose

View File

@ -592,11 +592,13 @@ typedef struct stdilib_api_s
// virtual filesystem
vfile_t *(*vfcreate)(byte *buffer, size_t buffsize); // create virtual stream
vfile_t *(*vfopen)(const char *filename, const char* mode); // virtual fopen
int (*vfclose)(vfile_t* file); // free buffer or write dump
vfile_t *(*vfopen)(file_t *handle, const char* mode); // virtual fopen
file_t *(*vfclose)(vfile_t* file); // free buffer or write dump
long (*vfwrite)(vfile_t* file, const void* buf, size_t datasize); // write into buffer
long (*vfwrite2)(vfile_t* handle, byte* buffer, size_t datasize); // deflate and write into buffer
long (*vfread)(vfile_t* file, void* buffer, size_t buffersize); // read from buffer
int (*vfprint)(vfile_t* file, const char *msg); // write message
int (*vfprintf)(vfile_t* file, const char* format, ...); // write formatted message
int (*vfseek)(vfile_t* file, fs_offset_t offset, int whence); // fseek, can seek in packfiles too
bool (*vfunpack)( void* comp, size_t size1, void **buf, size_t size2);// deflate zipped buffer
long (*vftell)(vfile_t* file); // like a ftell
@ -613,6 +615,16 @@ typedef struct stdilib_api_s
void*(*Com_GetProcAddress)( dll_info_t *dll, const char* name ); // gpa
double (*Com_DoubleTime)( void ); // hi-res timer
// console commands and variables (engine overloaded pointers after initialization)
void (*Com_AddCommand)( const char *name, xcommand_t cmd, const char *cmd_desc );
void (*Com_DelCommand)( const char *name );
uint (*Com_Argc)( void );
char *(*Com_Argv)( int num );
void (*Com_AddText)(const char *text);
void (*Com_CvarSetValue)( const char *name, float value );
void (*Com_CvarSetString)( const char *var_name, const char *value);
cvar_t *(*Com_GetCvar)( const char *name, const char *value, int flags, const char *desc );
// stdlib.c funcs
void (*strnupr)(const char *in, char *out, size_t size_out);// convert string to upper case
void (*strnlwr)(const char *in, char *out, size_t size_out);// convert string to lower case
@ -685,7 +697,6 @@ typedef struct render_exp_s
// initialize
bool (*Init)( void *hInstance, void *WndProc ); // init all render systems
void (*Shutdown)( void ); // shutdown all render systems
void (*AppActivate)( bool activate ); // ??
void (*BeginRegistration) (char *map);
model_t *(*RegisterModel) (char *name);
@ -704,8 +715,7 @@ typedef struct render_exp_s
void (*DrawStretchRaw) (int x, int y, int w, int h, int cols, int rows, byte *data, bool redraw );
void (*DrawStretchPic)(float x, float y, float w, float h, float s1, float t1, float s2, float t2, char *name);
// get rid of this
void (*DrawGetPicSize) (int *w, int *h, char *name); // will return 0 0 if not found
void (*DrawGetPicSize) (int *w, int *h, char *name); // get rid of this
} render_exp_t;
@ -714,23 +724,9 @@ typedef struct render_imp_s
// interface validator
size_t api_size; // must matched with sizeof(render_imp_t)
void (*Cmd_AddCommand)( const char *name, xcommand_t cmd, const char *cmd_desc );
void (*Cmd_RemoveCommand)( char *name );
int (*Cmd_Argc) (void);
char *(*Cmd_Argv) (int i);
void (*Cmd_ExecuteText) (int exec_when, char *text);
// client fundamental callbacks
void (*StudioEvent)( mstudioevent_t *event, entity_t *ent );
void (*ShowCollision)( void );// debug
cvar_t *(*Cvar_Get)( const char *name, const char *value, int flags, const char *desc );
void (*Cvar_Set)( const char *name, const char *value );
void (*Cvar_SetValue)( const char *name, float value );
bool (*Vid_GetModeInfo)( int *width, int *height, int mode );
void (*Vid_MenuInit)( void );
void (*Vid_NewWindow)( int width, int height );
void (*ShowCollision)( void ); // debug
} render_imp_t;

View File

@ -262,9 +262,9 @@ void Draw_FadeScreen (void)
qglBegin (GL_QUADS);
qglVertex2f (0,0);
qglVertex2f (vid.width, 0);
qglVertex2f (vid.width, vid.height);
qglVertex2f (0, vid.height);
qglVertex2f (r_width->integer, 0);
qglVertex2f (r_width->integer, r_height->integer);
qglVertex2f (0, r_height->integer);
qglEnd ();
qglColor4f (1,1,1,1);

View File

@ -62,19 +62,11 @@ void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
#define MsgWarn std.wprintf
#define Sys_Error std.error
#define Cvar_Get(name, value, flags) ri.Cvar_Get(name, value, flags, "render variable" )
#define Cmd_AddCommand(name, cmd) ri.Cmd_AddCommand(name, cmd, "render command" )
#ifndef __VIDDEF_T
#define __VIDDEF_T
typedef struct
{
int width;
int height; // coordinates from main game
} viddef_t;
#endif
extern viddef_t vid;
#define Cvar_Get(name, value, flags) std.Com_GetCvar(name, value, flags, "render variable" )
#define Cvar_SetValue(name, value) std.Com_CvarSetValue(name, value )
#define Cvar_SetString(name, value) std.Com_CvarSetString(name, value )
#define Cmd_AddCommand(name, cmd) std.Com_AddCommand(name, cmd, "render command" )
#define Cmd_RemoveCommand(name) std.Com_DelCommand(name )
#define MAX_RADAR_ENTS 1024
typedef struct radar_ent_s
@ -176,7 +168,6 @@ typedef struct
#define BACKFACE_EPSILON 0.01
//====================================================
extern image_t gltextures[MAX_GLTEXTURES];
@ -209,7 +200,7 @@ extern vec3_t r_origin;
// screen size info
//
extern refdef_t r_newrefdef;
extern int r_viewcluster, r_viewcluster2, r_oldviewcluster, r_oldviewcluster2;
extern int r_viewcluster, r_viewcluster2, r_oldviewcluster, r_oldviewcluster2;
extern cvar_t *r_norefresh;
extern cvar_t *r_lefthand;
@ -222,13 +213,15 @@ extern cvar_t *r_nocull;
extern cvar_t *r_lerpmodels;
extern cvar_t *r_loading;
extern cvar_t *r_pause;
extern cvar_t *r_width;
extern cvar_t *r_height;
extern cvar_t *r_mode;
extern cvar_t *r_lightlevel; // FIXME: This is a HACK to get the client's light level
extern cvar_t *gl_vertex_arrays;
extern cvar_t *gl_ext_swapinterval;
extern cvar_t *gl_ext_palettedtexture;
extern cvar_t *gl_ext_multitexture;
extern cvar_t *gl_ext_pointparameters;
extern cvar_t *gl_ext_compiled_vertex_array;
@ -260,14 +253,12 @@ extern cvar_t *r_motionblur;
extern cvar_t *gl_nosubimage;
extern cvar_t *gl_bitdepth;
extern cvar_t *gl_mode;
extern cvar_t *gl_log;
extern cvar_t *gl_lightmap;
extern cvar_t *gl_shadows;
extern cvar_t *gl_dynamic;
extern cvar_t *gl_nobind;
extern cvar_t *gl_round_down;
extern cvar_t *gl_picmip;
extern cvar_t *gl_skymip;
extern cvar_t *gl_showtris;
extern cvar_t *gl_finish;
@ -364,7 +355,7 @@ void R_AddSkySurface (msurface_t *fa);
void R_ClearSkyBox (void);
void R_DrawSkyBox (void);
void R_MarkLights (dlight_t *light, int bit, mnode_t *node);
void R_RoundImageDimensions(int *scaled_width, int *scaled_height, bool mipmap);
void R_RoundImageDimensions(int *scaled_width, int *scaled_height);
#if 0
short LittleShort (short l);
@ -449,9 +440,8 @@ typedef struct
float inverse_intensity;
bool fullscreen;
int prev_mode;
unsigned char *d_16to8table;
int prev_mode;
byte *d_16to8table;
int lightmap_textures;
@ -535,7 +525,7 @@ void GLimp_BeginFrame( void );
void GLimp_EndFrame( void );
int GLimp_Init( void *hinstance, void *hWnd );
void GLimp_Shutdown( void );
int GLimp_SetMode( int *pwidth, int *pheight, int mode, bool fullscreen );
int GLimp_SetMode( int vid_mode, bool fullscreen );
void GLimp_AppActivate( bool active );
void GLimp_EnableLogging( bool enable );
void GLimp_LogNewFrame( void );

View File

@ -457,7 +457,7 @@ void Mod_LoadTexinfo (lump_t *l)
out->image = R_FindImage (in->texture, NULL, 0, it_wall);
if(out->image)
{
ri.Cvar_SetValue("scr_loading", r_loading->value + 45.0f/count );
Cvar_SetValue("scr_loading", r_loading->value + 45.0f/count );
}
else
{
@ -960,7 +960,7 @@ void R_BeginRegistration (char *model)
else
{
// textures already loaded
ri.Cvar_SetValue("scr_loading", r_loading->value + 45.0f );
Cvar_SetValue("scr_loading", r_loading->value + 45.0f );
}
r_worldmodel = Mod_ForName(fullname, true);

View File

@ -22,8 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void R_Clear (void);
viddef_t vid;
render_imp_t ri;
stdlib_api_t std;
@ -115,7 +113,6 @@ cvar_t *r_minimap_zoom;
cvar_t *r_minimap_style;
cvar_t *gl_ext_swapinterval;
cvar_t *gl_ext_palettedtexture;
cvar_t *gl_ext_multitexture;
cvar_t *gl_ext_pointparameters;
cvar_t *gl_ext_compiled_vertex_array;
@ -126,12 +123,10 @@ cvar_t *gl_bitdepth;
cvar_t *gl_drawbuffer;
cvar_t *gl_lightmap;
cvar_t *gl_shadows;
cvar_t *gl_mode;
cvar_t *gl_dynamic;
cvar_t *gl_modulate;
cvar_t *gl_nobind;
cvar_t *gl_round_down;
cvar_t *gl_picmip;
cvar_t *gl_skymip;
cvar_t *gl_showtris;
cvar_t *gl_ztrick;
@ -160,6 +155,9 @@ cvar_t *gl_3dlabs_broken;
cvar_t *r_fullscreen;
cvar_t *vid_gamma;
cvar_t *r_pause;
cvar_t *r_width;
cvar_t *r_height;
cvar_t *r_mode;
/*
=================
@ -553,7 +551,7 @@ void R_SetupFrame (void)
{
qglEnable( GL_SCISSOR_TEST );
qglClearColor( 0.3, 0.3, 0.3, 1 );
qglScissor( r_newrefdef.x, vid.height - r_newrefdef.height - r_newrefdef.y, r_newrefdef.width, r_newrefdef.height );
qglScissor( r_newrefdef.x, r_height->integer - r_newrefdef.height - r_newrefdef.y, r_newrefdef.width, r_newrefdef.height );
qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
qglClearColor( 1, 0, 0.5, 0.5 );
qglDisable( GL_SCISSOR_TEST );
@ -574,10 +572,10 @@ void R_SetupGL (void)
//
// set up viewport
//
x = floor(r_newrefdef.x * vid.width / vid.width);
x2 = ceil((r_newrefdef.x + r_newrefdef.width) * vid.width / vid.width);
y = floor(vid.height - r_newrefdef.y * vid.height / vid.height);
y2 = ceil(vid.height - (r_newrefdef.y + r_newrefdef.height) * vid.height / vid.height);
x = floor(r_newrefdef.x * r_width->integer / r_width->integer);
x2 = ceil((r_newrefdef.x + r_newrefdef.width) * r_width->integer / r_width->integer);
y = floor(r_height->integer - r_newrefdef.y * r_height->integer / r_height->integer);
y2 = ceil(r_height->integer - (r_newrefdef.y + r_newrefdef.height) * r_height->integer / r_height->integer);
w = x2 - x;
h = y - y2;
@ -736,8 +734,8 @@ void R_DrawPauseScreen( void )
int i, s, r, g, b;
qglFlush();
qglReadPixels(0, 0, vid.width, vid.height, GL_RGB, GL_UNSIGNED_BYTE, r_framebuffer);
for (i = 0; i < vid.width * vid.height * 3; i+=3)
qglReadPixels(0, 0, r_width->integer, r_height->integer, GL_RGB, GL_UNSIGNED_BYTE, r_framebuffer);
for (i = 0; i < r_width->integer * r_height->integer * 3; i+=3)
{
r = r_framebuffer[i+0];
g = r_framebuffer[i+1];
@ -752,13 +750,13 @@ void R_DrawPauseScreen( void )
// set custom orthogonal mode
qglMatrixMode(GL_PROJECTION);
qglLoadIdentity ();
qglOrtho(0, vid.width, 0, vid.height, 0, 1.0f);
qglOrtho(0, r_width->integer, 0, r_height->integer, 0, 1.0f);
qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity ();
qglDisable(GL_TEXTURE_2D);
qglRasterPos2f(0, 0);
qglDrawPixels(vid.width, vid.height, GL_RGB, GL_UNSIGNED_BYTE, r_framebuffer);
qglDrawPixels(r_width->integer, r_height->integer, GL_RGB, GL_UNSIGNED_BYTE, r_framebuffer);
qglFlush();
qglEnable(GL_TEXTURE_2D);
}
@ -776,10 +774,10 @@ void R_SetGL2D (void)
R_DrawPauseScreen();
// set 2D virtual screen size
qglViewport (0,0, vid.width, vid.height);
qglViewport (0,0, r_width->integer, r_height->integer);
qglMatrixMode(GL_PROJECTION);
qglLoadIdentity ();
qglOrtho(0, vid.width, vid.height, 0, -99999, 99999);
qglOrtho(0, r_width->integer, r_height->integer, 0, -99999, 99999);
qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity ();
qglDisable(GL_DEPTH_TEST);
@ -797,9 +795,9 @@ void R_SetGL2D (void)
qglColor4fv (v_blend);
VA_SetElem2(vert_array[0], 0, 0);
VA_SetElem2(vert_array[1], vid.width, 0);
VA_SetElem2(vert_array[2], vid.width, vid.height);
VA_SetElem2(vert_array[3], 0, vid.height);
VA_SetElem2(vert_array[1], r_width->integer, 0);
VA_SetElem2(vert_array[2], r_width->integer, r_height->integer);
VA_SetElem2(vert_array[3], 0, r_height->integer);
GL_LockArrays( 4 );
qglDrawArrays(GL_QUADS, 0, 4);
@ -825,14 +823,14 @@ void R_SetGL2D (void)
qglColor4f (1, 0, 0, r_motionblur_intens->value);
qglBegin(GL_QUADS);
qglTexCoord2f(0,vid.height);
qglTexCoord2f(0,r_height->integer);
qglVertex2f(0,0);
qglTexCoord2f(vid.width,vid.height);
qglVertex2f(vid.width,0);
qglTexCoord2f(vid.width,0);
qglVertex2f(vid.width,vid.height);
qglTexCoord2f(r_width->integer,r_height->integer);
qglVertex2f(r_width->integer,0);
qglTexCoord2f(r_width->integer,0);
qglVertex2f(r_width->integer,r_height->integer);
qglTexCoord2f(0,0);
qglVertex2f(0,vid.height);
qglVertex2f(0,r_height->integer);
qglEnd();
qglDisable(gl_state.tex_rectangle_type);
@ -840,7 +838,7 @@ void R_SetGL2D (void)
}
if (!blurtex) qglGenTextures(1,&blurtex);
qglBindTexture(gl_state.tex_rectangle_type,blurtex);
qglCopyTexImage2D(gl_state.tex_rectangle_type,0,GL_RGB,0,0,vid.width,vid.height,0);
qglCopyTexImage2D(gl_state.tex_rectangle_type,0,GL_RGB,0,0,r_width->integer,r_height->integer,0);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
@ -927,6 +925,11 @@ void R_Register( void )
r_speeds = Cvar_Get ("r_speeds", "0", 0);
r_pause = Cvar_Get("paused", "0", 0);
// must been already existing
r_width = Cvar_Get("width", "640", 0);
r_height = Cvar_Get("height", "480", 0);
r_mode = Cvar_Get( "r_mode", "0", CVAR_ARCHIVE );
r_loading = Cvar_Get("scr_loading", "0", 0 );
r_lightlevel = Cvar_Get ("r_lightlevel", "0", 0);
@ -961,13 +964,12 @@ void R_Register( void )
gl_modulate = Cvar_Get ("gl_modulate", "1", CVAR_ARCHIVE );
gl_log = Cvar_Get( "gl_log", "0", 0 );
gl_bitdepth = Cvar_Get( "gl_bitdepth", "0", 0 );
gl_mode = Cvar_Get( "gl_mode", "3", CVAR_ARCHIVE );
gl_lightmap = Cvar_Get ("gl_lightmap", "0", 0);
gl_shadows = Cvar_Get ("gl_shadows", "0", CVAR_ARCHIVE );
gl_dynamic = Cvar_Get ("gl_dynamic", "1", 0);
gl_nobind = Cvar_Get ("gl_nobind", "0", 0);
gl_round_down = Cvar_Get ("gl_round_down", "1", 0);
gl_picmip = Cvar_Get ("gl_picmip", "0", 0);
gl_skymip = Cvar_Get ("gl_skymip", "0", 0);
gl_showtris = Cvar_Get ("gl_showtris", "0", 0);
gl_ztrick = Cvar_Get ("gl_ztrick", "0", 0);
@ -985,7 +987,6 @@ void R_Register( void )
gl_vertex_arrays = Cvar_Get( "gl_vertex_arrays", "0", CVAR_ARCHIVE );
gl_ext_swapinterval = Cvar_Get( "gl_ext_swapinterval", "1", CVAR_ARCHIVE );
gl_ext_palettedtexture = Cvar_Get( "gl_ext_palettedtexture", "0", CVAR_ARCHIVE );
gl_ext_multitexture = Cvar_Get( "gl_ext_multitexture", "1", CVAR_ARCHIVE );
gl_ext_pointparameters = Cvar_Get( "gl_ext_pointparameters", "1", CVAR_ARCHIVE );
gl_ext_compiled_vertex_array = Cvar_Get( "gl_ext_compiled_vertex_array", "1", CVAR_ARCHIVE );
@ -997,8 +998,8 @@ void R_Register( void )
gl_3dlabs_broken = Cvar_Get( "gl_3dlabs_broken", "1", CVAR_ARCHIVE );
r_fullscreen = Cvar_Get( "r_fullscreen", "0", CVAR_ARCHIVE );
vid_gamma = Cvar_Get( "vid_gamma", "1.0", CVAR_ARCHIVE );
r_fullscreen = Cvar_Get( "fullscreen", "0", CVAR_ARCHIVE );
vid_gamma = Cvar_Get( "vid_gamma", "1", CVAR_ARCHIVE );
Cmd_AddCommand( "imagelist", R_ImageList_f );
Cmd_AddCommand( "modellist", Mod_Modellist_f );
@ -1018,38 +1019,38 @@ bool R_SetMode (void)
if ( r_fullscreen->modified && !gl_config.allow_cds )
{
MsgWarn("R_SetMode: CDS not allowed with this driver\n" );
ri.Cvar_SetValue( "r_fullscreen", !r_fullscreen->value );
Cvar_SetValue( "fullscreen", !r_fullscreen->value );
r_fullscreen->modified = false;
}
fullscreen = r_fullscreen->value;
r_fullscreen->modified = false;
gl_mode->modified = false;
r_mode->modified = false;
if ( ( err = GLimp_SetMode( &vid.width, &vid.height, gl_mode->value, fullscreen ) ) == rserr_ok )
if(( err = GLimp_SetMode( r_mode->integer, fullscreen )) == rserr_ok )
{
gl_state.prev_mode = gl_mode->value;
gl_state.prev_mode = r_mode->integer;
}
else
{
if ( err == rserr_invalid_fullscreen )
if( err == rserr_invalid_fullscreen )
{
ri.Cvar_SetValue( "r_fullscreen", 0);
Cvar_SetValue( "fullscreen", 0 );
r_fullscreen->modified = false;
MsgWarn("R_SetMode: fullscreen unavailable in this mode\n" );
if ( ( err = GLimp_SetMode( &vid.width, &vid.height, gl_mode->value, false ) ) == rserr_ok )
if (( err = GLimp_SetMode( r_mode->integer, false ) ) == rserr_ok )
return true;
}
else if ( err == rserr_invalid_mode )
else if( err == rserr_invalid_mode )
{
ri.Cvar_SetValue( "gl_mode", gl_state.prev_mode );
gl_mode->modified = false;
Cvar_SetValue( "r_mode", gl_state.prev_mode );
r_mode->modified = false;
MsgWarn("R_SetMode: invalid mode\n" );
}
// try setting it back to something safe
if ( ( err = GLimp_SetMode( &vid.width, &vid.height, gl_state.prev_mode, false ) ) != rserr_ok )
if(( err = GLimp_SetMode( gl_state.prev_mode, false )) != rserr_ok )
{
MsgWarn("R_SetMode: could not revert to safe mode\n" );
return false;
@ -1095,9 +1096,6 @@ int R_Init( void *hinstance, void *hWnd )
return false;
}
// set our "safe" modes
gl_state.prev_mode = 3;
// create the window and set up the context
if ( !R_SetMode () )
{
@ -1106,12 +1104,7 @@ int R_Init( void *hinstance, void *hWnd )
return false;
}
// FIXME: don't remove - renderer immediately crash without it
MsgDev(D_INFO, "Initializing render\n" );
ri.Vid_MenuInit();
// get our various GL strings
gl_config.vendor_string = qglGetString (GL_VENDOR);
MsgDev(D_INFO, "GL_VENDOR: %s\n", gl_config.vendor_string );
gl_config.renderer_string = qglGetString (GL_RENDERER);
@ -1264,7 +1257,7 @@ int R_Init( void *hinstance, void *hWnd )
Draw_InitLocal ();
R_StudioInit();
if(!r_framebuffer) r_framebuffer = Z_Malloc(vid.width*vid.height*3);
if(!r_framebuffer) r_framebuffer = Z_Malloc(r_width->integer*r_height->integer*3);
err = qglGetError();
if ( err != GL_NO_ERROR ) MsgWarn("glGetError = 0x%x\n", err);
@ -1279,9 +1272,9 @@ R_Shutdown
*/
void R_Shutdown (void)
{
ri.Cmd_RemoveCommand ("modellist");
ri.Cmd_RemoveCommand ("imagelist");
ri.Cmd_RemoveCommand ("gl_strings");
Cmd_RemoveCommand ("modellist");
Cmd_RemoveCommand ("imagelist");
Cmd_RemoveCommand ("gl_strings");
if(r_framebuffer) Z_Free(r_framebuffer);
@ -1331,10 +1324,10 @@ void R_BeginFrame( void )
/*
** go into 2D mode
*/
qglViewport (0,0, vid.width, vid.height);
qglViewport (0,0, r_width->integer, r_height->integer);
qglMatrixMode(GL_PROJECTION);
qglLoadIdentity ();
qglOrtho (0, vid.width, vid.height, 0, -99999, 99999);
qglOrtho (0, r_width->integer, r_height->integer, 0, -99999, 99999);
qglMatrixMode(GL_MODELVIEW);
qglLoadIdentity ();
qglDisable (GL_DEPTH_TEST);
@ -1534,7 +1527,6 @@ render_exp_t DLLEXPORT *CreateAPI(stdlib_api_t *input, render_imp_t *engfuncs )
re.Init = R_Init;
re.Shutdown = R_Shutdown;
re.AppActivate = GLimp_AppActivate;
re.BeginRegistration = R_BeginRegistration;
re.RegisterModel = R_RegisterModel;

View File

@ -393,10 +393,7 @@ void R_RenderBrushPoly (msurface_t *fa)
// warp texture, no lightmaps
GL_TexEnv( GL_MODULATE );
qglColor4f( gl_state.inverse_intensity,
gl_state.inverse_intensity,
gl_state.inverse_intensity,
1.0F );
qglColor4f( gl_state.inverse_intensity, gl_state.inverse_intensity, gl_state.inverse_intensity, 1.0F );
EmitWaterPolys (fa);
GL_TexEnv( GL_REPLACE );
@ -444,7 +441,7 @@ dynamic:
{
if ( ( fa->styles[maps] >= 32 || fa->styles[maps] == 0 ) && ( fa->dlightframe != r_framecount ) )
{
unsigned temp[34*34];
uint temp[34*34];
int smax, tmax;
smax = (fa->extents[0]>>4)+1;
@ -495,7 +492,7 @@ void R_DrawAlphaSurfaces (void)
//
// go back to the world matrix
//
qglLoadMatrixf (r_world_matrix);
qglLoadMatrixf (r_world_matrix);
qglEnable (GL_BLEND);
GL_TexEnv( GL_MODULATE );
@ -1677,7 +1674,7 @@ void GL_DrawRadar( void )
if(r_newrefdef.rdflags & RDF_NOWORLDMODEL ) return;
if(!r_minimap->value) return;
qglViewport(vid.width - r_minimap_size->value, 0, r_minimap_size->value, r_minimap_size->value );
qglViewport(r_width->integer - r_minimap_size->value, 0, r_minimap_size->value, r_minimap_size->value );
GL_DisableAlphaTest();
GL_DisableDepthTest();
@ -1807,7 +1804,7 @@ void GL_DrawRadar( void )
GL_DisableTexGen();
qglPopMatrix();
qglViewport(0.0f, 0.0f, vid.width, vid.height);
qglViewport(0.0f, 0.0f, r_width->integer, r_height->integer);
qglMatrixMode(GL_PROJECTION);
qglPopMatrix();

View File

@ -606,23 +606,10 @@ void R_SetSky (char *name, float rotate, vec3_t axis)
skyrotate = rotate;
VectorCopy(axis, skyaxis);
// chop down rotating skies for less memory
if (gl_skymip->value || skyrotate) gl_picmip->value += 6;
sprintf (pathname, "cubemaps/env/%s", skyname);
sky_image = R_FindImage (pathname, NULL, 0, it_sky);
if (!sky_image) sky_image = r_notexture;
if (gl_skymip->value || skyrotate)
{
// take less memory
gl_picmip->value -= 6;
sky_min = 1.0/256;
sky_max = 255.0/256;
}
else
{
sky_min = 1.0/512;
sky_max = 511.0/512;
}
sky_min = 1.0/512;
sky_max = 511.0/512;
}

View File

@ -40,6 +40,53 @@ bool GLimp_InitGL (void);
glwstate_t glw_state;
static char wndname[128];
#define num_vidmodes ((int)(sizeof(vidmode) / sizeof(vidmode[0])) - 1)
typedef struct vidmode_s
{
const char *desc;
int width;
int height;
float pixelheight;
} vidmode_t;
vidmode_t vidmode[] =
{
{"Mode 0: 4x3", 640, 480, 1 },
{"Mode 1: 4x3", 800, 600, 1 },
{"Mode 2: 4x3", 1024, 768, 1 },
{"Mode 3: 4x3", 1152, 864, 1 },
{"Mode 4: 4x3", 1280, 960, 1 },
{"Mode 5: 4x3", 1400, 1050, 1 },
{"Mode 6: 4x3", 1600, 1200, 1 },
{"Mode 7: 4x3", 1920, 1440, 1 },
{"Mode 8: 4x3", 2048, 1536, 1 },
{"Mode 9: 14x9", 840, 540, 1 },
{"Mode 10: 14x9", 1680, 1080, 1 },
{"Mode 11: 16x9", 640, 360, 1 },
{"Mode 12: 16x9", 683, 384, 1 },
{"Mode 13: 16x9", 960, 540, 1 },
{"Mode 14: 16x9", 1280, 720, 1 },
{"Mode 15: 16x9", 1366, 768, 1 },
{"Mode 16: 16x9", 1920, 1080, 1 },
{"Mode 17: 16x9", 2560, 1440, 1 },
{"Mode 18: NTSC", 360, 240, 1.125 },
{"Mode 19: NTSC", 720, 480, 1.125 },
{"Mode 20: PAL ", 360, 283, 0.9545 },
{"Mode 21: PAL ", 720, 566, 0.9545 },
{NULL, 0, 0, 0 },
};
void R_GetVideoMode( int vid_mode )
{
int i = bound(0, vid_mode, num_vidmodes); // check range
Cvar_SetValue("width", vidmode[i].width );
Cvar_SetValue("height", vidmode[i].height );
Cvar_SetValue("r_mode", i ); // merge if out of bounds
MsgDev(D_NOTE, "Set: %s [%dx%d]\n", vidmode[i].desc, vidmode[i].width, vidmode[i].height );
}
static bool VerifyDriver( void )
{
char buffer[1024];
@ -117,8 +164,8 @@ bool VID_CreateWindow( int width, int height, bool fullscreen )
}
else
{
r_xpos = Cvar_Get ("r_xpos", "0", 0);
r_ypos = Cvar_Get ("r_ypos", "0", 0);
r_xpos = Cvar_Get ("r_xpos", "3", 0);
r_ypos = Cvar_Get ("r_ypos", "22", 0);
x = r_xpos->value;
y = r_ypos->value;
}
@ -143,10 +190,6 @@ bool VID_CreateWindow( int width, int height, bool fullscreen )
SetForegroundWindow( glw_state.hWnd );
SetFocus( glw_state.hWnd );
// let the sound and input subsystems know about the new window
ri.Vid_NewWindow (width, height);
return true;
}
@ -154,27 +197,20 @@ bool VID_CreateWindow( int width, int height, bool fullscreen )
/*
** GLimp_SetMode
*/
rserr_t GLimp_SetMode( int *pwidth, int *pheight, int mode, bool fullscreen )
rserr_t GLimp_SetMode( int vid_mode, bool fullscreen )
{
int width, height;
const char *win_fs[] = { "W", "FS" };
if ( !ri.Vid_GetModeInfo( &width, &height, mode ) )
{
Msg(" invalid mode\n" );
return rserr_invalid_mode;
}
R_GetVideoMode( vid_mode );
MsgDev(D_INFO, "Initializing OpenGL: %d %d %s\n", width, height, win_fs[fullscreen] );
width = r_width->integer;
height = r_height->integer;
// destroy the existing window
if (glw_state.hWnd)
{
GLimp_Shutdown();
}
if (glw_state.hWnd) GLimp_Shutdown();
// do a CDS if needed
if ( fullscreen )
if( fullscreen )
{
DEVMODE dm;
@ -197,23 +233,17 @@ rserr_t GLimp_SetMode( int *pwidth, int *pheight, int mode, bool fullscreen )
ReleaseDC( 0, hdc );
}
if ( ChangeDisplaySettings( &dm, CDS_FULLSCREEN ) == DISP_CHANGE_SUCCESSFUL )
if( ChangeDisplaySettings( &dm, CDS_FULLSCREEN ) == DISP_CHANGE_SUCCESSFUL )
{
*pwidth = width;
*pheight = height;
gl_state.fullscreen = true;
if ( !VID_CreateWindow (width, height, true) )
if( !VID_CreateWindow (width, height, true) )
return rserr_invalid_mode;
return rserr_ok;
}
else
{
*pwidth = width;
*pheight = height;
dm.dmPelsWidth = width * 2;
dm.dmPelsHeight = height;
dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
@ -232,8 +262,6 @@ rserr_t GLimp_SetMode( int *pwidth, int *pheight, int mode, bool fullscreen )
{
ChangeDisplaySettings( 0, 0 );
*pwidth = width;
*pheight = height;
gl_state.fullscreen = false;
if ( !VID_CreateWindow (width, height, false) )
return rserr_invalid_mode;
@ -253,8 +281,6 @@ rserr_t GLimp_SetMode( int *pwidth, int *pheight, int mode, bool fullscreen )
{
ChangeDisplaySettings( 0, 0 );
*pwidth = width;
*pheight = height;
gl_state.fullscreen = false;
if ( !VID_CreateWindow (width, height, false) )
return rserr_invalid_mode;
@ -500,7 +526,7 @@ void GLimp_BeginFrame( void )
{
if ( gl_bitdepth->value != 0 && !glw_state.allowdisplaydepthchange )
{
ri.Cvar_SetValue( "gl_bitdepth", 0 );
Cvar_SetValue( "gl_bitdepth", 0 );
Msg("gl_bitdepth requires Win95 OSR2.x or WinNT 4.x\n" );
}
gl_bitdepth->modified = false;
@ -527,22 +553,4 @@ void GLimp_EndFrame (void)
if ( !qwglSwapBuffers( glw_state.hDC ) )
Sys_Error("GLimp_EndFrame() - SwapBuffers() failed!\n" );
}
}
/*
** GLimp_AppActivate
*/
void GLimp_AppActivate( bool active )
{
if ( active )
{
SetForegroundWindow( glw_state.hWnd );
ShowWindow( glw_state.hWnd, SW_RESTORE );
}
else
{
if ( r_fullscreen->value )
ShowWindow( glw_state.hWnd, SW_MINIMIZE );
}
}
}

View File

@ -571,7 +571,7 @@ void VID_UpdateGamma(bool force, int rampsize)
return;
f = bound(0.1, v_gamma->value, 2.5);
if (v_gamma->value != f) ri.Cvar_SetValue("v_gamma", f);
if (v_gamma->value != f) Cvar_SetValue("v_gamma", f);
cachehwgamma = vid_activewindow ? v_hwgamma->value : 0;
@ -597,7 +597,7 @@ void VID_UpdateGamma(bool force, int rampsize)
BuildGammaTable16(1.0f, cachegamma, 1.0f, 1.0f, vid_gammaramps + vid_gammarampsize * 2, rampsize);
// set vid_hardwaregammasupported to true if VID_SetGamma succeeds, OR if vid_hwgamma is >= 2 (forced gamma - ignores driver return value)
ri.Cvar_SetValue("vid_hardwaregammasupported", VID_SetGamma(vid_gammaramps, vid_gammarampsize) || cachehwgamma >= 2);
Cvar_SetValue("vid_hardwaregammasupported", VID_SetGamma(vid_gammaramps, vid_gammarampsize) || cachehwgamma >= 2);
// if custom gamma ramps failed (Windows stupidity), restore to system gamma
if(!vid_hardwaregammasupported->value)
{
@ -623,7 +623,7 @@ void VID_RestoreSystemGamma(void)
if (vid_usinghwgamma)
{
vid_usinghwgamma = false;
ri.Cvar_SetValue("vid_hardwaregammasupported", VID_SetGamma(vid_systemgammaramps, vid_gammarampsize));
Cvar_SetValue("vid_hardwaregammasupported", VID_SetGamma(vid_systemgammaramps, vid_gammarampsize));
// force gamma situation to be reexamined next frame
gamma_forcenextframe = true;
}
@ -637,18 +637,18 @@ bool VID_ScreenShot( const char *filename, bool force_gamma )
if(!r_framebuffer) return false;
// get screen frame
qglReadPixels(0, 0, vid.width, vid.height, GL_RGB, GL_UNSIGNED_BYTE, r_framebuffer );
qglReadPixels(0, 0, r_width->integer, r_height->integer, GL_RGB, GL_UNSIGNED_BYTE, r_framebuffer );
memset(&r_shot, 0, sizeof(r_shot));
r_shot.width = vid.width;
r_shot.height = vid.height;
r_shot.width = r_width->integer;
r_shot.height = r_height->integer;
r_shot.type = PF_RGB_24_FLIP;
r_shot.numMips = 1;
r_shot.palette = NULL;
r_shot.buffer = r_framebuffer;
// remove any gamma adjust if need
if(force_gamma) VID_ImageBaseScale( (uint *)r_framebuffer, vid.width, vid.height );
if(force_gamma) VID_ImageBaseScale( (uint *)r_framebuffer, r_width->integer, r_height->integer );
// write image
FS_SaveImage( filename, &r_shot );

View File

@ -135,7 +135,7 @@ void R_Bloom_InitEffectTexture( void )
memset(&r_bloomfx, 0, sizeof(rgbdata_t));
if( (int)r_bloom_sample_size->value < 32 )
ri.Cvar_SetValue ("r_bloom_sample_size", 32);
Cvar_SetValue ("r_bloom_sample_size", 32);
//make sure bloom size is a power of 2
BLOOM_SIZE = (int)r_bloom_sample_size->value;
@ -154,7 +154,7 @@ void R_Bloom_InitEffectTexture( void )
BLOOM_SIZE = min( screen_texture_width, screen_texture_height );
if( BLOOM_SIZE != (int)r_bloom_sample_size->value )
ri.Cvar_SetValue ("r_bloom_sample_size", BLOOM_SIZE);
Cvar_SetValue ("r_bloom_sample_size", BLOOM_SIZE);
data = Z_Malloc( BLOOM_SIZE * BLOOM_SIZE * 4 );
@ -186,8 +186,8 @@ void R_Bloom_InitTextures( void )
memset(&r_downsample, 0, sizeof(rgbdata_t));
//find closer power of 2 to screen size
for (screen_texture_width = 1; screen_texture_width < vid.width; screen_texture_width *= 2);
for (screen_texture_height = 1; screen_texture_height < vid.height; screen_texture_height *= 2);
for (screen_texture_width = 1; screen_texture_width < r_width->integer; screen_texture_width *= 2);
for (screen_texture_height = 1; screen_texture_height < r_height->integer; screen_texture_height *= 2);
//init the screen texture
size = screen_texture_width * screen_texture_height * 4;
@ -211,7 +211,7 @@ void R_Bloom_InitTextures( void )
//if screensize is more than 2x the bloom effect texture, set up for stepped downsampling
r_bloomdownsamplingtexture = NULL;
r_screendownsamplingtexture_size = 0;
if( vid.width > (BLOOM_SIZE * 2) && !r_bloom_fast_sample->value )
if( r_width->integer > (BLOOM_SIZE * 2) && !r_bloom_fast_sample->value )
{
r_screendownsamplingtexture_size = (int)(BLOOM_SIZE * 2);
data = Z_Malloc( r_screendownsamplingtexture_size * r_screendownsamplingtexture_size * 4 );
@ -307,7 +307,7 @@ void R_Bloom_GeneratexDiamonds( void )
if( r_bloom_diamond_size->value > 7 || r_bloom_diamond_size->value <= 3)
{
if( (int)r_bloom_diamond_size->value != 8 ) ri.Cvar_SetValue( "r_bloom_diamond_size", 8 );
if( (int)r_bloom_diamond_size->value != 8 ) Cvar_SetValue( "r_bloom_diamond_size", 8 );
for(i=0; i<r_bloom_diamond_size->value; i++) {
for(j=0; j<r_bloom_diamond_size->value; j++) {
@ -319,7 +319,7 @@ void R_Bloom_GeneratexDiamonds( void )
}
} else if( r_bloom_diamond_size->value > 5 ) {
if( r_bloom_diamond_size->value != 6 ) ri.Cvar_SetValue( "r_bloom_diamond_size", 6 );
if( r_bloom_diamond_size->value != 6 ) Cvar_SetValue( "r_bloom_diamond_size", 6 );
for(i=0; i<r_bloom_diamond_size->value; i++) {
for(j=0; j<r_bloom_diamond_size->value; j++) {
@ -331,7 +331,7 @@ void R_Bloom_GeneratexDiamonds( void )
}
} else if( r_bloom_diamond_size->value > 3 ) {
if( (int)r_bloom_diamond_size->value != 4 ) ri.Cvar_SetValue( "r_bloom_diamond_size", 4 );
if( (int)r_bloom_diamond_size->value != 4 ) Cvar_SetValue( "r_bloom_diamond_size", 4 );
for(i=0; i<r_bloom_diamond_size->value; i++) {
for(j=0; j<r_bloom_diamond_size->value; j++) {
@ -346,10 +346,10 @@ void R_Bloom_GeneratexDiamonds( void )
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height);
//restore full screen workspace
qglViewport( 0, 0, vid.width, vid.height );
qglViewport( 0, 0, r_width->integer, r_height->integer );
qglMatrixMode( GL_PROJECTION );
qglLoadIdentity ();
qglOrtho(0, vid.width, vid.height, 0, -10, 100);
qglOrtho(0, r_width->integer, r_height->integer, 0, -10, 100);
qglMatrixMode( GL_MODELVIEW );
qglLoadIdentity ();
}
@ -372,8 +372,8 @@ void R_Bloom_DownsampleView( void )
//copy the screen and draw resized
GL_Bind(r_bloomscreentexture->texnum[0]);
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, vid.height - (curView_y + curView_height), curView_width, curView_height);
R_Bloom_Quad( 0, vid.height-midsample_height, midsample_width, midsample_height, screenText_tcw, screenText_tch );
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, r_height->integer - (curView_y + curView_height), curView_width, curView_height);
R_Bloom_Quad( 0, r_height->integer-midsample_height, midsample_width, midsample_height, screenText_tcw, screenText_tch );
//now copy into Downsampling (mid-sized) texture
GL_Bind(r_bloomdownsamplingtexture->texnum[0]);
@ -381,22 +381,22 @@ void R_Bloom_DownsampleView( void )
//now draw again in bloom size
qglColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
R_Bloom_Quad( 0, vid.height-sample_height, sample_width, sample_height, sampleText_tcw, sampleText_tch );
R_Bloom_Quad( 0, r_height->integer-sample_height, sample_width, sample_height, sampleText_tcw, sampleText_tch );
//now blend the big screen texture into the bloom generation space (hoping it adds some blur)
qglEnable( GL_BLEND );
qglBlendFunc(GL_ONE, GL_ONE);
qglColor4f( 0.5f, 0.5f, 0.5f, 1.0f );
GL_Bind(r_bloomscreentexture->texnum[0]);
R_Bloom_Quad( 0, vid.height-sample_height, sample_width, sample_height, screenText_tcw, screenText_tch );
R_Bloom_Quad( 0, r_height->integer-sample_height, sample_width, sample_height, screenText_tcw, screenText_tch );
qglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
qglDisable( GL_BLEND );
} else { //downsample simple
GL_Bind(r_bloomscreentexture->texnum[0]);
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, vid.height - (curView_y + curView_height), curView_width, curView_height);
R_Bloom_Quad( 0, vid.height-sample_height, sample_width, sample_height, screenText_tcw, screenText_tch );
qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, curView_x, r_height->integer - (curView_y + curView_height), curView_width, curView_height);
R_Bloom_Quad( 0, r_height->integer-sample_height, sample_width, sample_height, screenText_tcw, screenText_tch );
}
}
@ -414,11 +414,11 @@ void R_BloomBlend ( refdef_t *fd )
return;
//set up full screen workspace
qglViewport( 0, 0, vid.width, vid.height );
qglViewport( 0, 0, r_width->integer, r_height->integer );
qglDisable( GL_DEPTH_TEST );
qglMatrixMode( GL_PROJECTION );
qglLoadIdentity ();
qglOrtho(0, vid.width, vid.height, 0, -10, 100);
qglOrtho(0, r_width->integer, r_height->integer, 0, -10, 100);
qglMatrixMode( GL_MODELVIEW );
qglLoadIdentity ();
qglDisable(GL_CULL_FACE);
@ -461,7 +461,7 @@ void R_BloomBlend ( refdef_t *fd )
GL_Bind(r_bloombackuptexture->texnum[0]);
qglColor4f( 1, 1, 1, 1 );
R_Bloom_Quad( 0,
vid.height - (r_screenbackuptexture_size * sampleText_tch),
r_height->integer - (r_screenbackuptexture_size * sampleText_tch),
r_screenbackuptexture_size * sampleText_tcw,
r_screenbackuptexture_size * sampleText_tch,
sampleText_tcw, sampleText_tch );

View File

@ -15,7 +15,6 @@
image_t gltextures[MAX_GLTEXTURES];
int numgltextures;
byte intensitytable[256];
extern cvar_t *gl_picmip;
cvar_t *gl_maxsize;
byte *r_imagepool;
byte *imagebuffer;
@ -120,7 +119,7 @@ void R_ImageList_f (void)
}
Msg( " %3i %3i %s: %s\n", image->width, image->height, palstrings[image->paletted], image->name);
}
Msg( "Total images count (not counting mipmaps): %i\n", numgltextures);
Msg( "Total images count (without mipmaps): %i\n", numgltextures);
}
void R_SetPixelFormat( int width, int height, int depth )
@ -232,7 +231,7 @@ bool R_GetPixelFormat( rgbdata_t *pic, imagetype_t type )
}
// can use gl extension ?
R_RoundImageDimensions(&w, &h, (image_desc.flags & IMAGE_GEN_MIPS));
R_RoundImageDimensions(&w, &h);
if(w == image_desc.width && h == image_desc.height) use_gl_extension = true;
else use_gl_extension = false;
@ -307,7 +306,7 @@ void R_InitTextures( void )
gl_maxsize = Cvar_Get ("gl_maxsize", "0", 0);
qglGetIntegerv(GL_MAX_TEXTURE_SIZE, &texsize);
if (gl_maxsize->value > texsize) ri.Cvar_SetValue ("gl_maxsize", texsize);
if (gl_maxsize->value > texsize) Cvar_SetValue ("gl_maxsize", texsize);
if(texsize < 2048) imagebufsize = 2048*2048*4;
else imagebufsize = texsize * texsize * 4;
@ -321,7 +320,7 @@ void R_InitTextures( void )
// init intensity conversions
intensity = Cvar_Get ("intensity", "2", 0);
if ( intensity->value <= 1 ) ri.Cvar_Set( "intensity", "1" );
if ( intensity->value <= 1 ) Cvar_SetValue( "intensity", 1 );
gl_state.inverse_intensity = 1 / intensity->value;
for (i = 0; i < 256; i++)
@ -452,7 +451,7 @@ void R_FilterTexture (int filterindex, uint *data, int width, int height, float
Z_Free (temp); // release the temp buffer
}
void R_RoundImageDimensions(int *scaled_width, int *scaled_height, bool mipmap)
void R_RoundImageDimensions(int *scaled_width, int *scaled_height )
{
int width = *scaled_width;
int height = *scaled_height;
@ -460,12 +459,6 @@ void R_RoundImageDimensions(int *scaled_width, int *scaled_height, bool mipmap)
*scaled_width = nearest_pow( *scaled_width );
*scaled_height = nearest_pow( *scaled_height);
if (mipmap)
{
*scaled_width >>= (int)gl_picmip->value;
*scaled_height >>= (int)gl_picmip->value;
}
if (gl_maxsize->value)
{
if (*scaled_width > gl_maxsize->value) *scaled_width = gl_maxsize->value;
@ -970,7 +963,7 @@ bool qrsCompressedTexImage2D( uint target, int level, int internalformat, uint w
scaled_width = w;
scaled_height = h;
R_RoundImageDimensions(&scaled_width, &scaled_height, mipmap );
R_RoundImageDimensions(&scaled_width, &scaled_height );
// upload base image or miplevel
samples = (has_alpha) ? gl_tex_alpha_format : gl_tex_solid_format;
@ -1027,7 +1020,7 @@ bool R_LoadTexImage( uint *data )
scaled_width = image_desc.width;
scaled_height = image_desc.height;
R_RoundImageDimensions(&scaled_width, &scaled_height, mipmap);
R_RoundImageDimensions(&scaled_width, &scaled_height);
samples = (image_desc.flags & IMAGE_HAS_ALPHA) ? gl_tex_alpha_format : gl_tex_solid_format;
@ -1391,7 +1384,7 @@ bool R_StoreImageARGB( uint target, int level, uint width, uint height, uint ima
}
scaled_width = w;
scaled_height = h;
R_RoundImageDimensions(&scaled_width, &scaled_height, mipmap );
R_RoundImageDimensions(&scaled_width, &scaled_height );
// upload base image or miplevel
samples = (image_desc.flags & IMAGE_HAS_ALPHA) ? gl_tex_alpha_format : gl_tex_solid_format;