shithub: duke3d

Download patch

ref: e9379d17f01bce87e474f57cab1dee6e0d9b03f9
parent: 1d8bd38ea323126549d48553b1a2b9ceca62954e
author: Fabien Sanglard <[email protected]>
date: Sun Dec 16 23:43:05 EST 2012

Formatting.

--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -631,7 +631,7 @@
 }
 
 
-static int getpalookup(int32_t davis, int32_t dashade)
+static int32_t getpalookup(int32_t davis, int32_t dashade)
 {
     return(min(max(dashade+(davis>>8),0),numpalookups-1));
 }
@@ -649,7 +649,7 @@
     r = horizlookup2[yp-globalhoriz+horizycent];
     asm1 = globalx1*r;
     asm2 = globaly2*r;
-    s = ((int32_t)getpalookup((int32_t)mulscale16(r,globvis),globalshade)<<8);
+    s = (getpalookup(mulscale16(r,globvis),globalshade)<<8);
 
     hlineasm4(xr-xl,s,globalx2*r+globalypanning,globaly1*r+globalxpanning,ylookup[yp]+xr+frameoffset);
 }
@@ -665,7 +665,7 @@
     asm1 = globalx1*r;
     asm2 = globaly2*r;
 
-    asm3 = (long)globalpalwritten + ((long)getpalookup((long)mulscale16(r,globvis),globalshade)<<8);
+    asm3 = (int32_t)globalpalwritten + (getpalookup(mulscale16(r,globvis),globalshade)<<8);
     if (!(globalorientation&256))
     {
         mhline(globalbufplc,globaly1*r+globalxpanning-asm1*(xr-xl),(xr-xl)<<16,0L,
@@ -922,19 +922,27 @@
     }
 
     globalzd = globalposz-sec->floorz;
-    if (globalzd > 0) return;
+    if (globalzd > 0)
+        return;
     globalpicnum = sec->floorpicnum;
     if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
     setgotpic(globalpicnum);
-    if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) return;
+    
+    if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0))
+        return;
+    
     if (picanm[globalpicnum]&192) globalpicnum += animateoffs((short)globalpicnum,(short)sectnum);
 
-    if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
+    if (waloff[globalpicnum] == 0)
+        loadtile(globalpicnum);
+    
     globalbufplc = waloff[globalpicnum];
 
     globalshade = (long)sec->floorshade;
     globvis = globalcisibility;
-    if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
+    if (sec->visibility != 0){
+        globvis = mulscale4(globvis,(long)((sec->visibility+16)));
+    }
     globalorientation = (long)sec->floorstat;
 
 
@@ -1145,33 +1153,47 @@
     tsizx = tilesizx[globalpicnum];
     tsizy = tilesizy[globalpicnum];
     setgotpic(globalpicnum);
-    if ((tsizx <= 0) || (tsizy <= 0)) return;
-    if ((uwal[x1] > ydimen) && (uwal[x2] > ydimen)) return;
-    if ((dwal[x1] < 0) && (dwal[x2] < 0)) return;
+    
+    if ((tsizx <= 0) || (tsizy <= 0))
+        return;
+    
+    if ((uwal[x1] > ydimen) && (uwal[x2] > ydimen))
+        return;
+    
+    if ((dwal[x1] < 0) && (dwal[x2] < 0))
+        return;
 
-    if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
+    if (waloff[globalpicnum] == 0)
+        loadtile(globalpicnum);
 
     xnice = (pow2long[picsiz[globalpicnum]&15] == tsizx);
-    if (xnice) tsizx--;
+    if (xnice)
+        tsizx--;
+    
     ynice = (pow2long[picsiz[globalpicnum]>>4] == tsizy);
-    if (ynice) tsizy = (picsiz[globalpicnum]>>4);
+    if (ynice)
+        tsizy = (picsiz[globalpicnum]>>4);
 
     fpalookup = (long)FP_OFF(palookup[globalpal]);
 
     setupvlineasm(globalshiftval);
 
+    //Starting on the left column of the wall, check the occlusion arrays.
     x = x1;
-    while ((umost[x] > dmost[x]) && (x <= x2)) x++;
+    while ((umost[x] > dmost[x]) && (x <= x2))
+        x++;
 
     for(; (x<=x2)&&((x+frameoffset)&3); x++)
     {
         y1ve[0] = max(uwal[x],umost[x]);
         y2ve[0] = min(dwal[x],dmost[x]);
-        if (y2ve[0] <= y1ve[0]) continue;
+        if (y2ve[0] <= y1ve[0])
+            continue;
 
         palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8);
 
         bufplce[0] = lwal[x] + globalxpanning;
+        
         if (bufplce[0] >= tsizx)
         {
             if (xnice == 0)
@@ -1190,6 +1212,7 @@
 
         vlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0]+waloff[globalpicnum],x+frameoffset+ylookup[y1ve[0]]);
     }
+    
     for(; x<=x2-3; x+=4)
     {
         bad = 0;
@@ -1606,10 +1629,13 @@
         daz = sec->floorz;
     }
 
-    if ((picanm[globalpicnum]&192) != 0) globalpicnum += animateoffs(globalpicnum,(short) sectnum);
+    if ((picanm[globalpicnum]&192) != 0)
+        globalpicnum += animateoffs(globalpicnum,(short) sectnum);
     setgotpic(globalpicnum);
-    if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) return;
-    if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
+    if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0))
+        return;
+    if (waloff[globalpicnum] == 0)
+        loadtile(globalpicnum);
 
     wal = &wall[sec->wallptr];
     wx = wall[wal->point2].x - wal->x;
@@ -1974,12 +2000,6 @@
         intz = oz1 + mulscale30(oz2-oz1,t);
         xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
 
-        /*
-         * t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4));
-         * inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
-         * intz = z1 + mulscale30(z2-z1,t);
-         */
-
         if ((bad&3) == 2)
         {
             if (xb1[w] <= xcross) {
@@ -2008,12 +2028,6 @@
         intz = oz1 + mulscale30(oz2-oz1,t);
         xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
 
-        /*
-         * t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4));
-         * inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
-         * intz = z1 + mulscale30(z2-z1,t);
-         */
-
         if ((bad&12) == 8)
         {
             if (xb1[w] <= xcross) {
@@ -2090,8 +2104,6 @@
             parascan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum,1,bunch);
     }
 
-	//return;
-
     /* DRAW WALLS SECTION! */
     for(z=bunchfirst[bunch]; z>=0; z=p2[z])
     {
@@ -2279,7 +2291,7 @@
                         wal = &wall[wallnum];
                         globalorientation = (long)wal->cstat;
                         globalpicnum = wal->picnum;
-                        if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
+                        if ((uint32_t)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
                         globalxpanning = (long)wal->xpanning;
                         globalypanning = (long)wal->ypanning;
                         if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,(short)(wallnum+16384));
@@ -2292,7 +2304,7 @@
                     {
                         globalorientation = (long)wal->cstat;
                         globalpicnum = wal->picnum;
-                        if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
+                        if ((uint32_t)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
                         globalxpanning = (long)wal->xpanning;
                         globalypanning = (long)wal->ypanning;
                         if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,(short)(wallnum+16384));
--- a/Engine/src/pragmas.h
+++ b/Engine/src/pragmas.h
@@ -108,25 +108,25 @@
 DEFFUN(32)
 
 #define DEFFUN(N) \
-static __inline int mulscale##N(int32_t input1, int32_t input2) \
+static __inline int32_t mulscale##N(int32_t input1, int32_t input2) \
 { return mulscale(input1,input2,N); }
 DEFFUNCS
 #undef DEFFUN
 
 #define DEFFUN(N) \
-static __inline int dmulscale##N(int32_t input1, int32_t input2,int32_t input3,int32_t input4) \
+static __inline int32_t dmulscale##N(int32_t input1, int32_t input2,int32_t input3,int32_t input4) \
 { return dmulscale(input1,input2,input3,input4,N); }
 DEFFUNCS
 #undef DEFFUN
 
 #define DEFFUN(N) \
-static __inline int tmulscale##N(int32_t i1, int32_t i2,int32_t i3,int32_t i4,int32_t i5,int32_t i6) \
+static __inline int32_t tmulscale##N(int32_t i1, int32_t i2,int32_t i3,int32_t i4,int32_t i5,int32_t i6) \
 { return tmulscale(i1,i2,i3,i4,i5,i6,N); }
 DEFFUNCS
 #undef DEFFUN
 
 #define DEFFUN(N) \
-static __inline int divscale##N(int32_t input1, int32_t input2) \
+static __inline int32_t divscale##N(int32_t input1, int32_t input2) \
 { return divscale(input1,input2,N); }
 DEFFUNCS
 #undef DEFFUN
--- a/Game/src/audiolib/_multivc.h
+++ b/Game/src/audiolib/_multivc.h
@@ -197,7 +197,7 @@
 
 typedef struct
    {
-   unsigned char DATA[ 4 ];
+   char DATA[ 4 ];
    unsigned long size;
    } data_header;
 
--- a/Game/src/duke3d.h
+++ b/Game/src/duke3d.h
@@ -374,7 +374,7 @@
 extern struct animwalltype animwall[MAXANIMWALLS];
 extern short numanimwalls,probey,lastprobey;
 
-extern uint8_t  *mymembuf;
+char  *mymembuf;
 extern uint8_t  typebuflen;
 char typebuf[41];
 extern uint8_t  MusicPtr[72000];
--- a/Game/src/game.c
+++ b/Game/src/game.c
@@ -53,6 +53,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#include "global.h"
 
 
 // this is So lame
@@ -105,10 +106,10 @@
 void newint24( int errval, int ax, int bp, int si );
 
 int recfilep,totalreccnt;
-uint8_t  debug_on = 0,actor_tog = 0,*rtsptr,memorycheckoveride=0;
+uint8_t  debug_on = 0,actor_tog = 0,memorycheckoveride=0;
+char *rtsptr;
 
 
-
 extern uint8_t  syncstate;
 extern int32 numlumps;
 
@@ -456,6 +457,9 @@
 	return(id);
 }
 
+//This is a function from the Engine module, used in getpackets.
+void sampletimer(void);
+
 void getpackets(void)
 {
     int32_t i, j, k, l;
@@ -656,7 +660,7 @@
 
                 if (SoundToggle == 0 || ud.lockout == 1 || FXDevice == NumSoundCards)
                     break;
-                rtsptr = (uint8_t  *)RTS_GetSound(packbuf[1]-1);
+                rtsptr = (char  *)RTS_GetSound(packbuf[1]-1);
                 if (*rtsptr == 'C')
                     FX_PlayVOC3D(rtsptr,0,0,0,255,-packbuf[1]);
                 else
@@ -6748,7 +6752,7 @@
             if(ud.lockout == 0)
                 if(SoundToggle && ALT_IS_PRESSED && ( RTS_NumSounds() > 0 ) && rtsplaying == 0 && VoiceToggle )
             {
-                rtsptr = (uint8_t  *)RTS_GetSound (i-1);
+                rtsptr = (char  *)RTS_GetSound (i-1);
                 if(*rtsptr == 'C')
                     FX_PlayVOC3D( rtsptr,0,0,0,255,-i);
                 else FX_PlayWAV3D( rtsptr,0,0,0,255,-i);
@@ -10608,6 +10612,7 @@
 
 	if(ud.multimode>1) // if more than 1 player, we add name. Then add score if DM
 	{
+        tempbuf[0] = '\0';
 		strcat((char *)tempbuf, " [");
 		for(i=connecthead;i>=0;i=connectpoint2[i])
 		{
@@ -10619,8 +10624,8 @@
 			if(ud.m_coop==0 || ud.m_coop==2)  // if DM or DM No spawn. Add Score as well
 			{
 				strcat(tempbuf, "(");
-                snprintf(ps[i].frag-ps[i].fraggedself, sizeof(ps[i].frag-ps[i].fraggedself), "%s", score);
-				strcat(tempbuf, ps[i].frag-ps[i].fraggedself);
+                snprintf(score, sizeof(score), "%d",ps[i].frag-ps[i].fraggedself);
+				strcat(tempbuf, score);
 				strcat(tempbuf, ") vs ");
 			}
 			else
--- a/Game/src/game.h
+++ b/Game/src/game.h
@@ -2,7 +2,7 @@
 #define _GAME_H_
 
 //extern uint8_t  game_dir[512];
-uint8_t * getgamedir();
-
+char * getgamedir();
+int gametextpal(int x,int y,char  *t,uint8_t  s,uint8_t  p);
 #endif  // include-once header.
 
--- a/Game/src/global.c
+++ b/Game/src/global.c
@@ -29,10 +29,10 @@
 #include <string.h>
 #include <stdarg.h>
 #include <errno.h>
-
+#include "global.h"
 #include "duke3d.h"
 
-uint8_t  *mymembuf;
+char  *mymembuf;
 uint8_t  MusicPtr[72000];
 
 
@@ -664,13 +664,7 @@
 {
 	void *ptr;
 
-#if 0
-   if (zonememorystarted==false)
-      Error(EXIT_FAILURE, "Called SafeMalloc without starting zone memory\n");
-	ptr = Z_Malloc (size,PU_STATIC,NULL);
-#else
     ptr = malloc(size);
-#endif
 
 	if (!ptr)
       Error (EXIT_FAILURE, "SafeMalloc failure for %lu bytes",size);
@@ -682,13 +676,7 @@
 {
 	void *ptr;
 
-#if 0
-   if (zonememorystarted==false)
-      Error(EXIT_FAILURE, "Called SafeMalloc without starting zone memory\n");
-	ptr = Z_Malloc (size,PU_STATIC,NULL);
-#else
     ptr = realloc(*x, size);
-#endif
 
 	if (!ptr)
       Error (EXIT_FAILURE, "SafeRealloc failure for %lu bytes",size);
@@ -700,13 +688,7 @@
 {
 	void *ptr;
 
-#if 0
-   if (zonememorystarted==false)
-      Error(EXIT_FAILURE, "Called SafeLevelMalloc without starting zone memory\n");
-   ptr = Z_LevelMalloc (size,PU_STATIC,NULL);
-#else
     ptr = malloc(size);
-#endif
 
 	if (!ptr)
       Error (EXIT_FAILURE, "SafeLevelMalloc failure for %lu bytes",size);
@@ -719,49 +701,9 @@
    if ( ptr == NULL )
       Error (EXIT_FAILURE, "SafeFree : Tried to free a freed pointer\n");
 
-#if 0
-	Z_Free (ptr);
-#else
     free(ptr);
-#endif
-}
 
-
-#ifndef LITTLE_ENDIAN
-#define LITTLE_ENDIAN 1234
-#endif
-
-#ifndef BIG_ENDIAN
-#define BIG_ENDIAN 4321
-#endif
-
-#if PLATFORM_DOS
-#ifndef BYTE_ORDER
-#define BYTE_ORDER LITTLE_ENDIAN
-#endif
-#endif
-
-#if PLATFORM_WIN32
-#ifndef BYTE_ORDER
-#define BYTE_ORDER LITTLE_ENDIAN
-#endif
-#endif
-
-#ifndef BYTE_ORDER
-#error Please define your platform.
-#endif
-
-#if (BYTE_ORDER == LITTLE_ENDIAN)
-#define KeepShort IntelShort
-#define SwapShort MotoShort
-#define Keepint32_t IntelLong
-#define Swapint32_t MotoLong
-#else
-#define KeepShort MotoShort
-#define SwapShort IntelShort
-#define Keepint32_t MotoLong
-#define Swapint32_t IntelLong
-#endif
+}
 
 short	SwapShort (short l)
 {
--- /dev/null
+++ b/Game/src/global.h
@@ -1,0 +1,61 @@
+//
+//  global.h
+//  Duke3D
+//
+//  Created by fabien sanglard on 12-12-17.
+//  Copyright (c) 2012 fabien sanglard. All rights reserved.
+//
+
+#ifndef Duke3D_global_h
+#define Duke3D_global_h
+
+void FixFilePath(char  *filename);
+int FindDistance3D(int ix, int iy, int iz);
+void Shutdown(void);
+
+#ifndef LITTLE_ENDIAN
+    #ifdef __APPLE__
+    #else
+        #define LITTLE_ENDIAN 1234
+    #endif
+#endif
+
+#ifndef BIG_ENDIAN
+     #ifdef __APPLE__
+     #else
+        #define BIG_ENDIAN 4321
+    #endif
+#endif
+
+#if PLATFORM_WIN32
+#ifndef BYTE_ORDER
+#define BYTE_ORDER LITTLE_ENDIAN
+#endif
+#endif
+
+#ifdef __APPLE__
+#if __powerpc__
+#define BYTE_ORDER BIG_ENDIAN
+#else
+// Defined in endian.h
+// #define BYTE_ORDER LITTLE_ENDIAN
+#endif
+#endif
+
+#ifndef BYTE_ORDER
+#error Please define your platform.
+#endif
+
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define KeepShort IntelShort
+#define SwapShort MotoShort
+#define Keepint32_t IntelLong
+#define Swapint32_t MotoLong
+#else
+#define KeepShort MotoShort
+#define SwapShort IntelShort
+#define Keepint32_t MotoLong
+#define Swapint32_t IntelLong
+#endif
+
+#endif
--- a/Game/src/menues.c
+++ b/Game/src/menues.c
@@ -1753,7 +1753,7 @@
                         tempbuf[1] = lastsavedpos;
                         for(x=connecthead;x>=0;x=connectpoint2[x])
                             if(x != myconnectindex)
-                                sendpacket(x,(uint8_t)tempbuf,2);
+                                sendpacket(x,(uint8_t*)tempbuf,2);
 
                         getpackets();
 
@@ -2900,7 +2900,7 @@
 				sound(EXITMENUSOUND);
 			}
 
-			if (0<=x && x<NUMGAMEFUNCTIONS || waiting4key) // set a key
+			if ( (0<=x && x<NUMGAMEFUNCTIONS) || waiting4key) // set a key
 			{
 				if(!waiting4key)
 				{ 
--- a/Game/src/player.c
+++ b/Game/src/player.c
@@ -2725,8 +2725,8 @@
 		ud.playing_demo_rev == BYTEVERSION_116 || 
 		ud.playing_demo_rev == BYTEVERSION_117) &&
 		sb_snum&(1<<6) ||
-		ACTION(gamefunc_Look_Left) && (p->gm&MODE_GAME) && 
-		!(p->gm&MODE_MENU) && !(p->gm&MODE_TYPE) && !(ud.pause_on) && (ud.recstat != 2))
+		(ACTION(gamefunc_Look_Left) && (p->gm&MODE_GAME) && 
+		!(p->gm&MODE_MENU) && !(p->gm&MODE_TYPE) && !(ud.pause_on) && (ud.recstat != 2)))
 	{
 		p->look_ang -= 152;
 		p->rotscrnang += 24;
@@ -2733,11 +2733,11 @@
 	}
 
 	// 1<<7 : ANTIWEAPONSWITCH
-	if(	(ud.playing_demo_rev == BYTEVERSION_27 ||
+	if(	((ud.playing_demo_rev == BYTEVERSION_27 ||
 		ud.playing_demo_rev == BYTEVERSION_28 || 
 		ud.playing_demo_rev == BYTEVERSION_116 || 
 		ud.playing_demo_rev == BYTEVERSION_117) &&
-		sb_snum&(1<<7) || 
+		sb_snum&(1<<7)) ||
 		(
          ACTION(gamefunc_Look_Right) && (p->gm&MODE_GAME) &&
 		!(p->gm&MODE_MENU) && !(p->gm&MODE_TYPE) && !(ud.pause_on) && (ud.recstat != 2)
--- a/Game/src/rts.c
+++ b/Game/src/rts.c
@@ -25,6 +25,7 @@
 //-------------------------------------------------------------------------
 
 #include "duke3d.h"
+#include "global.h"
 
 //=============
 // STATICS
--- a/Game/src/sounds.c
+++ b/Game/src/sounds.c
@@ -33,6 +33,7 @@
 #include "types.h"
 #include "util_lib.h"
 #include "duke3d.h"
+#include "global.h"
 
 
 #define LOUDESTVOLUME 150
--- a/xcode/Duke3D.xcodeproj/project.pbxproj
+++ b/xcode/Duke3D.xcodeproj/project.pbxproj
@@ -72,6 +72,7 @@
 /* Begin PBXFileReference section */
 		2D2A07B8167EFA4900064107 /* music.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = music.h; path = ../../Game/src/audiolib/music.h; sourceTree = "<group>"; };
 		2D2A07BA167EFB5500064107 /* premap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = premap.h; path = ../../Game/src/premap.h; sourceTree = "<group>"; };
+		2D2A07BB167F1ABA00064107 /* global.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = global.h; path = ../../Game/src/global.h; sourceTree = "<group>"; };
 		2D4FB6FE167D430F00915887 /* sdl_midi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sdl_midi.c; sourceTree = "<group>"; };
 		2D7B61DE167886FB00E35E54 /* Duke3D */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Duke3D; sourceTree = BUILT_PRODUCTS_DIR; };
 		2D7B61F11678885A00E35E54 /* a.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = a.c; path = ../../Engine/src/a.c; sourceTree = "<group>"; };
@@ -341,6 +342,7 @@
 				2D7B62FD167905C400E35E54 /* dukeunix.h */,
 				2D7B62FE16790E8000E35E54 /* dummy_audiolib.c */,
 				2D2A07BA167EFB5500064107 /* premap.h */,
+				2D2A07BB167F1ABA00064107 /* global.h */,
 			);
 			name = Game;
 			sourceTree = "<group>";