2012-03-26 22:03:20 +00:00
//
// Definitions of common non-engine data structures/functions
// (and declarations of data appearing in both)
// for EDuke32 and Mapster32
//
# ifndef EDUKE32_COMMON_H_
# define EDUKE32_COMMON_H_
2019-12-17 22:25:07 +00:00
2018-11-18 18:09:48 +00:00
# include "compat.h"
2014-08-31 11:15:17 +00:00
# include "pragmas.h" // klabs
2018-11-18 18:09:48 +00:00
# include "scriptfile.h"
2014-08-31 11:15:17 +00:00
2019-09-18 22:19:02 +00:00
extern bool playing_rr ;
2019-09-19 21:02:57 +00:00
extern bool playing_blood ;
2019-09-18 22:19:02 +00:00
2012-03-26 22:03:20 +00:00
//// TYPES
struct strllist
{
struct strllist * next ;
char * str ;
} ;
2012-03-26 22:05:23 +00:00
typedef struct
{
const char * text ;
int32_t tokenid ;
}
tokenlist ;
2012-03-28 19:41:57 +00:00
2012-03-26 22:05:23 +00:00
enum
{
T_EOF = - 2 ,
T_ERROR = - 1 ,
} ;
2012-03-26 22:03:20 +00:00
//// EXTERN DECLS
2014-07-24 14:01:44 +00:00
extern const char * s_buildRev ;
extern const char * s_buildTimestamp ;
2012-03-26 22:03:20 +00:00
//// FUNCTIONS
2014-07-28 06:43:46 +00:00
2013-11-03 04:02:23 +00:00
void G_AddDef ( const char * buffer ) ;
void G_AddDefModule ( const char * buffer ) ;
# ifdef HAVE_CLIPSHAPE_FEATURE
void G_AddClipMap ( const char * buffer ) ;
# endif
2012-03-26 22:03:20 +00:00
2014-10-25 03:30:38 +00:00
// returns a buffer of size BMAX_PATH
static inline char * dup_filename ( const char * fn )
{
char * const buf = ( char * ) Xmalloc ( BMAX_PATH ) ;
return Bstrncpyz ( buf , fn , BMAX_PATH ) ;
}
2015-01-25 12:17:59 +00:00
static inline void realloc_copy ( char * * fn , const char * buf )
{
uint8_t len = Bstrlen ( buf ) + 1 ;
* fn = ( char * ) Xrealloc ( * fn , len ) ;
Bstrncpy ( * fn , buf , len ) ;
}
2012-03-26 22:05:23 +00:00
int32_t getatoken ( scriptfile * sf , const tokenlist * tl , int32_t ntokens ) ;
2012-09-08 22:18:31 +00:00
int32_t maybe_append_ext ( char * wbuf , int32_t wbufsiz , const char * fn , const char * ext ) ;
2012-03-28 19:43:39 +00:00
2014-08-31 11:15:17 +00:00
// Approximations to 2D and 3D Euclidean distances. Initial EDuke32 SVN import says
2017-02-01 10:20:54 +00:00
// in mact/src/mathutil.c: "Ken's reverse-engineering job".
// Note that mathutil.c contains practically the same code, but where the
2014-08-31 11:15:17 +00:00
// individual x/y(/z) distances are passed instead.
static inline int32_t sepldist ( const int32_t dx , const int32_t dy )
{
2014-12-27 17:17:50 +00:00
vec2_t d = { klabs ( dx ) , klabs ( dy ) } ;
2014-10-25 03:30:38 +00:00
2019-12-18 09:31:32 +00:00
if ( ! d . y ) return d . x ;
if ( ! d . x ) return d . y ;
2019-09-18 22:19:02 +00:00
2014-10-25 03:30:38 +00:00
if ( d . x < d . y )
swaplong ( & d . x , & d . y ) ;
2014-08-31 11:15:17 +00:00
2014-10-25 03:30:38 +00:00
d . y + = ( d . y > > 1 ) ;
2014-08-31 11:15:17 +00:00
2014-10-25 03:30:38 +00:00
return d . x - ( d . x > > 5 ) - ( d . x > > 7 ) + ( d . y > > 2 ) + ( d . y > > 6 ) ;
2014-08-31 11:15:17 +00:00
}
// dz: in Build coordinates
2014-10-25 03:30:38 +00:00
static inline int32_t sepdist ( const int32_t dx , const int32_t dy , const int32_t dz )
2014-08-31 11:15:17 +00:00
{
2014-12-27 17:17:50 +00:00
vec3_t d = { klabs ( dx ) , klabs ( dy ) , klabs ( dz > > 4 ) } ;
2014-10-25 03:30:38 +00:00
if ( d . x < d . y )
swaplong ( & d . x , & d . y ) ;
if ( d . x < d . z )
swaplong ( & d . x , & d . z ) ;
d . y + = d . z ;
return d . x - ( d . x > > 4 ) + ( d . y > > 2 ) + ( d . y > > 3 ) ;
2014-08-31 11:15:17 +00:00
}
2015-05-19 21:56:03 +00:00
int32_t FindDistance2D ( int32_t dx , int32_t dy ) ;
int32_t FindDistance3D ( int32_t dx , int32_t dy , int32_t dz ) ;
2015-01-12 09:28:41 +00:00
int32_t ldist ( const void * s1 , const void * s2 ) ;
int32_t dist ( const void * s1 , const void * s2 ) ;
2012-11-29 14:08:03 +00:00
2012-12-25 16:13:50 +00:00
void COMMON_clearbackground ( int32_t numcols , int32_t numrows ) ;
2012-04-04 18:57:42 +00:00
// timer defs for profiling function chunks the simple way
2018-04-12 21:02:51 +00:00
# define EDUKE32_TMRDEF int32_t t[20], ti=0; const char *tmrstr=__func__; fprintf(stderr,"%s\n",tmrstr); t[ti++]=timerGetTicks();
# define EDUKE32_TMRTIC t[ti++]=timerGetTicks()
2012-04-04 18:57:42 +00:00
# define EDUKE32_TMRPRN do { int ii=0; fprintf(stderr,"%s: ",tmrstr); for (ii=1; ii<ti; ii++) fprintf(stderr,"%d ", t[ii]-t[ii-1]); fprintf(stderr,"\n"); } while (0)
2019-10-30 05:51:39 +00:00
# if defined _WIN32 && !defined EDUKE32_STANDALONE
int Paths_ReadRegistryValue ( char const * const SubKey , char const * const Value , char * const Output , DWORD * OutputSize ) ;
# endif
2019-10-30 05:51:34 +00:00
using SteamPathParseFunc = void ( * ) ( const char * ) ;
void Paths_ParseSteamKeyValuesForPaths ( const char * vdf , SteamPathParseFunc func ) ;
2012-03-26 22:03:20 +00:00
# endif