mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 19:50:38 +02:00
writing jurisdiction map configs
This commit is contained in:
parent
81a363f053
commit
f57d86ddb2
3 changed files with 51 additions and 24 deletions
|
@ -64,11 +64,11 @@ bool JurisdictionMap::isMyJurisdiction(VoxelNode* node, int childIndex) const {
|
||||||
bool JurisdictionMap::readFromFile(const char* filename) {
|
bool JurisdictionMap::readFromFile(const char* filename) {
|
||||||
QString settingsFile(filename);
|
QString settingsFile(filename);
|
||||||
QSettings settings(settingsFile, QSettings::IniFormat);
|
QSettings settings(settingsFile, QSettings::IniFormat);
|
||||||
QString rootCode = settings.value("root","").toString();
|
QString rootCode = settings.value("root","00").toString();
|
||||||
qDebug() << "rootCode=" << rootCode << "\n";
|
qDebug() << "rootCode=" << rootCode << "\n";
|
||||||
|
|
||||||
unsigned char* rootOctCode = hexStringToOctalCode(rootCode);
|
_rootOctalCode = hexStringToOctalCode(rootCode);
|
||||||
printOctalCode(rootOctCode);
|
printOctalCode(_rootOctalCode);
|
||||||
|
|
||||||
settings.beginGroup("endNodes");
|
settings.beginGroup("endNodes");
|
||||||
const QStringList childKeys = settings.childKeys();
|
const QStringList childKeys = settings.childKeys();
|
||||||
|
@ -91,12 +91,15 @@ bool JurisdictionMap::writeToFile(const char* filename) {
|
||||||
QString settingsFile(filename);
|
QString settingsFile(filename);
|
||||||
QSettings settings(settingsFile, QSettings::IniFormat);
|
QSettings settings(settingsFile, QSettings::IniFormat);
|
||||||
|
|
||||||
settings.setValue("root", "rootNodeValue");
|
|
||||||
|
QString rootNodeValue = octalCodeToHexString(_rootOctalCode);
|
||||||
|
|
||||||
|
settings.setValue("root", rootNodeValue);
|
||||||
|
|
||||||
settings.beginGroup("endNodes");
|
settings.beginGroup("endNodes");
|
||||||
for (int i = 0; i < _endNodes.size(); i++) {
|
for (int i = 0; i < _endNodes.size(); i++) {
|
||||||
QString key = QString("endnode%1").arg(i);
|
QString key = QString("endnode%1").arg(i);
|
||||||
QString value = QString("valuenode%1").arg(i);
|
QString value = octalCodeToHexString(_endNodes[i]);
|
||||||
settings.setValue(key, value);
|
settings.setValue(key, value);
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
@ -104,23 +107,46 @@ bool JurisdictionMap::writeToFile(const char* filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned char* JurisdictionMap::hexStringToOctalCode(const QString& input) {
|
unsigned char* JurisdictionMap::hexStringToOctalCode(const QString& input) const {
|
||||||
// i variable used to hold position in string
|
const int HEX_NUMBER_BASE = 16;
|
||||||
int i = 0;
|
const int HEX_BYTE_SIZE = 2;
|
||||||
// x variable used to hold byte array element position
|
int stringIndex = 0;
|
||||||
int x = 0;
|
int byteArrayIndex = 0;
|
||||||
|
|
||||||
// allocate byte array based on half of string length
|
// allocate byte array based on half of string length
|
||||||
unsigned char* bytes = new unsigned char[(input.length()) / 2];
|
unsigned char* bytes = new unsigned char[(input.length()) / HEX_BYTE_SIZE];
|
||||||
|
|
||||||
// loop through the string - 2 bytes at a time converting
|
// loop through the string - 2 bytes at a time converting
|
||||||
// it to decimal equivalent and store in byte array
|
// it to decimal equivalent and store in byte array
|
||||||
while (input.length() > i + 1) {
|
bool ok;
|
||||||
|
while (stringIndex < input.length()) {
|
||||||
bool ok;
|
uint value = input.mid(stringIndex, HEX_BYTE_SIZE).toUInt(&ok, HEX_NUMBER_BASE);
|
||||||
uint value = input.mid(i, 2).toUInt(&ok,16);
|
if (!ok) {
|
||||||
bytes[x] = (unsigned char)value;
|
break;
|
||||||
i += 2;
|
}
|
||||||
x += 1;
|
bytes[byteArrayIndex] = (unsigned char)value;
|
||||||
|
stringIndex += HEX_BYTE_SIZE;
|
||||||
|
byteArrayIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// something went wrong
|
||||||
|
if (!ok) {
|
||||||
|
delete[] bytes;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
// return the finished byte array of decimal values
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString JurisdictionMap::octalCodeToHexString(unsigned char* octalCode) const {
|
||||||
|
const int HEX_NUMBER_BASE = 16;
|
||||||
|
const int HEX_BYTE_SIZE = 2;
|
||||||
|
QString output;
|
||||||
|
if (!octalCode) {
|
||||||
|
output = "00";
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < bytesRequiredForCodeLength(*octalCode); i++) {
|
||||||
|
output.append(QString("%1").arg(octalCode[i], HEX_BYTE_SIZE, HEX_NUMBER_BASE, QChar('0')).toUpper());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,8 @@ private:
|
||||||
void clear();
|
void clear();
|
||||||
void init(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes);
|
void init(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes);
|
||||||
|
|
||||||
unsigned char* hexStringToOctalCode(const QString& input);
|
unsigned char* hexStringToOctalCode(const QString& input) const;
|
||||||
|
QString octalCodeToHexString(unsigned char* octalCode) const;
|
||||||
|
|
||||||
|
|
||||||
unsigned char* _rootOctalCode;
|
unsigned char* _rootOctalCode;
|
||||||
|
|
|
@ -459,9 +459,9 @@ int main(int argc, const char * argv[]) {
|
||||||
printf("after readFromFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
printf("after readFromFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
||||||
|
|
||||||
// test writing the file...
|
// test writing the file...
|
||||||
//printf("about to writeToFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
printf("about to writeToFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
||||||
//jurisdiction->writeToFile(jurisdictionFile);
|
jurisdiction->writeToFile(jurisdictionFile);
|
||||||
//printf("after writeToFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
printf("after writeToFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, listenPort);
|
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, listenPort);
|
||||||
|
|
Loading…
Reference in a new issue