Relocate maphack related code into mhk.c.

This commit also relocates clipping related code into clip.c and makes a few other minor changes, because I fucked up and merged the commits together. God damn it.

git-svn-id: https://svn.eduke32.com/eduke32@5792 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2016-06-21 00:33:30 +00:00
parent cb2382285f
commit 32450bdd68
13 changed files with 2306 additions and 2298 deletions

View file

@ -43,6 +43,7 @@ ENGINE_OBJS = \
crc32 \ crc32 \
defs \ defs \
engine \ engine \
clip \
2d \ 2d \
hash \ hash \
palette \ palette \
@ -62,7 +63,8 @@ ENGINE_OBJS = \
xxhash \ xxhash \
md4 \ md4 \
colmatch \ colmatch \
screenshot screenshot \
mhk
ENGINE_EDITOR_OBJS = \ ENGINE_EDITOR_OBJS = \
build \ build \

View file

@ -137,6 +137,7 @@ ENGINE_OBJS= \
$(ENGINE_OBJ)\defs.$o \ $(ENGINE_OBJ)\defs.$o \
$(ENGINE_OBJ)\colmatch.$o \ $(ENGINE_OBJ)\colmatch.$o \
$(ENGINE_OBJ)\engine.$o \ $(ENGINE_OBJ)\engine.$o \
$(ENGINE_OBJ)\clip.$o \
$(ENGINE_OBJ)\2d.$o \ $(ENGINE_OBJ)\2d.$o \
$(ENGINE_OBJ)\hash.$o \ $(ENGINE_OBJ)\hash.$o \
$(ENGINE_OBJ)\palette.$o \ $(ENGINE_OBJ)\palette.$o \
@ -160,7 +161,8 @@ ENGINE_OBJS= \
$(ENGINE_OBJ)\mutex.$o \ $(ENGINE_OBJ)\mutex.$o \
$(ENGINE_OBJ)\winbits.$o \ $(ENGINE_OBJ)\winbits.$o \
$(ENGINE_OBJ)\xxhash.$o \ $(ENGINE_OBJ)\xxhash.$o \
$(ENGINE_OBJ)\screenshot.$o $(ENGINE_OBJ)\screenshot.$o \
$(ENGINE_OBJ)\mhk.$o
ENGINE_EDITOR_OBJS=$(ENGINE_OBJ)\build.$o \ ENGINE_EDITOR_OBJS=$(ENGINE_OBJ)\build.$o \
$(ENGINE_OBJ)\startwin.editor.$o \ $(ENGINE_OBJ)\startwin.editor.$o \

View file

@ -11,8 +11,11 @@ $(ENGINE_OBJ)/crc32.$o: $(ENGINE_SRC)/crc32.c $(ENGINE_INC)/crc32.h
$(ENGINE_OBJ)/defs.$o: $(ENGINE_SRC)/defs.c $(ENGINE_INC)/build.h $(ENGINE_INC)/buildtypes.h $(ENGINE_INC)/baselayer.h $(ENGINE_INC)/scriptfile.h $(ENGINE_INC)/compat.h $(ENGINE_OBJ)/defs.$o: $(ENGINE_SRC)/defs.c $(ENGINE_INC)/build.h $(ENGINE_INC)/buildtypes.h $(ENGINE_INC)/baselayer.h $(ENGINE_INC)/scriptfile.h $(ENGINE_INC)/compat.h
$(ENGINE_OBJ)/engine.$o: $(ENGINE_SRC)/engine.c $(ENGINE_INC)/compat.h $(ENGINE_INC)/build.h $(ENGINE_INC)/buildtypes.h $(ENGINE_INC)/pragmas.h $(ENGINE_INC)/cache1d.h $(ENGINE_INC)/a.h $(ENGINE_INC)/osd.h $(ENGINE_INC)/baselayer.h $(ENGINE_SRC)/engine_priv.h $(ENGINE_SRC)/engine_oldmap.h $(ENGINE_INC)/polymost.h $(ENGINE_INC)/hightile.h $(ENGINE_INC)/mdsprite.h $(ENGINE_INC)/polymer.h $(ENGINE_OBJ)/engine.$o: $(ENGINE_SRC)/engine.c $(ENGINE_INC)/compat.h $(ENGINE_INC)/build.h $(ENGINE_INC)/buildtypes.h $(ENGINE_INC)/pragmas.h $(ENGINE_INC)/cache1d.h $(ENGINE_INC)/a.h $(ENGINE_INC)/osd.h $(ENGINE_INC)/baselayer.h $(ENGINE_SRC)/engine_priv.h $(ENGINE_SRC)/engine_oldmap.h $(ENGINE_INC)/polymost.h $(ENGINE_INC)/hightile.h $(ENGINE_INC)/mdsprite.h $(ENGINE_INC)/polymer.h
$(ENGINE_OBJ)/2d.$o: $(ENGINE_SRC)/2d.c $(ENGINE_OBJ)/2d.$o: $(ENGINE_SRC)/2d.c
$(ENGINE_OBJ)/clip.$o: $(ENGINE_SRC)/clip.c
$(ENGINE_OBJ)/screenshot.$o: $(ENGINE_SRC)/screenshot.c $(ENGINE_OBJ)/screenshot.$o: $(ENGINE_SRC)/screenshot.c
$(ENGINE_OBJ)/hash.$o: $(ENGINE_SRC)/hash.c $(ENGINE_INC)/hash.h $(ENGINE_OBJ)/hash.$o: $(ENGINE_SRC)/hash.c $(ENGINE_INC)/hash.h
$(ENGINE_OBJ)/colmatch.$o: $(ENGINE_SRC)/colmatch.c
$(ENGINE_OBJ)/mhk.$o: $(ENGINE_SRC)/mhk.c
$(ENGINE_OBJ)/palette.$o: $(ENGINE_SRC)/palette.c $(ENGINE_INC)/palette.h $(ENGINE_OBJ)/palette.$o: $(ENGINE_SRC)/palette.c $(ENGINE_INC)/palette.h
$(ENGINE_OBJ)/polymost.$o: $(ENGINE_SRC)/polymost.c $(ENGINE_INC)/lz4.h $(ENGINE_INC)/compat.h $(ENGINE_INC)/build.h $(ENGINE_INC)/buildtypes.h $(ENGINE_SRC)/engine_priv.h $(ENGINE_INC)/polymost.h $(ENGINE_INC)/hightile.h $(ENGINE_INC)/mdsprite.h $(ENGINE_INC)/texcache.h $(ENGINE_OBJ)/polymost.$o: $(ENGINE_SRC)/polymost.c $(ENGINE_INC)/lz4.h $(ENGINE_INC)/compat.h $(ENGINE_INC)/build.h $(ENGINE_INC)/buildtypes.h $(ENGINE_SRC)/engine_priv.h $(ENGINE_INC)/polymost.h $(ENGINE_INC)/hightile.h $(ENGINE_INC)/mdsprite.h $(ENGINE_INC)/texcache.h
$(ENGINE_OBJ)/texcache.$o: $(ENGINE_SRC)/texcache.c $(ENGINE_INC)/texcache.h $(ENGINE_INC)/polymost.h $(ENGINE_INC)/dxtfilter.h $(ENGINE_INC)/kplib.h $(ENGINE_OBJ)/texcache.$o: $(ENGINE_SRC)/texcache.c $(ENGINE_INC)/texcache.h $(ENGINE_INC)/polymost.h $(ENGINE_INC)/dxtfilter.h $(ENGINE_INC)/kplib.h

View file

@ -307,6 +307,8 @@ enum {
#undef UNTRACKED_STRUCTS #undef UNTRACKED_STRUCTS
#endif #endif
#include "clip.h"
#ifdef NEW_MAP_FORMAT #ifdef NEW_MAP_FORMAT
//////////////////// Lunatic new-generation map format //////////////////// //////////////////// Lunatic new-generation map format ////////////////////
@ -1102,18 +1104,6 @@ FORCE_INLINE void rotatesprite_win(int32_t sx, int32_t sy, int32_t z, int16_t a,
void bfirst_search_init(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int32_t maxnum, int16_t firstelt); void bfirst_search_init(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int32_t maxnum, int16_t firstelt);
void bfirst_search_try(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int16_t elt); void bfirst_search_try(int16_t *list, uint8_t *bitmap, int32_t *eltnumptr, int16_t elt);
extern int32_t clipmoveboxtracenum;
int32_t clipmove(vec3_t *vect, int16_t *sectnum, int32_t xvect, int32_t yvect, int32_t walldist,
int32_t ceildist, int32_t flordist, uint32_t cliptype) ATTRIBUTE((nonnull(1,2)));
int32_t clipmovex(vec3_t *pos, int16_t *sectnum, int32_t xvect, int32_t yvect,
int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t cliptype,
uint8_t noslidep) ATTRIBUTE((nonnull(1,2)));
int32_t clipinsidebox(int32_t x, int32_t y, int16_t wallnum, int32_t walldist);
int32_t clipinsideboxline(int32_t x, int32_t y, int32_t x1, int32_t y1,
int32_t x2, int32_t y2, int32_t walldist);
int32_t pushmove(vec3_t *vect, int16_t *sectnum, int32_t walldist,
int32_t ceildist, int32_t flordist, uint32_t cliptype) ATTRIBUTE((nonnull(1,2)));
void getzrange(const vec3_t *vect, int16_t sectnum, int32_t *ceilz, int32_t *ceilhit, int32_t *florz, void getzrange(const vec3_t *vect, int16_t sectnum, int32_t *ceilz, int32_t *ceilhit, int32_t *florz,
int32_t *florhit, int32_t walldist, uint32_t cliptype) ATTRIBUTE((nonnull(1,3,4,5,6))); int32_t *florhit, int32_t walldist, uint32_t cliptype) ATTRIBUTE((nonnull(1,3,4,5,6)));
int32_t hitscan(const vec3_t *sv, int16_t sectnum, int32_t vx, int32_t vy, int32_t vz, int32_t hitscan(const vec3_t *sv, int16_t sectnum, int32_t vx, int32_t vy, int32_t vz,
@ -1475,6 +1465,11 @@ static inline int32_t setspritez_old(int16_t spritenum, int32_t x, int32_t y, in
return setspritez(spritenum, &vector); return setspritez(spritenum, &vector);
} }
extern int32_t rintersect(int32_t x1, int32_t y1, int32_t z1,
int32_t vx_, int32_t vy_, int32_t vz,
int32_t x3, int32_t y3, int32_t x4, int32_t y4,
int32_t *intx, int32_t *inty, int32_t *intz);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -0,0 +1,88 @@
#pragma once
#ifndef clip_h_
#define clip_h_
#ifdef HAVE_CLIPSHAPE_FEATURE
#define CM_MAX 256 // must be a power of 2
// sectoidx bits
#undef CM_NONE
#define CM_NONE (CM_MAX<<1)
#define CM_SOME (CM_NONE-1)
#define CM_OUTER (CM_MAX) // sector surrounds clipping sector
// sprite -> sector tag mappings
#define CM_XREPEAT floorpal
#define CM_YREPEAT floorxpanning
#define CM_XOFFSET ceilingshade
#define CM_YOFFSET floorshade
#define CM_CSTAT hitag
#define CM_ANG extra
#define CM_FLOORZ(Sec) (*(int32_t *)&sector[Sec].ceilingxpanning) // ceilingxpanning,ceilingypanning,floorpicnum
#define CM_CEILINGZ(Sec) (*(int32_t *)&sector[Sec].visibility) // visibility,fogpal,lotag
// backup of original normalized coordinates
#define CM_WALL_X(Wal) (*(int32_t *)&wall[Wal].picnum) // picnum, overpicnum
#define CM_WALL_Y(Wal) (*(int32_t *)&wall[Wal].lotag) // lotag, hitag
// don't rotate when applying clipping, for models with rotational symmetry
#define CM_NOROT(Spri) (sprite[Spri].cstat&2)
#define CM_NOROTS(Sect) (sector[Sect].CM_CSTAT&2)
#define MAXCLIPNUM 1024
typedef struct
{
int16_t qbeg, qend; // indices into sectq
int16_t picnum, next;
int32_t maxdist;
} clipinfo_t;
extern clipinfo_t clipinfo[CM_MAX];
typedef struct
{
int16_t numsectors, numwalls;
tsectortype *sector;
twalltype *wall;
} mapinfo_t;
extern mapinfo_t origmapinfo, clipmapinfo;
typedef struct
{
int32_t x1, y1, x2, y2;
} linetype;
extern linetype clipit[MAXCLIPNUM];
extern void clipmapinfo_init();
extern int32_t quickloadboard;
extern int16_t *sectq;
extern int16_t pictoidx[MAXTILES]; // maps tile num to clipinfo[] index
extern int16_t clipnum;
extern int32_t clipsectnum, origclipsectnum, clipspritenum;
extern int16_t clipsectorlist[MAXCLIPNUM], origclipsectorlist[MAXCLIPNUM];
extern int16_t clipspritelist[MAXCLIPNUM];
extern void mapinfo_set(mapinfo_t *bak, mapinfo_t *newmap);
extern int32_t clipsprite_try(const spritetype *spr, int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax);
extern int32_t clipsprite_initindex(int32_t curidx, spritetype *curspr, int32_t *clipsectcnt, const vec3_t *vect);
int32_t clipinsidebox(int32_t x, int32_t y, int16_t wallnum, int32_t walldist);
int32_t clipinsideboxline(int32_t x, int32_t y, int32_t x1, int32_t y1,
int32_t x2, int32_t y2, int32_t walldist);
extern int32_t clipmoveboxtracenum;
int32_t clipmove(vec3_t *vect, int16_t *sectnum, int32_t xvect, int32_t yvect, int32_t walldist,
int32_t ceildist, int32_t flordist, uint32_t cliptype) ATTRIBUTE((nonnull(1, 2)));
int32_t clipmovex(vec3_t *pos, int16_t *sectnum, int32_t xvect, int32_t yvect,
int32_t walldist, int32_t ceildist, int32_t flordist, uint32_t cliptype,
uint8_t noslidep) ATTRIBUTE((nonnull(1, 2)));
int32_t pushmove(vec3_t *vect, int16_t *sectnum, int32_t walldist,
int32_t ceildist, int32_t flordist, uint32_t cliptype) ATTRIBUTE((nonnull(1, 2)));
#endif
#endif

View file

@ -1,4 +1,3 @@
#include "compat.h"
#include "build.h" #include "build.h"
#include "editor.h" #include "editor.h"
@ -119,7 +118,6 @@ char getpixel(int32_t x, int32_t y)
} }
// //
// drawline256 // drawline256
// //

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,8 @@
#pragma once
#ifndef ENGINE_PRIV_H #ifndef ENGINE_PRIV_H
#define ENGINE_PRIV_H #define ENGINE_PRIV_H
#define MAXCLIPNUM 1024
#define MAXPERMS 512 #define MAXPERMS 512
#define MAXARTFILES_BASE 200 #define MAXARTFILES_BASE 200
#define MAXARTFILES_TOTAL 220 #define MAXARTFILES_TOTAL 220
@ -28,6 +29,244 @@ extern "C" {
extern "C" { extern "C" {
#endif #endif
extern uint16_t ATTRIBUTE((used)) sqrtable[4096], ATTRIBUTE((used)) shlookup[4096+256];
#if defined(_MSC_VER) && !defined(NOASM)
//
// Microsoft C Inline Assembly Routines
//
static inline int32_t nsqrtasm(int32_t a)
{
_asm
{
push ebx
mov eax, a
test eax, 0xff000000
mov ebx, eax
jnz short over24
shr ebx, 12
mov cx, word ptr shlookup[ebx*2]
jmp short under24
over24 :
shr ebx, 24
mov cx, word ptr shlookup[ebx*2+8192]
under24 :
shr eax, cl
mov cl, ch
mov ax, word ptr sqrtable[eax*2]
shr eax, cl
pop ebx
}
}
static inline int32_t msqrtasm(int32_t c)
{
_asm
{
push ebx
mov ecx, c
mov eax, 0x40000000
mov ebx, 0x20000000
begit:
cmp ecx, eax
jl skip
sub ecx, eax
lea eax, [eax+ebx*4]
skip :
sub eax, ebx
shr eax, 1
shr ebx, 2
jnz begit
cmp ecx, eax
sbb eax, -1
shr eax, 1
pop ebx
}
}
static inline int32_t getclipmask(int32_t a, int32_t b, int32_t c, int32_t d)
{
_asm
{
push ebx
mov eax, a
mov ebx, b
mov ecx, c
mov edx, d
sar eax, 31
add ebx, ebx
adc eax, eax
add ecx, ecx
adc eax, eax
add edx, edx
adc eax, eax
mov ebx, eax
shl ebx, 4
or al, 0xf0
xor eax, ebx
pop ebx
}
}
static inline int32_t getkensmessagecrc(void *b)
{
_asm
{
push ebx
mov ebx, b
xor eax, eax
mov ecx, 32
beg:
mov edx, dword ptr[ebx+ecx*4-4]
ror edx, cl
adc eax, edx
bswap eax
loop short beg
pop ebx
}
}
#elif defined(__GNUC__) && defined(__i386__) && !defined(NOASM) // _MSC_VER
//
// GCC "Inline" Assembly Routines
//
#define nsqrtasm(a) \
({ int32_t __r, __a=(a); \
__asm__ __volatile__ ( \
"testl $0xff000000, %%eax\n\t" \
"movl %%eax, %%ebx\n\t" \
"jnz 0f\n\t" \
"shrl $12, %%ebx\n\t" \
"movw " ASMSYM("shlookup") "(,%%ebx,2), %%cx\n\t" \
"jmp 1f\n\t" \
"0:\n\t" \
"shrl $24, %%ebx\n\t" \
"movw (" ASMSYM("shlookup") "+8192)(,%%ebx,2), %%cx\n\t" \
"1:\n\t" \
"shrl %%cl, %%eax\n\t" \
"movb %%ch, %%cl\n\t" \
"movw " ASMSYM("sqrtable") "(,%%eax,2), %%ax\n\t" \
"shrl %%cl, %%eax" \
: "=a" (__r) : "a" (__a) : "ebx", "ecx", "cc"); \
__r; })
// edx is blown by this code somehow?!
#define msqrtasm(c) \
({ int32_t __r, __c=(c); \
__asm__ __volatile__ ( \
"movl $0x40000000, %%eax\n\t" \
"movl $0x20000000, %%ebx\n\t" \
"0:\n\t" \
"cmpl %%eax, %%ecx\n\t" \
"jl 1f\n\t" \
"subl %%eax, %%ecx\n\t" \
"leal (%%eax,%%ebx,4), %%eax\n\t" \
"1:\n\t" \
"subl %%ebx, %%eax\n\t" \
"shrl $1, %%eax\n\t" \
"shrl $2, %%ebx\n\t" \
"jnz 0b\n\t" \
"cmpl %%eax, %%ecx\n\t" \
"sbbl $-1, %%eax\n\t" \
"shrl $1, %%eax" \
: "=a" (__r) : "c" (__c) : "edx","ebx", "cc"); \
__r; })
#define getclipmask(a,b,c,d) \
({ int32_t __a=(a), __b=(b), __c=(c), __d=(d); \
__asm__ __volatile__ ("sarl $31, %%eax; addl %%ebx, %%ebx; adcl %%eax, %%eax; " \
"addl %%ecx, %%ecx; adcl %%eax, %%eax; addl %%edx, %%edx; " \
"adcl %%eax, %%eax; movl %%eax, %%ebx; shl $4, %%ebx; " \
"orb $0xf0, %%al; xorl %%ebx, %%eax" \
: "=a" (__a), "=b" (__b), "=c" (__c), "=d" (__d) \
: "a" (__a), "b" (__b), "c" (__c), "d" (__d) : "cc"); \
__a; })
#define getkensmessagecrc(b) \
({ int32_t __a, __b=(b); \
__asm__ __volatile__ ( \
"xorl %%eax, %%eax\n\t" \
"movl $32, %%ecx\n\t" \
"0:\n\t" \
"movl -4(%%ebx,%%ecx,4), %%edx\n\t" \
"rorl %%cl, %%edx\n\t" \
"adcl %%edx, %%eax\n\t" \
"bswapl %%eax\n\t" \
"loop 0b" \
: "=a" (__a) : "b" (__b) : "ecx", "edx" \
__a; })
#else // __GNUC__ && __i386__
static inline int32_t nsqrtasm(uint32_t a)
{
// JBF 20030901: This was a damn lot simpler to reverse engineer than
// msqrtasm was. Really, it was just like simplifying an algebra equation.
uint16_t c;
if (a & 0xff000000) // test eax, 0xff000000 / jnz short over24
{
c = shlookup[(a >> 24) + 4096]; // mov ebx, eax
// over24: shr ebx, 24
// mov cx, word ptr shlookup[ebx*2+8192]
}
else
{
c = shlookup[a >> 12]; // mov ebx, eax
// shr ebx, 12
// mov cx, word ptr shlookup[ebx*2]
// jmp short under24
}
a >>= c&0xff; // under24: shr eax, cl
a = (a&0xffff0000)|(sqrtable[a]); // mov ax, word ptr sqrtable[eax*2]
a >>= ((c&0xff00) >> 8); // mov cl, ch
// shr eax, cl
return a;
}
static inline int32_t msqrtasm(uint32_t c)
{
uint32_t a, b;
a = 0x40000000l; // mov eax, 0x40000000
b = 0x20000000l; // mov ebx, 0x20000000
do // begit:
{
if (c >= a) // cmp ecx, eax / jl skip
{
c -= a; // sub ecx, eax
a += b*4; // lea eax, [eax+ebx*4]
} // skip:
a -= b; // sub eax, ebx
a >>= 1; // shr eax, 1
b >>= 2; // shr ebx, 2
} while (b); // jnz begit
if (c >= a) // cmp ecx, eax
a++; // sbb eax, -1
a >>= 1; // shr eax, 1
return a;
}
static inline int32_t getclipmask(int32_t a, int32_t b, int32_t c, int32_t d)
{
// Ken did this
d = ((a<0)<<3) + ((b<0)<<2) + ((c<0)<<1) + (d<0);
return(((d<<4)^0xf0)|d);
}
inline int32_t getkensmessagecrc(int32_t b)
{
UNREFERENCED_PARAMETER(b);
return 0x56c764d4l;
}
#endif
extern int16_t thesector[MAXWALLSB], thewall[MAXWALLSB]; extern int16_t thesector[MAXWALLSB], thewall[MAXWALLSB];
extern int16_t bunchfirst[MAXWALLSB], bunchlast[MAXWALLSB]; extern int16_t bunchfirst[MAXWALLSB], bunchlast[MAXWALLSB];
extern int16_t maskwall[MAXWALLSB], maskwallcnt; extern int16_t maskwall[MAXWALLSB], maskwallcnt;
@ -66,6 +305,7 @@ extern int32_t xb1[MAXWALLSB];
extern int32_t rx1[MAXWALLSB], ry1[MAXWALLSB]; extern int32_t rx1[MAXWALLSB], ry1[MAXWALLSB];
extern int16_t bunchp2[MAXWALLSB]; extern int16_t bunchp2[MAXWALLSB];
extern int16_t numscans, numbunches; extern int16_t numscans, numbunches;
extern int32_t rxi[8], ryi[8];
#ifdef USE_OPENGL #ifdef USE_OPENGL
@ -76,6 +316,13 @@ void calc_and_apply_fog(int32_t tile, int32_t shade, int32_t vis, int32_t pal);
void calc_and_apply_fog_factor(int32_t tile, int32_t shade, int32_t vis, int32_t pal, float factor); void calc_and_apply_fog_factor(int32_t tile, int32_t shade, int32_t vis, int32_t pal, float factor);
#endif #endif
extern void get_wallspr_points(const spritetype *spr, int32_t *x1, int32_t *x2,
int32_t *y1, int32_t *y2);
extern void get_floorspr_points(const tspritetype *spr, int32_t px, int32_t py,
int32_t *x1, int32_t *x2, int32_t *x3, int32_t *x4,
int32_t *y1, int32_t *y2, int32_t *y3, int32_t *y4);
// int32_t wallmost(int16_t *mostbuf, int32_t w, int32_t sectnum, char dastat); // int32_t wallmost(int16_t *mostbuf, int32_t w, int32_t sectnum, char dastat);
int32_t wallfront(int32_t l1, int32_t l2); int32_t wallfront(int32_t l1, int32_t l2);

View file

@ -0,0 +1,338 @@
#include "compat.h"
#include "build.h"
#include "scriptfile.h"
usermaphack_t g_loadedMapHack; // used only for the MD4 part
int32_t compare_usermaphacks(const void *a, const void *b)
{
return Bmemcmp(((usermaphack_t const *) a)->md4, ((usermaphack_t const *) b)->md4, 16);
}
usermaphack_t *usermaphacks;
int32_t num_usermaphacks;
#ifdef POLYMER
static int16_t maphacklightcnt=0;
static int16_t maphacklight[PR_MAXLIGHTS];
void delete_maphack_lights()
{
int32_t i;
for (i=0; i<maphacklightcnt; i++)
{
if (maphacklight[i] >= 0)
polymer_deletelight(maphacklight[i]);
maphacklight[i] = -1;
}
maphacklightcnt = 0;
}
#else
void delete_maphack_lights() {}
#endif
//
// loadmaphack
//
int32_t loadmaphack(const char *filename)
{
enum
{
T_SPRITE = 0,
T_ANGOFF,
T_NOMODEL,
T_NOANIM,
T_PITCH,
T_ROLL,
T_MDXOFF,
T_MDYOFF,
T_MDZOFF,
T_AWAY1,
T_AWAY2,
T_LIGHT,
};
static struct { const char *text; int32_t tokenid; } legaltokens [] =
{
{ "sprite", T_SPRITE },
{ "angleoff", T_ANGOFF },
{ "angoff", T_ANGOFF },
{ "notmd2", T_NOMODEL },
{ "notmd3", T_NOMODEL },
{ "notmd", T_NOMODEL },
{ "nomd2anim", T_NOANIM },
{ "nomd3anim", T_NOANIM },
{ "nomdanim", T_NOANIM },
{ "pitch", T_PITCH },
{ "roll", T_ROLL },
{ "mdxoff", T_MDXOFF },
{ "mdyoff", T_MDYOFF },
{ "mdzoff", T_MDZOFF },
{ "away1", T_AWAY1 },
{ "away2", T_AWAY2 },
{ "light", T_LIGHT },
{ NULL, -1 }
};
scriptfile *script = NULL;
char *tok, *cmdtokptr;
int32_t i;
int32_t whichsprite = -1;
static char fn[BMAX_PATH];
#ifdef POLYMER
int32_t toomanylights = 0;
delete_maphack_lights();
#endif
if (filename)
{
Bmemset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES);
Bmemset(spritesmooth, 0, sizeof(spritesmooth_t) *(MAXSPRITES+MAXUNIQHUDID));
Bstrcpy(fn, filename);
script = scriptfile_fromfile(filename);
}
else if (fn[0])
{
// re-load
// XXX: what if we changed between levels? Could a wrong maphack be loaded?
script = scriptfile_fromfile(fn);
}
if (!script)
{
fn[0] = 0;
return -1;
}
while (1)
{
tok = scriptfile_gettoken(script);
if (!tok) break;
for (i=0; legaltokens[i].text; i++) if (!Bstrcasecmp(tok, legaltokens[i].text)) break;
cmdtokptr = script->ltextptr;
if (!filename && legaltokens[i].tokenid != T_LIGHT) continue;
switch (legaltokens[i].tokenid)
{
case T_SPRITE: // sprite <xx>
if (scriptfile_getnumber(script, &whichsprite)) break;
if ((unsigned) whichsprite >= (unsigned) MAXSPRITES)
{
// sprite number out of range
initprintf("Sprite number out of range 0-%d on line %s:%d\n",
MAXSPRITES-1, script->filename, scriptfile_getlinum(script, cmdtokptr));
whichsprite = -1;
break;
}
break;
case T_ANGOFF: // angoff <xx>
{
int32_t ang;
if (scriptfile_getnumber(script, &ang)) break;
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring angle offset directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].angoff = (int16_t) ang;
}
break;
case T_NOMODEL: // notmd
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring not-MD2/MD3 directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].flags |= SPREXT_NOTMD;
break;
case T_NOANIM: // nomdanim
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring no-MD2/MD3-anim directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].flags |= SPREXT_NOMDANIM;
break;
case T_PITCH: // pitch <xx>
{
int32_t pitch;
if (scriptfile_getnumber(script, &pitch)) break;
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring pitch directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].pitch = (int16_t) pitch;
}
break;
case T_ROLL: // roll <xx>
{
int32_t roll;
if (scriptfile_getnumber(script, &roll)) break;
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring roll directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].roll = (int16_t) roll;
}
break;
case T_MDXOFF: // mdxoff <xx>
{
int32_t i;
if (scriptfile_getnumber(script, &i)) break;
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring mdxoff directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].offset.x = i;
}
break;
case T_MDYOFF: // mdyoff <xx>
{
int32_t i;
if (scriptfile_getnumber(script, &i)) break;
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring mdyoff directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].offset.y = i;
}
break;
case T_MDZOFF: // mdzoff <xx>
{
int32_t i;
if (scriptfile_getnumber(script, &i)) break;
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring mdzoff directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].offset.z = i;
}
break;
case T_AWAY1: // away1
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring moving away directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].flags |= SPREXT_AWAY1;
break;
case T_AWAY2: // away2
if (whichsprite < 0)
{
// no sprite directive preceeding
initprintf("Ignoring moving away directive because of absent/invalid sprite number on line %s:%d\n",
script->filename, scriptfile_getlinum(script, cmdtokptr));
break;
}
spriteext[whichsprite].flags |= SPREXT_AWAY2;
break;
#ifdef POLYMER
case T_LIGHT: // light sector x y z range r g b radius faderadius angle horiz minshade maxshade priority tilenum
{
int32_t value;
int16_t lightid;
#pragma pack(push,1)
_prlight light;
#pragma pack(pop)
if (toomanylights)
break; // ignore further light defs
scriptfile_getnumber(script, &value);
light.sector = value;
scriptfile_getnumber(script, &value);
light.x = value;
scriptfile_getnumber(script, &value);
light.y = value;
scriptfile_getnumber(script, &value);
light.z = value;
scriptfile_getnumber(script, &value);
light.range = value;
scriptfile_getnumber(script, &value);
light.color[0] = value;
scriptfile_getnumber(script, &value);
light.color[1] = value;
scriptfile_getnumber(script, &value);
light.color[2] = value;
scriptfile_getnumber(script, &value);
light.radius = value;
scriptfile_getnumber(script, &value);
light.faderadius = value;
scriptfile_getnumber(script, &value);
light.angle = value;
scriptfile_getnumber(script, &value);
light.horiz = value;
scriptfile_getnumber(script, &value);
light.minshade = value;
scriptfile_getnumber(script, &value);
light.maxshade = value;
scriptfile_getnumber(script, &value);
light.priority = value;
scriptfile_getnumber(script, &value);
light.tilenum = value;
light.publicflags.emitshadow = 1;
light.publicflags.negative = 0;
if (getrendermode() == REND_POLYMER)
{
if (maphacklightcnt == PR_MAXLIGHTS)
{
initprintf("warning: max light count %d exceeded, "
"ignoring further light defs\n", PR_MAXLIGHTS);
toomanylights = 1;
break;
}
lightid = polymer_addlight(&light);
if (lightid>=0)
maphacklight[maphacklightcnt++] = lightid;
}
break;
}
#endif // POLYMER
default:
// unrecognised token
break;
}
}
scriptfile_close(script);
return 0;
}

View file

@ -3,7 +3,6 @@
# include <string.h> # include <string.h>
#endif #endif
#include "compat.h"
#include "build.h" #include "build.h"
#include "editor.h" #include "editor.h"

View file

@ -105,6 +105,7 @@
<ClInclude Include="build\include\build.h" /> <ClInclude Include="build\include\build.h" />
<ClInclude Include="build\include\buildtypes.h" /> <ClInclude Include="build\include\buildtypes.h" />
<ClInclude Include="build\include\cache1d.h" /> <ClInclude Include="build\include\cache1d.h" />
<ClInclude Include="build\include\clip.h" />
<ClInclude Include="build\include\colmatch.h" /> <ClInclude Include="build\include\colmatch.h" />
<ClInclude Include="build\include\compat.h" /> <ClInclude Include="build\include\compat.h" />
<ClInclude Include="build\include\common.h" /> <ClInclude Include="build\include\common.h" />
@ -258,6 +259,7 @@
<ClCompile Include="build\src\baselayer.c" /> <ClCompile Include="build\src\baselayer.c" />
<ClCompile Include="build\src\build.c" /> <ClCompile Include="build\src\build.c" />
<ClCompile Include="build\src\cache1d.c" /> <ClCompile Include="build\src\cache1d.c" />
<ClCompile Include="build\src\clip.c" />
<ClCompile Include="build\src\colmatch.c" /> <ClCompile Include="build\src\colmatch.c" />
<ClCompile Include="build\src\common.c" /> <ClCompile Include="build\src\common.c" />
<ClCompile Include="build\src\compat.c" /> <ClCompile Include="build\src\compat.c" />
@ -276,6 +278,7 @@
<ClCompile Include="build\src\lzwnew.c" /> <ClCompile Include="build\src\lzwnew.c" />
<ClCompile Include="build\src\md4.c" /> <ClCompile Include="build\src\md4.c" />
<ClCompile Include="build\src\mdsprite.c" /> <ClCompile Include="build\src\mdsprite.c" />
<ClCompile Include="build\src\mhk.c" />
<ClCompile Include="build\src\mutex.c" /> <ClCompile Include="build\src\mutex.c" />
<ClCompile Include="build\src\osd.c" /> <ClCompile Include="build\src\osd.c" />
<ClCompile Include="build\src\palette.c" /> <ClCompile Include="build\src\palette.c" />

View file

@ -537,6 +537,9 @@
<ClInclude Include="build\include\colmatch.h"> <ClInclude Include="build\include\colmatch.h">
<Filter>build\headers</Filter> <Filter>build\headers</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="build\include\clip.h">
<Filter>build\headers</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="build\src\a-c.c"> <ClCompile Include="build\src\a-c.c">
@ -947,6 +950,12 @@
<ClCompile Include="build\src\screenshot.c"> <ClCompile Include="build\src\screenshot.c">
<Filter>build\source</Filter> <Filter>build\source</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="build\src\mhk.c">
<Filter>build\source</Filter>
</ClCompile>
<ClCompile Include="build\src\clip.c">
<Filter>build\source</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Makefile.msvc"> <None Include="Makefile.msvc">