Complete.Org: Mailing Lists: Archives: freeciv-dev: July 1999:
Re: [Freeciv-Dev] Server hangs on an Alpha
Home

Re: [Freeciv-Dev] Server hangs on an Alpha

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Matthew OConnor <matthew@xxxxxxxxxxxxxx>, Mr mapgen Peter Schaefer <schaefer@xxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: Re: [Freeciv-Dev] Server hangs on an Alpha
From: Nicolas Brunel <brunel@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 30 Jul 1999 00:37:34 +0000 (GMT)
Reply-to: Nicolas Brunel <brunel@xxxxxxxxxxxxxxxxxxxx>

> 1) Changed line 55 of shared.h and line 314 of shared.c from:
>    to  RANDOM_TYPE myrand(RANDOM_TYPE size)

This is now in cvs.

>       riverbuck = -(long int)myrand(totalmass);
>       mountbuck = -(long int)myrand(totalmass);
>       desertbuck = -(long int)myrand(totalmass);
>       forestbuck = -(long int)myrand(totalmass);
>       swampbuck = -(long int)myrand(totalmass);

Good idea as the result of myrand is an unsigned int.
This uint is cast into an int to do '-' and then cast into a (long int).
Bad karma as would have said Brunus !

> MAX_UINT32 is typecast to a signed int and thus becomes -1...

totally agreed.

> I played around and stepped through the source, played w/ the game and
> it seems that everything is working okay.

Good.
 
> There seems to be a lot of long ints used.

It was surely easiest to cope with multiplication problem. 
> 
> So that makes me wonder.  Are longs just used b/c you want FreeCiv to
> run on machines that have 2 byte ints?
On a 16 bits computer, we will have a big memory problem ! :)
Not enough place to run gcc.
 
> I'd be happy to do it if you would like.
thank you.

Ps : Don't use the extension .orig for the name of your file.
When there is a conflict with a patch with a file foo.c, a foo.c.rej and 
foo.c.orig are created.

Here is a little program :
<<<
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

#define MAX_UINT32 0xFFFFFFFF
#define SIGN_INT32 0x80000000

int main()
{
int i;
uint j;

for(i=-1;i>-20;i--) {
   j = i;
   if (j > (MAX_UINT32 >> 1)) printf("toto %d\n",i);
   if (j & SIGN_INT32) printf("toto %d\n",i);
   }

return 1;
}
>>>

We can still detect sign problems and put a warning with freelog.

Attached is some clean up in mapgen concerning totalmass.

Also, freeciv.pot is updated when I use the autostuff tools.
Maybe it's better to add freeciv.pot in cvsignore ?

It remembers me the good old time. :)

Bye,

Nicolas
diff -aur -Xfreestuff/no.freeciv fc/po/freeciv.pot freeciv/po/freeciv.pot
--- fc/po/freeciv.pot   Wed Jul 28 18:13:36 1999
+++ freeciv/po/freeciv.pot      Thu Jul 29 00:16:21 1999
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 1999-07-28 18:13+0000\n"
+"POT-Creation-Date: 1999-07-29 00:16+0000\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@xxxxxx>\n"
diff -aur -Xfreestuff/no.freeciv fc/server/mapgen.c freeciv/server/mapgen.c
--- fc/server/mapgen.c  Wed Jul 28 23:44:00 1999
+++ freeciv/server/mapgen.c     Thu Jul 29 22:50:10 1999
@@ -984,7 +984,13 @@
   globals for generator 2 & 3
 **************************************************************************/
 static int isleindex, n, e, s, w;
-static long int totalmass; /* better a global than a duplicate formula */
+static int totalmass; /* better a global than a duplicate formula */
+
+static void init_totalmass(int spares)
+{
+  totalmass = ( (map.ysize-6-spares) * map.landpercent * (map.xsize-spares) ) 
/ 100;
+}
+
 
 static int is_cold(int x, int y){
   return ( y * 5 < map.ysize || y * 5 > map.ysize * 4 );
@@ -999,14 +1005,14 @@
                enum tile_terrain_type warm0, enum tile_terrain_type warm1,
                enum tile_terrain_type cold0, enum tile_terrain_type cold1)
 {
-  int x, y, i, k, capac;
-  long int failsafe;
+  int x, y, i, k;
+  int failsafe;
 
   if (*bucket <= 0 ) return;
-  capac = totalmass;
-  i = *bucket / capac;
+  i = *bucket / totalmass;
+  printf(" i-> %d\n",i);
   i++;
-  *bucket -= i * capac;
+  *bucket -= i * totalmass;
 
   k= i;
   failsafe= i*(s-n)*(e-w);
@@ -1054,14 +1060,14 @@
 **************************************************************************/
 static void fillislandrivers(int coast, long int *bucket)
 {
-  int x, y, i, k, capac;
-  long int failsafe;
+  int x, y, i, k;
+  int failsafe;
 
   if (*bucket <= 0 ) return;
-  capac = totalmass;
-  i = *bucket / capac;
+  i = *bucket / totalmass;
   i++;
-  *bucket -= i * capac;
+  printf(" i-> %d\n",i);
+  *bucket -= i * totalmass;
 
   k= i;
   failsafe= i*(s-n)*(e-w);
@@ -1331,7 +1337,7 @@
   }
 
   adjust_terrain_param();
-  totalmass = ( (map.ysize-6-spares) * map.landpercent * (map.xsize-spares) ) 
/ 100;
+  init_totalmass(spares);
 
   /*!PS: The weights NEED to sum up to totalweight (dammit) */
   /* copying the flow of the makeisland loops is the safest way */
@@ -1377,8 +1383,7 @@
   }
 
   adjust_terrain_param();
-  totalmass = ( (map.ysize-6-spares) * map.landpercent * (map.xsize-spares) ) 
/ 100;
-
+  init_totalmass(spares);
 
   bigislands= game.nplayers;
 
@@ -1464,7 +1469,7 @@
   spares= (map.landpercent-5)/30;
 
   adjust_terrain_param();
-  totalmass = ( (map.ysize-6-spares) * map.landpercent * (map.xsize-spares) ) 
/ 100;
+  init_totalmass(spares);
 
   /*!PS: The weights NEED to sum up to totalweight (dammit) */
   totalweight= 0;

[Prev in Thread] Current Thread [Next in Thread]