From 5972b0564a9131de70064ed219cd8351844cf0ab Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 2 Jan 2005 19:35:53 +0000 Subject: Don't try to create video bitmaps, and store whole numbers as whole numbers in the configuration file. --- src/configuration.cpp | 46 +++++++++++++++++++++++++++++++--------------- src/graphic/image.cpp | 37 +++++++++++-------------------------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 8f4ebbc8..27b47ac7 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -21,6 +21,7 @@ #include "configuration.h" +#include /** \brief read INI file and parse all options into memory @@ -45,16 +46,17 @@ void Configuration::init(std::string filename) { while (inFile.good()) { getline(inFile, inBuffer, '\n'); - if(inBuffer.substr(0,1) != INI_COMMENTER) { + if (inBuffer.substr(0, 1) != INI_COMMENTER) { position = inBuffer.find(INI_DELIMITER, 0); - if(position != std::string::npos) { + if (position != std::string::npos) { // replace spaces with void :) - while(inBuffer.find(" ", 0) != std::string::npos) { + while (inBuffer.find(" ", 0) != std::string::npos) { inBuffer.replace(inBuffer.find(" ", 0), 1, ""); } std::string key = inBuffer.substr(0, position); - optionTmp.stringValue = inBuffer.substr(position+1, inBuffer.length()); + optionTmp.stringValue = inBuffer.substr(position + 1, + inBuffer.length()); inBuffer = inBuffer.substr(position+1, inBuffer.length()); optionTmp.numericValue = atof(inBuffer.c_str()); @@ -62,7 +64,9 @@ void Configuration::init(std::string filename) { iniOptions[key] = optionTmp; #ifdef __DEBUG - std::cout << "Configuration::init(" << key << ", \"" << optionTmp.stringValue << "\" / " << optionTmp.numericValue << ")\n"; + std::cout << "Configuration::init(" << key << ", \"" << + optionTmp.stringValue << "\" / " << + optionTmp.numericValue << ")\n"; #endif } } @@ -75,7 +79,8 @@ void Configuration::init(std::string filename) { \param filename full path to INI file (~/.manaworld/tmw.ini) */ bool Configuration::write(std::string filename) { - std::ofstream out(filename.c_str(), std::ofstream::out | std::ofstream::trunc); + std::ofstream out(filename.c_str(), + std::ofstream::out | std::ofstream::trunc); char tmp[20]; INI_OPTION optionTmp; @@ -83,15 +88,24 @@ bool Configuration::write(std::string filename) { out.write(iter->first.c_str(), iter->first.length()); out.write("=", 1); - if(iter->second.numericValue == 0) { - out.write(iter->second.stringValue.c_str(), iter->second.stringValue.length()); - }else{ - sprintf(tmp, "%f", iter->second.numericValue); + double numericValue = iter->second.numericValue; + + if (numericValue == 0) { + out.write(iter->second.stringValue.c_str(), + iter->second.stringValue.length()); + } + else if (numericValue == floor(numericValue)) { + out << (int)numericValue; + } + else { + sprintf(tmp, "%f", numericValue); out.write(tmp, strlen(tmp)); strcpy(tmp, ""); } #ifdef __DEBUG - std::cout << "Configuration::write(" << iter->first.c_str() << ", \"" << iter->second.stringValue << "\" / " << iter->second.numericValue << ")\n"; + std::cout << "Configuration::write(" << iter->first.c_str() << + ", \"" << iter->second.stringValue << "\" / " << + iter->second.numericValue << ")\n"; #endif out.write("\n", 1); } @@ -108,7 +122,8 @@ bool Configuration::write(std::string filename) { void Configuration::setValue(std::string key, std::string value) { INI_OPTION optionTmp; #ifdef __DEBUG - std::cout << "Configuration::setValue(" << key << ", " << value << ")\n"; + std::cout << "Configuration::setValue(" << key << ", " << value << + ")\n"; #endif optionTmp.stringValue = value; optionTmp.numericValue = 0; @@ -123,7 +138,8 @@ void Configuration::setValue(std::string key, std::string value) { void Configuration::setValue(std::string key, float value) { INI_OPTION optionTmp; #ifdef __DEBUG - std::cout << "Configuration::setValue(" << key << ", " << value << ")\n"; + std::cout << "Configuration::setValue(" << key << ", " << value << + ")\n"; #endif optionTmp.stringValue = ""; optionTmp.numericValue = value; @@ -137,7 +153,7 @@ void Configuration::setValue(std::string key, float value) { */ std::string Configuration::getValue(std::string key, std::string deflt) { iter = iniOptions.find(key); - if(iter != iniOptions.end()) { + if (iter != iniOptions.end()) { return iniOptions[key].stringValue; } return deflt; @@ -150,7 +166,7 @@ std::string Configuration::getValue(std::string key, std::string deflt) { */ float Configuration::getValue(std::string key, float deflt) { iter = iniOptions.find(key); - if(iter != iniOptions.end()) { + if (iter != iniOptions.end()) { return iniOptions[key].numericValue; } return deflt; diff --git a/src/graphic/image.cpp b/src/graphic/image.cpp index 7bbf6a68..9d0d3cac 100644 --- a/src/graphic/image.cpp +++ b/src/graphic/image.cpp @@ -61,8 +61,13 @@ VideoImage::~VideoImage() { destroy_bitmap(src); } -void VideoImage::draw(BITMAP *dest, int x, int y) { - masked_blit(src, dest, 0, 0, x + offset_x, y + offset_y, src->w, src->h); +void VideoImage::draw(BITMAP *dst, int x, int y) { + //SDL_Rect dst_rect; + //dst_rect.x = x + offset_x; + //dst_rect.y = y + offset_y; + //SDL_BlitSurface(src, NULL, dst, &dst_rect); + + masked_blit(src, dst, 0, 0, x + offset_x, y + offset_y, src->w, src->h); } @@ -75,30 +80,10 @@ Spriteset::Spriteset(std::string filename) int i = 0; while (datafile[i].type != DAT_END) { Image *temp_image; - if (gfx_capabilities & GFX_HW_VRAM_BLIT) { - BITMAP *temp_video_bitmap = create_video_bitmap( - ((RLE_SPRITE *)datafile[i].dat)->w, - ((RLE_SPRITE *)datafile[i].dat)->h); - if (temp_video_bitmap) { - clear_to_color(temp_video_bitmap, makecol(255, 0, 255)); - draw_rle_sprite(temp_video_bitmap, - (RLE_SPRITE *)datafile[i].dat, 0, 0); - temp_image = new VideoImage(temp_video_bitmap, - getProperty(&datafile[i], DAT_ID('X','C','R','P')), - getProperty(&datafile[i], DAT_ID('Y','C','R','P'))); - } else { - warning("You ran out of video memory!"); - temp_image = new RleImage( - (RLE_SPRITE*)datafile[i].dat, - getProperty(&datafile[i], DAT_ID('X','C','R','P')), - getProperty(&datafile[i], DAT_ID('Y','C','R','P'))); - } - } else { - temp_image = new RleImage( - (RLE_SPRITE*)datafile[i].dat, - getProperty(&datafile[i], DAT_ID('X','C','R','P')), - getProperty(&datafile[i], DAT_ID('Y','C','R','P'))); - } + temp_image = new RleImage( + (RLE_SPRITE*)datafile[i].dat, + getProperty(&datafile[i], DAT_ID('X','C','R','P')), + getProperty(&datafile[i], DAT_ID('Y','C','R','P'))); spriteset.push_back(temp_image); i++; } -- cgit v1.2.3-70-g09d2