Move code non-specific to Duke Nukem 3D from source/common.c to a new build/src/common.c.

DONT_BUILD.

git-svn-id: https://svn.eduke32.com/eduke32@4559 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2014-07-28 06:43:46 +00:00
parent b48f3b44e3
commit 5237346f5b
7 changed files with 278 additions and 258 deletions

View file

@ -35,7 +35,7 @@ UTIL_LIBS= -lm # -lpthread
ENGINE_OBJ=$(ENGINE_ROOT)/$(obj)
ENGINE_OBJS=baselayer cache1d compat crc32 defs engine polymost texcache dxtfilter hightile textfont smalltextfont kplib lz4 osd pragmas scriptfile mmulti_null mutex xxhash
ENGINE_OBJS=baselayer cache1d common compat crc32 defs engine polymost texcache dxtfilter hightile textfont smalltextfont kplib lz4 osd pragmas scriptfile mmulti_null mutex xxhash
ENGINE_EDITOR_OBJS=build config defs
ifeq (0,$(NOASM))
ENGINE_OBJS+= a
@ -216,11 +216,11 @@ MAPSTER32 ?= mapster32$(EXESUFFIX)
EDUKE32_TARGET:=$(EDUKE32)
MAPSTER32_TARGET:=$(MAPSTER32)
COMMON_OBJS=common rev
COMMON_EDITOR_OBJS=common m32def m32exec m32vars mathutil rev
COMMON_OBJS=rev
COMMON_EDITOR_OBJS=m32def m32exec m32vars mathutil rev
DUKE3D_OBJS=game actors anim config demo gamedef gameexec gamevars global input menus namesdyn net player premap savegame sector rts osdfuncs osdcmds grpscan sounds soundsdyn $(MACT_OBJ)
DUKE3D_EDITOR_OBJS=astub grpscan sounds_mapster32
DUKE3D_OBJS=game actors anim common config demo gamedef gameexec gamevars global input menus namesdyn net player premap savegame sector rts osdfuncs osdcmds grpscan sounds soundsdyn $(MACT_OBJ)
DUKE3D_EDITOR_OBJS=astub common grpscan sounds_mapster32
ifneq ($(USE_LIBVPX),0)
DUKE3D_OBJS+= animvpx

View file

@ -126,6 +126,7 @@ ENGINE_OBJS= \
!endif
$(ENGINE_OBJ)\baselayer.$o \
$(ENGINE_OBJ)\cache1d.$o \
$(ENGINE_OBJ)\common.$o \
$(ENGINE_OBJ)\compat.$o \
$(ENGINE_OBJ)\crc32.$o \
$(ENGINE_OBJ)\defs.$o \

View file

@ -52,6 +52,8 @@ extern const char *s_buildTimestamp;
extern const char *s_buildInfo;
//// FUNCTIONS
extern void clearDefNamePtr(void);
void G_AddGroup(const char *buffer);
void G_AddPath(const char *buffer);
void G_AddDef(const char *buffer);
@ -71,9 +73,6 @@ 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);
void G_LoadGroupsInDir(const char *dirname);
void G_DoAutoload(const char *dirname);
char *dup_filename(const char *fn);
int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char *ext);

View file

@ -0,0 +1,258 @@
#include "compat.h"
#include "build.h"
#include "scriptfile.h"
#include "cache1d.h"
#include "kplib.h"
#include "baselayer.h"
#include "common.h"
const char* s_buildInfo =
#ifdef BITNESS64
"(64-bit)"
#else
"(32-bit)"
#endif
#if defined (_MSC_VER) || defined(__cplusplus)
#ifdef _MSC_VER
" MSVC"
#endif
#ifdef __cplusplus
" C++"
#endif
" build"
#endif
;
// def/clipmap handling
// g_defNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
char *g_defNamePtr = NULL;
void clearDefNamePtr(void)
{
if (g_defNamePtr != NULL)
Bfree(g_defNamePtr);
// g_defNamePtr assumed to be assigned to right after
}
char **g_defModules = NULL;
int32_t g_defModulesNum = 0;
#ifdef HAVE_CLIPSHAPE_FEATURE
char **g_clipMapFiles = NULL;
int32_t g_clipMapFilesNum = 0;
#endif
void G_AddDef(const char *buffer)
{
clearDefNamePtr();
g_defNamePtr = dup_filename(buffer);
initprintf("Using DEF file \"%s\".\n",g_defNamePtr);
}
void G_AddDefModule(const char *buffer)
{
g_defModules = (char **) Xrealloc (g_defModules, (g_defModulesNum+1) * sizeof(char *));
g_defModules[g_defModulesNum] = Xstrdup(buffer);
++g_defModulesNum;
}
#ifdef HAVE_CLIPSHAPE_FEATURE
void G_AddClipMap(const char *buffer)
{
g_clipMapFiles = (char **) Xrealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *));
g_clipMapFiles[g_clipMapFilesNum] = Xstrdup(buffer);
++g_clipMapFilesNum;
}
#endif
//////////
int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens)
{
char *tok;
int32_t i;
if (!sf) return T_ERROR;
tok = scriptfile_gettoken(sf);
if (!tok) return T_EOF;
for (i=ntokens-1; i>=0; i--)
{
if (!Bstrcasecmp(tok, tl[i].text))
return tl[i].tokenid;
}
return T_ERROR;
}
//////////
int32_t G_CheckCmdSwitch(int32_t argc, const char **argv, const char *str)
{
int32_t i;
for (i=0; i<argc; i++)
{
if (str && !Bstrcasecmp(argv[i], str))
return 1;
}
return 0;
}
// returns: 1 if file could be opened, 0 else
int32_t testkopen(const char *filename, char searchfirst)
{
int32_t fd = kopen4load(filename, searchfirst);
if (fd >= 0)
kclose(fd);
return (fd >= 0);
}
// checks from path and in ZIPs, returns 1 if NOT found
int32_t check_file_exist(const char *fn)
{
int32_t opsm = pathsearchmode;
char *tfn;
pathsearchmode = 1;
if (findfrompath(fn,&tfn) < 0)
{
char buf[BMAX_PATH];
Bstrcpy(buf,fn);
kzfindfilestart(buf);
if (!kzfindfile(buf))
{
initprintf("Error: file \"%s\" does not exist\n",fn);
pathsearchmode = opsm;
return 1;
}
}
else Bfree(tfn);
pathsearchmode = opsm;
return 0;
}
//// FILE NAME / DIRECTORY LISTS ////
void fnlist_clearnames(fnlist_t *fnl)
{
klistfree(fnl->finddirs);
klistfree(fnl->findfiles);
fnl->finddirs = fnl->findfiles = NULL;
fnl->numfiles = fnl->numdirs = 0;
}
// dirflags, fileflags:
// -1 means "don't get dirs/files",
// otherwise ORed to flags for respective klistpath
int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern,
int32_t dirflags, int32_t fileflags)
{
CACHE1D_FIND_REC *r;
fnlist_clearnames(fnl);
if (dirflags != -1)
fnl->finddirs = klistpath(dirname, "*", CACHE1D_FIND_DIR|dirflags);
if (fileflags != -1)
fnl->findfiles = klistpath(dirname, pattern, CACHE1D_FIND_FILE|fileflags);
for (r=fnl->finddirs; r; r=r->next)
fnl->numdirs++;
for (r=fnl->findfiles; r; r=r->next)
fnl->numfiles++;
return(0);
}
////
// returns a buffer of size BMAX_PATH
char *dup_filename(const char *fn)
{
char *buf = (char *)Xmalloc(BMAX_PATH);
return Bstrncpyz(buf, fn, BMAX_PATH);
}
// Copy FN to WBUF and append an extension if it's not there, which is checked
// case-insensitively.
// Returns: 1 if not all characters could be written to WBUF, 0 else.
int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char *ext)
{
const int32_t slen=Bstrlen(fn), extslen=Bstrlen(ext);
const int32_t haveext = (slen>=extslen && Bstrcasecmp(&fn[slen-extslen], ext)==0);
Bassert((intptr_t)wbuf != (intptr_t)fn); // no aliasing
// If 'fn' has no extension suffixed, append one.
return (Bsnprintf(wbuf, wbufsiz, "%s%s", fn, haveext ? "" : ext) >= wbufsiz);
}
// 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.
int32_t ldist(const spritetype *s1, const spritetype *s2)
{
int32_t x = klabs(s1->x-s2->x);
int32_t y = klabs(s1->y-s2->y);
if (x<y) swaplong(&x,&y);
{
int32_t t = y + (y>>1);
return (x - (x>>5) - (x>>7) + (t>>2) + (t>>6));
}
}
int32_t dist(const spritetype *s1, const spritetype *s2)
{
int32_t x = klabs(s1->x-s2->x);
int32_t y = klabs(s1->y-s2->y);
int32_t z = klabs((s1->z-s2->z)>>4);
if (x<y) swaplong(&x,&y);
if (x<z) swaplong(&x,&z);
{
int32_t t = y + z;
return (x - (x>>4) + (t>>2) + (t>>3));
}
}
// Clear OSD background
void COMMON_clearbackground(int32_t numcols, int32_t numrows)
{
UNREFERENCED_PARAMETER(numcols);
# ifdef USE_OPENGL
if (getrendermode() >= REND_POLYMOST && qsetmode==200)
{
bglPushAttrib(GL_FOG_BIT);
bglDisable(GL_FOG);
setpolymost2dview();
bglColor4f(0,0,0,0.67f);
bglEnable(GL_BLEND);
bglRectd(0,0, xdim,8*numrows+8);
bglColor4f(0,0,0,1);
bglRectd(0,8*numrows+4, xdim,8*numrows+8);
bglPopAttrib();
return;
}
# endif
CLEARLINES2D(0, min(ydim, numrows*8+8), editorcolors[16]);
}

View file

@ -4,11 +4,7 @@
#include "compat.h"
#include "build.h"
#include "scriptfile.h"
#include "cache1d.h"
#include "kplib.h"
#include "baselayer.h"
#include "names.h"
#include "grpscan.h"
#ifdef _WIN32
@ -23,23 +19,6 @@
#include "common.h"
#include "common_game.h"
const char* s_buildInfo =
#ifdef BITNESS64
"(64-bit)"
#else
"(32-bit)"
#endif
#if defined (_MSC_VER) || defined(__cplusplus)
#ifdef _MSC_VER
" MSVC"
#endif
#ifdef __cplusplus
" C++"
#endif
" build"
#endif
;
int32_t g_gameType = GAMEFLAG_DUKE;
int32_t g_dependencyCRC = 0;
@ -49,7 +28,7 @@ int32_t g_usingAddon = 0;
// literal, malloc'd block (XXX: possible leak)
const char *g_gameNamePtr = NULL;
// grp/con/def handling
// grp/con handling
const char *defaultgamegrp[GAMECOUNT] = { "DUKE3D.GRP", "NAM.GRP", "NAPALM.GRP", "WW2GI.GRP" };
const char *defaultdeffilename[GAMECOUNT] = { "duke3d.def", "nam.def", "napalm.def", "ww2gi.def" };
@ -58,8 +37,6 @@ const char *defaultgameconfilename[GAMECOUNT] = { "EDUKE.CON", "NAM.CON", "NAPAL
// g_grpNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
char *g_grpNamePtr = NULL;
// g_defNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
char *g_defNamePtr = NULL;
// g_scriptNamePtr can ONLY point to a malloc'd block (length BMAX_PATH)
char *g_scriptNamePtr = NULL;
@ -70,13 +47,6 @@ void clearGrpNamePtr(void)
// g_grpNamePtr assumed to be assigned to right after
}
void clearDefNamePtr(void)
{
if (g_defNamePtr != NULL)
Bfree(g_defNamePtr);
// g_defNamePtr assumed to be assigned to right after
}
void clearScriptNamePtr(void)
{
if (g_scriptNamePtr != NULL)
@ -680,13 +650,6 @@ struct strllist *CommandPaths, *CommandGrps;
char **g_scriptModules = NULL;
int32_t g_scriptModulesNum = 0;
char **g_defModules = NULL;
int32_t g_defModulesNum = 0;
#ifdef HAVE_CLIPSHAPE_FEATURE
char **g_clipMapFiles = NULL;
int32_t g_clipMapFilesNum = 0;
#endif
void G_AddGroup(const char *buffer)
{
@ -726,29 +689,6 @@ void G_AddPath(const char *buffer)
CommandPaths = s;
}
void G_AddDef(const char *buffer)
{
clearDefNamePtr();
g_defNamePtr = dup_filename(buffer);
initprintf("Using DEF file \"%s\".\n",g_defNamePtr);
}
void G_AddDefModule(const char *buffer)
{
g_defModules = (char **) Xrealloc (g_defModules, (g_defModulesNum+1) * sizeof(char *));
g_defModules[g_defModulesNum] = Xstrdup(buffer);
++g_defModulesNum;
}
#ifdef HAVE_CLIPSHAPE_FEATURE
void G_AddClipMap(const char *buffer)
{
g_clipMapFiles = (char **) Xrealloc (g_clipMapFiles, (g_clipMapFilesNum+1) * sizeof(char *));
g_clipMapFiles[g_clipMapFilesNum] = Xstrdup(buffer);
++g_clipMapFilesNum;
}
#endif
void G_AddCon(const char *buffer)
{
clearScriptNamePtr();
@ -765,107 +705,6 @@ void G_AddConModule(const char *buffer)
//////////
int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens)
{
char *tok;
int32_t i;
if (!sf) return T_ERROR;
tok = scriptfile_gettoken(sf);
if (!tok) return T_EOF;
for (i=ntokens-1; i>=0; i--)
{
if (!Bstrcasecmp(tok, tl[i].text))
return tl[i].tokenid;
}
return T_ERROR;
}
//////////
int32_t G_CheckCmdSwitch(int32_t argc, const char **argv, const char *str)
{
int32_t i;
for (i=0; i<argc; i++)
{
if (str && !Bstrcasecmp(argv[i], str))
return 1;
}
return 0;
}
// returns: 1 if file could be opened, 0 else
int32_t testkopen(const char *filename, char searchfirst)
{
int32_t fd = kopen4load(filename, searchfirst);
if (fd >= 0)
kclose(fd);
return (fd >= 0);
}
// checks from path and in ZIPs, returns 1 if NOT found
int32_t check_file_exist(const char *fn)
{
int32_t opsm = pathsearchmode;
char *tfn;
pathsearchmode = 1;
if (findfrompath(fn,&tfn) < 0)
{
char buf[BMAX_PATH];
Bstrcpy(buf,fn);
kzfindfilestart(buf);
if (!kzfindfile(buf))
{
initprintf("Error: file \"%s\" does not exist\n",fn);
pathsearchmode = opsm;
return 1;
}
}
else Bfree(tfn);
pathsearchmode = opsm;
return 0;
}
//// FILE NAME / DIRECTORY LISTS ////
void fnlist_clearnames(fnlist_t *fnl)
{
klistfree(fnl->finddirs);
klistfree(fnl->findfiles);
fnl->finddirs = fnl->findfiles = NULL;
fnl->numfiles = fnl->numdirs = 0;
}
// dirflags, fileflags:
// -1 means "don't get dirs/files",
// otherwise ORed to flags for respective klistpath
int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern,
int32_t dirflags, int32_t fileflags)
{
CACHE1D_FIND_REC *r;
fnlist_clearnames(fnl);
if (dirflags != -1)
fnl->finddirs = klistpath(dirname, "*", CACHE1D_FIND_DIR|dirflags);
if (fileflags != -1)
fnl->findfiles = klistpath(dirname, pattern, CACHE1D_FIND_FILE|fileflags);
for (r=fnl->finddirs; r; r=r->next)
fnl->numdirs++;
for (r=fnl->findfiles; r; r=r->next)
fnl->numfiles++;
return(0);
}
// loads all group (grp, zip, pk3/4) files in the given directory
void G_LoadGroupsInDir(const char *dirname)
{
@ -900,89 +739,3 @@ void G_DoAutoload(const char *dirname)
Bsnprintf(buf, sizeof(buf), "autoload/%s", dirname);
G_LoadGroupsInDir(buf);
}
////
// returns a buffer of size BMAX_PATH
char *dup_filename(const char *fn)
{
char *buf = (char *)Xmalloc(BMAX_PATH);
return Bstrncpyz(buf, fn, BMAX_PATH);
}
// Copy FN to WBUF and append an extension if it's not there, which is checked
// case-insensitively.
// Returns: 1 if not all characters could be written to WBUF, 0 else.
int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char *ext)
{
const int32_t slen=Bstrlen(fn), extslen=Bstrlen(ext);
const int32_t haveext = (slen>=extslen && Bstrcasecmp(&fn[slen-extslen], ext)==0);
Bassert((intptr_t)wbuf != (intptr_t)fn); // no aliasing
// If 'fn' has no extension suffixed, append one.
return (Bsnprintf(wbuf, wbufsiz, "%s%s", fn, haveext ? "" : ext) >= wbufsiz);
}
// 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.
int32_t ldist(const spritetype *s1, const spritetype *s2)
{
int32_t x = klabs(s1->x-s2->x);
int32_t y = klabs(s1->y-s2->y);
if (x<y) swaplong(&x,&y);
{
int32_t t = y + (y>>1);
return (x - (x>>5) - (x>>7) + (t>>2) + (t>>6));
}
}
int32_t dist(const spritetype *s1, const spritetype *s2)
{
int32_t x = klabs(s1->x-s2->x);
int32_t y = klabs(s1->y-s2->y);
int32_t z = klabs((s1->z-s2->z)>>4);
if (x<y) swaplong(&x,&y);
if (x<z) swaplong(&x,&z);
{
int32_t t = y + z;
return (x - (x>>4) + (t>>2) + (t>>3));
}
}
// Clear OSD background
void COMMON_clearbackground(int32_t numcols, int32_t numrows)
{
UNREFERENCED_PARAMETER(numcols);
# ifdef USE_OPENGL
if (getrendermode() >= REND_POLYMOST && qsetmode==200)
{
bglPushAttrib(GL_FOG_BIT);
bglDisable(GL_FOG);
setpolymost2dview();
bglColor4f(0,0,0,0.67f);
bglEnable(GL_BLEND);
bglRectd(0,0, xdim,8*numrows+8);
bglColor4f(0,0,0,1);
bglRectd(0,8*numrows+4, xdim,8*numrows+8);
bglPopAttrib();
return;
}
# endif
CLEARLINES2D(0, min(ydim, numrows*8+8), editorcolors[16]);
}

View file

@ -66,7 +66,6 @@ extern void G_AddCon(const char *buffer);
extern void G_AddConModule(const char *buffer);
extern void clearGrpNamePtr(void);
extern void clearDefNamePtr(void);
extern void clearScriptNamePtr(void);
extern int32_t loaddefinitions_game(const char *, int32_t);
@ -91,4 +90,9 @@ extern void G_ExtPostStartupWindow(int32_t autoload);
extern const char * G_GetInstallPath(int32_t insttype);
//////////
void G_LoadGroupsInDir(const char *dirname);
void G_DoAutoload(const char *dirname);
#endif

View file

@ -5,6 +5,11 @@
#include "names.h"
#include "common_game.h"
const char *G_DefaultDefFile(void)
{
return "kenbuild.def";
}
uint8_t *basepaltable[1] = {
palette
};