00001
00002
00003
00004
00005
00006
00011 #include "Configuration.h"
00012 #include "Message.h"
00013 #include "Camera.h"
00014 #include "Opengl.h"
00015 #include "Window.h"
00016
00017 Configuration ourConfiguration;
00018
00022 Configuration::Configuration():showMenu(1),showOptionMenu(0),constructMode(0),
00023 speed(1),speedType(SECOND),linearScaleFactor(1.0),freezeAnimation(1),
00024 viewVectors(1),viewToObjectsFlightDirection(0),followObject(0),
00025 radiusAdaption(1),autoAdaption(0),movelike3Dshooter(1),showLighting(1),
00026 showTextures(1),viewModel(2),drawOldPositionsTimeSteps(30),drawOldPositions(1),sphereDetaillevel(10),clickedObject(0) {
00027 strcpy(filename,"space");
00028 integrator = Integrator::createIntegrator("RungeKuttaAdaptive");
00029 }
00030
00036 void Configuration::saveWorld(const string & filename, bool use_extensions) {
00037 string _name;
00038 if(use_extensions) {
00039 _name="save/";
00040 _name+=filename;
00041 _name+=FILE_EXTENSION;
00042 } else
00043 _name = filename;
00044
00045
00046 Message::msg(Message::MSG, "saveWorld ", _name);
00047
00048 ofstream FILE(_name.c_str());
00049 if(FILE.fail() ) {
00050 Message::msg(Message::ERROR, "FILE ", _name, " COULD NOT BE WRITTEN" );
00051 return;
00052 }
00053
00054
00055 ourConfiguration.saveConfiguration(FILE);
00056 ourCamera.saveCamera(FILE);
00057 ourObjectManager.save(FILE);
00058 FILE.close();
00059 }
00060
00066 void Configuration::loadWorld(const string & filename, bool use_extensions) {
00067
00068
00069 Message::clearMessages();
00070
00071
00072 Opengl::setAnimation(false);
00073
00074 string _name;
00075 if(use_extensions) {
00076 _name="save/";
00077 _name+=filename;
00078 _name+=FILE_EXTENSION;
00079 } else
00080 _name = filename;
00081
00082
00083 Message::msg(Message::MSG, "loadWorld ", _name);
00084 ifstream FILE(_name.c_str());
00085 if(FILE.fail() ) {
00086 Message::msg(Message::ERROR, "FILE ", _name, " COULD NOT BE READ" );
00087 return;
00088 }
00089
00090
00091 if(ourConfiguration.clickedObject != NULL) {
00092 Object::closeAttributeWindow();
00093 ourConfiguration.clickedObject = NULL;
00094 }
00095
00096
00097 ourConfiguration.loadConfiguration(FILE);
00098 ourCamera.loadCamera(FILE);
00099 ourObjectManager.load(FILE);
00100 FILE.close();
00101
00102 Window::load();
00103 Window::showMenu();
00104 }
00105
00111 double Configuration::getTime() {
00112 double multiplier=1.0;
00113 switch(ourConfiguration.speedType) {
00114 case(Configuration::SECOND):
00115 break;
00116 case(Configuration::HOUR):
00117 multiplier=3600;
00118 break;
00119 case(Configuration::DAY):
00120 multiplier=3600*24;
00121 break;
00122 case(Configuration::MONTH):
00123 multiplier=3600*24*30;
00124 break;
00125 case(Configuration::YEAR):
00126 multiplier=3600*24*365;
00127 break;
00128 }
00129 return speed * multiplier;
00130 }
00131
00136 void Configuration::saveConfiguration(ostream & FILE) {
00137 FILE << "!!BEGINCONFIGURATION!!" << endl;
00138 FILE << "0 speed: " << speed << endl;
00139 FILE << "1 radiusAdaption: " << radiusAdaption << endl;
00140 FILE << "2 freezeAnimation: " << freezeAnimation << endl;
00141 FILE << "3 viewVectors: " << viewVectors << endl;
00142 FILE << "4 viewToObjectsFlightDirection: " <<
00143 viewToObjectsFlightDirection << endl;
00144 FILE << "5 followObject: " << followObject << endl;
00145 FILE << "7 showMenue: " << showMenu << endl;
00146 FILE << "8 movelike3Dshooter: " << movelike3Dshooter << endl;
00147 FILE << "9 viewModel: " << viewModel << endl;
00148 FILE << "10 showLighting: " << showLighting << endl;
00149 FILE << "11 showTextures: " << showTextures << endl;
00150 FILE << "12 constructMode: " << constructMode << endl;
00151 FILE << "13 SphereDetaillevel: " << sphereDetaillevel << endl;
00152 FILE << "15 integrator: " << integrator->getName() << endl;
00153 FILE << "16 cameraSaveSlot: " << cameraSaveSlot << endl;
00154 FILE << "17 linearScaleFactor: " << linearScaleFactor << endl;
00155 FILE << "18 autoAdaption: " << autoAdaption << endl;
00156 FILE << "19 speedType: " << speedType << endl;
00157 FILE << "20 drawOldPositions: " << drawOldPositions << endl;
00158 FILE << "21 drawOldPositionTimeSteps: " << drawOldPositionsTimeSteps << endl;
00159
00160 FILE << "1000 !!END CONFIGURATION!!"<< endl;
00161 integrator->save(FILE);
00162 }
00163
00168 void Configuration::loadConfiguration(istream & FILE) {
00169 Integrator::closeAttributeWindow();
00170
00171 int option_=0;
00172 string s;
00173 while (! FILE.fail() ) {
00174 FILE >> s;
00175 if(s == "!!BEGINCONFIGURATION!!")
00176 break;
00177 }
00178 while (! FILE.fail() ) {
00179 FILE >> option_ >> s;
00180 switch(option_) {
00181 case 0:
00182 FILE >> speed;
00183 break;
00184 case 1:
00185 FILE >> radiusAdaption;
00186 break;
00187 case 2:
00188 FILE >> freezeAnimation;
00189 freezeAnimation = 1;
00190 break;
00191 case 3:
00192 FILE >> viewVectors;
00193 break;
00194 case 4:
00195 FILE >> viewToObjectsFlightDirection;
00196 break;
00197 case 5:
00198 FILE >> followObject;
00199 break;
00200 case 7:
00201 FILE >> showMenu;
00202 break;
00203 case 8:
00204 FILE >> movelike3Dshooter;
00205 break;
00206 case 9:
00207 FILE >> viewModel;
00208 break;
00209 case 10:
00210 FILE >> showLighting;
00211 break;
00212 case 11:
00213 FILE >> showTextures;
00214 break;
00215 case 12:
00216 FILE >> constructMode;
00217 break;
00218 case 13:
00219 FILE >> sphereDetaillevel;
00220 break;
00221 case 15:
00222 FILE >> s;
00223 integrator = Integrator::createIntegrator(s);
00224 break;
00225 case 16:
00226 FILE >> cameraSaveSlot;
00227 break;
00228 case 17:
00229 FILE >> linearScaleFactor;
00230 break;
00231 case 18:
00232 FILE >> autoAdaption;
00233 break;
00234 case 19:
00235 FILE >> speedType;
00236 break;
00237 case 20:
00238 FILE >> drawOldPositions;
00239 break;
00240 case 21:
00241 FILE >> drawOldPositionsTimeSteps;
00242 break;
00243 case 1000:
00244 integrator->load(FILE);
00245 return;
00246 default:
00247 cerr << "WARNUNG unbekannte option " << option_ << " " << s <<
00248 " gelesen" << endl;
00249 FILE >> s;
00250 }
00251 }
00252 }