[go: up one dir, main page]

Menu

[r25]: / CSettings.cpp  Maximize  Restore  History

Download this file

133 lines (108 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "main.h"
CSettings::CSettings(CLog* logger) {
current_keymap_id=0;
log = logger;
// <Default settings>
key_screenshot = KEY_F11; //TODO: In-game config
memcpy(&screenshot_ext, &".jpg", MAX_EXT); //TODO: In-game config
anaglyph_eye_dist = 0.01f;
camera_draw_distance_min = 0.5f;
camera_draw_distance_max = 5000.f; //TODO: In-game config
fullscreen = false; //TODO: In-game config
widescreen = false; //TODO: In-game config
resolution = dimension2d<u32>(800, 600); //TODO: In-game config
anaglyph = false; //TODO: In-game config
// </Default settings>
DriverType = EDT_COUNT;
}
CSettings::~CSettings() {
}
int CSettings::AddKeyMap(EKEY_ACTION action, EKEY_CODE key) {
keyMap[current_keymap_id].Action = action;
keyMap[current_keymap_id].KeyCode = key;
return current_keymap_id++;
}
//TODO: Load&save keyMap
void CSettings::save(const path &filename) {
IrrlichtDevice *device = createDevice(EDT_NULL);
log->info("SETT", "Saving settings...");
IFileSystem* filesystem = device->getFileSystem();
IXMLWriter* file = filesystem->createXMLWriter(filename);
file->writeXMLHeader();
file->writeElement(L"config", false);
file->writeLineBreak();
stringw typestr((int)DriverType);
file->writeElement(L"device", true, L"type", typestr.c_str());
file->writeLineBreak();
stringw scrkeystr((int)key_screenshot);
stringw scrext(screenshot_ext);
file->writeElement(L"screenshot", true, L"key", scrkeystr.c_str(), L"ext", scrext.c_str());
file->writeLineBreak();
stringw anaglyphdist(anaglyph_eye_dist);
stringw anaglyphenable(false); //TODO: Anaglyph enable in config
file->writeElement(L"anaglyph", true, L"enabled", anaglyphenable.c_str(), L"eyedist", anaglyphdist.c_str());
file->writeLineBreak();
stringw drawmin(camera_draw_distance_min);
stringw drawmax(camera_draw_distance_max);
file->writeElement(L"drawdist", true, L"min", drawmin.c_str(), L"max", drawmax.c_str());
file->writeLineBreak();
stringw scrfull(fullscreen);
stringw scrwide(widescreen);
stringw scrwidth(resolution.Width);
stringw scrheight(resolution.Height);
file->writeElement(L"screen", true, L"fullscreen", scrfull.c_str(), L"widescreen", scrwide.c_str(), L"width", scrwidth.c_str(), L"height", scrheight.c_str());
file->writeLineBreak();
file->writeClosingTag(L"config");
file->writeLineBreak();
file->drop();
log->info("SETT", "Settings saved!");
device->drop();
}
bool CSettings::load(const path &filename) {
IrrlichtDevice *device = createDevice(EDT_NULL);
log->info("SETT", "Loading settings...");
IXMLReader* file = device->getFileSystem()->createXMLReader(filename);
if(!file) {
log->error(0, "SETT", "Failed to open file.");
return false;
}
bool tagConfigOpened = false;
while(file && file->read()) {
if(core::stringw("config") == file->getNodeName()) {
if(file->getNodeType() == EXN_ELEMENT) tagConfigOpened = true;
else if(file->getNodeType() == EXN_ELEMENT_END) tagConfigOpened = false;
continue;
}
if(tagConfigOpened) {
if(core::stringw("device") == file->getNodeName()) {
DriverType = (E_DRIVER_TYPE)(file->getAttributeValueAsInt(L"type"));
continue;
}
if(core::stringw("screenshot") == file->getNodeName()) {
key_screenshot = (EKEY_CODE)(file->getAttributeValueAsInt(L"key"));
memcpy(&screenshot_ext, file->getAttributeValueSafe(L"ext"), MAX_EXT);
continue;
}
if(core::stringw("anaglyph") == file->getNodeName()) {
anaglyph = (bool)(file->getAttributeValueAsInt(L"enabled"));
anaglyph_eye_dist = file->getAttributeValueAsFloat(L"eyedist");
continue;
}
if(core::stringw("drawdist") == file->getNodeName()) {
camera_draw_distance_min = file->getAttributeValueAsFloat(L"min");
camera_draw_distance_max = file->getAttributeValueAsFloat(L"max");
continue;
}
if(core::stringw("screen") == file->getNodeName()) {
fullscreen = (bool)(file->getAttributeValueAsInt(L"fullscreen"));
widescreen = (bool)(file->getAttributeValueAsInt(L"widescreen"));
resolution = dimension2d<u32>(file->getAttributeValueAsInt(L"width"), file->getAttributeValueAsInt(L"height"));
continue;
}
}
}
file->drop();
log->info("SETT", "Settings loaded!");
device->drop();
return true;
}