mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 21:33:59 +02:00
- bugfix to allow headless server to load a texture for new tilesets where they must read it to determine parts.
- converted asserts to exceptions
This commit is contained in:
@@ -489,7 +489,7 @@ Texture2D * Renderer::getPlayerColorTexture(PlayerColor playerColor) {
|
||||
customTexture= customTextureMagenta;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
throw megaglest_runtime_error("Unknown playercolor: " + intToStr(playerColor));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,6 @@
|
||||
#include "path_finder.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "config.h"
|
||||
#include "map.h"
|
||||
@@ -1173,7 +1172,6 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
||||
|
||||
//a) push starting pos into openNodes
|
||||
Node *firstNode= newNode(factions[unitFactionIndex],maxNodeCount);
|
||||
assert(firstNode != NULL);
|
||||
if(firstNode == NULL) {
|
||||
throw megaglest_runtime_error("firstNode == NULL");
|
||||
}
|
||||
|
@@ -216,7 +216,6 @@ private:
|
||||
|
||||
//Node * minHeuristicFastLookup(FactionState &faction);
|
||||
inline static Node * minHeuristicFastLookup(FactionState &faction) {
|
||||
assert(faction.openNodesList.empty() == false);
|
||||
if(faction.openNodesList.empty() == true) {
|
||||
throw megaglest_runtime_error("openNodesList.empty() == true");
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@
|
||||
|
||||
#include "components.h"
|
||||
|
||||
//#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
#include "metrics.h"
|
||||
|
@@ -227,15 +227,50 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
||||
else {
|
||||
// read single big texture and cut it into pieces
|
||||
const XmlNode *textureNode= surfaceNode->getChild("texture", 0);
|
||||
Pixmap2D *pixmap=new Pixmap2D();
|
||||
pixmap->init(3);
|
||||
pixmap->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||
loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,textureNode->getAttribute("path")->getRestrictedValue()));
|
||||
int width=pixmap->getW();
|
||||
int heith=pixmap->getW();
|
||||
|
||||
// There is no way to figure out parts without loading the texture
|
||||
// unfortunately we must load it even for headless server
|
||||
// to get width and height
|
||||
bool switchOffNonGraphicalModeEnabled = GlobalStaticFlags::getIsNonGraphicalModeEnabled();
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
GlobalStaticFlags::setIsNonGraphicalModeEnabled(false);
|
||||
}
|
||||
|
||||
string exceptionError = "";
|
||||
Pixmap2D *pixmap = NULL;
|
||||
int width = 0;
|
||||
int heith = 0;
|
||||
|
||||
try {
|
||||
pixmap=new Pixmap2D();
|
||||
pixmap->init(3);
|
||||
pixmap->load(textureNode->getAttribute("path")->getRestrictedValue(currentPath));
|
||||
loadedFileList[textureNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,textureNode->getAttribute("path")->getRestrictedValue()));
|
||||
|
||||
width = pixmap->getW();
|
||||
heith = pixmap->getW();
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
|
||||
exceptionError = "Error: " + path + "\n" + ex.what();
|
||||
}
|
||||
|
||||
if(switchOffNonGraphicalModeEnabled == true) {
|
||||
GlobalStaticFlags::setIsNonGraphicalModeEnabled(true);
|
||||
|
||||
delete pixmap;
|
||||
pixmap = NULL;
|
||||
}
|
||||
|
||||
if(exceptionError != "") {
|
||||
throw megaglest_runtime_error(exceptionError.c_str());
|
||||
}
|
||||
|
||||
assert(width==heith);
|
||||
assert(width%64==0);
|
||||
assert(width%partsize==0);
|
||||
|
||||
int parts=width/partsize;
|
||||
int numberOfPieces=parts*parts;
|
||||
partsArray[i]=parts;
|
||||
@@ -244,9 +279,11 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck
|
||||
int j=0;
|
||||
for(int x = 0; x < parts; ++x) {
|
||||
for(int y = 0; y < parts; ++y) {
|
||||
surfPixmaps[i][j] = new Pixmap2D();
|
||||
surfPixmaps[i][j]->init(partsize,partsize,3);
|
||||
surfPixmaps[i][j]->copyImagePart(x*partsize,y*partsize,pixmap);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) {
|
||||
surfPixmaps[i][j] = new Pixmap2D();
|
||||
surfPixmaps[i][j]->init(partsize,partsize,3);
|
||||
surfPixmaps[i][j]->copyImagePart(x*partsize,y*partsize,pixmap);
|
||||
}
|
||||
surfProbs[i][j]=-1;
|
||||
j++;
|
||||
}
|
||||
|
@@ -74,7 +74,9 @@ BMPReader::BMPReader(): FileReader<Pixmap2D>(getExtensionsBmp()) {}
|
||||
*Path is used for printing error messages
|
||||
*@return <code>NULL</code> if the Pixmap2D could not be read, else the pixmap*/
|
||||
Pixmap2D* BMPReader::read(ifstream& in, const string& path, Pixmap2D* ret) const {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
//read file header
|
||||
BitmapFileHeader fileHeader;
|
||||
|
@@ -70,7 +70,10 @@ static inline std::vector<string> getExtensions() {
|
||||
JPGReader::JPGReader(): FileReader<Pixmap2D>(getExtensions()) {}
|
||||
|
||||
Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
//Read file
|
||||
is.seekg(0, ios::end);
|
||||
streampos length = is.tellg();
|
||||
|
@@ -63,7 +63,10 @@ static inline std::vector<string> getExtensionsPng() {
|
||||
PNGReader::PNGReader(): FileReader<Pixmap2D>(getExtensionsPng()) {}
|
||||
|
||||
Pixmap2D* PNGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
//Read file
|
||||
is.seekg(0, ios::end);
|
||||
//size_t length = is.tellg();
|
||||
|
@@ -68,7 +68,10 @@ TGAReader3D::TGAReader3D(): FileReader<Pixmap3D>(getExtensionStrings()) {}
|
||||
Pixmap3D* TGAReader3D::read(ifstream& in, const string& path, Pixmap3D* ret) const {
|
||||
//printf("In [%s] line: %d\n",__FILE__,__LINE__);
|
||||
// try {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
//read header
|
||||
TargaFileHeader fileHeader;
|
||||
in.read((char*)&fileHeader, sizeof(TargaFileHeader));
|
||||
|
@@ -218,7 +218,9 @@ string FontMetrics::wordWrapText(string text, int maxWidth) {
|
||||
// ===============================================
|
||||
|
||||
Font::Font(FontTextHandlerType type) {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
inited = false;
|
||||
this->type = fontTypeName;
|
||||
|
@@ -15,16 +15,21 @@
|
||||
#include "graphics_factory.h"
|
||||
#include <stdexcept>
|
||||
#include "util.h"
|
||||
#include "platform_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Platform;
|
||||
using namespace Shared::Util;
|
||||
|
||||
namespace Shared { namespace Graphics {
|
||||
|
||||
// =====================================================
|
||||
// class FontManager
|
||||
// =====================================================
|
||||
FontManager::FontManager() {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
fonts.clear();
|
||||
}
|
||||
|
||||
|
@@ -33,7 +33,9 @@ namespace Shared{ namespace Graphics{
|
||||
bool InterpolationData::enableCache = false;
|
||||
|
||||
InterpolationData::InterpolationData(const Mesh *mesh) {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
vertices= NULL;
|
||||
normals= NULL;
|
||||
|
@@ -1067,7 +1067,10 @@ void Mesh::deletePixels() {
|
||||
// ==================== constructor & destructor ====================
|
||||
|
||||
Model::Model() {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
meshCount = 0;
|
||||
meshes = NULL;
|
||||
textureManager = NULL;
|
||||
|
@@ -16,10 +16,11 @@
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
#include "util.h"
|
||||
|
||||
#include "platform_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
using namespace Shared::Platform;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
@@ -28,7 +29,10 @@ namespace Shared{ namespace Graphics{
|
||||
// =====================================================
|
||||
|
||||
ModelManager::ModelManager(){
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
textureManager= NULL;
|
||||
}
|
||||
|
||||
|
@@ -86,7 +86,6 @@ ParticleSystem::ParticleSystem(int particleCount) {
|
||||
memoryObjectList[this]++;
|
||||
}
|
||||
|
||||
//assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
textureFileLoadDeferred = "";
|
||||
textureFileLoadDeferredSystemId = 0;
|
||||
textureFileLoadDeferredFormat = Texture::fAuto;
|
||||
@@ -1850,7 +1849,6 @@ void SplashParticleSystem::loadGame(const XmlNode *rootNode) {
|
||||
// ===========================================================================
|
||||
|
||||
ParticleManager::ParticleManager() {
|
||||
//assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
}
|
||||
|
||||
ParticleManager::~ParticleManager() {
|
||||
|
@@ -759,7 +759,10 @@ void PixmapIoJpg::write(uint8 *pixels) {
|
||||
// ===================== PUBLIC ========================
|
||||
|
||||
Pixmap1D::Pixmap1D() {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
|
||||
w= -1;
|
||||
components= -1;
|
||||
@@ -767,13 +770,19 @@ Pixmap1D::Pixmap1D() {
|
||||
}
|
||||
|
||||
Pixmap1D::Pixmap1D(int components) {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
|
||||
init(components);
|
||||
}
|
||||
|
||||
Pixmap1D::Pixmap1D(int w, int components) {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
|
||||
init(w, components);
|
||||
}
|
||||
@@ -885,7 +894,10 @@ void Pixmap1D::loadTga(const string &path) {
|
||||
// ===================== PUBLIC ========================
|
||||
|
||||
Pixmap2D::Pixmap2D() {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
h= -1;
|
||||
w= -1;
|
||||
components= -1;
|
||||
@@ -893,7 +905,10 @@ Pixmap2D::Pixmap2D() {
|
||||
}
|
||||
|
||||
Pixmap2D::Pixmap2D(int components) {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
h= -1;
|
||||
w= -1;
|
||||
this->components= -1;
|
||||
@@ -903,7 +918,10 @@ Pixmap2D::Pixmap2D(int components) {
|
||||
}
|
||||
|
||||
Pixmap2D::Pixmap2D(int w, int h, int components) {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
this->h= 0;
|
||||
this->w= -1;
|
||||
this->components= -1;
|
||||
@@ -1323,7 +1341,10 @@ bool Pixmap2D::doDimensionsAgree(const Pixmap2D *pixmap){
|
||||
// =====================================================
|
||||
|
||||
Pixmap3D::Pixmap3D() {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
|
||||
w= -1;
|
||||
h= -1;
|
||||
@@ -1334,14 +1355,20 @@ Pixmap3D::Pixmap3D() {
|
||||
}
|
||||
|
||||
Pixmap3D::Pixmap3D(int w, int h, int d, int components) {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
pixels = NULL;
|
||||
slice=0;
|
||||
init(w, h, d, components);
|
||||
}
|
||||
|
||||
Pixmap3D::Pixmap3D(int d, int components) {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
pixels = NULL;
|
||||
slice=0;
|
||||
init(d, components);
|
||||
@@ -1468,7 +1495,10 @@ void Pixmap3D::loadSliceTga(const string &path, int slice){
|
||||
// class PixmapCube
|
||||
// =====================================================
|
||||
PixmapCube::PixmapCube() {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PixmapCube::~PixmapCube() {
|
||||
|
@@ -26,7 +26,10 @@ namespace Shared{ namespace Graphics{
|
||||
// =====================================================
|
||||
|
||||
ShaderManager::ShaderManager() {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ShaderManager::~ShaderManager(){
|
||||
|
@@ -12,9 +12,11 @@
|
||||
#include "texture.h"
|
||||
#include "util.h"
|
||||
#include <SDL.h>
|
||||
#include "platform_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
using namespace Shared::Platform;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
@@ -39,7 +41,10 @@ static int powerOfTwo(int input) {
|
||||
*/
|
||||
|
||||
Texture::Texture() {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
|
||||
mipmap= true;
|
||||
pixmapInit= true;
|
||||
|
@@ -18,9 +18,11 @@
|
||||
#include "graphics_factory.h"
|
||||
|
||||
#include "util.h"
|
||||
#include "platform_util.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Util;
|
||||
using namespace Shared::Platform;
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
@@ -29,7 +31,10 @@ namespace Shared{ namespace Graphics{
|
||||
// =====================================================
|
||||
|
||||
TextureManager::TextureManager() {
|
||||
assert(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false);
|
||||
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == true) {
|
||||
throw megaglest_runtime_error("Loading graphics in headless server mode not allowed!");
|
||||
}
|
||||
|
||||
|
||||
textureFilter= Texture::fBilinear;
|
||||
maxAnisotropy= 1;
|
||||
|
Reference in New Issue
Block a user