Created
August 19, 2016 12:26
-
-
Save mittorn/fe355ea00739e1909d2c231333057839 to your computer and use it in GitHub Desktop.
This file has been truncated, but you can view the full file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Только в engine/: Android.mk | |
diff --suppress-blank-empty -prudwEZbB engine/cdll_exp.h /mnt/data/Xash3D_original/engine/cdll_exp.h | |
--- engine/cdll_exp.h 2016-01-18 16:21:32.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/cdll_exp.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -15,10 +15,6 @@ GNU General Public License for more deta | |
#ifndef CDLL_EXP_H | |
#define CDLL_EXP_H | |
-struct tempent_s; | |
-struct engine_studio_api_s; | |
-struct r_studio_interface_s; | |
- | |
// NOTE: ordering is important! | |
typedef struct cldll_func_s | |
{ | |
@@ -68,10 +64,6 @@ typedef struct cldll_func_s | |
// Xash3D extension | |
int (*pfnGetRenderInterface)( int version, render_api_t *renderfuncs, render_interface_t *callback ); | |
void (*pfnClipMoveToEntity)( struct physent_s *pe, const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, struct pmtrace_s *tr ); | |
- // More extenstions for the extensions god! (SDL Xash port) | |
- int (*pfnTouchEvent)( int fingerID, float x, float y, float dx, float dy ); | |
- void (*pfnMoveEvent)( float forwardmove, float sidemove ); | |
- void (*pfnLookEvent)( float relyaw, float relpitch ); | |
} cldll_func_t; | |
#endif//CDLL_EXP_H | |
diff --suppress-blank-empty -prudwEZbB engine/cdll_int.h /mnt/data/Xash3D_original/engine/cdll_int.h | |
--- engine/cdll_int.h 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/cdll_int.h 2016-02-24 20:13:28.000000000 +0000 | |
@@ -27,7 +27,6 @@ extern "C" { | |
#endif | |
#include "const.h" | |
-#include <stdint.h> | |
#define MAX_ALIAS_NAME 32 | |
@@ -107,12 +106,9 @@ typedef struct hud_player_info_s | |
short topcolor; | |
short bottomcolor; | |
- uint64_t m_nSteamID; | |
+ unsigned long long m_nSteamID; | |
} hud_player_info_t; | |
-struct screenfade_s; | |
-struct tagPOINT; | |
- | |
typedef struct cl_enginefuncs_s | |
{ | |
// sprite handlers | |
@@ -209,7 +205,7 @@ typedef struct cl_enginefuncs_s | |
void (*pfnPlaybackEvent)( int flags, const struct edict_s *pInvoker, unsigned short eventindex, float delay, float *origin, float *angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2 ); | |
void (*pfnWeaponAnim)( int iAnim, int body ); | |
float (*pfnRandomFloat)( float flLow, float flHigh ); | |
- int (*pfnRandomLong)( int lLow, int lHigh ); | |
+ long (*pfnRandomLong)( long lLow, long lHigh ); | |
void (*pfnHookEvent)( char *name, void ( *pfnEvent )( struct event_args_s *args )); | |
int (*Con_IsVisible) (); | |
const char *(*pfnGetGameDirectory)( void ); | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_cmds.c /mnt/data/Xash3D_original/engine/client/cl_cmds.c | |
--- engine/client/cl_cmds.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_cmds.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,7 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -328,13 +327,13 @@ void CL_LevelShot_f( void ) | |
if( cls.scrshot_request != scrshot_plaque ) return; | |
cls.scrshot_request = scrshot_inactive; | |
- // check for existence | |
+ // check for exist | |
if( cls.demoplayback && ( cls.demonum != -1 )) | |
{ | |
Q_sprintf( cls.shotname, "levelshots/%s_%s.bmp", cls.demoname, glState.wideScreen ? "16x9" : "4x3" ); | |
Q_snprintf( filename, sizeof( filename ), "demos/%s.dem", cls.demoname ); | |
- // make sure that levelshot is newer than demo | |
+ // make sure what levelshot is newer than demo | |
ft1 = FS_FileTime( filename, false ); | |
ft2 = FS_FileTime( cls.shotname, true ); | |
} | |
@@ -342,13 +341,13 @@ void CL_LevelShot_f( void ) | |
{ | |
Q_sprintf( cls.shotname, "levelshots/%s_%s.bmp", clgame.mapname, glState.wideScreen ? "16x9" : "4x3" ); | |
- // make sure that levelshot is newer than bsp | |
+ // make sure what levelshot is newer than bsp | |
ft1 = FS_FileTime( cl.worldmodel->name, false ); | |
ft2 = FS_FileTime( cls.shotname, true ); | |
} | |
- // missing levelshot or level newer than levelshot | |
- if( ft2 == (unsigned long)-1 || ft1 > ft2 ) | |
+ // missing levelshot or level never than levelshot | |
+ if( ft2 == -1 || ft1 > ft2 ) | |
cls.scrshot_action = scrshot_plaque; // build new frame for levelshot | |
else cls.scrshot_action = scrshot_inactive; // disable - not needs | |
} | |
@@ -492,5 +491,3 @@ void SCR_Viewpos_f( void ) | |
Msg( "org ( %g %g %g )\n", cl.refdef.vieworg[0], cl.refdef.vieworg[1], cl.refdef.vieworg[2] ); | |
Msg( "ang ( %g %g %g )\n", cl.refdef.viewangles[0], cl.refdef.viewangles[1], cl.refdef.viewangles[2] ); | |
} | |
- | |
-#endif //XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_demo.c /mnt/data/Xash3D_original/engine/client/cl_demo.c | |
--- engine/client/cl_demo.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_demo.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "net_encode.h" | |
@@ -460,7 +458,7 @@ void CL_DrawDemoRecording( void ) | |
return; | |
pos = FS_Tell( cls.demofile ); | |
- Q_snprintf( string, sizeof( string ), "RECORDING %s: %ik", cls.demoname, (int)(pos / 1024) ); | |
+ Q_snprintf( string, sizeof( string ), "RECORDING %s: %ik", cls.demoname, pos / 1024 ); | |
Con_DrawStringLen( string, &len, NULL ); | |
Con_DrawString(( scr_width->integer - len) >> 1, scr_height->integer >> 2, string, color ); | |
@@ -677,7 +675,7 @@ reads demo data and write it to client | |
qboolean CL_DemoReadMessage( byte *buffer, size_t *length ) | |
{ | |
float f = 0.0f; | |
- int curpos = 0; | |
+ long curpos = 0; | |
float fElapsedTime = 0.0f; | |
qboolean swallowmessages = true; | |
byte *userbuf = NULL; | |
@@ -1154,7 +1152,7 @@ void CL_PlayDemo_f( void ) | |
demo.starttime = CL_GetDemoPlaybackClock(); // for determining whether to read another message | |
- Netchan_Setup( NS_CLIENT, &cls.netchan, net_from, net_qport->integer ); | |
+ Netchan_Setup( NS_CLIENT, &cls.netchan, net_from, Cvar_VariableValue( "net_qport" )); | |
demo.framecount = 0; | |
cls.lastoutgoingcommand = -1; | |
@@ -1252,4 +1250,3 @@ void CL_Stop_f( void ) | |
S_StopBackgroundTrack(); | |
} | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_events.c /mnt/data/Xash3D_original/engine/client/cl_events.c | |
--- engine/client/cl_events.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_events.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "event_flags.h" | |
@@ -88,7 +86,7 @@ CL_EventIndex | |
*/ | |
const char *CL_IndexEvent( word index ) | |
{ | |
- if( index >= MAX_EVENTS ) | |
+ if( index < 0 || index >= MAX_EVENTS ) | |
return 0; | |
return cl.event_precache[index]; | |
@@ -137,19 +135,6 @@ qboolean CL_FireEvent( event_info_t *ei | |
if( !ei || !ei->index ) | |
return false; | |
- if( cl_trace_events->value > 0.0f ) | |
- { | |
- MsgDev( D_INFO, "^3EVENT %s AT %.2f %.2f %.2f\n" // event name | |
- " %.2f %.2f\n" // float params | |
- " %i %i\n" // int params | |
- " %s %s\n", // bool params | |
- cl.event_precache[ bound( 1, ei->index, MAX_EVENTS )], ei->args.origin[0], ei->args.origin[1], ei->args.origin[2], | |
- ei->args.fparam1, ei->args.fparam2, | |
- ei->args.iparam1, ei->args.iparam2, | |
- ei->args.bparam1 ? "TRUE" : "FALSE", ei->args.bparam2 ? "TRUE" : "FALSE" ); | |
- | |
- } | |
- | |
// get the func pointer | |
for( i = 0; i < MAX_EVENTS; i++ ) | |
{ | |
@@ -410,12 +395,6 @@ void CL_ParseEvent( sizebuf_t *msg ) | |
args.angles[PITCH] = -state->angles[PITCH] * 3; | |
args.angles[YAW] = state->angles[YAW]; | |
args.angles[ROLL] = 0; // no roll | |
- | |
- // if we restore origin and velocity everytime, why don't do it here also? | |
- if( VectorIsNull( args.origin )) | |
- VectorCopy( state->origin, args.origin ); | |
- if( VectorIsNull( args.velocity )) | |
- VectorCopy( state->velocity, args.velocity ); | |
} | |
} | |
else if( state ) | |
@@ -464,14 +443,6 @@ void CL_PlaybackEvent( int flags, const | |
MsgDev( D_ERROR, "CL_PlaybackEvent: invalid eventindex %i\n", eventindex ); | |
return; | |
} | |
- | |
- | |
- if( flags & FEV_SERVER ) | |
- { | |
- MsgDev( D_WARN, "CL_PlaybackEvent: event with FEV_SERVER flag!\n" ); | |
- return; | |
- } | |
- | |
// check event for precached | |
if( !CL_EventIndex( cl.event_precache[eventindex] )) | |
{ | |
@@ -488,18 +459,15 @@ void CL_PlaybackEvent( int flags, const | |
args.flags = 0; | |
args.entindex = invokerIndex; | |
- if( !angles || VectorIsNull( angles )) | |
+// TODO: restore checks when predicting will be done | |
+// if( !angles || VectorIsNull( angles )) | |
VectorCopy( cl.refdef.cl_viewangles, args.angles ); | |
- else | |
- VectorCopy( angles, args.angles ); | |
- if( !origin || VectorIsNull( origin )) | |
- VectorCopy( cl.predicted.origin, args.origin ); | |
- else | |
- VectorCopy( origin, args.origin ); | |
+// if( !origin || VectorIsNull( origin )) | |
+ VectorCopy( cl.frame.client.origin, args.origin ); | |
- VectorCopy( cl.predicted.velocity, args.velocity ); | |
- args.ducking = cl.predicted.usehull == 1; | |
+ VectorCopy( cl.frame.client.velocity, args.velocity ); | |
+ args.ducking = cl.frame.client.bInDuck; | |
args.fparam1 = fparam1; | |
args.fparam2 = fparam2; | |
@@ -510,4 +478,3 @@ void CL_PlaybackEvent( int flags, const | |
CL_QueueEvent( flags, eventindex, delay, &args ); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_frame.c /mnt/data/Xash3D_original/engine/client/cl_frame.c | |
--- engine/client/cl_frame.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_frame.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "net_encode.h" | |
@@ -125,7 +123,7 @@ qboolean CL_FindInterpolationUpdates( cl | |
int CL_InterpolateModel( cl_entity_t *e ) | |
{ | |
- position_history_t *ph0 = NULL, *ph1 = NULL; | |
+ position_history_t *ph0, *ph1; | |
vec3_t origin, angles, delta; | |
float t, t1, t2, frac; | |
int i; | |
@@ -133,15 +131,13 @@ int CL_InterpolateModel( cl_entity_t *e | |
VectorCopy( e->curstate.origin, e->origin ); | |
VectorCopy( e->curstate.angles, e->angles ); | |
- if ( cls.timedemo || !e->model || e->model->name[0] == '*' && !r_bmodelinterp->value || RP_LOCALCLIENT(e) || cl.maxclients == 1 ) | |
- return 1; | |
- | |
- if( cl.predicted.moving && cl.predicted.onground == e->index ) | |
+ if( e->model == NULL || cl.maxclients <= 1 ) | |
return 1; | |
t = cl.time - cl_interp->value; | |
- CL_FindInterpolationUpdates( e, t, &ph0, &ph1, NULL ); | |
+ if( !CL_FindInterpolationUpdates( e, t, &ph0, &ph1, NULL )) | |
+ return 0; | |
if( ph0 == NULL || ph1 == NULL ) | |
return 0; | |
@@ -152,7 +148,7 @@ int CL_InterpolateModel( cl_entity_t *e | |
if( t - t2 < 0.0f ) | |
return 0; | |
- if( t2 == 0.0f || ( VectorIsNull( ph1->origin ) && !VectorIsNull( ph0->origin ) ) ) | |
+ if( t2 == 0.0f || VectorIsNull( ph1->origin ) && !VectorIsNull( ph0->origin )) | |
{ | |
VectorCopy( ph0->origin, e->origin ); | |
VectorCopy( ph0->angles, e->angles ); | |
@@ -197,36 +193,6 @@ int CL_InterpolateModel( cl_entity_t *e | |
return 1; | |
} | |
-void CL_InterpolateMovingEntity( cl_entity_t *ent ) | |
-{ | |
- float d, f = 0.0f; | |
- int i; | |
- | |
- // don't do it if the goalstarttime hasn't updated in a while. | |
- // NOTE: Because we need to interpolate multiplayer characters, the interpolation time limit | |
- // was increased to 1.0 s., which is 2x the max lag we are accounting for. | |
- if(( cl.time < ent->curstate.animtime + 1.0f ) && ( ent->curstate.animtime != ent->latched.prevanimtime )) | |
- f = ( cl.time - ent->curstate.animtime ) / ( ent->curstate.animtime - ent->latched.prevanimtime ); | |
- | |
- f = f - 1.0f; | |
- | |
- ent->origin[0] += ( ent->origin[0] - ent->latched.prevorigin[0] ) * f; | |
- ent->origin[1] += ( ent->origin[1] - ent->latched.prevorigin[1] ) * f; | |
- ent->origin[2] += ( ent->origin[2] - ent->latched.prevorigin[2] ) * f; | |
- | |
- for( i = 0; i < 3; i++ ) | |
- { | |
- float ang1, ang2; | |
- | |
- ang1 = ent->angles[i]; | |
- ang2 = ent->latched.prevangles[i]; | |
- d = ang1 - ang2; | |
- if( d > 180.0f ) d -= 360.0f; | |
- else if( d < -180.0f ) d += 360.0f; | |
- ent->angles[i] += d * f; | |
- } | |
-} | |
- | |
void CL_UpdateEntityFields( cl_entity_t *ent ) | |
{ | |
// parametric rockets code | |
@@ -253,9 +218,7 @@ void CL_UpdateEntityFields( cl_entity_t | |
ent->angles[PITCH] = -ent->angles[PITCH] / 3.0f; | |
// make me lerp | |
- if( ent->index == cl.predicted.onground && cl.predicted.moving ) | |
- CL_InterpolateMovingEntity( ent ); | |
- else if( ent->model && ent->model->type == mod_brush && ent->curstate.animtime != 0.0f) | |
+ if( ent->model && ent->model->type == mod_brush && ent->curstate.animtime != 0.0f ) | |
{ | |
float d, f = 0.0f; | |
int i; | |
@@ -361,7 +324,7 @@ void CL_UpdateEntityFields( cl_entity_t | |
} | |
} | |
- // moved code from StudioSetupTransform here | |
+ // move code from StudioSetupTransform here | |
if( host.features & ENGINE_COMPUTE_STUDIO_LERP ) | |
{ | |
ent->origin[0] += ( ent->curstate.origin[0] - ent->latched.prevorigin[0] ) * f; | |
@@ -549,12 +512,8 @@ Set new weapon animation | |
void CL_WeaponAnim( int iAnim, int body ) | |
{ | |
cl_entity_t *view = &clgame.viewent; | |
- cl.weaponstarttime = 0; | |
- cl.weaponseq = iAnim; | |
- if( CL_IsPredicted() || !cl_lw->value ) | |
+ | |
view->curstate.modelindex = cl.frame.client.viewmodel; | |
- else | |
- view->curstate.modelindex = cl.predicted.viewmodel; | |
// anim is changed. update latchedvars | |
if( iAnim != view->curstate.sequence ) | |
@@ -692,13 +651,7 @@ void CL_DeltaEntity( sizebuf_t *msg, fra | |
entity_state_t *state; | |
qboolean newent = (old) ? false : true; | |
qboolean result = true; | |
- if( ( newnum < 0 ) || ( newnum >= clgame.maxEntities ) ) | |
- { | |
- state = &cls.packet_entities[cls.next_client_entities % cls.num_client_entities]; | |
- if( !unchanged ) | |
- MSG_ReadDeltaEntity( msg, old, state, newnum, CL_IsPlayerIndex( newnum ), cl.mtime[0] ); | |
- return; | |
- } | |
+ | |
ent = CL_EDICT_NUM( newnum ); | |
state = &cls.packet_entities[cls.next_client_entities % cls.num_client_entities]; | |
ent->index = newnum; | |
@@ -710,21 +663,7 @@ void CL_DeltaEntity( sizebuf_t *msg, fra | |
if( !result ) | |
{ | |
- if( newent ) | |
- { | |
- MsgDev( D_WARN, "Cl_DeltaEntity: tried to release new entity\n" ); | |
- | |
- // Perform remove, entity was created and removed between packets | |
- | |
- if( state->number == -1 ) | |
- { | |
- ent->curstate.messagenum = 0; | |
- ent->baseline.number = 0; | |
- MsgDev( D_NOTE, "Entity %i was removed from server\n", newnum ); | |
- } | |
- else MsgDev( D_NOTE, "Entity %i was removed from delta-message\n", newnum ); | |
- return; | |
- } | |
+ if( newent ) Host_Error( "Cl_DeltaEntity: tried to release new entity\n" ); | |
CL_KillDeadBeams( ent ); // release dead beams | |
#if 0 | |
@@ -783,14 +722,14 @@ void CL_DeltaEntity( sizebuf_t *msg, fra | |
/* | |
================= | |
CL_FlushEntityPacket | |
- | |
-Read and ignore whole entity packet. | |
================= | |
*/ | |
void CL_FlushEntityPacket( sizebuf_t *msg ) | |
{ | |
int newnum; | |
entity_state_t from, to; | |
+ | |
+ MsgDev( D_INFO, "FlushEntityPacket()\n" ); | |
Q_memset( &from, 0, sizeof( from )); | |
cl.frames[cl.parsecountmod].valid = false; | |
@@ -849,9 +788,7 @@ void CL_ParsePacketEntities( sizebuf_t * | |
if( subtracted == 0 ) | |
{ | |
- MsgDev( D_NOTE, "CL_DeltaPacketEntities: update too old (flush)\n" ); | |
- Con_NPrintf( 2, "^3Warning:^1 update too old\n^7\n" ); | |
- CL_FlushEntityPacket( msg ); | |
+ Host_Error( "CL_DeltaPacketEntities: update too old, connection dropped.\n" ); | |
return; | |
} | |
@@ -855,12 +792,10 @@ void CL_ParsePacketEntities( sizebuf_t * | |
return; | |
} | |
- | |
if( subtracted >= CL_UPDATE_MASK ) | |
{ | |
- MsgDev( D_NOTE, "CL_ParsePacketEntities: delta frame is too old: overflow (flush)\n"); | |
// we can't use this, it is too old | |
- Con_NPrintf( 2, "^3Warning:^1 delta frame is too old: overflow^7\n" ); | |
+ Con_NPrintf( 2, "^3Warning:^1 delta frame is too old^7\n" ); | |
CL_FlushEntityPacket( msg ); | |
return; | |
} | |
@@ -869,7 +804,6 @@ void CL_ParsePacketEntities( sizebuf_t * | |
if(( cls.next_client_entities - oldframe->first_entity ) > ( cls.num_client_entities - 128 )) | |
{ | |
- MsgDev( D_NOTE, "CL_ParsePacketEntities: delta frame is too old (flush)\n"); | |
Con_NPrintf( 2, "^3Warning:^1 delta frame is too old^7\n" ); | |
CL_FlushEntityPacket( msg ); | |
return; | |
@@ -1041,7 +975,7 @@ void CL_SetIdealPitch( void ) | |
vec3_t top, bottom; | |
float z[MAX_FORWARD]; | |
int i, j; | |
- float step, dir, steps; | |
+ int step, dir, steps; | |
pmtrace_t tr; | |
if( !( cl.frame.client.flags & FL_ONGROUND )) | |
@@ -1052,9 +986,9 @@ void CL_SetIdealPitch( void ) | |
for( i = 0; i < MAX_FORWARD; i++ ) | |
{ | |
- top[0] = cl.predicted.origin[0] + cosval * (i + 3.0f) * 12.0f; | |
- top[1] = cl.predicted.origin[1] + sinval * (i + 3.0f) * 12.0f; | |
- top[2] = cl.predicted.origin[2] + cl.predicted.viewofs[2]; | |
+ top[0] = cl.frame.client.origin[0] + cosval * (i + 3.0f) * 12.0f; | |
+ top[1] = cl.frame.client.origin[1] + sinval * (i + 3.0f) * 12.0f; | |
+ top[2] = cl.frame.client.origin[2] + cl.frame.client.view_ofs[2]; | |
bottom[0] = top[0]; | |
bottom[1] = top[1]; | |
@@ -1207,10 +1141,6 @@ qboolean CL_GetEntitySpatialization( int | |
void CL_ExtraUpdate( void ) | |
{ | |
- if( !cls.initialized ) | |
- return; | |
- if( !m_ignore->value ) | |
clgame.dllFuncs.IN_Accumulate(); | |
S_ExtraUpdate(); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_game.c /mnt/data/Xash3D_original/engine/client/cl_game.c | |
--- engine/client/cl_game.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_game.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "const.h" | |
@@ -32,17 +30,12 @@ GNU General Public License for more deta | |
#include "vgui_draw.h" | |
#include "sound.h" // SND_STOP_LOOPING | |
-#include "port.h" | |
- | |
-#define MAX_LINELENGTH 80 | |
#define MAX_TEXTCHANNELS 8 // must be power of two (GoldSrc uses 4 channels) | |
#define TEXT_MSGNAME "TextMessage%i" | |
char cl_textbuffer[MAX_TEXTCHANNELS][512]; | |
client_textmessage_t cl_textmessage[MAX_TEXTCHANNELS]; | |
-rgba_t g_color_table[8]; | |
- | |
static dllfunc_t cdll_exports[] = | |
{ | |
{ "Initialize", (void **)&clgame.dllFuncs.pfnInitialize }, | |
@@ -95,9 +88,6 @@ static dllfunc_t cdll_new_exports[] = / | |
{ "HUD_GetRenderInterface", (void **)&clgame.dllFuncs.pfnGetRenderInterface }, // Xash3D ext | |
{ "HUD_GetPlayerTeam", (void **)&clgame.dllFuncs.pfnGetPlayerTeam }, | |
{ "HUD_ClipMoveToEntity", (void **)&clgame.dllFuncs.pfnClipMoveToEntity }, // Xash3D ext | |
-{ "IN_ClientTouchEvent", (void **)&clgame.dllFuncs.pfnTouchEvent}, // Xash3D ext | |
-{ "IN_ClientMoveEvent", (void **)&clgame.dllFuncs.pfnMoveEvent}, // Xash3D ext | |
-{ "IN_ClientLookEvent", (void **)&clgame.dllFuncs.pfnLookEvent}, // Xash3D ext | |
{ NULL, NULL } | |
}; | |
@@ -241,7 +231,7 @@ void CL_InitCDAudio( const char *filenam | |
CL_CreatePlaylist( filename ); | |
} | |
- afile = (char *)FS_LoadFile( filename, NULL, false ); | |
+ afile = FS_LoadFile( filename, NULL, false ); | |
if( !afile ) return; | |
pfile = afile; | |
@@ -254,7 +244,7 @@ void CL_InitCDAudio( const char *filenam | |
if( ++c > MAX_CDTRACKS - 1 ) | |
{ | |
- MsgDev( D_WARN, "CD_Init: too many tracks %i in %s (only %d allowed)\n", c, filename, MAX_CDTRACKS ); | |
+ MsgDev( D_WARN, "CD_Init: too many tracks %i in %s\n", filename, MAX_CDTRACKS ); | |
break; | |
} | |
} | |
@@ -362,7 +352,7 @@ print centerscreen message | |
*/ | |
void CL_CenterPrint( const char *text, float y ) | |
{ | |
- byte *s; | |
+ char *s; | |
int width = 0; | |
int length = 0; | |
@@ -583,7 +573,7 @@ void CL_DrawCenterPrint( void ) | |
char *pText; | |
int i, j, x, y; | |
int width, lineLength; | |
- byte *colorDefault, line[MAX_LINELENGTH]; | |
+ byte *colorDefault, line[80]; | |
int charWidth, charHeight; | |
if( !clgame.centerPrint.time ) | |
@@ -606,7 +596,7 @@ void CL_DrawCenterPrint( void ) | |
lineLength = 0; | |
width = 0; | |
- while( *pText && *pText != '\n' && lineLength < MAX_LINELENGTH ) | |
+ while( *pText && *pText != '\n' ) | |
{ | |
byte c = *pText; | |
line[lineLength] = c; | |
@@ -616,9 +606,6 @@ void CL_DrawCenterPrint( void ) | |
pText++; | |
} | |
- if( lineLength == MAX_LINELENGTH ) | |
- lineLength--; | |
- | |
pText++; // Skip LineFeed | |
line[lineLength] = 0; | |
@@ -693,7 +680,7 @@ and hold them into permament memory pool | |
*/ | |
static void CL_InitTitles( const char *filename ) | |
{ | |
- fs_offset_t fileSize; | |
+ size_t fileSize; | |
byte *pMemFile; | |
int i; | |
@@ -713,7 +700,7 @@ static void CL_InitTitles( const char *f | |
pMemFile = FS_LoadFile( filename, &fileSize, false ); | |
if( !pMemFile ) return; | |
- CL_TextMessageParse( pMemFile, (int)fileSize ); | |
+ CL_TextMessageParse( pMemFile, fileSize ); | |
Mem_Free( pMemFile ); | |
} | |
@@ -783,7 +770,7 @@ cl_entity_t *CL_GetLocalPlayer( void ) | |
cl_entity_t *player; | |
player = CL_EDICT_NUM( cl.playernum + 1 ); | |
- //ASSERT( player != NULL ); | |
+ ASSERT( player != NULL ); | |
return player; | |
} | |
@@ -812,7 +799,7 @@ const char *CL_SoundFromIndex( int index | |
sfx_t *sfx = NULL; | |
int hSound; | |
- // make sure that we're within bounds | |
+ // make sure what we in-bounds | |
index = bound( 0, index, MAX_SOUNDS ); | |
hSound = cl.sound_index[index]; | |
@@ -1096,8 +1083,6 @@ void CL_ClearWorld( void ) | |
void CL_InitEdicts( void ) | |
{ | |
ASSERT( clgame.entities == NULL ); | |
- if( !clgame.mempool ) | |
- return; // Host_Error without client | |
CL_UPDATE_BACKUP = ( cl.maxclients == 1 ) ? SINGLEPLAYER_BACKUP : MULTIPLAYER_BACKUP; | |
cls.num_client_entities = CL_UPDATE_BACKUP * 64; | |
@@ -1116,15 +1101,18 @@ void CL_InitEdicts( void ) | |
void CL_FreeEdicts( void ) | |
{ | |
- Z_Free( clgame.entities ); | |
+ if( clgame.entities ) | |
+ Mem_Free( clgame.entities ); | |
clgame.entities = NULL; | |
- Z_Free( clgame.static_entities ); | |
+ if( clgame.static_entities ) | |
+ Mem_Free( clgame.static_entities ); | |
clgame.static_entities = NULL; | |
+ if( cls.packet_entities ) | |
Z_Free( cls.packet_entities ); | |
- cls.packet_entities = NULL; | |
+ cls.packet_entities = NULL; | |
cls.num_client_entities = 0; | |
cls.next_client_entities = 0; | |
clgame.numStatics = 0; | |
@@ -1149,7 +1137,7 @@ void CL_ClearEdicts( void ) | |
static qboolean CL_LoadHudSprite( const char *szSpriteName, model_t *m_pSprite, qboolean mapSprite, uint texFlags ) | |
{ | |
byte *buf; | |
- fs_offset_t size; | |
+ size_t size; | |
qboolean loaded; | |
ASSERT( m_pSprite != NULL ); | |
@@ -1160,7 +1148,7 @@ static qboolean CL_LoadHudSprite( const | |
Q_strncpy( m_pSprite->name, szSpriteName, sizeof( m_pSprite->name )); | |
m_pSprite->flags = 256; // it's hud sprite, make difference names to prevent free shared textures | |
- if( mapSprite ) Mod_LoadMapSprite( m_pSprite, buf, (size_t)size, &loaded ); | |
+ if( mapSprite ) Mod_LoadMapSprite( m_pSprite, buf, size, &loaded ); | |
else Mod_LoadSpriteModel( m_pSprite, buf, &loaded, texFlags ); | |
Mem_Free( buf ); | |
@@ -1211,7 +1199,7 @@ HSPRITE pfnSPR_LoadExt( const char *szPi | |
break; // this is a valid spot | |
} | |
- if( i >= MAX_IMAGES ) | |
+ if( i == MAX_IMAGES ) | |
{ | |
MsgDev( D_ERROR, "SPR_Load: can't load %s, MAX_HSPRITES limit exceeded\n", szPicName ); | |
return 0; | |
@@ -1220,10 +1208,7 @@ HSPRITE pfnSPR_LoadExt( const char *szPi | |
// load new model | |
if( CL_LoadHudSprite( name, &clgame.sprites[i], false, texFlags )) | |
{ | |
- if( i < MAX_IMAGES - 1 ) | |
- { | |
clgame.sprites[i].needload = clgame.load_sequence; | |
- } | |
return i; | |
} | |
return 0; | |
@@ -1237,11 +1222,7 @@ pfnSPR_Load | |
*/ | |
HSPRITE pfnSPR_Load( const char *szPicName ) | |
{ | |
- int texFlags = TF_NOPICMIP; | |
- if( cl_sprite_nearest->value ) | |
- texFlags |= TF_NEAREST; | |
- | |
- return pfnSPR_LoadExt( szPicName, texFlags ); | |
+ return pfnSPR_LoadExt( szPicName, 0 ); | |
} | |
/* | |
@@ -1378,7 +1359,7 @@ static client_sprite_t *pfnSPR_GetList( | |
if( !clgame.itemspath[0] ) // typically it's sprites\*.txt | |
FS_ExtractFilePath( psz, clgame.itemspath ); | |
- afile = (char *)FS_LoadFile( psz, NULL, false ); | |
+ afile = FS_LoadFile( psz, NULL, false ); | |
if( !afile ) return NULL; | |
pfile = afile; | |
@@ -1439,17 +1420,16 @@ pfnFillRGBA | |
*/ | |
static void pfnFillRGBA( int x, int y, int width, int height, int r, int g, int b, int a ) | |
{ | |
- float x1 = x, y1 = y, w1 = width, h1 = height; | |
r = bound( 0, r, 255 ); | |
g = bound( 0, g, 255 ); | |
b = bound( 0, b, 255 ); | |
a = bound( 0, a, 255 ); | |
pglColor4ub( r, g, b, a ); | |
- SPR_AdjustSize( &x1, &y1, &w1, &h1 ); | |
+ SPR_AdjustSize( (float *)&x, (float *)&y, (float *)&width, (float *)&height ); | |
GL_SetRenderMode( kRenderTransAdd ); | |
- R_DrawStretchPic( x1, y1, w1, h1, 0, 0, 1, 1, cls.fillImage ); | |
+ R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.fillImage ); | |
pglColor4ub( 255, 255, 255, 255 ); | |
} | |
@@ -1460,17 +1440,25 @@ pfnGetScreenInfo | |
get actual screen info | |
============= | |
*/ | |
-int pfnGetScreenInfo( SCREENINFO *pscrinfo ) | |
+static int pfnGetScreenInfo( SCREENINFO *pscrinfo ) | |
{ | |
// setup screen info | |
- float scale_factor = hud_scale->value; | |
clgame.scrInfo.iSize = sizeof( clgame.scrInfo ); | |
- | |
- if( scale_factor && scale_factor != 1.0f) | |
+ if( Cvar_VariableInteger( "hud_scale" )) | |
{ | |
- clgame.scrInfo.iWidth = scr_width->integer/scale_factor; | |
- clgame.scrInfo.iHeight = scr_height->integer/scale_factor; | |
+ if( scr_width->integer < 640 ) | |
+ { | |
+ // virtual screen space 320x200 | |
+ clgame.scrInfo.iWidth = 320; | |
+ clgame.scrInfo.iHeight = 200; | |
+ } | |
+ else | |
+ { | |
+ // virtual screen space 640x480 | |
+ clgame.scrInfo.iWidth = 640; | |
+ clgame.scrInfo.iHeight = 480; | |
+ } | |
clgame.scrInfo.iFlags |= SCRINFO_STRETCHED; | |
} | |
else | |
@@ -1681,13 +1669,12 @@ pfnDrawCharacter | |
returns drawed chachter width (in real screen pixels) | |
============= | |
*/ | |
-int pfnDrawCharacter( int x, int y, int number, int r, int g, int b ) | |
+static int pfnDrawCharacter( int x, int y, int number, int r, int g, int b ) | |
{ | |
if( !cls.creditsFont.valid ) | |
return 0; | |
number &= 255; | |
- number = Con_UtfProcessChar( number ); | |
if( number < 32 ) return 0; | |
if( y < -clgame.scrInfo.iCharHeight ) | |
@@ -1763,8 +1750,8 @@ prints directly into console (can skip n | |
static void pfnConsolePrint( const char *string ) | |
{ | |
if( !string || !*string ) return; | |
- if( *string != 1 ) Msg( "%s", string ); // show notify | |
- else Con_NPrintf( 0, "%s", (char *)string + 1 ); // skip notify | |
+ if( *string != 1 ) Con_Print( (char *)string ); // show notify | |
+ else Con_NPrintf( 0, (char *)string + 1 ); // skip notify | |
} | |
/* | |
@@ -1789,11 +1776,7 @@ GetWindowCenterX | |
*/ | |
static int pfnGetWindowCenterX( void ) | |
{ | |
- int x = 0; | |
-#ifdef XASH_SDL | |
- SDL_GetWindowPosition( host.hWnd, &x, NULL ); | |
-#endif | |
- return host.window_center_x + x; | |
+ return host.window_center_x; | |
} | |
/* | |
@@ -1804,11 +1787,7 @@ GetWindowCenterY | |
*/ | |
static int pfnGetWindowCenterY( void ) | |
{ | |
- int y = 0; | |
-#ifdef XASH_SDL | |
- SDL_GetWindowPosition( host.hWnd, NULL, &y ); | |
-#endif | |
- return host.window_center_y + y; | |
+ return host.window_center_y; | |
} | |
/* | |
@@ -1894,13 +1873,15 @@ pfnGetMousePosition | |
============= | |
*/ | |
-void CL_GetMousePosition( int *mx, int *my ) | |
+static void pfnGetMousePosition( int *mx, int *my ) | |
{ | |
-#ifdef XASH_SDL | |
- SDL_GetMouseState(mx, my); | |
-#else | |
-mx=my=0; | |
-#endif | |
+ POINT curpos; | |
+ | |
+ GetCursorPos( &curpos ); | |
+ ScreenToClient( host.hWnd, &curpos ); | |
+ | |
+ if( mx ) *mx = curpos.x; | |
+ if( my ) *my = curpos.y; | |
} | |
/* | |
@@ -2117,7 +2098,7 @@ static void pfnHookEvent( const char *fi | |
if( !Q_stricmp( name, ev->name ) && ev->func != NULL ) | |
{ | |
- MsgDev( D_WARN, "CL_HookEvent: %s already hooked!\n", name ); | |
+ MsgDev( D_WARN, "CL_HookEvent: %s already hooked!\n" ); | |
return; | |
} | |
} | |
@@ -2218,7 +2199,7 @@ pfnLocalPlayerDucking | |
*/ | |
int pfnLocalPlayerDucking( void ) | |
{ | |
- return cl.predicted.usehull == 1; | |
+ return cl.frame.client.bInDuck; | |
} | |
/* | |
@@ -2233,7 +2214,7 @@ void pfnLocalPlayerViewheight( float *vi | |
if( !view_ofs ) return; | |
if( CL_IsPredicted( )) | |
- VectorCopy( cl.predicted.viewofs, view_ofs ); | |
+ VectorCopy( cl.predicted_viewofs, view_ofs ); | |
else VectorCopy( cl.frame.client.view_ofs, view_ofs ); | |
} | |
@@ -2284,7 +2265,93 @@ physent_t *pfnGetPhysent( int idx ) | |
return NULL; | |
} | |
+/* | |
+============= | |
+pfnSetUpPlayerPrediction | |
+ | |
+FIXME: finalize | |
+============= | |
+*/ | |
+void pfnSetUpPlayerPrediction( int dopred, int bIncludeLocalClient ) | |
+{ | |
+#if 0 | |
+ entity_state_t *playerstate = cl.frames[cl.parsecountmod].playerstate; | |
+ predicted_player_t *player = cls.predicted_players; | |
+ cl_entity_t *clent; | |
+ int j, v12; | |
+ | |
+ for( j = 0; j < MAX_CLIENTS; j++, player++, playerstate++ ) | |
+ { | |
+ player->active = false; | |
+ | |
+ if( playerstate->messagenum != cl.parsecount ) | |
+ continue; // not present this frame | |
+ | |
+ if( !playerstate->modelindex ) | |
+ continue; | |
+ | |
+ // special for EF_NODRAW and local client? | |
+ if(( playerstate->effects & EF_NODRAW ) && !bIncludeLocalClient ) | |
+ { | |
+ // don't include local player? | |
+ if( cl.playernum != j ) | |
+ { | |
+ player->active = true; | |
+ player->movetype = playerstate->movetype; | |
+ player->solid = playerstate->solid; | |
+ player->usehull = playerstate->usehull; | |
+ | |
+ clent = CL_EDICT_NUM( j + 1 ); | |
+// CL_ComputePlayerOrigin( v9 ); | |
+ VectorCopy( clent->origin, player->origin ); | |
+ VectorCopy( clent->angles, player->angles ); | |
+ } | |
+ else continue; | |
+ } | |
+ else | |
+ { | |
+ if( cl.playernum == j ) | |
+ continue; | |
+ | |
+ player->active = true; | |
+ player->movetype = playerstate->movetype; | |
+ player->solid = playerstate->solid; | |
+ player->usehull = playerstate->usehull; | |
+ | |
+ v12 = 17080 * cl.parsecountmod + 340 * j; | |
+ player->origin[0] = cl.frames[0].playerstate[0].origin[0] + v12; | |
+ player->origin[1] = cl.frames[0].playerstate[0].origin[1] + v12; | |
+ player->origin[2] = cl.frames[0].playerstate[0].origin[2] + v12; | |
+ | |
+ player->angles[0] = cl.frames[0].playerstate[0].angles[0] + v12; | |
+ player->angles[1] = cl.frames[0].playerstate[0].angles[1] + v12; | |
+ player->angles[2] = cl.frames[0].playerstate[0].angles[2] + v12; | |
+ } | |
+ } | |
+#endif | |
+} | |
+ | |
+/* | |
+============= | |
+pfnPushPMStates | |
+============= | |
+*/ | |
+void pfnPushPMStates( void ) | |
+{ | |
+ clgame.oldcount = clgame.pmove->numphysent; | |
+} | |
+ | |
+/* | |
+============= | |
+pfnPopPMStates | |
+ | |
+============= | |
+*/ | |
+void pfnPopPMStates( void ) | |
+{ | |
+ clgame.pmove->numphysent = clgame.oldcount; | |
+} | |
/* | |
============= | |
@@ -2407,7 +2475,7 @@ const char *pfnGetGameDirectory( void ) | |
{ | |
static char szGetGameDir[MAX_SYSPATH]; | |
- Q_sprintf( szGetGameDir, "%s", GI->gamedir ); | |
+ Q_sprintf( szGetGameDir, "%s/%s", host.rootdir, GI->gamedir ); | |
return szGetGameDir; | |
} | |
@@ -2471,11 +2539,6 @@ model_t *pfnLoadMapSprite( const char *f | |
{ | |
char name[64]; | |
int i; | |
- int texFlags = TF_NOPICMIP; | |
- | |
- | |
- if( cl_sprite_nearest->value ) | |
- texFlags |= TF_NEAREST; | |
if( !filename || !*filename ) | |
{ | |
@@ -2511,7 +2574,7 @@ model_t *pfnLoadMapSprite( const char *f | |
} | |
// load new map sprite | |
- if( CL_LoadHudSprite( name, &clgame.sprites[i], true, texFlags )) | |
+ if( CL_LoadHudSprite( name, &clgame.sprites[i], true, 0 )) | |
{ | |
clgame.sprites[i].needload = clgame.load_sequence; | |
return &clgame.sprites[i]; | |
@@ -2531,7 +2594,7 @@ const char *PlayerInfo_ValueForKey( int | |
if(( playerNum > cl.maxclients ) || ( playerNum < 1 )) | |
return NULL; | |
- if( !cl.players[playerNum-1].name[0] ) | |
+ if(( cl.players[playerNum-1].name == NULL ) || (*(cl.players[playerNum-1].name) == 0 )) | |
return NULL; | |
return Info_ValueForKey( cl.players[playerNum-1].userinfo, key ); | |
@@ -2630,13 +2693,13 @@ pfnGetMousePos | |
============= | |
*/ | |
-void pfnGetMousePos( POINT *ppt ) | |
+void pfnGetMousePos( struct tagPOINT *ppt ) | |
{ | |
-#ifdef XASH_SDL | |
- SDL_GetMouseState(&ppt->x, &ppt->y); | |
-#else | |
- ppt->x=ppt->y=0; | |
-#endif | |
+ ASSERT( ppt != NULL ); | |
+ | |
+ // find mouse movement | |
+ GetCursorPos( ppt ); | |
+ ScreenToClient( host.hWnd, ppt ); | |
} | |
/* | |
@@ -2647,9 +2710,13 @@ pfnSetMousePos | |
*/ | |
void pfnSetMousePos( int mx, int my ) | |
{ | |
-#ifdef XASH_SDL | |
- SDL_WarpMouseInWindow(host.hWnd, mx, my); | |
-#endif | |
+ POINT pt; | |
+ | |
+ pt.x = mx; | |
+ pt.y = my; | |
+ | |
+ ClientToScreen( host.hWnd, &pt ); | |
+ SetCursorPos( pt.x, pt.y ); | |
} | |
/* | |
@@ -2736,35 +2803,24 @@ void pfnSPR_DrawGeneric( int frame, int | |
============= | |
pfnDrawString | |
+TODO: implement | |
============= | |
*/ | |
int pfnDrawString( int x, int y, const char *str, int r, int g, int b ) | |
{ | |
- Con_UtfProcessChar(0); | |
- | |
- // draw the string until we hit the null character or a newline character | |
- for ( ; *str != 0 && *str != '\n'; str++ ) | |
- { | |
- x += pfnDrawCharacter( x, y, (unsigned char)*str, r, g, b ); | |
- } | |
- | |
- return x; | |
+ return 0; | |
} | |
/* | |
============= | |
pfnDrawStringReverse | |
+TODO: implement | |
============= | |
*/ | |
int pfnDrawStringReverse( int x, int y, const char *str, int r, int g, int b ) | |
{ | |
- // find the end of the string | |
- char *szIt; | |
- for( szIt = (char*)str; *szIt != 0; szIt++ ) | |
- x -= clgame.scrInfo.charWidths[ (unsigned char) *szIt ]; | |
- pfnDrawString( x, y, str, r, g, b ); | |
- return x; | |
+ return 0; | |
} | |
/* | |
@@ -2870,21 +2926,20 @@ pfnFillRGBABlend | |
*/ | |
void pfnFillRGBABlend( int x, int y, int width, int height, int r, int g, int b, int a ) | |
{ | |
- float x1 = x, y1 = y, w1 = width, h1 = height; | |
r = bound( 0, r, 255 ); | |
g = bound( 0, g, 255 ); | |
b = bound( 0, b, 255 ); | |
a = bound( 0, a, 255 ); | |
pglColor4ub( r, g, b, a ); | |
- SPR_AdjustSize( &x1, &y1, &w1, &h1 ); | |
+ SPR_AdjustSize( (float *)&x, (float *)&y, (float *)&width, (float *)&height ); | |
pglEnable( GL_BLEND ); | |
pglDisable( GL_ALPHA_TEST ); | |
- pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); | |
+ pglBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_ONE ); | |
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |
- R_DrawStretchPic( x1, y1, w1, h1, 0, 0, 1, 1, cls.fillImage ); | |
+ R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.fillImage ); | |
pglColor4ub( 255, 255, 255, 255 ); | |
} | |
@@ -2896,9 +2951,7 @@ pfnGetAppID | |
*/ | |
int pfnGetAppID( void ) | |
{ | |
- return 130; | |
- | |
- //return 220; // standard Valve value | |
+ return 220; // standard Valve value | |
} | |
/* | |
@@ -3135,7 +3188,7 @@ int TriSpriteTexture( model_t *pSpriteMo | |
pglAlphaFunc( GL_GREATER, 0.0f ); | |
} | |
- GL_Bind( XASH_TEXTURE0, gl_texturenum ); | |
+ GL_Bind( GL_TEXTURE0, gl_texturenum ); | |
return 1; | |
} | |
@@ -3153,7 +3206,7 @@ int TriWorldToScreen( float *world, floa | |
retval = R_WorldToScreen( world, screen ); | |
- screen[0] = 0.5f * (float)cl.refdef.viewport[2]; | |
+ screen[0] = 0.5f * screen[0] * (float)cl.refdef.viewport[2]; | |
screen[1] = -0.5f * screen[1] * (float)cl.refdef.viewport[3]; | |
screen[0] += 0.5f * (float)cl.refdef.viewport[2]; | |
screen[1] += 0.5f * (float)cl.refdef.viewport[3]; | |
@@ -3269,8 +3322,7 @@ TriForParams | |
*/ | |
void TriFogParams( float flDensity, int iFogSkybox ) | |
{ | |
- RI.fogDensity = flDensity; | |
- RI.fogCustom = iFogSkybox; | |
+ // TODO: implement | |
} | |
/* | |
@@ -3527,19 +3579,6 @@ void NetAPI_SetValueForKey( char *s, con | |
} | |
-void VGui_ViewportPaintBackground( int extents[4] ) | |
-{ | |
- // stub | |
-} | |
- | |
-#ifndef XASH_VGUI | |
-void *VGui_GetPanel() | |
-{ | |
- // stub | |
- return NULL; | |
-} | |
-#endif | |
- | |
/* | |
================= | |
IVoiceTweak implementation | |
@@ -3614,14 +3653,14 @@ triangleapi_t gTriApi = | |
TriColor4f, | |
TriColor4ub, | |
TriTexCoord2f, | |
- (void*)TriVertex3fv, | |
+ TriVertex3fv, | |
TriVertex3f, | |
TriBrightness, | |
TriCullFace, | |
TriSpriteTexture, | |
- (void*)R_WorldToScreen, // NOTE: XPROJECT, YPROJECT should be done in client.dll | |
+ R_WorldToScreen, // NOTE: XPROJECT, YPROJECT should be done in client.dll | |
TriFog, | |
- (void*)R_ScreenToWorld, | |
+ R_ScreenToWorld, | |
TriGetMatrix, | |
TriBoxInPVS, | |
TriLightAtPoint, | |
@@ -3632,75 +3671,75 @@ triangleapi_t gTriApi = | |
static efx_api_t gEfxApi = | |
{ | |
CL_AllocParticle, | |
- (void*)CL_BlobExplosion, | |
- (void*)CL_Blood, | |
- (void*)CL_BloodSprite, | |
- (void*)CL_BloodStream, | |
- (void*)CL_BreakModel, | |
- (void*)CL_Bubbles, | |
- (void*)CL_BubbleTrail, | |
- (void*)CL_BulletImpactParticles, | |
+ CL_BlobExplosion, | |
+ CL_Blood, | |
+ CL_BloodSprite, | |
+ CL_BloodStream, | |
+ CL_BreakModel, | |
+ CL_Bubbles, | |
+ CL_BubbleTrail, | |
+ CL_BulletImpactParticles, | |
CL_EntityParticles, | |
CL_Explosion, | |
CL_FizzEffect, | |
CL_FireField, | |
- (void*)CL_FlickerParticles, | |
- (void*)CL_FunnelSprite, | |
- (void*)CL_Implosion, | |
- (void*)CL_Large_Funnel, | |
- (void*)CL_LavaSplash, | |
- (void*)CL_MultiGunshot, | |
- (void*)CL_MuzzleFlash, | |
- (void*)CL_ParticleBox, | |
- (void*)CL_ParticleBurst, | |
- (void*)CL_ParticleExplosion, | |
- (void*)CL_ParticleExplosion2, | |
- (void*)CL_ParticleLine, | |
+ CL_FlickerParticles, | |
+ CL_FunnelSprite, | |
+ CL_Implosion, | |
+ CL_Large_Funnel, | |
+ CL_LavaSplash, | |
+ CL_MultiGunshot, | |
+ CL_MuzzleFlash, | |
+ CL_ParticleBox, | |
+ CL_ParticleBurst, | |
+ CL_ParticleExplosion, | |
+ CL_ParticleExplosion2, | |
+ CL_ParticleLine, | |
CL_PlayerSprites, | |
- (void*)CL_Projectile, | |
- (void*)CL_RicochetSound, | |
- (void*)CL_RicochetSprite, | |
- (void*)CL_RocketFlare, | |
+ CL_Projectile, | |
+ CL_RicochetSound, | |
+ CL_RicochetSprite, | |
+ CL_RocketFlare, | |
CL_RocketTrail, | |
- (void*)CL_RunParticleEffect, | |
- (void*)CL_ShowLine, | |
- (void*)CL_SparkEffect, | |
- (void*)CL_SparkShower, | |
- (void*)CL_SparkStreaks, | |
- (void*)CL_Spray, | |
+ CL_RunParticleEffect, | |
+ CL_ShowLine, | |
+ CL_SparkEffect, | |
+ CL_SparkShower, | |
+ CL_SparkStreaks, | |
+ CL_Spray, | |
CL_Sprite_Explode, | |
CL_Sprite_Smoke, | |
- (void*)CL_Sprite_Spray, | |
- (void*)CL_Sprite_Trail, | |
+ CL_Sprite_Spray, | |
+ CL_Sprite_Trail, | |
CL_Sprite_WallPuff, | |
- (void*)CL_StreakSplash, | |
- (void*)CL_TracerEffect, | |
+ CL_StreakSplash, | |
+ CL_TracerEffect, | |
CL_UserTracerParticle, | |
CL_TracerParticles, | |
- (void*)CL_TeleportSplash, | |
- (void*)CL_TempSphereModel, | |
- (void*)CL_TempModel, | |
- (void*)CL_DefaultSprite, | |
- (void*)CL_TempSprite, | |
+ CL_TeleportSplash, | |
+ CL_TempSphereModel, | |
+ CL_TempModel, | |
+ CL_DefaultSprite, | |
+ CL_TempSprite, | |
CL_DecalIndex, | |
- (void*)CL_DecalIndexFromName, | |
+ CL_DecalIndexFromName, | |
CL_DecalShoot, | |
CL_AttachTentToPlayer, | |
CL_KillAttachedTents, | |
- (void*)CL_BeamCirclePoints, | |
- (void*)CL_BeamEntPoint, | |
+ CL_BeamCirclePoints, | |
+ CL_BeamEntPoint, | |
CL_BeamEnts, | |
CL_BeamFollow, | |
CL_BeamKill, | |
- (void*)CL_BeamLightning, | |
- (void*)CL_BeamPoints, | |
- (void*)CL_BeamRing, | |
+ CL_BeamLightning, | |
+ CL_BeamPoints, | |
+ CL_BeamRing, | |
CL_AllocDlight, | |
CL_AllocElight, | |
- (void*)CL_TempEntAlloc, | |
- (void*)CL_TempEntAllocNoModel, | |
- (void*)CL_TempEntAllocHigh, | |
- (void*)CL_TempEntAllocCustom, | |
+ CL_TempEntAlloc, | |
+ CL_TempEntAllocNoModel, | |
+ CL_TempEntAllocHigh, | |
+ CL_TempEntAllocCustom, | |
CL_GetPackedColor, | |
CL_LookupColor, | |
CL_DecalRemoveAll, | |
@@ -3719,9 +3758,9 @@ static event_api_t gEventApi = | |
pfnLocalPlayerBounds, | |
pfnIndexFromTrace, | |
pfnGetPhysent, | |
- CL_SetUpPlayerPrediction, | |
- CL_PushPMStates, | |
- CL_PopPMStates, | |
+ pfnSetUpPlayerPrediction, | |
+ pfnPushPMStates, | |
+ pfnPopPMStates, | |
CL_SetSolidPlayers, | |
CL_SetTraceHull, | |
CL_PlayerTrace, | |
@@ -3787,15 +3826,15 @@ static cl_enginefunc_t gEngfuncs = | |
pfnFillRGBA, | |
pfnGetScreenInfo, | |
pfnSetCrosshair, | |
- (void*)pfnCvar_RegisterVariable, | |
- (void*)Cvar_VariableValue, | |
- (void*)Cvar_VariableString, | |
- (void*)pfnAddClientCommand, | |
- (void*)pfnHookUserMsg, | |
- (void*)pfnServerCmd, | |
- (void*)pfnClientCmd, | |
+ pfnCvar_RegisterVariable, | |
+ Cvar_VariableValue, | |
+ Cvar_VariableString, | |
+ pfnAddClientCommand, | |
+ pfnHookUserMsg, | |
+ pfnServerCmd, | |
+ pfnClientCmd, | |
pfnGetPlayerInfo, | |
- (void*)pfnPlaySoundByName, | |
+ pfnPlaySoundByName, | |
pfnPlaySoundByIndex, | |
AngleVectors, | |
CL_TextMessageGet, | |
@@ -3810,7 +3849,7 @@ static cl_enginefunc_t gEngfuncs = | |
pfnGetViewAngles, | |
pfnSetViewAngles, | |
CL_GetMaxClients, | |
- (void*)Cvar_SetFloat, | |
+ Cvar_SetFloat, | |
Cmd_Argc, | |
Cmd_Argv, | |
Con_Printf, | |
@@ -3821,8 +3860,8 @@ static cl_enginefunc_t gEngfuncs = | |
pfnServerInfo_ValueForKey, | |
pfnGetClientMaxspeed, | |
pfnCheckParm, | |
- (void*)Key_Event, | |
- CL_GetMousePosition, | |
+ Key_Event, | |
+ pfnGetMousePosition, | |
pfnIsNoClipping, | |
CL_GetLocalPlayer, | |
pfnGetViewModel, | |
@@ -3830,8 +3869,8 @@ static cl_enginefunc_t gEngfuncs = | |
pfnGetClientTime, | |
pfnCalcShake, | |
pfnApplyShake, | |
- (void*)pfnPointContents, | |
- (void*)CL_WaterEntity, | |
+ pfnPointContents, | |
+ CL_WaterEntity, | |
pfnTraceLine, | |
CL_LoadModel, | |
CL_AddEntity, | |
@@ -3842,8 +3881,8 @@ static cl_enginefunc_t gEngfuncs = | |
CL_WeaponAnim, | |
Com_RandomFloat, | |
Com_RandomLong, | |
- (void*)pfnHookEvent, | |
- (void*)Con_Visible, | |
+ pfnHookEvent, | |
+ Con_Visible, | |
pfnGetGameDirectory, | |
pfnCVarGetPointer, | |
Key_LookupBinding, | |
@@ -3852,7 +3891,7 @@ static cl_enginefunc_t gEngfuncs = | |
pfnSetScreenFade, | |
VGui_GetPanel, | |
VGui_ViewportPaintBackground, | |
- (void*)COM_LoadFile, | |
+ COM_LoadFile, | |
COM_ParseFile, | |
COM_FreeFile, | |
&gTriApi, | |
@@ -3875,9 +3914,9 @@ static cl_enginefunc_t gEngfuncs = | |
pfnSetMousePos, | |
pfnSetMouseEnable, | |
Cvar_GetList, | |
- (void*)Cmd_GetFirstFunctionHandle, | |
- (void*)Cmd_GetNextFunctionHandle, | |
- (void*)Cmd_GetName, | |
+ Cmd_GetFirstFunctionHandle, | |
+ Cmd_GetNextFunctionHandle, | |
+ Cmd_GetName, | |
pfnGetClientOldTime, | |
pfnGetGravity, | |
Mod_Handle, | |
@@ -3892,9 +3931,9 @@ static cl_enginefunc_t gEngfuncs = | |
LocalPlayerInfo_ValueForKey, | |
pfnVGUI2DrawCharacter, | |
pfnVGUI2DrawCharacterAdditive, | |
- (void*)Sound_GetApproxWavePlayLen, | |
+ Sound_GetApproxWavePlayLen, | |
GetCareerGameInterface, | |
- (void*)Cvar_Set, | |
+ Cvar_Set, | |
pfnIsCareerMatch, | |
pfnPlaySoundVoiceByName, | |
pfnMP3_InitStream, | |
@@ -3919,7 +3958,7 @@ void CL_UnloadProgs( void ) | |
CL_FreeParticles(); | |
CL_ClearAllRemaps(); | |
Mod_ClearUserData(); | |
- | |
+ VGui_Shutdown(); | |
// NOTE: HLFX 0.5 has strange bug: hanging on exit if no map was loaded | |
if( !( !Q_stricmp( GI->gamedir, "hlfx" ) && GI->version == 0.5f )) | |
@@ -3929,9 +3968,6 @@ void CL_UnloadProgs( void ) | |
Cvar_FullSet( "host_clientloaded", "0", CVAR_INIT ); | |
Com_FreeLibrary( clgame.hInstance ); | |
-#ifdef XASH_VGUI | |
- VGui_Shutdown(); | |
-#endif | |
Mem_FreePool( &cls.mempool ); | |
Mem_FreePool( &clgame.mempool ); | |
Q_memset( &clgame, 0, sizeof( clgame )); | |
@@ -3962,9 +3998,7 @@ qboolean CL_LoadProgs( const char *name | |
// NOTE: important stuff! | |
// vgui must startup BEFORE loading client.dll to avoid get error ERROR_NOACESS | |
// during LoadLibrary | |
-#ifdef XASH_VGUI | |
- VGui_Startup (menu.globals->scrWidth, menu.globals->scrHeight); | |
-#endif | |
+ VGui_Startup (); | |
clgame.hInstance = Com_LoadLibrary( name, false ); | |
if( !clgame.hInstance ) return false; | |
@@ -4040,7 +4074,7 @@ qboolean CL_LoadProgs( const char *name | |
} | |
Cvar_Get( "cl_nopred", "1", CVAR_ARCHIVE|CVAR_USERINFO, "disable client movement predicting" ); | |
- cl_lw = Cvar_Get( "cl_lw", "0", CVAR_ARCHIVE|CVAR_USERINFO, "enable client weapon predicting" ); | |
+ Cvar_Get( "cl_lw", "0", CVAR_ARCHIVE|CVAR_USERINFO, "enable client weapon predicting" ); | |
Cvar_Get( "cl_lc", "0", CVAR_ARCHIVE|CVAR_USERINFO, "enable lag compensation" ); | |
Cvar_FullSet( "host_clientloaded", "1", CVAR_INIT ); | |
@@ -4059,7 +4093,6 @@ qboolean CL_LoadProgs( const char *name | |
{ | |
MsgDev( D_WARN, "CL_LoadProgs: couldn't get render API\n" ); | |
} | |
- Mobile_Init(); // Xash3D extension: mobile interface | |
// initialize game | |
clgame.dllFuncs.pfnInit(); | |
@@ -4068,4 +4101,3 @@ qboolean CL_LoadProgs( const char *name | |
return true; | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/client.h /mnt/data/Xash3D_original/engine/client/client.h | |
--- engine/client/client.h 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/client.h 2016-08-19 14:21:49.000000000 +0000 | |
@@ -19,7 +19,6 @@ GNU General Public License for more deta | |
#include "mathlib.h" | |
#include "cdll_int.h" | |
#include "menu_int.h" | |
-#include "mobility_int.h" | |
#include "cl_entity.h" | |
#include "com_model.h" | |
#include "mod_local.h" | |
@@ -47,6 +46,8 @@ GNU General Public License for more deta | |
#define VID_MAPSHOT 3 // special case for overview layer | |
#define VID_SNAPSHOT 4 // save screenshot into root dir and no gamma correction | |
+typedef int sound_t; | |
+ | |
//============================================================================= | |
typedef struct frame_s | |
{ | |
@@ -86,37 +87,6 @@ extern int CL_UPDATE_BACKUP; | |
#define INVALID_HANDLE 0xFFFF // for XashXT cache system | |
-// used by SetUpPlayerPrediction | |
-#if 0 | |
-typedef struct | |
-{ | |
- int movetype; | |
- int solid; | |
- int usehull; | |
- qboolean active; | |
- vec3_t origin; | |
- vec3_t angles; | |
-} predicted_player_t; | |
-#endif | |
- | |
-typedef struct | |
-{ | |
- vec3_t origin; // generated by CL_PredictMovement | |
- vec3_t viewofs; | |
- vec3_t velocity; | |
- vec3_t punchangle; | |
- vec3_t origins[CMD_BACKUP]; | |
- vec3_t error; | |
- vec3_t lastorigin; | |
- double correction_time; | |
- int viewmodel; | |
- int onground; | |
- int waterlevel; | |
- int usehull; | |
- int moving; | |
- int lastground; | |
-} cl_predicted_data_t; // data we got from prediction system | |
- | |
// the client_t structure is wiped completely at every | |
// server map change | |
typedef struct | |
@@ -169,7 +140,12 @@ typedef struct | |
event_state_t events; | |
// predicting stuff | |
- cl_predicted_data_t predicted; // generated from CL_PredictMovement | |
+ vec3_t predicted_origin; // generated by CL_PredictMovement | |
+ vec3_t predicted_viewofs; | |
+ vec3_t predicted_velocity; | |
+ vec3_t predicted_punchangle; | |
+ vec3_t predicted_origins[CMD_BACKUP]; | |
+ vec3_t prediction_error; | |
// server state information | |
int playernum; | |
@@ -187,12 +163,6 @@ typedef struct | |
cl_entity_t *world; | |
model_t *worldmodel; // pointer to world | |
- float weaponstarttime; | |
- int weaponseq; | |
- int scr_fov; | |
-#if 0 // used by SetUpPlayerPrediction | |
- predicted_player_t predicted_players[MAX_CLIENTS]; | |
-#endif | |
} client_t; | |
/* | |
@@ -288,6 +258,17 @@ typedef struct | |
byte gammaTable[256]; | |
} client_draw_t; | |
+typedef struct cl_predicted_player_s | |
+{ | |
+ int flags; | |
+ int movetype; | |
+ int solid; | |
+ int usehull; | |
+ qboolean active; | |
+ vec3_t origin; // predicted origin | |
+ vec3_t angles; | |
+} predicted_player_t; | |
+ | |
typedef struct | |
{ | |
int gl_texturenum; // this is a real texnum | |
@@ -338,13 +319,13 @@ typedef struct | |
typedef struct | |
{ | |
net_response_t resp; | |
- double timeout; | |
- double timesend; // time when request was sent | |
net_api_response_func_t pfnFunc; | |
+ double timeout; | |
+ double timesend; // time when request was sended | |
int flags; // FNETAPI_MULTIPLE_RESPONSE etc | |
} net_request_t; | |
-// new versions of client dlls have a single export with all callbacks | |
+// new versions of client dlls have a sanigle export with all callbacks | |
typedef void (*CL_EXPORT_FUNCS)( void *pv ); | |
typedef struct | |
@@ -371,9 +352,7 @@ typedef struct | |
playermove_t *pmove; // pmove state | |
int old_trace_hull; // used by PM_Push\Pop state | |
- qboolean pushed; // used by PM_Push\Pop state | |
- int oldviscount; // used by PM_Push\Pop state | |
- int oldphyscount; // used by PM_Push\Pop state | |
+ int oldcount; // used by PM_Push\Pop state | |
vec3_t player_mins[MAX_MAP_HULLS]; // 4 hulls allowed | |
vec3_t player_maxs[MAX_MAP_HULLS]; // 4 hulls allowed | |
@@ -419,10 +398,9 @@ typedef struct | |
ui_globalvars_t *globals; | |
qboolean drawLogo; // set to TRUE if logo.avi missed or corrupted | |
- int logo_xres; | |
- int logo_yres; | |
+ long logo_xres; | |
+ long logo_yres; | |
float logo_length; | |
- qboolean use_text_api; | |
} menu_static_t; | |
typedef struct | |
@@ -468,7 +446,6 @@ typedef struct | |
int lastoutgoingcommand; // sequence number of last outgoing command | |
// internal images | |
- int oldParticleImage; | |
int fillImage; // used for emulate FillRGBA to avoid wrong draw-sort | |
int particleImage; // built-in particle and sparks image | |
int pauseIcon; // draw 'paused' when game in-pause | |
@@ -484,6 +461,8 @@ typedef struct | |
int next_client_entities; // next client_entity to use | |
entity_state_t *packet_entities; // [num_client_entities] | |
+ predicted_player_t predicted_players[MAX_CLIENTS]; | |
+ | |
scrshot_t scrshot_request; // request for screen shot | |
scrshot_t scrshot_action; // in-action | |
const float *envshot_vieworg; // envshot position | |
@@ -514,7 +493,6 @@ typedef struct | |
file_t *demofile; | |
file_t *demoheader; // contain demo startup info in case we record a demo on this level | |
- qboolean keybind_changed; | |
} client_static_t; | |
#ifdef __cplusplus | |
@@ -533,35 +511,23 @@ extern menu_static_t menu; | |
// | |
// cvars | |
// | |
-extern convar_t *r_oldparticles; | |
extern convar_t *cl_predict; | |
+extern convar_t *cl_smooth; | |
extern convar_t *cl_showfps; | |
-extern convar_t *cl_showpos; | |
extern convar_t *cl_envshot_size; | |
extern convar_t *cl_timeout; | |
-extern convar_t *cl_charset; | |
extern convar_t *cl_nodelta; | |
extern convar_t *cl_interp; | |
extern convar_t *cl_showerror; | |
-extern convar_t *cl_nosmooth; | |
-extern convar_t *cl_smoothtime; | |
extern convar_t *cl_crosshair; | |
extern convar_t *cl_testlights; | |
extern convar_t *cl_solid_players; | |
extern convar_t *cl_idealpitchscale; | |
extern convar_t *cl_allow_levelshots; | |
-extern convar_t *cl_allow_fragment; | |
extern convar_t *cl_lightstyle_lerping; | |
extern convar_t *cl_draw_particles; | |
extern convar_t *cl_levelshot_name; | |
extern convar_t *cl_draw_beams; | |
-extern convar_t *cl_lw; | |
-extern convar_t *cl_trace_events; | |
-extern convar_t *cl_trace_stufftext; | |
-extern convar_t *cl_sprite_nearest; | |
-extern convar_t *cl_updaterate; | |
-extern convar_t *r_bmodelinterp; | |
-extern convar_t *hud_scale; | |
extern convar_t *scr_centertime; | |
extern convar_t *scr_viewsize; | |
extern convar_t *scr_download; | |
@@ -569,8 +535,6 @@ extern convar_t *scr_loading; | |
extern convar_t *scr_dark; // start from dark | |
extern convar_t *userinfo; | |
extern convar_t *hltv; | |
-extern convar_t *m_ignore; | |
- | |
//============================================================================= | |
@@ -658,7 +622,6 @@ void CL_ParseUserMessage( sizebuf_t *msg | |
void CL_LinkUserMessage( char *pszName, const int svc_num, int iSize ); | |
void CL_ParseTextMessage( sizebuf_t *msg ); | |
void CL_DrawHUD( int state ); | |
-void CL_GetMousePosition ( int *x, int *y ); | |
void CL_InitEdicts( void ); | |
void CL_FreeEdicts( void ); | |
void CL_ClearWorld( void ); | |
@@ -678,11 +641,8 @@ void CL_PlayerTrace( float *start, float | |
void CL_PlayerTraceExt( float *start, float *end, int traceFlags, int (*pfnIgnore)( physent_t *pe ), pmtrace_t *tr ); | |
void CL_SetTraceHull( int hull ); | |
- | |
_inline cl_entity_t *CL_EDICT_NUM( int n ) | |
{ | |
- if( !clgame.entities ) | |
- return NULL; | |
if(( n >= 0 ) && ( n < clgame.maxEntities )) | |
return clgame.entities + n; | |
@@ -690,8 +650,6 @@ _inline cl_entity_t *CL_EDICT_NUM( int n | |
return NULL; | |
} | |
-extern rgba_t g_color_table[8]; | |
- | |
// | |
// cl_parse.c | |
// | |
@@ -715,8 +673,6 @@ void SCR_MakeLevelShot( void ); | |
void SCR_NetSpeeds( void ); | |
void SCR_RSpeeds( void ); | |
void SCR_DrawFPS( void ); | |
-void SCR_DrawPos( void ); | |
- | |
// | |
// cl_view.c | |
@@ -749,9 +705,6 @@ cl_entity_t *CL_GetWaterEntity( const fl | |
void CL_SetupPMove( playermove_t *pmove, local_state_t *from, usercmd_t *ucmd, qboolean runfuncs, double time ); | |
pmtrace_t CL_TraceLine( vec3_t start, vec3_t end, int flags ); | |
void CL_ClearPhysEnts( void ); | |
-void CL_PushPMStates( void ); | |
-void CL_PopPMStates( void ); | |
-void CL_SetUpPlayerPrediction( int dopred, int bIncludeLocalClient ); | |
// | |
// cl_studio.c | |
@@ -767,7 +720,6 @@ void CL_UpdateStudioVars( cl_entity_t *e | |
qboolean CL_GetEntitySpatialization( int entnum, vec3_t origin, float *pradius ); | |
void CL_UpdateEntityFields( cl_entity_t *ent ); | |
qboolean CL_IsPlayerIndex( int idx ); | |
-void CL_SetIdealPitch( void ); | |
// | |
// cl_remap.c | |
@@ -823,10 +775,6 @@ void Con_DrawDebug( void ); | |
void Con_RunConsole( void ); | |
void Con_DrawConsole( void ); | |
void Con_DrawVersion( void ); | |
-int Con_UtfProcessChar( int in ); | |
-int Con_UtfProcessCharForce( int in ); | |
-int Con_UtfMoveLeft( char *str, int pos ); | |
-int Con_UtfMoveRight( char *str, int pos, int length ); | |
void Con_DrawStringLen( const char *pText, int *length, int *height ); | |
int Con_DrawString( int x, int y, const char *string, rgba_t setColor ); | |
int Con_DrawCharacter( int x, int y, int number, rgba_t color ); | |
@@ -839,14 +787,12 @@ void Con_RestoreFont( void ); | |
void Key_Console( int key ); | |
void Key_Message( int key ); | |
void Con_Close( void ); | |
-void Con_PageUp( int lines ); | |
-void Con_PageDown( int lines ); | |
-void Con_Bottom( void ); | |
+ | |
// | |
// s_main.c | |
// | |
void S_StreamRawSamples( int samples, int rate, int width, int channels, const byte *data ); | |
-void S_StartBackgroundTrack( const char *intro, const char *loop, int position ); | |
+void S_StartBackgroundTrack( const char *intro, const char *loop, long position ); | |
void S_StopBackgroundTrack( void ); | |
void S_StreamSetPause( int pause ); | |
void S_StartStreaming( void ); | |
@@ -880,7 +826,6 @@ qboolean UI_CreditsActive( void ); | |
void UI_CharEvent( int key ); | |
qboolean UI_MouseInRect( void ); | |
qboolean UI_IsVisible( void ); | |
-void UI_AddTouchButtonToList( const char *name, const char *texture, const char *command, unsigned char *color, int flags ); | |
void pfnPIC_Set( HIMAGE hPic, int r, int g, int b, int a ); | |
void pfnPIC_Draw( int x, int y, int width, int height, const wrect_t *prc ); | |
void pfnPIC_DrawTrans( int x, int y, int width, int height, const wrect_t *prc ); | |
@@ -888,12 +833,6 @@ void pfnPIC_DrawHoles( int x, int y, int | |
void pfnPIC_DrawAdditive( int x, int y, int width, int height, const wrect_t *prc ); | |
// | |
-// cl_mobile.c | |
-// | |
-void Mobile_Init( void ); | |
-void Mobile_Destroy( void ); | |
- | |
-// | |
// cl_video.c | |
// | |
void SCR_InitCinematic( void ); | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_main.c /mnt/data/Xash3D_original/engine/client/cl_main.c | |
--- engine/client/cl_main.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_main.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,38 +13,31 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "net_encode.h" | |
#include "cl_tent.h" | |
#include "gl_local.h" | |
#include "input.h" | |
-#include "touch.h" | |
-#include "kbutton.h" | |
+#include "../cl_dll/kbutton.h" | |
#include "vgui_draw.h" | |
-#include "library.h" | |
#define MAX_TOTAL_CMDS 16 | |
#define MIN_CMD_RATE 10.0 | |
#define MAX_CMD_BUFFER 4000 | |
#define CONNECTION_PROBLEM_TIME 15.0 // 15 seconds | |
-convar_t *r_oldparticles; | |
convar_t *rcon_client_password; | |
convar_t *rcon_address; | |
+convar_t *cl_smooth; | |
convar_t *cl_timeout; | |
convar_t *cl_predict; | |
convar_t *cl_showfps; | |
-convar_t *cl_showpos; | |
convar_t *cl_nodelta; | |
convar_t *cl_crosshair; | |
convar_t *cl_cmdbackup; | |
convar_t *cl_showerror; | |
-convar_t *cl_nosmooth; | |
-convar_t *cl_smoothtime; | |
convar_t *cl_draw_particles; | |
convar_t *cl_lightstyle_lerping; | |
convar_t *cl_idealpitchscale; | |
@@ -52,16 +45,6 @@ convar_t *cl_solid_players; | |
convar_t *cl_draw_beams; | |
convar_t *cl_cmdrate; | |
convar_t *cl_interp; | |
-convar_t *cl_allow_fragment; | |
-convar_t *cl_lw; | |
-convar_t *cl_trace_events; | |
-convar_t *cl_trace_stufftext; | |
-convar_t *cl_charset; | |
-convar_t *cl_sprite_nearest; | |
-convar_t *cl_updaterate; | |
-convar_t *hud_scale; | |
-convar_t *cl_maxpacket; | |
-convar_t *r_bmodelinterp; | |
// | |
// userinfo | |
@@ -86,7 +69,7 @@ qboolean CL_Active( void ) | |
//====================================================================== | |
qboolean CL_IsInGame( void ) | |
{ | |
- if( Host_IsDedicated() ) return true; // always active for dedicated servers | |
+ if( host.type == HOST_DEDICATED ) return true; // always active for dedicated servers | |
if( CL_GetMaxClients() > 1 ) return true; // always active for multiplayer | |
return ( cls.key_dest == key_game ); // active if not menu or console | |
} | |
@@ -135,7 +118,7 @@ This is experiment. Use with precaution | |
*/ | |
qboolean CL_ChangeGame( const char *gamefolder, qboolean bReset ) | |
{ | |
- if( Host_IsDedicated() ) | |
+ if( host.type == HOST_DEDICATED ) | |
return false; | |
if( Q_stricmp( host.gamefolder, gamefolder )) | |
@@ -165,9 +148,8 @@ qboolean CL_ChangeGame( const char *game | |
Q_strncpy( mapname, clgame.mapname, MAX_STRING ); | |
Q_strncpy( maptitle, clgame.maptitle, MAX_STRING ); | |
- Com_ResetLibraryError(); | |
- if( !CL_LoadProgs( va( "%s/%s", GI->dll_path, GI->client_lib))) | |
- Sys_Warn( "Can't initialize client library\n%s", Com_GetLibraryError() ); | |
+ if( !CL_LoadProgs( va( "%s/client.dll", GI->dll_path ))) | |
+ Host_Error( "can't initialize client.dll\n" ); | |
// restore parms | |
clgame.maxEntities = maxEntities; | |
@@ -323,22 +305,20 @@ void CL_CreateCmd( void ) | |
// build list of all solid entities per next frame (exclude clients) | |
CL_SetSolidEntities (); | |
- CL_PushPMStates(); | |
CL_SetSolidPlayers ( cl.playernum ); | |
- VectorCopy( cl.refdef.cl_viewangles, angles ); | |
- // write cdata | |
+ VectorCopy( cl.refdef.cl_viewangles, angles ); | |
VectorCopy( cl.frame.client.origin, cl.data.origin ); | |
VectorCopy( cl.refdef.cl_viewangles, cl.data.viewangles ); | |
cl.data.iWeaponBits = cl.frame.client.weapons; | |
- cl.data.fov = cl.scr_fov; | |
+ cl.data.fov = cl.frame.client.fov; | |
- if( clgame.dllFuncs.pfnUpdateClientData( &cl.data, cl.time ) ) | |
- { | |
- // grab changes if successful | |
+ clgame.dllFuncs.pfnUpdateClientData( &cl.data, cl.time ); | |
+ | |
+ // grab changes | |
VectorCopy( cl.data.viewangles, cl.refdef.cl_viewangles ); | |
- cl.scr_fov = cl.data.fov; | |
- } | |
+ cl.frame.client.weapons = cl.data.iWeaponBits; | |
+ cl.frame.client.fov = cl.data.fov; | |
// allways dump the first ten messages, | |
// because it may contain leftover inputs | |
@@ -366,22 +346,16 @@ void CL_CreateCmd( void ) | |
pcmd->sendsize = 0; | |
active = ( cls.state == ca_active && !cl.refdef.paused && !cls.demoplayback ); | |
- | |
clgame.dllFuncs.CL_CreateMove( cl.time - cl.oldtime, &pcmd->cmd, active ); | |
- CL_PopPMStates(); | |
- | |
- // after command generated in client, | |
- // add motion events from engine controls | |
- IN_EngineAppendMove( host.frametime, &cmd, active); | |
R_LightForPoint( cl.frame.client.origin, &color, false, false, 128.0f ); | |
- cmd.lightlevel = (color.r + color.g + color.b) / 3; | |
+ pcmd->cmd.lightlevel = (color.r + color.g + color.b) / 3; | |
// never let client.dll calc frametime for player | |
// because is potential backdoor for cheating | |
pcmd->cmd.msec = ms; | |
pcmd->cmd.lerp_msec = cl_interp->value * 1000; | |
- pcmd->cmd.lerp_msec = bound( 0, pcmd->cmd.lerp_msec, 250 ); | |
+ pcmd->cmd.lerp_msec = bound( 0, cmd.lerp_msec, 250 ); | |
V_ProcessOverviewCmds( &pcmd->cmd ); | |
V_ProcessShowTexturesCmds( &pcmd->cmd ); | |
@@ -456,7 +430,6 @@ void CL_WritePacket( void ) | |
Cvar_SetFloat( "cl_cmdrate", MIN_CMD_RATE ); | |
} | |
#endif | |
- Q_memset( data, 0, MAX_CMD_BUFFER ); | |
BF_Init( &buf, "ClientData", data, sizeof( data )); | |
// Determine number of backup commands to send along | |
@@ -542,7 +515,7 @@ void CL_WritePacket( void ) | |
for( i = numcmds - 1; i >= 0; i-- ) | |
{ | |
cmdnumber = ( cls.netchan.outgoing_sequence - i ) & CL_UPDATE_MASK; | |
- //if( i == 0 ) cl.commands[cmdnumber].processedfuncs = true; // only last cmd allow to run funcs | |
+ if( i == 0 ) cl.commands[cmdnumber].processedfuncs = true; // only last cmd allow to run funcs | |
to = cmdnumber; | |
CL_WriteUsercmd( &buf, from, to ); | |
@@ -730,8 +704,6 @@ CL_Connect_f | |
================ | |
*/ | |
- | |
-//#include <sys/mman.h> | |
void CL_Connect_f( void ) | |
{ | |
string server; | |
@@ -742,14 +714,7 @@ void CL_Connect_f( void ) | |
return; | |
} | |
- // default value 40000 ignored as we don't want to grow userinfo string | |
- if( ( cl_maxpacket->integer < 40000 ) && ( cl_maxpacket->integer > 99 ) ) | |
- { | |
- cl_maxpacket->flags |= CVAR_USERINFO; | |
- userinfo->modified = true; | |
- } | |
- | |
- Q_strncpy( server, Cmd_Argv( 1 ), MAX_STRING ); | |
+ Q_strncpy( server, Cmd_Argv( 1 ), sizeof( cls.servername )); | |
if( Host_ServerState()) | |
{ | |
@@ -849,7 +814,6 @@ void CL_ClearState( void ) | |
Cvar_FullSet( "cl_background", "0", CVAR_READ_ONLY ); | |
cl.refdef.movevars = &clgame.movevars; | |
cl.maxclients = 1; // allow to drawing player in menu | |
- cl.scr_fov = 90.0f; | |
Cvar_SetFloat( "scr_download", 0.0f ); | |
Cvar_SetFloat( "scr_loading", 0.0f ); | |
@@ -932,7 +896,7 @@ void CL_Crashed( void ) | |
{ | |
// already freed | |
if( host.state == HOST_CRASHED ) return; | |
- if( Host_IsDedicated() ) return; | |
+ if( host.type != HOST_NORMAL ) return; | |
if( !cls.initialized ) return; | |
host.state = HOST_CRASHED; | |
@@ -977,17 +941,17 @@ CL_InternetServers_f | |
void CL_InternetServers_f( void ) | |
{ | |
netadr_t adr; | |
- char fullquery[512] = "1\xFF" "0.0.0.0:0\0" "\\gamedir\\"; | |
+ char fullquery[512] = "\x31\xFF" "0.0.0.0:0\0" "\\gamedir\\"; | |
MsgDev( D_INFO, "Scanning for servers on the internet area...\n" ); | |
NET_Config( true ); // allow remote | |
- if( !NET_StringToAdr( sv_master->string, &adr ) ) | |
- MsgDev( D_INFO, "Can't resolve adr: %s\n", sv_master->string ); | |
+ if( !NET_StringToAdr( MASTERSERVER_ADR, &adr ) ) | |
+ MsgDev( D_INFO, "Can't resolve adr: %s\n", MASTERSERVER_ADR ); | |
- Q_strcpy( &fullquery[22], GI->gamedir ); | |
+ Q_strcpy( &fullquery[21], GI->gamedir ); | |
- NET_SendPacket( NS_CLIENT, 23 + Q_strlen(GI->gamedir), fullquery, adr ); | |
+ NET_SendPacket( NS_CLIENT, Q_strlen( GI->gamedir ) + 22, fullquery, adr ); | |
} | |
/* | |
@@ -1104,7 +1068,6 @@ void CL_ParseStatusMessage( netadr_t fro | |
char *s; | |
s = BF_ReadString( msg ); | |
- MsgDev( D_NOTE, "Got info string: %s\n", s ); | |
UI_AddServerToList( from, s ); | |
} | |
@@ -1164,20 +1127,19 @@ Call before entering a new level, or aft | |
*/ | |
void CL_PrepSound( void ) | |
{ | |
- int i, sndcount, step; | |
+ int i, sndcount; | |
MsgDev( D_NOTE, "CL_PrepSound: %s\n", clgame.mapname ); | |
for( i = 0, sndcount = 0; i < MAX_SOUNDS && cl.sound_precache[i+1][0]; i++ ) | |
sndcount++; // total num sounds | |
- step = sndcount/10; | |
S_BeginRegistration(); | |
- for( i = 0; i < MAX_SOUNDS - 1 && cl.sound_precache[i+1][0]; i++ ) | |
+ for( i = 0; i < MAX_SOUNDS && cl.sound_precache[i+1][0]; i++ ) | |
{ | |
cl.sound_index[i+1] = S_RegisterSound( cl.sound_precache[i+1] ); | |
Cvar_SetFloat( "scr_loading", scr_loading->value + 5.0f / sndcount ); | |
- if( step && !( i % step ) && ( cl_allow_levelshots->integer || cl.background )) | |
+ if( cl_allow_levelshots->integer || host.developer > 3 || cl.background ) | |
SCR_UpdateScreen(); | |
} | |
@@ -1214,8 +1176,8 @@ Call before entering a new level, or aft | |
*/ | |
void CL_PrepVideo( void ) | |
{ | |
- string mdlname, mapname; | |
- int i, mdlcount, step; | |
+ string name, mapname; | |
+ int i, mdlcount; | |
int map_checksum; // dummy | |
if( !cl.model_precache[1][0] ) | |
@@ -1226,7 +1188,7 @@ void CL_PrepVideo( void ) | |
// let the render dll load the map | |
Q_strncpy( mapname, cl.model_precache[1], MAX_STRING ); | |
- Mod_LoadWorld( mapname, (uint *)&map_checksum, cl.maxclients > 1 ); | |
+ Mod_LoadWorld( mapname, &map_checksum, cl.maxclients > 1 ); | |
cl.worldmodel = Mod_Handle( 1 ); // get world pointer | |
Cvar_SetFloat( "scr_loading", 25.0f ); | |
@@ -1238,14 +1200,13 @@ void CL_PrepVideo( void ) | |
for( i = 0, mdlcount = 0; i < MAX_MODELS && cl.model_precache[i+1][0]; i++ ) | |
mdlcount++; // total num models | |
- step = mdlcount/10; | |
- for( i = 0; i < MAX_MODELS - 1 && cl.model_precache[i+1][0]; i++ ) | |
+ for( i = 0; i < MAX_MODELS && cl.model_precache[i+1][0]; i++ ) | |
{ | |
- Q_strncpy( mdlname, cl.model_precache[i+1], MAX_STRING ); | |
- Mod_RegisterModel( mdlname, i+1 ); | |
+ Q_strncpy( name, cl.model_precache[i+1], MAX_STRING ); | |
+ Mod_RegisterModel( name, i+1 ); | |
Cvar_SetFloat( "scr_loading", scr_loading->value + 75.0f / mdlcount ); | |
- if( step && !( i % step ) && ( cl_allow_levelshots->integer || cl.background ) ) | |
+ if( cl_allow_levelshots->integer || host.developer > 3 || cl.background ) | |
SCR_UpdateScreen(); | |
} | |
@@ -1334,7 +1295,8 @@ void CL_ConnectionlessPacket( netadr_t f | |
{ | |
char *args; | |
char *c, buf[MAX_SYSPATH]; | |
- int len = sizeof( buf ), i = 0; | |
+ int len = sizeof( buf ); | |
+ int dataoffset = 0; | |
netadr_t servadr; | |
BF_Clear( msg ); | |
@@ -1352,11 +1314,11 @@ void CL_ConnectionlessPacket( netadr_t f | |
{ | |
if( cls.state == ca_connected ) | |
{ | |
- MsgDev( D_INFO, "Dup connect received. Ignored.\n"); | |
+ MsgDev( D_INFO, "dup connect received. ignored\n"); | |
return; | |
} | |
- Netchan_Setup( NS_CLIENT, &cls.netchan, from, net_qport->integer); | |
+ Netchan_Setup( NS_CLIENT, &cls.netchan, from, Cvar_VariableValue( "net_qport" )); | |
BF_WriteByte( &cls.netchan.message, clc_stringcmd ); | |
BF_WriteString( &cls.netchan.message, "new" ); | |
cls.state = ca_connected; | |
@@ -1368,6 +1330,8 @@ void CL_ConnectionlessPacket( netadr_t f | |
cl.last_command_ack = -1; | |
CL_StartupDemoHeader (); | |
+ | |
+ UI_SetActiveMenu( false ); | |
} | |
else if( !Q_strcmp( c, "info" )) | |
{ | |
@@ -1387,9 +1351,9 @@ void CL_ConnectionlessPacket( netadr_t f | |
Msg( "Command packet from remote host. Ignored.\n" ); | |
return; | |
} | |
-#ifdef XASH_SDL | |
- SDL_RestoreWindow( host.hWnd ); | |
-#endif | |
+ | |
+ ShowWindow( host.hWnd, SW_RESTORE ); | |
+ SetForegroundWindow ( host.hWnd ); | |
args = BF_ReadString( msg ); | |
Cbuf_AddText( args ); | |
Cbuf_AddText( "\n" ); | |
@@ -1422,16 +1386,15 @@ void CL_ConnectionlessPacket( netadr_t f | |
// dropped the connection but it is still getting packets from us | |
CL_Disconnect(); | |
} | |
- else if( !Q_strcmp( c, "f") ) | |
+ else if( msg->pData[0] == 0xFF && msg->pData[1] == 0xFF && msg->pData[2] == 0xFF && msg->pData[3] == 0xFF && msg->pData[4] == 0x66 && msg->pData[5] == 0x0A ) | |
{ | |
- // serverlist got from masterserver | |
- while( !msg->bOverflow ) | |
+ dataoffset = 6; | |
+ | |
+ while( 1 ) | |
{ | |
servadr.type = NA_IP; | |
- // 4 bytes for IP | |
- BF_ReadBytes( msg, servadr.ip, sizeof( servadr.ip )); | |
- // 2 bytes for Port | |
- servadr.port = BF_ReadShort( msg ); | |
+ Q_memcpy( servadr.ip, &msg->pData[dataoffset], sizeof(servadr.ip)); | |
+ servadr.port = *(word *)&msg->pData[dataoffset + 4]; | |
if( !servadr.port ) | |
break; | |
@@ -1441,14 +1404,16 @@ void CL_ConnectionlessPacket( netadr_t f | |
NET_Config( true ); // allow remote | |
Netchan_OutOfBandPrint( NS_CLIENT, servadr, "info %i", PROTOCOL_VERSION ); | |
+ | |
+ dataoffset += 6; | |
} | |
} | |
else if( clgame.dllFuncs.pfnConnectionlessPacket( &from, args, buf, &len )) | |
{ | |
// user out of band message (must be handled in CL_ConnectionlessPacket) | |
- if( len > 0 ) Netchan_OutOfBand( NS_SERVER, from, len, (byte *)buf ); | |
+ if( len > 0 ) Netchan_OutOfBand( NS_SERVER, from, len, buf ); | |
} | |
- else MsgDev( D_ERROR, "Bad connectionless packet from %s:\n%s\n", NET_AdrToString( from ), args ); | |
+ else MsgDev( D_ERROR, "bad connectionless packet from %s:\n%s\n", NET_AdrToString( from ), args ); | |
} | |
/* | |
@@ -1458,14 +1423,18 @@ CL_GetMessage | |
Handles recording and playback of demos, on top of NET_ code | |
==================== | |
*/ | |
-static qboolean CL_GetMessage( byte *data, size_t *length ) | |
+int CL_GetMessage( byte *data, size_t *length ) | |
{ | |
if( cls.demoplayback ) | |
{ | |
- return CL_DemoReadMessage( data, length ); | |
+ if( CL_DemoReadMessage( data, length )) | |
+ return true; | |
+ return false; | |
} | |
- return NET_GetPacket( NS_CLIENT, &net_from, data, length ); | |
+ if( NET_GetPacket( NS_CLIENT, &net_from, data, length )) | |
+ return true; | |
+ return false; | |
} | |
/* | |
@@ -1579,9 +1548,8 @@ A file has been received via the fragmen | |
void CL_ProcessFile( qboolean successfully_received, const char *filename ) | |
{ | |
if( successfully_received) | |
- MsgDev( D_INFO, "Received %s\n", filename ); | |
- else | |
- MsgDev( D_WARN, "Failed to download %s\n", filename ); | |
+ MsgDev( D_INFO, "received %s\n", filename ); | |
+ else MsgDev( D_WARN, "failed to download %s", filename ); | |
if( cls.downloadfileid == cls.downloadcount - 1 ) | |
{ | |
@@ -1639,8 +1607,6 @@ void CL_Precache_f( void ) | |
CL_PrepSound(); | |
CL_PrepVideo(); | |
- Cvar_SetCheatState( false ); | |
- | |
BF_WriteByte( &cls.netchan.message, clc_stringcmd ); | |
BF_WriteString( &cls.netchan.message, va( "begin %i\n", spawncount )); | |
} | |
@@ -1677,80 +1643,61 @@ void CL_InitLocal( void ) | |
// register our variables | |
cl_predict = Cvar_Get( "cl_predict", "0", CVAR_ARCHIVE, "enable client movement prediction" ); | |
cl_crosshair = Cvar_Get( "crosshair", "1", CVAR_ARCHIVE, "show weapon chrosshair" ); | |
- cl_nodelta = Cvar_Get ("cl_nodelta", "0", 0, "disable delta-compression for usercommands" ); | |
+ cl_nodelta = Cvar_Get ("cl_nodelta", "0", 0, "disable delta-compression for usercommnds" ); | |
cl_idealpitchscale = Cvar_Get( "cl_idealpitchscale", "0.8", 0, "how much to look up/down slopes and stairs when not using freelook" ); | |
- cl_solid_players = Cvar_Get( "cl_solid_players", "1", 0, "make all players non-solid (can't traceline them)" ); | |
- cl_interp = Cvar_Get( "ex_interp", "0.1", 0, "interpolate object positions starting this many seconds in past" ); | |
- //Cvar_Get( "ex_maxerrordistance", "0", 0, "" ); | |
- cl_allow_fragment = Cvar_Get( "cl_allow_fragment", "0", CVAR_ARCHIVE, "allow downloading files directly from game server" ); | |
- cl_timeout = Cvar_Get( "cl_timeout", "60", 0, "connect timeout (in seconds)" ); | |
- cl_charset = Cvar_Get( "cl_charset", "utf-8", CVAR_ARCHIVE, "1-byte charset to use (iconv style)" ); | |
+ cl_solid_players = Cvar_Get( "cl_solid_players", "1", 0, "Make all players not solid (can't traceline them)" ); | |
+ cl_interp = Cvar_Get( "ex_interp", "0.1", 0, "Interpolate object positions starting this many seconds in past" ); | |
+ cl_timeout = Cvar_Get( "cl_timeout", "60", 0, "connect timeout (in-seconds)" ); | |
rcon_client_password = Cvar_Get( "rcon_password", "", 0, "remote control client password" ); | |
rcon_address = Cvar_Get( "rcon_address", "", 0, "remote control address" ); | |
- r_oldparticles = Cvar_Get("r_oldparticles", "0", CVAR_ARCHIVE, "make some particle textures a simple square, like with software rendering"); | |
- | |
- cl_trace_events = Cvar_Get( "cl_trace_events", "0", CVAR_ARCHIVE|CVAR_CHEAT, "enable client event tracing (good for developers)" ); | |
- | |
- cl_trace_stufftext = Cvar_Get( "cl_trace_stufftext", "0", CVAR_ARCHIVE|CVAR_CHEAT, "enable stufftext commands tracing (good for developers)" ); | |
- | |
// userinfo | |
Cvar_Get( "password", "", CVAR_USERINFO, "player password" ); | |
- // cvar is not registered as userinfo as it not needed usually | |
- // it will be set as userinfo only if it has non-default and correct value | |
- cl_maxpacket = Cvar_Get( "cl_maxpacket", "40000", CVAR_ARCHIVE, "Max packet size, sent from server durning connection" ); | |
- name = Cvar_Get( "name", Sys_GetCurrentUser(), CVAR_USERINFO|CVAR_ARCHIVE|CVAR_PRINTABLEONLY, "player name" ); | |
model = Cvar_Get( "model", "player", CVAR_USERINFO|CVAR_ARCHIVE, "player model ('player' is a singleplayer model)" ); | |
+ name = Cvar_Get( "name", Sys_GetCurrentUser(), CVAR_USERINFO|CVAR_ARCHIVE|CVAR_PRINTABLEONLY, "player name" ); | |
topcolor = Cvar_Get( "topcolor", "0", CVAR_USERINFO|CVAR_ARCHIVE, "player top color" ); | |
bottomcolor = Cvar_Get( "bottomcolor", "0", CVAR_USERINFO|CVAR_ARCHIVE, "player bottom color" ); | |
rate = Cvar_Get( "rate", "25000", CVAR_USERINFO|CVAR_ARCHIVE, "player network rate" ); | |
hltv = Cvar_Get( "hltv", "0", CVAR_USERINFO|CVAR_LATCH, "HLTV mode" ); | |
cl_showfps = Cvar_Get( "cl_showfps", "1", CVAR_ARCHIVE, "show client fps" ); | |
- cl_showpos = Cvar_Get( "cl_showpos", "0", CVAR_ARCHIVE, "show local player position and velocity" ); | |
+ cl_smooth = Cvar_Get ("cl_smooth", "0", CVAR_ARCHIVE, "smooth up stair climbing and interpolate position in multiplayer" ); | |
cl_cmdbackup = Cvar_Get( "cl_cmdbackup", "10", CVAR_ARCHIVE, "how many additional history commands are sent" ); | |
- cl_cmdrate = Cvar_Get( "cl_cmdrate", "30", CVAR_ARCHIVE, "max number of command packets sent to server per second" ); | |
- cl_draw_particles = Cvar_Get( "cl_draw_particles", "1", CVAR_ARCHIVE, "disable particle effects" ); | |
- cl_draw_beams = Cvar_Get( "cl_draw_beams", "1", CVAR_ARCHIVE, "disable view beams" ); | |
- cl_lightstyle_lerping = Cvar_Get( "cl_lightstyle_lerping", "0", CVAR_ARCHIVE, "enable animated light lerping (perfomance option)" ); | |
- cl_sprite_nearest = Cvar_Get( "cl_sprite_nearest", "0", CVAR_ARCHIVE, "disable texture filtering on sprites" ); | |
+ cl_cmdrate = Cvar_Get( "cl_cmdrate", "30", CVAR_ARCHIVE, "Max number of command packets sent to server per second" ); | |
+ cl_draw_particles = Cvar_Get( "cl_draw_particles", "1", CVAR_ARCHIVE, "Disable any particle effects" ); | |
+ cl_draw_beams = Cvar_Get( "cl_draw_beams", "1", CVAR_ARCHIVE, "Disable view beams" ); | |
+ cl_lightstyle_lerping = Cvar_Get( "cl_lightstyle_lerping", "0", CVAR_ARCHIVE, "enables animated light lerping (perfomance option)" ); | |
cl_showerror = Cvar_Get( "cl_showerror", "0", CVAR_ARCHIVE, "show prediction error" ); | |
- cl_updaterate = Cvar_Get( "cl_updaterate", "60", CVAR_USERINFO|CVAR_ARCHIVE, "refresh rate of server messages" ); | |
- cl_nosmooth = Cvar_Get( "cl_nosmooth", "0", CVAR_ARCHIVE, "smooth up stair climbing and interpolate position in multiplayer" ); | |
- cl_smoothtime = Cvar_Get( "cl_smoothtime", "0.1", CVAR_ARCHIVE, "time to smooth up" ); | |
- r_bmodelinterp = Cvar_Get( "r_bmodelinterp", "1", 0, "enable bmodel interpolation" ); | |
- hud_scale = Cvar_Get( "hud_scale", "0", CVAR_ARCHIVE|CVAR_LATCH, "scale hud at current resolution" ); | |
+ Cvar_Get( "hud_scale", "0", CVAR_ARCHIVE|CVAR_LATCH, "scale hud at current resolution" ); | |
Cvar_Get( "skin", "", CVAR_USERINFO, "player skin" ); // XDM 3.3 want this cvar | |
- Cvar_Get( "cl_background", "0", CVAR_READ_ONLY, "indicates that background map is running" ); | |
+ Cvar_Get( "cl_updaterate", "60", CVAR_USERINFO|CVAR_ARCHIVE, "refresh rate of server messages" ); | |
+ Cvar_Get( "cl_background", "0", CVAR_READ_ONLY, "indicate what background map is running" ); | |
// these two added to shut up CS 1.5 about 'unknown' commands | |
- Cvar_Get( "lightgamma", "1", 0, "ambient lighting level (legacy, unused)" ); | |
- Cvar_Get( "direct", "1", 0, "direct lighting level (legacy, unused)" ); | |
+ Cvar_Get( "lightgamma", "1", CVAR_ARCHIVE, "ambient lighting level (legacy, unused)" ); | |
+ Cvar_Get( "direct", "1", CVAR_ARCHIVE, "direct lighting level (legacy, unused)" ); | |
Cvar_Get( "voice_serverdebug", "0", 0, "debug voice (legacy, unused)" ); | |
+ // interpolation cvars | |
+ Cvar_Get( "ex_interp", "0", 0, "" ); | |
+ Cvar_Get( "ex_maxerrordistance", "0", 0, "" ); | |
+ | |
// server commands | |
- Cmd_AddCommand ("noclip", NULL, "toggle noclipping mode" ); | |
+ Cmd_AddCommand ("noclip", NULL, "enable or disable no clipping mode" ); | |
Cmd_AddCommand ("notarget", NULL, "notarget mode (monsters do not see you)" ); | |
- Cmd_AddCommand ("fullupdate", NULL, "re-init HUD on start of demo recording" ); | |
+ Cmd_AddCommand ("fullupdate", NULL, "re-init HUD on start demo recording" ); | |
Cmd_AddCommand ("give", NULL, "give specified item or weapon" ); | |
Cmd_AddCommand ("drop", NULL, "drop current/specified item or weapon" ); | |
Cmd_AddCommand ("gametitle", NULL, "show game logo" ); | |
- Cmd_AddCommand ("god", NULL, "toggle godmode" ); | |
+ Cmd_AddCommand ("god", NULL, "enable godmode" ); | |
Cmd_AddCommand ("fov", NULL, "set client field of view" ); | |
- Cmd_AddCommand ("kill", NULL, "commit suicide" ); | |
- Cmd_AddCommand ("ent_list", NULL, "list entities on server" ); | |
- Cmd_AddCommand ("ent_fire", NULL, "fire entity command (be careful)" ); | |
- Cmd_AddCommand ("ent_info", NULL, "dump entity information" ); | |
- Cmd_AddCommand ("ent_create", NULL, "create entity with specified values (be careful)" ); | |
- Cmd_AddCommand ("ent_getvars", NULL, "put parameters of specified entities to client's' ent_last_* cvars" ); | |
- | |
// register our commands | |
Cmd_AddCommand ("pause", NULL, "pause the game (if the server allows pausing)" ); | |
Cmd_AddCommand ("localservers", CL_LocalServers_f, "collect info about local servers" ); | |
Cmd_AddCommand ("internetservers", CL_InternetServers_f, "collect info about internet servers" ); | |
- Cmd_AddCommand ("cd", CL_PlayCDTrack_f, "play cd-track (not real cd-player of course)" ); | |
+ Cmd_AddCommand ("cd", CL_PlayCDTrack_f, "Play cd-track (not real cd-player of course)" ); | |
Cmd_AddCommand ("userinfo", CL_Userinfo_f, "print current client userinfo" ); | |
Cmd_AddCommand ("physinfo", CL_Physinfo_f, "print current client physinfo" ); | |
@@ -1774,9 +1721,9 @@ void CL_InitLocal( void ) | |
Cmd_AddCommand ("snapshot", CL_SnapShot_f, "takes a snapshot of the next rendered frame" ); | |
Cmd_AddCommand ("envshot", CL_EnvShot_f, "takes a six-sides cubemap shot with specified name" ); | |
Cmd_AddCommand ("skyshot", CL_SkyShot_f, "takes a six-sides envmap (skybox) shot with specified name" ); | |
- Cmd_AddCommand ("levelshot", CL_LevelShot_f, "same as \"screenshot\", used to create plaque images" ); | |
- Cmd_AddCommand ("saveshot", CL_SaveShot_f, "used to create save previews with LoadGame menu" ); | |
- Cmd_AddCommand ("demoshot", CL_DemoShot_f, "used to create demo previews with PlayDemo menu" ); | |
+ Cmd_AddCommand ("levelshot", CL_LevelShot_f, "same as \"screenshot\", used for create plaque images" ); | |
+ Cmd_AddCommand ("saveshot", CL_SaveShot_f, "used for create save previews with LoadGame menu" ); | |
+ Cmd_AddCommand ("demoshot", CL_DemoShot_f, "used for create demo previews with PlayDemo menu" ); | |
Cmd_AddCommand ("connect", CL_Connect_f, "connect to a server by hostname" ); | |
Cmd_AddCommand ("reconnect", CL_Reconnect_f, "reconnect to current level" ); | |
@@ -1814,7 +1761,8 @@ Host_ClientFrame | |
*/ | |
void Host_ClientFrame( void ) | |
{ | |
- // if client is not active, skip render functions | |
+ // if client is not active, do nothing | |
+ if( !cls.initialized ) return; | |
// decide the simulation time | |
cl.oldtime = cl.time; | |
@@ -1829,12 +1777,11 @@ void Host_ClientFrame( void ) | |
menu.globals->demorecording = cls.demorecording; | |
} | |
-#ifdef XASH_VGUI | |
+ // if in the debugger last frame, don't timeout | |
+ if( host.frametime > 5.0f ) cls.netchan.last_received = Sys_DoubleTime(); | |
+ | |
VGui_RunFrame (); | |
-#endif | |
- if( cls.initialized ) | |
- { | |
clgame.dllFuncs.pfnFrame( host.frametime ); | |
// fetch results from server | |
@@ -1849,11 +1796,9 @@ void Host_ClientFrame( void ) | |
if( !cl.audio_prepped ) CL_PrepSound(); | |
} | |
- } | |
// update the screen | |
SCR_UpdateScreen (); | |
- if( cls.initialized ) | |
- { | |
+ | |
// update audio | |
S_RenderFrame( &cl.refdef ); | |
@@ -1867,8 +1812,6 @@ void Host_ClientFrame( void ) | |
CL_DecayLights (); | |
SCR_RunCinematic(); | |
- } | |
- | |
Con_RunConsole(); | |
cls.framecount++; | |
@@ -1884,11 +1827,7 @@ CL_Init | |
*/ | |
void CL_Init( void ) | |
{ | |
- qboolean loaded; | |
- | |
- Q_memset( &cls, 0, sizeof( cls ) ); | |
- | |
- if( Host_IsDedicated() ) | |
+ if( host.type == HOST_DEDICATED ) | |
return; // nothing running on the client | |
Con_Init(); | |
@@ -1900,46 +1839,14 @@ void CL_Init( void ) | |
// unreliable buffer. unsed for unreliable commands and voice stream | |
BF_Init( &cls.datagram, "cls.datagram", cls.datagram_buf, sizeof( cls.datagram_buf )); | |
- IN_TouchInit(); | |
-#if defined (__ANDROID__) | |
- { | |
- char clientlib[256]; | |
- Q_snprintf( clientlib, sizeof(clientlib), "%s/" CLIENTDLL, getenv("XASH3D_GAMELIBDIR")); | |
- loaded = CL_LoadProgs( clientlib ); | |
- | |
- if( !loaded ) | |
- { | |
- Q_snprintf( clientlib, sizeof(clientlib), "%s/" CLIENTDLL, getenv("XASH3D_ENGLIBDIR")); | |
- loaded = CL_LoadProgs( clientlib ); | |
- } | |
- } | |
-#else | |
- { | |
- char clientlib[256]; | |
- Com_ResetLibraryError(); | |
- if( Sys_GetParmFromCmdLine( "-clientlib", clientlib ) ) | |
- loaded = CL_LoadProgs( clientlib ); | |
- else | |
- loaded = CL_LoadProgs( va( "%s/%s" , GI->dll_path, SI.clientlib )); | |
- if( !loaded ) | |
- { | |
- | |
- loaded = CL_LoadProgs( CLIENTDLL ); | |
+ if( !CL_LoadProgs( va( "%s/client.dll", GI->dll_path ))) | |
+ Host_Error( "can't initialize client.dll\n" ); | |
- } | |
- } | |
-#endif | |
- if( loaded ) | |
- { | |
cls.initialized = true; | |
- cls.keybind_changed = false; | |
cl.maxclients = 1; // allow to drawing player in menu | |
cls.olddemonum = -1; | |
cls.demonum = -1; | |
} | |
- else | |
- Sys_Warn("Could not load client library:\n%s", Com_GetLibraryError()); | |
-} | |
/* | |
=============== | |
@@ -1949,28 +1856,22 @@ CL_Shutdown | |
*/ | |
void CL_Shutdown( void ) | |
{ | |
- if( cls.initialized ) | |
- { | |
+ // already freed | |
+ if( !cls.initialized ) return; | |
+ cls.initialized = false; | |
+ | |
MsgDev( D_INFO, "CL_Shutdown()\n" ); | |
Host_WriteOpenGLConfig (); | |
Host_WriteVideoConfig (); | |
- } | |
- IN_TouchShutdown(); | |
+ | |
CL_CloseDemoHeader(); | |
IN_Shutdown (); | |
- Mobile_Destroy(); | |
- | |
SCR_Shutdown (); | |
- if( cls.initialized ) | |
- { | |
CL_UnloadProgs (); | |
- cls.initialized = false; | |
- } | |
FS_Delete( "demoheader.tmp" ); // remove tmp file | |
SCR_FreeCinematic (); // release AVI's *after* client.dll because custom renderer may use them | |
S_Shutdown (); | |
R_Shutdown (); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_menu.c /mnt/data/Xash3D_original/engine/client/cl_menu.c | |
--- engine/client/cl_menu.c 2016-08-12 08:25:28.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_menu.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,18 +13,14 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "const.h" | |
#include "gl_local.h" | |
#include "library.h" | |
#include "input.h" | |
-#include "events.h" | |
static MENUAPI GetMenuAPI; | |
-static ADDTOUCHBUTTONTOLIST pfnAddTouchButtonToList; | |
static void UI_UpdateUserinfo( void ); | |
menu_static_t menu; | |
@@ -52,16 +48,6 @@ void UI_SetActiveMenu( qboolean fActive | |
{ | |
movie_state_t *cin_state; | |
- if( host_xashds_hacks->value ) | |
- { | |
- if( !cl.refdef.paused && !cls.changelevel && fActive ) | |
- { | |
- Cbuf_InsertText("pause\n"); | |
- Cbuf_Execute(); | |
- } | |
- } | |
- | |
- | |
if( !menu.hInstance ) | |
{ | |
if( !fActive ) | |
@@ -130,7 +116,6 @@ qboolean UI_IsVisible( void ) | |
static void UI_DrawLogo( const char *filename, float x, float y, float width, float height ) | |
{ | |
-#ifdef USE_VFW | |
static float cin_time; | |
static int last_frame = -1; | |
byte *cin_data = NULL; | |
@@ -196,7 +181,6 @@ static void UI_DrawLogo( const char *fil | |
} | |
R_DrawStretchRaw( x, y, width, height, menu.logo_xres, menu.logo_yres, cin_data, redraw ); | |
-#endif | |
} | |
static int UI_GetLogoWidth( void ) | |
@@ -364,7 +348,7 @@ pfnPIC_Load | |
========= | |
*/ | |
-static HIMAGE pfnPIC_Load( const char *szPicName, const byte *image_buf, int image_size, int flags ) | |
+static HIMAGE pfnPIC_Load( const char *szPicName, const byte *image_buf, long image_size, long flags ) | |
{ | |
HIMAGE tx; | |
@@ -640,20 +624,6 @@ static void UI_DrawSetTextColor( int r, | |
menu.ds.textColor[2] = b; | |
menu.ds.textColor[3] = alpha; | |
} | |
-/* | |
-======================= | |
-UI_AddTouchButtonToList | |
- | |
-send button parameters to menu | |
-======================= | |
-*/ | |
-void UI_AddTouchButtonToList( const char *name, const char *texture, const char *command, unsigned char *color, int flags ) | |
-{ | |
- if( pfnAddTouchButtonToList ) | |
- { | |
- pfnAddTouchButtonToList( name, texture, command, color, flags ); | |
- } | |
-} | |
/* | |
==================== | |
@@ -690,7 +660,6 @@ for drawing playermodel previews | |
*/ | |
static void pfnRenderScene( const ref_params_t *fd ) | |
{ | |
- if ( !cls.initialized ) return; | |
// to avoid division by zero | |
if( !fd || fd->fov_x <= 0.0f || fd->fov_y <= 0.0f ) | |
return; | |
@@ -828,10 +797,7 @@ pointer must be released in call place | |
*/ | |
static char *pfnGetClipboardData( void ) | |
{ | |
- char *cb, *copy; | |
- cb = Sys_GetClipboardData(); | |
- copy = copystring( cb ); | |
- return copy; | |
+ return Sys_GetClipboardData(); | |
} | |
/* | |
@@ -844,19 +810,13 @@ int pfnCheckGameDll( void ) | |
{ | |
void *hInst; | |
- if( SV_Active( ) ) | |
- return true; | |
+ if( SV_Active( )) return true; | |
- if( Cvar_VariableInteger("xashds_hacks") ) | |
- return true; | |
- Com_ResetLibraryError(); | |
- if(( hInst = Com_LoadLibrary( SI.gamedll, true )) != NULL ) | |
+ if(( hInst = Com_LoadLibrary( GI->game_dll, true )) != NULL ) | |
{ | |
Com_FreeLibrary( hInst ); | |
return true; | |
} | |
- MsgDev( D_WARN, "Could not load server library:\n%s", Com_GetLibraryError() ); | |
- Com_ResetLibraryError(); | |
return false; | |
} | |
@@ -907,17 +867,19 @@ pfnStartBackgroundTrack | |
static void pfnStartBackgroundTrack( const char *introTrack, const char *mainTrack ) | |
{ | |
S_StartBackgroundTrack( introTrack, mainTrack, 0 ); | |
-} | |
-static void pfnEnableTextInput( int enable ) | |
+ // HACKHACK to remove glitches from background track while new game is started. | |
+ if( !introTrack && !mainTrack ) | |
{ | |
- Key_EnableTextInput( enable, false ); | |
+ S_Activate( 0, host.hWnd ); | |
+ S_Activate( 1, host.hWnd ); | |
+ } | |
} | |
// engine callbacks | |
static ui_enginefuncs_t gEngfuncs = | |
{ | |
- (void*)pfnPIC_Load, | |
+ pfnPIC_Load, | |
GL_FreeImage, | |
pfnPIC_Width, | |
pfnPIC_Height, | |
@@ -940,10 +902,10 @@ static ui_enginefuncs_t gEngfuncs = | |
Cmd_Argc, | |
Cmd_Argv, | |
Cmd_Args, | |
- (void*)Con_Printf, | |
- (void*)Con_DPrintf, | |
- (void*)UI_NPrintf, | |
- (void*)UI_NXPrintf, | |
+ Con_Printf, | |
+ Con_DPrintf, | |
+ UI_NPrintf, | |
+ UI_NXPrintf, | |
pfnPlaySound, | |
UI_DrawLogo, | |
UI_GetLogoWidth, | |
@@ -960,10 +922,10 @@ static ui_enginefuncs_t gEngfuncs = | |
pfnRenderScene, | |
CL_AddEntity, | |
Host_Error, | |
- (void*)FS_FileExists, | |
+ FS_FileExists, | |
pfnGetGameDir, | |
- (void*)Cmd_CheckMapsList, | |
- (void*)CL_Active, | |
+ Cmd_CheckMapsList, | |
+ CL_Active, | |
pfnClientJoin, | |
COM_LoadFileForMe, | |
COM_ParseFile, | |
@@ -973,7 +935,7 @@ static ui_enginefuncs_t gEngfuncs = | |
Key_KeynumToString, | |
Key_GetBinding, | |
Key_SetBinding, | |
- (void*)Key_IsDown, | |
+ Key_IsDown, | |
pfnKeyGetOverstrikeMode, | |
pfnKeySetOverstrikeMode, | |
pfnKeyGetState, | |
@@ -982,29 +944,21 @@ static ui_enginefuncs_t gEngfuncs = | |
pfnGetGameInfo, | |
pfnGetGamesList, | |
pfnGetFilesList, | |
- (void*)SV_GetComment, | |
- (void*)CL_GetComment, | |
+ SV_GetComment, | |
+ CL_GetComment, | |
pfnCheckGameDll, | |
pfnGetClipboardData, | |
- (void*)Sys_ShellExecute, | |
+ Sys_ShellExecute, | |
Host_WriteServerConfig, | |
pfnChangeInstance, | |
pfnStartBackgroundTrack, | |
pfnHostEndGame, | |
Com_RandomFloat, | |
- (void*)Com_RandomLong, | |
- (void*)IN_SetCursor, | |
+ Com_RandomLong, | |
+ IN_SetCursor, | |
pfnIsMapValid, | |
GL_ProcessTexture, | |
- (void*)COM_CompareFileTime, | |
-}; | |
- | |
-static ui_textfuncs_t gTextfuncs = | |
-{ | |
- pfnEnableTextInput, | |
- Con_UtfProcessChar, | |
- Con_UtfMoveLeft, | |
- Con_UtfMoveRight | |
+ COM_CompareFileTime, | |
}; | |
void UI_UnloadProgs( void ) | |
@@ -1022,38 +976,27 @@ void UI_UnloadProgs( void ) | |
qboolean UI_LoadProgs( void ) | |
{ | |
static ui_enginefuncs_t gpEngfuncs; | |
- static ui_textfuncs_t gpTextfuncs; | |
static ui_globalvars_t gpGlobals; | |
int i; | |
- UITEXTAPI GiveTextApi; | |
+ | |
if( menu.hInstance ) UI_UnloadProgs(); | |
// setup globals | |
menu.globals = &gpGlobals; | |
-#if defined (__ANDROID__) | |
- char menulib[256]; | |
- Q_snprintf( menulib, 256, "%s/%s", getenv("XASH3D_GAMELIBDIR"), MENUDLL ); | |
- if(!( menu.hInstance = Com_LoadLibrary( menulib, false ))) | |
- { | |
- Q_snprintf( menulib, 256, "%s/%s", getenv("XASH3D_ENGLIBDIR"), MENUDLL ); | |
- if(!( menu.hInstance = Com_LoadLibrary( menulib, false ))) | |
- return false; | |
- } | |
-#else | |
- if(!( menu.hInstance = Com_LoadLibrary( va( "%s/" MENUDLL, GI->dll_path ), false ))) | |
+ | |
+ if(!( menu.hInstance = Com_LoadLibrary( va( "%s/menu.dll", GI->dll_path ), false ))) | |
{ | |
FS_AllowDirectPaths( true ); | |
- if(!( menu.hInstance = Com_LoadLibrary( "../" MENUDLL, false )) | |
- && !( menu.hInstance = Com_LoadLibrary( MENUDLL, false ))) | |
- | |
+ if(!( menu.hInstance = Com_LoadLibrary( "../menu.dll", false ))) | |
{ | |
FS_AllowDirectPaths( false ); | |
return false; | |
} | |
- } | |
-#endif | |
+ | |
FS_AllowDirectPaths( false ); | |
+ } | |
+ | |
if(!( GetMenuAPI = (MENUAPI)Com_GetProcAddress( menu.hInstance, "GetMenuAPI" ))) | |
{ | |
Com_FreeLibrary( menu.hInstance ); | |
@@ -1076,18 +1019,6 @@ qboolean UI_LoadProgs( void ) | |
return false; | |
} | |
- menu.use_text_api = false; | |
- | |
- if( ( GiveTextApi = (UITEXTAPI)Com_GetProcAddress( menu.hInstance, "GiveTextAPI" ) ) ) | |
- { | |
- // make local copy of engfuncs to prevent overwrite it with user dll | |
- Q_memcpy( &gpTextfuncs, &gTextfuncs, sizeof( gpTextfuncs )); | |
- if( GiveTextApi( &gpTextfuncs ) ) | |
- menu.use_text_api = true; | |
- } | |
- | |
- pfnAddTouchButtonToList = (ADDTOUCHBUTTONTOLIST)Com_GetProcAddress( menu.hInstance, "AddTouchButtonToList" ); | |
- | |
// setup gameinfo | |
for( i = 0; i < SI.numgames; i++ ) | |
{ | |
@@ -1105,4 +1036,3 @@ qboolean UI_LoadProgs( void ) | |
return true; | |
} | |
-#endif // XASH_DEDICATED | |
Только в engine/client: cl_mobile.c | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_parse.c /mnt/data/Xash3D_original/engine/client/cl_parse.c | |
--- engine/client/cl_parse.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_parse.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "net_encode.h" | |
@@ -287,9 +285,6 @@ void CL_ParseSoundPacket( sizebuf_t *msg | |
} | |
else handle = cl.sound_index[sound]; // see precached sound | |
- if( !cl.audio_prepped ) | |
- return; // too early | |
- | |
if( is_ambient ) | |
{ | |
S_AmbientSound( pos, entnum, handle, volume, attn, pitch, flags ); | |
@@ -580,7 +575,7 @@ void CL_ParseServerData( sizebuf_t *msg | |
cls.serverProtocol = i; | |
if( i != PROTOCOL_VERSION ) | |
- Host_Error( "Server uses invalid protocol (%i should be %i)\n", i, PROTOCOL_VERSION ); | |
+ Host_Error( "Server use invalid protocol (%i should be %i)\n", i, PROTOCOL_VERSION ); | |
cl.servercount = BF_ReadLong( msg ); | |
cl.checksum = BF_ReadLong( msg ); | |
@@ -621,15 +616,14 @@ void CL_ParseServerData( sizebuf_t *msg | |
#endif | |
if( !cls.changedemo ) | |
UI_SetActiveMenu( cl.background ); | |
+ else if( !cls.demoplayback ) | |
+ Key_SetKeyDest( key_menu ); | |
cl.refdef.viewentity = cl.playernum + 1; // always keep viewent an actual | |
menu.globals->maxClients = cl.maxclients; | |
Q_strncpy( menu.globals->maptitle, clgame.maptitle, sizeof( menu.globals->maptitle )); | |
- if( cl.maxclients > 1 && r_decals->value > mp_decals->value ) | |
- Cvar_SetFloat( "r_decals", mp_decals->value ); | |
- | |
if( !cls.changelevel && !cls.changedemo ) | |
CL_InitEdicts (); // re-arrange edicts | |
@@ -832,8 +827,6 @@ void CL_ParseBaseline( sizebuf_t *msg ) | |
if( newnum >= clgame.maxEntities ) Host_Error( "CL_AllocEdict: no free edicts\n" ); | |
ent = CL_EDICT_NUM( newnum ); | |
- if( !ent ) | |
- Host_Error( "CL_ParseBaseline: got invalid entity"); | |
Q_memset( &ent->prevstate, 0, sizeof( ent->prevstate )); | |
ent->index = newnum; | |
@@ -1087,16 +1080,12 @@ void CL_CheckingResFile( char *pResFileN | |
byte data[32]; | |
if( FS_FileExists( pResFileName, false )) | |
- return; // already exists | |
- if( FS_FileExists( FS_ToLowerCase( pResFileName ), false ) ) | |
- return; | |
+ return; // already existing | |
cls.downloadcount++; | |
+ Msg( "Starting downloads file: %s\n", pResFileName ); | |
- if( cl_allow_fragment->value ) | |
- { | |
- Msg( "Starting file download: %s\n", pResFileName ); | |
if( cls.state == ca_disconnected ) return; | |
BF_Init( &buf, "ClientPacket", data, sizeof( data )); | |
@@ -1108,9 +1097,6 @@ void CL_CheckingResFile( char *pResFileN | |
// make sure message will be delivered | |
Netchan_Transmit( &cls.netchan, BF_GetNumBytesWritten( &buf ), BF_GetData( &buf )); | |
- } | |
- else | |
- HTTP_AddDownload( pResFileName, -1, true ); | |
} | |
@@ -1150,21 +1136,8 @@ void CL_ParseResourceList( sizebuf_t *ms | |
cls.downloadcount = 0; | |
- HTTP_ResetProcessState(); | |
- | |
for( i = 0; i < reslist.rescount; i++ ) | |
{ | |
- // skip some types | |
-#if 0 | |
- if( reslist.restype[i] == t_model && !Q_strchr( download_types->latched_string, 'm' ) ) | |
- continue; | |
- if( reslist.restype[i] == t_sound && !Q_strchr( download_types->latched_string, 's' ) ) | |
- continue; | |
- if( reslist.restype[i] == t_eventscript && !Q_strchr( download_types->latched_string, 'e' ) ) | |
- continue; | |
- if( reslist.restype[i] == t_generic && !Q_strchr( download_types->latched_string, 'c' ) ) | |
- continue; | |
-#endif | |
if( reslist.restype[i] == t_sound ) | |
CL_CheckingSoundResFile( reslist.resnames[i] ); | |
else CL_CheckingResFile( reslist.resnames[i] ); | |
@@ -1249,9 +1222,9 @@ Set screen shake | |
*/ | |
void CL_ParseScreenShake( sizebuf_t *msg ) | |
{ | |
- clgame.shake.amplitude = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1U << 12)); | |
- clgame.shake.duration = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1U << 12)); | |
- clgame.shake.frequency = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1U << 8)); | |
+ clgame.shake.amplitude = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1<<12)); | |
+ clgame.shake.duration = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1<<12)); | |
+ clgame.shake.frequency = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1<<8)); | |
clgame.shake.time = cl.time + max( clgame.shake.duration, 0.01f ); | |
clgame.shake.next_shake = 0.0f; // apply immediately | |
} | |
@@ -1268,8 +1241,8 @@ void CL_ParseScreenFade( sizebuf_t *msg | |
float duration, holdTime; | |
screenfade_t *sf = &clgame.fade; | |
- duration = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1U << 12)); | |
- holdTime = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1U << 12)); | |
+ duration = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1<<12)); | |
+ holdTime = (float)(word)BF_ReadShort( msg ) * (1.0f / (float)(1<<12)); | |
sf->fadeFlags = BF_ReadShort( msg ); | |
sf->fader = BF_ReadByte( msg ); | |
@@ -1400,7 +1373,7 @@ void CL_ParseUserMessage( sizebuf_t *msg | |
if( svc_num < svc_lastmsg || svc_num >= ( MAX_USER_MESSAGES + svc_lastmsg )) | |
{ | |
// out or range | |
- MsgDev( D_ERROR, "CL_ParseUserMessage: illegible server message %d (out or range)\n", svc_num ); | |
+ Host_Error( "CL_ParseUserMessage: illegible server message %d\n", svc_num ); | |
return; | |
} | |
@@ -1412,10 +1385,7 @@ void CL_ParseUserMessage( sizebuf_t *msg | |
} | |
if( i == MAX_USER_MESSAGES ) // probably unregistered | |
- { | |
- MsgDev( D_ERROR, "CL_ParseUserMessage: illegible server message %d (probably unregistered)\n", svc_num ); | |
- return; | |
- } | |
+ Host_Error( "CL_ParseUserMessage: illegible server message %d\n", svc_num ); | |
// NOTE: some user messages handled into engine | |
if( !Q_strcmp( clgame.msg[i].name, "ScreenShake" )) | |
@@ -1457,16 +1427,6 @@ void CL_ParseUserMessage( sizebuf_t *msg | |
} | |
} | |
-void CL_ParseStuffText( sizebuf_t *msg ) | |
-{ | |
- char *s = BF_ReadString( msg ); | |
- if( cl_trace_stufftext->value ) | |
- { | |
- Msg("^3STUFFTEXT:\n^2%s\n^3END^7\n", s); | |
- } | |
- Cbuf_AddText( s ); | |
-} | |
- | |
/* | |
===================================================================== | |
@@ -1565,7 +1525,8 @@ void CL_ParseServerMessage( sizebuf_t *m | |
if( i == PRINT_CHAT ) S_StartLocalSound( "common/menu2.wav", VOL_NORM, false ); | |
break; | |
case svc_stufftext: | |
- CL_ParseStuffText( msg ); | |
+ s = BF_ReadString( msg ); | |
+ Cbuf_AddText( s ); | |
break; | |
case svc_lightstyle: | |
CL_ParseLightStyle( msg ); | |
@@ -1726,4 +1687,3 @@ void CL_ParseServerMessage( sizebuf_t *m | |
} | |
} | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_pmove.c /mnt/data/Xash3D_original/engine/client/cl_pmove.c | |
--- engine/client/cl_pmove.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_pmove.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "const.h" | |
@@ -22,7 +20,6 @@ GNU General Public License for more deta | |
#include "pm_local.h" | |
#include "particledef.h" | |
#include "studio.h" | |
-#include "library.h" // Loader_GetDllHandle( ) | |
void CL_ClearPhysEnts( void ) | |
{ | |
@@ -32,112 +29,6 @@ void CL_ClearPhysEnts( void ) | |
clgame.pmove->numphysent = 0; | |
} | |
-/* | |
-============= | |
-CL_PushPMStates | |
- | |
-============= | |
-*/ | |
-void CL_PushPMStates( void ) | |
-{ | |
- if( clgame.pushed ) | |
- { | |
- MsgDev( D_WARN, "CL_PushPMStates called with pushed stack\n"); | |
- } | |
- else | |
- { | |
- clgame.oldphyscount = clgame.pmove->numphysent; | |
- clgame.oldviscount = clgame.pmove->numvisent; | |
- clgame.pushed = true; | |
- } | |
- | |
-} | |
- | |
-/* | |
-============= | |
-CL_PopPMStates | |
- | |
-============= | |
-*/ | |
-void CL_PopPMStates( void ) | |
-{ | |
- if( clgame.pushed ) | |
- { | |
- clgame.pmove->numphysent = clgame.oldphyscount; | |
- clgame.pmove->numvisent = clgame.oldviscount; | |
- clgame.pushed = false; | |
- } | |
- else | |
- { | |
- MsgDev( D_WARN, "CL_PopPMStates called without stack\n"); | |
- } | |
-} | |
- | |
-/* | |
-============= | |
-CL_SetUpPlayerPrediction | |
- | |
-============= | |
-*/ | |
-void CL_SetUpPlayerPrediction( int dopred, int includeLocal ) | |
-{ | |
-#if 0 | |
- int i; | |
- entity_state_t *state; | |
- predicted_player_t *player; | |
- cl_entity_t *ent; | |
- | |
- for( i = 0; i < MAX_CLIENTS; i++ ) | |
- { | |
- state = cl.frames[cl.parsecountmod].playerstate[i]; | |
- | |
- player = cl.predicted_players[j]; | |
- player->active = false; | |
- | |
- if( state->messagenum != cl.parsecount ) | |
- continue; // not present this frame | |
- | |
- if( !state->modelindex ) | |
- continue; | |
- | |
- ent = CL_GetEntityByIndex( j + 1 ); | |
- | |
- if( !ent ) // in case | |
- continue; | |
- | |
- // special for EF_NODRAW and local client? | |
- if( state->effects & EF_NODRAW && !includeLocal ) | |
- { | |
- if( cl.playernum == j ) | |
- continue; | |
- | |
- player->active = true; | |
- player->movetype = state->movetype; | |
- player->solid = state->solid; | |
- player->usehull = state->usehull; | |
- | |
- VectorCopy( ent->origin, player->origin ); | |
- VectorCopy( ent->angles, player->angles ); | |
- } | |
- else | |
- { | |
- player->active = true; | |
- player->movetype = state->movetype; | |
- player->solid = state->solid; | |
- player->usehull = state->usehull; | |
- | |
- // don't rewrite origin and angles of local client | |
- if( cl.playernum == j ) | |
- continue; | |
- | |
- VectorCopy(state->origin, player->origin); | |
- VectorCopy(state->angles, player->angles); | |
- } | |
- } | |
-#endif | |
-} | |
- | |
- | |
void CL_ClipPMoveToEntity( physent_t *pe, const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, pmtrace_t *tr ) | |
{ | |
ASSERT( tr != NULL ); | |
@@ -149,7 +40,7 @@ void CL_ClipPMoveToEntity( physent_t *pe | |
} | |
else | |
{ | |
- // function is missing, so we didn't hit anything | |
+ // function is missed, so we didn't hit anything | |
tr->allsolid = false; | |
} | |
} | |
@@ -321,8 +212,9 @@ pmove must be setup with world and solid | |
void CL_SetSolidPlayers( int playernum ) | |
{ | |
int j; | |
+ extern vec3_t player_mins; | |
+ extern vec3_t player_maxs; | |
cl_entity_t *ent; | |
- entity_state_t *state; | |
physent_t *pe; | |
if( !cl_solid_players->integer ) | |
@@ -331,28 +223,13 @@ void CL_SetSolidPlayers( int playernum ) | |
for( j = 0; j < cl.maxclients; j++ ) | |
{ | |
// the player object never gets added | |
- if( j == playernum ) | |
- continue; | |
+ if( j == playernum ) continue; | |
ent = CL_GetEntityByIndex( j + 1 ); | |
if( !ent || !ent->player ) | |
continue; // not present this frame | |
- | |
-#if 1 // came from SetUpPlayerPrediction | |
- state = cl.frames[cl.parsecountmod].playerstate + j; | |
- | |
- // This makes all players no | |
- //if( state->messagenum != cl.parsecount ) | |
- // continue; // not present this frame [2]*/ | |
- | |
- if( state->effects & EF_NODRAW ) | |
- continue; // skip invisible | |
- | |
- if( !state->solid ) | |
- continue; // not solid | |
-#endif | |
pe = &clgame.pmove->physents[clgame.pmove->numphysent]; | |
if( CL_CopyEntityToPhysEnt( pe, ent )) | |
clgame.pmove->numphysent++; | |
@@ -580,15 +457,7 @@ static int pfnHullPointContents( struct | |
{ | |
return PM_HullPointContents( hull, num, p ); | |
} | |
-#if defined(DLL_LOADER) || defined(__MINGW32__) | |
-static pmtrace_t *pfnPlayerTrace_w32(pmtrace_t * retvalue, float *start, float *end, int traceFlags, int ignore_pe) | |
-{ | |
- pmtrace_t tmp; | |
- tmp = PM_PlayerTraceExt( clgame.pmove, start, end, traceFlags, clgame.pmove->numphysent, clgame.pmove->physents, ignore_pe, NULL ); | |
- *retvalue = tmp; | |
- return retvalue; | |
-} | |
-#endif | |
+ | |
static pmtrace_t pfnPlayerTrace( float *start, float *end, int traceFlags, int ignore_pe ) | |
{ | |
return PM_PlayerTraceExt( clgame.pmove, start, end, traceFlags, clgame.pmove->numphysent, clgame.pmove->physents, ignore_pe, NULL ); | |
@@ -681,12 +550,7 @@ static const char *pfnTraceTexture( int | |
static void pfnPlaySound( int channel, const char *sample, float volume, float attenuation, int fFlags, int pitch ) | |
{ | |
- sound_t snd; | |
- | |
- if( !clgame.pmove->runfuncs ) | |
- return; | |
- | |
- snd = S_RegisterSound( sample ); | |
+ sound_t snd = S_RegisterSound( sample ); | |
S_StartSound( NULL, clgame.pmove->player_index + 1, channel, snd, volume, attenuation, pitch, fFlags ); | |
} | |
@@ -705,15 +569,7 @@ static void pfnPlaybackEventFull( int fl | |
iparam1, iparam2, | |
bparam1, bparam2 ); | |
} | |
-#if defined(DLL_LOADER) || defined(__MINGW32__) | |
-static pmtrace_t *pfnPlayerTraceEx_w32( pmtrace_t * retvalue, float *start, float *end, int traceFlags, pfnIgnore pmFilter ) | |
-{ | |
- pmtrace_t tmp; | |
- tmp = PM_PlayerTraceExt( clgame.pmove, start, end, traceFlags, clgame.pmove->numphysent, clgame.pmove->physents, -1, pmFilter ); | |
- *retvalue = tmp; | |
- return retvalue; | |
-} | |
-#endif | |
+ | |
static pmtrace_t pfnPlayerTraceEx( float *start, float *end, int traceFlags, pfnIgnore pmFilter ) | |
{ | |
return PM_PlayerTraceExt( clgame.pmove, start, end, traceFlags, clgame.pmove->numphysent, clgame.pmove->physents, -1, pmFilter ); | |
@@ -789,7 +645,7 @@ void CL_InitClientMove( void ) | |
Q_memcpy( clgame.pmove->player_maxs, clgame.player_maxs, sizeof( clgame.player_maxs )); | |
// common utilities | |
- clgame.pmove->PM_Info_ValueForKey = (void*)Info_ValueForKey; | |
+ clgame.pmove->PM_Info_ValueForKey = Info_ValueForKey; | |
clgame.pmove->PM_Particle = pfnParticle; | |
clgame.pmove->PM_TestPlayerPosition = pfnTestPlayerPosition; | |
clgame.pmove->Con_NPrintf = Con_NPrintf; | |
@@ -802,14 +658,14 @@ void CL_InitClientMove( void ) | |
clgame.pmove->PM_HullPointContents = pfnHullPointContents; | |
clgame.pmove->PM_PlayerTrace = pfnPlayerTrace; | |
clgame.pmove->PM_TraceLine = pfnTraceLine; | |
- clgame.pmove->RandomLong = (void*)Com_RandomLong; | |
+ clgame.pmove->RandomLong = Com_RandomLong; | |
clgame.pmove->RandomFloat = Com_RandomFloat; | |
clgame.pmove->PM_GetModelType = pfnGetModelType; | |
clgame.pmove->PM_GetModelBounds = pfnGetModelBounds; | |
- clgame.pmove->PM_HullForBsp = (void*)pfnHullForBsp; | |
+ clgame.pmove->PM_HullForBsp = pfnHullForBsp; | |
clgame.pmove->PM_TraceModel = pfnTraceModel; | |
- clgame.pmove->COM_FileSize = (void*)COM_FileSize; | |
- clgame.pmove->COM_LoadFile = (void*)COM_LoadFile; | |
+ clgame.pmove->COM_FileSize = COM_FileSize; | |
+ clgame.pmove->COM_LoadFile = COM_LoadFile; | |
clgame.pmove->COM_FreeFile = COM_FreeFile; | |
clgame.pmove->memfgets = COM_MemFgets; | |
clgame.pmove->PM_PlaySound = pfnPlaySound; | |
@@ -819,17 +675,6 @@ void CL_InitClientMove( void ) | |
clgame.pmove->PM_TestPlayerPositionEx = pfnTestPlayerPositionEx; | |
clgame.pmove->PM_TraceLineEx = pfnTraceLineEx; | |
clgame.pmove->PM_TraceSurface = pfnTraceSurface; | |
-#ifdef DLL_LOADER // w32-compatible ABI | |
- if( host.enabledll && Loader_GetDllHandle( clgame.hInstance ) ) | |
- { | |
- clgame.pmove->PM_PlayerTrace = (void*)pfnPlayerTrace_w32; | |
- clgame.pmove->PM_PlayerTraceEx = (void*)pfnPlayerTraceEx_w32; | |
- } | |
-#endif | |
-#if defined(__MINGW32__) | |
- clgame.pmove->PM_PlayerTrace = (void*)pfnPlayerTrace_w32; | |
- clgame.pmove->PM_PlayerTraceEx = (void*)pfnPlayerTraceEx_w32; | |
-#endif | |
// initalize pmove | |
clgame.dllFuncs.pfnPlayerMoveInit( clgame.pmove ); | |
@@ -994,9 +839,8 @@ void CL_RunUsercmd( local_state_t *from, | |
while( u->msec > 50 ) | |
{ | |
split = *u; | |
- split.msec /= 2.0; | |
+ split.msec /= 2; | |
CL_RunUsercmd( from, &temp, &split, runfuncs, time, random_seed ); | |
- | |
from = &temp; | |
u = &split; | |
} | |
@@ -1013,10 +857,6 @@ void CL_RunUsercmd( local_state_t *from, | |
// copy results back to client | |
CL_FinishPMove( clgame.pmove, to ); | |
- cl.predicted.lastground = clgame.pmove->onground; | |
- if( cl.predicted.lastground > 0 && cl.predicted.lastground < clgame.pmove->numphysent ) | |
- cl.predicted.lastground = clgame.pmove->physents[cl.predicted.lastground].info; | |
- | |
clgame.dllFuncs.pfnPostRunCmd( from, to, &cmd, runfuncs, *time, random_seed ); | |
*time += (double)cmd.msec / 1000.0; | |
} | |
@@ -1038,30 +878,26 @@ void CL_CheckPredictionError( void ) | |
frame = ( cls.netchan.incoming_acknowledged ) & CL_UPDATE_MASK; | |
// compare what the server returned with what we had predicted it to be | |
- VectorSubtract( cl.frame.playerstate[cl.playernum].origin, cl.predicted.origins[frame], delta ); | |
+ VectorSubtract( cl.frame.playerstate[cl.playernum].origin, cl.predicted_origins[frame], delta ); | |
maxspd = ( clgame.movevars.maxvelocity * host.frametime ); | |
len = VectorLength( delta ); | |
// save the prediction error for interpolation | |
- /*if(( cl.frame.client.flags & EF_NOINTERP ) || len > maxspd )*/ | |
- if( len > 64.0f ) | |
+ if(( cl.frame.client.flags & EF_NOINTERP ) || len > maxspd ) | |
{ | |
// a teleport or something or gamepaused | |
- VectorClear( cl.predicted.error ); | |
+ VectorClear( cl.prediction_error ); | |
} | |
else | |
{ | |
if( cl_showerror->value && len > 0.5f ) | |
MsgDev( D_ERROR, "prediction error on %i: %g\n", cl.parsecount, len ); | |
- VectorCopy( cl.frame.playerstate[cl.playernum].origin, cl.predicted.origins[frame] ); | |
- | |
- // save for error interpolation | |
- VectorCopy( delta, cl.predicted.error ); | |
+ VectorCopy( cl.frame.playerstate[cl.playernum].origin, cl.predicted_origins[frame] ); | |
- if ( len > 0.25 && cl.maxclients > 1 ) | |
- cl.predicted.correction_time = cl_smoothtime->value; | |
+ // save for error itnerpolation | |
+ VectorCopy( delta, cl.prediction_error ); | |
} | |
} | |
@@ -1076,10 +912,7 @@ void CL_PostRunCmd( usercmd_t *ucmd, int | |
{ | |
local_state_t from, to; | |
- Q_memset( &from, 0, sizeof( local_state_t ) ); | |
- Q_memset( &to, 0, sizeof( local_state_t ) ); | |
- Q_memcpy( from.weapondata, cl.frame.weapondata, sizeof( from.weapondata )); | |
- | |
+ memcpy( from.weapondata, cl.frame.weapondata, sizeof( from.weapondata )); | |
from.playerstate = cl.frame.playerstate[cl.playernum]; | |
from.client = cl.frame.client; | |
to = from; | |
@@ -1103,7 +936,7 @@ void CL_PredictMovement( void ) | |
int ack, outgoing_command; | |
int current_command; | |
int current_command_mod; | |
- local_state_t *from = 0, *to = 0; | |
+ local_state_t *from = NULL, *to = NULL; | |
if( cls.state != ca_active ) return; | |
@@ -1115,8 +948,6 @@ void CL_PredictMovement( void ) | |
if( !CL_IsInGame( )) return; | |
- CL_SetUpPlayerPrediction( false, false ); | |
- | |
// unpredicted pure angled values converted into axis | |
AngleVectors( cl.refdef.cl_viewangles, cl.refdef.forward, cl.refdef.right, cl.refdef.up ); | |
@@ -1124,28 +955,8 @@ void CL_PredictMovement( void ) | |
if( !CL_IsPredicted( )) | |
{ | |
- local_state_t from = { 0 }, to = { 0 }; | |
- | |
- Q_memcpy( from.weapondata, cl.frame.weapondata, sizeof( from.weapondata )); | |
- from.playerstate = cl.frame.playerstate[cl.playernum]; | |
- from.client = cl.frame.client; | |
- | |
- to = from; | |
- | |
- clgame.dllFuncs.pfnPostRunCmd( &from, &to, cl.refdef.cmd, !cl_predict->integer ? true : false, cl.time, cls.lastoutgoingcommand ); | |
- | |
- // fake unpredicted values | |
- VectorCopy( to.client.origin, cl.predicted.origin ); | |
- VectorCopy( to.client.velocity, cl.predicted.velocity ); | |
- VectorCopy( to.client.punchangle, cl.predicted.punchangle ); | |
- VectorCopy( to.client.view_ofs, cl.predicted.viewofs ); | |
- cl.predicted.usehull = to.playerstate.usehull; | |
- cl.predicted.waterlevel = to.client.waterlevel; | |
- cl.predicted.viewmodel = to.client.viewmodel; | |
- cl.predicted.correction_time = 0; | |
- cl.predicted.moving = 0; | |
- cl.predicted.onground = -1; | |
- | |
+ // run commands even if client predicting is disabled - client expected it | |
+ CL_PostRunCmd( cl.refdef.cmd, cls.lastoutgoingcommand ); | |
return; | |
} | |
@@ -1153,7 +964,7 @@ void CL_PredictMovement( void ) | |
outgoing_command = cls.netchan.outgoing_sequence; | |
from = &cl.predict[cl.parsecountmod]; | |
- Q_memcpy( from->weapondata, cl.frame.weapondata, sizeof( from->weapondata )); | |
+ memcpy( from->weapondata, cl.frame.weapondata, sizeof( from->weapondata )); | |
from->playerstate = cl.frame.playerstate[cl.playernum]; | |
from->client = cl.frame.client; | |
@@ -1184,7 +995,7 @@ void CL_PredictMovement( void ) | |
cl.commands[current_command_mod].processedfuncs = true; | |
// save for debug checking | |
- VectorCopy( to->playerstate.origin, cl.predicted.origins[current_command_mod] ); | |
+ VectorCopy( to->playerstate.origin, cl.predicted_origins[current_command_mod] ); | |
from = to; | |
frame++; | |
@@ -1192,103 +1003,9 @@ void CL_PredictMovement( void ) | |
if( to ) | |
{ | |
- float t0 = cl.commands[( cl.parsecountmod + frame - 1) & CL_UPDATE_MASK].senttime, | |
- t1 = cl.commands[( cl.parsecountmod + frame ) & CL_UPDATE_MASK].senttime; | |
- float t; | |
- if( t0 == t1 ) | |
- t = 0.0f; | |
- else | |
- { | |
- t = (host.realtime - t0) / (t1 - t0); | |
- t = bound( 0.0f, t, 1.0f ); | |
- } | |
- | |
- if( fabs(to->playerstate.origin[0] - from->playerstate.origin[0]) > 128.0f || | |
- fabs(to->playerstate.origin[1] - from->playerstate.origin[1]) > 128.0f || | |
- fabs(to->playerstate.origin[2] - from->playerstate.origin[2]) > 128.0f ) | |
- { | |
- VectorCopy( to->playerstate.origin, cl.predicted.origin ); | |
- VectorCopy( to->client.velocity, cl.predicted.velocity ); | |
- VectorCopy( to->client.punchangle, cl.predicted.punchangle ); | |
- VectorCopy( to->client.view_ofs, cl.predicted.viewofs ); | |
- } | |
- else | |
- { | |
- vec3_t delta_origin, delta_punch, delta_vel; | |
- VectorSubtract( to->playerstate.origin, from->playerstate.origin, delta_origin ); | |
- VectorSubtract( to->client.velocity, from->client.velocity, delta_vel ); | |
- VectorSubtract( to->client.punchangle, from->client.punchangle, delta_punch ); | |
- | |
- VectorMA( from->playerstate.origin, t, delta_origin, cl.predicted.origin ); | |
- VectorMA( from->client.velocity, t, delta_vel, cl.predicted.velocity ); | |
- VectorMA( from->client.punchangle, t, delta_punch, cl.predicted.punchangle ); | |
- | |
- if( from->playerstate.usehull == to->playerstate.usehull ) | |
- { | |
- vec3_t delta_viewofs; | |
- VectorSubtract( to->client.view_ofs, from->client.view_ofs, delta_viewofs ); | |
- VectorMA( from->client.view_ofs, t, delta_viewofs, cl.predicted.viewofs ); | |
- } | |
- } | |
- | |
- cl.predicted.waterlevel = to->client.waterlevel; | |
- cl.predicted.viewmodel = to->client.viewmodel; | |
- cl.predicted.usehull = to->playerstate.usehull; | |
- | |
- if( to->client.flags & FL_ONGROUND ) | |
- { | |
- cl_entity_t *ent = CL_GetEntityByIndex( cl.predicted.lastground ); | |
- | |
- cl.predicted.onground = cl.predicted.lastground; | |
- cl.predicted.moving = 0; | |
- | |
- if( ent ) | |
- { | |
- vec3_t delta; | |
- delta[0] = ent->curstate.origin[0] - ent->prevstate.origin[0]; | |
- delta[1] = ent->curstate.origin[1] - ent->prevstate.origin[1]; | |
- delta[2] = 0.0f; | |
- | |
- if( VectorLength( delta ) > 0.0f ) | |
- { | |
- cl.predicted.moving = 1; | |
- cl.predicted.correction_time = 0; | |
- } | |
- } | |
- } | |
- else | |
- { | |
- cl.predicted.onground = -1; | |
- cl.predicted.moving = 0; | |
- } | |
- | |
- if ( cl.predicted.correction_time > 0.0 && !cl_nosmooth->value && cl_smoothtime->value ) | |
- { | |
- float d; | |
- vec3_t delta; | |
- int i; | |
- | |
- cl.predicted.correction_time = cl.predicted.correction_time - host.frametime; | |
- | |
- if( cl_smoothtime->value <= 0 ) | |
- Cvar_SetFloat( "cl_smoothtime", 0.1 ); | |
- | |
- if( cl.predicted.correction_time < 0 ) | |
- cl.predicted.correction_time = 0; | |
- | |
- if( cl_smoothtime->value <= cl.predicted.correction_time ) | |
- cl.predicted.correction_time = cl_smoothtime->value; | |
- | |
- d = cl.predicted.correction_time / cl_smoothtime->value; | |
- | |
- for( i = 0; i < 3; i++ ) | |
- { | |
- cl.predicted.origin[i] = cl.predicted.lastorigin[i] + ( cl.predicted.origin[i] - cl.predicted.lastorigin[i] ) * (1.0 - d); | |
- } | |
- } | |
- VectorCopy( cl.predicted.origin, cl.predicted.lastorigin ); | |
- CL_SetIdealPitch(); | |
+ VectorCopy( to->playerstate.origin, cl.predicted_origin ); | |
+ VectorCopy( to->client.velocity, cl.predicted_velocity ); | |
+ VectorCopy( to->client.view_ofs, cl.predicted_viewofs ); | |
+ VectorCopy( to->client.punchangle, cl.predicted_punchangle ); | |
} | |
- CL_CheckPredictionError(); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_remap.c /mnt/data/Xash3D_original/engine/client/cl_remap.c | |
--- engine/client/cl_remap.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_remap.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -80,9 +78,7 @@ byte *CL_CreateRawTextureFromPixels( tex | |
// fill header | |
if( !pin.name[0] ) Q_strncpy( pin.name, "#raw_remap_image.mdl", sizeof( pin.name )); | |
pin.flags = STUDIO_NF_COLORMAP; // just in case :-) | |
- //pin.index = (int)(tx + 1); // pointer to pixels | |
- // no more pointer-to-int-to-pointer casts | |
- Image_SetMDLPointer( (byte*)((texture_t *)tx + 1) ); | |
+ pin.index = (int)(tx + 1); // pointer to pixels | |
pin.width = tx->width; | |
pin.height = tx->height; | |
@@ -106,8 +102,7 @@ void CL_DuplicateTexture( mstudiotexture | |
gltexture_t *glt; | |
texture_t *tx = NULL; | |
char texname[128]; | |
- int i, index; | |
- size_t size; | |
+ int i, size, index; | |
byte paletteBackup[768]; | |
byte *raw, *pal; | |
@@ -151,8 +146,7 @@ void CL_UpdateTexture( mstudiotexture_t | |
rgbdata_t *pic; | |
texture_t *tx = NULL; | |
char texname[128], name[128], mdlname[128]; | |
- int i, index; | |
- size_t size; | |
+ int i, size, index; | |
byte paletteBackup[768]; | |
byte *raw, *pal; | |
@@ -358,4 +352,3 @@ void CL_ClearAllRemaps( void ) | |
} | |
clgame.remap_info = NULL; | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_scrn.c /mnt/data/Xash3D_original/engine/client/cl_scrn.c | |
--- engine/client/cl_scrn.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_scrn.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,14 +13,11 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
#include "vgui_draw.h" | |
#include "qfont.h" | |
-#include "library.h" | |
convar_t *scr_centertime; | |
convar_t *scr_loading; | |
@@ -52,7 +49,7 @@ void SCR_DrawFPS( void ) | |
float calc; | |
rgba_t color; | |
static double nexttime = 0, lasttime = 0; | |
- static double framerate = 0, avgrate = 0; | |
+ static double framerate = 0; | |
static int framecount = 0; | |
static int minfps = 9999; | |
static int maxfps = 0; | |
@@ -84,8 +81,6 @@ void SCR_DrawFPS( void ) | |
framecount++; | |
calc = framerate; | |
- if( calc == 0 ) return; | |
- | |
if( calc < 1.0f ) | |
{ | |
Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i spf", (int)(1.0f / calc + 0.5f)); | |
@@ -98,60 +93,14 @@ void SCR_DrawFPS( void ) | |
if( curfps < minfps ) minfps = curfps; | |
if( curfps > maxfps ) maxfps = curfps; | |
- /*if( !avgrate ) avgrate = ( maxfps - minfps ) / 2.0f; | |
- else */avgrate += ( calc - avgrate ) / host.framecount; | |
- | |
- switch( cl_showfps->integer ) | |
- { | |
- case 3: | |
- Q_snprintf( fpsstring, sizeof( fpsstring ), "fps: ^1%4i min, ^3%4i cur, ^2%4i max | ^3%.2f avg", minfps, curfps, maxfps, avgrate ); | |
- break; | |
- case 2: | |
+ if( cl_showfps->integer == 2 ) | |
Q_snprintf( fpsstring, sizeof( fpsstring ), "fps: ^1%4i min, ^3%4i cur, ^2%4i max", minfps, curfps, maxfps ); | |
- break; | |
- case 1: | |
- default: | |
- Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i fps", curfps ); | |
- } | |
- | |
+ else Q_snprintf( fpsstring, sizeof( fpsstring ), "%4i fps", curfps ); | |
MakeRGBA( color, 255, 255, 255, 255 ); | |
} | |
Con_DrawStringLen( fpsstring, &offset, NULL ); | |
- Con_DrawString( scr_width->integer - offset - 2, 4, fpsstring, color ); | |
-} | |
- | |
-/* | |
-============== | |
-SCR_DrawPos | |
- | |
-Draw local player position, angles and velocity | |
-============== | |
-*/ | |
-void SCR_DrawPos( void ) | |
-{ | |
- static char msg[MAX_SYSPATH]; | |
- float speed; | |
- cl_entity_t *pPlayer; | |
- rgba_t color; | |
- | |
- if( cls.state != ca_active ) return; | |
- if( !cl_showpos->integer || cl.background ) return; | |
- | |
- pPlayer = CL_GetLocalPlayer(); | |
- speed = VectorLength( cl.frame.client.velocity ); | |
- | |
- Q_snprintf( msg, MAX_SYSPATH, | |
- "pos: %.2f %.2f %.2f\n" | |
- "ang: %.2f %.2f %.2f\n" | |
- "velocity: %.2f", pPlayer->origin[0], pPlayer->origin[1], pPlayer->origin[2], | |
- pPlayer->angles[0], pPlayer->angles[1], pPlayer->angles[2], | |
- speed ); | |
- | |
- MakeRGBA( color, 255, 255, 255, 255 ); | |
- | |
- Con_DrawString( scr_width->integer / 2, 4, msg, color ); | |
- | |
+ Con_DrawString( scr_width->integer - offset - 3, 4, fpsstring, color ); | |
} | |
/* | |
@@ -510,19 +459,17 @@ void SCR_LoadCreditsFont( void ) | |
cls.creditsFont.hFontTexture = GL_LoadTexture( "gfx.wad/creditsfont.fnt", NULL, 0, TF_IMAGE, NULL ); | |
R_GetTextureParms( &fontWidth, NULL, cls.creditsFont.hFontTexture ); | |
- if( fontWidth == 0 ) return; | |
- | |
// setup creditsfont | |
if( FS_FileExists( "gfx/creditsfont.fnt", false )) | |
{ | |
byte *buffer; | |
- fs_offset_t length; | |
+ size_t length; | |
qfont_t *src; | |
- // half-life font with variable chars width | |
+ // half-life font with variable chars witdh | |
buffer = FS_LoadFile( "gfx/creditsfont.fnt", &length, false ); | |
- if( buffer && length >= ( fs_offset_t )sizeof( qfont_t )) | |
+ if( buffer && length >= sizeof( qfont_t )) | |
{ | |
int i; | |
@@ -584,7 +531,6 @@ void SCR_RegisterTextures( void ) | |
cls.particleImage = GL_LoadTexture( "*particle", NULL, 0, TF_IMAGE, NULL ); | |
// register gfx.wad images | |
- cls.oldParticleImage = GL_LoadTexture("*oldparticle", NULL, 0, TF_IMAGE, NULL); | |
cls.pauseIcon = GL_LoadTexture( "gfx.wad/paused.lmp", NULL, 0, TF_IMAGE, NULL ); | |
if( cl_allow_levelshots->integer ) | |
cls.loadingBar = GL_LoadTexture( "gfx.wad/lambda.lmp", NULL, 0, TF_IMAGE|TF_LUMINANCE, NULL ); | |
@@ -629,17 +575,12 @@ void SCR_VidInit( void ) | |
Q_memset( &menu.ds, 0, sizeof( menu.ds )); // reset a draw state | |
Q_memset( &clgame.centerPrint, 0, sizeof( clgame.centerPrint )); | |
- if( menu.globals ) | |
- { | |
// update screen sizes for menu | |
menu.globals->scrWidth = scr_width->integer; | |
menu.globals->scrHeight = scr_height->integer; | |
- } | |
SCR_RebuildGammaTable(); | |
-#ifdef XASH_VGUI | |
- VGui_Startup (scr_width->integer, scr_height->integer); | |
-#endif | |
+ VGui_Startup (); | |
clgame.load_sequence++; // now all hud sprites are invalid | |
@@ -678,12 +619,9 @@ void SCR_Init( void ) | |
Cmd_AddCommand( "sizeup", SCR_SizeUp_f, "screen size up to 10 points" ); | |
Cmd_AddCommand( "sizedown", SCR_SizeDown_f, "screen size down to 10 points" ); | |
- Com_ResetLibraryError(); | |
- | |
if( host.state != HOST_RESTART && !UI_LoadProgs( )) | |
{ | |
- Sys_Warn( "can't initialize menu library:\n%s", Com_GetLibraryError() ); // this is not fatal for us | |
- // console still can't be toggled in-game without extra cmd-line switch | |
+ Msg( "^1Error: ^7can't initialize menu.dll\n" ); // there is non fatal for us | |
if( !host.developer ) host.developer = 1; // we need console, because menu is missing | |
} | |
@@ -711,13 +649,10 @@ void SCR_Shutdown( void ) | |
Cmd_RemoveCommand( "timerefresh" ); | |
Cmd_RemoveCommand( "skyname" ); | |
Cmd_RemoveCommand( "viewpos" ); | |
- Cmd_RemoveCommand( "sizeup" ); | |
- Cmd_RemoveCommand( "sizedown" ); | |
UI_SetActiveMenu( false ); | |
if( host.state != HOST_RESTART ) | |
UI_UnloadProgs(); | |
- cls.creditsFont.valid = false; | |
+ | |
scr_init = false; | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_tent.c /mnt/data/Xash3D_original/engine/client/cl_tent.c | |
--- engine/client/cl_tent.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_tent.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "r_efx.h" | |
@@ -205,7 +203,7 @@ void CL_TEntPlaySound( TEMPENTITY *pTemp | |
return; | |
} | |
- zvel = fabs( pTemp->entity.baseline.origin[2] ); | |
+ zvel = abs( pTemp->entity.baseline.origin[2] ); | |
// only play one out of every n | |
if( isshellcasing ) | |
@@ -319,7 +317,7 @@ TEMPENTITY *CL_TempEntAlloc( const vec3_ | |
if( !cl_free_tents ) | |
{ | |
- MsgDev( D_NOTE, "Overflow %d temporary ents!\n", GI->max_tents ); | |
+ MsgDev( D_INFO, "Overflow %d temporary ents!\n", GI->max_tents ); | |
return NULL; | |
} | |
@@ -444,9 +442,6 @@ void CL_FizzEffect( cl_entity_t *pent, i | |
if( !pent || Mod_GetType( modelIndex ) == mod_bad ) | |
return; | |
- if( pent->curstate.modelindex <= 0 ) | |
- return; | |
- | |
count = density + 1; | |
density = count * 3 + 6; | |
@@ -529,7 +524,7 @@ void CL_Bubbles( const vec3_t mins, cons | |
pTemp->x = origin[0]; | |
pTemp->y = origin[1]; | |
- angle = Com_RandomFloat( -M_PI, M_PI ); | |
+ angle = Com_RandomLong( -M_PI, M_PI ); | |
SinCos( angle, &sine, &cosine ); | |
zspeed = Com_RandomLong( 80, 140 ); | |
@@ -574,7 +569,7 @@ void CL_BubbleTrail( const vec3_t start, | |
pTemp->x = origin[0]; | |
pTemp->y = origin[1]; | |
- angle = Com_RandomFloat( -M_PI, M_PI ); | |
+ angle = Com_RandomLong( -M_PI, M_PI ); | |
zspeed = Com_RandomLong( 80, 140 ); | |
VectorSet( pTemp->entity.baseline.origin, speed * cos( angle ), speed * sin( angle ), zspeed ); | |
@@ -2655,9 +2650,9 @@ int CL_DecalIndexFromName( const char *n | |
return 0; | |
// look through the loaded sprite name list for SpriteName | |
- for( i = 0; i < MAX_DECALS - 1 && host.draw_decals[i+1][0]; i++ ) | |
+ for( i = 0; i < MAX_DECALS && host.draw_decals[i+1][0]; i++ ) | |
{ | |
- if( !Q_stricmp( name, (char *)host.draw_decals[i+1] )) | |
+ if( !Q_stricmp( name, host.draw_decals[i+1] )) | |
return i+1; | |
} | |
return 0; // invalid decal | |
@@ -2708,7 +2703,7 @@ int CL_DecalIndex( int id ) | |
} | |
} | |
- if( !load_external ) cl.decal_index[id] = GL_LoadTexture( (char *)host.draw_decals[id], NULL, 0, TF_DECAL, NULL ); | |
+ if( !load_external ) cl.decal_index[id] = GL_LoadTexture( host.draw_decals[id], NULL, 0, TF_DECAL, NULL ); | |
} | |
host.decal_loading = false; | |
@@ -2769,4 +2764,3 @@ void CL_ClearEffects( void ) | |
CL_ClearParticles (); | |
CL_ClearLightStyles (); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_video.c /mnt/data/Xash3D_original/engine/client/cl_video.c | |
--- engine/client/cl_video.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_video.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -110,7 +108,7 @@ void SCR_CheckStartupVids( void ) | |
if( !FS_FileExists( "media/StartupVids.txt", false )) | |
SCR_CreateStartupVids(); | |
- afile = (char *)FS_LoadFile( "media/StartupVids.txt", NULL, false ); | |
+ afile = FS_LoadFile( "media/StartupVids.txt", NULL, false ); | |
if( !afile ) return; // something bad happens | |
pfile = afile; | |
@@ -252,7 +250,7 @@ qboolean SCR_PlayCinematic( const char * | |
return true; | |
} | |
-int SCR_GetAudioChunk( char *rawdata, int length ) | |
+long SCR_GetAudioChunk( char *rawdata, long length ) | |
{ | |
int r; | |
@@ -318,4 +316,3 @@ void SCR_FreeCinematic( void ) | |
AVI_Shutdown(); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/cl_view.c /mnt/data/Xash3D_original/engine/client/cl_view.c | |
--- engine/client/cl_view.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/cl_view.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,15 +13,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "const.h" | |
#include "entity_types.h" | |
#include "gl_local.h" | |
#include "vgui_draw.h" | |
-#include "touch.h" // IN_TouchDraw( ) | |
/* | |
=============== | |
@@ -39,23 +36,24 @@ void V_SetupRefDef( void ) | |
clent = CL_GetLocalPlayer (); | |
clgame.entities->curstate.scale = clgame.movevars.waveHeight; | |
- clgame.viewent.curstate.modelindex = cl.predicted.viewmodel; | |
+ clgame.viewent.curstate.modelindex = cl.frame.client.viewmodel; | |
clgame.viewent.model = Mod_Handle( clgame.viewent.curstate.modelindex ); | |
clgame.viewent.curstate.number = cl.playernum + 1; | |
clgame.viewent.curstate.entityType = ET_NORMAL; | |
clgame.viewent.index = cl.playernum + 1; | |
cl.refdef.movevars = &clgame.movevars; | |
+ cl.refdef.onground = ( cl.frame.client.flags & FL_ONGROUND ) ? 1 : 0; | |
cl.refdef.health = cl.frame.client.health; | |
cl.refdef.playernum = cl.playernum; | |
cl.refdef.max_entities = clgame.maxEntities; | |
cl.refdef.maxclients = cl.maxclients; | |
cl.refdef.time = cl.time; | |
- cl.refdef.frametime = host.frametime; | |
- //cl.refdef.frametime = cl.time - cl.oldtime; | |
+ cl.refdef.frametime = cl.time - cl.oldtime; | |
cl.refdef.demoplayback = cls.demoplayback; | |
- cl.refdef.smoothing = 0; | |
+ cl.refdef.smoothing = cl_smooth->integer; | |
cl.refdef.viewsize = scr_viewsize->integer; | |
+ cl.refdef.waterlevel = cl.frame.client.waterlevel; | |
cl.refdef.onlyClientDraw = 0; // reset clientdraw | |
cl.refdef.hardware = true; // always true | |
cl.refdef.spectator = (clent->curstate.spectator != 0); | |
@@ -83,10 +81,8 @@ void V_SetupRefDef( void ) | |
cl.refdef.viewport[0] = (scr_width->integer - cl.refdef.viewport[2]) / 2; | |
cl.refdef.viewport[1] = (scr_height->integer - sb_lines - cl.refdef.viewport[3]) / 2; | |
- cl.scr_fov = bound( 10.0f, cl.scr_fov, 150.0f ); | |
- | |
// calc FOV | |
- cl.refdef.fov_x = cl.scr_fov; // this is a final fov value | |
+ cl.refdef.fov_x = cl.data.fov; // this is a final fov value | |
cl.refdef.fov_y = V_CalcFov( &cl.refdef.fov_x, cl.refdef.viewport[2], cl.refdef.viewport[3] ); | |
// adjust FOV for widescreen | |
@@ -95,13 +91,11 @@ void V_SetupRefDef( void ) | |
if( CL_IsPredicted( ) && !cl.refdef.demoplayback ) | |
{ | |
- //VectorMA( cl.predicted.origin, cl.lerpBack, cl.predicted.error, cl.predicted.origin ); | |
- VectorCopy( cl.predicted.origin, cl.refdef.simorg ); | |
- VectorCopy( cl.predicted.velocity, cl.refdef.simvel ); | |
- VectorCopy( cl.predicted.viewofs, cl.refdef.viewheight ); | |
- VectorCopy( cl.predicted.punchangle, cl.refdef.punchangle ); | |
- cl.refdef.onground = cl.predicted.onground != -1; | |
- cl.refdef.waterlevel = cl.predicted.waterlevel; | |
+ VectorMA( cl.predicted_origin, -cl.lerpBack, cl.prediction_error, cl.refdef.simorg ); | |
+ VectorCopy( cl.predicted_origin, cl.refdef.simorg ); | |
+ VectorCopy( cl.predicted_velocity, cl.refdef.simvel ); | |
+ VectorCopy( cl.predicted_viewofs, cl.refdef.viewheight ); | |
+ VectorCopy( cl.predicted_punchangle, cl.refdef.punchangle ); | |
} | |
else | |
{ | |
@@ -109,8 +103,6 @@ void V_SetupRefDef( void ) | |
VectorCopy( cl.frame.client.view_ofs, cl.refdef.viewheight ); | |
VectorCopy( cl.frame.client.velocity, cl.refdef.simvel ); | |
VectorCopy( cl.frame.client.punchangle, cl.refdef.punchangle ); | |
- cl.refdef.onground = cl.frame.client.flags & FL_ONGROUND ? 1 : 0; | |
- cl.refdef.waterlevel = cl.frame.client.waterlevel; | |
} | |
} | |
@@ -396,9 +388,7 @@ void V_PostRender( void ) | |
{ | |
SCR_TileClear(); | |
CL_DrawHUD( CL_ACTIVE ); | |
-#ifdef XASH_VGUI | |
VGui_Paint(); | |
-#endif | |
} | |
switch( cls.scrshot_action ) | |
@@ -408,17 +398,13 @@ void V_PostRender( void ) | |
case scrshot_snapshot: | |
draw_2d = true; | |
break; | |
- default: | |
- break; | |
} | |
if( draw_2d ) | |
{ | |
- IN_TouchDraw(); | |
SCR_RSpeeds(); | |
SCR_NetSpeeds(); | |
SCR_DrawFPS(); | |
- SCR_DrawPos(); | |
SV_DrawOrthoTriangles(); | |
CL_DrawDemoRecording(); | |
R_ShowTextures(); | |
@@ -434,4 +419,3 @@ void V_PostRender( void ) | |
SCR_MakeScreenShot(); | |
R_EndFrame(); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_backend.c /mnt/data/Xash3D_original/engine/client/gl_backend.c | |
--- engine/client/gl_backend.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_backend.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -105,7 +103,7 @@ void GL_BackendEndFrame( void ) | |
GL_LoadTexMatrix | |
================= | |
*/ | |
-void GL_LoadTexMatrix( cmatrix4x4 m ) | |
+void GL_LoadTexMatrix( const matrix4x4 m ) | |
{ | |
pglMatrixMode( GL_TEXTURE ); | |
GL_LoadMatrix( m ); | |
@@ -130,7 +128,7 @@ void GL_LoadTexMatrixExt( const float *g | |
GL_LoadMatrix | |
================= | |
*/ | |
-void GL_LoadMatrix( cmatrix4x4 source ) | |
+void GL_LoadMatrix( const matrix4x4 source ) | |
{ | |
GLfloat dest[16]; | |
@@ -184,12 +182,10 @@ void GL_SelectTexture( GLint tmu ) | |
if( tmu < glConfig.max_texture_coords ) | |
pglClientActiveTextureARB( tmu + GL_TEXTURE0_ARB ); | |
} | |
-#ifndef XASH_NANOGL | |
else if( pglSelectTextureSGIS ) | |
{ | |
pglSelectTextureSGIS( tmu + GL_TEXTURE0_SGIS ); | |
} | |
-#endif | |
} | |
/* | |
@@ -238,7 +234,6 @@ GL_MultiTexCoord2f | |
*/ | |
void GL_MultiTexCoord2f( GLenum texture, GLfloat s, GLfloat t ) | |
{ | |
-#ifndef XASH_NANOGL | |
if( pglMultiTexCoord2f ) | |
{ | |
pglMultiTexCoord2f( texture + GL_TEXTURE0_ARB, s, t ); | |
@@ -247,9 +242,6 @@ void GL_MultiTexCoord2f( GLenum texture, | |
{ | |
pglMTexCoord2fSGIS( texture + GL_TEXTURE0_SGIS, s, t ); | |
} | |
-#else | |
- glTexCoord2f( s, t ); | |
-#endif | |
} | |
/* | |
@@ -408,11 +400,7 @@ void GL_SetRenderMode( int mode ) | |
case kRenderTransAdd: | |
pglEnable( GL_BLEND ); | |
pglDisable( GL_ALPHA_TEST ); | |
-#if defined(XASH_GLES) // Problem with blending exists on every GLES configuration, not only on Android | |
- pglBlendFunc( GL_ONE, GL_ONE ); | |
-#else | |
pglBlendFunc( GL_SRC_ALPHA, GL_ONE ); | |
-#endif | |
break; | |
} | |
} | |
@@ -492,15 +480,15 @@ qboolean VID_ScreenShot( const char *fil | |
r_shot = Mem_Alloc( r_temppool, sizeof( rgbdata_t )); | |
r_shot->width = (glState.width + 3) & ~3; | |
r_shot->height = (glState.height + 3) & ~3; | |
- r_shot->flags = IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA; | |
- r_shot->type = PF_RGBA_32; | |
+ r_shot->flags = IMAGE_HAS_COLOR; | |
+ r_shot->type = PF_RGB_24; | |
r_shot->size = r_shot->width * r_shot->height * PFDesc[r_shot->type].bpp; | |
r_shot->palette = NULL; | |
r_shot->buffer = Mem_Alloc( r_temppool, r_shot->size ); | |
// get screen frame | |
- pglPixelStorei(GL_PACK_ALIGNMENT, 1); // PANDORA, just in case | |
- pglReadPixels( 0, 0, r_shot->width, r_shot->height, GL_RGBA, GL_UNSIGNED_BYTE, r_shot->buffer ); | |
+ pglReadPixels( 0, 0, r_shot->width, r_shot->height, GL_RGB, GL_UNSIGNED_BYTE, r_shot->buffer ); | |
+ | |
switch( shot_type ) | |
{ | |
case VID_SCREENSHOT: | |
@@ -661,7 +649,7 @@ void R_ShowTextures( void ) | |
if( showHelp ) | |
{ | |
- CL_CenterPrint( "use '<-' and '->' keys to view all the textures", 0.25f ); | |
+ CL_CenterPrint( "use '<-' and '->' keys for view all the textures", 0.25f ); | |
showHelp = false; | |
} | |
@@ -677,8 +665,8 @@ rebuild_page: | |
end = total * gl_showtextures->integer; | |
if( end > MAX_TEXTURES ) end = MAX_TEXTURES; | |
- w = glState.width / (float)base_w; | |
- h = glState.height / (float)base_h; | |
+ w = glState.width / base_w; | |
+ h = glState.height / base_h; | |
Con_DrawStringLen( NULL, NULL, &charHeight ); | |
@@ -705,10 +693,10 @@ rebuild_page: | |
continue; | |
x = k % base_w * w; | |
- y = k / (float)base_w * h; | |
+ y = k / base_w * h; | |
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); | |
- GL_Bind( XASH_TEXTURE0, i ); // NOTE: don't use image->texnum here, because skybox has a 'wrong' indexes | |
+ GL_Bind( GL_TEXTURE0, i ); // NOTE: don't use image->texnum here, because skybox has a 'wrong' indexes | |
if(( image->flags & TF_DEPTHMAP ) && !( image->flags & TF_NOCOMPARE )) | |
pglTexParameteri( image->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE ); | |
@@ -750,4 +738,3 @@ rebuild_page: | |
} | |
//======================================================= | |
-#endif // XASH_DEDICATED | |
Только в engine/client: gl_backend.c.orig | |
Только в engine/client: gl_backend.c.rej | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_beams.c /mnt/data/Xash3D_original/engine/client/gl_beams.c | |
--- engine/client/gl_beams.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_beams.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "r_efx.h" | |
@@ -92,17 +90,17 @@ static cl_entity_t *CL_GetBeamEntityByIn | |
void BeamNormalizeColor( BEAM *pBeam, float r, float g, float b, float brightness ) | |
{ | |
- float _max, scale; | |
+ float max, scale; | |
- _max = max( max( r, g ), b ); | |
+ max = max( max( r, g ), b ); | |
- if( _max == 0 ) | |
+ if( max == 0 ) | |
{ | |
pBeam->r = pBeam->g = pBeam->b = 255.0f; | |
pBeam->brightness = brightness; | |
} | |
- scale = 255.0f / _max; | |
+ scale = 255.0f / max; | |
pBeam->r = r * scale; | |
pBeam->g = g * scale; | |
@@ -133,10 +131,7 @@ static qboolean ComputeBeamEntPosition( | |
// get attachment | |
if( nAttachment > 0 ) | |
VectorCopy( pEnt->attachment[nAttachment - 1], pt ); | |
- else | |
- { | |
- VectorCopy( pEnt->origin, pt ); | |
- } | |
+ else VectorCopy( pEnt->origin, pt ); | |
return true; | |
} | |
@@ -264,7 +259,7 @@ static void CL_DrawSegs( int modelIndex, | |
total_segs = segments; | |
SetBeamRenderMode( rendermode ); | |
- GL_Bind( XASH_TEXTURE0, m_hSprite ); | |
+ GL_Bind( GL_TEXTURE0, m_hSprite ); | |
pglBegin( GL_TRIANGLE_STRIP ); | |
// specify all the segments. | |
@@ -431,7 +426,7 @@ static void CL_DrawDisk( int modelIndex, | |
w = freq * delta[2]; | |
SetBeamRenderMode( rendermode ); | |
- GL_Bind( XASH_TEXTURE0, m_hSprite ); | |
+ GL_Bind( GL_TEXTURE0, m_hSprite ); | |
pglBegin( GL_TRIANGLE_STRIP ); | |
@@ -498,7 +493,7 @@ static void CL_DrawCylinder( int modelIn | |
GL_Cull( GL_NONE ); // draw both sides | |
SetBeamRenderMode( rendermode ); | |
- GL_Bind( XASH_TEXTURE0, m_hSprite ); | |
+ GL_Bind( GL_TEXTURE0, m_hSprite ); | |
pglBegin( GL_TRIANGLE_STRIP ); | |
@@ -611,7 +606,7 @@ void CL_DrawRing( int modelIndex, float | |
j = segments / 8; | |
SetBeamRenderMode( rendermode ); | |
- GL_Bind( XASH_TEXTURE0, m_hSprite ); | |
+ GL_Bind( GL_TEXTURE0, m_hSprite ); | |
pglBegin( GL_TRIANGLE_STRIP ); | |
@@ -748,9 +743,9 @@ static void DrawBeamFollow( int modelInd | |
float div; | |
float vLast = 0.0; | |
float vStep = 1.0; | |
- vec3_t last1, last2, tmp, normal, scaledColor, saved_last2; | |
+ vec3_t last1, last2, tmp, normal, scaledColor; | |
HSPRITE m_hSprite; | |
- rgb_t nColor, saved_nColor; | |
+ rgb_t nColor; | |
m_hSprite = R_GetSpriteTexture( Mod_Handle( modelIndex ), frame ); | |
if( !m_hSprite ) return; | |
@@ -781,9 +776,9 @@ static void DrawBeamFollow( int modelInd | |
nColor[2] = (byte)bound( 0, (int)(scaledColor[2] * 255.0f), 255 ); | |
SetBeamRenderMode( rendermode ); | |
- GL_Bind( XASH_TEXTURE0, m_hSprite ); | |
+ GL_Bind( GL_TEXTURE0, m_hSprite ); | |
- pglBegin( GL_TRIANGLES ); | |
+ pglBegin( GL_QUADS ); | |
while( pHead ) | |
{ | |
@@ -795,11 +790,6 @@ static void DrawBeamFollow( int modelInd | |
pglTexCoord2f( 0.0f, 1.0f ); | |
pglVertex3fv( last1 ); | |
- VectorCopy( last2, saved_last2 ); | |
- saved_nColor[0] = nColor[0]; | |
- saved_nColor[1] = nColor[1]; | |
- saved_nColor[2] = nColor[2]; | |
- | |
// Transform point into screen space | |
TriWorldToScreen( pHead->org, screen ); | |
@@ -837,14 +827,6 @@ static void DrawBeamFollow( int modelInd | |
pglTexCoord2f( 0.0f, 0.0f ); | |
pglVertex3fv( last1 ); | |
- pglColor4ub( saved_nColor[0], saved_nColor[1], saved_nColor[2], 255 ); | |
- pglTexCoord2f( 1.0f, 1.0f ); | |
- pglVertex3fv( saved_last2 ); | |
- | |
- pglColor4ub( nColor[0], nColor[1], nColor[2], 255 ); | |
- pglTexCoord2f( 0.0f, 0.0f ); | |
- pglVertex3fv( last1 ); | |
- | |
pglColor4ub( nColor[0], nColor[1], nColor[2], 255 ); | |
pglTexCoord2f( 1.0f, 0.0f ); | |
pglVertex3fv( last2 ); | |
@@ -2151,7 +2133,7 @@ void CL_ReadLineFile_f( void ) | |
string token; | |
Q_snprintf( filename, sizeof( filename ), "maps/%s.lin", clgame.mapname ); | |
- afile = (char *)FS_LoadFile( filename, NULL, false ); | |
+ afile = FS_LoadFile( filename, NULL, false ); | |
if( !afile ) | |
{ | |
@@ -2184,7 +2166,7 @@ void CL_ReadLineFile_f( void ) | |
if( token[0] != '-' ) | |
{ | |
- MsgDev( D_ERROR, "%s is corrupted\n", filename ); | |
+ MsgDev( D_ERROR, "%s is corrupted\n" ); | |
break; | |
} | |
@@ -2216,4 +2198,3 @@ void CL_ReadLineFile_f( void ) | |
if( count ) Msg( "%i lines read\n", count ); | |
else Msg( "map %s has no leaks!\n", clgame.mapname ); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_cull.c /mnt/data/Xash3D_original/engine/client/gl_cull.c | |
--- engine/client/gl_cull.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_cull.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -225,4 +223,3 @@ qboolean R_CullSurface( msurface_t *surf | |
return ( clipflags && R_CullBox( info->mins, info->maxs, clipflags )); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_decals.c /mnt/data/Xash3D_original/engine/client/gl_decals.c | |
--- engine/client/gl_decals.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_decals.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -80,10 +78,8 @@ static void R_DecalUnlink( decal_t *pdec | |
else | |
{ | |
tmp = pdecal->psurface->pdecals; | |
- if( !tmp ) | |
- Host_Error( "D_DecalUnlink: bad decal list\n" ); | |
- else | |
- { | |
+ if( !tmp ) Host_Error( "D_DecalUnlink: bad decal list\n" ); | |
+ | |
while( tmp->pnext ) | |
{ | |
if( tmp->pnext == pdecal ) | |
@@ -95,7 +91,6 @@ static void R_DecalUnlink( decal_t *pdec | |
} | |
} | |
} | |
- } | |
if( pdecal->mesh ) | |
{ | |
@@ -564,10 +559,6 @@ msurfmesh_t *R_DecalCreateMesh( decalinf | |
mesh->elems[i*3+1] = i + 1; | |
mesh->elems[i*3+2] = i + 2; | |
} | |
- #ifdef __arm__ | |
- float inv_w = 1.0f / surf->texinfo->texture->width; | |
- float inv_h = 1.0f / surf->texinfo->texture->height; | |
- #endif | |
// fill the mesh | |
for( i = 0; i < numVerts; i++, v += VERTEXSIZE ) | |
@@ -582,18 +573,8 @@ msurfmesh_t *R_DecalCreateMesh( decalinf | |
out->stcoord[1] = v[4]; | |
out->lmcoord[0] = v[5]; | |
out->lmcoord[1] = v[6]; | |
- out->sccoord[0] = (( DotProduct( v , surf->texinfo->vecs[0] ) + surf->texinfo->vecs[0][3] ) | |
- #ifdef __arm__ | |
- * inv_w ); | |
- #else | |
- / surf->texinfo->texture->width ); | |
- #endif | |
- out->sccoord[1] = (( DotProduct( v , surf->texinfo->vecs[1] ) + surf->texinfo->vecs[1][3] ) | |
- #ifdef __arm__ | |
- * inv_h ); | |
- #else | |
- / surf->texinfo->texture->height ); | |
- #endif | |
+ out->sccoord[0] = (( DotProduct( v , surf->texinfo->vecs[0] ) + surf->texinfo->vecs[0][3] ) / surf->texinfo->texture->width ); | |
+ out->sccoord[1] = (( DotProduct( v , surf->texinfo->vecs[1] ) + surf->texinfo->vecs[1][3] ) / surf->texinfo->texture->height ); | |
// clear colors (it can be used for vertex lighting) | |
Q_memset( out->color, 0xFF, sizeof( out->color )); | |
@@ -966,7 +947,7 @@ void DrawSingleDecal( decal_t *pDecal, m | |
v = R_DecalSetupVerts( pDecal, fa, pDecal->texture, &numVerts ); | |
if( !numVerts ) return; | |
- GL_Bind( XASH_TEXTURE0, pDecal->texture ); | |
+ GL_Bind( GL_TEXTURE0, pDecal->texture ); | |
pglBegin( GL_POLYGON ); | |
@@ -1251,11 +1232,7 @@ void R_DecalRemoveAll( int textureIndex | |
{ | |
pdecal = &gDecalPool[i]; | |
- // don't remove permanent decals | |
- if( pdecal->flags & FDECAL_PERMANENT ) | |
- continue; | |
- | |
- if( !textureIndex || (pdecal->texture == textureIndex) ) | |
+ if( !textureIndex || pdecal->texture == textureIndex ) | |
R_DecalUnlink( pdecal ); | |
} | |
} | |
@@ -1309,5 +1286,3 @@ void R_ClearAllDecals( void ) | |
clgame.drawFuncs.R_ClearStudioDecals(); | |
} | |
} | |
- | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_draw.c /mnt/data/Xash3D_original/engine/client/gl_draw.c | |
--- engine/client/gl_draw.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_draw.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -68,7 +66,7 @@ R_DrawStretchPic | |
*/ | |
void R_DrawStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum ) | |
{ | |
- GL_Bind( XASH_TEXTURE0, texnum ); | |
+ GL_Bind( GL_TEXTURE0, texnum ); | |
pglBegin( GL_QUADS ); | |
pglTexCoord2f( s1, t1 ); | |
@@ -100,7 +98,7 @@ void R_DrawTileClear( int x, int y, int | |
GL_SetRenderMode( kRenderNormal ); | |
pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); | |
- GL_Bind( XASH_TEXTURE0, cls.tileImage ); | |
+ GL_Bind( GL_TEXTURE0, cls.tileImage ); | |
glt = R_GetTexture( cls.tileImage ); | |
tw = glt->srcWidth; | |
@@ -158,7 +156,7 @@ void R_DrawStretchRaw( float x, float y, | |
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); | |
tex = R_GetTexture( tr.cinTexture ); | |
- GL_Bind( XASH_TEXTURE0, tr.cinTexture ); | |
+ GL_Bind( GL_TEXTURE0, tr.cinTexture ); | |
if( cols == tex->width && rows == tex->height ) | |
{ | |
@@ -280,4 +278,3 @@ void R_Set2DMode( qboolean enable ) | |
} | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_export.h /mnt/data/Xash3D_original/engine/client/gl_export.h | |
--- engine/client/gl_export.h 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_export.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -15,103 +15,6 @@ GNU General Public License for more deta | |
#ifndef GL_EXPORT_H | |
#define GL_EXPORT_H | |
- | |
-#ifdef XASH_NANOGL | |
- | |
-#include "platform/android/gl_mangle.h" | |
-#undef pglMultiTexCoord2f | |
- | |
-#include <GL/gl.h> | |
- | |
- | |
-#define GL_TEXTURE0_ARB 0x84C0 | |
-#define GL_TEXTURE1_ARB 0x84C1 | |
- | |
-#define glActiveTextureARB glActiveTexture | |
-#define glClientActiveTextureARB glClientActiveTexture | |
-#define glTexEnvi glTexEnvf | |
- | |
-#define GL_TEXTURE_COMPARE_MODE_ARB 0x884C | |
-#define GL_TEXTURE_COMPARE_FUNC_ARB 0x884D | |
-#define GL_COMPARE_R_TO_TEXTURE_ARB 0x884E | |
-#define GL_TEXTURE_CUBE_MAP_ARB 0x8513 | |
-#define GL_BGRA 0x80E1 | |
-#define GL_TEXTURE_3D 0x806F | |
-#define GL_DEPTH_TEXTURE_MODE_ARB 0x884B | |
-#define GL_COMPRESSED_ALPHA_ARB 0x84E9 | |
-#define GL_COMPRESSED_LUMINANCE_ARB 0x84EA | |
-#define GL_COMPRESSED_LUMINANCE_ALPHA_ARB 0x84EB | |
-#define GL_COMPRESSED_INTENSITY_ARB 0x84EC | |
-#define GL_COMPRESSED_RGB_ARB 0x84ED | |
-#define GL_COMPRESSED_RGBA_ARB 0x84EE | |
-#define GL_RGBA32F_ARB 0x8814 | |
-#define GL_RGB32F_ARB 0x8815 | |
-#define GL_ALPHA32F_ARB 0x8816 | |
-#define GL_INTENSITY32F_ARB 0x8817 | |
-#define GL_LUMINANCE32F_ARB 0x8818 | |
-#define GL_LUMINANCE_ALPHA32F_ARB 0x8819 | |
-#define GL_RGBA16F_ARB 0x881A | |
-#define GL_RGB16F_ARB 0x881B | |
-#define GL_ALPHA16F_ARB 0x881C | |
-#define GL_INTENSITY16F_ARB 0x881D | |
-#define GL_LUMINANCE16F_ARB 0x881E | |
-#define GL_LUMINANCE_ALPHA16F_ARB 0x881F | |
-#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 | |
-#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 | |
-#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 | |
-#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 | |
- | |
-#define GL_GENERATE_MIPMAP 0x8191 | |
-#define GL_GENERATE_MIPMAP_HINT 0x8192 | |
- | |
-#define GL_TEXTURE_CUBE_MAP 0x8513 | |
-#define GL_TEXTURE_BINDING_CUBE_MAP 0x8514 | |
-#define GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515 | |
-#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516 | |
-#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517 | |
-#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518 | |
-#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519 | |
-#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A | |
-#define GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x8515 | |
-#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x8516 | |
-#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x8517 | |
-#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x8518 | |
-#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x8519 | |
-#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x851A | |
-#define GL_TEXTURE_RECTANGLE_EXT 0x84F5 | |
- | |
-#define GL_DEPTH_COMPONENT16 0x81A5 | |
-#define GL_DEPTH_COMPONENT24 0x81A6 | |
-#define GL_DEPTH_COMPONENT32 0x81A7 | |
-#define GL_DEPTH_COMPONENT32F 0x8CAC | |
- | |
-#define GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB 0x8B4A | |
-#define GL_MAX_VERTEX_ATTRIBS_ARB 0x8869 | |
- | |
- | |
-#define GL_GENERATE_MIPMAP_SGIS 0x8191 | |
-#define GL_GENERATE_MIPMAP_HINT_SGIS 0x8192 | |
- | |
-#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE | |
-#define GL_CLAMP_TO_BORDER 0x812D | |
-#define GL_TEXTURE_WRAP_R 0x8072 | |
-#define GL_TEXTURE_LOD_BIAS_EXT 0x8501 | |
- | |
-#define GL_ADD_SIGNED 0x8574 | |
- | |
-#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 | |
-#define GL_TEXTURE_RECTANGLE_NV 0x84F5 | |
-#define GL_MAX_TEXTURE_IMAGE_UNITS_ARB 0x8872 | |
-#define GL_MAX_TEXTURE_COORDS_ARB 0x8871 | |
-#define GL_MAX_3D_TEXTURE_SIZE_EXT 0x8073 | |
-#define GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB 0x851C | |
-#define GL_MAX_TEXTURE_UNITS_ARB 0x84E2 | |
- | |
-#define GL_MAX_TEXTURE_LOD_BIAS_EXT 0x84FD | |
-#define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF | |
-#define GL_MAX_3D_TEXTURE_SIZE 0x8073 | |
- | |
-#else | |
#ifndef APIENTRY | |
#define APIENTRY | |
#endif | |
@@ -531,18 +434,6 @@ typedef float GLmatrix[16]; | |
#define GL_MAX_3D_TEXTURE_SIZE 0x8073 | |
#define GL_TEXTURE_BINDING_3D 0x806A | |
-/* multisample */ | |
-#define GL_MULTISAMPLE 0x809D | |
-#define GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E | |
-#define GL_SAMPLE_ALPHA_TO_ONE 0x809F | |
-#define GL_SAMPLE_COVERAGE 0x80A0 | |
-#define GL_SAMPLE_BUFFERS 0x80A8 | |
-#define GL_SAMPLES 0x80A9 | |
-#define GL_SAMPLE_COVERAGE_VALUE 0x80AA | |
-#define GL_SAMPLE_COVERAGE_INVERT 0x80AB | |
-#define GL_MULTISAMPLE_BIT 0x20000000 | |
- | |
- | |
#define GL_STENCIL_TEST_TWO_SIDE_EXT 0x8910 | |
#define GL_ACTIVE_STENCIL_FACE_EXT 0x8911 | |
#define GL_STENCIL_BACK_FUNC 0x8800 | |
@@ -1185,6 +1076,12 @@ void ( APIENTRY *pglClientActiveTextureA | |
void ( APIENTRY *pglGetCompressedTexImage)( GLenum target, GLint lod, const GLvoid* data ); | |
void ( APIENTRY *pglDrawRangeElements)( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices ); | |
void ( APIENTRY *pglDrawRangeElementsEXT)( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices ); | |
+void ( APIENTRY *pglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); | |
+void ( APIENTRY *pglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr); | |
+void ( APIENTRY *pglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr); | |
+void ( APIENTRY *pglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr); | |
+void ( APIENTRY *pglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr); | |
+void ( APIENTRY *pglArrayElement)(GLint i); | |
void ( APIENTRY *pglMultiTexCoord1f) (GLenum, GLfloat); | |
void ( APIENTRY *pglMultiTexCoord2f) (GLenum, GLfloat, GLfloat); | |
void ( APIENTRY *pglMultiTexCoord3f) (GLenum, GLfloat, GLfloat, GLfloat); | |
@@ -1242,6 +1139,7 @@ void ( APIENTRY *pglGetActiveUniformARB) | |
void ( APIENTRY *pglGetUniformfvARB)(GLhandleARB programObj, GLint location, GLfloat *params); | |
void ( APIENTRY *pglGetUniformivARB)(GLhandleARB programObj, GLint location, GLint *params); | |
void ( APIENTRY *pglGetShaderSourceARB)(GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source); | |
+void ( APIENTRY *pglPolygonStipple)(const GLubyte *mask); | |
void ( APIENTRY *pglTexImage3D)( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels ); | |
void ( APIENTRY *pglTexSubImage3D)( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels ); | |
void ( APIENTRY *pglCopyTexSubImage3D)( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); | |
@@ -1275,7 +1173,23 @@ void ( APIENTRY * pglSelectTextureSGIS) | |
void ( APIENTRY * pglMTexCoord2fSGIS) ( GLenum, GLfloat, GLfloat ); | |
void ( APIENTRY * pglSwapInterval) ( int interval ); | |
extern void *pglGetProcAddress( const GLubyte * ); | |
- | |
-#endif | |
+BOOL ( WINAPI * pwglSwapBuffers)(HDC); | |
+BOOL ( WINAPI * pwglCopyContext)(HGLRC, HGLRC, UINT); | |
+HGLRC ( WINAPI * pwglCreateContext)(HDC); | |
+HGLRC ( WINAPI * pwglCreateLayerContext)(HDC, int); | |
+BOOL ( WINAPI * pwglDeleteContext)(HGLRC); | |
+HGLRC ( WINAPI * pwglGetCurrentContext)(VOID); | |
+PROC ( WINAPI * pwglGetProcAddress)(LPCSTR); | |
+BOOL ( WINAPI * pwglMakeCurrent)(HDC, HGLRC); | |
+BOOL ( WINAPI * pwglShareLists)(HGLRC, HGLRC); | |
+BOOL ( WINAPI * pwglUseFontBitmaps)(HDC, DWORD, DWORD, DWORD); | |
+BOOL ( WINAPI * pwglUseFontOutlines)(HDC, DWORD, DWORD, DWORD, FLOAT, FLOAT, int, LPGLYPHMETRICSFLOAT); | |
+BOOL ( WINAPI * pwglDescribeLayerPlane)(HDC, int, int, UINT, LPLAYERPLANEDESCRIPTOR); | |
+int ( WINAPI * pwglSetLayerPaletteEntries)(HDC, int, int, int, CONST COLORREF *); | |
+int ( WINAPI * pwglGetLayerPaletteEntries)(HDC, int, int, int, COLORREF *); | |
+BOOL ( WINAPI * pwglRealizeLayerPalette)(HDC, int, BOOL); | |
+BOOL ( WINAPI * pwglSwapLayerBuffers)(HDC, UINT); | |
+BOOL ( WINAPI * pwglSwapIntervalEXT)( int interval ); | |
+HGLRC ( WINAPI * pwglCreateContextAttribsARB)( HDC hDC, HGLRC hShareContext, const int *attribList ); | |
#endif//GL_EXPORT_H | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_image.c /mnt/data/Xash3D_original/engine/client/gl_image.c | |
--- engine/client/gl_image.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_image.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -45,18 +43,6 @@ static byte r_particleTexture[8][8] = | |
{0,0,0,0,0,0,0,0}, | |
}; | |
-static byte r_oldParticleTexture[8][8] = | |
-{ | |
-{0,0,0,0,0,0,0,0}, | |
-{0,0,0,0,0,0,0,0}, | |
-{0,0,1,1,1,1,0,0}, | |
-{0,0,1,1,1,1,0,0}, | |
-{0,0,1,1,1,1,0,0}, | |
-{0,0,1,1,1,1,0,0}, | |
-{0,0,0,0,0,0,0,0}, | |
-{0,0,0,0,0,0,0,0}, | |
-}; | |
- | |
const char *GL_Target( GLenum target ) | |
{ | |
switch( target ) | |
@@ -92,10 +78,6 @@ void GL_Bind( GLint tmu, GLenum texnum ) | |
GL_SelectTexture( tmu ); | |
else tmu = glState.activeTMU; | |
- // wrong texture unit | |
- //if( tmu < 0 || tmu >= MAX_TEXTURE_UNITS ) | |
- //return; | |
- | |
texture = &r_textures[texnum]; | |
if( glState.currentTextureTargets[tmu] != texture->target ) | |
@@ -121,7 +102,7 @@ R_GetTexture | |
*/ | |
gltexture_t *R_GetTexture( GLenum texnum ) | |
{ | |
- ASSERT( texnum < MAX_TEXTURES ); | |
+ ASSERT( texnum >= 0 && texnum < MAX_TEXTURES ); | |
return &r_textures[texnum]; | |
} | |
@@ -134,7 +115,8 @@ Just for debug (r_showtextures uses it) | |
*/ | |
void GL_SetTextureType( GLenum texnum, GLenum type ) | |
{ | |
- ASSERT( texnum < MAX_TEXTURES ); | |
+ if( texnum <= 0 ) return; | |
+ ASSERT( texnum >= 0 && texnum < MAX_TEXTURES ); | |
r_textures[texnum].texType = type; | |
} | |
@@ -228,7 +210,7 @@ void GL_TexFilter( gltexture_t *tex, qbo | |
if( tex->flags & ( TF_BORDER|TF_ALPHA_BORDER ) && !GL_Support( GL_CLAMP_TEXBORDER_EXT )) | |
{ | |
// border is not support, use clamp instead | |
- tex->flags &= ~(TF_BORDER|TF_ALPHA_BORDER); | |
+ tex->flags &= ~(TF_BORDER||TF_ALPHA_BORDER); | |
tex->flags |= TF_CLAMP; | |
} | |
@@ -357,7 +339,7 @@ void R_SetTextureParameters( void ) | |
for( i = 0, texture = r_textures; i < r_numTextures; i++, texture++ ) | |
{ | |
if( !texture->texnum ) continue; // free slot | |
- GL_Bind( XASH_TEXTURE0, i ); | |
+ GL_Bind( GL_TEXTURE0, i ); | |
GL_TexFilter( texture, true ); | |
} | |
} | |
@@ -1091,7 +1073,6 @@ static void GL_TextureImage( GLenum inFo | |
static void GL_TextureImageDXT( GLenum format, GLenum glTarget, GLint side, GLint level, GLint width, GLint height, GLint depth, qboolean subImage, size_t size, const void *data ) | |
{ | |
-#ifndef XASH_NANOGL | |
if( glTarget == GL_TEXTURE_1D ) | |
{ | |
if( subImage ) pglCompressedTexSubImage1DARB( glTarget, level, 0, width, format, size, data ); | |
@@ -1112,7 +1093,6 @@ static void GL_TextureImageDXT( GLenum f | |
if( subImage ) pglCompressedTexSubImage2DARB( glTarget, level, 0, 0, width, height, format, size, data ); | |
else pglCompressedTexImage2DARB( glTarget, level, format, width, height, 0, size, data ); | |
} | |
-#endif | |
} | |
/* | |
@@ -1485,7 +1464,7 @@ int GL_LoadTexture( const char *name, co | |
if( !name || !name[0] || !glw_state.initialized ) | |
return 0; | |
- if( Q_strlen( name ) >= sizeof( r_textures[0].name )) | |
+ if( Q_strlen( name ) >= sizeof( r_textures->name )) | |
{ | |
MsgDev( D_ERROR, "GL_LoadTexture: too long name %s\n", name ); | |
return 0; | |
@@ -1574,7 +1553,7 @@ int GL_LoadTextureInternal( const char * | |
if( !name || !name[0] || !glw_state.initialized ) | |
return 0; | |
- if( Q_strlen( name ) >= sizeof( r_textures[0].name ) ) | |
+ if( Q_strlen( name ) >= sizeof( r_textures->name )) | |
{ | |
MsgDev( D_ERROR, "GL_LoadTexture: too long name %s\n", name ); | |
return 0; | |
@@ -1759,7 +1738,7 @@ int GL_FindTexture( const char *name ) | |
if( !name || !name[0] || !glw_state.initialized ) | |
return 0; | |
- if( Q_strlen( name ) >= sizeof( r_textures[0].name ) ) | |
+ if( Q_strlen( name ) >= sizeof( r_textures->name )) | |
{ | |
MsgDev( D_ERROR, "GL_FindTexture: too long name %s\n", name ); | |
return 0; | |
@@ -1796,9 +1775,9 @@ void GL_FreeImage( const char *name ) | |
if( !name || !name[0] || !glw_state.initialized ) | |
return; | |
- if( Q_strlen( name ) >= sizeof( r_textures[0].name ) ) | |
+ if( Q_strlen( name ) >= sizeof( r_textures->name )) | |
{ | |
- MsgDev( D_ERROR, "GL_FreeImage: too long name %s\n", name ); | |
+ MsgDev( D_ERROR, "GL_FreeImage: too long name %s\n", name, sizeof( r_textures->name )); | |
return; | |
} | |
@@ -1829,1962 +1808,8 @@ void GL_FreeTexture( GLenum texnum ) | |
ASSERT( texnum > 0 && texnum < MAX_TEXTURES ); | |
R_FreeImage( &r_textures[texnum] ); | |
} | |
-#if 0 // Uncle Mike removed this | |
-/* | |
-======================================================================= | |
- | |
- IMAGE PROGRAM FUNCTIONS | |
- | |
-======================================================================= | |
-*/ | |
-/* | |
-================= | |
-R_ForceImageToRGBA | |
- | |
-Unpack any image to RGBA buffer | |
-================= | |
-*/ | |
-_inline rgbdata_t *R_ForceImageToRGBA( rgbdata_t *pic ) | |
-{ | |
- // don't need additional checks - image lib do it himself | |
- Image_Process( &pic, 0, 0, 0, IMAGE_FORCE_RGBA, NULL ); | |
- | |
- return pic; | |
-} | |
- | |
-/* | |
-================= | |
-R_AddImages | |
- | |
-Adds the given images together | |
-================= | |
-*/ | |
-static rgbdata_t *R_AddImages( rgbdata_t *in1, rgbdata_t *in2 ) | |
-{ | |
- rgbdata_t *out; | |
- int width, height; | |
- int r, g, b, a; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA images | |
- in1 = R_ForceImageToRGBA( in1 ); | |
- in2 = R_ForceImageToRGBA( in2 ); | |
- width = in1->width, height = in1->height; | |
- out = in1; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- r = in1->buffer[4*(y*width+x)+0] + in2->buffer[4*(y*width+x)+0]; | |
- g = in1->buffer[4*(y*width+x)+1] + in2->buffer[4*(y*width+x)+1]; | |
- b = in1->buffer[4*(y*width+x)+2] + in2->buffer[4*(y*width+x)+2]; | |
- a = in1->buffer[4*(y*width+x)+3] + in2->buffer[4*(y*width+x)+3]; | |
- out->buffer[4*(y*width+x)+0] = bound( 0, r, 255 ); | |
- out->buffer[4*(y*width+x)+1] = bound( 0, g, 255 ); | |
- out->buffer[4*(y*width+x)+2] = bound( 0, b, 255 ); | |
- out->buffer[4*(y*width+x)+3] = bound( 0, a, 255 ); | |
- } | |
- } | |
- | |
- FS_FreeImage( in2 ); | |
- | |
- return out; | |
-} | |
- | |
-/* | |
-================= | |
-R_MultiplyImages | |
- | |
-Multiplies the given images | |
-================= | |
-*/ | |
-static rgbdata_t *R_MultiplyImages( rgbdata_t *in1, rgbdata_t *in2 ) | |
-{ | |
- rgbdata_t *out; | |
- int width, height; | |
- int r, g, b, a; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA images | |
- in1 = R_ForceImageToRGBA( in1 ); | |
- in2 = R_ForceImageToRGBA( in2 ); | |
- width = in1->width, height = in1->height; | |
- out = in1; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- r = in1->buffer[4*(y*width+x)+0] * (in2->buffer[4*(y*width+x)+0] * (1.0f/255)); | |
- g = in1->buffer[4*(y*width+x)+1] * (in2->buffer[4*(y*width+x)+1] * (1.0f/255)); | |
- b = in1->buffer[4*(y*width+x)+2] * (in2->buffer[4*(y*width+x)+2] * (1.0f/255)); | |
- a = in1->buffer[4*(y*width+x)+3] * (in2->buffer[4*(y*width+x)+3] * (1.0f/255)); | |
- out->buffer[4*(y*width+x)+0] = bound( 0, r, 255 ); | |
- out->buffer[4*(y*width+x)+1] = bound( 0, g, 255 ); | |
- out->buffer[4*(y*width+x)+2] = bound( 0, b, 255 ); | |
- out->buffer[4*(y*width+x)+3] = bound( 0, a, 255 ); | |
- } | |
- } | |
- FS_FreeImage( in2 ); | |
- | |
- return out; | |
-} | |
- | |
-/* | |
-================= | |
-R_BiasImage | |
- | |
-Biases the given image | |
-================= | |
-*/ | |
-static rgbdata_t *R_BiasImage( rgbdata_t *in, const vec4_t bias ) | |
-{ | |
- rgbdata_t *out; | |
- int width, height; | |
- int r, g, b, a; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- width = in->width, height = in->height; | |
- out = in; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- r = in->buffer[4*(y*width+x)+0] + (255 * bias[0]); | |
- g = in->buffer[4*(y*width+x)+1] + (255 * bias[1]); | |
- b = in->buffer[4*(y*width+x)+2] + (255 * bias[2]); | |
- a = in->buffer[4*(y*width+x)+3] + (255 * bias[3]); | |
- out->buffer[4*(y*width+x)+0] = bound( 0, r, 255 ); | |
- out->buffer[4*(y*width+x)+1] = bound( 0, g, 255 ); | |
- out->buffer[4*(y*width+x)+2] = bound( 0, b, 255 ); | |
- out->buffer[4*(y*width+x)+3] = bound( 0, a, 255 ); | |
- } | |
- } | |
- | |
- return out; | |
-} | |
- | |
-/* | |
-================= | |
-R_ScaleImage | |
- | |
-Scales the given image | |
-================= | |
-*/ | |
-static rgbdata_t *R_ScaleImage( rgbdata_t *in, const vec4_t scale ) | |
-{ | |
- rgbdata_t *out; | |
- int width, height; | |
- int r, g, b, a; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- width = in->width, height = in->height; | |
- out = in; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- r = in->buffer[4*(y*width+x)+0] * scale[0]; | |
- g = in->buffer[4*(y*width+x)+1] * scale[1]; | |
- b = in->buffer[4*(y*width+x)+2] * scale[2]; | |
- a = in->buffer[4*(y*width+x)+3] * scale[3]; | |
- out->buffer[4*(y*width+x)+0] = bound( 0, r, 255 ); | |
- out->buffer[4*(y*width+x)+1] = bound( 0, g, 255 ); | |
- out->buffer[4*(y*width+x)+2] = bound( 0, b, 255 ); | |
- out->buffer[4*(y*width+x)+3] = bound( 0, a, 255 ); | |
- } | |
- } | |
- | |
- return out; | |
-} | |
- | |
-/* | |
-================= | |
-R_InvertColor | |
- | |
-Inverts the color channels of the given image | |
-================= | |
-*/ | |
-static rgbdata_t *R_InvertColor( rgbdata_t *in ) | |
-{ | |
- rgbdata_t *out; | |
- int width, height; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- width = in->width, height = in->height; | |
- out = in; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- out->buffer[4*(y*width+x)+0] = 255 - in->buffer[4*(y*width+x)+0]; | |
- out->buffer[4*(y*width+x)+1] = 255 - in->buffer[4*(y*width+x)+1]; | |
- out->buffer[4*(y*width+x)+2] = 255 - in->buffer[4*(y*width+x)+2]; | |
- } | |
- } | |
- | |
- return out; | |
-} | |
- | |
-/* | |
-================= | |
-R_InvertAlpha | |
- | |
-Inverts the alpha channel of the given image | |
-================= | |
-*/ | |
-static rgbdata_t *R_InvertAlpha( rgbdata_t *in ) | |
-{ | |
- rgbdata_t *out; | |
- int width, height; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- width = in->width, height = in->height; | |
- out = in; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- out->buffer[4*(y*width+x)+3] = 255 - in->buffer[4*(y*width+x)+3]; | |
- } | |
- | |
- return out; | |
-} | |
- | |
-/* | |
-================= | |
-R_MakeIntensity | |
- | |
-Converts the given image to intensity | |
-================= | |
-*/ | |
-static rgbdata_t *R_MakeIntensity( rgbdata_t *in ) | |
-{ | |
- rgbdata_t *out; | |
- int width, height; | |
- byte intensity; | |
- float r, g, b; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- width = in->width, height = in->height; | |
- out = in; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- r = r_luminanceTable[in->buffer[4*(y*width+x)+0]][0]; | |
- g = r_luminanceTable[in->buffer[4*(y*width+x)+1]][1]; | |
- b = r_luminanceTable[in->buffer[4*(y*width+x)+2]][2]; | |
- | |
- intensity = (byte)(r + g + b); | |
- | |
- out->buffer[4*(y*width+x)+0] = intensity; | |
- out->buffer[4*(y*width+x)+1] = intensity; | |
- out->buffer[4*(y*width+x)+2] = intensity; | |
- out->buffer[4*(y*width+x)+3] = intensity; | |
- } | |
- } | |
- | |
- return out; | |
-} | |
- | |
-/* | |
-================= | |
-R_MakeLuminance | |
- | |
-Converts the given image to luminance | |
-================= | |
-*/ | |
-static rgbdata_t *R_MakeLuminance( rgbdata_t *in ) | |
-{ | |
- rgbdata_t *out; | |
- int width, height; | |
- byte luminance; | |
- float r, g, b; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- width = in->width, height = in->height; | |
- out = in; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- r = r_luminanceTable[in->buffer[4*(y*width+x)+0]][0]; | |
- g = r_luminanceTable[in->buffer[4*(y*width+x)+1]][1]; | |
- b = r_luminanceTable[in->buffer[4*(y*width+x)+2]][2]; | |
- | |
- luminance = (byte)(r + g + b); | |
- | |
- out->buffer[4*(y*width+x)+0] = luminance; | |
- out->buffer[4*(y*width+x)+1] = luminance; | |
- out->buffer[4*(y*width+x)+2] = luminance; | |
- out->buffer[4*(y*width+x)+3] = 255; | |
- } | |
- } | |
- | |
- return out; | |
-} | |
- | |
-/* | |
-================= | |
-R_MakeLuma | |
- | |
-Converts the given image to glow (LUMA) | |
-================= | |
-*/ | |
-static rgbdata_t *R_MakeLuma( rgbdata_t *in ) | |
-{ | |
- Image_Process( &in, 0, 0, 0, IMAGE_MAKE_LUMA|IMAGE_FORCE_RGBA, NULL ); | |
- | |
- return in; | |
-} | |
- | |
-/* | |
-================= | |
-R_MakeImageBlock | |
- | |
-Scissor the specifed rectangle from image | |
-================= | |
-*/ | |
-static rgbdata_t *R_MakeImageBlock( rgbdata_t *in, int block[4] ) | |
-{ | |
- byte *fin, *fout, *out; | |
- int i, x, y, xl, yl, xh, yh, w, h; | |
- int linedelta; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- | |
- xl = block[0]; | |
- yl = block[1]; | |
- w = block[2]; | |
- h = block[3]; | |
- xh = xl + w; | |
- yh = yl + h; | |
- | |
- out = fout = Mem_Alloc( r_temppool, w * h * 4 ); | |
- | |
- fin = in->buffer + (yl * in->width + xl) * 4; | |
- linedelta = (in->width - w) * 4; | |
- | |
- // cut block from source | |
- for( y = yl; y < yh; y++ ) | |
- { | |
- for( x = xl; x < xh; x++ ) | |
- for( i = 0; i < 4; i++ ) | |
- *out++ = *fin++; | |
- fin += linedelta; | |
- } | |
- | |
- // update image size | |
- in->width = w, in->height = h; | |
- in->size = in->width * in->height * 4; | |
- | |
- // copy result back | |
- in->buffer = Mem_Realloc( host.imagepool, in->buffer, in->size ); | |
- Q_memcpy( in->buffer, fout, in->size ); | |
- Mem_Free( fout ); // purge temp buffer | |
- | |
- return in; | |
-} | |
- | |
-/* | |
-================= | |
-R_MakeAlpha | |
- | |
-Converts the given image to alpha | |
-================= | |
-*/ | |
-static rgbdata_t *R_MakeAlpha( rgbdata_t *in ) | |
-{ | |
- rgbdata_t *out; | |
- int width, height; | |
- byte alpha; | |
- float r, g, b; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- width = in->width, height = in->height; | |
- out = in; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- r = r_luminanceTable[in->buffer[4*(y*width+x)+0]][0]; | |
- g = r_luminanceTable[in->buffer[4*(y*width+x)+1]][1]; | |
- b = r_luminanceTable[in->buffer[4*(y*width+x)+2]][2]; | |
- | |
- alpha = (byte)(r + g + b); | |
- | |
- out->buffer[4*(y*width+x)+0] = 255; | |
- out->buffer[4*(y*width+x)+1] = 255; | |
- out->buffer[4*(y*width+x)+2] = 255; | |
- out->buffer[4*(y*width+x)+3] = alpha; | |
- } | |
- } | |
- | |
- return out; | |
-} | |
- | |
-/* | |
-================= | |
-R_HeightMap | |
- | |
-Converts the given height map to a normal map | |
-================= | |
-*/ | |
-static rgbdata_t *R_HeightMap( rgbdata_t *in, float bumpScale ) | |
-{ | |
- byte *out; | |
- int width, height; | |
- vec3_t normal; | |
- float r, g, b; | |
- float c, cx, cy; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- width = in->width, height = in->height; | |
- out = Mem_Alloc( r_temppool, width * height * 4 ); | |
- | |
- if( !bumpScale ) bumpScale = 1.0f; | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- r = r_luminanceTable[in->buffer[4*(y*width+x)+0]][0]; | |
- g = r_luminanceTable[in->buffer[4*(y*width+x)+1]][1]; | |
- b = r_luminanceTable[in->buffer[4*(y*width+x)+2]][2]; | |
- | |
- c = (r + g + b) * (1.0f/255); | |
- | |
- r = r_luminanceTable[in->buffer[4*(y*width+((x+1)%width))+0]][0]; | |
- g = r_luminanceTable[in->buffer[4*(y*width+((x+1)%width))+1]][1]; | |
- b = r_luminanceTable[in->buffer[4*(y*width+((x+1)%width))+2]][2]; | |
- | |
- cx = (r + g + b) * (1.0f/255); | |
- | |
- r = r_luminanceTable[in->buffer[4*(((y+1)%height)*width+x)+0]][0]; | |
- g = r_luminanceTable[in->buffer[4*(((y+1)%height)*width+x)+1]][1]; | |
- b = r_luminanceTable[in->buffer[4*(((y+1)%height)*width+x)+2]][2]; | |
- | |
- cy = (r + g + b) * (1.0f/255); | |
- | |
- normal[0] = (c - cx) * bumpScale; | |
- normal[1] = (c - cy) * bumpScale; | |
- normal[2] = 1.0f; | |
- | |
- if( !VectorNormalizeLength( normal )) | |
- VectorSet( normal, 0.0f, 0.0f, 1.0f ); | |
- | |
- out[4*(y*width+x)+0] = (byte)(128 + 127 * normal[0]); | |
- out[4*(y*width+x)+1] = (byte)(128 + 127 * normal[1]); | |
- out[4*(y*width+x)+2] = (byte)(128 + 127 * normal[2]); | |
- out[4*(y*width+x)+3] = 255; | |
- } | |
- } | |
- | |
- // copy result back | |
- Q_memcpy( in->buffer, out, width * height * 4 ); | |
- Mem_Free( out ); | |
- | |
- return in; | |
-} | |
- | |
-/* | |
-================= | |
-R_AddNormals | |
- | |
-Adds the given normal maps together | |
-================= | |
-*/ | |
-static rgbdata_t *R_AddNormals( rgbdata_t *in1, rgbdata_t *in2 ) | |
-{ | |
- byte *out; | |
- int width, height; | |
- vec3_t normal; | |
- int x, y; | |
- | |
- // make sure what we processing RGBA images | |
- in1 = R_ForceImageToRGBA( in1 ); | |
- in2 = R_ForceImageToRGBA( in2 ); | |
- width = in1->width, height = in1->height; | |
- out = Mem_Alloc( r_temppool, in1->size ); | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- for( x = 0; x < width; x++ ) | |
- { | |
- normal[0] = (in1->buffer[4*(y*width+x)+0] * (1.0f/127) - 1.0f) + (in2->buffer[4*(y*width+x)+0] * (1.0f/127) - 1.0f); | |
- normal[1] = (in1->buffer[4*(y*width+x)+1] * (1.0f/127) - 1.0f) + (in2->buffer[4*(y*width+x)+1] * (1.0f/127) - 1.0f); | |
- normal[2] = (in1->buffer[4*(y*width+x)+2] * (1.0f/127) - 1.0f) + (in2->buffer[4*(y*width+x)+2] * (1.0f/127) - 1.0f); | |
- | |
- if( !VectorNormalizeLength( normal )) | |
- VectorSet( normal, 0.0f, 0.0f, 1.0f ); | |
- | |
- out[4*(y*width+x)+0] = (byte)(128 + 127 * normal[0]); | |
- out[4*(y*width+x)+1] = (byte)(128 + 127 * normal[1]); | |
- out[4*(y*width+x)+2] = (byte)(128 + 127 * normal[2]); | |
- out[4*(y*width+x)+3] = 255; | |
- } | |
- } | |
- | |
- // copy result back | |
- Q_memcpy( in1->buffer, out, width * height * 4 ); | |
- FS_FreeImage( in2 ); | |
- Mem_Free( out ); | |
- | |
- return in1; | |
-} | |
/* | |
-================= | |
-R_SmoothNormals | |
- | |
-Smoothes the given normal map | |
-================= | |
-*/ | |
-static rgbdata_t *R_SmoothNormals( rgbdata_t *in ) | |
-{ | |
- byte *out; | |
- int width, height; | |
- uint frac, fracStep; | |
- uint p1[0x1000], p2[0x1000]; | |
- byte *pix1, *pix2, *pix3, *pix4; | |
- uint *inRow1, *inRow2; | |
- vec3_t normal; | |
- int i, x, y; | |
- | |
- // make sure what we processing RGBA image | |
- in = R_ForceImageToRGBA( in ); | |
- width = in->width, height = in->height; | |
- out = Mem_Alloc( r_temppool, in->size ); | |
- | |
- fracStep = 0x10000; | |
- frac = fracStep>>2; | |
- for( i = 0; i < width; i++ ) | |
- { | |
- p1[i] = 4 * (frac>>16); | |
- frac += fracStep; | |
- } | |
- | |
- frac = (fracStep>>2) * 3; | |
- for( i = 0; i < width; i++ ) | |
- { | |
- p2[i] = 4 * (frac>>16); | |
- frac += fracStep; | |
- } | |
- | |
- for( y = 0; y < height; y++ ) | |
- { | |
- inRow1 = (uint *)in->buffer + width * (int)((float)y + 0.25f); | |
- inRow2 = (uint *)in->buffer + width * (int)((float)y + 0.75f); | |
- | |
- for( x = 0; x < width; x++ ) | |
- { | |
- pix1 = (byte *)inRow1 + p1[x]; | |
- pix2 = (byte *)inRow1 + p2[x]; | |
- pix3 = (byte *)inRow2 + p1[x]; | |
- pix4 = (byte *)inRow2 + p2[x]; | |
- | |
- normal[0] = (pix1[0] * (1.0f/127) - 1.0f) + (pix2[0] * (1.0f/127) - 1.0f) + (pix3[0] * (1.0f/127) - 1.0f) + (pix4[0] * (1.0f/127) - 1.0f); | |
- normal[1] = (pix1[1] * (1.0f/127) - 1.0f) + (pix2[1] * (1.0f/127) - 1.0f) + (pix3[1] * (1.0f/127) - 1.0f) + (pix4[1] * (1.0f/127) - 1.0f); | |
- normal[2] = (pix1[2] * (1.0f/127) - 1.0f) + (pix2[2] * (1.0f/127) - 1.0f) + (pix3[2] * (1.0f/127) - 1.0f) + (pix4[2] * (1.0f/127) - 1.0f); | |
- | |
- if( !VectorNormalizeLength( normal )) | |
- VectorSet( normal, 0.0f, 0.0f, 1.0f ); | |
- | |
- out[4*(y*width+x)+0] = (byte)(128 + 127 * normal[0]); | |
- out[4*(y*width+x)+1] = (byte)(128 + 127 * normal[1]); | |
- out[4*(y*width+x)+2] = (byte)(128 + 127 * normal[2]); | |
- out[4*(y*width+x)+3] = 255; | |
- } | |
- } | |
- | |
- // copy result back | |
- Q_memcpy( in->buffer, out, width * height * 4 ); | |
- Mem_Free( out ); | |
- | |
- return in; | |
-} | |
- | |
-/* | |
-================ | |
-R_IncludeDepthmap | |
- | |
-Write depthmap into alpha-channel the given normal map | |
-================ | |
-*/ | |
-static rgbdata_t *R_IncludeDepthmap( rgbdata_t *in1, rgbdata_t *in2 ) | |
-{ | |
- int i; | |
- byte *pic1, *pic2; | |
- | |
- // make sure what we processing RGBA images | |
- in1 = R_ForceImageToRGBA( in1 ); | |
- in2 = R_ForceImageToRGBA( in2 ); | |
- | |
- pic1 = in1->buffer; | |
- pic2 = in2->buffer; | |
- | |
- for( i = (in1->width * in1->height) - 1; i > 0; i--, pic1 += 4, pic2 += 4 ) | |
- { | |
- if( in2->flags & IMAGE_HAS_COLOR ) | |
- pic1[3] = ((int)pic2[0] + (int)pic2[1] + (int)pic2[2]) / 3; | |
- else if( in2->flags & IMAGE_HAS_ALPHA ) | |
- pic1[3] = pic2[3]; | |
- else pic1[3] = pic2[0]; | |
- } | |
- | |
- in1->flags |= (IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA); | |
- FS_FreeImage( in2 ); | |
- | |
- return in1; | |
-} | |
- | |
-/* | |
-================ | |
-R_ClearPixels | |
- | |
-clear specified area: color or alpha | |
-================ | |
-*/ | |
-static rgbdata_t *R_ClearPixels( rgbdata_t *in, qboolean clearAlpha ) | |
-{ | |
- byte *pic; | |
- int i; | |
- | |
- // make sure what we processing RGBA images | |
- in = R_ForceImageToRGBA( in ); | |
- pic = in->buffer; | |
- | |
- if( clearAlpha ) | |
- { | |
- for( i = 0; ( i < in->width * in->height ) && ( in->flags & IMAGE_HAS_ALPHA ); i++ ) | |
- pic[(i<<2)+3] = 0xFF; | |
- } | |
- else | |
- { | |
- // clear color or greyscale image otherwise | |
- for( i = 0; i < in->width * in->height; i++ ) | |
- pic[(i<<2)+0] = pic[(i<<2)+1] = pic[(i<<2)+2] = 0xFF; | |
- } | |
- | |
- return in; | |
-} | |
- | |
-/* | |
-================ | |
-R_MovePixels | |
- | |
-move alpha-channel into color or back | |
-================ | |
-*/ | |
-static rgbdata_t *R_MovePixels( rgbdata_t *in, qboolean alphaToColor ) | |
-{ | |
- byte *pic; | |
- int i; | |
- | |
- // make sure what we processing RGBA images | |
- in = R_ForceImageToRGBA( in ); | |
- pic = in->buffer; | |
- | |
- if( alphaToColor ) | |
- { | |
- for( i = 0; ( i < in->width * in->height ) && ( in->flags & IMAGE_HAS_ALPHA ); i++ ) | |
- { | |
- pic[(i<<2)+0] = pic[(i<<2)+1] = pic[(i<<2)+2] = pic[(i<<2)+3]; // move from alpha to color | |
- pic[(i<<2)+3] = 0xFF; // clear alpha channel | |
- } | |
- } | |
- else | |
- { | |
- // clear color or greyscale image otherwise | |
- for( i = 0; i < in->width * in->height; i++ ) | |
- { | |
- // convert to grayscale | |
- pic[(i<<2)+3] = (pic[(i<<2)+0] * 0.32f) + (pic[(i<<2)+0] * 0.59f) + (pic[(i<<2)+0] * 0.09f); | |
- pic[(i<<2)+0] = pic[(i<<2)+1] = pic[(i<<2)+2] = 0x00; // clear RGB channels | |
- } | |
- } | |
- | |
- return in; | |
-} | |
- | |
-/* | |
-============================================================================== | |
- | |
-EXTENDED IMAGE INTERFACE | |
- | |
-============================================================================== | |
-*/ | |
-/* | |
-================= | |
-R_ParseAdd | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseAdd( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic1, *pic2; | |
- int samples1, samples2; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'add'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'add'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic1 = R_LoadImage( script, token, NULL, 0, &samples1, flags ); | |
- if( !pic1 ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "," )) | |
- { | |
- MsgDev( D_WARN, "expected ',', found '%s' instead for 'add'\n", token ); | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'add'\n" ); | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- pic2 = R_LoadImage( script, token, NULL, 0, &samples2, flags ); | |
- if( !pic2 ) | |
- { | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'add'\n", token ); | |
- FS_FreeImage( pic1 ); | |
- FS_FreeImage( pic2 ); | |
- return NULL; | |
- } | |
- | |
- if( pic1->width != pic2->width || pic1->height != pic2->height ) | |
- { | |
- MsgDev( D_WARN, "images for 'add' have mismatched dimensions [%ix%i] != [%ix%i]\n", | |
- pic1->width, pic1->height, pic2->width, pic2->height ); | |
- | |
- FS_FreeImage( pic1 ); | |
- FS_FreeImage( pic2 ); | |
- return NULL; | |
- } | |
- | |
- *samples = GL_CalcImageSamples( samples1, samples2 ); | |
- if( *samples != 1 ) | |
- { | |
- *flags &= ~TF_INTENSITY; | |
- *flags &= ~TF_LUMINANCE; | |
- } | |
- | |
- return R_AddImages( pic1, pic2 ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseMultiply | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseMultiply( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic1, *pic2; | |
- int samples1, samples2; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'multiply'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'multiply'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic1 = R_LoadImage( script, token, NULL, 0, &samples1, flags ); | |
- if( !pic1 ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "," )) | |
- { | |
- MsgDev( D_WARN, "expected ',', found '%s' instead for 'multiply'\n", token ); | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'multiply'\n" ); | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- pic2 = R_LoadImage( script, token, NULL, 0, &samples2, flags ); | |
- if( !pic2 ) | |
- { | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'multiply'\n", token ); | |
- | |
- FS_FreeImage( pic1 ); | |
- FS_FreeImage( pic2 ); | |
- return NULL; | |
- } | |
- | |
- if( pic1->width != pic2->width || pic1->height != pic2->height ) | |
- { | |
- MsgDev( D_WARN, "images for 'multiply' have mismatched dimensions [%ix%i] != [%ix%i]\n", | |
- pic1->width, pic1->height, pic2->width, pic2->height ); | |
- | |
- FS_FreeImage( pic1 ); | |
- FS_FreeImage( pic2 ); | |
- return NULL; | |
- } | |
- | |
- *samples = GL_CalcImageSamples( samples1, samples2 ); | |
- | |
- if( *samples != 1 ) | |
- { | |
- *flags &= ~TF_INTENSITY; | |
- *flags &= ~TF_LUMINANCE; | |
- } | |
- | |
- return R_MultiplyImages( pic1, pic2 ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseBias | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseBias( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- vec4_t bias; | |
- int i; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'bias'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'bias'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- for( i = 0; i < 4; i++ ) | |
- { | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "," )) | |
- { | |
- MsgDev( D_WARN, "expected ',', found '%s' instead for 'bias'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'bias'\n" ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- bias[i] = Q_atof( token ); | |
- } | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'bias'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- if( *samples < 3 ) *samples += 2; | |
- *flags &= ~TF_INTENSITY; | |
- *flags &= ~TF_LUMINANCE; | |
- | |
- return R_BiasImage( pic, bias ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseScale | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseScale( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- vec4_t scale; | |
- int i; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'scale'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'scale'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- for( i = 0; i < 4; i++ ) | |
- { | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "," )) | |
- { | |
- MsgDev( D_WARN, "expected ',', found '%s' instead for 'scale'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'scale'\n" ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- scale[i] = Q_atof( token ); | |
- } | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'scale'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- if( *samples < 3 ) *samples += 2; | |
- *flags &= ~TF_INTENSITY; | |
- *flags &= ~TF_LUMINANCE; | |
- | |
- return R_ScaleImage( pic, scale ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseInvertColor | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseInvertColor( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'invertColor'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'invertColor'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'invertColor'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- return R_InvertColor( pic ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseInvertAlpha | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseInvertAlpha( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'invertAlpha'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'invertAlpha'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'invertAlpha'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- return R_InvertAlpha( pic ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseMakeIntensity | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseMakeIntensity( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'makeIntensity'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'makeIntensity'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'makeIntensity'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- *samples = 1; | |
- *flags |= TF_INTENSITY; | |
- *flags &= ~TF_LUMINANCE; | |
- *flags &= ~TF_NORMALMAP; | |
- | |
- return R_MakeIntensity( pic ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseMakeLuminance | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseMakeLuminance( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'makeLuminance'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'makeLuminance'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'makeLuminance'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- *samples = 1; | |
- *flags |= TF_LUMINANCE; | |
- *flags &= ~TF_INTENSITY; | |
- *flags &= ~TF_NORMALMAP; | |
- | |
- return R_MakeIntensity( pic ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseMakeAlpha | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseMakeAlpha( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'makeAlpha'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'makeAlpha'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'makeAlpha'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- *samples = 1; | |
- *flags &= ~TF_INTENSITY; | |
- *flags |= TF_HAS_ALPHA; | |
- *flags &= ~TF_NORMALMAP; | |
- | |
- return R_MakeAlpha( pic ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseMakeLuma | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseMakeLuma( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'makeLuma'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'makeLuma'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- if( !( pic->flags & IMAGE_HAS_LUMA )) | |
- { | |
- MsgDev( D_WARN, "%s doesn't contain a luma-pixels for 'makeLuma'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'makeLuma'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- *samples = 3; | |
- | |
- return R_MakeLuma( pic ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseStudioSkin | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseStudioSkin( char **script, const byte *buf, size_t size, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- string model_path; | |
- string modelT_path; | |
- string skinname; | |
- rgbdata_t *pic; | |
- studiohdr_t hdr; | |
- file_t *f; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'Studio'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'Studio'\n" ); | |
- return NULL; | |
- } | |
- | |
- // NOTE: studio skin show as 'models/props/flame1.mdl/flame2a.bmp' | |
- FS_ExtractFilePath( token, model_path ); | |
- FS_StripExtension( model_path ); | |
- Q_snprintf( modelT_path, MAX_STRING, "%sT.mdl", model_path ); | |
- FS_DefaultExtension( model_path, ".mdl" ); | |
- FS_FileBase( token, skinname ); | |
- | |
- // load it in | |
- if( buf && size ) | |
- { | |
- pic = R_LoadImage( script, va( "#%s.mdl", skinname ), buf, size, samples, flags ); | |
- if( !pic ) return NULL; | |
- goto studio_done; | |
- } | |
- | |
- FS_DefaultExtension( skinname, ".bmp" ); | |
- f = FS_Open( model_path, "rb", false ); | |
- | |
- if( !f ) | |
- { | |
- MsgDev( D_WARN, "'Studio' can't find studiomodel %s\n", model_path ); | |
- return NULL; | |
- } | |
- | |
- if( FS_Read( f, &hdr, sizeof( hdr )) != sizeof( hdr )) | |
- { | |
- MsgDev( D_WARN, "'Studio' %s probably corrupted\n", model_path ); | |
- FS_Close( f ); | |
- return NULL; | |
- } | |
- | |
- if( hdr.numtextures == 0 ) | |
- { | |
- // textures are keep seperate | |
- FS_Close( f ); | |
- f = FS_Open( modelT_path, "rb", false ); | |
- | |
- if( !f ) | |
- { | |
- MsgDev( D_WARN, "'Studio' can't find studiotextures %s\n", modelT_path ); | |
- return NULL; | |
- } | |
- | |
- if( FS_Read( f, &hdr, sizeof( hdr )) != sizeof( hdr )) | |
- { | |
- MsgDev( D_WARN, "'Studio' %s probably corrupted\n", modelT_path ); | |
- FS_Close( f ); | |
- return NULL; | |
- } | |
- } | |
- | |
- if( hdr.textureindex > 0 && hdr.numtextures <= MAXSTUDIOSKINS ) | |
- { | |
- // all ok, can load model into memory | |
- mstudiotexture_t *ptexture, *tex; | |
- size_t mdl_size, tex_size; | |
- byte *pin; | |
- int i; | |
- | |
- FS_Seek( f, 0, SEEK_END ); | |
- mdl_size = FS_Tell( f ); | |
- FS_Seek( f, 0, SEEK_SET ); | |
- | |
- pin = Mem_Alloc( r_temppool, mdl_size ); | |
- | |
- if( FS_Read( f, pin, mdl_size ) != mdl_size ) | |
- { | |
- MsgDev( D_WARN, "'Studio' %s probably corrupted\n", model_path ); | |
- Mem_Free( pin ); | |
- FS_Close( f ); | |
- return NULL; | |
- } | |
- | |
- ptexture = (mstudiotexture_t *)(pin + hdr.textureindex); | |
- | |
- // find specified texture | |
- for( i = 0; i < hdr.numtextures; i++ ) | |
- { | |
- if( !Q_stricmp( ptexture[i].name, skinname )) | |
- break; // found | |
- } | |
- | |
- if( i == hdr.numtextures ) | |
- { | |
- MsgDev( D_WARN, "'Studio' %s doesn't have skin %s\n", model_path, skinname ); | |
- Mem_Free( pin ); | |
- FS_Close( f ); | |
- return NULL; | |
- } | |
- | |
- tex = ptexture + i; | |
- | |
- // NOTE: replace index with pointer to start of imagebuffer, ImageLib expected it | |
- //tex->index = (int)pin + tex->index; | |
- // no more pointer-to-int-to-pointer casts | |
- Image_SetMDLPointer((byte*)pin + tex->index); | |
- tex_size = sizeof( mstudiotexture_t ) + tex->width * tex->height + 768; | |
- | |
- // load studio texture and bind it | |
- FS_FileBase( skinname, skinname ); | |
- | |
- // load it in | |
- pic = R_LoadImage( script, va( "#%s.mdl", tex->name ), (byte *)tex, tex_size, samples, flags ); | |
- | |
- // shutdown operations | |
- Mem_Free( pin ); | |
- FS_Close( f ); | |
- | |
- if( !pic ) return NULL; | |
- } | |
- else | |
- { | |
- MsgDev( D_WARN, "'Studio' %s has invalid skin count\n", model_path ); | |
- FS_Close( f ); | |
- return NULL; | |
- } | |
- | |
-studio_done: | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'Studio'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- return pic; | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseSpriteFrame | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseSpriteFrame( char **script, const byte *buf, size_t size, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'Sprite'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'Sprite'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, va( "#%s.spr", token ), buf, size, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'Sprite'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- return pic; | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseScrapBlock | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseScrapBlock( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- int i, block[4]; | |
- char token[256]; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'scrapBlock'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'scrapBlock'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- for( i = 0; i < 4; i++ ) | |
- { | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "," )) | |
- { | |
- MsgDev( D_WARN, "expected ',', found '%s' instead for 'rect'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'block'\n" ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- block[i] = Q_atoi( token ); | |
-#if 0 | |
- if( block[i] < 0 ) | |
- { | |
- MsgDev( D_WARN, "invalid argument %i for 'block'\n", i + 1 ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- if((( i + 1 ) & 1 ) && block[i] > pic->width ) | |
- { | |
- MsgDev( D_WARN, "invalid argument %i for 'block'\n", i + 1 ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- if((( i + 1 ) & 2 ) && block[i] > pic->height ) | |
- { | |
- MsgDev( D_WARN, "invalid argument %i for 'block'\n", i + 1 ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
-#endif | |
- } | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'bias'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- // check bounds silently | |
- if( block[0] < 0 || block[0] > pic->width ) block[0] = 0; | |
- if( block[1] < 0 || block[1] > pic->height ) block[1] = 0; | |
- if( block[2] < 0 || block[2] > pic->width ) block[2] = pic->width; | |
- if( block[3] < 0 || block[3] > pic->height ) block[3] = pic->height; | |
- | |
- if(( block[0] + block[2] > pic->width ) || ( block[1] + block[3] > pic->height )) | |
- { | |
- MsgDev( D_WARN, "'ScrapBlock' image size out of bounds\n" ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- return R_MakeImageBlock( pic, block ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseHeightMap | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseHeightMap( char **script, const byte *buf, size_t size, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- float scale; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'heightMap'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'heightMap'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, buf, size, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "," )) | |
- { | |
- MsgDev( D_WARN, "expected ',', found '%s' instead for 'heightMap'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'heightMap'\n" ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- scale = Q_atof( token ); | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'heightMap'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- *samples = 3; | |
- *flags &= ~TF_INTENSITY; | |
- *flags &= ~TF_LUMINANCE; | |
- *flags |= TF_NORMALMAP; | |
- | |
- return R_HeightMap( pic, scale ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseAddNormals | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseAddNormals( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic1, *pic2; | |
- int samples1, samples2; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'addNormals'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'addNormals'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic1 = R_LoadImage( script, token, NULL, 0, &samples1, flags ); | |
- if( !pic1 ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "," )) | |
- { | |
- MsgDev( D_WARN, "expected ',', found '%s' instead for 'addNormals'\n", token ); | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'addNormals'\n" ); | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- pic2 = R_LoadImage( script, token, NULL, 0, &samples2, flags ); | |
- if( !pic2 ) | |
- { | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'addNormals'\n", token ); | |
- FS_FreeImage( pic1 ); | |
- FS_FreeImage( pic2 ); | |
- return NULL; | |
- } | |
- | |
- if( pic1->width != pic2->width || pic1->height != pic2->height ) | |
- { | |
- MsgDev( D_WARN, "images for 'addNormals' have mismatched dimensions [%ix%i] != [%ix%i]\n", | |
- pic1->width, pic1->height, pic2->width, pic2->height ); | |
- FS_FreeImage( pic1 ); | |
- FS_FreeImage( pic2 ); | |
- return NULL; | |
- } | |
- | |
- *samples = 3; | |
- *flags &= ~TF_INTENSITY; | |
- *flags &= ~TF_LUMINANCE; | |
- *flags |= TF_NORMALMAP; | |
- | |
- return R_AddNormals( pic1, pic2 ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseSmoothNormals | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseSmoothNormals( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'smoothNormals'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'smoothNormals'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'smoothNormals'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- *samples = 3; | |
- *flags &= ~TF_INTENSITY; | |
- *flags &= ~TF_LUMINANCE; | |
- *flags |= TF_NORMALMAP; | |
- | |
- return R_SmoothNormals( pic ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseDepthmap | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseDepthmap( char **script, const byte *buf, size_t size, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- rgbdata_t *pic1, *pic2; | |
- int samples1, samples2; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'mergeDepthmap'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'mergeDepthmap'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic1 = R_LoadImage( script, token, buf, size, &samples1, flags ); | |
- if( !pic1 ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "," )) | |
- { | |
- MsgDev( D_WARN, "expected ',', found '%s' instead for 'mergeDepthmap'\n", token ); | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'mergeDepthmap'\n" ); | |
- FS_FreeImage( pic1 ); | |
- return NULL; | |
- } | |
- | |
- *samples = 3; | |
- pic2 = R_LoadImage( script, token, buf, size, &samples2, flags ); | |
- if( !pic2 ) return pic1; // don't free normalmap | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'mergeDepthmap'\n", token ); | |
- | |
- FS_FreeImage( pic1 ); | |
- FS_FreeImage( pic2 ); | |
- return NULL; | |
- } | |
- | |
- if( pic1->width != pic2->width || pic1->height != pic2->height ) | |
- { | |
- MsgDev( D_WARN, "images for 'mergeDepthmap' have mismatched dimensions [%ix%i] != [%ix%i]\n", | |
- pic1->width, pic1->height, pic2->width, pic2->height ); | |
- | |
- FS_FreeImage( pic2 ); | |
- return pic1; // don't free normalmap | |
- } | |
- | |
- *samples = 4; | |
- *flags &= ~TF_INTENSITY; | |
- | |
- return R_IncludeDepthmap( pic1, pic2 ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseClearPixels | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseClearPixels( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- qboolean clearAlpha = false; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'clearPixels'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'clearPixels'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( !Q_stricmp( token, "alpha" )) | |
- { | |
- *script = COM_ParseFile( *script, token ); | |
- clearAlpha = true; | |
- } | |
- else if( !Q_stricmp( token, "color" )) | |
- { | |
- *script = COM_ParseFile( *script, token ); | |
- clearAlpha = false; | |
- } | |
- else if( !Q_stricmp( token, ")" )) | |
- { | |
- clearAlpha = false; // clear color as default | |
- } | |
- else *script = COM_ParseFile( *script, token ); // skip unknown token | |
- | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'clearPixels'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- *samples = clearAlpha ? 3 : 1; | |
- if( clearAlpha ) *flags &= ~TF_HAS_ALPHA; | |
- *flags &= ~TF_INTENSITY; | |
- | |
- return R_ClearPixels( pic, clearAlpha ); | |
-} | |
- | |
-/* | |
-================= | |
-R_ParseMovePixels | |
-================= | |
-*/ | |
-static rgbdata_t *R_ParseMovePixels( char **script, int *samples, texFlags_t *flags ) | |
-{ | |
- char token[256]; | |
- qboolean alphaToColor = false; | |
- rgbdata_t *pic; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( Q_stricmp( token, "(" )) | |
- { | |
- MsgDev( D_WARN, "expected '(', found '%s' instead for 'movePixels'\n", token ); | |
- return NULL; | |
- } | |
- | |
- if(( *script = COM_ParseFile( *script, token )) == NULL ) | |
- { | |
- MsgDev( D_WARN, "missing parameters for 'movePixels'\n" ); | |
- return NULL; | |
- } | |
- | |
- pic = R_LoadImage( script, token, NULL, 0, samples, flags ); | |
- if( !pic ) return NULL; | |
- | |
- *script = COM_ParseFile( *script, token ); | |
- if( !Q_stricmp( token, "AlphaToColor" )) | |
- { | |
- *script = COM_ParseFile( *script, token ); | |
- alphaToColor = true; | |
- } | |
- else if( !Q_stricmp( token, "ColorToAlpha" )) | |
- { | |
- *script = COM_ParseFile( *script, token ); | |
- alphaToColor = false; | |
- } | |
- else if( !Q_stricmp( token, ")" )) | |
- { | |
- alphaToColor = true; // move alpha to color as default | |
- } | |
- else *script = COM_ParseFile( *script, token ); // skip unknown token | |
- | |
- if( Q_stricmp( token, ")" )) | |
- { | |
- MsgDev( D_WARN, "expected ')', found '%s' instead for 'movePixels'\n", token ); | |
- FS_FreeImage( pic ); | |
- return NULL; | |
- } | |
- | |
- *samples = alphaToColor ? 3 : 1; | |
- if( alphaToColor ) *flags &= ~TF_HAS_ALPHA; | |
- *flags &= ~TF_INTENSITY; | |
- | |
- return R_MovePixels( pic, alphaToColor ); | |
-} | |
- | |
-/* | |
-================= | |
-R_LoadImage | |
-================= | |
-*/ | |
-static rgbdata_t *R_LoadImage( char **script, const char *name, const byte *buf, size_t size, int *samples, texFlags_t *flags ) | |
-{ | |
- if( !Q_stricmp( name, "add" )) | |
- return R_ParseAdd( script, samples, flags ); | |
- else if( !Q_stricmp( name, "multiply" )) | |
- return R_ParseMultiply( script, samples, flags ); | |
- else if( !Q_stricmp( name, "bias" )) | |
- return R_ParseBias( script, samples, flags ); | |
- else if( !Q_stricmp( name, "scale")) | |
- return R_ParseScale( script, samples, flags ); | |
- else if( !Q_stricmp( name, "invertColor" )) | |
- return R_ParseInvertColor( script, samples, flags ); | |
- else if( !Q_stricmp( name, "invertAlpha" )) | |
- return R_ParseInvertAlpha( script, samples, flags ); | |
- else if( !Q_stricmp( name, "makeIntensity" )) | |
- return R_ParseMakeIntensity( script, samples, flags ); | |
- else if( !Q_stricmp( name, "makeLuminance" )) | |
- return R_ParseMakeLuminance( script, samples, flags); | |
- else if( !Q_stricmp( name, "makeAlpha" )) | |
- return R_ParseMakeAlpha( script, samples, flags ); | |
- else if( !Q_stricmp( name, "makeLuma" )) | |
- return R_ParseMakeLuma( script, samples, flags ); | |
- else if( !Q_stricmp( name, "heightMap" )) | |
- return R_ParseHeightMap( script, buf, size, samples, flags ); | |
- else if( !Q_stricmp( name, "ScrapBlock" )) | |
- return R_ParseScrapBlock( script, samples, flags ); | |
- else if( !Q_stricmp( name, "addNormals" )) | |
- return R_ParseAddNormals( script, samples, flags ); | |
- else if( !Q_stricmp( name, "smoothNormals" )) | |
- return R_ParseSmoothNormals( script, samples, flags ); | |
- else if( !Q_stricmp( name, "mergeDepthmap" )) | |
- return R_ParseDepthmap( script, buf, size, samples, flags ); | |
- else if( !Q_stricmp( name, "clearPixels" )) | |
- return R_ParseClearPixels( script, samples, flags ); | |
- else if( !Q_stricmp( name, "movePixels" )) | |
- return R_ParseMovePixels( script, samples, flags ); | |
- else if( !Q_stricmp( name, "Studio" )) | |
- return R_ParseStudioSkin( script, buf, size, samples, flags ); | |
- else if( !Q_stricmp( name, "Sprite" )) | |
- return R_ParseSpriteFrame( script, buf, size, samples, flags ); | |
- else | |
- { | |
- // loading form disk | |
- rgbdata_t *image = FS_LoadImage( name, buf, size ); | |
- | |
- // we can't decompress DXT texture | |
- if( image && ImageDXT( image->type )) | |
- { | |
- FS_FreeImage( image ); | |
- return NULL; | |
- } | |
- | |
- if( image ) *samples = GL_CalcTextureSamples( image->flags ); | |
- | |
- return image; | |
- } | |
- return NULL; | |
-} | |
-#endif | |
-/* | |
================ | |
R_FreeImage | |
================ | |
@@ -3903,37 +1928,6 @@ static rgbdata_t *R_InitParticleTexture( | |
/* | |
================== | |
-R_InitOldParticleTexture | |
-================== | |
-*/ | |
-static rgbdata_t *R_InitOldParticleTexture(texFlags_t *flags) | |
-{ | |
- int x, y; | |
- | |
- // particle texture | |
- r_image.width = r_image.height = 8; | |
- r_image.buffer = data2D; | |
- r_image.flags = (IMAGE_HAS_COLOR | IMAGE_HAS_ALPHA); | |
- r_image.type = PF_RGBA_32; | |
- r_image.size = r_image.width * r_image.height * 4; | |
- | |
- *flags = TF_NOPICMIP | TF_NOMIPMAP; | |
- | |
- for (x = 0; x < 8; x++) | |
- { | |
- for (y = 0; y < 8; y++) | |
- { | |
- data2D[(y * 8 + x) * 4 + 0] = 255; | |
- data2D[(y * 8 + x) * 4 + 1] = 255; | |
- data2D[(y * 8 + x) * 4 + 2] = 255; | |
- data2D[(y * 8 + x) * 4 + 3] = r_oldParticleTexture[x][y] * 255; | |
- } | |
- } | |
- return &r_image; | |
-} | |
- | |
-/* | |
-================== | |
R_InitParticleTexture2 | |
================== | |
*/ | |
@@ -4504,7 +2497,6 @@ static void R_InitBuiltinTextures( void | |
{ "*gray", &tr.grayTexture, R_InitGrayTexture, TEX_SYSTEM }, | |
{ "*black", &tr.blackTexture, R_InitBlackTexture, TEX_SYSTEM }, | |
{ "*particle", &tr.particleTexture, R_InitParticleTexture, TEX_SYSTEM }, | |
- { "*oldparticle", &tr.oldParticleTexture, R_InitOldParticleTexture, TEX_SYSTEM }, | |
{ "*particle2", &tr.particleTexture2, R_InitParticleTexture2, TEX_SYSTEM }, | |
{ "*cintexture", &tr.cinTexture, R_InitCinematicTexture, TEX_NOMIP }, // force linear filter | |
{ "*dlight", &tr.dlightTexture, R_InitDlightTexture, TEX_LIGHTMAP }, | |
@@ -4556,9 +2548,9 @@ void R_InitImages( void ) | |
Q_memset( r_texturesHashTable, 0, sizeof( r_texturesHashTable )); | |
// create unused 0-entry | |
- Q_strncpy( r_textures[0].name, "*unused*", sizeof( r_textures[0].name )); | |
- hash = Com_HashKey( r_textures[0].name, TEXTURES_HASH_SIZE ); | |
- r_textures[0].nextHash = r_texturesHashTable[hash]; | |
+ Q_strncpy( r_textures->name, "*unused*", sizeof( r_textures->name )); | |
+ hash = Com_HashKey( r_textures->name, TEXTURES_HASH_SIZE ); | |
+ r_textures->nextHash = r_texturesHashTable[hash]; | |
r_texturesHashTable[hash] = r_textures; | |
r_numTextures = 1; | |
@@ -4613,4 +2605,3 @@ void R_ShutdownImages( void ) | |
Q_memset( r_textures, 0, sizeof( r_textures )); | |
r_numTextures = 0; | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_local.h /mnt/data/Xash3D_original/engine/client/gl_local.h | |
--- engine/client/gl_local.h 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_local.h 2016-08-19 14:21:49.000000000 +0000 | |
@@ -16,11 +16,6 @@ GNU General Public License for more deta | |
#ifndef GL_LOCAL_H | |
#define GL_LOCAL_H | |
-#include "port.h" | |
- | |
-#ifdef XASH_SDL | |
-#include <SDL_video.h> | |
-#endif | |
#include "gl_export.h" | |
#include "com_model.h" | |
#include "cl_entity.h" | |
@@ -169,7 +164,6 @@ typedef struct | |
int acontTexture; | |
int defaultTexture; // use for bad textures | |
int particleTexture; // particle texture | |
- int oldParticleTexture; // square particle texture | |
int particleTexture2; // unsmoothed particle texture | |
int solidskyTexture; // quake1 solid-sky layer | |
int alphaskyTexture; // quake1 alpha-sky layer | |
@@ -266,9 +260,9 @@ void GL_CleanUpTextureUnits( int last ); | |
void GL_Bind( GLint tmu, GLenum texnum ); | |
void GL_MultiTexCoord2f( GLenum texture, GLfloat s, GLfloat t ); | |
void GL_SetTexCoordArrayMode( GLenum mode ); | |
-void GL_LoadTexMatrix(vec4_t * const m ); | |
+void GL_LoadTexMatrix( const matrix4x4 m ); | |
void GL_LoadTexMatrixExt( const float *glmatrix ); | |
-void GL_LoadMatrix(vec4_t * const source ); | |
+void GL_LoadMatrix( const matrix4x4 source ); | |
void GL_TexGen( GLenum coord, GLenum mode ); | |
void GL_SelectTexture( GLint texture ); | |
void GL_LoadIdentityTexMatrix( void ); | |
@@ -364,16 +358,14 @@ void R_SetupFrustum( void ); | |
void R_FindViewLeaf( void ); | |
void R_DrawFog( void ); | |
-#define cmatrix3x4 vec4_t *const | |
-#define cmatrix4x4 vec4_t *const | |
// | |
// gl_rmath.c | |
// | |
float V_CalcFov( float *fov_x, float width, float height ); | |
void V_AdjustFov( float *fov_x, float *fov_y, float width, float height, qboolean lock_x ); | |
-void Matrix4x4_ToArrayFloatGL( cmatrix4x4 in, float out[16] ); | |
+void Matrix4x4_ToArrayFloatGL( const matrix4x4 in, float out[16] ); | |
void Matrix4x4_FromArrayFloatGL( matrix4x4 out, const float in[16] ); | |
-void Matrix4x4_Concat(matrix4x4 out, cmatrix4x4 in1, cmatrix4x4 in2 ); | |
+void Matrix4x4_Concat( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ); | |
void Matrix4x4_ConcatTranslate( matrix4x4 out, float x, float y, float z ); | |
void Matrix4x4_ConcatRotate( matrix4x4 out, float angle, float x, float y, float z ); | |
void Matrix4x4_ConcatScale( matrix4x4 out, float x ); | |
@@ -411,7 +403,7 @@ void GL_ResetFogColor( void ); | |
// gl_sprite.c | |
// | |
void R_SpriteInit( void ); | |
-void Mod_LoadSpriteModel( model_t *mod, byte *buffer, qboolean *loaded, uint texFlags ); | |
+void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, uint texFlags ); | |
mspriteframe_t *R_GetSpriteFrame( const model_t *pModel, int frame, float yaw ); | |
void R_DrawSpriteModel( cl_entity_t *e ); | |
@@ -423,12 +415,10 @@ void Mod_LoadStudioModel( model_t *mod, | |
struct mstudiotex_s *R_StudioGetTexture( cl_entity_t *e ); | |
void R_DrawStudioModel( cl_entity_t *e ); | |
-#include "wadfile.h" | |
- | |
// | |
// gl_warp.c | |
// | |
-void R_InitSky( struct mip_s *mt, byte *buf, struct texture_s *tx ); | |
+void R_InitSky( struct mip_s *mt, struct texture_s *tx ); | |
void R_AddSkyBoxSurface( msurface_t *fa ); | |
void R_ClearSkyBox( void ); | |
void R_DrawSkyBox( void ); | |
@@ -499,10 +489,6 @@ void R_NewMap( void ); | |
======================================================================= | |
*/ | |
-#ifdef XASH_NANOGL | |
-#undef GL_TEXTURE_3D_EXT | |
-#undef GL_VERTEX_SHADER_EXT | |
-#endif | |
enum | |
{ | |
GL_OPENGL_110 = 0, // base | |
@@ -547,10 +533,10 @@ enum | |
enum | |
{ | |
GL_KEEP_UNIT = -1, | |
- XASH_TEXTURE0 = 0, | |
- XASH_TEXTURE1, | |
- XASH_TEXTURE2, | |
- XASH_TEXTURE3, // g-cont. 4 units should be enough | |
+ GL_TEXTURE0 = 0, | |
+ GL_TEXTURE1, | |
+ GL_TEXTURE2, | |
+ GL_TEXTURE3, // g-cont. 4 units should be enough | |
MAX_TEXTURE_UNITS = 32 // can't acess to all over units without GLSL or cg | |
}; | |
@@ -588,13 +573,11 @@ typedef struct | |
qboolean softwareGammaUpdate; | |
qboolean deviceSupportsGamma; | |
int prev_mode; | |
- int prev_height; | |
- int prev_width; | |
} glconfig_t; | |
typedef struct | |
{ | |
- word gammaRamp[768]; // current gamma ramp, 0 is red, 1 is green, 2 is blue | |
+ word gammaRamp[768]; // current gamma ramp | |
word stateRamp[768]; // original gamma ramp | |
int width, height; | |
@@ -618,11 +601,9 @@ typedef struct | |
typedef struct | |
{ | |
-#ifdef XASH_SDL | |
- SDL_GLContext context; // SDL GL Context | |
-#else | |
- void *context; | |
-#endif | |
+ HDC hDC; // handle to device context | |
+ HGLRC hGLRC; // handle to GL rendering context | |
+ | |
int desktopBitsPixel; | |
int desktopWidth; | |
int desktopHeight; | |
@@ -664,10 +645,7 @@ extern convar_t *gl_finish; | |
extern convar_t *gl_nosort; | |
extern convar_t *gl_clear; | |
extern convar_t *gl_test; // cvar to testify new effects | |
-extern convar_t *gl_msaa; | |
-extern convar_t *r_ypos; | |
-extern convar_t *r_xpos; | |
extern convar_t *r_width; | |
extern convar_t *r_height; | |
extern convar_t *r_speeds; | |
@@ -691,8 +669,6 @@ extern convar_t *r_dynamic; | |
extern convar_t *r_lightmap; | |
extern convar_t *r_fastsky; | |
-extern convar_t *mp_decals; | |
- | |
extern convar_t *vid_displayfrequency; | |
extern convar_t *vid_fullscreen; | |
extern convar_t *vid_gamma; | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_mirror.c /mnt/data/Xash3D_original/engine/client/gl_mirror.c | |
--- engine/client/gl_mirror.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_mirror.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -166,7 +164,7 @@ int R_AllocateMirrorTexture( void ) | |
texture = tr.mirrorTextures[i]; | |
} | |
- GL_Bind( XASH_TEXTURE0, texture ); | |
+ GL_Bind( GL_TEXTURE0, texture ); | |
pglCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, RI.viewport[0], RI.viewport[1], RI.viewport[2], RI.viewport[3], 0 ); | |
return texture; | |
@@ -540,8 +538,6 @@ void R_CheckEntitiesOnList( void ) | |
case mod_brush: | |
R_FindBmodelMirrors( RI.currententity, true ); | |
break; | |
- default: | |
- break; | |
} | |
} | |
@@ -566,8 +562,6 @@ void R_CheckEntitiesOnList( void ) | |
case mod_brush: | |
R_FindBmodelMirrors( RI.currententity, false ); | |
break; | |
- default: | |
- break; | |
} | |
} | |
@@ -585,8 +579,6 @@ void R_CheckEntitiesOnList( void ) | |
case mod_brush: | |
R_FindBmodelMirrors( RI.currententity, false ); | |
break; | |
- default: | |
- break; | |
} | |
} | |
} | |
@@ -653,5 +645,3 @@ void R_FindMirrors( const ref_params_t * | |
R_CheckEntitiesOnList(); | |
} | |
- | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_refrag.c /mnt/data/Xash3D_original/engine/client/gl_refrag.c | |
--- engine/client/gl_refrag.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_refrag.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -224,4 +222,3 @@ void R_StoreEfrags( efrag_t **ppefrag, i | |
} | |
} | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_rlight.c /mnt/data/Xash3D_original/engine/client/gl_rlight.c | |
--- engine/client/gl_rlight.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_rlight.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "mathlib.h" | |
@@ -175,7 +173,7 @@ void R_PushDlights( void ) | |
if( R_CullSphere( l->origin, l->radius, 15 )) | |
continue; | |
- R_MarkLights( l, 1U << i, RI.currentmodel->nodes ); | |
+ R_MarkLights( l, 1<<i, RI.currentmodel->nodes ); | |
} | |
} | |
@@ -544,5 +542,3 @@ void R_LightDir( const vec3_t origin, ve | |
} | |
} | |
} | |
- | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_rmain.c /mnt/data/Xash3D_original/engine/client/gl_rmain.c | |
--- engine/client/gl_rmain.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_rmain.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -372,16 +370,16 @@ int R_ComputeFxBlend( cl_entity_t *e ) | |
break; | |
} | |
- if( e->model && e->model->type != mod_brush ) | |
+ if( e->model->type != mod_brush ) | |
{ | |
// NOTE: never pass sprites with rendercolor '0 0 0' it's a stupid Valve Hammer Editor bug | |
if( !e->curstate.rendercolor.r && !e->curstate.rendercolor.g && !e->curstate.rendercolor.b ) | |
e->curstate.rendercolor.r = e->curstate.rendercolor.g = e->curstate.rendercolor.b = 255; | |
+ } | |
// apply scale to studiomodels and sprites only | |
- if( !e->curstate.scale ) | |
+ if( e->model && e->model->type != mod_brush && !e->curstate.scale ) | |
e->curstate.scale = 1.0f; | |
- } | |
blend = bound( 0, blend, 255 ); | |
@@ -811,12 +809,12 @@ static void R_SetupFrame( void ) | |
R_RunViewmodelEvents(); | |
// sort opaque entities by model type to avoid drawing model shadows under alpha-surfaces | |
- qsort( tr.solid_entities, tr.num_solid_entities, sizeof( cl_entity_t* ), (void*)R_SolidEntityCompare ); | |
+ qsort( tr.solid_entities, tr.num_solid_entities, sizeof( cl_entity_t* ), R_SolidEntityCompare ); | |
if( !gl_nosort->integer ) | |
{ | |
// sort translucents entities by rendermode and distance | |
- qsort( tr.trans_entities, tr.num_trans_entities, sizeof( cl_entity_t* ), (void*)R_TransEntityCompare ); | |
+ qsort( tr.trans_entities, tr.num_trans_entities, sizeof( cl_entity_t* ), R_TransEntityCompare ); | |
} | |
// current viewleaf | |
@@ -1202,7 +1200,7 @@ void R_RenderScene( const ref_params_t * | |
RI.refdef = *fd; | |
if( !cl.worldmodel && RI.drawWorld ) | |
- Host_Error( "R_RenderScene: NULL worldmodel\n" ); | |
+ Host_Error( "R_RenderView: NULL worldmodel\n" ); | |
R_PushDlights(); | |
@@ -1343,11 +1341,9 @@ void R_EndFrame( void ) | |
{ | |
// flush any remaining 2D bits | |
R_Set2DMode( false ); | |
-#ifdef XASH_SDL | |
- SDL_GL_SwapWindow(host.hWnd); | |
-#elif defined __ANDROID__ // For direct android backend | |
- Android_SwapBuffers(); | |
-#endif | |
+ | |
+ if( !pwglSwapBuffers( glw_state.hDC )) | |
+ Sys_Error( "wglSwapBuffers() failed!\n" ); | |
} | |
/* | |
@@ -1665,20 +1661,20 @@ static render_api_t gRenderAPI = | |
GL_TextureName, | |
GL_TextureData, | |
GL_LoadTextureNoFilter, | |
- (void*)GL_CreateTexture, | |
+ GL_CreateTexture, | |
GL_SetTextureType, | |
GL_TextureUpdateCache, | |
GL_FreeTexture, | |
DrawSingleDecal, | |
R_DecalSetupVerts, | |
R_EntityRemoveDecals, | |
- (void*)AVI_LoadVideoNoSound, | |
- (void*)AVI_GetVideoInfo, | |
- (void*)AVI_GetVideoFrameNumber, | |
- (void*)AVI_GetVideoFrame, | |
+ AVI_LoadVideoNoSound, | |
+ AVI_GetVideoInfo, | |
+ AVI_GetVideoFrameNumber, | |
+ AVI_GetVideoFrame, | |
R_UploadStretchRaw, | |
- (void*)AVI_FreeVideo, | |
- (void*)AVI_IsActive, | |
+ AVI_FreeVideo, | |
+ AVI_IsActive, | |
GL_Bind, | |
GL_SelectTexture, | |
GL_LoadTexMatrixExt, | |
@@ -1692,7 +1688,7 @@ static render_api_t gRenderAPI = | |
NULL, | |
NULL, | |
CL_DrawParticlesExternal, | |
- (void*)R_EnvShot, | |
+ R_EnvShot, | |
COM_CompareFileTime, | |
Host_Error, | |
pfnSPR_LoadExt, | |
@@ -1700,7 +1696,7 @@ static render_api_t gRenderAPI = | |
R_StudioGetTexture, | |
GL_GetOverviewParms, | |
S_FadeMusicVolume, | |
- (void*)COM_SetRandomSeed, | |
+ COM_SetRandomSeed, | |
R_Mem_Alloc, | |
R_Mem_Free, | |
pfnGetFilesList, | |
@@ -1735,4 +1731,3 @@ qboolean R_InitRenderAPI( void ) | |
// render interface is missed | |
return true; | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_rmath.c /mnt/data/Xash3D_original/engine/client/gl_rmath.c | |
--- engine/client/gl_rmath.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_rmath.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "gl_local.h" | |
#include "mathlib.h" | |
@@ -78,7 +76,7 @@ void V_AdjustFov( float *fov_x, float *f | |
======================================================================== | |
*/ | |
-void Matrix4x4_Concat(matrix4x4 out, cmatrix4x4 in1, cmatrix4x4 in2 ) | |
+void Matrix4x4_Concat( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ) | |
{ | |
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0] + in1[0][3] * in2[3][0]; | |
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1] + in1[0][3] * in2[3][1]; | |
@@ -154,7 +152,7 @@ void Matrix4x4_CreateModelview( matrix4x | |
out[1][2] = 1.0f; | |
} | |
-void Matrix4x4_ToArrayFloatGL(cmatrix4x4 in, float out[16] ) | |
+void Matrix4x4_ToArrayFloatGL( const matrix4x4 in, float out[16] ) | |
{ | |
out[ 0] = in[0][0]; | |
out[ 1] = in[1][0]; | |
@@ -323,4 +318,3 @@ void Matrix4x4_ConcatScale3( matrix4x4 o | |
Matrix4x4_CreateScale3( temp, x, y, z ); | |
Matrix4x4_Concat( out, base, temp ); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_rmisc.c /mnt/data/Xash3D_original/engine/client/gl_rmisc.c | |
--- engine/client/gl_rmisc.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_rmisc.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -199,8 +197,8 @@ void R_CreateDetailTexturesList( const c | |
if( pic ) | |
{ | |
- xScale = (pic->width / (float)tex->width) * gl_detailscale->value; | |
- yScale = (pic->height / (float)tex->height) * gl_detailscale->value; | |
+ xScale = (pic->width / tex->width) * gl_detailscale->value; | |
+ yScale = (pic->height / tex->height) * gl_detailscale->value; | |
FS_FreeImage( pic ); | |
} | |
else xScale = yScale = 10.0f; | |
@@ -229,7 +227,7 @@ void R_ParseDetailTextures( const char * | |
R_CreateDetailTexturesList( filename ); | |
} | |
- afile = (char *)FS_LoadFile( filename, NULL, false ); | |
+ afile = FS_LoadFile( filename, NULL, false ); | |
if( !afile ) return; | |
pfile = afile; | |
@@ -312,7 +310,7 @@ void R_ParseTexFilters( const char *file | |
dfilter_t *tf; | |
int i; | |
- afile = (char *)FS_LoadFile( filename, NULL, false ); | |
+ afile = FS_LoadFile( filename, NULL, false ); | |
if( !afile ) return; | |
pfile = afile; | |
@@ -426,7 +424,7 @@ void R_ClearStaticEntities( void ) | |
{ | |
int i; | |
- if( Host_IsDedicated() ) | |
+ if( host.type == HOST_DEDICATED ) | |
return; | |
// clear out efrags in case the level hasn't been reloaded | |
@@ -482,4 +480,3 @@ void R_NewMap( void ) | |
GL_BuildLightmaps (); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_rpart.c /mnt/data/Xash3D_original/engine/client/gl_rpart.c | |
--- engine/client/gl_rpart.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_rpart.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -248,7 +246,7 @@ particle_t *CL_AllocParticle( void (*cal | |
if( !cl_free_particles ) | |
{ | |
- MsgDev( D_NOTE, "Overflow %d particles\n", GI->max_particles ); | |
+ MsgDev( D_INFO, "Overflow %d particles\n", GI->max_particles ); | |
return NULL; | |
} | |
@@ -364,7 +362,7 @@ static void CL_BulletTracerDraw( particl | |
GL_SetRenderMode( kRenderTransTexture ); | |
- GL_Bind( XASH_TEXTURE0, cls.particleImage ); | |
+ GL_Bind( GL_TEXTURE0, cls.particleImage ); | |
pglBegin( GL_QUADS ); | |
pglColor4ub( clgame.palette[p->color][0], clgame.palette[p->color][1], clgame.palette[p->color][2], alpha ); | |
@@ -505,10 +503,7 @@ void CL_UpdateParticle( particle_t *p, f | |
GL_SetRenderMode( kRenderTransTexture ); | |
pglColor4ub( color[0], color[1], color[2], alpha ); | |
- if( r_oldparticles->integer == 1 ) | |
- GL_Bind( XASH_TEXTURE0, cls.oldParticleImage ); | |
- else | |
- GL_Bind( XASH_TEXTURE0, cls.particleImage ); | |
+ GL_Bind( GL_TEXTURE0, cls.particleImage ); | |
// add the 4 corner vertices. | |
pglBegin( GL_QUADS ); | |
@@ -540,7 +535,7 @@ void CL_DrawParticles( void ) | |
if( !cl_draw_particles->integer ) | |
return; | |
- // don't evaluate particles when executed many times | |
+ // don't evaluate particles when executes many times | |
// at same frame e.g. mirror rendering | |
if( framecount != tr.realframecount ) | |
{ | |
@@ -620,18 +615,12 @@ void CL_EntityParticles( cl_entity_t *en | |
p = CL_AllocParticle( NULL ); | |
if( !p ) return; | |
-#ifdef VECTORIZE_SINCOS | |
- SinCosFastVector( cl.time * cl_avelocities[i][0], cl.time * cl_avelocities[i][1], cl.time * cl_avelocities[i][2], 0, | |
- &sy, &sp, &sr, NULL, | |
- &cy, &cp, &cr, NULL); | |
-#else | |
angle = cl.time * cl_avelocities[i][0]; | |
SinCos( angle, &sy, &cy ); | |
angle = cl.time * cl_avelocities[i][1]; | |
SinCos( angle, &sp, &cp ); | |
angle = cl.time * cl_avelocities[i][2]; | |
SinCos( angle, &sr, &cr ); | |
-#endif | |
VectorSet( forward, cp * cy, cp * sy, -sp ); | |
@@ -1222,29 +1211,6 @@ void CL_BulletImpactParticles( const vec | |
CL_SparkleTracer( pos, dir, vel ); | |
} | |
- if (r_oldparticles->integer == 1) | |
- { | |
- for (i = 0; i < 12; i++) | |
- { | |
- int greyColors; | |
- p = CL_AllocParticle(NULL); | |
- if (!p) return; | |
- | |
- p->die += 1.0f; | |
- // Randomly make each particle one of three colors: dark grey, medium grey or light grey. | |
- greyColors = (rand() % 3 + 1) * 32; | |
- p->color = CL_LookupColor(greyColors, greyColors, greyColors); | |
- | |
- p->type = pt_grav; | |
- for (j = 0; j < 3; j++) | |
- { | |
- p->org[j] = org[j] + Com_RandomFloat(-2.0f, 3.0f); | |
- p->vel[j] = Com_RandomFloat(-70.0f, 70.0f); | |
- } | |
- } | |
- } | |
- else | |
- { | |
for (i = 0; i < 12; i++) | |
{ | |
p = CL_AllocParticle(NULL); | |
@@ -1261,7 +1227,6 @@ void CL_BulletImpactParticles( const vec | |
} | |
} | |
} | |
-} | |
/* | |
=============== | |
@@ -1416,7 +1381,7 @@ void CL_DrawTracer( vec3_t start, vec3_t | |
pglColor4ub( color[0], color[1], color[2], alpha ); | |
- GL_Bind( XASH_TEXTURE0, cls.particleImage ); | |
+ GL_Bind( GL_TEXTURE0, cls.particleImage ); | |
pglBegin( GL_QUADS ); | |
pglTexCoord2f( 0.0f, endV ); | |
@@ -1680,7 +1645,7 @@ void CL_ReadPointFile_f( void ) | |
string token; | |
Q_snprintf( filename, sizeof( filename ), "maps/%s.pts", clgame.mapname ); | |
- afile = (char *)FS_LoadFile( filename, NULL, false ); | |
+ afile = FS_LoadFile( filename, NULL, false ); | |
if( !afile ) | |
{ | |
@@ -1734,4 +1699,3 @@ void CL_ReadPointFile_f( void ) | |
if( count ) Msg( "%i points read\n", count ); | |
else Msg( "map %s has no leaks!\n", clgame.mapname ); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_rsurf.c /mnt/data/Xash3D_original/engine/client/gl_rsurf.c | |
--- engine/client/gl_rsurf.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_rsurf.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -42,7 +40,7 @@ static qboolean draw_details = false; | |
static msurface_t *skychain = NULL; | |
static gllightmapstate_t gl_lms; | |
-static void LM_UploadBlock( qboolean dynamic ); | |
+static void LM_UploadBlock( int lightmapnum ); | |
byte *Mod_GetCurrentVis( void ) | |
{ | |
@@ -82,13 +80,11 @@ static void SubdividePolygon_r( msurface | |
{ | |
int i, j, k, f, b; | |
vec3_t mins, maxs; | |
- float m, frac, s, t, *v, vertsDiv, *verts_p; | |
+ float m, frac, s, t, *v, vertsDiv; | |
vec3_t front[SUBDIVIDE_SIZE], back[SUBDIVIDE_SIZE], total; | |
float dist[SUBDIVIDE_SIZE], total_s, total_t, total_ls, total_lt; | |
glpoly_t *poly; | |
- Q_memset( dist, 0, SUBDIVIDE_SIZE * sizeof( float ) ); | |
- | |
if( numverts > ( SUBDIVIDE_SIZE - 4 )) | |
Host_Error( "Mod_SubdividePolygon: too many vertexes on face ( %i )\n", numverts ); | |
@@ -152,14 +148,13 @@ static void SubdividePolygon_r( msurface | |
poly->flags = warpface->flags; | |
warpface->polys = poly; | |
poly->numverts = numverts + 2; | |
- verts_p = (float *)poly + ( ( sizeof( void* ) + sizeof( int ) ) >> 1 ); // pointer glpoly_t->verts | |
VectorClear( total ); | |
total_s = total_ls = 0.0f; | |
total_t = total_lt = 0.0f; | |
for( i = 0; i < numverts; i++, verts += 3 ) | |
{ | |
- VectorCopy( verts, &verts_p[VERTEXSIZE * ( i + 1 )] ); | |
+ VectorCopy( verts, poly->verts[i+1] ); | |
VectorAdd( total, verts, total ); | |
if( warpface->flags & SURF_DRAWTURB ) | |
@@ -175,8 +170,8 @@ static void SubdividePolygon_r( msurface | |
t /= warpface->texinfo->texture->height; | |
} | |
- verts_p[VERTEXSIZE * ( i + 1 ) + 3] = s; | |
- verts_p[VERTEXSIZE * ( i + 1 ) + 4] = t; | |
+ poly->verts[i+1][3] = s; | |
+ poly->verts[i+1][4] = t; | |
total_s += s; | |
total_t += t; | |
@@ -197,8 +192,8 @@ static void SubdividePolygon_r( msurface | |
t += LM_SAMPLE_SIZE >> 1; | |
t /= BLOCK_SIZE * LM_SAMPLE_SIZE; //fa->texinfo->texture->height; | |
- verts_p[VERTEXSIZE * ( i + 1 ) + 5] = s; | |
- verts_p[VERTEXSIZE * ( i + 1 ) + 6] = t; | |
+ poly->verts[i+1][5] = s; | |
+ poly->verts[i+1][6] = t; | |
total_ls += s; | |
total_lt += t; | |
@@ -207,18 +202,18 @@ static void SubdividePolygon_r( msurface | |
vertsDiv = ( 1.0f / (float)numverts ); | |
- VectorScale( total, vertsDiv, &verts_p[0] ); | |
- verts_p[3] = total_s * vertsDiv; | |
- verts_p[4] = total_t * vertsDiv; | |
+ VectorScale( total, vertsDiv, poly->verts[0] ); | |
+ poly->verts[0][3] = total_s * vertsDiv; | |
+ poly->verts[0][4] = total_t * vertsDiv; | |
if( !( warpface->flags & SURF_DRAWTURB )) | |
{ | |
- verts_p[5] = total_ls * vertsDiv; | |
- verts_p[6] = total_lt * vertsDiv; | |
+ poly->verts[0][5] = total_ls * vertsDiv; | |
+ poly->verts[0][6] = total_lt * vertsDiv; | |
} | |
// copy first vertex to last | |
- Q_memcpy(&verts_p[VERTEXSIZE * ( i + 1 )], &verts_p[VERTEXSIZE], VERTEXSIZE * sizeof( float ) ); | |
+ Q_memcpy( poly->verts[i+1], poly->verts[1], sizeof( poly->verts[0] )); | |
} | |
void GL_SetupFogColorForSurfaces( void ) | |
@@ -226,8 +221,6 @@ void GL_SetupFogColorForSurfaces( void ) | |
vec3_t fogColor; | |
float factor, div; | |
- Q_memset(fogColor, 0, 3 * sizeof(float)); //Result pow( RI.fogColor[i] / div, ( 1.0f / factor )) may be nan. | |
- | |
if(( !RI.fogEnabled && !RI.fogCustom ) || RI.refdef.onlyClientDraw || !RI.currententity ) | |
return; | |
@@ -296,7 +289,7 @@ void GL_BuildPolygonFromSurface( model_t | |
int vertpage; | |
texture_t *tex; | |
gltexture_t *glt; | |
- float *vec, *verts_p; | |
+ float *vec; | |
float s, t; | |
glpoly_t *poly; | |
@@ -328,7 +321,6 @@ void GL_BuildPolygonFromSurface( model_t | |
poly->flags = fa->flags; | |
fa->polys = poly; | |
poly->numverts = lnumverts; | |
- verts_p = (float *)poly + (( sizeof( void* ) + sizeof( int ) ) >> 1); //pointer glpoly_t->verts | |
for( i = 0; i < lnumverts; i++ ) | |
{ | |
@@ -351,9 +343,9 @@ void GL_BuildPolygonFromSurface( model_t | |
t = DotProduct( vec, fa->texinfo->vecs[1] ) + fa->texinfo->vecs[1][3]; | |
t /= fa->texinfo->texture->height; | |
- VectorCopy( vec, &verts_p[VERTEXSIZE * i] ); | |
- verts_p[VERTEXSIZE * i + 3] = s; | |
- verts_p[VERTEXSIZE * i + 4] = t; | |
+ VectorCopy( vec, poly->verts[i] ); | |
+ poly->verts[i][3] = s; | |
+ poly->verts[i][4] = t; | |
// lightmap texture coordinates | |
s = DotProduct( vec, fa->texinfo->vecs[0] ) + fa->texinfo->vecs[0][3]; | |
@@ -368,8 +360,8 @@ void GL_BuildPolygonFromSurface( model_t | |
t += LM_SAMPLE_SIZE >> 1; | |
t /= BLOCK_SIZE * LM_SAMPLE_SIZE; //fa->texinfo->texture->height; | |
- verts_p[VERTEXSIZE * i + 5] = s; | |
- verts_p[VERTEXSIZE * i + 6] = t; | |
+ poly->verts[i][5] = s; | |
+ poly->verts[i][6] = t; | |
} | |
// remove co-linear points - Ed | |
@@ -380,9 +372,9 @@ void GL_BuildPolygonFromSurface( model_t | |
vec3_t v1, v2; | |
float *prev, *this, *next; | |
- prev = &verts_p[VERTEXSIZE * ((i + lnumverts - 1) % lnumverts)]; | |
- next = &verts_p[VERTEXSIZE * ((i + 1) % lnumverts)]; | |
- this = &verts_p[VERTEXSIZE * i]; | |
+ prev = poly->verts[(i + lnumverts - 1) % lnumverts]; | |
+ next = poly->verts[(i + 1) % lnumverts]; | |
+ this = poly->verts[i]; | |
VectorSubtract( this, prev, v1 ); | |
VectorNormalize( v1 ); | |
@@ -397,7 +389,7 @@ void GL_BuildPolygonFromSurface( model_t | |
for( j = i + 1; j < lnumverts; j++ ) | |
{ | |
for( k = 0; k < VERTEXSIZE; k++ ) | |
- verts_p[VERTEXSIZE * ( j - 1 ) + k] = verts_p[VERTEXSIZE * j + k]; | |
+ poly->verts[j-1][k] = poly->verts[j][k]; | |
} | |
// retry next vertex next time, which is now current vertex | |
@@ -622,8 +614,8 @@ static void LM_UploadBlock( qboolean dyn | |
} | |
if( host.features & ENGINE_LARGE_LIGHTMAPS ) | |
- GL_Bind( XASH_TEXTURE0, tr.dlightTexture2 ); | |
- else GL_Bind( XASH_TEXTURE0, tr.dlightTexture ); | |
+ GL_Bind( GL_TEXTURE0, tr.dlightTexture2 ); | |
+ else GL_Bind( GL_TEXTURE0, tr.dlightTexture ); | |
pglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, BLOCK_SIZE, height, GL_RGBA, GL_UNSIGNED_BYTE, gl_lms.lightmap_buffer ); | |
} | |
@@ -724,9 +716,6 @@ void DrawGLPoly( glpoly_t *p, float xSca | |
cl_entity_t *e = RI.currententity; | |
int i, hasScale = false; | |
- if( !p ) | |
- return; | |
- | |
// special hack for non-lightmapped surfaces | |
if( p->flags & SURF_DRAWTILED ) | |
GL_ResetFogColor(); | |
@@ -741,7 +730,7 @@ void DrawGLPoly( glpoly_t *p, float xSca | |
if( e->curstate.rendercolor.r ) flConveyorSpeed = -flConveyorSpeed; | |
texture = R_GetTexture( glState.currentTextures[glState.activeTMU] ); | |
- flRate = fabs( flConveyorSpeed ) / (float)texture->srcWidth; | |
+ flRate = abs( flConveyorSpeed ) / (float)texture->srcWidth; | |
flAngle = ( flConveyorSpeed >= 0 ) ? 180 : 0; | |
SinCos( flAngle * ( M_PI / 180.0f ), &sy, &cy ); | |
@@ -867,7 +856,7 @@ void R_BlendLightmaps( void ) | |
{ | |
if( gl_lms.lightmap_surfaces[i] ) | |
{ | |
- GL_Bind( XASH_TEXTURE0, tr.lightmapTextures[i] ); | |
+ GL_Bind( GL_TEXTURE0, tr.lightmapTextures[i] ); | |
for( surf = gl_lms.lightmap_surfaces[i]; surf != NULL; surf = surf->lightmapchain ) | |
{ | |
@@ -882,8 +871,8 @@ void R_BlendLightmaps( void ) | |
LM_InitBlock(); | |
if( host.features & ENGINE_LARGE_LIGHTMAPS ) | |
- GL_Bind( XASH_TEXTURE0, tr.dlightTexture2 ); | |
- else GL_Bind( XASH_TEXTURE0, tr.dlightTexture ); | |
+ GL_Bind( GL_TEXTURE0, tr.dlightTexture2 ); | |
+ else GL_Bind( GL_TEXTURE0, tr.dlightTexture ); | |
newsurf = gl_lms.dynamic_surfaces; | |
@@ -1002,7 +991,7 @@ void R_RenderFullbrights( void ) | |
{ | |
if( !fullbright_polys[i] ) | |
continue; | |
- GL_Bind( XASH_TEXTURE0, i ); | |
+ GL_Bind( GL_TEXTURE0, i ); | |
for( p = fullbright_polys[i]; p; p = p->next ) | |
{ | |
@@ -1055,7 +1044,7 @@ void R_RenderDetails( void ) | |
es = detail_surfaces[i]; | |
if( !es ) continue; | |
- GL_Bind( XASH_TEXTURE0, i ); | |
+ GL_Bind( GL_TEXTURE0, i ); | |
for( p = es; p; p = p->detailchain ) | |
{ | |
@@ -1112,23 +1101,23 @@ void R_RenderBrushPoly( msurface_t *fa ) | |
{ | |
if( SURF_INFO( fa, RI.currentmodel )->mirrortexturenum ) | |
{ | |
- GL_Bind( XASH_TEXTURE0, SURF_INFO( fa, RI.currentmodel )->mirrortexturenum ); | |
+ GL_Bind( GL_TEXTURE0, SURF_INFO( fa, RI.currentmodel )->mirrortexturenum ); | |
is_mirror = true; | |
// BEGIN WATER STUFF | |
if( fa->flags & SURF_DRAWTURB ) | |
{ | |
R_BeginDrawMirror( fa ); | |
- GL_Bind( XASH_TEXTURE1, t->gl_texturenum ); | |
+ GL_Bind( GL_TEXTURE1, t->gl_texturenum ); | |
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |
} | |
} | |
- else GL_Bind( XASH_TEXTURE0, t->gl_texturenum ); // dummy | |
+ else GL_Bind( GL_TEXTURE0, t->gl_texturenum ); // dummy | |
// DEBUG: reset the mirror texture after drawing | |
SURF_INFO( fa, RI.currentmodel )->mirrortexturenum = 0; | |
} | |
- else GL_Bind( XASH_TEXTURE0, t->gl_texturenum ); | |
+ else GL_Bind( GL_TEXTURE0, t->gl_texturenum ); | |
if( fa->flags & SURF_DRAWTURB ) | |
{ | |
@@ -1197,11 +1186,8 @@ void R_RenderBrushPoly( msurface_t *fa ) | |
goto dynamic; | |
} | |
- if( maps == MAXLIGHTMAPS ) | |
- maps--; | |
- | |
// dynamic this frame or dynamic previously | |
- if( fa->dlightframe == tr.framecount ) | |
+ if(( fa->dlightframe == tr.framecount )) | |
{ | |
dynamic: | |
// NOTE: at this point we have only valid textures | |
@@ -1221,7 +1207,7 @@ dynamic: | |
R_BuildLightMap( fa, temp, smax * 4, true ); | |
R_SetCacheState( fa ); | |
- GL_Bind( XASH_TEXTURE0, tr.lightmapTextures[fa->lightmaptexturenum] ); | |
+ GL_Bind( GL_TEXTURE0, tr.lightmapTextures[fa->lightmaptexturenum] ); | |
pglTexSubImage2D( GL_TEXTURE_2D, 0, fa->light_s, fa->light_t, smax, tmax, | |
GL_RGBA, GL_UNSIGNED_BYTE, temp ); | |
@@ -1334,7 +1320,7 @@ void R_DrawWaterSurfaces( void ) | |
continue; | |
// set modulate mode explicitly | |
- GL_Bind( XASH_TEXTURE0, t->gl_texturenum ); | |
+ GL_Bind( GL_TEXTURE0, t->gl_texturenum ); | |
for( ; s; s = s->texturechain ) | |
EmitWaterPolys( s->polys, ( s->flags & SURF_NOCULL )); | |
@@ -1452,7 +1438,7 @@ void R_DrawBrushModel( cl_entity_t *e ) | |
VectorCopy( l->origin, oldorigin ); // save lightorigin | |
Matrix4x4_VectorITransform( RI.objectMatrix, l->origin, origin_l ); | |
VectorCopy( origin_l, l->origin ); // move light in bmodel space | |
- R_MarkLights( l, 1U << k, clmodel->nodes + clmodel->hulls[0].firstclipnode ); | |
+ R_MarkLights( l, 1<<k, clmodel->nodes + clmodel->hulls[0].firstclipnode ); | |
VectorCopy( oldorigin, l->origin ); // restore lightorigin | |
} | |
@@ -1509,7 +1495,7 @@ void R_DrawBrushModel( cl_entity_t *e ) | |
} | |
if( need_sort && !gl_nosort->integer ) | |
- qsort( world.draw_surfaces, num_sorted, sizeof( msurface_t* ), (void*)R_SurfaceCompare ); | |
+ qsort( world.draw_surfaces, num_sorted, sizeof( msurface_t* ), R_SurfaceCompare ); | |
// draw sorted translucent surfaces | |
for( i = 0; i < num_sorted; i++ ) | |
@@ -1556,7 +1542,7 @@ void R_DrawStaticModel( cl_entity_t *e ) | |
{ | |
if( l->die < cl.time || !l->radius ) | |
continue; | |
- R_MarkLights( l, 1U << k, clmodel->nodes + clmodel->hulls[0].firstclipnode ); | |
+ R_MarkLights( l, 1<<k, clmodel->nodes + clmodel->hulls[0].firstclipnode ); | |
} | |
psurf = &clmodel->surfaces[clmodel->firstmodelsurface]; | |
@@ -1642,12 +1628,12 @@ void R_RecursiveWorldNode( mnode_t *node | |
{ | |
for( i = 0, clipplane = RI.frustum; i < 6; i++, clipplane++ ) | |
{ | |
- if(!( clipflags & ( 1U << i ))) | |
+ if(!( clipflags & ( 1<<i ))) | |
continue; | |
clipped = BoxOnPlaneSide( node->minmaxs, node->minmaxs + 3, clipplane ); | |
if( clipped == 2 ) return; | |
- if( clipped == 1 ) clipflags &= ~(1U << i); | |
+ if( clipped == 1 ) clipflags &= ~(1<<i); | |
} | |
} | |
@@ -1791,12 +1777,12 @@ void R_DrawWorldTopView( mnode_t *node, | |
{ | |
for( c = 0, clipplane = RI.frustum; c < 6; c++, clipplane++ ) | |
{ | |
- if(!( clipflags & ( 1U << c ))) | |
+ if(!( clipflags & ( 1<<c ))) | |
continue; | |
clipped = BoxOnPlaneSide( node->minmaxs, node->minmaxs + 3, clipplane ); | |
if( clipped == 2 ) return; | |
- if( clipped == 1 ) clipflags &= ~(1U << c); | |
+ if( clipped == 1 ) clipflags &= ~(1<<c); | |
} | |
} | |
@@ -2009,7 +1995,7 @@ void R_MarkLeaves( void ) | |
for( i = 0; i < cl.worldmodel->numleafs; i++ ) | |
{ | |
- if( vis[i>>3] & ( 1U << ( i & 7 ))) | |
+ if( vis[i>>3] & ( 1<<( i & 7 ))) | |
{ | |
node = (mnode_t *)&cl.worldmodel->leafs[i+1]; | |
do | |
@@ -2202,6 +2188,5 @@ void GL_BuildLightmaps( void ) | |
} | |
if( !gl_keeptjunctions->integer ) | |
- MsgDev( D_INFO, "Eliminated %i vertices\n", nColinElim ); | |
+ MsgDev( D_INFO, "Eliminate %i vertexes\n", nColinElim ); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_sprite.c /mnt/data/Xash3D_original/engine/client/gl_sprite.c | |
--- engine/client/gl_sprite.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_sprite.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -54,20 +52,21 @@ R_SpriteLoadFrame | |
upload a single frame | |
==================== | |
*/ | |
-static byte *R_SpriteLoadFrame( model_t *mod, byte *pin, mspriteframe_t **ppframe, int num ) | |
+static dframetype_t *R_SpriteLoadFrame( model_t *mod, void *pin, mspriteframe_t **ppframe, int num ) | |
{ | |
- dspriteframe_t pinframe; | |
+ dspriteframe_t *pinframe; | |
mspriteframe_t *pspriteframe; | |
char texname[128], sprname[128]; | |
qboolean load_external = false; | |
int gl_texturenum = 0; | |
- Q_memcpy( &pinframe, pin, sizeof(dspriteframe_t)); | |
- // build unique frame name | |
+ pinframe = (dspriteframe_t *)pin; | |
+ | |
+ // build uinque frame name | |
if( mod->flags & 256 ) // it's a HUD sprite | |
{ | |
Q_snprintf( texname, sizeof( texname ), "#HUD/%s_%s_%i%i.spr", mod->name, group_suffix, num / 10, num % 10 ); | |
- gl_texturenum = GL_LoadTexture( texname, pin, pinframe.width * pinframe.height, r_texFlags, NULL ); | |
+ gl_texturenum = GL_LoadTexture( texname, pin, pinframe->width * pinframe->height, r_texFlags, NULL ); | |
} | |
else | |
{ | |
@@ -89,37 +88,25 @@ static byte *R_SpriteLoadFrame( model_t | |
if( !load_external ) | |
{ | |
Q_snprintf( texname, sizeof( texname ), "#%s_%s_%i%i.spr", mod->name, group_suffix, num / 10, num % 10 ); | |
- gl_texturenum = GL_LoadTexture( texname, pin, pinframe.width * pinframe.height, r_texFlags, NULL ); | |
+ gl_texturenum = GL_LoadTexture( texname, pin, pinframe->width * pinframe->height, r_texFlags, NULL ); | |
} | |
else MsgDev( D_NOTE, "loading HQ: %s\n", texname ); | |
} | |
// setup frame description | |
pspriteframe = Mem_Alloc( mod->mempool, sizeof( mspriteframe_t )); | |
- pspriteframe->width = pinframe.width; | |
- pspriteframe->height = pinframe.height; | |
- #ifdef __VFP_FP__ | |
- volatile int tmp2; // Cannot directly load unaligned int to float register | |
- tmp2 = *( pinframe.origin + 1 ); // So load it to int first. Must not be optimized out | |
- pspriteframe->up = tmp2; | |
- tmp2 = *( pinframe.origin ); | |
- pspriteframe->left = tmp2; | |
- tmp2 = *( pinframe.origin + 1 ) - pinframe.height; | |
- pspriteframe->down = tmp2; | |
- tmp2 = pinframe.width + * ( pinframe.origin ); | |
- pspriteframe->right = tmp2; | |
- #else | |
- pspriteframe->up = pinframe.origin[1]; | |
- pspriteframe->left = pinframe.origin[0]; | |
- pspriteframe->down = pinframe.origin[1] - pinframe.height; | |
- pspriteframe->right = pinframe.width + pinframe.origin[0]; | |
- #endif | |
+ pspriteframe->width = pinframe->width; | |
+ pspriteframe->height = pinframe->height; | |
+ pspriteframe->up = pinframe->origin[1]; | |
+ pspriteframe->left = pinframe->origin[0]; | |
+ pspriteframe->down = pinframe->origin[1] - pinframe->height; | |
+ pspriteframe->right = pinframe->width + pinframe->origin[0]; | |
pspriteframe->gl_texturenum = gl_texturenum; | |
*ppframe = pspriteframe; | |
GL_SetTextureType( pspriteframe->gl_texturenum, TEX_SPRITE ); | |
- return ( pin + sizeof(dspriteframe_t) + pinframe.width * pinframe.height ); | |
+ return (dframetype_t *)((byte *)(pinframe + 1) + pinframe->width * pinframe->height ); | |
} | |
/* | |
@@ -129,43 +116,43 @@ R_SpriteLoadGroup | |
upload a group frames | |
==================== | |
*/ | |
-static byte *R_SpriteLoadGroup( model_t *mod, byte *pin, mspriteframe_t **ppframe, int framenum ) | |
+static dframetype_t *R_SpriteLoadGroup( model_t *mod, void *pin, mspriteframe_t **ppframe, int framenum ) | |
{ | |
- dspritegroup_t pingroup; | |
+ dspritegroup_t *pingroup; | |
mspritegroup_t *pspritegroup; | |
- dspriteinterval_t pin_intervals; | |
+ dspriteinterval_t *pin_intervals; | |
float *poutintervals; | |
int i, groupsize, numframes; | |
+ void *ptemp; | |
- Q_memcpy( &pingroup, pin, sizeof(dspritegroup_t)); | |
- numframes = pingroup.numframes; | |
+ pingroup = (dspritegroup_t *)pin; | |
+ numframes = pingroup->numframes; | |
groupsize = sizeof( mspritegroup_t ) + (numframes - 1) * sizeof( pspritegroup->frames[0] ); | |
pspritegroup = Mem_Alloc( mod->mempool, groupsize ); | |
pspritegroup->numframes = numframes; | |
- Q_memcpy( ppframe, pspritegroup, sizeof(mspriteframe_t)); | |
- pin += sizeof(dspritegroup_t); | |
- Q_memcpy( &pin_intervals, pin, sizeof(dspriteinterval_t)); | |
- | |
+ *ppframe = (mspriteframe_t *)pspritegroup; | |
+ pin_intervals = (dspriteinterval_t *)(pingroup + 1); | |
poutintervals = Mem_Alloc( mod->mempool, numframes * sizeof( float )); | |
pspritegroup->intervals = poutintervals; | |
for( i = 0; i < numframes; i++ ) | |
{ | |
- *poutintervals = pin_intervals.interval; | |
+ *poutintervals = pin_intervals->interval; | |
if( *poutintervals <= 0.0f ) | |
*poutintervals = 1.0f; // set error value | |
poutintervals++; | |
- pin += sizeof(dspriteinterval_t); | |
+ pin_intervals++; | |
} | |
+ ptemp = (void *)pin_intervals; | |
for( i = 0; i < numframes; i++ ) | |
{ | |
- pin = R_SpriteLoadFrame( mod, pin, &pspritegroup->frames[i], framenum * 10 + i ); | |
+ ptemp = R_SpriteLoadFrame( mod, ptemp, &pspritegroup->frames[i], framenum * 10 + i ); | |
} | |
- return pin; | |
+ return (dframetype_t *)ptemp; | |
} | |
/* | |
@@ -175,22 +162,23 @@ Mod_LoadSpriteModel | |
load sprite model | |
==================== | |
*/ | |
-void Mod_LoadSpriteModel( model_t *mod, byte *buffer, qboolean *loaded, uint texFlags ) | |
+void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, uint texFlags ) | |
{ | |
- dsprite_t pin; | |
- short numi; | |
+ dsprite_t *pin; | |
+ short *numi; | |
msprite_t *psprite; | |
+ dframetype_t *pframetype; | |
int i, size; | |
if( loaded ) *loaded = false; | |
- Q_memcpy(&pin, buffer, sizeof(dsprite_t)); | |
+ pin = (dsprite_t *)buffer; | |
mod->type = mod_sprite; | |
r_texFlags = texFlags; | |
- i = pin.version; | |
+ i = pin->version; | |
- if( pin.ident != IDSPRITEHEADER ) | |
+ if( pin->ident != IDSPRITEHEADER ) | |
{ | |
- MsgDev( D_ERROR, "%s has wrong id (%x should be %x)\n", mod->name, pin.ident, IDSPRITEHEADER ); | |
+ MsgDev( D_ERROR, "%s has wrong id (%x should be %x)\n", mod->name, pin->ident, IDSPRITEHEADER ); | |
return; | |
} | |
@@ -201,25 +189,24 @@ void Mod_LoadSpriteModel( model_t *mod, | |
} | |
mod->mempool = Mem_AllocPool( va( "^2%s^7", mod->name )); | |
- size = sizeof( msprite_t ) + ( pin.numframes - 1 ) * sizeof( psprite->frames ); | |
+ size = sizeof( msprite_t ) + ( pin->numframes - 1 ) * sizeof( psprite->frames ); | |
psprite = Mem_Alloc( mod->mempool, size ); | |
mod->cache.data = psprite; // make link to extradata | |
- psprite->type = pin.type; | |
- psprite->texFormat = pin.texFormat; | |
- psprite->numframes = mod->numframes = pin.numframes; | |
- psprite->facecull = pin.facetype; | |
- psprite->radius = pin.boundingradius; | |
- psprite->synctype = pin.synctype; | |
+ psprite->type = pin->type; | |
+ psprite->texFormat = pin->texFormat; | |
+ psprite->numframes = mod->numframes = pin->numframes; | |
+ psprite->facecull = pin->facetype; | |
+ psprite->radius = pin->boundingradius; | |
+ psprite->synctype = pin->synctype; | |
- mod->mins[0] = mod->mins[1] = -pin.bounds[0] / 2.0f; | |
- mod->maxs[0] = mod->maxs[1] = pin.bounds[0] / 2.0f; | |
- mod->mins[2] = -pin.bounds[1] / 2.0f; | |
- mod->maxs[2] = pin.bounds[1] / 2.0f; | |
- buffer += sizeof(dsprite_t); | |
- Q_memcpy(&numi, buffer, sizeof(short)); | |
+ mod->mins[0] = mod->mins[1] = -pin->bounds[0] / 2; | |
+ mod->maxs[0] = mod->maxs[1] = pin->bounds[0] / 2; | |
+ mod->mins[2] = -pin->bounds[1] / 2; | |
+ mod->maxs[2] = pin->bounds[1] / 2; | |
+ numi = (short *)(pin + 1); | |
- if( Host_IsDedicated() ) | |
+ if( host.type == HOST_DEDICATED ) | |
{ | |
// skip frames loading | |
if( loaded ) *loaded = true; // done | |
@@ -227,31 +214,30 @@ void Mod_LoadSpriteModel( model_t *mod, | |
return; | |
} | |
- if( numi == 256 ) | |
+ if( *numi == 256 ) | |
{ | |
+ byte *src = (byte *)(numi+1); | |
rgbdata_t *pal; | |
- buffer += sizeof(short); | |
- | |
// install palette | |
switch( psprite->texFormat ) | |
{ | |
case SPR_ADDITIVE: | |
- pal = FS_LoadImage( "#normal.pal", buffer, 768 ); | |
+ pal = FS_LoadImage( "#normal.pal", src, 768 ); | |
break; | |
case SPR_INDEXALPHA: | |
- pal = FS_LoadImage( "#decal.pal", buffer, 768 ); | |
+ pal = FS_LoadImage( "#decal.pal", src, 768 ); | |
break; | |
case SPR_ALPHTEST: | |
- pal = FS_LoadImage( "#transparent.pal", buffer, 768 ); | |
+ pal = FS_LoadImage( "#transparent.pal", src, 768 ); | |
break; | |
case SPR_NORMAL: | |
default: | |
- pal = FS_LoadImage( "#normal.pal", buffer, 768 ); | |
+ pal = FS_LoadImage( "#normal.pal", src, 768 ); | |
break; | |
} | |
- buffer += 768; | |
+ pframetype = (dframetype_t *)(src + 768); | |
FS_FreeImage( pal ); // palette installed, no reason to keep this data | |
} | |
else | |
@@ -260,33 +246,33 @@ void Mod_LoadSpriteModel( model_t *mod, | |
return; | |
} | |
- if( pin.numframes < 1 ) | |
+ if( pin->numframes < 1 ) | |
{ | |
- MsgDev( D_ERROR, "%s has invalid # of frames: %d\n", mod->name, pin.numframes ); | |
+ MsgDev( D_ERROR, "%s has invalid # of frames: %d\n", mod->name, pin->numframes ); | |
return; | |
} | |
- for( i = 0; i < pin.numframes; i++ ) | |
+ for( i = 0; i < pin->numframes; i++ ) | |
{ | |
- frametype_t frametype = *buffer; | |
+ frametype_t frametype = pframetype->type; | |
psprite->frames[i].type = frametype; | |
switch( frametype ) | |
{ | |
case FRAME_SINGLE: | |
Q_strncpy( group_suffix, "one", sizeof( group_suffix )); | |
- buffer = R_SpriteLoadFrame( mod, buffer + sizeof(int), &psprite->frames[i].frameptr, i ); | |
+ pframetype = R_SpriteLoadFrame( mod, pframetype + 1, &psprite->frames[i].frameptr, i ); | |
break; | |
case FRAME_GROUP: | |
Q_strncpy( group_suffix, "grp", sizeof( group_suffix )); | |
- buffer = R_SpriteLoadGroup( mod, buffer + sizeof(int), &psprite->frames[i].frameptr, i ); | |
+ pframetype = R_SpriteLoadGroup( mod, pframetype + 1, &psprite->frames[i].frameptr, i ); | |
break; | |
case FRAME_ANGLED: | |
Q_strncpy( group_suffix, "ang", sizeof( group_suffix )); | |
- buffer = R_SpriteLoadGroup( mod, buffer + sizeof(int), &psprite->frames[i].frameptr, i ); | |
+ pframetype = R_SpriteLoadGroup( mod, pframetype + 1, &psprite->frames[i].frameptr, i ); | |
break; | |
} | |
- if( !buffer ) break; // technically an error | |
+ if( pframetype == NULL ) break; // technically an error | |
} | |
if( loaded ) *loaded = true; // done | |
@@ -310,10 +296,6 @@ void Mod_LoadMapSprite( model_t *mod, co | |
int linedelta, numframes; | |
mspriteframe_t *pspriteframe; | |
msprite_t *psprite; | |
- int texFlags = TF_IMAGE; | |
- | |
- if( cl_sprite_nearest->value ) | |
- texFlags |= TF_NEAREST; | |
if( loaded ) *loaded = false; | |
Q_snprintf( texname, sizeof( texname ), "#%s", mod->name ); | |
@@ -401,7 +383,7 @@ void Mod_LoadMapSprite( model_t *mod, co | |
pspriteframe->left = -( w >> 1 ); | |
pspriteframe->down = ( h >> 1 ) - h; | |
pspriteframe->right = w + -( w >> 1 ); | |
- pspriteframe->gl_texturenum = GL_LoadTextureInternal( texname, &temp, texFlags, false ); | |
+ pspriteframe->gl_texturenum = GL_LoadTextureInternal( texname, &temp, TF_IMAGE, false ); | |
GL_SetTextureType( pspriteframe->gl_texturenum, TEX_NOMIP ); | |
xl += w; | |
@@ -443,7 +425,7 @@ void Mod_UnloadSpriteModel( model_t *mod | |
// release all textures | |
for( i = 0; i < psprite->numframes; i++ ) | |
{ | |
- if( Host_IsDedicated() ) | |
+ if( host.type == HOST_DEDICATED ) | |
break; // nothing to release | |
if( psprite->frames[i].type == SPR_SINGLE ) | |
@@ -516,7 +498,7 @@ mspriteframe_t *R_GetSpriteFrame( const | |
} | |
pspriteframe = pspritegroup->frames[i]; | |
} | |
- else if( psprite->frames[frame].type == FRAME_ANGLED ) //-V556 | |
+ else if( psprite->frames[frame].type == FRAME_ANGLED ) | |
{ | |
int angleframe = (int)(Q_rint(( RI.refdef.viewangles[1] - yaw + 45.0f ) / 360 * 8) - 4) & 7; | |
@@ -564,11 +546,11 @@ float R_GetSpriteFrameInterpolant( cl_en | |
frame = psprite->numframes - 1; | |
} | |
- if( psprite->frames[frame].type == FRAME_SINGLE ) //-V556 | |
+ if( psprite->frames[frame].type == FRAME_SINGLE ) | |
{ | |
if( m_fDoInterp ) | |
{ | |
- if( ent->latched.prevblending[0] >= psprite->numframes || psprite->frames[ent->latched.prevblending[0]].type != FRAME_SINGLE ) //-V556 | |
+ if( ent->latched.prevblending[0] >= psprite->numframes || psprite->frames[ent->latched.prevblending[0]].type != FRAME_SINGLE ) | |
{ | |
// this can be happens when rendering switched between single and angled frames | |
// or change model on replace delta-entity | |
@@ -613,7 +595,7 @@ float R_GetSpriteFrameInterpolant( cl_en | |
if( oldframe ) *oldframe = psprite->frames[ent->latched.prevblending[0]].frameptr; | |
if( curframe ) *curframe = psprite->frames[frame].frameptr; | |
} | |
- else if( psprite->frames[frame].type == FRAME_GROUP ) //-V556 | |
+ else if( psprite->frames[frame].type == FRAME_GROUP ) | |
{ | |
pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; | |
pintervals = pspritegroup->intervals; | |
@@ -646,7 +628,7 @@ float R_GetSpriteFrameInterpolant( cl_en | |
if( oldframe ) *oldframe = pspritegroup->frames[j]; | |
if( curframe ) *curframe = pspritegroup->frames[i]; | |
} | |
- else if( psprite->frames[frame].type == FRAME_ANGLED ) //-V556 | |
+ else if( psprite->frames[frame].type == FRAME_ANGLED ) | |
{ | |
// e.g. doom-style sprite monsters | |
float yaw = ent->angles[YAW]; | |
@@ -654,7 +636,7 @@ float R_GetSpriteFrameInterpolant( cl_en | |
if( m_fDoInterp ) | |
{ | |
- if( ent->latched.prevblending[0] >= psprite->numframes || psprite->frames[ent->latched.prevblending[0]].type != FRAME_ANGLED ) //-V556 | |
+ if( ent->latched.prevblending[0] >= psprite->numframes || psprite->frames[ent->latched.prevblending[0]].type != FRAME_ANGLED ) | |
{ | |
// this can be happens when rendering switched between single and angled frames | |
// or change model on replace delta-entity | |
@@ -1078,7 +1060,7 @@ void R_DrawSpriteModel( cl_entity_t *e ) | |
{ | |
// draw the single non-lerped frame | |
pglColor4f( color[0], color[1], color[2], flAlpha ); | |
- GL_Bind( XASH_TEXTURE0, frame->gl_texturenum ); | |
+ GL_Bind( GL_TEXTURE0, frame->gl_texturenum ); | |
R_DrawSpriteQuad( frame, origin, v_right, v_up, scale ); | |
} | |
else | |
@@ -1090,14 +1072,14 @@ void R_DrawSpriteModel( cl_entity_t *e ) | |
if( ilerp != 0.0f ) | |
{ | |
pglColor4f( color[0], color[1], color[2], flAlpha * ilerp ); | |
- GL_Bind( XASH_TEXTURE0, oldframe->gl_texturenum ); | |
+ GL_Bind( GL_TEXTURE0, oldframe->gl_texturenum ); | |
R_DrawSpriteQuad( oldframe, origin, v_right, v_up, scale ); | |
} | |
if( lerp != 0.0f ) | |
{ | |
pglColor4f( color[0], color[1], color[2], flAlpha * lerp ); | |
- GL_Bind( XASH_TEXTURE0, frame->gl_texturenum ); | |
+ GL_Bind( GL_TEXTURE0, frame->gl_texturenum ); | |
R_DrawSpriteQuad( frame, origin, v_right, v_up, scale ); | |
} | |
} | |
@@ -1112,7 +1094,7 @@ void R_DrawSpriteModel( cl_entity_t *e ) | |
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |
pglColor4f( color2[0], color2[1], color2[2], flAlpha ); | |
- GL_Bind( XASH_TEXTURE0, tr.whiteTexture ); | |
+ GL_Bind( GL_TEXTURE0, tr.whiteTexture ); | |
R_DrawSpriteQuad( frame, origin, v_right, v_up, scale ); | |
if( glState.drawTrans ) | |
@@ -1136,4 +1118,3 @@ void R_DrawSpriteModel( cl_entity_t *e ) | |
if( RI.fogCustom || ( RI.fogEnabled && !glState.drawTrans )) | |
pglEnable( GL_FOG ); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_studio.c /mnt/data/Xash3D_original/engine/client/gl_studio.c | |
--- engine/client/gl_studio.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_studio.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "mathlib.h" | |
@@ -48,14 +46,14 @@ static vec3_t hullcolor[8] = | |
// enumerate all the bones that used for gait animation | |
const char *legs_bones[] = | |
{ | |
- "Bip01" , | |
- "Bip01 Pelvis" , | |
- "Bip01 L Leg" , | |
- "Bip01 L Leg1" , | |
- "Bip01 L Foot" , | |
- "Bip01 R Leg" , | |
- "Bip01 R Leg1" , | |
- "Bip01 R Foot" , | |
+{ "Bip01" }, | |
+{ "Bip01 Pelvis" }, | |
+{ "Bip01 L Leg" }, | |
+{ "Bip01 L Leg1" }, | |
+{ "Bip01 L Foot" }, | |
+{ "Bip01 R Leg" }, | |
+{ "Bip01 R Leg1" }, | |
+{ "Bip01 R Foot" }, | |
}; | |
typedef struct studiolight_s | |
@@ -83,7 +81,6 @@ convar_t *r_studio_lerping; | |
convar_t *r_studio_lambert; | |
convar_t *r_studio_lighting; | |
convar_t *r_studio_sort_textures; | |
-convar_t *r_studio_drawelements; | |
convar_t *r_drawviewmodel; | |
convar_t *r_customdraw_playermodel; | |
convar_t *cl_himodels; | |
@@ -106,9 +103,7 @@ static int g_chromeage[MAXSTUDIOBONES]; | |
static vec3_t g_xformverts[MAXSTUDIOVERTS]; | |
static vec3_t g_xformnorms[MAXSTUDIOVERTS]; | |
static vec3_t g_xarrayverts[MAXARRAYVERTS]; | |
-static vec2_t g_xarraycoord[MAXARRAYVERTS]; | |
-static GLubyte g_xarraycolor[MAXARRAYVERTS][4]; | |
-static unsigned short g_xarrayelems[MAXARRAYVERTS*6]; | |
+static uint g_xarrayelems[MAXARRAYVERTS*6]; | |
static uint g_nNumArrayVerts; | |
static uint g_nNumArrayElems; | |
static vec3_t g_lightvalues[MAXSTUDIOVERTS]; | |
@@ -151,7 +146,7 @@ void R_StudioInit( void ) | |
cl_himodels = Cvar_Get( "cl_himodels", "1", CVAR_ARCHIVE, "draw high-resolution player models in multiplayer" ); | |
r_studio_lighting = Cvar_Get( "r_studio_lighting", "1", CVAR_ARCHIVE, "studio lighting models ( 0 - normal, 1 - extended, 2 - experimental )" ); | |
r_studio_sort_textures = Cvar_Get( "r_studio_sort_textures", "0", CVAR_ARCHIVE, "sort additive and normal textures for right drawing" ); | |
- r_studio_drawelements = Cvar_Get( "r_studio_drawelements", "1", CVAR_ARCHIVE, "Use glDrawElements for studio render" ); | |
+ | |
// NOTE: some mods with custom studiomodel renderer may cause error when menu trying draw player model out of the loaded game | |
r_customdraw_playermodel = Cvar_Get( "r_customdraw_playermodel", "0", CVAR_ARCHIVE, "allow to drawing playermodel in menu with client renderer" ); | |
@@ -161,11 +156,8 @@ void R_StudioInit( void ) | |
pixelAspect *= (320.0f / 240.0f); | |
else pixelAspect *= (640.0f / 480.0f); | |
- if( RI.refdef.fov_y != 0 ) | |
- { | |
aliasXscale = (float)scr_width->integer / RI.refdef.fov_y; | |
aliasYscale = aliasXscale * pixelAspect; | |
- } | |
Matrix3x4_LoadIdentity( g_aliastransform ); | |
Matrix3x4_LoadIdentity( g_rotationmatrix ); | |
@@ -187,7 +179,7 @@ const char *R_StudioTexName( model_t *mo | |
Q_strncpy( texname, mod->name, sizeof( texname )); | |
FS_StripExtension( texname ); | |
- Q_strncat( texname, "t.mdl", sizeof( texname )); | |
+ Q_strncat( texname, "T.mdl", sizeof( texname )); | |
return texname; | |
} | |
@@ -396,7 +388,7 @@ pfnGetModelCounters | |
static void pfnGetModelCounters( int **s, int **a ) | |
{ | |
*s = &g_nStudioCount; | |
- *a = (int *)&r_stats.c_studio_models_drawn; | |
+ *a = &r_stats.c_studio_models_drawn; | |
} | |
/* | |
@@ -648,19 +640,15 @@ StudioGetAnim | |
mstudioanim_t *R_StudioGetAnim( model_t *m_pSubModel, mstudioseqdesc_t *pseqdesc ) | |
{ | |
mstudioseqgroup_t *pseqgroup; | |
- fs_offset_t filesize; | |
- byte *buf; | |
cache_user_t *paSequences; | |
+ size_t filesize; | |
+ byte *buf; | |
ASSERT( m_pSubModel ); | |
pseqgroup = (mstudioseqgroup_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqgroupindex) + pseqdesc->seqgroup; | |
if( pseqdesc->seqgroup == 0 ) | |
-#ifdef __amd64__ | |
- return (mstudioanim_t *)((byte *)m_pStudioHeader + pseqdesc->animindex); | |
-#else | |
return (mstudioanim_t *)((byte *)m_pStudioHeader + pseqgroup->data + pseqdesc->animindex); | |
-#endif | |
paSequences = (cache_user_t *)m_pSubModel->submodels; | |
@@ -671,7 +659,7 @@ mstudioanim_t *R_StudioGetAnim( model_t | |
} | |
// check for already loaded | |
- if( !paSequences[pseqdesc->seqgroup].data ) | |
+ if( !Mod_CacheCheck(( cache_user_t *)&( paSequences[pseqdesc->seqgroup] ))) | |
{ | |
string filepath, modelname, modelpath; | |
@@ -682,15 +670,13 @@ mstudioanim_t *R_StudioGetAnim( model_t | |
Q_snprintf( filepath, sizeof( filepath ), "%s/%s%i%i.mdl", modelpath, modelname, pseqdesc->seqgroup / 10, pseqdesc->seqgroup % 10 ); | |
buf = FS_LoadFile( filepath, &filesize, false ); | |
- if( !buf || !filesize ) | |
- Host_Error( "StudioGetAnim: can't load %s\n", filepath ); | |
- else if( IDSEQGRPHEADER != *(uint *)buf ) | |
- Host_Error( "StudioGetAnim: %s is corrupted\n", filepath ); | |
+ if( !buf || !filesize ) Host_Error( "StudioGetAnim: can't load %s\n", filepath ); | |
+ if( IDSEQGRPHEADER != *(uint *)buf ) Host_Error( "StudioGetAnim: %s is corrupted\n", filepath ); | |
MsgDev( D_INFO, "loading: %s\n", filepath ); | |
paSequences[pseqdesc->seqgroup].data = Mem_Alloc( com_studiocache, filesize ); | |
- Q_memcpy( paSequences[pseqdesc->seqgroup].data, buf, (size_t)filesize ); | |
+ Q_memcpy( paSequences[pseqdesc->seqgroup].data, buf, filesize ); | |
Mem_Free( buf ); | |
} | |
@@ -750,7 +736,7 @@ StudioCalcBoneAdj | |
void R_StudioCalcBoneAdj( float dadt, float *adj, const byte *pcontroller1, const byte *pcontroller2, byte mouthopen ) | |
{ | |
mstudiobonecontroller_t *pbonecontroller; | |
- float value = 0.0f; | |
+ float value; | |
int i, j; | |
pbonecontroller = (mstudiobonecontroller_t *)((byte *)m_pStudioHeader + m_pStudioHeader->bonecontrollerindex); | |
@@ -781,7 +767,7 @@ void R_StudioCalcBoneAdj( float dadt, fl | |
} | |
else | |
{ | |
- value = (pcontroller1[i] * dadt + (pcontroller2[i]) * (1.0f - dadt)) * (360.0f / 256.0f) + pbonecontroller[j].start; | |
+ value = ((pcontroller1[i] * dadt + (pcontroller2[i]) * (1.0f - dadt))) * (360.0f / 256.0f) + pbonecontroller[j].start; | |
} | |
} | |
else | |
@@ -1493,7 +1479,7 @@ void R_StudioDynamicLight( cl_entity_t * | |
VectorCopy( plight->lightvec, lightinfo->plightvec ); | |
// setup ambient lighting | |
- invLight = (ent && ent->curstate.effects & EF_INVLIGHT) ? true : false; | |
+ invLight = (ent->curstate.effects & EF_INVLIGHT) ? true : false; | |
R_LightForPoint( origin, &ambient, invLight, true, 0.0f ); // ignore dlights | |
R_GetLightSpot( plight->lightspot ); // shadow stuff | |
@@ -1525,7 +1511,7 @@ void R_StudioDynamicLight( cl_entity_t * | |
for( i = 0; i < m_pStudioHeader->numbones; i++ ) | |
{ | |
vec3_t vec, org; | |
- float atten; | |
+ float dist, atten; | |
Matrix3x4_OriginFromMatrix( g_lighttransform[i], org ); | |
VectorSubtract( org, dl->origin, vec ); | |
@@ -1611,7 +1597,7 @@ void R_StudioEntityLight( alight_t *ligh | |
for( i = 0; i < m_pStudioHeader->numbones; i++ ) | |
{ | |
vec3_t vec, org; | |
- float atten; | |
+ float dist, atten; | |
Matrix3x4_OriginFromMatrix( g_lighttransform[i], org ); | |
VectorSubtract( org, origin, vec ); | |
@@ -1682,7 +1668,7 @@ R_StudioLighting | |
*/ | |
void R_StudioLighting( float *lv, int bone, int flags, vec3_t normal ) | |
{ | |
- float _max, ambient; | |
+ float max, ambient; | |
vec3_t illum; | |
studiolight_t *plight; | |
@@ -1734,10 +1720,10 @@ void R_StudioLighting( float *lv, int bo | |
} | |
} | |
- _max = VectorMax( illum ); | |
+ max = VectorMax( illum ); | |
- if( _max > 1.0f ) | |
- VectorScale( illum, ( 1.0f / _max ), lv ); | |
+ if( max > 1.0f ) | |
+ VectorScale( illum, ( 1.0f / max ), lv ); | |
else VectorCopy( illum, lv ); | |
} | |
@@ -1801,7 +1787,7 @@ static void R_StudioSetupSkin( mstudiote | |
if( m_skinnum != 0 && m_skinnum < m_pTextureHeader->numskinfamilies ) | |
pskinref += (m_skinnum * m_pTextureHeader->numskinref); | |
- GL_Bind( XASH_TEXTURE0, ptexture[pskinref[index]].index ); | |
+ GL_Bind( GL_TEXTURE0, ptexture[pskinref[index]].index ); | |
} | |
/* | |
@@ -1931,7 +1916,7 @@ R_StudioDrawPoints | |
=============== | |
*/ | |
-static void R_StudioDrawPoints_legacy( void ) | |
+static void R_StudioDrawPoints( void ) | |
{ | |
int i, j, m_skinnum; | |
byte *pvertbone; | |
@@ -1941,7 +1926,7 @@ static void R_StudioDrawPoints_legacy( v | |
mstudiotexture_t *ptexture; | |
mstudiomesh_t *pmesh; | |
short *pskinref; | |
- float *av, *lv, *nv, scale = 0.0f; | |
+ float *av, *lv, *nv, scale; | |
R_StudioSetupTextureHeader (); | |
@@ -2002,7 +1987,7 @@ static void R_StudioDrawPoints_legacy( v | |
if( r_studio_sort_textures->integer ) | |
{ | |
// sort opaque and translucent for right results | |
- qsort( g_sortedMeshes, m_pSubModel->nummesh, sizeof( sortedmesh_t ), (void*)R_StudioMeshCompare ); | |
+ qsort( g_sortedMeshes, m_pSubModel->nummesh, sizeof( sortedmesh_t ), R_StudioMeshCompare ); | |
} | |
for( j = 0; j < m_pSubModel->nummesh; j++ ) | |
@@ -2065,10 +2050,10 @@ static void R_StudioDrawPoints_legacy( v | |
if( !( g_nForceFaceFlags & STUDIO_NF_CHROME )) | |
{ | |
- GL_Bind( XASH_TEXTURE0, ptexture[pskinref[pmesh->skinref]].index ); | |
+ GL_Bind( GL_TEXTURE0, ptexture[pskinref[pmesh->skinref]].index ); | |
} | |
- while( ( i = *( ptricmds++ ) ) ) | |
+ while( i = *( ptricmds++ )) | |
{ | |
int vertexState = 0; | |
qboolean tri_strip; | |
@@ -2177,306 +2162,6 @@ static void R_StudioDrawPoints_legacy( v | |
/* | |
=============== | |
-R_StudioDrawMesh | |
- | |
-=============== | |
-*/ | |
-static void R_StudioDrawMesh(short *ptricmds, float s, float t ) | |
-{ | |
- GLubyte alpha = 255; | |
- int i; | |
- vec2_t uv; | |
- float *av, *lv; | |
- | |
- g_nNumArrayVerts = g_nNumArrayElems = 0; | |
- | |
- while( ( i = *( ptricmds++ ) ) ) | |
- { | |
- int vertexState = 0; | |
- qboolean tri_strip; | |
- | |
- if( i < 0 ) | |
- { | |
- tri_strip = false; | |
- i = -i; | |
- } | |
- else | |
- { | |
- tri_strip = true; | |
- } | |
- | |
- r_stats.c_studio_polys += (i - 2); | |
- | |
- for( ; i > 0; i--, ptricmds += 4 ) | |
- { | |
- | |
- GLubyte cl[4]; | |
- // build in indices | |
- if( vertexState++ < 3 ) | |
- { | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts; | |
- } | |
- else if( tri_strip ) | |
- { | |
- // flip triangles between clockwise and counter clockwise | |
- if( vertexState & 1 ) | |
- { | |
- // draw triangle [n-2 n-1 n] | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts - 2; | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts - 1; | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts; | |
- } | |
- else | |
- { | |
- // draw triangle [n-1 n-2 n] | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts - 1; | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts - 2; | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts; | |
- } | |
- } | |
- else | |
- { | |
- // draw triangle fan [0 n-1 n] | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts - ( vertexState - 1 ); | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts - 1; | |
- g_xarrayelems[g_nNumArrayElems++] = g_nNumArrayVerts; | |
- } | |
- if( g_nFaceFlags & STUDIO_NF_CHROME || ( g_nForceFaceFlags & STUDIO_NF_CHROME )) | |
- { | |
- uv[0] = g_chrome[ptricmds[1]][0] * s; | |
- uv[1] = g_chrome[ptricmds[1]][1] * t ; | |
- } | |
- else if( g_nFaceFlags & STUDIO_NF_UV_COORDS ) | |
- { | |
- uv[0] = ptricmds[2] * (1.0f / 32768.0f); | |
- uv[1] = ptricmds[3] * (1.0f / 32768.0f); | |
- } | |
- else | |
- { | |
- uv[0] = ptricmds[2] * s; | |
- uv[1] = ptricmds[3] * t; | |
- } | |
- g_xarraycoord[g_nNumArrayVerts][0] = uv[0]; | |
- g_xarraycoord[g_nNumArrayVerts][1] = uv[1]; | |
- | |
- lv = (float *)g_lightvalues[ptricmds[1]]; | |
- cl[0] = lv[0]*255; | |
- cl[1] = lv[1]*255; | |
- cl[2] = lv[2]*255; | |
- cl[3] = alpha; | |
- | |
- Q_memcpy( g_xarraycolor[g_nNumArrayVerts], cl, sizeof(cl) ); | |
- | |
- av = g_xformverts[ptricmds[0]]; | |
- /*if( g_nForceFaceFlags & STUDIO_NF_CHROME ) | |
- { | |
- vec3_t scaled_vertex; | |
- nv = (float *)g_xformnorms[ptricmds[1]]; | |
- VectorMA( av, scale, nv, scaled_vertex ); | |
- pglVertex3fv( scaled_vertex ); | |
- } | |
- else*/ | |
- { | |
- //pglVertex3f( av[0], av[1], av[2] ); | |
- ASSERT( g_nNumArrayVerts < MAXARRAYVERTS ); | |
- VectorCopy( av, g_xarrayverts[g_nNumArrayVerts] ); // store off vertex | |
- g_nNumArrayVerts++; | |
- } | |
- } | |
- } | |
- | |
- pglEnableClientState( GL_VERTEX_ARRAY ); | |
- pglVertexPointer( 3, GL_FLOAT, 12, g_xarrayverts ); | |
- | |
- pglEnableClientState( GL_TEXTURE_COORD_ARRAY ); | |
- pglTexCoordPointer( 2, GL_FLOAT, 0, g_xarraycoord ); | |
- | |
- pglEnableClientState( GL_COLOR_ARRAY ); | |
- pglColorPointer( 4, GL_UNSIGNED_BYTE, 0, g_xarraycolor ); | |
-#ifndef XASH_NANOGL | |
- if( pglDrawRangeElements ) | |
- pglDrawRangeElements( GL_TRIANGLES, 0, g_nNumArrayVerts, g_nNumArrayElems, GL_UNSIGNED_SHORT, g_xarrayelems ); | |
- else | |
-#endif | |
- pglDrawElements( GL_TRIANGLES, g_nNumArrayElems, GL_UNSIGNED_SHORT, g_xarrayelems ); | |
- pglDisableClientState( GL_VERTEX_ARRAY ); | |
- pglDisableClientState( GL_TEXTURE_COORD_ARRAY ); | |
- pglDisableClientState( GL_COLOR_ARRAY ); | |
-} | |
- | |
-/* | |
-=============== | |
-R_StudioDrawMeshes | |
- | |
-=============== | |
-*/ | |
-static void R_StudioDrawMeshes( mstudiotexture_t *ptexture, short *pskinref ) | |
-{ | |
- int j; | |
- mstudiomesh_t *pmesh; | |
- | |
- for( j = 0; j < m_pSubModel->nummesh; j++ ) | |
- { | |
- float s, t, alpha; | |
- short *ptricmds; | |
- | |
- pmesh = g_sortedMeshes[j].mesh; | |
- ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); | |
- | |
- g_nFaceFlags = ptexture[pskinref[pmesh->skinref]].flags; | |
- s = 1.0f / (float)ptexture[pskinref[pmesh->skinref]].width; | |
- t = 1.0f / (float)ptexture[pskinref[pmesh->skinref]].height; | |
- | |
- if( g_iRenderMode != kRenderTransAdd ) | |
- pglDepthMask( GL_TRUE ); | |
- else pglDepthMask( GL_FALSE ); | |
- | |
- // check bounds | |
- if( ptexture[pskinref[pmesh->skinref]].index < 0 || ptexture[pskinref[pmesh->skinref]].index > MAX_TEXTURES ) | |
- ptexture[pskinref[pmesh->skinref]].index = tr.defaultTexture; | |
- | |
- if( g_nForceFaceFlags & STUDIO_NF_CHROME ) | |
- { | |
- color24 *clr; | |
- clr = &RI.currententity->curstate.rendercolor; | |
- pglColor4ub( clr->r, clr->g, clr->b, 255 ); | |
- alpha = 1.0f; | |
- } | |
- else if( g_nFaceFlags & STUDIO_NF_TRANSPARENT && R_StudioOpaque( RI.currententity )) | |
- { | |
- GL_SetRenderMode( kRenderTransAlpha ); | |
- pglAlphaFunc( GL_GREATER, 0.0f ); | |
- alpha = 1.0f; | |
- } | |
- else if( g_nFaceFlags & STUDIO_NF_ADDITIVE ) | |
- { | |
- GL_SetRenderMode( kRenderTransAdd ); | |
- alpha = RI.currententity->curstate.renderamt * (1.0f / 255.0f); | |
- pglBlendFunc( GL_SRC_ALPHA, GL_ONE ); | |
- pglDepthMask( GL_FALSE ); | |
- } | |
- else if( g_nFaceFlags & STUDIO_NF_ALPHA && !( host.features & ENGINE_DISABLE_HDTEXTURES )) // Paranoia2 collision flag | |
- { | |
- GL_SetRenderMode( kRenderTransTexture ); | |
- alpha = RI.currententity->curstate.renderamt * (1.0f / 255.0f); | |
- pglDepthMask( GL_FALSE ); | |
- } | |
- else | |
- { | |
- GL_SetRenderMode( g_iRenderMode ); | |
- | |
- if( g_iRenderMode == kRenderNormal ) | |
- { | |
- pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |
- alpha = 1.0f; | |
- } | |
- else alpha = RI.currententity->curstate.renderamt * (1.0f / 255.0f); | |
- } | |
- | |
- if( !( g_nForceFaceFlags & STUDIO_NF_CHROME )) | |
- { | |
- GL_Bind( XASH_TEXTURE0, ptexture[pskinref[pmesh->skinref]].index ); | |
- } | |
- | |
- R_StudioDrawMesh(ptricmds, s, t); | |
- } | |
-} | |
- | |
-/* | |
-=============== | |
-R_StudioDrawPoints | |
- | |
-=============== | |
-*/ | |
-static void R_StudioDrawPoints( void ) | |
-{ | |
- int i, j, m_skinnum; | |
- byte *pvertbone; | |
- byte *pnormbone; | |
- vec3_t *pstudioverts; | |
- vec3_t *pstudionorms; | |
- mstudiotexture_t *ptexture; | |
- mstudiomesh_t *pmesh; | |
- short *pskinref; | |
- float *av, *lv, *nv, scale = 0.0f; | |
- | |
- if( !r_studio_drawelements->integer ) | |
- { | |
- R_StudioDrawPoints_legacy(); | |
- return; | |
- } | |
- | |
- R_StudioSetupTextureHeader (); | |
- | |
- g_nNumArrayVerts = g_nNumArrayElems = 0; | |
- | |
- if( !m_pTextureHeader ) return; | |
- if( RI.currententity->curstate.renderfx == kRenderFxGlowShell ) | |
- g_nStudioCount++; | |
- | |
- // safety bounding the skinnum | |
- m_skinnum = bound( 0, RI.currententity->curstate.skin, ( m_pTextureHeader->numskinfamilies - 1 )); | |
- pvertbone = ((byte *)m_pStudioHeader + m_pSubModel->vertinfoindex); | |
- pnormbone = ((byte *)m_pStudioHeader + m_pSubModel->norminfoindex); | |
- | |
- // NOTE: user can comment call StudioRemapColors and remap_info will be unavailable | |
- if( m_fDoRemap ) ptexture = CL_GetRemapInfoForEntity( RI.currententity )->ptexture; | |
- else ptexture = (mstudiotexture_t *)((byte *)m_pTextureHeader + m_pTextureHeader->textureindex); | |
- | |
- ASSERT( ptexture != NULL ); | |
- | |
- pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex); | |
- pstudioverts = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->vertindex); | |
- pstudionorms = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->normindex); | |
- | |
- pskinref = (short *)((byte *)m_pTextureHeader + m_pTextureHeader->skinindex); | |
- if( m_skinnum != 0 && m_skinnum < m_pTextureHeader->numskinfamilies ) | |
- pskinref += (m_skinnum * m_pTextureHeader->numskinref); | |
- | |
- for( i = 0; i < m_pSubModel->numverts; i++ ) | |
- Matrix3x4_VectorTransform( g_bonestransform[pvertbone[i]], pstudioverts[i], g_xformverts[i] ); | |
- | |
- if( g_nForceFaceFlags & STUDIO_NF_CHROME ) | |
- { | |
- scale = RI.currententity->curstate.renderamt * (1.0f / 255.0f); | |
- | |
- for( i = 0; i < m_pSubModel->numnorms; i++ ) | |
- Matrix3x4_VectorRotate( g_bonestransform[pnormbone[i]], pstudionorms[i], g_xformnorms[i] ); | |
- } | |
- | |
- lv = (float *)g_lightvalues; | |
- for( j = 0; j < m_pSubModel->nummesh; j++ ) | |
- { | |
- g_nFaceFlags = ptexture[pskinref[pmesh[j].skinref]].flags; | |
- | |
- // fill in sortedmesh info | |
- g_sortedMeshes[j].mesh = &pmesh[j]; | |
- g_sortedMeshes[j].flags = g_nFaceFlags; | |
- | |
- for( i = 0; i < pmesh[j].numnorms; i++, lv += 3, pstudionorms++, pnormbone++ ) | |
- { | |
- R_StudioLighting( lv, *pnormbone, g_nFaceFlags, (float *)pstudionorms ); | |
- | |
- if(( g_nFaceFlags & STUDIO_NF_CHROME ) || ( g_nForceFaceFlags & STUDIO_NF_CHROME )) | |
- R_StudioSetupChrome( g_chrome[(float (*)[3])lv - g_lightvalues], *pnormbone, (float *)pstudionorms ); | |
- } | |
- } | |
- | |
- if( r_studio_sort_textures->integer ) | |
- { | |
- // sort opaque and translucent for right results | |
- qsort( g_sortedMeshes, m_pSubModel->nummesh, sizeof( sortedmesh_t ), (void *)R_StudioMeshCompare ); | |
- } | |
- | |
- R_StudioDrawMeshes(ptexture,pskinref); | |
- | |
- // restore depthmask for next call StudioDrawPoints | |
- if( g_iRenderMode != kRenderTransAdd ) | |
- pglDepthMask( GL_TRUE ); | |
-} | |
- | |
-/* | |
-=============== | |
R_StudioDrawHulls | |
=============== | |
@@ -2811,10 +2496,8 @@ static void R_StudioClientEvents( void ) | |
if( pseqdesc->numevents == 0 || cl.time == cl.oldtime ) | |
return; | |
- f = R_StudioEstimateFrame( e, pseqdesc ); // get start offset | |
- if ( e->latched.sequencetime == e->curstate.animtime && !( pseqdesc->flags & STUDIO_LOOPING ) ) | |
- start = -0.01f; | |
- else start = f - e->curstate.framerate * host.frametime * pseqdesc->fps; | |
+ f = R_StudioEstimateFrame( e, pseqdesc ) + 0.01f; // get start offset | |
+ start = f - e->curstate.framerate * host.frametime * pseqdesc->fps; | |
for( i = 0; i < pseqdesc->numevents; i++ ) | |
{ | |
@@ -2981,12 +2664,9 @@ static void R_StudioDrawPlanarShadow( vo | |
pglEnableClientState( GL_VERTEX_ARRAY ); | |
pglVertexPointer( 3, GL_FLOAT, 12, g_xarrayverts ); | |
-#ifndef XASH_NANOGL | |
if( GL_Support( GL_DRAW_RANGEELEMENTS_EXT )) | |
pglDrawRangeElementsEXT( GL_TRIANGLES, 0, g_nNumArrayVerts, g_nNumArrayElems, GL_UNSIGNED_INT, g_xarrayelems ); | |
- else | |
-#endif | |
- pglDrawElements( GL_TRIANGLES, g_nNumArrayElems, GL_UNSIGNED_INT, g_xarrayelems ); | |
+ else pglDrawElements( GL_TRIANGLES, g_nNumArrayElems, GL_UNSIGNED_INT, g_xarrayelems ); | |
if( glState.stencilEnabled ) | |
pglDisable( GL_STENCIL_TEST ); | |
@@ -3071,7 +2751,7 @@ void R_StudioRenderFinal( void ) | |
{ | |
for( i = 0; i < m_pStudioHeader->numbodyparts; i++ ) | |
{ | |
- R_StudioSetupModel( i, (void **)&m_pBodyPart, (void **)&m_pSubModel ); | |
+ R_StudioSetupModel( i, &m_pBodyPart, &m_pSubModel ); | |
GL_SetRenderMode( rendermode ); | |
R_StudioDrawPoints(); | |
@@ -3268,7 +2948,7 @@ R_StudioDrawPlayer | |
static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer ) | |
{ | |
int m_nPlayerIndex; | |
- float gaitframe = 0.0f, gaityaw = 0.0f; | |
+ float gaitframe, gaityaw; | |
vec3_t dir, prevgaitorigin; | |
alight_t lighting; | |
@@ -3621,20 +3301,10 @@ void R_RunViewmodelEvents( void ) | |
if( !Mod_Extradata( clgame.viewent.model )) | |
return; | |
-/*#ifndef _MSC_VER | |
-#warning "check this" | |
-#endif | |
- if( cl_lw->value && cl.frame.client.viewmodel != cl.predicted.viewmodel ) | |
- return;*/ | |
- | |
RI.currententity = &clgame.viewent; | |
RI.currentmodel = RI.currententity->model; | |
if( !RI.currentmodel ) return; | |
- if( !cl.weaponstarttime ) | |
- cl.weaponstarttime = cl.time; | |
- RI.currententity->curstate.animtime = cl.weaponstarttime; | |
- RI.currententity->curstate.sequence = cl.weaponseq; | |
pStudioDraw->StudioDrawModel( STUDIO_EVENTS ); | |
RI.currententity = NULL; | |
@@ -3660,11 +3330,6 @@ void R_DrawViewModel( void ) | |
if( !Mod_Extradata( clgame.viewent.model )) | |
return; | |
-/*#ifndef _MSC_VER | |
-#warning "check this" | |
-#endif | |
- if( cl_lw->value && cl.frame.client.viewmodel != cl.predicted.viewmodel ) | |
- return;*/ | |
RI.currententity = &clgame.viewent; | |
RI.currentmodel = RI.currententity->model; | |
@@ -3678,13 +3343,7 @@ void R_DrawViewModel( void ) | |
// backface culling for left-handed weapons | |
if( r_lefthand->integer == 1 || g_iBackFaceCull ) | |
GL_FrontFace( !glState.frontFace ); | |
- RI.currententity->curstate.scale = 1.0f; | |
- RI.currententity->curstate.frame = 0; | |
- RI.currententity->curstate.framerate = 1.0f; | |
- if( !cl.weaponstarttime ) | |
- cl.weaponstarttime = cl.time; | |
- RI.currententity->curstate.animtime = cl.weaponstarttime; | |
- RI.currententity->curstate.sequence = cl.weaponseq; | |
+ | |
pStudioDraw->StudioDrawModel( STUDIO_RENDER ); | |
// restore depth range | |
@@ -3720,7 +3379,7 @@ static void R_StudioLoadTexture( model_t | |
// store some textures for remapping | |
if( !Q_strnicmp( ptexture->name, "DM_Base", 7 ) || !Q_strnicmp( ptexture->name, "remap", 5 )) | |
{ | |
- int i; | |
+ int i, size; | |
char val[6]; | |
byte *pixels; | |
@@ -3793,8 +3452,7 @@ static void R_StudioLoadTexture( model_t | |
if( !load_external ) | |
{ | |
// NOTE: replace index with pointer to start of imagebuffer, ImageLib expected it | |
- //ptexture->index = (int)((byte *)phdr) + ptexture->index; | |
- Image_SetMDLPointer((byte *)phdr + ptexture->index); | |
+ ptexture->index = (int)((byte *)phdr) + ptexture->index; | |
size = sizeof( mstudiotexture_t ) + ptexture->width * ptexture->height + 768; | |
if( host.features & ENGINE_DISABLE_HDTEXTURES && ptexture->flags & STUDIO_NF_TRANSPARENT ) | |
@@ -3804,7 +3462,7 @@ static void R_StudioLoadTexture( model_t | |
Q_snprintf( texname, sizeof( texname ), "#%s/%s.mdl", mdlname, name ); | |
ptexture->index = GL_LoadTexture( texname, (byte *)ptexture, size, flags, filter ); | |
} | |
- else MsgDev( D_NOTE, "Loading HQ: %s\n", texname ); | |
+ else MsgDev( D_NOTE, "loading HQ: %s\n", texname ); | |
if( !ptexture->index ) | |
{ | |
@@ -3843,7 +3501,7 @@ studiohdr_t *R_StudioLoadHeader( model_t | |
return NULL; | |
} | |
- if( !Host_IsDedicated() ) | |
+ if( host.type != HOST_DEDICATED ) | |
{ | |
ptexture = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); | |
if( phdr->textureindex > 0 && phdr->numtextures <= MAXSTUDIOSKINS ) | |
@@ -3853,17 +3511,6 @@ studiohdr_t *R_StudioLoadHeader( model_t | |
} | |
} | |
-#if 0 | |
- { | |
- // HACK: pseqgroup->data contains garbage. Clean it now | |
- mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)phdr + phdr->seqindex); | |
- mstudioseqgroup_t *pseqgroup = (mstudioseqgroup_t *)((byte *)phdr + phdr->seqgroupindex) + pseqdesc->seqgroup; | |
- //MsgDev( D_INFO, "R_StudioLoadHeader: data=0x%08x\n", pseqgroup->data ); | |
- int *ptr = (byte*)(mstudioseqgroup_t *)( pseqgroup + 1); // pseqgroup->data field | |
- *ptr = 0; | |
- } | |
-#endif | |
- | |
return (studiohdr_t *)buffer; | |
} | |
@@ -3992,8 +3639,8 @@ static engine_studio_api_t gStudioAPI = | |
{ | |
Mod_Calloc, | |
Mod_CacheCheck, | |
- (void*)Mod_LoadCacheFile, | |
- (void*)Mod_ForName, | |
+ Mod_LoadCacheFile, | |
+ Mod_ForName, | |
Mod_Extradata, | |
Mod_Handle, | |
pfnGetCurrentEntity, | |
@@ -4019,13 +3666,13 @@ static engine_studio_api_t gStudioAPI = | |
R_StudioDrawHulls, | |
R_StudioDrawAbsBBox, | |
R_StudioDrawBones, | |
- (void*)R_StudioSetupSkin, | |
+ R_StudioSetupSkin, | |
R_StudioSetRemapColors, | |
R_StudioSetupPlayerModel, | |
R_StudioClientEvents, | |
R_StudioGetForceFaceFlags, | |
R_StudioSetForceFaceFlags, | |
- (void*)R_StudioSetHeader, | |
+ R_StudioSetHeader, | |
R_StudioSetRenderModel, | |
R_StudioSetupRenderer, | |
R_StudioRestoreRenderer, | |
@@ -4075,4 +3722,3 @@ void CL_InitStudioAPI( void ) | |
// just restore pointer to builtin function | |
pStudioDraw = &gStudioDraw; | |
} | |
-#endif // XASH_DEDICATED | |
Только в engine/client: gl_vidnt_android_nosdl.c | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_vidnt.c /mnt/data/Xash3D_original/engine/client/gl_vidnt.c | |
--- engine/client/gl_vidnt.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_vidnt.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,30 +13,93 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
-#ifndef XASH_NANOGL | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
#include "mod_local.h" | |
#include "input.h" | |
-#include "gl_vidnt.h" | |
- | |
-#if (defined(_WIN32) && defined(XASH_SDL)) | |
-#include <SDL_syswm.h> | |
-#endif | |
-#ifdef XASH_X11 | |
-#include <X11/Xlib.h> | |
-#include <X11/Xatom.h> | |
-#endif | |
+#define VID_AUTOMODE "-1" | |
+#define VID_DEFAULTMODE 2.0f | |
+#define DISP_CHANGE_BADDUALVIEW -6 // MSVC 6.0 doesn't | |
+#define num_vidmodes ( sizeof( vidmode ) / sizeof( vidmode[0] )) | |
+#define WINDOW_STYLE (WS_OVERLAPPED|WS_BORDER|WS_SYSMENU|WS_CAPTION|WS_VISIBLE) | |
+#define WINDOW_EX_STYLE (0) | |
+#define WINDOW_NAME "Xash Window" // Half-Life | |
#ifdef WIN32 | |
// Enable NVIDIA High Performance Graphics while using Integrated Graphics. | |
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; | |
#endif | |
+convar_t *renderinfo; | |
+convar_t *gl_allow_software; | |
+convar_t *gl_extensions; | |
+convar_t *gl_alphabits; | |
+convar_t *gl_stencilbits; | |
+convar_t *gl_ignorehwgamma; | |
+convar_t *gl_texture_anisotropy; | |
+convar_t *gl_compress_textures; | |
+convar_t *gl_luminance_textures; | |
+convar_t *gl_compensate_gamma_screenshots; | |
+convar_t *gl_keeptjunctions; | |
+convar_t *gl_texture_lodbias; | |
+convar_t *gl_showtextures; | |
+convar_t *gl_detailscale; | |
+convar_t *gl_swapInterval; | |
+convar_t *gl_check_errors; | |
+convar_t *gl_allow_static; | |
+convar_t *gl_allow_mirrors; | |
+convar_t *gl_texturemode; | |
+convar_t *gl_wireframe; | |
+convar_t *gl_round_down; | |
+convar_t *gl_overview; | |
+convar_t *gl_max_size; | |
+convar_t *gl_picmip; | |
+convar_t *gl_skymip; | |
+convar_t *gl_finish; | |
+convar_t *gl_nosort; | |
+convar_t *gl_clear; | |
+convar_t *gl_test; | |
+ | |
+convar_t *r_xpos; | |
+convar_t *r_ypos; | |
+convar_t *r_width; | |
+convar_t *r_height; | |
+convar_t *r_speeds; | |
+convar_t *r_fullbright; | |
+convar_t *r_norefresh; | |
+convar_t *r_lighting_extended; | |
+convar_t *r_lighting_modulate; | |
+convar_t *r_lighting_ambient; | |
+convar_t *r_detailtextures; | |
+convar_t *r_faceplanecull; | |
+convar_t *r_drawentities; | |
+convar_t *r_adjust_fov; | |
+convar_t *r_flaresize; | |
+convar_t *r_lefthand; | |
+convar_t *r_decals; | |
+convar_t *r_novis; | |
+convar_t *r_nocull; | |
+convar_t *r_lockpvs; | |
+convar_t *r_lockcull; | |
+convar_t *r_dynamic; | |
+convar_t *r_lightmap; | |
+convar_t *r_fastsky; | |
+ | |
+convar_t *vid_displayfrequency; | |
+convar_t *vid_fullscreen; | |
+convar_t *vid_gamma; | |
+convar_t *vid_texgamma; | |
+convar_t *vid_mode; | |
+ | |
+byte *r_temppool; | |
+ | |
+ref_globals_t tr; | |
+glconfig_t glConfig; | |
+glstate_t glState; | |
+glwstate_t glw_state; | |
+uint num_instances; | |
typedef enum | |
{ | |
@@ -46,6 +109,42 @@ typedef enum | |
rserr_unknown | |
} rserr_t; | |
+typedef struct vidmode_s | |
+{ | |
+ const char *desc; | |
+ int width; | |
+ int height; | |
+ qboolean wideScreen; | |
+} vidmode_t; | |
+ | |
+vidmode_t vidmode[] = | |
+{ | |
+{ "Mode 0: 4x3", 640, 480, false }, | |
+{ "Mode 1: 4x3", 800, 600, false }, | |
+{ "Mode 2: 4x3", 960, 720, false }, | |
+{ "Mode 3: 4x3", 1024, 768, false }, | |
+{ "Mode 4: 4x3", 1152, 864, false }, | |
+{ "Mode 5: 4x3", 1280, 800, false }, | |
+{ "Mode 6: 4x3", 1280, 960, false }, | |
+{ "Mode 7: 4x3", 1280, 1024, false }, | |
+{ "Mode 8: 4x3", 1600, 1200, false }, | |
+{ "Mode 9: 4x3", 2048, 1536, false }, | |
+{ "Mode 10: 16x9", 800, 480, true }, | |
+{ "Mode 11: 16x9", 856, 480, true }, | |
+{ "Mode 12: 16x9", 960, 540, true }, | |
+{ "Mode 13: 16x9", 1024, 576, true }, | |
+{ "Mode 14: 16x9", 1024, 600, true }, | |
+{ "Mode 15: 16x9", 1280, 720, true }, | |
+{ "Mode 16: 16x9", 1360, 768, true }, | |
+{ "Mode 17: 16x9", 1366, 768, true }, | |
+{ "Mode 18: 16x9", 1440, 900, true }, | |
+{ "Mode 19: 16x9", 1680, 1050, true }, | |
+{ "Mode 20: 16x9", 1920, 1080, true }, | |
+{ "Mode 21: 16x9", 1920, 1200, true }, | |
+{ "Mode 22: 16x9", 2560, 1600, true }, | |
+{ "Mode 23: 16x9", 1600, 900, true }, | |
+}; | |
+ | |
static dllfunc_t opengl_110funcs[] = | |
{ | |
{ "glClearColor" , (void **)&pglClearColor }, | |
@@ -345,25 +444,82 @@ static dllfunc_t texturecompressionfuncs | |
{ NULL, NULL } | |
}; | |
+static dllfunc_t wgl_funcs[] = | |
+{ | |
+{ "wglSwapBuffers" , (void **)&pwglSwapBuffers }, | |
+{ "wglCreateContext" , (void **)&pwglCreateContext }, | |
+{ "wglDeleteContext" , (void **)&pwglDeleteContext }, | |
+{ "wglMakeCurrent" , (void **)&pwglMakeCurrent }, | |
+{ "wglGetCurrentContext" , (void **)&pwglGetCurrentContext }, | |
+{ NULL, NULL } | |
+}; | |
+ | |
+static dllfunc_t wglproc_funcs[] = | |
+{ | |
+{ "wglGetProcAddress" , (void **)&pwglGetProcAddress }, | |
+{ NULL, NULL } | |
+}; | |
+ | |
+static dllfunc_t wglswapintervalfuncs[] = | |
+{ | |
+{ "wglSwapIntervalEXT" , (void **)&pwglSwapIntervalEXT }, | |
+{ NULL, NULL } | |
+}; | |
+ | |
+dll_info_t opengl_dll = { "opengl32.dll", wgl_funcs, true }; | |
+ | |
/* | |
================= | |
-GL_GetProcAddress | |
+GL_SetExtension | |
================= | |
*/ | |
-void *GL_GetProcAddress( const char *name ) | |
+void GL_SetExtension( int r_ext, int enable ) | |
{ | |
-#ifdef XASH_SDL | |
- void *func = SDL_GL_GetProcAddress(name); | |
-#elif defined (XASH_GLES) | |
- void *func = nanoGL_GetProcAddress(name); | |
-#else //No opengl implementation | |
- void *func = NULL; | |
-#endif | |
- if(!func) | |
+ if( r_ext >= 0 && r_ext < GL_EXTCOUNT ) | |
+ glConfig.extension[r_ext] = enable ? GL_TRUE : GL_FALSE; | |
+ else MsgDev( D_ERROR, "GL_SetExtension: invalid extension %d\n", r_ext ); | |
+} | |
+ | |
+/* | |
+================= | |
+GL_Support | |
+================= | |
+*/ | |
+qboolean GL_Support( int r_ext ) | |
{ | |
- MsgDev(D_ERROR, "Error: GL_GetProcAddress failed for %s\n", name); | |
+ if( r_ext >= 0 && r_ext < GL_EXTCOUNT ) | |
+ return glConfig.extension[r_ext] ? true : false; | |
+ MsgDev( D_ERROR, "GL_Support: invalid extension %d\n", r_ext ); | |
+ | |
+ return false; | |
} | |
- return func; | |
+ | |
+/* | |
+================= | |
+GL_MaxTextureUnits | |
+================= | |
+*/ | |
+int GL_MaxTextureUnits( void ) | |
+{ | |
+ if( GL_Support( GL_SHADER_GLSL100_EXT )) | |
+ return min( max( glConfig.max_texture_coords, glConfig.max_teximage_units ), MAX_TEXTURE_UNITS ); | |
+ return glConfig.max_texture_units; | |
+} | |
+ | |
+/* | |
+================= | |
+GL_GetProcAddress | |
+================= | |
+*/ | |
+void *GL_GetProcAddress( const char *name ) | |
+{ | |
+ void *p = NULL; | |
+ | |
+ if( pwglGetProcAddress != NULL ) | |
+ p = (void *)pwglGetProcAddress( name ); | |
+ if( !p ) p = (void *)Sys_GetProcAddress( &opengl_dll, name ); | |
+ | |
+ return p; | |
} | |
/* | |
@@ -417,7 +572,29 @@ void GL_CheckExtension( const char *name | |
else MsgDev( D_NOTE, "- ^1failed\n" ); | |
} | |
+/* | |
+=============== | |
+GL_BuildGammaTable | |
+=============== | |
+*/ | |
+void GL_BuildGammaTable( void ) | |
+{ | |
+ int i, v; | |
+ double invGamma, div; | |
+ invGamma = 1.0 / bound( 0.5, vid_gamma->value, 2.3 ); | |
+ div = (double) 1.0 / 255.5; | |
+ | |
+ Q_memcpy( glState.gammaRamp, glState.stateRamp, sizeof( glState.gammaRamp )); | |
+ | |
+ for( i = 0; i < 256; i++ ) | |
+ { | |
+ v = (int)(65535.0 * pow(((double)i + 0.5 ) * div, invGamma ) + 0.5 ); | |
+ glState.gammaRamp[i+0] = ((word)bound( 0, v, 65535 )); | |
+ glState.gammaRamp[i+256] = ((word)bound( 0, v, 65535 )); | |
+ glState.gammaRamp[i+512] = ((word)bound( 0, v, 65535 )); | |
+ } | |
+} | |
/* | |
=============== | |
@@ -429,9 +606,8 @@ void GL_UpdateGammaRamp( void ) | |
if( !glConfig.deviceSupportsGamma ) return; | |
GL_BuildGammaTable(); | |
-#ifdef XASH_SDL | |
- SDL_SetWindowGammaRamp( host.hWnd, &glState.gammaRamp[0], &glState.gammaRamp[256], &glState.gammaRamp[512] ); | |
-#endif | |
+ | |
+ SetDeviceGammaRamp( glw_state.hDC, glState.gammaRamp ); | |
} | |
/* | |
@@ -441,13 +617,19 @@ GL_UpdateSwapInterval | |
*/ | |
void GL_UpdateSwapInterval( void ) | |
{ | |
- if( gl_swapInterval->modified ) | |
+ // disable VSync while level is loading | |
+ if( cls.state < ca_active ) | |
+ { | |
+ if( pwglSwapIntervalEXT ) | |
+ pwglSwapIntervalEXT( 0 ); | |
+ gl_swapInterval->modified = true; | |
+ } | |
+ else if( gl_swapInterval->modified ) | |
{ | |
gl_swapInterval->modified = false; | |
-#ifdef XASH_SDL | |
- if( SDL_GL_SetSwapInterval(gl_swapInterval->integer) ) | |
- MsgDev(D_ERROR, "SDL_GL_SetSwapInterval: %s\n", SDL_GetError()); | |
-#endif | |
+ | |
+ if( pwglSwapIntervalEXT ) | |
+ pwglSwapIntervalEXT( gl_swapInterval->integer ); | |
} | |
} | |
@@ -451,261 +633,116 @@ void GL_UpdateSwapInterval( void ) | |
} | |
} | |
- | |
/* | |
=============== | |
-GL_ContextError | |
+GL_SetDefaultTexState | |
=============== | |
*/ | |
-static void GL_ContextError( void ) | |
-{ | |
-#ifdef XASH_SDL | |
- MsgDev( D_ERROR, "GL_ContextError: %s\n", SDL_GetError() ); | |
-#endif | |
-} | |
- | |
-/* | |
-================== | |
-GL_SetupAttributes | |
-================== | |
-*/ | |
-void GL_SetupAttributes() | |
+static void GL_SetDefaultTexState( void ) | |
{ | |
-#ifdef XASH_SDL | |
- int samples; | |
- | |
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |
- SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); | |
- | |
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); | |
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); | |
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); | |
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); | |
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); | |
+ int i; | |
- switch( gl_msaa->integer ) | |
- { | |
- case 2: | |
- case 4: | |
- case 8: | |
- case 16: | |
- samples = gl_msaa->integer; | |
- break; | |
- default: | |
- samples = 0; // don't use, because invalid parameter is passed | |
- } | |
+ Q_memset( glState.currentTextures, -1, MAX_TEXTURE_UNITS * sizeof( *glState.currentTextures )); | |
+ Q_memset( glState.texCoordArrayMode, 0, MAX_TEXTURE_UNITS * sizeof( *glState.texCoordArrayMode )); | |
+ Q_memset( glState.genSTEnabled, 0, MAX_TEXTURE_UNITS * sizeof( *glState.genSTEnabled )); | |
- if( samples ) | |
- { | |
- SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); | |
- SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples); | |
- } | |
- else | |
+ for( i = 0; i < MAX_TEXTURE_UNITS; i++ ) | |
{ | |
- SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); | |
- SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); | |
+ glState.currentTextureTargets[i] = GL_NONE; | |
+ glState.texIdentityMatrix[i] = true; | |
} | |
-#endif // XASH_SDL | |
} | |
-void GL_InitExtensions( void ) | |
-{ | |
- // initialize gl extensions | |
- GL_CheckExtension( "OpenGL 1.1.0", opengl_110funcs, NULL, GL_OPENGL_110 ); | |
- | |
- // get our various GL strings | |
- glConfig.vendor_string = pglGetString( GL_VENDOR ); | |
- glConfig.renderer_string = pglGetString( GL_RENDERER ); | |
- glConfig.version_string = pglGetString( GL_VERSION ); | |
- glConfig.extensions_string = pglGetString( GL_EXTENSIONS ); | |
- MsgDev( D_INFO, "Video: %s\n", glConfig.renderer_string ); | |
- | |
- // initalize until base opengl functions loaded | |
- | |
- GL_CheckExtension( "glDrawRangeElements", drawrangeelementsfuncs, "gl_drawrangeelments", GL_DRAW_RANGEELEMENTS_EXT ); | |
- | |
- if( !GL_Support( GL_DRAW_RANGEELEMENTS_EXT )) | |
- GL_CheckExtension( "GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "gl_drawrangeelments", GL_DRAW_RANGEELEMENTS_EXT ); | |
- | |
- // multitexture | |
- glConfig.max_texture_units = glConfig.max_texture_coords = glConfig.max_teximage_units = 1; | |
- GL_CheckExtension( "GL_ARB_multitexture", multitexturefuncs, "gl_arb_multitexture", GL_ARB_MULTITEXTURE ); | |
- | |
- if( GL_Support( GL_ARB_MULTITEXTURE )) | |
- { | |
- pglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &glConfig.max_texture_units ); | |
- GL_CheckExtension( "GL_ARB_texture_env_combine", NULL, "gl_texture_env_combine", GL_ENV_COMBINE_EXT ); | |
- | |
- if( !GL_Support( GL_ENV_COMBINE_EXT )) | |
- GL_CheckExtension( "GL_EXT_texture_env_combine", NULL, "gl_texture_env_combine", GL_ENV_COMBINE_EXT ); | |
- | |
- if( GL_Support( GL_ENV_COMBINE_EXT )) | |
- GL_CheckExtension( "GL_ARB_texture_env_dot3", NULL, "gl_texture_env_dot3", GL_DOT3_ARB_EXT ); | |
- } | |
- else | |
+/* | |
+=============== | |
+GL_SetDefaultState | |
+=============== | |
+*/ | |
+static void GL_SetDefaultState( void ) | |
{ | |
- GL_CheckExtension( "GL_SGIS_multitexture", sgis_multitexturefuncs, "gl_sgis_multitexture", GL_ARB_MULTITEXTURE ); | |
- if( GL_Support( GL_ARB_MULTITEXTURE )) glConfig.max_texture_units = 2; | |
+ Q_memset( &glState, 0, sizeof( glState )); | |
+ GL_SetDefaultTexState (); | |
} | |
- if( glConfig.max_texture_units == 1 ) | |
- GL_SetExtension( GL_ARB_MULTITEXTURE, false ); | |
- | |
- // 3d texture support | |
- GL_CheckExtension( "GL_EXT_texture3D", texture3dextfuncs, "gl_texture_3d", GL_TEXTURE_3D_EXT ); | |
- | |
- if( GL_Support( GL_TEXTURE_3D_EXT )) | |
+/* | |
+=============== | |
+GL_ContextError | |
+=============== | |
+*/ | |
+static void GL_ContextError( void ) | |
{ | |
- pglGetIntegerv( GL_MAX_3D_TEXTURE_SIZE, &glConfig.max_3d_texture_size ); | |
+ DWORD error = GetLastError(); | |
- if( glConfig.max_3d_texture_size < 32 ) | |
- { | |
- GL_SetExtension( GL_TEXTURE_3D_EXT, false ); | |
- MsgDev( D_ERROR, "GL_EXT_texture3D reported bogus GL_MAX_3D_TEXTURE_SIZE, disabled\n" ); | |
- } | |
+ if( error == ( 0xc0070000|ERROR_INVALID_VERSION_ARB )) | |
+ MsgDev( D_ERROR, "Unsupported OpenGL context version (%s).\n", "2.0" ); | |
+ else if( error == ( 0xc0070000|ERROR_INVALID_PROFILE_ARB )) | |
+ MsgDev( D_ERROR, "Unsupported OpenGL profile (%s).\n", "compat" ); | |
+ else if( error == ( 0xc0070000|ERROR_INVALID_OPERATION )) | |
+ MsgDev( D_ERROR, "wglCreateContextAttribsARB returned invalid operation.\n" ); | |
+ else if( error == ( 0xc0070000|ERROR_DC_NOT_FOUND )) | |
+ MsgDev( D_ERROR, "wglCreateContextAttribsARB returned dc not found.\n" ); | |
+ else if( error == ( 0xc0070000|ERROR_INVALID_PIXEL_FORMAT )) | |
+ MsgDev( D_ERROR, "wglCreateContextAttribsARB returned dc not found.\n" ); | |
+ else if( error == ( 0xc0070000|ERROR_NO_SYSTEM_RESOURCES )) | |
+ MsgDev( D_ERROR, "wglCreateContextAttribsARB ran out of system resources.\n" ); | |
+ else if( error == ( 0xc0070000|ERROR_INVALID_PARAMETER )) | |
+ MsgDev( D_ERROR, "wglCreateContextAttribsARB reported invalid parameter.\n" ); | |
+ else MsgDev( D_ERROR, "Unknown error creating an OpenGL (%s) Context.\n", "2.0" ); | |
} | |
- GL_CheckExtension( "GL_SGIS_generate_mipmap", NULL, "gl_sgis_generate_mipmaps", GL_SGIS_MIPMAPS_EXT ); | |
- | |
- // hardware cubemaps | |
- GL_CheckExtension( "GL_ARB_texture_cube_map", NULL, "gl_texture_cubemap", GL_TEXTURECUBEMAP_EXT ); | |
- | |
- if( GL_Support( GL_TEXTURECUBEMAP_EXT )) | |
+/* | |
+================= | |
+GL_CreateContext | |
+================= | |
+*/ | |
+qboolean GL_CreateContext( void ) | |
{ | |
- pglGetIntegerv( GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &glConfig.max_cubemap_size ); | |
- | |
- // check for seamless cubemaps too | |
- GL_CheckExtension( "GL_ARB_seamless_cube_map", NULL, "gl_seamless_cubemap", GL_ARB_SEAMLESS_CUBEMAP ); | |
- } | |
- | |
- // point particles extension | |
- GL_CheckExtension( "GL_EXT_point_parameters", pointparametersfunc, NULL, GL_EXT_POINTPARAMETERS ); | |
- | |
- GL_CheckExtension( "GL_ARB_texture_non_power_of_two", NULL, "gl_texture_npot", GL_ARB_TEXTURE_NPOT_EXT ); | |
- GL_CheckExtension( "GL_ARB_texture_compression", texturecompressionfuncs, "gl_dds_hardware_support", GL_TEXTURE_COMPRESSION_EXT ); | |
- GL_CheckExtension( "GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "gl_cva_support", GL_CUSTOM_VERTEX_ARRAY_EXT ); | |
- | |
- if( !GL_Support( GL_CUSTOM_VERTEX_ARRAY_EXT )) | |
- GL_CheckExtension( "GL_SGI_compiled_vertex_array", compiledvertexarrayfuncs, "gl_cva_support", GL_CUSTOM_VERTEX_ARRAY_EXT ); | |
- | |
- GL_CheckExtension( "GL_EXT_texture_edge_clamp", NULL, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT ); | |
- | |
- if( !GL_Support( GL_CLAMPTOEDGE_EXT )) | |
- GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT ); | |
- | |
- glConfig.max_texture_anisotropy = 0.0f; | |
- GL_CheckExtension( "GL_EXT_texture_filter_anisotropic", NULL, "gl_ext_anisotropic_filter", GL_ANISOTROPY_EXT ); | |
- | |
- if( GL_Support( GL_ANISOTROPY_EXT )) | |
- pglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glConfig.max_texture_anisotropy ); | |
- | |
- GL_CheckExtension( "GL_EXT_texture_lod_bias", NULL, "gl_ext_texture_lodbias", GL_TEXTURE_LODBIAS ); | |
- if( GL_Support( GL_TEXTURE_LODBIAS )) | |
- pglGetFloatv( GL_MAX_TEXTURE_LOD_BIAS_EXT, &glConfig.max_texture_lodbias ); | |
- | |
- GL_CheckExtension( "GL_ARB_texture_border_clamp", NULL, "gl_ext_texborder_clamp", GL_CLAMP_TEXBORDER_EXT ); | |
- | |
- GL_CheckExtension( "GL_EXT_blend_minmax", blendequationfuncs, "gl_ext_customblend", GL_BLEND_MINMAX_EXT ); | |
- GL_CheckExtension( "GL_EXT_blend_subtract", blendequationfuncs, "gl_ext_customblend", GL_BLEND_SUBTRACT_EXT ); | |
- | |
- GL_CheckExtension( "glStencilOpSeparate", gl2separatestencilfuncs, "gl_separate_stencil", GL_SEPARATESTENCIL_EXT ); | |
- | |
- if( !GL_Support( GL_SEPARATESTENCIL_EXT )) | |
- GL_CheckExtension("GL_ATI_separate_stencil", atiseparatestencilfuncs, "gl_separate_stencil", GL_SEPARATESTENCIL_EXT ); | |
- | |
- GL_CheckExtension( "GL_EXT_stencil_two_side", stenciltwosidefuncs, "gl_stenciltwoside", GL_STENCILTWOSIDE_EXT ); | |
- GL_CheckExtension( "GL_ARB_vertex_buffer_object", vbofuncs, "gl_vertex_buffer_object", GL_ARB_VERTEX_BUFFER_OBJECT_EXT ); | |
- | |
- // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code | |
-#ifndef __ANDROID__ | |
- if( pglDrawRangeElementsEXT == NULL ) pglDrawRangeElementsEXT = pglDrawRangeElements; | |
-#endif | |
- GL_CheckExtension( "GL_ARB_texture_env_add", NULL, "gl_texture_env_add", GL_TEXTURE_ENV_ADD_EXT ); | |
+ HGLRC hBaseRC; | |
- // vp and fp shaders | |
- GL_CheckExtension( "GL_ARB_shader_objects", shaderobjectsfuncs, "gl_shaderobjects", GL_SHADER_OBJECTS_EXT ); | |
- GL_CheckExtension( "GL_ARB_shading_language_100", NULL, "gl_glslprogram", GL_SHADER_GLSL100_EXT ); | |
- GL_CheckExtension( "GL_ARB_vertex_shader", vertexshaderfuncs, "gl_vertexshader", GL_VERTEX_SHADER_EXT ); | |
- GL_CheckExtension( "GL_ARB_fragment_shader", NULL, "gl_pixelshader", GL_FRAGMENT_SHADER_EXT ); | |
+ if(!( glw_state.hGLRC = pwglCreateContext( glw_state.hDC ))) | |
+ return GL_DeleteContext(); | |
- GL_CheckExtension( "GL_ARB_depth_texture", NULL, "gl_depthtexture", GL_DEPTH_TEXTURE ); | |
- GL_CheckExtension( "GL_ARB_shadow", NULL, "gl_arb_shadow", GL_SHADOW_EXT ); | |
+ if(!( pwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ))) | |
+ return GL_DeleteContext(); | |
- GL_CheckExtension( "GL_ARB_texture_float", NULL, "gl_arb_texture_float", GL_ARB_TEXTURE_FLOAT_EXT ); | |
- GL_CheckExtension( "GL_ARB_depth_buffer_float", NULL, "gl_arb_depth_float", GL_ARB_DEPTH_FLOAT_EXT ); | |
+ if( !Sys_CheckParm( "-gldebug" ) || host.developer < 1 ) // debug bit the kills perfomance | |
+ return true; | |
- // occlusion queries | |
- GL_CheckExtension( "GL_ARB_occlusion_query", occlusionfunc, "gl_occlusion_queries", GL_OCCLUSION_QUERIES_EXT ); | |
+ pwglCreateContextAttribsARB = GL_GetProcAddress( "wglCreateContextAttribsARB" ); | |
- if( GL_Support( GL_SHADER_GLSL100_EXT )) | |
+ if( pwglCreateContextAttribsARB != NULL ) | |
{ | |
- pglGetIntegerv( GL_MAX_TEXTURE_COORDS_ARB, &glConfig.max_texture_coords ); | |
- pglGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &glConfig.max_teximage_units ); | |
- } | |
- else | |
+ int attribs[] = | |
{ | |
- // just get from multitexturing | |
- glConfig.max_texture_coords = glConfig.max_teximage_units = glConfig.max_texture_units; | |
- } | |
+ WGL_CONTEXT_MAJOR_VERSION_ARB, 2, | |
+ WGL_CONTEXT_MINOR_VERSION_ARB, 0, | |
+ WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, | |
+// WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, | |
+ 0 | |
+ }; | |
- // rectangle textures support | |
- if( Q_strstr( glConfig.extensions_string, "GL_NV_texture_rectangle" )) | |
+ hBaseRC = glw_state.hGLRC; // backup | |
+ glw_state.hGLRC = NULL; | |
+ | |
+ if( !( glw_state.hGLRC = pwglCreateContextAttribsARB( glw_state.hDC, NULL, attribs ))) | |
{ | |
- glConfig.texRectangle = GL_TEXTURE_RECTANGLE_NV; | |
- pglGetIntegerv( GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, &glConfig.max_2d_rectangle_size ); | |
+ glw_state.hGLRC = hBaseRC; | |
+ GL_ContextError(); | |
+ return true; // just use old context | |
} | |
-#ifndef __ANDROID__ | |
- else if( Q_strstr( glConfig.extensions_string, "GL_EXT_texture_rectangle" )) | |
+ | |
+ if(!( pwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ))) | |
{ | |
- glConfig.texRectangle = GL_TEXTURE_RECTANGLE_EXT; | |
- pglGetIntegerv( GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &glConfig.max_2d_rectangle_size ); | |
+ pwglDeleteContext( glw_state.hGLRC ); | |
+ glw_state.hGLRC = hBaseRC; | |
+ GL_ContextError(); | |
+ return true; | |
} | |
-#endif | |
- else glConfig.texRectangle = glConfig.max_2d_rectangle_size = 0; // no rectangle | |
- | |
- glConfig.max_2d_texture_size = 0; | |
- pglGetIntegerv( GL_MAX_TEXTURE_SIZE, &glConfig.max_2d_texture_size ); | |
- if( glConfig.max_2d_texture_size <= 0 ) glConfig.max_2d_texture_size = 256; | |
- | |
- Cvar_Get( "gl_max_texture_size", "0", CVAR_INIT, "opengl texture max dims" ); | |
- Cvar_Set( "gl_max_texture_size", va( "%i", glConfig.max_2d_texture_size )); | |
- | |
- pglGetIntegerv( GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &glConfig.max_vertex_uniforms ); | |
- pglGetIntegerv( GL_MAX_VERTEX_ATTRIBS_ARB, &glConfig.max_vertex_attribs ); | |
- | |
- // MCD has buffering issues | |
- if(Q_strstr( glConfig.renderer_string, "gdi" )) | |
- Cvar_SetFloat( "gl_finish", 1 ); | |
- | |
- Cvar_Set( "gl_anisotropy", va( "%f", bound( 0, gl_texture_anisotropy->value, glConfig.max_texture_anisotropy ))); | |
- | |
- // software mipmap generator does wrong result with NPOT textures ... | |
- if( !GL_Support( GL_SGIS_MIPMAPS_EXT )) | |
- GL_SetExtension( GL_ARB_TEXTURE_NPOT_EXT, false ); | |
- if( GL_Support( GL_TEXTURE_COMPRESSION_EXT )) | |
- Image_AddCmdFlags( IL_DDS_HARDWARE ); | |
- | |
- glw_state.initialized = true; | |
- | |
- tr.framecount = tr.visframecount = 1; | |
+ MsgDev( D_NOTE, "GL_CreateContext: using extended context\n" ); | |
+ pwglDeleteContext( hBaseRC ); // release first context | |
} | |
- | |
-/* | |
-================= | |
-GL_CreateContext | |
-================= | |
-*/ | |
-qboolean GL_CreateContext( void ) | |
-{ | |
-#ifdef XASH_SDL | |
- if( ( glw_state.context = SDL_GL_CreateContext( host.hWnd ) ) == NULL) | |
- { | |
- MsgDev(D_ERROR, "GL_CreateContext: %s\n", SDL_GetError()); | |
- return GL_DeleteContext(); | |
- } | |
-#endif | |
return true; | |
} | |
@@ -716,13 +753,9 @@ GL_UpdateContext | |
*/ | |
qboolean GL_UpdateContext( void ) | |
{ | |
-#ifdef XASH_SDL | |
- if(!( SDL_GL_MakeCurrent( host.hWnd, glw_state.context ) ) ) | |
- { | |
- MsgDev(D_ERROR, "GL_UpdateContext: %s", SDL_GetError()); | |
+ if(!( pwglMakeCurrent( glw_state.hDC, glw_state.hGLRC ))) | |
return GL_DeleteContext(); | |
- } | |
-#endif | |
+ | |
return true; | |
} | |
@@ -733,147 +766,117 @@ GL_DeleteContext | |
*/ | |
qboolean GL_DeleteContext( void ) | |
{ | |
-#ifdef XASH_SDL | |
- if( glw_state.context ) | |
- SDL_GL_DeleteContext(glw_state.context); | |
-#endif | |
- glw_state.context = NULL; | |
+ if( pwglMakeCurrent ) | |
+ pwglMakeCurrent( NULL, NULL ); | |
- return false; | |
-} | |
-uint num_instances; | |
-#ifdef _WIN32 | |
-BOOL CALLBACK pfnEnumWnd( HWND hwnd, LPARAM lParam ) | |
+ if( glw_state.hGLRC ) | |
{ | |
- string wndname; | |
+ if( pwglDeleteContext ) | |
+ pwglDeleteContext( glw_state.hGLRC ); | |
+ glw_state.hGLRC = NULL; | |
+ } | |
- if( GetClassName( hwnd, wndname, sizeof( wndname ) - 1 )) | |
+ if( glw_state.hDC ) | |
{ | |
- if( !Q_strcmp( wndname, WINDOW_NAME )) | |
- num_instances++; | |
+ ReleaseDC( host.hWnd, glw_state.hDC ); | |
+ glw_state.hDC = NULL; | |
} | |
- return true; | |
+ | |
+ return false; | |
} | |
-#else | |
-#ifdef XASH_X11 | |
-Window* NetClientList(Display* display, unsigned long *len) | |
+ | |
+/* | |
+================= | |
+VID_ChoosePFD | |
+================= | |
+*/ | |
+static int VID_ChoosePFD( PIXELFORMATDESCRIPTOR *pfd, int colorBits, int alphaBits, int depthBits, int stencilBits ) | |
{ | |
- Window* windowList; | |
- Atom type; | |
- int form, errno; | |
- unsigned int remain; | |
+ int pixelFormat = 0; | |
- errno = XGetWindowProperty( | |
- display, | |
- XDefaultRootWindow(display), | |
- XInternAtom(display, "_NET_CLIENT_LIST", False), | |
- 0, | |
- 65536, | |
- False, | |
- XA_WINDOW, | |
- &type, | |
- &form, | |
- len, | |
- &remain, | |
- (byte**)&windowList | |
- ); | |
+ MsgDev( D_NOTE, "VID_ChoosePFD( color %i, alpha %i, depth %i, stencil %i )\n", colorBits, alphaBits, depthBits, stencilBits ); | |
- if(errno != Success) | |
+ // Fill out the PFD | |
+ pfd->nSize = sizeof (PIXELFORMATDESCRIPTOR); | |
+ pfd->nVersion = 1; | |
+ pfd->dwFlags = PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER; | |
+ pfd->iPixelType = PFD_TYPE_RGBA; | |
+ | |
+ pfd->cColorBits = colorBits; | |
+ pfd->cRedBits = 0; | |
+ pfd->cRedShift = 0; | |
+ pfd->cGreenBits = 0; | |
+ pfd->cGreenShift = 0; | |
+ pfd->cBlueBits = 0; | |
+ pfd->cBlueShift = 0; // wow! Blue Shift %) | |
+ | |
+ pfd->cAlphaBits = alphaBits; | |
+ pfd->cAlphaShift = 0; | |
+ | |
+ pfd->cAccumBits = 0; | |
+ pfd->cAccumRedBits = 0; | |
+ pfd->cAccumGreenBits = 0; | |
+ pfd->cAccumBlueBits = 0; | |
+ pfd->cAccumAlphaBits= 0; | |
+ | |
+ pfd->cDepthBits = depthBits; | |
+ pfd->cStencilBits = stencilBits; | |
+ | |
+ pfd->cAuxBuffers = 0; | |
+ pfd->iLayerType = PFD_MAIN_PLANE; | |
+ pfd->bReserved = 0; | |
+ | |
+ pfd->dwLayerMask = 0; | |
+ pfd->dwVisibleMask = 0; | |
+ pfd->dwDamageMask = 0; | |
+ | |
+ // count PFDs | |
+ pixelFormat = ChoosePixelFormat( glw_state.hDC, pfd ); | |
+ | |
+ if( !pixelFormat ) | |
{ | |
- MsgDev(D_ERROR, "VID_EnumerateInstances: Xlib error: %s\n", strerror(errno)); | |
- return NULL; | |
+ MsgDev( D_ERROR, "VID_ChoosePFD failed\n" ); | |
+ return 0; | |
} | |
- return windowList; | |
+ | |
+ return pixelFormat; | |
} | |
-char* WindowClassName(Display* display, Window window) | |
+BOOL CALLBACK pfnEnumWnd( HWND hwnd, LPARAM lParam ) | |
{ | |
- char* className; | |
- Atom type; | |
- unsigned int len, remain; | |
- int form, errno; | |
- errno = XGetWindowProperty( | |
- display, | |
- window, | |
- XInternAtom(display, "WM_CLASS", False), | |
- 0, | |
- 65536, | |
- False, | |
- XA_WINDOW, | |
- &type, | |
- &form, | |
- &len, | |
- &remain, | |
- (byte**)&className | |
- ); | |
+ string wndname; | |
- if(errno != Success) | |
+ if( GetClassName( hwnd, wndname, sizeof( wndname ) - 1 )) | |
{ | |
- MsgDev(D_ERROR, "VID_EnumerateInstances: Xlib error: %s\n", strerror(errno)); | |
- return NULL; | |
+ if( !Q_strcmp( wndname, WINDOW_NAME )) | |
+ num_instances++; | |
} | |
- | |
- return className; | |
+ return true; | |
} | |
-#endif | |
-#endif | |
uint VID_EnumerateInstances( void ) | |
{ | |
num_instances = 0; | |
-#ifdef _WIN32 | |
if( EnumWindows( &pfnEnumWnd, 0 )) | |
return num_instances; | |
-#else | |
-#ifdef XASH_X11 | |
- Display* display = XOpenDisplay(NULL); | |
- Window* winlist; | |
- char* name; | |
- unsigned int len; | |
- int i; | |
- | |
- if(!display) | |
- { | |
- MsgDev(D_ERROR, "Lol, no displays? Returning 1 instance.\n"); | |
- return 1; | |
- } | |
- | |
- if( !(winlist = NetClientList(display, &len)) ) return 1; | |
- | |
- for(i = 0; i < len; i++) | |
- { | |
- if( !(name = WindowClassName(display, winlist[i])) ) continue; | |
- if( !Q_strcmp( name, WINDOW_NAME ) ) | |
- num_instances++; | |
- free(name); | |
- } | |
- | |
- XFree(winlist); | |
-#endif | |
-#endif | |
return 1; | |
} | |
void VID_StartupGamma( void ) | |
{ | |
- // Device supports gamma anyway, but cannot do anything with it. | |
- fs_offset_t gamma_size; | |
+ size_t gamma_size; | |
byte *savedGamma; | |
- size_t gammaTypeSize = sizeof(glState.stateRamp); | |
// init gamma ramp | |
- Q_memset( glState.stateRamp, 0, gammaTypeSize); | |
+ Q_memset( glState.stateRamp, 0, sizeof( glState.stateRamp )); | |
-#if defined(XASH_SDL) | |
- glConfig.deviceSupportsGamma = !SDL_GetWindowGammaRamp( host.hWnd, NULL, NULL, NULL); | |
-#endif | |
+ glConfig.deviceSupportsGamma = GetDeviceGammaRamp( glw_state.hDC, glState.stateRamp ); | |
if( !glConfig.deviceSupportsGamma ) | |
{ | |
// force to set cvar | |
Cvar_FullSet( "gl_ignorehwgamma", "1", CVAR_GLCONFIG ); | |
- MsgDev( D_ERROR, "VID_StartupGamma: hardware gamma unsupported\n"); | |
} | |
if( gl_ignorehwgamma->integer ) | |
@@ -889,10 +892,10 @@ void VID_StartupGamma( void ) | |
savedGamma = FS_LoadFile( "gamma.dat", &gamma_size, false ); | |
- if( !savedGamma || gamma_size != (fs_offset_t)gammaTypeSize) | |
+ if( !savedGamma || gamma_size != sizeof( glState.stateRamp )) | |
{ | |
// saved gamma not found or corrupted file | |
- FS_WriteFile( "gamma.dat", glState.stateRamp, gammaTypeSize); | |
+ FS_WriteFile( "gamma.dat", glState.stateRamp, sizeof( glState.stateRamp )); | |
MsgDev( D_NOTE, "VID_StartupGamma: gamma.dat initialized\n" ); | |
if( savedGamma ) Mem_Free( savedGamma ); | |
} | |
@@ -901,20 +904,20 @@ void VID_StartupGamma( void ) | |
GL_BuildGammaTable(); | |
// validate base gamma | |
- if( !Q_memcmp( savedGamma, glState.stateRamp, gammaTypeSize)) | |
+ if( !Q_memcmp( savedGamma, glState.stateRamp, sizeof( glState.stateRamp ))) | |
{ | |
// all ok, previous gamma is valid | |
MsgDev( D_NOTE, "VID_StartupGamma: validate screen gamma - ok\n" ); | |
} | |
- else if( !Q_memcmp( glState.gammaRamp, glState.stateRamp, gammaTypeSize)) | |
+ else if( !Q_memcmp( glState.gammaRamp, glState.stateRamp, sizeof( glState.stateRamp ))) | |
{ | |
// screen gamma is equal to render gamma (probably previous instance crashed) | |
// run additional check to make sure for it | |
- if( Q_memcmp( savedGamma, glState.stateRamp, gammaTypeSize)) | |
+ if( Q_memcmp( savedGamma, glState.stateRamp, sizeof( glState.stateRamp ))) | |
{ | |
// yes, current gamma it's totally wrong, restore it from gamma.dat | |
MsgDev( D_NOTE, "VID_StartupGamma: restore original gamma after crash\n" ); | |
- Q_memcpy( glState.stateRamp, savedGamma, gammaTypeSize); | |
+ Q_memcpy( glState.stateRamp, savedGamma, sizeof( glState.gammaRamp )); | |
} | |
else | |
{ | |
@@ -923,15 +926,15 @@ void VID_StartupGamma( void ) | |
MsgDev( D_NOTE, "VID_StartupGamma: validate screen gamma - disabled\n" ); | |
} | |
} | |
- else if( !Q_memcmp( glState.gammaRamp, savedGamma, gammaTypeSize)) | |
+ else if( !Q_memcmp( glState.gammaRamp, savedGamma, sizeof( glState.stateRamp ))) | |
{ | |
// saved gamma is equal render gamma, probably gamma.dat wroted after crash | |
// run additional check to make sure it | |
- if( Q_memcmp( savedGamma, glState.stateRamp, gammaTypeSize)) | |
+ if( Q_memcmp( savedGamma, glState.stateRamp, sizeof( glState.stateRamp ))) | |
{ | |
// yes, saved gamma it's totally wrong, get origianl gamma from screen | |
MsgDev( D_NOTE, "VID_StartupGamma: merge gamma.dat after crash\n" ); | |
- FS_WriteFile( "gamma.dat", glState.stateRamp, gammaTypeSize); | |
+ FS_WriteFile( "gamma.dat", glState.stateRamp, sizeof( glState.stateRamp )); | |
} | |
else | |
{ | |
@@ -944,7 +947,7 @@ void VID_StartupGamma( void ) | |
{ | |
// current gamma unset by other application, so we can restore it here | |
MsgDev( D_NOTE, "VID_StartupGamma: restore original gamma after crash\n" ); | |
- Q_memcpy( glState.stateRamp, savedGamma, gammaTypeSize); | |
+ Q_memcpy( glState.stateRamp, savedGamma, sizeof( glState.gammaRamp )); | |
} | |
Mem_Free( savedGamma ); | |
@@ -955,115 +958,252 @@ void VID_StartupGamma( void ) | |
void VID_RestoreGamma( void ) | |
{ | |
- if( !glConfig.deviceSupportsGamma ) | |
+ if( !glw_state.hDC || !glConfig.deviceSupportsGamma ) | |
return; | |
// don't touch gamma if multiple instances was running | |
if( VID_EnumerateInstances( ) > 1 ) return; | |
-#if defined(XASH_SDL) | |
- SDL_SetWindowGammaRamp( host.hWnd, &glState.stateRamp[0], | |
- &glState.stateRamp[256], &glState.stateRamp[512] ); | |
-#endif | |
+ SetDeviceGammaRamp( glw_state.hDC, glState.stateRamp ); | |
} | |
+/* | |
+================= | |
+GL_SetPixelformat | |
+================= | |
+*/ | |
+qboolean GL_SetPixelformat( void ) | |
+{ | |
+ PIXELFORMATDESCRIPTOR PFD; | |
+ int alphaBits; | |
+ int stencilBits; | |
+ int pixelFormat; | |
+ if(( glw_state.hDC = GetDC( host.hWnd )) == NULL ) | |
+ return false; | |
+ // set alpha/stencil | |
+ alphaBits = bound( 0, gl_alphabits->integer, 8 ); | |
+ stencilBits = bound( 0, gl_stencilbits->integer, 8 ); | |
-qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) | |
+ if( glw_state.desktopBitsPixel < 32 ) | |
{ | |
-#ifdef XASH_SDL | |
- static string wndname; | |
- Uint32 wndFlags = SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; | |
+ // clear alphabits in case we in 16-bit mode | |
+ alphaBits = 0; | |
+ } | |
- Q_strncpy( wndname, GI->title, sizeof( wndname )); | |
+ // choose a pixel format | |
+ pixelFormat = VID_ChoosePFD( &PFD, 24, alphaBits, 32, stencilBits ); | |
- host.hWnd = SDL_CreateWindow(wndname, r_xpos->integer, | |
- r_ypos->integer, width, height, wndFlags); | |
+ if( !pixelFormat ) | |
+ { | |
+ // try again with default color/depth/stencil | |
+ pixelFormat = VID_ChoosePFD( &PFD, 24, 0, 32, 0 ); | |
- if( !host.hWnd ) | |
+ if( !pixelFormat ) | |
{ | |
- MsgDev( D_ERROR, "VID_CreateWindow: couldn't create '%s': %s\n", wndname, SDL_GetError()); | |
+ MsgDev( D_ERROR, "GL_SetPixelformat: failed to find an appropriate PIXELFORMAT\n" ); | |
+ return false; | |
+ } | |
+ } | |
- // remove MSAA, if it present, because | |
- // window creating may fail on GLX visual choose | |
- if( gl_msaa->integer ) | |
+ // set the pixel format | |
+ if( !SetPixelFormat( glw_state.hDC, pixelFormat, &PFD )) | |
{ | |
- Cvar_Set("gl_msaa", "0"); | |
- GL_SetupAttributes(); // re-choose attributes | |
+ MsgDev( D_ERROR, "GL_SetPixelformat: failed\n" ); | |
+ return false; | |
+ } | |
- // try again | |
- return VID_CreateWindow( width, height, fullscreen ); | |
+ DescribePixelFormat( glw_state.hDC, pixelFormat, sizeof( PIXELFORMATDESCRIPTOR ), &PFD ); | |
+ | |
+ if( PFD.dwFlags & PFD_GENERIC_FORMAT ) | |
+ { | |
+ if( PFD.dwFlags & PFD_GENERIC_ACCELERATED ) | |
+ { | |
+ MsgDev( D_NOTE, "VID_ChoosePFD: using Generic MCD acceleration\n" ); | |
+ glw_state.software = false; | |
} | |
+ else if( gl_allow_software->integer ) | |
+ { | |
+ MsgDev( D_NOTE, "VID_ChoosePFD: using software emulation\n" ); | |
+ glw_state.software = true; | |
+ } | |
+ else | |
+ { | |
+ MsgDev( D_ERROR, "GL_SetPixelformat: no hardware acceleration found\n" ); | |
return false; | |
} | |
- | |
- if( fullscreen ) | |
+ } | |
+ else | |
{ | |
- SDL_DisplayMode want, got; | |
+ MsgDev( D_NOTE, "VID_ChoosePFD: using hardware acceleration\n"); | |
+ glw_state.software = false; | |
+ } | |
- want.w = width; | |
- want.h = height; | |
- want.driverdata = NULL; | |
- want.format = want.refresh_rate = 0; // don't care | |
+ glConfig.color_bits = PFD.cColorBits; | |
+ glConfig.alpha_bits = PFD.cAlphaBits; | |
+ glConfig.depth_bits = PFD.cDepthBits; | |
+ glConfig.stencil_bits = PFD.cStencilBits; | |
- if( !SDL_GetClosestDisplayMode(0, &want, &got) ) | |
- return false; | |
+ if( PFD.cStencilBits != 0 ) | |
+ glState.stencilEnabled = true; | |
+ else glState.stencilEnabled = false; | |
- MsgDev(D_NOTE, "Got closest display mode: %ix%i@%i\n", got.w, got.h, got.refresh_rate); | |
+ // print out PFD specifics | |
+ MsgDev( D_NOTE, "GL PFD: color( %d-bits ) alpha( %d-bits ) Z( %d-bit )\n", PFD.cColorBits, PFD.cAlphaBits, PFD.cDepthBits ); | |
- if( SDL_SetWindowDisplayMode(host.hWnd, &got) == -1 ) | |
- return false; | |
+ return true; | |
+} | |
- if( SDL_SetWindowFullscreen(host.hWnd, SDL_WINDOW_FULLSCREEN) == -1 ) | |
- return false; | |
+void R_SaveVideoMode( int vid_mode ) | |
+{ | |
+ int mode = bound( 0, vid_mode, num_vidmodes ); // check range | |
+ | |
+ glState.width = vidmode[mode].width; | |
+ glState.height = vidmode[mode].height; | |
+ glState.wideScreen = vidmode[mode].wideScreen; | |
+ Cvar_FullSet( "width", va( "%i", vidmode[mode].width ), CVAR_READ_ONLY ); | |
+ Cvar_FullSet( "height", va( "%i", vidmode[mode].height ), CVAR_READ_ONLY ); | |
+ Cvar_SetFloat( "vid_mode", mode ); // merge if it out of bounds | |
+ | |
+ MsgDev( D_NOTE, "Set: %s [%dx%d]\n", vidmode[mode].desc, vidmode[mode].width, vidmode[mode].height ); | |
} | |
- host.window_center_x = width / 2; | |
- host.window_center_y = height / 2; | |
+qboolean R_DescribeVIDMode( int width, int height ) | |
+{ | |
+ int i; | |
-#if defined(_WIN32) & !defined(__amd64__) | |
+ for( i = 0; i < sizeof( vidmode ) / sizeof( vidmode[0] ); i++ ) | |
{ | |
- HICON ico; | |
- SDL_SysWMinfo info; | |
+ if( vidmode[i].width == width && vidmode[i].height == height ) | |
+ { | |
+ // found specified mode | |
+ Cvar_SetFloat( "vid_mode", i ); | |
+ return true; | |
+ } | |
+ } | |
+ | |
+ return false; | |
+} | |
+ | |
+qboolean VID_CreateWindow( int width, int height, qboolean fullscreen ) | |
+{ | |
+ WNDCLASS wc; | |
+ RECT rect; | |
+ int x = 0, y = 0, w, h; | |
+ int stylebits = WINDOW_STYLE; | |
+ int exstyle = WINDOW_EX_STYLE; | |
+ static string wndname; | |
+ HWND window; | |
+ | |
+ Q_strncpy( wndname, GI->title, sizeof( wndname )); | |
+ // register the frame class | |
+ wc.style = CS_OWNDC|CS_NOCLOSE; | |
+ wc.lpfnWndProc = (WNDPROC)IN_WndProc; | |
+ wc.cbClsExtra = 0; | |
+ wc.cbWndExtra = 0; | |
+ wc.hInstance = host.hInst; | |
+ wc.hCursor = LoadCursor( NULL, IDC_ARROW ); | |
+ wc.hbrBackground = (void *)COLOR_3DSHADOW; | |
+ wc.lpszClassName = WINDOW_NAME; | |
+ wc.lpszMenuName = 0; | |
+ | |
+ // find the icon file in the filesystem | |
if( FS_FileExists( GI->iconpath, true ) ) | |
{ | |
char localPath[MAX_PATH]; | |
Q_snprintf( localPath, sizeof( localPath ), "%s/%s", GI->gamedir, GI->iconpath ); | |
- ico = LoadImage( NULL, localPath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE|LR_DEFAULTSIZE ); | |
+ wc.hIcon = LoadImage( NULL, localPath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE|LR_DEFAULTSIZE ); | |
- if( !ico ) | |
+ if( !wc.hIcon ) | |
{ | |
MsgDev( D_INFO, "Extract %s from pak if you want to see it.\n", GI->iconpath ); | |
- ico = LoadIcon( host.hInst, MAKEINTRESOURCE( 101 ) ); | |
+ wc.hIcon = LoadIcon( host.hInst, MAKEINTRESOURCE( 101 )); | |
} | |
} | |
- else ico = LoadIcon( host.hInst, MAKEINTRESOURCE( 101 ) ); | |
+ else wc.hIcon = LoadIcon( host.hInst, MAKEINTRESOURCE( 101 )); | |
- if( SDL_GetWindowWMInfo( host.hWnd, &info ) ) | |
+ if( !RegisterClass( &wc )) | |
{ | |
- // info.info.info.info.info... Holy shit, SDL? | |
- SetClassLong( info.info.win.window, GCL_HICON, (LONG)ico ); | |
+ MsgDev( D_ERROR, "VID_CreateWindow: couldn't register window class %s\n" WINDOW_NAME ); | |
+ return false; | |
} | |
+ | |
+ if( fullscreen ) | |
+ { | |
+ stylebits = WS_POPUP|WS_VISIBLE; | |
+ exstyle = WS_EX_TOPMOST; | |
} | |
-#endif | |
- SDL_ShowWindow( host.hWnd ); | |
-#else | |
- host.hWnd = 1; //fake window | |
- host.window_center_x = width / 2; | |
- host.window_center_y = height / 2; | |
-#endif | |
- if( !glw_state.initialized ) | |
+ rect.left = 0; | |
+ rect.top = 0; | |
+ rect.right = width; | |
+ rect.bottom = height; | |
+ | |
+ AdjustWindowRect( &rect, stylebits, FALSE ); | |
+ w = rect.right - rect.left; | |
+ h = rect.bottom - rect.top; | |
+ | |
+ if( !fullscreen ) | |
{ | |
- if( !GL_CreateContext( )) | |
+ x = r_xpos->integer; | |
+ y = r_ypos->integer; | |
+ | |
+ // adjust window coordinates if necessary | |
+ // so that the window is completely on screen | |
+ if( x < 0 ) x = 0; | |
+ if( y < 0 ) y = 0; | |
+ | |
+ if( Cvar_VariableInteger( "vid_mode" ) != glConfig.prev_mode ) | |
+ { | |
+ // adjust window in the screen size | |
+ if(( x + w > glw_state.desktopWidth ) || ( y + h > glw_state.desktopHeight )) | |
{ | |
+ x = ( glw_state.desktopWidth - w ) / 2; | |
+ y = ( glw_state.desktopHeight - h ) / 2; | |
+ } | |
+ } | |
+ } | |
+ | |
+ window = CreateWindowEx( exstyle, WINDOW_NAME, wndname, stylebits, x, y, w, h, NULL, NULL, host.hInst, NULL ); | |
+ | |
+ if( host.hWnd != window ) | |
+ { | |
+ // probably never happens | |
+ MsgDev( D_WARN, "VID_CreateWindow: bad hWnd for '%s'\n", wndname ); | |
+ } | |
+ | |
+ // host.hWnd must be filled in IN_WndProc | |
+ if( !host.hWnd ) | |
+ { | |
+ MsgDev( D_ERROR, "VID_CreateWindow: couldn't create '%s'\n", wndname ); | |
return false; | |
} | |
+ ShowWindow( host.hWnd, SW_SHOW ); | |
+ UpdateWindow( host.hWnd ); | |
+ | |
+ // init all the gl stuff for the window | |
+ if( !GL_SetPixelformat( )) | |
+ { | |
+ ShowWindow( host.hWnd, SW_HIDE ); | |
+ DestroyWindow( host.hWnd ); | |
+ host.hWnd = NULL; | |
+ | |
+ UnregisterClass( WINDOW_NAME, host.hInst ); | |
+ MsgDev( D_ERROR, "OpenGL driver not installed\n" ); | |
+ | |
+ return false; | |
+ } | |
+ | |
+ if( !glw_state.initialized ) | |
+ { | |
+ if( !GL_CreateContext( )) | |
+ return false; | |
+ | |
VID_StartupGamma(); | |
} | |
else | |
@@ -1071,115 +1211,155 @@ qboolean VID_CreateWindow( int width, in | |
if( !GL_UpdateContext( )) | |
return false; | |
} | |
+ | |
+ SetForegroundWindow( host.hWnd ); | |
+ SetFocus( host.hWnd ); | |
+ | |
return true; | |
} | |
void VID_DestroyWindow( void ) | |
{ | |
-#ifdef XASH_SDL | |
- if( glw_state.context ) | |
+ if( pwglMakeCurrent ) | |
+ pwglMakeCurrent( NULL, NULL ); | |
+ | |
+ if( glw_state.hDC ) | |
{ | |
- SDL_GL_DeleteContext( glw_state.context ); | |
- glw_state.context = NULL; | |
+ ReleaseDC( host.hWnd, glw_state.hDC ); | |
+ glw_state.hDC = NULL; | |
} | |
if( host.hWnd ) | |
{ | |
- SDL_DestroyWindow ( host.hWnd ); | |
+ DestroyWindow ( host.hWnd ); | |
host.hWnd = NULL; | |
} | |
-#endif | |
+ | |
+ UnregisterClass( WINDOW_NAME, host.hInst ); | |
+ | |
if( glState.fullScreen ) | |
{ | |
+ ChangeDisplaySettings( 0, 0 ); | |
glState.fullScreen = false; | |
} | |
} | |
- | |
-/* | |
-================== | |
-R_ChangeDisplaySettingsFast | |
- | |
-Change window size fastly to custom values, without setting vid mode | |
-================== | |
-*/ | |
-void R_ChangeDisplaySettingsFast( int width, int height ) | |
+rserr_t R_ChangeDisplaySettings( int vid_mode, qboolean fullscreen ) | |
{ | |
- //Cvar_SetFloat("vid_mode", VID_NOMODE); | |
- Cvar_SetFloat("width", width); | |
- Cvar_SetFloat("height", height); | |
+ int width, height; | |
+ int cds_result; | |
+ HDC hDC; | |
- glState.width = width; | |
- glState.height = height; | |
- if( width * 3 != height * 4 && width * 4 != height * 5 ) | |
- glState.wideScreen = true; | |
- else glState.wideScreen = false; | |
+ R_SaveVideoMode( vid_mode ); | |
- SCR_VidInit(); | |
-} | |
+ width = r_width->integer; | |
+ height = r_height->integer; | |
+ | |
+ // check our desktop attributes | |
+ hDC = GetDC( GetDesktopWindow( )); | |
+ glw_state.desktopBitsPixel = GetDeviceCaps( hDC, BITSPIXEL ); | |
+ glw_state.desktopWidth = GetDeviceCaps( hDC, HORZRES ); | |
+ glw_state.desktopHeight = GetDeviceCaps( hDC, VERTRES ); | |
+ ReleaseDC( GetDesktopWindow(), hDC ); | |
+ // destroy the existing window | |
+ if( host.hWnd ) VID_DestroyWindow(); | |
-rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) | |
+ // do a CDS if needed | |
+ if( fullscreen ) | |
{ | |
-#ifdef XASH_SDL | |
- SDL_DisplayMode displayMode; | |
+ DEVMODE dm; | |
- SDL_GetCurrentDisplayMode(0, &displayMode); | |
+ Q_memset( &dm, 0, sizeof( dm )); | |
+ dm.dmSize = sizeof( dm ); | |
+ dm.dmPelsWidth = width; | |
+ dm.dmPelsHeight = height; | |
+ dm.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT; | |
- R_SaveVideoMode( width, height ); | |
+ if( vid_displayfrequency->integer > 0 ) | |
+ { | |
+ if( vid_displayfrequency->integer < 60 ) Cvar_SetFloat( "vid_displayfrequency", 60 ); | |
+ if( vid_displayfrequency->integer > 100 ) Cvar_SetFloat( "vid_displayfrequency", 100 ); | |
- // check our desktop attributes | |
- glw_state.desktopBitsPixel = SDL_BITSPERPIXEL(displayMode.format); | |
- glw_state.desktopWidth = displayMode.w; | |
- glw_state.desktopHeight = displayMode.h; | |
+ dm.dmFields |= DM_DISPLAYFREQUENCY; | |
+ dm.dmDisplayFrequency = vid_displayfrequency->integer; | |
+ } | |
- glState.fullScreen = fullscreen; | |
+ cds_result = ChangeDisplaySettings( &dm, CDS_FULLSCREEN ); | |
- // check for 4:3 or 5:4 | |
- if( width * 3 != height * 4 && width * 4 != height * 5 ) | |
- glState.wideScreen = true; | |
- else glState.wideScreen = false; | |
+ if( cds_result == DISP_CHANGE_SUCCESSFUL ) | |
+ { | |
+ glState.fullScreen = true; | |
+ if( !VID_CreateWindow( width, height, true )) | |
+ return rserr_invalid_mode; | |
+ return rserr_ok; | |
+ } | |
+ else if( cds_result == DISP_CHANGE_BADDUALVIEW ) | |
+ { | |
+ dm.dmPelsWidth = width * 2; | |
+ dm.dmPelsHeight = height; | |
+ dm.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT; | |
- if(!host.hWnd) | |
+ // our first CDS failed, so maybe we're running on some weird dual monitor system | |
+ if( ChangeDisplaySettings( &dm, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL ) | |
{ | |
- if( !VID_CreateWindow( width, height, fullscreen ) ) | |
+ ChangeDisplaySettings( 0, 0 ); | |
+ glState.fullScreen = false; | |
+ if( !VID_CreateWindow( width, height, false )) | |
return rserr_invalid_mode; | |
+ return rserr_invalid_fullscreen; | |
} | |
- else if( fullscreen ) | |
+ else | |
{ | |
- SDL_DisplayMode want, got; | |
- | |
- want.w = width; | |
- want.h = height; | |
- want.driverdata = NULL; | |
- want.format = want.refresh_rate = 0; // don't care | |
- | |
- if( !SDL_GetClosestDisplayMode(0, &want, &got) ) | |
+ if( !VID_CreateWindow( width, height, true )) | |
return rserr_invalid_mode; | |
+ glState.fullScreen = true; | |
+ return rserr_ok; | |
+ } | |
+ } | |
+ else | |
+ { | |
+ int freq_specified = 0; | |
- MsgDev(D_NOTE, "Got closest display mode: %ix%i@%i\n", got.w, got.h, got.refresh_rate); | |
- | |
- if( ( SDL_GetWindowFlags(host.hWnd) & SDL_WINDOW_FULLSCREEN ) == SDL_WINDOW_FULLSCREEN) | |
- if( SDL_SetWindowFullscreen(host.hWnd, 0) == -1 ) | |
- return rserr_invalid_fullscreen; | |
+ if( vid_displayfrequency->integer > 0 ) | |
+ { | |
+ // clear out custom frequency | |
+ freq_specified = vid_displayfrequency->integer; | |
+ Cvar_SetFloat( "vid_displayfrequency", 0.0f ); | |
+ dm.dmFields &= ~DM_DISPLAYFREQUENCY; | |
+ dm.dmDisplayFrequency = 0; | |
+ } | |
- if( SDL_SetWindowDisplayMode(host.hWnd, &got) ) | |
+ // our first CDS failed, so maybe we're running with too high displayfrequency | |
+ if( ChangeDisplaySettings( &dm, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL ) | |
+ { | |
+ ChangeDisplaySettings( 0, 0 ); | |
+ glState.fullScreen = false; | |
+ if( !VID_CreateWindow( width, height, false )) | |
return rserr_invalid_mode; | |
- | |
- if( SDL_SetWindowFullscreen(host.hWnd, SDL_WINDOW_FULLSCREEN) == -1 ) | |
return rserr_invalid_fullscreen; | |
+ } | |
+ else | |
+ { | |
+ if( !VID_CreateWindow( width, height, true )) | |
+ return rserr_invalid_mode; | |
- R_ChangeDisplaySettingsFast( got.w, got.h ); | |
+ if( freq_specified ) | |
+ MsgDev( D_ERROR, "VID_SetMode: display frequency %i Hz not supported by your display\n", freq_specified ); | |
+ glState.fullScreen = true; | |
+ return rserr_ok; | |
+ } | |
+ } | |
} | |
else | |
{ | |
- if( SDL_SetWindowFullscreen(host.hWnd, 0) ) | |
- return rserr_invalid_fullscreen; | |
- SDL_SetWindowSize(host.hWnd, width, height); | |
- R_ChangeDisplaySettingsFast( width, height ); | |
+ ChangeDisplaySettings( 0, 0 ); | |
+ glState.fullScreen = false; | |
+ if( !VID_CreateWindow( width, height, false )) | |
+ return rserr_invalid_mode; | |
} | |
-#endif // XASH_SDL | |
+ | |
return rserr_ok; | |
} | |
@@ -1192,40 +1372,36 @@ Set the described video mode | |
*/ | |
qboolean VID_SetMode( void ) | |
{ | |
-#ifdef XASH_SDL | |
- qboolean fullscreen = false; | |
- int iScreenWidth, iScreenHeight; | |
+ qboolean fullscreen; | |
rserr_t err; | |
+ gl_swapInterval->modified = true; | |
+ | |
if( vid_mode->integer == -1 ) // trying to get resolution automatically by default | |
{ | |
- SDL_DisplayMode mode; | |
- | |
- SDL_GetDesktopDisplayMode(0, &mode); | |
+ HDC hDCScreen = GetDC( NULL ); | |
+ int iScreenWidth = GetDeviceCaps( hDCScreen, HORZRES ); | |
+ int iScreenHeight = GetDeviceCaps( hDCScreen, VERTRES ); | |
- iScreenWidth = mode.w; | |
- iScreenHeight = mode.h; | |
+ ReleaseDC( NULL, hDCScreen ); | |
- Cvar_SetFloat( "fullscreen", 1 ); | |
- } | |
- else if( vid_mode->modified && vid_mode->integer >= 0 && vid_mode->integer <= num_vidmodes ) | |
+ if( R_DescribeVIDMode( iScreenWidth, iScreenHeight )) | |
{ | |
- iScreenWidth = vidmode[vid_mode->integer].width; | |
- iScreenHeight = vidmode[vid_mode->integer].height; | |
+ MsgDev( D_NOTE, "found specified vid mode %i [%ix%i]\n", vid_mode->integer, iScreenWidth, iScreenHeight ); | |
+ Cvar_SetFloat( "fullscreen", 1 ); | |
} | |
else | |
{ | |
- iScreenHeight = scr_height->integer; | |
- iScreenWidth = scr_width->integer; | |
+ MsgDev( D_NOTE, "failed to set specified vid mode [%ix%i]\n", iScreenWidth, iScreenHeight ); | |
+ Cvar_SetFloat( "vid_mode", VID_DEFAULTMODE ); | |
+ } | |
} | |
- gl_swapInterval->modified = true; | |
- fullscreen = Cvar_VariableInteger("fullscreen") != 0; | |
+ fullscreen = vid_fullscreen->integer; | |
- if(( err = R_ChangeDisplaySettings( iScreenWidth, iScreenHeight, fullscreen )) == rserr_ok ) | |
+ if(( err = R_ChangeDisplaySettings( vid_mode->integer, fullscreen )) == rserr_ok ) | |
{ | |
- glConfig.prev_width = iScreenWidth; | |
- glConfig.prev_height = iScreenHeight; | |
+ glConfig.prev_mode = vid_mode->integer; | |
} | |
else | |
{ | |
@@ -1233,7 +1409,7 @@ qboolean VID_SetMode( void ) | |
{ | |
Cvar_SetFloat( "fullscreen", 0 ); | |
MsgDev( D_ERROR, "VID_SetMode: fullscreen unavailable in this mode\n" ); | |
- if(( err = R_ChangeDisplaySettings( iScreenWidth, iScreenHeight, false )) == rserr_ok ) | |
+ if(( err = R_ChangeDisplaySettings( vid_mode->integer, false )) == rserr_ok ) | |
return true; | |
} | |
else if( err == rserr_invalid_mode ) | |
@@ -1243,17 +1419,46 @@ qboolean VID_SetMode( void ) | |
} | |
// try setting it back to something safe | |
- if(( err = R_ChangeDisplaySettings( glConfig.prev_width, glConfig.prev_height, false )) != rserr_ok ) | |
+ if(( err = R_ChangeDisplaySettings( glConfig.prev_mode, false )) != rserr_ok ) | |
{ | |
MsgDev( D_ERROR, "VID_SetMode: could not revert to safe mode\n" ); | |
return false; | |
} | |
} | |
-#endif | |
+ | |
return true; | |
} | |
+/* | |
+================== | |
+VID_CheckChanges | |
+check vid modes and fullscreen | |
+================== | |
+*/ | |
+void VID_CheckChanges( void ) | |
+{ | |
+ if( cl_allow_levelshots->modified ) | |
+ { | |
+ GL_FreeTexture( cls.loadingBar ); | |
+ SCR_RegisterTextures(); // reload 'lambda' image | |
+ cl_allow_levelshots->modified = false; | |
+ } | |
+ | |
+ if( renderinfo->modified ) | |
+ { | |
+ if( !VID_SetMode()) | |
+ { | |
+ // can't initialize video subsystem | |
+ Host_NewInstance( va("#%s", GI->gamefolder ), "fallback to dedicated mode\n" ); | |
+ } | |
+ else | |
+ { | |
+ renderinfo->modified = false; | |
+ SCR_VidInit(); // tell the client.dll what vid_mode has changed | |
+ } | |
+ } | |
+} | |
/* | |
================== | |
@@ -1262,14 +1467,13 @@ R_Init_OpenGL | |
*/ | |
qboolean R_Init_OpenGL( void ) | |
{ | |
- GL_SetupAttributes(); | |
-#ifdef XASH_SDL | |
- if( SDL_GL_LoadLibrary( NULL ) ) | |
- { | |
- MsgDev( D_ERROR, "Couldn't initialize OpenGL: %s\n", SDL_GetError()); | |
+ Sys_LoadLibrary( &opengl_dll ); // load opengl32.dll | |
+ | |
+ if( !opengl_dll.link ) | |
return false; | |
- } | |
-#endif | |
+ | |
+ GL_CheckExtension( "OpenGL Internal ProcAddress", wglproc_funcs, NULL, GL_WGL_PROCADDRESS ); | |
+ | |
return VID_SetMode(); | |
} | |
@@ -1286,12 +1489,506 @@ void R_Free_OpenGL( void ) | |
GL_DeleteContext (); | |
VID_DestroyWindow (); | |
-#ifdef XASH_SDL | |
- SDL_GL_UnloadLibrary (); | |
-#endif | |
+ | |
+ Sys_FreeLibrary( &opengl_dll ); | |
+ | |
// now all extensions are disabled | |
Q_memset( glConfig.extension, 0, sizeof( glConfig.extension[0] ) * GL_EXTCOUNT ); | |
glw_state.initialized = false; | |
} | |
-#endif //XASH3D_NANOGL | |
-#endif // XASH_DEDICATED | |
+ | |
+/* | |
+=============== | |
+GL_SetDefaults | |
+=============== | |
+*/ | |
+static void GL_SetDefaults( void ) | |
+{ | |
+ int i; | |
+ | |
+ pglFinish(); | |
+ | |
+ pglClearColor( 0.5f, 0.5f, 0.5f, 1.0f ); | |
+ | |
+ pglDisable( GL_DEPTH_TEST ); | |
+ pglDisable( GL_CULL_FACE ); | |
+ pglDisable( GL_SCISSOR_TEST ); | |
+ pglDepthFunc( GL_LEQUAL ); | |
+ pglDepthMask( GL_FALSE ); | |
+ | |
+ pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); | |
+ | |
+ if( glState.stencilEnabled ) | |
+ { | |
+ pglDisable( GL_STENCIL_TEST ); | |
+ pglStencilMask( ( GLuint ) ~0 ); | |
+ pglStencilFunc( GL_EQUAL, 0, ~0 ); | |
+ pglStencilOp( GL_KEEP, GL_INCR, GL_INCR ); | |
+ } | |
+ | |
+ pglPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); | |
+ pglPolygonOffset( -1.0f, -2.0f ); | |
+ | |
+ // properly disable multitexturing at startup | |
+ for( i = (MAX_TEXTURE_UNITS - 1); i > 0; i-- ) | |
+ { | |
+ if( i >= GL_MaxTextureUnits( )) | |
+ continue; | |
+ | |
+ GL_SelectTexture( i ); | |
+ pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |
+ pglDisable( GL_BLEND ); | |
+ pglDisable( GL_TEXTURE_2D ); | |
+ } | |
+ | |
+ GL_SelectTexture( 0 ); | |
+ pglDisable( GL_BLEND ); | |
+ pglDisable( GL_ALPHA_TEST ); | |
+ pglDisable( GL_POLYGON_OFFSET_FILL ); | |
+ pglAlphaFunc( GL_GREATER, 0.0f ); | |
+ pglEnable( GL_TEXTURE_2D ); | |
+ pglShadeModel( GL_FLAT ); | |
+ | |
+ pglPointSize( 1.2f ); | |
+ pglLineWidth( 1.2f ); | |
+ | |
+ GL_Cull( 0 ); | |
+ GL_FrontFace( 0 ); | |
+ | |
+ R_SetTextureParameters(); | |
+ | |
+ pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); | |
+ pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); | |
+ | |
+ pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); | |
+ pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); | |
+} | |
+ | |
+/* | |
+================= | |
+R_RenderInfo_f | |
+================= | |
+*/ | |
+void R_RenderInfo_f( void ) | |
+{ | |
+ Msg( "\n" ); | |
+ Msg( "GL_VENDOR: %s\n", glConfig.vendor_string ); | |
+ Msg( "GL_RENDERER: %s\n", glConfig.renderer_string ); | |
+ Msg( "GL_VERSION: %s\n", glConfig.version_string ); | |
+ | |
+ // don't spam about extensions | |
+ if( host.developer >= 4 ) | |
+ Msg( "GL_EXTENSIONS: %s\n", glConfig.extensions_string ); | |
+ | |
+ Msg( "GL_MAX_TEXTURE_SIZE: %i\n", glConfig.max_2d_texture_size ); | |
+ | |
+ if( GL_Support( GL_ARB_MULTITEXTURE )) | |
+ Msg( "GL_MAX_TEXTURE_UNITS_ARB: %i\n", glConfig.max_texture_units ); | |
+ if( GL_Support( GL_TEXTURECUBEMAP_EXT )) | |
+ Msg( "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB: %i\n", glConfig.max_cubemap_size ); | |
+ if( GL_Support( GL_ANISOTROPY_EXT )) | |
+ Msg( "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: %.1f\n", glConfig.max_texture_anisotropy ); | |
+ if( glConfig.texRectangle ) | |
+ Msg( "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV: %i\n", glConfig.max_2d_rectangle_size ); | |
+ if( GL_Support( GL_SHADER_GLSL100_EXT )) | |
+ { | |
+ Msg( "GL_MAX_TEXTURE_COORDS_ARB: %i\n", glConfig.max_texture_coords ); | |
+ Msg( "GL_MAX_TEXTURE_IMAGE_UNITS_ARB: %i\n", glConfig.max_teximage_units ); | |
+ Msg( "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB: %i\n", glConfig.max_vertex_uniforms ); | |
+ Msg( "GL_MAX_VERTEX_ATTRIBS_ARB: %i\n", glConfig.max_vertex_attribs ); | |
+ } | |
+ | |
+ Msg( "\n" ); | |
+ Msg( "MODE: %i, %i x %i %s\n", vid_mode->integer, r_width->integer, r_height->integer ); | |
+ Msg( "GAMMA: %s\n", (glConfig.deviceSupportsGamma) ? "hardware" : "software" ); | |
+ Msg( "\n" ); | |
+ Msg( "PICMIP: %i\n", gl_picmip->integer ); | |
+ Msg( "SKYMIP: %i\n", gl_skymip->integer ); | |
+ Msg( "TEXTUREMODE: %s\n", gl_texturemode->string ); | |
+ Msg( "VERTICAL SYNC: %s\n", gl_swapInterval->integer ? "enabled" : "disabled" ); | |
+ Msg( "Color %d bits, Alpha %d bits, Depth %d bits, Stencil %d bits\n", glConfig.color_bits, | |
+ glConfig.alpha_bits, glConfig.depth_bits, glConfig.stencil_bits ); | |
+} | |
+ | |
+//======================================================================= | |
+ | |
+void GL_InitCommands( void ) | |
+{ | |
+ Cbuf_AddText( "vidlatch\n" ); | |
+ Cbuf_Execute(); | |
+ | |
+ // system screen width and height (don't suppose for change from console at all) | |
+ r_width = Cvar_Get( "width", "640", CVAR_READ_ONLY, "screen width" ); | |
+ r_height = Cvar_Get( "height", "480", CVAR_READ_ONLY, "screen height" ); | |
+ renderinfo = Cvar_Get( "@renderinfo", "0", CVAR_READ_ONLY, "" ); // use ->modified value only | |
+ r_speeds = Cvar_Get( "r_speeds", "0", CVAR_ARCHIVE, "shows renderer speeds" ); | |
+ r_fullbright = Cvar_Get( "r_fullbright", "0", CVAR_CHEAT, "disable lightmaps, get fullbright for entities" ); | |
+ r_norefresh = Cvar_Get( "r_norefresh", "0", 0, "disable 3D rendering (use with caution)" ); | |
+ r_lighting_extended = Cvar_Get( "r_lighting_extended", "1", CVAR_ARCHIVE, "allow to get lighting from world and bmodels" ); | |
+ r_lighting_modulate = Cvar_Get( "r_lighting_modulate", "0.6", CVAR_ARCHIVE, "lightstyles modulate scale" ); | |
+ r_lighting_ambient = Cvar_Get( "r_lighting_ambient", "0.3", CVAR_ARCHIVE, "map ambient lighting scale" ); | |
+ r_adjust_fov = Cvar_Get( "r_adjust_fov", "1", CVAR_ARCHIVE, "making FOV adjustment for wide-screens" ); | |
+ r_novis = Cvar_Get( "r_novis", "0", 0, "ignore vis information (perfomance test)" ); | |
+ r_nocull = Cvar_Get( "r_nocull", "0", 0, "ignore frustrum culling (perfomance test)" ); | |
+ r_faceplanecull = Cvar_Get( "r_faceplanecull", "1", 0, "ignore face plane culling (perfomance test)" ); | |
+ r_detailtextures = Cvar_Get( "r_detailtextures", "1", CVAR_ARCHIVE, "enable detail textures support, use \"2\" for auto-generate mapname_detail.txt" ); | |
+ r_lockpvs = Cvar_Get( "r_lockpvs", "0", CVAR_CHEAT, "lockpvs area at current point (pvs test)" ); | |
+ r_lockcull = Cvar_Get( "r_lockcull", "0", CVAR_CHEAT, "lock frustrum area at current point (cull test)" ); | |
+ r_dynamic = Cvar_Get( "r_dynamic", "1", CVAR_ARCHIVE, "allow dynamic lighting (dlights, lightstyles)" ); | |
+ r_lightmap = Cvar_Get( "r_lightmap", "0", CVAR_CHEAT, "lightmap debugging tool" ); | |
+ r_fastsky = Cvar_Get( "r_fastsky", "0", CVAR_ARCHIVE, "enable algorhytm fo fast sky rendering (for old machines)" ); | |
+ r_drawentities = Cvar_Get( "r_drawentities", "1", CVAR_CHEAT|CVAR_ARCHIVE, "render entities" ); | |
+ r_flaresize = Cvar_Get( "r_flaresize", "200", CVAR_ARCHIVE, "set flares size" ); | |
+ r_lefthand = Cvar_Get( "hand", "0", CVAR_ARCHIVE, "viewmodel handedness" ); | |
+ r_decals = Cvar_Get( "r_decals", "4096", CVAR_ARCHIVE, "sets the maximum number of decals" ); | |
+ r_xpos = Cvar_Get( "r_xpos", "130", CVAR_GLCONFIG, "window position by horizontal" ); | |
+ r_ypos = Cvar_Get( "r_ypos", "48", CVAR_GLCONFIG, "window position by vertical" ); | |
+ | |
+ gl_picmip = Cvar_Get( "gl_picmip", "0", CVAR_GLCONFIG, "reduces resolution of textures by powers of 2" ); | |
+ gl_skymip = Cvar_Get( "gl_skymip", "0", CVAR_GLCONFIG, "reduces resolution of skybox textures by powers of 2" ); | |
+ gl_ignorehwgamma = Cvar_Get( "gl_ignorehwgamma", "0", CVAR_GLCONFIG, "ignore hardware gamma" ); | |
+ gl_allow_software = Cvar_Get( "gl_allow_software", "0", CVAR_ARCHIVE, "allow OpenGL software emulation" ); | |
+ gl_alphabits = Cvar_Get( "gl_alphabits", "8", CVAR_GLCONFIG, "pixelformat alpha bits (0 - auto)" ); | |
+ gl_texturemode = Cvar_Get( "gl_texturemode", "GL_LINEAR_MIPMAP_LINEAR", CVAR_ARCHIVE, "texture filter" ); | |
+ gl_round_down = Cvar_Get( "gl_round_down", "0", CVAR_GLCONFIG, "down size non-power of two textures" ); | |
+ gl_max_size = Cvar_Get( "gl_max_size", "512", CVAR_ARCHIVE, "no effect in Xash3D just a legacy" ); | |
+ gl_stencilbits = Cvar_Get( "gl_stencilbits", "8", CVAR_GLCONFIG, "pixelformat stencil bits (0 - auto)" ); | |
+ gl_check_errors = Cvar_Get( "gl_check_errors", "1", CVAR_ARCHIVE, "ignore video engine errors" ); | |
+ gl_swapInterval = Cvar_Get( "gl_swapInterval", "0", CVAR_ARCHIVE, "time beetween frames (in msec)" ); | |
+ gl_extensions = Cvar_Get( "gl_extensions", "1", CVAR_GLCONFIG, "allow gl_extensions" ); | |
+ gl_detailscale = Cvar_Get( "gl_detailscale", "4.0", CVAR_ARCHIVE, "default scale applies while auto-generate list of detail textures" ); | |
+ gl_texture_anisotropy = Cvar_Get( "gl_anisotropy", "2.0", CVAR_ARCHIVE, "textures anisotropic filter" ); | |
+ gl_texture_lodbias = Cvar_Get( "gl_texture_lodbias", "0.0", CVAR_ARCHIVE, "LOD bias for mipmapped textures" ); | |
+ gl_compress_textures = Cvar_Get( "gl_compress_textures", "0", CVAR_GLCONFIG, "compress textures to safe video memory" ); | |
+ gl_luminance_textures = Cvar_Get( "gl_luminance_textures", "0", CVAR_GLCONFIG, "force all textures to luminance" ); | |
+ gl_compensate_gamma_screenshots = Cvar_Get( "gl_compensate_gamma_screenshots", "0", CVAR_ARCHIVE, "allow to apply gamma value for screenshots and snapshots" ); | |
+ gl_keeptjunctions = Cvar_Get( "gl_keeptjunctions", "1", CVAR_ARCHIVE, "disable to reduce vertexes count but removing tjuncs causes blinking pixels" ); | |
+ gl_allow_static = Cvar_Get( "gl_allow_static", "0", CVAR_ARCHIVE, "force to drawing non-moveable brushes as part of world (save FPS)" ); | |
+ gl_allow_mirrors = Cvar_Get( "gl_allow_mirrors", "1", CVAR_ARCHIVE, "allow to draw mirror surfaces" ); | |
+ gl_showtextures = Cvar_Get( "r_showtextures", "0", CVAR_CHEAT, "show all uploaded textures (type values from 1 to 13)" ); | |
+ gl_finish = Cvar_Get( "gl_finish", "0", CVAR_ARCHIVE, "use glFinish instead of glFlush" ); | |
+ gl_nosort = Cvar_Get( "gl_nosort", "0", CVAR_ARCHIVE, "disable sorting of translucent surfaces" ); | |
+ gl_clear = Cvar_Get( "gl_clear", "0", CVAR_ARCHIVE, "clearing screen after each frame" ); | |
+ gl_test = Cvar_Get( "gl_test", "0", 0, "engine developer cvar for quick testing new features" ); | |
+ gl_wireframe = Cvar_Get( "gl_wireframe", "0", 0, "show wireframe overlay" ); | |
+ gl_overview = Cvar_Get( "dev_overview", "0", 0, "show level overview" ); | |
+ | |
+ // these cvar not used by engine but some mods requires this | |
+ Cvar_Get( "gl_polyoffset", "-0.1", 0, "polygon offset for decals" ); | |
+ | |
+ // make sure r_swapinterval is checked after vid_restart | |
+ gl_swapInterval->modified = true; | |
+ | |
+ vid_gamma = Cvar_Get( "gamma", "1.0", CVAR_ARCHIVE, "gamma amount" ); | |
+ vid_texgamma = Cvar_Get( "texgamma", "2.2", CVAR_GLCONFIG, "texgamma amount (default Half-Life artwork gamma)" ); | |
+ vid_mode = Cvar_Get( "vid_mode", VID_AUTOMODE, CVAR_RENDERINFO, "display resolution mode" ); | |
+ vid_fullscreen = Cvar_Get( "fullscreen", "0", CVAR_RENDERINFO, "set in 1 to enable fullscreen mode" ); | |
+ vid_displayfrequency = Cvar_Get ( "vid_displayfrequency", "0", CVAR_RENDERINFO, "fullscreen refresh rate" ); | |
+ | |
+ Cmd_AddCommand( "r_info", R_RenderInfo_f, "display renderer info" ); | |
+ Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" ); | |
+} | |
+ | |
+void GL_RemoveCommands( void ) | |
+{ | |
+ Cmd_RemoveCommand( "r_info"); | |
+ Cmd_RemoveCommand( "texturelist" ); | |
+} | |
+ | |
+void GL_InitExtensions( void ) | |
+{ | |
+ // initialize gl extensions | |
+ GL_CheckExtension( "OpenGL 1.1.0", opengl_110funcs, NULL, GL_OPENGL_110 ); | |
+ | |
+ // get our various GL strings | |
+ glConfig.vendor_string = pglGetString( GL_VENDOR ); | |
+ glConfig.renderer_string = pglGetString( GL_RENDERER ); | |
+ glConfig.version_string = pglGetString( GL_VERSION ); | |
+ glConfig.extensions_string = pglGetString( GL_EXTENSIONS ); | |
+ MsgDev( D_INFO, "Video: %s\n", glConfig.renderer_string ); | |
+ | |
+ // initalize until base opengl functions loaded | |
+ GL_CheckExtension( "WGL_EXT_swap_control", wglswapintervalfuncs, NULL, GL_WGL_SWAPCONTROL ); | |
+ | |
+ GL_CheckExtension( "glDrawRangeElements", drawrangeelementsfuncs, "gl_drawrangeelments", GL_DRAW_RANGEELEMENTS_EXT ); | |
+ | |
+ if( !GL_Support( GL_DRAW_RANGEELEMENTS_EXT )) | |
+ GL_CheckExtension( "GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "gl_drawrangeelments", GL_DRAW_RANGEELEMENTS_EXT ); | |
+ | |
+ // multitexture | |
+ glConfig.max_texture_units = glConfig.max_texture_coords = glConfig.max_teximage_units = 1; | |
+ GL_CheckExtension( "GL_ARB_multitexture", multitexturefuncs, "gl_arb_multitexture", GL_ARB_MULTITEXTURE ); | |
+ | |
+ if( GL_Support( GL_ARB_MULTITEXTURE )) | |
+ { | |
+ pglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &glConfig.max_texture_units ); | |
+ GL_CheckExtension( "GL_ARB_texture_env_combine", NULL, "gl_texture_env_combine", GL_ENV_COMBINE_EXT ); | |
+ | |
+ if( !GL_Support( GL_ENV_COMBINE_EXT )) | |
+ GL_CheckExtension( "GL_EXT_texture_env_combine", NULL, "gl_texture_env_combine", GL_ENV_COMBINE_EXT ); | |
+ | |
+ if( GL_Support( GL_ENV_COMBINE_EXT )) | |
+ GL_CheckExtension( "GL_ARB_texture_env_dot3", NULL, "gl_texture_env_dot3", GL_DOT3_ARB_EXT ); | |
+ } | |
+ else | |
+ { | |
+ GL_CheckExtension( "GL_SGIS_multitexture", sgis_multitexturefuncs, "gl_sgis_multitexture", GL_ARB_MULTITEXTURE ); | |
+ if( GL_Support( GL_ARB_MULTITEXTURE )) glConfig.max_texture_units = 2; | |
+ } | |
+ | |
+ if( glConfig.max_texture_units == 1 ) | |
+ GL_SetExtension( GL_ARB_MULTITEXTURE, false ); | |
+ | |
+ // 3d texture support | |
+ GL_CheckExtension( "GL_EXT_texture3D", texture3dextfuncs, "gl_texture_3d", GL_TEXTURE_3D_EXT ); | |
+ | |
+ if( GL_Support( GL_TEXTURE_3D_EXT )) | |
+ { | |
+ pglGetIntegerv( GL_MAX_3D_TEXTURE_SIZE, &glConfig.max_3d_texture_size ); | |
+ | |
+ if( glConfig.max_3d_texture_size < 32 ) | |
+ { | |
+ GL_SetExtension( GL_TEXTURE_3D_EXT, false ); | |
+ MsgDev( D_ERROR, "GL_EXT_texture3D reported bogus GL_MAX_3D_TEXTURE_SIZE, disabled\n" ); | |
+ } | |
+ } | |
+ | |
+ GL_CheckExtension( "GL_SGIS_generate_mipmap", NULL, "gl_sgis_generate_mipmaps", GL_SGIS_MIPMAPS_EXT ); | |
+ | |
+ // hardware cubemaps | |
+ GL_CheckExtension( "GL_ARB_texture_cube_map", NULL, "gl_texture_cubemap", GL_TEXTURECUBEMAP_EXT ); | |
+ | |
+ if( GL_Support( GL_TEXTURECUBEMAP_EXT )) | |
+ { | |
+ pglGetIntegerv( GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &glConfig.max_cubemap_size ); | |
+ | |
+ // check for seamless cubemaps too | |
+ GL_CheckExtension( "GL_ARB_seamless_cube_map", NULL, "gl_seamless_cubemap", GL_ARB_SEAMLESS_CUBEMAP ); | |
+ } | |
+ | |
+ // point particles extension | |
+ GL_CheckExtension( "GL_EXT_point_parameters", pointparametersfunc, NULL, GL_EXT_POINTPARAMETERS ); | |
+ | |
+ GL_CheckExtension( "GL_ARB_texture_non_power_of_two", NULL, "gl_texture_npot", GL_ARB_TEXTURE_NPOT_EXT ); | |
+ GL_CheckExtension( "GL_ARB_texture_compression", texturecompressionfuncs, "gl_dds_hardware_support", GL_TEXTURE_COMPRESSION_EXT ); | |
+ GL_CheckExtension( "GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "gl_cva_support", GL_CUSTOM_VERTEX_ARRAY_EXT ); | |
+ | |
+ if( !GL_Support( GL_CUSTOM_VERTEX_ARRAY_EXT )) | |
+ GL_CheckExtension( "GL_SGI_compiled_vertex_array", compiledvertexarrayfuncs, "gl_cva_support", GL_CUSTOM_VERTEX_ARRAY_EXT ); | |
+ | |
+ GL_CheckExtension( "GL_EXT_texture_edge_clamp", NULL, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT ); | |
+ | |
+ if( !GL_Support( GL_CLAMPTOEDGE_EXT )) | |
+ GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT ); | |
+ | |
+ glConfig.max_texture_anisotropy = 0.0f; | |
+ GL_CheckExtension( "GL_EXT_texture_filter_anisotropic", NULL, "gl_ext_anisotropic_filter", GL_ANISOTROPY_EXT ); | |
+ | |
+ if( GL_Support( GL_ANISOTROPY_EXT )) | |
+ pglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glConfig.max_texture_anisotropy ); | |
+ | |
+ GL_CheckExtension( "GL_EXT_texture_lod_bias", NULL, "gl_ext_texture_lodbias", GL_TEXTURE_LODBIAS ); | |
+ if( GL_Support( GL_TEXTURE_LODBIAS )) | |
+ pglGetFloatv( GL_MAX_TEXTURE_LOD_BIAS_EXT, &glConfig.max_texture_lodbias ); | |
+ | |
+ GL_CheckExtension( "GL_ARB_texture_border_clamp", NULL, "gl_ext_texborder_clamp", GL_CLAMP_TEXBORDER_EXT ); | |
+ | |
+ GL_CheckExtension( "GL_EXT_blend_minmax", blendequationfuncs, "gl_ext_customblend", GL_BLEND_MINMAX_EXT ); | |
+ GL_CheckExtension( "GL_EXT_blend_subtract", blendequationfuncs, "gl_ext_customblend", GL_BLEND_SUBTRACT_EXT ); | |
+ | |
+ GL_CheckExtension( "glStencilOpSeparate", gl2separatestencilfuncs, "gl_separate_stencil", GL_SEPARATESTENCIL_EXT ); | |
+ | |
+ if( !GL_Support( GL_SEPARATESTENCIL_EXT )) | |
+ GL_CheckExtension("GL_ATI_separate_stencil", atiseparatestencilfuncs, "gl_separate_stencil", GL_SEPARATESTENCIL_EXT ); | |
+ | |
+ GL_CheckExtension( "GL_EXT_stencil_two_side", stenciltwosidefuncs, "gl_stenciltwoside", GL_STENCILTWOSIDE_EXT ); | |
+ GL_CheckExtension( "GL_ARB_vertex_buffer_object", vbofuncs, "gl_vertex_buffer_object", GL_ARB_VERTEX_BUFFER_OBJECT_EXT ); | |
+ | |
+ // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code | |
+ if( pglDrawRangeElementsEXT == NULL ) pglDrawRangeElementsEXT = pglDrawRangeElements; | |
+ | |
+ GL_CheckExtension( "GL_ARB_texture_env_add", NULL, "gl_texture_env_add", GL_TEXTURE_ENV_ADD_EXT ); | |
+ | |
+ // vp and fp shaders | |
+ GL_CheckExtension( "GL_ARB_shader_objects", shaderobjectsfuncs, "gl_shaderobjects", GL_SHADER_OBJECTS_EXT ); | |
+ GL_CheckExtension( "GL_ARB_shading_language_100", NULL, "gl_glslprogram", GL_SHADER_GLSL100_EXT ); | |
+ GL_CheckExtension( "GL_ARB_vertex_shader", vertexshaderfuncs, "gl_vertexshader", GL_VERTEX_SHADER_EXT ); | |
+ GL_CheckExtension( "GL_ARB_fragment_shader", NULL, "gl_pixelshader", GL_FRAGMENT_SHADER_EXT ); | |
+ | |
+ GL_CheckExtension( "GL_ARB_depth_texture", NULL, "gl_depthtexture", GL_DEPTH_TEXTURE ); | |
+ GL_CheckExtension( "GL_ARB_shadow", NULL, "gl_arb_shadow", GL_SHADOW_EXT ); | |
+ | |
+ GL_CheckExtension( "GL_ARB_texture_float", NULL, "gl_arb_texture_float", GL_ARB_TEXTURE_FLOAT_EXT ); | |
+ GL_CheckExtension( "GL_ARB_depth_buffer_float", NULL, "gl_arb_depth_float", GL_ARB_DEPTH_FLOAT_EXT ); | |
+ | |
+ // occlusion queries | |
+ GL_CheckExtension( "GL_ARB_occlusion_query", occlusionfunc, "gl_occlusion_queries", GL_OCCLUSION_QUERIES_EXT ); | |
+ | |
+ if( GL_Support( GL_SHADER_GLSL100_EXT )) | |
+ { | |
+ pglGetIntegerv( GL_MAX_TEXTURE_COORDS_ARB, &glConfig.max_texture_coords ); | |
+ pglGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &glConfig.max_teximage_units ); | |
+ } | |
+ else | |
+ { | |
+ // just get from multitexturing | |
+ glConfig.max_texture_coords = glConfig.max_teximage_units = glConfig.max_texture_units; | |
+ } | |
+ | |
+ // rectangle textures support | |
+ if( Q_strstr( glConfig.extensions_string, "GL_NV_texture_rectangle" )) | |
+ { | |
+ glConfig.texRectangle = GL_TEXTURE_RECTANGLE_NV; | |
+ pglGetIntegerv( GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, &glConfig.max_2d_rectangle_size ); | |
+ } | |
+ else if( Q_strstr( glConfig.extensions_string, "GL_EXT_texture_rectangle" )) | |
+ { | |
+ glConfig.texRectangle = GL_TEXTURE_RECTANGLE_EXT; | |
+ pglGetIntegerv( GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &glConfig.max_2d_rectangle_size ); | |
+ } | |
+ else glConfig.texRectangle = glConfig.max_2d_rectangle_size = 0; // no rectangle | |
+ | |
+ glConfig.max_2d_texture_size = 0; | |
+ pglGetIntegerv( GL_MAX_TEXTURE_SIZE, &glConfig.max_2d_texture_size ); | |
+ if( glConfig.max_2d_texture_size <= 0 ) glConfig.max_2d_texture_size = 256; | |
+ | |
+ Cvar_Get( "gl_max_texture_size", "0", CVAR_INIT, "opengl texture max dims" ); | |
+ Cvar_Set( "gl_max_texture_size", va( "%i", glConfig.max_2d_texture_size )); | |
+ | |
+ pglGetIntegerv( GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &glConfig.max_vertex_uniforms ); | |
+ pglGetIntegerv( GL_MAX_VERTEX_ATTRIBS_ARB, &glConfig.max_vertex_attribs ); | |
+ | |
+ // MCD has buffering issues | |
+ if(Q_strstr( glConfig.renderer_string, "gdi" )) | |
+ Cvar_SetFloat( "gl_finish", 1 ); | |
+ | |
+ Cvar_Set( "gl_anisotropy", va( "%f", bound( 0, gl_texture_anisotropy->value, glConfig.max_texture_anisotropy ))); | |
+ | |
+ // software mipmap generator does wrong result with NPOT textures ... | |
+ if( !GL_Support( GL_SGIS_MIPMAPS_EXT )) | |
+ GL_SetExtension( GL_ARB_TEXTURE_NPOT_EXT, false ); | |
+ | |
+ if( GL_Support( GL_TEXTURE_COMPRESSION_EXT )) | |
+ Image_AddCmdFlags( IL_DDS_HARDWARE ); | |
+ | |
+ glw_state.initialized = true; | |
+ | |
+ tr.framecount = tr.visframecount = 1; | |
+} | |
+ | |
+/* | |
+=============== | |
+R_Init | |
+=============== | |
+*/ | |
+qboolean R_Init( void ) | |
+{ | |
+ if( glw_state.initialized ) | |
+ return true; | |
+ | |
+ // give initial OpenGL configuration | |
+ Cbuf_AddText( "exec opengl.cfg\n" ); | |
+ | |
+ GL_InitCommands(); | |
+ GL_SetDefaultState(); | |
+ | |
+ // create the window and set up the context | |
+ if( !R_Init_OpenGL( )) | |
+ { | |
+ GL_RemoveCommands(); | |
+ R_Free_OpenGL(); | |
+ | |
+ // can't initialize video subsystem | |
+ Host_NewInstance( va("#%s", GI->gamefolder ), "fallback to dedicated mode\n" ); | |
+ return false; | |
+ } | |
+ | |
+ renderinfo->modified = false; | |
+ r_temppool = Mem_AllocPool( "Render Zone" ); | |
+ | |
+ GL_InitExtensions(); | |
+ GL_SetDefaults(); | |
+ R_InitImages(); | |
+ R_SpriteInit(); | |
+ R_StudioInit(); | |
+ R_ClearDecals(); | |
+ R_ClearScene(); | |
+ | |
+ // initialize screen | |
+ SCR_Init(); | |
+ | |
+ return true; | |
+} | |
+ | |
+/* | |
+=============== | |
+R_Shutdown | |
+=============== | |
+*/ | |
+void R_Shutdown( void ) | |
+{ | |
+ int i; | |
+ | |
+ if( !glw_state.initialized ) | |
+ return; | |
+ | |
+ // release SpriteTextures | |
+ for( i = 1; i < MAX_IMAGES; i++ ) | |
+ { | |
+ if( !clgame.sprites[i].name[0] ) continue; | |
+ Mod_UnloadSpriteModel( &clgame.sprites[i] ); | |
+ } | |
+ Q_memset( clgame.sprites, 0, sizeof( clgame.sprites )); | |
+ | |
+ GL_RemoveCommands(); | |
+ R_ShutdownImages(); | |
+ | |
+ Mem_FreePool( &r_temppool ); | |
+ | |
+ // shut down OS specific OpenGL stuff like contexts, etc. | |
+ R_Free_OpenGL(); | |
+} | |
+ | |
+/* | |
+================= | |
+GL_CheckForErrors | |
+================= | |
+*/ | |
+void GL_CheckForErrors_( const char *filename, const int fileline ) | |
+{ | |
+ int err; | |
+ char *str; | |
+ | |
+ if( !gl_check_errors->integer ) | |
+ return; | |
+ | |
+ if(( err = pglGetError( )) == GL_NO_ERROR ) | |
+ return; | |
+ | |
+ switch( err ) | |
+ { | |
+ case GL_STACK_OVERFLOW: | |
+ str = "GL_STACK_OVERFLOW"; | |
+ break; | |
+ case GL_STACK_UNDERFLOW: | |
+ str = "GL_STACK_UNDERFLOW"; | |
+ break; | |
+ case GL_INVALID_ENUM: | |
+ str = "GL_INVALID_ENUM"; | |
+ break; | |
+ case GL_INVALID_VALUE: | |
+ str = "GL_INVALID_VALUE"; | |
+ break; | |
+ case GL_INVALID_OPERATION: | |
+ str = "GL_INVALID_OPERATION"; | |
+ break; | |
+ case GL_OUT_OF_MEMORY: | |
+ str = "GL_OUT_OF_MEMORY"; | |
+ break; | |
+ default: | |
+ str = "UNKNOWN ERROR"; | |
+ break; | |
+ } | |
+ | |
+ Host_Error( "GL_CheckForErrors: %s (called at %s:%i)\n", str, filename, fileline ); | |
+} | |
\ В конце файла нет новой строки | |
Только в engine/client: gl_vidnt_common.c | |
Только в engine/client: gl_vidnt.h | |
Только в engine/client: gl_vidnt_nanogl.c | |
diff --suppress-blank-empty -prudwEZbB engine/client/gl_warp.c /mnt/data/Xash3D_original/engine/client/gl_warp.c | |
--- engine/client/gl_warp.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/gl_warp.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
@@ -67,12 +65,12 @@ float r_turbsin[] = | |
static qboolean CheckSkybox( const char *name ) | |
{ | |
- const char *skybox_ext[] = { "dds", "tga", "bmp" }; | |
+ const char *skybox_ext[3] = { "dds", "tga", "bmp" }; | |
int i, j, num_checked_sides; | |
const char *sidename; | |
// search for skybox images | |
- for( i = 0; i < sizeof( skybox_ext ) / sizeof( skybox_ext[0] ); i++ ) | |
+ for( i = 0; i < 3; i++ ) | |
{ | |
num_checked_sides = 0; | |
for( j = 0; j < 6; j++ ) | |
@@ -129,8 +127,6 @@ void DrawSkyPolygon( int nump, vec3_t ve | |
j = vec_to_st[axis][2]; | |
dv = (j > 0) ? vecs[j-1] : -vecs[-j-1]; | |
- if( dv == 0 ) continue; | |
- | |
j = vec_to_st[axis][0]; | |
s = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv; | |
@@ -307,7 +303,6 @@ void R_AddSkyBoxSurface( msurface_t *fa | |
vec3_t verts[MAX_CLIP_VERTS]; | |
glpoly_t *p; | |
int i; | |
- float *verts_p; | |
if( r_fastsky->integer ) | |
return; | |
@@ -323,10 +318,10 @@ void R_AddSkyBoxSurface( msurface_t *fa | |
} | |
// calculate vertex values for sky box | |
- for( p = fa->polys, verts_p = (float *)p + ( ( sizeof( void* ) + sizeof( int ) ) >> 1 ); p; p = p->next ) | |
+ for( p = fa->polys; p; p = p->next ) | |
{ | |
for( i = 0; i < p->numverts; i++ ) | |
- VectorSubtract( &verts_p[VERTEXSIZE * i], RI.cullorigin, verts[i] ); | |
+ VectorSubtract( p->verts[i], RI.cullorigin, verts[i] ); | |
ClipSkyPolygon( p->numverts, verts[0], 0 ); | |
} | |
} | |
@@ -399,7 +394,7 @@ void R_DrawSkyBox( void ) | |
if( RI.skyMins[0][i] >= RI.skyMaxs[0][i] || RI.skyMins[1][i] >= RI.skyMaxs[1][i] ) | |
continue; | |
- GL_Bind( XASH_TEXTURE0, tr.skyboxTextures[r_skyTexOrder[i]] ); | |
+ GL_Bind( GL_TEXTURE0, tr.skyboxTextures[r_skyTexOrder[i]] ); | |
pglBegin( GL_QUADS ); | |
MakeSkyVec( RI.skyMins[0][i], RI.skyMins[1][i], i ); | |
@@ -480,7 +475,7 @@ R_InitSky | |
A sky texture is 256*128, with the right side being a masked overlay | |
============== | |
*/ | |
-void R_InitSky( mip_t *mt, byte *buf, texture_t *tx ) | |
+void R_InitSky( mip_t *mt, texture_t *tx ) | |
{ | |
rgbdata_t r_temp, *r_sky; | |
uint *trans, *rgba; | |
@@ -498,7 +493,7 @@ void R_InitSky( mip_t *mt, byte *buf, te | |
int size = (int)sizeof( mip_t ) + ((mt->width * mt->height * 85)>>6); | |
if( world.version >= HLBSP_VERSION ) size += sizeof( short ) + 768; | |
- r_sky = FS_LoadImage( texname, buf, size ); | |
+ r_sky = FS_LoadImage( texname, (byte *)mt, size ); | |
} | |
else | |
{ | |
@@ -507,7 +502,7 @@ void R_InitSky( mip_t *mt, byte *buf, te | |
} | |
// make sure what sky image is valid | |
- if( !r_sky || !r_sky->palette || r_sky->type != PF_INDEXED_32 || r_sky->height == 0 ) | |
+ if( !r_sky || !r_sky->palette || r_sky->type != PF_INDEXED_32 ) | |
{ | |
MsgDev( D_ERROR, "R_InitSky: unable to load sky texture %s\n", tx->name ); | |
FS_FreeImage( r_sky ); | |
@@ -688,7 +683,7 @@ void R_DrawSkyChain( msurface_t *s ) | |
msurface_t *fa; | |
GL_SetRenderMode( kRenderNormal ); | |
- GL_Bind( XASH_TEXTURE0, tr.solidskyTexture ); | |
+ GL_Bind( GL_TEXTURE0, tr.solidskyTexture ); | |
speedscale = cl.time * 8.0f; | |
speedscale -= (int)speedscale & ~127; | |
@@ -697,7 +692,7 @@ void R_DrawSkyChain( msurface_t *s ) | |
EmitSkyPolys( fa ); | |
GL_SetRenderMode( kRenderTransTexture ); | |
- GL_Bind( XASH_TEXTURE0, tr.alphaskyTexture ); | |
+ GL_Bind( GL_TEXTURE0, tr.alphaskyTexture ); | |
speedscale = cl.time * 16.0f; | |
speedscale -= (int)speedscale & ~127; | |
@@ -720,7 +715,7 @@ will have them chained together. | |
void EmitSkyLayers( msurface_t *fa ) | |
{ | |
GL_SetRenderMode( kRenderNormal ); | |
- GL_Bind( XASH_TEXTURE0, tr.solidskyTexture ); | |
+ GL_Bind( GL_TEXTURE0, tr.solidskyTexture ); | |
speedscale = cl.time * 8.0f; | |
speedscale -= (int)speedscale & ~127; | |
@@ -728,7 +723,7 @@ void EmitSkyLayers( msurface_t *fa ) | |
EmitSkyPolys( fa ); | |
GL_SetRenderMode( kRenderTransTexture ); | |
- GL_Bind( XASH_TEXTURE0, tr.alphaskyTexture ); | |
+ GL_Bind( GL_TEXTURE0, tr.alphaskyTexture ); | |
speedscale = cl.time * 16.0f; | |
speedscale -= (int)speedscale & ~127; | |
@@ -737,4 +732,3 @@ void EmitSkyLayers( msurface_t *fa ) | |
pglDisable( GL_BLEND ); | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/s_backend.c /mnt/data/Xash3D_original/engine/client/s_backend.c | |
--- engine/client/s_backend.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/s_backend.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,131 +13,363 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
-#ifndef XASH_OPENSL | |
- | |
-#include "port.h" | |
#include "common.h" | |
#include "sound.h" | |
-#ifdef XASH_SDL | |
-#include <SDL.h> | |
-#endif | |
+#include <dsound.h> | |
+ | |
+#define iDirectSoundCreate( a, b, c ) pDirectSoundCreate( a, b, c ) | |
+ | |
+static HRESULT ( _stdcall *pDirectSoundCreate)(GUID* lpGUID, LPDIRECTSOUND* lpDS, IUnknown* pUnkOuter ); | |
+ | |
+static dllfunc_t dsound_funcs[] = | |
+{ | |
+{ "DirectSoundCreate", (void **) &pDirectSoundCreate }, | |
+{ NULL, NULL } | |
+}; | |
+ | |
+dll_info_t dsound_dll = { "dsound.dll", dsound_funcs, false }; | |
+ | |
#define SAMPLE_16BIT_SHIFT 1 | |
#define SECONDARY_BUFFER_SIZE 0x10000 | |
+typedef enum | |
+{ | |
+ SIS_SUCCESS, | |
+ SIS_FAILURE, | |
+ SIS_NOTAVAIL | |
+} si_state_t; | |
+ | |
+convar_t *s_primary; | |
+ | |
+static HWND snd_hwnd; | |
+static qboolean snd_firsttime = true; | |
+static qboolean primary_format_set; | |
+ | |
/* | |
======================================================================= | |
Global variables. Must be visible to window-procedure function | |
so it can unlock and free the data block after it has been played. | |
======================================================================= | |
*/ | |
-convar_t *s_primary; | |
-convar_t *s_khz; | |
-dma_t dma; | |
+DWORD locksize; | |
+HPSTR lpData, lpData2; | |
+LPWAVEHDR lpWaveHdr; | |
+DWORD gSndBufSize; | |
+MMTIME mmstarttime; | |
+LPDIRECTSOUNDBUFFER pDSBuf, pDSPBuf; | |
+LPDIRECTSOUND pDS; | |
-//static qboolean snd_firsttime = true; | |
-//static qboolean primary_format_set; | |
+qboolean SNDDMA_InitDirect( void *hInst ); | |
+void SNDDMA_FreeSound( void ); | |
-#ifdef XASH_SDL | |
-void SDL_SoundCallback( void* userdata, Uint8* stream, int len) | |
+static const char *DSoundError( int error ) | |
{ | |
- int size = dma.samples << 1; | |
- int pos = dma.samplepos << 1; | |
- int wrapped = pos + len - size; | |
- | |
- if (wrapped < 0) { | |
- memcpy(stream, dma.buffer + pos, len); | |
- dma.samplepos += len >> 1; | |
- } else { | |
- int remaining = size - pos; | |
- memcpy(stream, dma.buffer + pos, remaining); | |
- memcpy(stream + remaining, dma.buffer, wrapped); | |
- dma.samplepos = wrapped >> 1; | |
+ switch( error ) | |
+ { | |
+ case DSERR_BUFFERLOST: | |
+ return "DSERR_BUFFERLOST"; | |
+ case DSERR_INVALIDCALL: | |
+ return "DSERR_INVALIDCALLS"; | |
+ case DSERR_INVALIDPARAM: | |
+ return "DSERR_INVALIDPARAM"; | |
+ case DSERR_PRIOLEVELNEEDED: | |
+ return "DSERR_PRIOLEVELNEEDED"; | |
} | |
+ return "Unknown Error"; | |
} | |
/* | |
================== | |
-SNDDMA_Init | |
- | |
-Try to find a sound device to mix for. | |
-Returns false if nothing is found. | |
+DS_CreateBuffers | |
================== | |
*/ | |
-qboolean SNDDMA_Init( void *hInst ) | |
+static qboolean DS_CreateBuffers( void *hInst ) | |
{ | |
- SDL_AudioSpec desired, obtained; | |
- int ret = 0; | |
+ DSBUFFERDESC dsbuf; | |
+ DSBCAPS dsbcaps; | |
+ WAVEFORMATEX pformat, format; | |
- if (SDL_WasInit(SDL_INIT_AUDIO) == 0) | |
- ret = SDL_InitSubSystem(SDL_INIT_AUDIO); | |
- if (ret == -1) { | |
- Con_Printf("Couldn't initialize SDL audio: %s\n", SDL_GetError()); | |
+ Q_memset( &format, 0, sizeof( format )); | |
+ | |
+ format.wFormatTag = WAVE_FORMAT_PCM; | |
+ format.nChannels = 2; | |
+ format.wBitsPerSample = 16; | |
+ format.nSamplesPerSec = SOUND_DMA_SPEED; | |
+ format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8; | |
+ format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign; | |
+ format.cbSize = 0; | |
+ | |
+ MsgDev( D_NOTE, "DS_CreateBuffers: initialize\n" ); | |
+ | |
+ MsgDev( D_NOTE, "DS_CreateBuffers: setting EXCLUSIVE coop level " ); | |
+ if( DS_OK != pDS->lpVtbl->SetCooperativeLevel( pDS, hInst, DSSCL_EXCLUSIVE )) | |
+ { | |
+ MsgDev( D_NOTE, "- failed\n" ); | |
+ SNDDMA_FreeSound(); | |
return false; | |
} | |
+ MsgDev( D_NOTE, "- ok\n" ); | |
- Q_memset(&desired, 0, sizeof(desired)); | |
- switch (s_khz->integer) | |
+ // get access to the primary buffer, if possible, so we can set the sound hardware format | |
+ Q_memset( &dsbuf, 0, sizeof( dsbuf )); | |
+ dsbuf.dwSize = sizeof( DSBUFFERDESC ); | |
+ dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER; | |
+ dsbuf.dwBufferBytes = 0; | |
+ dsbuf.lpwfxFormat = NULL; | |
+ | |
+ Q_memset( &dsbcaps, 0, sizeof( dsbcaps )); | |
+ dsbcaps.dwSize = sizeof( dsbcaps ); | |
+ primary_format_set = false; | |
+ | |
+ MsgDev( D_NOTE, "DS_CreateBuffers: creating primary buffer " ); | |
+ if( pDS->lpVtbl->CreateSoundBuffer( pDS, &dsbuf, &pDSPBuf, NULL ) == DS_OK ) | |
{ | |
- case 44: | |
- desired.freq = SOUND_44k; | |
- break; | |
- case 32: | |
- desired.freq = SOUND_32k; | |
- break; | |
- case 22: | |
- desired.freq = SOUND_22k; | |
- break; | |
- default: | |
- desired.freq = SOUND_11k; | |
- break; | |
+ pformat = format; | |
+ | |
+ MsgDev( D_NOTE, "- ok\n" ); | |
+ if( snd_firsttime ) | |
+ MsgDev( D_NOTE, "DS_CreateBuffers: setting primary sound format " ); | |
+ | |
+ if( pDSPBuf->lpVtbl->SetFormat( pDSPBuf, &pformat ) != DS_OK ) | |
+ { | |
+ if( snd_firsttime ) | |
+ MsgDev( D_NOTE, "- failed\n" ); | |
} | |
+ else | |
+ { | |
+ if( snd_firsttime ) | |
+ MsgDev( D_NOTE, "- ok\n" ); | |
+ primary_format_set = true; | |
+ } | |
+ } | |
+ else MsgDev( D_NOTE, "- failed\n" ); | |
- desired.format = AUDIO_S16LSB; | |
- desired.samples = 1024; | |
- desired.channels = 2; | |
- desired.callback = SDL_SoundCallback; | |
- ret = SDL_OpenAudio(&desired, &obtained); | |
- if (ret == -1) { | |
- Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError()); | |
+ if( !primary_format_set || !s_primary->integer ) | |
+ { | |
+ // create the secondary buffer we'll actually work with | |
+ Q_memset( &dsbuf, 0, sizeof( dsbuf )); | |
+ dsbuf.dwSize = sizeof( DSBUFFERDESC ); | |
+ dsbuf.dwFlags = (DSBCAPS_CTRLFREQUENCY|DSBCAPS_LOCSOFTWARE); | |
+ dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE; | |
+ dsbuf.lpwfxFormat = &format; | |
+ | |
+ Q_memset( &dsbcaps, 0, sizeof( dsbcaps )); | |
+ dsbcaps.dwSize = sizeof( dsbcaps ); | |
+ | |
+ MsgDev( D_NOTE, "DS_CreateBuffers: creating secondary buffer " ); | |
+ if( pDS->lpVtbl->CreateSoundBuffer( pDS, &dsbuf, &pDSBuf, NULL ) == DS_OK ) | |
+ { | |
+ MsgDev( D_NOTE, "- ok\n" ); | |
+ } | |
+ else | |
+ { | |
+ // couldn't get hardware, fallback to software. | |
+ dsbuf.dwFlags = (DSBCAPS_LOCSOFTWARE|DSBCAPS_GETCURRENTPOSITION2); | |
+ if( pDS->lpVtbl->CreateSoundBuffer( pDS, &dsbuf, &pDSBuf, NULL ) != DS_OK ) | |
+ { | |
+ MsgDev( D_NOTE, "- failed\n" ); | |
+ SNDDMA_FreeSound (); | |
return false; | |
} | |
+ MsgDev( D_INFO, "- failed. forced to software\n" ); | |
+ } | |
- if (obtained.format != AUDIO_S16LSB) { | |
- Con_Printf("SDL audio format %d unsupported.\n", obtained.format); | |
- goto fail; | |
+ if( pDSBuf->lpVtbl->GetCaps( pDSBuf, &dsbcaps ) != DS_OK ) | |
+ { | |
+ MsgDev( D_ERROR, "DS_CreateBuffers: GetCaps failed\n"); | |
+ SNDDMA_FreeSound (); | |
+ return false; | |
+ } | |
+ MsgDev( D_NOTE, "DS_CreateBuffers: using secondary sound buffer\n" ); | |
} | |
+ else | |
+ { | |
+ MsgDev( D_NOTE, "DS_CreateBuffers: using primary sound buffer\n" ); | |
+ MsgDev( D_NOTE, "DS_CreateBuffers: setting WRITEPRIMARY coop level " ); | |
+ if( pDS->lpVtbl->SetCooperativeLevel( pDS, hInst, DSSCL_WRITEPRIMARY ) != DS_OK ) | |
+ { | |
+ MsgDev( D_NOTE, "- failed\n" ); | |
+ SNDDMA_FreeSound (); | |
+ return false; | |
+ } | |
+ MsgDev( D_NOTE, "- ok\n" ); | |
- if (obtained.channels != 1 && obtained.channels != 2) { | |
- Con_Printf("SDL audio channels %d unsupported.\n", obtained.channels); | |
- goto fail; | |
+ if( pDSPBuf->lpVtbl->GetCaps( pDSPBuf, &dsbcaps ) != DS_OK ) | |
+ { | |
+ MsgDev( D_ERROR, "DS_CreateBuffers: GetCaps failed\n"); | |
+ SNDDMA_FreeSound (); | |
+ return false; | |
+ } | |
+ pDSBuf = pDSPBuf; | |
} | |
- dma.format.speed = obtained.freq; | |
- dma.format.channels = obtained.channels; | |
- dma.format.width = 2; | |
- dma.samples = 0x8000 * obtained.channels; | |
- dma.buffer = Z_Malloc(dma.samples * 2); | |
- dma.samplepos = 0; | |
- dma.sampleframes = dma.samples / dma.format.channels; | |
+ // make sure mixer is active | |
+ if( pDSBuf->lpVtbl->Play( pDSBuf, 0, 0, DSBPLAY_LOOPING ) != DS_OK ) | |
+ { | |
+ MsgDev( D_ERROR, "DS_CreateBuffers: looped sound play failed\n" ); | |
+ SNDDMA_FreeSound (); | |
+ return false; | |
+ } | |
- Con_Printf("Using SDL audio driver: %s @ %d Hz\n", SDL_GetCurrentAudioDriver(), obtained.freq); | |
+ // we don't want anyone to access the buffer directly w/o locking it first | |
+ lpData = NULL; | |
+ dma.samplepos = 0; | |
+ snd_hwnd = (HWND)hInst; | |
+ gSndBufSize = dsbcaps.dwBufferBytes; | |
+ dma.samples = gSndBufSize / 2; | |
+ dma.buffer = (byte *)lpData; | |
- SDL_PauseAudio(0); | |
+ SNDDMA_BeginPainting(); | |
+ if( dma.buffer ) Q_memset( dma.buffer, 0, dma.samples * 2 ); | |
+ SNDDMA_Submit(); | |
- dma.initialized = true; | |
return true; | |
+} | |
-fail: | |
- SNDDMA_Shutdown(); | |
- return false; | |
+/* | |
+================== | |
+DS_DestroyBuffers | |
+================== | |
+*/ | |
+static void DS_DestroyBuffers( void ) | |
+{ | |
+ MsgDev( D_NOTE, "DS_DestroyBuffers: shutdown\n" ); | |
+ | |
+ if( pDS ) | |
+ { | |
+ MsgDev( D_NOTE, "DS_DestroyBuffers: setting NORMAL coop level\n" ); | |
+ pDS->lpVtbl->SetCooperativeLevel( pDS, snd_hwnd, DSSCL_NORMAL ); | |
} | |
-#else | |
-qboolean SNDDMA_Init( void *hInst ) | |
+ | |
+ if( pDSBuf ) | |
+ { | |
+ MsgDev( D_NOTE, "DS_DestroyBuffers: stopping and releasing sound buffer\n" ); | |
+ pDSBuf->lpVtbl->Stop( pDSBuf ); | |
+ pDSBuf->lpVtbl->Release( pDSBuf ); | |
+ } | |
+ | |
+ // only release primary buffer if it's not also the mixing buffer we just released | |
+ if( pDSPBuf && ( pDSBuf != pDSPBuf )) | |
+ { | |
+ MsgDev( D_NOTE, "DS_DestroyBuffers: releasing primary buffer\n" ); | |
+ pDSPBuf->lpVtbl->Release( pDSPBuf ); | |
+ } | |
+ | |
+ pDSBuf = NULL; | |
+ pDSPBuf = NULL; | |
+ dma.buffer = NULL; | |
+} | |
+ | |
+/* | |
+================== | |
+SNDDMA_FreeSound | |
+================== | |
+*/ | |
+void SNDDMA_FreeSound( void ) | |
+{ | |
+ if( pDS ) | |
{ | |
+ DS_DestroyBuffers(); | |
+ pDS->lpVtbl->Release( pDS ); | |
+ Sys_FreeLibrary( &dsound_dll ); | |
+ } | |
+ | |
+ pDS = NULL; | |
+ pDSBuf = NULL; | |
+ pDSPBuf = NULL; | |
+ lpData = NULL; | |
+ lpWaveHdr = NULL; | |
+} | |
+ | |
+/* | |
+================== | |
+SNDDMA_InitDirect | |
+ | |
+Direct-Sound support | |
+================== | |
+*/ | |
+si_state_t SNDDMA_InitDirect( void *hInst ) | |
+{ | |
+ DSCAPS dscaps; | |
+ HRESULT hresult; | |
+ | |
+ if( !dsound_dll.link ) | |
+ { | |
+ if( !Sys_LoadLibrary( &dsound_dll )) | |
+ return SIS_FAILURE; | |
+ } | |
+ | |
+ MsgDev( D_NOTE, "SNDDMA_InitDirect: creating DS object " ); | |
+ if(( hresult = iDirectSoundCreate( NULL, &pDS, NULL )) != DS_OK ) | |
+ { | |
+ if( hresult != DSERR_ALLOCATED ) | |
+ { | |
+ MsgDev( D_NOTE, "- failed\n" ); | |
+ return SIS_FAILURE; | |
+ } | |
+ | |
+ MsgDev( D_NOTE, "- failed, hardware already in use\n" ); | |
+ return SIS_NOTAVAIL; | |
+ } | |
+ | |
+ MsgDev( D_NOTE, "- ok\n" ); | |
+ dscaps.dwSize = sizeof( dscaps ); | |
+ | |
+ if( pDS->lpVtbl->GetCaps( pDS, &dscaps ) != DS_OK ) | |
+ MsgDev( D_ERROR, "SNDDMA_InitDirect: GetCaps failed\n"); | |
+ | |
+ if( dscaps.dwFlags & DSCAPS_EMULDRIVER ) | |
+ { | |
+ MsgDev( D_ERROR, "SNDDMA_InitDirect: no DSound driver found\n" ); | |
+ SNDDMA_FreeSound(); | |
+ return SIS_FAILURE; | |
+ } | |
+ | |
+ if( !DS_CreateBuffers( hInst )) | |
+ return SIS_FAILURE; | |
+ | |
+ return SIS_SUCCESS; | |
+} | |
+ | |
+/* | |
+================== | |
+SNDDMA_Init | |
+ | |
+Try to find a sound device to mix for. | |
+Returns false if nothing is found. | |
+================== | |
+*/ | |
+int SNDDMA_Init( void *hInst ) | |
+{ | |
+ si_state_t stat = SIS_FAILURE; // assume DirectSound won't initialize | |
+ | |
+ // already initialized | |
+ if( dma.initialized ) return true; | |
+ | |
+ Q_memset( &dma, 0, sizeof( dma )); | |
+ | |
+ s_primary = Cvar_Get( "s_primary", "0", CVAR_INIT, "use direct primary buffer" ); | |
+ | |
+ // init DirectSound | |
+ stat = SNDDMA_InitDirect( hInst ); | |
+ | |
+ if( stat == SIS_SUCCESS ) | |
+ { | |
+ if( snd_firsttime ) | |
+ MsgDev( D_INFO, "Audio: DirectSound\n" ); | |
+ } | |
+ else | |
+ { | |
+ if( snd_firsttime ) | |
+ MsgDev( D_ERROR, "SNDDMA_Init: can't initialize sound device\n" ); | |
return false; | |
} | |
-#endif | |
+ | |
+ dma.initialized = true; | |
+ snd_firsttime = false; | |
+ return true; | |
+} | |
+ | |
/* | |
============== | |
SNDDMA_GetDMAPos | |
@@ -149,7 +381,18 @@ how many sample are required to fill it | |
*/ | |
int SNDDMA_GetDMAPos( void ) | |
{ | |
- return dma.samplepos; | |
+ int s; | |
+ MMTIME mmtime; | |
+ DWORD dwWrite; | |
+ | |
+ mmtime.wType = TIME_SAMPLES; | |
+ pDSBuf->lpVtbl->GetCurrentPosition( pDSBuf, &mmtime.u.sample, &dwWrite ); | |
+ s = mmtime.u.sample - mmstarttime.u.sample; | |
+ | |
+ s >>= SAMPLE_16BIT_SHIFT; | |
+ s &= (dma.samples - 1); | |
+ | |
+ return s; | |
} | |
/* | |
@@ -198,9 +441,42 @@ Makes sure dma.buffer is valid | |
*/ | |
void SNDDMA_BeginPainting( void ) | |
{ | |
-#ifdef XASH_SDL | |
- SDL_LockAudio(); | |
-#endif | |
+ int reps; | |
+ DWORD dwSize2; | |
+ DWORD *pbuf, *pbuf2; | |
+ HRESULT hr; | |
+ DWORD dwStatus; | |
+ | |
+ if( !pDSBuf ) return; | |
+ | |
+ // if the buffer was lost or stopped, restore it and/or restart it | |
+ if( pDSBuf->lpVtbl->GetStatus( pDSBuf, &dwStatus ) != DS_OK ) | |
+ MsgDev( D_WARN, "SNDDMA_BeginPainting: couldn't get sound buffer status\n" ); | |
+ | |
+ if( dwStatus & DSBSTATUS_BUFFERLOST ) | |
+ pDSBuf->lpVtbl->Restore( pDSBuf ); | |
+ | |
+ if( !( dwStatus & DSBSTATUS_PLAYING )) | |
+ pDSBuf->lpVtbl->Play( pDSBuf, 0, 0, DSBPLAY_LOOPING ); | |
+ | |
+ // lock the dsound buffer | |
+ dma.buffer = NULL; | |
+ reps = 0; | |
+ | |
+ while(( hr = pDSBuf->lpVtbl->Lock( pDSBuf, 0, gSndBufSize, &pbuf, &locksize, &pbuf2, &dwSize2, 0 )) != DS_OK ) | |
+ { | |
+ if( hr != DSERR_BUFFERLOST ) | |
+ { | |
+ MsgDev( D_ERROR, "SNDDMA_BeginPainting: lock error '%s'\n", DSoundError( hr )); | |
+ S_Shutdown (); | |
+ return; | |
+ } | |
+ else pDSBuf->lpVtbl->Restore( pDSBuf ); | |
+ | |
+ if( ++reps > 2 ) return; | |
+ } | |
+ | |
+ dma.buffer = (byte *)pbuf; | |
} | |
/* | |
@@ -213,9 +489,9 @@ Also unlocks the dsound buffer | |
*/ | |
void SNDDMA_Submit( void ) | |
{ | |
-#ifdef XASH_SDL | |
- SDL_UnlockAudio(); | |
-#endif | |
+ if( !dma.buffer ) return; | |
+ // unlock the dsound buffer | |
+ if( pDSBuf ) pDSBuf->lpVtbl->Unlock( pDSBuf, dma.buffer, locksize, NULL, 0 ); | |
} | |
/* | |
@@ -227,18 +503,9 @@ Reset the sound device for exiting | |
*/ | |
void SNDDMA_Shutdown( void ) | |
{ | |
- Con_Printf("Shutting down audio.\n"); | |
+ if( !dma.initialized ) return; | |
dma.initialized = false; | |
-#ifdef XASH_SDL | |
- SDL_CloseAudio(); | |
- if (SDL_WasInit(SDL_INIT_AUDIO != 0)) | |
- SDL_QuitSubSystem(SDL_INIT_AUDIO); | |
-#endif | |
- if (dma.buffer) | |
- { | |
- Mem_Free(dma.buffer); | |
- dma.buffer = NULL; | |
- } | |
+ SNDDMA_FreeSound(); | |
} | |
/* | |
@@ -248,9 +515,27 @@ S_PrintDeviceName | |
*/ | |
void S_PrintDeviceName( void ) | |
{ | |
-#ifdef XASH_SDL | |
- Msg( "Audio: SDL (driver: %s)\n", SDL_GetCurrentAudioDriver() ); | |
-#endif | |
+ Msg( "Audio: DirectSound\n" ); | |
+} | |
+ | |
+/* | |
+=========== | |
+S_Activate | |
+ | |
+Called when the main window gains or loses focus. | |
+The window have been destroyed and recreated | |
+between a deactivate and an activate. | |
+=========== | |
+*/ | |
+void S_Activate( qboolean active, void *hInst ) | |
+{ | |
+ if( !dma.initialized ) return; | |
+ snd_hwnd = (HWND)hInst; | |
+ | |
+ if( !pDS || !snd_hwnd ) | |
+ return; | |
+ | |
+ if( active ) | |
+ DS_CreateBuffers( snd_hwnd ); | |
+ else DS_DestroyBuffers(); | |
} | |
-#endif | |
-#endif // XASH_DEDICATED | |
Только в engine/client: s_backend_opensles.c | |
diff --suppress-blank-empty -prudwEZbB engine/client/s_dsp.c /mnt/data/Xash3D_original/engine/client/s_dsp.c | |
--- engine/client/s_dsp.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/s_dsp.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,931 +13,5446 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
-#include "client.h" | |
#include "sound.h" | |
+#define SIGN( d ) (( d ) < 0 ? -1 : 1 ) | |
+#define ABS( a ) abs( a ) | |
+#define MSEC_TO_SAMPS( a ) ((( a ) * SOUND_DMA_SPEED) / 1000 ) // convert milliseconds to # samples in equivalent time | |
+#define SEC_TO_SAMPS( a ) (( a ) * SOUND_DMA_SPEED) // conver seconds to # samples in equivalent time | |
+#define CLIP_DSP( x ) ( x ) | |
+#define SOUND_MS_PER_FT 1 // sound travels approx 1 foot per millisecond | |
+#define ROOM_MAX_SIZE 1000 // max size in feet of room simulation for dsp | |
-typedef struct sx_preset_s { | |
- float room_lp; // lowpass | |
- float room_mod; // modulation | |
+// Performance notes: | |
- // reverb | |
- float room_size; | |
- float room_refl; | |
- float room_rvblp; | |
+// DSP processing should take no more than 3ms total time per frame to remain on par with hl1 | |
+// Assume a min frame rate of 24fps = 42ms per frame | |
+// at 24fps, to maintain 44.1khz output rate, we must process about 1840 mono samples per frame. | |
+// So we must process 1840 samples in 3ms. | |
- // delay | |
- float room_delay; | |
- float room_feedback; | |
- float room_dlylp; | |
- float room_left; | |
-} sx_preset_t; | |
+// on a 1Ghz CPU (mid-low end CPU) 3ms provides roughly 3,000,000 cycles. | |
+// Thus we have 3e6 / 1840 = 1630 cycles per sample. | |
-typedef struct dly_s { | |
- size_t cdelaysamplesmax; // delay line array size | |
+#define PBITS 12 // parameter bits | |
+#define PMAX ((1 << PBITS)-1) // parameter max size | |
- // delay line pointers | |
- size_t idelayinput; | |
- size_t idelayoutput; | |
+// crossfade from y2 to y1 at point r (0 < r < PMAX ) | |
+#define XFADE( y1, y2, r ) (((y1) * (r)) >> PBITS) + (((y2) * (PMAX - (r))) >> PBITS); | |
+#define XFADEF( y1, y2, r ) (((y1) * (r)) / (float)(PMAX)) + (((y2) * (PMAX - (r))) / (float)(PMAX)); | |
- // crossfade | |
- size_t idelayoutputxf; // output pointer | |
- int xfade; // value | |
+///////////////////// | |
+// dsp helpers | |
+///////////////////// | |
- int delaysamples; // delay setting | |
- int delayfeedback; // feedback setting | |
+// dot two integer vectors of length M+1 | |
+// M is filter order, h is filter vector, w is filter state vector | |
+_inline int dot ( int M, int *h, int *w ) | |
+{ | |
+ int i, y; | |
- // lowpass | |
- int lp; // is lowpass enabled | |
- int lp0, lp1, lp2; // lowpass buffer | |
+ for( y = 0, i = 0; i <= M; i++ ) | |
+ y += ( h[i] * w[i] ) >> PBITS; | |
+ return y; | |
+} | |
- // modulation | |
- int mod; | |
- int modcur; | |
+// delay array w[] by D samples | |
+// w[0] = input, w[D] = output | |
+// practical for filters, but not for large values of D | |
+_inline void delay( int D, int *w ) | |
+{ | |
+ int i; | |
- // delay line | |
- int *lpdelayline; | |
-} dly_t; | |
+ for( i = D; i >= 1; i-- ) // reverse order updating | |
+ w[i] = w[i-1]; | |
+} | |
+// circular wrap of pointer p, relative to array w | |
+// D delay line size in samples w[0...D] | |
+// w delay line buffer pointer, dimension D+1 | |
+// p circular pointer | |
+_inline void wrap( int D, int *w, int **p ) | |
+{ | |
+ if( *p > w + D ) *p -= D + 1; // when *p = w + D + 1, it wraps around to *p = w | |
+ if( *p < w ) *p += D + 1; // when *p = w - 1, it wraps around to *p = w + D | |
+} | |
-const sx_preset_t rgsxpre[] = | |
+// simple averaging filter for performance - a[] is 0, b[] is 1, L is # of samples to average | |
+_inline int avg_filter( int M, int *a, int L, int *b, int *w, int x ) | |
{ | |
-// -------reverb-------- -------delay-------- | |
-// lp mod size refl rvblp delay feedback dlylp left | |
-{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 2.0, 0.0 }, // 0 off | |
-{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.065, 0.1, 0.0, 0.01 }, // 1 generic | |
-{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.02, 0.75, 0.0, 0.01 }, // 2 metalic | |
-{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.03, 0.78, 0.0, 0.02 }, // 3 | |
-{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.06, 0.77, 0.0, 0.03 }, // 4 | |
-{ 0.0, 0.0, 0.05, 0.85, 1.0, 0.008, 0.96, 2.0, 0.01 }, // 5 tunnel | |
-{ 0.0, 0.0, 0.05, 0.88, 1.0, 0.01, 0.98, 2.0, 0.02 }, // 6 | |
-{ 0.0, 0.0, 0.05, 0.92, 1.0, 0.015, 0.995, 2.0, 0.04 }, // 7 | |
-{ 0.0, 0.0, 0.05, 0.84, 1.0, 0.0, 0.0, 2.0, 0.012 }, // 8 chamber | |
-{ 0.0, 0.0, 0.05, 0.9, 1.0, 0.0, 0.0, 2.0, 0.008 }, // 9 | |
-{ 0.0, 0.0, 0.05, 0.95, 1.0, 0.0, 0.0, 2.0, 0.004 }, // 10 | |
-{ 0.0, 0.0, 0.05, 0.7, 0.0, 0.0, 0.0, 2.0, 0.012 }, // 11 brite | |
-{ 0.0, 0.0, 0.055, 0.78, 0.0, 0.0, 0.0, 2.0, 0.008 }, // 12 | |
-{ 0.0, 0.0, 0.05, 0.86, 0.0, 0.0, 0.0, 2.0, 0.002 }, // 13 | |
-{ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 2.0, 0.01 }, // 14 water | |
-{ 1.0, 0.0, 0.0, 0.0, 1.0, 0.06, 0.85, 2.0, 0.02 }, // 15 | |
-{ 1.0, 0.0, 0.0, 0.0, 1.0, 0.2, 0.6, 2.0, 0.05 }, // 16 | |
-{ 0.0, 0.0, 0.05, 0.8, 1.0, 0.0, 0.48, 2.0, 0.016 }, // 17 concrete | |
-{ 0.0, 0.0, 0.06, 0.9, 1.0, 0.0, 0.52, 2.0, 0.01 }, // 18 | |
-{ 0.0, 0.0, 0.07, 0.94, 1.0, 0.3, 0.6, 2.0, 0.008 }, // 19 | |
-{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.3, 0.42, 2.0, 0.0 }, // 20 outside | |
-{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.35, 0.48, 2.0, 0.0 }, // 21 | |
-{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.38, 0.6, 2.0, 0.0 }, // 22 | |
-{ 0.0, 0.0, 0.05, 0.9, 1.0, 0.2, 0.28, 0.0, 0.0 }, // 23 cavern | |
-{ 0.0, 0.0, 0.07, 0.9, 1.0, 0.3, 0.4, 0.0, 0.0 }, // 24 | |
-{ 0.0, 0.0, 0.09, 0.9, 1.0, 0.35, 0.5, 0.0, 0.0 }, // 25 | |
-{ 0.0, 1.0, 0.01, 0.9, 0.0, 0.0, 0.0, 2.0, 0.05 }, // 26 weirdo | |
-{ 0.0, 0.0, 0.0, 0.0, 1.0, 0.009, 0.999, 2.0, 0.04 }, // 27 | |
-{ 0.0, 0.0, 0.001, 0.999, 0.0, 0.2, 0.8, 2.0, 0.05 } // 28 | |
-}; | |
+ int i, y = 0; | |
-// cvars | |
-convar_t *dsp_off; // disable dsp | |
-convar_t *roomwater_type; // water room_type | |
-convar_t *room_type; // current room type | |
+ w[0] = x; | |
-// underwater/special fx modulations | |
-convar_t *sxmod_mod; | |
-convar_t *sxmod_lowpass; | |
+ // output adder | |
+ switch( L ) | |
+ { | |
+ default: | |
+ case 12: y += w[12]; | |
+ case 11: y += w[11]; | |
+ case 10: y += w[10]; | |
+ case 9: y += w[9]; | |
+ case 8: y += w[8]; | |
+ case 7: y += w[7]; | |
+ case 6: y += w[6]; | |
+ case 5: y += w[5]; | |
+ case 4: y += w[4]; | |
+ case 3: y += w[3]; | |
+ case 2: y += w[2]; | |
+ case 1: y += w[1]; | |
+ case 0: y += w[0]; | |
+ } | |
-// stereo delay(no feedback) | |
-convar_t *sxste_delay; // straight left delay | |
+ for( i = L; i >= 1; i-- ) // reverse update internal state | |
+ w[i] = w[i-1]; | |
-// mono reverb | |
-convar_t *sxrvb_lp; // lowpass | |
-convar_t *sxrvb_feedback; // reverb decay. Higher -- longer | |
-convar_t *sxrvb_size; // room size. Higher -- larger | |
+ switch( L ) | |
+ { | |
+ default: | |
+ case 12: return y / 13; | |
+ case 11: return y / 12; | |
+ case 10: return y / 11; | |
+ case 9: return y / 10; | |
+ case 8: return y / 9; | |
+ case 7: return y >> 3; | |
+ case 6: return y / 7; | |
+ case 5: return y / 6; | |
+ case 4: return y / 5; | |
+ case 3: return y >> 2; | |
+ case 2: return y / 3; | |
+ case 1: return y >> 1; | |
+ case 0: return y; | |
+ } | |
+} | |
-// mono delay | |
-convar_t *sxdly_lp; // lowpass | |
-convar_t *sxdly_feedback; // cycles | |
-convar_t *sxdly_delay; // current delay in seconds | |
+// IIR filter, cannonical form | |
+// returns single sample y for current input value x | |
+// x is input sample | |
+// w = internal state vector, dimension max(M,L) + 1 | |
+// L, M numerator and denominator filter orders | |
+// a,b are M+1 dimensional arrays of filter params | |
+// | |
+// for M = 4: | |
+// | |
+// 1 w0(n) b0 | |
+// x(n)--->(+)--(*)-----.------(*)->(+)---> y(n) | |
+// ^ | ^ | |
+// | [Delay d] | | |
+// | | | | |
+// | -a1 |W1 b1 | | |
+// ----(*)---.------(*)---- | |
+// ^ | ^ | |
+// | [Delay d] | | |
+// | | | | |
+// | -a2 |W2 b2 | | |
+// ----(*)---.------(*)---- | |
+// ^ | ^ | |
+// | [Delay d] | | |
+// | | | | |
+// | -a3 |W3 b3 | | |
+// ----(*)---.------(*)---- | |
+// ^ | ^ | |
+// | [Delay d] | | |
+// | | | | |
+// | -a4 |W4 b4 | | |
+// ----(*)---.------(*)---- | |
+// | |
+// for each input sample x, do: | |
+// w0 = x - a1*w1 - a2*w2 - ... aMwM | |
+// y = b0*w0 + b1*w1 + ...bL*wL | |
+// wi = wi-1, i = K, K-1, ..., 1 | |
-convar_t *dsp_room; // for compability | |
-int idsp_room; | |
-int room_typeprev; | |
+_inline int iir_filter( int M, int *a, int L, int *b, int *w, int x ) | |
+{ | |
+ int K, i, y, x0; | |
-// routines | |
-int sxamodl, sxamodr, // amplitude modulation values | |
- sxamodlt, sxamodrt; // modulation targets | |
-int sxhires, sxhiresprev; | |
-int sxmod1, sxmod2, | |
- sxmod1cur, sxmod2cur; | |
+ if( M == 0 ) | |
+ return avg_filter( M, a, L, b, w, x ); | |
-int speed; // dma sample speed | |
+ y = 0; | |
+ x0 = x; | |
-portable_samplepair_t *paintto = NULL; | |
+ K = max ( M, L ); | |
-#define MAX_DELAY 0.4f | |
-#define MAX_ROOM_TYPES ( sizeof( rgsxpre ) / sizeof( rgsxpre[0] ) ) | |
+ // for (i = 1; i <= M; i++) // input adder | |
+ // w[0] -= ( a[i] * w[i] ) >> PBITS; | |
-#define MONODLY 0 | |
-#define MAX_MONO_DELAY 0.4f | |
+ // M is clamped between 1 and FLT_M | |
+ // change this switch statement if FLT_M changes! | |
-#define REVERBPOS 1 | |
-#define MAX_REVERB_DELAY 0.1f | |
+ switch( M ) | |
+ { | |
+ case 12: x0 -= ( a[12] * w[12] ) >> PBITS; | |
+ case 11: x0 -= ( a[11] * w[11] ) >> PBITS; | |
+ case 10: x0 -= ( a[10] * w[10] ) >> PBITS; | |
+ case 9: x0 -= ( a[9] * w[9] ) >> PBITS; | |
+ case 8: x0 -= ( a[8] * w[8] ) >> PBITS; | |
+ case 7: x0 -= ( a[7] * w[7] ) >> PBITS; | |
+ case 6: x0 -= ( a[6] * w[6] ) >> PBITS; | |
+ case 5: x0 -= ( a[5] * w[5] ) >> PBITS; | |
+ case 4: x0 -= ( a[4] * w[4] ) >> PBITS; | |
+ case 3: x0 -= ( a[3] * w[3] ) >> PBITS; | |
+ case 2: x0 -= ( a[2] * w[2] ) >> PBITS; | |
+ default: | |
+ case 1: x0 -= ( a[1] * w[1] ) >> PBITS; | |
+ } | |
-#define STEREODLY 3 | |
-#define MAX_STEREO_DELAY 0.1f | |
+ w[0] = x0; | |
-#define MAXDLY (STEREODLY + 1) | |
-#define MAXLP 10 | |
-#define MAXPRESETS ARRAYSIZE(rgsxpre) | |
+ // for( i = 0; i <= L; i++ ) // output adder | |
+ // y += ( b[i] * w[i] ) >> PBITS; | |
-dly_t rgsxdly[MAXDLY]; // stereo is last | |
-int rgsxlp[MAXLP]; | |
+ switch( L ) | |
+ { | |
+ case 12: y += ( b[12] * w[12] ) >> PBITS; | |
+ case 11: y += ( b[11] * w[11] ) >> PBITS; | |
+ case 10: y += ( b[10] * w[10] ) >> PBITS; | |
+ case 9: y += ( b[9] * w[9] ) >> PBITS; | |
+ case 8: y += ( b[8] * w[8] ) >> PBITS; | |
+ case 7: y += ( b[7] * w[7] ) >> PBITS; | |
+ case 6: y += ( b[6] * w[6] ) >> PBITS; | |
+ case 5: y += ( b[5] * w[5] ) >> PBITS; | |
+ case 4: y += ( b[4] * w[4] ) >> PBITS; | |
+ case 3: y += ( b[3] * w[3] ) >> PBITS; | |
+ case 2: y += ( b[2] * w[2] ) >> PBITS; | |
+ default: | |
+ case 1: y += ( b[1] * w[1] ) >> PBITS; | |
+ case 0: y += ( b[0] * w[0] ) >> PBITS; | |
+ } | |
-void SX_Profiling_f( void ); | |
+ for( i = K; i >= 1; i-- ) // reverse update internal state | |
+ w[i] = w[i-1]; | |
-/* | |
-============ | |
-SX_ReloadRoomFX | |
+ return y; // current output sample | |
+} | |
-============ | |
-*/ | |
-void SX_ReloadRoomFX( void ) | |
+// IIR filter, cannonical form, using dot product and delay implementation | |
+// (may be easier to optimize this routine.) | |
+_inline int iir_filter2( int M, int *a, int L, int *b, int *w, int x ) | |
{ | |
- if( !dsp_room ) | |
- return; // not initialized | |
+ int K, y; | |
- sxste_delay->modified = true; | |
- sxrvb_feedback->modified = true; | |
- sxdly_delay->modified = true; | |
- room_type->modified = true; | |
+ K = max( M, L ); // K = max (M, L) | |
+ w[0] = 0; // needed for dot (M, a, w) | |
+ | |
+ w[0] = x - dot( M, a, w ); // input adder | |
+ y = dot( L, b, w ); // output adder | |
+ | |
+ delay( K, w ); // update delay line | |
+ | |
+ return y; // current output sample | |
} | |
-/* | |
-============ | |
-SX_Init() | |
-Starts sound crackling system | |
-============ | |
-*/ | |
-void SX_Init( void ) | |
+// fir filter - no feedback = high stability but also may be more expensive computationally | |
+_inline int fir_filter( int M, int *h, int *w, int x ) | |
{ | |
- Q_memset( rgsxdly, 0, sizeof( rgsxdly ) ); | |
- Q_memset( rgsxlp, 0, sizeof( rgsxlp ) ); | |
+ int i, y; | |
- sxamodr = sxamodl = sxamodrt = sxamodlt = 255; | |
+ w[0] = x; | |
- sxhires = sxhiresprev = 0; | |
- speed = dma.format.speed; | |
+ for( y = 0, i = 0; i <= M; i++ ) | |
+ y += h[i] * w[i]; | |
- sxmod1cur = sxmod1 = 350 * ( speed / SOUND_11k ); | |
- sxmod2cur = sxmod2 = 450 * ( speed / SOUND_11k ); | |
+ for( i = M; i >= -1; i-- ) | |
+ w[i] = w[i-1]; | |
- dsp_off = Cvar_Get( "dsp_off", "0", 0, "disable DSP processing" ); | |
- roomwater_type = Cvar_Get( "waterroom_type", "14", 0, "water room type" ); | |
- room_type = Cvar_Get( "room_type", "0", 0, "current room type preset" ); | |
+ return y; | |
+} | |
- sxmod_lowpass = Cvar_Get( "room_lp", "0", 0, "for water fx, lowpass for entire room" ); | |
- sxmod_mod = Cvar_Get( "room_mod", "0", 0, "stereo amptitude modulation for room" ); | |
+// fir filter, using dot product and delay implementation | |
+_inline int fir_filter2( int M, int *h, int *w, int x ) | |
+{ | |
+ int y; | |
- sxrvb_size = Cvar_Get( "room_size", "0", 0, "reverb: initial reflection size" ); | |
- sxrvb_feedback = Cvar_Get( "room_refl", "0", 0, "reverb: decay time" ); | |
- sxrvb_lp = Cvar_Get( "room_rvblp", "1", 0, "reverb: low pass filtering level" ); | |
+ w[0] = x; | |
+ y = dot( M, h, w ); | |
+ delay( M, w ); | |
- sxdly_delay = Cvar_Get( "room_delay", "0.8", 0, "mono delay: delay time" ); | |
- sxdly_feedback = Cvar_Get( "room_feedback", "0.2", 0, "mono delay: decay time" ); | |
- sxdly_lp = Cvar_Get( "room_dlylp", "1", 0, "mono delay: low pass filtering level" ); | |
+ return y; | |
+} | |
- sxste_delay = Cvar_Get( "room_left", "0", 0, "left channel delay time" ); | |
- Cmd_AddCommand( "dsp_profile", SX_Profiling_f, "dsp stress-test, first argument is room_type" ); | |
+// tap - i-th tap of circular delay line buffer | |
+// D delay line size in samples | |
+// w delay line buffer pointer, of dimension D+1 | |
+// p circular pointer | |
+// t = 0...D | |
+int tap( int D, int *w, int *p, int t ) | |
+{ | |
+ return w[(p - w + t) % (D + 1)]; | |
+} | |
- // for compability | |
- dsp_room = room_type; | |
- SX_ReloadRoomFX(); | |
+// tapi - interpolated tap output of a delay line | |
+// interpolates sample between adjacent samples in delay line for 'frac' part of delay | |
+// D delay line size in samples | |
+// w delay line buffer pointer, of dimension D+1 | |
+// p circular pointer | |
+// t - delay tap integer value 0...D. (complete delay is t.frac ) | |
+// frac - varying 16 bit fractional delay value 0...32767 (normalized to 0.0 - 1.0) | |
+_inline int tapi( int D, int *w, int *p, int t, int frac ) | |
+{ | |
+ int i, j; | |
+ int si, sj; | |
+ | |
+ i = t; // tap value, interpolate between adjacent samples si and sj | |
+ j = (i + 1) % (D+1); // if i = D, then j = 0; otherwise, j = i + 1 | |
+ | |
+ si = tap( D, w, p, i ); // si(n) = x(n - i) | |
+ sj = tap( D, w, p, j ); // sj(n) = x(n - j) | |
+ | |
+ return si + (((frac) * (sj - si) ) >> 16); | |
} | |
+// circular delay line, D-fold delay | |
+// D delay line size in samples w[0..D] | |
+// w delay line buffer pointer, dimension D+1 | |
+// p circular pointer | |
+_inline void cdelay( int D, int *w, int **p ) | |
+{ | |
+ (*p)--; // decrement pointer and wrap modulo (D+1) | |
+ wrap ( D, w, p ); // when *p = w-1, it wraps around to *p = w+D | |
+} | |
-/* | |
-=========== | |
-DLY_Free | |
+// plain reverberator with circular delay line | |
+// D delay line size in samples | |
+// t tap from this location - <= D | |
+// w delay line buffer pointer of dimension D+1 | |
+// p circular pointer, must be init to &w[0] before first call | |
+// a feedback value, 0-PMAX (normalized to 0.0-1.0) | |
+// b gain | |
+// x input sample | |
-Free memory allocated for DSP | |
-=========== | |
-*/ | |
-void DLY_Free( int idelay ) | |
+// w0(n) b | |
+// x(n)--->(+)--------.-----(*)-> y(n) | |
+// ^ | | |
+// | [Delay d] | |
+// | | | |
+// | a |Wd(n) | |
+// ----(*)---. | |
+ | |
+_inline int dly_plain( int D, int t, int *w, int **p, int a, int b, int x ) | |
{ | |
- Assert( idelay >= 0 && idelay < MAXDLY ); | |
+ int y, sD; | |
- if( rgsxdly[idelay].lpdelayline ) | |
+ sD = tap( D, w, *p, t ); // Tth tap delay output | |
+ y = x + (( a * sD ) >> PBITS); // filter output | |
+ **p = y; // delay input | |
+ cdelay( D, w, p ); // update delay line | |
+ | |
+ return (( y * b ) >> PBITS ); | |
+} | |
+ | |
+// straight delay line | |
+// | |
+// D delay line size in samples | |
+// t tap from this location - <= D | |
+// w delay line buffer pointer of dimension D+1 | |
+// p circular pointer, must be init to &w[0] before first call | |
+// x input sample | |
+// | |
+// x(n)--->[Delay d]---> y(n) | |
+// | |
+_inline int dly_linear ( int D, int t, int *w, int **p, int x ) | |
{ | |
- free( rgsxdly[idelay].lpdelayline ); | |
- rgsxdly[idelay].lpdelayline = NULL; | |
+ int y; | |
+ | |
+ y = tap( D, w, *p, t ); // Tth tap delay output | |
+ **p = x; // delay input | |
+ cdelay( D, w, p ); // update delay line | |
+ | |
+ return y; | |
} | |
+ | |
+// lowpass reverberator, replace feedback multiplier 'a' in | |
+// plain reverberator with a low pass filter | |
+// D delay line size in samples | |
+// t tap from this location - <= D | |
+// w delay line buffer pointer of dimension D+1 | |
+// p circular pointer, must be init to &w[0] before first call | |
+// a feedback gain | |
+// b output gain | |
+// M filter order | |
+// bf filter numerator, 0-PMAX (normalized to 0.0-1.0), M+1 dimensional | |
+// af filter denominator, 0-PMAX (normalized to 0.0-1.0), M+1 dimensional | |
+// vf filter state, M+1 dimensional | |
+// x input sample | |
+// w0(n) b | |
+// x(n)--->(+)--------------.----(*)--> y(n) | |
+// ^ | | |
+// | [Delay d] | |
+// | | | |
+// | a |Wd(n) | |
+// --(*)--[Filter])- | |
+ | |
+int dly_lowpass( int D, int t, int *w, int **p, int a, int b, int M, int *af, int L, int *bf, int *vf, int x ) | |
+{ | |
+ int y, sD; | |
+ | |
+ sD = tap( D, w, *p, t ); // delay output is filter input | |
+ y = x + ((iir_filter ( M, af, L, bf, vf, sD ) * a) >> PBITS); // filter output with gain | |
+ **p = y; // delay input | |
+ cdelay( D, w, p ); // update delay line | |
+ | |
+ return (( y * b ) >> PBITS ); // output with gain | |
} | |
-/* | |
-========== | |
-SX_Shutdown | |
+// allpass reverberator with circular delay line | |
+// D delay line size in samples | |
+// t tap from this location - <= D | |
+// w delay line buffer pointer of dimension D+1 | |
+// p circular pointer, must be init to &w[0] before first call | |
+// a feedback value, 0-PMAX (normalized to 0.0-1.0) | |
+// b gain | |
-Stop DSP processor | |
-========== | |
-*/ | |
-void SX_Free( ) | |
+// w0(n) -a b | |
+// x(n)--->(+)--------.-----(*)-->(+)--(*)-> y(n) | |
+// ^ | ^ | |
+// | [Delay d] | | |
+// | | | | |
+// | a |Wd(n) | | |
+// ----(*)---.------------- | |
+// | |
+// for each input sample x, do: | |
+// w0 = x + a*Wd | |
+// y = -a*w0 + Wd | |
+// delay (d, W) - w is the delay buffer array | |
+// | |
+// or, using circular delay, for each input sample x do: | |
+// | |
+// Sd = tap (D,w,p,D) | |
+// S0 = x + a*Sd | |
+// y = -a*S0 + Sd | |
+// *p = S0 | |
+// cdelay(D, w, &p) | |
+ | |
+_inline int dly_allpass( int D, int t, int *w, int **p, int a, int b, int x ) | |
{ | |
- int i; | |
- for( i = 0; i <= 3; i++ ) | |
- DLY_Free( i ); | |
+ int y, s0, sD; | |
- Cmd_RemoveCommand( "dsp_profile" ); | |
+ sD = tap( D, w, *p, t ); // Dth tap delay output | |
+ s0 = x + (( a * sD ) >> PBITS); | |
+ | |
+ y = (( -a * s0 ) >> PBITS ) + sD; // filter output | |
+ **p = s0; // delay input | |
+ cdelay( D, w, p ); // update delay line | |
+ | |
+ return (( y * b ) >> PBITS ); | |
} | |
-/* | |
-=========== | |
-DLY_Init | |
+/////////////////////////////////////////////////////////////////////////////////// | |
+// fixed point math for real-time wave table traversing, pitch shifting, resampling | |
+/////////////////////////////////////////////////////////////////////////////////// | |
+#define FIX20_BITS 20 // 20 bits of fractional part | |
+#define FIX20_SCALE (1 << FIX20_BITS) | |
+#define FIX20_INTMAX ((1 << (32 - FIX20_BITS))-1) // maximum step integer | |
+#define FLOAT_TO_FIX20(a) ((int)((a) * (float)FIX20_SCALE)) // convert float to fixed point | |
+#define INT_TO_FIX20(a) (((int)(a)) << FIX20_BITS) // convert int to fixed point | |
+#define FIX20_TO_FLOAT(a) ((float)(a) / (float)FIX20_SCALE) // convert fix20 to float | |
+#define FIX20_INTPART(a) (((int)(a)) >> FIX20_BITS) // get integer part of fixed point | |
+#define FIX20_FRACPART(a) ((a) - (((a) >> FIX20_BITS) << FIX20_BITS)) // get fractional part of fixed point | |
+#define FIX20_FRACTION(a,b) (FIX(a)/(b)) // convert int a to fixed point, divide by b | |
-Initialize dly | |
-=========== | |
-*/ | |
-int DLY_Init( int idelay, float delay ) | |
+typedef int fix20int; | |
+ | |
+///////////////////////////////// | |
+// DSP processor parameter block | |
+///////////////////////////////// | |
+ | |
+// NOTE: these prototypes must match the XXX_Params ( prc_t *pprc ) and XXX_GetNext ( XXX_t *p, int x ) functions | |
+ | |
+typedef void * (*prc_Param_t)( void *pprc ); // individual processor allocation functions | |
+typedef int (*prc_GetNext_t)( void *pdata, int x ); // get next function for processor | |
+typedef int (*prc_GetNextN_t)( void *pdata, portable_samplepair_t *pbuffer, int SampleCount, int op); // batch version of getnext | |
+typedef void (*prc_Free_t)( void *pdata ); // free function for processor | |
+typedef void (*prc_Mod_t)(void *pdata, float v); // modulation function for processor | |
+ | |
+#define OP_LEFT 0 // batch process left channel in place | |
+#define OP_RIGHT 1 // batch process right channel in place | |
+#define OP_LEFT_DUPLICATE 2 // batch process left channel in place, duplicate to right channel | |
+ | |
+#define PRC_NULL 0 // pass through - must be 0 | |
+#define PRC_DLY 1 // simple feedback reverb | |
+#define PRC_RVA 2 // parallel reverbs | |
+#define PRC_FLT 3 // lowpass or highpass filter | |
+#define PRC_CRS 4 // chorus | |
+#define PRC_PTC 5 // pitch shifter | |
+#define PRC_ENV 6 // adsr envelope | |
+#define PRC_LFO 7 // lfo | |
+#define PRC_EFO 8 // envelope follower | |
+#define PRC_MDY 9 // mod delay | |
+#define PRC_DFR 10 // diffusor - n series allpass delays | |
+#define PRC_AMP 11 // amplifier with distortion | |
+ | |
+#define QUA_LO 0 // quality of filter or reverb. Must be 0,1,2,3. | |
+#define QUA_MED 1 | |
+#define QUA_HI 2 | |
+#define QUA_VHI 3 | |
+#define QUA_MAX QUA_VHI | |
+ | |
+#define CPRCPARAMS 16 // up to 16 floating point params for each processor type | |
+ | |
+// processor definition - one for each running instance of a dsp processor | |
+typedef struct | |
{ | |
- dly_t *cur; | |
+ int type; // PRC type | |
- // DLY_Init called anytime with constants. So valid it in debug builds only. | |
- Assert( idelay >= 0 && idelay < MAXDLY ); | |
- Assert( delay > 0.0f && delay <= MAX_DELAY ); | |
+ float prm[CPRCPARAMS]; // dsp processor parameters - array of floats | |
- DLY_Free( idelay ); // free dly if it's allocated | |
+ prc_Param_t pfnParam; // allocation function - takes ptr to prc, returns ptr to specialized data struct for proc type | |
+ prc_GetNext_t pfnGetNext; // get next function | |
+ prc_GetNextN_t pfnGetNextN; // batch version of get next | |
+ prc_Free_t pfnFree; // free function | |
+ prc_Mod_t pfnMod; // modulation function | |
- cur = &rgsxdly[idelay]; | |
- cur->cdelaysamplesmax = ((int)(delay * speed) << sxhires) + 1; | |
- cur->lpdelayline = (int *) calloc( cur->cdelaysamplesmax, sizeof( int ) ); | |
- if( !cur->lpdelayline ) | |
+ void *pdata; // processor state data - ie: pdly, pflt etc. | |
+} prc_t; | |
+ | |
+// processor parameter ranges - for validating parameters during allocation of new processor | |
+typedef struct prm_rng_s | |
{ | |
- MsgDev( D_ERROR, "Failed to allocate memory for SoundFX!\n"); | |
- return 0; | |
+ int iprm; // parameter index | |
+ float lo; // min value of parameter | |
+ float hi; // max value of parameter | |
+} prm_rng_t; | |
+ | |
+void PRC_CheckParams( prc_t *pprc, prm_rng_t *prng ); | |
+ | |
+/////////// | |
+// Filters | |
+/////////// | |
+ | |
+#define CFLTS 64 // max number of filters simultaneously active | |
+#define FLT_M 12 // max order of any filter | |
+ | |
+#define FLT_LP 0 // lowpass filter | |
+#define FLT_HP 1 // highpass filter | |
+#define FTR_MAX FLT_HP | |
+ | |
+// flt parameters | |
+ | |
+typedef struct | |
+{ | |
+ qboolean fused; // true if slot in use | |
+ | |
+ int b[FLT_M+1]; // filter numerator parameters (convert 0.0-1.0 to 0-PMAX representation) | |
+ int a[FLT_M+1]; // filter denominator parameters (convert 0.0-1.0 to 0-PMAX representation) | |
+ int w[FLT_M+1]; // filter state - samples (dimension of max (M, L)) | |
+ int L; // filter order numerator (dimension of a[M+1]) | |
+ int M; // filter order denominator (dimension of b[L+1]) | |
+} flt_t; | |
+ | |
+// flt flts | |
+flt_t flts[CFLTS]; | |
+ | |
+void FLT_Init( flt_t *pf ) { if( pf ) Q_memset( pf, 0, sizeof( flt_t )); } | |
+void FLT_InitAll( void ) { int i; for( i = 0; i < CFLTS; i++ ) FLT_Init( &flts[i] ); } | |
+void FLT_Free( flt_t *pf ) { if( pf ) Q_memset( pf, 0, sizeof( flt_t )); } | |
+void FLT_FreeAll( void ) { int i; for( i = 0; i < CFLTS; i++ ) FLT_Free( &flts[i] ); } | |
+ | |
+ | |
+// find a free filter from the filter pool | |
+// initialize filter numerator, denominator b[0..M], a[0..L] | |
+flt_t * FLT_Alloc( int M, int L, int *a, int *b ) | |
+{ | |
+ int i, j; | |
+ flt_t *pf = NULL; | |
+ | |
+ for( i = 0; i < CFLTS; i++ ) | |
+ { | |
+ if( !flts[i].fused ) | |
+ { | |
+ pf = &flts[i]; | |
+ | |
+ // transfer filter params into filter struct | |
+ pf->M = M; | |
+ pf->L = L; | |
+ for( j = 0; j <= M; j++ ) | |
+ pf->a[j] = a[j]; | |
+ | |
+ for( j = 0; j <= L; j++ ) | |
+ pf->b[j] = b[j]; | |
+ | |
+ pf->fused = true; | |
+ break; | |
+ } | |
} | |
- cur->xfade = 0; | |
+ ASSERT( pf ); // make sure we're not trying to alloc more than CFLTS flts | |
- // init modulation | |
- cur->mod = cur->modcur = 0; | |
+ return pf; | |
+} | |
- // init lowpass | |
- cur->lp = 1; | |
- cur->lp0 = cur->lp1 = cur->lp2 = 0; | |
+// convert filter params cutoff and type into | |
+// iir transfer function params M, L, a[], b[] | |
+// iir filter, 1st order, transfer function is H(z) = b0 + b1 Z^-1 / a0 + a1 Z^-1 | |
+// or H(z) = b0 - b1 Z^-1 / a0 + a1 Z^-1 for lowpass | |
+// design cutoff filter at 3db (.5 gain) p579 | |
+void FLT_Design_3db_IIR( float cutoff, float ftype, int *pM, int *pL, int *a, int *b ) | |
+{ | |
+ // ftype: FLT_LP, FLT_HP, FLT_BP | |
- cur->idelayinput = 0; | |
- cur->idelayoutput = cur->cdelaysamplesmax - cur->delaysamples; // NOTE: delaysamples must be set!!! | |
+ double Wc = M_PI2 * cutoff / SOUND_DMA_SPEED; // radians per sample | |
+ double Oc; | |
+ double fa; | |
+ double fb; | |
+ // calculations: | |
+ // Wc = 2pi * fc/44100 convert to radians | |
+ // Oc = tan (Wc/2) * Gc / sqt ( 1 - Gc^2) get analog version, low pass | |
+ // Oc = tan (Wc/2) * (sqt (1 - Gc^2)) / Gc analog version, high pass | |
+ // Gc = 10 ^ (-Ac/20) gain at cutoff. Ac = 3db, so Gc^2 = 0.5 | |
+ // a = ( 1 - Oc ) / ( 1 + Oc ) | |
+ // b = ( 1 - a ) / 2 | |
- return 1; | |
+ Oc = tan( Wc / 2.0 ); | |
+ | |
+ fa = ( 1.0 - Oc ) / ( 1.0 + Oc ); | |
+ | |
+ fb = ( 1.0 - fa ) / 2.0; | |
+ | |
+ if( ftype == FLT_HP ) | |
+ fb = ( 1.0 + fa ) / 2.0; | |
+ | |
+ a[0] = 0; // a0 always ignored | |
+ a[1] = (int)( -fa * PMAX ); // quantize params down to 0-PMAX >> PBITS | |
+ b[0] = (int)( fb * PMAX ); | |
+ b[1] = b[0]; | |
+ | |
+ if( ftype == FLT_HP ) | |
+ b[1] = -b[1]; | |
+ | |
+ *pM = *pL = 1; | |
} | |
-/* | |
-============ | |
-DLY_MovePointer | |
-Checks overflow and moves pointer | |
-============ | |
-*/ | |
-_inline void DLY_MovePointer(dly_t *dly) | |
+// convolution of x[n] with h[n], resulting in y[n] | |
+// h, x, y filter, input and output arrays (double precision) | |
+// M = filter order, L = input length | |
+// h is M+1 dimensional | |
+// x is L dimensional | |
+// y is L+M dimensional | |
+void conv( int M, double *h, int L, double *x, double *y ) | |
{ | |
- if( ++dly->idelayinput >= dly->cdelaysamplesmax ) | |
- dly->idelayinput = 0; | |
+ int n, m; | |
- if( ++dly->idelayoutput >= dly->cdelaysamplesmax ) | |
- dly->idelayoutput = 0; | |
+ for( n = 0; n < L+M; n++ ) | |
+ { | |
+ for( y[n] = 0, m = max(0, n-L+1); m <= min(n, M); m++ ) | |
+ { | |
+ y[n] += h[m] * x[n-m]; | |
+ } | |
+ } | |
} | |
+// cas2can - convert cascaded, second order section parameter arrays to | |
+// canonical numerator/denominator arrays. Canonical implementations | |
+// have half as many multiplies as cascaded implementations. | |
+// K is number of cascaded sections | |
+// A is Kx3 matrix of sos params A[K] = A[0]..A[K-1] | |
+// a is (2K + 1) -dimensional output of canonical params | |
-/* | |
-============= | |
-DLY_CheckNewStereoDelayVal | |
+#define KMAX 32 // max # of sos sections - 8 is the most we should ever see at runtime | |
-Update stereo processor settings if we are in new room | |
-============= | |
-*/ | |
-void DLY_CheckNewStereoDelayVal( ) | |
+void cas2can( int K, double A[KMAX+1][3], int *aout ) | |
{ | |
- dly_t * const dly = &rgsxdly[STEREODLY]; | |
- float delay = sxste_delay->value; | |
+ int i, j; | |
+ double d[2*KMAX + 1]; | |
+ double a[2*KMAX + 1]; | |
- if( !sxste_delay->modified ) | |
- return; | |
+ ASSERT( K <= KMAX ); | |
- if( delay == 0 ) | |
+ Q_memset( d, 0, sizeof( double ) * ( 2 * KMAX + 1 )); | |
+ Q_memset( a, 0, sizeof( double ) * ( 2 * KMAX + 1 )); | |
+ | |
+ a[0] = 1; | |
+ | |
+ for( i = 0; i < K; i++ ) | |
{ | |
- DLY_Free( STEREODLY ); | |
+ conv( 2, A[i], 2 * i + 1, a, d ); | |
+ | |
+ for( j = 0; j < 2 * i + 3; j++ ) | |
+ a[j] = d[j]; | |
+ } | |
+ | |
+ for( i = 0; i < (2*K + 1); i++ ) | |
+ aout[i] = a[i] * PMAX; | |
+} | |
+ | |
+ | |
+// chebyshev IIR design, type 2, Lowpass or Highpass | |
+ | |
+#define lnf( e ) ( 2.303 * log10( e )) | |
+#define acosh( e ) ( lnf( (e) + sqrt(( e ) * ( e ) - 1) )) | |
+#define asinh( e ) ( lnf( (e) + sqrt(( e ) * ( e ) + 1) )) | |
+ | |
+ | |
+// returns a[], b[] which are Kx3 matrices of cascaded second-order sections | |
+// these matrices may be passed directly to the iir_cas() routine for evaluation | |
+// Nmax - maximum order of filter | |
+// cutoff, ftype, qwidth - filter cutoff in hz, filter type FLT_LOWPASS/HIGHPASS, qwidth in hz | |
+// pM - denominator order | |
+// pL - numerator order | |
+// a - array of canonical filter params | |
+// b - array of canonical filter params | |
+void FLT_Design_Cheb( int Nmax, float cutoff, float ftype, float qwidth, int *pM, int *pL, int *a, int *b ) | |
+{ | |
+// p769 - converted from MATLAB | |
+ | |
+ double s = (ftype == FLT_LP ? 1 : -1 ); // 1 for LP, -1 for HP | |
+ double fs = SOUND_DMA_SPEED; // sampling frequency | |
+ double fpass = cutoff; // cutoff frequency | |
+ double fstop = fpass + max (2000, qwidth); // stop frequency | |
+ double Apass = 0.5; // max attenuation of pass band UNDONE: use Quality to select this | |
+ double Astop = 10; // max amplitude of stop band UNDONE: use Quality to select this | |
+ | |
+ double Wpass, Wstop, epass, estop, Nex, aa; | |
+ double W3, f3, W0, G, Wi2, W02, a1, a2, th, Wi, D, b1; | |
+ int i, K, r, N; | |
+ double A[KMAX+1][3]; // denominator output matrices, second order sections | |
+ double B[KMAX+1][3]; // numerator output matrices, second order sections | |
+ | |
+ Wpass = tan( M_PI * fpass / fs ); | |
+ Wpass = pow( Wpass, s ); | |
+ Wstop = tan( M_PI * fstop / fs ); | |
+ Wstop = pow( Wstop, s ); | |
+ | |
+ epass = sqrt( pow( (float)10.0f, (float)Apass/10.0f ) - 1 ); | |
+ estop = sqrt( pow( (float)10.0f, (float)Astop/10.0f ) - 1 ); | |
+ | |
+ // calculate filter order N | |
+ | |
+ Nex = acosh( estop/epass ) / acosh ( Wstop/Wpass ); | |
+ N = min ( ceil(Nex), Nmax ); // don't exceed Nmax for filter order | |
+ r = ( (int)N & 1); // r == 1 if N is odd | |
+ K = (N - r ) / 2; | |
+ | |
+ aa = asinh ( estop ) / N; | |
+ W3 = Wstop / cosh( acosh( estop ) / N ); | |
+ f3 = (fs / M_PI) * atan( pow( W3, s )); | |
+ | |
+ W0 = sinh( aa ) / Wstop; | |
+ W02 = W0 * W0; | |
+ | |
+ // 1st order section for N odd | |
+ if( r == 1 ) | |
+ { | |
+ G = 1 / (1 + W0); | |
+ A[0][0] = 1; A[0][1] = s * (2*G-1); A[0][2] = 0; | |
+ B[0][0] = G; B[0][1] = G * s; B[0][2] = 0; | |
} | |
else | |
{ | |
- int samples; | |
+ A[0][0] = 1; A[0][1] = 0; A[0][2] = 0; | |
+ B[0][0] = 1; B[0][1] = 0; B[0][2] = 0; | |
+ } | |
- delay = min( delay, MAX_STEREO_DELAY ); | |
- samples = (int)(delay * speed) << sxhires; | |
+ for( i = 1; i <= K ; i++ ) | |
+ { | |
+ th = M_PI * (N - 1 + 2 * i) / (2 * N); | |
+ Wi = sin( th ) / Wstop; | |
+ Wi2 = Wi * Wi; | |
- // re-init dly | |
- if( !dly->lpdelayline ) | |
+ D = 1 - 2 * W0 * cos( th ) + W02 + Wi2; | |
+ G = ( 1 + Wi2 ) / D; | |
+ | |
+ b1 = 2 * ( 1 - Wi2 ) / ( 1 + Wi2 ); | |
+ a1 = 2 * ( 1 - W02 - Wi2) / D; | |
+ a2 = ( 1 + 2 * W0 * cos( th ) + W02 + Wi2) / D; | |
+ | |
+ A[i][0] = 1; | |
+ A[i][1] = s * a1; | |
+ A[i][2] = a2; | |
+ | |
+ B[i][0] = G; | |
+ B[i][1] = G* s* b1; | |
+ B[i][2] = G; | |
+ } | |
+ | |
+ // convert cascade parameters to canonical parameters | |
+ | |
+ cas2can( K, A, a ); | |
+ *pM = 2*K + 1; | |
+ | |
+ cas2can( K, B, b ); | |
+ *pL = 2*K + 1; | |
+} | |
+ | |
+// filter parameter order | |
+ | |
+typedef enum | |
{ | |
- dly->delaysamples = samples; | |
- DLY_Init( STEREODLY, MAX_STEREO_DELAY ); | |
+ flt_iftype, | |
+ flt_icutoff, | |
+ flt_iqwidth, | |
+ flt_iquality, | |
+ | |
+ flt_cparam // # of params | |
+} flt_e; | |
+ | |
+// filter parameter ranges | |
+ | |
+prm_rng_t flt_rng[] = | |
+{ | |
+{ flt_cparam, 0, 0 }, // first entry is # of parameters | |
+{ flt_iftype, 0, FTR_MAX }, // filter type FLT_LP, FLT_HP, FLT_BP (UNDONE: FLT_BP currently ignored) | |
+{ flt_icutoff, 10, 22050 }, // cutoff frequency in hz at -3db gain | |
+{ flt_iqwidth, 100, 11025 }, // width of BP, or steepness of LP/HP (ie: fcutoff + qwidth = -60db gain point) | |
+{ flt_iquality, 0, QUA_MAX }, // QUA_LO, _MED, _HI 0,1,2,3 | |
+}; | |
+ | |
+ | |
+// convert prc float params to iir filter params, alloc filter and return ptr to it | |
+// filter quality set by prc quality - 0,1,2 | |
+flt_t * FLT_Params ( prc_t *pprc ) | |
+{ | |
+ float qual = pprc->prm[flt_iquality]; | |
+ float cutoff = pprc->prm[flt_icutoff]; | |
+ float ftype = pprc->prm[flt_iftype]; | |
+ float qwidth = pprc->prm[flt_iqwidth]; | |
+ | |
+ int L = 0; // numerator order | |
+ int M = 0; // denominator order | |
+ int b[FLT_M+1]; // numerator params 0..PMAX | |
+ int a[FLT_M+1]; // denominator params 0..PMAX | |
+ | |
+ // low pass and highpass filter design | |
+ | |
+ if( (int)qual == QUA_LO ) | |
+ qual = QUA_MED; // disable lowest quality filter - check perf on lowend KDB | |
+ | |
+ switch ( (int)qual ) | |
+ { | |
+ case QUA_LO: | |
+ // lowpass averaging filter: perf KDB | |
+ ASSERT( ftype == FLT_LP ); | |
+ ASSERT( cutoff <= SOUND_DMA_SPEED ); | |
+ M = 0; | |
+ | |
+ // L is # of samples to average | |
+ | |
+ L = 0; | |
+ if( cutoff <= SOUND_DMA_SPEED / 4 ) L = 1; // 11k | |
+ if( cutoff <= SOUND_DMA_SPEED / 8 ) L = 2; // 5.5k | |
+ if( cutoff <= SOUND_DMA_SPEED / 16 ) L = 4; // 2.75k | |
+ if( cutoff <= SOUND_DMA_SPEED / 32 ) L = 8; // 1.35k | |
+ if( cutoff <= SOUND_DMA_SPEED / 64 ) L = 12; // 750hz | |
+ | |
+ break; | |
+ case QUA_MED: | |
+ // 1st order IIR filter, 3db cutoff at fc | |
+ FLT_Design_3db_IIR( cutoff, ftype, &M, &L, a, b ); | |
+ | |
+ M = bound( 1, M, FLT_M ); | |
+ L = bound( 1, L, FLT_M ); | |
+ break; | |
+ case QUA_HI: | |
+ // type 2 chebyshev N = 4 IIR | |
+ FLT_Design_Cheb( 4, cutoff, ftype, qwidth, &M, &L, a, b ); | |
+ | |
+ M = bound( 1, M, FLT_M ); | |
+ L = bound( 1, L, FLT_M ); | |
+ break; | |
+ case QUA_VHI: | |
+ // type 2 chebyshev N = 7 IIR | |
+ FLT_Design_Cheb( 8, cutoff, ftype, qwidth, &M, &L, a, b ); | |
+ | |
+ M = bound( 1, M, FLT_M ); | |
+ L = bound( 1, L, FLT_M ); | |
+ break; | |
} | |
- if( dly->delaysamples != samples ) | |
+ return FLT_Alloc( M, L, a, b ); | |
+} | |
+ | |
+_inline void * FLT_VParams( void *p ) | |
{ | |
- dly->xfade = 128; | |
- dly->idelayoutputxf = dly->idelayinput - samples; | |
- if( dly->idelayoutputxf < 0 ) | |
- dly->idelayoutputxf += dly->cdelaysamplesmax; | |
+ PRC_CheckParams(( prc_t *)p, flt_rng ); | |
+ return (void *)FLT_Params ((prc_t *)p); | |
} | |
- dly->modcur = dly->mod = 0; | |
- if( dly->delaysamples == 0 ) | |
- DLY_Free( STEREODLY ); | |
+_inline void FLT_Mod( void *p, float v ) | |
+{ | |
} | |
- sxste_delay->modified = false; | |
+// get next filter value for filter pf and input x | |
+_inline int FLT_GetNext( flt_t *pf, int x ) | |
+{ | |
+ return iir_filter( pf->M, pf->a, pf->L, pf->b, pf->w, x ); | |
} | |
-/* | |
-============= | |
-DLY_DoStereoDelay | |
+// batch version for performance | |
+_inline void FLT_GetNextN( flt_t *pflt, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
+{ | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
-Do stereo processing | |
-============= | |
-*/ | |
-void DLY_DoStereoDelay( int count ) | |
+ switch( op ) | |
{ | |
- int delay; | |
- int samplexf; | |
- dly_t *const dly = &rgsxdly[STEREODLY]; | |
- portable_samplepair_t *paint = paintto; | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = FLT_GetNext( pflt, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = FLT_GetNext( pflt, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = FLT_GetNext( pflt, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ } | |
+} | |
- if( !dly->lpdelayline ) | |
- return; // inactive | |
+/////////////////////////////////////////////////////////////////////////// | |
+// Positional updaters for pitch shift etc | |
+/////////////////////////////////////////////////////////////////////////// | |
- for( ; count; count--, paint++ ) | |
+// looping position within a wav, with integer and fractional parts | |
+// used for pitch shifting, upsampling/downsampling | |
+// 20 bits of fraction, 8+ bits of integer | |
+typedef struct | |
{ | |
- if( dly->mod && --dly->modcur < 0 ) | |
- dly->modcur = dly->mod; | |
- delay = dly->lpdelayline[dly->idelayoutput]; | |
+ fix20int step; // wave table whole and fractional step value | |
+ fix20int cstep; // current cummulative step value | |
+ int pos; // current position within wav table | |
- // process only if crossfading, active left value or delayline | |
- if( delay || paint->left || dly->xfade ) | |
+ int D; // max dimension of array w[0...D] ie: # of samples = D+1 | |
+} pos_t; | |
+ | |
+// circular wrap of pointer p, relative to array w | |
+// D max buffer index w[0...D] (count of samples in buffer is D+1) | |
+// i circular index | |
+_inline void POS_Wrap( int D, int *i ) | |
{ | |
- // set up new crossfade, if not crossfading, not modulating, but going to | |
- if( !dly->xfade && !dly->modcur && dly->mod ) | |
+ if( *i > D ) *i -= D + 1; // when *pi = D + 1, it wraps around to *pi = 0 | |
+ if( *i < 0 ) *i += D + 1; // when *pi = - 1, it wraps around to *pi = D | |
+} | |
+ | |
+// set initial update value - fstep can have no more than 8 bits of integer and 20 bits of fract | |
+// D is array max dimension w[0...D] (ie: size D+1) | |
+// w is ptr to array | |
+// p is ptr to pos_t to initialize | |
+_inline void POS_Init( pos_t *p, int D, float fstep ) | |
{ | |
- dly->idelayoutputxf = dly->idelayoutput + | |
- ((Com_RandomLong( 0, 255 ) * dly->delaysamples ) >> 9 ); | |
+ float step = fstep; | |
- dly->xfade = 128; | |
+ // make sure int part of step is capped at fix20_intmax | |
+ | |
+ if( (int)step > FIX20_INTMAX ) | |
+ step = (step - (int)step) + FIX20_INTMAX; | |
+ | |
+ p->step = FLOAT_TO_FIX20( step ); // convert fstep to fixed point | |
+ p->cstep = 0; | |
+ p->pos = 0; // current update value | |
+ p->D = D; // always init to end value, in case we're stepping backwards | |
} | |
- dly->idelayoutputxf %= dly->cdelaysamplesmax; | |
+// change step value - this is an instantaneous change, not smoothed. | |
+_inline void POS_ChangeVal( pos_t *p, float fstepnew ) | |
+{ | |
+ p->step = FLOAT_TO_FIX20( fstepnew ); // convert fstep to fixed point | |
+} | |
- // modify delay, if crossfading | |
- if( dly->xfade ) | |
+// return current integer position, then update internal position value | |
+_inline int POS_GetNext ( pos_t *p ) | |
{ | |
- samplexf = dly->lpdelayline[dly->idelayoutputxf] * (128 - dly->xfade) >> 7; | |
- delay = samplexf + ((delay * dly->xfade) >> 7); | |
- if( ++dly->idelayoutputxf >= dly->cdelaysamplesmax ) | |
- dly->idelayoutputxf = 0; | |
+ // float f = FIX20_TO_FLOAT( p->cstep ); | |
+ // int i1 = FIX20_INTPART( p->cstep ); | |
+ // float f1 = FIX20_TO_FLOAT( FIX20_FRACPART( p->cstep )); | |
+ // float f2 = FIX20_TO_FLOAT( p->step ); | |
- if( --dly->xfade == 0 ) | |
- dly->idelayoutput = dly->idelayoutputxf; | |
+ p->cstep += p->step; // update accumulated fraction step value (fixed point) | |
+ p->pos += FIX20_INTPART( p->cstep ); // update pos with integer part of accumulated step | |
+ p->cstep = FIX20_FRACPART( p->cstep ); // throw away the integer part of accumulated step | |
+ | |
+ // wrap pos around either end of buffer if needed | |
+ POS_Wrap( p->D, &( p->pos )); | |
+ | |
+ // make sure returned position is within array bounds | |
+ ASSERT( p->pos <= p->D ); | |
+ | |
+ return p->pos; | |
} | |
- // save left value to delay line | |
- dly->lpdelayline[dly->idelayinput] = paint->left; | |
+// oneshot position within wav | |
+typedef struct | |
+{ | |
+ pos_t p; // pos_t | |
+ qboolean fhitend; // flag indicating we hit end of oneshot wav | |
+} pos_one_t; | |
- // paint new delay value | |
- paint->left = CLIP(delay); | |
+// set initial update value - fstep can have no more than 8 bits of integer and 20 bits of fract | |
+// one shot position - play only once, don't wrap, when hit end of buffer, return last position | |
+_inline void POS_ONE_Init( pos_one_t *p1, int D, float fstep ) | |
+{ | |
+ POS_Init( &p1->p, D, fstep ) ; | |
+ | |
+ p1->fhitend = false; | |
} | |
- else // clear delay line | |
- dly->lpdelayline[dly->idelayinput] = 0; | |
- DLY_MovePointer( dly ); | |
+// return current integer position, then update internal position value | |
+_inline int POS_ONE_GetNext( pos_one_t *p1 ) | |
+{ | |
+ int pos; | |
+ pos_t *p0; | |
+ | |
+ pos = p1->p.pos; // return current position | |
+ | |
+ if( p1->fhitend ) | |
+ return pos; | |
+ | |
+ p0 = &(p1->p); | |
+ p0->cstep += p0->step; // update accumulated fraction step value (fixed point) | |
+ p0->pos += FIX20_INTPART( p0->cstep ); // update pos with integer part of accumulated step | |
+ //p0->cstep = SIGN(p0->cstep) * FIX20_FRACPART( p0->cstep ); | |
+ p0->cstep = FIX20_FRACPART( p0->cstep ); // throw away the integer part of accumulated step | |
+ | |
+ // if we wrapped, stop updating, always return last position | |
+ // if step value is 0, return hit end | |
+ | |
+ if( !p0->step || p0->pos < 0 || p0->pos >= p0->D ) | |
+ p1->fhitend = true; | |
+ else pos = p0->pos; | |
+ | |
+ // make sure returned value is within array bounds | |
+ ASSERT( pos <= p0->D ); | |
+ | |
+ return pos; | |
+} | |
+ | |
+///////////////////// | |
+// Reverbs and delays | |
+///////////////////// | |
+#define CDLYS 128 // max delay lines active. Also used for lfos. | |
+ | |
+#define DLY_PLAIN 0 // single feedback loop | |
+#define DLY_ALLPASS 1 // feedback and feedforward loop - flat frequency response (diffusor) | |
+#define DLY_LOWPASS 2 // lowpass filter in feedback loop | |
+#define DLY_LINEAR 3 // linear delay, no feedback, unity gain | |
+#define DLY_MAX DLY_LINEAR | |
+ | |
+// delay line | |
+typedef struct | |
+{ | |
+ qboolean fused; // true if dly is in use | |
+ int type; // delay type | |
+ int D; // delay size, in samples | |
+ int t; // current tap, <= D | |
+ int D0; // original delay size (only relevant if calling DLY_ChangeVal) | |
+ int *p; // circular buffer pointer | |
+ int *w; // array of samples | |
+ int a; // feedback value 0..PMAX,normalized to 0-1.0 | |
+ int b; // gain value 0..PMAX, normalized to 0-1.0 | |
+ flt_t *pflt; // pointer to filter, if type DLY_LOWPASS | |
+ HANDLE h; // memory handle for sample array | |
+} dly_t; | |
+ | |
+dly_t dlys[CDLYS]; // delay lines | |
+ | |
+void DLY_Init( dly_t *pdly ) { if( pdly ) Q_memset( pdly, 0, sizeof( dly_t )); } | |
+void DLY_InitAll( void ) { int i; for( i = 0; i < CDLYS; i++ ) DLY_Init( &dlys[i] ); } | |
+void DLY_Free( dly_t *pdly ) | |
+{ | |
+ // free memory buffer | |
+ if( pdly ) | |
+ { | |
+ FLT_Free( pdly->pflt ); | |
+ | |
+ if( pdly->w ) | |
+ { | |
+ GlobalUnlock( pdly->h ); | |
+ GlobalFree( pdly->h ); | |
+ } | |
+ | |
+ // free dly slot | |
+ Q_memset( pdly, 0, sizeof( dly_t )); | |
} | |
} | |
-/* | |
-============= | |
-DLY_CheckNewDelayVal | |
+void DLY_FreeAll( void ) { int i; for( i = 0; i < CDLYS; i++ ) DLY_Free( &dlys[i] ); } | |
-Update delay processor settings if we are in new room | |
-============= | |
-*/ | |
-void DLY_CheckNewDelayVal( ) | |
+// set up 'b' gain parameter of feedback delay to | |
+// compensate for gain caused by feedback. | |
+void DLY_SetNormalizingGain( dly_t *pdly ) | |
{ | |
- float delay = sxdly_delay->value; | |
- dly_t * const dly = &rgsxdly[MONODLY]; | |
+ // compute normalized gain, set as output gain | |
- if( sxdly_delay->modified ) | |
+ // calculate gain of delay line with feedback, and use it to | |
+ // reduce output. ie: force delay line with feedback to unity gain | |
+ | |
+ // for constant input x with feedback fb: | |
+ | |
+ // out = x + x*fb + x * fb^2 + x * fb^3... | |
+ // gain = out/x | |
+ // so gain = 1 + fb + fb^2 + fb^3... | |
+ // which, by the miracle of geometric series, equates to 1/1-fb | |
+ // thus, gain = 1/(1-fb) | |
+ | |
+ float fgain = 0; | |
+ float gain; | |
+ int b; | |
+ | |
+ // if b is 0, set b to PMAX (1) | |
+ b = pdly->b ? pdly->b : PMAX; | |
+ | |
+ // fgain = b * (1.0 / (1.0 - (float)pdly->a / (float)PMAX)) / (float)PMAX; | |
+ fgain = (1.0 / (1.0 - (float)pdly->a / (float)PMAX )); | |
+ | |
+ // compensating gain - multiply rva output by gain then >> PBITS | |
+ gain = (int)((1.0 / fgain) * PMAX); | |
+ | |
+ gain = gain * 4; // compensate for fact that gain calculation is for +/- 32767 amplitude wavs | |
+ // ie: ok to allow a bit more gain because most wavs are not at theoretical peak amplitude at all times | |
+ | |
+ gain = min( gain, PMAX ); // cap at PMAX | |
+ gain = ((float)b/(float)PMAX) * gain; // scale final gain by pdly->b. | |
+ | |
+ pdly->b = (int)gain; | |
+} | |
+ | |
+// allocate a new delay line | |
+// D number of samples to delay | |
+// a feedback value (0-PMAX normalized to 0.0-1.0) | |
+// b gain value (0-PMAX normalized to 0.0-1.0) | |
+// if DLY_LOWPASS: | |
+// L - numerator order of filter | |
+// M - denominator order of filter | |
+// fb - numerator params, M+1 | |
+// fa - denominator params, L+1 | |
+ | |
+dly_t * DLY_AllocLP( int D, int a, int b, int type, int M, int L, int *fa, int *fb ) | |
{ | |
- if( delay == 0 ) | |
- DLY_Free( MONODLY ); | |
- else | |
+ HANDLE h; | |
+ int cb; | |
+ int *w; | |
+ int i; | |
+ dly_t *pdly = NULL; | |
+ | |
+ // find open slot | |
+ for( i = 0; i < CDLYS; i++ ) | |
{ | |
- delay = min( delay, MAX_MONO_DELAY ); | |
- dly->delaysamples = (int)(delay * speed) << sxhires; | |
+ if( !dlys[i].fused ) | |
+ { | |
+ pdly = &dlys[i]; | |
+ DLY_Init( pdly ); | |
+ break; | |
+ } | |
+ } | |
- // init dly | |
- if( !dly->lpdelayline ) | |
- DLY_Init( MONODLY, MAX_MONO_DELAY ); | |
+ if( i == CDLYS ) | |
+ { | |
+ MsgDev( D_WARN, "DSP: failed to allocate delay line.\n" ); | |
+ return NULL; // all delay lines in use | |
+ } | |
- if( dly->lpdelayline ) | |
+ cb = (D + 1) * sizeof( int ); // assume all samples are signed integers | |
+ | |
+ if( type == DLY_LOWPASS ) | |
{ | |
- Q_memset( dly->lpdelayline, 0, dly->cdelaysamplesmax * sizeof( int ) ); | |
- dly->lp0 = dly->lp1 = dly->lp2 = 0; | |
+ // alloc lowpass fir_filter | |
+ pdly->pflt = FLT_Alloc( M, L, fa, fb ); | |
+ if( !pdly->pflt ) | |
+ { | |
+ MsgDev( D_WARN, "DSP: failed to allocate filter for delay line.\n" ); | |
+ return NULL; | |
+ } | |
} | |
- dly->idelayinput = 0; | |
- dly->idelayoutput = dly->cdelaysamplesmax - dly->delaysamples; | |
+ // alloc delay memory | |
+ h = GlobalAlloc( GMEM_MOVEABLE|GMEM_SHARE, cb ); | |
+ if( !h ) | |
+ { | |
+ MsgDev( D_ERROR, "Sound DSP: Out of memory.\n" ); | |
+ FLT_Free( pdly->pflt ); | |
+ return NULL; | |
+ } | |
- if( !dly->delaysamples ) | |
- DLY_Free( MONODLY ); | |
+ // lock delay memory | |
+ w = (int *)GlobalLock( h ); | |
+ | |
+ if( !w ) | |
+ { | |
+ MsgDev( D_ERROR, "Sound DSP: Failed to lock.\n" ); | |
+ GlobalFree( h ); | |
+ FLT_Free( pdly->pflt ); | |
+ return NULL; | |
+ } | |
+ | |
+ // clear delay array | |
+ Q_memset( w, 0, cb ); | |
+ // init values | |
+ pdly->type = type; | |
+ pdly->D = D; | |
+ pdly->t = D; // set delay tap to full delay | |
+ pdly->D0 = D; | |
+ pdly->p = w; // init circular pointer to head of buffer | |
+ pdly->w = w; | |
+ pdly->h = h; | |
+ pdly->a = min( a, PMAX ); // do not allow 100% feedback | |
+ pdly->b = b; | |
+ pdly->fused = true; | |
+ | |
+ if( type == DLY_LINEAR ) | |
+ { | |
+ // linear delay has no feedback and unity gain | |
+ pdly->a = 0; | |
+ pdly->b = PMAX; | |
} | |
+ else | |
+ { | |
+ // adjust b to compensate for feedback gain | |
+ DLY_SetNormalizingGain( pdly ); | |
} | |
- sxdly_delay->modified = false; | |
- dly->lp = sxdly_lp->integer; | |
- dly->delayfeedback = 255 * sxdly_feedback->value; | |
+ return pdly; | |
} | |
-/* | |
-============= | |
-DLY_DoDelay | |
+// allocate lowpass or allpass delay | |
+dly_t * DLY_Alloc( int D, int a, int b, int type ) | |
+{ | |
+ return DLY_AllocLP( D, a, b, type, 0, 0, 0, 0 ); | |
+} | |
-Do delay processing | |
-============= | |
-*/ | |
-void DLY_DoDelay( int count ) | |
+ | |
+// Allocate new delay, convert from float params in prc preset to internal parameters | |
+// Uses filter params in prc if delay is type lowpass | |
+ | |
+// delay parameter order | |
+typedef enum | |
{ | |
- dly_t * const dly = &rgsxdly[MONODLY]; | |
- portable_samplepair_t *paint = paintto; | |
- int delay; | |
+ dly_idtype, // NOTE: first 8 params must match those in mdy_e | |
+ dly_idelay, | |
+ dly_ifeedback, | |
+ dly_igain, | |
+ dly_iftype, | |
+ dly_icutoff, | |
+ dly_iqwidth, | |
+ dly_iquality, | |
+ dly_cparam | |
+} dly_e; | |
- if( !dly->lpdelayline || !count ) | |
- return; // inactive | |
- for( ; count; count--, paint++ ) | |
+// delay parameter ranges | |
+prm_rng_t dly_rng[] = | |
{ | |
- delay = dly->lpdelayline[dly->idelayoutput]; | |
+{ dly_cparam, 0, 0 }, // first entry is # of parameters | |
- // don't process if delay line and left/right samples are zero | |
- if( delay || paint->left || paint->right ) | |
+// delay params | |
+{ dly_idtype, 0, DLY_MAX }, // delay type DLY_PLAIN, DLY_LOWPASS, DLY_ALLPASS | |
+{ dly_idelay, 0.0, 1000.0 }, // delay in milliseconds | |
+{ dly_ifeedback, 0.0, 0.99 }, // feedback 0-1.0 | |
+{ dly_igain, 0.0, 1.0 }, // final gain of output stage, 0-1.0 | |
+ | |
+// filter params if dly type DLY_LOWPASS | |
+{ dly_iftype, 0, FTR_MAX }, | |
+{ dly_icutoff, 10.0, 22050.0 }, | |
+{ dly_iqwidth, 100.0, 11025.0 }, | |
+{ dly_iquality, 0, QUA_MAX }, | |
+}; | |
+ | |
+dly_t * DLY_Params( prc_t *pprc ) | |
{ | |
- // calculate delayed value from average | |
- int val = (( paint->left + paint->right ) / 2 ) + | |
- (( dly->delayfeedback * delay ) >> 8); | |
- val = CLIP( val ); | |
+ dly_t *pdly = NULL; | |
+ int D, a, b; | |
- if( dly->lp ) // lowpass | |
+ float delay = pprc->prm[dly_idelay]; | |
+ float feedback = pprc->prm[dly_ifeedback]; | |
+ float gain = pprc->prm[dly_igain]; | |
+ int type = pprc->prm[dly_idtype]; | |
+ | |
+ float ftype = pprc->prm[dly_iftype]; | |
+ float cutoff = pprc->prm[dly_icutoff]; | |
+ float qwidth = pprc->prm[dly_iqwidth]; | |
+ float qual = pprc->prm[dly_iquality]; | |
+ | |
+ D = MSEC_TO_SAMPS( delay ); // delay samples | |
+ a = feedback * PMAX; // feedback | |
+ b = gain * PMAX; // gain | |
+ | |
+ switch( type ) | |
{ | |
- dly->lp0 = dly->lp1; | |
- dly->lp1 = val; | |
- val = ( dly->lp0 + dly->lp1 + (val << 1) ) >> 2; | |
+ case DLY_PLAIN: | |
+ case DLY_ALLPASS: | |
+ case DLY_LINEAR: | |
+ pdly = DLY_Alloc( D, a, b, type ); | |
+ break; | |
+ case DLY_LOWPASS: | |
+ { | |
+ // set up dummy lowpass filter to convert params | |
+ prc_t prcf; | |
+ flt_t *pflt; | |
+ | |
+ // 0,1,2 - high, medium, low (low quality implies faster execution time) | |
+ prcf.prm[flt_iquality] = qual; | |
+ prcf.prm[flt_icutoff] = cutoff; | |
+ prcf.prm[flt_iftype] = ftype; | |
+ prcf.prm[flt_iqwidth] = qwidth; | |
+ | |
+ pflt = (flt_t *)FLT_Params( &prcf ); | |
+ | |
+ if( !pflt ) | |
+ { | |
+ MsgDev( D_WARN, "DSP: failed to allocate filter.\n" ); | |
+ return NULL; | |
} | |
- dly->lpdelayline[dly->idelayinput] = val; | |
+ pdly = DLY_AllocLP( D, a, b, type, pflt->M, pflt->L, pflt->a, pflt->b ); | |
- val >>= 2; | |
+ FLT_Free( pflt ); | |
+ break; | |
+ } | |
+ } | |
+ return pdly; | |
+} | |
- paint->left = CLIP( paint->left + val ); | |
- paint->right = CLIP( paint->right + val ); | |
+_inline void *DLY_VParams( void *p ) | |
+{ | |
+ PRC_CheckParams(( prc_t *)p, dly_rng ); | |
+ return (void *) DLY_Params((prc_t *)p); | |
} | |
- else | |
+ | |
+// get next value from delay line, move x into delay line | |
+int DLY_GetNext( dly_t *pdly, int x ) | |
{ | |
- dly->lpdelayline[dly->idelayinput] = 0; | |
- dly->lp0 = dly->lp1 = 0; | |
+ switch( pdly->type ) | |
+ { | |
+ default: | |
+ case DLY_PLAIN: | |
+ return dly_plain( pdly->D, pdly->t, pdly->w, &pdly->p, pdly->a, pdly->b, x ); | |
+ case DLY_ALLPASS: | |
+ return dly_allpass( pdly->D, pdly->t, pdly->w, &pdly->p, pdly->a, pdly->b, x ); | |
+ case DLY_LOWPASS: | |
+ return dly_lowpass( pdly->D, pdly->t, pdly->w, &(pdly->p), pdly->a, pdly->b, pdly->pflt->M, pdly->pflt->a, pdly->pflt->L, pdly->pflt->b, pdly->pflt->w, x ); | |
+ case DLY_LINEAR: | |
+ return dly_linear( pdly->D, pdly->t, pdly->w, &pdly->p, x ); | |
+ } | |
} | |
- DLY_MovePointer( dly ); | |
+// batch version for performance | |
+void DLY_GetNextN( dly_t *pdly, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
+{ | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
+ | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = DLY_GetNext( pdly, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = DLY_GetNext( pdly, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = DLY_GetNext( pdly, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
} | |
} | |
-/* | |
-=========== | |
-RVB_SetUpDly | |
+// get tap on t'th sample in delay - don't update buffer pointers, this is done via DLY_GetNext | |
+_inline int DLY_GetTap( dly_t *pdly, int t ) | |
+{ | |
+ return tap( pdly->D, pdly->w, pdly->p, t ); | |
+} | |
-Set up dly for reverb | |
-=========== | |
-*/ | |
-void RVB_SetUpDly( int pos, float delay, int kmod ) | |
+ | |
+// make instantaneous change to new delay value D. | |
+// t tap value must be <= original D (ie: we don't do any reallocation here) | |
+void DLY_ChangeVal( dly_t *pdly, int t ) | |
{ | |
- int samples; | |
- delay = min( delay, MAX_REVERB_DELAY ); | |
- samples = (int)(delay * speed) << sxhires; | |
+ // never set delay > original delay | |
+ pdly->t = min( t, pdly->D0 ); | |
+} | |
- if( !rgsxdly[pos].lpdelayline ) | |
+// ignored - use MDY_ for modulatable delay | |
+_inline void DLY_Mod( void *p, float v ) | |
{ | |
- rgsxdly[pos].delaysamples = samples; | |
- DLY_Init( pos, MAX_REVERB_DELAY ); | |
} | |
- rgsxdly[pos].modcur = rgsxdly[pos].mod = (int)(kmod * speed / SOUND_11k) << sxhires; | |
+/////////////////// | |
+// Parallel reverbs | |
+/////////////////// | |
- // set up crossfade, if delay has changed | |
- if( rgsxdly[pos].delaysamples != samples ) | |
+// Reverb A | |
+// M parallel reverbs, mixed to mono output | |
+ | |
+#define CRVAS 64 // max number of parallel series reverbs active | |
+#define CRVA_DLYS 12 // max number of delays making up reverb_a | |
+ | |
+typedef struct | |
{ | |
- rgsxdly[pos].idelayoutputxf = rgsxdly[pos].idelayinput - samples; | |
- if( rgsxdly[pos].idelayoutputxf < 0 ) | |
- rgsxdly[pos].idelayoutputxf += rgsxdly[pos].cdelaysamplesmax; | |
- rgsxdly[pos].xfade = 32; | |
+ qboolean fused; | |
+ int m; // number of parallel plain or lowpass delays | |
+ int fparallel; // true if filters in parallel with delays, otherwise single output filter | |
+ flt_t *pflt; | |
+ | |
+ dly_t *pdlys[CRVA_DLYS]; // array of pointers to delays | |
+} rva_t; | |
+ | |
+rva_t rvas[CRVAS]; | |
+ | |
+void RVA_Init( rva_t *prva ) { if( prva ) Q_memset( prva, 0, sizeof( rva_t )); } | |
+void RVA_InitAll( void ) { int i; for( i = 0; i < CRVAS; i++ ) RVA_Init( &rvas[i] ); } | |
+ | |
+// free parallel series reverb | |
+void RVA_Free( rva_t *prva ) | |
+{ | |
+ if( prva ) | |
+ { | |
+ int i; | |
+ | |
+ // free all delays | |
+ for( i = 0; i < CRVA_DLYS; i++) | |
+ DLY_Free ( prva->pdlys[i] ); | |
+ | |
+ FLT_Free( prva->pflt ); | |
+ Q_memset( prva, 0, sizeof (rva_t) ); | |
+ } | |
} | |
- if( !rgsxdly[pos].delaysamples ) | |
- DLY_Free( pos ); | |
+void RVA_FreeAll( void ) { int i; for( i = 0; i < CRVAS; i++ ) RVA_Free( &rvas[i] ); } | |
+ | |
+// create parallel reverb - m parallel reverbs summed | |
+// D array of CRVB_DLYS reverb delay sizes max sample index w[0...D] (ie: D+1 samples) | |
+// a array of reverb feedback parms for parallel reverbs (CRVB_P_DLYS) | |
+// b array of CRVB_P_DLYS - mix params for parallel reverbs | |
+// m - number of parallel delays | |
+// pflt - filter template, to be used by all parallel delays | |
+// fparallel - true if filter operates in parallel with delays, otherwise filter output only | |
+rva_t *RVA_Alloc( int *D, int *a, int *b, int m, flt_t *pflt, int fparallel ) | |
+{ | |
+ int i; | |
+ rva_t *prva; | |
+ flt_t *pflt2 = NULL; | |
+ | |
+ // find open slot | |
+ for( i = 0; i < CRVAS; i++ ) | |
+ { | |
+ if( !rvas[i].fused ) | |
+ break; | |
} | |
+ // return null if no free slots | |
+ if( i == CRVAS ) | |
+ { | |
+ MsgDev( D_WARN, "DSP: failed to allocate reverb.\n" ); | |
+ return NULL; | |
+ } | |
-/* | |
-=========== | |
-RVB_CheckNewReverbVal | |
+ prva = &rvas[i]; | |
-Update reverb settings if we are in new room | |
-=========== | |
-*/ | |
-void RVB_CheckNewReverbVal( ) | |
+ // if series filter specified, alloc | |
+ if( pflt && !fparallel ) | |
{ | |
- float delay = sxrvb_size->value; | |
- dly_t *const dly1 = &rgsxdly[REVERBPOS], | |
- *const dly2 = &rgsxdly[REVERBPOS + 1]; | |
- int samples; | |
+ // use filter data as template for a filter on output | |
+ pflt2 = FLT_Alloc( pflt->M, pflt->L, pflt->a, pflt->b ); | |
- if( sxrvb_size->modified ) | |
+ if( !pflt2 ) | |
{ | |
- if( delay == 0.0f ) | |
+ MsgDev( D_WARN, "DSP: failed to allocate flt for reverb.\n" ); | |
+ return NULL; | |
+ } | |
+ } | |
+ | |
+ // alloc parallel reverbs | |
+ if( pflt && fparallel ) | |
{ | |
- DLY_Free( REVERBPOS ); | |
- DLY_Free( REVERBPOS + 1 ); | |
+ | |
+ // use this filter data as a template to alloc a filter for each parallel delay | |
+ for( i = 0; i < m; i++ ) | |
+ prva->pdlys[i] = DLY_AllocLP( D[i], a[i], b[i], DLY_LOWPASS, pflt->M, pflt->L, pflt->a, pflt->b ); | |
} | |
else | |
{ | |
- RVB_SetUpDly( REVERBPOS, sxrvb_size->value, 500 ); | |
- RVB_SetUpDly( REVERBPOS+1, sxrvb_size->value*0.71, 700 ); | |
+ // no filter specified, use plain delays in parallel sections | |
+ for( i = 0; i < m; i++ ) | |
+ prva->pdlys[i] = DLY_Alloc( D[i], a[i], b[i], DLY_PLAIN ); | |
+ } | |
+ | |
+ | |
+ // if we failed to alloc any reverb, free all, return NULL | |
+ for( i = 0; i < m; i++ ) | |
+ { | |
+ if( !prva->pdlys[i] ) | |
+ { | |
+ FLT_Free( pflt2 ); | |
+ RVA_Free( prva ); | |
+ MsgDev( D_WARN, "DSP: failed to allocate delay for reverb.\n" ); | |
+ return NULL; | |
} | |
} | |
- sxrvb_size->modified = false; | |
- dly1->lp = dly2->lp = sxrvb_lp->integer; | |
- dly1->delayfeedback = dly2->delayfeedback = (int)(255 * sxrvb_feedback->value); | |
+ prva->fused = true; | |
+ prva->m = m; | |
+ prva->fparallel = fparallel; | |
+ prva->pflt = pflt2; | |
+ | |
+ return prva; | |
} | |
-/* | |
-=========== | |
-RVB_DoReverbForOneDly | |
-Do reverberation for one dly | |
-=========== | |
-*/ | |
-int RVB_DoReverbForOneDly( dly_t *dly, const int vlr, const portable_samplepair_t *samplepair ) | |
+// parallel reverberator | |
+// | |
+// for each input sample x do: | |
+// x0 = plain(D0,w0,&p0,a0,x) | |
+// x1 = plain(D1,w1,&p1,a1,x) | |
+// x2 = plain(D2,w2,&p2,a2,x) | |
+// x3 = plain(D3,w3,&p3,a3,x) | |
+// y = b0*x0 + b1*x1 + b2*x2 + b3*x3 | |
+// | |
+// rgdly - array of 6 delays: | |
+// D - Delay values (typical - 29, 37, 44, 50, 27, 31) | |
+// w - array of delayed values | |
+// p - array of pointers to circular delay line pointers | |
+// a - array of 6 feedback values (typical - all equal, like 0.75 * PMAX) | |
+// b - array of 6 gain values for plain reverb outputs (1, .9, .8, .7) | |
+// xin - input value | |
+// if fparallel, filters are built into delays, | |
+// otherwise, filter output | |
+ | |
+_inline int RVA_GetNext( rva_t *prva, int x ) | |
{ | |
- int delay; | |
- int samplexf; | |
- int val; | |
- int valt; | |
- int voutm = 0; | |
+ int m = prva->m; | |
+ int i, y, sum; | |
- if( --dly->modcur < 0 ) | |
- dly->modcur = dly->mod; | |
+ sum = 0; | |
- delay = dly->lpdelayline[dly->idelayoutput]; | |
+ for( i = 0; i < m; i++ ) | |
+ sum += DLY_GetNext( prva->pdlys[i], x ); | |
- if( dly->xfade || delay || samplepair->left || samplepair->right ) | |
+ // m is clamped between RVA_BASEM & CRVA_DLYS | |
+ | |
+ if( m ) y = sum/m; | |
+ else y = x; | |
+#if 0 | |
+ // PERFORMANCE: | |
+ // UNDONE: build as array | |
+ int mm; | |
+ | |
+ switch( m ) | |
{ | |
- // modulate delay rate | |
-#if 1 | |
- if( !dly->xfade && !dly->modcur && dly->mod ) | |
+ case 12: mm = (PMAX/12); break; | |
+ case 11: mm = (PMAX/11); break; | |
+ case 10: mm = (PMAX/10); break; | |
+ case 9: mm = (PMAX/9); break; | |
+ case 8: mm = (PMAX/8); break; | |
+ case 7: mm = (PMAX/7); break; | |
+ case 6: mm = (PMAX/6); break; | |
+ case 5: mm = (PMAX/5); break; | |
+ case 4: mm = (PMAX/4); break; | |
+ case 3: mm = (PMAX/3); break; | |
+ case 2: mm = (PMAX/2); break; | |
+ default: | |
+ case 1: mm = (PMAX/1); break; | |
+ } | |
+ | |
+ y = (sum * mm) >> PBITS; | |
+ | |
+#endif // 0 | |
+ | |
+ // run series filter if present | |
+ if( prva->pflt && !prva->fparallel ) | |
+ y = FLT_GetNext( prva->pflt, y ); | |
+ | |
+ return y; | |
+} | |
+ | |
+// batch version for performance | |
+_inline void RVA_GetNextN( rva_t *prva, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
{ | |
- dly->idelayoutputxf = dly->idelayoutput + ((Com_RandomLong( 0, 255 ) * delay) >> 9 ); | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
- //dly->xfade = 32; | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = RVA_GetNext( prva, pb->left ); | |
+ pb++; | |
} | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = RVA_GetNext( prva, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = RVA_GetNext( prva, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ } | |
+} | |
+ | |
+#define RVA_BASEM 3 // base number of parallel delays | |
+ | |
+// nominal delay and feedback values | |
+ | |
+//float rvadlys[] = { 29, 37, 44, 50, 62, 75, 96, 118, 127, 143, 164, 175 }; | |
+float rvadlys[] = { 18, 23, 28, 36, 47, 21, 26, 33, 40, 49, 45, 38 }; | |
+float rvafbs[] = { 0.7, 0.7, 0.7, 0.8, 0.8, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9 }; | |
+ | |
+// reverb parameter order | |
+typedef enum | |
+{ | |
+ // parameter order | |
+ rva_isize, | |
+ rva_idensity, | |
+ rva_idecay, | |
+ rva_iftype, | |
+ rva_icutoff, | |
+ rva_iqwidth, | |
+ rva_ifparallel, | |
+ rva_cparam // # of params | |
+} rva_e; | |
+ | |
+// filter parameter ranges | |
+prm_rng_t rva_rng[] = | |
+{ | |
+{ rva_cparam, 0, 0 }, // first entry is # of parameters | |
+ | |
+// reverb params | |
+{ rva_isize, 0.0, 2.0 }, // 0-2.0 scales nominal delay parameters (starting at approx 20ms) | |
+{ rva_idensity, 0.0, 2.0 }, // 0-2.0 density of reverbs (room shape) - controls # of parallel or series delays | |
+{ rva_idecay, 0.0, 2.0 }, // 0-2.0 scales feedback parameters (starting at approx 0.15) | |
+ | |
+// filter params for each parallel reverb (quality set to 0 for max execution speed) | |
+{ rva_iftype, 0, FTR_MAX }, | |
+{ rva_icutoff, 10, 22050 }, | |
+{ rva_iqwidth, 100, 11025 }, | |
+{ rva_ifparallel, 0, 1 } // if 1, then all filters operate in parallel with delays. otherwise filter output only | |
+}; | |
+ | |
+rva_t * RVA_Params( prc_t *pprc ) | |
+{ | |
+ flt_t *pflt; | |
+ rva_t *prva; | |
+ float size = pprc->prm[rva_isize]; // 0-2.0 controls scale of delay parameters | |
+ float density = pprc->prm[rva_idensity]; // 0-2.0 density of reverbs (room shape) - controls # of parallel delays | |
+ float decay = pprc->prm[rva_idecay]; // 0-1.0 controls feedback parameters | |
+ | |
+ float ftype = pprc->prm[rva_iftype]; | |
+ float cutoff = pprc->prm[rva_icutoff]; | |
+ float qwidth = pprc->prm[rva_iqwidth]; | |
+ | |
+ float fparallel = pprc->prm[rva_ifparallel]; | |
+ | |
+ // D array of CRVB_DLYS reverb delay sizes max sample index w[0...D] (ie: D+1 samples) | |
+ // a array of reverb feedback parms for parallel delays | |
+ // b array of CRVB_P_DLYS - mix params for parallel reverbs | |
+ // m - number of parallel delays | |
+ | |
+ int D[CRVA_DLYS]; | |
+ int a[CRVA_DLYS]; | |
+ int b[CRVA_DLYS]; | |
+ int m = RVA_BASEM; | |
+ int i; | |
+ | |
+ m = density * CRVA_DLYS / 2; | |
+ | |
+ // limit # delays 3-12 | |
+ m = bound( RVA_BASEM, m, CRVA_DLYS ); | |
+ | |
+ // average time sound takes to travel from most distant wall | |
+ // (cap at 1000 ft room) | |
+ for( i = 0; i < m; i++ ) | |
+ { | |
+ // delays of parallel reverb | |
+ D[i] = MSEC_TO_SAMPS( rvadlys[i] * size ); | |
+ | |
+ // feedback and gain of parallel reverb | |
+ a[i] = (int)min( 0.9 * PMAX, rvafbs[i] * (float)PMAX * decay ); | |
+ b[i] = PMAX; | |
+ } | |
+ | |
+ // add filter | |
+ pflt = NULL; | |
+ | |
+ if( cutoff ) | |
+ { | |
+ // set up dummy lowpass filter to convert params | |
+ prc_t prcf; | |
+ | |
+ prcf.prm[flt_iquality] = QUA_LO; // force filter to low quality for faster execution time | |
+ prcf.prm[flt_icutoff] = cutoff; | |
+ prcf.prm[flt_iftype] = ftype; | |
+ prcf.prm[flt_iqwidth] = qwidth; | |
+ | |
+ pflt = (flt_t *)FLT_Params( &prcf ); | |
+ } | |
+ | |
+ prva = RVA_Alloc( D, a, b, m, pflt, fparallel ); | |
+ FLT_Free( pflt ); | |
+ | |
+ return prva; | |
+} | |
+ | |
+_inline void *RVA_VParams( void *p ) | |
+{ | |
+ PRC_CheckParams((prc_t *)p, rva_rng ); | |
+ return (void *)RVA_Params((prc_t *)p ); | |
+} | |
+ | |
+_inline void RVA_Mod( void *p, float v ) | |
+{ | |
+} | |
+ | |
+ | |
+//////////// | |
+// Diffusor | |
+/////////// | |
+ | |
+// (N series allpass reverbs) | |
+#define CDFRS 64 // max number of series reverbs active | |
+#define CDFR_DLYS 16 // max number of delays making up diffusor | |
+ | |
+typedef struct | |
+{ | |
+ qboolean fused; | |
+ int n; // series allpass delays | |
+ int w[CDFR_DLYS]; // internal state array for series allpass filters | |
+ dly_t *pdlys[CDFR_DLYS]; // array of pointers to delays | |
+} dfr_t; | |
+ | |
+dfr_t dfrs[CDFRS]; | |
+ | |
+void DFR_Init( dfr_t *pdfr ) { if( pdfr ) Q_memset( pdfr, 0, sizeof( dfr_t )); } | |
+void DFR_InitAll( void ) { int i; for( i = 0; i < CDFRS; i++ ) DFR_Init ( &dfrs[i] ); } | |
+ | |
+// free parallel series reverb | |
+void DFR_Free( dfr_t *pdfr ) | |
+{ | |
+ if( pdfr ) | |
+ { | |
+ int i; | |
+ | |
+ // free all delays | |
+ for( i = 0; i < CDFR_DLYS; i++ ) | |
+ DLY_Free( pdfr->pdlys[i] ); | |
+ | |
+ Q_memset( pdfr, 0, sizeof( dfr_t )); | |
+ } | |
+} | |
+ | |
+ | |
+void DFR_FreeAll( void ) { int i; for( i = 0; i < CDFRS; i++ ) DFR_Free( &dfrs[i] ); } | |
+ | |
+// create n series allpass reverbs | |
+// D array of CRVB_DLYS reverb delay sizes max sample index w[0...D] (ie: D+1 samples) | |
+// a array of reverb feedback parms for series delays | |
+// b array of gain params for parallel reverbs | |
+// n - number of series delays | |
+ | |
+dfr_t *DFR_Alloc( int *D, int *a, int *b, int n ) | |
+{ | |
+ int i; | |
+ dfr_t *pdfr; | |
+ | |
+ // find open slot | |
+ for( i = 0; i < CDFRS; i++ ) | |
+ { | |
+ if( !dfrs[i].fused ) | |
+ break; | |
+ } | |
+ | |
+ // return null if no free slots | |
+ if( i == CDFRS ) | |
+ { | |
+ MsgDev( D_WARN, "DSP: failed to allocate diffusor.\n" ); | |
+ return NULL; | |
+ } | |
+ | |
+ pdfr = &dfrs[i]; | |
+ | |
+ DFR_Init( pdfr ); | |
+ | |
+ // alloc reverbs | |
+ for( i = 0; i < n; i++ ) | |
+ pdfr->pdlys[i] = DLY_Alloc( D[i], a[i], b[i], DLY_ALLPASS ); | |
+ | |
+ // if we failed to alloc any reverb, free all, return NULL | |
+ for( i = 0; i < n; i++ ) | |
+ { | |
+ if( !pdfr->pdlys[i] ) | |
+ { | |
+ DFR_Free( pdfr ); | |
+ MsgDev( D_WARN, "DSP: failed to allocate delay for diffusor.\n" ); | |
+ return NULL; | |
+ } | |
+ } | |
+ | |
+ pdfr->fused = true; | |
+ pdfr->n = n; | |
+ | |
+ return pdfr; | |
+} | |
+ | |
+// series reverberator | |
+_inline int DFR_GetNext( dfr_t *pdfr, int x ) | |
+{ | |
+ int i, y; | |
+ int n = pdfr->n; | |
+ | |
+ y = x; | |
+ for( i = 0; i < n; i++ ) | |
+ y = DLY_GetNext( pdfr->pdlys[i], y ); | |
+ return y; | |
+ | |
+#if 0 | |
+ // alternate method, using internal state - causes PREDELAY = sum of delay times | |
+ | |
+ int *v = pdfr->w; // intermediate results | |
+ | |
+ v[0] = x; | |
+ | |
+ // reverse evaluate series delays | |
+ // w[0] w[1] w[2] w[n-1] w[n] | |
+ // x---->D[0]--->D[1]--->D[2]...-->D[n-1]--->out | |
+ // | |
+ | |
+ for( i = n; i > 0; i-- ) | |
+ v[i] = DLY_GetNext( pdfr->pdlys[i-1], v[i-1] ); | |
+ | |
+ return v[n]; | |
#endif | |
+} | |
- dly->idelayoutputxf %= dly->cdelaysamplesmax; | |
+// batch version for performance | |
+_inline void DFR_GetNextN( dfr_t *pdfr, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
+{ | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
+ | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = DFR_GetNext( pdfr, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = DFR_GetNext( pdfr, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = DFR_GetNext( pdfr, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ } | |
+} | |
+#define DFR_BASEN 2 // base number of series allpass delays | |
- if( dly->xfade ) | |
+// nominal diffusor delay and feedback values | |
+//float dfrdlys[] = { 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95 }; | |
+float dfrdlys[] = { 13, 19, 26, 21, 32, 36, 38, 16, 24, 28, 41, 35, 10, 46, 50, 27 }; | |
+float dfrfbs[] = { 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15 }; | |
+ | |
+ | |
+// diffusor parameter order | |
+ | |
+typedef enum | |
{ | |
- samplexf = (dly->lpdelayline[dly->idelayoutputxf] * (32 - dly->xfade)) / 32; | |
- delay = delay * dly->xfade / 32 + samplexf; | |
+ // parameter order | |
+ dfr_isize, | |
+ dfr_idensity, | |
+ dfr_idecay, | |
+ dfr_cparam // # of params | |
- if( ++dly->idelayoutputxf >= dly->cdelaysamplesmax ) | |
- dly->idelayoutputxf = 0; | |
+} dfr_e; | |
- if( --dly->xfade == 0 ) | |
- dly->idelayoutput = dly->idelayoutputxf; | |
+// diffusor parameter ranges | |
+ | |
+prm_rng_t dfr_rng[] = | |
+{ | |
+{ dfr_cparam, 0, 0 }, // first entry is # of parameters | |
+{ dfr_isize, 0.0, 1.0 }, // 0-1.0 scales all delays | |
+{ dfr_idensity, 0.0, 1.0 }, // 0-1.0 controls # of series delays | |
+{ dfr_idecay, 0.0, 1.0 }, // 0-1.0 scales all feedback parameters | |
+}; | |
+ | |
+dfr_t *DFR_Params( prc_t *pprc ) | |
+{ | |
+ dfr_t *pdfr; | |
+ int i, s; | |
+ float size = pprc->prm[dfr_isize]; // 0-1.0 scales all delays | |
+ float density = pprc->prm[dfr_idensity]; // 0-1.0 controls # of series delays | |
+ float diffusion = pprc->prm[dfr_idecay]; // 0-1.0 scales all feedback parameters | |
+ | |
+ // D array of CRVB_DLYS reverb delay sizes max sample index w[0...D] (ie: D+1 samples) | |
+ // a array of reverb feedback parms for series delays (CRVB_S_DLYS) | |
+ // b gain of each reverb section | |
+ // n - number of series delays | |
+ | |
+ int D[CDFR_DLYS]; | |
+ int a[CDFR_DLYS]; | |
+ int b[CDFR_DLYS]; | |
+ int n = DFR_BASEN; | |
+ | |
+ // increase # of series diffusors with increased density | |
+ n += density * 2; | |
+ | |
+ // limit m, n to half max number of delays | |
+ n = min( CDFR_DLYS / 2, n ); | |
+ | |
+ // compute delays for diffusors | |
+ for( i = 0; i < n; i++ ) | |
+ { | |
+ s = (int)( dfrdlys[i] * size ); | |
+ | |
+ // delay of diffusor | |
+ D[i] = MSEC_TO_SAMPS( s ); | |
+ | |
+ // feedback and gain of diffusor | |
+ a[i] = min( 0.9 * PMAX, dfrfbs[i] * PMAX * diffusion ); | |
+ b[i] = PMAX; | |
} | |
- val = delay ? vlr + ((dly->delayfeedback * delay) >> 8) : vlr; | |
- val = CLIP(val); | |
+ pdfr = DFR_Alloc( D, a, b, n ); | |
- if( dly->lp ) | |
+ return pdfr; | |
+} | |
+ | |
+_inline void *DFR_VParams( void *p ) | |
{ | |
- valt = (dly->lp0 + val) >> 1; | |
- dly->lp0 = val; | |
+ PRC_CheckParams((prc_t *)p, dfr_rng ); | |
+ return (void *)DFR_Params((prc_t *)p ); | |
} | |
- else | |
- valt = val; | |
- voutm = dly->lpdelayline[dly->idelayinput] = valt; | |
+_inline void DFR_Mod( void *p, float v ) | |
+{ | |
} | |
- else | |
+ | |
+////////////////////// | |
+// LFO wav definitions | |
+////////////////////// | |
+ | |
+#define CLFOSAMPS 512 // samples per wav table - single cycle only | |
+#define LFOBITS 14 // bits of peak amplitude of lfo wav | |
+#define LFOAMP ((1<<LFOBITS)-1) // peak amplitude of lfo wav | |
+ | |
+//types of lfo wavs | |
+ | |
+#define LFO_SIN 0 // sine wav | |
+#define LFO_TRI 1 // triangle wav | |
+#define LFO_SQR 2 // square wave, 50% duty cycle | |
+#define LFO_SAW 3 // forward saw wav | |
+#define LFO_RND 4 // random wav | |
+#define LFO_LOG_IN 5 // logarithmic fade in | |
+#define LFO_LOG_OUT 6 // logarithmic fade out | |
+#define LFO_LIN_IN 7 // linear fade in | |
+#define LFO_LIN_OUT 8 // linear fade out | |
+#define LFO_MAX LFO_LIN_OUT | |
+ | |
+#define CLFOWAV 9 // number of LFO wav tables | |
+ | |
+typedef struct // lfo or envelope wave table | |
{ | |
- voutm = dly->lpdelayline[dly->idelayinput] = 0; | |
- dly->lp0 = dly->lp1 = 0; | |
+ int type; // lfo type | |
+ dly_t *pdly; // delay holds wav values and step pointers | |
+} lfowav_t; | |
+ | |
+lfowav_t lfowavs[CLFOWAV]; | |
+ | |
+// deallocate lfo wave table. Called only when sound engine exits. | |
+void LFOWAV_Free( lfowav_t *plw ) | |
+{ | |
+ // free delay | |
+ if( plw ) DLY_Free( plw->pdly ); | |
+ | |
+ Q_memset( plw, 0, sizeof( lfowav_t )); | |
} | |
- DLY_MovePointer( dly ); | |
+// deallocate all lfo wave tables. Called only when sound engine exits. | |
+void LFOWAV_FreeAll( void ) | |
+{ | |
+ int i; | |
- return voutm; | |
+ for( i = 0; i < CLFOWAV; i++ ) | |
+ LFOWAV_Free( &lfowavs[i] ); | |
+} | |
+// fill lfo array w with count samples of lfo type 'type' | |
+// all lfo wavs except fade out, rnd, and log_out should start with 0 output | |
+void LFOWAV_Fill( int *w, int count, int type ) | |
+{ | |
+ int i,x; | |
+ | |
+ switch( type ) | |
+ { | |
+ default: | |
+ case LFO_SIN: // sine wav, all values 0 <= x <= LFOAMP, initial value = 0 | |
+ for( i = 0; i < count; i++ ) | |
+ { | |
+ x = ( int )(( float)(LFOAMP) * sin( (M_PI2 * (float)i / (float)count ) + ( M_PI_F * 1.5 ))); | |
+ w[i] = (x + LFOAMP)/2; | |
} | |
+ break; | |
+ case LFO_TRI: // triangle wav, all values 0 <= x <= LFOAMP, initial value = 0 | |
+ for( i = 0; i < count; i++ ) | |
+ { | |
+ w[i] = ( int ) ( (float)(2 * LFOAMP * i ) / (float)(count) ); | |
-/* | |
-=========== | |
-RVB_DoReverb | |
+ if( i > count / 2 ) | |
+ w[i] = ( int )( (float) (2 * LFOAMP) - (float)( 2 * LFOAMP * i ) / (float)( count )); | |
+ } | |
+ break; | |
+ case LFO_SQR: // square wave, 50% duty cycle, all values 0 <= x <= LFOAMP, initial value = 0 | |
+ for( i = 0; i < count; i++ ) | |
+ w[i] = i > count / 2 ? 0 : LFOAMP; | |
+ break; | |
+ case LFO_SAW: // forward saw wav, aall values 0 <= x <= LFOAMP, initial value = 0 | |
+ for( i = 0; i < count; i++ ) | |
+ w[i] = ( int )( (float)(LFOAMP) * (float)i / (float)( count )); | |
+ break; | |
+ case LFO_RND: // random wav, all values 0 <= x <= LFOAMP | |
+ for( i = 0; i < count; i++ ) | |
+ w[i] = ( int )( Com_RandomLong( 0, LFOAMP )); | |
+ break; | |
+ case LFO_LOG_IN: // logarithmic fade in, all values 0 <= x <= LFOAMP, initial value = 0 | |
+ for( i = 0; i < count; i++ ) | |
+ w[i] = ( int ) ( (float)(LFOAMP) * pow( (float)i / (float)count, 2 )); | |
+ break; | |
+ case LFO_LOG_OUT: // logarithmic fade out, all values 0 <= x <= LFOAMP, initial value = LFOAMP | |
+ for( i = 0; i < count; i++ ) | |
+ w[i] = ( int ) ( (float)(LFOAMP) * pow( 1.0 - ((float)i / (float)count), 2 )); | |
+ break; | |
+ case LFO_LIN_IN: // linear fade in, all values 0 <= x <= LFOAMP, initial value = 0 | |
+ for( i = 0; i < count; i++ ) | |
+ w[i] = ( int )( (float)(LFOAMP) * (float)i / (float)(count) ); | |
+ break; | |
+ case LFO_LIN_OUT: // linear fade out, all values 0 <= x <= LFOAMP, initial value = LFOAMP | |
+ for( i = 0; i < count; i++ ) | |
+ w[i] = LFOAMP - ( int )( (float)(LFOAMP) * (float)i / (float)(count) ); | |
+ break; | |
+ } | |
+} | |
-Do reverberation processing | |
-=========== | |
-*/ | |
-void RVB_DoReverb( int count ) | |
+// allocate all lfo wave tables. Called only when sound engine loads. | |
+void LFOWAV_InitAll( void ) | |
{ | |
- int vlr; | |
- dly_t *const dly1 = &rgsxdly[REVERBPOS], | |
- *const dly2 = &rgsxdly[REVERBPOS+1]; | |
- portable_samplepair_t *paint = paintto; | |
+ int i; | |
+ dly_t *pdly; | |
- if( !dly1->lpdelayline || !count ) | |
- return; | |
+ Q_memset( lfowavs, 0, sizeof( lfowavs )); | |
- for( ; count; count--, paint++ ) | |
+ // alloc space for each lfo wav type | |
+ for( i = 0; i < CLFOWAV; i++ ) | |
{ | |
- int voutm; | |
- vlr = ( paint->left + paint->right ) >> 1; | |
+ pdly = DLY_Alloc( CLFOSAMPS, 0, 0 , DLY_PLAIN ); | |
- voutm = RVB_DoReverbForOneDly( dly1, vlr, paint ); | |
- voutm += RVB_DoReverbForOneDly( dly2, vlr, paint ); | |
+ lfowavs[i].pdly = pdly; | |
+ lfowavs[i].type = i; | |
- voutm = 11 * voutm >> 6; | |
+ LFOWAV_Fill( pdly->w, CLFOSAMPS, i ); | |
+ } | |
- paint->left = CLIP( paint->left + voutm); | |
- paint->right = CLIP( paint->right + voutm); | |
+ // if any dlys fail to alloc, free all | |
+ for( i = 0; i < CLFOWAV; i++ ) | |
+ { | |
+ if( !lfowavs[i].pdly ) | |
+ LFOWAV_FreeAll(); | |
} | |
} | |
-/* | |
-=========== | |
-RVB_DoAMod | |
-Do amplification modulation processing | |
-=========== | |
-*/ | |
-void RVB_DoAMod( int count ) | |
+//////////////////////////////////////// | |
+// LFO iterators - one shot and looping | |
+//////////////////////////////////////// | |
+ | |
+#define CLFO 16 // max active lfos (this steals from active delays) | |
+ | |
+typedef struct | |
{ | |
- portable_samplepair_t *paint = paintto; | |
+ qboolean fused; // true if slot take | |
+ dly_t *pdly; // delay points to lfo wav within lfowav_t (don't free this) | |
+ float f; // playback frequency in hz | |
+ pos_t pos; // current position within wav table, looping | |
+ pos_one_t pos1; // current position within wav table, one shot | |
+ int foneshot; // true - one shot only, don't repeat | |
+} lfo_t; | |
- if( !sxmod_lowpass->integer && !sxmod_mod->integer ) | |
- return; | |
+lfo_t lfos[CLFO]; | |
+ | |
+void LFO_Init( lfo_t *plfo ) { if( plfo ) Q_memset( plfo, 0, sizeof( lfo_t )); } | |
+void LFO_InitAll( void ) { int i; for( i = 0; i < CLFO; i++ ) LFO_Init( &lfos[i] ); } | |
+void LFO_Free( lfo_t *plfo ) { if( plfo ) Q_memset( plfo, 0, sizeof( lfo_t )); } | |
+void LFO_FreeAll( void ) { int i; for( i = 0; i < CLFO; i++ ) LFO_Free( &lfos[i] ); } | |
+ | |
+ | |
+// get step value given desired playback frequency | |
+_inline float LFO_HzToStep( float freqHz ) | |
+{ | |
+ float lfoHz; | |
+ | |
+ // calculate integer and fractional step values, | |
+ // assume an update rate of SOUND_DMA_SPEED samples/sec | |
+ | |
+ // 1 cycle/CLFOSAMPS * SOUND_DMA_SPEED samps/sec = cycles/sec = current lfo rate | |
+ // | |
+ // lforate * X = freqHz so X = freqHz/lforate = update rate | |
+ lfoHz = (float)(SOUND_DMA_SPEED) / (float)(CLFOSAMPS); | |
+ | |
+ return freqHz / lfoHz; | |
+} | |
+ | |
+// return pointer to new lfo | |
+ | |
+lfo_t *LFO_Alloc( int wtype, float freqHz, qboolean foneshot ) | |
+{ | |
+ int i, type = min( CLFOWAV - 1, wtype ); | |
+ float lfostep; | |
+ | |
+ for( i = 0; i < CLFO; i++ ) | |
+ { | |
+ if( !lfos[i].fused ) | |
+ { | |
+ lfo_t *plfo = &lfos[i]; | |
+ | |
+ LFO_Init( plfo ); | |
+ | |
+ plfo->fused = true; | |
+ plfo->pdly = lfowavs[type].pdly; // pdly in lfo points to wav table data in lfowavs | |
+ plfo->f = freqHz; | |
+ plfo->foneshot = foneshot; | |
+ | |
+ lfostep = LFO_HzToStep( freqHz ); | |
+ | |
+ // init positional pointer (ie: fixed point updater for controlling pitch of lfo) | |
+ if( !foneshot ) POS_Init(&(plfo->pos), plfo->pdly->D, lfostep ); | |
+ else POS_ONE_Init(&(plfo->pos1), plfo->pdly->D,lfostep ); | |
+ | |
+ return plfo; | |
+ } | |
+ } | |
+ | |
+ MsgDev( D_WARN, "DSP: failed to allocate LFO.\n" ); | |
+ return NULL; | |
+} | |
+ | |
+// get next lfo value | |
+// Value returned is 0..LFOAMP. can be normalized by shifting right by LFOBITS | |
+// To play back at correct passed in frequency, routien should be | |
+// called once for every output sample (ie: at SOUND_DMA_SPEED) | |
+// x is dummy param | |
+_inline int LFO_GetNext( lfo_t *plfo, int x ) | |
+{ | |
+ int i; | |
+ | |
+ // get current position | |
+ if( !plfo->foneshot ) i = POS_GetNext( &plfo->pos ); | |
+ else i = POS_ONE_GetNext( &plfo->pos1 ); | |
+ | |
+ // return current sample | |
+ return plfo->pdly->w[i]; | |
+} | |
+ | |
+// batch version for performance | |
+_inline void LFO_GetNextN( lfo_t *plfo, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
+{ | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
+ | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = LFO_GetNext( plfo, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = LFO_GetNext( plfo, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = LFO_GetNext( plfo, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ } | |
+} | |
+ | |
+// uses lfowav, rate, foneshot | |
+typedef enum | |
+{ | |
+ // parameter order | |
+ lfo_iwav, | |
+ lfo_irate, | |
+ lfo_ifoneshot, | |
+ lfo_cparam // # of params | |
+ | |
+} lfo_e; | |
+ | |
+// parameter ranges | |
+ | |
+prm_rng_t lfo_rng[] = | |
+{ | |
+{ lfo_cparam, 0, 0 }, // first entry is # of parameters | |
+{ lfo_iwav, 0.0, LFO_MAX }, // lfo type to use (LFO_SIN, LFO_RND...) | |
+{ lfo_irate, 0.0, 16000.0 }, // modulation rate in hz. for MDY, 1/rate = 'glide' time in seconds | |
+{ lfo_ifoneshot, 0.0, 1.0 }, // 1.0 if lfo is oneshot | |
+}; | |
+ | |
+lfo_t * LFO_Params( prc_t *pprc ) | |
+{ | |
+ lfo_t *plfo; | |
+ qboolean foneshot = pprc->prm[lfo_ifoneshot] > 0 ? true : false; | |
+ | |
+ plfo = LFO_Alloc( pprc->prm[lfo_iwav], pprc->prm[lfo_irate], foneshot ); | |
+ | |
+ return plfo; | |
+} | |
+ | |
+void LFO_ChangeVal( lfo_t *plfo, float fhz ) | |
+{ | |
+ float fstep = LFO_HzToStep( fhz ); | |
+ | |
+ // change lfo playback rate to new frequency fhz | |
+ if( plfo->foneshot ) POS_ChangeVal( &plfo->pos, fstep ); | |
+ else POS_ChangeVal( &plfo->pos1.p, fstep ); | |
+} | |
+ | |
+_inline void *LFO_VParams( void *p ) | |
+{ | |
+ PRC_CheckParams((prc_t *)p, lfo_rng ); | |
+ return (void *)LFO_Params((prc_t *)p); | |
+} | |
+ | |
+// v is +/- 0-1.0 | |
+// v changes current lfo frequency up/down by +/- v% | |
+_inline void LFO_Mod( lfo_t *plfo, float v ) | |
+{ | |
+ float fhz; | |
+ float fhznew; | |
+ | |
+ fhz = plfo->f; | |
+ fhznew = fhz * (1.0 + v); | |
+ | |
+ LFO_ChangeVal( plfo, fhznew ); | |
- if( !count ) | |
return; | |
+} | |
- for( ; count; count--, paint++ ) | |
+ | |
+///////////////////////////////////////////////////////////////////////////// | |
+// Ramp - used for varying smoothly between int parameters ie: modulation delays | |
+///////////////////////////////////////////////////////////////////////////// | |
+typedef struct | |
{ | |
- portable_samplepair_t res = *paint; | |
- if( sxmod_lowpass->value ) | |
+ int initval; // initial ramp value | |
+ int target; // final ramp value | |
+ int sign; // increasing (1) or decreasing (-1) ramp | |
+ int yprev; // previous output value | |
+ qboolean fhitend; // true if hit end of ramp | |
+ pos_one_t ps; // current ramp output | |
+} rmp_t; | |
+ | |
+// ramp smoothly between initial value and target value in approx 'ramptime' seconds. | |
+// (initial value may be greater or less than target value) | |
+// never changes output by more than +1 or -1 (which can cause the ramp to take longer to complete than ramptime) | |
+// called once per sample while ramping | |
+// ramptime - duration of ramp in seconds | |
+// initval - initial ramp value | |
+// targetval - target ramp value | |
+void RMP_Init( rmp_t *prmp, float ramptime, int initval, int targetval ) | |
{ | |
- res.left = rgsxlp[0] + rgsxlp[1] + rgsxlp[2] + rgsxlp[3] + rgsxlp[4] + res.left; | |
- res.right = rgsxlp[5] + rgsxlp[6] + rgsxlp[7] + rgsxlp[8] + rgsxlp[9] + res.right; | |
+ int rise; | |
+ int run; | |
- res.left >>= 2; | |
- res.right >>= 2; | |
+ if( prmp ) Q_memset( prmp, 0, sizeof( rmp_t )); | |
- rgsxlp[0] = rgsxlp[1]; | |
- rgsxlp[1] = rgsxlp[2]; | |
- rgsxlp[2] = rgsxlp[3]; | |
- rgsxlp[3] = rgsxlp[4]; | |
- rgsxlp[4] = paint->left; | |
+ run = (int)( ramptime * SOUND_DMA_SPEED ); // 'samples' in ramp | |
+ rise = (targetval - initval); // height of ramp | |
+ | |
+ // init fixed point iterator to iterate along the height of the ramp 'rise' | |
+ // always iterates from 0..'rise', increasing in value | |
+ | |
+ POS_ONE_Init( &prmp->ps, ABS( rise ), ABS((float) rise) / ((float) run)); | |
+ | |
+ prmp->yprev = initval; | |
+ prmp->initval = initval; | |
+ prmp->target = targetval; | |
+ prmp->sign = SIGN( rise ); | |
- rgsxlp[5] = rgsxlp[6]; | |
- rgsxlp[6] = rgsxlp[7]; | |
- rgsxlp[7] = rgsxlp[8]; | |
- rgsxlp[8] = rgsxlp[9]; | |
- rgsxlp[9] = paint->right; | |
} | |
- if( sxmod_mod->integer ) | |
+// continues from current position to new target position | |
+void RMP_SetNext( rmp_t *prmp, float ramptime, int targetval ) | |
{ | |
- if( --sxmod1cur < 0 ) | |
- sxmod1cur = sxmod1; | |
+ RMP_Init( prmp, ramptime, prmp->yprev, targetval ); | |
+} | |
- if( !sxmod1 ) | |
- sxamodlt = Com_RandomLong( 32, 255 ); | |
+_inline qboolean RMP_HitEnd( rmp_t *prmp ) | |
+{ | |
+ return prmp->fhitend; | |
+} | |
- if( --sxmod2cur < 0 ) | |
- sxmod2cur = sxmod2; | |
+_inline void RMP_SetEnd( rmp_t *prmp ) | |
+{ | |
+ prmp->fhitend = true; | |
+} | |
- if( !sxmod2 ) | |
-#ifndef XASH_DSP_FIXES | |
- sxamodlt = Com_RandomLong( 32, 255 ); // rt maybe??? | |
-#else | |
- sxamodrt = Com_RandomLong( 32, 255 ); | |
-#endif | |
+// get next ramp value & update ramp, never varies by more than +1 or -1 between calls | |
+// when ramp hits target value, it thereafter always returns last value | |
- res.left = (sxamodl * res.left) >> 8; | |
- res.right = (sxamodr * res.right) >> 8; | |
+_inline int RMP_GetNext( rmp_t *prmp ) | |
+{ | |
+ int y, d; | |
- if( sxamodl < sxamodlt ) | |
- sxamodl++; | |
- else if( sxamodl > sxamodlt ) | |
- sxamodl--; | |
+ // if we hit ramp end, return last value | |
+ if( prmp->fhitend ) | |
+ return prmp->yprev; | |
- if( sxamodr < sxamodrt ) | |
- sxamodr++; | |
- else if( sxamodr > sxamodrt ) | |
- sxamodr--; | |
+ // get next integer position in ramp height. | |
+ d = POS_ONE_GetNext( &prmp->ps ); | |
+ | |
+ if( prmp->ps.fhitend ) | |
+ prmp->fhitend = true; | |
+ | |
+ // increase or decrease from initval, depending on ramp sign | |
+ if( prmp->sign > 0 ) | |
+ y = prmp->initval + d; | |
+ else y = prmp->initval - d; | |
+ | |
+ // only update current height by a max of +1 or -1 | |
+ // this means that for short ramp times, we may not hit target | |
+ if( ABS( y - prmp->yprev ) >= 1 ) | |
+ prmp->yprev += prmp->sign; | |
+ | |
+ return prmp->yprev; | |
} | |
- paint->left = CLIP(res.left); | |
- paint->right = CLIP(res.right); | |
+// get current ramp value, don't update ramp | |
+_inline int RMP_GetCurrent( rmp_t *prmp ) | |
+{ | |
+ return prmp->yprev; | |
} | |
+ | |
+//////////////////////////////////////// | |
+// Time Compress/expand with pitch shift | |
+//////////////////////////////////////// | |
+ | |
+// realtime pitch shift - ie: pitch shift without change to playback rate | |
+ | |
+#define CPTCS 64 | |
+ | |
+typedef struct | |
+{ | |
+ qboolean fused; | |
+ dly_t *pdly_in; // input buffer space | |
+ dly_t *pdly_out; // output buffer space | |
+ int *pin; // input buffer (pdly_in->w) | |
+ int *pout; // output buffer (pdly_out->w) | |
+ int cin; // # samples in input buffer | |
+ int cout; // # samples in output buffer | |
+ int cxfade; // # samples in crossfade segment | |
+ int ccut; // # samples to cut | |
+ int cduplicate; // # samples to duplicate (redundant - same as ccut) | |
+ int iin; // current index into input buffer (reading) | |
+ pos_one_t psn; // stepping index through output buffer | |
+ qboolean fdup; // true if duplicating, false if cutting | |
+ float fstep; // pitch shift & time compress/expand | |
+} ptc_t; | |
+ | |
+ptc_t ptcs[CPTCS]; | |
+ | |
+void PTC_Init( ptc_t *pptc ) { if( pptc ) Q_memset( pptc, 0, sizeof( ptc_t )); }; | |
+void PTC_Free( ptc_t *pptc ) | |
+{ | |
+ if( pptc ) | |
+ { | |
+ DLY_Free( pptc->pdly_in ); | |
+ DLY_Free( pptc->pdly_out ); | |
+ | |
+ Q_memset( pptc, 0, sizeof( ptc_t )); | |
} | |
+}; | |
+void PTC_InitAll() { int i; for( i = 0; i < CPTCS; i++ ) PTC_Init( &ptcs[i] ); }; | |
+void PTC_FreeAll() { int i; for( i = 0; i < CPTCS; i++ ) PTC_Free( &ptcs[i] ); }; | |
-/* | |
-=========== | |
-DSP_Process | |
+// Time compressor/expander with pitch shift (ie: pitch changes, playback rate does not) | |
+// | |
+// Algorithm: | |
+// 1) Duplicate or discard chunks of sound to provide tslice * fstep seconds of sound. | |
+// (The user-selectable size of the buffer to process is tslice milliseconds in length) | |
+// 2) Resample this compressed/expanded buffer at fstep to produce a pitch shifted | |
+// output with the same duration as the input (ie: #samples out = # samples in, an | |
+// obvious requirement for realtime _inline processing). | |
-(xash dsp interface) | |
-=========== | |
-*/ | |
-void DSP_Process(int idsp, portable_samplepair_t *pbfront, int sampleCount) | |
+// timeslice is size in milliseconds of full buffer to process. | |
+// timeslice * fstep is the size of the expanded/compressed buffer | |
+// timexfade is length in milliseconds of crossfade region between duplicated or cut sections | |
+// fstep is % expanded/compressed sound normalized to 0.01-2.0 (1% - 200%) | |
+ | |
+// input buffer: | |
+ | |
+// iin--> | |
+ | |
+// [0... tslice ...D] input samples 0...D (D is NEWEST sample) | |
+// [0... ...n][m... tseg ...D] region to be cut or duplicated m...D | |
+ | |
+// [0... [p..txf1..n][m... tseg ...D] fade in region 1 txf1 p...n | |
+// [0... ...n][m..[q..txf2..D] fade out region 2 txf2 q...D | |
+ | |
+ | |
+// pitch up: duplicate into output buffer: tdup = tseg | |
+ | |
+// [0... ...n][m... tdup ...D][m... tdup ...D] output buffer size with duplicate region | |
+// [0... ...n][m..[p...xf1..n][m... tdup ...D] fade in p...n while fading out q...D | |
+// [0... ...n][m..[q...xf2..D][m... tdup ...D] | |
+// [0... ...n][m..[.XFADE...n][m... tdup ...D] final duplicated output buffer - resample at fstep | |
+ | |
+// pitch down: cut into output buffer: tcut = tseg | |
+ | |
+// [0... ...n][m... tcut ...D] input samples with cut region delineated m...D | |
+// [0... ...n] output buffer size after cut | |
+// [0... [q..txf2...D] fade in txf1 q...D while fade out txf2 p...n | |
+// [0... [.XFADE ...D] final cut output buffer - resample at fstep | |
+ | |
+ | |
+ptc_t * PTC_Alloc( float timeslice, float timexfade, float fstep ) | |
{ | |
- if( dsp_off->value != 0.0f ) | |
- return; | |
+ int i; | |
+ ptc_t *pptc; | |
+ float tout; | |
+ int cin, cout; | |
+ float tslice = timeslice; | |
+ float txfade = timexfade; | |
+ float tcutdup; | |
- // HACKHACK: don't process while in menu | |
- if( cls.key_dest == key_menu ) | |
- return; | |
+ // find time compressor slot | |
+ for( i = 0; i < CPTCS; i++ ) | |
+ { | |
+ if( !ptcs[i].fused ) | |
+ break; | |
+ } | |
- // preset is already installed by CheckNewDspPresets | |
- paintto = pbfront; | |
+ if( i == CPTCS ) | |
+ { | |
+ MsgDev( D_WARN, "DSP: failed to allocate pitch shifter.\n" ); | |
+ return NULL; | |
+ } | |
- RVB_DoAMod( sampleCount ); | |
- RVB_DoReverb( sampleCount ); | |
- DLY_DoDelay( sampleCount ); | |
- DLY_DoStereoDelay( sampleCount ); | |
+ pptc = &ptcs[i]; | |
+ PTC_Init( pptc ); | |
+ | |
+ // get size of region to cut or duplicate | |
+ tcutdup = abs(( fstep - 1.0 ) * timeslice ); | |
+ | |
+ // to prevent buffer overruns: | |
+ | |
+ // make sure timeslice is greater than cut/dup time | |
+ tslice = max ( tslice, 1.1 * tcutdup); | |
+ | |
+ // make sure xfade time smaller than cut/dup time, and smaller than (timeslice-cutdup) time | |
+ txfade = min( txfade, 0.9 * tcutdup ); | |
+ txfade = min( txfade, 0.9 * ( tslice - tcutdup )); | |
+ | |
+ pptc->cxfade = MSEC_TO_SAMPS( txfade ); | |
+ pptc->ccut = MSEC_TO_SAMPS( tcutdup ); | |
+ pptc->cduplicate = MSEC_TO_SAMPS( tcutdup ); | |
+ | |
+ // alloc delay lines (buffers) | |
+ tout = tslice * fstep; | |
+ | |
+ cin = MSEC_TO_SAMPS( tslice ); | |
+ cout = MSEC_TO_SAMPS( tout ); | |
+ | |
+ pptc->pdly_in = DLY_Alloc( cin, 0, 1, DLY_LINEAR ); // alloc input buffer | |
+ pptc->pdly_out = DLY_Alloc( cout, 0, 1, DLY_LINEAR ); // alloc output buffer | |
+ | |
+ if( !pptc->pdly_in || !pptc->pdly_out ) | |
+ { | |
+ PTC_Free( pptc ); | |
+ MsgDev( D_WARN, "DSP: failed to allocate delay for pitch shifter.\n" ); | |
+ return NULL; | |
} | |
+ // buffer pointers | |
+ pptc->pin = pptc->pdly_in->w; | |
+ pptc->pout = pptc->pdly_out->w; | |
-/* | |
-=========== | |
-DSP_ClearState | |
+ // input buffer index | |
+ pptc->iin = 0; | |
-(xash dsp interface) | |
-=========== | |
-*/ | |
-void DSP_ClearState( void ) | |
+ // output buffer index | |
+ POS_ONE_Init( &pptc->psn, cout, fstep ); | |
+ | |
+ // if fstep > 1.0 we're pitching shifting up, so fdup = true | |
+ pptc->fdup = fstep > 1.0 ? true : false; | |
+ | |
+ pptc->cin = cin; | |
+ pptc->cout = cout; | |
+ | |
+ pptc->fstep = fstep; | |
+ pptc->fused = true; | |
+ | |
+ return pptc; | |
+} | |
+ | |
+// linear crossfader | |
+// yfadein - instantaneous value fading in | |
+// ydafeout -instantaneous value fading out | |
+// nsamples - duration in #samples of fade | |
+// isample - index in to fade 0...nsamples-1 | |
+_inline int xfade( int yfadein, int yfadeout, int nsamples, int isample ) | |
{ | |
- Cvar_SetFloat( "room_type", 0.0f ); | |
- SX_ReloadRoomFX(); | |
+ int yout; | |
+ int m = (isample << PBITS ) / nsamples; | |
+ | |
+ yout = ((yfadein * m) >> PBITS) + ((yfadeout * (PMAX - m)) >> PBITS); | |
+ | |
+ return yout; | |
} | |
-/* | |
-=========== | |
-AllocDsps | |
+// w - pointer to start of input buffer samples | |
+// v - pointer to start of output buffer samples | |
+// cin - # of input buffer samples | |
+// cout = # of output buffer samples | |
+// cxfade = # of crossfade samples | |
+// cduplicate = # of samples in duplicate/cut segment | |
+void TimeExpand( int *w, int *v, int cin, int cout, int cxfade, int cduplicate ) | |
+{ | |
+ int i, j; | |
+ int m; | |
+ int p; | |
+ int q; | |
+ int D; | |
-(xash dsp interface) | |
-=========== | |
-*/ | |
-qboolean AllocDsps( void ) | |
+ // input buffer | |
+ // xfade source duplicate | |
+ // [0...........][p.......n][m...........D] | |
+ | |
+ // output buffer | |
+ // xfade region duplicate | |
+ // [0.....................n][m..[q.......D][m...........D] | |
+ | |
+ // D - index of last sample in input buffer | |
+ // m - index of 1st sample in duplication region | |
+ // p - index of 1st sample of crossfade source | |
+ // q - index of 1st sample in crossfade region | |
+ | |
+ D = cin - 1; | |
+ m = cin - cduplicate; | |
+ p = m - cxfade; | |
+ q = cin - cxfade; | |
+ | |
+ // copy up to crossfade region | |
+ for( i = 0; i < q; i++ ) | |
+ v[i] = w[i]; | |
+ | |
+ // crossfade region | |
+ j = p; | |
+ | |
+ for( i = q; i <= D; i++ ) | |
+ v[i] = xfade( w[j++], w[i], cxfade, i-q ); // fade out p..n, fade in q..D | |
+ | |
+ // duplicate region | |
+ j = D+1; | |
+ | |
+ for( i = m; i <= D; i++ ) | |
+ v[j++] = w[i]; | |
+ | |
+} | |
+ | |
+// cut ccut samples from end of input buffer, crossfade end of cut section | |
+// with end of remaining section | |
+ | |
+// w - pointer to start of input buffer samples | |
+// v - pointer to start of output buffer samples | |
+// cin - # of input buffer samples | |
+// cout = # of output buffer samples | |
+// cxfade = # of crossfade samples | |
+// ccut = # of samples in cut segment | |
+void TimeCompress( int *w, int *v, int cin, int cout, int cxfade, int ccut ) | |
{ | |
- SX_Init(); | |
+ int i, j; | |
+ int m; | |
+ int p; | |
+ int q; | |
+ int D; | |
- return 1; | |
+ // input buffer | |
+ // xfade source | |
+ // [0.....................n][m..[p.......D] | |
+ | |
+ // xfade region cut | |
+ // [0...........][q.......n][m...........D] | |
+ | |
+ // output buffer | |
+ // xfade to source | |
+ // [0...........][p.......D] | |
+ | |
+ // D - index of last sample in input buffer | |
+ // m - index of 1st sample in cut region | |
+ // p - index of 1st sample of crossfade source | |
+ // q - index of 1st sample in crossfade region | |
+ | |
+ D = cin - 1; | |
+ m = cin - ccut; | |
+ p = cin - cxfade; | |
+ q = m - cxfade; | |
+ | |
+ // copy up to crossfade region | |
+ | |
+ for( i = 0; i < q; i++ ) | |
+ v[i] = w[i]; | |
+ | |
+ // crossfade region | |
+ j = p; | |
+ | |
+ for( i = q; i < m; i++ ) | |
+ v[i] = xfade( w[j++], w[i], cxfade, i-q ); // fade out p..n, fade in q..D | |
+ | |
+ // skip rest of input buffer | |
} | |
-/* | |
-=========== | |
-FreeDsps | |
+// get next sample | |
-(xash dsp interface) | |
-=========== | |
-*/ | |
-void FreeDsps( void ) | |
+// put input sample into input (delay) buffer | |
+// get output sample from output buffer, step by fstep % | |
+// output buffer is time expanded or compressed version of previous input buffer | |
+_inline int PTC_GetNext( ptc_t *pptc, int x ) | |
{ | |
- SX_Free(); | |
+ int iout, xout; | |
+ qboolean fhitend = false; | |
+ | |
+ // write x into input buffer | |
+ ASSERT( pptc->iin < pptc->cin ); | |
+ | |
+ pptc->pin[pptc->iin] = x; | |
+ | |
+ pptc->iin++; | |
+ | |
+ // check for end of input buffer | |
+ if( pptc->iin >= pptc->cin ) | |
+ fhitend = true; | |
+ | |
+ // read sample from output buffer, resampling at fstep | |
+ iout = POS_ONE_GetNext( &pptc->psn ); | |
+ ASSERT( iout < pptc->cout ); | |
+ xout = pptc->pout[iout]; | |
+ | |
+ if( fhitend ) | |
+ { | |
+ // if hit end of input buffer (ie: input buffer is full) | |
+ // reset input buffer pointer | |
+ // reset output buffer pointer | |
+ // rebuild entire output buffer (TimeCompress/TimeExpand) | |
+ | |
+ pptc->iin = 0; | |
+ | |
+ POS_ONE_Init( &pptc->psn, pptc->cout, pptc->fstep ); | |
+ | |
+ if( pptc->fdup ) TimeExpand ( pptc->pin, pptc->pout, pptc->cin, pptc->cout, pptc->cxfade, pptc->cduplicate ); | |
+ else TimeCompress ( pptc->pin, pptc->pout, pptc->cin, pptc->cout, pptc->cxfade, pptc->ccut ); | |
} | |
-/* | |
-=========== | |
-CheckNewDspPresets | |
+ return xout; | |
+} | |
-(xash dsp interface) | |
-=========== | |
-*/ | |
-void CheckNewDspPresets( void ) | |
+// batch version for performance | |
+_inline void PTC_GetNextN( ptc_t *pptc, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
{ | |
- sxhires = 1; | |
- sxhiresprev = 1; | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
- if( dsp_off->value != 0.0f ) | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = PTC_GetNext( pptc, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = PTC_GetNext( pptc, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = PTC_GetNext( pptc, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ } | |
+} | |
+ | |
+// change time compression to new value | |
+// fstep is new value | |
+// ramptime is how long change takes in seconds (ramps smoothly), 0 for no ramp | |
+ | |
+void PTC_ChangeVal( ptc_t *pptc, float fstep, float ramptime ) | |
+{ | |
+// UNDONE: ignored | |
+// UNDONE: just realloc time compressor with new fstep | |
+} | |
+ | |
+// uses pitch: | |
+// 1.0 = playback normal rate | |
+// 0.5 = cut 50% of sound (2x playback) | |
+// 1.5 = add 50% sound (0.5x playback) | |
+ | |
+typedef enum | |
+{ | |
+ // parameter order | |
+ ptc_ipitch, | |
+ ptc_itimeslice, | |
+ ptc_ixfade, | |
+ ptc_cparam // # of params | |
+} ptc_e; | |
+ | |
+// diffusor parameter ranges | |
+prm_rng_t ptc_rng[] = | |
+{ | |
+{ ptc_cparam, 0, 0 }, // first entry is # of parameters | |
+{ ptc_ipitch, 0.1, 4.0 }, // 0-n.0 where 1.0 = 1 octave up and 0.5 is one octave down | |
+{ ptc_itimeslice, 20.0, 300.0 }, // in milliseconds - size of sound chunk to analyze and cut/duplicate - 100ms nominal | |
+{ ptc_ixfade, 1.0, 200.0 }, // in milliseconds - size of crossfade region between spliced chunks - 20ms nominal | |
+}; | |
+ | |
+ptc_t *PTC_Params( prc_t *pprc ) | |
+{ | |
+ ptc_t *pptc; | |
+ | |
+ float pitch = pprc->prm[ptc_ipitch]; | |
+ float timeslice = pprc->prm[ptc_itimeslice]; | |
+ float txfade = pprc->prm[ptc_ixfade]; | |
+ | |
+ pptc = PTC_Alloc( timeslice, txfade, pitch ); | |
+ | |
+ return pptc; | |
+} | |
+ | |
+_inline void *PTC_VParams( void *p ) | |
+{ | |
+ PRC_CheckParams((prc_t *)p, ptc_rng ); | |
+ return (void *)PTC_Params((prc_t *)p); | |
+} | |
+ | |
+// change to new pitch value | |
+// v is +/- 0-1.0 | |
+// v changes current pitch up/down by +/- v% | |
+void PTC_Mod( ptc_t *pptc, float v ) | |
+{ | |
+ float fstep; | |
+ float fstepnew; | |
+ | |
+ fstep = pptc->fstep; | |
+ fstepnew = fstep * (1.0 + v); | |
+ | |
+ PTC_ChangeVal( pptc, fstepnew, 0.01 ); | |
+} | |
+ | |
+ | |
+//////////////////// | |
+// ADSR envelope | |
+//////////////////// | |
+ | |
+#define CENVS 64 // max # of envelopes active | |
+#define CENVRMPS 4 // A, D, S, R | |
+ | |
+#define ENV_LIN 0 // linear a,d,s,r | |
+#define ENV_EXP 1 // exponential a,d,s,r | |
+#define ENV_MAX ENV_EXP | |
+ | |
+#define ENV_BITS 14 // bits of resolution of ramp | |
+ | |
+typedef struct | |
+{ | |
+ qboolean fused; | |
+ qboolean fhitend; // true if done | |
+ int ienv; // current ramp | |
+ rmp_t rmps[CENVRMPS]; // ramps | |
+} env_t; | |
+ | |
+env_t envs[CENVS]; | |
+ | |
+void ENV_Init( env_t *penv ) { if( penv ) Q_memset( penv, 0, sizeof( env_t )); }; | |
+void ENV_Free( env_t *penv ) { if( penv ) Q_memset( penv, 0, sizeof( env_t )); }; | |
+void ENV_InitAll() { int i; for( i = 0; i < CENVS; i++ ) ENV_Init( &envs[i] ); }; | |
+void ENV_FreeAll() { int i; for( i = 0; i < CENVS; i++ ) ENV_Free( &envs[i] ); }; | |
+ | |
+ | |
+// allocate ADSR envelope | |
+// all times are in seconds | |
+// amp1 - attack amplitude multiplier 0-1.0 | |
+// amp2 - sustain amplitude multiplier 0-1.0 | |
+// amp3 - end of sustain amplitude multiplier 0-1.0 | |
+env_t *ENV_Alloc( int type, float famp1, float famp2, float famp3, float attack, float decay, float sustain, float release ) | |
+{ | |
+ int i; | |
+ env_t *penv; | |
+ | |
+ for( i = 0; i < CENVS; i++ ) | |
+ { | |
+ if( !envs[i].fused ) | |
+ { | |
+ int amp1 = famp1 * (1 << ENV_BITS); // ramp resolution | |
+ int amp2 = famp2 * (1 << ENV_BITS); | |
+ int amp3 = famp3 * (1 << ENV_BITS); | |
+ | |
+ penv = &envs[i]; | |
+ | |
+ ENV_Init( penv ); | |
+ | |
+ // UNDONE: ignoring type = ENV_EXP - use oneshot LFOS instead with sawtooth/exponential | |
+ | |
+ // set up ramps | |
+ RMP_Init( &penv->rmps[0], attack, 0, amp1 ); | |
+ RMP_Init( &penv->rmps[1], decay, amp1, amp2 ); | |
+ RMP_Init( &penv->rmps[2], sustain, amp2, amp3 ); | |
+ RMP_Init( &penv->rmps[3], release, amp3, 0 ); | |
+ | |
+ penv->ienv = 0; | |
+ penv->fused = true; | |
+ penv->fhitend = false; | |
+ | |
+ return penv; | |
+ } | |
+ } | |
+ | |
+ MsgDev( D_WARN, "DSP: failed to allocate envelope.\n" ); | |
+ return NULL; | |
+} | |
+ | |
+_inline int ENV_GetNext( env_t *penv, int x ) | |
+{ | |
+ if( !penv->fhitend ) | |
+ { | |
+ int i, y; | |
+ | |
+ i = penv->ienv; | |
+ y = RMP_GetNext( &penv->rmps[i] ); | |
+ | |
+ // check for next ramp | |
+ if( penv->rmps[i].fhitend ) | |
+ i++; | |
+ | |
+ penv->ienv = i; | |
+ | |
+ // check for end of all ramps | |
+ if( i > 3 ) penv->fhitend = true; | |
+ | |
+ // multiply input signal by ramp | |
+ return (x * y) >> ENV_BITS; | |
+ } | |
+ return 0; | |
+} | |
+ | |
+// batch version for performance | |
+ | |
+_inline void ENV_GetNextN( env_t *penv, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
+{ | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
+ | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = ENV_GetNext( penv, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = ENV_GetNext( penv, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = ENV_GetNext( penv, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ } | |
+} | |
+ | |
+// uses lfowav, amp1, amp2, amp3, attack, decay, sustain, release | |
+// lfowav is type, currently ignored - ie: LFO_LIN_IN, LFO_LOG_IN | |
+ | |
+// parameter order | |
+typedef enum | |
+{ | |
+ env_itype, | |
+ env_iamp1, | |
+ env_iamp2, | |
+ env_iamp3, | |
+ env_iattack, | |
+ env_idecay, | |
+ env_isustain, | |
+ env_irelease, | |
+ env_cparam // # of params | |
+ | |
+} env_e; | |
+ | |
+// parameter ranges | |
+prm_rng_t env_rng[] = | |
+{ | |
+{ env_cparam, 0, 0 }, // first entry is # of parameters | |
+{ env_itype, 0.0, ENV_MAX }, // ENV_LINEAR, ENV_LOG - currently ignored | |
+{ env_iamp1, 0.0, 1.0 }, // attack peak amplitude 0-1.0 | |
+{ env_iamp2, 0.0, 1.0 }, // decay target amplitued 0-1.0 | |
+{ env_iamp3, 0.0, 1.0 }, // sustain target amplitude 0-1.0 | |
+{ env_iattack, 0.0, 20000.0 }, // attack time in milliseconds | |
+{ env_idecay, 0.0, 20000.0 }, // envelope decay time in milliseconds | |
+{ env_isustain, 0.0, 20000.0 }, // sustain time in milliseconds | |
+{ env_irelease, 0.0, 20000.0 }, // release time in milliseconds | |
+}; | |
+ | |
+env_t *ENV_Params( prc_t *pprc ) | |
+{ | |
+ env_t *penv; | |
+ | |
+ float type = pprc->prm[env_itype]; | |
+ float amp1 = pprc->prm[env_iamp1]; | |
+ float amp2 = pprc->prm[env_iamp2]; | |
+ float amp3 = pprc->prm[env_iamp3]; | |
+ float attack = pprc->prm[env_iattack] / 1000.0f; | |
+ float decay = pprc->prm[env_idecay] / 1000.0f; | |
+ float sustain = pprc->prm[env_isustain] / 1000.0f; | |
+ float release = pprc->prm[env_irelease] / 1000.0f; | |
+ | |
+ penv = ENV_Alloc( type, amp1, amp2, amp3, attack, decay, sustain, release ); | |
+ return penv; | |
+} | |
+ | |
+_inline void *ENV_VParams( void *p ) | |
+{ | |
+ PRC_CheckParams((prc_t *)p, env_rng ); | |
+ return (void *)ENV_Params((prc_t *)p); | |
+} | |
+ | |
+_inline void ENV_Mod ( void *p, float v ) | |
+{ | |
+} | |
+ | |
+//////////////////// | |
+// envelope follower | |
+//////////////////// | |
+#define CEFOS 64 // max # of envelope followers active | |
+ | |
+#define CEFOBITS 6 // size 2^6 = 64 | |
+#define CEFOWINDOW (1 << (CEFOBITS)) // size of sample window | |
+ | |
+typedef struct | |
+{ | |
+ qboolean fused; | |
+ int avg; // accumulating average over sample window | |
+ int cavg; // count down | |
+ int xout; // current output value | |
+ | |
+} efo_t; | |
+ | |
+efo_t efos[CEFOS]; | |
+ | |
+void EFO_Init( efo_t *pefo ) { if( pefo ) Q_memset( pefo, 0, sizeof( efo_t )); }; | |
+void EFO_Free( efo_t *pefo ) { if( pefo ) Q_memset( pefo, 0, sizeof( efo_t )); }; | |
+void EFO_InitAll() { int i; for( i = 0; i < CEFOS; i++ ) EFO_Init( &efos[i] ); }; | |
+void EFO_FreeAll() { int i; for( i = 0; i < CEFOS; i++ ) EFO_Free( &efos[i] ); }; | |
+ | |
+// allocate enveloper follower | |
+efo_t *EFO_Alloc( void ) | |
+{ | |
+ int i; | |
+ efo_t *pefo; | |
+ | |
+ for( i = 0; i < CEFOS; i++ ) | |
+ { | |
+ if( !efos[i].fused ) | |
+ { | |
+ pefo = &efos[i]; | |
+ | |
+ EFO_Init( pefo ); | |
+ | |
+ pefo->xout = 0; | |
+ pefo->cavg = CEFOWINDOW; | |
+ pefo->fused = true; | |
+ | |
+ return pefo; | |
+ } | |
+ } | |
+ | |
+ MsgDev( D_WARN, "DSP: failed to allocate envelope follower.\n" ); | |
+ return NULL; | |
+} | |
+ | |
+ | |
+_inline int EFO_GetNext( efo_t *pefo, int x ) | |
+{ | |
+ int xa = ABS( x ); // rectify input wav | |
+ | |
+ // get running sum / 2 | |
+ pefo->avg += xa >> 1; // divide by 2 to prevent overflow | |
+ | |
+ pefo->cavg--; | |
+ | |
+ if( !pefo->cavg ) | |
+ { | |
+ // new output value - end of window | |
+ | |
+ // get average over window | |
+ pefo->xout = pefo->avg >> (CEFOBITS - 1); // divide by window size / 2 | |
+ pefo->cavg = CEFOWINDOW; | |
+ pefo->avg = 0; | |
+ } | |
+ | |
+ return pefo->xout; | |
+} | |
+ | |
+// batch version for performance | |
+_inline void EFO_GetNextN( efo_t *pefo, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
+{ | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
+ | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = EFO_GetNext( pefo, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = EFO_GetNext( pefo, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = EFO_GetNext( pefo, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ } | |
+} | |
+ | |
+ | |
+efo_t * EFO_Params( prc_t *pprc ) | |
+{ | |
+ return EFO_Alloc(); | |
+} | |
+ | |
+_inline void *EFO_VParams( void *p ) | |
+{ | |
+ // PRC_CheckParams(( prc_t *)p, efo_rng ); - efo has no params | |
+ return (void *)EFO_Params((prc_t *)p ); | |
+} | |
+ | |
+_inline void EFO_Mod( void *p, float v ) | |
+{ | |
+} | |
+ | |
+////////////// | |
+// mod delay | |
+////////////// | |
+ | |
+// modulate delay time anywhere from 0..D using MDY_ChangeVal. no output glitches (uses RMP) | |
+ | |
+#define CMDYS 64 // max # of mod delays active (steals from delays) | |
+ | |
+typedef struct | |
+{ | |
+ qboolean fused; | |
+ qboolean fchanging; // true if modulating to new delay value | |
+ dly_t *pdly; // delay | |
+ int Dcur; // current delay value | |
+ float ramptime; // ramp 'glide' time - time in seconds to change between values | |
+ int mtime; // time in samples between delay changes. 0 implies no self-modulating | |
+ int mtimecur; // current time in samples until next delay change | |
+ float depth; // modulate delay from D to D - (D*depth) depth 0-1.0 | |
+ int xprev; // previous delay output, used to smooth transitions between delays | |
+ rmp_t rmp; // ramp | |
+} mdy_t; | |
+ | |
+mdy_t mdys[CMDYS]; | |
+ | |
+void MDY_Init( mdy_t *pmdy ) { if( pmdy ) Q_memset( pmdy, 0, sizeof( mdy_t )); }; | |
+void MDY_Free( mdy_t *pmdy ) { if( pmdy ) { DLY_Free( pmdy->pdly ); Q_memset( pmdy, 0, sizeof( mdy_t )); } }; | |
+void MDY_InitAll() { int i; for( i = 0; i < CMDYS; i++ ) MDY_Init( &mdys[i] ); }; | |
+void MDY_FreeAll() { int i; for( i = 0; i < CMDYS; i++ ) MDY_Free( &mdys[i] ); }; | |
+ | |
+ | |
+// allocate mod delay, given previously allocated dly | |
+// ramptime is time in seconds for delay to change from dcur to dnew | |
+// modtime is time in seconds between modulations. 0 if no self-modulation | |
+// depth is 0-1.0 multiplier, new delay values when modulating are Dnew = randomlong (D - D*depth, D) | |
+mdy_t *MDY_Alloc( dly_t *pdly, float ramptime, float modtime, float depth ) | |
+{ | |
+ int i; | |
+ mdy_t *pmdy; | |
+ | |
+ if( !pdly ) | |
+ return NULL; | |
+ | |
+ for( i = 0; i < CMDYS; i++ ) | |
+ { | |
+ if( !mdys[i].fused ) | |
+ { | |
+ pmdy = &mdys[i]; | |
+ | |
+ MDY_Init( pmdy ); | |
+ | |
+ pmdy->pdly = pdly; | |
+ | |
+ if( !pmdy->pdly ) | |
+ { | |
+ MsgDev( D_WARN, "DSP: failed to allocate delay for mod delay.\n" ); | |
+ return NULL; | |
+ } | |
+ | |
+ pmdy->Dcur = pdly->D0; | |
+ pmdy->fused = true; | |
+ pmdy->ramptime = ramptime; | |
+ pmdy->mtime = SEC_TO_SAMPS( modtime ); | |
+ pmdy->mtimecur = pmdy->mtime; | |
+ pmdy->depth = depth; | |
+ | |
+ return pmdy; | |
+ } | |
+ } | |
+ | |
+ MsgDev( D_WARN, "DSP: failed to allocate mod delay.\n" ); | |
+ return NULL; | |
+} | |
+ | |
+// change to new delay tap value t samples, ramp linearly over ramptime seconds | |
+void MDY_ChangeVal( mdy_t *pmdy, int t ) | |
+{ | |
+ // if D > original delay value, cap at original value | |
+ | |
+ t = min( pmdy->pdly->D0, t ); | |
+ pmdy->fchanging = true; | |
+ | |
+ RMP_Init( &pmdy->rmp, pmdy->ramptime, pmdy->Dcur, t ); | |
+} | |
+ | |
+// get next value from modulating delay | |
+int MDY_GetNext( mdy_t *pmdy, int x ) | |
+{ | |
+ int xout; | |
+ int xcur; | |
+ | |
+ // get current delay output | |
+ xcur = DLY_GetNext( pmdy->pdly, x ); | |
+ | |
+ // return right away if not modulating (not changing and not self modulating) | |
+ if( !pmdy->fchanging && !pmdy->mtime ) | |
+ { | |
+ pmdy->xprev = xcur; | |
+ return xcur; | |
+ } | |
+ | |
+ xout = xcur; | |
+ | |
+ // if currently changing to new delay target, get next delay value | |
+ if( pmdy->fchanging ) | |
+ { | |
+ // get next ramp value, test for done | |
+ int r = RMP_GetNext( &pmdy->rmp ); | |
+ | |
+ if( RMP_HitEnd( &pmdy->rmp )) | |
+ pmdy->fchanging = false; | |
+ | |
+ // if new delay different from current delay, change delay | |
+ if( r != pmdy->Dcur ) | |
+ { | |
+ // ramp never changes by more than + or - 1 | |
+ | |
+ // change delay tap value to r | |
+ DLY_ChangeVal( pmdy->pdly, r ); | |
+ | |
+ pmdy->Dcur = r; | |
+ | |
+ // filter delay output within transitions. | |
+ // note: xprev = xcur = 0 if changing delay on 1st sample | |
+ xout = ( xcur + pmdy->xprev ) >> 1; | |
+ } | |
+ } | |
+ | |
+ // if self-modulating and timer has expired, get next change | |
+ if( pmdy->mtime && !pmdy->mtimecur-- ) | |
+ { | |
+ int D0 = pmdy->pdly->D0; | |
+ int Dnew; | |
+ float D1; | |
+ | |
+ pmdy->mtimecur = pmdy->mtime; | |
+ | |
+ // modulate between 0 and 100% of d0 | |
+ D1 = (float)D0 * (1.0 - pmdy->depth); | |
+ Dnew = Com_RandomLong( (int)D1, D0 ); | |
+ | |
+ MDY_ChangeVal( pmdy, Dnew ); | |
+ } | |
+ | |
+ pmdy->xprev = xcur; | |
+ | |
+ return xout; | |
+} | |
+ | |
+// batch version for performance | |
+_inline void MDY_GetNextN( mdy_t *pmdy, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
+{ | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
+ | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = MDY_GetNext( pmdy, pb->left ); | |
+ pb++; | |
+ } | |
return; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = MDY_GetNext( pmdy, pb->right ); | |
+ pb++; | |
+ } | |
+ return; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = MDY_GetNext( pmdy, pb->left ); | |
+ pb++; | |
+ } | |
+ return; | |
+ } | |
+} | |
- if( cl.predicted.waterlevel > 2 ) | |
- idsp_room = roomwater_type->value; | |
+// parameter order | |
+typedef enum | |
+{ | |
+ mdy_idtype, // NOTE: first 8 params must match params in dly_e | |
+ mdy_idelay, | |
+ mdy_ifeedback, | |
+ mdy_igain, | |
+ mdy_iftype, | |
+ mdy_icutoff, | |
+ mdy_iqwidth, | |
+ mdy_iquality, | |
+ mdy_imodrate, | |
+ mdy_imoddepth, | |
+ mdy_imodglide, | |
+ mdy_cparam | |
+} mdy_e; | |
+ | |
+ | |
+// parameter ranges | |
+prm_rng_t mdy_rng[] = | |
+{ | |
+{ mdy_cparam, 0, 0 }, // first entry is # of parameters | |
+ | |
+// delay params | |
+{ mdy_idtype, 0, DLY_MAX }, // delay type DLY_PLAIN, DLY_LOWPASS, DLY_ALLPASS | |
+{ mdy_idelay, 0.0, 1000.0 }, // delay in milliseconds | |
+{ mdy_ifeedback, 0.0, 0.99 }, // feedback 0-1.0 | |
+{ mdy_igain, 0.0, 1.0 }, // final gain of output stage, 0-1.0 | |
+ | |
+// filter params if mdy type DLY_LOWPASS | |
+{ mdy_iftype, 0, FTR_MAX }, | |
+{ mdy_icutoff, 10.0, 22050.0 }, | |
+{ mdy_iqwidth, 100.0, 11025.0 }, | |
+{ mdy_iquality, 0, QUA_MAX }, | |
+{ mdy_imodrate, 0.01, 200.0 }, // frequency at which delay values change to new random value. 0 is no self-modulation | |
+{ mdy_imoddepth, 0.0, 1.0 }, // how much delay changes (decreases) from current value (0-1.0) | |
+{ mdy_imodglide, 0.01, 100.0 }, // glide time between dcur and dnew in milliseconds | |
+}; | |
+ | |
+// convert user parameters to internal parameters, allocate and return | |
+mdy_t *MDY_Params( prc_t *pprc ) | |
+{ | |
+ mdy_t *pmdy; | |
+ dly_t *pdly; | |
+ | |
+ float ramptime = pprc->prm[mdy_imodglide] / 1000.0; // get ramp time in seconds | |
+ float modtime = 1.0 / pprc->prm[mdy_imodrate]; // time between modulations in seconds | |
+ float depth = pprc->prm[mdy_imoddepth]; // depth of modulations 0-1.0 | |
+ | |
+ // alloc plain, allpass or lowpass delay | |
+ pdly = DLY_Params( pprc ); | |
+ if( !pdly ) return NULL; | |
+ | |
+ pmdy = MDY_Alloc( pdly, ramptime, modtime, depth ); | |
+ | |
+ return pmdy; | |
+} | |
+ | |
+_inline void * MDY_VParams( void *p ) | |
+{ | |
+ PRC_CheckParams(( prc_t *)p, mdy_rng ); | |
+ return (void *)MDY_Params ((prc_t *)p ); | |
+} | |
+ | |
+// v is +/- 0-1.0 | |
+// change current delay value 0..D | |
+void MDY_Mod( mdy_t *pmdy, float v ) | |
+{ | |
+ int D = pmdy->Dcur; | |
+ float v2 = -(v + 1.0)/2.0; // v2 varies -1.0-0.0 | |
+ | |
+ // D varies 0..D | |
+ D = D + (int)((float)D * v2); | |
+ | |
+ // change delay | |
+ MDY_ChangeVal( pmdy, D ); | |
+} | |
+ | |
+ | |
+/////////////////////////////////////////// | |
+// Chorus - lfo modulated delay | |
+/////////////////////////////////////////// | |
+ | |
+ | |
+#define CCRSS 64 // max number chorus' active | |
+ | |
+typedef struct | |
+{ | |
+ qboolean fused; | |
+ mdy_t *pmdy; // modulatable delay | |
+ lfo_t *plfo; // modulating lfo | |
+ int lfoprev; // previous modulator value from lfo | |
+ int mix; // mix of clean & chorus signal - 0..PMAX | |
+} crs_t; | |
+ | |
+crs_t crss[CCRSS]; | |
+ | |
+void CRS_Init( crs_t *pcrs ) { if( pcrs ) Q_memset( pcrs, 0, sizeof( crs_t )); }; | |
+void CRS_Free( crs_t *pcrs ) | |
+{ | |
+ if( pcrs ) | |
+ { | |
+ MDY_Free( pcrs->pmdy ); | |
+ LFO_Free( pcrs->plfo ); | |
+ Q_memset( pcrs, 0, sizeof( crs_t )); | |
+ } | |
+} | |
+ | |
+void CRS_InitAll() { int i; for( i = 0; i < CCRSS; i++ ) CRS_Init( &crss[i] ); } | |
+void CRS_FreeAll() { int i; for( i = 0; i < CCRSS; i++ ) CRS_Free( &crss[i] ); } | |
+ | |
+// fstep is base pitch shift, ie: floating point step value, where 1.0 = +1 octave, 0.5 = -1 octave | |
+// lfotype is LFO_SIN, LFO_RND, LFO_TRI etc (LFO_RND for chorus, LFO_SIN for flange) | |
+// fHz is modulation frequency in Hz | |
+// depth is modulation depth, 0-1.0 | |
+// mix is mix of chorus and clean signal | |
+ | |
+#define CRS_DELAYMAX 100 // max milliseconds of sweepable delay | |
+#define CRS_RAMPTIME 5 // milliseconds to ramp between new delay values | |
+ | |
+crs_t * CRS_Alloc( int lfotype, float fHz, float fdepth, float mix ) | |
+{ | |
+ int i, D; | |
+ crs_t *pcrs; | |
+ dly_t *pdly; | |
+ mdy_t *pmdy; | |
+ lfo_t *plfo; | |
+ float ramptime; | |
+ | |
+ // find free chorus slot | |
+ for( i = 0; i < CCRSS; i++ ) | |
+ { | |
+ if( !crss[i].fused ) | |
+ break; | |
+ } | |
+ | |
+ if( i == CCRSS ) | |
+ { | |
+ MsgDev( D_WARN, "DSP: failed to allocate chorus.\n" ); | |
+ return NULL; | |
+ } | |
+ | |
+ pcrs = &crss[i]; | |
+ CRS_Init( pcrs ); | |
+ | |
+ D = fdepth * MSEC_TO_SAMPS( CRS_DELAYMAX ); // sweep from 0 - n milliseconds | |
+ | |
+ ramptime = (float)CRS_RAMPTIME / 1000.0f; // # milliseconds to ramp between new values | |
+ | |
+ pdly = DLY_Alloc( D, 0, 1, DLY_LINEAR ); | |
+ pmdy = MDY_Alloc( pdly, ramptime, 0.0, 0.0 ); | |
+ plfo = LFO_Alloc( lfotype, fHz, false ); | |
+ | |
+ if( !plfo || !pmdy ) | |
+ { | |
+ LFO_Free( plfo ); | |
+ MDY_Free( pmdy ); | |
+ MsgDev( D_WARN, "DSP: failed to allocate lfo or mdy for chorus.\n" ); | |
+ return NULL; | |
+ } | |
+ | |
+ pcrs->pmdy = pmdy; | |
+ pcrs->plfo = plfo; | |
+ pcrs->mix = (int)( PMAX * mix ); | |
+ pcrs->fused = true; | |
+ | |
+ return pcrs; | |
+} | |
+ | |
+// return next chorused sample (modulated delay) mixed with input sample | |
+_inline int CRS_GetNext( crs_t *pcrs, int x ) | |
+{ | |
+ int l, y; | |
+ | |
+ // get current mod delay value | |
+ y = MDY_GetNext( pcrs->pmdy, x ); | |
+ | |
+ // get next lfo value for modulation | |
+ // note: lfo must return 0 as first value | |
+ l = LFO_GetNext( pcrs->plfo, x ); | |
+ | |
+ // if modulator has changed, change mdy | |
+ if( l != pcrs->lfoprev ) | |
+ { | |
+ // calculate new tap (starts at D) | |
+ int D = pcrs->pmdy->pdly->D0; | |
+ int tap; | |
+ | |
+ // lfo should always output values 0 <= l <= LFOMAX | |
+ | |
+ if( l < 0 ) l = 0; | |
+ | |
+ tap = D - ((l * D) >> LFOBITS); | |
+ MDY_ChangeVal ( pcrs->pmdy, tap ); | |
+ pcrs->lfoprev = l; | |
+ } | |
+ | |
+ return ((y * pcrs->mix) >> PBITS) + x; | |
+} | |
+ | |
+// batch version for performance | |
+_inline void CRS_GetNextN( crs_t *pcrs, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
+{ | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
+ | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = CRS_GetNext( pcrs, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = CRS_GetNext( pcrs, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = CRS_GetNext( pcrs, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ } | |
+} | |
+ | |
+// parameter order | |
+typedef enum | |
+{ | |
+ crs_ilfotype, | |
+ crs_irate, | |
+ crs_idepth, | |
+ crs_imix, | |
+ crs_cparam | |
+} crs_e; | |
+ | |
+ | |
+// parameter ranges | |
+prm_rng_t crs_rng[] = | |
+{ | |
+{ crs_cparam, 0, 0 }, // first entry is # of parameters | |
+{ crs_ilfotype, 0, LFO_MAX }, // lfotype is LFO_SIN, LFO_RND, LFO_TRI etc (LFO_RND for chorus, LFO_SIN for flange) | |
+{ crs_irate, 0.0, 1000.0 }, // rate is modulation frequency in Hz | |
+{ crs_idepth, 0.0, 1.0 }, // depth is modulation depth, 0-1.0 | |
+{ crs_imix, 0.0, 1.0 }, // mix is mix of chorus and clean signal | |
+}; | |
+ | |
+// uses pitch, lfowav, rate, depth | |
+crs_t *CRS_Params( prc_t *pprc ) | |
+{ | |
+ crs_t *pcrs; | |
+ | |
+ pcrs = CRS_Alloc( pprc->prm[crs_ilfotype], pprc->prm[crs_irate], pprc->prm[crs_idepth], pprc->prm[crs_imix] ); | |
+ | |
+ return pcrs; | |
+} | |
+ | |
+_inline void *CRS_VParams( void *p ) | |
+{ | |
+ PRC_CheckParams((prc_t *)p, crs_rng ); | |
+ return (void *)CRS_Params((prc_t *)p ); | |
+} | |
+ | |
+_inline void CRS_Mod( void *p, float v ) | |
+{ | |
+} | |
+ | |
+//////////////////////////////////////////////////// | |
+// amplifier - modulatable gain, distortion | |
+//////////////////////////////////////////////////// | |
+ | |
+#define CAMPS 64 // max number amps active | |
+#define AMPSLEW 10 // milliseconds of slew time between gain changes | |
+ | |
+typedef struct | |
+{ | |
+ qboolean fused; | |
+ float gain; // amplification 0-6.0 | |
+ float vthresh; // clip distortion threshold 0-1.0 | |
+ float distmix; // 0-1.0 mix of distortion with clean | |
+ float vfeed; // 0-1.0 feedback with distortion; | |
+ float gaintarget; // new gain | |
+ float gaindif; // incrementer | |
+} amp_t; | |
+ | |
+amp_t amps[CAMPS]; | |
+ | |
+void AMP_Init( amp_t *pamp ) { if( pamp ) Q_memset( pamp, 0, sizeof( amp_t )); } | |
+void AMP_Free( amp_t *pamp ) { if( pamp ) Q_memset( pamp, 0, sizeof( amp_t )); } | |
+void AMP_InitAll() { int i; for( i = 0; i < CAMPS; i++ ) AMP_Init( &s[i] ); } | |
+void AMP_FreeAll() { int i; for( i = 0; i < CAMPS; i++ ) AMP_Free( &s[i] ); } | |
+ | |
+amp_t *AMP_Alloc( float gain, float vthresh, float distmix, float vfeed ) | |
+{ | |
+ int i; | |
+ amp_t *pamp; | |
+ | |
+ // find free amp slot | |
+ for( i = 0; i < CAMPS; i++ ) | |
+ { | |
+ if ( !amps[i].fused ) | |
+ break; | |
+ } | |
+ | |
+ if( i == CAMPS ) | |
+ { | |
+ MsgDev( D_WARN, "DSP: failed to allocate amp.\n" ); | |
+ return NULL; | |
+ } | |
+ | |
+ pamp = &s[i]; | |
+ | |
+ AMP_Init ( pamp ); | |
+ | |
+ pamp->gain = gain; | |
+ pamp->vthresh = vthresh; | |
+ pamp->distmix = distmix; | |
+ pamp->vfeed = vfeed; | |
+ | |
+ return pamp; | |
+} | |
+ | |
+// return next amplified sample | |
+_inline int AMP_GetNext( amp_t *pamp, int x ) | |
+{ | |
+ float y = (float)x; | |
+ float yin; | |
+ float gain = pamp->gain; | |
+ | |
+ yin = y; | |
+ | |
+ // slew between gains | |
+ if( gain != pamp->gaintarget ) | |
+ { | |
+ float gaintarget = pamp->gaintarget; | |
+ float gaindif = pamp->gaindif; | |
+ | |
+ if( gain > gaintarget ) | |
+ { | |
+ gain -= gaindif; | |
+ if( gain <= gaintarget ) | |
+ pamp->gaintarget = gain; | |
+ } | |
else | |
- idsp_room = room_type->value; | |
+ { | |
+ gain += gaindif; | |
+ if( gain >= gaintarget ) | |
+ pamp->gaintarget = gain; | |
+ } | |
- if( idsp_room == room_typeprev && idsp_room == 0 ) | |
+ pamp->gain = gain; | |
+ } | |
+ | |
+ // if distortion is on, add distortion, feedback | |
+ if( pamp->vthresh < 1.0 ) | |
+ { | |
+ float fclip = pamp->vthresh * 32767.0; | |
+ | |
+ if( pamp->vfeed > 0.0 ) | |
+ { | |
+ // UNDONE: feedback | |
+ } | |
+ | |
+ // clip distort | |
+ y = ( y > fclip ? fclip : ( y < -fclip ? -fclip : y)); | |
+ | |
+ // mix distorted with clean (1.0 = full distortion) | |
+ if( pamp->distmix > 0.0 ) | |
+ y = y * pamp->distmix + yin * (1.0 - pamp->distmix); | |
+ } | |
+ | |
+ // amplify | |
+ y *= gain; | |
+ | |
+ return (int)y; | |
+} | |
+ | |
+// batch version for performance | |
+_inline void AMP_GetNextN( amp_t *pamp, portable_samplepair_t *pbuffer, int SampleCount, int op ) | |
+{ | |
+ int count = SampleCount; | |
+ portable_samplepair_t *pb = pbuffer; | |
+ | |
+ switch( op ) | |
+ { | |
+ default: | |
+ case OP_LEFT: | |
+ while( count-- ) | |
+ { | |
+ pb->left = AMP_GetNext( pamp, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_RIGHT: | |
+ while( count-- ) | |
+ { | |
+ pb->right = AMP_GetNext( pamp, pb->right ); | |
+ pb++; | |
+ } | |
+ break; | |
+ case OP_LEFT_DUPLICATE: | |
+ while( count-- ) | |
+ { | |
+ pb->left = pb->right = AMP_GetNext( pamp, pb->left ); | |
+ pb++; | |
+ } | |
+ break; | |
+ } | |
+} | |
+ | |
+_inline void AMP_Mod( amp_t *pamp, float v ) | |
+{ | |
+ float vmod = bound( v, 0.0, 1.0 ); | |
+ float samps = MSEC_TO_SAMPS( AMPSLEW ); // # samples to slew between amp values | |
+ | |
+ // ramp to new amplification value | |
+ pamp->gaintarget = pamp->gain * vmod; | |
+ | |
+ pamp->gaindif = fabs( pamp->gain - pamp->gaintarget ) / samps; | |
+ | |
+ if( pamp->gaindif == 0.0f ) | |
+ pamp->gaindif = fabs( pamp->gain - pamp->gaintarget ) / 100; | |
+} | |
+ | |
+ | |
+// parameter order | |
+typedef enum | |
+{ | |
+ amp_gain, | |
+ amp_vthresh, | |
+ amp_distmix, | |
+ amp_vfeed, | |
+ amp_cparam | |
+} amp_e; | |
+ | |
+ | |
+// parameter ranges | |
+prm_rng_t amp_rng[] = | |
+{ | |
+{ amp_cparam, 0, 0 }, // first entry is # of parameters | |
+{ amp_gain, 0.0, 10.0 }, // amplification | |
+{ amp_vthresh, 0.0, 1.0 }, // threshold for distortion (1.0 = no distortion) | |
+{ amp_distmix, 0.0, 1.0 }, // mix of clean and distortion (1.0 = full distortion, 0.0 = full clean) | |
+{ amp_vfeed, 0.0, 1.0 }, // distortion feedback | |
+}; | |
+ | |
+amp_t * AMP_Params( prc_t *pprc ) | |
+{ | |
+ amp_t *pamp; | |
+ | |
+ pamp = AMP_Alloc( pprc->prm[amp_gain], pprc->prm[amp_vthresh], pprc->prm[amp_distmix], pprc->prm[amp_vfeed] ); | |
+ | |
+ return pamp; | |
+} | |
+ | |
+_inline void *AMP_VParams( void *p ) | |
+{ | |
+ PRC_CheckParams((prc_t *)p, amp_rng ); | |
+ return (void *)AMP_Params((prc_t *)p ); | |
+} | |
+ | |
+ | |
+///////////////// | |
+// NULL processor | |
+///////////////// | |
+typedef struct | |
+{ | |
+ int type; | |
+} nul_t; | |
+ | |
+nul_t nuls[] = { 0 }; | |
+ | |
+void NULL_Init( nul_t *pnul ) { } | |
+void NULL_InitAll( ) { } | |
+void NULL_Free( nul_t *pnul ) { } | |
+void NULL_FreeAll( ) { } | |
+nul_t *NULL_Alloc( ) { return &nuls[0]; } | |
+ | |
+_inline int NULL_GetNext( void *p, int x ) { return x; } | |
+_inline void NULL_GetNextN( nul_t *pnul, portable_samplepair_t *pbuffer, int SampleCount, int op ) { return; } | |
+_inline void NULL_Mod( void *p, float v ) { return; } | |
+_inline void * NULL_VParams( void *p ) { return (void *)(&nuls[0]); } | |
+ | |
+////////////////////////// | |
+// DSP processors presets | |
+////////////////////////// | |
+ | |
+// A dsp processor (prc) performs a single-sample function, such as pitch shift, delay, reverb, filter | |
+ | |
+// note, this array must have CPRCPARMS entries | |
+#define PRMZERO 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 | |
+#define PFNZERO NULL,NULL,NULL,NULL,NULL // zero pointers for pfnparam...pdata within prc_t | |
+ | |
+////////////////// | |
+// NULL processor | |
+///////////////// | |
+ | |
+#define PRC_NULL1 { PRC_NULL, PRMZERO, PFNZERO } | |
+ | |
+#define PRC0 PRC_NULL1 | |
+ | |
+////////////// | |
+// Amplifiers | |
+////////////// | |
+ | |
+// {amp_gain, 0.0, 10.0 }, // amplification | |
+// {amp_vthresh, 0.0, 1.0 }, // threshold for distortion (1.0 = no distortion) | |
+// {amp_distmix, 0.0, 1.0 }, // mix of clean and distortion (1.0 = full distortion, 0.0 = full clean) | |
+// {amp_vfeed, 0.0, 1.0 }, // distortion feedback | |
+ | |
+// prctype gain vthresh distmix vfeed | |
+#define PRC_AMP1 {PRC_AMP, { 1.0, 1.0, 0.0, 0.0, }, PFNZERO } // modulatable unity gain amp | |
+#define PRC_AMP2 {PRC_AMP, { 1.5, 0.75, 1.0, 0.0, }, PFNZERO } // amp with light distortion | |
+#define PRC_AMP3 {PRC_AMP, { 2.0, 0.5, 1.0, 0.0, }, PFNZERO } // amp with medium distortion | |
+#define PRC_AMP4 {PRC_AMP, { 4.0, 0.25, 1.0, 0.0, }, PFNZERO } // amp with heavy distortion | |
+#define PRC_AMP5 {PRC_AMP, { 10.0, 0.10, 1.0, 0.0, }, PFNZERO } // mega distortion | |
+ | |
+#define PRC_AMP6 {PRC_AMP, { 0.1, 1.0, 0.0, 0.0, }, PFNZERO } // fade out | |
+#define PRC_AMP7 {PRC_AMP, { 0.2, 1.0, 0.0, 0.0, }, PFNZERO } // fade out | |
+#define PRC_AMP8 {PRC_AMP, { 0.3, 1.0, 0.0, 0.0, }, PFNZERO } // fade out | |
+ | |
+#define PRC_AMP9 {PRC_AMP, { 0.75, 1.0, 0.0, 0.0, }, PFNZERO } // duck out | |
+ | |
+ | |
+/////////// | |
+// Filters | |
+/////////// | |
+ | |
+// ftype: filter type FLT_LP, FLT_HP, FLT_BP (UNDONE: FLT_BP currently ignored) | |
+// cutoff: cutoff frequency in hz at -3db gain | |
+// qwidth: width of BP, or steepness of LP/HP (ie: fcutoff + qwidth = -60db gain point) | |
+// quality: QUA_LO, _MED, _HI 0,1,2 | |
+ | |
+// prctype ftype cutoff qwidth quality | |
+#define PRC_FLT1 {PRC_FLT, { FLT_LP, 3000, 1000, QUA_MED, }, PFNZERO } | |
+#define PRC_FLT2 {PRC_FLT, { FLT_LP, 2000, 2000, QUA_MED, }, PFNZERO } // lowpass for facing away | |
+#define PRC_FLT3 {PRC_FLT, { FLT_LP, 1000, 1000, QUA_MED, }, PFNZERO } | |
+#define PRC_FLT4 {PRC_FLT, { FLT_LP, 700, 700, QUA_LO, }, PFNZERO } // muffle filter | |
+ | |
+#define PRC_FLT5 {PRC_FLT, { FLT_HP, 700, 200, QUA_MED, }, PFNZERO } // highpass (bandpass pair) | |
+#define PRC_FLT6 {PRC_FLT, { FLT_HP, 2000, 1000, QUA_MED, }, PFNZERO } // lowpass (bandpass pair) | |
+ | |
+////////// | |
+// Delays | |
+////////// | |
+ | |
+// dtype: delay type DLY_PLAIN, DLY_LOWPASS, DLY_ALLPASS | |
+// delay: delay in milliseconds | |
+// feedback: feedback 0-1.0 | |
+// gain: final gain of output stage, 0-1.0 | |
+ | |
+// prctype dtype delay feedbk gain ftype cutoff qwidth quality | |
+#define PRC_DLY1 {PRC_DLY, { DLY_PLAIN, 500.0, 0.5, 0.6, 0.0, 0.0, 0.0, 0.0, }, PFNZERO } | |
+#define PRC_DLY2 {PRC_DLY, { DLY_LOWPASS, 45.0, 0.8, 0.6, FLT_LP, 3000, 3000, QUA_LO, }, PFNZERO } | |
+#define PRC_DLY3 {PRC_DLY, { DLY_LOWPASS, 300.0, 0.5, 0.6, FLT_LP, 2000, 2000, QUA_LO, }, PFNZERO } // outside S | |
+#define PRC_DLY4 {PRC_DLY, { DLY_LOWPASS, 400.0, 0.5, 0.6, FLT_LP, 1500, 1500, QUA_LO, }, PFNZERO } // outside M | |
+#define PRC_DLY5 {PRC_DLY, { DLY_LOWPASS, 750.0, 0.5, 0.6, FLT_LP, 1000, 1000, QUA_LO, }, PFNZERO } // outside L | |
+#define PRC_DLY6 {PRC_DLY, { DLY_LOWPASS, 1000.0, 0.5, 0.6, FLT_LP, 800, 400, QUA_LO, }, PFNZERO } // outside VL | |
+#define PRC_DLY7 {PRC_DLY, { DLY_LOWPASS, 45.0, 0.4, 0.5, FLT_LP, 3000, 3000, QUA_LO, }, PFNZERO } // tunnel S | |
+#define PRC_DLY8 {PRC_DLY, { DLY_LOWPASS, 55.0, 0.4, 0.5, FLT_LP, 3000, 3000, QUA_LO, }, PFNZERO } // tunnel M | |
+#define PRC_DLY9 {PRC_DLY, { DLY_LOWPASS, 65.0, 0.4, 0.5, FLT_LP, 3000, 3000, QUA_LO, }, PFNZERO } // tunnel L | |
+#define PRC_DLY10 {PRC_DLY, { DLY_LOWPASS, 150.0, 0.5, 0.6, FLT_LP, 3000, 3000, QUA_LO, }, PFNZERO } // cavern S | |
+#define PRC_DLY11 {PRC_DLY, { DLY_LOWPASS, 200.0, 0.7, 0.6, FLT_LP, 3000, 3000, QUA_LO, }, PFNZERO } // cavern M | |
+#define PRC_DLY12 {PRC_DLY, { DLY_LOWPASS, 300.0, 0.7, 0.6, FLT_LP, 3000, 3000, QUA_LO, }, PFNZERO } // cavern L | |
+#define PRC_DLY13 {PRC_DLY, { DLY_LINEAR, 300.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,}, PFNZERO } // straight delay 300ms | |
+#define PRC_DLY14 {PRC_DLY, { DLY_LINEAR, 80.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,}, PFNZERO } // straight delay 80ms | |
+ | |
+/////////// | |
+// Reverbs | |
+/////////// | |
+ | |
+// size: 0-2.0 scales nominal delay parameters (starting at approx 20ms) | |
+// density: 0-2.0 density of reverbs (room shape) - controls # of parallel or series delays | |
+// decay: 0-2.0 scales feedback parameters (starting at approx 0.15) | |
+ | |
+// prctype size density decay ftype cutoff qwidth fparallel | |
+#define PRC_RVA1 {PRC_RVA, {2.0, 0.5, 1.5, FLT_LP, 6000, 2000, 1}, PFNZERO } | |
+#define PRC_RVA2 {PRC_RVA, {1.0, 0.2, 1.5, 0, 0, 0, 0}, PFNZERO } | |
+ | |
+#define PRC_RVA3 {PRC_RVA, {0.8, 0.5, 1.5, FLT_LP, 2500, 2000, 0}, PFNZERO } // metallic S | |
+#define PRC_RVA4 {PRC_RVA, {1.0, 0.5, 1.5, FLT_LP, 2500, 2000, 0}, PFNZERO } // metallic M | |
+#define PRC_RVA5 {PRC_RVA, {1.2, 0.5, 1.5, FLT_LP, 2500, 2000, 0}, PFNZERO } // metallic L | |
+ | |
+#define PRC_RVA6 {PRC_RVA, {0.8, 0.3, 1.5, FLT_LP, 4000, 2000, 0}, PFNZERO } // tunnel S | |
+#define PRC_RVA7 {PRC_RVA, {0.9, 0.3, 1.5, FLT_LP, 4000, 2000, 0}, PFNZERO } // tunnel M | |
+#define PRC_RVA8 {PRC_RVA, {1.0, 0.3, 1.5, FLT_LP, 4000, 2000, 0}, PFNZERO } // tunnel L | |
+ | |
+#define PRC_RVA9 {PRC_RVA, {2.0, 1.5, 2.0, FLT_LP, 1500, 1500, 1}, PFNZERO } // cavern S | |
+#define PRC_RVA10 {PRC_RVA, {2.0, 1.5, 2.0, FLT_LP, 1500, 1500, 1}, PFNZERO } // cavern M | |
+#define PRC_RVA11 {PRC_RVA, {2.0, 1.5, 2.0, FLT_LP, 1500, 1500, 1}, PFNZERO } // cavern L | |
+ | |
+#define PRC_RVA12 {PRC_RVA, {2.0, 0.5, 1.5, FLT_LP, 6000, 2000, 1}, PFNZERO } // chamber S | |
+#define PRC_RVA13 {PRC_RVA, {2.0, 1.0, 1.5, FLT_LP, 6000, 2000, 1}, PFNZERO } // chamber M | |
+#define PRC_RVA14 {PRC_RVA, {2.0, 2.0, 1.5, FLT_LP, 6000, 2000, 1}, PFNZERO } // chamber L | |
+ | |
+#define PRC_RVA15 {PRC_RVA, {1.7, 1.0, 1.2, FLT_LP, 5000, 4000, 1}, PFNZERO } // brite S | |
+#define PRC_RVA16 {PRC_RVA, {1.75, 1.0, 1.5, FLT_LP, 5000, 4000, 1}, PFNZERO } // brite M | |
+#define PRC_RVA17 {PRC_RVA, {1.85, 1.0, 2.0, FLT_LP, 6000, 4000, 1}, PFNZERO } // brite L | |
+ | |
+#define PRC_RVA18 {PRC_RVA, {1.0, 1.5, 1.0, FLT_LP, 1000, 1000, 0}, PFNZERO } // generic | |
+ | |
+#define PRC_RVA19 {PRC_RVA, {1.9, 1.8, 1.25, FLT_LP, 4000, 2000, 1}, PFNZERO } // concrete S | |
+#define PRC_RVA20 {PRC_RVA, {2.0, 1.8, 1.5, FLT_LP, 3500, 2000, 1}, PFNZERO } // concrete M | |
+#define PRC_RVA21 {PRC_RVA, {2.0, 1.8, 1.75, FLT_LP, 3000, 2000, 1}, PFNZERO } // concrete L | |
+ | |
+#define PRC_RVA22 {PRC_RVA, {1.8, 1.5, 1.5, FLT_LP, 1000, 1000, 0}, PFNZERO } // water S | |
+#define PRC_RVA23 {PRC_RVA, {1.9, 1.75, 1.5, FLT_LP, 1000, 1000, 0}, PFNZERO } // water M | |
+#define PRC_RVA24 {PRC_RVA, {2.0, 2.0, 1.5, FLT_LP, 1000, 1000, 0}, PFNZERO } // water L | |
+ | |
+ | |
+///////////// | |
+// Diffusors | |
+///////////// | |
+ | |
+// size: 0-1.0 scales all delays | |
+// density: 0-1.0 controls # of series delays | |
+// decay: 0-1.0 scales all feedback parameters | |
+ | |
+// prctype size density decay | |
+#define PRC_DFR1 {PRC_DFR, { 1.0, 0.5, 1.0 }, PFNZERO } | |
+#define PRC_DFR2 {PRC_DFR, { 0.5, 0.3, 0.5 }, PFNZERO } // S | |
+#define PRC_DFR3 {PRC_DFR, { 0.75, 0.5, 0.75 }, PFNZERO } // M | |
+#define PRC_DFR4 {PRC_DFR, { 1.0, 0.5, 1.0 }, PFNZERO } // L | |
+#define PRC_DFR5 {PRC_DFR, { 1.0, 1.0, 1.0 }, PFNZERO } // VL | |
+ | |
+//////// | |
+// LFOs | |
+//////// | |
+ | |
+// wavtype: lfo type to use (LFO_SIN, LFO_RND...) | |
+// rate: modulation rate in hz. for MDY, 1/rate = 'glide' time in seconds | |
+// foneshot: 1.0 if lfo is oneshot | |
+ | |
+// prctype wavtype rate foneshot | |
+#define PRC_LFO1 {PRC_LFO, { LFO_SIN, 440.0, 0.0, }, PFNZERO} | |
+#define PRC_LFO2 {PRC_LFO, { LFO_SIN, 3000.0, 0.0, }, PFNZERO} // ear noise ring | |
+#define PRC_LFO3 {PRC_LFO, { LFO_SIN, 4500.0, 0.0, }, PFNZERO} // ear noise ring | |
+#define PRC_LFO4 {PRC_LFO, { LFO_SIN, 6000.0, 0.0, }, PFNZERO} // ear noise ring | |
+#define PRC_LFO5 {PRC_LFO, { LFO_SAW, 100.0, 0.0, }, PFNZERO} // sub bass | |
+ | |
+///////// | |
+// Pitch | |
+///////// | |
+ | |
+// pitch: 0-n.0 where 1.0 = 1 octave up and 0.5 is one octave down | |
+// timeslice: in milliseconds - size of sound chunk to analyze and cut/duplicate - 100ms nominal | |
+// xfade: in milliseconds - size of crossfade region between spliced chunks - 20ms nominal | |
+ | |
+// prctype pitch timeslice xfade | |
+#define PRC_PTC1 {PRC_PTC, { 1.1, 100.0, 20.0 }, PFNZERO} // pitch up 10% | |
+#define PRC_PTC2 {PRC_PTC, { 0.9, 100.0, 20.0 }, PFNZERO} // pitch down 10% | |
+#define PRC_PTC3 {PRC_PTC, { 0.95, 100.0, 20.0 }, PFNZERO} // pitch down 5% | |
+#define PRC_PTC4 {PRC_PTC, { 1.01, 100.0, 20.0 }, PFNZERO} // pitch up 1% | |
+#define PRC_PTC5 {PRC_PTC, { 0.5, 100.0, 20.0 }, PFNZERO} // pitch down 50% | |
+ | |
+///////////// | |
+// Envelopes | |
+///////////// | |
+ | |
+// etype: ENV_LINEAR, ENV_LOG - currently ignored | |
+// amp1: attack peak amplitude 0-1.0 | |
+// amp2: decay target amplitued 0-1.0 | |
+// amp3: sustain target amplitude 0-1.0 | |
+// attack time in milliseconds | |
+// envelope decay time in milliseconds | |
+// sustain time in milliseconds | |
+// release time in milliseconds | |
+ | |
+// prctype etype amp1 amp2 amp3 attack decay sustain release | |
+#define PRC_ENV1 {PRC_ENV, {ENV_LIN, 1.0, 0.5, 0.4, 500, 500, 3000, 6000 }, PFNZERO} | |
+ | |
+ | |
+////////////// | |
+// Mod delays | |
+////////////// | |
+ | |
+// dtype: delay type DLY_PLAIN, DLY_LOWPASS, DLY_ALLPASS | |
+// delay: delay in milliseconds | |
+// feedback: feedback 0-1.0 | |
+// gain: final gain of output stage, 0-1.0 | |
+ | |
+// modrate: frequency at which delay values change to new random value. 0 is no self-modulation | |
+// moddepth: how much delay changes (decreases) from current value (0-1.0) | |
+// modglide: glide time between dcur and dnew in milliseconds | |
+ | |
+// prctype dtype delay feedback gain ftype cutoff qwidth qual modrate moddepth modglide | |
+#define PRC_MDY1 {PRC_MDY, {DLY_PLAIN, 500.0, 0.5, 1.0, 0, 0, 0, 0, 10, 0.8, 5,}, PFNZERO} | |
+#define PRC_MDY2 {PRC_MDY, {DLY_PLAIN, 50.0, 0.8, 1.0, 0, 0, 0, 0, 5, 0.8, 5,}, PFNZERO} | |
+ | |
+#define PRC_MDY3 {PRC_MDY, {DLY_PLAIN, 300.0, 0.2, 1.0, 0, 0, 0, 0, 30, 0.01, 15,}, PFNZERO } // weird 1 | |
+#define PRC_MDY4 {PRC_MDY, {DLY_PLAIN, 400.0, 0.3, 1.0, 0, 0, 0, 0, 0.25, 0.01, 15,}, PFNZERO } // weird 2 | |
+#define PRC_MDY5 {PRC_MDY, {DLY_PLAIN, 500.0, 0.4, 1.0, 0, 0, 0, 0, 0.25, 0.01, 15,}, PFNZERO } // weird 3 | |
+ | |
+////////// | |
+// Chorus | |
+////////// | |
+ | |
+// lfowav: lfotype is LFO_SIN, LFO_RND, LFO_TRI etc (LFO_RND for chorus, LFO_SIN for flange) | |
+// rate: rate is modulation frequency in Hz | |
+// depth: depth is modulation depth, 0-1.0 | |
+// mix: mix is mix of chorus and clean signal | |
+ | |
+// prctype lfowav rate depth mix | |
+#define PRC_CRS1 {PRC_CRS, { LFO_SIN, 10, 1.0, 0.5, }, PFNZERO } | |
+ | |
+///////////////////// | |
+// Envelope follower | |
+///////////////////// | |
+ | |
+// takes no parameters | |
+#define PRC_EFO1 {PRC_EFO, { PRMZERO }, PFNZERO } | |
+ | |
+// init array of processors - first store pfnParam, pfnGetNext and pfnFree functions for type, | |
+// then call the pfnParam function to initialize each processor | |
+ | |
+// prcs - an array of prc structures, all with initialized params | |
+// count - number of elements in the array | |
+// returns false if failed to init one or more processors | |
+ | |
+qboolean PRC_InitAll( prc_t *prcs, int count ) | |
+{ | |
+ int i; | |
+ prc_Param_t pfnParam; // allocation function - takes ptr to prc, returns ptr to specialized data struct for proc type | |
+ prc_GetNext_t pfnGetNext; // get next function | |
+ prc_GetNextN_t pfnGetNextN; // get next function, batch version | |
+ prc_Free_t pfnFree; | |
+ prc_Mod_t pfnMod; | |
+ qboolean fok = true; | |
+ | |
+ // set up pointers to XXX_Free, XXX_GetNext and XXX_Params functions | |
+ | |
+ for( i = 0; i < count; i++ ) | |
+ { | |
+ switch (prcs[i].type) | |
+ { | |
+ case PRC_DLY: | |
+ pfnFree = &(prc_Free_t)DLY_Free; | |
+ pfnGetNext = &(prc_GetNext_t)DLY_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)DLY_GetNextN; | |
+ pfnParam = &DLY_VParams; | |
+ pfnMod = &(prc_Mod_t)DLY_Mod; | |
+ break; | |
+ case PRC_RVA: | |
+ pfnFree = &(prc_Free_t)RVA_Free; | |
+ pfnGetNext = &(prc_GetNext_t)RVA_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)RVA_GetNextN; | |
+ pfnParam = &RVA_VParams; | |
+ pfnMod = &(prc_Mod_t)RVA_Mod; | |
+ break; | |
+ case PRC_FLT: | |
+ pfnFree = &(prc_Free_t)FLT_Free; | |
+ pfnGetNext = &(prc_GetNext_t)FLT_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)FLT_GetNextN; | |
+ pfnParam = &FLT_VParams; | |
+ pfnMod = &(prc_Mod_t)FLT_Mod; | |
+ break; | |
+ case PRC_CRS: | |
+ pfnFree = &(prc_Free_t)CRS_Free; | |
+ pfnGetNext = &(prc_GetNext_t)CRS_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)CRS_GetNextN; | |
+ pfnParam = &CRS_VParams; | |
+ pfnMod = &(prc_Mod_t)CRS_Mod; | |
+ break; | |
+ case PRC_PTC: | |
+ pfnFree = &(prc_Free_t)PTC_Free; | |
+ pfnGetNext = &(prc_GetNext_t)PTC_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)PTC_GetNextN; | |
+ pfnParam = &PTC_VParams; | |
+ pfnMod = &(prc_Mod_t)PTC_Mod; | |
+ break; | |
+ case PRC_ENV: | |
+ pfnFree = &(prc_Free_t)ENV_Free; | |
+ pfnGetNext = &(prc_GetNext_t)ENV_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)ENV_GetNextN; | |
+ pfnParam = &ENV_VParams; | |
+ pfnMod = &(prc_Mod_t)ENV_Mod; | |
+ break; | |
+ case PRC_LFO: | |
+ pfnFree = &(prc_Free_t)LFO_Free; | |
+ pfnGetNext = &(prc_GetNext_t)LFO_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)LFO_GetNextN; | |
+ pfnParam = &LFO_VParams; | |
+ pfnMod = &(prc_Mod_t)LFO_Mod; | |
+ break; | |
+ case PRC_EFO: | |
+ pfnFree = &(prc_Free_t)EFO_Free; | |
+ pfnGetNext = &(prc_GetNext_t)EFO_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)EFO_GetNextN; | |
+ pfnParam = &EFO_VParams; | |
+ pfnMod = &(prc_Mod_t)EFO_Mod; | |
+ break; | |
+ case PRC_MDY: | |
+ pfnFree = &(prc_Free_t)MDY_Free; | |
+ pfnGetNext = &(prc_GetNext_t)MDY_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)MDY_GetNextN; | |
+ pfnParam = &MDY_VParams; | |
+ pfnMod = &(prc_Mod_t)MDY_Mod; | |
+ break; | |
+ case PRC_DFR: | |
+ pfnFree = &(prc_Free_t)DFR_Free; | |
+ pfnGetNext = &(prc_GetNext_t)DFR_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)DFR_GetNextN; | |
+ pfnParam = &DFR_VParams; | |
+ pfnMod = &(prc_Mod_t)DFR_Mod; | |
+ break; | |
+ case PRC_AMP: | |
+ pfnFree = &(prc_Free_t)AMP_Free; | |
+ pfnGetNext = &(prc_GetNext_t)AMP_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)AMP_GetNextN; | |
+ pfnParam = &_VParams; | |
+ pfnMod = &(prc_Mod_t)AMP_Mod; | |
+ break; | |
+ case PRC_NULL: | |
+ default: | |
+ pfnFree = &(prc_Free_t)NULL_Free; | |
+ pfnGetNext = &(prc_GetNext_t)NULL_GetNext; | |
+ pfnGetNextN = &(prc_GetNextN_t)NULL_GetNextN; | |
+ pfnParam = &NULL_VParams; | |
+ pfnMod = &(prc_Mod_t)NULL_Mod; | |
+ break; | |
+ } | |
+ | |
+ // set up function pointers | |
+ prcs[i].pfnParam = pfnParam; | |
+ prcs[i].pfnGetNext = pfnGetNext; | |
+ prcs[i].pfnGetNextN = pfnGetNextN; | |
+ prcs[i].pfnFree = pfnFree; | |
+ | |
+ // call param function, store pdata for the processor type | |
+ prcs[i].pdata = pfnParam((void *)( &prcs[i] )); | |
+ | |
+ if( !prcs[i].pdata ) | |
+ fok = false; | |
+ } | |
+ return fok; | |
+} | |
+ | |
+// free individual processor's data | |
+void PRC_Free( prc_t *pprc ) | |
+{ | |
+ if( pprc->pfnFree && pprc->pdata ) | |
+ pprc->pfnFree( pprc->pdata ); | |
+} | |
+ | |
+// free all processors for supplied array | |
+// prcs - array of processors | |
+// count - elements in array | |
+void PRC_FreeAll( prc_t *prcs, int count ) | |
+{ | |
+ int i; | |
+ | |
+ for( i = 0; i < count; i++ ) | |
+ PRC_Free( &prcs[i] ); | |
+} | |
+ | |
+// get next value for processor - (usually called directly by PSET_GetNext) | |
+_inline int PRC_GetNext( prc_t *pprc, int x ) | |
+{ | |
+ return pprc->pfnGetNext( pprc->pdata, x ); | |
+} | |
+ | |
+// automatic parameter range limiting | |
+// force parameters between specified min/max in param_rng | |
+void PRC_CheckParams( prc_t *pprc, prm_rng_t *prng ) | |
+{ | |
+ // first entry in param_rng is # of parameters | |
+ int cprm = prng[0].iprm; | |
+ int i; | |
+ | |
+ for( i = 0; i < cprm; i++) | |
+ { | |
+ // if parameter is 0.0f, always allow it (this is 'off' for most params) | |
+ if( pprc->prm[i] != 0.0f && ( pprc->prm[i] > prng[i+1].hi || pprc->prm[i] < prng[i+1].lo )) | |
+ { | |
+ MsgDev( D_WARN, "DSP: clamping out of range parameter.\n" ); | |
+ pprc->prm[i] = bound( prng[i+1].lo, pprc->prm[i], prng[i+1].hi ); | |
+ } | |
+ } | |
+} | |
+ | |
+// DSP presets | |
+// A dsp preset comprises one or more dsp processors in linear, parallel or feedback configuration | |
+// preset configurations | |
+// | |
+#define PSET_SIMPLE 0 | |
+ | |
+// x(n)--->P(0)--->y(n) | |
+#define PSET_LINEAR 1 | |
+ | |
+// x(n)--->P(0)-->P(1)-->...P(m)--->y(n) | |
+#define PSET_PARALLEL6 4 | |
+ | |
+// x(n)-P(0)-->P(1)-->P(2)-->(+)-P(5)->y(n) | |
+// | ^ | |
+// | | | |
+// -->P(3)-->P(4)----> | |
+ | |
+ | |
+#define PSET_PARALLEL2 5 | |
+ | |
+// x(n)--->P(0)-->(+)-->y(n) | |
+// ^ | |
+// | | |
+// x(n)--->P(1)----- | |
+ | |
+#define PSET_PARALLEL4 6 | |
+ | |
+// x(n)--->P(0)-->P(1)-->(+)-->y(n) | |
+// ^ | |
+// | | |
+// x(n)--->P(2)-->P(3)----- | |
+ | |
+#define PSET_PARALLEL5 7 | |
+ | |
+// x(n)--->P(0)-->P(1)-->(+)-->P(4)-->y(n) | |
+// ^ | |
+// | | |
+// x(n)--->P(2)-->P(3)----- | |
+ | |
+#define PSET_FEEDBACK 8 | |
+ | |
+// x(n)-P(0)--(+)-->P(1)-->P(2)-->P(5)->y(n) | |
+// ^ | | |
+// | v | |
+// -----P(4)<--P(3)-- | |
+ | |
+#define PSET_FEEDBACK3 9 | |
+ | |
+// x(n)---(+)-->P(0)--------->y(n) | |
+// ^ | | |
+// | v | |
+// -----P(2)<--P(1)-- | |
+ | |
+#define PSET_FEEDBACK4 10 | |
+ | |
+// x(n)---(+)-->P(0)-------->P(3)--->y(n) | |
+// ^ | | |
+// | v | |
+// ---P(2)<--P(1)-- | |
+ | |
+#define PSET_MOD 11 | |
+ | |
+// | |
+// x(n)------>P(1)--P(2)--P(3)--->y(n) | |
+// ^ | |
+// x(n)------>P(0)....: | |
+ | |
+#define PSET_MOD2 12 | |
+ | |
+// | |
+// x(n)-------P(1)-->y(n) | |
+// ^ | |
+// x(n)-->P(0)..: | |
+ | |
+ | |
+#define PSET_MOD3 13 | |
+ | |
+// | |
+// x(n)-------P(1)-->P(2)-->y(n) | |
+// ^ | |
+// x(n)-->P(0)..: | |
+ | |
+ | |
+#define CPSETS 64 // max number of presets simultaneously active | |
+ | |
+#define CPSET_PRCS 6 // max # of processors per dsp preset | |
+#define CPSET_STATES (CPSET_PRCS+3) // # of internal states | |
+ | |
+// NOTE: do not reorder members of pset_t - psettemplates relies on it!!! | |
+typedef struct | |
+{ | |
+ int type; // preset configuration type | |
+ int cprcs; // number of processors for this preset | |
+ prc_t prcs[CPSET_PRCS]; // processor preset data | |
+ float gain; // preset gain 0.1->2.0 | |
+ int w[CPSET_STATES]; // internal states | |
+ int fused; | |
+} pset_t; | |
+ | |
+pset_t psets[CPSETS]; | |
+ | |
+// array of dsp presets, each with up to 6 processors per preset | |
+ | |
+#define WZERO {0,0,0,0,0,0,0,0,0}, 0 | |
+ | |
+pset_t psettemplates[] = | |
+{ | |
+// presets 0-29 map to legacy room_type 0-29 | |
+ | |
+// type # proc P0 P1 P2 P3 P4 P5 GAIN | |
+{PSET_SIMPLE, 1, { PRC_NULL1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // OFF 0 | |
+{PSET_SIMPLE, 1, { PRC_RVA18, PRC0, PRC0, PRC0, PRC0, PRC0 },1.4, WZERO }, // GENERIC 1 // general, low reflective, diffuse room | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA3, PRC0, PRC0, PRC0, PRC0 },1.4, WZERO }, // METALIC_S 2 // highly reflective, parallel surfaces | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA4, PRC0, PRC0, PRC0, PRC0 },1.4, WZERO }, // METALIC_M 3 | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA5, PRC0, PRC0, PRC0, PRC0 },1.4, WZERO }, // METALIC_L 4 | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA6, PRC0, PRC0, PRC0, PRC0 },2.0, WZERO }, // TUNNEL_S 5 // resonant reflective, long surfaces | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA7, PRC0, PRC0, PRC0, PRC0 },1.8, WZERO }, // TUNNEL_M 6 | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA8, PRC0, PRC0, PRC0, PRC0 },1.7, WZERO }, // TUNNEL_L 7 | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA12,PRC0, PRC0, PRC0, PRC0 },1.7, WZERO }, // CHAMBER_S 8 // diffuse, moderately reflective surfaces | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA13,PRC0, PRC0, PRC0, PRC0 },1.7, WZERO }, // CHAMBER_M 9 | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA14,PRC0, PRC0, PRC0, PRC0 },1.9, WZERO }, // CHAMBER_L 10 | |
+{PSET_SIMPLE, 1, { PRC_RVA15, PRC0, PRC0, PRC0, PRC0, PRC0 },1.5, WZERO }, // BRITE_S 11 // diffuse, highly reflective | |
+{PSET_SIMPLE, 1, { PRC_RVA16, PRC0, PRC0, PRC0, PRC0, PRC0 },1.6, WZERO }, // BRITE_M 12 | |
+{PSET_SIMPLE, 1, { PRC_RVA17, PRC0, PRC0, PRC0, PRC0, PRC0 },1.7, WZERO }, // BRITE_L 13 | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA22,PRC0, PRC0, PRC0, PRC0 },1.8, WZERO }, // WATER1 14 // underwater fx | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA23,PRC0, PRC0, PRC0, PRC0 },1.8, WZERO }, // WATER2 15 | |
+{PSET_LINEAR, 3, { PRC_DFR1, PRC_RVA24,PRC_MDY5, PRC0, PRC0, PRC0 },1.8, WZERO }, // WATER3 16 | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA19,PRC0, PRC0, PRC0, PRC0 },1.7, WZERO }, // CONCRTE_S 17 // bare, reflective, parallel surfaces | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA20,PRC0, PRC0, PRC0, PRC0 },1.8, WZERO }, // CONCRTE_M 18 | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA21,PRC0, PRC0, PRC0, PRC0 },1.9, WZERO }, // CONCRTE_L 19 | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_DLY3, PRC0, PRC0, PRC0, PRC0 },1.7, WZERO }, // OUTSIDE1 20 // echoing, moderately reflective | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_DLY4, PRC0, PRC0, PRC0, PRC0 },1.7, WZERO }, // OUTSIDE2 21 // echoing, dull | |
+{PSET_LINEAR, 3, { PRC_DFR1, PRC_DFR1, PRC_DLY5, PRC0, PRC0, PRC0 },1.6, WZERO }, // OUTSIDE3 22 // echoing, very dull | |
+{PSET_LINEAR, 2, { PRC_DLY10, PRC_RVA10,PRC0, PRC0, PRC0, PRC0 },2.8, WZERO }, // CAVERN_S 23 // large, echoing area | |
+{PSET_LINEAR, 2, { PRC_DLY11, PRC_RVA10,PRC0, PRC0, PRC0, PRC0 },2.6, WZERO }, // CAVERN_M 24 | |
+{PSET_LINEAR, 3, { PRC_DFR1, PRC_DLY12,PRC_RVA11,PRC0, PRC0, PRC0 },2.6, WZERO }, // CAVERN_L 25 | |
+{PSET_LINEAR, 2, { PRC_DLY7, PRC_DFR1, PRC0, PRC0, PRC0, PRC0 },2.0, WZERO }, // WEIRDO1 26 | |
+{PSET_LINEAR, 2, { PRC_DLY8, PRC_DFR1, PRC0, PRC0, PRC0, PRC0 },1.9, WZERO }, // WEIRDO2 27 | |
+{PSET_LINEAR, 2, { PRC_DLY9, PRC_DFR1, PRC0, PRC0, PRC0, PRC0 },1.8, WZERO }, // WEIRDO3 28 | |
+{PSET_LINEAR, 2, { PRC_DLY9, PRC_DFR1, PRC0, PRC0, PRC0, PRC0 },1.8, WZERO }, // WEIRDO4 29 | |
+ | |
+// presets 30-40 are new presets | |
+{PSET_SIMPLE, 1, { PRC_FLT2, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 30 lowpass - facing away | |
+{PSET_LINEAR, 2, { PRC_FLT3, PRC_DLY14,PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 31 lowpass - facing away+80ms delay | |
+//{PSET_PARALLEL2,2, { PRC_AMP6, PRC_LFO2, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 32 explosion ring 1 | |
+//{PSET_PARALLEL2,2, { PRC_AMP7, PRC_LFO3, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 33 explosion ring 2 | |
+//{PSET_PARALLEL2,2, { PRC_AMP8, PRC_LFO4, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 34 explosion ring 3 | |
+{PSET_LINEAR, 3, { PRC_DFR1, PRC_DFR1, PRC_FLT3, PRC0, PRC0, PRC0 },0.25, WZERO }, // 32 explosion ring | |
+{PSET_LINEAR, 3, { PRC_DFR1, PRC_DFR1, PRC_FLT3, PRC0, PRC0, PRC0 },0.25, WZERO }, // 33 explosion ring 2 | |
+{PSET_LINEAR, 3, { PRC_DFR1, PRC_DFR1, PRC_FLT3, PRC0, PRC0, PRC0 },0.25, WZERO }, // 34 explosion ring 3 | |
+{PSET_PARALLEL2,2, { PRC_DFR1, PRC_LFO2, PRC0, PRC0, PRC0, PRC0 },0.25, WZERO }, // 35 shock muffle 1 | |
+{PSET_PARALLEL2,2, { PRC_DFR1, PRC_LFO2, PRC0, PRC0, PRC0, PRC0 },0.25, WZERO }, // 36 shock muffle 2 | |
+{PSET_PARALLEL2,2, { PRC_DFR1, PRC_LFO2, PRC0, PRC0, PRC0, PRC0 },0.25, WZERO }, // 37 shock muffle 3 | |
+//{PSET_LINEAR, 3, { PRC_DFR1, PRC_LFO4, PRC_FLT3, PRC0, PRC0, PRC0 },1.0, WZERO }, // 35 shock muffle 1 | |
+//{PSET_LINEAR, 3, { PRC_DFR1, PRC_LFO4, PRC_FLT3, PRC0, PRC0, PRC0 },1.0, WZERO }, // 36 shock muffle 2 | |
+//{PSET_LINEAR, 3, { PRC_DFR1, PRC_LFO4, PRC_FLT3, PRC0, PRC0, PRC0 },1.0, WZERO }, // 37 shock muffle 3 | |
+{PSET_FEEDBACK3,3, { PRC_DLY13, PRC_PTC4, PRC_FLT2, PRC0, PRC0, PRC0 },0.25, WZERO }, // 38 fade pitchdown 1 | |
+{PSET_LINEAR, 3, { PRC_AMP3, PRC_FLT5, PRC_FLT6, PRC0, PRC0, PRC0 },2.0, WZERO }, // 39 distorted speaker 1 | |
+ | |
+// fade out fade in | |
+ | |
+// presets 40+ are test presets | |
+{PSET_SIMPLE, 1, { PRC_NULL1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 39 null | |
+{PSET_SIMPLE, 1, { PRC_DLY1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 40 delay | |
+{PSET_SIMPLE, 1, { PRC_RVA1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 41 parallel reverb | |
+{PSET_SIMPLE, 1, { PRC_DFR1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 42 series diffusor | |
+{PSET_LINEAR, 2, { PRC_DFR1, PRC_RVA1, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 43 diff & reverb | |
+{PSET_SIMPLE, 1, { PRC_DLY2, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 44 lowpass delay | |
+{PSET_SIMPLE, 1, { PRC_MDY2, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 45 modulating delay | |
+{PSET_SIMPLE, 1, { PRC_PTC1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 46 pitch shift | |
+{PSET_SIMPLE, 1, { PRC_PTC2, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 47 pitch shift | |
+{PSET_SIMPLE, 1, { PRC_FLT1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 48 filter | |
+{PSET_SIMPLE, 1, { PRC_CRS1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 49 chorus | |
+{PSET_SIMPLE, 1, { PRC_ENV1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 50 | |
+{PSET_SIMPLE, 1, { PRC_LFO1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 51 lfo | |
+{PSET_SIMPLE, 1, { PRC_EFO1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 52 | |
+{PSET_SIMPLE, 1, { PRC_MDY1, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 53 modulating delay | |
+{PSET_SIMPLE, 1, { PRC_FLT2, PRC0, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 54 lowpass - facing away | |
+{PSET_PARALLEL2, 2, { PRC_PTC2, PRC_PTC1, PRC0, PRC0, PRC0, PRC0 },1.0, WZERO }, // 55 ptc1/ptc2 | |
+{PSET_FEEDBACK, 6, { PRC_DLY1, PRC0, PRC0, PRC_PTC1, PRC_FLT1, PRC0 },1.0, WZERO }, // 56 dly/ptc1 | |
+{PSET_MOD, 4, { PRC_EFO1, PRC0, PRC_PTC1, PRC0, PRC0, PRC0 },1.0, WZERO }, // 57 efo mod ptc | |
+{PSET_LINEAR, 3, { PRC_DLY1, PRC_RVA1, PRC_CRS1, PRC0, PRC0, PRC0 },1.0, WZERO } // 58 dly/rvb/crs | |
+}; | |
+ | |
+ | |
+// number of presets currently defined above | |
+ | |
+#define CPSETTEMPLATES 60 //(sizeof( psets ) / sizeof( pset_t )) | |
+ | |
+// init a preset - just clear state array | |
+void PSET_Init( pset_t *ppset ) | |
+{ | |
+ // clear state array | |
+ if( ppset ) Q_memset( ppset->w, 0, sizeof( int ) * ( CPSET_STATES )); | |
+} | |
+ | |
+// clear runtime slots | |
+void PSET_InitAll( void ) | |
+{ | |
+ int i; | |
+ | |
+ for( i = 0; i < CPSETS; i++ ) | |
+ Q_memset( &psets[i], 0, sizeof( pset_t )); | |
+} | |
+ | |
+// free the preset - free all processors | |
+ | |
+void PSET_Free( pset_t *ppset ) | |
+{ | |
+ if( ppset ) | |
+ { | |
+ // free processors | |
+ PRC_FreeAll( ppset->prcs, ppset->cprcs ); | |
+ | |
+ // clear | |
+ Q_memset( ppset, 0, sizeof( pset_t )); | |
+ } | |
+} | |
+ | |
+void PSET_FreeAll() { int i; for( i = 0; i < CPSETS; i++ ) PSET_Free( &psets[i] ); }; | |
+ | |
+// return preset struct, given index into preset template array | |
+// NOTE: should not ever be more than 2 or 3 of these active simultaneously | |
+pset_t *PSET_Alloc( int ipsettemplate ) | |
+{ | |
+ pset_t *ppset; | |
+ qboolean fok; | |
+ int i; | |
+ | |
+ // don't excede array bounds | |
+ if( ipsettemplate >= CPSETTEMPLATES ) | |
+ ipsettemplate = 0; | |
+ | |
+ // find free slot | |
+ for( i = 0; i < CPSETS; i++) | |
+ { | |
+ if( !psets[i].fused ) | |
+ break; | |
+ } | |
+ | |
+ if( i == CPSETS ) | |
+ return NULL; | |
+ | |
+ ppset = &psets[i]; | |
+ | |
+ // copy template into preset | |
+ *ppset = psettemplates[ipsettemplate]; | |
+ | |
+ ppset->fused = true; | |
+ | |
+ // clear state array | |
+ PSET_Init( ppset ); | |
+ | |
+ // init all processors, set up processor function pointers | |
+ fok = PRC_InitAll( ppset->prcs, ppset->cprcs ); | |
+ | |
+ if( !fok ) | |
+ { | |
+ // failed to init one or more processors | |
+ MsgDev( D_ERROR, "Sound DSP: preset failed to init.\n"); | |
+ PRC_FreeAll( ppset->prcs, ppset->cprcs ); | |
+ return NULL; | |
+ } | |
+ return ppset; | |
+} | |
+ | |
+// batch version of PSET_GetNext for linear array of processors. For performance. | |
+ | |
+// ppset - preset array | |
+// pbuffer - input sample data | |
+// SampleCount - size of input buffer | |
+// OP: OP_LEFT - process left channel in place | |
+// OP_RIGHT - process right channel in place | |
+// OP_LEFT_DUPLICATe - process left channel, duplicate into right | |
+ | |
+_inline void PSET_GetNextN( pset_t *ppset, portable_samplepair_t *pbf, int SampleCount, int op ) | |
+{ | |
+ prc_t *pprc; | |
+ int i, count = ppset->cprcs; | |
+ | |
+ switch( ppset->type ) | |
+ { | |
+ default: | |
+ case PSET_SIMPLE: | |
+ { | |
+ // x(n)--->P(0)--->y(n) | |
+ ppset->prcs[0].pfnGetNextN( ppset->prcs[0].pdata, pbf, SampleCount, op ); | |
+ break; | |
+ } | |
+ case PSET_LINEAR: | |
+ { | |
+ | |
+ // w0 w1 w2 | |
+ // x(n)--->P(0)-->P(1)-->...P(count-1)--->y(n) | |
+ | |
+ // w0 w1 w2 w3 w4 w5 | |
+ // x(n)--->P(0)-->P(1)-->P(2)-->P(3)-->P(4)-->y(n) | |
+ | |
+ // call batch processors in sequence - no internal state for batch processing | |
+ // point to first processor | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ for( i = 0; i < count; i++ ) | |
+ { | |
+ pprc->pfnGetNextN( pprc->pdata, pbf, SampleCount, op ); | |
+ pprc++; | |
+ } | |
+ break; | |
+ } | |
+ } | |
+} | |
+ | |
+ | |
+// Get next sample from this preset. called once for every sample in buffer | |
+// ppset is pointer to preset | |
+// x is input sample | |
+_inline int PSET_GetNext( pset_t *ppset, int x ) | |
+{ | |
+ int *w = ppset->w; | |
+ prc_t *pprc; | |
+ int count = ppset->cprcs; | |
+ | |
+ // initialized 0'th element of state array | |
+ | |
+ w[0] = x; | |
+ | |
+ switch( ppset->type ) | |
+ { | |
+ default: | |
+ case PSET_SIMPLE: | |
+ { | |
+ // x(n)--->P(0)--->y(n) | |
+ return ppset->prcs[0].pfnGetNext (ppset->prcs[0].pdata, x); | |
+ } | |
+ case PSET_LINEAR: | |
+ { | |
+ // w0 w1 w2 | |
+ // x(n)--->P(0)-->P(1)-->...P(count-1)--->y(n) | |
+ | |
+ // w0 w1 w2 w3 w4 w5 | |
+ // x(n)--->P(0)-->P(1)-->P(2)-->P(3)-->P(4)-->y(n) | |
+ | |
+ // call processors in reverse order, from count to 1 | |
+ | |
+ // point to last processor | |
+ | |
+ pprc = &ppset->prcs[count-1]; | |
+ | |
+ switch( count ) | |
+ { | |
+ default: | |
+ case 5: | |
+ w[5] = pprc->pfnGetNext (pprc->pdata, w[4]); | |
+ pprc--; | |
+ case 4: | |
+ w[4] = pprc->pfnGetNext (pprc->pdata, w[3]); | |
+ pprc--; | |
+ case 3: | |
+ w[3] = pprc->pfnGetNext (pprc->pdata, w[2]); | |
+ pprc--; | |
+ case 2: | |
+ w[2] = pprc->pfnGetNext (pprc->pdata, w[1]); | |
+ pprc--; | |
+ case 1: | |
+ w[1] = pprc->pfnGetNext (pprc->pdata, w[0]); | |
+ } | |
+ return w[count]; | |
+ } | |
+ | |
+ case PSET_PARALLEL6: | |
+ { | |
+ // w0 w1 w2 w3 w6 w7 | |
+ // x(n)-P(0)-->P(1)-->P(2)-->(+)---P(5)--->y(n) | |
+ // | ^ | |
+ // | w4 w5 | | |
+ // -->P(3)-->P(4)----> | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ // start with all adders | |
+ | |
+ w[6] = w[3] + w[5]; | |
+ | |
+ // top branch - evaluate in reverse order | |
+ | |
+ w[7] = pprc[5].pfnGetNext( pprc[5].pdata, w[6] ); | |
+ w[3] = pprc[2].pfnGetNext( pprc[2].pdata, w[2] ); | |
+ w[2] = pprc[1].pfnGetNext( pprc[1].pdata, w[1] ); | |
+ | |
+ // bottom branch - evaluate in reverse order | |
+ | |
+ w[5] = pprc[4].pfnGetNext( pprc[4].pdata, w[4] ); | |
+ w[4] = pprc[3].pfnGetNext( pprc[3].pdata, w[1] ); | |
+ | |
+ w[1] = pprc[0].pfnGetNext( pprc[0].pdata, w[0] ); | |
+ | |
+ return w[7]; | |
+ } | |
+ case PSET_PARALLEL2: | |
+ { // w0 w1 w3 | |
+ // x(n)--->P(0)-->(+)-->y(n) | |
+ // ^ | |
+ // w0 w2 | | |
+ // x(n)--->P(1)----- | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ w[3] = w[1] + w[2]; | |
+ | |
+ w[1] = pprc->pfnGetNext( pprc->pdata, w[0] ); | |
+ pprc++; | |
+ w[2] = pprc->pfnGetNext( pprc->pdata, w[0] ); | |
+ | |
+ return w[3]; | |
+ } | |
+ | |
+ case PSET_PARALLEL4: | |
+ { | |
+ // w0 w1 w2 w5 | |
+ // x(n)--->P(0)-->P(1)-->(+)-->y(n) | |
+ // ^ | |
+ // w0 w3 w4 | | |
+ // x(n)--->P(2)-->P(3)----- | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ w[5] = w[2] + w[4]; | |
+ | |
+ w[2] = pprc[1].pfnGetNext( pprc[1].pdata, w[1] ); | |
+ w[4] = pprc[3].pfnGetNext( pprc[3].pdata, w[3] ); | |
+ | |
+ w[1] = pprc[0].pfnGetNext( pprc[0].pdata, w[0] ); | |
+ w[3] = pprc[2].pfnGetNext( pprc[2].pdata, w[0] ); | |
+ | |
+ return w[5]; | |
+ } | |
+ | |
+ case PSET_PARALLEL5: | |
+ { | |
+ // w0 w1 w2 w5 w6 | |
+ // x(n)--->P(0)-->P(1)-->(+)-->P(4)-->y(n) | |
+ // ^ | |
+ // w0 w3 w4 | | |
+ // x(n)--->P(2)-->P(3)----- | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ w[5] = w[2] + w[4]; | |
+ | |
+ w[6] = pprc[4].pfnGetNext( pprc[4].pdata, w[5] ); | |
+ | |
+ w[2] = pprc[1].pfnGetNext( pprc[1].pdata, w[1] ); | |
+ w[4] = pprc[3].pfnGetNext( pprc[3].pdata, w[3] ); | |
+ | |
+ w[1] = pprc[0].pfnGetNext( pprc[0].pdata, w[0] ); | |
+ w[3] = pprc[2].pfnGetNext( pprc[2].pdata, w[0] ); | |
+ | |
+ return w[6]; | |
+ } | |
+ | |
+ case PSET_FEEDBACK: | |
+ { | |
+ // w0 w1 w2 w3 w4 w7 | |
+ // x(n)-P(0)--(+)-->P(1)-->P(2)-->P(5)->y(n) | |
+ // ^ | | |
+ // | w6 w5 v | |
+ // -----P(4)<--P(3)-- | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ // start with adders | |
+ | |
+ w[2] = w[1] + w[6]; | |
+ | |
+ // evaluate in reverse order | |
+ | |
+ w[7] = pprc[5].pfnGetNext( pprc[5].pdata, w[4] ); | |
+ w[6] = pprc[4].pfnGetNext( pprc[4].pdata, w[5] ); | |
+ w[5] = pprc[3].pfnGetNext( pprc[3].pdata, w[4] ); | |
+ w[4] = pprc[2].pfnGetNext( pprc[2].pdata, w[3] ); | |
+ w[3] = pprc[1].pfnGetNext( pprc[1].pdata, w[2] ); | |
+ w[1] = pprc[0].pfnGetNext( pprc[0].pdata, w[0] ); | |
+ | |
+ return w[7]; | |
+ } | |
+ case PSET_FEEDBACK3: | |
+ { | |
+ // w0 w1 w2 | |
+ // x(n)---(+)-->P(0)--------->y(n) | |
+ // ^ | | |
+ // | w4 w3 v | |
+ // -----P(2)<--P(1)-- | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ // start with adders | |
+ | |
+ w[1] = w[0] + w[4]; | |
+ | |
+ // evaluate in reverse order | |
+ | |
+ w[4] = pprc[2].pfnGetNext( pprc[2].pdata, w[3] ); | |
+ w[3] = pprc[1].pfnGetNext( pprc[1].pdata, w[2] ); | |
+ w[2] = pprc[0].pfnGetNext( pprc[0].pdata, w[1] ); | |
+ | |
+ return w[2]; | |
+ } | |
+ case PSET_FEEDBACK4: | |
+ { | |
+ // w0 w1 w2 w5 | |
+ // x(n)---(+)-->P(0)-------->P(3)--->y(n) | |
+ // ^ | | |
+ // | w4 w3 v | |
+ // ---P(2)<--P(1)-- | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ // start with adders | |
+ | |
+ w[1] = w[0] + w[4]; | |
+ | |
+ // evaluate in reverse order | |
+ | |
+ w[5] = pprc[3].pfnGetNext( pprc[3].pdata, w[2] ); | |
+ w[4] = pprc[2].pfnGetNext( pprc[2].pdata, w[3] ); | |
+ w[3] = pprc[1].pfnGetNext( pprc[1].pdata, w[2] ); | |
+ w[2] = pprc[0].pfnGetNext( pprc[0].pdata, w[1] ); | |
+ | |
+ return w[2]; | |
+ } | |
+ case PSET_MOD: | |
+ { | |
+ // w0 w1 w3 w4 | |
+ // x(n)------>P(1)--P(2)--P(3)--->y(n) | |
+ // w0 w2 ^ | |
+ // x(n)------>P(0)....: | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ w[4] = pprc[3].pfnGetNext( pprc[3].pdata, w[3] ); | |
+ | |
+ w[3] = pprc[2].pfnGetNext( pprc[2].pdata, w[1] ); | |
+ | |
+ // modulate processor 2 | |
+ | |
+ pprc[2].pfnMod( pprc[2].pdata, ((float)w[2] / (float)PMAX)); | |
+ | |
+ // get modulator output | |
+ | |
+ w[2] = pprc[0].pfnGetNext( pprc[0].pdata, w[0] ); | |
+ | |
+ w[1] = pprc[1].pfnGetNext( pprc[1].pdata, w[0] ); | |
+ | |
+ return w[4]; | |
+ } | |
+ case PSET_MOD2: | |
+ { | |
+ // w0 w2 | |
+ // x(n)---------P(1)-->y(n) | |
+ // w0 w1 ^ | |
+ // x(n)-->P(0)....: | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ // modulate processor 1 | |
+ | |
+ pprc[1].pfnMod( pprc[1].pdata, ((float)w[1] / (float)PMAX)); | |
+ | |
+ // get modulator output | |
+ | |
+ w[1] = pprc[0].pfnGetNext( pprc[0].pdata, w[0] ); | |
+ | |
+ w[2] = pprc[1].pfnGetNext( pprc[1].pdata, w[0] ); | |
+ | |
+ return w[2]; | |
+ | |
+ } | |
+ case PSET_MOD3: | |
+ { | |
+ // w0 w2 w3 | |
+ // x(n)----------P(1)-->P(2)-->y(n) | |
+ // w0 w1 ^ | |
+ // x(n)-->P(0).....: | |
+ | |
+ pprc = &ppset->prcs[0]; | |
+ | |
+ w[3] = pprc[2].pfnGetNext( pprc[2].pdata, w[2] ); | |
+ | |
+ // modulate processor 1 | |
+ | |
+ pprc[1].pfnMod( pprc[1].pdata, ((float)w[1] / (float)PMAX)); | |
+ | |
+ // get modulator output | |
+ | |
+ w[1] = pprc[0].pfnGetNext( pprc[0].pdata, w[0] ); | |
+ | |
+ w[2] = pprc[1].pfnGetNext( pprc[1].pdata, w[0] ); | |
+ | |
+ return w[2]; | |
+ } | |
+ } | |
+} | |
+ | |
+ | |
+///////////// | |
+// DSP system | |
+///////////// | |
+ | |
+// Main interface | |
+ | |
+// Whenever the preset # changes on any of these processors, the old processor is faded out, new is faded in. | |
+// dsp_chan is optionally set when a sound is played - a preset is sent with the start_static/dynamic sound. | |
+// | |
+// sound1---->dsp_chan--> -------------(+)---->dsp_water--->dsp_player--->out | |
+// sound2---->dsp_chan--> | | | |
+// sound3---------------> ----dsp_room--- | |
+// | | | |
+// --dsp_indirect- | |
+ | |
+// dsp_room - set this cvar to a preset # to change the room dsp. room fx are more prevalent farther from player. | |
+// use: when player moves into a new room, all sounds played in room take on its reverberant character | |
+// dsp_water - set this cvar (once) to a preset # for serial underwater sound. | |
+// use: when player goes under water, all sounds pass through this dsp (such as low pass filter) | |
+// dsp_player - set this cvar to a preset # to cause all sounds to run through the effect (serial, in-line). | |
+// use: player is deafened, player fires special weapon, player is hit by special weapon. | |
+// dsp_facingaway- set this cvar to a preset # appropriate for sounds which are played facing away from player (weapon,voice) | |
+ | |
+// Dsp presets | |
+ | |
+convar_t *dsp_room; // room dsp preset - sounds more distant from player (1ch) | |
+ | |
+int ipset_room_prev; | |
+ | |
+// legacy room_type support | |
+convar_t *dsp_room_type; | |
+int ipset_room_typeprev; | |
+ | |
+ | |
+// DSP processors | |
+ | |
+int idsp_room; | |
+convar_t *dsp_stereo; // set to 1 for true stereo processing. 2x perf hit. | |
+ | |
+// DSP preset executor | |
+#define CDSPS 32 // max number dsp executors active | |
+#define DSPCHANMAX 4 // max number of channels dsp can process (allocs a separte processor for each chan) | |
+ | |
+typedef struct | |
+{ | |
+ qboolean fused; | |
+ int cchan; // 1-4 channels, ie: mono, FrontLeft, FrontRight, RearLeft, RearRight | |
+ pset_t *ppset[DSPCHANMAX]; // current preset (1-4 channels) | |
+ int ipset; // current ipreset | |
+ pset_t *ppsetprev[DSPCHANMAX]; // previous preset (1-4 channels) | |
+ int ipsetprev; // previous ipreset | |
+ float xfade; // crossfade time between previous preset and new | |
+ rmp_t xramp; // crossfade ramp | |
+} dsp_t; | |
+ | |
+dsp_t dsps[CDSPS]; | |
+ | |
+void DSP_Init( int idsp ) | |
+{ | |
+ dsp_t *pdsp; | |
+ | |
+ if( idsp < 0 || idsp > CDSPS ) | |
return; | |
- if( idsp_room > MAX_ROOM_TYPES ) | |
+ pdsp = &dsps[idsp]; | |
+ Q_memset( pdsp, 0, sizeof( dsp_t )); | |
+} | |
+ | |
+void DSP_Free( int idsp ) | |
+{ | |
+ dsp_t *pdsp; | |
+ int i; | |
+ | |
+ if( idsp < 0 || idsp > CDSPS ) | |
return; | |
- if( idsp_room != room_typeprev ) | |
+ pdsp = &dsps[idsp]; | |
+ | |
+ for( i = 0; i < pdsp->cchan; i++ ) | |
{ | |
- const sx_preset_t *cur = rgsxpre + idsp_room; | |
+ if( pdsp->ppset[i] ) | |
+ PSET_Free( pdsp->ppset[i] ); | |
- Cvar_SetFloat( "room_lp", cur->room_lp ); | |
- Cvar_SetFloat( "room_mod", cur->room_mod ); | |
- Cvar_SetFloat( "room_size", cur->room_size ); | |
- Cvar_SetFloat( "room_refl", cur->room_refl ); | |
- Cvar_SetFloat( "room_rvblp", cur->room_rvblp ); | |
- Cvar_SetFloat( "room_delay", cur->room_delay ); | |
- Cvar_SetFloat( "room_feedback", cur->room_feedback ); | |
- Cvar_SetFloat( "room_dlylp", cur->room_dlylp ); | |
- Cvar_SetFloat( "room_left", cur->room_left ); | |
+ if( pdsp->ppsetprev[i] ) | |
+ PSET_Free( pdsp->ppsetprev[i] ); | |
} | |
- room_typeprev = idsp_room; | |
+ Q_memset( pdsp, 0, sizeof( dsp_t )); | |
+} | |
- RVB_CheckNewReverbVal( ); | |
- DLY_CheckNewDelayVal( ); | |
- DLY_CheckNewStereoDelayVal(); | |
+// Init all dsp processors - called once, during engine startup | |
+void DSP_InitAll( void ) | |
+{ | |
+ int idsp; | |
+ | |
+ // order is important, don't rearange. | |
+ FLT_InitAll(); | |
+ DLY_InitAll(); | |
+ RVA_InitAll(); | |
+ LFOWAV_InitAll(); | |
+ LFO_InitAll(); | |
+ | |
+ CRS_InitAll(); | |
+ PTC_InitAll(); | |
+ ENV_InitAll(); | |
+ EFO_InitAll(); | |
+ MDY_InitAll(); | |
+ AMP_InitAll(); | |
+ | |
+ PSET_InitAll(); | |
+ | |
+ for( idsp = 0; idsp < CDSPS; idsp++ ) | |
+ DSP_Init( idsp ); | |
} | |
-/* | |
-=========== | |
-DSP_GetGain | |
+// free all resources associated with dsp - called once, during engine shutdown | |
-(xash dsp interface) | |
-=========== | |
-*/ | |
+void DSP_FreeAll( void ) | |
+{ | |
+ int idsp; | |
+ | |
+ // order is important, don't rearange. | |
+ for( idsp = 0; idsp < CDSPS; idsp++ ) | |
+ DSP_Free( idsp ); | |
+ | |
+ AMP_FreeAll(); | |
+ MDY_FreeAll(); | |
+ EFO_FreeAll(); | |
+ ENV_FreeAll(); | |
+ PTC_FreeAll(); | |
+ CRS_FreeAll(); | |
+ | |
+ LFO_FreeAll(); | |
+ LFOWAV_FreeAll(); | |
+ RVA_FreeAll(); | |
+ DLY_FreeAll(); | |
+ FLT_FreeAll(); | |
+} | |
+ | |
+ | |
+// allocate a new dsp processor chain, kill the old processor. Called by DSP_CheckNewPreset() | |
+// ipset is new preset | |
+// xfade is crossfade time when switching between presets (milliseconds) | |
+// cchan is how many simultaneous preset channels to allocate (1-4) | |
+// return index to new dsp | |
+int DSP_Alloc( int ipset, float xfade, int cchan ) | |
+{ | |
+ dsp_t *pdsp; | |
+ int i, idsp; | |
+ int cchans = bound( 1, cchan, DSPCHANMAX); | |
+ | |
+ // find free slot | |
+ for( idsp = 0; idsp < CDSPS; idsp++ ) | |
+ { | |
+ if( !dsps[idsp].fused ) | |
+ break; | |
+ } | |
+ | |
+ if( idsp == CDSPS ) | |
+ return -1; | |
+ | |
+ pdsp = &dsps[idsp]; | |
+ | |
+ DSP_Init( idsp ); | |
+ | |
+ pdsp->fused = true; | |
+ pdsp->cchan = cchans; | |
+ | |
+ // allocate a preset processor for each channel | |
+ pdsp->ipset = ipset; | |
+ pdsp->ipsetprev = 0; | |
+ | |
+ for( i = 0; i < pdsp->cchan; i++ ) | |
+ { | |
+ pdsp->ppset[i] = PSET_Alloc( ipset ); | |
+ pdsp->ppsetprev[i] = NULL; | |
+ } | |
+ | |
+ // set up crossfade time in seconds | |
+ pdsp->xfade = xfade / 1000.0f; | |
+ | |
+ RMP_SetEnd( &pdsp->xramp ); | |
+ | |
+ return idsp; | |
+} | |
+ | |
+// return gain for current preset associated with dsp | |
+// get crossfade to new gain if switching from previous preset (from preset crossfader value) | |
+// Returns 1.0 gain if no preset (preset 0) | |
float DSP_GetGain( int idsp ) | |
{ | |
+ float gain_target = 0.0; | |
+ float gain_prev = 0.0; | |
+ float gain; | |
+ dsp_t *pdsp; | |
+ int r; | |
+ | |
+ if( idsp < 0 || idsp > CDSPS ) | |
return 1.0f; | |
+ | |
+ pdsp = &dsps[idsp]; | |
+ | |
+ // get current preset's gain | |
+ if( pdsp->ppset[0] ) | |
+ gain_target = pdsp->ppset[0]->gain; | |
+ else gain_target = 1.0f; | |
+ | |
+ // if not crossfading, return current preset gain | |
+ if( RMP_HitEnd( &pdsp->xramp )) | |
+ { | |
+ // return current preset's gain | |
+ return gain_target; | |
} | |
-void SX_Profiling_f( void ) | |
+ // get previous preset gain | |
+ | |
+ if( pdsp->ppsetprev[0] ) | |
+ gain_prev = pdsp->ppsetprev[0]->gain; | |
+ else gain_prev = 1.0; | |
+ | |
+ // if current gain = target preset gain, return | |
+ if( gain_target == gain_prev ) | |
+ { | |
+ if( gain_target == 0.0f ) | |
+ return 1.0f; | |
+ return gain_target; | |
+ } | |
+ | |
+ // get crossfade ramp value (updated elsewhere, when actually crossfading preset data) | |
+ r = RMP_GetCurrent( &pdsp->xramp ); | |
+ | |
+ // crossfade from previous to current preset gain | |
+ if( gain_target > gain_prev ) | |
+ { | |
+ // ramping gain up - ramp up gain to target in last 10% of ramp | |
+ float rf = (float)r; | |
+ float pmax = (float)PMAX; | |
+ | |
+ rf = rf / pmax; // rf 0->1.0 | |
+ | |
+ if( rf < 0.9 ) rf = 0.0; | |
+ else rf = (rf - 0.9) / (1.0 - 0.9); // 0->1.0 after rf > 0.9 | |
+ | |
+ // crossfade gain from prev to target over rf | |
+ gain = gain_prev + (gain_target - gain_prev) * rf; | |
+ | |
+ return gain; | |
+ } | |
+ else | |
+ { | |
+ // ramping gain down - drop gain to target in first 10% of ramp | |
+ float rf = (float) r; | |
+ float pmax = (float)PMAX; | |
+ | |
+ rf = rf / pmax; // rf 0.0->1.0 | |
+ | |
+ if( rf < 0.1 ) rf = (rf - 0.1) / (0.0 - 0.1); // 1.0->0.0 if rf < 0.1 | |
+ else rf = 0.0; | |
+ | |
+ // crossfade gain from prev to target over rf | |
+ gain = gain_prev + (gain_target - gain_prev) * (1.0 - rf); | |
+ | |
+ return gain; | |
+ } | |
+} | |
+ | |
+// free previous preset if not 0 | |
+_inline void DSP_FreePrevPreset( dsp_t *pdsp ) | |
+{ | |
+ // free previous presets if non-null - ie: rapid change of preset just kills old without xfade | |
+ if( pdsp->ipsetprev ) | |
{ | |
- portable_samplepair_t testbuffer[512]; | |
int i; | |
- int calls = 10000; | |
- double start, end; | |
- float oldroom = room_type->value; | |
- for( i = 0; i < 512; i++ ) | |
+ for( i = 0; i < pdsp->cchan; i++ ) | |
{ | |
- testbuffer[i].left = Com_RandomLong( 0, 3000 ); | |
- testbuffer[i].right = Com_RandomLong( 0, 3000 ); | |
+ if( pdsp->ppsetprev[i] ) | |
+ { | |
+ PSET_Free( pdsp->ppsetprev[i] ); | |
+ pdsp->ppsetprev[i] = NULL; | |
+ } | |
+ } | |
+ pdsp->ipsetprev = 0; | |
} | |
- if( Cmd_Argc() > 1 ) | |
+} | |
+ | |
+// alloc new preset if different from current | |
+// xfade from prev to new preset | |
+// free previous preset, copy current into previous, set up xfade from previous to new | |
+void DSP_SetPreset( int idsp, int ipsetnew ) | |
{ | |
- Cvar_SetFloat("room_type", atof(Cmd_Argv( 1 ))); | |
- SX_ReloadRoomFX(); | |
- CheckNewDspPresets(); // we just need idsp_room immediately, for message below | |
+ dsp_t *pdsp; | |
+ pset_t *ppsetnew[DSPCHANMAX]; | |
+ int i; | |
+ | |
+ ASSERT( idsp >= 0 && idsp < CDSPS ); | |
+ | |
+ pdsp = &dsps[idsp]; | |
+ | |
+ // validate new preset range | |
+ if( ipsetnew >= CPSETTEMPLATES || ipsetnew < 0 ) | |
+ return; | |
+ | |
+ // ignore if new preset is same as current preset | |
+ if( ipsetnew == pdsp->ipset ) | |
+ return; | |
+ | |
+ // alloc new presets (each channel is a duplicate preset) | |
+ ASSERT( pdsp->cchan <= DSPCHANMAX ); | |
+ | |
+ for( i = 0; i < pdsp->cchan; i++ ) | |
+ { | |
+ ppsetnew[i] = PSET_Alloc( ipsetnew ); | |
+ | |
+ if( !ppsetnew[i] ) | |
+ { | |
+ MsgDev( D_NOTE, "DSP preset failed to allocate.\n" ); | |
+ return; | |
+ } | |
} | |
- MsgDev( D_INFO, "Profiling 10000 calls to DSP. Sample count is 512, room_type is %i\n", idsp_room ); | |
+ ASSERT( pdsp ); | |
+ // free PREVIOUS previous preset if not 0 | |
+ DSP_FreePrevPreset( pdsp ); | |
- start = Sys_DoubleTime(); | |
- for( ; calls; calls-- ) | |
+ for( i = 0; i < pdsp->cchan; i++ ) | |
{ | |
- DSP_Process( idsp_room, testbuffer, 512 ); | |
+ // current becomes previous | |
+ pdsp->ppsetprev[i] = pdsp->ppset[i]; | |
+ | |
+ // new becomes current | |
+ pdsp->ppset[i] = ppsetnew[i]; | |
} | |
- end = Sys_DoubleTime(); | |
- MsgDev( D_INFO, "----------\nTook %.3f seconds.\n", end - start ); | |
+ pdsp->ipsetprev = pdsp->ipset; | |
+ pdsp->ipset = ipsetnew; | |
- if( Cmd_Argc() > 1 ) | |
+ // clear ramp | |
+ RMP_SetEnd( &pdsp->xramp ); | |
+ | |
+ // make sure previous dsp preset has data | |
+ ASSERT( pdsp->ppsetprev[0] ); | |
+ | |
+ // shouldn't be crossfading if current dsp preset == previous dsp preset | |
+ ASSERT( pdsp->ipset != pdsp->ipsetprev ); | |
+ | |
+ RMP_Init( &pdsp->xramp, pdsp->xfade, 0, PMAX ); | |
+} | |
+ | |
+/////////////////////////////////////// | |
+// Helpers: called only from DSP_Process | |
+/////////////////////////////////////// | |
+ | |
+// return true if batch processing version of preset exists | |
+_inline qboolean FBatchPreset( pset_t *ppset ) | |
{ | |
- Cvar_SetFloat( "room_type", oldroom ); | |
- SX_ReloadRoomFX(); | |
+ switch( ppset->type ) | |
+ { | |
+ case PSET_LINEAR: | |
+ return true; | |
+ case PSET_SIMPLE: | |
+ return true; | |
+ default: | |
+ return false; | |
+ } | |
+} | |
+ | |
+// Helper: called only from DSP_Process | |
+// mix front stereo buffer to mono buffer, apply dsp fx | |
+_inline void DSP_ProcessStereoToMono( dsp_t *pdsp, portable_samplepair_t *pbfront, int sampleCount, qboolean bcrossfading ) | |
+{ | |
+ portable_samplepair_t *pbf = pbfront; // pointer to buffer of front stereo samples to process | |
+ int count = sampleCount; | |
+ int av, x; | |
+ | |
+ if( !bcrossfading ) | |
+ { | |
+ if( FBatchPreset( pdsp->ppset[0] )) | |
+ { | |
+ // convert Stereo to Mono in place, then batch process fx: perf KDB | |
+ | |
+ // front->left + front->right / 2 into front->left, front->right duplicated. | |
+ while( count-- ) | |
+ { | |
+ pbf->left = (pbf->left + pbf->right) >> 1; | |
+ pbf++; | |
+ } | |
+ | |
+ // process left (mono), duplicate output into right | |
+ PSET_GetNextN( pdsp->ppset[0], pbfront, sampleCount, OP_LEFT_DUPLICATE); | |
+ } | |
+ else | |
+ { | |
+ // avg left and right -> mono fx -> duplcate out left and right | |
+ while( count-- ) | |
+ { | |
+ av = ( ( pbf->left + pbf->right ) >> 1 ); | |
+ x = PSET_GetNext( pdsp->ppset[0], av ); | |
+ x = CLIP_DSP( x ); | |
+ pbf->left = pbf->right = x; | |
+ pbf++; | |
+ } | |
+ } | |
+ return; | |
+ } | |
+ | |
+ // crossfading to current preset from previous preset | |
+ if( bcrossfading ) | |
+ { | |
+ int r = -1; | |
+ int fl, flp; | |
+ int xf_fl; | |
+ | |
+ while( count-- ) | |
+ { | |
+ av = ( ( pbf->left + pbf->right ) >> 1 ); | |
+ | |
+ // get current preset values | |
+ fl = PSET_GetNext( pdsp->ppset[0], av ); | |
+ | |
+ // get previous preset values | |
+ flp = PSET_GetNext( pdsp->ppsetprev[0], av ); | |
+ | |
+ fl = CLIP_DSP(fl); | |
+ flp = CLIP_DSP(flp); | |
+ | |
+ // get current ramp value | |
+ r = RMP_GetNext( &pdsp->xramp ); | |
+ | |
+ // crossfade from previous to current preset | |
+ xf_fl = XFADE( fl, flp, r ); // crossfade front left previous to front left | |
+ | |
+ pbf->left = xf_fl; // crossfaded front left, duplicate in right channel | |
+ pbf->right = xf_fl; | |
+ | |
+ pbf++; | |
+ | |
+ } | |
+ | |
+ } | |
+} | |
+ | |
+// Helper: called only from DSP_Process | |
+// DSP_Process stereo in to stereo out (if more than 2 procs, ignore them) | |
+_inline void DSP_ProcessStereoToStereo( dsp_t *pdsp, portable_samplepair_t *pbfront, int sampleCount, qboolean bcrossfading ) | |
+{ | |
+ portable_samplepair_t *pbf = pbfront; // pointer to buffer of front stereo samples to process | |
+ int count = sampleCount; | |
+ int fl, fr; | |
+ | |
+ if( !bcrossfading ) | |
+ { | |
+ | |
+ if( FBatchPreset( pdsp->ppset[0] ) && FBatchPreset( pdsp->ppset[1] )) | |
+ { | |
+ // process left & right | |
+ PSET_GetNextN( pdsp->ppset[0], pbfront, sampleCount, OP_LEFT ); | |
+ PSET_GetNextN( pdsp->ppset[1], pbfront, sampleCount, OP_RIGHT ); | |
+ } | |
+ else | |
+ { | |
+ // left -> left fx, right -> right fx | |
+ while( count-- ) | |
+ { | |
+ fl = PSET_GetNext( pdsp->ppset[0], pbf->left ); | |
+ fr = PSET_GetNext( pdsp->ppset[1], pbf->right ); | |
+ | |
+ fl = CLIP_DSP( fl ); | |
+ fr = CLIP_DSP( fr ); | |
+ | |
+ pbf->left = fl; | |
+ pbf->right = fr; | |
+ pbf++; | |
+ } | |
+ } | |
+ return; | |
+ } | |
+ | |
+ // crossfading to current preset from previous preset | |
+ if( bcrossfading ) | |
+ { | |
+ int r, flp, frp; | |
+ int xf_fl, xf_fr; | |
+ | |
+ while( count-- ) | |
+ { | |
+ // get current preset values | |
+ fl = PSET_GetNext( pdsp->ppset[0], pbf->left ); | |
+ fr = PSET_GetNext( pdsp->ppset[1], pbf->right ); | |
+ | |
+ // get previous preset values | |
+ flp = PSET_GetNext( pdsp->ppsetprev[0], pbf->left ); | |
+ frp = PSET_GetNext( pdsp->ppsetprev[1], pbf->right ); | |
+ | |
+ // get current ramp value | |
+ r = RMP_GetNext( &pdsp->xramp ); | |
+ | |
+ fl = CLIP_DSP( fl ); | |
+ fr = CLIP_DSP( fr ); | |
+ flp = CLIP_DSP( flp ); | |
+ frp = CLIP_DSP( frp ); | |
+ | |
+ // crossfade from previous to current preset | |
+ xf_fl = XFADE( fl, flp, r ); // crossfade front left previous to front left | |
+ xf_fr = XFADE( fr, frp, r ); | |
+ | |
+ pbf->left = xf_fl; // crossfaded front left | |
+ pbf->right = xf_fr; | |
+ | |
+ pbf++; | |
+ } | |
+ } | |
+} | |
+ | |
+void DSP_ClearState( void ) | |
+{ | |
+ if( !dsp_room ) return; // not init | |
+ | |
+ Cvar_SetFloat( "dsp_room", 0.0f ); | |
+ Cvar_SetFloat( "room_type", 0.0f ); | |
+ | |
CheckNewDspPresets(); | |
+ | |
+ // don't crossfade | |
+ dsps[0].xramp.fhitend = true; | |
+} | |
+ | |
+// Main DSP processing routine: | |
+// process samples in buffers using pdsp processor | |
+// continue crossfade between 2 dsp processors if crossfading on switch | |
+// pfront - front stereo buffer to process | |
+// prear - rear stereo buffer to process (may be NULL) | |
+// sampleCount - number of samples in pbuf to process | |
+// This routine also maps the # processing channels in the pdsp to the number of channels | |
+// supplied. ie: if the pdsp has 4 channels and pbfront and pbrear are both non-null, the channels | |
+// map 1:1 through the processors. | |
+ | |
+void DSP_Process( int idsp, portable_samplepair_t *pbfront, int sampleCount ) | |
+{ | |
+ qboolean bcrossfading; | |
+ int cprocs; // output cannels (1, 2 or 4) | |
+ dsp_t *pdsp; | |
+ | |
+ if( idsp < 0 || idsp >= CDSPS ) | |
+ return; | |
+ | |
+ ASSERT ( idsp < CDSPS ); // make sure idsp is valid | |
+ | |
+ pdsp = &dsps[idsp]; | |
+ | |
+ // if current and previous preset 0, return - preset 0 is 'off' | |
+ if( !pdsp->ipset && !pdsp->ipsetprev ) | |
+ return; | |
+ | |
+ ASSERT( pbfront ); | |
+ | |
+ // return right away if fx processing is turned off | |
+ if( dsp_off->integer ) | |
+ return; | |
+ | |
+ if( sampleCount < 0 ) | |
+ return; | |
+ | |
+ bcrossfading = !RMP_HitEnd( &pdsp->xramp ); | |
+ | |
+ // if not crossfading, and previous channel is not null, free previous | |
+ if( !bcrossfading ) DSP_FreePrevPreset( pdsp ); | |
+ | |
+ cprocs = pdsp->cchan; | |
+ | |
+ // NOTE: when mixing between different channel sizes, | |
+ // always AVERAGE down to fewer channels and DUPLICATE up more channels. | |
+ // The following routines always process cchan_in channels. | |
+ // ie: QuadToMono still updates 4 values in buffer | |
+ | |
+ // DSP_Process stereo in to mono out (ie: left and right are averaged) | |
+ if( cprocs == 1 ) | |
+ { | |
+ DSP_ProcessStereoToMono( pdsp, pbfront, sampleCount, bcrossfading ); | |
+ return; | |
+ } | |
+ | |
+ // DSP_Process stereo in to stereo out (if more than 2 procs, ignore them) | |
+ if( cprocs >= 2 ) | |
+ { | |
+ DSP_ProcessStereoToStereo( pdsp, pbfront, sampleCount, bcrossfading ); | |
+ return; | |
+ } | |
+} | |
+ | |
+// DSP helpers | |
+ | |
+// free all dsp processors | |
+void FreeDsps( void ) | |
+{ | |
+ DSP_Free( idsp_room ); | |
+ idsp_room = 0; | |
+ | |
+ DSP_FreeAll(); | |
+} | |
+ | |
+// alloc dsp processors | |
+qboolean AllocDsps( void ) | |
+{ | |
+ DSP_InitAll(); | |
+ | |
+ idsp_room = -1.0; | |
+ | |
+ // initialize DSP cvars | |
+ dsp_room = Cvar_Get( "dsp_room", "0", 0, "room dsp preset - sounds more distant from player (1ch)" ); | |
+ dsp_room_type = Cvar_Get( "room_type", "0", 0, "duplicate for dsp_room cvar for backward compatibility" ); | |
+ dsp_stereo = Cvar_Get( "dsp_stereo", "0", 0, "set to 1 for true stereo processing. 2x perf hits" ); | |
+ | |
+ // alloc dsp room channel (mono, stereo if dsp_stereo is 1) | |
+ | |
+ // dsp room is mono, 300ms fade time | |
+ idsp_room = DSP_Alloc( dsp_room->integer, 300, dsp_stereo->integer * 2 ); | |
+ | |
+ // init prev values | |
+ ipset_room_prev = dsp_room->integer; | |
+ ipset_room_typeprev = dsp_room_type->integer; | |
+ | |
+ if( idsp_room < 0 ) | |
+ { | |
+ MsgDev( D_WARN, "DSP processor failed to initialize! \n" ); | |
+ | |
+ FreeDsps(); | |
+ return false; | |
+ } | |
+ return true; | |
+} | |
+ | |
+ | |
+// Helper to check for change in preset of any of 4 processors | |
+// if switching to a new preset, alloc new preset, simulate both presets in DSP_Process & xfade, | |
+void CheckNewDspPresets( void ) | |
+{ | |
+ int iroomtype = dsp_room_type->integer; | |
+ int iroom; | |
+ | |
+ if( dsp_off->integer ) | |
+ return; | |
+ | |
+ if( s_listener.waterlevel > 2 ) | |
+ iroom = 15; | |
+ else if( s_listener.inmenu ) | |
+ iroom = 0; | |
+ else iroom = dsp_room->integer; | |
+ | |
+ // legacy code support for "room_type" Cvar | |
+ if( iroomtype != ipset_room_typeprev ) | |
+ { | |
+ // force dsp_room = room_type | |
+ ipset_room_typeprev = iroomtype; | |
+ Cvar_SetFloat( "dsp_room", iroomtype ); | |
+ } | |
+ | |
+ if( iroom != ipset_room_prev ) | |
+ { | |
+ DSP_SetPreset( idsp_room, iroom ); | |
+ ipset_room_prev = iroom; | |
+ | |
+ // force room_type = dsp_room | |
+ Cvar_SetFloat( "room_type", iroom ); | |
+ ipset_room_typeprev = iroom; | |
} | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/s_load.c /mnt/data/Xash3D_original/engine/client/s_load.c | |
--- engine/client/s_load.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/s_load.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "sound.h" | |
@@ -399,4 +397,3 @@ void S_FreeSounds( void ) | |
s_numSfx = 0; | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/s_main.c /mnt/data/Xash3D_original/engine/client/s_main.c | |
--- engine/client/s_main.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/s_main.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,17 +13,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "sound.h" | |
#include "client.h" | |
#include "con_nprint.h" | |
#include "ref_params.h" | |
#include "pm_local.h" | |
-#ifdef XASH_SDL | |
-#include <SDL.h> | |
-#endif | |
+ | |
#define MAX_DUPLICATED_CHANNELS 4 // threshold for identical static channels (probably error) | |
#define SND_CLIP_DISTANCE (float)(GI->soundclip_dist) | |
@@ -53,9 +49,9 @@ convar_t *snd_foliage_db_loss; | |
convar_t *snd_gain; | |
convar_t *snd_gain_max; | |
convar_t *snd_gain_min; | |
-convar_t *snd_mute_losefocus; | |
convar_t *s_refdist; | |
convar_t *s_refdb; | |
+convar_t *dsp_off; // set to 1 to disable all dsp processing | |
convar_t *s_cull; // cull sounds by geometry | |
convar_t *s_test; // cvar for testing new effects | |
convar_t *s_phs; | |
@@ -360,11 +356,9 @@ already playing. | |
channel_t *SND_PickStaticChannel( int entnum, sfx_t *sfx, const vec3_t pos ) | |
{ | |
channel_t *ch = NULL; | |
- int i; | |
- | |
-#if 0 | |
- int dupe = 0; | |
+ int i, dupe = 0; | |
+#if 1 | |
// TODO: remove this code when predicting is will be done | |
// check for duplicate sounds | |
for( i = 0; i < total_channels; i++ ) | |
@@ -726,7 +720,7 @@ qboolean SND_CheckPHS( channel_t *ch ) | |
{ | |
leafnum = Mod_PointLeafnum( s_listener.origin ) - 1; | |
- if( leafnum != -1 && (!(mask[leafnum>>3] & (1U << ( leafnum & 7 ))))) | |
+ if( leafnum != -1 && (!(mask[leafnum>>3] & (1<<( leafnum & 7 ))))) | |
return false; | |
} | |
return true; | |
@@ -981,7 +975,7 @@ void S_StartSound( const vec3_t pos, int | |
if( check->sfx == sfx && !check->pMixer.sample ) | |
{ | |
// skip up to 0.1 seconds of audio | |
- int skip = Com_RandomLong( 0, (int)( 0.1f * check->sfx->cache->rate )); | |
+ int skip = Com_RandomLong( 0, (long)( 0.1f * check->sfx->cache->rate )); | |
S_SetSampleStart( check, sfx->cache, skip ); | |
break; | |
@@ -1452,7 +1446,6 @@ void S_StopAllSounds( void ) | |
S_InitAmbientChannels (); | |
S_ClearBuffer (); | |
- S_StopBackgroundTrack(); | |
// clear any remaining soundfade | |
Q_memset( &soundfade, 0, sizeof( soundfade )); | |
@@ -1616,7 +1609,7 @@ void S_RenderFrame( ref_params_t *fd ) | |
else VectorSet( info.color, 1.0f, 1.0f, 1.0f ); | |
info.index = 0; | |
- Con_NXPrintf( &info, "room_type: %i ----(%i)---- painted: %i\n", idsp_room, total - 1, paintedtime ); | |
+ Con_NXPrintf( &info, "----(%i)---- painted: %i\n", total - 1, paintedtime ); | |
} | |
S_StreamBackgroundTrack (); | |
@@ -1774,46 +1767,36 @@ qboolean S_Init( void ) | |
MsgDev( D_INFO, "Audio: Disabled\n" ); | |
return false; | |
} | |
-#ifdef XASH_SDL | |
- if( SDL_Init( SDL_INIT_AUDIO ) ) | |
- { | |
- MsgDev( D_ERROR, "Audio: SDL: %s \n", SDL_GetError() ); | |
- return false; | |
- } | |
-#elif !defined(XASH_OPENSL) | |
- return false; | |
-#endif | |
s_volume = Cvar_Get( "volume", "0.7", CVAR_ARCHIVE, "sound volume" ); | |
s_musicvolume = Cvar_Get( "musicvolume", "1.0", CVAR_ARCHIVE, "background music volume" ); | |
s_mixahead = Cvar_Get( "_snd_mixahead", "0.12", 0, "how much sound to mix ahead of time" ); | |
s_show = Cvar_Get( "s_show", "0", CVAR_ARCHIVE, "show playing sounds" ); | |
s_lerping = Cvar_Get( "s_lerping", "0", CVAR_ARCHIVE, "apply interpolation to sound output" ); | |
+ dsp_off = Cvar_Get( "dsp_off", "0", CVAR_ARCHIVE, "set to 1 to disable all dsp processing" ); | |
s_ambient_level = Cvar_Get( "ambient_level", "0.3", 0, "volume of environment noises (water and wind)" ); | |
s_ambient_fade = Cvar_Get( "ambient_fade", "100", 0, "rate of volume fading when client is moving" ); | |
s_combine_sounds = Cvar_Get( "s_combine_channels", "1", CVAR_ARCHIVE, "combine channels with same sounds" ); | |
snd_foliage_db_loss = Cvar_Get( "snd_foliage_db_loss", "4", 0, "foliage loss factor" ); | |
snd_gain_max = Cvar_Get( "snd_gain_max", "1", 0, "gain maximal threshold" ); | |
snd_gain_min = Cvar_Get( "snd_gain_min", "0.01", 0, "gain minimal threshold" ); | |
- snd_mute_losefocus = Cvar_Get( "snd_mute_losefocus", "1", CVAR_ARCHIVE, "silence the audio when game window loses focus" ); | |
s_refdist = Cvar_Get( "s_refdist", "36", 0, "soundlevel reference distance" ); | |
s_refdb = Cvar_Get( "s_refdb", "60", 0, "soundlevel refernce dB" ); | |
snd_gain = Cvar_Get( "snd_gain", "1", 0, "sound default gain" ); | |
s_cull = Cvar_Get( "s_cull", "0", CVAR_ARCHIVE, "cull sounds by geometry" ); | |
- s_test = Cvar_Get( "s_test", "0", 0, "engine developer cvar for quick testing of new features" ); | |
+ s_test = Cvar_Get( "s_test", "0", 0, "engine developer cvar for quick testing new features" ); | |
s_phs = Cvar_Get( "s_phs", "0", CVAR_ARCHIVE, "cull sounds by PHS" ); | |
- s_khz = Cvar_Get("s_khz", "44", CVAR_ARCHIVE, "set sampling frequency, available values are 11, 22, 44, 48"); | |
- Cmd_AddCommand( "play", S_Play_f, "play a specified sound file" ); | |
- Cmd_AddCommand( "playvol", S_PlayVol_f, "play a specified sound file with specified volume" ); | |
+ Cmd_AddCommand( "play", S_Play_f, "playing a specified sound file" ); | |
+ Cmd_AddCommand( "playvol", S_PlayVol_f, "playing a specified sound file with specified volume" ); | |
Cmd_AddCommand( "stopsound", S_StopSound_f, "stop all sounds" ); | |
- Cmd_AddCommand( "music", S_Music_f, "start a background track" ); | |
+ Cmd_AddCommand( "music", S_Music_f, "starting a background track" ); | |
Cmd_AddCommand( "soundlist", S_SoundList_f, "display loaded sounds" ); | |
Cmd_AddCommand( "s_info", S_SoundInfo_f, "print sound system information" ); | |
Cmd_AddCommand( "+voicerecord", Cmd_Null_f, "start voice recording (non-implemented)" ); | |
Cmd_AddCommand( "-voicerecord", Cmd_Null_f, "stop voice recording (non-implemented)" ); | |
- Cmd_AddCommand( "spk", S_SayReliable_f, "reliable play of a specified sentence" ); | |
- Cmd_AddCommand( "speak", S_Say_f, "play a specified sentence" ); | |
+ Cmd_AddCommand( "spk", S_SayReliable_f, "reliable play a specified sententce" ); | |
+ Cmd_AddCommand( "speak", S_Say_f, "playing a specified sententce" ); | |
if( !SNDDMA_Init( host.hWnd )) | |
{ | |
@@ -1864,6 +1847,4 @@ void S_Shutdown( void ) | |
SNDDMA_Shutdown (); | |
MIX_FreeAllPaintbuffers (); | |
Mem_FreePool( &sndpool ); | |
- dsp_room = NULL; | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/s_mix.c /mnt/data/Xash3D_original/engine/client/s_mix.c | |
--- engine/client/s_mix.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/s_mix.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "sound.h" | |
#include "client.h" | |
@@ -31,8 +29,7 @@ GNU General Public License for more deta | |
#define SND_SCALE_BITS 7 | |
#define SND_SCALE_SHIFT (8 - SND_SCALE_BITS) | |
-#define SND_SCALE_LEVELS (1U << SND_SCALE_BITS) | |
- | |
+#define SND_SCALE_LEVELS (1 << SND_SCALE_BITS) | |
portable_samplepair_t *g_curpaintbuffer; | |
portable_samplepair_t streambuffer[(PAINTBUFFER_SIZE+1)]; | |
@@ -51,7 +48,7 @@ void S_InitScaletable( void ) | |
for( i = 0; i < SND_SCALE_LEVELS; i++ ) | |
{ | |
for( j = 0; j < 256; j++ ) | |
- snd_scaletable[i][j] = ((signed char)j) * i * (1U << SND_SCALE_SHIFT); | |
+ snd_scaletable[i][j] = ((signed char)j) * i * (1<<SND_SCALE_SHIFT); | |
} | |
} | |
@@ -246,7 +243,7 @@ void S_PaintStereoFrom8( portable_sample | |
for( i = 0; i < outCount; i++, data++ ) | |
{ | |
- left = (byte)(*data & 0x00FF); | |
+ left = (byte)((*data & 0x00FF)); | |
right = (byte)((*data & 0xFF00) >> 8); | |
pbuf[i].left += lscale[left]; | |
pbuf[i].right += rscale[right]; | |
@@ -278,7 +275,7 @@ void S_PaintStereoFrom16( portable_sampl | |
for( i = 0; i < outCount; i++, data++ ) | |
{ | |
- left = (signed short)(*data & 0x0000FFFF); | |
+ left = (signed short)((*data & 0x0000FFFF)); | |
right = (signed short)((*data & 0xFFFF0000) >> 16); | |
left = (left * volume[0]) >> 8; | |
@@ -401,13 +398,13 @@ void S_MixChannel( channel_t *pChannel, | |
if( pSource->channels == 1 ) | |
{ | |
if( pSource->width == 1 ) | |
- S_Mix8Mono( pbuf, pvol, (byte *)pData, inputOffset, fracRate, outCount ); | |
+ S_Mix8Mono( pbuf, pvol, (char *)pData, inputOffset, fracRate, outCount ); | |
else S_Mix16Mono( pbuf, pvol, (short *)pData, inputOffset, fracRate, outCount ); | |
} | |
else | |
{ | |
if( pSource->width == 1 ) | |
- S_Mix8Stereo( pbuf, pvol, (byte *)pData, inputOffset, fracRate, outCount ); | |
+ S_Mix8Stereo( pbuf, pvol, (char *)pData, inputOffset, fracRate, outCount ); | |
else S_Mix16Stereo( pbuf, pvol, (short *)pData, inputOffset, fracRate, outCount ); | |
} | |
} | |
@@ -451,7 +448,7 @@ int S_MixDataToDevice( channel_t *pChann | |
double end = pChannel->pMixer.sample + rate * sampleCount; | |
int inputSampleCount = (int)(ceil( end ) - floor( pChannel->pMixer.sample )); | |
- availableSamples = S_GetOutputData( pSource, (void **)&pData, pChannel->pMixer.sample, inputSampleCount, use_loop ); | |
+ availableSamples = S_GetOutputData( pSource, &pData, pChannel->pMixer.sample, inputSampleCount, use_loop ); | |
// none available, bail out | |
if( !availableSamples ) break; | |
@@ -1061,4 +1058,3 @@ void MIX_PaintChannels( int endtime ) | |
paintedtime = end; | |
} | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/s_mouth.c /mnt/data/Xash3D_original/engine/client/s_mouth.c | |
--- engine/client/s_mouth.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/s_mouth.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "sound.h" | |
#include "client.h" | |
@@ -59,7 +57,7 @@ void SND_CloseMouth( channel_t *ch ) | |
void SND_MoveMouth8( channel_t *ch, wavdata_t *pSource, int count ) | |
{ | |
cl_entity_t *clientEntity; | |
- signed char *pdata = NULL; | |
+ char *pdata = NULL; | |
mouth_t *pMouth = NULL; | |
int savg, data; | |
int scount, pos = 0; | |
@@ -77,7 +75,7 @@ void SND_MoveMouth8( channel_t *ch, wavd | |
} | |
else pos = ch->pMixer.sample; | |
- count = S_GetOutputData( pSource, (void **)&pdata, pos, count, ch->use_loop ); | |
+ count = S_GetOutputData( pSource, &pdata, pos, count, ch->use_loop ); | |
if( pdata == NULL ) return; | |
i = 0; | |
@@ -125,7 +123,7 @@ void SND_MoveMouth16( channel_t *ch, wav | |
} | |
else pos = ch->pMixer.sample; | |
- count = S_GetOutputData( pSource, (void **)&pdata, pos, count, ch->use_loop ); | |
+ count = S_GetOutputData( pSource, &pdata, pos, count, ch->use_loop ); | |
if( pdata == NULL ) return; | |
i = 0; | |
@@ -152,4 +150,3 @@ void SND_MoveMouth16( channel_t *ch, wav | |
pMouth->sndcount = 0; | |
} | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/sound.h /mnt/data/Xash3D_original/engine/client/sound.h | |
--- engine/client/sound.h 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/sound.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -21,8 +21,8 @@ extern byte *sndpool; | |
#include "mathlib.h" | |
// local flags (never sending acorss the net) | |
-#define SND_LOCALSOUND (1U << 9) // not paused, not looped, for internal use | |
-#define SND_STOP_LOOPING (1U << 10) // stop all looping sounds on the entity. | |
+#define SND_LOCALSOUND (1<<9) // not paused, not looped, for internal use | |
+#define SND_STOP_LOOPING (1<<10) // stop all looping sounds on the entity. | |
// sound engine rate defines | |
#define SOUND_DMA_SPEED 44100 // hardware playback rate | |
@@ -51,10 +51,10 @@ extern byte *sndpool; | |
// fixed point stuff for real-time resampling | |
#define FIX_BITS 28 | |
-#define FIX_SCALE (1U << FIX_BITS) | |
-#define FIX_MASK ((1U << FIX_BITS)-1) | |
+#define FIX_SCALE (1 << FIX_BITS) | |
+#define FIX_MASK ((1 << FIX_BITS)-1) | |
#define FIX_FLOAT(a) ((int)((a) * FIX_SCALE)) | |
-#define FIX(a) (((uint)(a)) << FIX_BITS) | |
+#define FIX(a) (((int)(a)) << FIX_BITS) | |
#define FIX_INTPART(a) (((int)(a)) >> FIX_BITS) | |
#define FIX_FRACTION(a,b) (FIX(a)/(b)) | |
#define FIX_FRACPART(a) ((a) & FIX_MASK) | |
@@ -127,21 +127,12 @@ typedef struct | |
float percent; | |
} musicfade_t; | |
-typedef struct snd_format_s | |
-{ | |
- unsigned int speed; | |
- unsigned int width; | |
- unsigned int channels; | |
-} snd_format_t; | |
- | |
typedef struct | |
{ | |
int samples; // mono samples in buffer | |
int samplepos; // in mono samples | |
- int sampleframes; | |
byte *buffer; | |
qboolean initialized; // sound engine is active | |
- snd_format_t format; | |
} dma_t; | |
#include "vox.h" | |
@@ -149,12 +140,13 @@ typedef struct | |
typedef struct | |
{ | |
double sample; | |
- double forcedEndSample; | |
+ | |
wavdata_t *pData; | |
+ double forcedEndSample; | |
qboolean finished; | |
} mixer_t; | |
-struct channel_s | |
+typedef struct channel_s | |
{ | |
char name[16]; // keept sentence name | |
sfx_t *sfx; // sfx number | |
@@ -187,7 +179,7 @@ struct channel_s | |
int wordIndex; | |
mixer_t *currentWord; // NULL if sentence is finished | |
voxword_t words[CVOXWORDMAX]; | |
-}; | |
+} channel_t; | |
typedef struct | |
{ | |
@@ -255,8 +247,6 @@ extern convar_t *s_lerping; | |
extern convar_t *dsp_off; | |
extern convar_t *s_test; | |
extern convar_t *s_phs; | |
-extern convar_t *s_khz; | |
-extern convar_t *dsp_room; | |
extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES]; | |
@@ -297,6 +287,7 @@ void DSP_ClearState( void ); | |
qboolean S_Init( void ); | |
void S_Shutdown( void ); | |
+void S_Activate( qboolean active, void *hInst ); | |
void S_SoundList_f( void ); | |
void S_SoundInfo_f( void ); | |
@@ -322,8 +313,7 @@ void SND_CloseMouth( channel_t *ch ); | |
// | |
void S_StreamSoundTrack( void ); | |
void S_StreamBackgroundTrack( void ); | |
-qboolean S_StreamGetCurrentState( char *currentTrack, char *loopTrack, fs_offset_t *position ); | |
-void S_StopBackgroundTrack( void ); | |
+qboolean S_StreamGetCurrentState( char *currentTrack, char *loopTrack, int *position ); | |
void S_PrintBackgroundTrackState( void ); | |
void S_FadeMusicVolume( float fadePercent ); | |
diff --suppress-blank-empty -prudwEZbB engine/client/s_stream.c /mnt/data/Xash3D_original/engine/client/s_stream.c | |
--- engine/client/s_stream.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/s_stream.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "sound.h" | |
#include "client.h" | |
@@ -78,7 +76,7 @@ float S_GetMusicVolume( void ) | |
S_StartBackgroundTrack | |
================= | |
*/ | |
-void S_StartBackgroundTrack( const char *introTrack, const char *mainTrack, int position ) | |
+void S_StartBackgroundTrack( const char *introTrack, const char *mainTrack, long position ) | |
{ | |
S_StopBackgroundTrack(); | |
@@ -141,7 +139,7 @@ S_StreamGetCurrentState | |
save\restore code | |
================= | |
*/ | |
-qboolean S_StreamGetCurrentState( char *currentTrack, char *loopTrack, fs_offset_t *position ) | |
+qboolean S_StreamGetCurrentState( char *currentTrack, char *loopTrack, int *position ) | |
{ | |
if( !s_bgTrack.stream ) | |
return false; // not active | |
@@ -319,7 +317,7 @@ void S_StreamSoundTrack( void ) | |
} | |
// read audio stream | |
- r = SCR_GetAudioChunk( (char *)raw, fileBytes ); | |
+ r = SCR_GetAudioChunk( raw, fileBytes ); | |
if( r < fileBytes ) | |
{ | |
@@ -395,4 +393,3 @@ void S_StreamRawSamples( int samples, in | |
RESAMPLE_RAW | |
} | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/s_utils.c /mnt/data/Xash3D_original/engine/client/s_utils.c | |
--- engine/client/s_utils.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/s_utils.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "sound.h" | |
@@ -62,7 +60,7 @@ int S_ZeroCrossingBefore( wavdata_t *pWa | |
if( pWaveData->width == 1 ) | |
{ | |
- char *pData = (char *)pWaveData->buffer + sample * sampleSize; | |
+ char *pData = pWaveData->buffer + sample * sampleSize; | |
qboolean zero = false; | |
if( pWaveData->channels == 1 ) | |
@@ -159,7 +157,7 @@ int S_ZeroCrossingAfter( wavdata_t *pWav | |
if( pWaveData->width == 1 ) // 8-bit | |
{ | |
- char *pData = (char *)pWaveData->buffer + sample * sampleSize; | |
+ char *pData = pWaveData->buffer + sample * sampleSize; | |
qboolean zero = false; | |
if( pWaveData->channels == 1 ) | |
@@ -324,4 +322,3 @@ void S_SetSampleEnd( channel_t *pChan, w | |
pChan->pMixer.forcedEndSample = newEndPosition; | |
} | |
-#endif // XASH_DEDICATED | |
diff --suppress-blank-empty -prudwEZbB engine/client/s_vox.c /mnt/data/Xash3D_original/engine/client/s_vox.c | |
--- engine/client/s_vox.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/s_vox.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,8 +13,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
- | |
#include "common.h" | |
#include "sound.h" | |
#include "const.h" | |
@@ -608,7 +605,7 @@ void VOX_ReadSentenceFile( const char *p | |
{ | |
char c, *pch, *pFileData; | |
char *pchlast, *pSentenceData; | |
- fs_offset_t fileSize; | |
+ int fileSize; | |
// load file | |
pFileData = (char *)FS_LoadFile( psentenceFileName, &fileSize, false ); | |
@@ -686,4 +683,3 @@ void VOX_Shutdown( void ) | |
{ | |
g_numSentences = 0; | |
} | |
-#endif // XASH_DEDICATED | |
Только в /mnt/data/Xash3D_original/engine/client/vgui: utlmemory.h | |
Только в /mnt/data/Xash3D_original/engine/client/vgui: utlrbtree.h | |
Только в /mnt/data/Xash3D_original/engine/client/vgui: utlvector.h | |
Только в engine/client/vgui: vgui_api.h | |
Только в /mnt/data/Xash3D_original/engine/client/vgui: vgui_clip.cpp | |
diff --suppress-blank-empty -prudwEZbB engine/client/vgui/vgui_draw.c /mnt/data/Xash3D_original/engine/client/vgui/vgui_draw.c | |
--- engine/client/vgui/vgui_draw.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/vgui/vgui_draw.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,482 +13,15 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#ifdef XASH_VGUI | |
- | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
#include "vgui_draw.h" | |
-#include "vgui_api.h" | |
-#include "library.h" | |
-#include <string.h> | |
-#include "../keydefs.h" | |
+convar_t *vgui_colorstrings; | |
int g_textures[VGUI_MAX_TEXTURES]; | |
int g_textureId = 0; | |
int g_iBoundTexture; | |
-static enum VGUI_KeyCode s_pVirtualKeyTrans[256]; | |
-#ifdef XASH_SDL | |
-static SDL_Cursor* s_pDefaultCursor[20]; | |
-#endif | |
- | |
-void VGUI_DrawInit( void ); | |
-void VGUI_DrawShutdown( void ); | |
-void VGUI_SetupDrawingText( int *pColor ); | |
-void VGUI_SetupDrawingRect( int *pColor ); | |
-void VGUI_SetupDrawingImage( int *pColor ); | |
-void VGUI_BindTexture( int id ); | |
-void VGUI_EnableTexture( qboolean enable ); | |
-void VGUI_CreateTexture( int id, int width, int height ); | |
-void VGUI_UploadTexture( int id, const char *buffer, int width, int height ); | |
-void VGUI_UploadTextureBlock( int id, int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight ); | |
-void VGUI_DrawQuad( const vpoint_t *ul, const vpoint_t *lr ); | |
-void VGUI_GetTextureSizes( int *width, int *height ); | |
-int VGUI_GenerateTexture( void ); | |
- | |
-// Helper functions for vgui backend | |
- | |
-/*void VGUI_HideCursor( void ) | |
-{ | |
- host.mouse_visible = false; | |
- SDL_HideCursor(); | |
-} | |
- | |
-void VGUI_ShowCursor( void ) | |
-{ | |
- host.mouse_visible = true; | |
- SDL_ShowCursor(); | |
-}*/ | |
- | |
-void *VGUI_EngineMalloc(size_t size) | |
-{ | |
- return Z_Malloc( size ); | |
-} | |
- | |
-qboolean VGUI_IsInGame() | |
-{ | |
- return cls.state == ca_active && cls.key_dest == key_game; | |
-} | |
- | |
-void VGUI_GetMousePos( int *x, int *y ) | |
-{ | |
- CL_GetMousePosition( x, y ); | |
-} | |
- | |
-void VGUI_InitCursors( void ) | |
-{ | |
- // load up all default cursors | |
-#ifdef XASH_SDL | |
- s_pDefaultCursor[dc_none] = NULL; | |
- s_pDefaultCursor[dc_arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); | |
- s_pDefaultCursor[dc_ibeam] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM); | |
- s_pDefaultCursor[dc_hourglass]= SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT); | |
- s_pDefaultCursor[dc_crosshair]= SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR); | |
- s_pDefaultCursor[dc_up] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); | |
- s_pDefaultCursor[dc_sizenwse] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE); | |
- s_pDefaultCursor[dc_sizenesw] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW); | |
- s_pDefaultCursor[dc_sizewe] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE); | |
- s_pDefaultCursor[dc_sizens] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS); | |
- s_pDefaultCursor[dc_sizeall] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL); | |
- s_pDefaultCursor[dc_no] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO); | |
- s_pDefaultCursor[dc_hand] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND); | |
- //host.mouse_visible = true; | |
- SDL_SetCursor( s_pDefaultCursor[dc_arrow] ); | |
-#endif | |
-} | |
- | |
-void VGUI_CursorSelect(enum VGUI_DefaultCursor cursor ) | |
-{ | |
- qboolean oldstate = host.mouse_visible; | |
- if( cls.key_dest != key_game || cl.refdef.paused ) | |
- return; | |
-#ifdef XASH_SDL | |
- | |
- switch( cursor ) | |
- { | |
- case dc_user: | |
- case dc_none: | |
- host.mouse_visible = false; | |
- break; | |
- default: | |
- host.mouse_visible = true; | |
- SDL_SetRelativeMouseMode( SDL_FALSE ); | |
- SDL_SetCursor( s_pDefaultCursor[cursor] ); | |
- break; | |
- } | |
- if( host.mouse_visible ) | |
- { | |
- SDL_ShowCursor( true ); | |
- } | |
- else | |
- { | |
- SDL_ShowCursor( false ); | |
- if( oldstate ) | |
- SDL_GetRelativeMouseState( 0, 0 ); | |
- } | |
- //SDL_SetRelativeMouseMode(false); | |
-#endif | |
-} | |
- | |
-byte VGUI_GetColor( int i, int j) | |
-{ | |
- return g_color_table[i][j]; | |
-} | |
- | |
-// Define and initialize vgui API | |
- | |
-void VGUI_SetVisible ( qboolean state ) | |
-{ | |
- host.input_enabled=state; | |
- host.mouse_visible=state; | |
-#ifdef XASH_SDL | |
- SDL_ShowCursor( state ); | |
- if(!state) SDL_GetRelativeMouseState( 0, 0 ); | |
-#endif | |
-} | |
-vguiapi_t vgui = | |
-{ | |
- false, //Not initialized yet | |
- VGUI_DrawInit, | |
- VGUI_DrawShutdown, | |
- VGUI_SetupDrawingText, | |
- VGUI_SetupDrawingRect, | |
- VGUI_SetupDrawingImage, | |
- VGUI_BindTexture, | |
- VGUI_EnableTexture, | |
- VGUI_CreateTexture, | |
- VGUI_UploadTexture, | |
- VGUI_UploadTextureBlock, | |
- VGUI_DrawQuad, | |
- VGUI_GetTextureSizes, | |
- VGUI_GenerateTexture, | |
- VGUI_EngineMalloc, | |
-/* VGUI_ShowCursor, | |
- VGUI_HideCursor,*/ | |
- VGUI_CursorSelect, | |
- VGUI_GetColor, | |
- VGUI_IsInGame, | |
- VGUI_SetVisible, | |
- VGUI_GetMousePos, | |
- Con_UtfProcessChar, | |
- NULL, | |
- NULL, | |
- NULL, | |
- NULL, | |
- NULL, | |
- NULL, | |
- NULL, | |
-} ; | |
- | |
- | |
-void *lib; //vgui_support library | |
- | |
- | |
-/* | |
-================ | |
-VGui_Startup | |
- | |
-Load vgui_support library and call VGui_Startup | |
-================ | |
-*/ | |
-void VGui_Startup( int width, int height ) | |
-{ | |
- static qboolean failed = false; | |
- if( failed ) | |
- return; | |
- if(!vgui.initialized) | |
- { | |
- void (*F) ( vguiapi_t * ); | |
- char vguiloader[256]; | |
- char vguilib[256]; | |
- | |
- Com_ResetLibraryError(); | |
- | |
- // hack: load vgui with correct path first if specified. | |
- // it will be reused while resolving vgui support and client deps | |
- if( Sys_GetParmFromCmdLine( "-vguilib", vguilib ) ) | |
- { | |
- if( Q_strstr( vguilib, ".dll") ) | |
- Q_strncpy( vguiloader, "vgui_support.dll", 256 ); | |
- else | |
- Q_strncpy( vguiloader, VGUI_SUPPORT_DLL, 256 ); | |
- if( !Com_LoadLibrary( vguilib, false ) ) | |
- MsgDev( D_WARN, "VGUI preloading failed. Default library will be used!\n"); | |
- } | |
- | |
- if( !Sys_GetParmFromCmdLine( "-vguiloader", vguiloader ) ) | |
- Q_strncpy( vguiloader, VGUI_SUPPORT_DLL, 256 ); | |
- | |
- lib = Com_LoadLibrary( vguiloader, false ); | |
- if(!lib) | |
- MsgDev( D_ERROR, "Failed to load vgui_support library: %s", Com_GetLibraryError() ); | |
- else | |
- { | |
- F = Com_GetProcAddress( lib, "InitAPI" ); | |
- if( F ) | |
- { | |
- F( &vgui ); | |
- vgui.initialized = true; | |
- VGUI_InitCursors(); | |
- } | |
- else | |
- MsgDev( D_ERROR, "Failed to find vgui_support library entry point!\n" ); | |
- } | |
- | |
- } | |
- | |
- // vgui may crash if it cannot find font | |
- if( width <= 320 ) | |
- width = 320; | |
- else if( width <= 400 ) | |
- width = 400; | |
- else if( width <= 512 ) | |
- width = 512; | |
- else if( width <= 640 ) | |
- width = 640; | |
- else if( width <= 800 ) | |
- width = 800; | |
- else if( width <= 1024 ) | |
- width = 1024; | |
- else if( width <= 1152 ) | |
- width = 1152; | |
- else if( width <= 1280 ) | |
- width = 1280; | |
- else //if( width <= 1600 ) | |
- width = 1600; | |
- | |
- | |
- if( vgui.initialized ) | |
- { | |
- //host.mouse_visible = true; | |
- vgui.Startup( width, height ); | |
- } | |
- else failed = true; | |
-} | |
- | |
- | |
- | |
-/* | |
-================ | |
-VGui_Shutdown | |
- | |
-Unload vgui_support library and call VGui_Shutdown | |
-================ | |
-*/ | |
-void VGui_Shutdown( void ) | |
-{ | |
- if( vgui.Shutdown ) | |
- vgui.Shutdown(); | |
- if( lib ) | |
- Com_FreeLibrary( lib ); | |
- lib = NULL; | |
- vgui.initialized = false; | |
-} | |
- | |
- | |
-void VGUI_InitKeyTranslationTable( void ) | |
-{ | |
- static qboolean bInitted = false; | |
- | |
- if( bInitted ) return; | |
- bInitted = true; | |
- | |
- // set virtual key translation table | |
- Q_memset( s_pVirtualKeyTrans, -1, sizeof( s_pVirtualKeyTrans ) ); | |
- | |
- s_pVirtualKeyTrans['0'] = KEY_0; | |
- s_pVirtualKeyTrans['1'] = KEY_1; | |
- s_pVirtualKeyTrans['2'] = KEY_2; | |
- s_pVirtualKeyTrans['3'] = KEY_3; | |
- s_pVirtualKeyTrans['4'] = KEY_4; | |
- s_pVirtualKeyTrans['5'] = KEY_5; | |
- s_pVirtualKeyTrans['6'] = KEY_6; | |
- s_pVirtualKeyTrans['7'] = KEY_7; | |
- s_pVirtualKeyTrans['8'] = KEY_8; | |
- s_pVirtualKeyTrans['9'] = KEY_9; | |
- s_pVirtualKeyTrans['A'] = s_pVirtualKeyTrans['a'] = KEY_A; | |
- s_pVirtualKeyTrans['B'] = s_pVirtualKeyTrans['b'] = KEY_B; | |
- s_pVirtualKeyTrans['C'] = s_pVirtualKeyTrans['c'] = KEY_C; | |
- s_pVirtualKeyTrans['D'] = s_pVirtualKeyTrans['d'] = KEY_D; | |
- s_pVirtualKeyTrans['E'] = s_pVirtualKeyTrans['e'] = KEY_E; | |
- s_pVirtualKeyTrans['F'] = s_pVirtualKeyTrans['f'] = KEY_F; | |
- s_pVirtualKeyTrans['G'] = s_pVirtualKeyTrans['g'] = KEY_G; | |
- s_pVirtualKeyTrans['H'] = s_pVirtualKeyTrans['h'] = KEY_H; | |
- s_pVirtualKeyTrans['I'] = s_pVirtualKeyTrans['i'] = KEY_I; | |
- s_pVirtualKeyTrans['J'] = s_pVirtualKeyTrans['j'] = KEY_J; | |
- s_pVirtualKeyTrans['K'] = s_pVirtualKeyTrans['k'] = KEY_K; | |
- s_pVirtualKeyTrans['L'] = s_pVirtualKeyTrans['l'] = KEY_L; | |
- s_pVirtualKeyTrans['M'] = s_pVirtualKeyTrans['m'] = KEY_M; | |
- s_pVirtualKeyTrans['N'] = s_pVirtualKeyTrans['n'] = KEY_N; | |
- s_pVirtualKeyTrans['O'] = s_pVirtualKeyTrans['o'] = KEY_O; | |
- s_pVirtualKeyTrans['P'] = s_pVirtualKeyTrans['p'] = KEY_P; | |
- s_pVirtualKeyTrans['Q'] = s_pVirtualKeyTrans['q'] = KEY_Q; | |
- s_pVirtualKeyTrans['R'] = s_pVirtualKeyTrans['r'] = KEY_R; | |
- s_pVirtualKeyTrans['S'] = s_pVirtualKeyTrans['s'] = KEY_S; | |
- s_pVirtualKeyTrans['T'] = s_pVirtualKeyTrans['t'] = KEY_T; | |
- s_pVirtualKeyTrans['U'] = s_pVirtualKeyTrans['u'] = KEY_U; | |
- s_pVirtualKeyTrans['V'] = s_pVirtualKeyTrans['v'] = KEY_V; | |
- s_pVirtualKeyTrans['W'] = s_pVirtualKeyTrans['w'] = KEY_W; | |
- s_pVirtualKeyTrans['X'] = s_pVirtualKeyTrans['x'] = KEY_X; | |
- s_pVirtualKeyTrans['Y'] = s_pVirtualKeyTrans['y'] = KEY_Y; | |
- s_pVirtualKeyTrans['Z'] = s_pVirtualKeyTrans['z'] = KEY_Z; | |
-#ifdef XASH_SDL | |
- | |
- | |
- s_pVirtualKeyTrans[K_KP_5 - 5] = KEY_PAD_0; | |
- s_pVirtualKeyTrans[K_KP_5 - 4] = KEY_PAD_1; | |
- s_pVirtualKeyTrans[K_KP_5 - 3] = KEY_PAD_2; | |
- s_pVirtualKeyTrans[K_KP_5 - 2] = KEY_PAD_3; | |
- s_pVirtualKeyTrans[K_KP_5 - 1] = KEY_PAD_4; | |
- s_pVirtualKeyTrans[K_KP_5 - 0] = KEY_PAD_5; | |
- s_pVirtualKeyTrans[K_KP_5 + 1] = KEY_PAD_6; | |
- s_pVirtualKeyTrans[K_KP_5 + 2] = KEY_PAD_7; | |
- s_pVirtualKeyTrans[K_KP_5 + 3] = KEY_PAD_8; | |
- s_pVirtualKeyTrans[K_KP_5 + 4] = KEY_PAD_9; | |
- s_pVirtualKeyTrans[K_KP_SLASH] = KEY_PAD_DIVIDE; | |
- s_pVirtualKeyTrans['*'] = KEY_PAD_MULTIPLY; | |
- s_pVirtualKeyTrans[K_KP_MINUS] = KEY_PAD_MINUS; | |
- s_pVirtualKeyTrans[K_KP_PLUS] = KEY_PAD_PLUS; | |
- s_pVirtualKeyTrans[K_KP_ENTER] = KEY_PAD_ENTER; | |
- //s_pVirtualKeyTrans[K_KP_DECIMAL] = KEY_PAD_DECIMAL; | |
- s_pVirtualKeyTrans['['] = KEY_LBRACKET; | |
- s_pVirtualKeyTrans[']'] = KEY_RBRACKET; | |
- s_pVirtualKeyTrans[';'] = KEY_SEMICOLON; | |
- s_pVirtualKeyTrans['\''] = KEY_APOSTROPHE; | |
- s_pVirtualKeyTrans['`'] = KEY_BACKQUOTE; | |
- s_pVirtualKeyTrans[','] = KEY_COMMA; | |
- s_pVirtualKeyTrans['.'] = KEY_PERIOD; | |
- s_pVirtualKeyTrans[K_KP_SLASH] = KEY_SLASH; | |
- s_pVirtualKeyTrans['\\'] = KEY_BACKSLASH; | |
- s_pVirtualKeyTrans['-'] = KEY_MINUS; | |
- s_pVirtualKeyTrans['='] = KEY_EQUAL; | |
- s_pVirtualKeyTrans[K_ENTER] = KEY_ENTER; | |
- s_pVirtualKeyTrans[K_SPACE] = KEY_SPACE; | |
- s_pVirtualKeyTrans[K_BACKSPACE] = KEY_BACKSPACE; | |
- s_pVirtualKeyTrans[K_TAB] = KEY_TAB; | |
- s_pVirtualKeyTrans[K_CAPSLOCK] = KEY_CAPSLOCK; | |
- s_pVirtualKeyTrans[K_KP_NUMLOCK] = KEY_NUMLOCK; | |
- s_pVirtualKeyTrans[K_ESCAPE] = KEY_ESCAPE; | |
- //s_pVirtualKeyTrans[K_KP_SCROLLLOCK] = KEY_SCROLLLOCK; | |
- s_pVirtualKeyTrans[K_INS] = KEY_INSERT; | |
- s_pVirtualKeyTrans[K_DEL] = KEY_DELETE; | |
- s_pVirtualKeyTrans[K_HOME] = KEY_HOME; | |
- s_pVirtualKeyTrans[K_END] = KEY_END; | |
- s_pVirtualKeyTrans[K_PGUP] = KEY_PAGEUP; | |
- s_pVirtualKeyTrans[K_PGDN] = KEY_PAGEDOWN; | |
- s_pVirtualKeyTrans[K_PAUSE] = KEY_BREAK; | |
- //s_pVirtualKeyTrans[K_SHIFT] = KEY_RSHIFT; | |
- s_pVirtualKeyTrans[K_SHIFT] = KEY_LSHIFT; // SHIFT -> left SHIFT | |
- //s_pVirtualKeyTrans[SDLK_RALT] = KEY_RALT; | |
- s_pVirtualKeyTrans[K_ALT] = KEY_LALT; // ALT -> left ALT | |
- //s_pVirtualKeyTrans[SDLK_RCTRL] = KEY_RCONTROL; | |
- s_pVirtualKeyTrans[K_CTRL] = KEY_LCONTROL; // CTRL -> left CTRL | |
- s_pVirtualKeyTrans[K_WIN] = KEY_LWIN; | |
- //s_pVirtualKeyTrans[SDLK_APPLICATION] = KEY_RWIN; | |
- //s_pVirtualKeyTrans[K_WIN] = KEY_APP; | |
- s_pVirtualKeyTrans[K_UPARROW] = KEY_UP; | |
- s_pVirtualKeyTrans[K_LEFTARROW] = KEY_LEFT; | |
- s_pVirtualKeyTrans[K_DOWNARROW] = KEY_DOWN; | |
- s_pVirtualKeyTrans[K_RIGHTARROW] = KEY_RIGHT; | |
- s_pVirtualKeyTrans[K_F1] = KEY_F1; | |
- s_pVirtualKeyTrans[K_F2] = KEY_F2; | |
- s_pVirtualKeyTrans[K_F3] = KEY_F3; | |
- s_pVirtualKeyTrans[K_F4] = KEY_F4; | |
- s_pVirtualKeyTrans[K_F5] = KEY_F5; | |
- s_pVirtualKeyTrans[K_F6] = KEY_F6; | |
- s_pVirtualKeyTrans[K_F7] = KEY_F7; | |
- s_pVirtualKeyTrans[K_F8] = KEY_F8; | |
- s_pVirtualKeyTrans[K_F9] = KEY_F9; | |
- s_pVirtualKeyTrans[K_F10] = KEY_F10; | |
- s_pVirtualKeyTrans[K_F11] = KEY_F11; | |
- s_pVirtualKeyTrans[K_F12] = KEY_F12; | |
-#endif | |
-} | |
- | |
-enum VGUI_KeyCode VGUI_MapKey( int keyCode ) | |
-{ | |
- VGUI_InitKeyTranslationTable(); | |
- | |
- if( keyCode < 0 || keyCode >= sizeof( s_pVirtualKeyTrans ) / sizeof( s_pVirtualKeyTrans[0] )) | |
- { | |
- //Assert( false ); | |
- return (enum VGUI_KeyCode)-1; | |
- } | |
- else | |
- { | |
- return s_pVirtualKeyTrans[keyCode]; | |
- } | |
-} | |
- | |
- | |
-enum VGUI_MouseCode VGUI_MapMouseButton( byte button) | |
-{ | |
-#ifdef XASH_SDL | |
- switch(button) | |
- { | |
- case SDL_BUTTON_LEFT: | |
- return MOUSE_LEFT; | |
- case SDL_BUTTON_MIDDLE: | |
- return MOUSE_MIDDLE; | |
- case SDL_BUTTON_RIGHT: | |
- return MOUSE_RIGHT; | |
- } | |
-#else | |
- return (enum VGUI_MouseCode)button; | |
-#endif | |
- return MOUSE_LAST; // What is MOUSE_LAST? Is it really used? | |
-} | |
- | |
- | |
- | |
-void VGUI_SurfaceWndProc( Xash_Event *event ) | |
-{ | |
-#ifdef XASH_SDL | |
-/* When false returned, event passed to engine, else only to vgui*/ | |
-/* NOTE: this disabled because VGUI shows its cursor on engine start*/ | |
- if( !vgui.initialized ) | |
- return /*false*/; | |
- | |
- switch( event->type ) | |
- { | |
- /*case : | |
- VGUI_ActivateCurrentCursor(); | |
- break;*/ | |
- case SDL_MOUSEMOTION: | |
- vgui.MouseMove(event->motion.x, event->motion.y); | |
- //return false; | |
- break; | |
- case SDL_MOUSEBUTTONDOWN: | |
- //if(event->button.clicks == 1) | |
- vgui.Mouse(MA_PRESSED, VGUI_MapMouseButton(event->button.button)); | |
- // else | |
- // vgui.Mouse(MA_DOUBLE, VGUI_MapMouseButton(event->button.button)); | |
- //return true; | |
- break; | |
- case SDL_MOUSEBUTTONUP: | |
- vgui.Mouse(MA_RELEASED, VGUI_MapMouseButton(event->button.button)); | |
- //return true; | |
- break; | |
- case SDL_MOUSEWHEEL: | |
- vgui.Mouse(MA_WHEEL, event->wheel.y); | |
- //return true; | |
- break; | |
- case SDL_KEYDOWN: | |
- if(!( event->key.keysym.sym & ( 1 << 30 ))) | |
- vgui.Key( KA_PRESSED, VGUI_MapKey( event->key.keysym.sym )); | |
- vgui.Key( KA_TYPED, VGUI_MapKey( event->key.keysym.sym )); | |
- //return false; | |
- break; | |
- case SDL_KEYUP: | |
- vgui.Key( KA_RELEASED, VGUI_MapKey( event->key.keysym.sym ) ); | |
- //return false; | |
- break; | |
- } | |
- | |
-#endif | |
- //return false; | |
-} | |
- | |
/* | |
================ | |
@@ -501,6 +34,8 @@ void VGUI_DrawInit( void ) | |
{ | |
Q_memset( g_textures, 0, sizeof( g_textures )); | |
g_textureId = g_iBoundTexture = 0; | |
+ | |
+ vgui_colorstrings = Cvar_Get( "vgui_colorstrings", "0", CVAR_ARCHIVE, "allow colorstrings in VGUI texts" ); | |
} | |
/* | |
@@ -644,14 +179,14 @@ void VGUI_BindTexture( int id ) | |
{ | |
if( id > 0 && id < VGUI_MAX_TEXTURES && g_textures[id] ) | |
{ | |
- GL_Bind( XASH_TEXTURE0, g_textures[id] ); | |
+ GL_Bind( GL_TEXTURE0, g_textures[id] ); | |
g_iBoundTexture = id; | |
} | |
else | |
{ | |
// NOTE: same as bogus index 2700 in GoldSrc | |
id = g_iBoundTexture = 1; | |
- GL_Bind( XASH_TEXTURE0, g_textures[id] ); | |
+ GL_Bind( GL_TEXTURE0, g_textures[id] ); | |
} | |
} | |
@@ -714,22 +249,3 @@ void VGUI_DrawQuad( const vpoint_t *ul, | |
pglVertex2f( ul->point[0], lr->point[1] ); | |
pglEnd(); | |
} | |
- | |
-void VGui_Paint() | |
-{ | |
- if(vgui.initialized) | |
- vgui.Paint(); | |
-} | |
- | |
-void *VGui_GetPanel() | |
-{ | |
- if( vgui.initialized ) | |
- return vgui.GetPanel(); | |
- return NULL; | |
-} | |
- | |
-void VGui_RunFrame() | |
-{ | |
- //stub | |
-} | |
-#endif | |
diff --suppress-blank-empty -prudwEZbB engine/client/vgui/vgui_draw.h /mnt/data/Xash3D_original/engine/client/vgui/vgui_draw.h | |
--- engine/client/vgui/vgui_draw.h 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/vgui/vgui_draw.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -20,21 +20,22 @@ GNU General Public License for more deta | |
extern "C" { | |
#endif | |
-#include "port.h" | |
- | |
#define VGUI_MAX_TEXTURES 2048 // a half of total textures count | |
-//#include "vgui_api.h" | |
+extern rgba_t g_color_table[8]; // for colored strings support | |
+extern convar_t *vgui_colorstrings; | |
-#ifdef XASH_SDL | |
-#include <SDL_events.h> | |
-typedef SDL_Event Xash_Event; | |
-#else | |
-typedef void Xash_Event; | |
-#endif | |
+// VGUI generic vertex | |
+typedef struct | |
+{ | |
+ vec2_t point; | |
+ vec2_t coord; | |
+} vpoint_t; | |
+ | |
+// | |
+// vgui_backend.c | |
+// | |
-//extern vguiapi_t vgui; | |
-/* | |
void VGUI_DrawInit( void ); | |
void VGUI_DrawShutdown( void ); | |
void VGUI_SetupDrawingText( int *pColor ); | |
@@ -45,20 +46,32 @@ void VGUI_EnableTexture( qboolean enable | |
void VGUI_CreateTexture( int id, int width, int height ); | |
void VGUI_UploadTexture( int id, const char *buffer, int width, int height ); | |
void VGUI_UploadTextureBlock( int id, int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight ); | |
+long VGUI_SurfaceWndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); | |
void VGUI_DrawQuad( const vpoint_t *ul, const vpoint_t *lr ); | |
void VGUI_GetTextureSizes( int *width, int *height ); | |
int VGUI_GenerateTexture( void ); | |
-*/ | |
+void *VGui_GetPanel( void ); | |
+ | |
+#ifdef __cplusplus | |
+void EnableScissor( qboolean enable ); | |
+void SetScissorRect( int left, int top, int right, int bottom ); | |
+qboolean ClipRect( const vpoint_t &inUL, const vpoint_t &inLR, vpoint_t *pOutUL, vpoint_t *pOutLR ); | |
+#endif | |
// | |
-// vgui_draw.c | |
+// gl_vidnt.c | |
// | |
-void VGui_Startup( int width, int height ); | |
+qboolean R_DescribeVIDMode( int width, int height ); | |
+ | |
+// | |
+// vgui_int.c | |
+// | |
+void VGui_Startup( void ); | |
void VGui_Shutdown( void ); | |
-void VGui_Paint(); | |
-void VGui_RunFrame(); | |
-void VGUI_SurfaceWndProc( Xash_Event *event ); | |
-void *VGui_GetPanel(); | |
+void *VGui_GetPanel( void ); | |
+void VGui_Paint( void ); | |
+void VGui_RunFrame( void ); | |
+void VGui_ViewportPaintBackground( int extents[4] ); | |
#ifdef __cplusplus | |
} | |
Только в /mnt/data/Xash3D_original/engine/client/vgui: vgui_font.cpp | |
Только в /mnt/data/Xash3D_original/engine/client/vgui: vgui_input.cpp | |
Только в /mnt/data/Xash3D_original/engine/client/vgui: vgui_int.cpp | |
Только в /mnt/data/Xash3D_original/engine/client/vgui: vgui_main.h | |
Только в /mnt/data/Xash3D_original/engine/client/vgui: vgui_surf.cpp | |
diff --suppress-blank-empty -prudwEZbB engine/client/vox.h /mnt/data/Xash3D_original/engine/client/vox.h | |
--- engine/client/vox.h 2016-01-18 16:21:32.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/client/vox.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -35,7 +34,6 @@ typedef struct voxword_s | |
sfx_t *sfx; // name and cache pointer | |
} voxword_t; | |
-#include "sound.h" | |
typedef struct | |
{ | |
@@ -43,8 +41,6 @@ typedef struct | |
float length; | |
} sentence_t; | |
-typedef struct channel_s channel_t; | |
- | |
void VOX_LoadWord( struct channel_s *pchan ); | |
void VOX_FreeWord( struct channel_s *pchan ); | |
Только в engine/: CMakeLists.txt | |
diff --suppress-blank-empty -prudwEZbB engine/common/avikit.c /mnt/data/Xash3D_original/engine/common/avikit.c | |
--- engine/common/avikit.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/avikit.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -16,15 +16,6 @@ GNU General Public License for more deta | |
#include "common.h" | |
#include "client.h" | |
#include "gl_local.h" | |
-#if defined(_WIN32) && !defined(XASH_DEDICATED) | |
-#define USE_VFW | |
-#endif | |
-#ifdef USE_VFW | |
-#ifdef __MINGW32__ | |
-#include <mmreg.h> | |
-#include <msacm.h> | |
- | |
-#endif | |
#include <vfw.h> // video for windows | |
// msvfw32.dll exports | |
@@ -138,18 +130,10 @@ typedef struct movie_state_s | |
static qboolean avi_initialized = false; | |
static movie_state_t avi[2]; | |
-#ifndef ACM_STREAMSIZEF_SOURCE | |
-#define ACM_STREAMSIZEF_SOURCE 0 | |
-#define ACM_STREAMCONVERTF_BLOCKALIGN 0x00000004 | |
-#define ACM_STREAMCONVERTF_START 0x00000010 | |
-#define ACM_STREAMCONVERTF_END 0x00000020 | |
-#endif | |
-#endif | |
// Converts a compressed audio stream into uncompressed PCM. | |
qboolean AVI_ACMConvertAudio( movie_state_t *Avi ) | |
{ | |
-#ifdef USE_VFW | |
WAVEFORMATEX dest_header, *sh, *dh; | |
AVISTREAMINFO stream_info; | |
dword dest_length; | |
@@ -261,14 +245,10 @@ qboolean AVI_ACMConvertAudio( movie_stat | |
Avi->audio_bytes_per_sample = (bits >> 3 ) * Avi->audio_header->nChannels; | |
return true; | |
-#else | |
- return false; | |
-#endif | |
} | |
qboolean AVI_GetVideoInfo( movie_state_t *Avi, long *xres, long *yres, float *duration ) | |
{ | |
-#ifdef USE_VFW | |
ASSERT( Avi != NULL ); | |
if( !Avi->active ) | |
@@ -284,30 +264,22 @@ qboolean AVI_GetVideoInfo( movie_state_t | |
*duration = (float)Avi->video_frames / Avi->video_fps; | |
return true; | |
-#else | |
- return false; | |
-#endif | |
} | |
// returns a unique frame identifier | |
long AVI_GetVideoFrameNumber( movie_state_t *Avi, float time ) | |
{ | |
-#ifdef USE_VFW | |
ASSERT( Avi != NULL ); | |
if( !Avi->active ) | |
return 0; | |
return (time * Avi->video_fps); | |
-#else | |
- return 0; | |
-#endif | |
} | |
// gets the raw frame data | |
byte *AVI_GetVideoFrame( movie_state_t *Avi, long frame ) | |
{ | |
-#ifdef USE_VFW | |
LPBITMAPINFOHEADER frame_info; | |
byte *frame_raw, *tmp; | |
int i; | |
@@ -334,14 +306,10 @@ byte *AVI_GetVideoFrame( movie_state_t * | |
} | |
return Avi->pframe_data; | |
-#else | |
- return NULL; | |
-#endif | |
} | |
qboolean AVI_GetAudioInfo( movie_state_t *Avi, wavdata_t *snd_info ) | |
{ | |
-#ifdef USE_VFW | |
ASSERT( Avi != NULL ); | |
if( !Avi->active || Avi->audio_stream == NULL || snd_info == NULL ) | |
@@ -360,15 +328,11 @@ qboolean AVI_GetAudioInfo( movie_state_t | |
snd_info->loopStart = 0; // HACKHACK: use loopStart as streampos | |
return true; | |
-#else | |
- return false; | |
-#endif | |
} | |
// sync the current audio read to a specific offset | |
qboolean AVI_SeekPosition( movie_state_t *Avi, dword offset ) | |
{ | |
-#ifdef USE_VFW | |
int breaker; | |
ASSERT( Avi != NULL ); | |
@@ -415,15 +379,11 @@ qboolean AVI_SeekPosition( movie_state_t | |
Avi->cpa_blockpos = offset - Avi->cpa_blockoffset; | |
return true; | |
-#else | |
- return false; | |
-#endif | |
} | |
// get a chunk of audio from the stream (in bytes) | |
fs_offset_t AVI_GetAudioChunk( movie_state_t *Avi, char *audiodata, long offset, long length ) | |
{ | |
-#ifdef USE_VFW | |
int i; | |
long result = 0; | |
@@ -493,14 +453,10 @@ fs_offset_t AVI_GetAudioChunk( movie_sta | |
return result; | |
} | |
-#else | |
- return 0; | |
-#endif | |
} | |
void AVI_CloseVideo( movie_state_t *Avi ) | |
{ | |
-#ifdef USE_VFW | |
ASSERT( Avi != NULL ); | |
if( Avi->active ) | |
@@ -529,12 +485,10 @@ void AVI_CloseVideo( movie_state_t *Avi | |
} | |
Q_memset( Avi, 0, sizeof( movie_state_t )); | |
-#endif | |
} | |
void AVI_OpenVideo( movie_state_t *Avi, const char *filename, qboolean load_audio, qboolean ignore_hwgamma, int quiet ) | |
{ | |
-#ifdef USE_VFW | |
BITMAPINFOHEADER bmih; | |
AVISTREAMINFO stream_info; | |
long opened_streams = 0; | |
@@ -668,25 +622,18 @@ void AVI_OpenVideo( movie_state_t *Avi, | |
SelectObject( Avi->hDC, Avi->hBitmap ); | |
Avi->active = true; // done | |
-#endif | |
} | |
qboolean AVI_IsActive( movie_state_t *Avi ) | |
{ | |
-#ifdef USE_VFW | |
if( Avi != NULL ) | |
return Avi->active; | |
-#endif | |
return false; | |
} | |
movie_state_t *AVI_GetState( int num ) | |
{ | |
-#ifdef USE_VFW | |
return &avi[num]; | |
-#else | |
- return NULL; | |
-#endif | |
} | |
/* | |
@@ -697,7 +644,6 @@ AVIKit user interface | |
*/ | |
movie_state_t *AVI_LoadVideo( const char *filename, qboolean load_audio, qboolean ignore_hwgamma ) | |
{ | |
-#ifdef USE_VFW | |
movie_state_t *Avi; | |
string path; | |
const char *fullpath; | |
@@ -731,9 +677,6 @@ movie_state_t *AVI_LoadVideo( const char | |
// all done | |
return Avi; | |
-#else | |
- return NULL; | |
-#endif | |
} | |
movie_state_t *AVI_LoadVideoNoSound( const char *filename, qboolean ignore_hwgamma ) | |
@@ -743,7 +686,6 @@ movie_state_t *AVI_LoadVideoNoSound( con | |
void AVI_FreeVideo( movie_state_t *state ) | |
{ | |
-#ifdef USE_VFW | |
if( !state ) return; | |
if( Mem_IsAllocatedExt( cls.mempool, state )) | |
@@ -751,12 +693,10 @@ void AVI_FreeVideo( movie_state_t *state | |
AVI_CloseVideo( state ); | |
Mem_Free( state ); | |
} | |
-#endif | |
} | |
qboolean AVI_Initailize( void ) | |
{ | |
-#ifdef USE_VFW | |
if( Sys_CheckParm( "-noavi" )) | |
{ | |
MsgDev( D_INFO, "AVI: Disabled\n" ); | |
@@ -784,19 +724,15 @@ qboolean AVI_Initailize( void ) | |
return false; | |
} | |
+ pAVIFileInit(); | |
avi_initialized = true; | |
MsgDev( D_NOTE, "AVI_Initailize: done\n" ); | |
- pAVIFileInit(); | |
return true; | |
-#endif | |
- MsgDev( D_INFO, "AVI: Not supported\n" ); | |
- return false; | |
} | |
void AVI_Shutdown( void ) | |
{ | |
-#ifdef USE_VFW | |
if( !avi_initialized ) return; | |
pAVIFileExit(); | |
@@ -805,5 +741,4 @@ void AVI_Shutdown( void ) | |
Sys_FreeLibrary( &msvfw_dll ); | |
Sys_FreeLibrary( &msacm_dll ); | |
avi_initialized = false; | |
-#endif | |
} | |
Только в engine/common: base_cmd.c | |
Только в engine/common: base_cmd.h | |
diff --suppress-blank-empty -prudwEZbB engine/common/build.c /mnt/data/Xash3D_original/engine/common/build.c | |
--- engine/common/build.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/build.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -15,15 +15,14 @@ GNU General Public License for more deta | |
#include "common.h" | |
-//static char *date = __DATE__ ; | |
-//static char *mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; | |
-//static char mond[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | |
+static char *date = __DATE__ ; | |
+static char *mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; | |
+static char mond[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | |
// returns days since Feb 13 2007 | |
int Q_buildnum( void ) | |
{ | |
// do not touch this! Only author of Xash3D can increase buildnumbers! | |
-// Xash3D SDL: HAHAHA! I TOUCHED THIS! | |
#if 0 | |
int m = 0, d = 0, y = 0; | |
static int b = 0; | |
@@ -47,8 +46,6 @@ int Q_buildnum( void ) | |
} | |
b -= 38752; // Feb 13 2007 | |
- //b -= 41728; // Apr 1 2015. Date of first release of crossplatform Xash3D | |
- | |
return b; | |
#else | |
return 3366; | |
diff --suppress-blank-empty -prudwEZbB engine/common/cmd.c /mnt/data/Xash3D_original/engine/common/cmd.c | |
--- engine/common/cmd.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/cmd.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -27,17 +27,10 @@ typedef struct | |
int maxsize; | |
} cmdbuf_t; | |
-static qboolean cmd_wait; | |
-static cmdbuf_t cmd_text; | |
-static byte cmd_text_buf[MAX_CMD_BUFFER]; | |
-static cmdalias_t *cmd_alias; | |
-static int maxcmdnamelen; // this is used to nicely format command list output | |
-extern convar_t *cvar_vars; | |
-extern convar_t *cmd_scripting; | |
- | |
-// condition checking | |
-uint64_t cmd_cond; | |
-int cmd_condlevel; | |
+qboolean cmd_wait; | |
+cmdbuf_t cmd_text; | |
+byte cmd_text_buf[MAX_CMD_BUFFER]; | |
+cmdalias_t *cmd_alias; | |
/* | |
============================================================================= | |
@@ -56,7 +49,6 @@ void Cbuf_Init( void ) | |
cmd_text.data = cmd_text_buf; | |
cmd_text.maxsize = MAX_CMD_BUFFER; | |
cmd_text.cursize = 0; | |
- Q_memset( cmd_text_buf, 0, sizeof( cmd_text_buf ) ); | |
} | |
/* | |
@@ -75,7 +67,7 @@ void Cbuf_Clear( void ) | |
Cbuf_GetSpace | |
============ | |
*/ | |
-static void *Cbuf_GetSpace( cmdbuf_t *buf, int length ) | |
+void *Cbuf_GetSpace( cmdbuf_t *buf, int length ) | |
{ | |
void *data; | |
@@ -107,12 +99,11 @@ void Cbuf_AddText( const char *text ) | |
if( cmd_text.cursize + l >= cmd_text.maxsize ) | |
{ | |
MsgDev( D_WARN, "Cbuf_AddText: overflow\n" ); | |
+ return; | |
} | |
- else | |
- { | |
+ | |
Q_memcpy( Cbuf_GetSpace( &cmd_text, l ), text, l ); | |
} | |
-} | |
/* | |
============ | |
@@ -124,19 +115,28 @@ Adds a \n to the text | |
*/ | |
void Cbuf_InsertText( const char *text ) | |
{ | |
- int l; | |
+ char *temp; | |
+ int templen; | |
- l = Q_strlen( text ); | |
+ // copy off any commands still remaining in the exec buffer | |
+ templen = cmd_text.cursize; | |
- if( cmd_text.cursize + l >= cmd_text.maxsize ) | |
+ if( templen ) | |
{ | |
- MsgDev( D_WARN, "Cbuf_InsertText: overflow\n" ); | |
+ temp = Z_Malloc( templen ); | |
+ Q_memcpy( temp, cmd_text.data, templen ); | |
+ cmd_text.cursize = 0; | |
} | |
- else | |
+ else temp = NULL; | |
+ | |
+ // add the entire text of the file | |
+ Cbuf_AddText( text ); | |
+ | |
+ // add the copied off data | |
+ if( templen ) | |
{ | |
- Q_memmove( cmd_text.data + l, cmd_text.data, cmd_text.cursize ); | |
- cmd_text.cursize += l; | |
- Q_memcpy( cmd_text.data, text, l ); | |
+ Q_memcpy( Cbuf_GetSpace( &cmd_text, templen ), temp, templen ); | |
+ Z_Free( temp ); | |
} | |
} | |
@@ -147,57 +147,31 @@ Cbuf_Execute | |
*/ | |
void Cbuf_Execute( void ) | |
{ | |
- int i; | |
char *text; | |
char line[MAX_CMD_LINE]; | |
- qboolean quotes; | |
- char *comment; | |
+ int i, quotes; | |
while( cmd_text.cursize ) | |
{ | |
// find a \n or ; line break | |
text = (char *)cmd_text.data; | |
- quotes = false; | |
- comment = NULL; | |
+ quotes = 0; | |
for( i = 0; i < cmd_text.cursize; i++ ) | |
{ | |
- if( !comment ) | |
- { | |
- if( text[i] == '"' ) | |
- quotes = !quotes; | |
- | |
- if( quotes ) | |
- { | |
- // make sure i doesn't get > cursize which causes a negative | |
- // size in memmove, which is fatal --blub | |
- if ( i < ( cmd_text.cursize-1 ) && ( text[i] == '\\' && (text[i+1] == '"' || text[i+1] == '\\' ))) | |
- i++; | |
- } | |
- else | |
- { | |
- if( text[i] == '/' && text[i + 1] == '/' && (i == 0 || (byte)text[i - 1] <= ' ' )) | |
- comment = &text[i]; | |
- if( text[i] == ';' ) | |
- break; // don't break if inside a quoted string or comment | |
- } | |
- } | |
- if( text[i] == '\r' || text[i] == '\n' ) | |
+ 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; | |
} | |
- // better than CRASHING on overlong input lines that may SOMEHOW enter the buffer | |
- if( i >= MAX_CMD_LINE ) | |
- { | |
- MsgDev( D_WARN, "Console input buffer had an overlong line. Ignored.\n" ); | |
- line[0] = 0; | |
- } | |
- else | |
- { | |
- Q_memcpy( line, text, comment ? (comment - text) : i ); | |
- line[comment ? (comment - text) : i] = 0; | |
- } | |
+ if( i >= ( MAX_CMD_LINE - 1 )) | |
+ Sys_Error( "Cbuf_Execute: command string owerflow\n" ); | |
+ | |
+ Q_memcpy( 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 | |
@@ -210,7 +184,7 @@ void Cbuf_Execute( void ) | |
{ | |
i++; | |
cmd_text.cursize -= i; | |
- Q_memmove( cmd_text.data, text + i, cmd_text.cursize ); | |
+ Q_memcpy( text, text + i, cmd_text.cursize ); | |
} | |
// execute the command line | |
@@ -243,7 +217,7 @@ xash -dev 3 +map c1a0d | |
xash -nosound -game bshift | |
=============== | |
*/ | |
-static void Cmd_StuffCmds_f( void ) | |
+void Cmd_StuffCmds_f( void ) | |
{ | |
int i, j, l = 0; | |
char build[MAX_CMD_LINE]; // this is for all commandline options combined (and is bounds checked) | |
@@ -307,7 +281,7 @@ next frame. This allows commands like: | |
bind g "cmd use rocket ; +attack ; wait ; -attack ; cmd use blaster" | |
============ | |
*/ | |
-static void Cmd_Wait_f( void ) | |
+void Cmd_Wait_f( void ) | |
{ | |
cmd_wait = true; | |
} | |
@@ -319,12 +293,12 @@ Cmd_Echo_f | |
Just prints the rest of the line to the console | |
=============== | |
*/ | |
-static void Cmd_Echo_f( void ) | |
+void Cmd_Echo_f( void ) | |
{ | |
int i; | |
for( i = 1; i < Cmd_Argc(); i++ ) | |
- Msg( "%s ", Cmd_Argv( i )); | |
+ Sys_Print( Cmd_Argv( i )); | |
Sys_Print( "\n" ); | |
} | |
@@ -335,13 +309,12 @@ Cmd_Alias_f | |
Creates a new command that executes a command string (possibly ; seperated) | |
=============== | |
*/ | |
-static void Cmd_Alias_f( void ) | |
+void Cmd_Alias_f( void ) | |
{ | |
cmdalias_t *a; | |
char cmd[MAX_CMD_LINE]; | |
int i, c; | |
- const char *s; | |
- size_t alloclen; | |
+ char *s; | |
if( Cmd_Argc() == 1 ) | |
{ | |
@@ -359,44 +332,24 @@ static void Cmd_Alias_f( void ) | |
return; | |
} | |
- // if the alias already exists, reuse it | |
-#if defined( XASH_HASHED_VARS ) | |
- a = BaseCmd_Find( HM_CMDALIAS, s ); | |
- if( a ) | |
- { | |
- Mem_Free( a->value ); | |
- } | |
-#else | |
+ // if the alias allready exists, reuse it | |
for( a = cmd_alias; a; a = a->next ) | |
{ | |
if( !Q_strcmp( s, a->name )) | |
{ | |
- Mem_Free( a->value ); | |
+ Z_Free( a->value ); | |
break; | |
} | |
} | |
-#endif | |
if( !a ) | |
{ | |
- cmdalias_t *prev, *current; | |
- | |
a = Z_Malloc( sizeof( cmdalias_t )); | |
- Q_strncpy( a->name, s, sizeof( a->name )); | |
- // insert it at the right alphanumeric position | |
- for( prev = NULL, current = cmd_alias ; current && Q_strcmp( current->name, a->name ) < 0 ; prev = current, current = current->next ) | |
- ; | |
- if( prev ) { | |
- prev->next = a; | |
- } else { | |
+ a->next = cmd_alias; | |
cmd_alias = a; | |
} | |
- a->next = current; | |
-#if defined( XASH_HASHED_VARS ) | |
- BaseCmd_Insert( HM_CMDALIAS, a, a->name ); | |
-#endif | |
- } | |
+ Q_strncpy( a->name, s, sizeof( a->name )); | |
// copy the rest of the command line | |
cmd[0] = 0; // start out with a null string | |
@@ -405,60 +358,12 @@ static void Cmd_Alias_f( void ) | |
for( i = 2; i < c; i++ ) | |
{ | |
- if( i != 2 ) | |
- Q_strncat( cmd, " ", sizeof( cmd )); | |
- Q_strncat( cmd, Cmd_Argv( i ), sizeof( cmd )); | |
- } | |
- Q_strncat( cmd, "\n", sizeof( cmd )); | |
- | |
- alloclen = Q_strlen( cmd ) + 1; | |
- if( alloclen >= 2 ) | |
- cmd[alloclen - 2] = '\n'; // to make sure a newline is appended even if too long | |
- a->value = Z_Malloc( alloclen ); | |
- Q_memcpy( a->value, cmd, alloclen ); | |
-} | |
- | |
-/* | |
-=============== | |
-Cmd_UnAlias_f | |
- | |
-Remove existing aliases. | |
-=============== | |
-*/ | |
-static void Cmd_UnAlias_f ( void ) | |
-{ | |
- cmdalias_t *a, *p; | |
- int i; | |
- const char *s; | |
- | |
- if( Cmd_Argc() == 1 ) | |
- { | |
- Msg( "Usage: unalias alias1 [alias2 ...]\n" ); | |
- return; | |
+ Q_strcat( cmd, Cmd_Argv( i )); | |
+ if( i != c ) Q_strcat( cmd, " " ); | |
} | |
- for( i = 1; i < Cmd_Argc(); ++i ) | |
- { | |
- s = Cmd_Argv( i ); | |
- for( p = NULL, a = cmd_alias; a; p = a, a = a->next ) | |
- { | |
- if( !Q_strcmp( s, a->name )) | |
- { | |
-#if defined( XASH_HASHED_VARS ) | |
- BaseCmd_Remove( HM_CMDALIAS, p, a->name ); | |
-#endif | |
- if( a == cmd_alias ) | |
- cmd_alias = a->next; | |
- if( p ) | |
- p->next = a->next; | |
- Mem_Free( a->value ); | |
- Mem_Free( a ); | |
- break; | |
- } | |
- } | |
- if( !a ) | |
- Msg( "unalias: %s alias not found\n", s ); | |
- } | |
+ Q_strcat( cmd, "\n" ); | |
+ a->value = copystring( cmd ); | |
} | |
/* | |
@@ -470,17 +375,17 @@ static void Cmd_UnAlias_f ( void ) | |
*/ | |
typedef struct cmd_s | |
{ | |
- char *name; // must be first, to match cvar_t | |
struct cmd_s *next; | |
+ char *name; | |
xcommand_t function; | |
char *desc; | |
int flags; | |
} cmd_t; | |
static int cmd_argc; | |
-static char *cmd_args; | |
+static char *cmd_args = NULL; | |
static char *cmd_argv[MAX_CMD_TOKENS]; | |
-//static char cmd_tokenized[MAX_CMD_BUFFER]; // will have 0 bytes inserted | |
+static char cmd_tokenized[MAX_CMD_BUFFER]; // will have 0 bytes inserted | |
static cmd_t *cmd_functions; // possible commands to execute | |
cmd_source_t cmd_source; | |
@@ -489,7 +394,7 @@ cmd_source_t cmd_source; | |
Cmd_Argc | |
============ | |
*/ | |
-int Cmd_Argc( void ) | |
+uint Cmd_Argc( void ) | |
{ | |
return cmd_argc; | |
} | |
@@ -501,7 +406,7 @@ Cmd_Argv | |
*/ | |
char *Cmd_Argv( int arg ) | |
{ | |
- if( arg >= cmd_argc ) | |
+ if((uint)arg >= cmd_argc ) | |
return ""; | |
return cmd_argv[arg]; | |
} | |
@@ -521,7 +426,7 @@ char *Cmd_Args( void ) | |
Cmd_AliasGetList | |
============ | |
*/ | |
-cmdalias_t *Cmd_AliasGetList( void ) | |
+struct cmdalias_s *Cmd_AliasGetList( void ) | |
{ | |
return cmd_alias; | |
} | |
@@ -531,7 +436,7 @@ cmdalias_t *Cmd_AliasGetList( void ) | |
Cmd_GetList | |
============ | |
*/ | |
-cmd_t *Cmd_GetFirstFunctionHandle( void ) | |
+struct cmd_s *Cmd_GetFirstFunctionHandle( void ) | |
{ | |
return cmd_functions; | |
} | |
@@ -541,7 +446,7 @@ cmd_t *Cmd_GetFirstFunctionHandle( void | |
Cmd_GetNext | |
============ | |
*/ | |
-cmd_t *Cmd_GetNextFunctionHandle( cmd_t *cmd ) | |
+struct cmd_s *Cmd_GetNextFunctionHandle( struct cmd_s *cmd ) | |
{ | |
return (cmd) ? cmd->next : NULL; | |
} | |
@@ -551,7 +457,7 @@ cmd_t *Cmd_GetNextFunctionHandle( cmd_t | |
Cmd_GetName | |
============ | |
*/ | |
-char *Cmd_GetName( cmd_t *cmd ) | |
+char *Cmd_GetName( struct cmd_s *cmd ) | |
{ | |
return cmd->name; | |
} | |
@@ -566,7 +472,7 @@ are inserted in the apropriate place, Th | |
will point into this temporary buffer. | |
============ | |
*/ | |
-void Cmd_TokenizeString( const char *text ) | |
+void Cmd_TokenizeString( char *text ) | |
{ | |
char cmd_token[MAX_CMD_BUFFER]; | |
int i; | |
@@ -583,14 +489,12 @@ void Cmd_TokenizeString( const char *tex | |
while( 1 ) | |
{ | |
// skip whitespace up to a /n | |
- while( *text && ((byte)*text) <= ' ' && *text != '\r' && *text != '\n' ) | |
+ while( *text && ((byte)*text) <= ' ' && *text != '\n' ) | |
text++; | |
- if( *text == '\n' || *text == '\r' ) | |
+ if( *text == '\n' ) | |
{ | |
// a newline seperates commands in the buffer | |
- if( *text == '\r' && text[1] == '\n' ) | |
- text++; | |
text++; | |
break; | |
} | |
@@ -599,8 +503,9 @@ void Cmd_TokenizeString( const char *tex | |
return; | |
if( cmd_argc == 1 ) | |
- cmd_args = (char*)text; | |
- text = COM_ParseFile( (char*)text, cmd_token ); | |
+ cmd_args = text; | |
+ | |
+ text = COM_ParseFile( text, cmd_token ); | |
if( !text ) return; | |
if( cmd_argc < MAX_CMD_TOKENS ) | |
@@ -620,8 +525,6 @@ Cmd_AddCommand | |
void Cmd_AddCommand( const char *cmd_name, xcommand_t function, const char *cmd_desc ) | |
{ | |
cmd_t *cmd; | |
- cmd_t *prev, *current; | |
- int cmdnamelen; | |
// fail if the command is a variable name | |
if( Cvar_FindVar( cmd_name )) | |
@@ -637,30 +540,14 @@ void Cmd_AddCommand( const char *cmd_nam | |
return; | |
} | |
- cmdnamelen = Q_strlen( cmd_name ); | |
- if ( cmdnamelen > maxcmdnamelen ) | |
- maxcmdnamelen = cmdnamelen; | |
- | |
// use a small malloc to avoid zone fragmentation | |
cmd = Z_Malloc( sizeof( cmd_t )); | |
cmd->name = copystring( cmd_name ); | |
cmd->desc = copystring( cmd_desc ); | |
cmd->function = function; | |
cmd->next = cmd_functions; | |
- | |
- // insert it at the right alphanumeric position | |
- for( prev = NULL, current = cmd_functions ; current && Q_strcmp( current->name, cmd_name ) < 0 ; prev = current, current = current->next ) | |
- ; | |
- if( prev ) { | |
- prev->next = cmd; | |
- } else { | |
cmd_functions = cmd; | |
} | |
- cmd->next = current; | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Insert( HM_CMD, cmd, cmd->name ); | |
-#endif | |
-} | |
/* | |
============ | |
@@ -670,27 +557,21 @@ Cmd_AddGameCommand | |
void Cmd_AddGameCommand( const char *cmd_name, xcommand_t function ) | |
{ | |
cmd_t *cmd; | |
- cmd_t *prev, *current; | |
- int cmdnamelen; | |
// fail if the command is a variable name | |
if( Cvar_FindVar( cmd_name )) | |
{ | |
- MsgDev( D_INFO, "Cmd_AddGameCommand: %s already defined as a var\n", cmd_name ); | |
+ MsgDev( D_INFO, "Cmd_AddCommand: %s already defined as a var\n", cmd_name ); | |
return; | |
} | |
// fail if the command already exists | |
if( Cmd_Exists( cmd_name )) | |
{ | |
- MsgDev(D_INFO, "Cmd_AddGameCommand: %s already defined\n", cmd_name); | |
+ MsgDev(D_INFO, "Cmd_AddCommand: %s already defined\n", cmd_name); | |
return; | |
} | |
- cmdnamelen = Q_strlen( cmd_name ); | |
- if ( cmdnamelen > maxcmdnamelen ) | |
- maxcmdnamelen = cmdnamelen; | |
- | |
// use a small malloc to avoid zone fragmentation | |
cmd = Z_Malloc( sizeof( cmd_t )); | |
cmd->name = copystring( cmd_name ); | |
@@ -698,21 +579,8 @@ void Cmd_AddGameCommand( const char *cmd | |
cmd->function = function; | |
cmd->flags = CMD_EXTDLL; | |
cmd->next = cmd_functions; | |
- | |
- // insert it at the right alphanumeric position | |
- for( prev = NULL, current = cmd_functions ; current && Q_strcmp( current->name, cmd_name ) < 0 ; prev = current, current = current->next ) | |
- ; | |
- if( prev ) { | |
- prev->next = cmd; | |
- } else { | |
cmd_functions = cmd; | |
} | |
- cmd->next = current; | |
- | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Insert( HM_CMD, cmd, cmd->name ); | |
-#endif | |
-} | |
/* | |
============ | |
@@ -722,27 +590,21 @@ Cmd_AddClientCommand | |
void Cmd_AddClientCommand( const char *cmd_name, xcommand_t function ) | |
{ | |
cmd_t *cmd; | |
- cmd_t *prev, *current; | |
- int cmdnamelen; | |
// fail if the command is a variable name | |
if( Cvar_FindVar( cmd_name )) | |
{ | |
- MsgDev( D_INFO, "Cmd_AddClientCommand: %s already defined as a var\n", cmd_name ); | |
+ MsgDev( D_INFO, "Cmd_AddCommand: %s already defined as a var\n", cmd_name ); | |
return; | |
} | |
// fail if the command already exists | |
if( Cmd_Exists( cmd_name )) | |
{ | |
- MsgDev(D_INFO, "Cmd_AddClientCommand: %s already defined\n", cmd_name); | |
+ MsgDev(D_INFO, "Cmd_AddCommand: %s already defined\n", cmd_name); | |
return; | |
} | |
- cmdnamelen = Q_strlen( cmd_name ); | |
- if ( cmdnamelen > maxcmdnamelen ) | |
- maxcmdnamelen = cmdnamelen; | |
- | |
// use a small malloc to avoid zone fragmentation | |
cmd = Z_Malloc( sizeof( cmd_t )); | |
cmd->name = copystring( cmd_name ); | |
@@ -750,21 +612,8 @@ void Cmd_AddClientCommand( const char *c | |
cmd->function = function; | |
cmd->flags = CMD_CLIENTDLL; | |
cmd->next = cmd_functions; | |
- | |
- // insert it at the right alphanumeric position | |
- for( prev = NULL, current = cmd_functions ; current && Q_strcmp( current->name, cmd_name ) < 0 ; prev = current, current = current->next ) | |
- ; | |
- if( prev ) { | |
- prev->next = cmd; | |
- } else { | |
cmd_functions = cmd; | |
} | |
- cmd->next = current; | |
- | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Insert( HM_CMD, cmd, cmd->name ); | |
-#endif | |
-} | |
/* | |
============ | |
@@ -773,24 +622,31 @@ Cmd_RemoveCommand | |
*/ | |
void Cmd_RemoveCommand( const char *cmd_name ) | |
{ | |
- cmd_t *cmd, **prev; | |
+ cmd_t *cmd, **back; | |
- for( prev = &cmd_functions; ( cmd = *prev ); prev = &cmd->next ) | |
+ if( !cmd_name || !*cmd_name ) | |
+ return; | |
+ | |
+ back = &cmd_functions; | |
+ while( 1 ) | |
{ | |
+ cmd = *back; | |
+ if( !cmd ) return; | |
+ | |
if( !Q_strcmp( cmd_name, cmd->name )) | |
{ | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Remove( HM_CMD, cmd, cmd->name ); | |
-#endif | |
- | |
- *prev = cmd->next; | |
+ *back = cmd->next; | |
+ if( cmd->name ) | |
Mem_Free( cmd->name ); | |
+ | |
+ if( cmd->desc ) | |
Mem_Free( cmd->desc ); | |
- Mem_Free( cmd ); | |
+ Mem_Free( cmd ); | |
return; | |
} | |
+ back = &cmd->next; | |
} | |
} | |
@@ -827,93 +683,12 @@ qboolean Cmd_Exists( const char *cmd_nam | |
{ | |
cmd_t *cmd; | |
-#if defined(XASH_HASHED_VARS) | |
- if( BaseCmd_Find( HM_CMD, cmd_name ) ) | |
- return true; | |
- return false; | |
-#else | |
for( cmd = cmd_functions; cmd; cmd = cmd->next ) | |
{ | |
if( !Q_strcmp( cmd_name, cmd->name )) | |
return true; | |
} | |
return false; | |
-#endif | |
-} | |
- | |
-/* | |
-============ | |
-Cmd_If_f | |
- | |
-Compare and et condition bit if true | |
-============ | |
-*/ | |
-#define BIT64(x) ( (uint64_t)1 << x ) | |
-void Cmd_If_f( void ) | |
-{ | |
- // reset bit first | |
- cmd_cond &= ~BIT64( cmd_condlevel ); | |
- | |
- // usage | |
- if( cmd_argc == 1 ) | |
- { | |
- Msg("Usage: if <op1> [ <operator> <op2> ]\n"); | |
- Msg(":<action1>\n" ); | |
- Msg(":<action2>\n" ); | |
- Msg("else\n" ); | |
- Msg(":<action3>\n" ); | |
- Msg("operands are string or float values\n" ); | |
- Msg("and substituted cvars like '$cl_lw'\n" ); | |
- Msg("operator is '='', '==', '>', '<', '>=', '<=' or '!='\n" ); | |
- } | |
- // one argument - check if nonzero | |
- else if( cmd_argc == 2 ) | |
- { | |
- if( Q_atof( cmd_argv[1] ) ) | |
- cmd_cond |= BIT64( cmd_condlevel ); | |
- } | |
- else if( cmd_argc == 4 ) | |
- { | |
- // simple compare | |
- float f1 = Q_atof( cmd_argv[1] ); | |
- float f2 = Q_atof( cmd_argv[3] ); | |
- | |
- if( !cmd_argv[2][0] ) // this is wrong | |
- return; | |
- | |
- if( ( cmd_argv[2][0] == '=' ) || | |
- ( cmd_argv[2][1] == '=' ) ) // =, ==, >=, <= | |
- { | |
- if( !Q_strcmp( cmd_argv[1], cmd_argv[3] ) || | |
- ( ( f1 || f2 ) && ( f1 == f2 ) ) ) | |
- cmd_cond |= BIT64( cmd_condlevel ); | |
- } | |
- | |
- if( cmd_argv[2][0] == '!' ) // != | |
- { | |
- cmd_cond ^= BIT64( cmd_condlevel ); | |
- return; | |
- } | |
- | |
- if( ( cmd_argv[2][0] == '>' ) && ( f1 > f2 ) ) // >, >= | |
- cmd_cond |= BIT64( cmd_condlevel ); | |
- | |
- if( ( cmd_argv[2][0] == '<' ) && ( f1 < f2 ) ) // <, <= | |
- cmd_cond |= BIT64( cmd_condlevel ); | |
- } | |
-} | |
- | |
- | |
-/* | |
-============ | |
-Cmd_Else_f | |
- | |
-Invert condition bit | |
-============ | |
-*/ | |
-void Cmd_Else_f( void ) | |
-{ | |
- cmd_cond ^= BIT64( cmd_condlevel ); | |
} | |
/* | |
@@ -923,75 +698,20 @@ Cmd_ExecuteString | |
A complete command line has been parsed, so try to execute it | |
============ | |
*/ | |
-void Cmd_ExecuteString( const char *text, cmd_source_t src ) | |
+void Cmd_ExecuteString( char *text, cmd_source_t src ) | |
{ | |
cmd_t *cmd; | |
cmdalias_t *a; | |
- char command[MAX_CMD_LINE], *pcmd = command; | |
- int len = 0;; | |
// set cmd source | |
cmd_source = src; | |
- cmd_condlevel = 0; | |
- | |
- // cvar value substitution | |
- if( cmd_scripting && cmd_scripting->value ) | |
- { | |
- while( *text ) | |
- { | |
- // check for escape | |
- if( ( *text == '\\' || *text == '$') && ( *(text + 1) == '$' )) | |
- { | |
- text ++; | |
- } | |
- else if( *text == '$' ) | |
- { | |
- char token[MAX_CMD_LINE], *ptoken = token; | |
- | |
- // check for correct cvar name | |
- text++; | |
- while( ( *text >= '0' && *text <= '9' ) || | |
- ( *text >= 'A' && *text <= 'Z' ) || | |
- ( *text >= 'a' && *text <= 'z' ) || | |
- (*text == '_' ) ) | |
- *ptoken++ = *text++; | |
- *ptoken = 0; | |
- | |
- len += Q_strncpy( pcmd, Cvar_VariableString( token ), MAX_CMD_LINE - len ); | |
- pcmd = command + len; | |
- | |
- if( !*text ) | |
- break; | |
- } | |
- *pcmd++ = *text++; | |
- len++; | |
- } | |
- *pcmd = 0; | |
- text = command; | |
- | |
- while( *text == ':' ) | |
- { | |
- if( !( cmd_cond & BIT64( cmd_condlevel ) ) ) | |
- return; | |
- cmd_condlevel++; | |
- text++; | |
- } | |
- } | |
// execute the command line | |
Cmd_TokenizeString( text ); | |
if( !Cmd_Argc()) return; // no tokens | |
- // check aliases | |
-#if defined(XASH_HASHED_VARS) | |
- a = BaseCmd_Find(HM_CMDALIAS, cmd_argv[0] ); | |
- if( a ) | |
- { | |
- Cbuf_InsertText( a->value ); | |
- return; | |
- } | |
-#else | |
+ // check alias | |
for( a = cmd_alias; a; a = a->next ) | |
{ | |
if( !Q_stricmp( cmd_argv[0], a->name )) | |
@@ -1000,17 +720,8 @@ void Cmd_ExecuteString( const char *text | |
return; | |
} | |
} | |
-#endif | |
// check functions | |
-#if defined(XASH_HASHED_VARS) | |
- cmd = BaseCmd_Find( HM_CMD, cmd_argv[0] ); | |
- if( cmd && cmd->function ) | |
- { | |
- cmd->function(); | |
- return; | |
- } | |
-#else | |
for( cmd = cmd_functions; cmd; cmd = cmd->next ) | |
{ | |
if( !Q_stricmp( cmd_argv[0], cmd->name ) && cmd->function ) | |
@@ -1019,19 +730,24 @@ void Cmd_ExecuteString( const char *text | |
return; | |
} | |
} | |
-#endif | |
// check cvars | |
if( Cvar_Command( )) return; | |
-#ifndef XASH_DEDICATED | |
+ | |
// forward the command line to the server, so the entity DLL can parse it | |
- // UCyborg: Is src_client used anywhere? | |
- if( cmd_source == src_command && !Host_IsDedicated() ) | |
+ if( cmd_source == src_command && host.type == HOST_NORMAL ) | |
{ | |
if( cls.state >= ca_connected ) | |
+ { | |
Cmd_ForwardToServer(); | |
+ return; | |
+ } | |
+ } | |
+ else if( text[0] != '@' && host.type == HOST_NORMAL ) | |
+ { | |
+ // commands with leading '@' are hidden system commands | |
+ MsgDev( D_INFO, "Unknown command \"%s\"\n", text ); | |
} | |
-#endif | |
} | |
/* | |
@@ -1047,7 +763,6 @@ void Cmd_ForwardToServer( void ) | |
{ | |
char str[MAX_CMD_BUFFER]; | |
-#ifndef XASH_DEDICATED | |
if( cls.demoplayback ) | |
{ | |
if( !Q_stricmp( Cmd_Argv( 0 ), "pause" )) | |
@@ -1075,7 +790,6 @@ void Cmd_ForwardToServer( void ) | |
else Q_strcat( str, "\n" ); | |
BF_WriteString( &cls.netchan.message, str ); | |
-#endif | |
} | |
/* | |
@@ -1086,124 +800,20 @@ Cmd_List_f | |
void Cmd_List_f( void ) | |
{ | |
cmd_t *cmd; | |
- const char *partial; | |
- size_t len; | |
- int i = 0, j = 0; | |
- qboolean ispattern; | |
- | |
- if( Cmd_Argc() > 1 ) | |
- { | |
- partial = Cmd_Argv( 1 ); | |
- len = Q_strlen( partial ); | |
- ispattern = ( Q_strchr( partial, '*' ) || Q_strchr( partial, '?' )); | |
- } | |
- else | |
- { | |
- partial = NULL; | |
- len = 0; | |
- ispattern = false; | |
- } | |
- | |
- for( cmd = cmd_functions; cmd; cmd = cmd->next, i++ ) | |
- { | |
- if( cmd->name[0] == '@' ) | |
- continue; // never show system cmds | |
- | |
- if( partial && ( ispattern ? !matchpattern_with_separator( cmd->name, partial, false, "", false ) : Q_strncmp( partial, cmd->name, len ))) | |
- continue; | |
- | |
- // doesn't look exactly as anticipated, but still better | |
- Msg( "%-*s %s\n", maxcmdnamelen, cmd->name, cmd->desc ); | |
- j++; | |
- } | |
- | |
- if( len ) | |
- { | |
- if( ispattern ) | |
- Msg( "\n%i command%s matching \"%s\"\n", j, ( j > 1 ) ? "s" : "", partial ); | |
- else | |
- Msg( "\n%i command%s beginning with \"%s\"\n", j, ( j > 1 ) ? "s" : "", partial ); | |
- } | |
- else | |
- { | |
- Msg( "\n%i command%s\n", j, ( j > 1 ) ? "s" : "" ); | |
- } | |
- | |
- Msg( "%i total commands\n", i ); | |
-} | |
- | |
-static void Cmd_Apropos_f( void ) | |
-{ | |
- cmd_t *cmd; | |
- convar_t *var; | |
- cmdalias_t *alias; | |
- const char *partial; | |
- int count = 0; | |
- qboolean ispattern; | |
- | |
- if( Cmd_Argc() > 1 ) | |
- partial = Cmd_Args(); | |
- else | |
- { | |
- Msg( "usage: apropos <string>\n" ); | |
- return; | |
- } | |
- | |
- ispattern = partial && ( Q_strchr( partial, '*' ) || Q_strchr( partial, '?' )); | |
- if( !ispattern ) | |
- partial = va( "*%s*", partial ); | |
- | |
- for( var = cvar_vars; var; var = var->next ) | |
- { | |
- if( var->name[0] == '@' ) | |
- continue; // never shows system cvars | |
- | |
- if( !matchpattern_with_separator( var->name, partial, true, "", false ) ) | |
- { | |
- char *desc; | |
- | |
- if( var->flags & CVAR_EXTDLL ) | |
- desc = "game cvar"; | |
- else desc = var->description; | |
- | |
- if( !desc ) | |
- desc = "user cvar"; | |
- | |
- if( !matchpattern_with_separator( desc, partial, true, "", false )) | |
- continue; | |
- } | |
+ int i = 0; | |
+ char *match; | |
- // TODO: maybe add flags output like cvarlist, also | |
- // fix inconsistencies in output from different commands | |
- Msg( "cvar ^3%s^7 is \"%s\" [\"%s\"] %s\n", var->name, var->string, ( var->flags & CVAR_EXTDLL ) ? "" : var->reset_string, ( var->flags & CVAR_EXTDLL ) ? "game cvar" : var->description ); | |
- count++; | |
- } | |
+ if( Cmd_Argc() > 1 ) match = Cmd_Argv( 1 ); | |
+ else match = NULL; | |
for( cmd = cmd_functions; cmd; cmd = cmd->next ) | |
{ | |
- if( cmd->name[0] == '@' ) | |
- continue; // never show system cmds | |
- | |
- if( !matchpattern_with_separator( cmd->name, partial, true, "", false )) | |
- if( !matchpattern_with_separator( cmd->desc, partial, true, "", false )) | |
- continue; | |
- | |
- Msg( "command ^2%s^7: %s\n", cmd->name, cmd->desc ); | |
- count++; | |
- } | |
- | |
- for( alias = cmd_alias; alias; alias = alias->next ) | |
- { | |
- // proceed a bit differently here as an alias value always got a final \n | |
- if( !matchpattern_with_separator( alias->name, partial, true, "", false )) | |
- if( !matchpattern_with_separator( alias->value, partial, true, "\n", false )) // when \n is a separator, wildcards don't match it //-V666 | |
+ if( match && !Q_stricmpext( match, cmd->name )) | |
continue; | |
- | |
- Msg( "alias ^5%s^7: %s", alias->name, alias->value ); // do not print an extra \n | |
- count++; | |
+ Msg( "%10s %s\n", cmd->name, cmd->desc ); | |
+ i++; | |
} | |
- | |
- Msg( "\n%i result%s\n\n", count, (count > 1) ? "s" : "" ); | |
+ Msg( "%i commands\n", i ); | |
} | |
/* | |
@@ -1217,36 +827,42 @@ void Cmd_Unlink( int group ) | |
{ | |
cmd_t *cmd; | |
cmd_t **prev; | |
+ int count = 0; | |
if( Cvar_VariableInteger( "host_gameloaded" ) && ( group & CMD_EXTDLL )) | |
{ | |
- Msg( "Can't unlink commands while game is loaded\n" ); | |
+ Msg( "can't unlink cvars while game is loaded\n" ); | |
return; | |
} | |
if( Cvar_VariableInteger( "host_clientloaded" ) && ( group & CMD_CLIENTDLL )) | |
{ | |
- Msg( "Can't unlink commands while client is loaded\n" ); | |
+ Msg( "can't unlink cvars while client is loaded\n" ); | |
return; | |
} | |
- for( prev = &cmd_functions; ( cmd = *prev ); ) | |
+ prev = &cmd_functions; | |
+ while( 1 ) | |
{ | |
+ cmd = *prev; | |
+ if( !cmd ) break; | |
+ | |
if( group && !( cmd->flags & group )) | |
{ | |
prev = &cmd->next; | |
continue; | |
} | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Remove( HM_CMD, cmd, cmd->name ); | |
-#endif | |
- | |
*prev = cmd->next; | |
+ if( cmd->name ) | |
Mem_Free( cmd->name ); | |
+ | |
+ if( cmd->desc ) | |
Mem_Free( cmd->desc ); | |
+ | |
Mem_Free( cmd ); | |
+ count++; | |
} | |
} | |
@@ -1268,33 +884,14 @@ Cmd_Init | |
*/ | |
void Cmd_Init( void ) | |
{ | |
- cvar_vars = NULL; | |
- cmd_functions = NULL; | |
- cmd_argc = 0; | |
- cmd_args = NULL; | |
- cmd_alias = NULL; | |
- cmd_cond = 0; | |
Cbuf_Init(); | |
+ cmd_functions = NULL; | |
// register our commands | |
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 until next rendered frame" ); | |
- Cmd_AddCommand( "cmdlist", Cmd_List_f, "display all console commands beginning with the specified prefix or matching the specified wildcard pattern" ); | |
- Cmd_AddCommand( "apropos", Cmd_Apropos_f, "lists all console variables/commands/aliases containing the specified string in the name or description" ); | |
+ 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, va( "execute commandline parameters (must be present in %s.rc script)", SI.ModuleName )); | |
Cmd_AddCommand( "cmd", Cmd_ForwardToServer, "send a console commandline to the server" ); | |
- Cmd_AddCommand( "alias", Cmd_Alias_f, "create a script function, without arguments show the list of all aliases" ); | |
- Cmd_AddCommand( "unalias", Cmd_UnAlias_f, "remove a script function" ); | |
- Cmd_AddCommand( "if", Cmd_If_f, "compare and set condition bits" ); | |
- Cmd_AddCommand( "else", Cmd_Else_f, "invert condition bit" ); | |
-} | |
- | |
-void Cmd_Shutdown( void ) | |
-{ | |
- int i; | |
- for( i = 0; i < cmd_argc; i++ ) | |
- Z_Free( cmd_argv[i] ); | |
- cmd_argc = 0; // clear previous args | |
- cmd_args = NULL; | |
- //Q_memset( cmd_text_buf, 0, sizeof( cmd_text_buf ) ); | |
+ Cmd_AddCommand ("alias", Cmd_Alias_f, "create a script function. Without arguments show the list of all alias" ); | |
} | |
diff --suppress-blank-empty -prudwEZbB engine/common/common.c /mnt/data/Xash3D_original/engine/common/common.c | |
--- engine/common/common.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/common.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -62,23 +62,8 @@ skipwhite: | |
data++; | |
while( 1 ) | |
{ | |
- c = (byte)*data; | |
- | |
- // unexpected line end | |
- if( !c ) | |
- { | |
- token[len] = 0; | |
- return data; | |
- } | |
- data++; | |
- | |
- if( c == '\\' && *data == '"' ) | |
- { | |
- token[len++] = *data++; | |
- continue; | |
- } | |
- | |
- if( c == '\"' ) | |
+ c = (byte)*data++; | |
+ if( c == '\"' || !c ) | |
{ | |
token[len] = 0; | |
return data; | |
@@ -277,7 +262,7 @@ byte* COM_LoadFileForMe( const char *fil | |
{ | |
string name; | |
byte *file, *pfile; | |
- fs_offset_t iLength; | |
+ int iLength; | |
if( !filename || !*filename ) | |
{ | |
@@ -313,7 +298,7 @@ byte *COM_LoadFile( const char *filename | |
{ | |
string name; | |
byte *file, *pfile; | |
- fs_offset_t iLength; | |
+ int iLength; | |
ASSERT( usehunk == 5 ); | |
@@ -444,7 +429,7 @@ void Con_Printf( char *szFmt, ... ) | |
return; | |
va_start( args, szFmt ); | |
- Q_vsnprintf( buffer, sizeof( buffer ), szFmt, args ); | |
+ Q_vsnprintf( buffer, 16384, szFmt, args ); | |
va_end( args ); | |
Sys_Print( buffer ); | |
@@ -465,7 +450,7 @@ void Con_DPrintf( char *szFmt, ... ) | |
return; | |
va_start( args, szFmt ); | |
- Q_vsnprintf( buffer, sizeof( buffer ), szFmt, args ); | |
+ Q_vsnprintf( buffer, 16384, szFmt, args ); | |
va_end( args ); | |
Sys_Print( buffer ); | |
@@ -485,8 +470,8 @@ int COM_CompareFileTime( const char *fil | |
if( filename1 && filename2 ) | |
{ | |
- int ft1 = FS_FileTime( filename1, false ); | |
- int ft2 = FS_FileTime( filename2, false ); | |
+ long ft1 = FS_FileTime( filename1, false ); | |
+ long ft2 = FS_FileTime( filename2, false ); | |
// one of files is missing | |
if( ft1 == -1 || ft2 == -1 ) | |
@@ -507,7 +492,7 @@ pfnGetGameDir | |
void pfnGetGameDir( char *szGetGameDir ) | |
{ | |
if( !szGetGameDir ) return; | |
- Q_sprintf( szGetGameDir, "%s", GI->gamedir ); | |
+ Q_sprintf( szGetGameDir, "%s/%s", host.rootdir, GI->gamedir ); | |
} | |
/* | |
diff --suppress-blank-empty -prudwEZbB engine/common/common.h /mnt/data/Xash3D_original/engine/common/common.h | |
--- engine/common/common.h 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/common.h 2016-08-19 14:21:49.000000000 +0000 | |
@@ -20,33 +20,25 @@ GNU General Public License for more deta | |
extern "C" { | |
#endif | |
-#include "port.h" | |
- | |
-#ifndef _WIN32 | |
-#ifdef __linux__ | |
-#include <linux/limits.h> // PATH_MAX | |
-#endif | |
-#include <stddef.h> // size_t | |
-#include <stdio.h> // off_t | |
-#include <stdarg.h> // va_list | |
-#include <stdlib.h> // rand, abs | |
- | |
-#define EXPORT __attribute__ ((visibility ("default"))) | |
-#else | |
-#include <sys/types.h> // off_t | |
-#include <stdio.h> | |
-#include <stdlib.h> // rand, adbs | |
-#include <stdarg.h> // va | |
-#define EXPORT __declspec( dllexport ) | |
-#undef PATH_MAX | |
-#define PATH_MAX 4096 // Try workaround some strange bugs | |
-#endif | |
+// disable some warnings | |
+#pragma warning(disable : 4244) // MIPS | |
+#pragma warning(disable : 4018) // signed/unsigned mismatch | |
+#pragma warning(disable : 4305) // truncation from const double to float | |
+#pragma warning(disable : 4115) // named type definition in parentheses | |
+#pragma warning(disable : 4100) // unreferenced formal parameter | |
+#pragma warning(disable : 4127) // conditional expression is constant | |
+#pragma warning(disable : 4057) // differs in indirection to slightly different base types | |
+#pragma warning(disable : 4201) // nonstandard extension used | |
+#pragma warning(disable : 4706) // assignment within conditional expression | |
+#pragma warning(disable : 4054) // type cast' : from function pointer | |
+#pragma warning(disable : 4310) // cast truncates constant value | |
#define MAX_STRING 256 // generic string | |
#define MAX_INFO_STRING 256 // infostrings are transmitted across network | |
-#define MAX_SYSPATH PATH_MAX // system filepath | |
+#define MAX_SYSPATH 1024 // system filepath | |
#define MAX_MODS 512 // environment games that engine can keep visible | |
-#define BIT( n ) (1U << ( n )) | |
+#define EXPORT __declspec( dllexport ) | |
+#define BIT( n ) (1<<( n )) | |
#ifndef __cplusplus | |
#define NULL ((void *)0) | |
@@ -58,17 +50,10 @@ extern "C" { | |
#define Mod_AllowMaterials() ( mod_allow_materials != NULL && mod_allow_materials->integer && !( host.features & ENGINE_DISABLE_HDTEXTURES )) | |
-#ifdef XASH_FORCEINLINE | |
-#define xash_force_inline _inline | |
-#else | |
-#define xash_force_inline | |
-#endif | |
- | |
-typedef unsigned int dword; | |
+typedef unsigned long dword; | |
typedef unsigned int uint; | |
typedef char string[MAX_STRING]; | |
-typedef struct searchpath_s searchpath_t; | |
-typedef off_t fs_offset_t; | |
+typedef long fs_offset_t; | |
typedef struct file_s file_t; // normal file | |
typedef struct wfile_s wfile_t; // wad file | |
typedef struct stream_s stream_t; // sound stream for background music playing | |
@@ -91,25 +76,16 @@ enum | |
typedef enum | |
{ | |
- HOST_UNKNOWN = 0, // prevent detecting as normal before host.type set | |
HOST_NORMAL, // listen server, singleplayer | |
HOST_DEDICATED, | |
} instance_t; | |
-#ifdef XASH_DEDICATED | |
-#define Host_IsDedicated() ( true ) | |
-#else | |
-#define Host_IsDedicated() ( host.type == HOST_DEDICATED ) | |
-#endif | |
- | |
#include "system.h" | |
#include "ref_params.h" | |
#include "com_model.h" | |
#include "crtlib.h" | |
-#define XASH_VERSION "0.17.1" // engine current version | |
-// since this fork have own version, this is just left for compability | |
-#define BASED_VERSION 0.98f | |
+#define XASH_VERSION 0.98f // engine current version | |
// PERFORMANCE INFO | |
#define MIN_FPS 15.0 // host minimum fps value for maxfps. | |
@@ -141,7 +117,6 @@ typedef enum | |
#define FS_STATIC_PATH 1 // FS_ClearSearchPath will be ignore this path | |
#define FS_NOWRITE_PATH 2 // default behavior - last added gamedir set as writedir. This flag disables it | |
#define FS_GAMEDIR_PATH 4 // just a marker for gamedir path | |
-#define FS_CUSTOM_PATH 8 // map search allowed | |
#define GI SI.GameInfo | |
#define FS_Gamedir() SI.GameInfo->gamedir | |
@@ -162,10 +137,7 @@ extern convar_t *cl_allow_levelshots; | |
extern convar_t *mod_allow_materials; | |
extern convar_t *host_limitlocal; | |
extern convar_t *host_maxfps; | |
-extern convar_t *net_qport; | |
-extern convar_t *download_types; | |
-extern convar_t *host_xashds_hacks; | |
-extern convar_t *sv_master; | |
+ | |
/* | |
============================================================== | |
@@ -196,9 +168,7 @@ typedef struct gameinfo_s | |
// .dll pathes | |
char dll_path[64]; // e.g. "bin" or "cl_dlls" | |
char game_dll[64]; // custom path for game.dll | |
- char game_dll_linux[64]; // custom path for game.dll | |
- char game_dll_osx[64]; // custom path for game.dll | |
- char client_lib[64]; // custom name of client library | |
+ | |
// .ico path | |
char iconpath[64]; // "game.ico" by default | |
@@ -234,8 +204,6 @@ typedef struct sysinfo_s | |
gameinfo_t *GameInfo; // current GameInfo | |
gameinfo_t *games[MAX_MODS]; // environment games (founded at each engine start) | |
int numgames; | |
- char gamedll[256]; | |
- char clientlib[256]; | |
} sysinfo_t; | |
typedef enum | |
@@ -285,8 +253,7 @@ typedef enum | |
typedef enum | |
{ | |
NS_CLIENT, | |
- NS_SERVER, | |
- NS_MULTICAST | |
+ NS_SERVER | |
} netsrc_t; | |
#include "netadr.h" | |
@@ -319,8 +286,10 @@ typedef struct host_parm_s | |
{ | |
HINSTANCE hInst; | |
HANDLE hMutex; | |
+ LPTOP_LEVEL_EXCEPTION_FILTER oldFilter; | |
+ | |
host_state state; // global host state | |
- instance_t type; // running at | |
+ uint type; // running at | |
jmp_buf abortframe; // abort current frame | |
dword errorframe; // to prevent multiple host error | |
byte *mempool; // static mempool for misc allocations | |
@@ -329,7 +298,7 @@ typedef struct host_parm_s | |
// command line parms | |
int argc; | |
- const char **argv; | |
+ const char *argv[MAX_NUM_ARGVS]; | |
double realtime; // host.curtime | |
double frametime; // time between engine frames | |
@@ -338,12 +307,9 @@ typedef struct host_parm_s | |
uint framecount; // global framecount | |
// list of unique decal indexes | |
- signed char draw_decals[MAX_DECALS][CS_SIZE]; | |
-#ifdef XASH_SDL | |
- SDL_Window* hWnd; // main window | |
-#else | |
- void *hWnd; | |
-#endif | |
+ char draw_decals[MAX_DECALS][CS_SIZE]; | |
+ | |
+ HWND hWnd; // main window | |
int developer; // show all developer's message | |
int old_developer; // keep real dev state (we need enable dev-mode in multiplayer) | |
qboolean key_overstrike; // key overstrike mode | |
@@ -375,8 +341,6 @@ typedef struct host_parm_s | |
soundlist_t *soundList; // used for keep ambient sounds, when renderer or sound is restarted | |
int numsounds; | |
- qboolean enabledll; | |
- qboolean textmode; | |
} host_parm_t; | |
extern host_parm_t host; | |
@@ -385,11 +349,9 @@ extern sysinfo_t SI; | |
// | |
// filesystem.c | |
// | |
-int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive ); | |
-int matchpattern_with_separator( const char *in, const char *pattern, qboolean caseinsensitive, const char *separators, qboolean wildcard_least_one ); | |
void FS_Init( void ); | |
void FS_Path( void ); | |
-char *FS_ToLowerCase( const char *path ); | |
+void FS_Rescan( void ); | |
void FS_Shutdown( void ); | |
void FS_ClearSearchPath( void ); | |
void FS_AllowDirectPaths( qboolean enable ); | |
@@ -399,13 +361,12 @@ void FS_LoadGameInfo( const char *rootfo | |
void FS_FileBase( const char *in, char *out ); | |
const char *FS_FileExtension( const char *in ); | |
void FS_DefaultExtension( char *path, const char *extension ); | |
-void FS_ExtractFilePath( const char *path, char* dest ); | |
+void FS_ExtractFilePath( const char* const path, char* dest ); | |
const char *FS_GetDiskPath( const char *name, qboolean gamedironly ); | |
const char *FS_FileWithoutPath( const char *in ); | |
wfile_t *W_Open( const char *filename, const char *mode ); | |
byte *W_LoadLump( wfile_t *wad, const char *lumpname, size_t *lumpsizeptr, const char type ); | |
void W_Close( wfile_t *wad ); | |
-searchpath_t *FS_FindFile( const char *name, int *index, qboolean gamedironly ); | |
file_t *FS_OpenFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ); | |
byte *FS_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ); | |
qboolean FS_WriteFile( const char *filename, const void *data, fs_offset_t len ); | |
@@ -419,7 +380,8 @@ fs_offset_t FS_Write( file_t *file, cons | |
fs_offset_t FS_Read( file_t *file, void *buffer, size_t buffersize ); | |
int FS_VPrintf( file_t *file, const char *format, va_list ap ); | |
int FS_Seek( file_t *file, fs_offset_t offset, int whence ); | |
-int FS_Printf( file_t *file, const char *format, ... ) _format(2); | |
+int FS_Gets( file_t *file, byte *string, size_t bufsize ); | |
+int FS_Printf( file_t *file, const char *format, ... ); | |
fs_offset_t FS_FileSize( const char *filename, qboolean gamedironly ); | |
fs_offset_t FS_FileTime( const char *filename, qboolean gamedironly ); | |
int FS_Print( file_t *file, const char *msg ); | |
@@ -436,13 +398,13 @@ int FS_Close( file_t *file ); | |
int FS_Getc( file_t *file ); | |
qboolean FS_Eof( file_t *file ); | |
fs_offset_t FS_FileLength( file_t *f ); | |
-void FS_Rescan( void ); | |
// | |
// network.c | |
// | |
void NET_Init( void ); | |
void NET_Shutdown( void ); | |
+void NET_Sleep( int msec ); | |
void NET_Config( qboolean net_enable ); | |
qboolean NET_IsLocalAddress( netadr_t adr ); | |
char *NET_AdrToString( const netadr_t a ); | |
@@ -556,7 +518,7 @@ typedef struct rgbdata_s | |
word depth; // image depth | |
uint type; // compression type | |
uint flags; // misc image flags | |
- word encode; | |
+ word encode; // DXT may have custom encoder, that will be decoded in GLSL-side | |
byte numMips; // mipmap count | |
byte *palette; // palette if present | |
byte *buffer; // image buffer | |
@@ -594,7 +556,6 @@ qboolean Image_Process( rgbdata_t **pix, | |
void Image_PaletteHueReplace( byte *palSrc, int newHue, int start, int end ); | |
void Image_SetForceFlags( uint flags ); // set image force flags on loading | |
size_t Image_DXTGetLinearSize( int type, int width, int height, int depth ); | |
-void Image_SetMDLPointer(byte *p); | |
/* | |
======================================================================== | |
@@ -654,9 +615,9 @@ wavdata_t *FS_LoadSound( const char *fil | |
void FS_FreeSound( wavdata_t *pack ); | |
stream_t *FS_OpenStream( const char *filename ); | |
wavdata_t *FS_StreamInfo( stream_t *stream ); | |
-int FS_ReadStream( stream_t *stream, int bytes, void *buffer ); | |
-int FS_SetStreamPos( stream_t *stream, int newpos ); | |
-int FS_GetStreamPos( stream_t *stream ); | |
+long FS_ReadStream( stream_t *stream, int bytes, void *buffer ); | |
+long FS_SetStreamPos( stream_t *stream, long newpos ); | |
+long FS_GetStreamPos( stream_t *stream ); | |
void FS_FreeStream( stream_t *stream ); | |
qboolean Sound_Process( wavdata_t **wav, int rate, int width, uint flags ); | |
uint Sound_GetApproxWavePlayLen( const char *filepath ); | |
@@ -672,7 +633,7 @@ int Q_buildnum( void ); | |
void EXPORT Host_Shutdown( void ); | |
void Host_SetServerState( int state ); | |
int Host_ServerState( void ); | |
-int Host_CompareFileTime( int ft1, int ft2 ); | |
+int Host_CompareFileTime( long ft1, long ft2 ); | |
void Host_NewInstance( const char *name, const char *finalmsg ); | |
qboolean Host_NewGame( const char *mapName, qboolean loadGame ); | |
void Host_EndGame( const char *message, ... ); | |
@@ -688,8 +649,7 @@ qboolean Host_IsLocalGame( void ); | |
qboolean Host_IsLocalClient( void ); | |
void Host_ShutdownServer( void ); | |
void Host_Print( const char *txt ); | |
-void Host_Error( const char *error, ... ) _format(1); | |
-void Host_MapDesignError( const char *error, ... ) _format(1); | |
+void Host_Error( const char *error, ... ); | |
void Host_PrintEngineFeatures( void ); | |
void Host_InitDecals( void ); | |
void Host_Credits( void ); | |
@@ -734,8 +694,8 @@ void pfnGetGameDir( char *szGetGameDir ) | |
int pfnDecalIndex( const char *m ); | |
int pfnGetModelType( model_t *mod ); | |
int pfnIsMapValid( char *filename ); | |
-void Con_DPrintf( char *fmt, ... ) _format(1); | |
-void Con_Printf( char *szFmt, ... ) _format(1); | |
+void Con_DPrintf( char *fmt, ... ); | |
+void Con_Printf( char *szFmt, ... ); | |
int pfnIsInGame( void ); | |
// CS:CS engfuncs (stubs) | |
@@ -804,7 +764,6 @@ int Key_StringToKeynum( const char *str | |
int Key_GetKey( const char *binding ); | |
void Key_EnumCmds_f( void ); | |
void Key_SetKeyDest( int key_dest ); | |
-void Key_EnableTextInput( qboolean enable, qboolean force ); | |
// | |
// avikit.c | |
@@ -825,25 +784,6 @@ movie_state_t *AVI_GetState( int num ); | |
qboolean AVI_Initailize( void ); | |
void AVI_Shutdown( void ); | |
-#include "con_nprint.h" | |
-#include "cl_entity.h" | |
-#include "studio_event.h" | |
-#include "pm_defs.h" | |
- | |
-// Compiler warning: struct X declared inside parameter list | |
-struct sizebuf_s; | |
-struct modelstate_s; | |
-struct pmtrace_s; | |
- | |
- | |
-// | |
-// input.c | |
-// | |
- | |
-void IN_EngineAppendMove( float frametime, usercmd_t *cmd, qboolean active ); | |
-//void IN_JoyAppendMove( usercmd_t *cmd, float forwardmove, float sidemove ); | |
- | |
- | |
// shared calls | |
qboolean CL_IsInGame( void ); | |
qboolean CL_IsInMenu( void ); | |
@@ -865,13 +805,14 @@ struct pmtrace_s *PM_TraceLine( float *s | |
void SV_StartSound( edict_t *ent, int chan, const char *sample, float vol, float attn, int flags, int pitch ); | |
void SV_StartMusic( const char *curtrack, const char *looptrack, fs_offset_t position ); | |
void SV_CreateDecal( struct sizebuf_s *msg, const float *origin, int decalIndex, int entityIndex, int modelIndex, int flags, float scale ); | |
-void SV_CreateStudioDecal( struct sizebuf_s *msg, const float *origin, const float *start, int decalIndex, int entityIndex, int modelIndex, int flags, struct modelstate_s *state ); | |
+void SV_CreateStudioDecal( struct sizebuf_s *msg, const float *origin, const float *start, int decalIndex, int entityIndex, int modelIndex, | |
+int flags, struct modelstate_s *state ); | |
struct sizebuf_s *SV_GetReliableDatagram( void ); | |
qboolean SV_RestoreCustomDecal( struct decallist_s *entry, edict_t *pEdict, qboolean adjacent ); | |
int R_CreateDecalList( struct decallist_s *pList, qboolean changelevel ); | |
void R_ClearAllDecals( void ); | |
void R_ClearStaticEntities( void ); | |
-qboolean S_StreamGetCurrentState( char *currentTrack, char *loopTrack, fs_offset_t *position ); | |
+qboolean S_StreamGetCurrentState( char *currentTrack, char *loopTrack, int *position ); | |
struct cl_entity_s *CL_GetEntityByIndex( int index ); | |
struct cl_entity_s *CL_GetLocalPlayer( void ); | |
struct player_info_s *CL_GetPlayerInfo( int playerIndex ); | |
@@ -903,14 +844,14 @@ void SCR_Init( void ); | |
void SCR_UpdateScreen( void ); | |
void SCR_BeginLoadingPlaque( qboolean is_background ); | |
void SCR_CheckStartupVids( void ); | |
-int SCR_GetAudioChunk( char *rawdata, int length ); | |
+long SCR_GetAudioChunk( char *rawdata, long length ); | |
wavdata_t *SCR_GetMovieInfo( void ); | |
void SCR_Shutdown( void ); | |
void Con_Print( const char *txt ); | |
-void Con_NPrintf( int idx, char *fmt, ... ) _format(2); | |
-void Con_NXPrintf( struct con_nprint_s *info, char *fmt, ... ) _format(2); | |
-void UI_NPrintf( int idx, char *fmt, ... ) _format(2); | |
-void UI_NXPrintf( struct con_nprint_s *info, char *fmt, ... ) _format(2); | |
+void Con_NPrintf( int idx, char *fmt, ... ); | |
+void Con_NXPrintf( struct con_nprint_s *info, char *fmt, ... ); | |
+void UI_NPrintf( int idx, char *fmt, ... ); | |
+void UI_NXPrintf( struct con_nprint_s *info, char *fmt, ... ); | |
char *Info_ValueForKey( const char *s, const char *key ); | |
void Info_RemovePrefixedKeys( char *start, char prefix ); | |
qboolean Info_RemoveKey( char *s, const char *key ); | |
@@ -923,10 +864,10 @@ char *Cvar_Serverinfo( void ); | |
void Cmd_WriteVariables( file_t *f ); | |
qboolean Cmd_CheckMapsList( qboolean fRefresh ); | |
void Cmd_AutoComplete( char *complete_string ); | |
-void COM_SetRandomSeed( int lSeed ); | |
-int Com_RandomLong( int lMin, int lMax ); | |
+void COM_SetRandomSeed( long lSeed ); | |
+long Com_RandomLong( long lMin, long lMax ); | |
float Com_RandomFloat( float fMin, float fMax ); | |
-void TrimSpace( const char *source, char *dest );\ | |
+void TrimSpace( const char *source, char *dest ); | |
const byte *GL_TextureData( unsigned int texnum ); | |
void GL_FreeImage( const char *name ); | |
void VID_RestoreGamma( void ); | |
@@ -938,13 +879,6 @@ char *Cmd_GetName( struct cmd_s *cmd ); | |
cvar_t *Cvar_GetList( void ); | |
void Cmd_Null_f( void ); | |
-void HTTP_AddDownload( char *path, int size, qboolean process ); | |
-void HTTP_ResetProcessState ( void ); | |
-void HTTP_Init( void ); | |
-void HTTP_Shutdown( void ); | |
-void HTTP_Run( void ); | |
-void CL_ProcessFile( qboolean successfully_received, const char *filename ); | |
- | |
typedef struct autocomplete_list_s | |
{ | |
const char *name; | |
@@ -952,25 +886,15 @@ typedef struct autocomplete_list_s | |
} autocomplete_list_t; | |
extern autocomplete_list_t cmd_list[]; | |
- | |
-typedef struct | |
-{ | |
- string buffer; | |
- int cursor; | |
- int scroll; | |
- int widthInChars; | |
-} field_t; | |
- | |
-void Con_CompleteCommand( field_t *field ); | |
-void Con_ClearAutoComplete(); | |
- | |
extern const char *svc_strings[256]; | |
// soundlib shared exports | |
qboolean S_Init( void ); | |
void S_Shutdown( void ); | |
+void S_Activate( qboolean active, void *hInst ); | |
void S_StopSound( int entnum, int channel, const char *soundname ); | |
int S_GetCurrentStaticSounds( soundlist_t *pout, int size ); | |
+void S_StopBackgroundTrack( void ); | |
void S_StopAllSounds( void ); | |
// gamma routines | |
@@ -978,10 +902,6 @@ void BuildGammaTable( float gamma, float | |
byte TextureToTexGamma( byte b ); | |
byte TextureToGamma( byte b ); | |
-#ifdef __ANDROID__ | |
-#include "platform/android/android-main.h" | |
-#endif | |
- | |
#ifdef __cplusplus | |
} | |
#endif | |
diff --suppress-blank-empty -prudwEZbB engine/common/console.c /mnt/data/Xash3D_original/engine/common/console.c | |
--- engine/common/console.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/console.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -12,31 +12,24 @@ but WITHOUT ANY WARRANTY; without even t | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
+ | |
#include "common.h" | |
#include "client.h" | |
#include "keydefs.h" | |
#include "protocol.h" // get the protocol version | |
+#include "con_nprint.h" | |
#include "gl_local.h" | |
#include "qfont.h" | |
-#include "server.h" // Log_Printf( , ... ) | |
convar_t *con_notifytime; | |
convar_t *scr_conspeed; | |
convar_t *con_fontsize; | |
-convar_t *con_maxfrac; | |
-convar_t *con_halffrac; | |
-convar_t *con_charset; | |
-convar_t *con_alpha; | |
-convar_t *con_black; | |
- | |
-static int g_codepage = 0; | |
-static qboolean g_utf8 = false; | |
#define CON_TIMES 5 // need for 4 lines | |
#define COLOR_DEFAULT '7' | |
#define CON_HISTORY 64 | |
#define MAX_DBG_NOTIFY 128 | |
+#define CON_MAXCMDS 4096 // auto-complete intermediate list | |
#define CON_NUMFONTS 3 // maxfonts | |
#define CON_TEXTSIZE 131072 // 128 kb buffer | |
@@ -56,6 +49,14 @@ rgba_t g_color_table[8] = | |
typedef struct | |
{ | |
+ string buffer; | |
+ int cursor; | |
+ int scroll; | |
+ int widthInChars; | |
+} field_t; | |
+ | |
+typedef struct | |
+{ | |
string szNotify; | |
float expire; | |
rgba_t color; | |
@@ -102,6 +103,13 @@ typedef struct | |
notify_t notify[MAX_DBG_NOTIFY]; // for Con_NXPrintf | |
qboolean draw_notify; // true if we have NXPrint message | |
+ | |
+ // console auto-complete | |
+ string shortestMatch; | |
+ field_t *completionField; // con.input or dedicated server fake field-line | |
+ char *completionString; | |
+ char *cmds[CON_MAXCMDS]; | |
+ int matchCount; | |
} console_t; | |
static console_t con; | |
@@ -188,7 +196,17 @@ void Con_ClearTyping( void ) | |
Con_ClearField( &con.input ); | |
con.input.widthInChars = con.linewidth; | |
- Con_ClearAutoComplete(); | |
+ // free the old autocomplete list | |
+ for( i = 0; i < con.matchCount; i++ ) | |
+ { | |
+ if( con.cmds[i] != NULL ) | |
+ { | |
+ Mem_Free( con.cmds[i] ); | |
+ con.cmds[i] = NULL; | |
+ } | |
+ } | |
+ | |
+ con.matchCount = 0; | |
} | |
/* | |
@@ -426,19 +444,17 @@ static void Con_LoadConsoleFont( int fon | |
font->hFontTexture = GL_LoadTexture( va( "fonts.wad/font%i", fontNumber ), NULL, 0, TF_FONT|TF_NEAREST, NULL ); | |
R_GetTextureParms( &fontWidth, NULL, font->hFontTexture ); | |
- if( fontWidth == 0 ) return; | |
- | |
// setup creditsfont | |
- if( FS_FileExists( va( "fonts.wad/font%i.fnt", fontNumber ), false ) ) | |
+ if( FS_FileExists( va( "fonts.wad/font%i.fnt", fontNumber ), false ) && fontWidth != 0 ) | |
{ | |
byte *buffer; | |
- fs_offset_t length; | |
+ size_t length; | |
qfont_t *src; | |
// half-life font with variable chars witdh | |
buffer = FS_LoadFile( va( "fonts.wad/font%i", fontNumber ), &length, false ); | |
- if( buffer && length >= ( fs_offset_t )sizeof( qfont_t )) | |
+ if( buffer && length >= sizeof( qfont_t )) | |
{ | |
int i; | |
@@ -485,144 +501,7 @@ static void Con_LoadConchars( void ) | |
} | |
-// CP1251 table | |
- | |
-int table_cp1251[64] = { | |
- 0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021, | |
- 0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F, | |
- 0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, | |
- 0x007F, 0x2122, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F, | |
- 0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7, | |
- 0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407, | |
- 0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7, | |
- 0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457 | |
-}; | |
- | |
-/* | |
-============================ | |
-Con_UtfProcessChar | |
- | |
-Convert utf char to current font's single-byte encoding | |
-============================ | |
-*/ | |
-int Con_UtfProcessCharForce( int in ) | |
-{ | |
- static int m = -1, k = 0; //multibyte state | |
- static int uc = 0; //unicode char | |
- | |
- if( !in ) | |
- { | |
- m = -1; | |
- k = 0; | |
- uc = 0; | |
- return 0; | |
- } | |
- | |
- // Get character length | |
- if(m == -1) | |
- { | |
- uc = 0; | |
- if( in >= 0xF8 ) | |
- return 0; | |
- else if( in >= 0xF0 ) | |
- uc = in & 0x07, m = 3; | |
- else if( in >= 0xE0 ) | |
- uc = in & 0x0F, m = 2; | |
- else if( in >= 0xC0 ) | |
- uc = in & 0x1F, m = 1; | |
- else if( in <= 0x7F) | |
- return in; //ascii | |
- // return 0 if we need more chars to decode one | |
- k=0; | |
- return 0; | |
- } | |
- // get more chars | |
- else if( k <= m ) | |
- { | |
- uc <<= 6; | |
- uc += in & 0x3F; | |
- k++; | |
- } | |
- if( in > 0xBF || m < 0 ) | |
- { | |
- m = -1; | |
- return 0; | |
- } | |
- if( k == m ) | |
- { | |
- k = m = -1; | |
- if( g_codepage == 1251 ) | |
- { | |
- // cp1251 now | |
- if( uc >= 0x0410 && uc <= 0x042F ) | |
- return uc - 0x410 + 0xC0; | |
- if( uc >= 0x0430 && uc <= 0x044F ) | |
- return uc - 0x430 + 0xE0; | |
- else | |
- { | |
- int i; | |
- for( i = 0; i < 64; i++ ) | |
- if( table_cp1251[i] == uc ) | |
- return i + 0x80; | |
- } | |
- } | |
- // not implemented yet | |
- return '?'; | |
- } | |
- return 0; | |
-} | |
- | |
-int Con_UtfProcessChar( int in ) | |
-{ | |
- if( !g_utf8 ) | |
- return in; | |
- else | |
- return Con_UtfProcessCharForce( in ); | |
-} | |
-/* | |
-================= | |
-Con_UtfMoveLeft | |
- | |
-get position of previous printful char | |
-================= | |
-*/ | |
-int Con_UtfMoveLeft( char *str, int pos ) | |
-{ | |
- int i, j, k = 0; | |
- if( !g_utf8 ) | |
- return pos - 1; | |
- Con_UtfProcessChar( 0 ); | |
- if(pos == 1) return 0; | |
- for( i = 0; i < pos-1; i++ ) | |
- if( Con_UtfProcessChar( (unsigned char)str[i] ) ) | |
- k = i+1; | |
- Con_UtfProcessChar( 0 ); | |
- return k; | |
-} | |
- | |
-/* | |
-================= | |
-Con_UtfMoveRight | |
- | |
-get next of previous printful char | |
-================= | |
-*/ | |
-int Con_UtfMoveRight( char *str, int pos, int length ) | |
-{ | |
- int i; | |
- if( !g_utf8 ) | |
- return pos + 1; | |
- Con_UtfProcessChar( 0 ); | |
- for( i = pos; i <= length; i++ ) | |
- { | |
- if( Con_UtfProcessChar( (unsigned char)str[i] ) ) | |
- return i+1; | |
- } | |
- Con_UtfProcessChar( 0 ); | |
- return pos+1; | |
-} | |
- | |
-int Con_DrawGenericChar( int x, int y, int number, rgba_t color ) | |
+static int Con_DrawGenericChar( int x, int y, int number, rgba_t color ) | |
{ | |
int width, height; | |
float s1, t1, s2, t2; | |
@@ -633,9 +512,7 @@ int Con_DrawGenericChar( int x, int y, i | |
if( !con.curFont || !con.curFont->valid ) | |
return 0; | |
- number = Con_UtfProcessChar(number); | |
- if( number < 32 ) | |
- return 0; | |
+ if( number < 32 ) return 0; | |
if( y < -con.curFont->charHeight ) | |
return 0; | |
@@ -697,7 +574,7 @@ void Con_DrawStringLen( const char *pTex | |
{ | |
byte c = *pText; | |
- if( *pText == '\n' ) //-V595 | |
+ if( *pText == '\n' ) | |
{ | |
pText++; | |
curLength = 0; | |
@@ -710,12 +587,7 @@ void Con_DrawStringLen( const char *pTex | |
continue; | |
} | |
- // Convert to unicode | |
- c = Con_UtfProcessChar( c ); | |
- | |
- if( c ) | |
curLength += con.curFont->charWidths[ c ]; | |
- | |
pText++; | |
if( curLength > *length ) | |
@@ -740,8 +612,6 @@ int Con_DrawGenericString( int x, int y, | |
if( !con.curFont ) return 0; // no font set | |
- Con_UtfProcessChar( 0 ); | |
- | |
// draw the colored text | |
s = string; | |
*(uint *)color = *(uint *)setColor; | |
@@ -797,16 +667,11 @@ void Con_Init( void ) | |
int i; | |
// must be init before startup video subsystem | |
- scr_width = Cvar_Get( "width", "640", CVAR_RENDERINFO, "screen width" ); | |
- scr_height = Cvar_Get( "height", "480", CVAR_RENDERINFO, "screen height" ); | |
+ scr_width = Cvar_Get( "width", "640", 0, "screen width" ); | |
+ scr_height = Cvar_Get( "height", "480", 0, "screen height" ); | |
scr_conspeed = Cvar_Get( "scr_conspeed", "600", 0, "console moving speed" ); | |
con_notifytime = Cvar_Get( "con_notifytime", "3", 0, "notify time to live" ); | |
con_fontsize = Cvar_Get( "con_fontsize", "1", CVAR_ARCHIVE, "console font number (0, 1 or 2)" ); | |
- con_maxfrac = Cvar_Get( "con_maxfrac", "1.0", CVAR_ARCHIVE, "console max height" ); | |
- con_halffrac = Cvar_Get( "con_halffrac", "0.5", CVAR_ARCHIVE, "console half height" ); | |
- con_charset = Cvar_Get( "con_charset", "cp1251", CVAR_ARCHIVE, "console font charset (only cp1251 supported now)" ); | |
- con_alpha = Cvar_Get( "con_alpha", "1.0", CVAR_ARCHIVE, "console alpha value" ); | |
- con_black = Cvar_Get( "con_black", "0", CVAR_ARCHIVE, "make console black like a nigga" ); | |
Con_CheckResize(); | |
@@ -822,8 +687,6 @@ void Con_Init( void ) | |
con.historyLines[i].widthInChars = con.linewidth; | |
} | |
- Con_ClearAutoComplete(); | |
- | |
Cmd_AddCommand( "toggleconsole", Con_ToggleConsole_f, "opens or closes the console" ); | |
Cmd_AddCommand( "con_color", Con_SetColor_f, "set a custom console color" ); | |
Cmd_AddCommand( "clear", Con_Clear_f, "clear console history" ); | |
@@ -872,7 +735,7 @@ void Con_Print( const char *txt ) | |
int y, c, l, color; | |
// client not running | |
- if( Host_IsDedicated() ) return; | |
+ if( host.type == HOST_DEDICATED ) return; | |
if( !con.initialized ) return; | |
color = ColorIndex( COLOR_DEFAULT ); | |
@@ -892,11 +755,12 @@ void Con_Print( const char *txt ) | |
if( txt[l] <= ' ') | |
break; | |
} | |
- | |
+#if 0 | |
+ // g-cont. experiment from SDLash3D | |
// word wrap | |
- // mittorn: Line already wrapped | |
- //if( l != con.linewidth && ( con.x + l >= con.linewidth )) | |
- // Con_Linefeed(); | |
+ if( l != con.linewidth && ( con.x + l >= con.linewidth )) | |
+ Con_Linefeed(); | |
+#endif | |
txt++; | |
switch( c ) | |
@@ -1040,6 +904,219 @@ EDIT FIELDS | |
============================================================================= | |
*/ | |
+/* | |
+=============== | |
+Cmd_CheckName | |
+ | |
+compare first argument with string | |
+=============== | |
+*/ | |
+static qboolean Cmd_CheckName( const char *name ) | |
+{ | |
+ if( !Q_stricmp( Cmd_Argv( 0 ), name )) | |
+ return true; | |
+ if( !Q_stricmp( Cmd_Argv( 0 ), va( "\\%s", name ))) | |
+ return true; | |
+ return false; | |
+} | |
+ | |
+/* | |
+=============== | |
+Con_AddCommandToList | |
+ | |
+=============== | |
+*/ | |
+static void Con_AddCommandToList( const char *s, const char *unused1, const char *unused2, void *unused3 ) | |
+{ | |
+ if( *s == '@' ) return; // never show system cvars or cmds | |
+ if( con.matchCount >= CON_MAXCMDS ) return; // list is full | |
+ | |
+ if( Q_strnicmp( s, con.completionString, Q_strlen( con.completionString ))) | |
+ return; // no match | |
+ | |
+ con.cmds[con.matchCount++] = copystring( s ); | |
+} | |
+ | |
+/* | |
+================= | |
+Con_SortCmds | |
+================= | |
+*/ | |
+static int Con_SortCmds( const char **arg1, const char **arg2 ) | |
+{ | |
+ return Q_stricmp( *arg1, *arg2 ); | |
+} | |
+ | |
+/* | |
+=============== | |
+pfnPrintMatches | |
+=============== | |
+*/ | |
+static void Con_PrintMatches( const char *s, const char *unused1, const char *m, void *unused2 ) | |
+{ | |
+ if( !Q_strnicmp( s, con.shortestMatch, Q_strlen( con.shortestMatch ))) | |
+ { | |
+ if( m && *m ) Msg( " %s ^3\"%s\"\n", s, m ); | |
+ else Msg( " %s\n", s ); // variable or command without description | |
+ } | |
+} | |
+ | |
+static void ConcatRemaining( const char *src, const char *start ) | |
+{ | |
+ char *arg; | |
+ int i; | |
+ | |
+ arg = Q_strstr( src, start ); | |
+ | |
+ if( !arg ) | |
+ { | |
+ for( i = 1; i < Cmd_Argc(); i++ ) | |
+ { | |
+ Q_strncat( con.completionField->buffer, " ", sizeof( con.completionField->buffer )); | |
+ arg = Cmd_Argv( i ); | |
+ while( *arg ) | |
+ { | |
+ if( *arg == ' ' ) | |
+ { | |
+ Q_strncat( con.completionField->buffer, "\"", sizeof( con.completionField->buffer )); | |
+ break; | |
+ } | |
+ arg++; | |
+ } | |
+ | |
+ Q_strncat( con.completionField->buffer, Cmd_Argv( i ), sizeof( con.completionField->buffer )); | |
+ if( *arg == ' ' ) Q_strncat( con.completionField->buffer, "\"", sizeof( con.completionField->buffer )); | |
+ } | |
+ return; | |
+ } | |
+ | |
+ arg += Q_strlen( start ); | |
+ Q_strncat( con.completionField->buffer, arg, sizeof( con.completionField->buffer )); | |
+} | |
+ | |
+/* | |
+=============== | |
+Con_CompleteCommand | |
+ | |
+perform Tab expansion | |
+=============== | |
+*/ | |
+void Con_CompleteCommand( field_t *field ) | |
+{ | |
+ field_t temp; | |
+ string filename; | |
+ qboolean nextcmd; | |
+ autocomplete_list_t *list; | |
+ int i; | |
+ | |
+ // setup the completion field | |
+ con.completionField = field; | |
+ | |
+ // only look at the first token for completion purposes | |
+ Cmd_TokenizeString( con.completionField->buffer ); | |
+ | |
+ nextcmd = ( con.completionField->buffer[Q_strlen( con.completionField->buffer ) - 1] == ' ' ) ? true : false; | |
+ | |
+ con.completionString = Cmd_Argv( 0 ); | |
+ | |
+ // skip backslash | |
+ while( *con.completionString && ( *con.completionString == '\\' || *con.completionString == '/' )) | |
+ con.completionString++; | |
+ | |
+ if( !Q_strlen( con.completionString )) | |
+ return; | |
+ | |
+ // free the old autocomplete list | |
+ for( i = 0; i < con.matchCount; i++ ) | |
+ { | |
+ if( con.cmds[i] != NULL ) | |
+ { | |
+ Mem_Free( con.cmds[i] ); | |
+ con.cmds[i] = NULL; | |
+ } | |
+ } | |
+ | |
+ con.matchCount = 0; | |
+ con.shortestMatch[0] = 0; | |
+ | |
+ // find matching commands and variables | |
+ Cmd_LookupCmds( NULL, NULL, Con_AddCommandToList ); | |
+ Cvar_LookupVars( 0, NULL, NULL, Con_AddCommandToList ); | |
+ | |
+ if( !con.matchCount ) return; // no matches | |
+ | |
+ Q_memcpy( &temp, con.completionField, sizeof( field_t )); | |
+ | |
+ if(( Cmd_Argc() == 2 ) || (( Cmd_Argc() == 1 ) && nextcmd )) | |
+ { | |
+ qboolean result = false; | |
+ | |
+ // autocomplete second arg | |
+ for( list = cmd_list; list->name; list++ ) | |
+ { | |
+ if( Cmd_CheckName( list->name )) | |
+ { | |
+ result = list->func( Cmd_Argv( 1 ), filename, MAX_STRING ); | |
+ break; | |
+ } | |
+ } | |
+ | |
+ if( result ) | |
+ { | |
+ Q_sprintf( con.completionField->buffer, "%s %s", Cmd_Argv( 0 ), filename ); | |
+ con.completionField->cursor = Q_strlen( con.completionField->buffer ); | |
+ } | |
+ | |
+ // don't adjusting cursor pos if we nothing found | |
+ return; | |
+ } | |
+ else if( Cmd_Argc() >= 3 ) | |
+ { | |
+ // disable autocomplete for all next args | |
+ return; | |
+ } | |
+ | |
+ if( con.matchCount == 1 ) | |
+ { | |
+ Q_sprintf( con.completionField->buffer, "\\%s", con.cmds[0] ); | |
+ if( Cmd_Argc() == 1 ) Q_strncat( con.completionField->buffer, " ", sizeof( con.completionField->buffer )); | |
+ else ConcatRemaining( temp.buffer, con.completionString ); | |
+ con.completionField->cursor = Q_strlen( con.completionField->buffer ); | |
+ } | |
+ else | |
+ { | |
+ char *first, *last; | |
+ int len = 0; | |
+ | |
+ qsort( con.cmds, con.matchCount, sizeof( char* ), Con_SortCmds ); | |
+ | |
+ // find the number of matching characters between the first and | |
+ // the last element in the list and copy it | |
+ first = con.cmds[0]; | |
+ last = con.cmds[con.matchCount-1]; | |
+ | |
+ while( *first && *last && Q_tolower( *first ) == Q_tolower( *last )) | |
+ { | |
+ first++; | |
+ last++; | |
+ | |
+ con.shortestMatch[len] = con.cmds[0][len]; | |
+ len++; | |
+ } | |
+ con.shortestMatch[len] = 0; | |
+ | |
+ // multiple matches, complete to shortest | |
+ Q_sprintf( con.completionField->buffer, "\\%s", con.shortestMatch ); | |
+ con.completionField->cursor = Q_strlen( con.completionField->buffer ); | |
+ ConcatRemaining( temp.buffer, con.completionString ); | |
+ | |
+ Msg( "]%s\n", con.completionField->buffer ); | |
+ | |
+ // run through again, printing matches | |
+ Cmd_LookupCmds( NULL, NULL, Con_PrintMatches ); | |
+ Cvar_LookupVars( 0, NULL, NULL, Con_PrintMatches ); | |
+ } | |
+} | |
/* | |
================ | |
@@ -1048,8 +1125,6 @@ Field_Paste | |
*/ | |
void Field_Paste( field_t *edit ) | |
{ | |
-// I guess we don't have the ability to paste without SDL. | |
-#ifdef XASH_SDL | |
char *cbd; | |
int i, pasteLen; | |
@@ -1060,8 +1135,7 @@ void Field_Paste( field_t *edit ) | |
pasteLen = Q_strlen( cbd ); | |
for( i = 0; i < pasteLen; i++ ) | |
Field_CharEvent( edit, cbd[i] ); | |
- SDL_free( cbd ); | |
-#endif | |
+ Mem_Free( cbd ); | |
} | |
/* | |
@@ -1098,9 +1172,8 @@ void Field_KeyDownEvent( field_t *edit, | |
{ | |
if( edit->cursor > 0 ) | |
{ | |
- int newcursor = Con_UtfMoveLeft( edit->buffer, edit->cursor ); | |
- Q_memmove( edit->buffer + newcursor, edit->buffer + edit->cursor, len - edit->cursor + 1 ); | |
- edit->cursor = newcursor; | |
+ Q_memmove( edit->buffer + edit->cursor - 1, edit->buffer + edit->cursor, len - edit->cursor + 1 ); | |
+ edit->cursor--; | |
if( edit->scroll ) edit->scroll--; | |
} | |
return; | |
@@ -1108,7 +1181,7 @@ void Field_KeyDownEvent( field_t *edit, | |
if( key == K_RIGHTARROW ) | |
{ | |
- if( edit->cursor < len ) edit->cursor = Con_UtfMoveRight( edit->buffer, edit->cursor, edit->widthInChars ); | |
+ if( edit->cursor < len ) edit->cursor++; | |
if( edit->cursor >= edit->scroll + edit->widthInChars && edit->cursor <= len ) | |
edit->scroll++; | |
return; | |
@@ -1116,7 +1189,7 @@ void Field_KeyDownEvent( field_t *edit, | |
if( key == K_LEFTARROW ) | |
{ | |
- if( edit->cursor > 0 ) edit->cursor= Con_UtfMoveLeft( edit->buffer, edit->cursor ); | |
+ if( edit->cursor > 0 ) edit->cursor--; | |
if( edit->cursor < edit->scroll ) edit->scroll--; | |
return; | |
} | |
@@ -1182,7 +1255,7 @@ void Field_CharEvent( field_t *edit, int | |
} | |
// ignore any other non printable chars | |
- //if( ch < 32 ) return; | |
+ if( ch < 32 ) return; | |
if( host.key_overstrike ) | |
{ | |
@@ -1212,7 +1285,7 @@ void Field_DrawInputLine( int x, int y, | |
{ | |
int len, cursorChar; | |
int drawLen, hideChar = -1; | |
- int prestep, curPos = 0; | |
+ int prestep, curPos; | |
char str[MAX_SYSPATH]; | |
byte *colorDefault; | |
@@ -1260,7 +1333,6 @@ void Field_DrawInputLine( int x, int y, | |
// calc cursor position | |
str[edit->cursor - prestep] = 0; | |
Con_DrawStringLen( str, &curPos, NULL ); | |
- Con_UtfProcessChar( 0 ); | |
if( host.key_overstrike && cursorChar ) | |
{ | |
@@ -1271,11 +1343,7 @@ void Field_DrawInputLine( int x, int y, | |
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |
Con_DrawGenericChar( x + curPos, y, cursorChar, colorDefault ); | |
} | |
- else | |
- { | |
- Con_UtfProcessChar( 0 ); | |
- Con_DrawCharacter( x + curPos, y, '_', colorDefault ); | |
- } | |
+ else Con_DrawCharacter( x + curPos, y, '_', colorDefault ); | |
} | |
/* | |
@@ -1304,9 +1372,6 @@ void Key_Console( int key ) | |
// enter finishes the line | |
if ( key == K_ENTER || key == K_KP_ENTER ) | |
{ | |
- // scroll down | |
- Con_Bottom(); | |
- | |
// if not in the game explicitly prepent a slash if needed | |
if( cls.state != ca_active && con.input.buffer[0] != '\\' && con.input.buffer[0] != '/' ) | |
{ | |
@@ -1439,8 +1504,6 @@ void Key_Message( int key ) | |
{ | |
Q_snprintf( buffer, sizeof( buffer ), "%s \"%s\"\n", con.chat_cmd, con.chat.buffer ); | |
Cbuf_AddText( buffer ); | |
- | |
- Log_Printf( "Server say \"%s\"\n", con.chat.buffer ); | |
} | |
Key_SetKeyDest( key_game ); | |
@@ -1482,25 +1545,6 @@ void Con_DrawInput( void ) | |
Field_DrawInputLine( x, y, &con.input ); | |
} | |
-qboolean Con_DrawProgress( void ) | |
-{ | |
- int x = QCHAR_WIDTH; | |
- int y = con.vislines - ( con.curFont->charHeight * 3 ); | |
- if( scr_download->value > 0 ) | |
- { | |
- while( x < scr_download->value * (scr_width->value - QCHAR_WIDTH * 2) / 100 ) | |
- x += Con_DrawCharacter( x, y, '=', g_color_table[7] ); | |
- } | |
- else if( scr_loading->value > 0 ) | |
- { | |
- while( x < scr_loading->value * (scr_width->value - QCHAR_WIDTH * 2) / 100 ) | |
- x += Con_DrawCharacter( x, y, '=', g_color_table[7] ); | |
- } | |
- else return false; | |
- return true; | |
-} | |
- | |
- | |
/* | |
================ | |
Con_DrawDebugLines | |
@@ -1601,17 +1645,6 @@ void Con_DrawNotify( void ) | |
v += con.curFont->charHeight; | |
} | |
} | |
- x = con.curFont->charWidths[' ']; | |
- if( scr_download->value > 0 ) | |
- { | |
- while( x < scr_download->value * scr_width->value / 100 ) | |
- x += Con_DrawCharacter( x, scr_height->value - con.curFont->charHeight * 2, '=', g_color_table[7] ); | |
- } | |
- else if( scr_loading->value > 0 ) | |
- { | |
- while( x < scr_loading->value * scr_width->value / 100 ) | |
- x += Con_DrawCharacter( x, scr_height->value - con.curFont->charHeight * 2, '=', g_color_table[7] ); | |
- } | |
if( cls.key_dest == key_message ) | |
{ | |
@@ -1645,7 +1678,7 @@ Con_DrawConsole | |
Draws the console with the solid background | |
================ | |
*/ | |
-void Con_DrawSolidConsole( float frac, qboolean fill ) | |
+void Con_DrawSolidConsole( float frac ) | |
{ | |
int i, x, y; | |
int rows; | |
@@ -1661,54 +1694,24 @@ void Con_DrawSolidConsole( float frac, q | |
lines = scr_height->integer; | |
// draw the background | |
- y = scr_height->integer; | |
- if( !fill ) | |
- y *= frac; | |
+ y = frac * scr_height->integer; | |
+ | |
if( y >= 1 ) | |
{ | |
- if( fill ) | |
- { | |
GL_SetRenderMode( kRenderNormal ); | |
- if( con_black->value ) | |
- { | |
- pglColor4ub( 0, 0, 0, 255 ); | |
- R_DrawStretchPic( 0, y - scr_width->integer * 3 / 4, scr_width->integer, scr_width->integer * 3 / 4, 0, 0, 1, 1, cls.fillImage ); | |
- } | |
- else | |
- { | |
- pglColor4ub( 255, 255, 255, 255 ); | |
- R_DrawStretchPic( 0, y - scr_width->integer * 3 / 4, scr_width->integer, scr_width->integer * 3 / 4, 0, 0, 1, 1, con.background ); | |
- } | |
- } | |
- else | |
- { | |
- GL_SetRenderMode( kRenderTransTexture ); | |
- if( con_black->value ) | |
- { | |
- pglColor4ub( 0, 0, 0, 255 * con_alpha->value ); | |
- R_DrawStretchPic( 0, y - scr_width->integer * 3 / 4, scr_width->integer, scr_width->integer * 3 / 4, 0, 0, 1, 1, cls.fillImage ); | |
- } | |
- else | |
- { | |
- pglColor4ub( 255, 255, 255, 255 * con_alpha->value ); | |
- R_DrawStretchPic( 0, y - scr_width->integer * 3 / 4, scr_width->integer, scr_width->integer * 3 / 4, 0, 0, 1, 1, con.background ); | |
- } | |
- } | |
- pglColor4ub( 255, 255, 255, 255 ); | |
+ R_DrawStretchPic( 0, y - scr_height->integer, scr_width->integer, scr_height->integer, 0, 0, 1, 1, con.background ); | |
} | |
else y = 0; | |
if( !con.curFont ) return; // nothing to draw | |
- rows = ( lines - QCHAR_WIDTH ) / QCHAR_WIDTH; // rows of text to draw | |
- | |
if( host.developer ) | |
{ | |
// draw current version | |
byte *color = g_color_table[7]; | |
int stringLen, width = 0, charH; | |
- Q_snprintf( curbuild, MAX_STRING, "Xash3D SDL %i/%s (based on %g build%i)", PROTOCOL_VERSION, XASH_VERSION, BASED_VERSION, Q_buildnum( )); | |
+ Q_snprintf( curbuild, MAX_STRING, "Xash3D %i/%g (hw build %i)", PROTOCOL_VERSION, XASH_VERSION, Q_buildnum( )); | |
Con_DrawStringLen( curbuild, &stringLen, &charH ); | |
start = scr_width->integer - stringLen; | |
stringLen = Con_StringLength( curbuild ); | |
@@ -1719,7 +1722,8 @@ void Con_DrawSolidConsole( float frac, q | |
// draw the text | |
con.vislines = lines; | |
- y = lines - ( con.curFont->charHeight * (Con_DrawProgress()?4:3) ); | |
+ rows = ( lines - QCHAR_WIDTH ) / QCHAR_WIDTH; // rows of text to draw | |
+ y = lines - ( con.curFont->charHeight * 3 ); | |
// draw from the bottom up | |
if( con.display != con.current ) | |
@@ -1773,9 +1776,8 @@ Con_DrawConsole | |
void Con_DrawConsole( void ) | |
{ | |
// never draw console when changelevel in-progress | |
- // mittorn: breaks console when downloading map, it may hang! | |
- //if( cls.state != ca_disconnected && ( cls.changelevel || cls.changedemo )) | |
- // return; | |
+ if( cls.state != ca_disconnected && ( cls.changelevel || cls.changedemo )) | |
+ return; | |
// check for console width changes from a vid mode change | |
Con_CheckResize (); | |
@@ -1786,13 +1788,13 @@ void Con_DrawConsole( void ) | |
{ | |
if(( Cvar_VariableInteger( "cl_background" ) || Cvar_VariableInteger( "sv_background" )) && cls.key_dest != key_console ) | |
con.displayFrac = con.finalFrac = 0.0f; | |
- else con.displayFrac = con.finalFrac = con_maxfrac->value; | |
+ else con.displayFrac = con.finalFrac = 1.0f; | |
} | |
else | |
{ | |
if( host.developer >= 4 ) | |
{ | |
- con.displayFrac = con_halffrac->value; // keep console open | |
+ con.displayFrac = 0.5f; // keep console open | |
} | |
else | |
{ | |
@@ -1813,26 +1815,26 @@ void Con_DrawConsole( void ) | |
case ca_disconnected: | |
if( cls.key_dest != key_menu && host.developer ) | |
{ | |
- Con_DrawSolidConsole( con_maxfrac->value, true ); | |
+ Con_DrawSolidConsole( 1.0f ); | |
Key_SetKeyDest( key_console ); | |
} | |
break; | |
case ca_connected: | |
case ca_connecting: | |
// force to show console always for -dev 3 and higher | |
- if( con.displayFrac ) Con_DrawSolidConsole( con.displayFrac, true ); | |
+ if( con.displayFrac ) Con_DrawSolidConsole( con.displayFrac ); | |
break; | |
case ca_active: | |
case ca_cinematic: | |
if( Cvar_VariableInteger( "cl_background" ) || Cvar_VariableInteger( "sv_background" )) | |
{ | |
if( cls.key_dest == key_console ) | |
- Con_DrawSolidConsole( con_maxfrac->value, true ); | |
+ Con_DrawSolidConsole( 1.0f ); | |
} | |
else | |
{ | |
if( con.displayFrac ) | |
- Con_DrawSolidConsole( con.displayFrac, false ); | |
+ Con_DrawSolidConsole( con.displayFrac ); | |
else if( cls.state == ca_active && ( cls.key_dest == key_game || cls.key_dest == key_message )) | |
Con_DrawNotify(); // draw notify lines | |
} | |
@@ -1862,8 +1864,6 @@ void Con_DrawVersion( void ) | |
case scrshot_snapshot: | |
draw_version = true; | |
break; | |
- default: | |
- break; | |
} | |
if( !host.force_draw_version ) | |
@@ -1873,8 +1873,8 @@ void Con_DrawVersion( void ) | |
} | |
if( host.force_draw_version || draw_version ) | |
- Q_snprintf( curbuild, MAX_STRING, "Xash3D SDL %i/%s (based on %g build%i)", PROTOCOL_VERSION, XASH_VERSION, BASED_VERSION, Q_buildnum( )); | |
- else Q_snprintf( curbuild, MAX_STRING, "v%i/%s (based on %g build%i)", PROTOCOL_VERSION, XASH_VERSION, BASED_VERSION, Q_buildnum( )); | |
+ Q_snprintf( curbuild, MAX_STRING, "Xash3D v%i/%g (build %i)", PROTOCOL_VERSION, XASH_VERSION, Q_buildnum( )); | |
+ else Q_snprintf( curbuild, MAX_STRING, "v%i/%g (build %i)", PROTOCOL_VERSION, XASH_VERSION, Q_buildnum( )); | |
Con_DrawStringLen( curbuild, &stringLen, &charH ); | |
start = scr_width->integer - stringLen * 1.05f; | |
stringLen = Con_StringLength( curbuild ); | |
@@ -1898,8 +1898,7 @@ void Con_RunConsole( void ) | |
{ | |
if( cls.state == ca_disconnected ) | |
con.finalFrac = 1.0f;// full screen | |
- else | |
- con.finalFrac = 0.5f; // half screen | |
+ else con.finalFrac = 0.5f; // half screen | |
} | |
else con.finalFrac = 0; // none visible | |
@@ -1919,12 +1918,6 @@ void Con_RunConsole( void ) | |
if( con.finalFrac < con.displayFrac ) | |
con.displayFrac = con.finalFrac; | |
} | |
- | |
- // update codepage parameters | |
- g_codepage = 0; | |
- if( !Q_stricmp( con_charset->string, "cp1251" ) ) | |
- g_codepage = 1251; | |
- g_utf8 = !Q_stricmp( cl_charset->string, "utf-8" ); | |
} | |
/* | |
@@ -1957,7 +1950,6 @@ void Con_CharEvent( int key ) | |
void Con_VidInit( void ) | |
{ | |
Con_CheckResize(); | |
- Con_InvalidateFonts(); | |
// loading console image | |
if( host.developer ) | |
@@ -2004,11 +1996,36 @@ void Con_InvalidateFonts( void ) | |
con.curFont = con.lastUsedFont = NULL; | |
} | |
+/* | |
+========= | |
+Cmd_AutoComplete | |
+ | |
+NOTE: input string must be equal or longer than MAX_STRING | |
+========= | |
+*/ | |
+void Cmd_AutoComplete( char *complete_string ) | |
+{ | |
+ field_t input; | |
+ | |
+ if( !complete_string || !*complete_string ) | |
+ return; | |
+ | |
+ // setup input | |
+ Q_strncpy( input.buffer, complete_string, sizeof( input.buffer )); | |
+ input.cursor = input.scroll = 0; | |
+ | |
+ Con_CompleteCommand( &input ); | |
+ | |
+ // setup output | |
+ if( input.buffer[0] == '\\' || input.buffer[0] == '/' ) | |
+ Q_strncpy( complete_string, input.buffer + 1, sizeof( input.buffer )); | |
+ else Q_strncpy( complete_string, input.buffer, sizeof( input.buffer )); | |
+} | |
+ | |
void Con_Close( void ) | |
{ | |
Con_ClearField( &con.input ); | |
Con_ClearNotify(); | |
- Con_ClearTyping(); | |
con.finalFrac = 0.0f; // none visible | |
con.displayFrac = 0.0f; | |
} | |
@@ -2027,4 +2044,3 @@ void Con_DefaultColor( int r, int g, int | |
b = bound( 0, b, 255 ); | |
MakeRGBA( g_color_table[7], r, g, b, 255 ); | |
} | |
-#endif | |
diff --suppress-blank-empty -prudwEZbB engine/common/con_utils.c /mnt/data/Xash3D_original/engine/common/con_utils.c | |
--- engine/common/con_utils.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/con_utils.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -17,22 +17,10 @@ GNU General Public License for more deta | |
#include "client.h" | |
#include "const.h" | |
#include "bspfile.h" | |
-#include "kbutton.h" | |
-#include "touch.h" | |
+#include "../cl_dll/kbutton.h" | |
extern convar_t *con_gamemaps; | |
-#define CON_MAXCMDS 4096 // auto-complete intermediate list | |
-typedef struct | |
-{ | |
-// console auto-complete | |
-string shortestMatch; | |
-field_t *completionField; // con.input or dedicated server fake field-line | |
-char *completionString; | |
-char *cmds[CON_MAXCMDS]; | |
-int matchCount; | |
-} | |
-autocomlete_t; | |
-static autocomlete_t con; | |
+ | |
#ifdef _DEBUG | |
void DBG_AssertFunction( qboolean fExpr, const char* szExpr, const char* szFile, int szLine, const char* szMessage ) | |
{ | |
@@ -44,263 +32,6 @@ void DBG_AssertFunction( qboolean fExpr, | |
} | |
#endif // DEBUG | |
- | |
-/* | |
-=============== | |
-Cmd_CheckName | |
- | |
-compare first argument with string | |
-=============== | |
-*/ | |
-static qboolean Cmd_CheckName( const char *name ) | |
-{ | |
- if( !Q_stricmp( Cmd_Argv( 0 ), name )) | |
- return true; | |
- if( !Q_stricmp( Cmd_Argv( 0 ), va( "\\%s", name ))) | |
- return true; | |
- return false; | |
-} | |
- | |
-/* | |
-=============== | |
-Con_AddCommandToList | |
- | |
-=============== | |
-*/ | |
-static void Con_AddCommandToList( const char *s, const char *unused1, const char *unused2, void *unused3 ) | |
-{ | |
- if( *s == '@' ) return; // never show system cvars or cmds | |
- if( con.matchCount >= CON_MAXCMDS ) return; // list is full | |
- | |
- if( Q_strnicmp( s, con.completionString, Q_strlen( con.completionString ))) | |
- return; // no match | |
- | |
- con.cmds[con.matchCount++] = copystring( s ); | |
-} | |
- | |
-/* | |
-================= | |
-Con_SortCmds | |
-================= | |
-*/ | |
-static int Con_SortCmds( const char **arg1, const char **arg2 ) | |
-{ | |
- return Q_stricmp( *arg1, *arg2 ); | |
-} | |
- | |
-/* | |
-=============== | |
-pfnPrintMatches | |
-=============== | |
-*/ | |
-static void Con_PrintMatches( const char *s, const char *unused1, const char *m, void *unused2 ) | |
-{ | |
- if( !Q_strnicmp( s, con.shortestMatch, Q_strlen( con.shortestMatch ))) | |
- { | |
- if( m && *m ) Msg( " %s ^3\"%s\"\n", s, m ); | |
- else Msg( " %s\n", s ); // variable or command without description | |
- } | |
-} | |
- | |
-static void ConcatRemaining( const char *src, const char *start ) | |
-{ | |
- char *arg; | |
- int i; | |
- | |
- arg = Q_strstr( src, start ); | |
- | |
- if( !arg ) | |
- { | |
- for( i = 1; i < Cmd_Argc(); i++ ) | |
- { | |
- Q_strncat( con.completionField->buffer, " ", sizeof( con.completionField->buffer )); | |
- arg = Cmd_Argv( i ); | |
- while( *arg ) | |
- { | |
- if( *arg == ' ' ) | |
- { | |
- Q_strncat( con.completionField->buffer, "\"", sizeof( con.completionField->buffer )); | |
- break; | |
- } | |
- arg++; | |
- } | |
- | |
- Q_strncat( con.completionField->buffer, Cmd_Argv( i ), sizeof( con.completionField->buffer )); | |
- if( *arg == ' ' ) Q_strncat( con.completionField->buffer, "\"", sizeof( con.completionField->buffer )); | |
- } | |
- return; | |
- } | |
- | |
- arg += Q_strlen( start ); | |
- Q_strncat( con.completionField->buffer, arg, sizeof( con.completionField->buffer )); | |
-} | |
- | |
-/* | |
-=============== | |
-Con_CompleteCommand | |
- | |
-perform Tab expansion | |
-=============== | |
-*/ | |
-void Con_CompleteCommand( field_t *field ) | |
-{ | |
- field_t temp; | |
- string filename; | |
- autocomplete_list_t *list; | |
- int i; | |
- qboolean nextcmd; | |
- | |
- // setup the completion field | |
- con.completionField = field; | |
- | |
- // only look at the first token for completion purposes | |
- Cmd_TokenizeString( con.completionField->buffer ); | |
- | |
- nextcmd = con.completionField->buffer[ Q_strlen( con.completionField->buffer ) - 1 ] == ' '; | |
- | |
- con.completionString = Cmd_Argv( 0 ); | |
- | |
- // skip backslash | |
- while( *con.completionString && ( *con.completionString == '\\' || *con.completionString == '/' )) | |
- con.completionString++; | |
- | |
- if( !Q_strlen( con.completionString )) | |
- return; | |
- | |
- // free the old autocomplete list | |
- for( i = 0; i < con.matchCount; i++ ) | |
- { | |
- if( con.cmds[i] != NULL ) | |
- { | |
- Mem_Free( con.cmds[i] ); | |
- con.cmds[i] = NULL; | |
- } | |
- } | |
- | |
- con.matchCount = 0; | |
- con.shortestMatch[0] = 0; | |
- | |
- // find matching commands and variables | |
- Cmd_LookupCmds( NULL, NULL, (void*)Con_AddCommandToList ); | |
- Cvar_LookupVars( 0, NULL, NULL, (void*)Con_AddCommandToList ); | |
- | |
- if( !con.matchCount ) return; // no matches | |
- | |
- Q_memcpy( &temp, con.completionField, sizeof( field_t )); | |
- | |
- if( ( Cmd_Argc() == 2 ) || ( ( Cmd_Argc() == 1 ) && nextcmd )) | |
- { | |
- qboolean result = false; | |
- | |
- // autocomplete second arg | |
- for( list = cmd_list; list->name; list++ ) | |
- { | |
- if( Cmd_CheckName( list->name )) | |
- { | |
- result = list->func( Cmd_Argv( 1 ), filename, MAX_STRING ); | |
- break; | |
- } | |
- } | |
- | |
- if( result ) | |
- { | |
- Q_sprintf( con.completionField->buffer, "%s %s", Cmd_Argv( 0 ), filename ); | |
- con.completionField->cursor = Q_strlen( con.completionField->buffer ); | |
- } | |
- | |
- // don't adjusting cursor pos if we nothing found | |
- return; | |
- } | |
- else if( Cmd_Argc() >= 3 ) | |
- { | |
- // disable autocomplete for all next args | |
- return; | |
- } | |
- | |
- if( con.matchCount == 1 ) | |
- { | |
- Q_sprintf( con.completionField->buffer, "\\%s", con.cmds[0] ); | |
- if( Cmd_Argc() == 1 ) Q_strncat( con.completionField->buffer, " ", sizeof( con.completionField->buffer )); | |
- else ConcatRemaining( temp.buffer, con.completionString ); | |
- con.completionField->cursor = Q_strlen( con.completionField->buffer ); | |
- } | |
- else | |
- { | |
- char *first, *last; | |
- int len = 0; | |
- | |
- qsort( con.cmds, con.matchCount, sizeof( char* ), (void*)Con_SortCmds ); | |
- | |
- // find the number of matching characters between the first and | |
- // the last element in the list and copy it | |
- first = con.cmds[0]; | |
- last = con.cmds[con.matchCount-1]; | |
- | |
- while( *first && *last && Q_tolower( *first ) == Q_tolower( *last )) | |
- { | |
- first++; | |
- last++; | |
- | |
- con.shortestMatch[len] = con.cmds[0][len]; | |
- len++; | |
- } | |
- con.shortestMatch[len] = 0; | |
- | |
- // multiple matches, complete to shortest | |
- Q_sprintf( con.completionField->buffer, "\\%s", con.shortestMatch ); | |
- con.completionField->cursor = Q_strlen( con.completionField->buffer ); | |
- ConcatRemaining( temp.buffer, con.completionString ); | |
- | |
- Msg( "]%s\n", con.completionField->buffer ); | |
- | |
- // run through again, printing matches | |
- Cmd_LookupCmds( NULL, NULL, (void*)Con_PrintMatches ); | |
- Cvar_LookupVars( 0, NULL, NULL, (void*)Con_PrintMatches ); | |
- } | |
-} | |
-/* | |
-========= | |
-Cmd_AutoComplete | |
- | |
-NOTE: input string must be equal or longer than MAX_STRING | |
-========= | |
-*/ | |
-void Cmd_AutoComplete( char *complete_string ) | |
-{ | |
- field_t input; | |
- | |
- if( !complete_string || !*complete_string ) | |
- return; | |
- | |
- // setup input | |
- Q_strncpy( input.buffer, complete_string, sizeof( input.buffer )); | |
- input.cursor = input.scroll = 0; | |
- | |
- Con_CompleteCommand( &input ); | |
- | |
- // setup output | |
- if( input.buffer[0] == '\\' || input.buffer[0] == '/' ) | |
- Q_strncpy( complete_string, input.buffer + 1, sizeof( input.buffer )); | |
- else Q_strncpy( complete_string, input.buffer, sizeof( input.buffer )); | |
-} | |
- | |
-void Con_ClearAutoComplete() | |
-{ | |
- int i; | |
- | |
- // free the old autocomplete list | |
- for( i = 0; i < con.matchCount; i++ ) | |
- { | |
- if( con.cmds[i] != NULL ) | |
- { | |
- Mem_Free( con.cmds[i] ); | |
- con.cmds[i] = NULL; | |
- } | |
- } | |
- | |
- con.matchCount = 0; | |
-} | |
- | |
/* | |
======================================================================= | |
@@ -383,7 +114,7 @@ qboolean Cmd_GetMapList( const char *s, | |
Q_strncpy( entfilename, t->filenames[i], sizeof( entfilename )); | |
FS_StripExtension( entfilename ); | |
FS_DefaultExtension( entfilename, ".ent" ); | |
- ents = (char *)FS_LoadFile( entfilename, NULL, true ); | |
+ ents = FS_LoadFile( entfilename, NULL, true ); | |
if( !ents && lumplen >= 10 ) | |
{ | |
@@ -427,21 +158,19 @@ qboolean Cmd_GetMapList( const char *s, | |
switch( ver ) | |
{ | |
case Q1BSP_VERSION: | |
- if( mapver == 220 ) Q_strncpy( (char *)buf, "Half-Life Alpha", sizeof( buf )); | |
- else Q_strncpy( (char *)buf, "Quake", sizeof( buf )); | |
+ if( mapver == 220 ) Q_strncpy( buf, "Half-Life Alpha", sizeof( buf )); | |
+ else Q_strncpy( buf, "Quake", sizeof( buf )); | |
break; | |
case HLBSP_VERSION: | |
- if( gearbox ) Q_strncpy( (char *)buf, "Blue-Shift", sizeof( buf )); | |
- else if( paranoia ) Q_strncpy( (char *)buf, "Paranoia 2", sizeof( buf )); | |
- else Q_strncpy( (char *)buf, "Half-Life", sizeof( buf )); | |
+ if( gearbox ) Q_strncpy( buf, "Blue-Shift", sizeof( buf )); | |
+ else if( paranoia ) Q_strncpy( buf, "Paranoia 2", sizeof( buf )); | |
+ else Q_strncpy( buf, "Half-Life", sizeof( buf )); | |
break; | |
case XTBSP_VERSION: | |
- if( paranoia ) Q_strncpy( (char *)buf, "Paranoia 2", sizeof( buf )); | |
- else Q_strncpy( (char *)buf, "Xash3D", sizeof( buf )); | |
- break; | |
- default: | |
- Q_strncpy( (char *)buf, "??", sizeof( buf )); | |
+ if( paranoia ) Q_strncpy( buf, "Paranoia 2", sizeof( buf )); | |
+ else Q_strncpy( buf, "Xash3D", sizeof( buf )); | |
break; | |
+ default: Q_strncpy( buf, "??", sizeof( buf )); break; | |
} | |
Msg( "%16s (%s) ^3%s^7\n", matchbuf, buf, message ); | |
@@ -575,8 +304,8 @@ qboolean Cmd_GetMusicList( const char *s | |
{ | |
const char *ext = FS_FileExtension( t->filenames[i] ); | |
- if( Q_stricmp( ext, "wav" ) || Q_stricmp( ext, "mp3" )) | |
- continue; | |
+ if( !Q_stricmp( ext, "wav" ) || !Q_stricmp( ext, "mp3" )); | |
+ else continue; | |
FS_FileBase( t->filenames[i], matchbuf ); | |
Msg( "%16s\n", matchbuf ); | |
@@ -660,7 +389,7 @@ qboolean Cmd_GetConfigList( const char * | |
t = FS_Search( va( "%s*.cfg", s ), true, false ); | |
if( !t ) return false; | |
- Q_strncpy( matchbuf, t->filenames[0], 256 ); | |
+ FS_FileBase( t->filenames[0], matchbuf ); | |
if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); | |
if( t->numfilenames == 1 ) return true; | |
@@ -669,7 +398,7 @@ qboolean Cmd_GetConfigList( const char * | |
const char *ext = FS_FileExtension( t->filenames[i] ); | |
if( Q_stricmp( ext, "cfg" )) continue; | |
- Q_strncpy( matchbuf, t->filenames[i], 256 ); | |
+ FS_FileBase( t->filenames[i], matchbuf ); | |
Msg( "%16s\n", matchbuf ); | |
numconfigs++; | |
} | |
@@ -754,7 +483,6 @@ qboolean Cmd_GetItemsList( const char *s | |
string matchbuf; | |
int i, numitems; | |
-#ifndef XASH_DEDICATED | |
if( !clgame.itemspath[0] ) return false; // not in game yet | |
t = FS_Search( va( "%s/%s*.txt", clgame.itemspath, s ), true, false ); | |
if( !t ) return false; | |
@@ -785,11 +513,7 @@ qboolean Cmd_GetItemsList( const char *s | |
completedname[i] = 0; | |
} | |
} | |
- | |
return true; | |
-#else | |
- return false; | |
-#endif | |
} | |
/* | |
@@ -839,12 +563,12 @@ qboolean Cmd_GetCustomList( const char * | |
/* | |
===================================== | |
-Cmd_GetTextureModes | |
+Cmd_GetTexturemodes | |
Prints or complete sound filename | |
===================================== | |
*/ | |
-qboolean Cmd_GetTextureModes( const char *s, char *completedname, int length ) | |
+qboolean Cmd_GetTexturemodes( const char *s, char *completedname, int length ) | |
{ | |
int i, numtexturemodes; | |
string texturemodes[6]; // keep an actual ( sizeof( gl_texturemode) / sizeof( gl_texturemode[0] )) | |
@@ -860,7 +584,7 @@ qboolean Cmd_GetTextureModes( const char | |
"GL_NEAREST_MIPMAP_NEAREST", | |
}; | |
- // compare texture filtering mode list with current keyword | |
+ // compare gamelist with current keyword | |
for( i = 0, numtexturemodes = 0; i < 6; i++ ) | |
{ | |
if(( *s == '*' ) || !Q_strnicmp( gl_texturemode[i], s, Q_strlen( s ))) | |
@@ -868,7 +592,7 @@ qboolean Cmd_GetTextureModes( const char | |
} | |
if( !numtexturemodes ) return false; | |
- Q_strncpy( matchbuf, texturemodes[0], MAX_STRING ); | |
+ Q_strncpy( matchbuf, gl_texturemode[0], MAX_STRING ); | |
if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); | |
if( numtexturemodes == 1 ) return true; | |
@@ -905,7 +629,7 @@ qboolean Cmd_GetGamesList( const char *s | |
string gamedirs[MAX_MODS]; | |
string matchbuf; | |
- // stand-alone games don't have cmd "game" | |
+ // stand-alone games doesn't have cmd "game" | |
if( !Cmd_Exists( "game" )) | |
return false; | |
@@ -952,8 +676,8 @@ qboolean Cmd_CheckMapsList_R( qboolean f | |
if( FS_FileSize( "maps.lst", onlyingamedir ) > 0 && !fRefresh ) | |
{ | |
- MsgDev( D_NOTE, "maps.lst found: %s\n", onlyingamedir ? "basedir" : "gamedir" ); | |
- return true; // exists | |
+ MsgDev( D_NOTE, "maps.lst is exist: %s\n", onlyingamedir ? "basedir" : "gamedir" ); | |
+ return true; // exist | |
} | |
t = FS_Search( "maps/*.bsp", false, onlyingamedir ); | |
@@ -1013,7 +737,7 @@ qboolean Cmd_CheckMapsList_R( qboolean f | |
Q_strncpy( entfilename, t->filenames[i], sizeof( entfilename )); | |
FS_StripExtension( entfilename ); | |
FS_DefaultExtension( entfilename, ".ent" ); | |
- ents = (char *)FS_LoadFile( entfilename, NULL, true ); | |
+ ents = FS_LoadFile( entfilename, NULL, true ); | |
if( !ents && lumplen >= 10 ) | |
{ | |
@@ -1084,63 +808,6 @@ qboolean Cmd_CheckMapsList_R( qboolean f | |
return false; | |
} | |
-/* | |
-===================================== | |
-Cmd_GetCdCommands | |
- | |
-Prints or complete CD command name | |
-===================================== | |
-*/ | |
-qboolean Cmd_GetCdCommands( const char *s, char *completedname, int length ) | |
-{ | |
- int i, numcdcommands; | |
- string cdcommands[8]; | |
- string matchbuf; | |
- | |
- const char *cd_command[] = | |
- { | |
- "info", | |
- "loop", | |
- "off", | |
- "on", | |
- "pause", | |
- "play", | |
- "resume", | |
- "stop", | |
- }; | |
- | |
- // compare CD command list with current keyword | |
- for( i = 0, numcdcommands = 0; i < 8; i++ ) | |
- { | |
- if(( *s == '*' ) || !Q_strnicmp( cd_command[i], s, Q_strlen( s ))) | |
- Q_strcpy( cdcommands[numcdcommands++], cd_command[i] ); | |
- } | |
- | |
- if( !numcdcommands ) return false; | |
- Q_strncpy( matchbuf, cdcommands[0], MAX_STRING ); | |
- if( completedname && length ) Q_strncpy( completedname, matchbuf, length ); | |
- if( numcdcommands == 1 ) return true; | |
- | |
- for( i = 0; i < numcdcommands; i++ ) | |
- { | |
- Q_strncpy( matchbuf, cdcommands[i], MAX_STRING ); | |
- Msg( "%16s\n", matchbuf ); | |
- } | |
- | |
- Msg( "\n^3 %i commands found.\n", numcdcommands ); | |
- | |
- // cut shortestMatch to the amount common with s | |
- if( completedname && length ) | |
- { | |
- for( i = 0; matchbuf[i]; i++ ) | |
- { | |
- if( Q_tolower( completedname[i] ) != Q_tolower( matchbuf[i] )) | |
- completedname[i] = 0; | |
- } | |
- } | |
- return true; | |
-} | |
- | |
qboolean Cmd_CheckMapsList( qboolean fRefresh ) | |
{ | |
return Cmd_CheckMapsList_R( fRefresh, true ); | |
@@ -1148,9 +815,8 @@ qboolean Cmd_CheckMapsList( qboolean fRe | |
autocomplete_list_t cmd_list[] = | |
{ | |
-{ "gl_texturemode", Cmd_GetTextureModes }, | |
+{ "gl_texturemode", Cmd_GetTexturemodes }, | |
{ "map_background", Cmd_GetMapList }, | |
-{ "changelevel2", Cmd_GetMapList }, | |
{ "changelevel", Cmd_GetMapList }, | |
{ "playdemo", Cmd_GetDemoList, }, | |
{ "playvol", Cmd_GetSoundList }, | |
@@ -1166,8 +832,7 @@ autocomplete_list_t cmd_list[] = | |
{ "load", Cmd_GetSavesList }, | |
{ "play", Cmd_GetSoundList }, | |
{ "map", Cmd_GetMapList }, | |
-{ "cd", Cmd_GetCdCommands }, | |
-{ NULL }, // terminator | |
+{ NULL }, // termiantor | |
}; | |
/* | |
@@ -1180,31 +845,31 @@ with the archive flag set to true. | |
*/ | |
static void Cmd_WriteCvar(const char *name, const char *string, const char *desc, void *f ) | |
{ | |
- if( !desc || !*desc ) return; // ignore cvars without description (phantom variables) | |
+ if( !desc || !*desc ) return; // ignore cvars without description (fantom variables) | |
FS_Printf( f, "%s \"%s\"\n", name, string ); | |
} | |
static void Cmd_WriteServerCvar(const char *name, const char *string, const char *desc, void *f ) | |
{ | |
- if( !desc || !*desc ) return; // ignore cvars without description (phantom variables) | |
+ if( !desc || !*desc ) return; // ignore cvars without description (fantom variables) | |
FS_Printf( f, "set %s \"%s\"\n", name, string ); | |
} | |
static void Cmd_WriteOpenGLCvar( const char *name, const char *string, const char *desc, void *f ) | |
{ | |
- if( !desc || !*desc ) return; // ignore cvars without description (phantom variables) | |
+ if( !desc || !*desc ) return; // ignore cvars without description (fantom variables) | |
FS_Printf( f, "setgl %s \"%s\"\n", name, string ); | |
} | |
static void Cmd_WriteRenderCvar( const char *name, const char *string, const char *desc, void *f ) | |
{ | |
- if( !desc || !*desc ) return; // ignore cvars without description (phantom variables) | |
+ if( !desc || !*desc ) return; // ignore cvars without description (fantom variables) | |
FS_Printf( f, "setr %s \"%s\"\n", name, string ); | |
} | |
static void Cmd_WriteHelp(const char *name, const char *unused, const char *desc, void *f ) | |
{ | |
- if( !desc ) return; // ignore phantom cmds | |
+ if( !desc ) return; // ignore fantom cmds | |
if( !Q_strcmp( desc, "" )) return; // blank description | |
if( name[0] == '+' || name[0] == '-' ) return; // key bindings | |
FS_Printf( f, "%s\t\t\t\"%s\"\n", name, desc ); | |
@@ -1212,22 +877,22 @@ static void Cmd_WriteHelp(const char *na | |
void Cmd_WriteVariables( file_t *f ) | |
{ | |
- Cvar_LookupVars( CVAR_ARCHIVE, NULL, f, (void*)Cmd_WriteCvar ); | |
+ Cvar_LookupVars( CVAR_ARCHIVE, NULL, f, Cmd_WriteCvar ); | |
} | |
void Cmd_WriteServerVariables( file_t *f ) | |
{ | |
- Cvar_LookupVars( CVAR_SERVERNOTIFY, NULL, f, (void*)Cmd_WriteServerCvar ); | |
+ Cvar_LookupVars( CVAR_SERVERNOTIFY, NULL, f, Cmd_WriteServerCvar ); | |
} | |
void Cmd_WriteOpenGLVariables( file_t *f ) | |
{ | |
- Cvar_LookupVars( CVAR_GLCONFIG, NULL, f, (void*)Cmd_WriteOpenGLCvar ); | |
+ Cvar_LookupVars( CVAR_GLCONFIG, NULL, f, Cmd_WriteOpenGLCvar ); | |
} | |
void Cmd_WriteRenderVariables( file_t *f ) | |
{ | |
- Cvar_LookupVars( CVAR_RENDERINFO, NULL, f, (void*)Cmd_WriteRenderCvar ); | |
+ Cvar_LookupVars( CVAR_RENDERINFO, NULL, f, Cmd_WriteRenderCvar ); | |
} | |
/* | |
@@ -1241,42 +906,19 @@ void Host_WriteConfig( void ) | |
{ | |
kbutton_t *mlook, *jlook; | |
file_t *f; | |
-#ifndef XASH_DEDICATED | |
- // if client not loaded, client cvars will lost | |
- if( !clgame.hInstance ) | |
- { | |
- MsgDev( D_NOTE, "Client not loaded, skipping config save!\n" ); | |
- return; | |
- } | |
+ | |
+ if( !clgame.hInstance ) return; | |
MsgDev( D_NOTE, "Host_WriteConfig()\n" ); | |
- f = FS_Open( "config.cfg", "w", true ); | |
+ f = FS_Open( "config.cfg", "w", false ); | |
if( f ) | |
{ | |
FS_Printf( f, "//=======================================================================\n"); | |
- FS_Printf( f, "//\t\t\tCopyright XashXT Group %s ©\n", Q_timestamp( TIME_YEAR_ONLY )); | |
+ FS_Printf( f, "//\t\t\tCopyright XashXT Group %s �\n", Q_timestamp( TIME_YEAR_ONLY )); | |
FS_Printf( f, "//\t\t\tconfig.cfg - archive of cvars\n" ); | |
FS_Printf( f, "//=======================================================================\n" ); | |
- Cmd_WriteVariables( f ); | |
- | |
- FS_Printf( f, "exec keyboard.cfg\n" ); | |
- | |
- FS_Printf( f, "exec userconfig.cfg\n" ); | |
- | |
- FS_Close( f ); | |
- } | |
- else MsgDev( D_ERROR, "Couldn't write config.cfg.\n" ); | |
- | |
- if( cls.initialized && ( cls.keybind_changed || !FS_FileExists( "keyboard.cfg", true ) ) ) | |
- { | |
- f = FS_Open( "keyboard.cfg", "w", true ); | |
- if( f ) | |
- { | |
- FS_Printf( f, "//=======================================================================\n"); | |
- FS_Printf( f, "//\t\t\tCopyright XashXT Group %s ©\n", Q_timestamp( TIME_YEAR_ONLY )); | |
- FS_Printf( f, "//\t\t\tkeyboard.cfg - archive of keybindings\n" ); | |
- FS_Printf( f, "//=======================================================================\n" ); | |
Key_WriteBindings( f ); | |
+ Cmd_WriteVariables( f ); | |
mlook = (kbutton_t *)clgame.dllFuncs.KB_Find( "in_mlook" ); | |
jlook = (kbutton_t *)clgame.dllFuncs.KB_Find( "in_jlook" ); | |
@@ -1287,14 +929,11 @@ void Host_WriteConfig( void ) | |
if( jlook && ( jlook->state & 1 )) | |
FS_Printf( f, "+jlook\n" ); | |
+ FS_Printf( f, "exec userconfig.cfg" ); | |
+ | |
FS_Close( f ); | |
} | |
- else MsgDev( D_ERROR, "Couldn't write keyboard.cfg.\n" ); | |
- } | |
- else | |
- MsgDev( D_NOTE, "Keyboard configuration not changed\n" ); | |
- IN_TouchWriteConfig(); | |
-#endif | |
+ else MsgDev( D_ERROR, "Couldn't write config.cfg.\n" ); | |
} | |
/* | |
@@ -1306,26 +945,24 @@ save serverinfo variables into server.cf | |
*/ | |
void Host_WriteServerConfig( const char *name ) | |
{ | |
- /* Old Xash3D behaviour is writing listenserver config | |
- every time when starting server from ui. | |
- WON Half-Life uses game.cfg for this purpose*/ | |
file_t *f; | |
SV_InitGameProgs(); // collect user variables | |
- if(( f = FS_Open( "game.cfg", "w", false )) != NULL ) | |
+ if(( f = FS_Open( name, "w", false )) != NULL ) | |
{ | |
FS_Printf( f, "//=======================================================================\n" ); | |
- FS_Printf( f, "//\t\t\tCopyright XashXT Group %s ©\n", Q_timestamp( TIME_YEAR_ONLY )); | |
- FS_Printf( f, "//\t\t\tgame.cfg - multiplayer config\n" ); | |
+ FS_Printf( f, "//\t\t\tCopyright XashXT Group %s �\n", Q_timestamp( TIME_YEAR_ONLY )); | |
+ FS_Printf( f, "//\t\t\tserver.cfg - server temporare config\n" ); | |
FS_Printf( f, "//=======================================================================\n" ); | |
Cmd_WriteServerVariables( f ); | |
FS_Close( f ); | |
} | |
- else MsgDev( D_ERROR, "Couldn't write game.cfg.\n" ); | |
+ else MsgDev( D_ERROR, "Couldn't write %s.\n", name ); | |
- //SV_FreeGameProgs(); // release progs with all variables | |
+ SV_FreeGameProgs(); // release progs with all variables | |
} | |
+ | |
/* | |
=============== | |
Host_WriteOpenGLConfig | |
@@ -1342,13 +979,13 @@ void Host_WriteOpenGLConfig( void ) | |
if( f ) | |
{ | |
FS_Printf( f, "//=======================================================================\n" ); | |
- FS_Printf( f, "//\t\t\tCopyright XashXT Group %s ©\n", Q_timestamp( TIME_YEAR_ONLY )); | |
+ FS_Printf( f, "//\t\t\tCopyright XashXT Group %s �\n", Q_timestamp( TIME_YEAR_ONLY )); | |
FS_Printf( f, "//\t\t opengl.cfg - archive of opengl extension cvars\n"); | |
FS_Printf( f, "//=======================================================================\n" ); | |
Cmd_WriteOpenGLVariables( f ); | |
FS_Close( f ); | |
} | |
- else MsgDev( D_ERROR, "Can't update opengl.cfg.\n" ); | |
+ else MsgDev( D_ERROR, "can't update opengl.cfg.\n" ); | |
} | |
/* | |
@@ -1362,21 +999,18 @@ void Host_WriteVideoConfig( void ) | |
{ | |
file_t *f; | |
- if( Host_IsDedicated() ) | |
- return; | |
- | |
MsgDev( D_NOTE, "Host_WriteVideoConfig()\n" ); | |
f = FS_Open( "video.cfg", "w", false ); | |
if( f ) | |
{ | |
FS_Printf( f, "//=======================================================================\n" ); | |
- FS_Printf( f, "//\t\t\tCopyright XashXT Group %s ©\n", Q_timestamp( TIME_YEAR_ONLY )); | |
+ FS_Printf( f, "//\t\t\tCopyright XashXT Group %s �\n", Q_timestamp( TIME_YEAR_ONLY )); | |
FS_Printf( f, "//\t\tvideo.cfg - archive of renderer variables\n"); | |
FS_Printf( f, "//=======================================================================\n" ); | |
Cmd_WriteRenderVariables( f ); | |
FS_Close( f ); | |
} | |
- else MsgDev( D_ERROR, "Can't update video.cfg.\n" ); | |
+ else MsgDev( D_ERROR, "can't update video.cfg.\n" ); | |
} | |
void Key_EnumCmds_f( void ) | |
@@ -1395,14 +1029,14 @@ void Key_EnumCmds_f( void ) | |
if( f ) | |
{ | |
FS_Printf( f, "//=======================================================================\n"); | |
- FS_Printf( f, "//\t\t\tCopyright XashXT Group %s ©\n", Q_timestamp( TIME_YEAR_ONLY )); | |
+ FS_Printf( f, "//\t\t\tCopyright XashXT Group %s �\n", Q_timestamp( TIME_YEAR_ONLY )); | |
FS_Printf( f, "//\t\thelp.txt - xash commands and console variables\n"); | |
FS_Printf( f, "//=======================================================================\n"); | |
FS_Printf( f, "\n\n\t\t\tconsole variables\n\n"); | |
- Cvar_LookupVars( 0, NULL, f, (void*)Cmd_WriteHelp ); | |
+ Cvar_LookupVars( 0, NULL, f, Cmd_WriteHelp ); | |
FS_Printf( f, "\n\n\t\t\tconsole commands\n\n"); | |
- Cmd_LookupCmds( NULL, f, (void*)Cmd_WriteHelp ); | |
+ Cmd_LookupCmds( NULL, f, Cmd_WriteHelp ); | |
FS_Printf( f, "\n\n"); | |
FS_Close( f ); | |
Msg( "help.txt created\n" ); | |
diff --suppress-blank-empty -prudwEZbB engine/common/crclib.c /mnt/data/Xash3D_original/engine/common/crclib.c | |
--- engine/common/crclib.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/crclib.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -110,7 +110,7 @@ void CRC32_ProcessByte( dword *pulCRC, b | |
void CRC32_ProcessBuffer( dword *pulCRC, const void *pBuffer, int nBuffer ) | |
{ | |
- dword poolpb, ulCrc = *pulCRC; | |
+ dword ulCrc = *pulCRC; | |
byte *pb = (byte *)pBuffer; | |
uint nFront; | |
int nMain; | |
@@ -121,8 +121,7 @@ JustAfew: | |
case 6: ulCrc = crc32table[*pb++ ^ (byte)ulCrc] ^ (ulCrc >> 8); | |
case 5: ulCrc = crc32table[*pb++ ^ (byte)ulCrc] ^ (ulCrc >> 8); | |
case 4: | |
- Q_memcpy( &poolpb, pb, sizeof(dword)); | |
- ulCrc ^= poolpb; // warning, this only works on little-endian. | |
+ ulCrc ^= *(dword *)pb; // warning, this only works on little-endian. | |
ulCrc = crc32table[(byte)ulCrc] ^ (ulCrc >> 8); | |
ulCrc = crc32table[(byte)ulCrc] ^ (ulCrc >> 8); | |
ulCrc = crc32table[(byte)ulCrc] ^ (ulCrc >> 8); | |
@@ -140,7 +139,7 @@ JustAfew: | |
// the main loop is aligned and only has to worry about 8 byte at a time. | |
// The low-order two bits of pb and nBuffer in total control the | |
// upfront work. | |
- nFront = ((size_t)pb) & 3; | |
+ nFront = ((uint)pb) & 3; | |
nBuffer -= nFront; | |
switch( nFront ) | |
@@ -241,14 +240,12 @@ qboolean CRC32_MapFile( dword *crcvalue, | |
if( !crcvalue ) return false; | |
-#ifndef XASH_DEDICATED | |
// always calc same checksum for singleplayer | |
if( multiplayer == false ) | |
{ | |
*crcvalue = (('H'<<24)+('S'<<16)+('A'<<8)+'X'); | |
return true; | |
} | |
-#endif | |
f = FS_Open( filename, "rb", false ); | |
if( !f ) return false; | |
@@ -435,7 +432,7 @@ void MD5Final( byte digest[16], MD5Conte | |
MD5Transform( ctx->buf, (uint *)ctx->in ); | |
Q_memcpy( digest, ctx->buf, 16 ); | |
- Q_memset( ctx, 0, sizeof( *ctx )); // in case it's sensitive | |
+ Q_memset( ctx, 0, sizeof( ctx )); // in case it's sensitive | |
} | |
// The four core functions | |
@@ -563,7 +560,7 @@ qboolean MD5_HashFile( byte digest[16], | |
bytes = FS_Read( file, buffer, sizeof( buffer )); | |
if( bytes > 0 ) | |
- MD5Update( &MD5_Hash, (byte *)buffer, bytes ); | |
+ MD5Update( &MD5_Hash, buffer, bytes ); | |
if( FS_Eof( file )) | |
break; | |
diff --suppress-blank-empty -prudwEZbB engine/common/crtlib.c /mnt/data/Xash3D_original/engine/common/crtlib.c | |
--- engine/common/crtlib.c 2016-08-11 19:14:10.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/crtlib.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -54,7 +54,22 @@ qboolean Q_isdigit( const char *str ) | |
return false; | |
} | |
-#ifndef XASH_SKIPCRTLIB | |
+int Q_strlen( const char *string ) | |
+{ | |
+ int len; | |
+ const char *p; | |
+ | |
+ if( !string ) return 0; | |
+ | |
+ len = 0; | |
+ p = string; | |
+ while( *p ) | |
+ { | |
+ p++; | |
+ len++; | |
+ } | |
+ return len; | |
+} | |
char Q_toupper( const char in ) | |
{ | |
@@ -77,7 +92,66 @@ char Q_tolower( const char in ) | |
return out; | |
} | |
-#endif | |
+ | |
+size_t Q_strncat( char *dst, const char *src, size_t size ) | |
+{ | |
+ register char *d = dst; | |
+ register const char *s = src; | |
+ register size_t n = size; | |
+ size_t dlen; | |
+ | |
+ if( !dst || !src || !size ) | |
+ return 0; | |
+ | |
+ // find the end of dst and adjust bytes left but don't go past end | |
+ while( n-- != 0 && *d != '\0' ) d++; | |
+ dlen = d - dst; | |
+ n = size - dlen; | |
+ | |
+ if( n == 0 ) return( dlen + Q_strlen( s )); | |
+ | |
+ while( *s != '\0' ) | |
+ { | |
+ if( n != 1 ) | |
+ { | |
+ *d++ = *s; | |
+ n--; | |
+ } | |
+ s++; | |
+ } | |
+ | |
+ *d = '\0'; | |
+ return( dlen + ( s - src )); // count does not include NULL | |
+} | |
+ | |
+size_t Q_strncpy( char *dst, const char *src, size_t size ) | |
+{ | |
+ register char *d = dst; | |
+ register const char *s = src; | |
+ register size_t n = size; | |
+ | |
+ if( !dst || !src || !size ) | |
+ return 0; | |
+ | |
+ // copy as many bytes as will fit | |
+ if( n != 0 && --n != 0 ) | |
+ { | |
+ do | |
+ { | |
+ if(( *d++ = *s++ ) == 0 ) | |
+ break; | |
+ } while( --n != 0 ); | |
+ } | |
+ | |
+ // not enough room in dst, add NULL and traverse rest of src | |
+ if( n == 0 ) | |
+ { | |
+ if( size != 0 ) | |
+ *d = '\0'; // NULL-terminate dst | |
+ while( *s++ ); | |
+ } | |
+ return ( s - src - 1 ); // count does not include NULL | |
+} | |
char *_copystring( byte *mempool, const char *s, const char *filename, int fileline ) | |
{ | |
@@ -91,7 +165,7 @@ char *_copystring( byte *mempool, const | |
return b; | |
} | |
-#ifndef XASH_SKIPCRTLIB | |
+ | |
int Q_atoi( const char *str ) | |
{ | |
int val = 0; | |
@@ -208,7 +282,7 @@ float Q_atof( const char *str ) | |
return val * sign; | |
} | |
-#endif | |
+ | |
void Q_atov( float *vec, const char *str, size_t siz ) | |
{ | |
string buffer; | |
@@ -233,6 +307,94 @@ void Q_atov( float *vec, const char *str | |
} | |
} | |
+char *Q_strchr( const char *s, char c ) | |
+{ | |
+ int len = Q_strlen( s ); | |
+ | |
+ while( len-- ) | |
+ { | |
+ if( *++s == c ) | |
+ return (char *)s; | |
+ } | |
+ return 0; | |
+} | |
+ | |
+char *Q_strrchr( const char *s, char c ) | |
+{ | |
+ int len = Q_strlen( s ); | |
+ | |
+ s += len; | |
+ | |
+ while( len-- ) | |
+ { | |
+ if( *--s == c ) | |
+ return (char *)s; | |
+ } | |
+ return 0; | |
+} | |
+ | |
+int Q_strnicmp( const char *s1, const char *s2, int n ) | |
+{ | |
+ int c1, c2; | |
+ | |
+ if( s1 == NULL ) | |
+ { | |
+ if( s2 == NULL ) | |
+ return 0; | |
+ else return -1; | |
+ } | |
+ else if( s2 == NULL ) | |
+ { | |
+ return 1; | |
+ } | |
+ | |
+ do { | |
+ c1 = *s1++; | |
+ c2 = *s2++; | |
+ | |
+ if( !n-- ) return 0; // strings are equal until end point | |
+ | |
+ if( c1 != c2 ) | |
+ { | |
+ if( c1 >= 'a' && c1 <= 'z' ) c1 -= ('a' - 'A'); | |
+ if( c2 >= 'a' && c2 <= 'z' ) c2 -= ('a' - 'A'); | |
+ if( c1 != c2 ) return c1 < c2 ? -1 : 1; | |
+ } | |
+ } while( c1 ); | |
+ | |
+ // strings are equal | |
+ return 0; | |
+} | |
+ | |
+int Q_strncmp( const char *s1, const char *s2, int n ) | |
+{ | |
+ int c1, c2; | |
+ | |
+ if( s1 == NULL ) | |
+ { | |
+ if( s2 == NULL ) | |
+ return 0; | |
+ else return -1; | |
+ } | |
+ else if( s2 == NULL ) | |
+ { | |
+ return 1; | |
+ } | |
+ | |
+ do { | |
+ c1 = *s1++; | |
+ c2 = *s2++; | |
+ | |
+ // strings are equal until end point | |
+ if( !n-- ) return 0; | |
+ if( c1 != c2 ) return c1 < c2 ? -1 : 1; | |
+ | |
+ } while( c1 ); | |
+ | |
+ // strings are equal | |
+ return 0; | |
+} | |
+ | |
static qboolean Q_starcmp( const char *pattern, const char *text ) | |
{ | |
char c, c1; | |
@@ -277,7 +439,7 @@ qboolean Q_stricmpext( const char *patte | |
return false; | |
} | |
} | |
- return true; | |
+ return ( *text == '\0' ); | |
} | |
const char* Q_timestamp( int format ) | |
@@ -323,7 +485,7 @@ const char* Q_timestamp( int format ) | |
return timestamp; | |
} | |
-#ifndef XASH_SKIPCRTLIB | |
+ | |
char *Q_strstr( const char *string, const char *string2 ) | |
{ | |
int c, len; | |
@@ -374,11 +536,11 @@ char *Q_stristr( const char *string, con | |
int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args ) | |
{ | |
- int result; | |
+ size_t result; | |
- result = vsnprintf( buffer, buffersize, format, args ); | |
+ result = _vsnprintf( buffer, buffersize, format, args ); | |
- if( result < 0 || result >= ( int )buffersize ) | |
+ if( result < 0 || result >= buffersize ) | |
{ | |
buffer[buffersize - 1] = '\0'; | |
return -1; | |
@@ -409,7 +571,7 @@ int Q_sprintf( char *buffer, const char | |
return result; | |
} | |
-#endif | |
+ | |
char *Q_pretifymem( float value, int digitsafterdecimal ) | |
{ | |
static char output[8][32]; | |
@@ -532,6 +694,8 @@ void _Q_memmove( void *dest, const void | |
if( dest == NULL ) Sys_Error( "memmove: dest == NULL (called at %s:%i)\n", filename, fileline ); | |
memmove( dest, src, count ); | |
} | |
-#ifndef XASH_FORCEINLINE | |
-#include "crtlib_inline.h" | |
-#endif | |
+ | |
+void CRT_Init( void ) | |
+{ | |
+ Memory_Init(); | |
+} | |
\ В конце файла нет новой строки | |
diff --suppress-blank-empty -prudwEZbB engine/common/crtlib.h /mnt/data/Xash3D_original/engine/common/crtlib.h | |
--- engine/common/crtlib.h 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/crtlib.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -16,11 +16,6 @@ GNU General Public License for more deta | |
#ifndef STDLIB_H | |
#define STDLIB_H | |
-#include <stdarg.h> | |
-#ifndef XASH_SDL | |
-#include <string.h> | |
-#include <ctype.h> | |
-#endif | |
// timestamp modes | |
enum | |
{ | |
@@ -77,17 +72,16 @@ typedef enum | |
CVAR_SPONLY = BIT(6), // this cvar cannot be changed by clients connected to a multiplayer server. | |
CVAR_PRINTABLEONLY = BIT(7), // this cvar's string cannot contain unprintable characters ( player name ) | |
CVAR_UNLOGGED = BIT(8), // if this is a FCVAR_SERVER, don't log changes to the log file / console | |
- CVAR_NOEXTRAWHITESPACE = BIT(9), // strip trailing/leading white space from this cvar | |
- CVAR_SERVERINFO = BIT(10), // added to serverinfo when changed | |
- CVAR_PHYSICINFO = BIT(11),// added to physinfo when changed | |
- CVAR_RENDERINFO = BIT(12),// save to a seperate config called opengl.cfg | |
- CVAR_CHEAT = BIT(13),// can not be changed if cheats are disabled | |
- CVAR_INIT = BIT(14),// don't allow change from console at all, but can be set from the command line | |
- CVAR_LATCH = BIT(15),// save changes until server restart | |
- CVAR_READ_ONLY = BIT(16),// display only, cannot be set by user at all | |
- CVAR_LATCH_VIDEO = BIT(17),// save changes until render restart | |
- CVAR_USER_CREATED = BIT(18),// created by a set command (dll's used) | |
- CVAR_GLCONFIG = BIT(19),// set to cause it to be saved to opengl.cfg | |
+ CVAR_SERVERINFO = BIT(9), // added to serverinfo when changed | |
+ CVAR_PHYSICINFO = BIT(10),// added to physinfo when changed | |
+ CVAR_RENDERINFO = BIT(11),// save to a seperate config called opengl.cfg | |
+ CVAR_CHEAT = BIT(12),// can not be changed if cheats are disabled | |
+ CVAR_INIT = BIT(13),// don't allow change from console at all, but can be set from the command line | |
+ CVAR_LATCH = BIT(14),// save changes until server restart | |
+ CVAR_READ_ONLY = BIT(15),// display only, cannot be set by user at all | |
+ CVAR_LATCH_VIDEO = BIT(16),// save changes until render restart | |
+ CVAR_USER_CREATED = BIT(17),// created by a set command (dll's used) | |
+ CVAR_GLCONFIG = BIT(18),// set to cause it to be saved to opengl.cfg | |
} cvar_flags_t; | |
#include "cvardef.h" | |
@@ -109,7 +103,7 @@ int Cvar_VariableInteger( const char *va | |
char *Cvar_VariableString( const char *var_name ); | |
void Cvar_DirectSet( cvar_t *var, const char *value ); | |
void Cvar_Reset( const char *var_name ); | |
-void Cvar_SetCheatState( qboolean force ); | |
+void Cvar_SetCheatState( void ); | |
qboolean Cvar_Command( void ); | |
void Cvar_WriteVariables( file_t *f ); | |
void Cvar_Init( void ); | |
@@ -125,11 +119,10 @@ void Cbuf_Clear( void ); | |
void Cbuf_AddText( const char *text ); | |
void Cbuf_InsertText( const char *text ); | |
void Cbuf_Execute (void); | |
-int Cmd_Argc( void ); | |
+uint Cmd_Argc( void ); | |
char *Cmd_Args( void ); | |
char *Cmd_Argv( int arg ); | |
void Cmd_Init( void ); | |
-void Cmd_Shutdown( void ); | |
void Cmd_Unlink( int group ); | |
void Cmd_AddCommand( const char *cmd_name, xcommand_t function, const char *cmd_desc ); | |
void Cmd_AddGameCommand( const char *cmd_name, xcommand_t function ); | |
@@ -140,8 +133,8 @@ void Cmd_LookupCmds( char *buffer, void | |
qboolean Cmd_GetMapList( const char *s, char *completedname, int length ); | |
qboolean Cmd_GetDemoList( const char *s, char *completedname, int length ); | |
qboolean Cmd_GetMovieList( const char *s, char *completedname, int length ); | |
-void Cmd_TokenizeString( const char *text ); | |
-void Cmd_ExecuteString( const char *text, cmd_source_t src ); | |
+void Cmd_TokenizeString( char *text ); | |
+void Cmd_ExecuteString( char *text, cmd_source_t src ); | |
void Cmd_ForwardToServer( void ); | |
// | |
@@ -152,151 +144,40 @@ void Cmd_ForwardToServer( void ); | |
void Q_strnupr( const char *in, char *out, size_t size_out ); | |
#define Q_strlwr( int, out ) Q_strnlwr( in, out, 99999 ) | |
void Q_strnlwr( const char *in, char *out, size_t size_out ); | |
-#ifndef XASH_SKIPCRTLIB | |
- | |
+int Q_strlen( const char *string ); | |
char Q_toupper( const char in ); | |
char Q_tolower( const char in ); | |
- | |
-#else | |
-static inline int Q_strlen( const char *str ) | |
-{ | |
- if( !str ) | |
- return 0; | |
- return strlen(str); | |
-} | |
-#define Q_toupper toupper | |
-#define Q_tolower tolower | |
-#endif | |
-#ifndef XASH_FORCEINLINE | |
+#define Q_strcat( dst, src ) Q_strncat( dst, src, 99999 ) | |
size_t Q_strncat( char *dst, const char *src, size_t siz ); | |
+#define Q_strcpy( dst, src ) Q_strncpy( dst, src, 99999 ) | |
size_t Q_strncpy( char *dst, const char *src, size_t siz ); | |
-size_t Q_strcat( char *dst, const char *src ); | |
-size_t Q_strcpy( char *dst, const char *src ); | |
-int Q_strlen( const char *string ); | |
-#else | |
-#include "crtlib_inline.h" | |
-#endif | |
#define copystring( s ) _copystring( host.mempool, s, __FILE__, __LINE__ ) | |
char *_copystring( byte *mempool, const char *s, const char *filename, int fileline ); | |
qboolean Q_isdigit( const char *str ); | |
-#ifndef XASH_SKIPCRTLIB | |
int Q_atoi( const char *str ); | |
float Q_atof( const char *str ); | |
-#else | |
-#define Q_atoi atoi | |
-#define Q_atof atof | |
-#endif | |
void Q_atov( float *vec, const char *str, size_t siz ); | |
-#ifndef XASH_SKIPCRTLIB | |
-#ifndef XASH_FORCEINLINE | |
char *Q_strchr( const char *s, char c ); | |
char *Q_strrchr( const char *s, char c ); | |
+#define Q_stricmp( s1, s2 ) Q_strnicmp( s1, s2, 99999 ) | |
int Q_strnicmp( const char *s1, const char *s2, int n ); | |
+#define Q_strcmp( s1, s2 ) Q_strncmp( s1, s2, 99999 ) | |
int Q_strncmp( const char *s1, const char *s2, int n ); | |
-int Q_stricmp( const char *s1, const char *s2 ); | |
-int Q_strcmp( const char *s1, const char *s2 ); | |
-#endif | |
-#else | |
-static inline char *Q_strchr( const char *s, char c ) | |
-{ | |
- if( !s ) | |
- return NULL; | |
- return strchr( s, c ); | |
-} | |
-static inline char *Q_strrchr( const char *s, char c ) | |
-{ | |
- if( !s ) | |
- return NULL; | |
- return strrchr( s, c ); | |
-} | |
-static inline int Q_stricmp( const char *s1, const char *s2 ) | |
-{ | |
- if( s1 == NULL ) | |
- { | |
- if( s2 == NULL ) | |
- return 0; | |
- else return -1; | |
- } | |
- else if( s2 == NULL ) | |
- { | |
- return 1; | |
- } | |
- return strcasecmp( s1, s2 ); | |
-} | |
-static inline int Q_strnicmp( const char *s1, const char *s2, int n ) | |
-{ | |
- if( s1 == NULL ) | |
- { | |
- if( s2 == NULL ) | |
- return 0; | |
- else return -1; | |
- } | |
- else if( s2 == NULL ) | |
- { | |
- return 1; | |
- } | |
- return strncasecmp( s1, s2, n ); | |
-} | |
-static inline int Q_strcmp( const char *s1, const char *s2 ) | |
-{ | |
- if( s1 == NULL ) | |
- { | |
- if( s2 == NULL ) | |
- return 0; | |
- else return -1; | |
- } | |
- else if( s2 == NULL ) | |
- { | |
- return 1; | |
- } | |
- return strcmp( s1, s2 ); | |
-} | |
-static inline int Q_strncmp( const char *s1, const char *s2, int n ) | |
-{ | |
- if( s1 == NULL ) | |
- { | |
- if( s2 == NULL ) | |
- return 0; | |
- else return -1; | |
- } | |
- else if( s2 == NULL ) | |
- { | |
- return 1; | |
- } | |
- return strncmp( s1, s2, n ); | |
-} | |
-#endif | |
qboolean Q_stricmpext( const char *s1, const char *s2 ); | |
const char *Q_timestamp( int format ); | |
-#ifndef XASH_SKIPCRTLIB | |
char *Q_stristr( const char *string, const char *string2 ); | |
char *Q_strstr( const char *string, const char *string2 ); | |
#define Q_vsprintf( buffer, format, args ) Q_vsnprintf( buffer, 99999, format, args ) | |
int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args ); | |
-int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ) _format(3); | |
-int Q_sprintf( char *buffer, const char *format, ... ) _format(2); | |
-#else | |
-#define Q_stristr strcasestr | |
-#define Q_strstr strstr | |
-#define Q_vsprintf vsprintf | |
-#define Q_vsnprintf vsnprintf | |
-#define Q_snprintf snprintf | |
-#define Q_sprintf sprintf | |
-#endif | |
+int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ); | |
+int Q_sprintf( char *buffer, const char *format, ... ); | |
#define Q_memprint( val ) Q_pretifymem( val, 2 ) | |
char *Q_pretifymem( float value, int digitsafterdecimal ); | |
-char *va( const char *format, ... ) _format(1); | |
-#ifndef XASH_SKIPCRTLIB | |
+char *va( const char *format, ... ); | |
#define Q_memcpy( dest, src, size ) _Q_memcpy( dest, src, size, __FILE__, __LINE__ ) | |
#define Q_memset( dest, val, size ) _Q_memset( dest, val, size, __FILE__, __LINE__ ) | |
#define Q_memcmp( src0, src1, siz ) _Q_memcmp( src0, src1, siz, __FILE__, __LINE__ ) | |
#define Q_memmove( dest, src, size ) _Q_memmove( dest, src, size, __FILE__, __LINE__ ) | |
-#else | |
-#define Q_memcpy memcpy | |
-#define Q_memset memset | |
-#define Q_memcmp memcmp | |
-#define Q_memmove memmove | |
-#endif | |
void _Q_memset( void *dest, int set, size_t count, const char *filename, int fileline ); | |
void _Q_memcpy( void *dest, const void *src, size_t count, const char *filename, int fileline ); | |
int _Q_memcmp( const void *src0, const void *src1, size_t count, const char *filename, int fileline ); | |
@@ -305,6 +186,7 @@ void _Q_memmove( void *dest, const void | |
// | |
// zone.c | |
// | |
+void Memory_Init( void ); | |
void *_Mem_Realloc( byte *poolptr, void *memptr, size_t size, const char *filename, int fileline ); | |
void *_Mem_Alloc( byte *poolptr, size_t size, const char *filename, int fileline ); | |
byte *_Mem_AllocPool( const char *name, const char *filename, int fileline ); | |
@@ -325,4 +207,6 @@ void Mem_PrintStats( void ); | |
#define Mem_IsAllocated( mem ) Mem_IsAllocatedExt( NULL, mem ) | |
#define Mem_Check() _Mem_Check( __FILE__, __LINE__ ) | |
+void CRT_Init( void ); // must be call first | |
+ | |
#endif//STDLIB_H | |
Только в engine/common: crtlib_inline.h | |
diff --suppress-blank-empty -prudwEZbB engine/common/cvar.c /mnt/data/Xash3D_original/engine/common/cvar.c | |
--- engine/common/cvar.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/cvar.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -14,9 +14,6 @@ GNU General Public License for more deta | |
*/ | |
#include "common.h" | |
-#include "base_cmd.h" | |
- | |
-#define HASH_SIZE 256 | |
convar_t *cvar_vars; // head of list | |
convar_t *userinfo, *physinfo, *serverinfo, *renderinfo; | |
@@ -43,7 +40,7 @@ char *Cvar_GetName( cvar_t *cvar ) | |
/* | |
============ | |
-Cvar_ValidateString | |
+Cvar_InfoValidate | |
============ | |
*/ | |
static qboolean Cvar_ValidateString( const char *s, qboolean isvalue ) | |
@@ -63,9 +60,6 @@ Cvar_FindVar | |
*/ | |
convar_t *Cvar_FindVar( const char *var_name ) | |
{ | |
-#if defined(XASH_HASHED_VARS) | |
- return (convar_t *)BaseCmd_Find( HM_CVAR, var_name ); | |
-#else | |
convar_t *var; | |
for( var = cvar_vars; var; var = var->next ) | |
@@ -73,8 +67,6 @@ convar_t *Cvar_FindVar( const char *var_ | |
if( !Q_stricmp( var_name, var->name )) | |
return var; | |
} | |
-#endif | |
- | |
return NULL; | |
} | |
@@ -146,17 +138,10 @@ void Cvar_LookupVars( int checkbit, void | |
} | |
else | |
{ | |
- char *desc; | |
- | |
+ // NOTE: dlls cvars doesn't have description | |
if( cvar->flags & CVAR_EXTDLL ) | |
- desc = "game cvar"; | |
- else | |
- desc = cvar->description; | |
- | |
- if( !desc ) | |
- desc = "user cvar"; | |
- | |
- callback( cvar->name, cvar->string, desc, ptr ); | |
+ callback( cvar->name, cvar->string, "game cvar", ptr ); | |
+ else callback( cvar->name, cvar->string, cvar->description, ptr ); | |
} | |
} | |
} | |
@@ -171,14 +156,17 @@ The flags will be or'ed in if the variab | |
*/ | |
convar_t *Cvar_Get( const char *var_name, const char *var_value, int flags, const char *var_desc ) | |
{ | |
- convar_t *cvar; | |
- convar_t *current, *next; | |
+ convar_t *var; | |
- ASSERT( var_name != NULL ); | |
+ if( !var_name ) | |
+ { | |
+ Sys_Error( "Cvar_Get: passed NULL name\n" ); | |
+ return NULL; | |
+ } | |
if( !var_value ) var_value = "0"; // just apply default value | |
- // all broadcast cvars must pass this check | |
+ // all broadcast cvars must be passed this check | |
if( flags & ( CVAR_USERINFO|CVAR_SERVERINFO|CVAR_PHYSICINFO )) | |
{ | |
if( !Cvar_ValidateString( var_name, false )) | |
@@ -194,88 +182,77 @@ convar_t *Cvar_Get( const char *var_name | |
} | |
} | |
- // check for overlap with a command | |
+ // check for command coexisting | |
if( Cmd_Exists( var_name )) | |
{ | |
MsgDev( D_ERROR, "Cvar_Get: %s is a command\n", var_name ); | |
return NULL; | |
} | |
- cvar = Cvar_FindVar( var_name ); | |
+ var = Cvar_FindVar( var_name ); | |
- if( cvar ) | |
+ if( var ) | |
{ | |
// fast check for short cvars | |
- if( cvar->flags & CVAR_EXTDLL ) | |
+ if( var->flags & CVAR_EXTDLL ) | |
{ | |
- cvar->flags |= flags; | |
- return cvar; | |
+ var->flags |= flags; | |
+ return 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(( cvar->flags & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED ) && var_value[0] ) | |
+ if(( var->flags & CVAR_USER_CREATED ) && !( flags & CVAR_USER_CREATED ) && var_value[0] ) | |
{ | |
- cvar->flags &= ~CVAR_USER_CREATED; | |
- Mem_Free( cvar->reset_string ); | |
- cvar->reset_string = copystring( var_value ); | |
+ var->flags &= ~CVAR_USER_CREATED; | |
+ Mem_Free( var->reset_string ); | |
+ var->reset_string = copystring( var_value ); | |
} | |
- cvar->flags |= flags; | |
+ var->flags |= flags; | |
// only allow one non-empty reset string without a warning | |
- if( !cvar->reset_string[0] ) | |
+ if( !var->reset_string[0] ) | |
{ | |
// we don't have a reset string yet | |
- Mem_Free( cvar->reset_string ); | |
- cvar->reset_string = copystring( var_value ); | |
+ Mem_Free( var->reset_string ); | |
+ var->reset_string = copystring( var_value ); | |
} | |
// if we have a latched string, take that value now | |
- if( cvar->latched_string ) | |
+ if( var->latched_string ) | |
{ | |
- char *s = cvar->latched_string; | |
- cvar->latched_string = NULL; // otherwise cvar_set2 would free it | |
+ char *s = var->latched_string; | |
+ var->latched_string = NULL; // otherwise cvar_set2 would free it | |
Cvar_Set2( var_name, s, true ); | |
Mem_Free( s ); | |
} | |
if( var_desc ) | |
{ | |
- // update description if needed | |
- Z_Free( cvar->description ); | |
- cvar->description = copystring( var_desc ); | |
+ // update description if needs | |
+ if( var->description ) Mem_Free( var->description ); | |
+ var->description = copystring( var_desc ); | |
} | |
- return cvar; | |
+ return var; | |
} | |
// allocate a new cvar | |
- cvar = Z_Malloc( sizeof( convar_t )); | |
- cvar->name = copystring( var_name ); | |
- cvar->string = copystring( var_value ); | |
- cvar->reset_string = copystring( var_value ); | |
- if( var_desc ) cvar->description = copystring( var_desc ); | |
- cvar->value = Q_atof( cvar->string ); | |
- cvar->integer = Q_atoi( cvar->string ); | |
- cvar->modified = true; | |
- cvar->flags = flags; | |
- | |
- // link the variable in alphanumerical order | |
- for( current = NULL, next = cvar_vars ; next && Q_strcmp( next->name, cvar->name ) < 0 ; current = next, next = next->next ); | |
- | |
- if( current ) | |
- current->next = cvar; | |
- else | |
- cvar_vars = cvar; | |
- | |
- cvar->next = next; | |
+ var = Z_Malloc( sizeof( *var )); | |
+ var->name = copystring( var_name ); | |
+ var->string = copystring( var_value ); | |
+ var->reset_string = copystring( var_value ); | |
+ if( var_desc ) var->description = copystring( var_desc ); | |
+ var->value = Q_atof( var->string ); | |
+ var->integer = Q_atoi( var->string ); | |
+ var->modified = true; | |
+ var->flags = flags; | |
-#if defined(XASH_HASHED_VARS) | |
- // add to map | |
- BaseCmd_Insert( HM_CVAR, cvar, cvar->name ); | |
-#endif | |
+ // link the variable in | |
+ var->next = cvar_vars; | |
+ cvar_vars = var; | |
- return cvar; | |
+ return var; | |
} | |
/* | |
@@ -287,53 +264,70 @@ Adds a freestanding variable to the vari | |
*/ | |
void Cvar_RegisterVariable( cvar_t *var ) | |
{ | |
- convar_t *current, *next, *cvar; | |
+ convar_t **prev, *cur = NULL; | |
+ convar_t *find; | |
ASSERT( var != NULL ); | |
+ // check for overlap with a command | |
+ if( Cmd_Exists( var->name )) | |
+ { | |
+ MsgDev( D_ERROR, "Cvar_Register: %s is a command\n", var->name ); | |
+ return; | |
+ } | |
+ | |
// first check to see if it has already been defined | |
- if(( cvar = Cvar_FindVar( var->name )) != NULL ) | |
+ if(( cur = Cvar_FindVar( var->name )) != NULL ) | |
{ | |
// this cvar is already registered with Cvar_RegisterVariable | |
// so we can't replace it | |
- if( cvar->flags & CVAR_EXTDLL ) | |
+ if( cur->flags & CVAR_EXTDLL ) | |
{ | |
- MsgDev( D_ERROR, "Can't register variable %s, already defined\n", var->name ); | |
+ MsgDev( D_ERROR, "can't register variable %s, allready defined\n", var->name ); | |
+ return; | |
} | |
- else | |
+ } | |
+ | |
+ if( cur ) | |
{ | |
- var->string = cvar->string; // we already have right string | |
- var->value = Q_atof( var->string ); | |
- var->flags |= CVAR_EXTDLL; // all cvars passed this function are game cvars | |
- var->next = (cvar_t *)cvar->next; | |
+ prev = &cvar_vars; | |
- if( cvar_vars == cvar ) | |
+ while( 1 ) | |
{ | |
- // head of the list is easy to change | |
+ find = *prev; | |
+ | |
+ ASSERT( find != NULL ); | |
+ | |
+ if( cur == cvar_vars ) | |
+ { | |
+ // relink at tail | |
cvar_vars = (convar_t *)var; | |
+ break; | |
} | |
- else | |
+ | |
+ // search for previous cvar | |
+ if( cur != find->next ) | |
{ | |
- // otherwise find it somewhere in the list | |
- for( current = cvar_vars; current->next != cvar; current = current->next ); | |
+ prev = &find->next; | |
+ continue; | |
+ } | |
- current->next = (convar_t *)var; | |
+ // link new variable | |
+ find->next = (convar_t *)var; | |
+ break; | |
} | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Replace( HM_CVAR, var, var->name ); | |
-#endif | |
+ var->string = cur->string; // we already have right string | |
+ var->value = Q_atof( var->string ); | |
+ var->flags |= CVAR_EXTDLL; // all cvars passed this function are game cvars | |
+ var->next = (cvar_t *)cur->next; | |
+ | |
// release current cvar (but keep string) | |
- Z_Free( cvar->name ); | |
- Z_Free( cvar->latched_string ); | |
- Z_Free( cvar->reset_string ); | |
- Z_Free( cvar->description ); | |
- Mem_Free( cvar ); | |
- } | |
- } | |
- else if( Cmd_Exists( var->name )) | |
- { | |
- MsgDev( D_ERROR, "Cvar_Register: %s is a command\n", var->name ); | |
+ if( cur->name ) Mem_Free( cur->name ); | |
+ if( cur->latched_string ) Mem_Free( cur->latched_string ); | |
+ if( cur->reset_string ) Mem_Free( cur->reset_string ); | |
+ if( cur->description ) Mem_Free( cur->description ); | |
+ Mem_Free( cur ); | |
} | |
else | |
{ | |
@@ -342,23 +336,9 @@ void Cvar_RegisterVariable( cvar_t *var | |
var->value = Q_atof( var->string ); | |
var->flags |= CVAR_EXTDLL; // all cvars passed this function are game cvars | |
- // link the variable in alphanumerical order | |
- for( current = NULL, next = cvar_vars ; next && Q_strcmp( next->name, var->name ) < 0 ; current = next, next = next->next ); | |
- | |
- if( current ) | |
- current->next = var; | |
- else | |
- cvar_vars = var; | |
- | |
- var->next = next; | |
- | |
- // add to bucket | |
- // we got a cvar_t from gamedll, where we have no left to chain in bucket | |
- // so disable it | |
- | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Insert( HM_CVAR, var, var->name ); | |
-#endif | |
+ // link the variable in | |
+ var->next = (cvar_t *)cvar_vars; | |
+ cvar_vars = (convar_t *)var; | |
} | |
} | |
@@ -376,7 +356,7 @@ convar_t *Cvar_Set2( const char *var_nam | |
if( !Cvar_ValidateString( var_name, false )) | |
{ | |
- MsgDev( D_ERROR, "Invalid cvar name string: %s\n", var_name ); | |
+ MsgDev( D_ERROR, "invalid cvar name string: %s\n", var_name ); | |
return NULL; | |
} | |
@@ -475,7 +455,7 @@ convar_t *Cvar_Set2( const char *var_nam | |
// This cvar's string must only contain printable characters. | |
// Strip out any other crap. | |
- // We'll fill in "empty" if nothing is left. | |
+ // We'll fill in "empty" if nothing is left | |
if( var->flags & CVAR_PRINTABLEONLY ) | |
{ | |
const char *pS; | |
@@ -490,7 +470,7 @@ convar_t *Cvar_Set2( const char *var_nam | |
// step through the string, only copying back in characters that are printable | |
while( *pS ) | |
{ | |
- if( ((byte)*pS) < 32 ) | |
+ if( ((byte)*pS) < 32 || ((byte)*pS) > 255 ) | |
{ | |
pS++; | |
continue; | |
@@ -516,16 +496,16 @@ convar_t *Cvar_Set2( const char *var_nam | |
return var; | |
if( var->flags & CVAR_USERINFO ) | |
- userinfo->modified = true; // transmit at next opportunity | |
+ userinfo->modified = true; // transmit at next oportunity | |
if( var->flags & CVAR_PHYSICINFO ) | |
- physinfo->modified = true; // transmit at next opportunity | |
+ physinfo->modified = true; // transmit at next oportunity | |
if( var->flags & CVAR_SERVERINFO ) | |
- serverinfo->modified = true; // transmit at next opportunity | |
+ serverinfo->modified = true; // transmit at next oportunity | |
if( var->flags & CVAR_RENDERINFO ) | |
- renderinfo->modified = true; // transmit at next opportunity | |
+ renderinfo->modified = true; // transmit at next oportunity | |
// free the old value string | |
Mem_Free( var->string ); | |
@@ -579,8 +559,8 @@ void Cvar_FullSet( const char *var_name, | |
return; | |
} | |
- // use this check to prevent acessing of non-existing fields | |
- // for cvar_t: latched_string, description, etc. | |
+ // use this check to prevent acessing for unexisting fields | |
+ // for cvar_t: latechd_string, description, etc | |
if( var->flags & CVAR_EXTDLL ) | |
{ | |
dll_variable = true; | |
@@ -588,25 +568,25 @@ void Cvar_FullSet( const char *var_name, | |
if( var->flags & CVAR_USERINFO ) | |
{ | |
- // transmit at next opportunity | |
+ // transmit at next oportunity | |
userinfo->modified = true; | |
} | |
if( var->flags & CVAR_PHYSICINFO ) | |
{ | |
- // transmit at next opportunity | |
+ // transmit at next oportunity | |
physinfo->modified = true; | |
} | |
if( var->flags & CVAR_SERVERINFO ) | |
{ | |
- // transmit at next opportunity | |
+ // transmit at next oportunity | |
serverinfo->modified = true; | |
} | |
if( var->flags & CVAR_RENDERINFO ) | |
{ | |
- // transmit at next opportunity | |
+ // transmit at next oportunity | |
renderinfo->modified = true; | |
} | |
@@ -615,7 +595,7 @@ void Cvar_FullSet( const char *var_name, | |
var->value = Q_atof( var->string ); | |
var->flags = flags; | |
- if( dll_variable ) return; // below fields don't exist in cvar_t | |
+ if( dll_variable ) return; // below fields doesn't exist in cvar_t | |
var->integer = Q_atoi( var->string ); | |
var->modified = true; | |
@@ -632,7 +612,7 @@ void Cvar_DirectSet( cvar_t *var, const | |
const char *pszValue; | |
char szNew[MAX_SYSPATH]; | |
- if( !var ) return; // GET_CVAR_POINTER has failed ? | |
+ if( !var ) return; // GET_CVAR_POINTER is failed ? | |
// make sure what is really pointer to the cvar | |
test = (cvar_t *)Cvar_FindVar( var->name ); | |
@@ -640,7 +620,7 @@ void Cvar_DirectSet( cvar_t *var, const | |
if( value && !Cvar_ValidateString( value, true )) | |
{ | |
- MsgDev( D_WARN, "Invalid cvar value string: %s\n", value ); | |
+ MsgDev( D_WARN, "invalid cvar value string: %s\n", value ); | |
value = "0"; | |
} | |
@@ -662,7 +642,7 @@ void Cvar_DirectSet( cvar_t *var, const | |
// This cvar's string must only contain printable characters. | |
// Strip out any other crap. | |
- // We'll fill in "empty" if nothing is left. | |
+ // We'll fill in "empty" if nothing is left | |
if( var->flags & CVAR_PRINTABLEONLY ) | |
{ | |
const char *pS; | |
@@ -677,7 +657,7 @@ void Cvar_DirectSet( cvar_t *var, const | |
// step through the string, only copying back in characters that are printable | |
while( *pS ) | |
{ | |
- if( *pS < 32 ) | |
+ if( *pS < 32 || *pS > 255 ) | |
{ | |
pS++; | |
continue; | |
@@ -702,16 +682,16 @@ void Cvar_DirectSet( cvar_t *var, const | |
return; | |
if( var->flags & CVAR_USERINFO ) | |
- userinfo->modified = true; // transmit at next opportunity | |
+ userinfo->modified = true; // transmit at next oportunity | |
if( var->flags & CVAR_PHYSICINFO ) | |
- physinfo->modified = true; // transmit at next opportunity | |
+ physinfo->modified = true; // transmit at next oportunity | |
if( var->flags & CVAR_SERVERINFO ) | |
- serverinfo->modified = true; // transmit at next opportunity | |
+ serverinfo->modified = true; // transmit at next oportunity | |
if( var->flags & CVAR_RENDERINFO ) | |
- renderinfo->modified = true; // transmit at next opportunity | |
+ renderinfo->modified = true; // transmit at next oportunity | |
// free the old value string | |
Mem_Free( var->string ); | |
@@ -751,23 +731,9 @@ Cvar_SetCheatState | |
Any testing variables will be reset to the safe values | |
============ | |
*/ | |
-void Cvar_SetCheatState( qboolean force ) | |
+void Cvar_SetCheatState( void ) | |
{ | |
convar_t *var; | |
- qboolean disable_cheats; | |
- | |
- var = Cvar_FindVar( "sv_cheats" ); | |
- | |
- ASSERT( var ); | |
- | |
- disable_cheats = !var->integer; | |
- | |
- if( var->latched_string ) | |
- disable_cheats = !Q_atoi( var->latched_string ); | |
- | |
- // when shutting down, restore all latched cvars before saving it to config | |
- if( force ) | |
- disable_cheats = false; | |
// set all default vars to the safe value | |
for( var = cvar_vars; var; var = var->next ) | |
@@ -776,25 +742,20 @@ void Cvar_SetCheatState( qboolean force | |
if( var->flags & CVAR_EXTDLL ) | |
continue; | |
- if( ( var->flags & CVAR_CHEAT ) && var->reset_string ) | |
- { | |
- if( disable_cheats ) | |
+ if( var->flags & CVAR_CHEAT ) | |
{ | |
- char *value = copystring( var->string ); | |
- Cvar_FullSet( var->name, var->reset_string, var->flags ); | |
- // keep values in latched field | |
+ // the CVAR_LATCHED|CVAR_CHEAT vars might escape the reset here | |
+ // because of a different var->latched_string | |
if( var->latched_string ) | |
- Mem_Free( value ); | |
- else | |
- var->latched_string = value; | |
- } | |
- else if( var->latched_string ) | |
{ | |
- Cvar_FullSet( var->name, var->latched_string, var->flags ); | |
Mem_Free( var->latched_string ); | |
var->latched_string = NULL; | |
} | |
+ if( Q_strcmp( var->reset_string, var->string )) | |
+ { | |
+ Cvar_Set( var->name, var->reset_string ); | |
+ } | |
} | |
} | |
} | |
@@ -966,9 +927,9 @@ void Cvar_SetA_f( void ) | |
{ | |
convar_t *v; | |
- if( Cmd_Argc() < 3 ) | |
+ if( Cmd_Argc() != 3 ) | |
{ | |
- Msg( "Usage: seta <variable> <value> [<description>]\n" ); | |
+ Msg( "Usage: seta <variable> <value>\n" ); | |
return; | |
} | |
@@ -977,12 +938,6 @@ void Cvar_SetA_f( void ) | |
if( !v ) return; | |
v->flags |= CVAR_ARCHIVE; | |
- | |
- if( v->description ) | |
- Mem_Free( v->description ); | |
- | |
- // cvars without description are not saved, so add description | |
- v->description = copystring( "user archive cvar" ); | |
} | |
/* | |
@@ -1044,33 +999,20 @@ Cvar_List_f | |
void Cvar_List_f( void ) | |
{ | |
convar_t *var; | |
- const char *partial; | |
- size_t len; | |
+ char *match = NULL; | |
int i = 0, j = 0; | |
- qboolean ispattern; | |
if( Cmd_Argc() > 1 ) | |
- { | |
- partial = Cmd_Argv( 1 ); | |
- len = Q_strlen( partial ); | |
- ispattern = ( Q_strchr( partial, '*' ) || Q_strchr( partial, '?' )); | |
- } | |
- else | |
- { | |
- partial = NULL; | |
- len = 0; | |
- ispattern = false; | |
- } | |
+ match = Cmd_Argv( 1 ); | |
for( var = cvar_vars; var; var = var->next, i++ ) | |
{ | |
if( var->name[0] == '@' ) | |
continue; // never shows system cvars | |
- if( len && ( ispattern ? !matchpattern_with_separator( var->name, partial, false, "", false ) : Q_strncmp( partial, var->name, len ))) | |
+ if( match && !Q_stricmpext( match, var->name )) | |
continue; | |
- // TODO: fix ugly formatting | |
if( var->flags & CVAR_SERVERINFO ) Msg( "SV " ); | |
else Msg( " " ); | |
@@ -1107,18 +1049,7 @@ void Cvar_List_f( void ) | |
j++; | |
} | |
- if( len ) | |
- { | |
- if( ispattern ) | |
- Msg( "\n%i cvar%s matching \"%s\"\n\n", j, ( j > 1 ) ? "s" : "", partial ); | |
- else | |
- Msg( "\n%i cvar%s beginning with \"%s\"\n\n", j, ( j > 1 ) ? "s" : "", partial ); | |
- } | |
- else | |
- { | |
- Msg( "\n%i cvar%s\n", j, ( j > 1 ) ? "s" : "" ); | |
- } | |
- | |
+ Msg( "\n%i cvars\n", j ); | |
Msg( "%i total cvars\n", i ); | |
} | |
@@ -1134,10 +1065,15 @@ void Cvar_Restart_f( void ) | |
convar_t *var; | |
convar_t **prev; | |
- for( prev = &cvar_vars; ( var = *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 (cl.active, etc.) | |
+ // communication will get broken (cl.active, etc) | |
if( var->flags & ( CVAR_READ_ONLY|CVAR_GLCONFIG|CVAR_INIT|CVAR_RENDERINFO|CVAR_EXTDLL )) | |
{ | |
prev = &var->next; | |
@@ -1147,17 +1083,14 @@ void Cvar_Restart_f( void ) | |
// throw out any variables the user created | |
if( var->flags & CVAR_USER_CREATED ) | |
{ | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Remove( HM_CVAR, var, var->name ); | |
-#endif | |
- | |
*prev = var->next; | |
- Z_Free( var->name ); | |
- Z_Free( var->string ); | |
- Z_Free( var->latched_string ); | |
- Z_Free( var->reset_string ); | |
- Z_Free( var->description ); | |
+ if( var->name ) Mem_Free( var->name ); | |
+ if( var->string ) Mem_Free( var->string ); | |
+ if( var->latched_string ) Mem_Free( var->latched_string ); | |
+ if( var->reset_string ) Mem_Free( var->reset_string ); | |
+ if( var->description ) Mem_Free( var->description ); | |
Mem_Free( var ); | |
+ | |
continue; | |
} | |
@@ -1170,27 +1103,26 @@ void Cvar_Restart_f( void ) | |
============ | |
Cvar_Latched_f | |
-Now all latched strings are valid | |
+Now all latched strings is valid | |
============ | |
*/ | |
void Cvar_Latched_f( void ) | |
{ | |
convar_t *var; | |
- qboolean disable_cheats; | |
- | |
- var = Cvar_FindVar( "sv_cheats" ); | |
- | |
- ASSERT( var ); | |
- | |
- disable_cheats = !var->integer; | |
+ convar_t **prev; | |
- if( var->latched_string ) | |
- disable_cheats = !Q_atoi( var->latched_string ); | |
+ prev = &cvar_vars; | |
- for( var = cvar_vars ; var ; var = var->next ) | |
+ while( 1 ) | |
{ | |
+ var = *prev; | |
+ if( !var ) break; | |
+ | |
if( var->flags & CVAR_EXTDLL ) | |
+ { | |
+ prev = &var->next; | |
continue; | |
+ } | |
if( var->flags & CVAR_LATCH && var->latched_string ) | |
{ | |
@@ -1198,26 +1130,7 @@ void Cvar_Latched_f( void ) | |
Mem_Free( var->latched_string ); | |
var->latched_string = NULL; | |
} | |
- if( ( var->flags & CVAR_CHEAT ) && var->reset_string ) | |
- { | |
- if( disable_cheats ) | |
- { | |
- char *value = copystring( var->string ); | |
- Cvar_FullSet( var->name, var->reset_string, var->flags ); | |
- // keep values in latched field | |
- if( var->latched_string ) | |
- Mem_Free( value ); | |
- else | |
- var->latched_string = value; | |
- } | |
- else if( var->latched_string ) | |
- { | |
- Cvar_FullSet( var->name, var->latched_string, var->flags ); | |
- Mem_Free( var->latched_string ); | |
- var->latched_string = NULL; | |
- } | |
- | |
- } | |
+ prev = &var->next; | |
} | |
} | |
@@ -1225,17 +1138,26 @@ void Cvar_Latched_f( void ) | |
============ | |
Cvar_LatchedVideo_f | |
-Now all latched video strings are valid | |
+Now all latched video strings is valid | |
============ | |
*/ | |
void Cvar_LatchedVideo_f( void ) | |
{ | |
convar_t *var; | |
+ convar_t **prev; | |
- for( var = cvar_vars ; var ; var = var->next ) | |
+ prev = &cvar_vars; | |
+ | |
+ while ( 1 ) | |
{ | |
+ var = *prev; | |
+ if( !var ) break; | |
+ | |
if( var->flags & CVAR_EXTDLL ) | |
+ { | |
+ prev = &var->next; | |
continue; | |
+ } | |
if( var->flags & CVAR_LATCH_VIDEO && var->latched_string ) | |
{ | |
@@ -1243,6 +1165,7 @@ void Cvar_LatchedVideo_f( void ) | |
Mem_Free( var->latched_string ); | |
var->latched_string = NULL; | |
} | |
+ prev = &var->next; | |
} | |
} | |
@@ -1257,15 +1180,20 @@ void Cvar_Unlink_f( void ) | |
{ | |
convar_t *var; | |
convar_t **prev; | |
+ int count = 0; | |
if( Cvar_VariableInteger( "host_gameloaded" )) | |
{ | |
- MsgDev( D_NOTE, "Can't unlink cvars while game is loaded.\n" ); | |
+ MsgDev( D_NOTE, "can't unlink cvars while game is loaded\n" ); | |
return; | |
} | |
- for( prev = &cvar_vars; ( var = *prev ); ) | |
+ prev = &cvar_vars; | |
+ | |
+ while( 1 ) | |
{ | |
+ var = *prev; | |
+ if( !var ) break; | |
// ignore all non-game cvars | |
if( !( var->flags & CVAR_EXTDLL )) | |
@@ -1275,11 +1203,9 @@ void Cvar_Unlink_f( void ) | |
} | |
// throw out any variables the game created | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Remove( HM_CVAR, var, var->name ); | |
-#endif | |
*prev = var->next; | |
- Z_Free( var->string ); | |
+ if( var->string ) Mem_Free( var->string ); | |
+ count++; | |
} | |
} | |
@@ -1294,15 +1220,21 @@ void Cvar_Unlink( void ) | |
{ | |
convar_t *var; | |
convar_t **prev; | |
+ int count = 0; | |
if( Cvar_VariableInteger( "host_clientloaded" )) | |
{ | |
- MsgDev( D_NOTE, "Can't unlink cvars while client is loaded.\n" ); | |
+ MsgDev( D_NOTE, "can't unlink cvars while client is loaded\n" ); | |
return; | |
} | |
- for( prev = &cvar_vars; ( var = *prev ); ) | |
+ prev = &cvar_vars; | |
+ | |
+ while( 1 ) | |
{ | |
+ var = *prev; | |
+ if( !var ) break; | |
+ | |
// ignore all non-client cvars | |
if( !( var->flags & CVAR_CLIENTDLL )) | |
{ | |
@@ -1311,17 +1243,14 @@ void Cvar_Unlink( void ) | |
} | |
// throw out any variables the game created | |
-#if defined(XASH_HASHED_VARS) | |
- BaseCmd_Remove( HM_CVAR, var, var->name ); | |
-#endif | |
- | |
*prev = var->next; | |
- Z_Free( var->name ); | |
- Z_Free( var->string ); | |
- Z_Free( var->latched_string ); | |
- Z_Free( var->reset_string ); | |
- Z_Free( var->description ); | |
+ if( var->name ) Mem_Free( var->name ); | |
+ if( var->string ) Mem_Free( var->string ); | |
+ if( var->latched_string ) Mem_Free( var->latched_string ); | |
+ if( var->reset_string ) Mem_Free( var->reset_string ); | |
+ if( var->description ) Mem_Free( var->description ); | |
Mem_Free( var ); | |
+ count++; | |
} | |
} | |
@@ -1340,16 +1269,15 @@ void Cvar_Init( void ) | |
serverinfo = Cvar_Get( "@serverinfo", "0", CVAR_READ_ONLY, "" ); // use ->modified value only | |
renderinfo = Cvar_Get( "@renderinfo", "0", CVAR_READ_ONLY, "" ); // use ->modified value only | |
- Cmd_AddCommand ("toggle", Cvar_Toggle_f, "toggles a console variable's value (use for more info)" ); | |
+ 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 ("setinfo", Cvar_SetU_f, "create or change the value of a userinfo variable" ); | |
Cmd_AddCommand ("setp", Cvar_SetP_f, "create or change the value of a physicinfo variable" ); | |
Cmd_AddCommand ("setr", Cvar_SetR_f, "create or change the value of a renderinfo variable" ); | |
Cmd_AddCommand ("setgl", Cvar_SetGL_f, "create or change the value of a opengl variable" ); | |
Cmd_AddCommand ("seta", Cvar_SetA_f, "create or change the value of a console variable that will be saved to config.cfg" ); | |
- Cmd_AddCommand ("reset", Cvar_Reset_f, "reset any type of variable to initial value" ); | |
+ Cmd_AddCommand ("reset", Cvar_Reset_f, "reset any type variable to initial value" ); | |
Cmd_AddCommand ("latch", Cvar_Latched_f, "apply latched values" ); | |
Cmd_AddCommand ("vidlatch", Cvar_LatchedVideo_f, "apply latched values for video subsystem" ); | |
Cmd_AddCommand ("cvarlist", Cvar_List_f, "display all console variables beginning with the specified prefix" ); | |
Только в engine/common: dedicated.c | |
diff --suppress-blank-empty -prudwEZbB engine/common/filesystem.c /mnt/data/Xash3D_original/engine/common/filesystem.c | |
--- engine/common/filesystem.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/filesystem.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,24 +13,11 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#include "port.h" | |
- | |
#include <fcntl.h> | |
+#include <direct.h> | |
#include <sys/stat.h> | |
-#include <time.h> | |
-#include <stdarg.h> // va | |
-#ifdef XASH_SDL | |
-#include <SDL_system.h> // Android External storage | |
-#endif | |
-#ifdef _WIN32 | |
#include <io.h> | |
-#include <direct.h> | |
-#else | |
-#include <dirent.h> | |
-#include <errno.h> | |
-#include <unistd.h> | |
-#endif | |
- | |
+#include <time.h> | |
#include "common.h" | |
#include "wadfile.h" | |
#include "filesystem.h" | |
@@ -57,10 +44,10 @@ typedef struct stringlist_s | |
typedef struct wadtype_s | |
{ | |
char *ext; | |
- signed char type; | |
+ char type; | |
} wadtype_t; | |
-struct file_s | |
+typedef struct file_s | |
{ | |
int handle; // file descriptor | |
fs_offset_t real_length; // uncompressed file size (for files opened in "read" mode) | |
@@ -73,6 +60,43 @@ struct file_s | |
byte buff[FILE_BUFF_SIZE]; // intermediate buffer | |
}; | |
+typedef struct wfile_s | |
+{ | |
+ char filename[MAX_SYSPATH]; | |
+ int infotableofs; | |
+ byte *mempool; // W_ReadLump temp buffers | |
+ int numlumps; | |
+ int mode; | |
+ int handle; | |
+ dlumpinfo_t *lumps; | |
+ time_t filetime; | |
+}; | |
+ | |
+typedef struct packfile_s | |
+{ | |
+ char name[56]; | |
+ fs_offset_t offset; | |
+ fs_offset_t realsize; // real file size (uncompressed) | |
+} packfile_t; | |
+ | |
+typedef struct pack_s | |
+{ | |
+ char filename[MAX_SYSPATH]; | |
+ int handle; | |
+ int numfiles; | |
+ time_t filetime; // common for all packed files | |
+ packfile_t *files; | |
+} pack_t; | |
+ | |
+typedef struct searchpath_s | |
+{ | |
+ char filename[MAX_SYSPATH]; | |
+ pack_t *pack; | |
+ wfile_t *wad; | |
+ int flags; | |
+ struct searchpath_s *next; | |
+} searchpath_t; | |
+ | |
byte *fs_mempool; | |
searchpath_t *fs_searchpaths = NULL; | |
searchpath_t fs_directpath; // static direct path | |
@@ -81,17 +105,19 @@ char fs_basedir[MAX_SYSPATH]; // base d | |
char fs_falldir[MAX_SYSPATH]; // game falling directory | |
char fs_gamedir[MAX_SYSPATH]; // game current directory | |
char gs_basedir[MAX_SYSPATH]; // initial dir before loading gameinfo.txt (used for compilers too) | |
-qboolean fs_ext_path = false; // attempt to read\write from ./ or ../ paths | |
+qboolean fs_ext_path = false; // attempt to read\write from ./ or ../ pathes | |
static void FS_InitMemory( void ); | |
-static dlumpinfo_t *W_FindLump( wfile_t *wad, const char *name, const signed char matchtype ); | |
+const char *FS_FileExtension( const char *in ); | |
+static searchpath_t *FS_FindFile( const char *name, int *index, qboolean gamedironly ); | |
+static dlumpinfo_t *W_FindLump( wfile_t *wad, const char *name, const char matchtype ); | |
static packfile_t* FS_AddFileToPack( const char* name, pack_t *pack, fs_offset_t offset, fs_offset_t size ); | |
static byte *W_LoadFile( const char *path, fs_offset_t *filesizeptr, qboolean gamedironly ); | |
static qboolean FS_SysFileExists( const char *path ); | |
static qboolean FS_SysFolderExists( const char *path ); | |
-static int FS_SysFileTime( const char *filename ); | |
-static signed char W_TypeFromExt( const char *lumpname ); | |
-static const char *W_ExtFromType( signed char lumptype ); | |
+static long FS_SysFileTime( const char *filename ); | |
+static char W_TypeFromExt( const char *lumpname ); | |
+static const char *W_ExtFromType( char lumptype ); | |
/* | |
============================================================================= | |
@@ -102,43 +128,28 @@ FILEMATCH COMMON SYSTEM | |
*/ | |
int matchpattern( const char *in, const char *pattern, qboolean caseinsensitive ) | |
{ | |
- return matchpattern_with_separator( in, pattern, caseinsensitive, "/\\:", false ); | |
-} | |
- | |
-// wildcard_least_one: if true * matches 1 or more characters | |
-// if false * matches 0 or more characters | |
-int matchpattern_with_separator( const char *in, const char *pattern, qboolean caseinsensitive, const char *separators, qboolean wildcard_least_one ) | |
-{ | |
int c1, c2; | |
- ASSERT( in ); | |
- | |
while( *pattern ) | |
{ | |
switch( *pattern ) | |
{ | |
- case 0: | |
- return 1; // end of pattern | |
+ case 0: return 1; // end of pattern | |
case '?': // match any single character | |
- if( *in == 0 || Q_strchr( separators, *in )) | |
+ if( *in == 0 || *in == '/' || *in == '\\' || *in == ':' ) | |
return 0; // no match | |
in++; | |
pattern++; | |
break; | |
case '*': // match anything until following string | |
- if( wildcard_least_one ) | |
- { | |
- if( *in == 0 || Q_strchr( separators, *in )) | |
- return 0; // no match | |
- in++; | |
- } | |
+ if( !*in ) return 1; // match | |
pattern++; | |
while( *in ) | |
{ | |
- if( Q_strchr(separators, *in )) | |
+ if( *in == '/' || *in == '\\' || *in == ':' ) | |
break; | |
// see if pattern matches at this offset | |
- if( matchpattern_with_separator(in, pattern, caseinsensitive, separators, wildcard_least_one )) | |
+ if( matchpattern( in, pattern, caseinsensitive )) | |
return 1; | |
// nope, advance to next offset | |
in++; | |
@@ -155,25 +166,24 @@ int matchpattern_with_separator( const c | |
c2 = *pattern; | |
if( c2 >= 'A' && c2 <= 'Z' ) | |
c2 += 'a' - 'A'; | |
- if( c1 != c2 ) | |
- return 0; // no match | |
+ if( c1 != c2) return 0; // no match | |
} | |
in++; | |
pattern++; | |
break; | |
} | |
} | |
- if( *in ) | |
- return 0; // reached end of pattern but not end of input | |
+ | |
+ if( *in ) return 0; // reached end of pattern but not end of input | |
return 1; // success | |
} | |
-static void stringlistinit( stringlist_t *list ) | |
+void stringlistinit( stringlist_t *list ) | |
{ | |
Q_memset( list, 0, sizeof( *list )); | |
} | |
-static void stringlistfreecontents( stringlist_t *list ) | |
+void stringlistfreecontents( stringlist_t *list ) | |
{ | |
int i; | |
@@ -186,11 +196,10 @@ static void stringlistfreecontents( stri | |
list->numstrings = 0; | |
list->maxstrings = 0; | |
- Z_Free( list->strings ); | |
- list->strings = NULL; | |
+ if( list->strings ) Mem_Free( list->strings ); | |
} | |
-static void stringlistappend( stringlist_t *list, const char *text ) | |
+void stringlistappend( stringlist_t *list, char *text ) | |
{ | |
size_t textlen; | |
char **oldstrings; | |
@@ -201,7 +210,7 @@ static void stringlistappend( stringlist | |
list->maxstrings += 4096; | |
list->strings = Mem_Alloc( fs_mempool, list->maxstrings * sizeof( *list->strings )); | |
if( list->numstrings ) Q_memcpy( list->strings, oldstrings, list->numstrings * sizeof( *list->strings )); | |
- Z_Free( oldstrings ); | |
+ if( oldstrings ) Mem_Free( oldstrings ); | |
} | |
textlen = Q_strlen( text ) + 1; | |
@@ -210,7 +219,7 @@ static void stringlistappend( stringlist | |
list->numstrings++; | |
} | |
-static void stringlistsort( stringlist_t *list ) | |
+void stringlistsort( stringlist_t *list ) | |
{ | |
int i, j; | |
char *temp; | |
@@ -230,35 +239,17 @@ static void stringlistsort( stringlist_t | |
} | |
} | |
-#ifndef _WIN32 | |
-int sel(const struct dirent *d) | |
-{ | |
- int plen, extlen; | |
- char* p = strrchr(d->d_name, '.'); | |
- if ( !p ) return 0; | |
- plen = strlen(p); | |
- extlen = strlen("*"); | |
- return strncmp("*", p, (extlen < plen) ? extlen : plen) == 0; | |
-} | |
-#endif | |
- | |
- | |
-static void listdirectory( stringlist_t *list, const char *path ) | |
+void listdirectory( stringlist_t *list, const char *path ) | |
{ | |
int i; | |
- signed char pattern[4096], *c; | |
-#ifdef _WIN32 | |
+ char pattern[4096], *c; | |
struct _finddata_t n_file; | |
-#else | |
- struct dirent **n_file; | |
-#endif | |
- int hFile; | |
+ long hFile; | |
- Q_strncpy( (char *)pattern, path, sizeof( pattern )); | |
- Q_strncat( (char *)pattern, "*", sizeof( pattern )); | |
+ Q_strncpy( pattern, path, sizeof( pattern )); | |
+ Q_strncat( pattern, "*", sizeof( pattern )); | |
// ask for the directory listing handle | |
-#ifdef _WIN32 | |
hFile = _findfirst( pattern, &n_file ); | |
if( hFile == -1 ) return; | |
@@ -268,28 +259,11 @@ static void listdirectory( stringlist_t | |
while( _findnext( hFile, &n_file ) == 0 ) | |
stringlistappend( list, n_file.name ); | |
_findclose( hFile ); | |
-#else | |
- // ask for the directory listing handle | |
- hFile = scandir( path, &n_file, NULL, NULL ); | |
- if( hFile < 1 ) | |
- { | |
-#if 0 | |
- MsgDev( D_INFO, "listdirectory: scandir() failed, %s at %s", strerror(hFile), path ); | |
-#endif | |
- return; | |
- } | |
- | |
- // iterate through the directory | |
- for( i = 0; i < hFile; i++) | |
- { | |
- stringlistappend( list, n_file[i]->d_name ); | |
- } | |
-#endif | |
// convert names to lowercase because windows doesn't care, but pattern matching code often does | |
for( i = 0; i < list->numstrings; i++ ) | |
{ | |
- for( c = (signed char *)list->strings[i]; *c; c++ ) | |
+ for( c = list->strings[i]; *c; c++ ) | |
{ | |
if( *c >= 'A' && *c <= 'Z' ) | |
*c += 'a' - 'A'; | |
@@ -725,8 +699,6 @@ void FS_AddGameDirectory( const char *di | |
string fullpath; | |
int i; | |
- MsgDev(D_NOTE, "FS_AddGameDirectory( %s, %i )\n", dir, flags ); | |
- | |
if(!( flags & FS_NOWRITE_PATH )) | |
Q_strncpy( fs_gamedir, dir, sizeof( fs_gamedir )); | |
@@ -735,10 +706,9 @@ void FS_AddGameDirectory( const char *di | |
listdirectory( &list, dir ); | |
stringlistsort( &list ); | |
- // For priority files, first is unpacked, then WAD and last PAK | |
+ // add any PAK package in the directory | |
for( i = 0; i < list.numstrings; i++ ) | |
{ | |
- // add any PAK package in the directory | |
if( !Q_stricmp( FS_FileExtension( list.strings[i] ), "pak" )) | |
{ | |
Q_sprintf( fullpath, "%s%s", dir, list.strings[i] ); | |
@@ -746,9 +716,9 @@ void FS_AddGameDirectory( const char *di | |
} | |
} | |
+ // add any WAD package in the directory | |
for( i = 0; i < list.numstrings; i++ ) | |
{ | |
- // add any WAD package in the directory | |
if( !Q_stricmp( FS_FileExtension( list.strings[i] ), "wad" )) | |
{ | |
Q_sprintf( fullpath, "%s%s", dir, list.strings[i] ); | |
@@ -762,10 +732,11 @@ void FS_AddGameDirectory( const char *di | |
// (unpacked files have the priority over packed files) | |
search = (searchpath_t *)Mem_Alloc( fs_mempool, sizeof( searchpath_t )); | |
Q_strncpy( search->filename, dir, sizeof ( search->filename )); | |
- search->flags = flags; | |
search->next = fs_searchpaths; | |
+ search->flags = flags; | |
fs_searchpaths = search; | |
+ | |
} | |
/* | |
@@ -776,30 +747,7 @@ FS_AddGameHierarchy | |
void FS_AddGameHierarchy( const char *dir, int flags ) | |
{ | |
// Add the common game directory | |
- if( dir && *dir ) | |
- { | |
- // add recursively new game directories | |
- if( Q_strnicmp( dir, GI->gamedir, 64 ) ) | |
- { | |
- int i; | |
- for( i = 0; i < SI.numgames; i++ ) | |
- { | |
- ASSERT(SI.games[i]); | |
- MsgDev( D_NOTE, "%d %s %s\n", i, SI.games[i]->gamedir, SI.games[i]->basedir ); | |
- if( !Q_strnicmp( dir, SI.games[i]->gamedir, 64 ) ) | |
- { | |
- if( Q_strnicmp( SI.games[i]->gamedir, SI.games[i]->basedir, 64 ) ) | |
- FS_AddGameHierarchy( SI.games[i]->basedir, flags ); | |
- } | |
- } | |
- | |
- } | |
- | |
- | |
- FS_AddGameDirectory( va( "%s%s/downloaded/", fs_basedir, dir ), FS_NOWRITE_PATH | FS_CUSTOM_PATH ); | |
- FS_AddGameDirectory( va( "%s%s/", fs_basedir, dir ), flags ); | |
- FS_AddGameDirectory( va( "%s%s/custom/", fs_basedir, dir ), FS_NOWRITE_PATH | FS_CUSTOM_PATH ); | |
- } | |
+ if( dir && *dir ) FS_AddGameDirectory( va( "%s%s/", fs_basedir, dir ), flags ); | |
} | |
/* | |
@@ -845,7 +793,7 @@ const char *FS_FileWithoutPath( const ch | |
FS_ExtractFilePath | |
============ | |
*/ | |
-void FS_ExtractFilePath( const char* path, char* dest ) | |
+void FS_ExtractFilePath( const char* const path, char* dest ) | |
{ | |
const char *src; | |
src = path + Q_strlen( path ) - 1; | |
@@ -875,7 +823,7 @@ void FS_ClearSearchPath( void ) | |
if( search->flags & FS_STATIC_PATH ) | |
{ | |
- // skip read-only paths | |
+ // skip read-only pathes | |
if( search->next ) | |
fs_searchpaths = search->next->next; | |
else break; | |
@@ -893,7 +841,7 @@ void FS_ClearSearchPath( void ) | |
W_Close( search->wad ); | |
} | |
- Z_Free( search ); | |
+ if( search ) Mem_Free( search ); | |
} | |
} | |
@@ -954,16 +902,8 @@ FS_Rescan | |
void FS_Rescan( void ) | |
{ | |
MsgDev( D_NOTE, "FS_Rescan( %s )\n", GI->title ); | |
- FS_ClearSearchPath(); | |
-#ifdef __ANDROID__ | |
- char *str; | |
- if( str = getenv("XASH3D_EXTRAS_PAK1") ) | |
- FS_AddPack_Fullpath( str, NULL, false, FS_NOWRITE_PATH | FS_CUSTOM_PATH ); | |
- if( str = getenv("XASH3D_EXTRAS_PAK2") ) | |
- FS_AddPack_Fullpath( str, NULL, false, FS_NOWRITE_PATH | FS_CUSTOM_PATH ); | |
- //FS_AddPack_Fullpath( "/data/data/in.celest.xash3d.hl.test/files/pak.pak", NULL, false, FS_NOWRITE_PATH | FS_CUSTOM_PATH ); | |
-#endif | |
+ FS_ClearSearchPath(); | |
if( Q_stricmp( GI->basedir, GI->gamedir )) | |
FS_AddGameHierarchy( GI->basedir, 0 ); | |
@@ -972,7 +912,7 @@ void FS_Rescan( void ) | |
FS_AddGameHierarchy( GI->gamedir, FS_GAMEDIR_PATH ); | |
} | |
-static void FS_Rescan_f( void ) | |
+void FS_Rescan_f( void ) | |
{ | |
FS_Rescan(); | |
} | |
@@ -1079,20 +1019,14 @@ static qboolean FS_WriteGameInfo( const | |
FS_Printf( f, "dllpath\t\t\"%s\"\n", GameInfo->dll_path ); | |
if( Q_strlen( GameInfo->game_dll )) | |
FS_Printf( f, "gamedll\t\t\"%s\"\n", GameInfo->game_dll ); | |
- if( Q_strlen( GameInfo->game_dll_linux )) | |
- FS_Printf( f, "gamedll_linux\t\t\"%s\"\n", GameInfo->game_dll_linux ); | |
- if( Q_strlen( GameInfo->game_dll_osx )) | |
- FS_Printf( f, "gamedll_osx\t\t\"%s\"\n", GameInfo->game_dll_osx ); | |
if( Q_strlen( GameInfo->iconpath )) | |
FS_Printf( f, "icon\t\t\"%s\"\n", GameInfo->iconpath ); | |
switch( GameInfo->gamemode ) | |
{ | |
- case 1: | |
- FS_Print( f, "gamemode\t\t\"singleplayer_only\"\n" ); break; | |
- case 2: | |
- FS_Print( f, "gamemode\t\t\"multiplayer_only\"\n" ); break; | |
+ case 1: FS_Print( f, "gamemode\t\t\"singleplayer_only\"\n" ); break; | |
+ case 2: FS_Print( f, "gamemode\t\t\"multiplayer_only\"\n" ); break; | |
} | |
if( Q_strlen( GameInfo->sp_entity )) | |
@@ -1100,10 +1034,8 @@ static qboolean FS_WriteGameInfo( const | |
if( Q_strlen( GameInfo->mp_entity )) | |
FS_Printf( f, "mp_entity\t\t\"%s\"\n", GameInfo->mp_entity ); | |
-#if DEPRECATED_SECURE | |
if( GameInfo->secure ) | |
FS_Printf( f, "secure\t\t\"%i\"\n", GameInfo->secure ); | |
-#endif | |
if( GameInfo->nomodels ) | |
FS_Printf( f, "nomodels\t\t\"%i\"\n", GameInfo->nomodels ); | |
@@ -1160,15 +1092,11 @@ void FS_CreateDefaultGameInfo( const cha | |
Q_strncpy( defGI.title, "New Game", sizeof( defGI.title )); | |
Q_strncpy( defGI.gamedir, gs_basedir, sizeof( defGI.gamedir )); | |
- //Q_strncpy( defGI.basedir, SI.ModuleName, sizeof( defGI.basedir )); | |
- Q_strncpy( defGI.basedir, "valve", sizeof( defGI.basedir )); | |
+ Q_strncpy( defGI.basedir, SI.ModuleName, sizeof( defGI.basedir )); | |
Q_strncpy( defGI.sp_entity, "info_player_start", sizeof( defGI.sp_entity )); | |
Q_strncpy( defGI.mp_entity, "info_player_deathmatch", sizeof( defGI.mp_entity )); | |
Q_strncpy( defGI.dll_path, "cl_dlls", sizeof( defGI.dll_path )); | |
- Q_strncpy( defGI.dll_path, CLIENTDLL, sizeof( defGI.client_lib )); | |
Q_strncpy( defGI.game_dll, "dlls/hl.dll" , sizeof( defGI.game_dll )); | |
- Q_strncpy( defGI.game_dll_osx, "dlls/hl.dylib", sizeof(defGI.game_dll_osx)); | |
- Q_strncpy( defGI.game_dll_linux, "dlls/hl.so", sizeof(defGI.game_dll_linux)); | |
Q_strncpy( defGI.startmap, "newmap", sizeof( defGI.startmap )); | |
Q_strncpy( defGI.iconpath, "game.ico", sizeof( defGI.iconpath )); | |
@@ -1191,7 +1119,7 @@ static qboolean FS_ParseLiblistGam( cons | |
string token; | |
if( !GameInfo ) return false; | |
- afile = (char *)FS_LoadFile( filename, NULL, false ); | |
+ afile = FS_LoadFile( filename, NULL, false ); | |
if( !afile ) return false; | |
// setup default values | |
@@ -1205,16 +1133,12 @@ static qboolean FS_ParseLiblistGam( cons | |
Q_strncpy( GameInfo->title, "New Game", sizeof( GameInfo->title )); | |
Q_strncpy( GameInfo->gamedir, gamedir, sizeof( GameInfo->gamedir )); | |
- // TODO: Remove this ugly hack | |
- Q_strncpy( GameInfo->basedir, "valve", sizeof( GameInfo->basedir )); | |
+ Q_strncpy( GameInfo->basedir, SI.ModuleName, sizeof( GameInfo->basedir )); | |
Q_strncpy( GameInfo->sp_entity, "info_player_start", sizeof( GameInfo->sp_entity )); | |
Q_strncpy( GameInfo->mp_entity, "info_player_deathmatch", sizeof( GameInfo->mp_entity )); | |
+ Q_strncpy( GameInfo->game_dll, "dlls/hl.dll", sizeof( GameInfo->game_dll )); | |
Q_strncpy( GameInfo->startmap, "newmap", sizeof( GameInfo->startmap )); | |
Q_strncpy( GameInfo->dll_path, "cl_dlls", sizeof( GameInfo->dll_path )); | |
- Q_strncpy( GameInfo->client_lib, CLIENTDLL, sizeof( GameInfo->client_lib )); | |
- Q_strncpy( GameInfo->game_dll, "dlls/hl.dll", sizeof( GameInfo->game_dll )); | |
- Q_strncpy( GameInfo->game_dll_osx, "dlls/hl.dylib", sizeof( GameInfo->game_dll_osx )); | |
- Q_strncpy( GameInfo->game_dll_linux, "dlls/hl.so", sizeof( GameInfo->game_dll_linux )); | |
Q_strncpy( GameInfo->iconpath, "game.ico", sizeof( GameInfo->iconpath )); | |
VectorSet( GameInfo->client_mins[0], 0, 0, 0 ); | |
@@ -1265,14 +1189,6 @@ static qboolean FS_ParseLiblistGam( cons | |
pfile = COM_ParseFile( pfile, GameInfo->game_dll ); | |
COM_FixSlashes( GameInfo->game_dll ); | |
} | |
- else if( !Q_stricmp( token, "gamedll_linux" )) | |
- { | |
- pfile = COM_ParseFile( pfile, GameInfo->game_dll_linux ); | |
- } | |
- else if( !Q_stricmp( token, "gamedll_osx" )) | |
- { | |
- pfile = COM_ParseFile( pfile, GameInfo->game_dll_osx ); | |
- } | |
else if( !Q_stricmp( token, "icon" )) | |
{ | |
pfile = COM_ParseFile( pfile, GameInfo->iconpath ); | |
@@ -1285,15 +1201,7 @@ static qboolean FS_ParseLiblistGam( cons | |
if( !Q_stricmp( token, "singleplayer_only" )) | |
{ | |
- // TODO: Remove this ugly hack too. | |
- // This was made because Half-Life has multiplayer, | |
- // but for some reason it's marked as singleplayer_only. | |
- // Old WON version is fine. | |
- if( !Q_stricmp( GameInfo->gamedir, "valve") ) | |
- GameInfo->gamemode = 0; | |
- else | |
GameInfo->gamemode = 1; | |
- | |
Q_strncpy( GameInfo->type, "Single", sizeof( GameInfo->type )); | |
} | |
else if( !Q_stricmp( token, "multiplayer_only" )) | |
@@ -1325,8 +1233,7 @@ static qboolean FS_ParseLiblistGam( cons | |
else if( !Q_stricmp( token, "secure" )) | |
{ | |
pfile = COM_ParseFile( pfile, token ); | |
- MsgDev( D_WARN, "secure parameter in liblist.gam is deprecated.\n"); | |
- GameInfo->secure = 0; | |
+ GameInfo->secure = Q_atoi( token ); | |
} | |
else if( !Q_stricmp( token, "nomodels" )) | |
{ | |
@@ -1388,7 +1295,7 @@ static qboolean FS_ParseGameInfo( const | |
if( !GameInfo ) return false; // no dest | |
- afile = (char *)FS_LoadFile( filepath, NULL, false ); | |
+ afile = FS_LoadFile( filepath, NULL, false ); | |
if( !afile ) return false; | |
// setup default values | |
@@ -1404,18 +1311,8 @@ static qboolean FS_ParseGameInfo( const | |
Q_strncpy( GameInfo->title, "New Game", sizeof( GameInfo->title )); | |
Q_strncpy( GameInfo->sp_entity, "info_player_start", sizeof( GameInfo->sp_entity )); | |
Q_strncpy( GameInfo->mp_entity, "info_player_deathmatch", sizeof( GameInfo->mp_entity )); | |
-#if defined(__ANDROID__) | |
- Q_strncpy( GameInfo->dll_path, getenv("XASH3D_GAMELIBDIR"), sizeof( GameInfo->dll_path )); | |
- Q_strncpy( GameInfo->client_lib, CLIENTDLL, sizeof( GameInfo->client_lib )); | |
- Q_strncpy( GameInfo->game_dll, GameInfo->dll_path, sizeof( GameInfo->game_dll )); | |
- Q_strncat( GameInfo->game_dll,"/" SERVERDLL, sizeof( GameInfo->game_dll )); | |
-#else | |
Q_strncpy( GameInfo->dll_path, "cl_dlls", sizeof( GameInfo->dll_path )); | |
Q_strncpy( GameInfo->game_dll, "dlls/hl.dll", sizeof( GameInfo->game_dll )); | |
- Q_strncpy( GameInfo->game_dll_osx, "dlls/hl.dylib", sizeof( GameInfo->game_dll_osx )); | |
- Q_strncpy( GameInfo->game_dll_linux, "dlls/hl.so", sizeof( GameInfo->game_dll_linux )); | |
- Q_strncpy( GameInfo->client_lib, CLIENTDLL, sizeof( GameInfo->client_lib )); | |
-#endif | |
Q_strncpy( GameInfo->startmap, "", sizeof( GameInfo->startmap )); | |
Q_strncpy( GameInfo->iconpath, "game.ico", sizeof( GameInfo->iconpath )); | |
@@ -1466,18 +1363,6 @@ static qboolean FS_ParseGameInfo( const | |
{ | |
pfile = COM_ParseFile( pfile, GameInfo->game_dll ); | |
} | |
- else if( !Q_stricmp( token, "gamedll_osx" )) | |
- { | |
- pfile = COM_ParseFile( pfile, GameInfo->game_dll_osx ); | |
- } | |
- else if( !Q_stricmp( token, "gamedll_linux" )) | |
- { | |
- pfile = COM_ParseFile( pfile, GameInfo->game_dll_linux ); | |
- } | |
- else if( !Q_stricmp( token, "clientlib" )) | |
- { | |
- pfile = COM_ParseFile( pfile, GameInfo->client_lib ); | |
- } | |
else if( !Q_stricmp( token, "dllpath" )) | |
{ | |
pfile = COM_ParseFile( pfile, GameInfo->dll_path ); | |
@@ -1546,11 +1431,7 @@ static qboolean FS_ParseGameInfo( const | |
else if( !Q_stricmp( token, "gamemode" )) | |
{ | |
pfile = COM_ParseFile( pfile, token ); | |
- // TODO: Remove this ugly hack too. | |
- // This was made because Half-Life has multiplayer, | |
- // but for some reason it's marked as singleplayer_only. | |
- // Old WON version is fine. | |
- if( !Q_stricmp( token, "singleplayer_only" ) && Q_stricmp( GameInfo->gamedir, "valve") ) | |
+ if( !Q_stricmp( token, "singleplayer_only" )) | |
GameInfo->gamemode = 1; | |
else if( !Q_stricmp( token, "multiplayer_only" )) | |
GameInfo->gamemode = 2; | |
@@ -1558,8 +1439,7 @@ static qboolean FS_ParseGameInfo( const | |
else if( !Q_stricmp( token, "secure" )) | |
{ | |
pfile = COM_ParseFile( pfile, token ); | |
- MsgDev( D_WARN, "secure parameter in gameinfo.txt is deprecated.\n"); | |
- GameInfo->secure = 0; | |
+ GameInfo->secure = Q_atoi( token ); | |
} | |
else if( !Q_stricmp( token, "nomodels" )) | |
{ | |
@@ -1607,7 +1487,8 @@ static qboolean FS_ParseGameInfo( const | |
if( !FS_SysFolderExists( va( "%s\\%s", host.rootdir, GameInfo->falldir ))) | |
GameInfo->falldir[0] = '\0'; | |
- Z_Free( afile ); | |
+ if( afile != NULL ) | |
+ Mem_Free( afile ); | |
return true; | |
} | |
@@ -1629,7 +1510,7 @@ void FS_LoadGameInfo( const char *rootfo | |
if( rootfolder ) Q_strcpy( gs_basedir, rootfolder ); | |
MsgDev( D_NOTE, "FS_LoadGameInfo( %s )\n", gs_basedir ); | |
- // clear any old paths | |
+ // clear any old pathes | |
FS_ClearSearchPath(); | |
// validate gamedir | |
@@ -1643,28 +1524,6 @@ void FS_LoadGameInfo( const char *rootfo | |
Sys_Error( "Couldn't find game directory '%s'\n", gs_basedir ); | |
SI.GameInfo = SI.games[i]; | |
- if( !Sys_GetParmFromCmdLine( "-dll", SI.gamedll ) ) | |
- { | |
-#if defined(_WIN32) | |
- Q_strncpy( SI.gamedll, GI->game_dll, sizeof( SI.gamedll ) ); | |
-#elif defined(__APPLE__) | |
- Q_strncpy( SI.gamedll, GI->game_dll_osx, sizeof( SI.gamedll ) ); | |
-#elif defined(__ANDROID__) | |
- Q_strncpy( SI.gamedll, getenv("XASH3D_GAMELIBDIR"), sizeof( SI.gamedll ) ); | |
- Q_strncat( SI.gamedll, "/" SERVERDLL, sizeof( SI.gamedll ) ); | |
-#else | |
- Q_strncpy( SI.gamedll, GI->game_dll_linux, sizeof( SI.gamedll ) ); | |
-#endif | |
- } | |
- if( !Sys_GetParmFromCmdLine( "-clientlib", SI.clientlib ) ) | |
- { | |
-#ifdef __ANDROID__ | |
- Q_strncpy( SI.clientlib, CLIENTDLL, sizeof( SI.clientlib ) ); | |
-#else | |
- Q_strncpy( SI.clientlib, GI->client_lib, sizeof( SI.clientlib ) ); | |
-#endif | |
- } | |
- | |
FS_Rescan(); // create new filesystem | |
Host_InitDecals (); // reload decals | |
@@ -1683,12 +1542,12 @@ void FS_Init( void ) | |
FS_InitMemory(); | |
- Cmd_AddCommand( "fs_rescan", FS_Rescan_f, "rescan filesystem search paths" ); | |
- Cmd_AddCommand( "fs_path", FS_Path_f, "show filesystem search paths" ); | |
- Cmd_AddCommand( "fs_clearpaths", FS_ClearPaths_f, "clear filesystem search paths" ); | |
+ Cmd_AddCommand( "fs_rescan", FS_Rescan_f, "rescan filesystem search pathes" ); | |
+ Cmd_AddCommand( "fs_path", FS_Path_f, "show filesystem search pathes" ); | |
+ Cmd_AddCommand( "fs_clearpaths", FS_ClearPaths_f, "clear filesystem search pathes" ); | |
// ignore commandlineoption "-game" for other stuff | |
- if( host.type != HOST_UNKNOWN ) | |
+ if( host.type == HOST_NORMAL || host.type == HOST_DEDICATED ) | |
{ | |
stringlistinit( &dirs ); | |
listdirectory( &dirs, "./" ); | |
@@ -1772,7 +1631,7 @@ FS_SysFileTime | |
Internal function used to determine filetime | |
==================== | |
*/ | |
-static int FS_SysFileTime( const char *filename ) | |
+static long FS_SysFileTime( const char *filename ) | |
{ | |
struct stat buf; | |
@@ -1784,29 +1643,6 @@ static int FS_SysFileTime( const char *f | |
/* | |
==================== | |
-FS_ToLowerCase | |
- | |
-Function to set all characters of path lowercase | |
-==================== | |
-*/ | |
-char* FS_ToLowerCase( const char* path ) | |
-{ | |
- if (path) { | |
- char *result = malloc(strlen(path) + 1); | |
- int i = 0; | |
- while( path[i] ) | |
- { | |
- result[i] = tolower( path[i] ); | |
- ++i; | |
- } | |
- result[i] = '\0'; | |
- return result; | |
- } | |
- return NULL; | |
-} | |
- | |
-/* | |
-==================== | |
FS_SysOpen | |
Internal function used to create a file_t and open the relevant non-packed file on disk | |
@@ -1849,7 +1685,7 @@ static file_t* FS_SysOpen( const char* f | |
opt |= O_BINARY; | |
break; | |
default: | |
- MsgDev( D_ERROR, "FS_SysOpen: %s: unknown char in mode %s (%c)\n", filepath, mode, mode[ind] ); | |
+ MsgDev( D_ERROR, "FS_SysOpen: %s: unknown char in mode (%c)\n", filepath, mode, mode[ind] ); | |
break; | |
} | |
} | |
@@ -1866,11 +1702,6 @@ static file_t* FS_SysOpen( const char* f | |
} | |
file->real_length = lseek( file->handle, 0, SEEK_END ); | |
- if( file->real_length == -1 ) | |
- { | |
- MsgDev( D_ERROR, "FS_SysOpen: Cannot lseek file: %s\n", strerror(errno)); | |
- return NULL; | |
- } | |
// For files opened in append mode, we start at the end of the file | |
if( mod & O_APPEND ) file->position = file->real_length; | |
@@ -1941,28 +1772,9 @@ Look for a existing folder | |
*/ | |
qboolean FS_SysFolderExists( const char *path ) | |
{ | |
-#ifdef _WIN32 | |
DWORD dwFlags = GetFileAttributes( path ); | |
return ( dwFlags != -1 ) && ( dwFlags & FILE_ATTRIBUTE_DIRECTORY ); | |
-#else | |
- DIR *dir = opendir(path); | |
- | |
- if(dir) | |
- { | |
- closedir(dir); | |
- return 1; | |
- } | |
- else if((errno == ENOENT) || (errno == ENOTDIR)) | |
- { | |
- return 0; | |
- } | |
- else | |
- { | |
- MsgDev(D_ERROR, "FS_SysFolderExists: problem while opening dir: %s", strerror(errno)); | |
- return 0; | |
- } | |
-#endif | |
} | |
/* | |
@@ -1975,7 +1787,7 @@ Return the searchpath where the file was | |
and the file index in the package if relevant | |
==================== | |
*/ | |
-searchpath_t *FS_FindFile( const char *name, int* index, qboolean gamedironly ) | |
+static searchpath_t *FS_FindFile( const char *name, int* index, qboolean gamedironly ) | |
{ | |
searchpath_t *search; | |
char *pEnvPath; | |
@@ -1984,7 +1796,7 @@ searchpath_t *FS_FindFile( const char *n | |
// search through the path, one element at a time | |
for( search = fs_searchpaths; search; search = search->next ) | |
{ | |
- if( gamedironly && !( search->flags & ( FS_GAMEDIR_PATH | FS_CUSTOM_PATH ))) | |
+ if( gamedironly & !( search->flags & FS_GAMEDIR_PATH )) | |
continue; | |
// is the element a pak file? | |
@@ -2020,7 +1832,7 @@ searchpath_t *FS_FindFile( const char *n | |
else if( search->wad ) | |
{ | |
dlumpinfo_t *lump; | |
- signed char type = W_TypeFromExt( name ); | |
+ char type = W_TypeFromExt( name ); | |
qboolean anywadname = true; | |
string wadname, wadfolder; | |
string shortname; | |
@@ -2164,9 +1976,7 @@ Open a file. The syntax is the same as f | |
*/ | |
file_t *FS_Open( const char *filepath, const char *mode, qboolean gamedironly ) | |
{ | |
- if( !filepath ) | |
- return NULL; | |
- if( host.type != HOST_UNKNOWN ) | |
+ if( host.type == HOST_NORMAL || host.type == HOST_DEDICATED ) | |
{ | |
// some stupid mappers used leading '/' or '\' in path to models or sounds | |
if( filepath[0] == '/' || filepath[0] == '\\' ) filepath++; | |
@@ -2419,6 +2228,37 @@ int FS_UnGetc( file_t *file, byte c ) | |
/* | |
==================== | |
+FS_Gets | |
+ | |
+Same as fgets | |
+==================== | |
+*/ | |
+int FS_Gets( file_t *file, byte *string, size_t bufsize ) | |
+{ | |
+ int c, end = 0; | |
+ | |
+ while( 1 ) | |
+ { | |
+ c = FS_Getc( file ); | |
+ if( c == '\r' || c == '\n' || c < 0 ) | |
+ break; | |
+ if( end < bufsize - 1 ) | |
+ string[end++] = c; | |
+ } | |
+ string[end] = 0; | |
+ | |
+ // remove \n following \r | |
+ if( c == '\r' ) | |
+ { | |
+ c = FS_Getc( file ); | |
+ if( c != '\n' ) FS_UnGetc( file, (byte)c ); | |
+ } | |
+ | |
+ return c; | |
+} | |
+ | |
+/* | |
+==================== | |
FS_Seek | |
Move the position index in a file | |
@@ -2441,7 +2281,7 @@ int FS_Seek( file_t *file, fs_offset_t o | |
return -1; | |
} | |
- if( offset < 0 || offset > (int)file->real_length ) | |
+ if( offset < 0 || offset > (long)file->real_length ) | |
return -1; | |
// if we have the data in our read buffer, we don't need to actually seek | |
@@ -2517,30 +2357,18 @@ byte *FS_LoadFile( const char *path, fs_ | |
file = FS_Open( path, "rb", gamedironly ); | |
- if( !file ) | |
- { | |
- // Try to open this file with lowered path | |
- char *loweredPath = FS_ToLowerCase( path ); | |
- file = FS_Open( loweredPath, "rb", gamedironly ); | |
- free(loweredPath); | |
- if( !file ) | |
+ if( file ) | |
{ | |
- // Now it truly doesn't exist in file system | |
- buf = W_LoadFile( path, &filesize, gamedironly ); | |
- | |
- if( filesizeptr ) | |
- *filesizeptr = filesize; | |
- | |
- return buf; | |
- } | |
- } | |
- | |
- // Try to load | |
filesize = file->real_length; | |
buf = (byte *)Mem_Alloc( fs_mempool, filesize + 1 ); | |
buf[filesize] = '\0'; | |
FS_Read( file, buf, filesize ); | |
FS_Close( file ); | |
+ } | |
+ else | |
+ { | |
+ buf = W_LoadFile( path, &filesize, gamedironly ); | |
+ } | |
if( filesizeptr ) | |
*filesizeptr = filesize; | |
@@ -2559,13 +2387,6 @@ file_t *FS_OpenFile( const char *path, f | |
{ | |
file_t *file = FS_Open( path, "rb", gamedironly ); | |
- if( !file ) | |
- { | |
- char *loweredPath = FS_ToLowerCase( path ); | |
- file = FS_Open( loweredPath, "rb", gamedironly ); | |
- free(loweredPath); | |
- } | |
- | |
if( filesizeptr ) | |
{ | |
if( file ) *filesizeptr = file->real_length; | |
@@ -2697,7 +2518,7 @@ return true if library is crypted | |
qboolean FS_CheckForCrypt( const char *dllname ) | |
{ | |
file_t *f; | |
- int key = 0; | |
+ int key; | |
f = FS_Open( dllname, "rb", false ); | |
if( !f ) return false; | |
@@ -2956,7 +2777,8 @@ search_t *FS_Search( const char *pattern | |
slash = Q_strrchr( pattern, '/' ); | |
backslash = Q_strrchr( pattern, '\\' ); | |
colon = Q_strrchr( pattern, ':' ); | |
- separator = max(max( slash, backslash ), colon); | |
+ separator = max( slash, backslash ); | |
+ separator = max( separator, colon ); | |
basepathlength = separator ? (separator + 1 - pattern) : 0; | |
basepath = Mem_Alloc( fs_mempool, basepathlength + 1 ); | |
if( basepathlength ) Q_memcpy( basepath, pattern, basepathlength ); | |
@@ -2965,7 +2787,7 @@ search_t *FS_Search( const char *pattern | |
// search through the path, one element at a time | |
for( searchpath = fs_searchpaths; searchpath; searchpath = searchpath->next ) | |
{ | |
- if( gamedironly && !( searchpath->flags & (FS_GAMEDIR_PATH | FS_CUSTOM_PATH ))) | |
+ if( gamedironly && !( searchpath->flags & FS_GAMEDIR_PATH )) | |
continue; | |
// is the element a pak file? | |
@@ -3010,7 +2832,7 @@ search_t *FS_Search( const char *pattern | |
else if( searchpath->wad ) | |
{ | |
string wadpattern, wadname, temp2; | |
- signed char type = W_TypeFromExt( pattern ); | |
+ char type = W_TypeFromExt( pattern ); | |
qboolean anywadname = true; | |
string wadfolder; | |
@@ -3020,7 +2842,7 @@ search_t *FS_Search( const char *pattern | |
FS_FileBase( pattern, wadpattern ); | |
wadfolder[0] = '\0'; | |
- if( wadname[0] ) | |
+ if( Q_strlen( wadname )) | |
{ | |
FS_FileBase( wadname, wadname ); | |
Q_strncpy( wadfolder, wadname, sizeof( wadfolder )); | |
@@ -3184,7 +3006,7 @@ static const wadtype_t wad_hints[10] = | |
{ NULL, 0 } // terminator | |
}; | |
-static signed char W_TypeFromExt( const char *lumpname ) | |
+static char W_TypeFromExt( const char *lumpname ) | |
{ | |
const char *ext = FS_FileExtension( lumpname ); | |
const wadtype_t *type; | |
@@ -3208,7 +3030,7 @@ W_ExtFromType | |
Convert type to extension | |
=========== | |
*/ | |
-static const char *W_ExtFromType( signed char lumptype ) | |
+static const char *W_ExtFromType( char lumptype ) | |
{ | |
const wadtype_t *type; | |
@@ -3231,7 +3053,7 @@ W_HintFromSuf | |
Convert name suffix into image type | |
=========== | |
*/ | |
-signed char W_HintFromSuf( const char *lumpname ) | |
+char W_HintFromSuf( const char *lumpname ) | |
{ | |
char barename[64]; | |
char suffix[8]; | |
@@ -3252,9 +3074,9 @@ signed char W_HintFromSuf( const char *l | |
return IMG_DIFFUSE; | |
} | |
-static dlumpinfo_t *W_FindLump( wfile_t *wad, const char *name, const signed char matchtype ) | |
+static dlumpinfo_t *W_FindLump( wfile_t *wad, const char *name, const char matchtype ) | |
{ | |
- signed char img_type = IMG_DIFFUSE; | |
+ char img_type = IMG_DIFFUSE; | |
char barename[64], suffix[8]; | |
int left, right; | |
const wadtype_t *hint; | |
@@ -3264,9 +3086,6 @@ static dlumpinfo_t *W_FindLump( wfile_t | |
// trying to extract hint from the name | |
FS_FileBase( name, barename ); | |
- | |
- if( Q_strlen( barename ) >= HINT_NAMELEN ) | |
- { | |
Q_strncpy( suffix, barename + Q_strlen( barename ) - HINT_NAMELEN, sizeof( suffix )); | |
// we not known about filetype, so match only by filename | |
@@ -3281,7 +3100,6 @@ static dlumpinfo_t *W_FindLump( wfile_t | |
if( img_type != IMG_DIFFUSE ) | |
barename[Q_strlen( barename ) - HINT_NAMELEN] = '\0'; // kill the suffix | |
- } | |
// look for the file (binary search) | |
left = 0; | |
@@ -3416,7 +3234,7 @@ static qboolean W_ReadLumpTable( wfile_t | |
return true; | |
} | |
-byte *W_ReadLump( wfile_t *wad, dlumpinfo_t *lump, fs_offset_t *lumpsizeptr ) | |
+byte *W_ReadLump( wfile_t *wad, dlumpinfo_t *lump, size_t *lumpsizeptr ) | |
{ | |
byte *buf; | |
size_t size = 0; | |
@@ -3521,7 +3339,7 @@ wfile_t *W_Open( const char *filename, c | |
wad->numlumps = header.numlumps; | |
if( wad->numlumps >= MAX_FILES_IN_WAD && wad->mode == O_APPEND ) | |
{ | |
- MsgDev( D_WARN, "W_Open: %s is full (%i lumps)\n", filename, wad->numlumps ); | |
+ MsgDev( D_WARN, "W_Open: %s is full (%i lumps)\n", wad->numlumps ); | |
wad->mode = O_RDONLY; // set read-only mode | |
} | |
wad->infotableofs = header.infotableofs; // save infotableofs position | |
diff --suppress-blank-empty -prudwEZbB engine/common/filesystem.h /mnt/data/Xash3D_original/engine/common/filesystem.h | |
--- engine/common/filesystem.h 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/filesystem.h 2016-08-19 14:21:49.000000000 +0000 | |
@@ -83,52 +83,13 @@ typedef struct | |
int filepos; // file offset in WAD | |
int disksize; // compressed or uncompressed | |
int size; // uncompressed | |
- signed char type; | |
- signed char attribs; // file attribs | |
- signed char img_type; // IMG_* | |
- signed char pad; | |
+ char type; // TYP_* | |
+ char attribs; // file attribs | |
+ char img_type; // IMG_* | |
+ char pad; | |
char name[WAD3_NAMELEN]; // must be null terminated | |
} dlumpinfo_t; | |
- | |
-struct wfile_s | |
-{ | |
- char filename[MAX_SYSPATH]; | |
- int infotableofs; | |
- byte *mempool; // W_ReadLump temp buffers | |
- int numlumps; | |
- int mode; | |
- int handle; | |
- dlumpinfo_t *lumps; | |
- time_t filetime; | |
-}; | |
- | |
-typedef struct packfile_s | |
-{ | |
- char name[56]; | |
- fs_offset_t offset; | |
- fs_offset_t realsize; // real file size (uncompressed) | |
-} packfile_t; | |
- | |
-typedef struct pack_s | |
-{ | |
- char filename[MAX_SYSPATH]; | |
- int handle; | |
- int numfiles; | |
- time_t filetime; // common for all packed files | |
- packfile_t *files; | |
-} pack_t; | |
- | |
-struct searchpath_s | |
-{ | |
- char filename[MAX_SYSPATH]; | |
- pack_t *pack; | |
- wfile_t *wad; | |
- int flags; | |
- struct searchpath_s *next; | |
-}; | |
- | |
- | |
#include "custom.h" | |
#define IDCUSTOMHEADER (('K'<<24)+('A'<<16)+('P'<<8)+'H') // little-endian "HPAK" | |
diff --suppress-blank-empty -prudwEZbB engine/common/gamma.c /mnt/data/Xash3D_original/engine/common/gamma.c | |
--- engine/common/gamma.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/gamma.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -12,7 +12,7 @@ but WITHOUT ANY WARRANTY; without even t | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
+ | |
#include "common.h" | |
#include <mathlib.h> | |
#include "gl_local.h" | |
@@ -29,8 +29,8 @@ void BuildGammaTable( float gamma, float | |
float g1, g = gamma; | |
double f; | |
- g = bound( 1.8f, g, 30.0f ); | |
- texGamma = bound( 1.0f, texGamma, 15.0f ); // In settings only 1.8-7.0, but give user more values with cvar | |
+ g = bound( 1.8f, g, 3.0f ); | |
+ texGamma = bound( 1.8f, texGamma, 3.0f ); | |
g = 1.0f / g; | |
g1 = texGamma * g; | |
@@ -54,7 +54,7 @@ byte TextureToTexGamma( byte b ) | |
if( glConfig.deviceSupportsGamma ) | |
return b; // passthrough | |
- //b = bound( 0, b, 255 ); | |
+ b = bound( 0, b, 255 ); | |
return texgammatable[b]; | |
} | |
@@ -63,7 +63,6 @@ byte TextureToGamma( byte b ) | |
if( glConfig.deviceSupportsGamma ) | |
return b; // passthrough | |
- //b = bound( 0, b, 255 ); | |
+ b = bound( 0, b, 255 ); | |
return gammatable[b]; | |
} | |
-#endif | |
diff --suppress-blank-empty -prudwEZbB engine/common/host.c /mnt/data/Xash3D_original/engine/common/host.c | |
--- engine/common/host.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/host.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,31 +13,19 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#include "port.h" | |
- | |
-#if defined(XASH_SDL) | |
-#include <SDL.h> | |
-#endif | |
- | |
-#include <stdarg.h> // va_args | |
-#include <errno.h> // errno | |
- | |
#include "common.h" | |
#include "netchan.h" | |
-#include "server.h" | |
#include "protocol.h" | |
#include "mod_local.h" | |
#include "mathlib.h" | |
#include "input.h" | |
-#include "touch.h" | |
-#include "engine_features.h" | |
+#include "features.h" | |
#include "render_api.h" // decallist_t | |
-#include "sdl/events.h" | |
-#include "library.h" | |
typedef void (*pfnChangeGame)( const char *progname ); | |
pfnChangeGame pChangeGame = NULL; | |
+HINSTANCE hCurrent; // hinstance of current .dll | |
host_parm_t host; // host parms | |
sysinfo_t SI; | |
@@ -48,23 +36,18 @@ convar_t *host_limitlocal; | |
convar_t *host_cheats; | |
convar_t *host_maxfps; | |
convar_t *host_framerate; | |
-convar_t *host_sleeptime; | |
-convar_t *host_xashds_hacks; | |
convar_t *con_gamemaps; | |
-convar_t *download_types; | |
convar_t *build, *ver; | |
-convar_t *host_mapdesign_fatal; | |
-convar_t *cmd_scripting = NULL; | |
static int num_decals; | |
// these cvars will be duplicated on each client across network | |
int Host_ServerState( void ) | |
{ | |
- return host_serverstate->integer; | |
+ return Cvar_VariableInteger( "host_serverstate" ); | |
} | |
-int Host_CompareFileTime( int ft1, int ft2 ) | |
+int Host_CompareFileTime( long ft1, long ft2 ) | |
{ | |
if( ft1 < ft2 ) | |
{ | |
@@ -81,10 +64,6 @@ void Host_ShutdownServer( void ) | |
{ | |
if( !SV_Active()) return; | |
Q_strncpy( host.finalmsg, "Server was killed", MAX_STRING ); | |
- | |
- Log_Printf( "Server shutdown\n" ); | |
- Log_Close(); | |
- | |
SV_Shutdown( false ); | |
} | |
@@ -96,13 +75,13 @@ Host_PrintEngineFeatures | |
void Host_PrintEngineFeatures( void ) | |
{ | |
if( host.features & ENGINE_WRITE_LARGE_COORD ) | |
- MsgDev( D_AICONSOLE, "^3EXT:^7 Big world support enabled\n" ); | |
+ MsgDev( D_AICONSOLE, "^3EXT:^7 big world support enabled\n" ); | |
if( host.features & ENGINE_BUILD_SURFMESHES ) | |
- MsgDev( D_AICONSOLE, "^3EXT:^7 Surfmeshes enabled\n" ); | |
+ MsgDev( D_AICONSOLE, "^3EXT:^7 surfmeshes enabled\n" ); | |
if( host.features & ENGINE_LOAD_DELUXEDATA ) | |
- MsgDev( D_AICONSOLE, "^3EXT:^7 Deluxemap support enabled\n" ); | |
+ MsgDev( D_AICONSOLE, "^3EXT:^7 deluxemap support enabled\n" ); | |
if( host.features & ENGINE_TRANSFORM_TRACE_AABB ) | |
MsgDev( D_AICONSOLE, "^3EXT:^7 Transform trace AABB enabled\n" ); | |
@@ -111,7 +90,7 @@ void Host_PrintEngineFeatures( void ) | |
MsgDev( D_AICONSOLE, "^3EXT:^7 Large lightmaps enabled\n" ); | |
if( host.features & ENGINE_COMPENSATE_QUAKE_BUG ) | |
- MsgDev( D_AICONSOLE, "^3EXT:^7 Quake bug compensation enabled\n" ); | |
+ MsgDev( D_AICONSOLE, "^3EXT:^7 Compensate quake bug enabled\n" ); | |
} | |
/* | |
@@ -148,10 +127,9 @@ void Host_EndGame( const char *message, | |
{ | |
Q_snprintf( host.finalmsg, sizeof( host.finalmsg ), "Host_EndGame: %s", string ); | |
SV_Shutdown( false ); | |
- return; | |
} | |
- if( Host_IsDedicated() ) | |
+ if( host.type == HOST_DEDICATED ) | |
Sys_Break( "Host_EndGame: %s\n", string ); // dedicated servers exit | |
SV_Shutdown( false ); | |
@@ -173,20 +151,9 @@ Host_AbortCurrentFrame | |
aborts the current host frame and goes on with the next one | |
================ | |
*/ | |
- | |
-#ifdef __GNUC__ | |
-void EXPORT Host_AbortCurrentFrame( void ) __attribute__ ((noreturn)) __attribute__ ((noinline)) ; | |
-#endif | |
-#ifdef _MSC_VER | |
-__declspec(noreturn) void EXPORT Host_AbortCurrentFrame( void ); | |
-#endif | |
-void EXPORT Host_AbortCurrentFrame( void ) | |
+void Host_AbortCurrentFrame( void ) | |
{ | |
- if( host.framecount == 0 ) // abort frame was not set up | |
- Sys_Break("Could not abort current frame"); | |
- else | |
longjmp( host.abortframe, 1 ); | |
- exit(127); | |
} | |
/* | |
@@ -257,7 +224,8 @@ Host_Exec_f | |
void Host_Exec_f( void ) | |
{ | |
string cfgpath; | |
- char *f; | |
+ char *f, *txt; | |
+ size_t len; | |
if( Cmd_Argc() != 2 ) | |
{ | |
@@ -275,20 +243,22 @@ void Host_Exec_f( void ) | |
Q_strncpy( cfgpath, Cmd_Argv( 1 ), sizeof( cfgpath )); | |
FS_DefaultExtension( cfgpath, ".cfg" ); // append as default | |
- f = (char *)FS_LoadFile( cfgpath, NULL, false ); | |
+ f = FS_LoadFile( cfgpath, &len, false ); | |
if( !f ) | |
{ | |
MsgDev( D_NOTE, "couldn't exec %s\n", Cmd_Argv( 1 )); | |
return; | |
} | |
- MsgDev( D_INFO, "execing %s\n", Cmd_Argv( 1 )); | |
- | |
- // terminate the string with newline just in case it's missing | |
- // insertion order is backwards from execution order | |
- Cbuf_InsertText( "\n" ); | |
- Cbuf_InsertText( f ); | |
+ // adds \n\0 at end of the file | |
+ txt = Z_Malloc( len + 2 ); | |
+ Q_memcpy( txt, f, len ); | |
+ Q_strncat( txt, "\n", len + 2 ); | |
Mem_Free( f ); | |
+ | |
+ MsgDev( D_INFO, "execing %s\n", Cmd_Argv( 1 )); | |
+ Cbuf_InsertText( txt ); | |
+ Mem_Free( txt ); | |
} | |
/* | |
@@ -316,15 +286,11 @@ void Host_MemStats_f( void ) | |
void Host_Minimize_f( void ) | |
{ | |
-#ifdef XASH_SDL | |
- if( host.hWnd ) SDL_MinimizeWindow( host.hWnd ); | |
-#endif | |
+ if( host.hWnd ) ShowWindow( host.hWnd, SW_MINIMIZE ); | |
} | |
qboolean Host_IsLocalGame( void ) | |
{ | |
- if( Host_IsDedicated() ) | |
- return false; | |
if( CL_Active() && SV_Active() && CL_GetMaxClients() == 1 ) | |
return true; | |
return false; | |
@@ -332,7 +298,7 @@ qboolean Host_IsLocalGame( void ) | |
qboolean Host_IsLocalClient( void ) | |
{ | |
- // only the local client has the active server | |
+ // only the local client have the active server | |
if( CL_Active() && SV_Active()) | |
return true; | |
return false; | |
@@ -355,7 +321,7 @@ qboolean Host_RegisterDecal( const char | |
for( i = 1; i < MAX_DECALS && host.draw_decals[i][0]; i++ ) | |
{ | |
- if( !Q_stricmp( (char *)host.draw_decals[i], shortname )) | |
+ if( !Q_stricmp( host.draw_decals[i], shortname )) | |
return true; | |
} | |
@@ -366,7 +332,7 @@ qboolean Host_RegisterDecal( const char | |
} | |
// register new decal | |
- Q_strncpy( (char *)host.draw_decals[i], shortname, sizeof( host.draw_decals[i] )); | |
+ Q_strncpy( host.draw_decals[i], shortname, sizeof( host.draw_decals[i] )); | |
num_decals++; | |
return true; | |
@@ -479,7 +445,7 @@ void Host_RestartDecals( void ) | |
decalIndex = pfnDecalIndex( entry->name ); | |
- // BSP and studio decals have different messages | |
+ // BSP and studio decals has different messages | |
if( entry->flags & FDECAL_STUDIO ) | |
{ | |
// NOTE: studio decal trace start saved into impactPlaneNormal | |
@@ -508,10 +474,10 @@ void Host_GetConsoleCommands( void ) | |
{ | |
char *cmd; | |
- while( ( cmd = Con_Input() ) ) | |
+ if( host.type == HOST_DEDICATED ) | |
{ | |
- Cbuf_AddText( cmd ); | |
- Cbuf_Execute(); | |
+ cmd = Con_Input(); | |
+ if( cmd ) Cbuf_AddText( cmd ); | |
} | |
} | |
@@ -536,7 +502,7 @@ qboolean Host_FilterTime( float time ) | |
{ | |
float minframetime; | |
- // limit fps to within tolerable range | |
+ // limit fps to withing tolerable range | |
fps = bound( MIN_FPS, fps, MAX_FPS ); | |
minframetime = 1.0f / fps; | |
@@ -544,7 +510,6 @@ qboolean Host_FilterTime( float time ) | |
if(( host.realtime - oldtime ) < minframetime ) | |
{ | |
// framerate is too high | |
- //Sys_Sleep( 2000 * ( minframetime - ( host.realtime - oldtime ) ) ); | |
return false; | |
} | |
} | |
@@ -555,7 +520,7 @@ qboolean Host_FilterTime( float time ) | |
if( host_framerate->value > 0 && ( Host_IsLocalGame())) | |
{ | |
- fps = host_framerate->value; | |
+ float fps = host_framerate->value; | |
if( fps > 1 ) fps = 1.0f / fps; | |
host.frametime = fps; | |
} | |
@@ -569,41 +534,6 @@ qboolean Host_FilterTime( float time ) | |
/* | |
================= | |
-Host_Autosleep | |
-================= | |
-*/ | |
-void Host_Autosleep( void ) | |
-{ | |
- int sleeptime = host_sleeptime->value; | |
- | |
- if( Host_IsDedicated() ) | |
- { | |
- // let the dedicated server some sleep | |
- Sys_Sleep( sleeptime ); | |
- | |
- } | |
- else | |
- { | |
- if( host.state == HOST_NOFOCUS ) | |
- { | |
- if( Host_ServerState() && CL_IsInGame( )) | |
- Sys_Sleep( sleeptime ); // listenserver | |
- else Sys_Sleep( 20 ); // sleep 20 ms otherwise | |
- } | |
- else if( host.state == HOST_SLEEP ) | |
- { | |
- // completely sleep in minimized state | |
- Sys_Sleep( 20 ); | |
- } | |
- else | |
- { | |
- Sys_Sleep( sleeptime ); | |
- } | |
- } | |
-} | |
- | |
-/* | |
-================= | |
Host_Frame | |
================= | |
*/ | |
@@ -612,26 +542,17 @@ void Host_Frame( float time ) | |
if( setjmp( host.abortframe )) | |
return; | |
- Host_Autosleep(); | |
+ Host_InputFrame (); // input frame | |
// decide the simulation time | |
if( !Host_FilterTime( time )) | |
return; | |
- rand (); // keep the random time dependent | |
- | |
- Sys_SendKeyEvents (); // call WndProc on WIN32 | |
- | |
- Host_InputFrame (); // input frame | |
- | |
Host_GetConsoleCommands (); | |
Host_ServerFrame (); // server frame | |
- if ( !Host_IsDedicated() ) | |
Host_ClientFrame (); // client frame | |
- HTTP_Run(); | |
- | |
host.framecount++; | |
} | |
@@ -677,9 +598,7 @@ void Host_Error( const char *error, ... | |
if( host.mouse_visible && !CL_IsInMenu( )) | |
{ | |
// hide VGUI mouse | |
-#ifdef XASH_SDL | |
- SDL_ShowCursor( false ); | |
-#endif | |
+ while( ShowCursor( false ) >= 0 ); | |
host.mouse_visible = false; | |
} | |
@@ -704,7 +623,7 @@ void Host_Error( const char *error, ... | |
{ | |
UI_SetActiveMenu( false ); | |
Key_SetKeyDest( key_console ); | |
- Msg( "^1Host_Error: ^7%s", hosterror1 ); | |
+ Msg( "Host_Error: %s", hosterror1 ); | |
} | |
else MSGBOX2( hosterror1 ); | |
} | |
@@ -715,22 +634,22 @@ void Host_Error( const char *error, ... | |
if( recursive ) | |
{ | |
Msg( "Host_RecursiveError: %s", hosterror2 ); | |
- Sys_Error( "%s", hosterror1 ); | |
+ Sys_Error( hosterror1 ); | |
return; // don't multiple executes | |
} | |
recursive = true; | |
Q_strncpy( hosterror2, hosterror1, MAX_SYSPATH ); | |
- host.errorframe = host.framecount; // to avoid multple calls per frame | |
+ host.errorframe = host.framecount; // to avoid multply calls per frame | |
Q_sprintf( host.finalmsg, "Server crashed: %s", hosterror1 ); | |
- // clear cmd buffer to prevent execution of any commands | |
+ // clearing cmd buffer to prevent execute any commands | |
Cbuf_Clear(); | |
SV_Shutdown( false ); | |
CL_Drop(); // drop clients | |
- // recreate world if required | |
+ // recreate world if needs | |
CL_ClearEdicts (); | |
// release all models | |
@@ -772,103 +690,41 @@ static void Host_Crash_f( void ) | |
{ | |
*(int *)0 = 0xffffffff; | |
} | |
-/* | |
-================= | |
-Host_MapDesignError | |
- | |
-Stop mappers for making bad maps | |
-but allow to ignore errors when need | |
-================= | |
-*/ | |
-void Host_MapDesignError( const char *format, ... ) | |
-{ | |
- char str[256]; | |
- va_list argptr; | |
- va_start( argptr, format ); | |
- Q_vsnprintf( str, 256, format, argptr ); | |
- va_end( argptr ); | |
- if( host_mapdesign_fatal->value ) | |
- Host_Error( "Map Design Error: %s\n", str ); | |
- else | |
- Msg( "^1Map Design Error: ^3%s", str ); | |
-} | |
-/* | |
-================= | |
-Host_Userconfigd_f | |
- | |
-Exec all configs from userconfig.d directory | |
-================= | |
-*/ | |
-void Host_Userconfigd_f( void ) | |
-{ | |
- search_t *t; | |
- int i; | |
- | |
- t = FS_Search( "userconfig.d/*.cfg", true, false ); | |
- if( !t ) return; | |
- | |
- for( i = 0; i < t->numfilenames; i++ ) | |
- { | |
- Cbuf_AddText( va("exec %s\n", t->filenames[i] ) ); | |
- } | |
- | |
- Mem_Free( t ); | |
- | |
-} | |
- | |
/* | |
================= | |
Host_InitCommon | |
================= | |
*/ | |
-void Host_InitCommon( int argc, const char** argv, const char *progname, qboolean bChangeGame ) | |
+void Host_InitCommon( const char *progname, qboolean bChangeGame ) | |
{ | |
+ MEMORYSTATUS lpBuffer; | |
char dev_level[4]; | |
- char *baseDir; | |
- | |
- // some commands may turn engine into infinite loop, | |
- // e.g. xash.exe +game xash -game xash | |
- // so we clear all cmd_args, but leave dbg states as well | |
- Sys_ParseCommandLine( argc, argv ); | |
- | |
- host.enabledll = !Sys_CheckParm( "-nodll" ); | |
+ char szTemp[MAX_SYSPATH]; | |
+ string szRootPath; | |
- host.shutdown_issued = false; | |
- host.crashed = false; | |
-#ifdef DLL_LOADER | |
- if( host.enabledll ) | |
- Setup_LDT_Keeper( ); // Must call before creating any thread | |
-#endif | |
+ lpBuffer.dwLength = sizeof( MEMORYSTATUS ); | |
+ GlobalMemoryStatus( &lpBuffer ); | |
- if( ( baseDir = getenv( "XASH3D_BASEDIR" ) ) ) | |
- { | |
- Q_strncpy( host.rootdir, baseDir, sizeof(host.rootdir) ); | |
- } | |
- else | |
- { | |
- #if defined(XASH_SDL) | |
- if( !( baseDir = SDL_GetBasePath() ) ) | |
- Sys_Error( "couldn't determine current directory: %s", SDL_GetError() ); | |
- Q_strncpy( host.rootdir, baseDir, sizeof( host.rootdir ) ); | |
- #else | |
- if( !getcwd( host.rootdir, sizeof(host.rootdir) ) ) | |
- host.rootdir[0] = 0; | |
- #endif | |
- } | |
+ if( !GetCurrentDirectory( sizeof( host.rootdir ), host.rootdir )) | |
+ Sys_Error( "couldn't determine current directory" ); | |
if( host.rootdir[Q_strlen( host.rootdir ) - 1] == '/' ) | |
host.rootdir[Q_strlen( host.rootdir ) - 1] = 0; | |
- if( !Sys_CheckParm( "-noch" ) ) | |
- { | |
- Sys_SetupCrashHandler(); | |
- } | |
- | |
+ host.oldFilter = SetUnhandledExceptionFilter( Sys_Crash ); | |
+ host.hInst = GetModuleHandle( NULL ); | |
host.change_game = bChangeGame; | |
- host.state = HOST_INIT; // initialization started | |
+ host.state = HOST_INIT; // initialzation started | |
host.developer = host.old_developer = 0; | |
- host.textmode = false; | |
+ | |
+ CRT_Init(); // init some CRT functions | |
+ | |
+ // some commands may turn engine into infinity loop, | |
+ // e.g. xash.exe +game xash -game xash | |
+ // so we clearing all cmd_args, but leave dbg states as well | |
+ Sys_ParseCommandLine( GetCommandLine( )); | |
+ SetErrorMode( SEM_FAILCRITICALERRORS ); // no abort/retry/fail errors | |
host.mempool = Mem_AllocPool( "Zone Engine" ); | |
@@ -884,38 +740,46 @@ void Host_InitCommon( int argc, const ch | |
else host.developer++; // -dev == 1, -dev -console == 2 | |
} | |
-#ifdef XASH_DEDICATED | |
- host.type = HOST_DEDICATED; // predict state | |
-#else | |
- if( Sys_CheckParm("-dedicated") || progname[0] == '#' ) | |
- host.type = HOST_DEDICATED; | |
- else host.type = HOST_NORMAL; | |
-#endif | |
+ host.type = HOST_NORMAL; // predict state | |
host.con_showalways = true; | |
- host.mouse_visible = false; | |
-#ifdef XASH_SDL | |
- if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS ) ) | |
+ // we can specified custom name, from Sys_NewInstance | |
+ if( GetModuleFileName( NULL, szTemp, sizeof( szTemp )) && !host.change_game ) | |
+ FS_FileBase( szTemp, SI.ModuleName ); | |
+ | |
+ FS_ExtractFilePath( szTemp, szRootPath ); | |
+ if( Q_stricmp( host.rootdir, szRootPath )) | |
{ | |
- SDL_Init( SDL_INIT_TIMER ); | |
- Sys_Warn( "SDL_Init failed: %s", SDL_GetError() ); | |
- host.type = HOST_DEDICATED; | |
+ Q_strncpy( host.rootdir, szRootPath, sizeof( host.rootdir )); | |
+ SetCurrentDirectory( host.rootdir ); | |
} | |
-#endif | |
- if ( SetCurrentDirectory( host.rootdir ) != 0) | |
- MsgDev( D_INFO, "%s is working directory now\n", host.rootdir ); | |
- else | |
- Sys_Error( "Changing working directory to %s failed.\n", host.rootdir ); | |
+ if( SI.ModuleName[0] == '#' ) host.type = HOST_DEDICATED; | |
- // set default gamedir | |
- if( progname[0] == '#' ) progname++; | |
- Q_strncpy( SI.ModuleName, progname, sizeof( SI.ModuleName )); | |
+ // determine host type | |
+ if( progname[0] == '#' ) | |
+ { | |
+ Q_strncpy( SI.ModuleName, progname + 1, sizeof( SI.ModuleName )); | |
+ host.type = HOST_DEDICATED; | |
+ } | |
+ else Q_strncpy( SI.ModuleName, progname, sizeof( SI.ModuleName )); | |
- if( Host_IsDedicated() ) | |
+ if( host.type == HOST_DEDICATED ) | |
{ | |
- Sys_MergeCommandLine( ); | |
+ // check for duplicate dedicated server | |
+ host.hMutex = CreateMutex( NULL, 0, "Xash Dedicated Server" ); | |
+ if( !host.hMutex ) | |
+ { | |
+ MSGBOX( "Dedicated server already running" ); | |
+ Sys_Quit(); | |
+ return; | |
+ } | |
+ | |
+ Sys_MergeCommandLine( GetCommandLine( )); | |
+ | |
+ CloseHandle( host.hMutex ); | |
+ host.hMutex = CreateSemaphore( NULL, 0, 1, "Xash Dedicated Server" ); | |
if( host.developer < 3 ) host.developer = 3; // otherwise we see empty console | |
} | |
else | |
@@ -925,11 +789,11 @@ void Host_InitCommon( int argc, const ch | |
} | |
host.old_developer = host.developer; | |
- if( !Sys_CheckParm( "-nowcon" ) ) | |
+ | |
Con_CreateConsole(); | |
// first text message into console or log | |
- MsgDev( D_NOTE, "Sys_LoadLibrary: Loading Engine Library - ok\n" ); | |
+ MsgDev( D_NOTE, "Sys_LoadLibrary: Loading xash.dll - ok\n" ); | |
// startup cmds and cvars subsystem | |
Cmd_Init(); | |
@@ -941,8 +804,6 @@ void Host_InitCommon( int argc, const ch | |
Cvar_Get( "developer", dev_level, CVAR_INIT, "current developer level" ); | |
Cmd_AddCommand( "exec", Host_Exec_f, "execute a script file" ); | |
Cmd_AddCommand( "memlist", Host_MemStats_f, "prints memory pool information" ); | |
- Cmd_AddCommand( "userconfigd", Host_Userconfigd_f, "execute all scripts from userconfig.d" ); | |
- cmd_scripting = Cvar_Get( "cmd_scripting", "0", CVAR_ARCHIVE, "enable simple condition checking and variable operations" ); | |
FS_Init(); | |
Image_Init(); | |
@@ -980,15 +841,13 @@ void Host_FreeCommon( void ) | |
Host_Main | |
================= | |
*/ | |
-int EXPORT Host_Main( int argc, const char **argv, const char *progname, int bChangeGame, pfnChangeGame func ) | |
+int EXPORT Host_Main( const char *progname, int bChangeGame, pfnChangeGame func ) | |
{ | |
static double oldtime, newtime; | |
-#ifdef XASH_SDL | |
- SDL_Event event; | |
-#endif | |
+ | |
pChangeGame = func; // may be NULL | |
- Host_InitCommon( argc, argv, progname, bChangeGame ); | |
+ Host_InitCommon( progname, bChangeGame ); | |
// init commands and vars | |
if( host.developer >= 3 ) | |
@@ -999,20 +858,16 @@ int EXPORT Host_Main( int argc, const ch | |
Cmd_AddCommand ( "net_error", Net_Error_f, "send network bad message from random place"); | |
} | |
- host_cheats = Cvar_Get( "sv_cheats", "0", CVAR_LATCH, "allow usage of cheat commands and variables" ); | |
+ host_cheats = Cvar_Get( "sv_cheats", "0", CVAR_LATCH, "allow cheat variables to enable" ); | |
host_maxfps = Cvar_Get( "fps_max", "72", CVAR_ARCHIVE, "host fps upper limit" ); | |
- host_sleeptime = Cvar_Get( "sleeptime", "1", CVAR_ARCHIVE, "higher value means lower accuracy" ); | |
host_framerate = Cvar_Get( "host_framerate", "0", 0, "locks frame timing to this value in seconds" ); | |
host_serverstate = Cvar_Get( "host_serverstate", "0", CVAR_INIT, "displays current server state" ); | |
- host_gameloaded = Cvar_Get( "host_gameloaded", "0", CVAR_INIT, "indicates a loaded game library" ); | |
- host_clientloaded = Cvar_Get( "host_clientloaded", "0", CVAR_INIT, "indicates a loaded client library" ); | |
+ host_gameloaded = Cvar_Get( "host_gameloaded", "0", CVAR_INIT, "inidcates a loaded game.dll" ); | |
+ host_clientloaded = Cvar_Get( "host_clientloaded", "0", CVAR_INIT, "inidcates a loaded client.dll" ); | |
host_limitlocal = Cvar_Get( "host_limitlocal", "0", 0, "apply cl_cmdrate and rate to loopback connection" ); | |
- con_gamemaps = Cvar_Get( "con_mapfilter", "1", CVAR_ARCHIVE, "when enabled, show only maps in game folder (no maps from base folder when running mod)" ); | |
- download_types = Cvar_Get( "download_types", "msec", CVAR_ARCHIVE, "list of types to download: Model, Sounds, Events, Custom" ); | |
+ con_gamemaps = Cvar_Get( "con_mapfilter", "1", CVAR_ARCHIVE, "when true show only maps in game folder" ); | |
build = Cvar_Get( "build", va( "%i", Q_buildnum()), CVAR_INIT, "returns a current build number" ); | |
- ver = Cvar_Get( "ver", va( "%i/%s.%i", PROTOCOL_VERSION, XASH_VERSION, Q_buildnum( ) ), CVAR_INIT, "shows an engine version" ); | |
- host_mapdesign_fatal = Cvar_Get( "host_mapdesign_fatal", "1", CVAR_ARCHIVE, "make map design errors fatal" ); | |
- host_xashds_hacks = Cvar_Get( "xashds_hacks", "0", 0, "hacks for xashds in singleplayer" ); | |
+ ver = Cvar_Get( "ver", va( "%i/%g (hw build %i)", PROTOCOL_VERSION, XASH_VERSION, Q_buildnum( )), CVAR_INIT, "shows an engine version" ); | |
// content control | |
Cvar_Get( "violence_hgibs", "1", CVAR_ARCHIVE, "show human gib entities" ); | |
@@ -1020,9 +875,9 @@ int EXPORT Host_Main( int argc, const ch | |
Cvar_Get( "violence_hblood", "1", CVAR_ARCHIVE, "draw human blood" ); | |
Cvar_Get( "violence_ablood", "1", CVAR_ARCHIVE, "draw alien blood" ); | |
- if( !Host_IsDedicated() ) | |
+ if( host.type != HOST_DEDICATED ) | |
{ | |
- // when we're in developer-mode, automatically turn cheats on | |
+ // when we in developer-mode automatically turn cheats on | |
if( host.developer > 1 ) Cvar_SetFloat( "sv_cheats", 1.0f ); | |
Cbuf_AddText( "exec video.cfg\n" ); | |
} | |
@@ -1034,8 +889,8 @@ int EXPORT Host_Main( int argc, const ch | |
// allow to change game from the console | |
if( pChangeGame != NULL ) | |
{ | |
- Cmd_AddCommand( "game", Host_ChangeGame_f, "change active game/mod" ); | |
- Cvar_Get( "host_allow_changegame", "1", CVAR_READ_ONLY, "whether changing game/mod is allowed" ); | |
+ Cmd_AddCommand( "game", Host_ChangeGame_f, "change game" ); | |
+ Cvar_Get( "host_allow_changegame", "1", CVAR_READ_ONLY, "allows to change games" ); | |
} | |
else | |
{ | |
@@ -1045,101 +900,58 @@ int EXPORT Host_Main( int argc, const ch | |
SV_Init(); | |
CL_Init(); | |
- HTTP_Init(); | |
- | |
- // post initializations | |
- switch( host.type ) | |
- { | |
- case HOST_NORMAL: | |
- Con_ShowConsole( false ); // hide console | |
- // execute startup config and cmdline | |
- Cbuf_AddText( va( "exec %s.rc\n", SI.ModuleName )); | |
- // intentional fallthrough | |
- case HOST_DEDICATED: | |
- Cbuf_Execute(); // force stuffcmds run if it is in cbuf | |
- // if stuffcmds wasn't run, then init.rc is probably missing, use default | |
- if( !host.stuffcmdsrun ) Cbuf_AddText( "stuffcmds\n" ); | |
- | |
- Cbuf_Execute(); | |
- break; | |
- case HOST_UNKNOWN: | |
- break; | |
- } | |
- | |
- if( Host_IsDedicated() ) | |
+ if( host.type == HOST_DEDICATED ) | |
{ | |
- char *defaultmap; | |
Con_InitConsoleCommands (); | |
Cmd_AddCommand( "quit", Sys_Quit, "quit the game" ); | |
Cmd_AddCommand( "exit", Sys_Quit, "quit the game" ); | |
- SV_InitGameProgs(); | |
- | |
- Cbuf_AddText( "exec config.cfg\n" ); | |
- | |
- // dedicated servers are using settings from server.cfg file | |
+ // dedicated servers using settings from server.cfg file | |
Cbuf_AddText( va( "exec %s\n", Cvar_VariableString( "servercfgfile" ))); | |
Cbuf_Execute(); | |
- defaultmap = Cvar_VariableString( "defaultmap" ); | |
- if( !defaultmap[0] ) | |
- Msg( "Please add \"defaultmap\" cvar with default map name to your server.cfg!\n" ); | |
- else | |
- Cbuf_AddText( va( "map %s\n", defaultmap )); | |
- | |
- Cvar_FullSet( "xashds_hacks", "0", CVAR_READ_ONLY ); | |
- | |
- NET_Config( true ); | |
+ Cbuf_AddText( va( "map %s\n", Cvar_VariableString( "defaultmap" ))); | |
} | |
else | |
{ | |
- Cmd_AddCommand( "minimize", Host_Minimize_f, "minimize main window to taskbar" ); | |
+ Cmd_AddCommand( "minimize", Host_Minimize_f, "minimize main window to tray" ); | |
Cbuf_AddText( "exec config.cfg\n" ); | |
- // listenserver/multiplayer config. | |
- // need load it to update menu options. | |
- Cbuf_AddText( "exec game.cfg\n" ); | |
} | |
host.errorframe = 0; | |
Cbuf_Execute(); | |
+ // post initializations | |
+ switch( host.type ) | |
+ { | |
+ case HOST_NORMAL: | |
+ Con_ShowConsole( false ); // hide console | |
+ // execute startup config and cmdline | |
+ Cbuf_AddText( va( "exec %s.rc\n", SI.ModuleName )); | |
+ // intentional fallthrough | |
+ case HOST_DEDICATED: | |
+ // if stuffcmds wasn't run, then init.rc is probably missing, use default | |
+ if( !host.stuffcmdsrun ) Cbuf_AddText( "stuffcmds\n" ); | |
+ | |
+ Cbuf_Execute(); | |
+ break; | |
+ } | |
+ | |
host.change_game = false; // done | |
- Cmd_RemoveCommand( "setr" ); // remove potential backdoor for changing renderer settings | |
+ Cmd_RemoveCommand( "setr" ); // remove potentially backdoor for change render settings | |
Cmd_RemoveCommand( "setgl" ); | |
// we need to execute it again here | |
- if( !Host_IsDedicated() ) | |
Cmd_ExecuteString( "exec config.cfg\n", src_command ); | |
- | |
- // exec all files from userconfig.d | |
- Host_Userconfigd_f(); | |
- | |
oldtime = Sys_DoubleTime(); | |
- IN_TouchInitConfig(); | |
SCR_CheckStartupVids(); // must be last | |
-#ifdef XASH_SDL | |
- SDL_StopTextInput(); // disable text input event. Enable this in chat/console? | |
-#endif | |
-#if defined(__ANDROID__) && !defined( XASH_SDL ) && !defined(XASH_DEDICATED) | |
- Android_Init(); | |
-#endif | |
- | |
- if( host.state == HOST_INIT ) | |
- host.state = HOST_FRAME; // initialization is finished | |
// main window message loop | |
- while( !host.crashed && !host.shutdown_issued ) | |
+ while( !host.crashed ) | |
{ | |
-#ifdef XASH_SDL | |
- while( !host.crashed && !host.shutdown_issued && SDL_PollEvent( &event ) ) | |
- SDLash_EventFilter( &event ); | |
-#elif defined(__ANDROID__) | |
- Android_RunEvents(); | |
-#endif | |
newtime = Sys_DoubleTime (); | |
Host_Frame( newtime - oldtime ); | |
- | |
oldtime = newtime; | |
} | |
@@ -1157,41 +969,27 @@ void EXPORT Host_Shutdown( void ) | |
if( host.shutdown_issued ) return; | |
host.shutdown_issued = true; | |
+ if( host.state != HOST_ERR_FATAL ) host.state = HOST_SHUTDOWN; // prepare host to normal shutdown | |
+ if( !host.change_game ) Q_strncpy( host.finalmsg, "Server shutdown", sizeof( host.finalmsg )); | |
- switch( host.state ) | |
- { | |
- case HOST_INIT: | |
- case HOST_CRASHED: | |
- case HOST_ERR_FATAL: | |
- if( !Host_IsDedicated() ) | |
- MsgDev( D_WARN, "Not shutting down normally (%d), skipping config save!\n", host.state ); | |
- if( host.state != HOST_ERR_FATAL) | |
- host.state = HOST_SHUTDOWN; | |
- break; | |
- default: | |
- if( !Host_IsDedicated() ) | |
- { | |
- // restore all latched cheat cvars | |
- Cvar_SetCheatState( true ); | |
+ if( host.type == HOST_NORMAL ) | |
Host_WriteConfig(); | |
- } | |
- host.state = HOST_SHUTDOWN; // prepare host to normal shutdown | |
- } | |
- | |
- if( !host.change_game ) | |
- Q_strncpy( host.finalmsg, "Server shutdown", sizeof( host.finalmsg )); | |
- | |
- Log_Printf( "Server shutdown\n" ); | |
- Log_Close(); | |
SV_Shutdown( false ); | |
CL_Shutdown(); | |
Mod_Shutdown(); | |
NET_Shutdown(); | |
- HTTP_Shutdown(); | |
- Cmd_Shutdown(); | |
Host_FreeCommon(); | |
Con_DestroyConsole(); | |
- Sys_RestoreCrashHandler(); | |
+ | |
+ // restore filter | |
+ if( host.oldFilter ) SetUnhandledExceptionFilter( host.oldFilter ); | |
+} | |
+ | |
+// main DLL entry point | |
+BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) | |
+{ | |
+ hCurrent = hinstDLL; | |
+ return TRUE; | |
} | |
diff --suppress-blank-empty -prudwEZbB engine/common/hpak.c /mnt/data/Xash3D_original/engine/common/hpak.c | |
--- engine/common/hpak.c 2016-04-07 17:03:10.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/hpak.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -117,7 +117,7 @@ void HPAK_CreatePak( const char *filenam | |
FS_Read( f, temp, DirEnt->nDownloadSize ); | |
FS_Seek( f, filelocation, SEEK_SET ); | |
- MD5Update( &MD5_Hash, (byte *)temp, DirEnt->nDownloadSize ); | |
+ MD5Update( &MD5_Hash, temp, DirEnt->nDownloadSize ); | |
Mem_Free( temp ); | |
} | |
else | |
@@ -125,7 +125,7 @@ void HPAK_CreatePak( const char *filenam | |
MD5Update( &MD5_Hash, data, DirEnt->nDownloadSize ); | |
} | |
- MD5Final( (byte *)md5, &MD5_Hash ); | |
+ MD5Final( md5, &MD5_Hash ); | |
if( Q_memcmp( md5, DirEnt->rgucMD5_hash, 16 )) | |
{ | |
@@ -238,7 +238,7 @@ void HPAK_AddLump( qboolean add_to_queue | |
MD5Update( &MD5_Hash, data, DirEnt->nDownloadSize ); | |
} | |
- MD5Final( (byte *)md5, &MD5_Hash ); | |
+ MD5Final( md5, &MD5_Hash ); | |
if( Q_memcmp( md5, DirEnt->rgucMD5_hash, 0x10 )) | |
{ | |
@@ -308,7 +308,7 @@ void HPAK_AddLump( qboolean add_to_queue | |
FS_Read( f1, hpak1.dirs, sizeof( hpak_dir_t ) * hpak1.count ); | |
FS_Close( f1 ); | |
- if( HPAK_FindResource( &hpak1, (char *)DirEnt->rgucMD5_hash, NULL )) | |
+ if( HPAK_FindResource( &hpak1, DirEnt->rgucMD5_hash, NULL )) | |
{ | |
Mem_Free( hpak1.dirs ); | |
FS_Close( f2 ); | |
@@ -452,7 +452,7 @@ static qboolean HPAK_Validate( const cha | |
Q_memset( &MD5_Hash, 0, sizeof( MD5Context_t )); | |
MD5Init( &MD5_Hash ); | |
MD5Update( &MD5_Hash, dataPak, dataDir[i].size ); | |
- MD5Final( (byte *)md5, &MD5_Hash ); | |
+ MD5Final( md5, &MD5_Hash ); | |
pRes = &dataDir[i].DirectoryResource; | |
@@ -814,7 +814,7 @@ void HPAK_RemoveLump( const char *name, | |
FS_Read( f1, hpak_read.dirs, sizeof( hpak_dir_t ) * hpak_read.count ); | |
- if( !HPAK_FindResource( &hpak_read, (char *)resource->rgucMD5_hash, NULL )) | |
+ if( !HPAK_FindResource( &hpak_read, resource->rgucMD5_hash, NULL )) | |
{ | |
MsgDev( D_ERROR, "HPAK_RemoveLump: Couldn't find the lump %s in hpak %s.n", resource->szFileName, read_path ); | |
Mem_Free( hpak_read.dirs ); | |
diff --suppress-blank-empty -prudwEZbB engine/common/imagelib/imagelib.h /mnt/data/Xash3D_original/engine/common/imagelib/imagelib.h | |
--- engine/common/imagelib/imagelib.h 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/imagelib/imagelib.h 2016-08-19 14:21:49.000000000 +0000 | |
@@ -104,24 +104,26 @@ typedef struct imglib_s | |
======================================================================== | |
*/ | |
+#pragma pack( 1 ) | |
typedef struct | |
{ | |
- //char id[2]; // bmfh.bfType | |
- uint fileSize; // bmfh.bfSize | |
- uint reserved0; // bmfh.bfReserved1 + bmfh.bfReserved2 | |
- uint bitmapDataOffset; // bmfh.bfOffBits | |
- uint bitmapHeaderSize; // bmih.biSize | |
- uint width; // bmih.biWidth | |
+ char id[2]; // bmfh.bfType | |
+ dword fileSize; // bmfh.bfSize | |
+ dword reserved0; // bmfh.bfReserved1 + bmfh.bfReserved2 | |
+ dword bitmapDataOffset; // bmfh.bfOffBits | |
+ dword bitmapHeaderSize; // bmih.biSize | |
+ int width; // bmih.biWidth | |
int height; // bmih.biHeight | |
word planes; // bmih.biPlanes | |
word bitsPerPixel; // bmih.biBitCount | |
- uint compression; // bmih.biCompression | |
- uint bitmapDataSize; // bmih.biSizeImage | |
- uint hRes; // bmih.biXPelsPerMeter | |
- uint vRes; // bmih.biYPelsPerMeter | |
- uint colors; // bmih.biClrUsed | |
- uint importantColors; // bmih.biClrImportant | |
+ dword compression; // bmih.biCompression | |
+ dword bitmapDataSize; // bmih.biSizeImage | |
+ dword hRes; // bmih.biXPelsPerMeter | |
+ dword vRes; // bmih.biYPelsPerMeter | |
+ dword colors; // bmih.biClrUsed | |
+ dword importantColors; // bmih.biClrImportant | |
} bmp_t; | |
+#pragma pack( ) | |
/* | |
======================================================================== | |
@@ -130,14 +132,15 @@ typedef struct | |
======================================================================== | |
*/ | |
+#pragma pack( 1 ) | |
typedef struct tga_s | |
{ | |
byte id_length; | |
byte colormap_type; | |
byte image_type; | |
- byte colormap_size; | |
word colormap_index; | |
word colormap_length; | |
+ byte colormap_size; | |
word x_origin; | |
word y_origin; | |
word width; | |
@@ -145,6 +148,7 @@ typedef struct tga_s | |
byte pixel_size; | |
byte attributes; | |
} tga_t; | |
+#pragma pack( ) | |
/* | |
======================================================================== | |
@@ -230,7 +234,7 @@ typedef struct dds_caps_s | |
typedef struct dds_s | |
{ | |
- uint dwIdent; // must match DDSHEADER | |
+ uint dwIdent; // must matched with DDSHEADER | |
uint dwSize; | |
uint dwFlags; // determines what fields are valid | |
uint dwHeight; | |
@@ -246,8 +250,8 @@ typedef struct dds_s | |
} dds_t; | |
// imagelib definitions | |
-#define IMAGE_MAXWIDTH 8196 | |
-#define IMAGE_MAXHEIGHT 8196 | |
+#define IMAGE_MAXWIDTH 8192 | |
+#define IMAGE_MAXHEIGHT 8192 | |
#define LUMP_MAXWIDTH 1024 // WorldCraft limits | |
#define LUMP_MAXHEIGHT 1024 | |
@@ -298,8 +302,8 @@ qboolean Image_LoadMDL( const char *name | |
qboolean Image_LoadSPR( const char *name, const byte *buffer, size_t filesize ); | |
qboolean Image_LoadTGA( const char *name, const byte *buffer, size_t filesize ); | |
qboolean Image_LoadBMP( const char *name, const byte *buffer, size_t filesize ); | |
-qboolean Image_LoadFNT( const char *name, const byte *buffer, size_t filesize ); | |
qboolean Image_LoadDDS( const char *name, const byte *buffer, size_t filesize ); | |
+qboolean Image_LoadFNT( const char *name, const byte *buffer, size_t filesize ); | |
qboolean Image_LoadLMP( const char *name, const byte *buffer, size_t filesize ); | |
qboolean Image_LoadPAL( const char *name, const byte *buffer, size_t filesize ); | |
diff --suppress-blank-empty -prudwEZbB engine/common/imagelib/img_bmp.c /mnt/data/Xash3D_original/engine/common/imagelib/img_bmp.c | |
--- engine/common/imagelib/img_bmp.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/imagelib/img_bmp.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -15,18 +15,6 @@ GNU General Public License for more deta | |
#include "imagelib.h" | |
-#define BI_SIZE 40 //size of bitmap info header. | |
-#ifndef _WIN32 | |
-#define BI_RGB 0 | |
- | |
-typedef struct tagRGBQUAD { | |
- BYTE rgbBlue; | |
- BYTE rgbGreen; | |
- BYTE rgbRed; | |
- BYTE rgbReserved; | |
-} RGBQUAD; | |
-#endif | |
- | |
/* | |
============= | |
Image_LoadBMP | |
@@ -34,26 +22,38 @@ Image_LoadBMP | |
*/ | |
qboolean Image_LoadBMP( const char *name, const byte *buffer, size_t filesize ) | |
{ | |
- byte *buf_p, *pixbuf, magic[2]; | |
+ byte *buf_p, *pixbuf; | |
byte palette[256][4]; | |
int i, columns, column, rows, row, bpp = 1; | |
- int padSize = 0, bps; | |
+ int cbPalBytes = 0, padSize = 0, bps = 0; | |
qboolean load_qfont = false; | |
bmp_t bhdr; | |
if( filesize < sizeof( bhdr )) return false; | |
buf_p = (byte *)buffer; | |
- Q_memcpy( magic, buf_p, sizeof( magic ) ); | |
- buf_p += sizeof( magic ); // move pointer | |
- Q_memcpy( &bhdr, buf_p, sizeof( bmp_t )); | |
- buf_p += sizeof( bmp_t ); | |
+ bhdr.id[0] = *buf_p++; | |
+ bhdr.id[1] = *buf_p++; // move pointer | |
+ bhdr.fileSize = *(long *)buf_p; buf_p += 4; | |
+ bhdr.reserved0 = *(long *)buf_p; buf_p += 4; | |
+ bhdr.bitmapDataOffset = *(long *)buf_p; buf_p += 4; | |
+ bhdr.bitmapHeaderSize = *(long *)buf_p; buf_p += 4; | |
+ bhdr.width = *(long *)buf_p; buf_p += 4; | |
+ bhdr.height = *(long *)buf_p; buf_p += 4; | |
+ bhdr.planes = *(short *)buf_p; buf_p += 2; | |
+ bhdr.bitsPerPixel = *(short *)buf_p; buf_p += 2; | |
+ bhdr.compression = *(long *)buf_p; buf_p += 4; | |
+ bhdr.bitmapDataSize = *(long *)buf_p; buf_p += 4; | |
+ bhdr.hRes = *(long *)buf_p; buf_p += 4; | |
+ bhdr.vRes = *(long *)buf_p; buf_p += 4; | |
+ bhdr.colors = *(long *)buf_p; buf_p += 4; | |
+ bhdr.importantColors = *(long *)buf_p; buf_p += 4; | |
// bogus file header check | |
if( bhdr.reserved0 != 0 ) return false; | |
if( bhdr.planes != 1 ) return false; | |
- if( Q_memcmp( magic, "BM", 2 )) | |
+ if( Q_memcmp( bhdr.id, "BM", 2 )) | |
{ | |
MsgDev( D_ERROR, "Image_LoadBMP: only Windows-style BMP files supported (%s)\n", name ); | |
return false; | |
@@ -99,8 +99,6 @@ qboolean Image_LoadBMP( const char *name | |
if( bhdr.bitsPerPixel <= 8 ) | |
{ | |
- int cbPalBytes; | |
- | |
// figure out how many entries are actually in the table | |
if( bhdr.colors == 0 ) | |
{ | |
@@ -108,10 +106,9 @@ qboolean Image_LoadBMP( const char *name | |
cbPalBytes = (1 << bhdr.bitsPerPixel) * sizeof( RGBQUAD ); | |
} | |
else cbPalBytes = bhdr.colors * sizeof( RGBQUAD ); | |
+ } | |
Q_memcpy( palette, buf_p, cbPalBytes ); | |
- buf_p += cbPalBytes; | |
- } | |
if( host.overview_loading && bhdr.bitsPerPixel == 8 ) | |
{ | |
@@ -149,8 +146,10 @@ qboolean Image_LoadBMP( const char *name | |
bpp = 4; | |
} | |
+ buf_p += cbPalBytes; | |
image.size = image.width * image.height * bpp; | |
image.rgba = Mem_Alloc( host.imagepool, image.size ); | |
+ bps = image.width * (bhdr.bitsPerPixel >> 3); | |
switch( bhdr.bitsPerPixel ) | |
{ | |
@@ -165,7 +164,6 @@ qboolean Image_LoadBMP( const char *name | |
break; | |
case 8: | |
case 24: | |
- bps = image.width * (bhdr.bitsPerPixel >> 3); | |
padSize = ( 4 - ( bps % 4 )) % 4; | |
break; | |
} | |
@@ -176,7 +174,7 @@ qboolean Image_LoadBMP( const char *name | |
for( column = 0; column < columns; column++ ) | |
{ | |
- byte red = '\0', green = '\0', blue = '\0', alpha; | |
+ byte red, green, blue, alpha; | |
word shortPixel; | |
int c, k, palIndex; | |
@@ -296,14 +294,15 @@ qboolean Image_LoadBMP( const char *name | |
qboolean Image_SaveBMP( const char *name, rgbdata_t *pix ) | |
{ | |
file_t *pfile = NULL; | |
- bmp_t bhdr; | |
- size_t total_size = 0, cur_size; | |
+ BITMAPFILEHEADER bmfh; | |
+ BITMAPINFOHEADER bmih; | |
+ size_t total_size, cur_size; | |
RGBQUAD rgrgbPalette[256]; | |
- uint cbBmpBits; | |
- byte *clipbuf = NULL, magic[2]; | |
+ dword cbBmpBits; | |
+ byte *clipbuf = NULL; | |
byte *pb, *pbBmpBits; | |
- uint cbPalBytes; | |
- uint biTrueWidth; | |
+ dword cbPalBytes = 0; | |
+ dword biTrueWidth; | |
int pixel_size; | |
int i, x, y; | |
@@ -340,42 +339,52 @@ qboolean Image_SaveBMP( const char *name | |
// NOTE: align transparency column will sucessfully removed | |
// after create sprite or lump image, it's just standard requiriments | |
- //biTrueWidth = pix->width; | |
- biTrueWidth = ((pix->width + 3) & ~3); // What is this? | |
+ biTrueWidth = ((pix->width + 3) & ~3); | |
cbBmpBits = biTrueWidth * pix->height * pixel_size; | |
- cbPalBytes = ( pixel_size == 1 ) ? 256 * sizeof( RGBQUAD ) : 0; | |
+ if( pixel_size == 1 ) cbPalBytes = 256 * sizeof( RGBQUAD ); | |
// Bogus file header check | |
- magic[0] = 'B'; | |
- magic[1] = 'M'; | |
- bhdr.fileSize = sizeof( magic ) + sizeof( bmp_t ) + cbBmpBits + cbPalBytes; | |
- bhdr.reserved0 = 0; | |
- bhdr.bitmapDataOffset = sizeof( magic ) + sizeof( bmp_t ) + cbPalBytes; | |
- bhdr.bitmapHeaderSize = BI_SIZE; | |
- bhdr.width = biTrueWidth; | |
- bhdr.height = pix->height; | |
- bhdr.planes = 1; | |
- bhdr.bitsPerPixel = pixel_size * 8; | |
- bhdr.compression = BI_RGB; | |
- bhdr.bitmapDataSize = cbBmpBits; | |
- bhdr.hRes = 0; | |
- bhdr.vRes = 0; | |
- bhdr.colors = ( pixel_size == 1 ) ? 256 : 0; | |
- bhdr.importantColors = 0; | |
+ bmfh.bfType = MAKEWORD( 'B', 'M' ); | |
+ bmfh.bfSize = sizeof( bmfh ) + sizeof( bmih ) + cbBmpBits + cbPalBytes; | |
+ bmfh.bfReserved1 = 0; | |
+ bmfh.bfReserved2 = 0; | |
+ bmfh.bfOffBits = sizeof( bmfh ) + sizeof( bmih ) + cbPalBytes; | |
if( host.write_to_clipboard ) | |
{ | |
// NOTE: the cbPalBytes may be 0 | |
- total_size = BI_SIZE + cbPalBytes + cbBmpBits; | |
+ total_size = sizeof( bmih ) + cbPalBytes + cbBmpBits; | |
clipbuf = Z_Malloc( total_size ); | |
- Q_memcpy( clipbuf, (byte *)&bhdr + ( sizeof( bmp_t ) - BI_SIZE ), BI_SIZE ); | |
- cur_size = BI_SIZE; | |
+ cur_size = 0; | |
} | |
else | |
{ | |
- // Write header | |
- FS_Write( pfile, magic, sizeof( magic )); | |
- FS_Write( pfile, &bhdr, sizeof( bmp_t )); | |
+ // write header | |
+ FS_Write( pfile, &bmfh, sizeof( bmfh )); | |
+ } | |
+ | |
+ // size of structure | |
+ bmih.biSize = sizeof( bmih ); | |
+ bmih.biWidth = biTrueWidth; | |
+ bmih.biHeight = pix->height; | |
+ bmih.biPlanes = 1; | |
+ bmih.biBitCount = pixel_size * 8; | |
+ bmih.biCompression = BI_RGB; | |
+ bmih.biSizeImage = cbBmpBits; | |
+ bmih.biXPelsPerMeter = 0; | |
+ bmih.biYPelsPerMeter = 0; | |
+ bmih.biClrUsed = ( pixel_size == 1 ) ? 256 : 0; | |
+ bmih.biClrImportant = 0; | |
+ | |
+ if( host.write_to_clipboard ) | |
+ { | |
+ Q_memcpy( clipbuf + cur_size, &bmih, sizeof( bmih )); | |
+ cur_size += sizeof( bmih ); | |
+ } | |
+ else | |
+ { | |
+ // Write info header | |
+ FS_Write( pfile, &bmih, sizeof( bmih )); | |
} | |
pbBmpBits = Mem_Alloc( host.imagepool, cbBmpBits ); | |
@@ -385,7 +394,7 @@ qboolean Image_SaveBMP( const char *name | |
pb = pix->palette; | |
// copy over used entries | |
- for( i = 0; i < (int)bhdr.colors; i++ ) | |
+ for( i = 0; i < (int)bmih.biClrUsed; i++ ) | |
{ | |
rgrgbPalette[i].rgbRed = *pb++; | |
rgrgbPalette[i].rgbGreen = *pb++; | |
@@ -412,9 +421,9 @@ qboolean Image_SaveBMP( const char *name | |
pb = pix->buffer; | |
- for( y = 0; y < bhdr.height; y++ ) | |
+ for( y = 0; y < bmih.biHeight; y++ ) | |
{ | |
- i = ( bhdr.height - 1 - y ) * ( bhdr.width ); | |
+ i = (bmih.biHeight - 1 - y ) * (bmih.biWidth); | |
for( x = 0; x < pix->width; x++ ) | |
{ | |
diff --suppress-blank-empty -prudwEZbB engine/common/imagelib/img_dds.c /mnt/data/Xash3D_original/engine/common/imagelib/img_dds.c | |
--- engine/common/imagelib/img_dds.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/imagelib/img_dds.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -22,7 +22,6 @@ qboolean Image_CheckDXT3Alpha( dds_t *hd | |
byte *alpha; | |
int x, y, i, j; | |
- // analyze quad 4x4 | |
for( y = 0; y < hdr->dwHeight; y += 4 ) | |
{ | |
for( x = 0; x < hdr->dwWidth; x += 4 ) | |
@@ -58,7 +57,6 @@ qboolean Image_CheckDXT5Alpha( dds_t *hd | |
byte *alphamask; | |
int x, y, i, j; | |
- // analyze quad 4x4 | |
for( y = 0; y < hdr->dwHeight; y += 4 ) | |
{ | |
for( x = 0; x < hdr->dwWidth; x += 4 ) | |
diff --suppress-blank-empty -prudwEZbB engine/common/imagelib/img_main.c /mnt/data/Xash3D_original/engine/common/imagelib/img_main.c | |
--- engine/common/imagelib/img_main.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/imagelib/img_main.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -100,8 +100,8 @@ void Image_Reset( void ) | |
// reset global variables | |
image.width = image.height = image.depth = 0; | |
image.source_width = image.source_height = 0; | |
- image.num_sides = image.flags = 0; | |
image.source_type = image.num_mips = 0; | |
+ image.num_sides = image.flags = 0; | |
image.type = PF_UNKNOWN; | |
image.fogParams[0] = 0; | |
image.fogParams[1] = 0; | |
@@ -224,9 +224,7 @@ rgbdata_t *FS_LoadImage( const char *fil | |
const char *ext = FS_FileExtension( filename ); | |
string path, loadname, sidename; | |
qboolean anyformat = true; | |
- qboolean gamedironly = true; | |
- int i; | |
- fs_offset_t filesize = 0; | |
+ int i, filesize = 0; | |
const loadpixformat_t *format; | |
const cubepack_t *cmap; | |
byte *f; | |
@@ -252,8 +250,6 @@ rgbdata_t *FS_LoadImage( const char *fil | |
// HACKHACK: skip any checks, load file from buffer | |
if( filename[0] == '#' && buffer && size ) goto load_internal; | |
-search_fs: | |
- | |
// now try all the formats in the selected list | |
for( format = image.loadformats; format && format->formatstring; format++) | |
{ | |
@@ -261,10 +257,10 @@ search_fs: | |
{ | |
Q_sprintf( path, format->formatstring, loadname, "", format->ext ); | |
image.hint = format->hint; | |
- f = FS_LoadFile( path, &filesize, gamedironly ); | |
+ f = FS_LoadFile( path, &filesize, false ); | |
if( f && filesize > 0 ) | |
{ | |
- if( format->loadfunc( path, f, (size_t)filesize )) | |
+ if( format->loadfunc( path, f, filesize )) | |
{ | |
Mem_Free( f ); // release buffer | |
return ImagePack(); // loaded | |
@@ -274,12 +270,6 @@ search_fs: | |
} | |
} | |
- if( gamedironly ) | |
- { | |
- gamedironly = false; | |
- goto search_fs; | |
- } | |
- | |
// check all cubemap sides with package suffix | |
for( cmap = load_cubemap; cmap && cmap->type; cmap++ ) | |
{ | |
@@ -298,7 +288,7 @@ search_fs: | |
if( f && filesize > 0 ) | |
{ | |
// this name will be used only for tell user about problems | |
- if( format->loadfunc( path, f, (size_t)filesize )) | |
+ if( format->loadfunc( path, f, filesize )) | |
{ | |
Q_snprintf( sidename, sizeof( sidename ), "%s%s.%s", loadname, cmap->type[i].suf, format->ext ); | |
if( FS_AddSideToPack( sidename, cmap->type[i].flags )) // process flags to flip some sides | |
diff --suppress-blank-empty -prudwEZbB engine/common/imagelib/img_quant.c /mnt/data/Xash3D_original/engine/common/imagelib/img_quant.c | |
--- engine/common/imagelib/img_quant.c 2016-04-07 17:03:10.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/imagelib/img_quant.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -30,9 +30,9 @@ GNU General Public License for more deta | |
// defs for freq and bias | |
#define intbiasshift 16 // bias for fractions | |
-#define intbias (1U << intbiasshift) | |
+#define intbias (1<<intbiasshift) | |
#define gammashift 10 // gamma = 1024 | |
-#define gamma (1U << gammashift) | |
+#define gamma (1<<gammashift) | |
#define betashift 10 | |
#define beta (intbias>>betashift) // beta = 1 / 1024 | |
#define betagamma (intbias<<(gammashift - betashift)) | |
@@ -40,20 +40,20 @@ GNU General Public License for more deta | |
// defs for decreasing radius factor | |
#define initrad (netsize>>3) // for 256 cols, radius starts | |
#define radiusbiasshift 6 // at 32.0 biased by 6 bits | |
-#define radiusbias (1U << radiusbiasshift) | |
+#define radiusbias (1<<radiusbiasshift) | |
#define initradius (initrad * radiusbias) // and decreases by a | |
#define radiusdec 30 // factor of 1/30 each cycle | |
// defs for decreasing alpha factor | |
#define alphabiasshift 10 // alpha starts at 1.0 | |
-#define initalpha (1U << alphabiasshift) | |
+#define initalpha (1<<alphabiasshift) | |
int alphadec; // biased by 10 bits | |
// radbias and alpharadbias used for radpower calculation | |
#define radbiasshift 8 | |
-#define radbias (1U << radbiasshift) | |
+#define radbias (1<<radbiasshift) | |
#define alpharadbshift (alphabiasshift+radbiasshift) | |
-#define alpharadbias (1U << alpharadbshift) | |
+#define alpharadbias (1<<alpharadbshift) | |
// types and global variables | |
static byte *thepicture; // the input image itself | |
@@ -93,7 +93,7 @@ void unbiasnet( void ) | |
{ | |
// OLD CODE: network[i][j] >>= netbiasshift; | |
// Fix based on bug report by Juergen Weigert [email protected] | |
- temp = (network[i][j] + (1U << (netbiasshift - 1))) >> netbiasshift; | |
+ temp = (network[i][j] + (1 << (netbiasshift - 1))) >> netbiasshift; | |
if( temp > 255 ) temp = 255; | |
network[i][j] = temp; | |
} | |
@@ -254,7 +254,7 @@ int contest( int r, int g, int b ) | |
register int i, dist, a, biasdist, betafreq; | |
int bestpos, bestbiaspos, bestd, bestbiasd; | |
- bestd = ~(1U << 31); | |
+ bestd = ~(1<<31); | |
bestbiasd = bestd; | |
bestpos = -1; | |
bestbiaspos = bestpos; | |
diff --suppress-blank-empty -prudwEZbB engine/common/imagelib/img_tga.c /mnt/data/Xash3D_original/engine/common/imagelib/img_tga.c | |
--- engine/common/imagelib/img_tga.c 2016-04-07 17:03:10.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/imagelib/img_tga.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -61,7 +61,7 @@ qboolean Image_LoadTGA( const char *name | |
MsgDev( D_WARN, "Image_LoadTGA: (%s) Only 8 bit images supported for type 1 and 9\n", name ); | |
return false; | |
} | |
- if( targa_header.colormap_length > 256 ) | |
+ if( targa_header.colormap_length != 256 ) | |
{ | |
MsgDev( D_WARN, "Image_LoadTGA: (%s) Only 8 bit colormaps are supported for type 1 and 9\n", name ); | |
return false; | |
@@ -109,7 +109,7 @@ qboolean Image_LoadTGA( const char *name | |
else if( targa_header.image_type == 3 || targa_header.image_type == 11 ) | |
{ | |
// uncompressed greyscale | |
- if( targa_header.pixel_size != 8 && targa_header.pixel_size != 16 ) | |
+ if( targa_header.pixel_size != 8 ) | |
{ | |
MsgDev( D_WARN, "Image_LoadTGA: (%s) Only 8 bit images supported for type 3 and 11\n", name ); | |
return false; | |
@@ -161,15 +161,11 @@ qboolean Image_LoadTGA( const char *name | |
case 9: | |
// colormapped image | |
blue = *buf_p++; | |
- if( blue < targa_header.colormap_length ) | |
- { | |
red = palette[blue][0]; | |
green = palette[blue][1]; | |
alpha = palette[blue][3]; | |
blue = palette[blue][2]; | |
if( alpha != 255 ) image.flags |= IMAGE_HAS_ALPHA; | |
- } | |
- else red = green = blue = alpha = 255; | |
break; | |
case 2: | |
case 10: | |
@@ -187,17 +183,9 @@ qboolean Image_LoadTGA( const char *name | |
break; | |
case 3: | |
case 11: | |
+ // greyscale image | |
blue = green = red = *buf_p++; | |
- if( targa_header.pixel_size == 16 ) | |
- { | |
- alpha = *buf_p++; | |
- if( alpha != 255 ) | |
- image.flags |= IMAGE_HAS_ALPHA; | |
- } | |
- else | |
alpha = 255; | |
- // greyscale image | |
- | |
break; | |
} | |
} | |
@@ -252,7 +240,7 @@ qboolean Image_SaveTGA( const char *name | |
buffer[15] = (pix->height >> 8) & 0xFF; | |
buffer[16] = ( pix->flags & IMAGE_HAS_ALPHA ) ? 32 : 24; | |
buffer[17] = ( pix->flags & IMAGE_HAS_ALPHA ) ? 8 : 0; // 8 bits of alpha | |
- Q_strncpy( (char *)buffer + 18, comment, Q_strlen( comment )); | |
+ Q_strncpy( buffer + 18, comment, Q_strlen( comment )); | |
out = buffer + 18 + Q_strlen( comment ); | |
// get image description | |
diff --suppress-blank-empty -prudwEZbB engine/common/imagelib/img_utils.c /mnt/data/Xash3D_original/engine/common/imagelib/img_utils.c | |
--- engine/common/imagelib/img_utils.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/imagelib/img_utils.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -131,8 +131,8 @@ static const loadpixformat_t load_null[] | |
static const loadpixformat_t load_game[] = | |
{ | |
{ "%s%s.%s", "dds", Image_LoadDDS, IL_HINT_NO }, // dds for world and studio models | |
-{ "%s%s.%s", "bmp", Image_LoadBMP, IL_HINT_NO }, // WON menu images | |
{ "%s%s.%s", "tga", Image_LoadTGA, IL_HINT_NO }, // hl vgui menus | |
+{ "%s%s.%s", "bmp", Image_LoadBMP, IL_HINT_NO }, // WON menu images | |
{ "%s%s.%s", "mip", Image_LoadMIP, IL_HINT_NO }, // hl textures from wad or buffer | |
{ "%s%s.%s", "mdl", Image_LoadMDL, IL_HINT_HL }, // hl studio model skins | |
{ "%s%s.%s", "spr", Image_LoadSPR, IL_HINT_HL }, // hl sprite frames | |
@@ -463,8 +463,6 @@ void Image_PaletteHueReplace( byte *palS | |
maxcol = max( max( r, g ), b ) / 255.0f; | |
mincol = min( min( r, g ), b ) / 255.0f; | |
- if( maxcol == 0 ) continue; | |
- | |
val = maxcol; | |
sat = (maxcol - mincol) / maxcol; | |
@@ -569,7 +567,7 @@ qboolean Image_Copy8bitRGBA( const byte | |
// check for color | |
for( i = 0; i < 256; i++ ) | |
{ | |
- col = (rgba_t *)&image.d_currentpal[i]; | |
+ col = (rgba_t *)image.d_currentpal[i]; | |
if( col[0] != col[1] || col[1] != col[2] ) | |
{ | |
image.flags |= IMAGE_HAS_COLOR; | |
@@ -1116,7 +1114,7 @@ byte *Image_FloodInternal( const byte *i | |
{ | |
if( x < inwidth ) | |
*out++ = *in++; | |
- else out++; | |
+ else *out++; | |
} | |
} | |
} | |
@@ -1252,7 +1250,7 @@ qboolean Image_AddIndexedImageToPack( co | |
if( Image_CheckFlag( IL_KEEP_8BIT )) | |
expand_to_rgba = false; | |
- else if( !Host_IsDedicated() && ( image.flags & ( IMAGE_HAS_LUMA|IMAGE_QUAKESKY ))) | |
+ else if( host.type == HOST_NORMAL && ( image.flags & ( IMAGE_HAS_LUMA|IMAGE_QUAKESKY ))) | |
expand_to_rgba = false; | |
image.size = mipsize; | |
diff --suppress-blank-empty -prudwEZbB engine/common/imagelib/img_wad.c /mnt/data/Xash3D_original/engine/common/imagelib/img_wad.c | |
--- engine/common/imagelib/img_wad.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/imagelib/img_wad.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -122,18 +122,6 @@ qboolean Image_LoadFNT( const char *name | |
return Image_AddIndexedImageToPack( fin, image.width, image.height ); | |
} | |
-/* | |
-====================== | |
-Image_SetMDLPointer | |
- | |
-Transfer buffer pointer before Image_LoadMDL | |
-====================== | |
-*/ | |
-void *g_mdltexdata; | |
-void Image_SetMDLPointer(byte *p) | |
-{ | |
- g_mdltexdata = p; | |
-} | |
/* | |
============ | |
@@ -153,10 +141,7 @@ qboolean Image_LoadMDL( const char *name | |
image.width = pin->width; | |
image.height = pin->height; | |
pixels = image.width * image.height; | |
- | |
- fin = (byte *)g_mdltexdata; | |
- ASSERT(fin); | |
- g_mdltexdata = NULL; | |
+ fin = (byte *)pin->index; // setup buffer | |
if( !Image_ValidSize( name )) return false; | |
@@ -196,7 +181,7 @@ Image_LoadSPR | |
*/ | |
qboolean Image_LoadSPR( const char *name, const byte *buffer, size_t filesize ) | |
{ | |
- dspriteframe_t pin; // identical for q1\hl sprites | |
+ dspriteframe_t *pin; // identical for q1\hl sprites | |
if( image.hint == IL_HINT_HL ) | |
{ | |
@@ -216,9 +201,9 @@ qboolean Image_LoadSPR( const char *name | |
return false; | |
} | |
- Q_memcpy( &pin, buffer, sizeof(dspriteframe_t) ); | |
- image.width = pin.width; | |
- image.height = pin.height; | |
+ pin = (dspriteframe_t *)buffer; | |
+ image.width = pin->width; | |
+ image.height = pin->height; | |
if( filesize < image.width * image.height ) | |
{ | |
@@ -243,7 +228,7 @@ qboolean Image_LoadSPR( const char *name | |
if( image.d_rendermode == LUMP_TRANSPARENT ) | |
image.d_currentpal[255] = 0; | |
- return Image_AddIndexedImageToPack( (byte *)(buffer + sizeof(dspriteframe_t)), image.width, image.height ); | |
+ return Image_AddIndexedImageToPack( (byte *)(pin + 1), image.width, image.height ); | |
} | |
/* | |
diff --suppress-blank-empty -prudwEZbB engine/common/infostring.c /mnt/data/Xash3D_original/engine/common/infostring.c | |
--- engine/common/infostring.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/infostring.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -295,7 +295,7 @@ qboolean Info_SetValueForKey( char *s, c | |
return Info_SetValueForStarKey( s, key, value, MAX_INFO_STRING ); | |
} | |
-static void Cvar_LookupBitInfo( const char *name, const char *string, void *info, void *unused ) | |
+static void Cvar_LookupBitInfo( const char *name, const char *string, const char *info, void *unused ) | |
{ | |
Info_SetValueForKey( (char *)info, name, string ); | |
} | |
diff --suppress-blank-empty -prudwEZbB engine/common/input.c /mnt/data/Xash3D_original/engine/common/input.c | |
--- engine/common/input.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/input.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -12,30 +12,26 @@ but WITHOUT ANY WARRANTY; without even t | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
-#include "port.h" | |
#include "common.h" | |
#include "input.h" | |
-#include "touch.h" | |
#include "client.h" | |
#include "vgui_draw.h" | |
-#include "wrect.h" | |
-#ifdef XASH_SDL | |
-#include <SDL.h> | |
-#endif | |
-#ifdef _WIN32 | |
-#include "windows.h" | |
-#endif | |
-Xash_Cursor* in_mousecursor; | |
+#define PRINTSCREEN_ID 1 | |
+#define WND_HEADSIZE wnd_caption // some offset | |
+#define WND_BORDER 3 // sentinel border in pixels | |
+ | |
+HICON in_mousecursor; | |
qboolean in_mouseactive; // false when not focus app | |
+qboolean in_restore_spi; | |
qboolean in_mouseinitialized; | |
-qboolean in_mouse_suspended; | |
int in_mouse_oldbuttonstate; | |
+qboolean in_mouse_suspended; | |
int in_mouse_buttons; | |
- | |
-extern convar_t *vid_fullscreen; | |
+RECT window_rect, real_rect; | |
+uint in_mouse_wheel; | |
+int wnd_caption; | |
static byte scan_to_key[128] = | |
{ | |
@@ -51,15 +47,18 @@ static byte scan_to_key[128] = | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 | |
}; | |
-convar_t *m_enginemouse; | |
-convar_t *m_pitch; | |
-convar_t *m_yaw; | |
- | |
-convar_t *m_enginesens; | |
-convar_t *m_ignore; | |
-convar_t *cl_forwardspeed; | |
-convar_t *cl_sidespeed; | |
-convar_t *cl_backspeed; | |
+// extra mouse buttons | |
+static int mouse_buttons[] = | |
+{ | |
+ MK_LBUTTON, | |
+ MK_RBUTTON, | |
+ MK_MBUTTON, | |
+ MK_XBUTTON1, | |
+ MK_XBUTTON2, | |
+ MK_XBUTTON3, | |
+ MK_XBUTTON4, | |
+ MK_XBUTTON5 | |
+}; | |
/* | |
======= | |
@@ -76,7 +75,7 @@ static int Host_MapKey( int key ) | |
modified = ( key >> 16 ) & 255; | |
if( modified > 127 ) return 0; | |
- if( key & ( 1U << 24 )) | |
+ if( key & ( 1 << 24 )) | |
is_extended = true; | |
result = scan_to_key[modified]; | |
@@ -116,151 +115,46 @@ static int Host_MapKey( int key ) | |
IN_StartupMouse | |
=========== | |
*/ | |
- | |
-#ifdef USE_EVDEV | |
- | |
-#include <fcntl.h> | |
-#include <errno.h> | |
-#include <linux/input.h> | |
- | |
-int evdev_open, mouse_fd, evdev_dx, evdev_dy; | |
- | |
-convar_t *evdev_mousepath; | |
-convar_t *evdev_grab; | |
- | |
- | |
-int KeycodeFromEvdev(int keycode); | |
- | |
-/* | |
-=========== | |
-Evdev_OpenMouse_f | |
-=========== | |
-For shitty systems that cannot provide relative mouse axes | |
-*/ | |
-void Evdev_OpenMouse_f ( void ) | |
-{ | |
- /* Android users can try open all devices starting from last | |
- by listing all of them in script as they cannot write udev rules | |
- for example: | |
- evdev_mousepath /dev/input/event10 | |
- evdev_mouseopen | |
- evdev_mousepath /dev/input/event9 | |
- evdev_mouseopen | |
- evdev_mousepath /dev/input/event8 | |
- evdev_mouseopen | |
- etc | |
- So we will not print annoying messages that it is already open | |
- */ | |
- if ( evdev_open ) return; | |
-#ifdef __ANDROID__ // use root to grant access to evdev | |
- char chmodstr[ 255 ] = "su 0 chmod 777 "; | |
- strcat( chmodstr, evdev_mousepath->string ); | |
- system( chmodstr ); | |
- // allow write input via selinux, need for some lollipop devices | |
- system( "su 0 supolicy --live \"allow appdomain input_device dir { ioctl read getattr search open }\" \"allow appdomain input_device chr_file { ioctl read write getattr lock append open }\"" ); | |
- system( chmodstr ); | |
- system( "su 0 setenforce permissive" ); | |
- system( chmodstr ); | |
-#endif | |
- mouse_fd = open ( evdev_mousepath->string, O_RDONLY | O_NONBLOCK ); | |
- if ( mouse_fd < 0 ) | |
- { | |
- MsgDev( D_ERROR, "Could not open input device %s: %s\n", evdev_mousepath->string, strerror( errno ) ); | |
- return; | |
- } | |
- MsgDev( D_INFO, "Input device %s opened sucessfully\n", evdev_mousepath->string ); | |
- evdev_open = 1; | |
-} | |
-/* | |
-=========== | |
-Evdev_OpenClose_f | |
-=========== | |
-Allow open other mouse | |
-*/ | |
-void Evdev_CloseMouse_f ( void ) | |
-{ | |
- if ( !evdev_open ) return; | |
- evdev_open = 0; | |
- close( mouse_fd ); | |
-} | |
- | |
-void IN_EvdevFrame () | |
-{ | |
- if ( evdev_open ) | |
- { | |
- struct input_event ev; | |
- evdev_dx = evdev_dy = 0; | |
- while ( read( mouse_fd, &ev, 16) == 16 ) | |
- { | |
- if ( ev.type == EV_REL ) | |
- { | |
- switch ( ev.code ) | |
- { | |
- case REL_X: evdev_dx += ev.value; | |
- break; | |
- case REL_Y: evdev_dy += ev.value; | |
- break; | |
- } | |
- } | |
- else if ( ( ev.type == EV_KEY ) && (evdev_grab->value == 1.0 ) ) | |
- { | |
- Key_Event ( KeycodeFromEvdev( ev.code ) , ev.value); | |
- } | |
- } | |
- if( ( evdev_grab->value == 1 ) && ( cls.key_dest != key_game ) ) | |
- { | |
- ioctl( mouse_fd, EVIOCGRAB, (void*) 0); | |
- Key_Event( K_ESCAPE, 0 ); //Do not leave ESC down | |
- } | |
- if(clgame.dllFuncs.pfnLookEvent) | |
- clgame.dllFuncs.pfnLookEvent( -evdev_dx * m_yaw->value, evdev_dy * m_pitch->value ); | |
- else | |
+void IN_StartupMouse( void ) | |
{ | |
- cl.refdef.cl_viewangles[PITCH] += evdev_dy * m_enginesens->value; | |
- cl.refdef.cl_viewangles[PITCH] = bound( -90, cl.refdef.cl_viewangles[PITCH], 90 ); | |
- cl.refdef.cl_viewangles[YAW] -= evdev_dx * m_enginesens->value; | |
- } | |
- } | |
+ if( host.type == HOST_DEDICATED ) return; | |
+ if( Sys_CheckParm( "-nomouse" )) return; | |
+ in_mouse_buttons = 8; | |
+ in_mouseinitialized = true; | |
+ in_mouse_wheel = RegisterWindowMessage( "MSWHEEL_ROLLMSG" ); | |
} | |
-#endif | |
-void IN_StartupMouse( void ) | |
+static qboolean IN_CursorInRect( void ) | |
{ | |
- if( Host_IsDedicated() ) return; | |
-#ifdef __ANDROID__ | |
-#define M_IGNORE "1" | |
-#else | |
-#define M_IGNORE "0" | |
-#endif | |
- m_ignore = Cvar_Get( "m_ignore", M_IGNORE, CVAR_ARCHIVE , "ignore mouse events" ); | |
+ POINT curpos; | |
- // You can use -nomouse argument to prevent using mouse from client | |
- // -noenginemouse will disable all mouse input | |
- if( Sys_CheckParm( "-noenginemouse" )) return; | |
+ if( !in_mouseinitialized || !in_mouseactive ) | |
+ return false; | |
-#if defined XASH_SDL || defined USE_EVDEV | |
- m_enginemouse = Cvar_Get("m_enginemouse", "0", CVAR_ARCHIVE, "Read mouse events in engine instead of client"); | |
- m_enginesens = Cvar_Get("m_enginesens", "0.3", CVAR_ARCHIVE, "Mouse sensitivity, when m_enginemouse enabled"); | |
- m_pitch = Cvar_Get("m_pitch", "0.022", CVAR_ARCHIVE, "Mouse pitch value"); | |
- m_yaw = Cvar_Get("m_yaw", "0.022", CVAR_ARCHIVE, "Mouse yaw value"); | |
-#endif | |
+ // find mouse movement | |
+ GetCursorPos( &curpos ); | |
- in_mouse_buttons = 8; | |
- in_mouseinitialized = true; | |
+ if( curpos.x < real_rect.left + WND_BORDER ) | |
+ return false; | |
+ if( curpos.x > real_rect.right - WND_BORDER * 3 ) | |
+ return false; | |
+ if( curpos.y < real_rect.top + WND_HEADSIZE + WND_BORDER ) | |
+ return false; | |
+ if( curpos.y > real_rect.bottom - WND_BORDER * 3 ) | |
+ return false; | |
+ return true; | |
} | |
static void IN_ActivateCursor( void ) | |
{ | |
if( cls.key_dest == key_menu ) | |
{ | |
-#ifdef XASH_SDL | |
- SDL_SetCursor( in_mousecursor ); | |
-#endif | |
+ SetCursor( in_mousecursor ); | |
} | |
} | |
-void IN_SetCursor( Xash_Cursor* hCursor ) | |
+void IN_SetCursor( HICON hCursor ) | |
{ | |
in_mousecursor = hCursor; | |
@@ -280,24 +174,21 @@ void IN_ToggleClientMouse( int newstate, | |
if( oldstate == key_game ) | |
{ | |
- if( cls.initialized ) | |
clgame.dllFuncs.IN_DeactivateMouse(); | |
} | |
else if( newstate == key_game ) | |
{ | |
// reset mouse pos, so cancel effect in game | |
-#ifdef XASH_SDL | |
- SDL_WarpMouseInWindow( host.hWnd, host.window_center_x, host.window_center_y ); | |
-#endif | |
- if( cls.initialized ) | |
+ SetCursorPos( host.window_center_x, host.window_center_y ); | |
clgame.dllFuncs.IN_ActivateMouse(); | |
} | |
- if( ( newstate == key_menu || newstate == key_console ) && ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo())) | |
+ if( newstate == key_menu && ( !CL_IsBackgroundMap() || CL_IsBackgroundDemo())) | |
{ | |
-#ifdef XASH_SDL | |
- SDL_SetWindowGrab(host.hWnd, SDL_FALSE); | |
-#endif | |
+ in_mouseactive = false; | |
+ ClipCursor( NULL ); | |
+ ReleaseCapture(); | |
+ while( ShowCursor( true ) < 0 ); | |
} | |
} | |
@@ -310,6 +201,7 @@ Called when the window gains focus or ch | |
*/ | |
void IN_ActivateMouse( qboolean force ) | |
{ | |
+ int width, height; | |
static int oldstate; | |
if( !in_mouseinitialized ) | |
@@ -317,16 +209,8 @@ void IN_ActivateMouse( qboolean force ) | |
if( CL_Active() && host.mouse_visible && !force ) | |
return; // VGUI controls | |
-#ifdef USE_EVDEV | |
- if( evdev_open && ( evdev_grab->value == 1 ) && cls.key_dest == key_game ) | |
- { | |
- ioctl( mouse_fd, EVIOCGRAB, (void*) 1); | |
- Key_Event( K_ESCAPE, 0 ); //Do not leave ESC down | |
- } | |
- else | |
-#endif | |
- if( cls.key_dest == key_menu && vid_fullscreen && !vid_fullscreen->integer) | |
+ if( cls.key_dest == key_menu && !Cvar_VariableInteger( "fullscreen" )) | |
{ | |
// check for mouse leave-entering | |
if( !in_mouse_suspended && !UI_MouseInRect( )) | |
@@ -336,16 +220,16 @@ void IN_ActivateMouse( qboolean force ) | |
{ | |
if( in_mouse_suspended ) | |
{ | |
-#ifdef XASH_SDL | |
- SDL_ShowCursor( false ); | |
-#endif | |
+ ClipCursor( NULL ); | |
+ ReleaseCapture(); | |
+ while( ShowCursor( true ) < 0 ); | |
UI_ShowCursor( false ); | |
} | |
} | |
oldstate = in_mouse_suspended; | |
- if( in_mouse_suspended ) | |
+ if( in_mouse_suspended && IN_CursorInRect( )) | |
{ | |
in_mouse_suspended = false; | |
in_mouseactive = false; // re-initialize mouse | |
@@ -361,12 +245,24 @@ void IN_ActivateMouse( qboolean force ) | |
if( cls.key_dest == key_game ) | |
{ | |
clgame.dllFuncs.IN_ActivateMouse(); | |
-#ifdef XASH_SDL | |
- SDL_SetWindowGrab( host.hWnd, SDL_TRUE ); | |
- SDL_GetRelativeMouseState( 0, 0 ); // Reset mouse position | |
-#endif | |
} | |
+ width = GetSystemMetrics( SM_CXSCREEN ); | |
+ height = GetSystemMetrics( SM_CYSCREEN ); | |
+ | |
+ GetWindowRect( host.hWnd, &window_rect ); | |
+ if( window_rect.left < 0 ) window_rect.left = 0; | |
+ if( window_rect.top < 0 ) window_rect.top = 0; | |
+ if( window_rect.right >= width ) window_rect.right = width - 1; | |
+ if( window_rect.bottom >= height - 1 ) window_rect.bottom = height - 1; | |
+ | |
+ host.window_center_x = (window_rect.right + window_rect.left) / 2; | |
+ host.window_center_y = (window_rect.top + window_rect.bottom) / 2; | |
+ SetCursorPos( host.window_center_x, host.window_center_y ); | |
+ | |
+ SetCapture( host.hWnd ); | |
+ ClipCursor( &window_rect ); | |
+ while( ShowCursor( false ) >= 0 ); | |
} | |
/* | |
@@ -378,17 +274,10 @@ Called when the window loses focus | |
*/ | |
void IN_DeactivateMouse( void ) | |
{ | |
-#ifdef USE_EVDEV | |
- if( evdev_open && ( evdev_grab->value == 1 ) ) | |
- { | |
- ioctl( mouse_fd, EVIOCGRAB, (void*) 0); | |
- Key_Event( K_ESCAPE, 0 ); //Do not leave ESC down | |
- } | |
-#endif | |
if( !in_mouseinitialized || !in_mouseactive ) | |
return; | |
- if( cls.key_dest == key_game && cls.initialized ) | |
+ if( cls.key_dest == key_game ) | |
{ | |
clgame.dllFuncs.IN_DeactivateMouse(); | |
} | |
@@ -392,10 +281,11 @@ void IN_DeactivateMouse( void ) | |
{ | |
clgame.dllFuncs.IN_DeactivateMouse(); | |
} | |
+ | |
in_mouseactive = false; | |
-#ifdef XASH_SDL | |
- SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); | |
-#endif | |
+ ClipCursor( NULL ); | |
+ ReleaseCapture(); | |
+ while( ShowCursor( true ) < 0 ); | |
} | |
/* | |
@@ -410,17 +300,10 @@ void IN_MouseMove( void ) | |
if( !in_mouseinitialized || !in_mouseactive || !UI_IsVisible( )) | |
return; | |
- if( m_ignore->value ) | |
- return; | |
- | |
- // Show cursor in UI | |
-#ifdef XASH_SDL | |
- if( UI_IsVisible() ) SDL_ShowCursor( true ); | |
-#endif | |
// find mouse movement | |
-#ifdef XASH_SDL | |
- SDL_GetMouseState( ¤t_pos.x, ¤t_pos.y ); | |
-#endif | |
+ GetCursorPos( ¤t_pos ); | |
+ ScreenToClient( host.hWnd, ¤t_pos ); | |
+ | |
// if the menu is visible, move the menu cursor | |
UI_MouseMove( current_pos.x, current_pos.y ); | |
@@ -435,57 +318,25 @@ IN_MouseEvent | |
void IN_MouseEvent( int mstate ) | |
{ | |
int i; | |
+ | |
if( !in_mouseinitialized || !in_mouseactive ) | |
return; | |
- if( m_ignore->value ) | |
- return; | |
+ | |
if( cls.key_dest == key_game ) | |
{ | |
-#if defined(XASH_SDL) | |
- static qboolean ignore; // igonre mouse warp event | |
- int x, y; | |
- SDL_GetMouseState(&x, &y); | |
- if( host.mouse_visible ) | |
- SDL_ShowCursor( SDL_TRUE ); | |
- else | |
- SDL_ShowCursor( SDL_FALSE ); | |
- if( x < host.window_center_x / 2 || y < host.window_center_y / 2 || x > host.window_center_x + host.window_center_x/2 || y > host.window_center_y + host.window_center_y / 2 ) | |
- { | |
- SDL_WarpMouseInWindow(host.hWnd, host.window_center_x, host.window_center_y); | |
- ignore = 1; // next mouse event will be mouse warp | |
- return; | |
- } | |
- if ( !ignore ) | |
- { | |
- if( !m_enginemouse->integer ) | |
clgame.dllFuncs.IN_MouseEvent( mstate ); | |
- } | |
- else | |
- { | |
- SDL_GetRelativeMouseState( 0, 0 ); // reset relative state | |
- ignore = 0; | |
- } | |
-#endif | |
return; | |
} | |
- else | |
- { | |
-#if defined(XASH_SDL) && !defined(_WIN32) | |
- SDL_SetRelativeMouseMode( SDL_FALSE ); | |
- SDL_ShowCursor( SDL_TRUE ); | |
-#endif | |
- IN_MouseMove(); | |
- } | |
// perform button actions | |
for( i = 0; i < in_mouse_buttons; i++ ) | |
{ | |
- if(( mstate & ( 1U << i )) && !( in_mouse_oldbuttonstate & ( 1U << i ))) | |
+ if(( mstate & ( 1<<i )) && !( in_mouse_oldbuttonstate & ( 1<<i ))) | |
{ | |
Key_Event( K_MOUSE1 + i, true ); | |
} | |
- if(!( mstate & ( 1U << i )) && ( in_mouse_oldbuttonstate & ( 1U << i ))) | |
+ if(!( mstate & ( 1<<i )) && ( in_mouse_oldbuttonstate & ( 1<<i ))) | |
{ | |
Key_Event( K_MOUSE1 + i, false ); | |
} | |
@@ -494,102 +345,6 @@ void IN_MouseEvent( int mstate ) | |
in_mouse_oldbuttonstate = mstate; | |
} | |
-#ifdef XASH_SDL | |
-/* | |
-========================== | |
-SDL Joystick Code | |
-========================== | |
-*/ | |
- | |
-struct sdl_joydada_s | |
-{ | |
- qboolean open; | |
- int num_axes; | |
- char binding[10]; | |
- SDL_Joystick *joy; | |
-} joydata; | |
- | |
- | |
-convar_t *joy_index; | |
-convar_t *joy_binding; | |
-convar_t *joy_pitch; | |
-convar_t *joy_yaw; | |
-convar_t *joy_forward; | |
-convar_t *joy_side; | |
-convar_t *joy_enable; | |
- | |
-void IN_SDL_JoyOpen( void ) | |
-{ | |
- int num; | |
- //if (joydata.joy) SDL_JoystickClose ( joydata.joy ); (crash in sdl on android if used) | |
- joydata.joy = 0; | |
- if (!joy_enable->integer) return; | |
- if( ( num = SDL_NumJoysticks() ) ) | |
- { | |
- MsgDev ( D_INFO, "%d joysticks found\n", num ); | |
- joydata.joy = SDL_JoystickOpen( joy_index->integer ); | |
- if(!joydata.joy) | |
- { | |
- MsgDev ( D_ERROR, "Failed to open joystick!\n"); | |
- } | |
- joydata.num_axes = SDL_JoystickNumAxes( joydata.joy ); | |
- MsgDev ( D_INFO, "Joystick %s has %d axes\n", SDL_JoystickName( joydata.joy ), joydata.num_axes ); | |
- SDL_JoystickEventState( SDL_IGNORE ); | |
- } | |
- joy_enable->modified = false; | |
-} | |
- | |
-void IN_SDL_JoyMove( float frametime, float *forward, float *side, float *pitch, float *yaw ) | |
-{ | |
- int i; | |
- if( joy_enable->modified ) | |
- IN_SDL_JoyOpen(); | |
- if(!joydata.joy) return; | |
- // Extend cvar with zeroes | |
- if(joy_binding->modified) | |
- { | |
- Q_strncpy(joydata.binding, joy_binding->string, 10); | |
- Q_strncat(joydata.binding,"0000000000", joydata.num_axes); | |
- joy_binding->modified = false; | |
- } | |
- SDL_JoystickUpdate(); | |
- for(i = 0; i < joydata.num_axes; i++) | |
- { | |
- signed short value = SDL_JoystickGetAxis( joydata.joy, i ); | |
- if( value <= 3200 && value >= -3200 ) continue; | |
- switch(joy_binding->string[i]) | |
- { | |
- case 'f': *forward -= joy_forward->value/32768.0 * value;break; //must be form -1.0 to 1.0 | |
- case 's': *side += joy_side->value/32768.0 * value;break; | |
- case 'p': *pitch += joy_pitch->value/32768.0 * (float)value * frametime;break; // abs axis rotate is frametime related | |
- case 'y': *yaw -= joy_yaw->value/32768.0 * (float)value * frametime;break; | |
- default:break; | |
- } | |
- } | |
-} | |
- | |
- | |
-void IN_SDL_JoyInit( void ) | |
-{ | |
- joydata.joy = 0; | |
- joy_binding = Cvar_Get( "joy_binding", "sfyp", CVAR_ARCHIVE, "Joystick binding (f/s/p/y)" ); | |
- joy_binding->modified = true; | |
- joy_index = Cvar_Get( "joy_index" ,"0" , CVAR_ARCHIVE, "Joystick number to open" ); | |
- joy_enable = Cvar_Get( "joy_enable" ,"1" , CVAR_ARCHIVE, "Enable joystick" ); | |
- joy_pitch = Cvar_Get( "joy_pitch" ,"200.0" , CVAR_ARCHIVE, "Joystick pitch sensitivity" ); | |
- joy_yaw = Cvar_Get( "joy_yaw" ,"200.0" , CVAR_ARCHIVE, "Joystick yaw sensitivity" ); | |
- joy_side = Cvar_Get( "joy_side" ,"1.0" , CVAR_ARCHIVE, "Joystick side sensitivity" ); | |
- joy_forward = Cvar_Get( "joy_forward" ,"1.0" , CVAR_ARCHIVE, "Joystick forward sensitivity" ); | |
- if( SDL_Init( SDL_INIT_JOYSTICK ) ) | |
- { | |
- MsgDev( D_ERROR, "Joystick: SDL: %s \n", SDL_GetError() ); | |
- return; | |
- } | |
- IN_SDL_JoyOpen(); | |
-} | |
- | |
-#endif | |
- | |
/* | |
=========== | |
IN_Shutdown | |
@@ -609,198 +364,220 @@ IN_Init | |
void IN_Init( void ) | |
{ | |
IN_StartupMouse( ); | |
- | |
- cl_forwardspeed = Cvar_Get( "cl_forwardspeed", "400", CVAR_ARCHIVE | CVAR_CLIENTDLL, "Default forward move speed" ); | |
- cl_backspeed = Cvar_Get( "cl_backspeed", "400", CVAR_ARCHIVE | CVAR_CLIENTDLL, "Default back move speed" ); | |
- cl_sidespeed = Cvar_Get( "cl_sidespeed", "400", CVAR_ARCHIVE | CVAR_CLIENTDLL, "Default side move speed" ); | |
-#ifdef XASH_SDL | |
- if( !Host_IsDedicated() ) | |
- IN_SDL_JoyInit(); | |
-#endif | |
-#ifdef USE_EVDEV | |
- evdev_mousepath = Cvar_Get( "evdev_mousepath", "", 0, "Path for evdev device node"); | |
- evdev_grab = Cvar_Get( "evdev_grab", "0", CVAR_ARCHIVE, "Enable event device grab" ); | |
- Cmd_AddCommand ("evdev_mouseopen", Evdev_OpenMouse_f, "Open device selected by evdev_mousepath"); | |
- Cmd_AddCommand ("evdev_mouseclose", Evdev_CloseMouse_f, "Close current evdev device"); | |
- evdev_open = 0; | |
-#endif | |
} | |
/* | |
-================ | |
-IN_JoyMove | |
- | |
-Common function for engine joystick movement | |
- | |
- -1 < forwardmove < 1, -1 < sidemove < 1 | |
+================== | |
+Host_InputFrame | |
-================ | |
+Called every frame, even if not generating commands | |
+================== | |
*/ | |
- | |
-#define F 1U << 0 // Forward | |
-#define B 1U << 1 // Back | |
-#define L 1U << 2 // Left | |
-#define R 1U << 3 // Right | |
-#define T 1U << 4 // Forward stop | |
-#define S 1U << 5 // Side stop | |
-void IN_JoyAppendMove( usercmd_t *cmd, float forwardmove, float sidemove ) | |
+void Host_InputFrame( void ) | |
{ | |
- static uint moveflags = T | S; | |
+ qboolean shutdownMouse = false; | |
- if( forwardmove ) cmd->forwardmove = forwardmove * cl_forwardspeed->value; | |
- if( sidemove ) cmd->sidemove = sidemove * cl_sidespeed->value; | |
+ rand (); // keep the random time dependent | |
- if( forwardmove ) | |
- moveflags &= ~T; | |
- else if( !( moveflags & T ) ) | |
- { | |
- Cmd_ExecuteString("-back", src_command ); | |
- Cmd_ExecuteString("-forward", src_command ); | |
- moveflags |= T; | |
- } | |
- if( sidemove ) | |
- moveflags &= ~S; | |
- else if( !( moveflags & S ) ) | |
- { | |
- Cmd_ExecuteString("-moveleft", src_command ); | |
- Cmd_ExecuteString("-moveright", src_command ); | |
- moveflags |= S; | |
- } | |
+ Sys_SendKeyEvents (); | |
- if ( forwardmove > 0.7 && !( moveflags & F )) | |
- { | |
- moveflags |= F; | |
- Cmd_ExecuteString( "+forward", src_command ); | |
- } | |
- else if ( forwardmove < 0.7 && ( moveflags & F )) | |
- { | |
- moveflags &= ~F; | |
- Cmd_ExecuteString( "-forward", src_command ); | |
- } | |
- if ( forwardmove < -0.7 && !( moveflags & B )) | |
+ Cbuf_Execute (); | |
+ | |
+ if( host.state == HOST_RESTART ) | |
+ host.state = HOST_FRAME; // restart is finished | |
+ | |
+ if( host.type == HOST_DEDICATED ) | |
{ | |
- moveflags |= B; | |
- Cmd_ExecuteString( "+back", src_command ); | |
+ // let the dedicated server some sleep | |
+ Sys_Sleep( 1 ); | |
} | |
- else if ( forwardmove > -0.7 && ( moveflags & B )) | |
+ else | |
{ | |
- moveflags &= ~B; | |
- Cmd_ExecuteString( "-back", src_command ); | |
- } | |
- if ( sidemove > 0.9 && !( moveflags & R )) | |
+ if( host.state == HOST_NOFOCUS ) | |
{ | |
- moveflags |= R; | |
- Cmd_ExecuteString( "+moveright", src_command ); | |
+ if( Host_ServerState() && CL_IsInGame( )) | |
+ Sys_Sleep( 1 ); // listenserver | |
+ else Sys_Sleep( 20 ); // sleep 20 ms otherwise | |
} | |
- else if ( sidemove < 0.9 && ( moveflags & R )) | |
+ else if( host.state == HOST_SLEEP ) | |
{ | |
- moveflags &= ~R; | |
- Cmd_ExecuteString( "-moveright", src_command ); | |
+ // completely sleep in minimized state | |
+ Sys_Sleep( 20 ); | |
} | |
- if ( sidemove < -0.9 && !( moveflags & L )) | |
- { | |
- moveflags |= L; | |
- Cmd_ExecuteString( "+moveleft", src_command ); | |
} | |
- else if ( sidemove > -0.9 && ( moveflags & L )) | |
+ | |
+ if( !in_mouseinitialized ) | |
+ return; | |
+ | |
+ if( host.state != HOST_FRAME ) | |
{ | |
- moveflags &= ~L; | |
- Cmd_ExecuteString( "-moveleft", src_command ); | |
- } | |
+ IN_DeactivateMouse(); | |
+ return; | |
} | |
-/* | |
-================ | |
-IN_EngineAppendMove | |
+ if( cl.refdef.paused && cls.key_dest == key_game ) | |
+ shutdownMouse = true; // release mouse during pause or console typeing | |
-Called from cl_main.c after generating command in client | |
-================ | |
-*/ | |
-void IN_EngineAppendMove( float frametime, usercmd_t *cmd, qboolean active ) | |
+ if( shutdownMouse && !Cvar_VariableInteger( "fullscreen" )) | |
{ | |
- float forward = 0, side = 0, dpitch = 0, dyaw = 0; | |
- if(clgame.dllFuncs.pfnLookEvent) | |
+ IN_DeactivateMouse(); | |
return; | |
- if(active) | |
- { | |
- float sensitivity = ((float)cl.refdef.fov_x / (float)90.0f); | |
-#ifdef XASH_SDL | |
- IN_SDL_JoyMove( frametime, &forward, &side, &dpitch, &dyaw ); | |
- if( m_enginemouse->integer ) | |
- { | |
- int mouse_x, mouse_y; | |
- SDL_GetRelativeMouseState( &mouse_x, &mouse_y ); | |
- cl.refdef.cl_viewangles[PITCH] += mouse_y * sensitivity; | |
- cl.refdef.cl_viewangles[YAW] -= mouse_x * sensitivity; | |
} | |
-#endif | |
- IN_TouchMove( &forward, &side, &dyaw, &dpitch ); | |
- IN_JoyAppendMove( cmd, forward, side ); | |
- cl.refdef.cl_viewangles[YAW] += dyaw * sensitivity; | |
- cl.refdef.cl_viewangles[PITCH] += dpitch * sensitivity; | |
- cl.refdef.cl_viewangles[PITCH] = bound( -90, cl.refdef.cl_viewangles[PITCH], 90 ); | |
+ IN_ActivateMouse( false ); | |
+ IN_MouseMove(); | |
} | |
- | |
-} | |
/* | |
-================== | |
-Host_InputFrame | |
+==================== | |
+IN_WndProc | |
-Called every frame, even if not generating commands | |
-================== | |
+main window procedure | |
+==================== | |
*/ | |
-void Host_InputFrame( void ) | |
+long IN_WndProc( void *hWnd, uint uMsg, uint wParam, long lParam ) | |
{ | |
- qboolean shutdownMouse = false; | |
- float forward = 0, side = 0, pitch = 0, yaw = 0; | |
+ int i, temp = 0; | |
+ qboolean fActivate; | |
-#ifdef USE_EVDEV | |
- IN_EvdevFrame(); | |
-#endif | |
- if(clgame.dllFuncs.pfnLookEvent) | |
- { | |
- int dx, dy; | |
+ if( uMsg == in_mouse_wheel ) | |
+ uMsg = WM_MOUSEWHEEL; | |
-#ifdef XASH_SDL | |
- IN_SDL_JoyMove( host.frametime, &forward, &side, &pitch, &yaw ); | |
-#ifndef __ANDROID__ | |
- if( in_mouseinitialized ) | |
+ VGUI_SurfaceWndProc( hWnd, uMsg, wParam, lParam ); | |
+ | |
+ switch( uMsg ) | |
{ | |
- SDL_GetRelativeMouseState( &dx, &dy ); | |
- pitch += dy * m_pitch->value, yaw -= dx * m_yaw->value; //mouse speed | |
+ case WM_KILLFOCUS: | |
+ if( Cvar_VariableInteger( "fullscreen" )) | |
+ ShowWindow( host.hWnd, SW_SHOWMINNOACTIVE ); | |
+ break; | |
+ case WM_SETCURSOR: | |
+ IN_ActivateCursor(); | |
+ break; | |
+ case WM_MOUSEWHEEL: | |
+ if( !in_mouseactive ) break; | |
+ if(( short )HIWORD( wParam ) > 0 ) | |
+ { | |
+ Key_Event( K_MWHEELUP, true ); | |
+ Key_Event( K_MWHEELUP, false ); | |
} | |
-#endif | |
-#endif | |
- IN_TouchMove( &forward, &side, &yaw, &pitch ); | |
- clgame.dllFuncs.pfnLookEvent( yaw, pitch ); | |
- clgame.dllFuncs.pfnMoveEvent( forward, side ); | |
+ else | |
+ { | |
+ Key_Event( K_MWHEELDOWN, true ); | |
+ Key_Event( K_MWHEELDOWN, false ); | |
} | |
- Cbuf_Execute (); | |
+ break; | |
+ case WM_CREATE: | |
+ host.hWnd = hWnd; | |
+ GetWindowRect( host.hWnd, &real_rect ); | |
+ RegisterHotKey( host.hWnd, PRINTSCREEN_ID, 0, VK_SNAPSHOT ); | |
+ break; | |
+ case WM_CLOSE: | |
+ Sys_Quit(); | |
+ break; | |
+ case WM_ACTIVATE: | |
+ if( host.state == HOST_SHUTDOWN ) | |
+ break; // no need to activate | |
+ if( host.state != HOST_RESTART ) | |
+ { | |
+ if( HIWORD( wParam )) | |
+ host.state = HOST_SLEEP; | |
+ else if( LOWORD( wParam ) == WA_INACTIVE ) | |
+ host.state = HOST_NOFOCUS; | |
+ else host.state = HOST_FRAME; | |
+ fActivate = (host.state == HOST_FRAME) ? true : false; | |
+ } | |
+ else fActivate = true; // video sucessfully restarted | |
- if( host.state == HOST_RESTART ) | |
- host.state = HOST_FRAME; // restart is finished | |
+ wnd_caption = GetSystemMetrics( SM_CYCAPTION ) + WND_BORDER; | |
- if( !in_mouseinitialized ) | |
- return; | |
+ S_Activate( fActivate, host.hWnd ); | |
+ IN_ActivateMouse( fActivate ); | |
+ Key_ClearStates(); | |
- if( host.state != HOST_FRAME ) | |
+ if( host.state == HOST_FRAME ) | |
{ | |
- IN_DeactivateMouse(); | |
- return; | |
+ SetForegroundWindow( hWnd ); | |
+ ShowWindow( hWnd, SW_RESTORE ); | |
+ } | |
+ else if( Cvar_VariableInteger( "fullscreen" ) && host.state != HOST_RESTART ) | |
+ { | |
+ ShowWindow( hWnd, SW_MINIMIZE ); | |
} | |
+ break; | |
+ case WM_MOVE: | |
+ if( !Cvar_VariableInteger( "fullscreen" )) | |
+ { | |
+ RECT rect; | |
+ int xPos, yPos, style; | |
- if( cl.refdef.paused && cls.key_dest == key_game ) | |
- shutdownMouse = true; // release mouse during pause or console typeing | |
+ xPos = (short)LOWORD( lParam ); // horizontal position | |
+ yPos = (short)HIWORD( lParam ); // vertical position | |
- if( shutdownMouse && !vid_fullscreen->integer ) | |
+ rect.left = rect.top = 0; | |
+ rect.right = rect.bottom = 1; | |
+ style = GetWindowLong( hWnd, GWL_STYLE ); | |
+ AdjustWindowRect( &rect, style, FALSE ); | |
+ | |
+ Cvar_SetFloat( "r_xpos", xPos + rect.left ); | |
+ Cvar_SetFloat( "r_ypos", yPos + rect.top ); | |
+ GetWindowRect( host.hWnd, &real_rect ); | |
+ } | |
+ break; | |
+ case WM_LBUTTONDOWN: | |
+ case WM_LBUTTONUP: | |
+ case WM_RBUTTONDOWN: | |
+ case WM_RBUTTONUP: | |
+ case WM_MBUTTONDOWN: | |
+ case WM_MBUTTONUP: | |
+ case WM_XBUTTONDOWN: | |
+ case WM_XBUTTONUP: | |
+ case WM_MOUSEMOVE: | |
+ for( i = 0; i < in_mouse_buttons; i++ ) | |
{ | |
- IN_DeactivateMouse(); | |
- return; | |
+ if( wParam & mouse_buttons[i] ) | |
+ temp |= (1<<i); | |
+ } | |
+ IN_MouseEvent( temp ); | |
+ break; | |
+ case WM_SYSCOMMAND: | |
+ // never turn screensaver while Xash is active | |
+ if( wParam == SC_SCREENSAVE && host.state != HOST_SLEEP ) | |
+ return 0; | |
+ break; | |
+ case WM_SYSKEYDOWN: | |
+ if( wParam == VK_RETURN ) | |
+ { | |
+ // alt+enter fullscreen switch | |
+ Cvar_SetFloat( "fullscreen", !Cvar_VariableValue( "fullscreen" )); | |
+ return 0; | |
+ } | |
+ // intentional fallthrough | |
+ case WM_KEYDOWN: | |
+ Key_Event( Host_MapKey( lParam ), true ); | |
+ if( Host_MapKey( lParam ) == K_ALT ) | |
+ return 0; // prevent WC_SYSMENU call | |
+ break; | |
+ case WM_SYSKEYUP: | |
+ case WM_KEYUP: | |
+ Key_Event( Host_MapKey( lParam ), false ); | |
+ break; | |
+ case WM_CHAR: | |
+ CL_CharEvent( wParam ); | |
+ break; | |
+ case WM_HOTKEY: | |
+ switch( LOWORD( wParam )) | |
+ { | |
+ case PRINTSCREEN_ID: | |
+ // anti FiEctro system: prevent to write snapshot without Xash version | |
+ Q_strncpy( cls.shotname, "clipboard.bmp", sizeof( cls.shotname )); | |
+ cls.scrshot_action = scrshot_snapshot; // build new frame for screenshot | |
+ host.write_to_clipboard = true; | |
+ cls.envshot_vieworg = NULL; | |
+ break; | |
+ } | |
+ break; | |
} | |
- IN_ActivateMouse( false ); | |
- IN_MouseMove(); | |
+ return DefWindowProc( hWnd, uMsg, wParam, lParam ); | |
} | |
-#endif | |
Только в engine/common: input_evdevkey.c | |
diff --suppress-blank-empty -prudwEZbB engine/common/input.h /mnt/data/Xash3D_original/engine/common/input.h | |
--- engine/common/input.h 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/input.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -25,12 +25,15 @@ INPUT | |
*/ | |
#include "keydefs.h" | |
-#ifdef XASH_SDL | |
-#include <SDL_mouse.h> | |
-typedef SDL_Cursor Xash_Cursor; | |
-#else | |
-typedef void Xash_Cursor; | |
-#endif | |
+ | |
+#define WM_MOUSEWHEEL ( WM_MOUSELAST + 1 ) // message that will be supported by the OS | |
+#define MK_XBUTTON1 0x0020 | |
+#define MK_XBUTTON2 0x0040 | |
+#define MK_XBUTTON3 0x0080 | |
+#define MK_XBUTTON4 0x0100 | |
+#define MK_XBUTTON5 0x0200 | |
+#define WM_XBUTTONUP 0x020C | |
+#define WM_XBUTTONDOWN 0x020B | |
// | |
// input.c | |
@@ -43,7 +46,6 @@ void IN_ActivateMouse( qboolean force ); | |
void IN_DeactivateMouse( void ); | |
void IN_ToggleClientMouse( int newstate, int oldstate ); | |
long IN_WndProc( void *hWnd, uint uMsg, uint wParam, long lParam ); | |
-void IN_SetCursor( Xash_Cursor *hCursor ); | |
-extern qboolean in_mouseinitialized; | |
+void IN_SetCursor( HICON hCursor ); | |
#endif//INPUT_H | |
diff --suppress-blank-empty -prudwEZbB engine/common/keys.c /mnt/data/Xash3D_original/engine/common/keys.c | |
--- engine/common/keys.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/keys.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -12,20 +12,17 @@ but WITHOUT ANY WARRANTY; without even t | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
*/ | |
-#ifndef XASH_DEDICATED | |
+ | |
#include "common.h" | |
#include "input.h" | |
#include "client.h" | |
-#ifdef XASH_SDL | |
-#include <SDL_keyboard.h> | |
-#include <events.h> | |
-#endif | |
+ | |
typedef struct key_s | |
{ | |
qboolean down; | |
int repeats; // if > 1, it is autorepeating | |
const char *binding; | |
-} engine_key_t; | |
+} key_t; | |
typedef struct keyname_s | |
{ | |
@@ -34,7 +31,7 @@ typedef struct keyname_s | |
const char *binding; // default bind | |
} keyname_t; | |
-engine_key_t keys[256]; | |
+key_t keys[256]; | |
keyname_t keynames[] = | |
{ | |
@@ -96,42 +93,7 @@ keyname_t keynames[] = | |
{"KP_MINUS", K_KP_MINUS, "" }, | |
{"KP_PLUS", K_KP_PLUS, "" }, | |
{"PAUSE", K_PAUSE, "pause" }, | |
-{"AUX1", K_AUX1, ""}, | |
-{"AUX2", K_AUX2, ""}, | |
-{"AUX3", K_AUX3, ""}, | |
-{"AUX4", K_AUX4, ""}, | |
-{"AUX5", K_AUX5, ""}, | |
-{"AUX6", K_AUX6, ""}, | |
-{"AUX7", K_AUX7, ""}, | |
-{"AUX8", K_AUX8, ""}, | |
-{"AUX9", K_AUX9, ""}, | |
-{"AUX10", K_AUX10, ""}, | |
-{"AUX11", K_AUX11, ""}, | |
-{"AUX12", K_AUX12, ""}, | |
-{"AUX13", K_AUX13, ""}, | |
-{"AUX14", K_AUX14, ""}, | |
-{"AUX15", K_AUX15, ""}, | |
-{"AUX16", K_AUX16, ""}, | |
-{"AUX17", K_AUX17, ""}, | |
-{"AUX18", K_AUX18, ""}, | |
-{"AUX19", K_AUX19, ""}, | |
-{"AUX20", K_AUX20, ""}, | |
-{"AUX21", K_AUX21, ""}, | |
-{"AUX22", K_AUX22, ""}, | |
-{"AUX23", K_AUX23, ""}, | |
-{"AUX24", K_AUX24, ""}, | |
-{"AUX25", K_AUX25, ""}, | |
-{"AUX26", K_AUX26, ""}, | |
-{"AUX27", K_AUX27, ""}, | |
-{"AUX28", K_AUX28, ""}, | |
-{"AUX29", K_AUX29, ""}, | |
-{"AUX30", K_AUX30, ""}, | |
-{"AUX31", K_AUX31, ""}, | |
-{"AUX32", K_AUX32, ""}, | |
-{"JOY1" , K_JOY1 , ""}, | |
-{"JOY2" , K_JOY2 , ""}, | |
-{"JOY3" , K_JOY3 , ""}, | |
-{"JOY4" , K_JOY4 , ""}, | |
+ | |
// raw semicolon seperates commands | |
{"SEMICOLON", ';', ""}, | |
{NULL, 0, NULL}, | |
@@ -274,22 +236,13 @@ void Key_SetBinding( int keynum, const c | |
{ | |
if( keynum == -1 ) return; | |
- // free old binding | |
+ // free old bindings | |
if( keys[keynum].binding ) | |
{ | |
- // GoldSrc doesn't touch ESC | |
- if( keynum == K_ESCAPE ) return; | |
- | |
- if( host.state != HOST_INIT && Q_stricmp( keys[keynum].binding, binding ) ) | |
- cls.keybind_changed = true; | |
- | |
Mem_Free((char *)keys[keynum].binding ); | |
keys[keynum].binding = NULL; | |
} | |
- // don't bind to empty string | |
- if( !binding[0] ) return; | |
- | |
// allocate memory for new binding | |
keys[keynum].binding = copystring( binding ); | |
} | |
@@ -346,11 +299,6 @@ void Key_Unbind_f( void ) | |
Msg( "\"%s\" isn't a valid key\n", Cmd_Argv( 1 )); | |
return; | |
} | |
- if( b == K_ESCAPE ) | |
- { | |
- Msg( "Can't unbind ESCAPE key\n" ); | |
- return; | |
- } | |
Key_SetBinding( b, "" ); | |
} | |
@@ -365,7 +313,7 @@ void Key_Unbindall_f( void ) | |
for( i = 0; i < 256; i++ ) | |
{ | |
- if( i != K_ESCAPE && keys[i].binding ) | |
+ if( keys[i].binding ) | |
Key_SetBinding( i, "" ); | |
} | |
} | |
@@ -492,8 +440,6 @@ void Key_Init( void ) | |
{ | |
keyname_t *kn; | |
- cls.key_dest = key_console; | |
- | |
// register our functions | |
Cmd_AddCommand( "bind", Key_Bind_f, "binds a command to the specified key in bindmap" ); | |
Cmd_AddCommand( "unbind", Key_Unbind_f, "removes a command on the specified key in bindmap" ); | |
@@ -501,9 +447,8 @@ void Key_Init( void ) | |
Cmd_AddCommand( "resetkeys", Key_Reset_f, "reset all keys to their default values" ); | |
Cmd_AddCommand( "bindlist", Key_Bindlist_f, "display current key bindings" ); | |
Cmd_AddCommand( "makehelp", Key_EnumCmds_f, "write help.txt that contains all console cvars and cmds" ); | |
- Q_memset( keys, 0, sizeof( keys ) ); | |
- // setup default binding. "unbindall" from config.cfg will reset it | |
+ // setup default binding. "unbindall" from config.cfg will be reset it | |
for( kn = keynames; kn->name; kn++ ) Key_SetBinding( kn->keynum, kn->binding ); | |
} | |
@@ -566,18 +511,13 @@ void Key_Event( int key, qboolean down ) | |
{ | |
const char *kb; | |
char cmd[1024]; | |
- //Con_Printf( "Keycode %d\n", key ); | |
- if ( key > 255 || key < 0) | |
- { | |
- MsgDev (D_NOTE, "Keynum %d out of range\n", key); | |
- return; | |
- } | |
+ | |
// update auto-repeat status and BUTTON_ANY status | |
keys[key].down = down; | |
if( down ) | |
{ | |
- //keys[key].repeats++; | |
+ keys[key].repeats++; | |
if( key != K_BACKSPACE && key != K_PAUSE && keys[key].repeats > 1 ) | |
{ | |
@@ -596,17 +536,23 @@ void Key_Event( int key, qboolean down ) | |
// console key is hardcoded, so the user can never unbind it | |
if( key == '`' || key == '~' ) | |
{ | |
- // we are in typing mode, so don't switch to console | |
- if( cls.key_dest == key_message || !down ) | |
+ // we are in typing mode. So don't switch to console | |
+ if( (word)GetKeyboardLayout( 0 ) == (word)0x419 ) | |
+ { | |
+ if( cls.key_dest != key_game ) | |
return; | |
+ } | |
+ if( !down ) return; | |
Con_ToggleConsole_f(); | |
return; | |
} | |
- // escape is always handled specially | |
+ // escape is always handled special | |
if( key == K_ESCAPE && down ) | |
{ | |
+ kb = keys[key].binding; | |
+ | |
switch( cls.key_dest ) | |
{ | |
case key_game: | |
@@ -636,27 +582,6 @@ void Key_Event( int key, qboolean down ) | |
if( cls.key_dest == key_menu ) | |
{ | |
// only non printable keys passed | |
- // shift + click enables text mode (old menu compatibility) | |
- /*if( down && !host.textmode && Key_IsDown( K_SHIFT ) && ( key == 241 ) ) | |
- { | |
- SDLash_EnableTextInput( true ); | |
- return; | |
- } | |
- // and click disables | |
- else if( down && ( key == 241 ) ) | |
- SDLash_EnableTextInput( false ); | |
- */ | |
- if( !menu.use_text_api ) | |
- Key_EnableTextInput( true, false ); | |
- //pass printable chars for old menus | |
- if( !menu.use_text_api && !host.textmode && down && ( key >= 32 ) && ( key <= 'z' ) ) | |
- { | |
- if( Key_IsDown( K_SHIFT ) ) | |
- { | |
- key += 'A'-'a'; | |
- } | |
- UI_CharEvent( key ); | |
- } | |
UI_KeyEvent( key, down ); | |
return; | |
} | |
@@ -679,15 +604,12 @@ void Key_Event( int key, qboolean down ) | |
// distribute the key down event to the apropriate handler | |
if( cls.key_dest == key_game ) | |
{ | |
- if( cls.state == ca_cinematic ) | |
+ if( cls.state == ca_cinematic && ( key != K_ESCAPE || !down )) | |
{ | |
// only escape passed when cinematic is playing | |
// HLFX 0.6 bug: crash in vgui3.dll while press +attack during movie playback | |
- if( key != K_ESCAPE || !down ) | |
return; | |
} | |
- else if( host.mouse_visible ) | |
- return; | |
// send the bound action | |
kb = keys[key].binding; | |
@@ -747,15 +669,6 @@ void Key_Event( int key, qboolean down ) | |
} | |
} | |
-void Key_EnableTextInput( qboolean enable, qboolean force ) | |
-{ | |
-#ifdef XASH_SDL | |
- SDLash_EnableTextInput( enable, force ); | |
-#elif defined(__ANDROID__) | |
- Android_EnableTextInput( enable, force ); | |
-#endif | |
-} | |
- | |
/* | |
========= | |
Key_SetKeyDest | |
@@ -768,27 +681,15 @@ void Key_SetKeyDest( int key_dest ) | |
switch( key_dest ) | |
{ | |
case key_game: | |
- Key_EnableTextInput( false, false ); | |
- if( host_xashds_hacks->value ) | |
- { | |
- Cbuf_Execute(); | |
- if( cl.refdef.paused ) | |
- Cbuf_InsertText("pause\n"); | |
- Cbuf_Execute(); | |
- cl.refdef.paused = 0; | |
- } | |
cls.key_dest = key_game; | |
break; | |
case key_menu: | |
- Key_EnableTextInput( false, false ); | |
cls.key_dest = key_menu; | |
break; | |
case key_console: | |
- Key_EnableTextInput( true, false ); | |
cls.key_dest = key_console; | |
break; | |
case key_message: | |
- Key_EnableTextInput( true, false ); | |
cls.key_dest = key_message; | |
break; | |
default: | |
@@ -831,17 +732,14 @@ Normal keyboard characters, already shif | |
void CL_CharEvent( int key ) | |
{ | |
// the console key should never be used as a char | |
-#ifdef _WIN32 | |
if( key == '`' || key == '~' ) return; | |
-#if 0 | |
if( cls.key_dest == key_console && !Con_Visible( )) | |
{ | |
- if((char)key == '�' || (char)key == '�' ) | |
- return; // don't pass '�' when we open the console | |
+ if((char)key == '�' || (char)key == '�' ) | |
+ return; // don't pass '�' when we open the console | |
} | |
-#endif | |
-#endif | |
+ | |
// distribute the key down event to the apropriate handler | |
if( cls.key_dest == key_console || cls.key_dest == key_message ) | |
{ | |
@@ -852,4 +750,3 @@ void CL_CharEvent( int key ) | |
UI_CharEvent( key ); | |
} | |
} | |
-#endif | |
Только в engine/common: launcher.c | |
diff --suppress-blank-empty -prudwEZbB engine/common/library.c /mnt/data/Xash3D_original/engine/common/library.c | |
--- engine/common/library.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/library.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -13,208 +13,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#define _GNU_SOURCE | |
- | |
#include "common.h" | |
#include "library.h" | |
-#include "filesystem.h" | |
- | |
-char lasterror[1024] = ""; | |
-const char *Com_GetLibraryError() | |
-{ | |
- return lasterror; | |
-} | |
- | |
-void Com_ResetLibraryError() | |
-{ | |
- lasterror[0] = 0; | |
-} | |
- | |
-void Com_PushLibraryError( const char *error ) | |
-{ | |
- Q_strncat( lasterror, error, sizeof( lasterror ) ); | |
- Q_strncat( lasterror, "\n", sizeof( lasterror ) ); | |
-} | |
- | |
-#ifndef _WIN32 | |
- | |
-#ifdef __ANDROID__ | |
-#include "platform/android/dlsym-weak.h" | |
-#endif | |
- | |
- | |
-#ifdef NO_LIBDL | |
- | |
-#ifndef DLL_LOADER | |
-#error Enable at least one dll backend!!! | |
-#endif | |
- | |
-void *dlsym(void *handle, const char *symbol ) | |
-{ | |
- MsgDev( D_NOTE, "dlsym( %p, \"%s\" ): stub\n", handle, symbol ); | |
- return NULL; | |
-} | |
-void *dlopen(const char *name, int flag ) | |
-{ | |
- MsgDev( D_NOTE, "dlopen( \"%s\", %d ): stub\n", name, flag ); | |
- return NULL; | |
-} | |
-int dlclose(void *handle) | |
-{ | |
- MsgDev( D_NOTE, "dlsym( %p ): stub\n", handle ); | |
- return 0; | |
-} | |
-char *dlerror( void ) | |
-{ | |
- return "Loading ELF libraries not supported in this build!\n"; | |
-} | |
-int dladdr( const void *addr, Dl_info *info ) | |
-{ | |
- return 0; | |
-} | |
-#endif | |
- | |
- | |
-void *Com_LoadLibrary( const char *dllname, int build_ordinals_table ) | |
-{ | |
- searchpath_t *search = NULL; | |
- int pack_ind; | |
- char path [MAX_SYSPATH]; | |
- | |
- void *pHandle; | |
- qboolean dll = host.enabledll && ( Q_stristr( dllname, ".dll" ) != 0 ); | |
-#ifdef DLL_LOADER | |
- if(dll) | |
- { | |
- pHandle = Loader_LoadLibrary( dllname ); | |
- if(!pHandle) | |
- { | |
- string errorstring; | |
- Q_snprintf( errorstring, MAX_STRING, "Failed to load dll with dll loader: %s", dllname ); | |
- Com_PushLibraryError( errorstring ); | |
- } | |
- } | |
- else | |
-#endif | |
- { | |
- pHandle = dlopen( dllname, RTLD_LAZY ); | |
- if( !pHandle ) | |
- Com_PushLibraryError(dlerror()); | |
- } | |
- if(!pHandle) | |
- { | |
- search = FS_FindFile( dllname, &pack_ind, true ); | |
- | |
- if( !search ) | |
- { | |
- return NULL; | |
- } | |
- sprintf( path, "%s%s", search->filename, dllname ); | |
- | |
-#ifdef DLL_LOADER | |
- if(dll) | |
- { | |
- pHandle = Loader_LoadLibrary( path ); | |
- if(!pHandle) | |
- { | |
- string errorstring; | |
- Q_snprintf( errorstring, MAX_STRING, "Failed to load dll with dll loader: %s", dllname ); | |
- Com_PushLibraryError( errorstring ); | |
- } | |
- } | |
- else | |
-#endif | |
- { | |
- pHandle = dlopen( path, RTLD_LAZY ); | |
- if( !pHandle ) | |
- Com_PushLibraryError(dlerror()); | |
- } | |
- if(!pHandle) | |
- { | |
- return NULL; | |
- } | |
- } | |
- | |
- return pHandle; | |
-} | |
- | |
-void Com_FreeLibrary( void *hInstance ) | |
-{ | |
-#ifdef DLL_LOADER | |
- void *wm; | |
- if( host.enabledll && (wm = Loader_GetDllHandle( hInstance )) ) | |
- return Loader_FreeLibrary(hInstance); | |
- else | |
-#endif | |
- dlclose( hInstance ); | |
-} | |
- | |
-void *Com_GetProcAddress( void *hInstance, const char *name ) | |
-{ | |
-#ifdef DLL_LOADER | |
- void *wm; | |
- if( host.enabledll && (wm = Loader_GetDllHandle( hInstance )) ) | |
- return Loader_GetProcAddress(hInstance, name); | |
- else | |
-#endif | |
- return dlsym( hInstance, name ); | |
-} | |
- | |
-void *Com_FunctionFromName( void *hInstance, const char *pName ) | |
-{ | |
- void *function; | |
-#ifdef DLL_LOADER | |
- void *wm; | |
- if( host.enabledll && (wm = Loader_GetDllHandle( hInstance )) ) | |
- return Loader_GetProcAddress(hInstance, pName); | |
- else | |
-#endif | |
- function = dlsym( hInstance, pName ); | |
- if(!function) | |
- { | |
-#ifdef __ANDROID__ | |
- // Shitty Android's dlsym don't resolve weak symbols | |
- function = dlsym_weak( hInstance, pName ); | |
- if(!function) | |
-#endif | |
- MsgDev(D_ERROR, "FunctionFromName: Can't get symbol %s: %s\n", pName, dlerror()); | |
- } | |
- return function; | |
-} | |
- | |
-#ifdef XASH_DYNAMIC_DLADDR | |
-int d_dladdr( void *sym, Dl_info *info ) | |
-{ | |
- static int (*dladdr_real) ( void *sym, Dl_info *info ); | |
- | |
- if( !dladdr_real ) | |
- dladdr_real = dlsym( (void*)(size_t)(-1), "dladdr" ); | |
- | |
- Q_memset( info, 0, sizeof( *info ) ); | |
- | |
- if( !dladdr_real ) | |
- return -1; | |
- | |
- return dladdr_real( sym, info ); | |
-} | |
-#endif | |
-const char *Com_NameForFunction( void *hInstance, void *function ) | |
-{ | |
-#ifdef DLL_LOADER | |
- void *wm; | |
- if( host.enabledll && (wm = Loader_GetDllHandle( hInstance )) ) | |
- return Loader_GetFuncName_int(wm, function); | |
- else | |
-#endif | |
- // Note: dladdr() is a glibc extension | |
- { | |
- Dl_info info; | |
- dladdr((void*)function, &info); | |
- return info.dli_sname; | |
- } | |
-} | |
-#else | |
/* | |
--------------------------------------------------------------- | |
@@ -223,11 +24,6 @@ const char *Com_NameForFunction( void *h | |
--------------------------------------------------------------- | |
*/ | |
-#ifndef IMAGE_SIZEOF_BASE_RELOCATION | |
-// Vista SDKs no longer define IMAGE_SIZEOF_BASE_RELOCATION!? | |
-#define IMAGE_SIZEOF_BASE_RELOCATION (sizeof(IMAGE_BASE_RELOCATION)) | |
-#endif | |
- | |
typedef struct | |
{ | |
PIMAGE_NT_HEADERS headers; | |
@@ -675,7 +471,6 @@ library_error: | |
// cleanup | |
if( data ) Mem_Free( data ); | |
MemoryFreeLibrary( result ); | |
- Com_PushLibraryError( errorstring ); | |
MsgDev( D_ERROR, "LoadLibrary: %s\n", errorstring ); | |
return NULL; | |
@@ -955,7 +750,6 @@ table_error: | |
if( f ) FS_Close( f ); | |
if( p_Names ) Mem_Free( p_Names ); | |
FreeNameFuncGlobals( hInst ); | |
- Com_PushLibraryError( errorstring ); | |
MsgDev( D_ERROR, "LoadLibrary: %s\n", errorstring ); | |
return false; | |
@@ -973,21 +767,12 @@ void *Com_LoadLibraryExt( const char *dl | |
dll_user_t *hInst; | |
hInst = FS_FindLibrary( dllname, directpath ); | |
- if( !hInst ) | |
- { | |
- char errorstring[256]; | |
- Q_snprintf( errorstring, 256, "LoadLibraryExt: could not find %s!", dllname ); | |
- Com_PushLibraryError(errorstring); | |
- return NULL; // nothing to load | |
- } | |
+ if( !hInst ) return NULL; // nothing to load | |
if( hInst->custom_loader ) | |
{ | |
if( hInst->encrypted ) | |
{ | |
- char errorstring[256]; | |
- Q_snprintf( errorstring, 256, "couldn't load encrypted library %s", dllname ); | |
- Com_PushLibraryError(errorstring); | |
MsgDev( D_ERROR, "Sys_LoadLibrary: couldn't load encrypted library %s\n", dllname ); | |
return NULL; | |
} | |
@@ -998,9 +783,7 @@ void *Com_LoadLibraryExt( const char *dl | |
if( !hInst->hInstance ) | |
{ | |
- string errorstring; | |
- Q_snprintf( errorstring, MAX_STRING, "LoadLibrary failed for %s:%d", dllname, GetLastError() ); | |
- Com_PushLibraryError( errorstring ); | |
+ MsgDev( D_NOTE, "Sys_LoadLibrary: Loading %s - failed\n", dllname ); | |
Com_FreeLibrary( hInst ); | |
return NULL; | |
} | |
@@ -1010,11 +793,7 @@ void *Com_LoadLibraryExt( const char *dl | |
{ | |
if( !LibraryLoadSymbols( hInst )) | |
{ | |
- string errorstring; | |
- Q_snprintf( errorstring, MAX_STRING, "Failed to build ordinals table for %s", dllname ); | |
- Com_PushLibraryError( errorstring ); | |
- //MsgDev( D_NOTE, "Sys_LoadLibrary: Loading %s - failed\n", dllname ); | |
- | |
+ MsgDev( D_NOTE, "Sys_LoadLibrary: Loading %s - failed\n", dllname ); | |
Com_FreeLibrary( hInst ); | |
return NULL; | |
} | |
@@ -1068,7 +847,7 @@ void Com_FreeLibrary( void *hInstance ) | |
Mem_Free( hInst ); // done | |
} | |
-void *Com_FunctionFromName(void *hInstance, const char *pName) | |
+dword Com_FunctionFromName( void *hInstance, const char *pName ) | |
{ | |
dll_user_t *hInst = (dll_user_t *)hInstance; | |
int i, index; | |
@@ -1081,14 +860,14 @@ void *Com_FunctionFromName(void *hInstan | |
if( !Q_strcmp( pName, hInst->names[i] )) | |
{ | |
index = hInst->ordinals[i]; | |
- return (void*)(hInst->funcs[index] + hInst->funcBase); | |
+ return hInst->funcs[index] + hInst->funcBase; | |
} | |
} | |
// couldn't find the function name to return address | |
return 0; | |
} | |
-const char *Com_NameForFunction( void *hInstance, void * function ) | |
+const char *Com_NameForFunction( void *hInstance, dword function ) | |
{ | |
dll_user_t *hInst = (dll_user_t *)hInstance; | |
int i, index; | |
@@ -1100,10 +879,9 @@ const char *Com_NameForFunction( void *h | |
{ | |
index = hInst->ordinals[i]; | |
- if(( (char*)function - hInst->funcBase ) == hInst->funcs[index] ) | |
+ if(( function - hInst->funcBase ) == hInst->funcs[index] ) | |
return hInst->names[i]; | |
} | |
// couldn't find the function address to return name | |
return NULL; | |
} | |
-#endif | |
diff --suppress-blank-empty -prudwEZbB engine/common/library.h /mnt/data/Xash3D_original/engine/common/library.h | |
--- engine/common/library.h 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/library.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -154,34 +154,8 @@ dll_user_t *FS_FindLibrary( const char * | |
void *Com_LoadLibrary( const char *dllname, int build_ordinals_table ); | |
void *Com_LoadLibraryExt( const char *dllname, int build_ordinals_table, qboolean directpath ); | |
void *Com_GetProcAddress( void *hInstance, const char *name ); | |
-const char *Com_NameForFunction( void *hInstance, void *function ); | |
-void *Com_FunctionFromName( void *hInstance, const char *pName ); | |
+const char *Com_NameForFunction( void *hInstance, dword function ); | |
+dword Com_FunctionFromName( void *hInstance, const char *pName ); | |
void Com_FreeLibrary( void *hInstance ); | |
-void Com_PushLibraryError( const char *error ); | |
-void Com_ResetLibraryError(); | |
-const char *Com_GetLibraryError(); | |
- | |
-#ifdef XASH_DYNAMIC_DLADDR | |
-#define Dl_info d_Dl_info | |
-typedef struct | |
-{ | |
- const char *dli_fname; /* File name of defining object. */ | |
- void *dli_fbase; /* Load address of that object. */ | |
- const char *dli_sname; /* Name of nearest symbol. */ | |
- void *dli_saddr; /* Exact value of nearest symbol. */ | |
-} Dl_info; | |
-int d_dladdr( void *sym, Dl_info *info ); | |
-#define dladdr d_dladdr | |
-#endif | |
- | |
-#ifdef DLL_LOADER // wine-based dll loader | |
-void * Loader_LoadLibrary (const char *name); | |
-void * Loader_GetProcAddress (void *hndl, const char *name); | |
-void Loader_FreeLibrary(void *hndl); | |
-void *Loader_GetDllHandle( void *hndl ); | |
-const char * Loader_GetFuncName( void *hndl, void *func); | |
-const char * Loader_GetFuncName_int( void *wm , void *func); | |
-void *Setup_LDT_Keeper(void); | |
-#endif | |
#endif//LIBRARY_H | |
diff --suppress-blank-empty -prudwEZbB engine/common/mathlib.c /mnt/data/Xash3D_original/engine/common/mathlib.c | |
--- engine/common/mathlib.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/mathlib.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -13,31 +13,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICU | |
GNU General Public License for more details. | |
*/ | |
-#if defined (__linux__) && !defined (__ANDROID__) | |
-//sincosf | |
-#define _GNU_SOURCE | |
-#include <math.h> | |
-#endif | |
#include "common.h" | |
#include "mathlib.h" | |
-#ifdef VECTORIZE_SINCOS | |
- | |
-// Test shown that this is not so effictively | |
-#if defined(__SSE__) || defined(_M_IX86_FP) | |
-#if defined(__SSE2__) || defined(_M_IX86_FP) | |
- #define USE_SSE2 | |
- #endif | |
-#include "sse_mathfun.h" | |
-#endif | |
- | |
- | |
-#if defined(__ARM_NEON__) || defined(__NEON__) | |
- #include "neon_mathfun.h" | |
-#endif | |
- | |
-#endif | |
- | |
vec3_t vec3_origin = { 0, 0, 0 }; | |
/* | |
@@ -180,7 +158,6 @@ SinCos | |
*/ | |
void SinCos( float radians, float *sine, float *cosine ) | |
{ | |
-#if _MSC_VER == 1200 | |
_asm | |
{ | |
fld dword ptr [radians] | |
@@ -192,39 +169,8 @@ void SinCos( float radians, float *sine, | |
fstp dword ptr [edx] | |
fstp dword ptr [eax] | |
} | |
-#else | |
- // I think, better use math.h function, instead of ^ | |
-#if defined (__linux__) && !defined (__ANDROID__) | |
- sincosf(radians, sine, cosine); | |
-#else | |
- *sine = sinf(radians); | |
- *cosine = cosf(radians); | |
-#endif | |
-#endif | |
} | |
-#ifdef VECTORIZE_SINCOS | |
-void SinCosFastVector(float r1, float r2, float r3, float r4, | |
- float *s0, float *s1, float *s2, float *s3, | |
- float *c0, float *c1, float *c2, float *c3) | |
-{ | |
- v4sf rad_vector = {r1, r2, r3, r4}; | |
- v4sf sin_vector, cos_vector; | |
- | |
- sincos_ps(rad_vector, &sin_vector, &cos_vector); | |
- | |
- *s0 = sin_vector[0]; | |
- if(s1) *s1 = sin_vector[1]; | |
- if(s2) *s2 = sin_vector[2]; | |
- if(s3) *s3 = sin_vector[3]; | |
- | |
- *c0 = cos_vector[0]; | |
- if(s1) *c1 = cos_vector[1]; | |
- if(s2) *c2 = cos_vector[2]; | |
- if(s3) *c3 = cos_vector[3]; | |
-} | |
-#endif | |
- | |
float VectorNormalizeLength2( const vec3_t v, vec3_t out ) | |
{ | |
float length, ilength; | |
@@ -265,17 +211,11 @@ AngleVectors | |
*/ | |
void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up ) | |
{ | |
- static float sr, sp, sy, cr, cp, cy; | |
+ float sr, sp, sy, cr, cp, cy; | |
-#ifdef VECTORIZE_SINCOS | |
- SinCosFastVector( DEG2RAD(angles[YAW]), DEG2RAD(angles[PITCH]), DEG2RAD(angles[ROLL]), 0, | |
- &sy, &sp, &sr, NULL, | |
- &cy, &cp, &cr, NULL); | |
-#else | |
SinCos( DEG2RAD( angles[YAW] ), &sy, &cy ); | |
SinCos( DEG2RAD( angles[PITCH] ), &sp, &cp ); | |
SinCos( DEG2RAD( angles[ROLL] ), &sr, &cr ); | |
-#endif | |
if( forward ) | |
{ | |
@@ -492,14 +432,8 @@ AngleQuaternion | |
*/ | |
void AngleQuaternion( const vec3_t angles, vec4_t q ) | |
{ | |
- float sr, sp, sy, cr, cp, cy; | |
- | |
-#ifdef VECTORIZE_SINCOS | |
- SinCosFastVector( angles[2] * 0.5f, angles[1] * 0.5f, angles[0] * 0.5f, 0, | |
- &sy, &sp, &sr, NULL, | |
- &cy, &cp, &cr, NULL); | |
-#else | |
float angle; | |
+ float sr, sp, sy, cr, cp, cy; | |
angle = angles[2] * 0.5f; | |
SinCos( angle, &sy, &cy ); | |
@@ -507,7 +441,6 @@ void AngleQuaternion( const vec3_t angle | |
SinCos( angle, &sp, &cp ); | |
angle = angles[0] * 0.5f; | |
SinCos( angle, &sr, &cr ); | |
-#endif | |
q[0] = sr * cp * cy - cr * sp * sy; // X | |
q[1] = cr * sp * cy + sr * cp * sy; // Y | |
diff --suppress-blank-empty -prudwEZbB engine/common/mathlib.h /mnt/data/Xash3D_original/engine/common/mathlib.h | |
--- engine/common/mathlib.h 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/mathlib.h 2016-08-19 14:21:49.000000000 +0000 | |
@@ -101,10 +101,7 @@ GNU General Public License for more deta | |
#define MakeRGBA( out, x, y, z, w ) Vector4Set( out, x, y, z, w ) | |
#define PlaneDist(point,plane) ((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) | |
#define PlaneDiff(point,plane) (((plane)->type < 3 ? (point)[(plane)->type] : DotProduct((point), (plane)->normal)) - (plane)->dist) | |
-#define boundmax( num, high ) ( (num) < (high) ? (num) : (high) ) | |
-#define boundmin( num, low ) ( (num) >= (low) ? (num) : (low) ) | |
-#define bound( low, num, high ) ( boundmin( boundmax(num, high), low )) | |
-//#define bound( min, num, max ) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min)) | |
+#define bound( min, num, max ) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min)) | |
float rsqrt( float number ); | |
float anglemod( const float a ); | |
@@ -113,11 +110,6 @@ float HalfToFloat( word h ); | |
int SignbitsForPlane( const vec3_t normal ); | |
int NearestPOW( int value, qboolean roundDown ); | |
void SinCos( float radians, float *sine, float *cosine ); | |
-#ifdef VECTORIZE_SINCOS | |
-void SinCosFastVector(float r1, float r2, float r3, float r4, | |
- float *s0, float *s1, float *s2, float *s3, | |
- float *c0, float *c1, float *c2, float *c3); | |
-#endif | |
float VectorNormalizeLength2( const vec3_t v, vec3_t out ); | |
void VectorVectors( const vec3_t forward, vec3_t right, vec3_t up ); | |
void VectorAngles( const float *forward, float *angles ); | |
@@ -142,39 +134,36 @@ float ApproachVal( float target, float v | |
#define Matrix3x4_LoadIdentity( mat ) Matrix3x4_Copy( mat, matrix3x4_identity ) | |
#define Matrix3x4_Copy( out, in ) Q_memcpy( out, in, sizeof( matrix3x4 )) | |
-#define cmatrix3x4 vec4_t *const | |
-#define cmatrix4x4 vec4_t *const | |
- | |
-void Matrix3x4_VectorTransform( cmatrix3x4 in, const float v[3], float out[3] ); | |
-void Matrix3x4_VectorITransform( cmatrix3x4 in, const float v[3], float out[3] ); | |
-void Matrix3x4_VectorRotate( cmatrix3x4 in, const float v[3], float out[3] ); | |
-void Matrix3x4_VectorIRotate( cmatrix3x4 in, const float v[3], float out[3] ); | |
-void Matrix3x4_ConcatTransforms( matrix3x4 out, cmatrix3x4 in1, cmatrix3x4 in2 ); | |
+void Matrix3x4_VectorTransform( const matrix3x4 in, const float v[3], float out[3] ); | |
+void Matrix3x4_VectorITransform( const matrix3x4 in, const float v[3], float out[3] ); | |
+void Matrix3x4_VectorRotate( const matrix3x4 in, const float v[3], float out[3] ); | |
+void Matrix3x4_VectorIRotate( const matrix3x4 in, const float v[3], float out[3] ); | |
+void Matrix3x4_ConcatTransforms( matrix3x4 out, const matrix3x4 in1, const matrix3x4 in2 ); | |
void Matrix3x4_FromOriginQuat( matrix3x4 out, const vec4_t quaternion, const vec3_t origin ); | |
void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_t origin, float scale ); | |
-void Matrix3x4_TransformPositivePlane( cmatrix3x4 in, const vec3_t normal, float d, vec3_t out, float *dist ); | |
+void Matrix3x4_TransformPositivePlane( const matrix3x4 in, const vec3_t normal, float d, vec3_t out, float *dist ); | |
void Matrix3x4_SetOrigin( matrix3x4 out, float x, float y, float z ); | |
-void Matrix3x4_Invert_Simple( matrix3x4 out, cmatrix3x4 in1 ); | |
-void Matrix3x4_OriginFromMatrix( cmatrix3x4 in, float *out ); | |
+void Matrix3x4_Invert_Simple( matrix3x4 out, const matrix3x4 in1 ); | |
+void Matrix3x4_OriginFromMatrix( const matrix3x4 in, float *out ); | |
#define Matrix4x4_LoadIdentity( mat ) Matrix4x4_Copy( mat, matrix4x4_identity ) | |
#define Matrix4x4_Copy( out, in ) Q_memcpy( out, in, sizeof( matrix4x4 )) | |
-void Matrix4x4_VectorTransform( cmatrix4x4 in, const float v[3], float out[3] ); | |
-void Matrix4x4_VectorITransform( cmatrix4x4 in, const float v[3], float out[3] ); | |
-void Matrix4x4_VectorRotate( cmatrix4x4 in, const float v[3], float out[3] ); | |
-void Matrix4x4_VectorIRotate( cmatrix4x4 in, const float v[3], float out[3] ); | |
-void Matrix4x4_ConcatTransforms( matrix4x4 out, cmatrix4x4 in1, cmatrix4x4 in2 ); | |
+void Matrix4x4_VectorTransform( const matrix4x4 in, const float v[3], float out[3] ); | |
+void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out[3] ); | |
+void Matrix4x4_VectorRotate( const matrix4x4 in, const float v[3], float out[3] ); | |
+void Matrix4x4_VectorIRotate( const matrix4x4 in, const float v[3], float out[3] ); | |
+void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ); | |
void Matrix4x4_FromOriginQuat( matrix4x4 out, const vec4_t quaternion, const vec3_t origin ); | |
void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale ); | |
-void Matrix4x4_TransformPositivePlane( cmatrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ); | |
-void Matrix4x4_TransformStandardPlane( cmatrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ); | |
-void Matrix4x4_ConvertToEntity( cmatrix4x4 in, vec3_t angles, vec3_t origin ); | |
+void Matrix4x4_TransformPositivePlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ); | |
+void Matrix4x4_TransformStandardPlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ); | |
+void Matrix4x4_ConvertToEntity( const matrix4x4 in, vec3_t angles, vec3_t origin ); | |
void Matrix4x4_SetOrigin( matrix4x4 out, float x, float y, float z ); | |
-void Matrix4x4_Invert_Simple( matrix4x4 out, cmatrix4x4 in1 ); | |
-void Matrix4x4_OriginFromMatrix( cmatrix4x4 in, float *out ); | |
-void Matrix4x4_Transpose( matrix4x4 out, cmatrix4x4 in1 ); | |
-qboolean Matrix4x4_Invert_Full( matrix4x4 out, cmatrix4x4 in1 ); | |
+void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 ); | |
+void Matrix4x4_OriginFromMatrix( const matrix4x4 in, float *out ); | |
+void Matrix4x4_Transpose( matrix4x4 out, const matrix4x4 in1 ); | |
+qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 ); | |
extern vec3_t vec3_origin; | |
extern const matrix3x4 matrix3x4_identity; | |
diff --suppress-blank-empty -prudwEZbB engine/common/matrixlib.c /mnt/data/Xash3D_original/engine/common/matrixlib.c | |
--- engine/common/matrixlib.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/matrixlib.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -30,14 +30,14 @@ const matrix3x4 matrix3x4_identity = | |
======================================================================== | |
*/ | |
-void Matrix3x4_VectorTransform( cmatrix3x4 in, const float v[3], float out[3] ) | |
+void Matrix3x4_VectorTransform( const matrix3x4 in, const float v[3], float out[3] ) | |
{ | |
out[0] = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2] + in[0][3]; | |
out[1] = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2] + in[1][3]; | |
out[2] = v[0] * in[2][0] + v[1] * in[2][1] + v[2] * in[2][2] + in[2][3]; | |
} | |
-void Matrix3x4_VectorITransform( cmatrix3x4 in, const float v[3], float out[3] ) | |
+void Matrix3x4_VectorITransform( const matrix3x4 in, const float v[3], float out[3] ) | |
{ | |
vec3_t dir; | |
@@ -50,21 +50,21 @@ void Matrix3x4_VectorITransform( cmatrix | |
out[2] = dir[0] * in[0][2] + dir[1] * in[1][2] + dir[2] * in[2][2]; | |
} | |
-void Matrix3x4_VectorRotate( cmatrix3x4 in, const float v[3], float out[3] ) | |
+void Matrix3x4_VectorRotate( const matrix3x4 in, const float v[3], float out[3] ) | |
{ | |
out[0] = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2]; | |
out[1] = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2]; | |
out[2] = v[0] * in[2][0] + v[1] * in[2][1] + v[2] * in[2][2]; | |
} | |
-void Matrix3x4_VectorIRotate( cmatrix3x4 in, const float v[3], float out[3] ) | |
+void Matrix3x4_VectorIRotate( const matrix3x4 in, const float v[3], float out[3] ) | |
{ | |
out[0] = v[0] * in[0][0] + v[1] * in[1][0] + v[2] * in[2][0]; | |
out[1] = v[0] * in[0][1] + v[1] * in[1][1] + v[2] * in[2][1]; | |
out[2] = v[0] * in[0][2] + v[1] * in[1][2] + v[2] * in[2][2]; | |
} | |
-void Matrix3x4_ConcatTransforms( matrix3x4 out, cmatrix3x4 in1, cmatrix3x4 in2 ) | |
+void Matrix3x4_ConcatTransforms( matrix3x4 out, const matrix3x4 in1, const matrix3x4 in2 ) | |
{ | |
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0]; | |
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1]; | |
@@ -87,7 +87,7 @@ void Matrix3x4_SetOrigin( matrix3x4 out, | |
out[2][3] = z; | |
} | |
-void Matrix3x4_OriginFromMatrix( cmatrix3x4 in, float *out ) | |
+void Matrix3x4_OriginFromMatrix( const matrix3x4 in, float *out ) | |
{ | |
out[0] = in[0][3]; | |
out[1] = in[1][3]; | |
@@ -119,18 +119,12 @@ void Matrix3x4_CreateFromEntity( matrix3 | |
if( angles[ROLL] ) | |
{ | |
-#ifdef VECTORIZE_SINCOS | |
- SinCosFastVector( DEG2RAD(angles[YAW]), DEG2RAD(angles[PITCH]), DEG2RAD(angles[ROLL]), 0, | |
- &sy, &sp, &sr, NULL, | |
- &cy, &cp, &cr, NULL); | |
-#else | |
angle = angles[YAW] * (M_PI2 / 360.0f); | |
SinCos( angle, &sy, &cy ); | |
angle = angles[PITCH] * (M_PI2 / 360.0f); | |
SinCos( angle, &sp, &cp ); | |
angle = angles[ROLL] * (M_PI2 / 360.0f); | |
SinCos( angle, &sr, &cr ); | |
-#endif | |
out[0][0] = (cp*cy) * scale; | |
out[0][1] = (sr*sp*cy+cr*-sy) * scale; | |
@@ -147,16 +141,10 @@ void Matrix3x4_CreateFromEntity( matrix3 | |
} | |
else if( angles[PITCH] ) | |
{ | |
-#ifdef VECTORIZE_SINCOS | |
- SinCosFastVector( DEG2RAD(angles[YAW]), DEG2RAD(angles[PITCH]), 0, 0, | |
- &sy, &sp, &sr, NULL, | |
- &cy, &cp, &cr, NULL); | |
-#else | |
angle = angles[YAW] * (M_PI2 / 360.0f); | |
SinCos( angle, &sy, &cy ); | |
angle = angles[PITCH] * (M_PI2 / 360.0f); | |
SinCos( angle, &sp, &cp ); | |
-#endif | |
out[0][0] = (cp*cy) * scale; | |
out[0][1] = (-sy) * scale; | |
@@ -206,7 +194,7 @@ void Matrix3x4_CreateFromEntity( matrix3 | |
} | |
} | |
-void Matrix3x4_TransformPositivePlane( cmatrix3x4 in, const vec3_t normal, float d, vec3_t out, float *dist ) | |
+void Matrix3x4_TransformPositivePlane( const matrix3x4 in, const vec3_t normal, float d, vec3_t out, float *dist ) | |
{ | |
float scale = sqrt( in[0][0] * in[0][0] + in[0][1] * in[0][1] + in[0][2] * in[0][2] ); | |
float iscale = 1.0f / scale; | |
@@ -217,7 +205,7 @@ void Matrix3x4_TransformPositivePlane( c | |
*dist = d * scale + ( out[0] * in[0][3] + out[1] * in[1][3] + out[2] * in[2][3] ); | |
} | |
-void Matrix3x4_Invert_Simple( matrix3x4 out, cmatrix3x4 in1 ) | |
+void Matrix3x4_Invert_Simple( matrix3x4 out, const matrix3x4 in1 ) | |
{ | |
// we only support uniform scaling, so assume the first row is enough | |
// (note the lack of sqrt here, because we're trying to undo the scaling, | |
@@ -258,14 +246,14 @@ const matrix4x4 matrix4x4_identity = | |
======================================================================== | |
*/ | |
-void Matrix4x4_VectorTransform( cmatrix4x4 in, const float v[3], float out[3] ) | |
+void Matrix4x4_VectorTransform( const matrix4x4 in, const float v[3], float out[3] ) | |
{ | |
out[0] = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2] + in[0][3]; | |
out[1] = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2] + in[1][3]; | |
out[2] = v[0] * in[2][0] + v[1] * in[2][1] + v[2] * in[2][2] + in[2][3]; | |
} | |
-void Matrix4x4_VectorITransform( cmatrix4x4 in, const float v[3], float out[3] ) | |
+void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out[3] ) | |
{ | |
vec3_t dir; | |
@@ -278,21 +266,21 @@ void Matrix4x4_VectorITransform( cmatrix | |
out[2] = dir[0] * in[0][2] + dir[1] * in[1][2] + dir[2] * in[2][2]; | |
} | |
-void Matrix4x4_VectorRotate( cmatrix4x4 in, const float v[3], float out[3] ) | |
+void Matrix4x4_VectorRotate( const matrix4x4 in, const float v[3], float out[3] ) | |
{ | |
out[0] = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2]; | |
out[1] = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2]; | |
out[2] = v[0] * in[2][0] + v[1] * in[2][1] + v[2] * in[2][2]; | |
} | |
-void Matrix4x4_VectorIRotate( cmatrix4x4 in, const float v[3], float out[3] ) | |
+void Matrix4x4_VectorIRotate( const matrix4x4 in, const float v[3], float out[3] ) | |
{ | |
out[0] = v[0] * in[0][0] + v[1] * in[1][0] + v[2] * in[2][0]; | |
out[1] = v[0] * in[0][1] + v[1] * in[1][1] + v[2] * in[2][1]; | |
out[2] = v[0] * in[0][2] + v[1] * in[1][2] + v[2] * in[2][2]; | |
} | |
-void Matrix4x4_ConcatTransforms( matrix4x4 out, cmatrix4x4 in1, cmatrix4x4 in2 ) | |
+void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ) | |
{ | |
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0]; | |
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1]; | |
@@ -315,7 +303,7 @@ void Matrix4x4_SetOrigin( matrix4x4 out, | |
out[2][3] = z; | |
} | |
-void Matrix4x4_OriginFromMatrix( cmatrix4x4 in, float *out ) | |
+void Matrix4x4_OriginFromMatrix( const matrix4x4 in, float *out ) | |
{ | |
out[0] = in[0][3]; | |
out[1] = in[1][3]; | |
@@ -348,18 +336,12 @@ void Matrix4x4_CreateFromEntity( matrix4 | |
if( angles[ROLL] ) | |
{ | |
-#ifdef VECTORIZE_SINCOS | |
- SinCosFastVector( DEG2RAD(angles[YAW]), DEG2RAD(angles[PITCH]), DEG2RAD(angles[ROLL]), 0, | |
- &sy, &sp, &sr, NULL, | |
- &cy, &cp, &cr, NULL); | |
-#else | |
angle = angles[YAW] * (M_PI2 / 360.0f); | |
SinCos( angle, &sy, &cy ); | |
angle = angles[PITCH] * (M_PI2 / 360.0f); | |
SinCos( angle, &sp, &cp ); | |
angle = angles[ROLL] * (M_PI2 / 360.0f); | |
SinCos( angle, &sr, &cr ); | |
-#endif | |
out[0][0] = (cp*cy) * scale; | |
out[0][1] = (sr*sp*cy+cr*-sy) * scale; | |
@@ -380,16 +362,10 @@ void Matrix4x4_CreateFromEntity( matrix4 | |
} | |
else if( angles[PITCH] ) | |
{ | |
-#ifdef VECTORIZE_SINCOS | |
- SinCosFastVector( DEG2RAD(angles[YAW]), DEG2RAD(angles[PITCH]), 0, 0, | |
- &sy, &sp, &sr, NULL, | |
- &cy, &cp, &cr, NULL); | |
-#else | |
angle = angles[YAW] * (M_PI2 / 360.0f); | |
SinCos( angle, &sy, &cy ); | |
angle = angles[PITCH] * (M_PI2 / 360.0f); | |
SinCos( angle, &sp, &cp ); | |
-#endif | |
out[0][0] = (cp*cy) * scale; | |
out[0][1] = (-sy) * scale; | |
@@ -451,7 +427,7 @@ void Matrix4x4_CreateFromEntity( matrix4 | |
} | |
} | |
-void Matrix4x4_ConvertToEntity( cmatrix4x4 in, vec3_t angles, vec3_t origin ) | |
+void Matrix4x4_ConvertToEntity( const matrix4x4 in, vec3_t angles, vec3_t origin ) | |
{ | |
float xyDist = sqrt( in[0][0] * in[0][0] + in[1][0] * in[1][0] ); | |
@@ -474,7 +450,7 @@ void Matrix4x4_ConvertToEntity( cmatrix4 | |
origin[2] = in[2][3]; | |
} | |
-void Matrix4x4_TransformPositivePlane( cmatrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ) | |
+void Matrix4x4_TransformPositivePlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ) | |
{ | |
float scale = sqrt( in[0][0] * in[0][0] + in[0][1] * in[0][1] + in[0][2] * in[0][2] ); | |
float iscale = 1.0f / scale; | |
@@ -485,7 +461,7 @@ void Matrix4x4_TransformPositivePlane( c | |
*dist = d * scale + ( out[0] * in[0][3] + out[1] * in[1][3] + out[2] * in[2][3] ); | |
} | |
-void Matrix4x4_TransformStandardPlane( cmatrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ) | |
+void Matrix4x4_TransformStandardPlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist ) | |
{ | |
float scale = sqrt( in[0][0] * in[0][0] + in[0][1] * in[0][1] + in[0][2] * in[0][2] ); | |
float iscale = 1.0f / scale; | |
@@ -496,7 +472,7 @@ void Matrix4x4_TransformStandardPlane( c | |
*dist = d * scale - ( out[0] * in[0][3] + out[1] * in[1][3] + out[2] * in[2][3] ); | |
} | |
-void Matrix4x4_Invert_Simple( matrix4x4 out, cmatrix4x4 in1 ) | |
+void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 ) | |
{ | |
// we only support uniform scaling, so assume the first row is enough | |
// (note the lack of sqrt here, because we're trying to undo the scaling, | |
@@ -528,7 +504,7 @@ void Matrix4x4_Invert_Simple( matrix4x4 | |
out[3][3] = 1.0f; | |
} | |
-void Matrix4x4_Transpose( matrix4x4 out, cmatrix4x4 in1 ) | |
+void Matrix4x4_Transpose( matrix4x4 out, const matrix4x4 in1 ) | |
{ | |
out[0][0] = in1[0][0]; | |
out[0][1] = in1[1][0]; | |
@@ -548,7 +524,7 @@ void Matrix4x4_Transpose( matrix4x4 out, | |
out[3][3] = in1[3][3]; | |
} | |
-qboolean Matrix4x4_Invert_Full( matrix4x4 out, cmatrix4x4 in1 ) | |
+qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 ) | |
{ | |
float *temp; | |
float *r[4]; | |
diff --suppress-blank-empty -prudwEZbB engine/common/model.c /mnt/data/Xash3D_original/engine/common/model.c | |
--- engine/common/model.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/model.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -20,7 +20,7 @@ GNU General Public License for more deta | |
#include "wadfile.h" | |
#include "world.h" | |
#include "gl_local.h" | |
-#include "engine_features.h" | |
+#include "features.h" | |
#include "client.h" | |
#define MAX_SIDE_VERTS 512 // per one polygon | |
@@ -160,8 +160,8 @@ void Mod_PrintBSPFileSizes_f( void ) | |
Msg( "=== Total BSP file data space used: %s ===\n", Q_memprint( totalmemory )); | |
Msg( "World size ( %g %g %g ) units\n", world.size[0], world.size[1], world.size[2] ); | |
- Msg( "Original name: ^1%s\n", worldmodel->name ); | |
- Msg( "Internal name: %s\n", (world.message[0]) ? va( "^2%s", world.message ) : "none" ); | |
+ Msg( "original name: ^1%s\n", worldmodel->name ); | |
+ Msg( "internal name: %s\n", (world.message[0]) ? va( "^2%s", world.message ) : "none" ); | |
} | |
/* | |
@@ -215,7 +215,7 @@ byte *Mod_CompressVis( const byte *in, s | |
if( !worldmodel ) | |
{ | |
- Host_MapDesignError( "Mod_CompressVis: no worldmodel\n" ); | |
+ Host_Error( "Mod_CompressVis: no worldmodel\n" ); | |
return NULL; | |
} | |
@@ -255,7 +255,7 @@ byte *Mod_DecompressVis( const byte *in | |
if( !worldmodel ) | |
{ | |
- Host_MapDesignError( "Mod_DecompressVis: no worldmodel\n" ); | |
+ Host_Error( "Mod_DecompressVis: no worldmodel\n" ); | |
return NULL; | |
} | |
@@ -489,13 +489,12 @@ static void Mod_FreeUserData( model_t *m | |
// already freed? | |
if( !mod || !mod->name[0] ) | |
return; | |
-#ifndef XASH_DEDICATED | |
+ | |
if( clgame.drawFuncs.Mod_ProcessUserData != NULL ) | |
{ | |
// let the client.dll free custom data | |
clgame.drawFuncs.Mod_ProcessUserData( mod, false, NULL ); | |
} | |
-#endif | |
} | |
/* | |
@@ -523,8 +522,6 @@ static void Mod_FreeModel( model_t *mod | |
case mod_brush: | |
Mod_UnloadBrushModel( mod ); | |
break; | |
- default: | |
- break; | |
} | |
} | |
@@ -542,7 +539,7 @@ void Mod_Init( void ) | |
mod_studiocache = Cvar_Get( "r_studiocache", "1", CVAR_ARCHIVE, "enables studio cache for speedup tracing hitboxes" ); | |
r_wadtextures = Cvar_Get( "r_wadtextures", "1", CVAR_ARCHIVE, "completely ignore textures in the wad-files if disabled" ); | |
- if( !Host_IsDedicated() ) | |
+ if( host.type == HOST_NORMAL ) | |
mod_allow_materials = Cvar_Get( "host_allow_materials", "0", CVAR_LATCH|CVAR_ARCHIVE, "allow HD textures" ); | |
else mod_allow_materials = NULL; // no reason to load HD-textures for dedicated server | |
@@ -565,10 +562,10 @@ void Mod_ClearAll( qboolean keep_playerm | |
continue; | |
Mod_FreeModel( mod ); | |
- Q_memset( mod, 0, sizeof( *mod )); | |
+ memset( mod, 0, sizeof( *mod )); | |
} | |
- // g-cont. may just leave unchanged? | |
+ // g-cont. may be just leave unchanged? | |
if( !keep_playermodel ) cm_nummodels = 0; | |
} | |
@@ -608,17 +605,8 @@ static void Mod_LoadSubmodels( const dlu | |
if( l->filelen % sizeof( *in )) Host_Error( "Mod_LoadBModel: funny lump size\n" ); | |
count = l->filelen / sizeof( *in ); | |
- if( count < 1 ) | |
- { | |
- Host_MapDesignError( "Map %s without models\n", loadmodel->name ); | |
- return; | |
- } | |
- if( count > MAX_MAP_MODELS ) | |
- { | |
- Host_MapDesignError( "Map %s has too many models\n", loadmodel->name ); | |
- // recover: cut models count | |
- count = MAX_MAP_MODELS; | |
- } | |
+ if( count < 1 ) Host_Error( "Map %s without models\n", loadmodel->name ); | |
+ if( count > MAX_MAP_MODELS ) Host_Error( "Map %s has too many models\n", loadmodel->name ); | |
// allocate extradata | |
out = Mem_Alloc( loadmodel->mempool, count * sizeof( *out )); | |
@@ -666,26 +654,22 @@ Mod_LoadTextures | |
*/ | |
static void Mod_LoadTextures( const dlump_t *l ) | |
{ | |
- byte *buf; | |
- int *offset; | |
+ dmiptexlump_t *in; | |
texture_t *tx, *tx2; | |
texture_t *anims[10]; | |
texture_t *altanims[10]; | |
int num, max, altmax; | |
char texname[64]; | |
imgfilter_t *filter; | |
- mip_t mt; | |
+ mip_t *mt; | |
int i, j; | |
if( world.loading ) | |
{ | |
// release old sky layers first | |
-#ifndef XASH_DEDICATED | |
GL_FreeTexture( tr.solidskyTexture ); | |
GL_FreeTexture( tr.alphaskyTexture ); | |
- | |
tr.solidskyTexture = tr.alphaskyTexture = 0; | |
-#endif | |
world.texdatasize = l->filelen; | |
world.has_mirrors = false; | |
world.sky_sphere = false; | |
@@ -698,9 +682,9 @@ static void Mod_LoadTextures( const dlum | |
return; | |
} | |
- offset = (int *)(mod_base + l->fileofs); | |
+ in = (void *)(mod_base + l->fileofs); | |
- loadmodel->numtextures = *offset; | |
+ loadmodel->numtextures = in->nummiptex; | |
loadmodel->textures = (texture_t **)Mem_Alloc( loadmodel->mempool, loadmodel->numtextures * sizeof( texture_t* )); | |
for( i = 0; i < loadmodel->numtextures; i++ ) | |
@@ -708,53 +692,49 @@ static void Mod_LoadTextures( const dlum | |
qboolean load_external = false; | |
qboolean load_external_luma = false; | |
- if( *(offset + i + 1) == -1 ) | |
+ if( in->dataofs[i] == -1 ) | |
{ | |
// create default texture (some mods requires this) | |
tx = Mem_Alloc( loadmodel->mempool, sizeof( *tx )); | |
loadmodel->textures[i] = tx; | |
Q_strncpy( tx->name, "*default", sizeof( tx->name )); | |
-#ifndef XASH_DEDICATED | |
tx->gl_texturenum = tr.defaultTexture; | |
tx->width = tx->height = 16; | |
-#endif | |
continue; // missed | |
} | |
- buf = (byte *)offset + *(offset + i + 1); | |
- Q_memcpy( &mt, buf, sizeof(mip_t)); | |
+ mt = (mip_t *)((byte *)in + in->dataofs[i] ); | |
- if( !mt.name[0] ) | |
+ if( !mt->name[0] ) | |
{ | |
MsgDev( D_WARN, "unnamed texture in %s\n", loadmodel->name ); | |
- Q_snprintf( mt.name, sizeof( mt.name ), "miptex_%i", i ); | |
+ Q_snprintf( mt->name, sizeof( mt->name ), "miptex_%i", i ); | |
} | |
tx = Mem_Alloc( loadmodel->mempool, sizeof( *tx )); | |
loadmodel->textures[i] = tx; | |
// convert to lowercase | |
- Q_strnlwr( mt.name, mt.name, sizeof( mt.name )); | |
- Q_strncpy( tx->name, mt.name, sizeof( tx->name )); | |
- Q_memcpy( buf, mt.name, sizeof(mt.name)); | |
+ Q_strnlwr( mt->name, mt->name, sizeof( mt->name )); | |
+ Q_strncpy( tx->name, mt->name, sizeof( tx->name )); | |
filter = R_FindTexFilter( tx->name ); // grab texture filter | |
- tx->width = mt.width; | |
- tx->height = mt.height; | |
-#ifndef XASH_DEDICATED | |
+ tx->width = mt->width; | |
+ tx->height = mt->height; | |
+ | |
// check for multi-layered sky texture | |
- if( world.loading && !Q_strncmp( mt.name, "sky", 3 ) && mt.width == 256 && mt.height == 128 ) | |
+ if( world.loading && !Q_strncmp( mt->name, "sky", 3 ) && mt->width == 256 && mt->height == 128 ) | |
{ | |
if( Mod_AllowMaterials( )) | |
{ | |
// build standard path: "materials/mapname/texname_solid.tga" | |
- Q_snprintf( texname, sizeof( texname ), "materials/%s/%s_solid.tga", modelname, mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "materials/%s/%s_solid.tga", modelname, mt->name ); | |
if( !FS_FileExists( texname, false )) | |
{ | |
// build common path: "materials/mapname/texname_solid.tga" | |
- Q_snprintf( texname, sizeof( texname ), "materials/common/%s_solid.tga", mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "materials/common/%s_solid.tga", mt->name ); | |
if( FS_FileExists( texname, false )) | |
load_external = true; | |
@@ -771,12 +751,12 @@ static void Mod_LoadTextures( const dlum | |
if( tr.solidskyTexture ) | |
{ | |
// build standard path: "materials/mapname/texname_alpha.tga" | |
- Q_snprintf( texname, sizeof( texname ), "materials/%s/%s_alpha.tga", modelname, mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "materials/%s/%s_alpha.tga", modelname, mt->name ); | |
if( !FS_FileExists( texname, false )) | |
{ | |
// build common path: "materials/mapname/texname_alpha.tga" | |
- Q_snprintf( texname, sizeof( texname ), "materials/common/%s_alpha.tga", mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "materials/common/%s_alpha.tga", mt->name ); | |
if( FS_FileExists( texname, false )) | |
load_external = true; | |
@@ -801,7 +781,7 @@ static void Mod_LoadTextures( const dlum | |
} | |
if( !tr.solidskyTexture && !tr.alphaskyTexture ) | |
- R_InitSky( &mt, buf, tx ); // fallback to standard sky | |
+ R_InitSky( mt, tx ); // fallback to standard sky | |
if( tr.solidskyTexture && tr.alphaskyTexture ) | |
world.sky_sphere = true; | |
@@ -815,15 +795,15 @@ static void Mod_LoadTextures( const dlum | |
if( Mod_AllowMaterials( )) | |
{ | |
- if( mt.name[0] == '*' ) mt.name[0] = '!'; // replace unexpected symbol | |
+ if( mt->name[0] == '*' ) mt->name[0] = '!'; // replace unexpected symbol | |
// build standard path: "materials/mapname/texname.tga" | |
- Q_snprintf( texname, sizeof( texname ), "materials/%s/%s.tga", modelname, mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "materials/%s/%s.tga", modelname, mt->name ); | |
if( !FS_FileExists( texname, false )) | |
{ | |
// build common path: "materials/mapname/texname.tga" | |
- Q_snprintf( texname, sizeof( texname ), "materials/common/%s.tga", mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "materials/common/%s.tga", mt->name ); | |
if( FS_FileExists( texname, false )) | |
load_external = true; | |
@@ -837,10 +817,11 @@ static void Mod_LoadTextures( const dlum | |
if( !tx->gl_texturenum ) load_external = false; // for some reasons we can't load HQ texture | |
else MsgDev( D_NOTE, "loading HQ: %s\n", texname ); | |
} | |
+ | |
// trying wad texture (force while r_wadtextures is 1) | |
- if( !load_external && ( r_wadtextures->integer || mt.offsets[0] <= 0 )) | |
+ if( !load_external && ( r_wadtextures->integer || mt->offsets[0] <= 0 )) | |
{ | |
- Q_snprintf( texname, sizeof( texname ), "%s.mip", mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "%s.mip", mt->name ); | |
// check wads in reverse order | |
for( j = wadlist.count - 1; j >= 0; j-- ) | |
@@ -856,16 +837,15 @@ static void Mod_LoadTextures( const dlum | |
} | |
// HQ failed, wad failed, so use internal texture (if present) | |
- if( mt.offsets[0] > 0 && !tx->gl_texturenum ) | |
+ if( mt->offsets[0] > 0 && !tx->gl_texturenum ) | |
{ | |
// NOTE: imagelib detect miptex version by size | |
// 770 additional bytes is indicated custom palette | |
- int size = (int)sizeof( mip_t ) + ((mt.width * mt.height * 85)>>6); | |
+ int size = (int)sizeof( mip_t ) + ((mt->width * mt->height * 85)>>6); | |
if( bmodel_version >= HLBSP_VERSION ) size += sizeof( short ) + 768; | |
- Q_snprintf( texname, sizeof( texname ), "#%s.mip", mt.name ); | |
- Q_memcpy( buf, &mt, sizeof( mt ) ); | |
- tx->gl_texturenum = GL_LoadTexture( texname, buf, size, 0, filter ); | |
+ Q_snprintf( texname, sizeof( texname ), "#%s.mip", mt->name ); | |
+ tx->gl_texturenum = GL_LoadTexture( texname, (byte *)mt, size, 0, filter ); | |
} | |
} | |
@@ -875,12 +855,12 @@ static void Mod_LoadTextures( const dlum | |
if( load_external ) | |
{ | |
// build standard luma path: "materials/mapname/texname_luma.tga" | |
- Q_snprintf( texname, sizeof( texname ), "materials/%s/%s_luma.tga", modelname, mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "materials/%s/%s_luma.tga", modelname, mt->name ); | |
if( !FS_FileExists( texname, false )) | |
{ | |
// build common path: "materials/mapname/texname_luma.tga" | |
- Q_snprintf( texname, sizeof( texname ), "materials/common/%s_luma.tga", mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "materials/common/%s_luma.tga", mt->name ); | |
if( FS_FileExists( texname, false )) | |
load_external_luma = true; | |
@@ -892,21 +872,21 @@ static void Mod_LoadTextures( const dlum | |
if( R_GetTexture( tx->gl_texturenum )->flags & TF_HAS_LUMA || load_external_luma ) | |
{ | |
if( !load_external_luma ) | |
- Q_snprintf( texname, sizeof( texname ), "#%s_luma.mip", mt.name ); | |
+ Q_snprintf( texname, sizeof( texname ), "#%s_luma.mip", mt->name ); | |
else MsgDev( D_NOTE, "loading luma HQ: %s\n", texname ); | |
- if( mt.offsets[0] > 0 && !load_external_luma ) | |
+ if( mt->offsets[0] > 0 && !load_external_luma ) | |
{ | |
// NOTE: imagelib detect miptex version by size | |
// 770 additional bytes is indicated custom palette | |
- int size = (int)sizeof( mip_t ) + ((mt.width * mt.height * 85)>>6); | |
+ int size = (int)sizeof( mip_t ) + ((mt->width * mt->height * 85)>>6); | |
if( bmodel_version >= HLBSP_VERSION ) size += sizeof( short ) + 768; | |
- tx->fb_texturenum = GL_LoadTexture( texname, buf, size, TF_NOMIPMAP|TF_MAKELUMA, NULL ); | |
+ tx->fb_texturenum = GL_LoadTexture( texname, (byte *)mt, size, TF_NOMIPMAP|TF_MAKELUMA, NULL ); | |
} | |
else | |
{ | |
- fs_offset_t srcSize = 0; | |
+ size_t srcSize = 0; | |
byte *src = NULL; | |
// NOTE: we can't loading it from wad as normal because _luma texture doesn't exist | |
@@ -928,7 +908,7 @@ static void Mod_LoadTextures( const dlum | |
} | |
// okay, loading it from wad or hi-res version | |
- tx->fb_texturenum = GL_LoadTexture( texname, src, (size_t)srcSize, TF_NOMIPMAP|TF_MAKELUMA, NULL ); | |
+ tx->fb_texturenum = GL_LoadTexture( texname, src, srcSize, TF_NOMIPMAP|TF_MAKELUMA, NULL ); | |
if( src ) Mem_Free( src ); | |
if( !tx->fb_texturenum && load_external_luma ) | |
@@ -945,7 +925,6 @@ static void Mod_LoadTextures( const dlum | |
GL_SetTextureType( tx->gl_texturenum, TEX_BRUSH ); | |
GL_SetTextureType( tx->fb_texturenum, TEX_BRUSH ); | |
} | |
-#endif | |
} | |
// sequence the animations | |
@@ -980,10 +959,7 @@ static void Mod_LoadTextures( const dlum | |
altanims[altmax] = tx; | |
altmax++; | |
} | |
- else | |
- { | |
- Host_MapDesignError( "Mod_LoadTextures: bad animating texture %s\n", tx->name ); | |
- } | |
+ else Host_Error( "Mod_LoadTextures: bad animating texture %s\n", tx->name ); | |
for( j = i + 1; j < loadmodel->numtextures; j++ ) | |
{ | |
@@ -1009,18 +985,14 @@ static void Mod_LoadTextures( const dlum | |
if( num + 1 > altmax ) | |
altmax = num + 1; | |
} | |
- else Host_MapDesignError( "Mod_LoadTextures: bad animating texture %s\n", tx->name ); | |
+ else Host_Error( "Mod_LoadTextures: bad animating texture %s\n", tx->name ); | |
} | |
// link them all together | |
for( j = 0; j < max; j++ ) | |
{ | |
tx2 = anims[j]; | |
- if( !tx2 ) | |
- { | |
- Host_MapDesignError( "Mod_LoadTextures: missing frame %i of %s\n", j, tx->name ); | |
- continue; | |
- } | |
+ if( !tx2 ) Host_Error( "Mod_LoadTextures: missing frame %i of %s\n", j, tx->name ); | |
tx2->anim_total = max * ANIM_CYCLE; | |
tx2->anim_min = j * ANIM_CYCLE; | |
tx2->anim_max = (j + 1) * ANIM_CYCLE; | |
@@ -1031,11 +1003,7 @@ static void Mod_LoadTextures( const dlum | |
for( j = 0; j < altmax; j++ ) | |
{ | |
tx2 = altanims[j]; | |
- if( !tx2 ) | |
- { | |
- Host_MapDesignError( "Mod_LoadTextures: missing frame %i of %s\n", j, tx->name ); | |
- continue; | |
- } | |
+ if( !tx2 ) Host_Error( "Mod_LoadTextures: missing frame %i of %s\n", j, tx->name ); | |
tx2->anim_total = altmax * ANIM_CYCLE; | |
tx2->anim_min = j * ANIM_CYCLE; | |
tx2->anim_max = (j+1) * ANIM_CYCLE; | |
@@ -1066,10 +1034,7 @@ static void Mod_LoadTextures( const dlum | |
anims[max] = tx; | |
max++; | |
} | |
- else | |
- { | |
- Host_MapDesignError( "Mod_LoadTextures: bad detail texture %s\n", tx->name ); | |
- } | |
+ else Host_Error( "Mod_LoadTextures: bad detail texture %s\n", tx->name ); | |
for( j = i + 1; j < loadmodel->numtextures; j++ ) | |
{ | |
@@ -1088,18 +1053,14 @@ static void Mod_LoadTextures( const dlum | |
if( num+1 > max ) | |
max = num + 1; | |
} | |
- else Host_MapDesignError( "Mod_LoadTextures: bad detail texture %s\n", tx->name ); | |
+ else Host_Error( "Mod_LoadTextures: bad detail texture %s\n", tx->name ); | |
} | |
// link them all together | |
for( j = 0; j < max; j++ ) | |
{ | |
tx2 = anims[j]; | |
- if( !tx2 ) | |
- { | |
- Host_MapDesignError( "Mod_LoadTextures: missing frame %i of %s\n", j, tx->name ); | |
- continue; | |
- } | |
+ if( !tx2 ) Host_Error( "Mod_LoadTextures: missing frame %i of %s\n", j, tx->name ); | |
tx2->anim_total = -( max * ANIM_CYCLE ); // to differentiate from animations | |
tx2->anim_min = j * ANIM_CYCLE; | |
tx2->anim_max = (j + 1) * ANIM_CYCLE; | |
@@ -1133,11 +1094,8 @@ static void Mod_LoadTexInfo( const dlump | |
for( i = 0; i < count; i++, in++, out++ ) | |
{ | |
- for( j = 0; j < 4; j++ ) | |
- { | |
+ for( j = 0; j < 8; j++ ) | |
out->vecs[0][j] = in->vecs[0][j]; | |
- out->vecs[1][j] = in->vecs[1][j]; | |
- } | |
len1 = VectorLength( out->vecs[0] ); | |
len2 = VectorLength( out->vecs[1] ); | |
@@ -1168,7 +1126,6 @@ static void Mod_LoadDeluxemap( void ) | |
char path[64]; | |
int iCompare; | |
byte *in; | |
- fs_offset_t filesize; | |
if( !world.loading ) return; // only world can have deluxedata | |
@@ -1181,7 +1138,7 @@ static void Mod_LoadDeluxemap( void ) | |
Q_snprintf( path, sizeof( path ), "maps/%s.dlit", modelname ); | |
- // make sure that deluxemap is actual | |
+ // make sure what deluxemap is actual | |
if( !COM_CompareFileTime( path, loadmodel->name, &iCompare )) | |
{ | |
world.deluxedata = NULL; | |
@@ -1189,11 +1146,10 @@ static void Mod_LoadDeluxemap( void ) | |
return; | |
} | |
- if( iCompare < 0 ) // this may happen if level-designer used -onlyents key for hlcsg | |
- MsgDev( D_WARN, "Mod_LoadDeluxemap: %s is probably out of date\n", path ); | |
+ if( iCompare < 0 ) // this may happens if level-designer used -onlyents key for hlcsg | |
+ MsgDev( D_WARN, "Mod_LoadDeluxemap: %s probably is out of date\n", path ); | |
- in = FS_LoadFile( path, &filesize, false ); | |
- world.vecdatasize = filesize; | |
+ in = FS_LoadFile( path, &world.vecdatasize, false ); | |
ASSERT( in != NULL ); | |
@@ -1273,7 +1229,7 @@ static void Mod_LoadLighting( const dlum | |
break; | |
} | |
- // also try to load deluxemap | |
+ // try to loading deluxemap too | |
Mod_LoadDeluxemap (); | |
} | |
@@ -1302,10 +1258,7 @@ static void Mod_CalcSurfaceExtents( msur | |
e = loadmodel->surfedges[surf->firstedge + i]; | |
if( e >= loadmodel->numedges || e <= -loadmodel->numedges ) | |
- { | |
- Host_MapDesignError( "Mod_CalcSurfaceBounds: bad edge\n" ); | |
- continue; | |
- } | |
+ Host_Error( "Mod_CalcSurfaceBounds: bad edge\n" ); | |
if( e >= 0 ) v = &loadmodel->vertexes[loadmodel->edges[e].v[0]]; | |
else v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]]; | |
@@ -1350,10 +1303,7 @@ static void Mod_CalcSurfaceBounds( msurf | |
e = loadmodel->surfedges[surf->firstedge + i]; | |
if( e >= loadmodel->numedges || e <= -loadmodel->numedges ) | |
- { | |
- Host_MapDesignError( "Mod_CalcSurfaceBounds: bad edge\n" ); | |
- return; | |
- } | |
+ Host_Error( "Mod_CalcSurfaceBounds: bad edge\n" ); | |
if( e >= 0 ) v = &loadmodel->vertexes[loadmodel->edges[e].v[0]]; | |
else v = &loadmodel->vertexes[loadmodel->edges[-e].v[1]]; | |
@@ -1396,7 +1346,7 @@ static void Mod_BuildPolygon( mextrasurf | |
VectorCopy( surf->texinfo->vecs[0], tangent ); | |
VectorNegate( surf->texinfo->vecs[1], binormal ); | |
- VectorNormalize( normal ); // g-cont. is this even needed? | |
+ VectorNormalize( normal ); // g-cont. this is even needed? | |
VectorNormalize( tangent ); | |
VectorNormalize( binormal ); | |
@@ -1477,8 +1427,6 @@ static void Mod_SubdividePolygon( mextra | |
byte *buffer; | |
msurfmesh_t *mesh; | |
- Q_memset( dists, 0, MAX_SIDE_VERTS * sizeof( float ) ); | |
- | |
ClearBounds( mins, maxs ); | |
for( i = 0, v = verts; i < numVerts; i++, v += 3 ) | |
@@ -1945,7 +1893,7 @@ static void Mod_LoadSurfaces( const dlum | |
out->samples = loadmodel->lightdata + (in->lightofs / 3); | |
else out->samples = loadmodel->lightdata + in->lightofs; | |
- // also setup deluxemap if present | |
+ // if deluxemap is present setup it too | |
if( world.deluxedata ) | |
info->deluxemap = world.deluxedata + (in->lightofs / 3); | |
} | |
@@ -2074,8 +2022,7 @@ static void Mod_LoadMarkSurfaces( const | |
{ | |
j = in[i]; | |
if( j < 0 || j >= loadmodel->numsurfaces ) | |
- Host_MapDesignError( "Mod_LoadMarkFaces: bad surface number in '%s'\n", loadmodel->name ); | |
- else | |
+ Host_Error( "Mod_LoadMarkFaces: bad surface number in '%s'\n", loadmodel->name ); | |
out[i] = loadmodel->surfaces + j; | |
} | |
} | |
@@ -2192,7 +2139,7 @@ static void Mod_LoadLeafs( const dlump_t | |
} | |
if( loadmodel->leafs[0].contents != CONTENTS_SOLID ) | |
- Host_MapDesignError( "Mod_LoadLeafs: Map %s has leaf 0 is not CONTENTS_SOLID\n", loadmodel->name ); | |
+ Host_Error( "Mod_LoadLeafs: Map %s has leaf 0 is not CONTENTS_SOLID\n", loadmodel->name ); | |
} | |
/* | |
@@ -2302,12 +2249,10 @@ static void Mod_LoadEntities( const dlum | |
string wadpath; | |
// parse wad pathes | |
- while( path && *path ) | |
+ while( path ) | |
{ | |
char *end = Q_strchr( path, ';' ); | |
if( !end ) | |
- end = path + Q_strlen( path ); | |
- if( !end ) | |
{ | |
// if specified only once wad | |
if( !wadlist.count ) | |
@@ -2325,9 +2270,9 @@ static void Mod_LoadEntities( const dlum | |
else if( !Q_stricmp( keyname, "message" )) | |
Q_strncpy( world.message, token, sizeof( world.message )); | |
} | |
- } | |
return; // all done | |
} | |
+} | |
/* | |
================= | |
@@ -2573,7 +2518,7 @@ void Mod_CalcPHS( void ) | |
int hcount, vcount; | |
int i, j, k, l, index, num; | |
int rowbytes, rowwords; | |
- int bitbyte, rowsize = 0; | |
+ int bitbyte, rowsize; | |
int *visofs, total_size = 0; | |
byte *vismap, *vismap_p; | |
byte *uncompressed_vis; | |
@@ -2653,7 +2598,7 @@ void Mod_CalcPHS( void ) | |
} | |
// compress PHS data back | |
- comp = Mod_CompressVis( (byte *)dest, (size_t *)&rowsize ); | |
+ comp = Mod_CompressVis( (byte *)dest, &rowsize ); | |
visofs[i] = vismap_p - vismap; // leaf 0 is a common solid | |
total_size += rowsize; | |
@@ -2711,7 +2656,6 @@ void Mod_UnloadBrushModel( model_t *mod | |
if( mod->name[0] != '*' ) | |
{ | |
-#ifndef XASH_DEDICATED | |
for( i = 0; i < mod->numtextures; i++ ) | |
{ | |
tx = mod->textures[i]; | |
@@ -2721,7 +2665,7 @@ void Mod_UnloadBrushModel( model_t *mod | |
GL_FreeTexture( tx->gl_texturenum ); // main texture | |
GL_FreeTexture( tx->fb_texturenum ); // luma texture | |
} | |
-#endif | |
+ | |
Mem_FreePool( &mod->mempool ); | |
} | |
@@ -2760,7 +2704,7 @@ static void Mod_LoadBrushModel( model_t | |
sample_size = 8; | |
break; | |
default: | |
- MsgDev( D_ERROR, "%s has wrong version number (%i should be %i)\n", loadmodel->name, i, HLBSP_VERSION ); | |
+ MsgDev( D_ERROR, "%s has wrong version number (%i should be %i)", loadmodel->name, i, HLBSP_VERSION ); | |
return; | |
} | |
@@ -2772,8 +2716,8 @@ static void Mod_LoadBrushModel( model_t | |
} | |
else if( world.lm_sample_size != sample_size ) | |
{ | |
- // can't mix world and bmodels with different sample sizes! | |
- MsgDev( D_ERROR, "%s has wrong version number (%i should be %i)\n", loadmodel->name, i, world.version ); | |
+ // can't mixing world and bmodels with different sample sizes! | |
+ MsgDev( D_ERROR, "%s has wrong version number (%i should be %i)", loadmodel->name, i, world.version ); | |
return; | |
} | |
bmodel_version = i; // share it | |
@@ -2930,10 +2874,7 @@ model_t *Mod_FindName( const char *filen | |
} | |
} | |
- if( !create ) | |
- { | |
- return NULL; | |
- } | |
+ if( !create ) return NULL; | |
// find a free model slot spot | |
for( i = 0, mod = cm_models; i < cm_nummodels; i++, mod++ ) | |
@@ -2967,7 +2908,7 @@ model_t *Mod_LoadModel( model_t *mod, qb | |
if( !mod ) | |
{ | |
- if( crash ) Host_MapDesignError( "Mod_ForName: NULL model\n" ); | |
+ if( crash ) Host_Error( "Mod_ForName: NULL model\n" ); | |
else MsgDev( D_ERROR, "Mod_ForName: NULL model\n" ); | |
return NULL; | |
} | |
@@ -2984,22 +2925,14 @@ model_t *Mod_LoadModel( model_t *mod, qb | |
if( !buf ) | |
{ | |
- // Try to load this model with lowered file name | |
- char *loweredName = FS_ToLowerCase( tempname ); | |
- buf = FS_LoadFile( loweredName, NULL, false ); | |
- free(loweredName); | |
- if( !buf ) | |
- { | |
Q_memset( mod, 0, sizeof( model_t )); | |
- if( crash ) Host_MapDesignError( "Mod_ForName: %s couldn't load\n", tempname ); | |
+ if( crash ) Host_Error( "Mod_ForName: %s couldn't load\n", tempname ); | |
else MsgDev( D_ERROR, "Mod_ForName: %s couldn't load\n", tempname ); | |
return NULL; | |
} | |
- } | |
- | |
FS_FileBase( mod->name, modelname ); | |
MsgDev( D_NOTE, "Mod_LoadModel: %s\n", mod->name ); | |
@@ -3023,7 +2956,7 @@ model_t *Mod_LoadModel( model_t *mod, qb | |
break; | |
default: | |
Mem_Free( buf ); | |
- if( crash ) Host_MapDesignError( "Mod_ForName: %s unknown format\n", tempname ); | |
+ if( crash ) Host_Error( "Mod_ForName: %s unknown format\n", tempname ); | |
else MsgDev( D_ERROR, "Mod_ForName: %s unknown format\n", tempname ); | |
return NULL; | |
} | |
@@ -3033,18 +2966,17 @@ model_t *Mod_LoadModel( model_t *mod, qb | |
Mod_FreeModel( mod ); | |
Mem_Free( buf ); | |
- if( crash ) Host_MapDesignError( "Mod_ForName: %s couldn't load\n", tempname ); | |
+ if( crash ) Host_Error( "Mod_ForName: %s couldn't load\n", tempname ); | |
else MsgDev( D_ERROR, "Mod_ForName: %s couldn't load\n", tempname ); | |
return NULL; | |
} | |
-#ifndef XASH_DEDICATED | |
else if( clgame.drawFuncs.Mod_ProcessUserData != NULL ) | |
{ | |
// let the client.dll load custom data | |
clgame.drawFuncs.Mod_ProcessUserData( mod, true, buf ); | |
} | |
-#endif | |
+ | |
Mem_Free( buf ); | |
return mod; | |
@@ -3116,7 +3048,7 @@ void Mod_LoadWorld( const char *name, ui | |
// load the newmap | |
world.loading = true; | |
worldmodel = Mod_ForName( name, true ); | |
- CRC32_MapFile( (dword *)&world.checksum, worldmodel->name, multiplayer ); | |
+ CRC32_MapFile( &world.checksum, worldmodel->name, multiplayer ); | |
world.loading = false; | |
if( checksum ) *checksum = world.checksum; | |
@@ -3241,8 +3173,7 @@ void Mod_LoadCacheFile( const char *file | |
{ | |
byte *buf; | |
string name; | |
- size_t i, j; | |
- fs_offset_t size; | |
+ size_t i, j, size; | |
ASSERT( cu != NULL ); | |
@@ -3259,11 +3190,7 @@ void Mod_LoadCacheFile( const char *file | |
name[j] = '\0'; | |
buf = FS_LoadFile( name, &size, false ); | |
- if( !buf || !size ) | |
- { | |
- Host_MapDesignError( "LoadCacheFile: ^1can't load %s^7\n", filename ); | |
- return; | |
- } | |
+ if( !buf || !size ) Host_Error( "LoadCacheFile: ^1can't load %s^7\n", filename ); | |
cu->data = Mem_Alloc( com_studiocache, size ); | |
Q_memcpy( cu->data, buf, size ); | |
Mem_Free( buf ); | |
diff --suppress-blank-empty -prudwEZbB engine/common/mod_studio.c /mnt/data/Xash3D_original/engine/common/mod_studio.c | |
--- engine/common/mod_studio.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/mod_studio.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -207,15 +207,11 @@ hull_t *Mod_HullForStudio( model_t *mode | |
mstudiocache_t *bonecache; | |
mstudiobbox_t *phitbox; | |
int i, j; | |
- qboolean bSkipShield = 0; | |
ASSERT( numhitboxes ); | |
*numhitboxes = 0; // assume error | |
- if((sv_skipshield->integer == 1 && pEdict && pEdict->v.gamestate == 1) || sv_skipshield->integer == 2) | |
- bSkipShield = 1; | |
- | |
if( mod_studiocache->integer ) | |
{ | |
bonecache = Mod_CheckStudioCache( model, frame, sequence, angles, origin, size, pcontroller, pblending ); | |
@@ -255,16 +251,16 @@ hull_t *Mod_HullForStudio( model_t *mode | |
Mod_SetStudioHullPlane( &studio_planes[j+4], phitbox[i].bone, 2, phitbox[i].bbmax[2] ); | |
Mod_SetStudioHullPlane( &studio_planes[j+5], phitbox[i].bone, 2, phitbox[i].bbmin[2] ); | |
- studio_planes[j+0].dist += DotProductFabs( studio_planes[j+0].normal, size ); | |
- studio_planes[j+1].dist -= DotProductFabs( studio_planes[j+1].normal, size ); | |
- studio_planes[j+2].dist += DotProductFabs( studio_planes[j+2].normal, size ); | |
- studio_planes[j+3].dist -= DotProductFabs( studio_planes[j+3].normal, size ); | |
- studio_planes[j+4].dist += DotProductFabs( studio_planes[j+4].normal, size ); | |
- studio_planes[j+5].dist -= DotProductFabs( studio_planes[j+5].normal, size ); | |
+ studio_planes[j+0].dist += DotProductAbs( studio_planes[j+0].normal, size ); | |
+ studio_planes[j+1].dist -= DotProductAbs( studio_planes[j+1].normal, size ); | |
+ studio_planes[j+2].dist += DotProductAbs( studio_planes[j+2].normal, size ); | |
+ studio_planes[j+3].dist -= DotProductAbs( studio_planes[j+3].normal, size ); | |
+ studio_planes[j+4].dist += DotProductAbs( studio_planes[j+4].normal, size ); | |
+ studio_planes[j+5].dist -= DotProductAbs( studio_planes[j+5].normal, size ); | |
} | |
// tell trace code about hitbox count | |
- *numhitboxes = (bSkipShield == true) ? mod_studiohdr->numhitboxes - 1 : mod_studiohdr->numhitboxes; | |
+ *numhitboxes = mod_studiohdr->numhitboxes; | |
if( mod_studiocache->integer ) | |
{ | |
@@ -290,7 +286,7 @@ StudioCalcBoneAdj | |
static void Mod_StudioCalcBoneAdj( float *adj, const byte *pcontroller ) | |
{ | |
int i, j; | |
- float value = 0.0f; | |
+ float value; | |
mstudiobonecontroller_t *pbonecontroller; | |
pbonecontroller = (mstudiobonecontroller_t *)((byte *)mod_studiohdr + mod_studiohdr->bonecontrollerindex); | |
@@ -502,8 +498,6 @@ static void Mod_StudioCalcRotations( int | |
float adj[MAXSTUDIOCONTROLLERS]; | |
float s; | |
- Q_memset( adj, 0, MAXSTUDIOCONTROLLERS * sizeof( float ) ); | |
- | |
if( f > pseqdesc->numframes - 1 ) | |
f = 0.0f; | |
else if( f < -0.01f ) | |
@@ -596,13 +590,13 @@ StudioGetAnim | |
static mstudioanim_t *Mod_StudioGetAnim( model_t *m_pSubModel, mstudioseqdesc_t *pseqdesc ) | |
{ | |
mstudioseqgroup_t *pseqgroup; | |
- fs_offset_t filesize; | |
- byte *buf; | |
cache_user_t *paSequences; | |
+ size_t filesize; | |
+ byte *buf; | |
pseqgroup = (mstudioseqgroup_t *)((byte *)mod_studiohdr + mod_studiohdr->seqgroupindex) + pseqdesc->seqgroup; | |
if( pseqdesc->seqgroup == 0 ) | |
- return (mstudioanim_t *)((byte *)mod_studiohdr + pseqdesc->animindex); | |
+ return (mstudioanim_t *)((byte *)mod_studiohdr + pseqgroup->data + pseqdesc->animindex); | |
paSequences = (cache_user_t *)m_pSubModel->submodels; | |
@@ -613,7 +607,7 @@ static mstudioanim_t *Mod_StudioGetAnim( | |
} | |
// check for already loaded | |
- if( !paSequences[pseqdesc->seqgroup].data ) | |
+ if( !Mod_CacheCheck(( cache_user_t *)&( paSequences[pseqdesc->seqgroup] ))) | |
{ | |
string filepath, modelname, modelpath; | |
@@ -622,15 +616,14 @@ static mstudioanim_t *Mod_StudioGetAnim( | |
Q_snprintf( filepath, sizeof( filepath ), "%s/%s%i%i.mdl", modelpath, modelname, pseqdesc->seqgroup / 10, pseqdesc->seqgroup % 10 ); | |
buf = FS_LoadFile( filepath, &filesize, false ); | |
- if( !buf || !filesize ) | |
- Host_Error( "StudioGetAnim: can't load %s\n", filepath ); | |
- else if( IDSEQGRPHEADER != *(uint *)buf ) | |
+ if( !buf || !filesize ) Host_Error( "StudioGetAnim: can't load %s\n", filepath ); | |
+ if( IDSEQGRPHEADER != *(uint *)buf ) | |
Host_Error( "StudioGetAnim: %s is corrupted\n", filepath ); | |
MsgDev( D_INFO, "loading: %s\n", filepath ); | |
paSequences[pseqdesc->seqgroup].data = Mem_Alloc( com_studiocache, filesize ); | |
- Q_memcpy( paSequences[pseqdesc->seqgroup].data, buf, (size_t)filesize ); | |
+ Q_memcpy( paSequences[pseqdesc->seqgroup].data, buf, filesize ); | |
Mem_Free( buf ); | |
} | |
return (mstudioanim_t *)((byte *)paSequences[pseqdesc->seqgroup].data + pseqdesc->animindex); | |
@@ -974,7 +967,7 @@ static server_studio_api_t gStudioAPI = | |
{ | |
Mod_Calloc, | |
Mod_CacheCheck, | |
- (void*)Mod_LoadCacheFile, | |
+ Mod_LoadCacheFile, | |
Mod_Extradata, | |
}; | |
Только в engine/common: neon_mathfun.h | |
diff --suppress-blank-empty -prudwEZbB engine/common/net_buffer.c /mnt/data/Xash3D_original/engine/common/net_buffer.c | |
--- engine/common/net_buffer.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/net_buffer.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -26,7 +26,6 @@ static dword ExtraMasks[32]; | |
short BF_BigShort( short swap ) | |
{ | |
-#ifdef __MSC_VER | |
short *s = &swap; | |
__asm { | |
@@ -35,14 +34,7 @@ short BF_BigShort( short swap ) | |
mov ah, [ebx ] | |
mov [ebx], ax | |
} | |
- | |
return *s; | |
-#else | |
- // Taken from Xash3DLinux project | |
- short pDest = 0; | |
- pDest = (swap >> 8) | (swap << 8); | |
- return pDest; | |
-#endif | |
} | |
void BF_InitMasks( void ) | |
@@ -75,7 +67,7 @@ void BF_InitExt( sizebuf_t *bf, const ch | |
void BF_StartWriting( sizebuf_t *bf, void *pData, int nBytes, int iStartBit, int nBits ) | |
{ | |
// make sure it's dword aligned and padded. | |
- Assert(((size_t)pData & 3 ) == 0 ); | |
+ Assert(((dword)pData & 3 ) == 0 ); | |
bf->pData = (byte *)pData; | |
@@ -143,7 +135,7 @@ void BF_WriteOneBit( sizebuf_t *bf, int | |
void BF_WriteUBitLongExt( sizebuf_t *bf, uint curData, int numbits, qboolean bCheckRange ) | |
{ | |
- //Assert( numbits >= 0 && numbits <= 32 ); | |
+ Assert( numbits >= 0 && numbits <= 32 ); | |
// bounds checking.. | |
if(( bf->iCurBit + numbits ) > bf->nDataBits ) | |
@@ -159,7 +151,7 @@ void BF_WriteUBitLongExt( sizebuf_t *bf, | |
dword iCurBitMasked; | |
int nBitsWritten; | |
- Assert(( iDWord * 4 + sizeof( int )) <= (uint)BF_GetMaxBytes( bf )); | |
+ Assert(( iDWord * 4 + sizeof( long )) <= (uint)BF_GetMaxBytes( bf )); | |
iCurBitMasked = iCurBit & 31; | |
((dword *)bf->pData)[iDWord] &= BitWriteMasks[iCurBitMasked][nBitsLeft]; | |
@@ -221,7 +213,7 @@ qboolean BF_WriteBits( sizebuf_t *bf, co | |
int nBitsLeft = nBits; | |
// get output dword-aligned. | |
- while((( size_t )pOut & 3 ) != 0 && nBitsLeft >= 8 ) | |
+ while((( dword )pOut & 3 ) != 0 && nBitsLeft >= 8 ) | |
{ | |
BF_WriteUBitLongExt( bf, *pOut, 8, false ); | |
@@ -291,12 +283,12 @@ void BF_WriteVec3Coord( sizebuf_t *bf, c | |
void BF_WriteBitFloat( sizebuf_t *bf, float val ) | |
{ | |
- int intVal; | |
+ long intVal; | |
- ASSERT( sizeof( int ) == sizeof( float )); | |
+ ASSERT( sizeof( long ) == sizeof( float )); | |
ASSERT( sizeof( float ) == 4 ); | |
- intVal = *((int *)&val ); | |
+ intVal = *((long *)&val ); | |
BF_WriteUBitLong( bf, intVal, 32 ); | |
} | |
@@ -320,9 +312,9 @@ void BF_WriteWord( sizebuf_t *bf, int va | |
BF_WriteUBitLong( bf, val, sizeof( word ) << 3 ); | |
} | |
-void BF_WriteLong( sizebuf_t *bf, int val ) | |
+void BF_WriteLong( sizebuf_t *bf, long val ) | |
{ | |
- BF_WriteSBitLong( bf, val, sizeof( int ) << 3 ); | |
+ BF_WriteSBitLong( bf, val, sizeof( long ) << 3 ); | |
} | |
void BF_WriteFloat( sizebuf_t *bf, float val ) | |
@@ -341,7 +333,7 @@ qboolean BF_WriteString( sizebuf_t *bf, | |
{ | |
do | |
{ | |
- BF_WriteChar( bf, (signed char)*pStr ); | |
+ BF_WriteChar( bf, *pStr ); | |
pStr++; | |
} while( *( pStr - 1 )); | |
} | |
@@ -381,7 +373,7 @@ uint BF_ReadUBitLong( sizebuf_t *bf, int | |
return 0; | |
} | |
- //ASSERT( numbits > 0 && numbits <= 32 ); | |
+ ASSERT( numbits > 0 && numbits <= 32 ); | |
// Read the current dword. | |
idword1 = bf->iCurBit >> 5; | |
@@ -411,10 +403,10 @@ uint BF_ReadUBitLong( sizebuf_t *bf, int | |
float BF_ReadBitFloat( sizebuf_t *bf ) | |
{ | |
- int val; | |
+ long val; | |
int bit, byte; | |
- ASSERT( sizeof( float ) == sizeof( int )); | |
+ ASSERT( sizeof( float ) == sizeof( long )); | |
ASSERT( sizeof( float ) == 4 ); | |
if( BF_Overflow( bf, 32 )) | |
@@ -441,7 +433,7 @@ qboolean BF_ReadBits( sizebuf_t *bf, voi | |
int nBitsLeft = nBits; | |
// get output dword-aligned. | |
- while((( size_t )pOut & 3) != 0 && nBitsLeft >= 8 ) | |
+ while((( dword )pOut & 3) != 0 && nBitsLeft >= 8 ) | |
{ | |
*pOut = (byte)BF_ReadUBitLong( bf, 8 ); | |
++pOut; | |
@@ -500,7 +492,7 @@ int BF_ReadSBitLong( sizebuf_t *bf, int | |
// NOTE: it does this wierdness here so it's bit-compatible with regular integer data in the buffer. | |
// (Some old code writes direct integers right into the buffer). | |
sign = BF_ReadOneBit( bf ); | |
- if( sign ) r = -( (int)( BIT( numbits - 1 ) - r ) ); | |
+ if( sign ) r = -( BIT( numbits - 1 ) - r ); | |
return r; | |
} | |
@@ -547,9 +539,9 @@ void BF_ReadVec3Coord( sizebuf_t *bf, ve | |
fa[2] = BF_ReadCoord( bf ); | |
} | |
-int BF_ReadLong( sizebuf_t *bf ) | |
+long BF_ReadLong( sizebuf_t *bf ) | |
{ | |
- return BF_ReadSBitLong( bf, sizeof( int ) << 3 ); | |
+ return BF_ReadSBitLong( bf, sizeof( long ) << 3 ); | |
} | |
float BF_ReadFloat( sizebuf_t *bf ) | |
diff --suppress-blank-empty -prudwEZbB engine/common/net_buffer.h /mnt/data/Xash3D_original/engine/common/net_buffer.h | |
--- engine/common/net_buffer.h 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/net_buffer.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -16,7 +16,7 @@ GNU General Public License for more deta | |
#ifndef NET_BUFFER_H | |
#define NET_BUFFER_H | |
-#include "engine_features.h" | |
+#include "features.h" | |
/* | |
============================================================================== | |
@@ -83,7 +83,7 @@ void BF_WriteChar( sizebuf_t *bf, int va | |
void BF_WriteByte( sizebuf_t *bf, int val ); | |
void BF_WriteShort( sizebuf_t *bf, int val ); | |
void BF_WriteWord( sizebuf_t *bf, int val ); | |
-void BF_WriteLong( sizebuf_t *bf, int val ); | |
+void BF_WriteLong( sizebuf_t *bf, long val ); | |
void BF_WriteCoord( sizebuf_t *bf, float val ); | |
void BF_WriteFloat( sizebuf_t *bf, float val ); | |
void BF_WriteVec3Coord( sizebuf_t *bf, const float *fa ); | |
@@ -114,7 +114,7 @@ int BF_ReadChar( sizebuf_t *bf ); | |
int BF_ReadByte( sizebuf_t *bf ); | |
int BF_ReadShort( sizebuf_t *bf ); | |
int BF_ReadWord( sizebuf_t *bf ); | |
-int BF_ReadLong( sizebuf_t *bf ); | |
+long BF_ReadLong( sizebuf_t *bf ); | |
float BF_ReadCoord( sizebuf_t *bf ); | |
float BF_ReadFloat( sizebuf_t *bf ); | |
void BF_ReadVec3Coord( sizebuf_t *bf, vec3_t fa ); | |
diff --suppress-blank-empty -prudwEZbB engine/common/net_chan.c /mnt/data/Xash3D_original/engine/common/net_chan.c | |
--- engine/common/net_chan.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/net_chan.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -376,7 +376,7 @@ void Netchan_OutOfBandPrint( int net_soc | |
Q_vsprintf( string, format, argptr ); | |
va_end( argptr ); | |
- Netchan_OutOfBand( net_socket, adr, Q_strlen( string ), (byte *)string ); | |
+ Netchan_OutOfBand( net_socket, adr, Q_strlen( string ), string ); | |
} | |
/* | |
@@ -710,7 +710,7 @@ void Netchan_CheckForCompletion( netchan | |
if( c == intotalbuffers ) | |
{ | |
chan->incomingready[stream] = true; | |
- MsgDev( D_NOTE, "\nincoming is complete, %i bytes waiting\n", size ); | |
+ MsgDev( D_NOTE, "\nincoming is complete %i bytes waiting\n", size ); | |
} | |
} | |
@@ -967,8 +967,7 @@ qboolean Netchan_CopyFileFragments( netc | |
BF_WriteBits( msg, BF_GetData( &p->frag_message ), BF_GetNumBitsWritten( &p->frag_message )); | |
BF_SeekToBit( msg, 0 ); // rewind buffer | |
- //Q_strncpy( filename, BF_ReadString( msg ), sizeof( filename )); | |
- Q_snprintf( filename, sizeof( filename ), "downloaded/%s", BF_ReadString( msg ) ); | |
+ Q_strncpy( filename, BF_ReadString( msg ), sizeof( filename )); | |
if( Q_strlen( filename ) <= 0 ) | |
{ | |
@@ -1068,6 +1067,11 @@ void Netchan_UpdateProgress( netchan_t * | |
int total = 0; | |
float bestpercent = 0.0; | |
+ if( scr_download->integer != -1 ) | |
+ { | |
+ Cvar_SetFloat( "scr_download", -1 ); | |
+ } | |
+ | |
if ( net_drawslider->integer != 1 ) | |
{ | |
// do show slider for file downloads. | |
@@ -1139,9 +1143,9 @@ void Netchan_UpdateProgress( netchan_t * | |
} | |
} | |
} | |
+ | |
} | |
- if( bestpercent ) | |
Cvar_SetFloat( "scr_download", bestpercent ); | |
} | |
@@ -1329,12 +1333,11 @@ void Netchan_TransmitBits( netchan_t *ch | |
} | |
} | |
- Q_memset( send_buf, 0, NET_MAX_MESSAGE ); | |
BF_Init( &send, "NetSend", send_buf, sizeof( send_buf )); | |
// prepare the packet header | |
w1 = chan->outgoing_sequence | (send_reliable << 31); | |
- w2 = chan->incoming_sequence | ((uint)chan->incoming_reliable_sequence << 31); | |
+ w2 = chan->incoming_sequence | (chan->incoming_reliable_sequence << 31); | |
send_reliable_fragment = false; | |
@@ -1349,7 +1352,7 @@ void Netchan_TransmitBits( netchan_t *ch | |
if( send_reliable && send_reliable_fragment ) | |
{ | |
- w1 |= ( 1U << 30 ); | |
+ w1 |= ( 1 << 30 ); | |
} | |
chan->outgoing_sequence++; | |
@@ -1361,7 +1364,7 @@ void Netchan_TransmitBits( netchan_t *ch | |
// send the qport if we are a client | |
if( chan->sock == NS_CLIENT ) | |
{ | |
- BF_WriteWord( &send, net_qport->integer); | |
+ BF_WriteWord( &send, Cvar_VariableValue( "net_qport" )); | |
} | |
if( send_reliable && send_reliable_fragment ) | |
@@ -1404,6 +1407,8 @@ void Netchan_TransmitBits( netchan_t *ch | |
// deal with packets that are too small for some networks | |
if( BF_GetNumBytesWritten( &send ) < 16 ) // packet too small for some networks | |
{ | |
+ int i; | |
+ | |
// go ahead and pad a full 16 extra bytes -- this only happens during authentication / signon | |
for( i = BF_GetNumBytesWritten( &send ); i < 16; i++ ) | |
{ | |
@@ -1432,9 +1437,6 @@ void Netchan_TransmitBits( netchan_t *ch | |
NET_SendPacket( chan->sock, BF_GetNumBytesWritten( &send ), BF_GetData( &send ), chan->remote_address ); | |
} | |
- if( chan->rate == 0) | |
- chan->rate = DEFAULT_RATE; | |
- | |
fRate = 1.0f / chan->rate; | |
if( chan->cleartime < host.realtime ) | |
@@ -1515,7 +1517,7 @@ qboolean Netchan_Process( netchan_t *cha | |
reliable_message = sequence >> 31; | |
reliable_ack = sequence_ack >> 31; | |
- message_contains_fragments = sequence & ( 1U << 30 ) ? true : false; | |
+ message_contains_fragments = sequence & ( 1 << 30 ) ? true : false; | |
if( message_contains_fragments ) | |
{ | |
@@ -1531,9 +1533,9 @@ qboolean Netchan_Process( netchan_t *cha | |
} | |
} | |
- sequence &= ~(1U<<31); | |
- sequence &= ~(1U<<30); | |
- sequence_ack &= ~(1U<<31); | |
+ sequence &= ~(1<<31); | |
+ sequence &= ~(1<<30); | |
+ sequence_ack &= ~(1<<31); | |
if( net_showpackets->integer == 2 ) | |
{ | |
diff --suppress-blank-empty -prudwEZbB engine/common/netchan.h /mnt/data/Xash3D_original/engine/common/netchan.h | |
--- engine/common/netchan.h 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/netchan.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -59,11 +59,11 @@ GNU General Public License for more deta | |
// bytes will be stripped by the networking channel layer | |
#define NET_MAX_MESSAGE PAD_NUMBER(( NET_MAX_PAYLOAD + HEADER_BYTES ), 16 ) | |
-#define MASTERSERVER_ADR "ms.xash.su:27010" | |
+#define MASTERSERVER_ADR "celest.in:27010" | |
#define PORT_MASTER 27010 | |
#define PORT_CLIENT 27005 | |
#define PORT_SERVER 27015 | |
-#define MULTIPLAYER_BACKUP 128 // how many data slots to use when in multiplayer (must be power of 2) | |
+#define MULTIPLAYER_BACKUP 64 // how many data slots to use when in multiplayer (must be power of 2) | |
#define SINGLEPLAYER_BACKUP 16 // same for single player | |
/* | |
@@ -197,7 +197,6 @@ extern sizebuf_t net_message; | |
extern byte net_message_buffer[NET_MAX_PAYLOAD]; | |
extern convar_t *net_speeds; | |
extern int net_drop; | |
-extern byte *net_mempool; | |
void Netchan_Init( void ); | |
void Netchan_Shutdown( void ); | |
diff --suppress-blank-empty -prudwEZbB engine/common/net_encode.c /mnt/data/Xash3D_original/engine/common/net_encode.c | |
--- engine/common/net_encode.c 2016-08-19 14:22:46.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/net_encode.c 2016-08-19 14:21:49.000000000 +0000 | |
@@ -20,6 +20,9 @@ GNU General Public License for more deta | |
#include "event_api.h" | |
#include "usercmd.h" | |
#include "pm_movevars.h" | |
+#include "entity_state.h" | |
+#include "weaponinfo.h" | |
+#include "event_args.h" | |
#include "protocol.h" | |
#include "client.h" | |
@@ -513,11 +516,10 @@ void Delta_ParseTableField( sizebuf_t *m | |
tableIndex = BF_ReadUBitLong( msg, 4 ); | |
dt = Delta_FindStructByIndex( tableIndex ); | |
- if( !dt ) | |
- Host_Error( "Delta_ParseTableField: not initialized" ); | |
+ ASSERT( dt != NULL ); | |
+ | |
nameIndex = BF_ReadUBitLong( msg, 8 ); // read field name index | |
- if( !( nameIndex >= 0 && nameIndex < dt->maxFields ) ) | |
- Host_Error( "Delta_ParseTableField: wrong nameIndex" ); | |
+ ASSERT( nameIndex >= 0 && nameIndex < dt->maxFields ); | |
pName = dt->pInfo[nameIndex].name; | |
flags = BF_ReadUBitLong( msg, 10 ); | |
bits = BF_ReadUBitLong( msg, 5 ) + 1; | |
@@ -737,7 +739,7 @@ void Delta_InitFields( void ) | |
string encodeDll, encodeFunc, token; | |
delta_info_t *dt; | |
- afile = (char *)FS_LoadFile( DELTA_PATH, NULL, false ); | |
+ afile = FS_LoadFile( DELTA_PATH, NULL, false ); | |
if( !afile ) Sys_Error( "DELTA_Load: couldn't load file %s\n", DELTA_PATH ); | |
pfile = afile; | |
@@ -802,7 +804,7 @@ void Delta_Init( void ) | |
Delta_AddField( "movevars_t", "bounce", DT_FLOAT|DT_SIGNED, 16, 8.0f, 1.0f ); | |
Delta_AddField( "movevars_t", "stepsize", DT_FLOAT|DT_SIGNED, 16, 16.0f, 1.0f ); | |
Delta_AddField( "movevars_t", "maxvelocity", DT_FLOAT|DT_SIGNED, 16, 8.0f, 1.0f ); | |
- Delta_AddField( "movevars_t", "zmax", DT_FLOAT|DT_SIGNED, 16, 1.0f, 1.0f ); // no fractional part | |
+ Delta_AddField( "movevars_t", "zmax", DT_FLOAT|DT_SIGNED, 18, 1.0f, 1.0f ); // no fractional part | |
Delta_AddField( "movevars_t", "waveHeight", DT_FLOAT|DT_SIGNED, 16, 16.0f, 8.0f ); | |
Delta_AddField( "movevars_t", "skyName", DT_STRING, 1, 1.0f, 1.0f ); | |
Delta_AddField( "movevars_t", "footsteps", DT_INTEGER, 1, 1.0f, 1.0f ); | |
@@ -858,7 +860,7 @@ void Delta_Shutdown( void ) | |
if( dt_info[i].pFields ) | |
{ | |
- Mem_Free( dt_info[i].pFields ); | |
+ Z_Free( dt_info[i].pFields ); | |
dt_info[i].pFields = NULL; | |
} | |
@@ -884,63 +886,63 @@ int Delta_ClampIntegerField( int iValue, | |
break; | |
case 2: | |
if( bSigned ) iValue = bound( -2, (short)iValue, 1 ); | |
- else iValue = boundmax( (word)iValue, 3 ); | |
+ else iValue = bound( 0, (word)iValue, 3 ); | |
break; | |
case 3: | |
if( bSigned ) iValue = bound( -4, (short)iValue, 3 ); | |
- else iValue = boundmax( (word)iValue, 7 ); | |
+ else iValue = bound( 0, (word)iValue, 7 ); | |
break; | |
case 4: | |
if( bSigned ) iValue = bound( -8, (short)iValue, 7 ); | |
- else iValue = boundmax( (word)iValue, 15 ); | |
+ else iValue = bound( 0, (word)iValue, 15 ); | |
break; | |
case 5: | |
if( bSigned ) iValue = bound( -16, (short)iValue, 15 ); | |
- else iValue = boundmax( (word)iValue, 31 ); | |
+ else iValue = bound( 0, (word)iValue, 31 ); | |
break; | |
case 6: | |
if( bSigned ) iValue = bound( -32, (short)iValue, 31 ); | |
- else iValue = boundmax( (word)iValue, 63 ); | |
+ else iValue = bound( 0, (word)iValue, 63 ); | |
break; | |
case 7: | |
if( bSigned ) iValue = bound( -64, (short)iValue, 63 ); | |
- else iValue = boundmax( (word)iValue, 127 ); | |
+ else iValue = bound( 0, (word)iValue, 127 ); | |
break; | |
case 8: | |
if( bSigned ) iValue = bound( -128, (short)iValue, 127 ); | |
- else iValue = boundmax( (word)iValue, 255 ); | |
+ else iValue = bound( 0, (word)iValue, 255 ); | |
break; | |
case 9: | |
if( bSigned ) iValue = bound( -256, (short)iValue, 255 ); | |
- else iValue = boundmax( (word)iValue, 511 ); | |
+ else iValue = bound( 0, (word)iValue, 511 ); | |
break; | |
case 10: | |
if( bSigned ) iValue = bound( -512, (short)iValue, 511 ); | |
- else iValue = boundmax( (word)iValue, 1023 ); | |
+ else iValue = bound( 0, (word)iValue, 1023 ); | |
break; | |
case 11: | |
if( bSigned ) iValue = bound( -1024, (short)iValue, 1023 ); | |
- else iValue = boundmax( (word)iValue, 2047 ); | |
+ else iValue = bound( 0, (word)iValue, 2047 ); | |
break; | |
case 12: | |
if( bSigned ) iValue = bound( -2048, (short)iValue, 2047 ); | |
- else iValue = boundmax( (word)iValue, 4095 ); | |
+ else iValue = bound( 0, (word)iValue, 4095 ); | |
break; | |
case 13: | |
if( bSigned ) iValue = bound( -4096, (short)iValue, 4095 ); | |
- else iValue = boundmax( (word)iValue, 8191 ); | |
+ else iValue = bound( 0, (word)iValue, 8191 ); | |
break; | |
case 14: | |
if( bSigned ) iValue = bound( -8192, (short)iValue, 8191 ); | |
- else iValue = boundmax( (word)iValue, 16383 ); | |
+ else iValue = bound( 0, (word)iValue, 16383 ); | |
break; | |
case 15: | |
if( bSigned ) iValue = bound( -16384, (short)iValue, 16383 ); | |
- else iValue = boundmax( (word)iValue, 32767 ); | |
+ else iValue = bound( 0, (word)iValue, 32767 ); | |
break; | |
case 16: | |
if( bSigned ) iValue = bound( -32768, (short)iValue, 32767 ); | |
- else iValue = boundmax( (word)iValue, 65535 ); | |
+ else iValue = bound( 0, (word)iValue, 65535 ); | |
break; | |
} | |
@@ -986,11 +988,8 @@ qboolean Delta_CompareField( delta_t *pF | |
fromF = Delta_ClampIntegerField( fromF, bSigned, pField->bits ); | |
toF = Delta_ClampIntegerField( toF, bSigned, pField->bits ); | |
- if( pField->multiplier != 1.0f ) | |
- { | |
- fromF *= pField->multiplier; | |
- toF *= pField->multiplier; | |
- } | |
+ if( pField->multiplier != 1.0f ) fromF *= pField->multiplier; | |
+ if( pField->multiplier != 1.0f ) toF *= pField->multiplier; | |
} | |
else if( pField->flags & DT_SHORT ) | |
{ | |
@@ -1007,11 +1006,8 @@ qboolean Delta_CompareField( delta_t *pF | |
fromF = Delta_ClampIntegerField( fromF, bSigned, pField->bits ); | |
toF = Delta_ClampIntegerField( toF, bSigned, pField->bits ); | |
- if( pField->multiplier != 1.0f ) | |
- { | |
- fromF *= pField->multiplier; | |
- toF *= pField->multiplier; | |
- } | |
+ if( pField->multiplier != 1.0f ) fromF *= pField->multiplier; | |
+ if( pField->multiplier != 1.0f ) toF *= pField->multiplier; | |
} | |
else if( pField->flags & DT_INTEGER ) | |
{ | |
@@ -1028,11 +1024,8 @@ qboolean Delta_CompareField( delta_t *pF | |
fromF = Delta_ClampIntegerField( fromF, bSigned, pField->bits ); | |
toF = Delta_ClampIntegerField( toF, bSigned, pField->bits ); | |
- if( pField->multiplier != 1.0f ) | |
- { | |
- fromF *= pField->multiplier; | |
- toF *= pField->multiplier; | |
- } | |
+ if( pField->multiplier != 1.0f ) fromF *= pField->multiplier; | |
+ if( pField->multiplier != 1.0f ) toF *= pField->multiplier; | |
} | |
else if( pField->flags & ( DT_FLOAT|DT_ANGLE )) | |
{ | |
@@ -1127,21 +1122,13 @@ qboolean Delta_WriteField( sizebuf_t *ms | |
} | |
else if( pField->flags & DT_FLOAT ) | |
{ | |
- #ifdef __arm__ | |
- memcpy(&flValue,(byte *)to + pField->offset, sizeof(float) ); | |
- #else | |
flValue = *(float *)((byte *)to + pField->offset ); | |
- #endif | |
iValue = (int)(flValue * pField->multiplier); | |
BF_WriteBitLong( msg, iValue, pField->bits, bSigned ); | |
} | |
else if( pField->flags & DT_ANGLE ) | |
{ | |
- #ifdef __arm__ | |
- memcpy(&flAngle,(byte *)to + pField->offset, sizeof(float) ); | |
- #else | |
flAngle = *(float *)((byte *)to + pField->offset ); | |
- #endif | |
// NOTE: never applies multipliers to angle because | |
// result may be wrong on client-side | |
@@ -1149,39 +1136,17 @@ qboolean Delta_WriteField( sizebuf_t *ms | |
} | |
else if( pField->flags & DT_TIMEWINDOW_8 ) | |
{ | |
- #ifdef __arm__ | |
- memcpy(&flValue,(byte *)to + pField->offset, sizeof(float) ); | |
- #else | |
flValue = *(float *)((byte *)to + pField->offset ); | |
- #endif | |
flTime = Q_rint( timebase * 100.0f ) - Q_rint(flValue * 100.0f); | |
- #if 1 | |
- iValue = (uint)fabs( flTime ); | |
- #else | |
- iValue = (uint)fabs( flTime ); | |
- if (flTime<0.0f) { | |
- iValue |= 0x80000000; | |
- } | |
- #endif | |
+ iValue = (uint)abs( flTime ); | |
BF_WriteBitLong( msg, iValue, pField->bits, bSigned ); | |
} | |
else if( pField->flags & DT_TIMEWINDOW_BIG ) | |
{ | |
- #ifdef __arm__ | |
- memcpy(&flValue,(byte *)to + pField->offset, sizeof(float) ); | |
- #else | |
flValue = *(float *)((byte *)to + pField->offset ); | |
- #endif | |
flTime = (timebase * pField->multiplier) - (flValue * pField->multiplier); | |
- #if 1 | |
- iValue = (uint)fabs( flTime ); | |
- #else | |
- iValue = (uint)fabs( flTime ); | |
- if (flTime<0.0f) { | |
- iValue |= 0x80000000; | |
- } | |
- #endif | |
+ iValue = (uint)abs( flTime ); | |
BF_WriteBitLong( msg, iValue, pField->bits, bSigned ); | |
} | |
@@ -1263,17 +1228,9 @@ qboolean Delta_ReadField( sizebuf_t *msg | |
} | |
else | |
{ | |
- #ifdef __arm__ | |
- memcpy(&flValue, (byte *)from + pField->offset, sizeof(float) ); | |
- #else | |
flValue = *(float *)((byte *)from + pField->offset ); | |
- #endif | |
} | |
- #ifdef __arm__ | |
- memcpy((byte *)to + pField->offset, &flValue, sizeof(float)); | |
- #else | |
*(float *)((byte *)to + pField->offset ) = flValue; | |
- #endif | |
} | |
else if( pField->flags & DT_ANGLE ) | |
{ | |
@@ -1283,17 +1240,9 @@ qboolean Delta_ReadField( sizebuf_t *msg | |
} | |
else | |
{ | |
- #ifdef __arm__ | |
- memcpy(&flAngle, (byte *)from + pField->offset, sizeof(float) ); | |
- #else | |
flAngle = *(float *)((byte *)from + pField->offset ); | |
- #endif | |
} | |
- #ifdef __arm__ | |
- memcpy((byte *)to + pField->offset, &flAngle, sizeof(float)); | |
- #else | |
*(float *)((byte *)to + pField->offset ) = flAngle; | |
- #endif | |
} | |
else if( pField->flags & DT_TIMEWINDOW_8 ) | |
{ | |
@@ -1305,17 +1254,9 @@ qboolean Delta_ReadField( sizebuf_t *msg | |
} | |
else | |
{ | |
- #ifdef __arm__ | |
- memcpy(&flTime, (byte *)from + pField->offset, sizeof(float) ); | |
- #else | |
flTime = *(float *)((byte *)from + pField->offset ); | |
- #endif | |
} | |
- #ifdef __arm__ | |
- memcpy((byte *)to + pField->offset, &flTime, sizeof(float)); | |
- #else | |
*(float *)((byte *)to + pField->offset ) = flTime; | |
- #endif | |
} | |
else if( pField->flags & DT_TIMEWINDOW_BIG ) | |
{ | |
@@ -1327,17 +1268,9 @@ qboolean Delta_ReadField( sizebuf_t *msg | |
} | |
else | |
{ | |
- #ifdef __arm__ | |
- memcpy(&flTime, (byte *)from + pField->offset, sizeof(float) ); | |
- #else | |
flTime = *(float *)((byte *)from + pField->offset ); | |
- #endif | |
} | |
- #ifdef __arm__ | |
- memcpy((byte *)to + pField->offset, &flTime, sizeof(float)); | |
- #else | |
*(float *)((byte *)to + pField->offset ) = flTime; | |
- #endif | |
} | |
else if( pField->flags & DT_STRING ) | |
{ | |
@@ -1375,10 +1308,7 @@ void MSG_WriteDeltaUsercmd( sizebuf_t *m | |
int i; | |
dt = Delta_FindStruct( "usercmd_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_WriteDeltaUsercmd: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1405,10 +1335,7 @@ void MSG_ReadDeltaUsercmd( sizebuf_t *ms | |
int i; | |
dt = Delta_FindStruct( "usercmd_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_ReadDeltaUsercmd: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1441,10 +1368,7 @@ void MSG_WriteDeltaEvent( sizebuf_t *msg | |
int i; | |
dt = Delta_FindStruct( "event_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_WriteDeltaEvent: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1471,10 +1395,7 @@ void MSG_ReadDeltaEvent( sizebuf_t *msg, | |
int i; | |
dt = Delta_FindStruct( "event_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_ReadDeltaEvent: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1503,10 +1424,7 @@ qboolean MSG_WriteDeltaMovevars( sizebuf | |
int numChanges = 0; | |
dt = Delta_FindStruct( "movevars_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_WriteDeltaMovevars: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1541,10 +1459,7 @@ void MSG_ReadDeltaMovevars( sizebuf_t *m | |
int i; | |
dt = Delta_FindStruct( "movevars_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_ReadDeltaMovevars: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1580,10 +1495,7 @@ void MSG_WriteClientData( sizebuf_t *msg | |
int i; | |
dt = Delta_FindStruct( "clientdata_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_WriteClientData: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1611,10 +1524,7 @@ void MSG_ReadClientData( sizebuf_t *msg, | |
int i; | |
dt = Delta_FindStruct( "clientdata_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_ReadClientData: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1651,10 +1561,7 @@ void MSG_WriteWeaponData( sizebuf_t *msg | |
int numChanges = 0; | |
dt = Delta_FindStruct( "weapon_data_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_WriteWeaponData: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1692,10 +1599,7 @@ void MSG_ReadWeaponData( sizebuf_t *msg, | |
int i; | |
dt = Delta_FindStruct( "weapon_data_t" ); | |
- if( !dt || !dt->bInitialized ) | |
- { | |
- Host_Error( "MSG_ReadWeaponData: delta not initialized!\n" ); | |
- } | |
+ ASSERT( dt && dt->bInitialized ); | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1757,10 +1661,7 @@ void MSG_WriteDeltaEntity( entity_state_ | |
startBit = msg->iCurBit; | |
if( to->number < 0 || to->number >= GI->max_edicts ) | |
- { | |
- MsgDev( D_ERROR, "MSG_WriteDeltaEntity: Bad entity number: %i\n", to->number ); | |
- return; | |
- } | |
+ Host_Error( "MSG_WriteDeltaEntity: Bad entity number: %i\n", to->number ); | |
BF_WriteWord( msg, to->number ); | |
BF_WriteUBitLong( msg, 0, 2 ); // alive | |
@@ -1823,13 +1724,9 @@ qboolean MSG_ReadDeltaEntity( sizebuf_t | |
delta_info_t *dt = NULL; | |
delta_t *pField; | |
int i, fRemoveType; | |
-#ifndef XASH_DEDICATED | |
+ | |
if( number < 0 || number >= clgame.maxEntities ) | |
- { | |
- // broken packet, try to skip it | |
- MsgDev( D_ERROR, "MSG_ReadDeltaEntity: bad delta entity number: %i\n", number ); | |
- return false; | |
- } | |
+ Host_Error( "MSG_ReadDeltaEntity: bad delta entity number: %i\n", number ); | |
*to = *from; | |
to->number = number; | |
@@ -1853,25 +1750,14 @@ qboolean MSG_ReadDeltaEntity( sizebuf_t | |
return false; | |
} | |
- MsgDev( D_ERROR, "MSG_ReadDeltaEntity: unknown update type %i\n", fRemoveType ); | |
- return false; | |
+ Host_Error( "MSG_ReadDeltaEntity: unknown update type %i\n", fRemoveType ); | |
} | |
if( BF_ReadOneBit( msg )) | |
to->entityType = BF_ReadUBitLong( msg, 2 ); | |
- | |
- if( to->entityType == ENTITY_BEAM ) | |
- { | |
- dt = Delta_FindStruct( "custom_entity_state_t" ); | |
- } | |
- else // ENTITY_NORMAL or other (try predict type) | |
+ if( to->entityType == ENTITY_NORMAL ) | |
{ | |
- /* Omit connection drop on wromg data from server. | |
- * I know that it is very dirty, | |
- * but i don't know how to do it better.*/ | |
- if( to->entityType != ENTITY_NORMAL ) | |
- MsgDev( D_NOTE, "MSG_ReadDeltaEntity: broken delta: entityType = %d\n", to->entityType ); | |
if( player ) | |
{ | |
dt = Delta_FindStruct( "entity_state_player_t" ); | |
@@ -1881,12 +1767,13 @@ qboolean MSG_ReadDeltaEntity( sizebuf_t | |
dt = Delta_FindStruct( "entity_state_t" ); | |
} | |
} | |
- | |
- if( !(dt && dt->bInitialized) ) // Broken delta? | |
+ else if( to->entityType == ENTITY_BEAM ) | |
{ | |
- MsgDev( D_ERROR, "MSG_ReadDeltaEntity: broken delta\n"); | |
- return true; | |
+ dt = Delta_FindStruct( "custom_entity_state_t" ); | |
} | |
+ | |
+ ASSERT( dt && dt->bInitialized ); | |
+ | |
pField = dt->pFields; | |
ASSERT( pField ); | |
@@ -1895,7 +1782,7 @@ qboolean MSG_ReadDeltaEntity( sizebuf_t | |
{ | |
Delta_ReadField( msg, pField, from, to, timebase ); | |
} | |
-#endif | |
+ | |
// message parsed | |
return true; | |
} | |
diff --suppress-blank-empty -prudwEZbB engine/common/net_encode.h /mnt/data/Xash3D_original/engine/common/net_encode.h | |
--- engine/common/net_encode.h 2016-01-18 16:21:32.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/net_encode.h 2016-02-24 19:10:06.000000000 +0000 | |
@@ -26,11 +26,7 @@ GNU General Public License for more deta | |
#define DT_STRING BIT( 7 ) // A null terminated string, sent as 8 byte chars | |
#define DT_SIGNED BIT( 8 ) // sign modificator | |
-#ifdef offsetof | |
-#undef offsetof | |
#define offsetof( s, m ) (size_t)&(((s *)0)->m) | |
-#endif | |
- | |
#define NUM_FIELDS( x ) ((sizeof( x ) / sizeof( x[0] )) - 1) | |
// helper macroses | |
diff --suppress-blank-empty -prudwEZbB engine/common/net_huff.c /mnt/data/Xash3D_original/engine/common/net_huff.c | |
--- engine/common/net_huff.c 2016-08-01 09:09:04.000000000 +0000 | |
+++ /mnt/data/Xash3D_original/engine/common/net_huff.c 2016-02-24 19:10:06.000000000 +0000 | |
@@ -16,7 +16,7 @@ GNU General Public License for more deta | |
#include "common.h" | |
#include "netchan.h" | |
-#define VALUE(a) ((int )(size_t)(a)) | |
+#define VALUE(a) ((int )(a)) | |
#define NODE(a) ((void *)(a)) | |
#define NODE_START NODE( 1) | |
@@ -26,7 +26,7 @@ GNU General Public License for more deta | |
#define NOT_REFERENCED 256 | |
#define HUFF_TREE_SIZE 7175 | |
-typedef byte *tree_t[HUFF_TREE_SIZE]; | |
+typedef void *tree_t[HUFF_TREE_SIZE]; | |
// | |
// pre-defined frequency counts for all bytes [0..255] | |
@@ -86,21 +86,21 @@ static qboolean huffInit = false; | |
Huff_PrepareTree | |
============ | |
*/ | |
-_inline void Huff_PrepareTree( tree_t tree ) | |
+static _inline void Huff_PrepareTree( tree_t tree ) | |
{ | |
- byte **node; | |
+ void **node; | |
Q_memset( tree, 0, sizeof( tree_t )); | |
// create first node | |
node = &tree[263]; | |
- VALUE( tree[0]++ ); | |
+ VALUE( tree[0] )++; | |
node[7] = NODE_NONE; | |
- tree[2] = (byte*)node; | |
- tree[3] = (byte*)node; | |
- tree[4] = (byte*)node; | |
- tree[261] = (byte*)node; | |
+ tree[2] = node; | |
+ tree[3] = node; | |
+ tree[4] = node; | |
+ tree[261] = node; | |
} | |
/* | |
@@ -108,16 +108,16 @@ _inline void Huff_PrepareTree( tree_t tr | |
Huff_GetNode | |
============ | |
*/ | |
-_inline void **Huff_GetNode( byte **tree ) | |
+static _inline void **Huff_GetNode( void **tree ) | |
{ | |
void **node; | |
int value; | |
- node = (void**)tree[262]; | |
+ node = tree[262]; | |
if( !node ) | |
{ | |
- value = VALUE( tree[1]++ ); | |
- node = (void**)&tree[value + 6407]; | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment