Permalink
Browse files

style junk

  • Loading branch information...
rt
rt committed Nov 17, 2018
1 parent 6e2a739 commit 28391fb730c022954ec3f6ba8aa1a9416cf858a1
@@ -1300,10 +1300,9 @@ int LuaUtils::Log(lua_State* L)
const char* section = luaL_checkstring(L, 1);
int loglevel = LuaUtils::ParseLogLevel(L, 2);
if (loglevel < 0) {
const int loglevel = LuaUtils::ParseLogLevel(L, 2);
if (loglevel < 0)
return luaL_error(L, "Incorrect arguments to Spring.Log(logsection, loglevel, ...)");
}
LogMsg(L, section, loglevel, 3);
return 0;
@@ -68,24 +68,20 @@ CInfoTextureCombiner::CInfoTextureCombiner()
void CInfoTextureCombiner::SwitchMode(const std::string& name)
{
if (name.empty()) {
curMode = name;
disabled = true;
CreateShader("", true);
CreateShader(curMode = "", true);
return;
}
// WTF? fully reloaded from disk on every switch?
if (name == "los") {
disabled = !CreateShader("shaders/GLSL/infoLOS.lua", true, float4(0.5f, 0.5f, 0.5f, 1.0f));
} else if (name == "metal") {
disabled = !CreateShader("shaders/GLSL/infoMetal.lua", true, float4(0.f, 0.f, 0.f, 1.0f));
} else if (name == "height") {
disabled = !CreateShader("shaders/GLSL/infoHeight.lua");
} else if (name == "path") {
disabled = !CreateShader("shaders/GLSL/infoPath.lua");
} else {
//FIXME allow "info:myluainfotex"
disabled = !CreateShader(name);
// TODO: allow "info:myluainfotex"
switch (hashString(name.c_str())) {
case hashString("los" ): { disabled = !CreateShader("shaders/GLSL/infoLOS.lua" , true, float4(0.5f, 0.5f, 0.5f, 1.0f)); } break;
case hashString("metal" ): { disabled = !CreateShader("shaders/GLSL/infoMetal.lua" , true, float4(0.0f, 0.0f, 0.0f, 1.0f)); } break;
case hashString("height"): { disabled = !CreateShader("shaders/GLSL/infoHeight.lua" ); } break;
case hashString("path" ): { disabled = !CreateShader("shaders/GLSL/infoPath.lua" ); } break;
default : { disabled = !CreateShader(name ); } break;
}
curMode = (disabled) ? "" : name;
@@ -6,18 +6,11 @@
#include <array>
#include <string>
#include "Archives/ArchiveTypes.h"
class IArchive;
class IArchiveFactory;
enum {
ARCHIVE_TYPE_SDP = 0, // pool
ARCHIVE_TYPE_SDD = 1, // dir
ARCHIVE_TYPE_SDZ = 2, // zip
ARCHIVE_TYPE_SD7 = 3, // 7zip
ARCHIVE_TYPE_SDV = 4, // virtual
ARCHIVE_TYPE_CNT = 5,
};
/**
* Engine side interface for loading of different archive types.
* This loader is responsible for offering access to different archive types,
@@ -51,7 +51,7 @@ LOG_REGISTER_SECTION_GLOBAL(LOG_SECTION_ARCHIVESCANNER)
* but mapping them all, every time to make the list is)
*/
constexpr int INTERNAL_VER = 15;
constexpr static int INTERNAL_VER = 15;
/*
@@ -665,27 +665,25 @@ void CArchiveScanner::ScanArchive(const std::string& fullName, bool doChecksum)
std::string error;
std::string arMapFile; // file in archive with "smf" extension
std::string miMapFile; // value for the 'mapfile' key parsed from mapinfo
std::string luaInfoFile;
const bool hasModinfo = ar->FileExists("modinfo.lua");
const bool hasMapinfo = ar->FileExists("mapinfo.lua");
const bool hasModInfo = ar->FileExists("modinfo.lua");
const bool hasMapInfo = ar->FileExists("mapinfo.lua");
ArchiveInfo ai;
ArchiveData& ad = ai.archiveData;
std::string archiveDataName;
// execute the respective .lua, otherwise assume this archive is a map
if (hasMapinfo) {
archiveDataName = "mapinfo.lua";
ScanArchiveLua(ar.get(), archiveDataName, ai, error);
if (hasMapInfo) {
ScanArchiveLua(ar.get(), luaInfoFile = "mapinfo.lua", ai, error);
if ((miMapFile = ad.GetMapFile()).empty()) {
LOG_L(L_WARNING, "[AS::%s] set the 'mapfile' key in mapinfo.lua of archive \"%s\" for faster loading!", __func__, fullName.c_str());
arMapFile = SearchMapFile(ar.get(), error);
}
} else if (hasModinfo) {
archiveDataName = "modinfo.lua";
ScanArchiveLua(ar.get(), archiveDataName, ai, error);
} else if (hasModInfo) {
ScanArchiveLua(ar.get(), luaInfoFile = "modinfo.lua", ai, error);
} else {
arMapFile = SearchMapFile(ar.get(), error);
}
@@ -707,7 +705,7 @@ void CArchiveScanner::ScanArchive(const std::string& fullName, bool doChecksum)
return;
}
if (hasMapinfo || !arMapFile.empty()) {
if (hasMapInfo || !arMapFile.empty()) {
// map archive
// FIXME: name will never be empty if version is set (see HACK in ArchiveData)
if ((ad.GetName()).empty()) {
@@ -722,7 +720,7 @@ void CArchiveScanner::ScanArchive(const std::string& fullName, bool doChecksum)
ad.SetInfoItemValueInteger("modType", modtype::map);
LOG_S(LOG_SECTION_ARCHIVESCANNER, "Found new map: %s", ad.GetNameVersioned().c_str());
} else if (hasModinfo) {
} else if (hasModInfo) {
// game or base-type (cursors, bitmaps, ...) archive
// babysitting like this is really no longer required
if (ad.IsGame() || ad.IsMenu())
@@ -731,18 +729,18 @@ void CArchiveScanner::ScanArchive(const std::string& fullName, bool doChecksum)
LOG_S(LOG_SECTION_ARCHIVESCANNER, "Found new game: %s", ad.GetNameVersioned().c_str());
} else {
// neither a map nor a mod: error
// FIXME: This seems pointless: error is not used and there is no return or throw??
error = "missing modinfo.lua/mapinfo.lua";
LOG_S(LOG_SECTION_ARCHIVESCANNER, "missing modinfo.lua/mapinfo.lua");
}
ai.path = fpath;
ai.modified = modifiedTime;
// Store modinfo.lua/mapinfo.lua modified timestamp for directory archives, as only they can change.
const auto dirArchive = dynamic_cast<const CDirArchive*>(ar.get());
if (dirArchive != nullptr && !archiveDataName.empty()) {
ai.archiveDataPath = ar->GetArchiveFile() + "/" + dirArchive->GetOrigFileName(dirArchive->FindFile(archiveDataName));
if (ar->GetType() == ARCHIVE_TYPE_SDD && !luaInfoFile.empty()) {
ai.archiveDataPath = ar->GetArchiveFile() + "/" + static_cast<const CDirArchive*>(ar.get())->GetOrigFileName(ar->FindFile(luaInfoFile));
ai.modifiedArchiveData = FileSystemAbstraction::GetFileModificationTime(ai.archiveDataPath);
}
ai.origName = fn;
ai.updated = true;
ai.hashed = doChecksum && GetArchiveChecksum(fullName, ai);
@@ -760,41 +758,39 @@ bool CArchiveScanner::CheckCachedData(const std::string& fullName, unsigned& mod
if ((modified = FileSystemAbstraction::GetFileModificationTime(fullName)) == 0)
return false;
const std::string& fn = FileSystem::GetFilename(fullName);
const std::string& fpath = FileSystem::GetDirectory(fullName);
const std::string& lcfn = StringToLower(fn);
const std::string& fileName = FileSystem::GetFilename(fullName);
const std::string& filePath = FileSystem::GetDirectory(fullName);
const std::string& fileNameLower = StringToLower(fileName);
// Determine whether this archive has earlier be found to be broken
auto baIter = brokenArchivesIndex.find(lcfn);
const auto baIter = brokenArchivesIndex.find(fileNameLower);
const auto aiIter = archiveInfosIndex.find(fileNameLower);
// Determine whether this archive has earlier be found to be broken
if (baIter != brokenArchivesIndex.end()) {
BrokenArchive& ba = brokenArchives[baIter->second];
if (modified == ba.modified && fpath == ba.path)
if (modified == ba.modified && filePath == ba.path)
return (ba.updated = true);
}
// Determine whether to rely on the cached info or not
const auto aiIter = archiveInfosIndex.find(lcfn);
if (aiIter == archiveInfosIndex.end())
return false;
ArchiveInfo& ai = archiveInfos[aiIter->second];
ArchiveInfo& ai = archiveInfos[aiIter->second];
ArchiveInfo& rai = archiveInfos[archiveInfos.size() - 1];
// This archive may have been obsoleted, do not process it if so
if (!ai.replaced.empty())
return true;
bool archiveDataChanged = false;
const bool haveValidCacheData = (modified == ai.modified && filePath == ai.path);
// Check if the archive data file (modinfo.lua/mapinfo.lua) has changed
if (!ai.archiveDataPath.empty())
archiveDataChanged = (FileSystemAbstraction::GetFileModificationTime(ai.archiveDataPath) != ai.modifiedArchiveData);
const bool archiveDataChanged = (!ai.archiveDataPath.empty() && FileSystemAbstraction::GetFileModificationTime(ai.archiveDataPath) != ai.modifiedArchiveData);
if (modified == ai.modified && fpath == ai.path && !archiveDataChanged) {
if (haveValidCacheData && !archiveDataChanged) {
// archive found in cache, update checksum if wanted
// this also has to flag isDirty or ArchiveCache will
// not be rewritten even if the hash silently changed,
@@ -815,22 +811,22 @@ bool CArchiveScanner::CheckCachedData(const std::string& fullName, unsigned& mod
throw user_error(
std::string("duplicate base content detected:\n\t") + ai.path +
std::string("\n\t") + fpath +
std::string("\n\t") + filePath +
std::string("\nPlease fix your configuration/installation as this can cause desyncs!"));
}
// If we are here, we could have invalid info in the cache
// Force a reread if it is a directory archive (.sdd), as
// st_mtime only reflects changes to the directory itself,
// not the contents.
const std::string& relcfn = StringToLower(archiveInfos[archiveInfos.size() - 1].origName);
ai = std::move(archiveInfos[archiveInfos.size() - 1]);
//
// remap replacement archive
if (aiIter->second != (archiveInfos.size() - 1)) {
archiveInfosIndex[StringToLower(rai.origName)] = aiIter->second;
archiveInfos[aiIter->second] = std::move(rai);
}
// remap
archiveInfosIndex.erase(relcfn);
archiveInfosIndex.insert(relcfn, aiIter->second);
archiveInfosIndex.erase(lcfn);
archiveInfosIndex.erase(fileNameLower);
archiveInfos.pop_back();
return false;
}
@@ -160,11 +160,12 @@ class CArchiveScanner
memset(checksum, 0, sizeof(checksum));
}
std::string path; // FileSystem::GetDirectory(origName)
std::string origName; // non-lowercased name
std::string replaced; // if not empty, use this archive instead
std::string path; // FileSystem::GetDirectory(origName)
std::string origName; // non-lowercased name
std::string replaced; // if not empty, use this archive instead
std::string archiveDataPath; // path to {mod,map}info.lua for .sdd's
ArchiveData archiveData;
std::string archiveDataPath;
uint32_t modified = 0;
uint32_t modifiedArchiveData = 0;
@@ -0,0 +1,17 @@
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef _ARCHIVE_TYPES_H
#define _ARCHIVE_TYPES_H
enum {
ARCHIVE_TYPE_SDP = 0, // pool
ARCHIVE_TYPE_SDD = 1, // dir
ARCHIVE_TYPE_SDZ = 2, // zip
ARCHIVE_TYPE_SD7 = 3, // 7zip
ARCHIVE_TYPE_SDV = 4, // virtual
ARCHIVE_TYPE_CNT = 5,
ARCHIVE_TYPE_BUF = 6, // buffered, not created directly
};
#endif
@@ -22,6 +22,8 @@ class CBufferedArchive : public IArchive
virtual ~CBufferedArchive();
virtual int GetType() const override { return ARCHIVE_TYPE_BUF; }
bool GetFile(unsigned int fid, std::vector<std::uint8_t>& buffer) override;
protected:
@@ -31,6 +31,8 @@ class CDirArchive : public IArchive
public:
CDirArchive(const std::string& archiveName);
int GetType() const override { return ARCHIVE_TYPE_SDD; }
bool IsOpen() override { return true; }
unsigned int NumFiles() const override { return (searchFiles.size()); }
@@ -7,6 +7,7 @@
#include <vector>
#include <cinttypes>
#include "ArchiveTypes.h"
#include "System/Sync/SHA512.hpp"
#include "System/UnorderedMap.hpp"
@@ -27,6 +28,8 @@ class IArchive
public:
virtual ~IArchive() {}
virtual int GetType() const = 0;
virtual bool IsOpen() = 0;
const std::string& GetArchiveFile() const { return archiveFile; }
@@ -78,6 +78,8 @@ class CPoolArchive : public CBufferedArchive
CPoolArchive(const std::string& name);
~CPoolArchive();
int GetType() const override { return ARCHIVE_TYPE_SDP; }
bool IsOpen() override { return isOpen; }
unsigned NumFiles() const override { return (files.size()); }
@@ -36,6 +36,8 @@ class CSevenZipArchive : public CBufferedArchive
CSevenZipArchive(const std::string& name);
virtual ~CSevenZipArchive();
int GetType() const override { return ARCHIVE_TYPE_SD7; }
bool IsOpen() override;
unsigned int NumFiles() const override;
@@ -64,6 +64,8 @@ class CVirtualArchiveOpen : public IArchive
public:
CVirtualArchiveOpen(CVirtualArchive* archive, const std::string& fileName);
int GetType() const override { return ARCHIVE_TYPE_SDV; }
// virtual archives are stored in memory and as such always open
bool IsOpen() override { return true; }
unsigned int NumFiles() const override;
@@ -33,6 +33,8 @@ class CZipArchive : public CBufferedArchive
CZipArchive(const std::string& archiveName);
virtual ~CZipArchive();
int GetType() const override { return ARCHIVE_TYPE_SDZ; }
bool IsOpen() override;
unsigned int NumFiles() const override;

0 comments on commit 28391fb

Please sign in to comment.