mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
instead of a json checkbox, a dropdown to chose the file type
This commit is contained in:
parent
ac882f86e2
commit
3bc85c2531
8 changed files with 44 additions and 62 deletions
|
@ -1036,12 +1036,12 @@ void OctreeServer::readConfiguration() {
|
|||
strcpy(_persistFilename, qPrintable(persistFilename));
|
||||
qDebug("persistFilename=%s", _persistFilename);
|
||||
|
||||
bool persistAsJson;
|
||||
if (!readOptionBool(QString("persistAsJson"), settingsSectionObject, persistAsJson)) {
|
||||
persistAsJson = false;
|
||||
QString persistAsFileType;
|
||||
if (!readOptionString(QString("persistAsFileType"), settingsSectionObject, persistAsFileType)) {
|
||||
persistAsFileType = "svo";
|
||||
}
|
||||
_persistAsJson = persistAsJson;
|
||||
qDebug() << "persistAsJson=" << _persistAsJson;
|
||||
_persistAsFileType = persistAsFileType;
|
||||
qDebug() << "persistAsFileType=" << _persistAsFileType;
|
||||
|
||||
_persistInterval = OctreePersistThread::DEFAULT_PERSIST_INTERVAL;
|
||||
readOptionInt(QString("persistInterval"), settingsSectionObject, _persistInterval);
|
||||
|
@ -1138,7 +1138,7 @@ void OctreeServer::run() {
|
|||
|
||||
// now set up PersistThread
|
||||
_persistThread = new OctreePersistThread(_tree, _persistFilename, _persistInterval,
|
||||
_wantBackup, _settings, _debugTimestampNow, _persistAsJson);
|
||||
_wantBackup, _settings, _debugTimestampNow, _persistAsFileType);
|
||||
if (_persistThread) {
|
||||
_persistThread->initialize(true);
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ protected:
|
|||
QString _statusHost;
|
||||
|
||||
char _persistFilename[MAX_FILENAME_LENGTH];
|
||||
bool _persistAsJson;
|
||||
QString _persistAsFileType;
|
||||
int _packetsPerClientPerInterval;
|
||||
int _packetsTotalPerInterval;
|
||||
Octree* _tree; // this IS a reaveraging tree
|
||||
|
|
|
@ -326,11 +326,21 @@
|
|||
"advanced": true
|
||||
},
|
||||
{
|
||||
"name": "persistAsJson",
|
||||
"type": "checkbox",
|
||||
"label": "Encode persist file as JSON:",
|
||||
"help": "Entity server will save entities as JSON rather than SVO",
|
||||
"default": false,
|
||||
"name": "persistAsFileType",
|
||||
"label": "File format for entity server's persistent data",
|
||||
"help": "This defines how the entity server will save entities to disk.",
|
||||
"default": "svo",
|
||||
"type": "select",
|
||||
"options": [
|
||||
{
|
||||
"value": "svo",
|
||||
"label": "Entity server persists data as SVO"
|
||||
},
|
||||
{
|
||||
"value": "json",
|
||||
"label": "Entity server persists data as JSON"
|
||||
}
|
||||
]
|
||||
"advanced": true
|
||||
},
|
||||
{
|
||||
|
|
|
@ -1848,21 +1848,16 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element,
|
|||
return bytesAtThisLevel;
|
||||
}
|
||||
|
||||
|
||||
bool Octree::readFromFile(const char* fileName) {
|
||||
bool fileOk = false;
|
||||
|
||||
QString qFileName = findMostRecentPersist(fileName);
|
||||
// QByteArray byteArray = qFileName.toUtf8();
|
||||
// const char* cFileName = byteArray.constData();
|
||||
|
||||
QFile file(qFileName);
|
||||
fileOk = file.open(QIODevice::ReadOnly);
|
||||
|
||||
QFileInfo fileInfo(qFileName);
|
||||
|
||||
if(fileOk) {
|
||||
QDataStream fileInputStream(&file);
|
||||
QFileInfo fileInfo(qFileName);
|
||||
unsigned long fileLength = fileInfo.size();
|
||||
|
||||
emit importSize(1.0f, 1.0f, 1.0f);
|
||||
|
@ -2057,38 +2052,30 @@ bool Octree::readSVOFromStream(unsigned long streamLength, QDataStream& inputStr
|
|||
}
|
||||
|
||||
bool Octree::readJSONFromStream(unsigned long streamLength, QDataStream& inputStream) {
|
||||
// QFile file;
|
||||
// file.setFileName("/tmp/ok.json");
|
||||
// file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
// QString val = file.readAll();
|
||||
// file.close();
|
||||
|
||||
char rawData[streamLength];
|
||||
inputStream.readRawData(rawData, streamLength);
|
||||
|
||||
// QJsonDocument d = QJsonDocument::fromJson(val.toUtf8());
|
||||
QJsonDocument d = QJsonDocument::fromJson(rawData);
|
||||
QVariant v = d.toVariant();
|
||||
QVariantMap m = v.toMap();
|
||||
|
||||
readFromMap(m);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Octree::writeToFile(const char* fileName, OctreeElement* element, bool persistAsJson) {
|
||||
if (persistAsJson) {
|
||||
// make the sure file extension is correct. This isn't great, but it allows a user with
|
||||
// an existing .svo save to migrate.
|
||||
QString qFileName = fileNameWithoutExtension(QString(fileName), persistExtensions) + ".json";
|
||||
QByteArray byteArray = qFileName.toUtf8();
|
||||
const char* cFileName = byteArray.constData();
|
||||
void Octree::writeToFile(const char* fileName, OctreeElement* element, QString persistAsFileType) {
|
||||
// make the sure file extension makes sense
|
||||
QString qFileName = fileNameWithoutExtension(QString(fileName), persistExtensions) + "." + persistAsFileType;
|
||||
QByteArray byteArray = qFileName.toUtf8();
|
||||
const char* cFileName = byteArray.constData();
|
||||
|
||||
if (persistAsFileType == "svo") {
|
||||
writeToSVOFile(fileName, element);
|
||||
} else if (persistAsFileType == "json") {
|
||||
writeToJSONFile(cFileName, element);
|
||||
} else {
|
||||
writeToSVOFile(fileName, element);
|
||||
qDebug() << "unable to write octree to file of type" << persistAsFileType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Octree::writeToJSONFile(const char* fileName, OctreeElement* element) {
|
||||
QFile persistFile(fileName);
|
||||
QVariantMap entityDescription;
|
||||
|
@ -2110,7 +2097,6 @@ void Octree::writeToJSONFile(const char* fileName, OctreeElement* element) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void Octree::writeToSVOFile(const char* fileName, OctreeElement* element) {
|
||||
std::ofstream file(fileName, std::ios::out|std::ios::binary);
|
||||
|
||||
|
|
|
@ -214,7 +214,6 @@ public:
|
|||
{}
|
||||
};
|
||||
|
||||
|
||||
class Octree : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -328,21 +327,19 @@ public:
|
|||
// Note: this assumes the fileFormat is the HIO individual voxels code files
|
||||
void loadOctreeFile(const char* fileName, bool wantColorRandomizer);
|
||||
|
||||
// these will read/write files that match the wireformat, excluding the 'V' leading
|
||||
void writeToFile(const char* filename, OctreeElement* element = NULL, bool persistAsJson = false);
|
||||
// Octree exporters
|
||||
void writeToFile(const char* filename, OctreeElement* element = NULL, QString persistAsFileType = "svo");
|
||||
void writeToJSONFile(const char* filename, OctreeElement* element = NULL);
|
||||
void writeToSVOFile(const char* filename, OctreeElement* element = NULL);
|
||||
virtual bool writeToMap(QVariantMap& entityDescription, OctreeElement* element) = 0;
|
||||
|
||||
|
||||
// Octree importers
|
||||
bool readFromFile(const char* filename);
|
||||
bool readFromURL(const QString& url); // will support file urls as well...
|
||||
|
||||
bool readFromStream(unsigned long streamLength, QDataStream& inputStream);
|
||||
bool readSVOFromStream(unsigned long streamLength, QDataStream& inputStream);
|
||||
bool readJSONFromStream(unsigned long streamLength, QDataStream& inputStream);
|
||||
|
||||
|
||||
virtual bool readFromMap(QVariantMap& entityDescription) = 0;
|
||||
|
||||
unsigned long getOctreeElementsCount();
|
||||
|
||||
|
@ -373,9 +370,6 @@ public:
|
|||
virtual void dumpTree() { };
|
||||
virtual void pruneTree() { };
|
||||
|
||||
|
||||
virtual bool readFromMap(QVariantMap& entityDescription) = 0;
|
||||
|
||||
signals:
|
||||
void importSize(float x, float y, float z);
|
||||
void importProgress(int progress);
|
||||
|
|
|
@ -49,10 +49,6 @@ public:
|
|||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class OctreeElement {
|
||||
|
||||
protected:
|
||||
|
|
|
@ -31,7 +31,7 @@ const int OctreePersistThread::DEFAULT_PERSIST_INTERVAL = 1000 * 30; // every 30
|
|||
|
||||
OctreePersistThread::OctreePersistThread(Octree* tree, const QString& filename, int persistInterval,
|
||||
bool wantBackup, const QJsonObject& settings, bool debugTimestampNow,
|
||||
bool persistAsJson) :
|
||||
QString persistAsFileType) :
|
||||
_tree(tree),
|
||||
_filename(filename),
|
||||
_persistInterval(persistInterval),
|
||||
|
@ -41,17 +41,13 @@ OctreePersistThread::OctreePersistThread(Octree* tree, const QString& filename,
|
|||
_wantBackup(wantBackup),
|
||||
_debugTimestampNow(debugTimestampNow),
|
||||
_lastTimeDebug(0),
|
||||
_persistAsJson(persistAsJson)
|
||||
_persistAsFileType(persistAsFileType)
|
||||
{
|
||||
parseSettings(settings);
|
||||
|
||||
// in case the persist filename has an extension that doesn't match the file type
|
||||
QString sansExt = fileNameWithoutExtension(_filename, persistExtensions);
|
||||
if (_persistAsJson) {
|
||||
_filename = sansExt + "." + "json";
|
||||
} else {
|
||||
_filename = sansExt + "." + "svo";
|
||||
}
|
||||
|
||||
_filename = sansExt + "." + _persistAsFileType;
|
||||
}
|
||||
|
||||
void OctreePersistThread::parseSettings(const QJsonObject& settings) {
|
||||
|
@ -253,7 +249,7 @@ void OctreePersistThread::persist() {
|
|||
if(lockFile.is_open()) {
|
||||
qDebug() << "saving Octree lock file created at:" << lockFileName;
|
||||
|
||||
_tree->writeToFile(qPrintable(_filename), NULL, _persistAsJson);
|
||||
_tree->writeToFile(qPrintable(_filename), NULL, _persistAsFileType);
|
||||
time(&_lastPersistTime);
|
||||
_tree->clearDirtyBit(); // tree is clean after saving
|
||||
qDebug() << "DONE saving Octree to file...";
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
|
||||
OctreePersistThread(Octree* tree, const QString& filename, int persistInterval = DEFAULT_PERSIST_INTERVAL,
|
||||
bool wantBackup = false, const QJsonObject& settings = QJsonObject(),
|
||||
bool debugTimestampNow = false, bool persistAsJson=false);
|
||||
bool debugTimestampNow = false, QString persistAsFileType="svo");
|
||||
|
||||
bool isInitialLoadComplete() const { return _initialLoadComplete; }
|
||||
quint64 getLoadElapsedTime() const { return _loadTimeUSecs; }
|
||||
|
@ -73,7 +73,7 @@ private:
|
|||
bool _debugTimestampNow;
|
||||
quint64 _lastTimeDebug;
|
||||
|
||||
bool _persistAsJson;
|
||||
QString _persistAsFileType;
|
||||
};
|
||||
|
||||
#endif // hifi_OctreePersistThread_h
|
||||
|
|
Loading…
Reference in a new issue