summaryrefslogtreecommitdiff
path: root/Config.cpp
diff options
context:
space:
mode:
authorJapa2009-12-16 10:32:22 +0000
committerJapa2009-12-16 10:32:22 +0000
commit3da163b0cbcd9efa0d3f2cd190b1d09988c09725 (patch)
treeb355c50923fc9f27e742d70a2c1b8ca59f2c42fd /Config.cpp
parentec2f58ceba06ce3e58c8e98c6bf52b3f79fd1b12 (diff)
downloadstonesense-3da163b0cbcd9efa0d3f2cd190b1d09988c09725.tar.gz
stonesense-3da163b0cbcd9efa0d3f2cd190b1d09988c09725.tar.bz2
stonesense-3da163b0cbcd9efa0d3f2cd190b1d09988c09725.tar.xz
Merged the fog branch to trunk
Diffstat (limited to 'Config.cpp')
-rw-r--r--Config.cpp316
1 files changed, 179 insertions, 137 deletions
diff --git a/Config.cpp b/Config.cpp
index 0ae78e8..97900f0 100644
--- a/Config.cpp
+++ b/Config.cpp
@@ -1,120 +1,120 @@
-#include <iostream>
-#include <fstream>
-#include <string>
-#include "common.h"
-
-using namespace std;
-
-string parseStrFromLine( string keyword, string line ){
- string retVal = "";
- string trimString = "";
- trimString += "[";
- trimString += keyword;
- trimString += ":";
- int length = (int)trimString.length();
-
-
- if( line.compare(0,length, trimString) == 0){
- line.replace(0,length,"");
- line.replace(line.length()-1,1,"");
- retVal = line;
- }
-
- return retVal;
-}
-
-int parseIntFromLine( string keyword, string line ){
- int retVal = 0;
- string trimString = "";
- trimString += "[";
- trimString += keyword;
- trimString += ":";
- int length = (int)trimString.length();
-
-
- if( line.compare(0,length, trimString) == 0){
- line.replace(0,length,"");
- line.replace(line.length()-1,1,"");
- retVal = atoi( line.c_str() );
- }
-
- return retVal;
-}
-
-
-void parseConfigLine( string line ){
- char c = line[0];
- if( c != '[') return;
-
- //some systems don't remove the \r char as a part of the line change:
- if(line.size() > 0 && line[line.size() -1 ] == '\r' )
- line.resize(line.size() -1);
-
- c = line[ line.length() -1 ];
- if( c != ']' ) return;
-
- if( line.find("WIDTH") != -1){
- int width = parseIntFromLine( "WIDTH", line );
- config.screenWidth = width;
- }
- if( line.find("HEIGHT") != -1){
- int height = parseIntFromLine( "HEIGHT", line );
- config.screenHeight = height;
- }
- if( line.find("WINDOWED") != -1){
- string result = parseStrFromLine( "WINDOWED", line );
- config.Fullscreen = (result == "NO");
- }
- if( line.find("SEGMENTSIZE_XY") != -1){
- int value = parseIntFromLine( "SEGMENTSIZE_XY", line );
- if(value < 5) value = DEFAULT_SEGMENTSIZE;
- if(value > 100) value = 100;
- //plus 2 to allow edge readings
- config.segmentSize.x = value+2;
- config.segmentSize.y = value+2;
- }
- if( line.find("SEGMENTSIZE_Z") != -1){
- int value = parseIntFromLine( "SEGMENTSIZE_Z", line );
- if(value < 1) value = DEFAULT_SEGMENTSIZE_Z;
- if(value > 30) value = 30;
- config.segmentSize.z = value;
- }
-
- if( line.find("ALLCREATURES") != -1){
- string result = parseStrFromLine( "ALLCREATURES", line );
- config.show_all_creatures = (result == "YES");
- }
- if( line.find("AUTO_RELOAD_STEP") != -1){
- int value = parseIntFromLine( "AUTO_RELOAD_STEP", line);
- if(value < 50) value = 50;
- config.automatic_reload_step = value;
- }
- if( line.find("AUTO_RELOAD_TIME") != -1){
- int value = parseIntFromLine( "AUTO_RELOAD_TIME", line);
- if(value < 0) value = 0;
- config.automatic_reload_time = value;
- }
- if( line.find("DEBUGMODE") != -1){
- string result = parseStrFromLine( "DEBUGMODE", line );
- config.debug_mode = (result == "YES");
- }
- if( line.find("LIFTSEGMENT") != -1){
- int value = parseIntFromLine( "LIFTSEGMENT", line);
- config.lift_segment_offscreen = value;
- }
- if( line.find("ANIMATION_RATE") != -1){
- int value = parseIntFromLine( "ANIMATION_RATE", line );
- if(value < 50) value = 50;
- config.animation_step = value;
- }
- if( line.find("VERBOSE_LOGGING") != -1){
- string result = parseStrFromLine( "VERBOSE_LOGGING", line );
- config.verbose_logging = (result == "YES");
- }
- if( line.find("TRACK_CENTER") != -1){
- string result = parseStrFromLine( "TRACK_CENTER", line );
- config.track_center = (result == "YES");
- }
+#include <iostream>
+#include <fstream>
+#include <string>
+#include "common.h"
+
+using namespace std;
+
+string parseStrFromLine( string keyword, string line ){
+ string retVal = "";
+ string trimString = "";
+ trimString += "[";
+ trimString += keyword;
+ trimString += ":";
+ int length = (int)trimString.length();
+
+
+ if( line.compare(0,length, trimString) == 0){
+ line.replace(0,length,"");
+ line.replace(line.length()-1,1,"");
+ retVal = line;
+ }
+
+ return retVal;
+}
+
+int parseIntFromLine( string keyword, string line ){
+ int retVal = 0;
+ string trimString = "";
+ trimString += "[";
+ trimString += keyword;
+ trimString += ":";
+ int length = (int)trimString.length();
+
+
+ if( line.compare(0,length, trimString) == 0){
+ line.replace(0,length,"");
+ line.replace(line.length()-1,1,"");
+ retVal = atoi( line.c_str() );
+ }
+
+ return retVal;
+}
+
+
+void parseConfigLine( string line ){
+ char c = line[0];
+ if( c != '[') return;
+
+ //some systems don't remove the \r char as a part of the line change:
+ if(line.size() > 0 && line[line.size() -1 ] == '\r' )
+ line.resize(line.size() -1);
+
+ c = line[ line.length() -1 ];
+ if( c != ']' ) return;
+
+ if( line.find("WIDTH") != -1){
+ int width = parseIntFromLine( "WIDTH", line );
+ config.screenWidth = width;
+ }
+ if( line.find("HEIGHT") != -1){
+ int height = parseIntFromLine( "HEIGHT", line );
+ config.screenHeight = height;
+ }
+ if( line.find("WINDOWED") != -1){
+ string result = parseStrFromLine( "WINDOWED", line );
+ config.Fullscreen = (result == "NO");
+ }
+ if( line.find("SEGMENTSIZE_XY") != -1){
+ int value = parseIntFromLine( "SEGMENTSIZE_XY", line );
+ if(value < 5) value = DEFAULT_SEGMENTSIZE;
+ if(value > 100) value = 100;
+ //plus 2 to allow edge readings
+ config.segmentSize.x = value+2;
+ config.segmentSize.y = value+2;
+ }
+ if( line.find("SEGMENTSIZE_Z") != -1){
+ int value = parseIntFromLine( "SEGMENTSIZE_Z", line );
+ if(value < 1) value = DEFAULT_SEGMENTSIZE_Z;
+ if(value > 30) value = 30;
+ config.segmentSize.z = value;
+ }
+
+ if( line.find("ALLCREATURES") != -1){
+ string result = parseStrFromLine( "ALLCREATURES", line );
+ config.show_all_creatures = (result == "YES");
+ }
+ if( line.find("AUTO_RELOAD_STEP") != -1){
+ int value = parseIntFromLine( "AUTO_RELOAD_STEP", line);
+ if(value < 50) value = 50;
+ config.automatic_reload_step = value;
+ }
+ if( line.find("AUTO_RELOAD_TIME") != -1){
+ int value = parseIntFromLine( "AUTO_RELOAD_TIME", line);
+ if(value < 0) value = 0;
+ config.automatic_reload_time = value;
+ }
+ if( line.find("DEBUGMODE") != -1){
+ string result = parseStrFromLine( "DEBUGMODE", line );
+ config.debug_mode = (result == "YES");
+ }
+ if( line.find("LIFTSEGMENT") != -1){
+ int value = parseIntFromLine( "LIFTSEGMENT", line);
+ config.lift_segment_offscreen = value;
+ }
+ if( line.find("ANIMATION_RATE") != -1){
+ int value = parseIntFromLine( "ANIMATION_RATE", line );
+ if(value < 50) value = 50;
+ config.animation_step = value;
+ }
+ if( line.find("VERBOSE_LOGGING") != -1){
+ string result = parseStrFromLine( "VERBOSE_LOGGING", line );
+ config.verbose_logging = (result == "YES");
+ }
+ if( line.find("TRACK_CENTER") != -1){
+ string result = parseStrFromLine( "TRACK_CENTER", line );
+ config.track_center = (result == "YES");
+ }
if( line.find("FOLLOW_DF_SCREEN") != -1){
string result = parseStrFromLine( "FOLLOW_DF_SCREEN", line );
config.follow_DFscreen = (result == "YES");
@@ -131,26 +131,68 @@ void parseConfigLine( string line ){
string result = parseStrFromLine( "INTRO", line );
config.show_intro = !(result == "OFF");
}
-}
-
-
-bool loadConfigFile(){
- string line;
- ifstream myfile ("init.txt");
- if (myfile.is_open() == false)
- {
- cout << "Cannot find init file" << endl;
- return false;
+ if( line.find("FOG_RED") != -1){
+ int value = parseIntFromLine( "FOG_RED", line);
+ if(value > 255) value = 255;
+ if(value < 0) value = 0;
+ config.fogr = value;
+ }
+ if( line.find("FOG_GREEN") != -1){
+ int value = parseIntFromLine( "FOG_GREEN", line);
+ if(value > 255) value = 255;
+ if(value < 0) value = 0;
+ config.fogg = value;
+ }
+ if( line.find("FOG_BLUE") != -1){
+ int value = parseIntFromLine( "FOG_BLUE", line);
+ if(value > 255) value = 255;
+ if(value < 0) value = 0;
+ config.fogb = value;
+ }
+ if( line.find("FOG_ALPHA") != -1){
+ int value = parseIntFromLine( "FOG_ALPHA", line);
+ if(value > 255) value = 255;
+ if(value < 0) value = 0;
+ config.foga = value;
}
-
- while ( !myfile.eof() )
- {
- getline (myfile,line);
- cout << line << endl;
- parseConfigLine( line );
+ if( line.find("BACK_RED") != -1){
+ int value = parseIntFromLine( "BACK_RED", line);
+ if(value > 255) value = 255;
+ if(value < 0) value = 0;
+ config.backr = value;
}
- myfile.close();
-
-
- return true;
+ if( line.find("BACK_GREEN") != -1){
+ int value = parseIntFromLine( "BACK_GREEN", line);
+ if(value > 255) value = 255;
+ if(value < 0) value = 0;
+ config.backg = value;
+ }
+ if( line.find("BACK_BLUE") != -1){
+ int value = parseIntFromLine( "BACK_BLUE", line);
+ if(value > 255) value = 255;
+ if(value < 0) value = 0;
+ config.backb = value;
+ }
+}
+
+
+bool loadConfigFile(){
+ string line;
+ ifstream myfile ("init.txt");
+ if (myfile.is_open() == false)
+ {
+ cout << "Cannot find init file" << endl;
+ return false;
+ }
+
+ while ( !myfile.eof() )
+ {
+ getline (myfile,line);
+ cout << line << endl;
+ parseConfigLine( line );
+ }
+ myfile.close();
+
+
+ return true;
} \ No newline at end of file