This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/common.h

253 lines
6.7 KiB
C
Raw Normal View History

2008-06-09 22:00:00 +02:00
//=======================================================================
// Copyright XashXT Group 2007 <20>
// common.h - definitions common between client and server
//=======================================================================
#ifndef COMMON_H
#define COMMON_H
#include <setjmp.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
2008-10-27 22:00:00 +01:00
#include "launch_api.h"
2008-11-25 22:00:00 +01:00
#include "qfiles_ref.h"
2008-11-09 22:00:00 +01:00
#include "engine_api.h"
2009-01-05 22:00:00 +01:00
#include "entity_def.h"
2008-11-09 22:00:00 +01:00
#include "physic_api.h"
2008-11-25 22:00:00 +01:00
#include "vprogs_api.h"
#include "vsound_api.h"
2008-06-09 22:00:00 +02:00
#include "net_msg.h"
// linked interfaces
extern stdlib_api_t com;
extern physic_exp_t *pe;
extern vprogs_exp_t *vm;
2008-06-12 22:00:00 +02:00
extern vsound_exp_t *se;
2008-06-09 22:00:00 +02:00
2008-07-04 22:00:00 +02:00
#define MAX_ENTNUMBER 99999 // for server and client parsing
#define MAX_HEARTBEAT -99999 // connection time
2008-08-04 22:00:00 +02:00
#define MAX_EVENTS 1024 // system events
2008-06-09 22:00:00 +02:00
2009-01-11 22:00:00 +01:00
// some engine shared constants
#define DEFAULT_MAXVELOCITY "2000"
#define DEFAULT_GRAVITY "800"
2009-01-22 22:00:00 +01:00
#define DEFAULT_ROLLSPEED "200"
#define DEFAULT_ROLLANGLE "2"
#define DEFAULT_STEPHEIGHT "18"
#define DEFAULT_AIRACCEL "0"
#define DEFAULT_MAXSPEED "320"
#define DEFAULT_ACCEL "10"
#define DEFAULT_FRICTION "4"
2009-01-11 22:00:00 +01:00
2009-11-02 22:00:00 +01:00
/*
==============================================================
SCREEN GLOBAL INFO
2009-01-09 22:00:00 +01:00
2009-11-02 22:00:00 +01:00
==============================================================
*/
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
extern cvar_t *scr_width;
extern cvar_t *scr_height;
2008-06-09 22:00:00 +02:00
/*
==============================================================
2007-06-21 22:00:00 +02:00
2008-06-09 22:00:00 +02:00
HOST INTERFACE
==============================================================
2007-06-21 22:00:00 +02:00
*/
2008-06-09 22:00:00 +02:00
typedef enum
{
2008-06-12 22:00:00 +02:00
HOST_INIT = 0, // initalize operations
2008-06-09 22:00:00 +02:00
HOST_FRAME, // host running
HOST_SHUTDOWN, // shutdown operations
HOST_ERROR, // host stopped by error
HOST_SLEEP, // sleeped by different reason, e.g. minimize window
HOST_NOFOCUS, // same as HOST_FRAME, but disable mouse
2009-02-02 22:00:00 +01:00
HOST_RESTART, // during the changes video mode
2008-06-09 22:00:00 +02:00
} host_state;
2008-07-12 22:00:00 +02:00
typedef enum
{
RD_NONE = 0,
RD_CLIENT,
RD_PACKET,
2008-08-04 22:00:00 +02:00
} rdtype_t;
2008-07-12 22:00:00 +02:00
2008-06-09 22:00:00 +02:00
typedef struct host_redirect_s
{
2009-10-28 22:00:00 +01:00
rdtype_t target;
char *buffer;
int buffersize;
netadr_t address;
void (*flush)( netadr_t adr, rdtype_t target, char *buffer );
2008-06-09 22:00:00 +02:00
} host_redirect_t;
typedef struct host_parm_s
{
host_state state; // global host state
uint type; // running at
host_redirect_t rd; // remote console
jmp_buf abortframe; // abort current frame
2008-11-04 22:00:00 +01:00
dword errorframe; // to avoid each-frame host error
2008-06-09 22:00:00 +02:00
string finalmsg; // server shutdown final message
2009-09-20 22:00:00 +02:00
int frametime[2]; // time between engine frames
uint framecount; // global framecount
int events_head;
int events_tail;
sys_event_t events[MAX_EVENTS];
2009-09-16 22:00:00 +02:00
2008-07-11 22:00:00 +02:00
HWND hWnd; // main window
int developer; // show all developer's message
2008-06-09 22:00:00 +02:00
} host_parm_t;
2009-11-02 22:00:00 +01:00
extern host_parm_t host;
2008-08-04 22:00:00 +02:00
//
// host.c
//
2009-08-18 22:00:00 +02:00
void Host_Init( const int argc, const char **argv );
void Host_Main( void );
void Host_Free( void );
2008-06-09 22:00:00 +02:00
void Host_SetServerState( int state );
int Host_ServerState( void );
2009-09-28 22:00:00 +02:00
int Host_CompareFileTime( long ft1, long ft2 );
2009-10-16 22:00:00 +02:00
void Host_EndGame( const char *message, ... );
2008-06-09 22:00:00 +02:00
void Host_AbortCurrentFrame( void );
2009-09-10 22:00:00 +02:00
void Host_WriteDefaultConfig( void );
void Host_WriteConfig( void );
2009-10-13 22:00:00 +02:00
void Host_ShutdownServer( void );
2009-10-02 22:00:00 +02:00
void Host_CheckChanges( void );
2009-09-22 22:00:00 +02:00
int Host_Milliseconds( void );
2009-09-10 22:00:00 +02:00
void Host_Print( const char *txt );
2008-06-09 22:00:00 +02:00
void Host_Error( const char *error, ... );
2007-06-21 22:00:00 +02:00
/*
==============================================================
2008-06-09 22:00:00 +02:00
CLIENT / SERVER SYSTEMS
2007-06-21 22:00:00 +02:00
==============================================================
*/
2008-06-09 22:00:00 +02:00
void CL_Init( void );
void CL_Shutdown( void );
2009-09-20 22:00:00 +02:00
void CL_Frame( int time );
2009-11-02 22:00:00 +01:00
bool CL_Active( void );
2008-06-09 22:00:00 +02:00
void SV_Init( void );
void SV_Shutdown( bool reconnect );
2009-09-20 22:00:00 +02:00
void SV_Frame( int time );
2008-12-15 22:00:00 +01:00
bool SV_Active( void );
2008-06-09 22:00:00 +02:00
/*
==============================================================
2009-11-02 22:00:00 +01:00
SHARED ENGFUNCS
2008-06-09 22:00:00 +02:00
==============================================================
*/
2009-11-02 22:00:00 +01:00
//
// obsolete vm stuff
//
#define VM_Frame vm->Update
2009-01-11 22:00:00 +01:00
void pfnMemCopy( void *dest, const void *src, size_t cb, const char *filename, const int fileline );
2009-01-22 22:00:00 +01:00
cvar_t *pfnCVarRegister( const char *szName, const char *szValue, int flags, const char *szDesc );
2009-01-02 22:00:00 +01:00
byte* pfnLoadFile( const char *filename, int *pLength );
2009-09-22 22:00:00 +02:00
void pfnFreeFile( void *buffer );
2009-01-02 22:00:00 +01:00
int pfnFileExists( const char *filename );
long pfnRandomLong( long lLow, long lHigh );
float pfnRandomFloat( float flLow, float flHigh );
void pfnAlertMessage( ALERT_TYPE level, char *szFmt, ... );
2009-01-22 22:00:00 +01:00
void *pfnFOpen( const char* path, const char* mode );
long pfnFWrite( void *file, const void* data, size_t datasize );
long pfnFRead( void *file, void* buffer, size_t buffersize );
int pfnFGets( void *file, byte *string, size_t bufsize );
int pfnFSeek( void *file, long offset, int whence );
int pfnFClose( void *file );
long pfnFTell( void *file );
2009-01-02 22:00:00 +01:00
void pfnGetGameDir( char *szGetGameDir );
2009-09-22 22:00:00 +02:00
float pfnTime( void );
2009-01-02 22:00:00 +01:00
2008-06-09 22:00:00 +02:00
/*
==============================================================
2009-11-02 22:00:00 +01:00
MISC COMMON FUNCTIONS
2008-06-09 22:00:00 +02:00
==============================================================
*/
2008-07-23 22:00:00 +02:00
#define MAX_INFO_STRING 512
2009-11-02 22:00:00 +01:00
extern byte *zonepool;
#define Z_Malloc(size) Mem_Alloc( zonepool, size )
#define Z_Realloc( ptr, size ) Mem_Realloc( zonepool, ptr, size )
#define Z_Free( ptr ) if( ptr ) Mem_Free( ptr )
2008-07-30 22:00:00 +02:00
2009-11-02 22:00:00 +01:00
//
// physic.dll exports
//
2009-10-28 22:00:00 +01:00
#define Mod_GetBounds if( pe ) pe->Mod_GetBounds
#define Mod_GetFrames if( pe ) pe->Mod_GetFrames
#define CM_RegisterModel if( pe ) pe->RegisterModel
2009-11-02 22:00:00 +01:00
_inline int CM_LeafArea( int leafnum )
2009-10-28 22:00:00 +01:00
{
2009-11-02 22:00:00 +01:00
if( !pe ) return -1;
return pe->LeafArea( leafnum );
}
_inline int CM_LeafCluster( int leafnum )
{
if( !pe ) return -1;
return pe->LeafCluster( leafnum );
2009-10-28 22:00:00 +01:00
}
2009-11-02 22:00:00 +01:00
_inline int CM_BoxLeafnums( vec3_t mins, vec3_t maxs, int *list, int listsize, int *lastleaf )
{
if( !pe )
{
if( lastleaf ) *lastleaf = 0;
return 0;
}
return pe->BoxLeafnums( mins, maxs, list, listsize, lastleaf );
}
2009-10-28 22:00:00 +01:00
2009-11-02 22:00:00 +01:00
_inline void *Mod_Extradata( model_t modelIndex )
{
if( !pe ) return NULL;
return pe->Mod_Extradata( modelIndex );
}
2008-06-09 22:00:00 +02:00
2008-06-12 22:00:00 +02:00
void CL_GetEntitySoundSpatialization( int ent, vec3_t origin, vec3_t velocity );
2009-01-09 22:00:00 +01:00
bool SV_GetComment( char *comment, int savenum );
2009-02-03 22:00:00 +01:00
void CL_MouseEvent( int mx, int my );
2008-06-12 22:00:00 +02:00
void CL_AddLoopingSounds( void );
2008-06-09 22:00:00 +02:00
void CL_Drop( void );
char *Info_ValueForKey( char *s, char *key );
void Info_RemoveKey( char *s, char *key );
void Info_SetValueForKey( char *s, char *key, char *value );
bool Info_Validate( char *s );
void Info_Print( char *s );
char *Cvar_Userinfo( void );
char *Cvar_Serverinfo( void );
void Cmd_WriteVariables( file_t *f );
2008-06-22 22:00:00 +02:00
bool Cmd_CheckMapsList( void );
2008-06-09 22:00:00 +02:00
2008-08-03 22:00:00 +02:00
typedef struct autocomplete_list_s
{
const char *name;
bool (*func)( const char *s, char *name, int length );
} autocomplete_list_t;
2007-11-25 22:00:00 +01:00
2008-08-03 22:00:00 +02:00
extern autocomplete_list_t cmd_list[];
2007-06-21 22:00:00 +02:00
#endif//COMMON_H