r4140 - in packages/trunk/hex-a-hop/debian: . patches

Jens Seidel jseidel-guest at alioth.debian.org
Sun Sep 9 17:42:43 UTC 2007


Author: jseidel-guest
Date: 2007-09-09 17:42:43 +0000 (Sun, 09 Sep 2007)
New Revision: 4140

Modified:
   packages/trunk/hex-a-hop/debian/changelog
   packages/trunk/hex-a-hop/debian/patches/endianess.patch
Log:
Game status file is now always written with little endian data.
So it's exchangeable across different systems.


Modified: packages/trunk/hex-a-hop/debian/changelog
===================================================================
--- packages/trunk/hex-a-hop/debian/changelog	2007-09-09 16:58:33 UTC (rev 4139)
+++ packages/trunk/hex-a-hop/debian/changelog	2007-09-09 17:42:43 UTC (rev 4140)
@@ -5,8 +5,7 @@
   * Reduced the CPU load a little bit. Thanks to Joey Hess
     <joeyh at debian.org> for the patch. Closes: #440377
     There is more to do to get it properly fixed.
-  * Code is now (more or less) big endian clean.
-    Closes: #438857
+  * Code is now big endian clean. Closes: #438857
   * Use an ordinary (ASCII) dash instead of a UTF-8
     encoded one in the Vietnamese translation which is
     invalid in the generated man page.
@@ -16,7 +15,7 @@
   * Added Tamil translation. Thanks to Tirumurti
     Vasudevan <agnihot3 at gmail.com>. Closes: #441040
 
- -- Jens Seidel <jensseidel at users.sf.net>  Thu, 06 Sep 2007 00:20:00 +0200
+ -- Jens Seidel <jensseidel at users.sf.net>  Sun, 09 Sep 2007 19:20:00 +0200
 
 hex-a-hop (0.0.20070315-4) unstable; urgency=low
 

Modified: packages/trunk/hex-a-hop/debian/patches/endianess.patch
===================================================================
--- packages/trunk/hex-a-hop/debian/patches/endianess.patch	2007-09-09 16:58:33 UTC (rev 4139)
+++ packages/trunk/hex-a-hop/debian/patches/endianess.patch	2007-09-09 17:42:43 UTC (rev 4140)
@@ -4,8 +4,8 @@
 
 Index: hex-a-hop.svn/packfile.h
 ===================================================================
---- hex-a-hop.svn.orig/packfile.h	2007-09-06 20:37:51.000000000 +0200
-+++ hex-a-hop.svn/packfile.h	2007-09-06 20:44:29.000000000 +0200
+--- hex-a-hop.svn.orig/packfile.h	2007-09-09 18:28:14.000000000 +0200
++++ hex-a-hop.svn/packfile.h	2007-09-09 19:16:58.000000000 +0200
 @@ -16,11 +16,23 @@
      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
@@ -31,7 +31,15 @@
  	public:
  		char name[1];
  
-@@ -73,10 +85,11 @@
+@@ -42,6 +54,7 @@
+ 			return len - strlen(name) - 1;
+ 		}
+ 	};
++	int static_assert1[sizeof(Entry)==8 ? 0 : -1];
+ 
+ 	int numfiles;
+ 	Entry** e;
+@@ -73,10 +86,11 @@
  		if (numfiles || e || data)
  			FATAL("Calling Packfile1::Read when already initialised.");
  
@@ -44,7 +52,7 @@
  		fseek(f, end_offset - size, SEEK_SET);
  
  		data = malloc(size);
-@@ -88,6 +101,8 @@
+@@ -88,10 +102,12 @@
  		while ((void*)i < data_end)
  		{
  			numfiles++;
@@ -53,15 +61,22 @@
  			i = i->GetNext();
  		}
  		
+-		e = new Entry* [numfiles];
++		e = new Entry* [numfiles]; // CHECKME: where to delete?
+ 
+ 		i = (Entry*)data;
+ 		for (int j=0; j<numfiles; j++, i = i->GetNext())
 Index: hex-a-hop.svn/hex_puzzzle.cpp
 ===================================================================
---- hex-a-hop.svn.orig/hex_puzzzle.cpp	2007-09-06 20:37:51.000000000 +0200
-+++ hex-a-hop.svn/hex_puzzzle.cpp	2007-09-06 20:48:40.000000000 +0200
-@@ -444,10 +444,10 @@
+--- hex-a-hop.svn.orig/hex_puzzzle.cpp	2007-09-09 18:28:14.000000000 +0200
++++ hex-a-hop.svn/hex_puzzzle.cpp	2007-09-09 19:03:43.000000000 +0200
+@@ -444,10 +444,12 @@
  }
  
  
 -typedef int Tile;
++// somewhere else Tile map[][] is assigned to an unsigned char not int32_t
++// but the data file format expects it to be 32 bit wide!??
 +typedef int32_t Tile;
  typedef int Dir;
  struct Pos{
@@ -70,16 +85,19 @@
  	Pos() : x(0), y(0) {}
  	Pos(int a, int b) : x(a), y(b) {}
  	bool operator == (Pos const & p) const 
-@@ -1497,7 +1497,7 @@
+@@ -1495,9 +1497,9 @@
+ 	#define MAP_SIZE 30
+ 	char* special[MAP_SIZE][MAP_SIZE];
  	Tile map[MAP_SIZE][MAP_SIZE];
- 	int map_item[MAP_SIZE][MAP_SIZE];
+-	int map_item[MAP_SIZE][MAP_SIZE];
++	int32_t map_item[MAP_SIZE][MAP_SIZE];
  	int tileCount[NumTileTypes];
 -	int levelPar, levelDiff;
 +	int32_t levelPar, levelDiff;
  	int turboAnim;
  	Pos player;
  	int player_items[2];
-@@ -1565,14 +1565,20 @@
+@@ -1565,14 +1567,20 @@
  
  			fgetc(f); // Remove '\n' character
  
@@ -103,68 +121,100 @@
  
  			int highval=0;
  
-@@ -1884,7 +1890,7 @@
+@@ -1902,13 +1910,18 @@
+ 		return false;
+ 	}
  
- 				if (!save)
- 				{
--					char* data = ReadAll(f);
-+					char* data = ReadAll(f); //??
- 					_LoadSave(f, save);
- 					delete [] data;
- 					loadPtr = endLoad = 0;
-@@ -1935,10 +1941,16 @@
++  /** \brief Writes/reads game status to/from a file
++   *
++   *  The game data file is written in little endian so it can be shared
++   *  across different machines.
++   */
+ 	void _LoadSave(FILE* f, bool save)
+ 	{
+ 		typedef unsigned int _fn(void*, unsigned int, unsigned int, FILE*);
+ 		_fn * fn = save ? (_fn*)fwrite : (loadPtr ? (_fn*)fread_replace : (_fn*)fread);
+ 
+ 		#define VERSION 4
+-		int version = VERSION;
++		int version = VERSION; // 1--9
+ 		if (save)
+ 			fprintf(f, "%d\n", version);
+ 		else
+@@ -1935,13 +1948,26 @@
  		if (version==1)
  		{
  			for (int i=0; i<MAP_SIZE; i++)
 -				for (int j=0; j<MAP_SIZE; j++)
 +				for (int j=0; j<MAP_SIZE; j++) {
++					map[i][j] = SWAP32(map[i][j]);
  					fn(&map[i][j], sizeof(map[i][j]), 1, f);
 +					map[i][j] = SWAP32(map[i][j]);
-+					}
++				}
  
++			player.x = SWAP32(player.x);
++			player.y = SWAP32(player.y);
  			fn(&player, sizeof(player), 1, f);
-+      if (!save) {
-+					player.x = SWAP32(player.x);
-+					player.y = SWAP32(player.y);
-+      }
++			player.x = SWAP32(player.x);
++			player.y = SWAP32(player.y);
  
++			for (int i=0; i<MAP_SIZE; ++i)
++				for (int j=0; j<MAP_SIZE; ++j)
++					map_item[i][j] = SWAP32(map_item[i][j]);
  			if (fn(map_item, sizeof(map_item), 1, f) == 0)
  				memset(map_item, 0, sizeof(map_item));
-@@ -1966,18 +1978,28 @@
++			for (int i=0; i<MAP_SIZE; ++i)
++				for (int j=0; j<MAP_SIZE; ++j)
++					map_item[i][j] = SWAP32(map_item[i][j]);
+ 		}
+ 		else if (version>=2 && version<=4)
+ 		{
+@@ -1966,18 +1992,28 @@
  				memset(map_item, 0, sizeof(map_item));
  			}
  
 -			if (version>=3)
--				fn(&levelPar, 1, sizeof(levelPar), f);
 +			if (version>=3) {
-+				fn(&levelPar, sizeof(levelPar), 1, f);
-+				if (!save) {
-+					levelPar = SWAP32(levelPar);
-+				}
++				levelPar = SWAP32(levelPar);
+ 				fn(&levelPar, 1, sizeof(levelPar), f);
++				levelPar = SWAP32(levelPar);
 +			}
  			else if (!save)
  				levelPar = 0;
  
 -			if (version>=4)
--				fn(&levelDiff, 1, sizeof(levelDiff), f);
 +			if (version>=4) {
-+				fn(&levelDiff, sizeof(levelDiff), 1, f);
-+				if (!save) {
-+					levelDiff = SWAP32(levelDiff);
-+				}
++				levelDiff = SWAP32(levelDiff);
+ 				fn(&levelDiff, 1, sizeof(levelDiff), f);
++				levelDiff = SWAP32(levelDiff);
 +			}
  			else if (!save)
  				levelDiff = 0;
  
--			fn(bounds, sizeof(bounds), 1, f);
-+			fn(bounds, sizeof(bounds), 1, f); // CHECKME
+ 			fn(bounds, sizeof(bounds), 1, f);
++			player.x = SWAP32(player.x);
++			player.y = SWAP32(player.y);
  			fn(&player, sizeof(player), 1, f);
 +			player.x = SWAP32(player.x);
 +			player.y = SWAP32(player.y);
  
  			int offsetx=0, offsety=0;
  
-@@ -2027,13 +2049,14 @@
+@@ -2016,24 +2052,27 @@
+ 					for (int j=bounds[2]; j<=bounds[3]; j++)
+ 						if (special[i][j])
+ 						{
+-							short len = strlen(special[i][j]);
++							int16_t len = strlen(special[i][j]);
+ 							unsigned char x=i, y=j;
+ 							fn(&x, sizeof(x), 1, f);
+ 							fn(&y, sizeof(y), 1, f);
++							len = SWAP16(len);
+ 							fn(&len, sizeof(len), 1, f);
++							len = SWAP16(len);
+ 							fn(special[i][j], 1, len, f);
+ 						}
+ 			}
  			else
  			{
  				while(1){
@@ -180,7 +230,7 @@
  					if (len<0) break;
  					char* tmp = new char[len+1];
  					tmp[len] = 0;
-@@ -2398,10 +2421,12 @@
+@@ -2398,10 +2437,12 @@
  		FILE* f = file_open(bmp, "rb");
  		if (!f) FATAL("Unable to open file", bmp);
  
@@ -195,7 +245,7 @@
  
  		tmp = new uint32[(int)w*h];
  		
-@@ -2414,9 +2439,12 @@
+@@ -2414,9 +2455,12 @@
  			else
  			{
  				fread(&c, sizeof(c), 1, f);
@@ -209,3 +259,122 @@
  			}
  			tmp[p] = c | 0xff000000;
  		}
+Index: hex-a-hop.svn/savestate.h
+===================================================================
+--- hex-a-hop.svn.orig/savestate.h	2007-09-09 18:28:14.000000000 +0200
++++ hex-a-hop.svn/savestate.h	2007-09-09 19:23:22.000000000 +0200
+@@ -23,12 +23,16 @@
+ {
+ 	friend struct HexPuzzle;
+ 
++	// CHECKME: If char is larger than 8 bits (== 1 byte???)
++	// the code is no longer big endian save? SWAP16/32 is necessary?
++	// Or is a byte always of the same size as char, e.g. 16 bits, so
++	// that int16_t is equally saved on big and little endian systems?
+ 	char * bestSolution;
+-	int bestSolutionLength;
+-	int bestScore;
++	int32_t bestSolutionLength;
++	int32_t bestScore;
+ 	#define NUM_LAST_SCORES 19
+-	int lastScores[NUM_LAST_SCORES];
+-	int unlocked;
++	int32_t lastScores[NUM_LAST_SCORES];
++	int32_t unlocked;
+ public:
+ 	LevelSave()
+ 	{
+@@ -47,11 +51,24 @@
+ 		typedef unsigned int _fn(void*, unsigned int, unsigned int, FILE*);
+ 		_fn * fn = save ? (_fn*)fwrite : (_fn*)fread;
+ 
++		// we write little endian data
++		bestSolutionLength = SWAP32(bestSolutionLength);
++		bestScore = SWAP32(bestScore);
++		for (int i=0; i<NUM_LAST_SCORES; ++i)
++			lastScores[i] = SWAP32(lastScores[i]);
++		unlocked = SWAP32(unlocked);
++
+ 		fn(&bestSolutionLength, sizeof(bestSolutionLength), 1, f);
+ 		fn(&bestScore, sizeof(bestScore), 1, f);
+ 		fn(&lastScores, sizeof(lastScores), 1, f);
+ 		fn(&unlocked, sizeof(unlocked), 1, f);		
+-		
++
++		bestSolutionLength = SWAP32(bestSolutionLength);
++		bestScore = SWAP32(bestScore);
++		for (int i=0; i<NUM_LAST_SCORES; ++i)
++			lastScores[i] = SWAP32(lastScores[i]);
++		unlocked = SWAP32(unlocked);
++
+ 		if (bestSolutionLength)
+ 		{
+ 			if (!save) SetSolution(bestSolutionLength);
+@@ -132,12 +149,23 @@
+ 	};
+ 
+ 	struct General {
+-		int scoringOn;
+-		int hintFlags;
+-		int completionPercentage;
+-		int endSequence;
+-		int masteredPercentage;
+-		int pad[6];
++    /// Change big endian data into little endian data, do nothing on little endian systems
++		void SwapBytes()
++		{
++			scoringOn = SWAP32(scoringOn);
++			hintFlags = SWAP32(hintFlags);
++			completionPercentage = SWAP32(completionPercentage);
++			endSequence = SWAP32(endSequence);
++			masteredPercentage = SWAP32(masteredPercentage);
++			for (unsigned int i=0; i<sizeof(pad)/sizeof(int32_t); ++i)
++				pad[i] = SWAP32(pad[i]);
++		}
++		int32_t scoringOn;
++		int32_t hintFlags;
++		int32_t completionPercentage;
++		int32_t endSequence;
++		int32_t masteredPercentage;
++		int32_t pad[6];
+ 	};
+ 
+ 	X* first;
+@@ -191,12 +219,16 @@
+ 			//printf("----\n");
+ 
+ 			fputc('2', f);
++			general.SwapBytes(); // big==>little endian
+ 			fwrite(&general, sizeof(general), 1, f);
++			general.SwapBytes(); // revert changes
+ 			for(X* x=first; x; x=x->next)
+ 			{
+-				short len = strlen(x->name);
++				int16_t len = strlen(x->name);
++				len = SWAP16(len);
+ 				fwrite(&len, sizeof(len), 1, f);
+-				fwrite(x->name, len, 1, f);
++				len = SWAP16(len);
++				fwrite(x->name, 1, len, f);
+ 
+ 				x->LoadSave(f,save);
+ 
+@@ -214,6 +246,7 @@
+ 			if (v=='2')
+ 			{
+ 				fread(&general, sizeof(general), 1, f);
++				general.SwapBytes();
+ 				v = '1';
+ 			}
+ 			if (v=='1')
+@@ -221,8 +254,9 @@
+ 				while(!feof(f))
+ 				{
+ 					char temp[1000];
+-					short len;
++					int16_t len;
+ 					fread(&len, sizeof(len), 1, f);
++					len = SWAP16(len);
+ 					if (feof(f)) break;
+ 					fread(temp, len, 1, f);
+ 					temp[len] = 0;




More information about the Pkg-games-commits mailing list