made updates to fix building

This commit is contained in:
utkarshgautamnyu 2017-09-28 11:12:26 -07:00
parent 290e3d307c
commit 463afd6be5
7 changed files with 77 additions and 80 deletions

View file

@ -50,9 +50,9 @@ static const int INTERFACE_RUNNING_CHECK_FREQUENCY_MS = 1000;
const QString ASSET_SERVER_LOGGING_TARGET_NAME = "asset-server";
static const QStringList BAKEABLE_MODEL_EXTENSIONS = {"fbx"};
static const QStringList BAKEABLE_MODEL_EXTENSIONS = { "fbx" };
static QStringList BAKEABLE_TEXTURE_EXTENSIONS;
static const QStringList BAKEABLE_SCRIPT_EXTENSIONS = {"js"};
static const QStringList BAKEABLE_SCRIPT_EXTENSIONS = { "js" };
static const QString BAKED_MODEL_SIMPLE_NAME = "asset.fbx";
static const QString BAKED_TEXTURE_SIMPLE_NAME = "texture.ktx";
static const QString BAKED_SCRIPT_SIMPLE_NAME = "asset.js";
@ -147,7 +147,7 @@ void AssetServer::maybeBake(const AssetPath& path, const AssetHash& hash) {
void AssetServer::createEmptyMetaFile(const AssetHash& hash) {
QString metaFilePath = "atp:/" + hash + "/meta.json";
QFile metaFile { metaFilePath };
QFile metaFile{ metaFilePath };
if (!metaFile.exists()) {
qDebug() << "Creating metafile for " << hash;
@ -205,7 +205,7 @@ bool interfaceRunning() {
bool result = false;
#ifdef Q_OS_WIN
QSharedMemory sharedMemory { getInterfaceSharedMemoryName() };
QSharedMemory sharedMemory{ getInterfaceSharedMemoryName() };
result = sharedMemory.attach(QSharedMemory::ReadOnly);
if (result) {
sharedMemory.detach();
@ -235,8 +235,7 @@ void updateConsumedCores() {
AssetServer::AssetServer(ReceivedMessage& message) :
ThreadedAssignment(message),
_transferTaskPool(this),
_bakingTaskPool(this)
{
_bakingTaskPool(this) {
// store the current state of image compression so we can reset it when this assignment is complete
_wasColorTextureCompressionEnabled = image::isColorTexturesCompressionEnabled();
_wasGrayscaleTextureCompressionEnabled = image::isGrayscaleTexturesCompressionEnabled();
@ -287,7 +286,7 @@ void AssetServer::aboutToFinish() {
// abort each of our still running bake tasks, remove pending bakes that were never put on the thread pool
auto it = _pendingBakes.begin();
while (it != _pendingBakes.end()) {
auto pendingRunnable = _bakingTaskPool.tryTake(it->get());
auto pendingRunnable = _bakingTaskPool.tryTake(it->get());
if (pendingRunnable) {
it = _pendingBakes.erase(it);
@ -348,7 +347,7 @@ void AssetServer::completeSetup() {
int maxBandwidth = maxBandwidthFloat * BITS_PER_MEGABITS;
nodeList->setConnectionMaxBandwidth(maxBandwidth);
qCInfo(asset_server) << "Set maximum bandwith per connection to" << maxBandwidthFloat << "Mb/s."
" (" << maxBandwidth << "bits/s)";
" (" << maxBandwidth << "bits/s)";
}
// get the path to the asset folder from the domain server settings
@ -362,7 +361,7 @@ void AssetServer::completeSetup() {
}
auto assetsPathString = assetsJSONValue.toString();
QDir assetsPath { assetsPathString };
QDir assetsPath{ assetsPathString };
QString absoluteFilePath = assetsPath.absolutePath();
if (assetsPath.isRelative()) {
@ -390,7 +389,7 @@ void AssetServer::completeSetup() {
// Check the asset directory to output some information about what we have
auto files = _filesDirectory.entryList(QDir::Files);
QRegExp hashFileRegex { ASSET_HASH_REGEX_STRING };
QRegExp hashFileRegex{ ASSET_HASH_REGEX_STRING };
auto hashedFiles = files.filter(hashFileRegex);
qCInfo(asset_server) << "There are" << hashedFiles.size() << "asset files in the asset directory.";
@ -409,7 +408,7 @@ void AssetServer::completeSetup() {
}
void AssetServer::cleanupUnmappedFiles() {
QRegExp hashFileRegex { "^[a-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}" };
QRegExp hashFileRegex{ "^[a-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}" };
auto files = _filesDirectory.entryInfoList(QDir::Files);
@ -418,7 +417,7 @@ void AssetServer::cleanupUnmappedFiles() {
for (const auto& fileInfo : files) {
auto filename = fileInfo.fileName();
if (hashFileRegex.exactMatch(filename)) {
bool matched { false };
bool matched{ false };
for (auto& pair : _fileMappings) {
if (pair.second == filename) {
matched = true;
@ -427,7 +426,7 @@ void AssetServer::cleanupUnmappedFiles() {
}
if (!matched) {
// remove the unmapped file
QFile removeableFile { fileInfo.absoluteFilePath() };
QFile removeableFile{ fileInfo.absoluteFilePath() };
if (removeableFile.remove()) {
qCDebug(asset_server) << "\tDeleted" << filename << "from asset files directory since it is unmapped.";
@ -479,7 +478,7 @@ void AssetServer::handleAssetMappingOperation(QSharedPointer<ReceivedMessage> me
void AssetServer::handleGetMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket) {
QString assetPath = message.readString();
QUrl url { assetPath };
QUrl url{ assetPath };
assetPath = url.path();
auto it = _fileMappings.find(assetPath);
@ -562,7 +561,7 @@ void AssetServer::handleGetAllMappingOperation(ReceivedMessage& message, SharedN
replyPacket.writePrimitive(count);
for (auto it = _fileMappings.cbegin(); it != _fileMappings.cend(); ++ it) {
for (auto it = _fileMappings.cbegin(); it != _fileMappings.cend(); ++it) {
auto mapping = it->first;
auto hash = it->second;
replyPacket.writeString(mapping);
@ -603,7 +602,7 @@ void AssetServer::handleSetMappingOperation(ReceivedMessage& message, SharedNode
void AssetServer::handleDeleteMappingsOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket) {
if (senderNode->getCanWriteToAssetServer()) {
int numberOfDeletedMappings { 0 };
int numberOfDeletedMappings{ 0 };
message.readPrimitive(&numberOfDeletedMappings);
QStringList mappingsToDelete;
@ -653,7 +652,7 @@ void AssetServer::handleRenameMappingOperation(ReceivedMessage& message, SharedN
void AssetServer::handleSetBakingEnabledOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket) {
if (senderNode->getCanWriteToAssetServer()) {
bool enabled { true };
bool enabled{ true };
message.readPrimitive(&enabled);
int numberOfMappings{ 0 };
@ -696,7 +695,7 @@ void AssetServer::handleAssetGetInfo(QSharedPointer<ReceivedMessage> message, Sh
replyPacket->write(assetHash);
QString fileName = QString(hexHash);
QFileInfo fileInfo { _filesDirectory.filePath(fileName) };
QFileInfo fileInfo{ _filesDirectory.filePath(fileName) };
if (fileInfo.exists() && fileInfo.isReadable()) {
qCDebug(asset_server) << "Opening file: " << fileInfo.filePath();
@ -827,7 +826,7 @@ bool AssetServer::loadMappingsFromFile() {
auto mapFilePath = _resourcesDirectory.absoluteFilePath(MAP_FILE_NAME);
QFile mapFile { mapFilePath };
QFile mapFile{ mapFilePath };
if (mapFile.exists()) {
if (mapFile.open(QIODevice::ReadOnly)) {
QJsonParseError error;
@ -883,7 +882,7 @@ bool AssetServer::loadMappingsFromFile() {
bool AssetServer::writeMappingsToFile() {
auto mapFilePath = _resourcesDirectory.absoluteFilePath(MAP_FILE_NAME);
QFile mapFile { mapFilePath };
QFile mapFile{ mapFilePath };
if (mapFile.open(QIODevice::WriteOnly)) {
QJsonObject root;
@ -891,7 +890,7 @@ bool AssetServer::writeMappingsToFile() {
root[it.first] = it.second;
}
QJsonDocument jsonDocument { root };
QJsonDocument jsonDocument{ root };
if (mapFile.write(jsonDocument.toJson()) != -1) {
qCDebug(asset_server) << "Wrote JSON mappings to file at" << mapFilePath;
@ -955,7 +954,7 @@ void AssetServer::removeBakedPathsForDeletedAsset(AssetHash hash) {
// check if we had baked content for that file that should also now be removed
// by calling deleteMappings for the hidden baked content folder for this hash
AssetPathList hiddenBakedFolder { HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" };
AssetPathList hiddenBakedFolder{ HIDDEN_BAKED_CONTENT_FOLDER + hash + "/" };
qCDebug(asset_server) << "Deleting baked content below" << hiddenBakedFolder << "since" << hash << "was deleted";
@ -1026,7 +1025,7 @@ bool AssetServer::deleteMappings(const AssetPathList& paths) {
// we now have a set of hashes that are unmapped - we will delete those asset files
for (auto& hash : hashesToCheckForDeletion) {
// remove the unmapped file
QFile removeableFile { _filesDirectory.absoluteFilePath(hash) };
QFile removeableFile{ _filesDirectory.absoluteFilePath(hash) };
if (removeableFile.remove()) {
qCDebug(asset_server) << "\tDeleted" << hash << "from asset files directory since it is now unmapped.";
@ -1173,7 +1172,7 @@ void AssetServer::handleFailedBake(QString originalAssetHash, QString assetPath,
}
void AssetServer::handleCompletedBake(QString originalAssetHash, QString originalAssetPath, QVector<QString> bakedFilePaths) {
bool errorCompletingBake { false };
bool errorCompletingBake{ false };
QString errorReason;
qDebug() << "Completing bake for " << originalAssetHash;
@ -1272,7 +1271,7 @@ std::pair<bool, AssetMeta> AssetServer::readMetaFile(AssetHash hash) {
auto it = _fileMappings.find(metaFilePath);
if (it == _fileMappings.end()) {
return { false, {} };
return { false,{} };
}
auto metaFileHash = it->second;
@ -1309,7 +1308,7 @@ std::pair<bool, AssetMeta> AssetServer::readMetaFile(AssetHash hash) {
}
}
return { false, {} };
return { false,{} };
}
bool AssetServer::writeMetaFile(AssetHash originalAssetHash, const AssetMeta& meta) {

View file

@ -20,8 +20,7 @@
BakeAssetTask::BakeAssetTask(const AssetHash& assetHash, const AssetPath& assetPath, const QString& filePath) :
_assetHash(assetHash),
_assetPath(assetPath),
_filePath(filePath)
{
_filePath(filePath) {
}
@ -32,7 +31,7 @@ void BakeAssetTask::run() {
TextureBakerThreadGetter fn = []() -> QThread* { return QThread::currentThread(); };
if (_assetPath.endsWith(".fbx")) {
_baker = std::unique_ptr<FBXBaker> {
_baker = std::unique_ptr<FBXBaker>{
new FBXBaker(QUrl("file:///" + _filePath), fn, PathUtils::generateTemporaryDir())
};
} else if (_assetPath.endsWith(".js", Qt::CaseInsensitive)) {
@ -40,9 +39,9 @@ void BakeAssetTask::run() {
new JSBaker(QUrl("file:///" + _filePath), PathUtils::generateTemporaryDir())
};
} else {
_baker = std::unique_ptr<TextureBaker> {
_baker = std::unique_ptr<TextureBaker>{
new TextureBaker(QUrl("file:///" + _filePath), image::TextureUsage::CUBE_TEXTURE,
PathUtils::generateTemporaryDir())
PathUtils::generateTemporaryDir())
};
}

View file

@ -18,8 +18,7 @@ const int ASCII_CHARACTERS_UPPER_LIMIT = 126;
JSBaker::JSBaker(const QUrl& jsURL, const QString& bakedOutputDir) :
_jsURL(jsURL),
_bakedOutputDir(bakedOutputDir)
{
_bakedOutputDir(bakedOutputDir) {
};
@ -71,7 +70,7 @@ void JSBaker::bake() {
bool JSBaker::bakeJS(const QByteArray* inputFile, QByteArray* outputFile) {
// Read from inputFile and write to outputFile per character
QTextStream in(*inputFile,QIODevice::ReadOnly);
QTextStream in(*inputFile, QIODevice::ReadOnly);
QTextStream out(outputFile, QIODevice::WriteOnly);
// Algorithm requires the knowledge of previous and next character for each character read
@ -200,14 +199,14 @@ bool JSBaker::handleMultiLineComments(QTextStream* in) {
bool JSBaker::canOmitSpace(QChar previousCharacter, QChar nextCharacter) {
return(!((isAlphanum(previousCharacter) || isNonAscii(previousCharacter) || isSpecialCharacter(previousCharacter)) &&
(isAlphanum(nextCharacter) || isNonAscii(nextCharacter) || isSpecialCharacter(nextCharacter)))
);
(isAlphanum(nextCharacter) || isNonAscii(nextCharacter) || isSpecialCharacter(nextCharacter)))
);
}
bool JSBaker::canOmitNewLine(QChar previousCharacter, QChar nextCharacter) {
return (!((isAlphanum(previousCharacter) || isNonAscii(previousCharacter) || isSpecialCharacterPrevious(previousCharacter)) &&
(isAlphanum(nextCharacter) || isNonAscii(nextCharacter) || isSpecialCharacterNext(nextCharacter)))
);
(isAlphanum(nextCharacter) || isNonAscii(nextCharacter) || isSpecialCharacterNext(nextCharacter)))
);
}
//Check if character is alphabet, number or one of the following: '_', '$', '\\' or a non-ASCII character

View file

@ -22,13 +22,13 @@ class JSBaker : public Baker {
public:
JSBaker(const QUrl& jsURL, const QString& bakedOutputDir);
public slots:
public slots:
virtual void bake() override;
public:
static bool bakeJS(const QByteArray* inputFile, QByteArray* outputFile);
private :
private:
QUrl _jsURL;
QString _bakedOutputDir;
QString _bakedJSFilePath;

View file

@ -23,7 +23,7 @@ void JSBakerTest::setTestCases() {
_testCases.emplace_back("var a = 1;", "var a=1;"); // Multiple spaces omitted
_testCases.emplace_back("var a= 1;", "var a=1;"); // Multiple tabs omitted
// Cases for space not omitted
// Cases for space not omitted
_testCases.emplace_back("var x", "var x");
_testCases.emplace_back("a '", "a '");
_testCases.emplace_back("a $", "a $");
@ -42,7 +42,7 @@ void JSBakerTest::setTestCases() {
_testCases.emplace_back("a\n\n b", "a\nb"); // Skip multiple new lines followed by whitespace
_testCases.emplace_back("a\n\n b", "a\nb"); // Skip multiple new lines followed by tab
//Cases for new line not omitted
//Cases for new line not omitted
_testCases.emplace_back("a\nb", "a\nb");
_testCases.emplace_back("a\n9", "a\n9");
_testCases.emplace_back("9\na", "9\na");

View file

@ -15,10 +15,10 @@
#include <QtTest/QtTest>
#include "../../libraries/baking/src/JSBaker.h"
class JSBakerTest: public QObject {
class JSBakerTest : public QObject {
Q_OBJECT
private slots:
private slots:
void setTestCases();
void testJSBaking();