mirror of
https://github.com/overte-org/overte.git
synced 2025-04-16 10:28:57 +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) {
|
||||
QString settingsFile(filename);
|
||||
QSettings settings(settingsFile, QSettings::IniFormat);
|
||||
QString rootCode = settings.value("root","").toString();
|
||||
QString rootCode = settings.value("root","00").toString();
|
||||
qDebug() << "rootCode=" << rootCode << "\n";
|
||||
|
||||
unsigned char* rootOctCode = hexStringToOctalCode(rootCode);
|
||||
printOctalCode(rootOctCode);
|
||||
_rootOctalCode = hexStringToOctalCode(rootCode);
|
||||
printOctalCode(_rootOctalCode);
|
||||
|
||||
settings.beginGroup("endNodes");
|
||||
const QStringList childKeys = settings.childKeys();
|
||||
|
@ -91,12 +91,15 @@ bool JurisdictionMap::writeToFile(const char* filename) {
|
|||
QString settingsFile(filename);
|
||||
QSettings settings(settingsFile, QSettings::IniFormat);
|
||||
|
||||
settings.setValue("root", "rootNodeValue");
|
||||
|
||||
QString rootNodeValue = octalCodeToHexString(_rootOctalCode);
|
||||
|
||||
settings.setValue("root", rootNodeValue);
|
||||
|
||||
settings.beginGroup("endNodes");
|
||||
for (int i = 0; i < _endNodes.size(); 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.endGroup();
|
||||
|
@ -104,23 +107,46 @@ bool JurisdictionMap::writeToFile(const char* filename) {
|
|||
}
|
||||
|
||||
|
||||
unsigned char* JurisdictionMap::hexStringToOctalCode(const QString& input) {
|
||||
// i variable used to hold position in string
|
||||
int i = 0;
|
||||
// x variable used to hold byte array element position
|
||||
int x = 0;
|
||||
unsigned char* JurisdictionMap::hexStringToOctalCode(const QString& input) const {
|
||||
const int HEX_NUMBER_BASE = 16;
|
||||
const int HEX_BYTE_SIZE = 2;
|
||||
int stringIndex = 0;
|
||||
int byteArrayIndex = 0;
|
||||
|
||||
// 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
|
||||
// it to decimal equivalent and store in byte array
|
||||
while (input.length() > i + 1) {
|
||||
|
||||
bool ok;
|
||||
uint value = input.mid(i, 2).toUInt(&ok,16);
|
||||
bytes[x] = (unsigned char)value;
|
||||
i += 2;
|
||||
x += 1;
|
||||
bool ok;
|
||||
while (stringIndex < input.length()) {
|
||||
uint value = input.mid(stringIndex, HEX_BYTE_SIZE).toUInt(&ok, HEX_NUMBER_BASE);
|
||||
if (!ok) {
|
||||
break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 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;
|
||||
|
|
|
@ -459,9 +459,9 @@ int main(int argc, const char * argv[]) {
|
|||
printf("after readFromFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
||||
|
||||
// test writing the file...
|
||||
//printf("about to writeToFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
||||
//jurisdiction->writeToFile(jurisdictionFile);
|
||||
//printf("after writeToFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
||||
printf("about to writeToFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
||||
jurisdiction->writeToFile(jurisdictionFile);
|
||||
printf("after writeToFile().... jurisdictionFile=%s\n", jurisdictionFile);
|
||||
}
|
||||
|
||||
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, listenPort);
|
||||
|
|
Loading…
Reference in a new issue