[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[netPanzer-CVS] netpanzer/src ChangeLog Lib/Exception.hpp Lib/F...
From: |
Matthias Braun |
Subject: |
[netPanzer-CVS] netpanzer/src ChangeLog Lib/Exception.hpp Lib/F... |
Date: |
Fri, 12 Sep 2003 10:12:46 -0400 |
CVSROOT: /cvsroot/netpanzer
Module name: netpanzer
Branch:
Changes by: Matthias Braun <address@hidden> 03/09/12 10:12:45
Modified files:
src : ChangeLog
src/Lib : Exception.hpp FileSystem.cpp FileSystem.hpp
src/Lib/2D : ColorTable.cpp ColorTable.hpp PackedSurface.cpp
Palette.cpp RGBColor.hpp
src/Lib/Interfaces: UtilInterface.hpp
src/NetPanzer/Classes/Weapons: Weapon.cpp
src/NetPanzer/Core: main.cpp
src/NetPanzer/Interfaces: GameManager.cpp
src/NetPanzer/Views/MainMenu/Multi: FlagSelectionView.cpp
src/UILib/SDL : SDLSound.cpp
Log message:
use physfs for the colortable cache
Patches:
Index: netpanzer/src/ChangeLog
diff -u netpanzer/src/ChangeLog:1.17 netpanzer/src/ChangeLog:1.18
--- netpanzer/src/ChangeLog:1.17 Thu Sep 11 13:35:46 2003
+++ netpanzer/src/ChangeLog Fri Sep 12 10:12:45 2003
@@ -1,3 +1,6 @@
+12-Sep-2003 by Matze Braun
+-use the physfs for the colortable cache now
+
11-Sep-2003 by Matze Braun
-removed more win32 specific code
-removed #ifdef USE_SDLs, the code is enabled by default now
Index: netpanzer/src/Lib/2D/ColorTable.cpp
diff -u netpanzer/src/Lib/2D/ColorTable.cpp:1.10
netpanzer/src/Lib/2D/ColorTable.cpp:1.11
--- netpanzer/src/Lib/2D/ColorTable.cpp:1.10 Wed Sep 10 07:26:06 2003
+++ netpanzer/src/Lib/2D/ColorTable.cpp Fri Sep 12 10:12:45 2003
@@ -18,6 +18,7 @@
#include <config.h>
#include "SplitPath.hpp"
+#include "FileSystem.hpp"
#include "Log.hpp"
#include "Exception.hpp"
#include "ColorTable.hpp"
@@ -109,50 +110,56 @@
const
int &brightness)
{
assert(brightness > 0 && brightness <= 256);
-
init(256 * 256);
- // Check to see if the color table file exists, if so, load it.
- if (isValid(filename))
- {
- loadTableError(filename);
-
- } else
- {
- // Since the file was not found, create the color tables and
dump
- // it to a file.
- int curOffset;
- int curRed;
- int curGreen;
- int curBlue;
- float nb; // The new brightness color.
+ if(FileSystem::exists(filename)) {
+ try {
+ loadTable(filename);
+ return;
+ } catch(Exception e) {
+ LOG( ("Error while loading palette '%s': %s", filename,
e.getMessage(),
+ e.getMessage()) );
+ }
+ }
+
+ LOG ( ("Creating ColorTable '%s'.", filename) );
+ // Since the file was not found, create the color tables and dump
+ // it to a file.
+ int curOffset;
+ int curRed;
+ int curGreen;
+ int curBlue;
+ float nb; // The new brightness color.
- float fBrightness = float(brightness) / 256.0f;
+ float fBrightness = float(brightness) / 256.0f;
- for (int y = 0; y < 256; y++)
+ for (int y = 0; y < 256; y++)
+ {
+ for (int x = 0; x < 256; x++)
{
- for (int x = 0; x < 256; x++)
- {
- nb = float(x) * fBrightness;
- curOffset = (y * 256) + x;
+ nb = float(x) * fBrightness;
+ curOffset = (y * 256) + x;
- // !SOMDEDAY! Try holding a threshold when any
value gets to 255.
- curRed = (int) (nb + Palette::color[y].red);
- curGreen = (int) (nb + Palette::color[y].green);
- curBlue = (int) (nb + Palette::color[y].blue);
-
- if (curRed > 255) curRed = 255;
- if (curGreen > 255) curGreen = 255;
- if (curBlue > 255) curBlue = 255;
- //curColor = Palette::color[y];
+ // !SOMDEDAY! Try holding a threshold when any value
gets to 255.
+ curRed = (int) (nb + Palette::color[y].red);
+ curGreen = (int) (nb + Palette::color[y].green);
+ curBlue = (int) (nb + Palette::color[y].blue);
+
+ if (curRed > 255) curRed = 255;
+ if (curGreen > 255) curGreen = 255;
+ if (curBlue > 255) curBlue = 255;
+ //curColor = Palette::color[y];
- setColor(curOffset,
Palette::findNearestColor(RGBColor(curRed, curGreen, curBlue)));
- }
+ setColor(curOffset,
Palette::findNearestColor(RGBColor(curRed, curGreen, curBlue)));
}
-
- saveTableError(filename);
}
+ try {
+ saveTable(filename);
+ } catch(Exception e) {
+ LOG ( ("Caching of ColorTable '%s' failed: %s", filename,
+ e.getMessage()) );
+ }
} // end createBrightenFilter
// createDarkenFilter
@@ -161,39 +168,45 @@
{
init(256 * 256);
- // Check to see if the color table file exists, if so, load it.
- if (isValid(filename))
- {
- loadTableError(filename);
+ if(FileSystem::exists(filename)) {
+ try {
+ loadTable(filename);
+ return;
+ } catch(Exception e) {
+ LOG( ("Error while loading palette'%s': %s", filename,
e.getMessage()) );
+ }
+ }
- } else
- {
- // Since the file was not found, create the color tables and
dump
- // it to a file.
- float curPercent;
- int curOffset;
- RGBColor col;
- RGBColor curColor;
- const float percent = fudgeValue;
+ LOG ( ("Creating colortable '%s'.", filename) );
+ // Since the file was not found, create the color tables and dump
+ // it to a file.
+ float curPercent;
+ int curOffset;
+ RGBColor col;
+ RGBColor curColor;
+ const float percent = fudgeValue;
- for (int y = 0; y < 256; y++)
+ for (int y = 0; y < 256; y++)
+ {
+ for (int x = 0; x < 256; x++)
{
- for (int x = 0; x < 256; x++)
- {
- curPercent = (float(255 - x) / 255.0f) *
percent + 1.0f - percent;
- curOffset = (y * 256) + x;
+ curPercent = (float(255 - x) / 255.0f) * percent + 1.0f
- percent;
+ curOffset = (y * 256) + x;
- curColor.red = (BYTE) (curPercent *
float(Palette::color[y].red));
- curColor.green = (BYTE) (curPercent *
float(Palette::color[y].green));
- curColor.blue = (BYTE) (curPercent *
float(Palette::color[y].blue));
+ curColor.red = (BYTE) (curPercent *
float(Palette::color[y].red));
+ curColor.green = (BYTE) (curPercent *
float(Palette::color[y].green));
+ curColor.blue = (BYTE) (curPercent *
float(Palette::color[y].blue));
- setColor(curOffset,
Palette::findNearestColor(curColor));
- }
+ setColor(curOffset,
Palette::findNearestColor(curColor));
}
-
- saveTableError(filename);
}
-
+
+ try {
+ saveTable(filename);
+ } catch(Exception e) {
+ LOG ( ("Caching of ColorTable '%s' failed: %s", filename,
+ e.getMessage()) );
+ }
} // end createDarkenFilter
// create
@@ -205,223 +218,111 @@
{
init(256 * 256);
- // Check to see if the color table file exists, if so, load it.
- if (isValid(filename))
- {
- loadTableError(filename);
+ if(FileSystem::exists(filename)) {
+ try {
+ loadTable(filename);
+ return;
+ } catch(Exception e) {
+ LOG( ("Error while loading palette'%s': %s", filename,
e.getMessage()) );
+ }
+ }
+
+ LOG ( ("Creating colortable '%s'.", filename) );
+ //float curPercent;
+ //int totalColors = colorCount;
+ //int curColorIndex = 0;
+ //int num = 0;
+ //int numInterval = (totalColors) / 100;
+
+ // Since the file was not found, create the color tables and dump
+ // it to a file.
+ unsigned curOffset = 0;
- } else
+ for (unsigned index = 0; index < 256; index++)
{
- //float curPercent;
- //int totalColors = colorCount;
- //int curColorIndex = 0;
- //int num = 0;
- //int numInterval = (totalColors) / 100;
-
- char strBuf[256];
+ float color1 = float(color1Percent) / 100.0f;
+ float color2 = float(color2Percent) / 100.0f;
+ const RGBColor col = Palette::color[index];
- sprintf(strBuf, " %s: progress: 0%%", filename);
- //progressView->scrollAndUpdate(strBuf);
+ for (unsigned indexPic = 0; indexPic < 256; indexPic++)
+ {
+ const RGBColor colPic = Palette::color[indexPic];
- // Since the file was not found, create the color tables and
dump
- // it to a file.
- unsigned curOffset = 0;
+ curOffset = (int(index) << 8) + indexPic;
- for (unsigned index = 0; index < 256; index++)
- {
- float color1 = float(color1Percent) / 100.0f;
- float color2 = float(color2Percent) / 100.0f;
- const RGBColor col = Palette::color[index];
+ RGBColor curColor((BYTE) (color1 * col.red + color2 *
colPic.red),
+ (BYTE) (color1 *
col.green + color2 * colPic.green),
+ (BYTE) (color1 *
col.blue + color2 * colPic.blue));
- for (unsigned indexPic = 0; indexPic < 256; indexPic++)
+ // Makes the color table use color 0 as transparent.
+ if (indexPic == 0)
{
- const RGBColor colPic =
Palette::color[indexPic];
-
- curOffset = (int(index) << 8) + indexPic;
+ setColor(curOffset, index);
- RGBColor curColor((BYTE) (color1 * col.red +
color2 * colPic.red),
- (BYTE)
(color1 * col.green + color2 * colPic.green),
- (BYTE)
(color1 * col.blue + color2 * colPic.blue));
-
- // Makes the color table use color 0 as
transparent.
- if (indexPic == 0)
- {
- setColor(curOffset, index);
-
- } else
- {
- setColor(curOffset,
Palette::findNearestColor(curColor));
- }
-
- // Display a progress update every 1%.
- /*if (num > numInterval)
- {
- curColorIndex += numInterval;
- curPercent = float(curColorIndex) /
float(totalColors);
- //sprintf(strBuf, " %s: progress:
%d%%", filename, int(curPercent * 100));
- //progressView->update(strBuf);
- num = 0;
- } else num++;
- */
+ } else
+ {
+ setColor(curOffset,
Palette::findNearestColor(curColor));
}
- }
-
- sprintf(strBuf, " %s: progress: 100%%", filename);
- //progressView->update(strBuf);
- saveTableError(filename);
+ // Display a progress update every 1%.
+ /*if (num > numInterval)
+ {
+ curColorIndex += numInterval;
+ curPercent = float(curColorIndex) /
float(totalColors);
+ num = 0;
+ } else num++;
+ */
+ }
}
-} // end ColorTable::create
-
-// getDiskName
-//---------------------------------------------------------------------------
-void ColorTable::getDiskName(char *destname, const char *filename) const
-{
- char paletteFilename[256];
- char tablePath[256];
- char tableFilename[256];
-
- _splitpath(Palette::getName(), 0, 0, paletteFilename, 0);
- _splitpath(filename, 0, tablePath, tableFilename, 0);
-
- // This is dangerous, so make sure the filename can handle the length
of the possible
- // sprintf.
- sprintf(destname, "%s%s%s%s", tablePath, tableFilename,
paletteFilename, extension);
-
- return;
-
-} // end ColorTable::getDiskName
-
-// loadTableError
-//---------------------------------------------------------------------------
-void ColorTable::loadTableError(const char *filename)
-{
try {
- loadTable(filename);
+ saveTable(filename);
} catch(Exception e) {
- LOG( ("Error while loading Color Table: %s", e.getMessage()) );
- throw Exception("ERROR: Unable to load %s", filename);
- }
-} // end ColorTable::loadTableError
+ LOG ( ("Caching of ColorTable '%s' failed: %s", filename,
+ e.getMessage()) );
+ }
+} // end ColorTable::create
// loadTable
//---------------------------------------------------------------------------
void ColorTable::loadTable(const char *filename)
{
- char strBuf[768];
+ ReadFile *file = FileSystem::openRead(filename);
- getDiskName(strBuf, filename);
-
- FILE *fp = fopen(strBuf, "rb");
- if (fp == 0)
- throw Exception("Couldn't load colortable %s('%s').", strBuf);
-
- loadTable(fp);
-
- fclose(fp);
-} // end ColorTable::loadTable
-
-// loadTable
-//---------------------------------------------------------------------------
-void ColorTable::loadTable(FILE *fp)
-{
- assert(fp != 0);
-
- char strBuf[768];
-
- // Bypass the palette info.
- fread(strBuf, 768, 1, fp);
+ // make sure palette in file is the same as current one
+ for(size_t i=0; i<PALETTE_LENGTH; i++) {
+ RGBColor checkcolor;
+ if(file->read(&checkcolor, sizeof(BYTE), 3) != 3)
+ throw Exception("couldn't load colortable '%s': "
+ "file corrupted(too
short)", filename);
+
+ if(Palette::originalColor[i] != checkcolor)
+ throw Exception("couldn't load colortable '%s': "
+ "palettes don't match",
filename);
+ }
+
+ // put the color table data into the colorArray
+ if(file->read(colorArray, colorCount, 1) != 1)
+ throw Exception("couldn't load colortable '%s': "
+ "file corrupted(too short)",
filename);
- // Put the color table data into the colorArray.
- fread(colorArray, colorCount, 1, fp);
+ delete file;
} // end ColorTable::loadTable
-// saveTableError
-//---------------------------------------------------------------------------
-void ColorTable::saveTableError(const char *filename) const
-{
- try {
- saveTable(filename);
- } catch(Exception e) {
- printf("Exception while saving colortable: '%s'.\n",
e.getMessage());
- throw Exception("Couldn't save color table '%s'.", filename);
- }
-} // end ColorTable::saveTableError
-
// saveTable
//---------------------------------------------------------------------------
void ColorTable::saveTable(const char *filename) const
{
- char strBuf[768];
-
- getDiskName(strBuf, filename);
-
- FILE *fp = fopen(strBuf, "wb");
- if (fp == 0)
- throw Exception("couldn't save colortable to '%s'.", strBuf);
-
- saveTable(fp);
-
- fclose(fp);
-} // end ColorTable::saveTable
-
-// saveTable
-//---------------------------------------------------------------------------
-void ColorTable::saveTable(FILE *fp) const
-{
- assert(fp != 0);
-
- // Dump the colorTable source palette.
- fwrite(&Palette::color, 768, sizeof(BYTE), fp);
-
- // Dump the colorTable data.
- fwrite(colorArray, colorCount, sizeof(BYTE), fp);
-} // end ColorTable::saveTable
-
-// isValid
-//---------------------------------------------------------------------------
-// Purpose: Makes sure the table on disk has the correct number of colors
-// plus the palette data of the associated palette.
-//---------------------------------------------------------------------------
-bool ColorTable::isValid(const char *filename) const
-{
- char strBuf[768];
-
- getDiskName(strBuf, filename);
-
- if (UtilInterface::getFileSize(strBuf) == (size_t) (colorCount + 768))
- {
- // Check and make sure the file palette matches the loaded
palette.
- FILE *fp = fopen(strBuf, "rb");
- if (fp == 0) { return false; }
-
- RGBColor checkPal[PALETTE_LENGTH];
-
- for (size_t i = 0; i < PALETTE_LENGTH; i++)
- {
- fread(&checkPal[i], 3, sizeof(BYTE), fp);
- }
-
- fclose(fp);
-
- for (size_t j = 0; j < PALETTE_LENGTH; j++)
- {
- if (Palette::originalColor[j].red != checkPal[j].red ||
- Palette::originalColor[j].green !=
checkPal[j].green ||
- Palette::originalColor[j].blue !=
checkPal[j].blue)
- {
- return false;
- }
- }
+ WriteFile *file = FileSystem::openWrite(filename);
- return true;
+ if (file->write(&Palette::color, 768, 1) != 1
+ || file->write(colorArray, colorCount, 1) != 1) {
+ throw Exception("error while writing to file '%s' (disk full?)",
+ filename);
}
- return false;
-
-} // end ColorTable::isValid
-
+ delete file;
+} // end ColorTable::saveTable
// createTrans0
//---------------------------------------------------------------------------
@@ -432,54 +333,60 @@
{
init(256 * 256);
- // Check to see if the color table file exists, if so, load it.
- if (isValid(filename))
- {
- loadTableError(filename);
+ if(FileSystem::exists(filename)) {
+ try {
+ loadTable(filename);
+ return;
+ } catch(Exception e) {
+ LOG( ("Error while loading palette'%s': %s", filename,
e.getMessage()) );
+ }
+ }
+
+ LOG ( ("Creating colortable '%s'.", filename) );
+ float color1 = float(color1Percent) / 100.0f;
+ float color2 = float(color2Percent) / 100.0f;
+ //int totalColors = colorCount;
+ //int curColorIndex = 0;
+ //int num = 0;
+ //int numInterval = (totalColors) / 100;
+
+ // Since the file was not found, create the color tables and dump
+ // it to a file.
+ unsigned curOffset = 0;
- } else
+ for (unsigned index = 0; index < 256; index++)
{
- float color1 = float(color1Percent) / 100.0f;
- float color2 = float(color2Percent) / 100.0f;
- //int totalColors = colorCount;
- //int curColorIndex = 0;
- //int num = 0;
- //int numInterval = (totalColors) / 100;
-
- // Since the file was not found, create the color tables and
dump
- // it to a file.
- unsigned curOffset = 0;
+ const RGBColor col = Palette::color[index];
- for (unsigned index = 0; index < 256; index++)
+ for (unsigned indexPic = 0; indexPic < 256; indexPic++)
{
- const RGBColor col = Palette::color[index];
+ const RGBColor colPic = Palette::color[indexPic];
- for (unsigned indexPic = 0; indexPic < 256; indexPic++)
- {
- const RGBColor colPic =
Palette::color[indexPic];
-
- curOffset = (int(index) << 8) + indexPic;
+ curOffset = (int(index) << 8) + indexPic;
- RGBColor curColor((int) (color1 * col.red +
color2 * colPic.red),
- (int) (color1
* col.green + color2 * colPic.green),
- (int) (color1
* col.blue + color2 * colPic.blue));
+ RGBColor curColor((int) (color1 * col.red + color2 *
colPic.red),
+ (int) (color1 *
col.green + color2 * colPic.green),
+ (int) (color1 *
col.blue + color2 * colPic.blue));
- // Makes the color table use color 0 as
transparent.
+ // Makes the color table use color 0 as transparent.
- if (indexPic == 0)
- {
- setColor(curOffset, index);
- } else
- {
+ if (indexPic == 0)
+ {
+ setColor(curOffset, index);
+ } else
+ {
- setColor(curOffset,
Palette::findNearestColor(curColor));
- }
+ setColor(curOffset,
Palette::findNearestColor(curColor));
}
}
-
- saveTableError(filename);
}
-
+
+ try {
+ saveTable(filename);
+ } catch(Exception e) {
+ LOG ( ("Caching of ColorTable '%s' failed: %s",
+ filename, e.getMessage()) );
+ }
} // end ColorTable::createTrans0
// lightDark table builder logic.
@@ -495,40 +402,48 @@
{
init(256 * 256);
- if (isValid(filename))
- {
- loadTableError(filename);
+ if(FileSystem::exists(filename)) {
+ try {
+ loadTable(filename);
+ return;
+ } catch(Exception e) {
+ LOG( ("Error while loading palette'%s': %s", filename,
e.getMessage()) );
+ }
+ }
- } else
- {
- int curOffset;
- int curRed;
- int curGreen;
- int curBlue;
+ LOG ( ("Creating colortable '%s'.", filename) );
+
+ int curOffset;
+ int curRed;
+ int curGreen;
+ int curBlue;
- for (int y = 0; y < 256; y++)
+ for (int y = 0; y < 256; y++)
+ {
+ int x;
+ for (x = 0; x <= 128; x++)
{
- int x;
- for (x = 0; x <= 128; x++)
- {
- curOffset = x + (y << 8);
- curRed = Palette::color[y].red * x / 128;
- curGreen = Palette::color[y].green * x / 128;
- curBlue = Palette::color[y].blue * x / 128;
+ curOffset = x + (y << 8);
+ curRed = Palette::color[y].red * x / 128;
+ curGreen = Palette::color[y].green * x / 128;
+ curBlue = Palette::color[y].blue * x / 128;
- setColor(curOffset,
Palette::findNearestColor(RGBColor(curRed, curGreen, curBlue)));
- }
- for (x = 129; x < 256; x++)
- {
- curOffset = x + (y << 8);
- curRed = Palette::color[y].red + ((255 -
Palette::color[y].red) * (x-128) / 127);
- curGreen = Palette::color[y].green + ((255 -
Palette::color[y].green) * (x-128) / 127);
- curBlue = Palette::color[y].blue + ((255 -
Palette::color[y].blue) * (x-128) / 127);
-
- setColor(curOffset,
Palette::findNearestColor(RGBColor(curRed, curGreen, curBlue)));
- }
+ setColor(curOffset,
Palette::findNearestColor(RGBColor(curRed, curGreen, curBlue)));
}
+ for (x = 129; x < 256; x++)
+ {
+ curOffset = x + (y << 8);
+ curRed = Palette::color[y].red + ((255 -
Palette::color[y].red) * (x-128) / 127);
+ curGreen = Palette::color[y].green + ((255 -
Palette::color[y].green) * (x-128) / 127);
+ curBlue = Palette::color[y].blue + ((255 -
Palette::color[y].blue) * (x-128) / 127);
- saveTableError(filename);
+ setColor(curOffset,
Palette::findNearestColor(RGBColor(curRed, curGreen, curBlue)));
+ }
}
+
+ try {
+ saveTable(filename);
+ } catch(Exception e) {
+ LOG ( ("Caching of ColorTable '%s' failed: %s", filename,
e.getMessage()) );
+ }
} // end ColorTable::createLightDarkFilter
Index: netpanzer/src/Lib/2D/ColorTable.hpp
diff -u netpanzer/src/Lib/2D/ColorTable.hpp:1.4
netpanzer/src/Lib/2D/ColorTable.hpp:1.5
--- netpanzer/src/Lib/2D/ColorTable.hpp:1.4 Sat Sep 6 11:48:10 2003
+++ netpanzer/src/Lib/2D/ColorTable.hpp Fri Sep 12 10:12:45 2003
@@ -63,22 +63,11 @@
void createDarkenFilter(const char *filename, float fudgeValue);
void createLightDarkFilter(const char *filename);
- void loadTableError(const char *filename);
void loadTable(const char *filename);
- void loadTable(FILE *fp);
-
- void saveTableError(const char *filename) const;
void saveTable(const char *filename) const;
- void saveTable(FILE *fp) const;
-
- bool isValid(const char *filename) const;
-
- // Gets the name of the filename + palettename + extension.
- void getDiskName(char *destname, const char *filename) const;
private:
void free();
-
}; // end ColorTable
#endif // end __ColorTable_hpp__
Index: netpanzer/src/Lib/2D/PackedSurface.cpp
diff -u netpanzer/src/Lib/2D/PackedSurface.cpp:1.7
netpanzer/src/Lib/2D/PackedSurface.cpp:1.8
--- netpanzer/src/Lib/2D/PackedSurface.cpp:1.7 Tue Sep 9 13:16:12 2003
+++ netpanzer/src/Lib/2D/PackedSurface.cpp Fri Sep 12 10:12:45 2003
@@ -216,7 +216,7 @@
throw Exception("Invalid PAK file version: %d", version);
}
if (version > CURRENT_PAK_VERSION) {
- throw Exception("PAK file version %d is newer than the .exe you
are using, which only supports up to version", version, CURRENT_PAK_VERSION);
+ throw Exception("PAK file version %d is newer than the .exe
(%d) you are using, which only supports up to version", version,
CURRENT_PAK_VERSION);
}
fread(&pix, sizeof(pix), 1, f);
Index: netpanzer/src/Lib/2D/Palette.cpp
diff -u netpanzer/src/Lib/2D/Palette.cpp:1.7
netpanzer/src/Lib/2D/Palette.cpp:1.8
--- netpanzer/src/Lib/2D/Palette.cpp:1.7 Mon Sep 8 12:20:41 2003
+++ netpanzer/src/Lib/2D/Palette.cpp Fri Sep 12 10:12:45 2003
@@ -19,6 +19,7 @@
#include "Palette.hpp"
#include "FileUtil.hpp"
+#include "FileSystem.hpp"
#include "Exception.hpp"
#include "UtilInterface.hpp"
@@ -304,29 +305,25 @@
}
}
- FileUtil::mkdir("pics");
- FileUtil::mkdir("pics/colorFilters");
-
- char strBuf[256];
- char tablePath[] = "pics/colorFilters/";
-
+ char tablePath[512];
+ snprintf(tablePath, 512, "cache/colorfilters/%s", getName());
+ if(!FileSystem::exists(tablePath)) {
+ FileSystem::mkdir(tablePath);
+ }
+ char strBuf[512];
//progressView->scrollAndUpdate("");
// Best color match.
- //progressView->update(" col2575.tbl");
- sprintf(strBuf, "%s2080", tablePath);
+ sprintf(strBuf, "%s/2080.tbl", tablePath);
colorTable2080.create(20, 80, strBuf);
- //progressView->update(" col5050.tbl");
- sprintf(strBuf, "%s4060", tablePath);
+ sprintf(strBuf, "%s/4060.tbl", tablePath);
colorTable4060.create(40, 60, strBuf);
- //progressView->update(" col7525.tbl");
- sprintf(strBuf, "%s6040", tablePath);
+ sprintf(strBuf, "%s/6040.tbl", tablePath);
colorTable6040.create(60, 40, strBuf);
- //progressView->update(" col7525.tbl");
- sprintf(strBuf, "%s8020", tablePath);
+ sprintf(strBuf, "%s/8020.tbl", tablePath);
colorTable8020.create(80, 20, strBuf);
//sprintf(strBuf, "%sSolidTrans0", tablePath);
@@ -336,21 +333,17 @@
//colorTableSolid.create(0, 100, strBuf);
// Brighten.
- sprintf(strBuf, "%sBrighten", tablePath);
+ sprintf(strBuf, "%s/Brighten.tbl", tablePath);
colorTableBrighten.createBrightenFilter(strBuf, 256);
// Darken.
- sprintf(strBuf, "%sDarkenALot", tablePath);
+ sprintf(strBuf, "%s/DarkenALot.tbl", tablePath);
colorTableDarkenALot.createDarkenFilter(strBuf, 0.5f);
- sprintf(strBuf, "%sDarkenALittle", tablePath);
+ sprintf(strBuf, "%s/DarkenALittle.tbl", tablePath);
colorTableDarkenALittle.createDarkenFilter(strBuf, 0.15f);
- //progressView->update(" litedark.tbl");
- sprintf(strBuf, "%sLightDark", tablePath);
+ sprintf(strBuf, "%s/LightDark.tbl", tablePath);
colorTableLightDark.createLightDarkFilter(strBuf);
-
- //progressView->update(" DONE.");
-
} // end setColorTables
@@ -359,12 +352,9 @@
void Palette::setName(String filename)
{
char strBuf[256];
- sprintf(strBuf, "%s", (const char *) filename);
-
- UtilInterface::getFilename(filename);
+ sprintf(strBuf, "%s", (const char*)
UtilInterface::getFilename(filename));
char *dotPtr = 0;
-
if ((dotPtr = strchr(strBuf, '.')) != 0)
{
// Remove the extension.
@@ -372,7 +362,6 @@
}
name = strBuf;
-
} // end Palette::setName
// loadACT
Index: netpanzer/src/Lib/2D/RGBColor.hpp
diff -u netpanzer/src/Lib/2D/RGBColor.hpp:1.2
netpanzer/src/Lib/2D/RGBColor.hpp:1.3
--- netpanzer/src/Lib/2D/RGBColor.hpp:1.2 Mon Sep 1 16:24:18 2003
+++ netpanzer/src/Lib/2D/RGBColor.hpp Fri Sep 12 10:12:45 2003
@@ -37,6 +37,15 @@
// Returns an int between [+0.0...+1.0]
int getBrightnessFloat();
+
+ bool operator == (const RGBColor& other) const
+ {
+ return red == other.red &&
+ green == other.green &&
+ blue == other.blue;
+ }
+ bool operator != (const RGBColor& other) const
+ { return ! (*this == other); }
};
#endif // end __RGBColor_hpp__
Index: netpanzer/src/Lib/Exception.hpp
diff -u netpanzer/src/Lib/Exception.hpp:1.2 netpanzer/src/Lib/Exception.hpp:1.3
--- netpanzer/src/Lib/Exception.hpp:1.2 Sat Sep 6 18:31:20 2003
+++ netpanzer/src/Lib/Exception.hpp Fri Sep 12 10:12:45 2003
@@ -23,7 +23,8 @@
class Exception
{
public:
- Exception(const char* message, ...);
+ Exception(const char* message, ...)
+ __attribute__((format (__printf__, 2, 3)));
Exception(const Exception& other);
~Exception();
Index: netpanzer/src/Lib/FileSystem.cpp
diff -u netpanzer/src/Lib/FileSystem.cpp:1.1
netpanzer/src/Lib/FileSystem.cpp:1.2
--- netpanzer/src/Lib/FileSystem.cpp:1.1 Thu Sep 11 14:56:54 2003
+++ netpanzer/src/Lib/FileSystem.cpp Fri Sep 12 10:12:45 2003
@@ -21,14 +21,13 @@
#include "Exception.hpp"
#include "FileSystem.hpp"
-void FileSystem::initialize(const char* argv0)
+void FileSystem::initialize(const char* argv0, const char* company,
+ const char* application)
{
- if (!PHYSFS_init(argv0))
+ if(!PHYSFS_init(argv0) ||
+ !PHYSFS_setSaneConfig(company, application, "zip", 0, 0))
throw Exception("failure while initialising physfs: %s",
PHYSFS_getLastError());
-
- // TODO check search and writepaths here
- PHYSFS_setSaneConfig("netpanzer", "netpanzer", "zip", 0, 0);
}
void FileSystem::shutdown()
Index: netpanzer/src/Lib/FileSystem.hpp
diff -u netpanzer/src/Lib/FileSystem.hpp:1.1
netpanzer/src/Lib/FileSystem.hpp:1.2
--- netpanzer/src/Lib/FileSystem.hpp:1.1 Thu Sep 11 14:56:54 2003
+++ netpanzer/src/Lib/FileSystem.hpp Fri Sep 12 10:12:45 2003
@@ -106,7 +106,8 @@
class FileSystem
{
public:
- static void initialize(const char* argv0);
+ static void initialize(const char* argv0, const char* company,
+ const char* applicationname);
static void shutdown();
static ReadFile* openRead(const char* filename);
Index: netpanzer/src/Lib/Interfaces/UtilInterface.hpp
diff -u netpanzer/src/Lib/Interfaces/UtilInterface.hpp:1.3
netpanzer/src/Lib/Interfaces/UtilInterface.hpp:1.4
--- netpanzer/src/Lib/Interfaces/UtilInterface.hpp:1.3 Sat Sep 6 09:12:39 2003
+++ netpanzer/src/Lib/Interfaces/UtilInterface.hpp Fri Sep 12 10:12:45 2003
@@ -19,13 +19,6 @@
#ifndef __UtilInterface_hpp__
#define __UtilInterface_hpp__
-
-#if _MSC_VER > 1000
- #pragma once
-#endif
-
-
-
#include "String.hpp"
class Filename
Index: netpanzer/src/NetPanzer/Classes/Weapons/Weapon.cpp
diff -u netpanzer/src/NetPanzer/Classes/Weapons/Weapon.cpp:1.8
netpanzer/src/NetPanzer/Classes/Weapons/Weapon.cpp:1.9
--- netpanzer/src/NetPanzer/Classes/Weapons/Weapon.cpp:1.8 Wed Sep 10
08:46:55 2003
+++ netpanzer/src/NetPanzer/Classes/Weapons/Weapon.cpp Fri Sep 12 10:12:45 2003
@@ -201,7 +201,7 @@
lifecycle_status = _lifecycle_weapon_in_active;
//SFX
- sound->PlayAmbientSound( _not_applicable, Sound::_hit_target, 0 );
+ sound->playSound("hit_target");
// ** Particle Shit
iXY loc = iXY( location.x, location.y );
@@ -252,7 +252,7 @@
// measurements work. We measure with 0 pointing north, moving around
// clockwise. We also want to measure the angle from 0.0 to 1.0.
float ourGoalAngle = ((PI / 2) - goalAngleRad) / (PI * 2);
- int angle = ourGoalAngle * 360;
+ int angle = (int) (ourGoalAngle * 360);
while (angle < 0)
{
Index: netpanzer/src/NetPanzer/Core/main.cpp
diff -u netpanzer/src/NetPanzer/Core/main.cpp:1.2
netpanzer/src/NetPanzer/Core/main.cpp:1.3
--- netpanzer/src/NetPanzer/Core/main.cpp:1.2 Thu Sep 11 13:35:47 2003
+++ netpanzer/src/NetPanzer/Core/main.cpp Fri Sep 12 10:12:45 2003
@@ -25,6 +25,7 @@
#include "Log.hpp"
#include "Exception.hpp"
+#include "FileSystem.hpp"
#include "GameManager.hpp"
#include "MouseInterface.hpp"
#include "KeyboardInterface.hpp"
@@ -104,8 +105,15 @@
//---------------------------------------------------------------------------
-int main(int argc, char** argv)
+void shutdown()
+{
+ SDL_Quit();
+ FileSystem::shutdown();
+}
+
+void initialise(int argc, char** argv)
{
+ // Parse commandline
using namespace optionmm;
command_line commandline(PACKAGE_NAME, PACKAGE_VERSION,
"Copyright(c) 1998 Pyrosoft Inc. and others", "", argc,
argv);
@@ -117,11 +125,22 @@
commandline.add(&port_option);
if(!commandline.process() || commandline.help() ||
commandline.version())
- return 0;
-
+ exit(0);
+
+ // Initialize SDL
SDL_Init(SDL_INIT_TIMER);
SDL_EnableUNICODE(1);
+ // Initialize libphysfs
+ try {
+ FileSystem::initialize(argv[0], "netpanzer", "netpanzer");
+ } catch(Exception e) {
+ fprintf(stderr, "%s", e.getMessage());
+ shutdown();
+ exit(1);
+ }
+
+ // Initialize random number generator
srand(time(0));
// the STL functions in gcc3 seem to use the 48er versions of the random
// generator instead of the default libc one, so we have todo a double
srand
@@ -130,13 +149,19 @@
srand48(time(0));
#endif
+ // finally initialize the game objects
try {
GameManager::initialize(dedicated_option.value());
} catch(Exception e) {
fprintf(stderr, "Couldn't initialize the game: %s\n",
e.getMessage());
- SDL_Quit();
+ shutdown();
exit(1);
}
+}
+
+int main(int argc, char** argv)
+{
+ initialise(argc, argv);
// we'll catch every exception here, just to be sure the user gets at
least
// a usefull error message and SDL has a chance to shutdown...
@@ -153,16 +178,15 @@
GameManager::shutdown();
LOG ( ("successfull shutdown.") );
- SDL_Quit();
-
+ shutdown();
} catch(Exception e) {
fprintf(stderr, "An unexpected exception occured: %s\nShutdown
needed.",
e.getMessage());
- SDL_Quit();
+ shutdown();
throw;
} catch(...) {
fprintf(stderr, "An unexpected exception occured.\nShutdown
needed.");
- SDL_Quit();
+ shutdown();
throw;
}
Index: netpanzer/src/NetPanzer/Interfaces/GameManager.cpp
diff -u netpanzer/src/NetPanzer/Interfaces/GameManager.cpp:1.35
netpanzer/src/NetPanzer/Interfaces/GameManager.cpp:1.36
--- netpanzer/src/NetPanzer/Interfaces/GameManager.cpp:1.35 Thu Sep 11
21:55:56 2003
+++ netpanzer/src/NetPanzer/Interfaces/GameManager.cpp Fri Sep 12 10:12:45 2003
@@ -823,9 +823,9 @@
{
UnitProfileInterface::loadUnitProfiles();
LoadUnitSurfaces();
- UNIT_FLAGS_SURFACE.loadAllBMPInDirectory("pics/flags/netp/");
+ UNIT_FLAGS_SURFACE.loadAllBMPInDirectory("pics/flags/");
if(UNIT_FLAGS_SURFACE.getFrameCount() == 0)
- throw Exception("Couldn't find any flag in pics/flags/netp.");
+ throw Exception("Couldn't find any flag in pics/flags/.");
GameConfig::loadConfigScript();
return true;
@@ -836,9 +836,9 @@
{
UnitProfileInterface::loadUnitProfiles();
LoadUnitSurfaces();
- UNIT_FLAGS_SURFACE.loadAllBMPInDirectory("pics/flags/netp/");
+ UNIT_FLAGS_SURFACE.loadAllBMPInDirectory("pics/flags/");
if(UNIT_FLAGS_SURFACE.getFrameCount() == 0)
- throw Exception("Couldn't find any flag in pics/flags/netp.");
+ throw Exception("Couldn't find any flag in pics/flags/.");
GameConfig::loadConfigScript();
}
Index: netpanzer/src/NetPanzer/Views/MainMenu/Multi/FlagSelectionView.cpp
diff -u netpanzer/src/NetPanzer/Views/MainMenu/Multi/FlagSelectionView.cpp:1.8
netpanzer/src/NetPanzer/Views/MainMenu/Multi/FlagSelectionView.cpp:1.9
--- netpanzer/src/NetPanzer/Views/MainMenu/Multi/FlagSelectionView.cpp:1.8
Wed Sep 10 07:26:10 2003
+++ netpanzer/src/NetPanzer/Views/MainMenu/Multi/FlagSelectionView.cpp Fri Sep
12 10:12:45 2003
@@ -42,7 +42,7 @@
moveTo(bodyTextRect.min.x + bodyTextRect.getSizeX() / 2 + 10 + 30,
bodyTextRect.min.y + 50);
// Load the flag images.
- //flags.loadAllBMPInDirectory("pics/flags/netpmenu/");
+ //flags.loadAllBMPInDirectory("pics/flags/");
resizeClientArea(bodyTextRect.getSizeX() / 2 - 10 - 30, 108);
@@ -65,9 +65,9 @@
//---------------------------------------------------------------------------
void FlagSelectionView::init()
{
- if (playerFlag.loadAllBMPInDirectory("pics/flags/netpmenu/") <= 0)
+ if (playerFlag.loadAllBMPInDirectory("pics/flags/") <= 0)
throw Exception("Couldn't find flags for menu in '%s'.",
- "pics/flags/netpmenu/");
+ "pics/flags/");
iXY flagStartOffset(BORDER_SPACE, BORDER_SPACE * 2 +
playerFlag.getPixY());
Index: netpanzer/src/UILib/SDL/SDLSound.cpp
diff -u netpanzer/src/UILib/SDL/SDLSound.cpp:1.4
netpanzer/src/UILib/SDL/SDLSound.cpp:1.5
--- netpanzer/src/UILib/SDL/SDLSound.cpp:1.4 Mon Sep 8 08:12:19 2003
+++ netpanzer/src/UILib/SDL/SDLSound.cpp Fri Sep 12 10:12:45 2003
@@ -45,6 +45,13 @@
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
+struct SoundEntry
+{
+public:
+ std::string name;
+ std::vector<Mix_Chunk*> sounds;
+};
+
void SDLSound::PlayTankIdle()
{
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [netPanzer-CVS] netpanzer/src ChangeLog Lib/Exception.hpp Lib/F...,
Matthias Braun <=