Commit 570bc27f authored by Robert Scott James's avatar Robert Scott James

Started the process of changing all of ripp_'s std::cerr into the new debugging functions

Added some frees to the code still leaks but meh
  Changes to be committed:

 	modified:   src/configReader.cpp
 	modified:   src/configReader.h
 	modified:   src/dungeon/dungeon.cpp
 	modified:   src/game/game.cpp
 	modified:   src/main.cpp
parent ed770734
#include <iostream>
#include <libconfig.h++>
#include "debug.h"
#include "configReader.h"
using namespace libconfig;
......@@ -10,46 +11,10 @@ int loadConfig(std::string file,Config *cfg){
cfg->setAutoConvert (1);
return (0);
} catch(const FileIOException &fioex){
std::cerr << "I/O error while reading file." << std::endl;
ERROR("I/O error while reading file.");
return (1);
} catch(const ParseException &pex){
std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() << " - " << pex.getError() << std::endl;
ERROR("Parse error at " << pex.getFile() << ":" << pex.getLine() << " - " << pex.getError());
return (1);
}
}
int fromConfig(Config *cfg,const char* addr,int def){
try{
return cfg->lookup(addr);
} catch(const SettingNotFoundException &nfex){
std::cerr << "WARNING: config value " << addr << " not set. using default" << std::endl;
return def;
} catch(const SettingTypeException &nfex){
std::cerr << "WARNING: config value " << addr << " not a int. using default" << std::endl;
return def;
}
}
std::string fromConfig(Config *cfg,const char * addr,std::string def){
try{
return cfg->lookup(addr);
} catch(const SettingNotFoundException &nfex){
std::cerr << "WARNING: config value " << addr << " not set. using default" << std::endl;
return def;
} catch(const SettingTypeException &nfex){
std::cerr << "WARNING: config value " << addr << " not a string. using default" << std::endl;
return def;
}
}
float fromConfig(Config *cfg, const char * addr,float def){
try{
return cfg->lookup(addr);
} catch(const SettingNotFoundException &nfex){
std::cerr << "WARNING: config value " << addr << " not set. using default" << std::endl;
return def;
} catch(const SettingTypeException &nfex){
std::cerr << "WARNING: config value " << addr << " not a float. using default" << std::endl;
return def;
}
}
......@@ -3,12 +3,29 @@
#include <iostream>
#include <libconfig.h++>
#include "debug.h"
using namespace libconfig;
int loadConfig(std::string,Config *);
template<typename TYPE> TYPE fromConfig(Config *cfg, const char *addr, TYPE def);
/*
int fromConfig(Config *,const char *,int);
std::string fromConfig(Config *,const char *,std::string);
float fromConfig(Config *,const char *,float);
*/
template<typename TYPE> TYPE fromConfig(Config *cfg, const char *addr, TYPE def){
try{
return cfg->lookup(addr);
} catch(const SettingNotFoundException &nfex){
WARN("WARNING: config value " << addr << " not set. using default");
return def;
} catch(const SettingTypeException &nfex){
WARN("WARNING: config value " << addr << " not a int. using default");
return def;
}
}
#endif
#include "space.h"
#include "types.h"
#include "../debug.h"
#include <string>
#include <iostream>
#include <tuple>
......@@ -13,7 +14,7 @@ std::tuple<int,int> Dungeon::upStairPosition(){
}
}
}
std::cerr << "Warning: No upstairs found";
CRIT("ERROR: No upstairs found");
return std::make_tuple(-1,-1);
}
......
......@@ -7,6 +7,7 @@
#include <chrono>
#include <memory>
#include "../debug.h"
#include "../entity/vision/alive/mob/mob.h"
#include "../vroot.h"
#include "../lodepng/lodepng.h"
......@@ -54,7 +55,8 @@ void Game::loop(){
unsigned long milliseconds_since_epoch = std::chrono::system_clock::now().time_since_epoch() / std::chrono::milliseconds(1);
// Print Level Seed
std::cout << "Drawing seed for level " << dungeonLevel << ": " << milliseconds_since_epoch << std::endl;
VERBOSE("Drawing seed for level" << dungeonLevel << ": " << milliseconds_since_epoch);
if (!levelToLoad.empty()){
std::shared_ptr<Loader> d(new Loader(202,202,levelToLoad));
levels.emplace_back(d);
......@@ -68,8 +70,6 @@ void Game::loop(){
// Create hero at coordinates of the dungeon start
std::tuple<int,int> heroStart = levels.back()->upStairPosition();
//std::cerr << std::get<0>(heroStart) << ","<< std::get<0>(heroStart) << std::endl;
BasicSolverHero levelHero = BasicSolverHero( *levels.back() ,std::get<0>(heroStart), std::get<1>(heroStart),5 /*vision*/);
//Hero levelHero = Hero(levels.back(),std::get<0>(heroStart), std::get<1>(heroStart),20 /*vision*/);
theHero = &levelHero;
......@@ -126,7 +126,7 @@ void Game::loop(){
}
XCopyArea(dpy, double_buffer, w, gc, 0, 0, wa.width, wa.height, 0, 0);
XFillRectangle(dpy, double_buffer, gc, 0, 0, wa.width, wa.height);
XFillRectangle(dpy, double_buffer, gc, 0, 0, wa.width, wa.height);
XFlush(dpy);
if(theHero->levelComplete() == true){
break;
......@@ -142,6 +142,11 @@ void Game::loop(){
}
XFreeGC(dpy, gc);
XFreePixmap(dpy, double_buffer);
for(unsigned int ni = 0; ni < nTiles; ni++){
XFreePixmap(dpy,tiles[ni]);
}
}
......@@ -151,7 +156,7 @@ int Game::readTiles(std::string tilesFilename,Display*& dpy,Drawable d,GC gc){
error = lodepng_decode32_file(&image, &tileFileWidth, &tileHeight, tilesFilename.c_str());
if(error){
std::cerr << "Error " << error << ": " << lodepng_error_text(error) << std::endl;
ERROR("Error " << error << ": " << lodepng_error_text(error));
return(1);
}
error = 0; // Reset the error variable so I can use it again later
......@@ -162,8 +167,6 @@ int Game::readTiles(std::string tilesFilename,Display*& dpy,Drawable d,GC gc){
// Allocate the memory for the tiles
tiles = new Pixmap[nTiles];
std::cerr << image << std::endl;
for(int n = 0; n < nTiles; n++){
//char *rawData = new char[tileHeight*tileHeight*4];
tiles[n] = XCreatePixmap(dpy,d,tileHeight,tileHeight,24);
......@@ -174,9 +177,7 @@ int Game::readTiles(std::string tilesFilename,Display*& dpy,Drawable d,GC gc){
// Find the respective element in the image char array for the start of the current pixel
int imageOffset = ((4*j) + (n * tileHeight * 4)) + (4 * i * tileFileWidth);
int colour = (image[imageOffset]<<24) | (image[imageOffset+1]<<16) | (image[imageOffset+2]<<8);
//std::cerr << n << "," << i << "," << j << "," << (colour) << std::endl;
XSetForeground(dpy, gc, colour>>8);
XFillRectangle (dpy, tiles[n], gc, j, i, 1, 1);
}
......@@ -185,5 +186,4 @@ int Game::readTiles(std::string tilesFilename,Display*& dpy,Drawable d,GC gc){
// Now the individual tiles are stored we can free the original image
free(image);
return(0);
}
......@@ -15,7 +15,6 @@ int main(int argc, char **argv){
executableConfig_t executableArguments;
executableArguments.root = 0;
const struct option longopts[] = {
{"root", no_argument, &executableArguments.root,1},
{"load", required_argument, 0, 'l'},
......@@ -34,7 +33,6 @@ int main(int argc, char **argv){
}
}
// Create a game class
Game main(executableArguments);
main.loop();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment