shithub: duke3d

Download patch

ref: a0e4933fca3d1680616045bd7c32153722915a07
parent: 1a6360ad7073cb0f916bbea176b7625692ca6b52
author: Tanguy Fautre <[email protected]>
date: Wed Feb 12 16:08:03 EST 2020

64-bit: Fix game-related crashes and bugs, as well as more warnings.

--- a/Engine/src/cache.c
+++ b/Engine/src/cache.c
@@ -97,7 +97,7 @@
 	if ((uint32_t)newbytes > (uint32_t)cachesize)
 	{
 		printf("Cachesize: %d\n",cachesize);
-		printf("*Newhandle: 0x%x, Newbytes: %d, *Newlock: %d\n",(unsigned int)newhandle,newbytes,*newlockptr);
+		printf("*Newhandle: 0x%p, Newbytes: %d, *Newlock: %d\n",newhandle,newbytes,*newlockptr);
 		reportandexit("BUFFER TOO BIG TO FIT IN CACHE!\n");
 	}
 
@@ -172,7 +172,7 @@
 
 		/* Can't exit early, because invalid pointer might be same even though lock = 0 */
 	for(i=0;i<cacnum;i++)
-		if ((int32_t )(*cac[i].hand) == (int32_t )suckptr)
+		if ((intptr_t)(*cac[i].hand) == (intptr_t)suckptr)
 		{
 			if (*cac[i].lock) *cac[i].hand = 0;
 			cac[i].lock = &zerochar;
--- a/Engine/src/draw.c
+++ b/Engine/src/draw.c
@@ -105,8 +105,7 @@
 
 void rhlineasm4(int32_t i1, uint8_t* texture, int32_t i3, uint32_t i4, uint32_t i5, uint8_t* dest)
 {
-    uint32_t ebp = dest - i1;
-    uint32_t rmach6b = ebp-1;
+    uint32_t ebp = 0;
     int32_t numPixels;
 	int32_t offset = i1 + 1;
 	
@@ -153,8 +152,7 @@
 //FCS: ????
 void rmhlineasm4(int32_t i1, uint8_t* shade, int32_t colorIndex, int32_t i4, int32_t i5, uint8_t* dest)
 {
-    uint32_t ebp = dest - i1;
-    uint32_t rmach6b = ebp-1;
+    uint32_t ebp = 0;
     int32_t numPixels;
 	int32_t offset = i1 + 1;
     
--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -8270,7 +8270,8 @@
 static void fillpolygon(int32_t npoints)
 {
     int32_t z, zz, x1, y1, x2, y2, miny, maxy, y, xinc, cnt;
-    int32_t ox, oy, bx, by, p, day1, day2;
+    int32_t ox, oy, bx, by, day1, day2;
+    uint8_t *p;
     short *ptr, *ptr2;
 
     miny = 0x7fffffff;
@@ -8937,7 +8938,7 @@
             else
                 globalshade = ((int32_t)sector[spr->sectnum].floorshade);
             globalshade = max(min(globalshade+spr->shade+6,numpalookups-1),0);
-            asm3 = (int32_t) FP_OFF(palookup[spr->pal]+(globalshade<<8));
+            asm3 = (intptr_t) palookup[spr->pal]+(globalshade<<8);
             globvis = globalhisibility;
             if (sec->visibility != 0) globvis = mulscale4(globvis,(int32_t)((uint8_t )(sec->visibility+16)));
             globalpolytype = ((spr->cstat&2)>>1)+1;
--- a/Engine/src/macos_compat.h
+++ b/Engine/src/macos_compat.h
@@ -11,14 +11,6 @@
 
 #include <stdlib.h>
 
-#ifdef FP_OFF
-#undef FP_OFF
-#endif
-
-// Horrible horrible macro: Watcom allowed memory pointer to be cast
-// to a 32bits integer. The code is unfortunately stuffed with this :( !
-#define FP_OFF(x) ((int32_t) (x))
-
 #ifndef max
 #define max(x, y)  (((x) > (y)) ? (x) : (y))
 #endif
--- a/Engine/src/unix_compat.h
+++ b/Engine/src/unix_compat.h
@@ -13,14 +13,6 @@
 
 #include <stdlib.h>
 
-#ifdef FP_OFF
-#undef FP_OFF
-#endif
-
-// Horrible horrible macro: Watcom allowed memory pointer to be cast
-// to a 32bits integer. The code is unfortunately stuffed with this :( !
-#define FP_OFF(x) ((int32_t) (x))
-
 #ifndef max
 #define max(x, y)  (((x) > (y)) ? (x) : (y))
 #endif
--- a/Engine/src/win32_compat.h
+++ b/Engine/src/win32_compat.h
@@ -35,14 +35,6 @@
 #include <assert.h>
 #include <string.h>
 
-#ifdef FP_OFF
-#undef FP_OFF
-#endif
-
-// Horrible horrible macro: Watcom allowed memory pointer to be cast
-// to a 32bits integer. The code is unfortunately stuffed with this :( !
-#define FP_OFF(x) ((int32_t) (x))
-
 #ifndef max
 #define max(x, y)  (((x) > (y)) ? (x) : (y))
 #endif
--- a/Game/src/actors.c
+++ b/Game/src/actors.c
@@ -1516,7 +1516,8 @@
 void movestandables(void)
 {
     short i, j, k, m, nexti, nextj, p, sect;
-    int32_t l=0, x, *t;
+    intptr_t l=0,*t;
+    int32_t x;
     spritetype *s;
 
     i = headspritestat[6];
@@ -3138,7 +3139,8 @@
 
 void moveactors(void)
 {
-    int32_t x, m, l, *t;
+    int32_t x, m, l;
+	intptr_t *t;
     short a, i, j, nexti, nextj, sect, p;
     spritetype *s;
     uint16_t k;
@@ -4395,7 +4397,8 @@
 void moveexplosions(void)  // STATNUM 5
 {
     short i, j, nexti, sect, p;
-    int32_t l, x, *t;
+    intptr_t l, *t;
+    int32_t x;
     spritetype *s;
 
     i = headspritestat[5];
@@ -4927,7 +4930,8 @@
 
 void moveeffectors(void)   //STATNUM 3
 {
-    int32_t q=0, l, m, x, st, j, *t;
+    intptr_t q=0, l, st, j, *t;
+    int32_t x,m;
     short i, k, nexti, nextk, p, sh, nextj;
     spritetype *s;
     sectortype *sc;
@@ -6486,23 +6490,23 @@
                 if( t[0] == 0 ) break;
 
                 if( s->ang == 1536 )
-                    l = (int32_t) &sc->ceilingz;
+                    l = (intptr_t) &sc->ceilingz;
                 else
-                    l = (int32_t) &sc->floorz;
+                    l = (intptr_t) &sc->floorz;
 
                 if( t[0] == 1 ) //Decide if the s->sectnum should go up or down
                 {
-                    s->zvel = ksgn(s->z-*(int32_t *)l) * (SP<<4);
+                    s->zvel = ksgn(s->z-*(intptr_t*)l) * (SP<<4);
                     t[0]++;
                 }
 
                 if( sc->extra == 0 )
                 {
-                    *(int32_t *)l += s->zvel;
+                    *(intptr_t*)l += s->zvel;
 
-                    if(klabs(*(int32_t *)l-s->z) < 1024)
+                    if(klabs(*(intptr_t*)l-s->z) < 1024)
                     {
-                        *(int32_t *)l = s->z;
+                        *(intptr_t*)l = s->z;
                         KILLIT(i); //All done
                     }
                 }
--- a/Game/src/game.c
+++ b/Game/src/game.c
@@ -5373,7 +5373,7 @@
 void animatesprites(int32_t x,int32_t y,short a,int32_t smoothratio)
 {
     short i, j, k, p, sect;
-    int32_t l, t1,t3,t4;
+    intptr_t l, t1,t3,t4;
     spritetype *s,*t;
 
     for(j=0;j < spritesortcnt; j++)
@@ -5872,7 +5872,7 @@
 				// Lame fix. ok for w32. Doesn't work for other plateform.
 				// How to make a differene between a timer and an address??
             {
-                l = *(int32_t *)(t4+8);
+                l = *(intptr_t *)(t4+sizeof(intptr_t)*2);
 
                 switch( l )
                 {
@@ -5920,7 +5920,7 @@
                         break;
                 }
 
-                t->picnum += k + ( *(int32_t *)t4 ) + l * t3;
+                t->picnum += k + ( *(intptr_t *)t4 ) + l * t3;
 
                 if(l > 0)
                     while(tiles[t->picnum].dim.width == 0 && t->picnum > 0 )
@@ -7687,7 +7687,7 @@
 	char  userconfilename[512];
 
    mymembuf = (char  *)hittype;
-   labelcode = (int32_t *)&sector[0];
+   labelcode = (intptr_t *)&sector[0];
    label = (char  *)sprite;
 
 	sprintf(userconfilename, "%s", confilename);
--- a/Game/src/gamedef.c
+++ b/Game/src/gamedef.c
@@ -2038,7 +2038,7 @@
     }
     else
     {
-        insptr = (int32_t *) *(insptr+1);
+        insptr = (intptr_t *) *(insptr+1);
         if(*insptr == 10)
         {
             insptr+=2;
--- a/Game/src/midi/sdl_midi.c
+++ b/Game/src/midi/sdl_midi.c
@@ -173,7 +173,7 @@
 {
 }
 
-void MUSIC_RerouteMidiChannel(int channel, int cdecl function( int event, int c1, int c2 ))
+void MUSIC_RerouteMidiChannel(int channel, int cdecl (*function)( int event, int c1, int c2 ))
 {
 }
 
--- a/Game/src/util_lib.h
+++ b/Game/src/util_lib.h
@@ -45,7 +45,7 @@
 extern  char  **  _argv;
 
 void RegisterShutdownFunction( void (* shutdown) (void) );
-void   Error (int errorType, char  *error, ...);
+void   Error (int errorType, const char  *error, ...);
 
 uint8_t    CheckParm (char  *check);