- 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:
Mark Vejvoda
2013-06-23 04:17:25 +00:00
parent 4764da0e50
commit d46479df95
19 changed files with 140 additions and 39 deletions

View File

@@ -489,7 +489,7 @@ Texture2D * Renderer::getPlayerColorTexture(PlayerColor playerColor) {
customTexture= customTextureMagenta;
break;
default:
assert(false);
throw megaglest_runtime_error("Unknown playercolor: " + intToStr(playerColor));
break;
}

View File

@@ -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");
}

View File

@@ -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");
}

View File

@@ -11,7 +11,6 @@
#include "components.h"
//#include <cassert>
#include <algorithm>
#include "metrics.h"

View File

@@ -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();
// 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()));
int width=pixmap->getW();
int heith=pixmap->getW();
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) {
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++;
}

View File

@@ -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;

View File

@@ -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();

View File

@@ -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();

View File

@@ -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));

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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(){

View File

@@ -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;

View File

@@ -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;