Thread: [Ika-commits] SF.net SVN: ika:[718] trunk/common
Status: Beta
Brought to you by:
the_speed_bump
From: <slu...@us...> - 2010-02-15 10:02:42
|
Revision: 718 http://ika.svn.sourceforge.net/ika/?rev=718&view=rev Author: sluimers Date: 2010-02-15 10:02:35 +0000 (Mon, 15 Feb 2010) Log Message: ----------- Linux bug fixes. First time I ever commit something to ika, so if anything goes wrong please tell me. Modified Paths: -------------- trunk/common/Canvas.cpp trunk/common/chr.cpp trunk/common/fileio.cpp trunk/common/fontfile.cpp trunk/common/log.cpp trunk/common/vsp.cpp Modified: trunk/common/Canvas.cpp =================================================================== --- trunk/common/Canvas.cpp 2010-01-27 06:40:51 UTC (rev 717) +++ trunk/common/Canvas.cpp 2010-02-15 10:02:35 UTC (rev 718) @@ -1,4 +1,6 @@ - +#ifdef linux +#include <string.h> +#endif #include <sstream> #include <stdexcept> Modified: trunk/common/chr.cpp =================================================================== --- trunk/common/chr.cpp 2010-01-27 06:40:51 UTC (rev 717) +++ trunk/common/chr.cpp 2010-02-15 10:02:35 UTC (rev 718) @@ -1,3 +1,6 @@ +#ifdef linux +#include <string.h> +#endif #include <cassert> #include <cstdlib> #include <fstream> Modified: trunk/common/fileio.cpp =================================================================== --- trunk/common/fileio.cpp 2010-01-27 06:40:51 UTC (rev 717) +++ trunk/common/fileio.cpp 2010-02-15 10:02:35 UTC (rev 718) @@ -1,3 +1,6 @@ +#ifdef linux +#include <string.h> +#endif #include "fileio.h" #include "zlib.h" #include <stdio.h> Modified: trunk/common/fontfile.cpp =================================================================== --- trunk/common/fontfile.cpp 2010-01-27 06:40:51 UTC (rev 717) +++ trunk/common/fontfile.cpp 2010-02-15 10:02:35 UTC (rev 718) @@ -1,3 +1,7 @@ +#ifdef linux +#include <string.h> +#include <memory> +#endif #include <limits> #include "fontfile.h" Modified: trunk/common/log.cpp =================================================================== --- trunk/common/log.cpp 2010-01-27 06:40:51 UTC (rev 717) +++ trunk/common/log.cpp 2010-02-15 10:02:35 UTC (rev 718) @@ -59,7 +59,7 @@ #elif defined(__GNUC__) char* buffer = 0; - int len = asprintf(&buffer, s, lst); + int len = vasprintf(&buffer, s, lst); if (len == -1) { logFile << "Log system error: Unable to write some stuff."; @@ -95,7 +95,7 @@ #elif defined(__GNUC__) char* buffer = 0; - int len = asprintf(&buffer, s, lst); + int len = vasprintf(&buffer, s, lst); if (len == -1) { logFile << "Log system error: Unable to write some stuff."; Modified: trunk/common/vsp.cpp =================================================================== --- trunk/common/vsp.cpp 2010-01-27 06:40:51 UTC (rev 717) +++ trunk/common/vsp.cpp 2010-02-15 10:02:35 UTC (rev 718) @@ -1,4 +1,8 @@ // VSP.cpp +#ifdef linux +#include <string.h> +#endif + #include <cassert> #include <stdio.h> #include "vsp.h" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <slu...@us...> - 2010-07-21 19:44:53
|
Revision: 726 http://ika.svn.sourceforge.net/ika/?rev=726&view=rev Author: sluimers Date: 2010-07-21 19:44:46 +0000 (Wed, 21 Jul 2010) Log Message: ----------- Cleaned up the warnings. Modified Paths: -------------- trunk/common/Canvas.h trunk/common/chr.cpp trunk/common/chr.h trunk/common/compression.h trunk/common/configfile.h trunk/common/fileio.cpp trunk/common/fileio.h trunk/common/fontfile.h trunk/common/log.cpp trunk/common/log.h trunk/common/map.cpp trunk/common/map.h trunk/common/matrix.h trunk/common/oldbase64.cpp trunk/common/oldbase64.h trunk/common/rle.cpp trunk/common/rle.h trunk/common/types.h trunk/common/utility.h trunk/common/vergemap.cpp trunk/common/vsp.cpp trunk/common/vsp.h Modified: trunk/common/Canvas.h =================================================================== --- trunk/common/Canvas.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/Canvas.h 2010-07-21 19:44:46 UTC (rev 726) @@ -1,7 +1,7 @@ #pragma once -#include "common/utility.h" -#include "common/types.h" +#include "utility.h" +#include "types.h" /** * Canvases are purely software representations of images. Nothing more. @@ -48,9 +48,8 @@ void SetClipRect(const Rect& r); private: - RGBA* _pixels; ///< Pointer to raw pixel data int _width, _height; ///< Dimensions - + RGBA* _pixels; ///< Pointer to raw pixel data Rect _cliprect; ///< Operations are restricted to this region of the image. }; Modified: trunk/common/chr.cpp =================================================================== --- trunk/common/chr.cpp 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/chr.cpp 2010-07-21 19:44:46 UTC (rev 726) @@ -11,7 +11,7 @@ #include "chr.h" #include "compression.h" #include "fileio.h" -#include "common/log.h" +#include "log.h" #include "oldbase64.h" #include "rle.h" #include "utility.h" @@ -406,7 +406,7 @@ f.Write(moveScripts.size()); // write the number of scripts - for (uint i = 0; i < scriptCount; i++) { + for (uint i = 0; i < (uint)scriptCount; i++) { const std::string& script = moveScripts[scriptNames[i]]; f.Write(script.length()); // write the length f.Write(script.c_str(), script.length()); // write the actual script Modified: trunk/common/chr.h =================================================================== --- trunk/common/chr.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/chr.h 2010-07-21 19:44:46 UTC (rev 726) @@ -1,7 +1,7 @@ #pragma once #include <map> -#include "common/utility.h" +#include "utility.h" #include "Canvas.h" struct File; @@ -12,7 +12,7 @@ * Note that the data structure allows for each frame to have its own dimensions. * The file format does too, however we won't be actually implementing this yet. * - * This is TERRIBLE. TODO: unscrew. :P + * This is TERRIBLE. TODO: fix this. :P */ struct CCHRfile { typedef std::map<std::string, std::string> StringMap; @@ -57,9 +57,11 @@ private: std::vector<Canvas*> _frame; ///< Frame data. - int _width, _height; - int _hotspotX, _hotspotY; ///< Hotspot position. - int _hotspotWidth, _hotspotHeight; ///< Hotspot width and height. + int _hotspotX, _hotspotY; ///< Hotspot position. + int _hotspotWidth, _hotspotHeight; ///< Hotspot width and height. + int _width, _height; + + void LoadCHR(const std::string& filename); void Loadv2CHR(File& f); Modified: trunk/common/compression.h =================================================================== --- trunk/common/compression.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/compression.h 2010-07-21 19:44:46 UTC (rev 726) @@ -1,6 +1,6 @@ #pragma once -#include "common/utility.h" +#include "utility.h" namespace Compression { Modified: trunk/common/configfile.h =================================================================== --- trunk/common/configfile.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/configfile.h 2010-07-21 19:44:46 UTC (rev 726) @@ -15,7 +15,7 @@ #include <map> -#include "common/utility.h" +#include "utility.h" struct CConfigFile { typedef std::map<std::string, std::string> ConfigMap; Modified: trunk/common/fileio.cpp =================================================================== --- trunk/common/fileio.cpp 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/fileio.cpp 2010-07-21 19:44:46 UTC (rev 726) @@ -3,6 +3,7 @@ #endif #include "fileio.h" #include "zlib.h" +#include "log.h" #include <stdio.h> /* @@ -163,11 +164,15 @@ } void File::Read(void* dest, int numbytes) { - if (numbytes == 0) return; - if (dest == NULL) return; + if (numbytes == 0) return; + if (dest == NULL) return; if (mode!=open_read) return; - fread(dest, 1, numbytes, f); + int rf = fread(dest, 1, numbytes, f); + if (!rf) { + Log::Write("Fileio: Error while reading file\n"); + return; + } } void File::ReadString(char* dest) { @@ -183,7 +188,12 @@ char buffer[256]; - fscanf(f, "%255s", buffer); + int sf = fscanf(f, "%255s", buffer); + if (!sf) { + Log::Write("Fileio: Error while reading token\n"); + return; + } + dest = buffer; } Modified: trunk/common/fileio.h =================================================================== --- trunk/common/fileio.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/fileio.h 2010-07-21 19:44:46 UTC (rev 726) @@ -1,6 +1,6 @@ #pragma once -#include "common/utility.h" +#include "utility.h" #include <stdio.h> struct File { Modified: trunk/common/fontfile.h =================================================================== --- trunk/common/fontfile.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/fontfile.h 2010-07-21 19:44:46 UTC (rev 726) @@ -4,7 +4,7 @@ #pragma once -#include "common/utility.h" +#include "utility.h" #include "Canvas.h" struct File; Modified: trunk/common/log.cpp =================================================================== --- trunk/common/log.cpp 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/log.cpp 2010-07-21 19:44:46 UTC (rev 726) @@ -1,5 +1,5 @@ -#include "common/log.h" +#include "log.h" #include "utility.h" #include <stdarg.h> Modified: trunk/common/log.h =================================================================== --- trunk/common/log.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/log.h 2010-07-21 19:44:46 UTC (rev 726) @@ -6,7 +6,7 @@ #pragma once -#include "common/utility.h" +#include "utility.h" //#define LOG_CALLBACK Modified: trunk/common/map.cpp =================================================================== --- trunk/common/map.cpp 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/map.cpp 2010-07-21 19:44:46 UTC (rev 726) @@ -5,7 +5,7 @@ #include "aries.h" #include "base64.h" #include "compression.h" -#include "common/log.h" +#include "log.h" #include "map.h" #include "oldbase64.h" #include "utility.h" @@ -267,7 +267,7 @@ std::string dir = Local::getStringNode(*iter, "direction"); e.direction = face_down; - for (uint i = 0; i < numDirs; i++) + for (uint i = 0; i < (uint)numDirs; i++) if (dir == dirNames[i]) { e.direction = (Direction)i; break; } e.speed = Local::getIntNode(*iter, "speed"); Modified: trunk/common/map.h =================================================================== --- trunk/common/map.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/map.h 2010-07-21 19:44:46 UTC (rev 726) @@ -1,7 +1,7 @@ #pragma once -#include "common/utility.h" +#include "utility.h" #include "types.h" #include "matrix.h" @@ -37,9 +37,9 @@ Direction direction; int speed; std::string moveScript; - bool obstructsEntities; - bool obstructedByEntities; - bool obstructedByMap; + bool obstructedByEntities; + bool obstructedByMap; + bool obstructsEntities; std::string adjActivateScript; // called when the entity touches another entity std::string activateScript; // called when the entity is activated. (talked to, etc) Entity() @@ -88,14 +88,14 @@ std::vector<Entity> entities; std::vector<Zone> zones; - RGBA tintColour; - // TODO: // std::vector<LineSegments> obstructionVectors; - Matrix<u8> obstructions; - Matrix<uint> tiles; + Matrix<uint> tiles; + Matrix<u8> obstructions; + RGBA tintColour; + Layer(const std::string& l = "", int width = 0, int height = 0) : label(l) , x(0) , y(0) Modified: trunk/common/matrix.h =================================================================== --- trunk/common/matrix.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/matrix.h 2010-07-21 19:44:46 UTC (rev 726) @@ -3,7 +3,7 @@ #include <cassert> #include <algorithm> -#include "common/utility.h" +#include "utility.h" //#define FOLLOWTHEWHITERABBIT Modified: trunk/common/oldbase64.cpp =================================================================== --- trunk/common/oldbase64.cpp 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/oldbase64.cpp 2010-07-21 19:44:46 UTC (rev 726) @@ -213,7 +213,7 @@ #include <cassert> #include <vector> -#include "common/utility.h" +#include "utility.h" namespace oldBase64 { Modified: trunk/common/oldbase64.h =================================================================== --- trunk/common/oldbase64.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/oldbase64.h 2010-07-21 19:44:46 UTC (rev 726) @@ -1,8 +1,8 @@ #include <string> -#include "common/utility.h" +#include "utility.h" /** - * Old shitty base64 implementation. + * Old base64 implementation. * This is WRONG. It does not produce correct output. * It remains in the source so ika can load files that were made using it. */ Modified: trunk/common/rle.cpp =================================================================== --- trunk/common/rle.cpp 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/rle.cpp 2010-07-21 19:44:46 UTC (rev 726) @@ -1,5 +1,5 @@ -#include "common/utility.h" +#include "utility.h" void ReadCompressedLayer1(u8 *dest, int numBytes, u8 *src) { int j, n = 0; Modified: trunk/common/rle.h =================================================================== --- trunk/common/rle.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/rle.h 2010-07-21 19:44:46 UTC (rev 726) @@ -9,7 +9,7 @@ #pragma once -#include "common/utility.h" +#include "utility.h" extern void ReadCompressedLayer1(u8 *dest, int numbytes, u8 *src); extern void ReadCompressedLayer2(u16 *dest, int numwords, u16 *src); Modified: trunk/common/types.h =================================================================== --- trunk/common/types.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/types.h 2010-07-21 19:44:46 UTC (rev 726) @@ -8,13 +8,13 @@ /// Everybody has their own Rect struct. This is mine. struct Rect { - int left; - int top; - int right; - int bottom; + int left; + int right; + int top; + int bottom; - inline int Width() const { return right - left; } - inline int Height() const { return bottom - top; } + inline int Width() const { return right - left; } + inline int Height() const { return bottom - top; } void Normalize() { if (left > right) std::swap(left, right); Modified: trunk/common/utility.h =================================================================== --- trunk/common/utility.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/utility.h 2010-07-21 19:44:46 UTC (rev 726) @@ -48,18 +48,18 @@ #endif template <bool B> -struct static_assert { +struct static_assertion { int static_assert_failed[B ? 1 : -1]; }; #ifndef __GNUC__ -static_assert<sizeof(u8) == 1>; -static_assert<sizeof(u16) == 2>; -static_assert<sizeof(u32) == 4>; -static_assert<sizeof(u64) == 8>; +static_assertion<sizeof(u8) == 1>; +static_assertion<sizeof(u16) == 2>; +static_assertion<sizeof(u32) == 4>; +static_assertion<sizeof(u64) == 8>; #endif -// This really belongs in the language anyway, so fuckit. +// This really belongs in the language anyway, or whatever. #define foreach BOOST_FOREACH // Tempted, but probably a bad idea: Modified: trunk/common/vergemap.cpp =================================================================== --- trunk/common/vergemap.cpp 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/vergemap.cpp 2010-07-21 19:44:46 UTC (rev 726) @@ -8,17 +8,26 @@ #include "map.h" #include "vsp.h" #include "rle.h" +#include "log.h" #include "utility.h" static u16 fgetw(FILE* f) { u16 s = 0; - fread(&s, 1, 2, f); + int rf = fread(&s, 1, 2, f); + if (!rf) { + Log::Write("vergemap: Error fgetw\n"); + return 0; + } return s; } static u32 fgetq(FILE* f) { u32 q = 0; - fread(&q, 1, 4, f); + int rf = fread(&q, 1, 4, f); + if (!rf) { + Log::Write("vergemap: Error fgetq\n"); + return 0; + } return q; } @@ -49,8 +58,16 @@ char buffer[256]; std::fill(buffer, buffer + 256, 0); - fread(buffer, 1, 13, f); map->tilesetName = buffer; - fread(buffer, 1, 13, f); map->metaData["music"] = buffer; + int rf = fread(buffer, 1, 13, f); map->tilesetName = buffer; + if (!rf) { + Log::Write("vergemap: Error tilesetname\n"); + return 0; + } + rf = fread(buffer, 1, 13, f); map->metaData["music"] = buffer; + if (!rf) { + Log::Write("vergemap: Error metaData['music']\n"); + return 0; + } fgetc(f); // layerCount fgetc(f); // pmulx @@ -58,7 +75,11 @@ fgetc(f); // pdivx //int pdivy = pdivx; - fread(buffer, 1, 30, f); map->metaData["name"] = buffer; + int rn = fread(buffer, 1, 30, f); map->metaData["name"] = buffer; + if (!rn) { + Log::Write("vergemap: Error metaData['name']\n"); + return 0; + } bool showName = fgetc(f) != 0; map->metaData["showname"] = showName ? "true" : "false"; bool saveFlag = fgetc(f) != 0; map->metaData["saveflag"] = saveFlag ? "true" : "false"; @@ -79,10 +100,23 @@ ScopedArray<u16> lay0(new u16[xsize * ysize]); ScopedArray<u16> lay1(new u16[xsize * ysize]); ScopedArray<u8> obs(new u8[xsize * ysize]); - fread(lay0.get(), sizeof(u16), xsize * ysize, f); - fread(lay1.get(), sizeof(u16), xsize * ysize, f); - fread(obs.get(), sizeof(u8), xsize * ysize, f); + rf = fread(lay0.get(), sizeof(u16), xsize * ysize, f); + if (!rf) { + Log::Write("vergemap: Error layer 0\n"); + return 0; + } + rf = fread(lay1.get(), sizeof(u16), xsize * ysize, f); + if (!rf) { + Log::Write("vergemap: Error layer 1\n"); + return 0; + } + rf = fread(obs.get(), sizeof(u8), xsize * ysize, f); + if (!rf) { + Log::Write("vergemap: Error obstruction layer\n"); + return 0; + } + // copy 16 bit indeces into a 32 bit buffer ScopedArray<uint> layBuffer(new uint[xsize * ysize]); std::copy(lay0.get(), lay0.get() + xsize * ysize, layBuffer.get()); @@ -114,12 +148,16 @@ std::fill(buffer, buffer + 256, 0); std::vector<std::string> chrlist; for (int i = 0; i < 100; i++) { - fread(buffer, 1, 13, f); + rf = fread(buffer, 1, 13, f); chrlist.push_back(std::string(buffer)); } int numEntities = 0; - fread(&numEntities, 1, 4, f); + rf = fread(&numEntities, 1, 4, f); + if (!rf) { + Log::Write("vergemap: Error numEntities\n"); + return 0; + } struct VergeEntity { u16 x; @@ -157,7 +195,7 @@ VergeEntity vergeEnt; Map::Entity ikaEnt; - fread(&vergeEnt, 1, 88, f); // don't ask where the 88 comes from :P + rf = fread(&vergeEnt, 1, 88, f); // don't ask where the 88 comes from :P ikaEnt.label = va("Ent%i", i); ikaEnt.x = vergeEnt.x * 16; ikaEnt.y = vergeEnt.y * 16; @@ -173,7 +211,7 @@ int numMoveScripts = fgetc(f); int thingie = fgetq(f); fseek(f, numMoveScripts, SEEK_CUR); // skip movescripts - fseek(f, thingie, SEEK_CUR); // and other shit (who knows what the hell it is) + fseek(f, thingie, SEEK_CUR); // and other stuff fclose(f); return map; @@ -198,16 +236,32 @@ std::fill(buffer, buffer + 256, 0); - fread(buffer, 1, 6, f); + int rf = fread(buffer, 1, 6, f); + if (!rf) { + Log::Write("vergemap: Error fgetw\n"); + return 0; + } if (std::string(buffer) != mapsig) { throw "Bogus map file"; } fseek(f, 4, SEEK_CUR); - fread(buffer, 1, 60, f); map->tilesetName = buffer; - fread(buffer, 1, 60, f); map->metaData["music"] = buffer; - fread(buffer, 1, 20, f); map->metaData["rstring"] = buffer; + rf = fread(buffer, 1, 60, f); map->tilesetName = buffer; + if (!rf) { + Log::Write("vergemap: Error map->tilesetName\n"); + return 0; + } + rf = fread(buffer, 1, 60, f); map->metaData["music"] = buffer; + if (!rf) { + Log::Write("vergemap: Error map->metaData['music']\n"); + return 0; + } + rf = fread(buffer, 1, 20, f); map->metaData["rstring"] = buffer; + if (!rf) { + Log::Write("vergemap: Error map->metaData['rstring']\n"); + return 0; + } fseek(f, 55, SEEK_CUR); @@ -237,7 +291,7 @@ u32 bufSize = fgetq(f); ScopedArray<u16> buffer(new u16[bufSize]); ScopedArray<u32> data(new u32[width * height]); - fread(buffer.get(), 1, bufSize, f); + rf = fread(buffer.get(), 1, bufSize, f); ReadCompressedLayer2tou32(data.get(), width * height, buffer.get()); Map::Layer* lay = new Map::Layer(va("Layer%i", i), width, height); @@ -264,7 +318,7 @@ u32 bufSize = fgetq(f); ScopedArray<u8> rleBuffer(new u8[bufSize]); ScopedArray<u8> obsData(new u8[width * height]); - fread(rleBuffer.get(), 1, bufSize, f); + rf = fread(rleBuffer.get(), 1, bufSize, f); ReadCompressedLayer1(obsData.get(), width * height, rleBuffer.get()); if (map->NumLayers()) { map->GetLayer(0)->obstructions = Matrix<u8>(width, height, obsData.get()); @@ -290,7 +344,7 @@ int numSprites = fgetc(f); std::vector<std::string> chrList(numSprites); for (int i = 0; i < numSprites; i++) { - fread(buffer, 1, 60, f); + rf = fread(buffer, 1, 60, f); chrList.push_back(buffer); } @@ -341,7 +395,11 @@ fseek(f, 18, SEEK_CUR); // ??? - fread(buffer, 1, 20, f); + rf = fread(buffer, 1, 20, f); + if (!rf) { + Log::Write("vergemap: Error numEntities\n"); + return 0; + } ent.label = buffer; // what the hell map->GetLayer(0)->entities.push_back(ent); @@ -371,7 +429,12 @@ uLong zsize = outSize; ScopedArray<u8> cdata(new u8[compressedSize]); - fread(cdata.get(), 1, compressedSize, f); + int rf = fread(cdata.get(), 1, compressedSize, f); + if (!rf) { + Log::Write("vergemap: Error decompression\n"); + return; + } + int result = uncompress(reinterpret_cast<Bytef*>(dest), &zsize, cdata.get(), compressedSize); if (result != Z_OK) { throw std::runtime_error(va("DecompressVerge3 returned zlib error %i", result)); @@ -406,7 +469,12 @@ char buffer[256]; - fread(buffer, 1, 6, f); + int rf = fread(buffer, 1, 6, f); + if (!rf) { + Log::Write("vergemap: Error reading file\n"); + return 0; + } + if (std::string(buffer) != verge3MapSig) { throw std::runtime_error("Bogus map signature"); } @@ -418,11 +486,11 @@ fseek(f, 4, SEEK_CUR); // skip vc offset - fread(buffer, 1, 256, f); map->title = buffer; - fread(buffer, 1, 256, f); map->tilesetName = buffer; - fread(buffer, 1, 256, f); map->metaData["music"] = buffer; - fread(buffer, 1, 256, f); map->metaData["rstring"] = buffer; - fread(buffer, 1, 256, f); map->metaData["startupscript"] = buffer; + rf = fread(buffer, 1, 256, f); map->title = buffer; + rf = fread(buffer, 1, 256, f); map->tilesetName = buffer; + rf = fread(buffer, 1, 256, f); map->metaData["music"] = buffer; + rf = fread(buffer, 1, 256, f); map->metaData["rstring"] = buffer; + rf = fread(buffer, 1, 256, f); map->metaData["startupscript"] = buffer; map->metaData["startx"] = toString(fgetw(f)); map->metaData["starty"] = toString(fgetw(f)); @@ -430,11 +498,13 @@ int numLayers = fgetq(f); for (int i = 0; i < numLayers; i++) { Map::Layer* lay = new Map::Layer; - fread(buffer, 1, 256, f); lay->label = buffer; + rf = fread(buffer, 1, 256, f); lay->label = buffer; assert(sizeof(double) == 8); // TODO: convert to a fraction somehow. #_# - double parallaxX; fread(¶llaxX, 1, 8, f); - double parallaxY; fread(¶llaxY, 1, 8, f); + double parallaxX; + rf = fread(¶llaxX, 1, 8, f); + double parallaxY; + rf = fread(¶llaxY, 1, 8, f); int width = fgetw(f); int height = fgetw(f); fgetc(f); // lucent @@ -503,7 +573,7 @@ char buffer[256]; std::fill(buffer, buffer + 256, 0); - fread(buffer, 1, 4, f); + int rf = fread(buffer, 1, 4, f); if (std::string(buffer) != VSP_SIGNATURE) { throw std::runtime_error("VSP signature ain't there. This isn't no map."); } @@ -559,7 +629,7 @@ for (int i = 0; i < numAnimStrands; i++) { VSP::AnimState ikaAnim; - fread(buffer, 1, 256, f); // discard strand name + rf = fread(buffer, 1, 256, f); // discard strand name ikaAnim.start = fgetq(f); ikaAnim.finish = fgetq(f); ikaAnim.delay = fgetq(f); Modified: trunk/common/vsp.cpp =================================================================== --- trunk/common/vsp.cpp 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/vsp.cpp 2010-07-21 19:44:46 UTC (rev 726) @@ -6,10 +6,10 @@ #include <cassert> #include <stdio.h> #include "vsp.h" -#include "common/utility.h" +#include "utility.h" #include "rle.h" #include "fileio.h" -#include "common/log.h" +#include "log.h" #include "zlib.h" VSP::VSP() Modified: trunk/common/vsp.h =================================================================== --- trunk/common/vsp.h 2010-07-21 07:43:22 UTC (rev 725) +++ trunk/common/vsp.h 2010-07-21 19:44:46 UTC (rev 726) @@ -1,16 +1,16 @@ /* the Speed Bump's Spiffy VSP class object thingie (tm) Copyright (c) 2000 the Speed Bump - Based on some crap that vecna made way back when. (c) 199x + Based on the vsp code that vecna made way back. (c) 199x - Ihis is my first real attempt to make anything object - oriented, so it may + This is my first real attempt to make anything object - oriented, so it may look icky, but I'm kinda proud of it right now. This has got to be the oldest code chunk I have that I still use. ^_~ --tSB May 2001 - And it sucked! Major revamp. + And it failed! Major revamp. --andy Nov 2001 */ @@ -18,7 +18,7 @@ #pragma once -#include "common/utility.h" +#include "utility.h" #include "Canvas.h" struct VSP { @@ -65,6 +65,10 @@ void SetSize(int w, int h); +private: // just to get the warnings out + int _width, _height; + +public: std::vector<AnimState>& vspAnim; // I see no reason to hide this, really. Canvas& GetTile(uint tileidx); @@ -90,6 +94,6 @@ std::vector<AnimState> _vspanim; - int _width, _height; + }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <slu...@us...> - 2010-09-23 17:52:39
|
Revision: 734 http://ika.svn.sourceforge.net/ika/?rev=734&view=rev Author: sluimers Date: 2010-09-23 17:52:34 +0000 (Thu, 23 Sep 2010) Log Message: ----------- python 3.1 upgrade Modified Paths: -------------- trunk/common/configfile.cpp trunk/common/configfile.h Added Paths: ----------- trunk/common/debug.cpp trunk/common/debug.h Modified: trunk/common/configfile.cpp =================================================================== --- trunk/common/configfile.cpp 2010-09-23 17:51:21 UTC (rev 733) +++ trunk/common/configfile.cpp 2010-09-23 17:52:34 UTC (rev 734) @@ -42,11 +42,14 @@ return i->second; } -int CConfigFile::Int(const std::string& key) -{ +int CConfigFile::Int(const std::string& key) { return atoi((*this)[key].c_str()); } +long long CConfigFile::Long(const std::string& key) { + return atoi((*this)[key].c_str()); +} + void CConfigFile::Load(const char* fname) { File f; Modified: trunk/common/configfile.h =================================================================== --- trunk/common/configfile.h 2010-09-23 17:51:21 UTC (rev 733) +++ trunk/common/configfile.h 2010-09-23 17:52:34 UTC (rev 734) @@ -29,6 +29,7 @@ void Add(const std::string& key, const std::string& value); std::string operator [](const std::string& key); int Int(const std::string& key); + long long Long(const std::string& key); void Load(const char* fname); void Save(const char* fname); Added: trunk/common/debug.cpp =================================================================== --- trunk/common/debug.cpp (rev 0) +++ trunk/common/debug.cpp 2010-09-23 17:52:34 UTC (rev 734) @@ -0,0 +1,7 @@ +#include "debug.h" + +string int2string(const int& number) { + ostringstream oss; + oss << number; + return oss.str(); +} Added: trunk/common/debug.h =================================================================== --- trunk/common/debug.h (rev 0) +++ trunk/common/debug.h 2010-09-23 17:52:34 UTC (rev 734) @@ -0,0 +1,39 @@ +#define DEBUG + +#ifndef DEBUG_H +#define DEBUG_H + +#include <iostream> +#include <string> +#include <sstream> +using namespace std; + +#ifdef DEBUG + +/* just a helper for code location */ +#define PyDEBUGSTR (string("print('debug: ") + __FILE__ + ":" + int2string(__LINE__) + "')").c_str() +#define LOC cout << "debug:" << __FILE__ << ":" << __LINE__ << " "; +#define PyLOC PyRun_SimpleString(PyDEBUGSTR); + +/* macro for general debug print statements. */ +#define DEBUG_PRINT(text) LOC cout << text << endl; + +/* macro that prints a variable name and its actual value */ +#define DEBUG_VAR(text) LOC cout << (#text) << "=" << text << endl; + +/* python macro that prints a variable name and its actual value */ +#define DEBUG_PyRUN(text) PyLOC PyRun_SimpleString(text); + +/* python macro that prints an error */ +#define DEBUG_PyERR(type, text) PyLOC PyErr_SetString(type, text); + +#else + +/* when debug isn't defined all the macro calls do absolutely nothing for C++ debugging code and the same without helper for python debugging code */ +#define DEBUG_PRINT(text) +#define DEBUG_VAR(text) +#define DEBUG_PyRUN(text) +#define DEBUG_PyERR(type, text) PyErr_SetString(type, text); + +#endif /* DEBUG */ +#endif /* DEBUG_H */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <slu...@us...> - 2010-09-23 19:56:15
|
Revision: 736 http://ika.svn.sourceforge.net/ika/?rev=736&view=rev Author: sluimers Date: 2010-09-23 19:56:09 +0000 (Thu, 23 Sep 2010) Log Message: ----------- edited debugging file Modified Paths: -------------- trunk/common/debug.cpp trunk/common/debug.h Modified: trunk/common/debug.cpp =================================================================== --- trunk/common/debug.cpp 2010-09-23 17:52:55 UTC (rev 735) +++ trunk/common/debug.cpp 2010-09-23 19:56:09 UTC (rev 736) @@ -1,7 +1,7 @@ #include "debug.h" -string int2string(const int& number) { - ostringstream oss; +std::string int2string(const int& number) { + std::ostringstream oss; oss << number; return oss.str(); } Modified: trunk/common/debug.h =================================================================== --- trunk/common/debug.h 2010-09-23 17:52:55 UTC (rev 735) +++ trunk/common/debug.h 2010-09-23 19:56:09 UTC (rev 736) @@ -1,4 +1,4 @@ -#define DEBUG +//#define DEBUG #ifndef DEBUG_H #define DEBUG_H @@ -6,20 +6,21 @@ #include <iostream> #include <string> #include <sstream> -using namespace std; #ifdef DEBUG +std::string int2string(const int& number); + /* just a helper for code location */ -#define PyDEBUGSTR (string("print('debug: ") + __FILE__ + ":" + int2string(__LINE__) + "')").c_str() -#define LOC cout << "debug:" << __FILE__ << ":" << __LINE__ << " "; +#define PyDEBUGSTR (std::string("print('debug: ") + __FILE__ + ":" + int2string(__LINE__) + "')").c_str() +#define LOC std::cout << "debug:" << __FILE__ << ":" << __LINE__ << " "; #define PyLOC PyRun_SimpleString(PyDEBUGSTR); /* macro for general debug print statements. */ -#define DEBUG_PRINT(text) LOC cout << text << endl; +#define DEBUG_PRINT(text) LOC std::cout << text << endl; /* macro that prints a variable name and its actual value */ -#define DEBUG_VAR(text) LOC cout << (#text) << "=" << text << endl; +#define DEBUG_VAR(text) LOC std::cout << (#text) << "=" << text << endl; /* python macro that prints a variable name and its actual value */ #define DEBUG_PyRUN(text) PyLOC PyRun_SimpleString(text); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <slu...@us...> - 2010-09-26 16:40:51
|
Revision: 742 http://ika.svn.sourceforge.net/ika/?rev=742&view=rev Author: sluimers Date: 2010-09-26 16:40:45 +0000 (Sun, 26 Sep 2010) Log Message: ----------- vsp changes Modified Paths: -------------- trunk/common/vsp.cpp trunk/common/vsp.h Modified: trunk/common/vsp.cpp =================================================================== --- trunk/common/vsp.cpp 2010-09-26 11:49:00 UTC (rev 741) +++ trunk/common/vsp.cpp 2010-09-26 16:40:45 UTC (rev 742) @@ -4,14 +4,25 @@ #endif #include <cassert> +#include <cstdlib> +#include <fstream> +#include <stdexcept> #include <stdio.h> +#include "aries.h" +#include "base64.h" +#include "compression.h" #include "vsp.h" -#include "utility.h" +#include "common/utility.h" #include "rle.h" #include "fileio.h" -#include "log.h" +#include "common/log.h" #include "zlib.h" +using aries::NodeList; +using aries::DataNodeList; +using aries::DataNode; +using aries::newNode; + VSP::VSP() : _width(0) , _height(0) @@ -40,6 +51,8 @@ name = fileName; + bool newVersion = false; + u16 ver; f.Read(&ver, 2); switch(ver) { @@ -90,7 +103,7 @@ ScopedArray<u16> data16(new u16[numTiles * _width * _height]); - f.Read(data16.get(), numTiles * _width * _height * 2); + f.Read(data16.get(), numTiles * _width * _height * 2); CreateTilesFromBuffer(data16.get(), numTiles, _width, _height); @@ -171,21 +184,133 @@ break; } + case 26920: { //first two bytes == "(i". + //The tileset WILL NOT LOAD if this is not the case (and if it's not an old VSP. + f.Close(); //close file and restart the process from the beginning. + newVersion = true; + try { + if (!fileName.length()) { + throw std::runtime_error("VSP::Load: No filename given."); + } + + std::ifstream file; + file.open(fileName.c_str()); + if (!file.is_open()) { + throw std::runtime_error(va("VSP::Load: %s does not exist.", fileName.c_str())); + } + + DataNode* document; + file >> document; + file.close(); + + DataNode* rootNode = document->getChild("ika-tileset"); + + std::string version = rootNode->getChild("version")->getString(); + + if (version == "1.0") { + Log::Write( + "Warning: v%s ika-tileset being loaded.\n", + version.c_str(), + fileName.c_str() + ); + + } + else { + Log::Write( + "Warning: Unknown ika-tileset version %s in %s! Expecting\n" + " 1.0. Trying to load it anyway.", + version.c_str(), fileName.c_str() + ); + } + + { + DataNode* infoNode = rootNode->getChild("information"); + + { + DataNode* metaNode = infoNode->getChild("meta"); + + NodeList nodes = metaNode->getChildren(); + for (NodeList::iterator iter = nodes.begin(); iter != nodes.end(); iter++) { + if ((*iter)->isString()) { + continue; + } + + DataNode* n = static_cast<DataNode*>(*iter); + + if (n->getString().empty()) { + metaData[n->getName()] = n->getString(); + } + } + + name = infoNode->getChild("title")->getString(); + } + } + + { + //DataNode* animationNode = rootNode->getChild("animations"); + + //I'll need to know a little more about the animations part of ika-tileset to complete this + } + + { + DataNode* tileNode = rootNode->getChild("tiles"); + + numTiles = (int)std::atoi(tileNode->getChild("count")->getString().c_str()); + + DataNode* dimNode = tileNode->getChild("dimensions"); + _width = std::atoi(dimNode->getChild("width")->getString().c_str()); + _height = std::atoi(dimNode->getChild("height")->getString().c_str()); + + DataNode* dataNode = tileNode->getChild("data"); + if (dataNode->getChild("format")->getString() != "zlib") { + throw std::runtime_error("Unsupported data format"); + } + + std::string d64 = dataNode->getString(); + ScopedArray<u8> compressed(new u8[d64.length()]); // way more than enough. + uint compressedSize; + + std::string un64 = base64::decode(d64); + std::copy((u8*)(un64.c_str()), (u8*)(un64.c_str() + un64.length()), compressed.get()); + compressedSize = un64.length(); + + ScopedArray<u8> pixels(new u8[_width * _height * numTiles * sizeof(RGBA)]); + Compression::decompress(compressed.get(), compressedSize, pixels.get(), _width * _height * numTiles * sizeof(RGBA)); + + tiles.clear(); + tiles.reserve(numTiles); + RGBA* ptr = (RGBA*)pixels.get(); + for (uint i = 0; i < (uint)numTiles; i++) { + tiles.push_back(Canvas(ptr, _width, _height)); + ptr += _width * _height; + } + } + + delete rootNode; + } + catch (std::runtime_error error) { + Log::Write("VSP::Load(\"%s\"): %s", fileName.c_str(), error.what()); + throw error; + } + break; + } default: { Log::Write("Fatal error: unknown VSP version (%d)", ver); return false; } } - for (int j = 0; j < 100; j++) { - f.Read(&_vspanim[j].start, 2); - f.Read(&_vspanim[j].finish, 2); - f.Read(&_vspanim[j].delay, 2); - f.Read(&_vspanim[j].mode, 2); - } + if (!newVersion) + { + for (int j = 0; j < 100; j++) { + f.Read(&_vspanim[j].start, 2); + f.Read(&_vspanim[j].finish, 2); + f.Read(&_vspanim[j].delay, 2); + f.Read(&_vspanim[j].mode, 2); + } + f.Close(); + } - f.Close(); - return true; } @@ -203,8 +328,8 @@ // copy all the tile data into one big long buffer that we can write to disk for (uint j = 0; j < tiles.size(); j++) { memcpy( - tileBuffer.get() + (j * _width * _height), - tiles[j].GetPixels(), + tileBuffer.get() + (j * _width * _height), + tiles[j].GetPixels(), _width * _height * sizeof(RGBA) ); } Modified: trunk/common/vsp.h =================================================================== --- trunk/common/vsp.h 2010-09-26 11:49:00 UTC (rev 741) +++ trunk/common/vsp.h 2010-09-26 16:40:45 UTC (rev 742) @@ -1,16 +1,16 @@ -/* +/* the Speed Bump's Spiffy VSP class object thingie (tm) Copyright (c) 2000 the Speed Bump - Based on the vsp code that vecna made way back. (c) 199x + Based on some crap that vecna made way back when. (c) 199x - This is my first real attempt to make anything object - oriented, so it may + Ihis is my first real attempt to make anything object - oriented, so it may look icky, but I'm kinda proud of it right now. - + This has got to be the oldest code chunk I have that I still use. ^_~ --tSB May 2001 - - And it failed! Major revamp. + + And it sucked! Major revamp. --andy Nov 2001 */ @@ -18,7 +18,8 @@ #pragma once -#include "utility.h" +#include <map> +#include "common/utility.h" #include "Canvas.h" struct VSP { @@ -38,7 +39,7 @@ int count; - AnimState() + AnimState() : start(0) , finish(0) , delay(0) @@ -47,9 +48,12 @@ {} }; + typedef std::map<std::string, std::string> StringMap; + StringMap metaData; ///< Authoring information and the like. + VSP(); VSP(const std::string& fname); - + bool Load(const std::string& fname); int Save(const std::string& fname); void Free(); @@ -62,13 +66,9 @@ void CopyTile(Canvas& tb, uint pos); // Copies the tile into a buffer. void PasteTile(const Canvas& tb, uint pos); // pastes the tile from a buffer void TPasteTile(Canvas& tb, uint pos); // transparently pastes the tile from a buffer - + void SetSize(int w, int h); - -private: // just to get the warnings out - int _width, _height; -public: std::vector<AnimState>& vspAnim; // I see no reason to hide this, really. Canvas& GetTile(uint tileidx); @@ -76,9 +76,9 @@ inline int Width() const { return _width; } inline int Height() const { return _height; } inline uint NumTiles() const { return tiles.size(); } - + inline const std::string& Name() const { return name; } - + private: VSP(VSP& v); VSP& operator =(VSP& rhs); @@ -88,12 +88,12 @@ void CreateTilesFromBuffer(RGBA* data, uint numtiles, int tilex, int tiley); std::vector<Canvas> tiles; // tile images - + std::string desc; std::string name; // the VSPs filename - + std::vector<AnimState> _vspanim; - - + + int _width, _height; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |