ソースを参照

- gcc compile fix
- mismatching enum (?) in HeroBonus
- probably fixed some cases of unaligned access

Ivan Savenko 12 年 前
コミット
8ffd482324

+ 9 - 11
client/CAnimation.cpp

@@ -4,7 +4,6 @@
 #include "../lib/Filesystem/CResourceLoader.h"
 #include "../lib/Filesystem/ISimpleResourceLoader.h"
 #include "../lib/JsonNode.h"
-#include "../lib/vcmi_endian.h"
 
 #include "CBitmapHandler.h"
 #include "Graphics.h"
@@ -131,13 +130,13 @@ CDefFile::CDefFile(std::string Name):
 	static SDL_Color H3Palette[8] =
 	{
 		{   0,   0,   0,   0},// 100% - transparency
-		{   0,   0,   0, 192},//  75% - shadow border,
+		{   0,   0,   0,  64},//  75% - shadow border,
 		{   0,   0,   0, 128},// TODO: find exact value
 		{   0,   0,   0, 128},// TODO: for transparency
 		{   0,   0,   0, 128},//  50% - shadow body
 		{   0,   0,   0,   0},// 100% - selection highlight
 		{   0,   0,   0, 128},//  50% - shadow body   below selection
-		{   0,   0,   0, 192} // 75% - shadow border below selection
+		{   0,   0,   0,  64} // 75% - shadow border below selection
 	};
 	data = animationCache.getCachedFile(ResourceID(std::string("SPRITES/") + Name, EResType::ANIMATION));
 
@@ -196,14 +195,13 @@ void CDefFile::loadFrame(size_t frame, size_t group, ImageLoader &loader) const
 	const SSpriteDef sd = * reinterpret_cast<const SSpriteDef *>(FDef);
 	SSpriteDef sprite;
 
-	//sprite.size = SDL_SwapLE32(sd.size);//unused
-	sprite.format = SDL_SwapLE32(sd.format);
-	sprite.fullWidth = SDL_SwapLE32(sd.fullWidth);
-	sprite.fullHeight = SDL_SwapLE32(sd.fullHeight);
-	sprite.width = SDL_SwapLE32(sd.width);
-	sprite.height = SDL_SwapLE32(sd.height);
-	sprite.leftMargin = SDL_SwapLE32(sd.leftMargin);
-	sprite.topMargin = SDL_SwapLE32(sd.topMargin);
+	sprite.format = read_le_u32(&sd.format);
+	sprite.fullWidth = read_le_u32(&sd.fullWidth);
+	sprite.fullHeight = read_le_u32(&sd.fullHeight);
+	sprite.width = read_le_u32(&sd.width);
+	sprite.height = read_le_u32(&sd.height);
+	sprite.leftMargin = read_le_u32(&sd.leftMargin);
+	sprite.topMargin = read_le_u32(&sd.topMargin);
 
 	ui32 currentOffset = sizeof(SSpriteDef);
 	ui32 BaseOffset =    sizeof(SSpriteDef);

+ 2 - 1
client/CAnimation.h

@@ -1,5 +1,6 @@
 #pragma once
 
+#include "../lib/vcmi_endian.h"
 #include "UIFramework/CIntObject.h"
 
 /*
@@ -33,7 +34,7 @@ private:
 		ui32 height;
 		si32 leftMargin;
 		si32 topMargin;
-	};
+	} PACKED_STRUCT;
 	//offset[group][frame] - offset of frame data in file
 	std::map<size_t, std::vector <size_t> > offset;
 

+ 11 - 12
client/CDefHandler.cpp

@@ -4,7 +4,6 @@
 
 #include "../lib/Filesystem/CResourceLoader.h"
 #include "../lib/VCMI_Lib.h"
-#include "../lib/vcmi_endian.h"
 #include "CBitmapHandler.h"
 
 /*
@@ -58,10 +57,10 @@ void CDefHandler::openFromMemory(ui8 *table, const std::string & name)
 	ui8 *p;
 
 	defName = name;
-	DEFType = SDL_SwapLE32(de.DEFType);
-	width = SDL_SwapLE32(de.width);
-	height = SDL_SwapLE32(de.height);
-	ui32 totalBlocks = SDL_SwapLE32(de.totalBlocks);
+	DEFType = read_le_u32(&de.DEFType);
+	width = read_le_u32(&de.width);
+	height = read_le_u32(&de.height);
+	ui32 totalBlocks = read_le_u32(&de.totalBlocks);
 
 	for (ui32 it=0;it<256;it++)
 	{
@@ -147,13 +146,13 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const BMPPal
 	BaseOffset = SEntries[SIndex].offset;
 	SSpriteDef sd = * reinterpret_cast<const SSpriteDef *>(FDef + BaseOffset);
 
-	defType2 = SDL_SwapLE32(sd.defType2);
-	FullWidth = SDL_SwapLE32(sd.FullWidth);
-	FullHeight = SDL_SwapLE32(sd.FullHeight);
-	SpriteWidth = SDL_SwapLE32(sd.SpriteWidth);
-	SpriteHeight = SDL_SwapLE32(sd.SpriteHeight);
-	LeftMargin = SDL_SwapLE32(sd.LeftMargin);
-	TopMargin = SDL_SwapLE32(sd.TopMargin);
+	defType2 = read_le_u32(&sd.defType2);
+	FullWidth = read_le_u32(&sd.FullWidth);
+	FullHeight = read_le_u32(&sd.FullHeight);
+	SpriteWidth = read_le_u32(&sd.SpriteWidth);
+	SpriteHeight = read_le_u32(&sd.SpriteHeight);
+	LeftMargin = read_le_u32(&sd.LeftMargin);
+	TopMargin = read_le_u32(&sd.TopMargin);
 	RightMargin = FullWidth - SpriteWidth - LeftMargin;
 	BottomMargin = FullHeight - SpriteHeight - TopMargin;
 

+ 10 - 7
client/CDefHandler.h

@@ -1,6 +1,6 @@
 #pragma once
 
-
+#include "../lib/vcmi_endian.h"
 
 struct SDL_Surface;
 struct BMPPalette;
@@ -24,17 +24,19 @@ struct Cimage
 
 // Def entry in file. Integer fields are all little endian and will
 // need to be converted.
-struct SDefEntryBlock {
+struct SDefEntryBlock
+{
 	ui32 unknown1;
 	ui32 totalInBlock;
 	ui32 unknown2;
 	ui32 unknown3;
 	ui8 data[0];
-};
+} PACKED_STRUCT;
 
 // Def entry in file. Integer fields are all little endian and will
 // need to be converted.
-struct SDefEntry {
+struct SDefEntry
+{
 	ui32 DEFType;
 	ui32 width;
 	ui32 height;
@@ -49,11 +51,12 @@ struct SDefEntry {
 	// SDefEntry is followed by a series of SDefEntryBlock
 	// This is commented out because VC++ doesn't accept C99 syntax.
 	//struct SDefEntryBlock blocks[];
-};
+} PACKED_STRUCT;
 
 // Def entry in file. Integer fields are all little endian and will
 // need to be converted.
-struct SSpriteDef {
+struct SSpriteDef
+{
 	ui32 prSize;
 	ui32 defType2;
 	ui32 FullWidth;
@@ -62,7 +65,7 @@ struct SSpriteDef {
 	ui32 SpriteHeight;
 	ui32 LeftMargin;
 	ui32 TopMargin;
-};
+} PACKED_STRUCT;
 
 class CDefEssential //DefHandler with images only
 {

+ 1 - 1
lib/BattleHex.h

@@ -1,5 +1,5 @@
 #pragma once
-#include "../global.h"
+
 #include "GameConstants.h"
 
 

+ 9 - 20
lib/Filesystem/CLodArchiveLoader.cpp

@@ -49,43 +49,32 @@ CLodArchiveLoader::CLodArchiveLoader(const std::string & archive)
 
 void CLodArchiveLoader::initLODArchive(CFileInputStream & fileStream)
 {
-	// Define LodEntryBlock struct
-	struct LodEntryBlock
-	{
-		char filename[16];
-		ui32 offset;
-		ui32 uncompressedSize;
-		ui32 unused;
-		ui32 size;
-	};
-
 	// Read count of total files
-    CBinaryReader reader(&fileStream);
+	CBinaryReader reader(&fileStream);
 
 	fileStream.seek(8);
 	ui32 totalFiles = reader.readUInt32();
 
 	// Get all entries from file
 	fileStream.seek(0x5c);
-	struct LodEntryBlock * lodEntries = new struct LodEntryBlock[totalFiles];
-	fileStream.read(reinterpret_cast<ui8 *>(lodEntries), sizeof(struct LodEntryBlock) * totalFiles);
 
 	// Insert entries to list
 	for(ui32 i = 0; i < totalFiles; i++)
 	{
+		char filename[16];
+		reader.read(reinterpret_cast<ui8*>(filename), 16);
+
 		// Create archive entry
 		ArchiveEntry entry;
-		entry.name = lodEntries[i].filename;
-		entry.offset= SDL_SwapLE32(lodEntries[i].offset);
-		entry.realSize = SDL_SwapLE32(lodEntries[i].uncompressedSize);
-		entry.size = SDL_SwapLE32(lodEntries[i].size);
+		entry.name     = filename;
+		entry.offset   = reader.readUInt32();
+		entry.realSize = reader.readUInt32();
+		fileStream.skip(4); // unused, unknown
+		entry.size     = reader.readUInt32();
 
 		// Add lod entry to local entries map
 		entries[entry.name] = entry;
 	}
-
-	// Delete lod entries array
-	delete[] lodEntries;
 }
 
 void CLodArchiveLoader::initVIDArchive(CFileInputStream & fileStream)

+ 1 - 1
lib/HeroBonus.cpp

@@ -1496,7 +1496,7 @@ int RankRangeLimiter::limit(const BonusLimitationContext &context) const
 	const CStackInstance *csi = retreiveStackInstance(&context.node);
 	if(csi)
 	{
-		if (csi->getNodeType() == Bonus::COMMANDER) //no stack exp bonuses for commander creatures
+		if (csi->getNodeType() == CBonusSystemNode::COMMANDER) //no stack exp bonuses for commander creatures
 			return true;
 		return csi->getExpRank() < minRank || csi->getExpRank() > maxRank;
 	}

+ 8 - 1
lib/vcmi_endian.h

@@ -1,5 +1,6 @@
 #pragma once
 
+//FIXME:library file depends on SDL - make cause troubles
 #include <SDL_endian.h>
 
 /*
@@ -18,7 +19,7 @@
  *    memory. On big endian machines, the value will be byteswapped.
  */
 
-#if defined(linux) && defined(sparc) 
+#if defined(linux) && (defined(sparc) || defined(__arm__))
 /* SPARC does not support unaligned memory access. Let gcc know when
  * to emit the right code. */
 struct unaligned_Uint16 { ui16 val __attribute__(( packed )); };
@@ -39,9 +40,15 @@ static inline ui32 read_unaligned_u32(const void *p)
 #define read_le_u16(p) (SDL_SwapLE16(read_unaligned_u16(p)))
 #define read_le_u32(p) (SDL_SwapLE32(read_unaligned_u32(p)))
 
+#define PACKED_STRUCT __attribute__(( packed ))
+
 #else
+
 #define read_le_u16(p) (SDL_SwapLE16(* reinterpret_cast<const ui16 *>(p)))
 #define read_le_u32(p) (SDL_SwapLE32(* reinterpret_cast<const ui32 *>(p)))
+
+#define PACKED_STRUCT
+
 #endif
 
 static inline char readChar(const ui8 * buffer, int & i)