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_
2014-09-30 04:12:41 +00:00
# include "compat.h"
2012-03-26 22:05:23 +00:00
# include "scriptfile.h"
2012-03-28 19:41:57 +00:00
# include "cache1d.h"
2014-08-31 11:15:17 +00:00
# include "pragmas.h" // klabs
# include "build.h"
2012-03-26 22:05:23 +00:00
2014-11-26 04:39:23 +00:00
# ifdef __cplusplus
2012-11-05 02:49:08 +00:00
extern " C " {
# endif
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
typedef struct
{
CACHE1D_FIND_REC * finddirs , * findfiles ;
int32_t numdirs , numfiles ;
}
fnlist_t ;
# define FNLIST_INITIALIZER { NULL, NULL, 0, 0 }
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
extern struct strllist * CommandPaths , * CommandGrps ;
2014-07-28 08:59:58 +00:00
# ifdef __cplusplus
extern " C " {
# endif
2014-07-24 14:01:44 +00:00
extern const char * s_buildRev ;
extern const char * s_buildTimestamp ;
2014-07-28 08:59:58 +00:00
# ifdef __cplusplus
}
# endif
2014-07-24 14:01:44 +00:00
extern const char * s_buildInfo ;
2012-03-26 22:03:20 +00:00
//// FUNCTIONS
2014-07-28 06:43:46 +00:00
extern void clearDefNamePtr ( void ) ;
2012-03-26 22:03:20 +00:00
void G_AddGroup ( const char * buffer ) ;
void G_AddPath ( const char * buffer ) ;
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 ) ;
}
2012-03-26 22:05:23 +00:00
int32_t getatoken ( scriptfile * sf , const tokenlist * tl , int32_t ntokens ) ;
2014-07-28 06:42:28 +00:00
int32_t G_CheckCmdSwitch ( int32_t argc , const char * * argv , const char * str ) ;
2012-06-11 20:35:47 +00:00
int32_t testkopen ( const char * filename , char searchfirst ) ; // full-blown kopen4load
int32_t check_file_exist ( const char * fn ) ; // findfrompath with pathsearchmode=1 / search in zips
2012-03-28 19:41:39 +00:00
2012-03-28 19:41:57 +00:00
void fnlist_clearnames ( fnlist_t * fnl ) ;
int32_t fnlist_getnames ( fnlist_t * fnl , const char * dirname , const char * pattern ,
int32_t dirflags , int32_t fileflags ) ;
2012-03-28 19:43:39 +00:00
char * dup_filename ( const char * fn ) ;
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
// in jmact/mathutil.c: "Ken's reverse-engineering job".
// Note that jmact/mathutil.c contains practically the same code, but where the
// 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
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
}
2012-11-29 14:08:03 +00:00
int32_t ldist ( const spritetype * s1 , const spritetype * s2 ) ;
int32_t dist ( const spritetype * s1 , const spritetype * s2 ) ;
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
# define EDUKE32_TMRDEF int32_t t[20], ti=0; const char *tmrstr=__func__; fprintf(stderr,"%s\n",tmrstr); t[ti++]=getticks();
# define EDUKE32_TMRTIC t[ti++]=getticks()
# 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)
2014-11-26 04:39:23 +00:00
# ifdef __cplusplus
2012-11-05 02:49:08 +00:00
}
# endif
2012-03-26 22:03:20 +00:00
# endif