Commit 853d4b4c by NTAuthority

clang-format _all_ the things!

parent a01166fa
Pipeline #81 skipped
......@@ -13,7 +13,7 @@ void PrintWarning(const char* format, ...);
void PrintError(const char* format, ...);
// NOT thread-safe!
void AddPrintListener(void(*function)(const char*));
void AddPrintListener(void (*function)(const char*));
}
namespace sys
......
#pragma once
#include <Console.h>
#include <Console.Commands.h>
#include <Console.h>
namespace krt
{
class ConsoleCommand
{
private:
private:
int m_token;
ConsoleCommandManager* m_manager;
public:
public:
template <typename TFunction>
ConsoleCommand(const std::string& name, TFunction function)
: ConsoleCommand(ConsoleCommandManager::GetDefaultInstance(), name, function)
{
}
template<typename TFunction>
template <typename TFunction>
ConsoleCommand(console::Context* context, const std::string& name, TFunction function)
: ConsoleCommand(context->GetCommandManager(), name, function)
: ConsoleCommand(context->GetCommandManager(), name, function)
{
}
template <typename TFunction>
......
......@@ -19,7 +19,7 @@ namespace krt
{
namespace console
{
class Context;
class Context;
}
// console execution context
......@@ -36,10 +36,10 @@ struct ConsoleExecutionContext
class ConsoleCommandManager
{
private:
private:
using THandler = std::function<bool(ConsoleExecutionContext& context)>;
public:
public:
ConsoleCommandManager(console::Context* context);
~ConsoleCommandManager();
......@@ -54,7 +54,7 @@ class ConsoleCommandManager
void ForAllCommands(const std::function<void(const std::string&)>& callback);
private:
private:
struct Entry
{
std::string name;
......@@ -68,7 +68,7 @@ class ConsoleCommandManager
}
};
private:
private:
console::Context* m_parentContext;
std::multimap<std::string, Entry, IgnoreCaseLess> m_entries;
......@@ -77,16 +77,16 @@ class ConsoleCommandManager
std::atomic<int> m_curToken;
public:
public:
static ConsoleCommandManager* GetDefaultInstance();
};
template <typename TArgument, typename TConstraint = void>
struct ConsoleArgumentTraits
{
using Less = std::less<TArgument>;
using Less = std::less<TArgument>;
using Greater = std::greater<TArgument>;
using Equal = std::equal_to<TArgument>;
using Equal = std::equal_to<TArgument>;
};
template <typename TArgument, typename TConstraint = void>
......@@ -137,55 +137,55 @@ struct ConsoleArgumentName<std::string>
};
template <typename TArgument>
struct ConsoleArgumentType <TArgument, typename std::enable_if <std::is_same <TArgument, bool>::value>::type>
struct ConsoleArgumentType<TArgument, typename std::enable_if<std::is_same<TArgument, bool>::value>::type>
{
static std::string Unparse( const TArgument& input )
{
if ( input == true )
{
return "true";
}
else
{
return "false";
}
}
static bool Parse( const std::string& input, TArgument *out )
{
const char *inputPtr = input.c_str();
bool retBool = false;
if ( _stricmp( inputPtr, "TRUE" ) == 0 )
{
retBool = true;
}
else if ( _stricmp( inputPtr, "FALSE" ) == 0 )
{
retBool = false;
}
else
{
// If the boolean declaration is not a recognized string, then just check whether its integral.
try
{
retBool = ( std::stoull( input ) != 0 );
}
catch( ... )
{
// Just do nothing.
// Assume that the best default is already written to retBool.
}
}
*out = retBool;
return true;
}
static std::string Unparse(const TArgument& input)
{
if (input == true)
{
return "true";
}
else
{
return "false";
}
}
static bool Parse(const std::string& input, TArgument* out)
{
const char* inputPtr = input.c_str();
bool retBool = false;
if (_stricmp(inputPtr, "TRUE") == 0)
{
retBool = true;
}
else if (_stricmp(inputPtr, "FALSE") == 0)
{
retBool = false;
}
else
{
// If the boolean declaration is not a recognized string, then just check whether its integral.
try
{
retBool = (std::stoull(input) != 0);
}
catch (...)
{
// Just do nothing.
// Assume that the best default is already written to retBool.
}
}
*out = retBool;
return true;
}
};
template <typename TArgument>
struct ConsoleArgumentType<TArgument, std::enable_if_t<std::is_integral<TArgument>::value && !std::is_same<TArgument,bool>::value>>
struct ConsoleArgumentType<TArgument, std::enable_if_t<std::is_integral<TArgument>::value && !std::is_same<TArgument, bool>::value>>
{
static std::string Unparse(const TArgument& input)
{
......
#pragma once
#include <Console.h>
#include <Console.Variables.h>
#include <Console.h>
namespace krt
{
......@@ -16,40 +16,35 @@ private:
public:
ConVar(const std::string& name, int flags, const TVariable& defaultValue)
: ConVar(ConsoleVariableManager::GetDefaultInstance(), name, flags, defaultValue, nullptr)
: ConVar(ConsoleVariableManager::GetDefaultInstance(), name, flags, defaultValue, nullptr)
{
}
ConVar(console::Context* context, const std::string& name, int flags, const TVariable& defaultValue)
: ConVar(context->GetVariableManager(), name, flags, defaultValue, nullptr)
: ConVar(context->GetVariableManager(), name, flags, defaultValue, nullptr)
{
}
ConVar(ConsoleVariableManager* manager, const std::string& name, int flags, const TVariable& defaultValue)
: ConVar(manager, name, flags, defaultValue, nullptr)
: ConVar(manager, name, flags, defaultValue, nullptr)
{
}
ConVar(const std::string& name, int flags, const TVariable& defaultValue, TVariable* trackingVar)
: ConVar(ConsoleVariableManager::GetDefaultInstance(), name, flags, defaultValue, trackingVar)
: ConVar(ConsoleVariableManager::GetDefaultInstance(), name, flags, defaultValue, trackingVar)
{
}
ConVar(console::Context* context, const std::string& name, int flags, const TVariable& defaultValue, TVariable* trackingVar)
: ConVar(context->GetVariableManager(), name, flags, defaultValue, trackingVar)
: ConVar(context->GetVariableManager(), name, flags, defaultValue, trackingVar)
{
}
ConVar(ConsoleVariableManager* manager, const std::string& name, int flags, const TVariable& defaultValue, TVariable* trackingVar)
: m_manager(manager)
: m_manager(manager)
{
m_helper = CreateVariableEntry<TVariable>(manager, name, defaultValue);
m_token = m_manager->Register(name, flags, m_helper);
m_token = m_manager->Register(name, flags, m_helper);
if (trackingVar)
{
......
#pragma once
#include <Console.Commands.h>
#include <Console.CommandHelpers.h>
#include <Console.Commands.h>
namespace krt
{
......@@ -15,7 +15,7 @@ public:
virtual bool SetValue(const std::string& value) = 0;
};
template<typename T, typename TConstraint = void>
template <typename T, typename TConstraint = void>
struct Constraints
{
inline static bool Compare(const T& value, const T& minValue, const T& maxValue)
......@@ -24,7 +24,7 @@ struct Constraints
}
};
template<typename T>
template <typename T>
struct Constraints<T, std::enable_if_t<std::is_arithmetic<T>::value>>
{
inline static bool Compare(const T& value, const T& minValue, const T& maxValue)
......@@ -47,20 +47,18 @@ struct Constraints<T, std::enable_if_t<std::is_arithmetic<T>::value>>
void MarkConsoleVarModified(ConsoleVariableManager* manager, const std::string& name);
template<typename T>
template <typename T>
class ConsoleVariableEntry : public ConsoleVariableEntryBase
{
public:
ConsoleVariableEntry(ConsoleVariableManager* manager, const std::string& name, const T& defaultValue)
: m_manager(manager), m_name(name), m_trackingVar(nullptr), m_defaultValue(defaultValue), m_curValue(defaultValue), m_hasConstraints(false)
: m_manager(manager), m_name(name), m_trackingVar(nullptr), m_defaultValue(defaultValue), m_curValue(defaultValue), m_hasConstraints(false)
{
m_getCommand = std::make_unique<ConsoleCommand>(manager->GetParentContext(), name, [=] ()
{
m_getCommand = std::make_unique<ConsoleCommand>(manager->GetParentContext(), name, [=]() {
console::Printf(" \"%s\" is \"%s\"\n default: \"%s\"\n type: %s\n", name.c_str(), GetValue().c_str(), UnparseArgument(m_defaultValue).c_str(), ConsoleArgumentName<T>::Get());
});
m_setCommand = std::make_unique<ConsoleCommand>(manager->GetParentContext(), name, [=] (const T& newValue)
{
m_setCommand = std::make_unique<ConsoleCommand>(manager->GetParentContext(), name, [=](const T& newValue) {
SetRawValue(newValue);
});
}
......@@ -161,8 +159,8 @@ private:
enum ConsoleVariableFlags
{
ConVar_None = 0,
ConVar_Archive = 0x1,
ConVar_None = 0,
ConVar_Archive = 0x1,
ConVar_Modified = 2
};
......@@ -187,7 +185,7 @@ public:
bool Process(const std::string& commandName, const ProgramArguments& arguments);
THandlerPtr FindEntryRaw(const std::string& name);
void AddEntryFlags(const std::string& name, int flags);
void RemoveEntryFlags(const std::string& name, int flags);
......@@ -205,7 +203,7 @@ private:
struct Entry
{
std::string name;
int flags;
THandlerPtr variable;
......@@ -213,7 +211,7 @@ private:
int token;
inline Entry(const std::string& name, int flags, const THandlerPtr& variable, int token)
: name(name), flags(flags), variable(variable), token(token)
: name(name), flags(flags), variable(variable), token(token)
{
}
};
......@@ -237,7 +235,7 @@ public:
static ConsoleVariableManager* GetDefaultInstance();
};
template<typename TValue>
template <typename TValue>
static std::shared_ptr<internal::ConsoleVariableEntry<TValue>> CreateVariableEntry(ConsoleVariableManager* manager, const std::string& name, const TValue& defaultValue)
{
ConsoleVariableManager::THandlerPtr oldEntry = manager->FindEntryRaw(name);
......
......@@ -9,7 +9,7 @@ namespace krt
{
namespace console
{
static std::vector<void(*)(const char*)> g_printListeners;
static std::vector<void (*)(const char*)> g_printListeners;
static int g_useDeveloper;
void Printf(const char* format, ...)
......@@ -18,7 +18,7 @@ void Printf(const char* format, ...)
static thread_local std::vector<char> buffer(32768);
va_list ap;
va_start(ap, format);
vsnprintf(&buffer[0], buffer.size(), format, ap);
va_end(ap);
......@@ -90,7 +90,7 @@ void PrintError(const char* format, ...)
Printf("^1Error: %s^7", buffer.data());
}
void AddPrintListener(void(*function)(const char*))
void AddPrintListener(void (*function)(const char*))
{
g_printListeners.push_back(function);
}
......
#include <StdInc.h>
#include <Console.h>
#include <Console.Commands.h>
#include <Console.h>
#include <utils/IteratorView.h>
#include <utils/LockUtil.h>
......@@ -8,7 +8,7 @@
namespace krt
{
ConsoleCommandManager::ConsoleCommandManager(console::Context* parentContext)
: m_parentContext(parentContext), m_curToken(0)
: m_parentContext(parentContext), m_curToken(0)
{
}
......@@ -21,7 +21,7 @@ int ConsoleCommandManager::Register(const std::string& name, const THandler& han
auto lock = exclusive_lock_acquire<std::shared_timed_mutex>(m_mutex);
int token = m_curToken.fetch_add(1);
m_entries.insert({ name, Entry{name, handler, token} });
m_entries.insert({name, Entry{name, handler, token}});
return token;
}
......@@ -45,7 +45,7 @@ void ConsoleCommandManager::Unregister(int token)
void ConsoleCommandManager::Invoke(const std::string& commandString)
{
ProgramArguments arguments = console::Tokenize(commandString);
std::string command = arguments.Shift();
std::string command = arguments.Shift();
return Invoke(command, arguments);
}
......
#include <StdInc.h>
#include <vfs/Manager.h>
#include <Console.CommandHelpers.h>
#include <vfs/Manager.h>
namespace krt
{
static ConsoleCommand execCommand("exec", [] (const std::string& path)
{
static ConsoleCommand execCommand("exec", [](const std::string& path) {
vfs::StreamPtr stream = vfs::OpenRead(path);
if (!stream)
......
#include <StdInc.h>
#include <Console.h>
#include <Console.Variables.h>
#include <Console.h>
namespace krt
{
ConsoleVariableManager::ConsoleVariableManager(console::Context* parentContext)
: m_parentContext(parentContext), m_curToken(0)
: m_parentContext(parentContext), m_curToken(0)
{
auto setCommand = [=] (bool archive, const std::string& variable, const std::string& value)
{
auto setCommand = [=](bool archive, const std::string& variable, const std::string& value) {
// weird order is to prevent recursive locking
{
Entry* entry = nullptr;
......@@ -50,14 +49,12 @@ ConsoleVariableManager::ConsoleVariableManager(console::Context* parentContext)
Register(variable, flags, entry);
};
m_setCommand = std::make_unique<ConsoleCommand>(m_parentContext, "set", [=] (const std::string& variable, const std::string& value)
{
m_setCommand = std::make_unique<ConsoleCommand>(m_parentContext, "set", [=](const std::string& variable, const std::string& value) {
setCommand(false, variable, value);
});
// set archived
m_setaCommand = std::make_unique<ConsoleCommand>(m_parentContext, "seta", [=] (const std::string& variable, const std::string& value)
{
m_setaCommand = std::make_unique<ConsoleCommand>(m_parentContext, "seta", [=](const std::string& variable, const std::string& value) {
setCommand(true, variable, value);
});
}
......@@ -85,7 +82,7 @@ int ConsoleVariableManager::Register(const std::string& name, int flags, const T
int token = m_curToken.fetch_add(1);
m_entries.erase(name); // remove any existing entry
m_entries.insert({ name, Entry{name, flags, variable, token} });
m_entries.insert({name, Entry{name, flags, variable, token}});
return token;
}
......@@ -159,10 +156,10 @@ void ConsoleVariableManager::ForAllVariables(const TVariableCB& callback, int fl
void ConsoleVariableManager::SaveConfiguration(const TWriteLineCB& writeLineFunction)
{
ForAllVariables([&] (const std::string& name, int flags, const THandlerPtr& variable)
{
ForAllVariables([&](const std::string& name, int flags, const THandlerPtr& variable) {
writeLineFunction("seta \"" + name + "\" \"" + variable->GetValue() + "\"");
}, ConVar_Archive);
},
ConVar_Archive);
}
bool ConsoleVariableManager::Process(const std::string& commandName, const ProgramArguments& arguments)
......
#include <StdInc.h>
#include <Console.h>
#include <Console.Commands.h>
#include <Console.Variables.h>
#include <Console.h>
#include <KeyBinding.h>
......@@ -23,18 +23,17 @@ struct ConsoleManagers : public ConsoleManagersBase
};
Context::Context()
: Context(GetDefaultContext())
: Context(GetDefaultContext())
{
}
Context::Context(Context* fallbackContext)
: m_fallbackContext(fallbackContext)
: m_fallbackContext(fallbackContext)
{
m_managers = std::make_unique<ConsoleManagers>();
ConsoleManagers* managers = static_cast<ConsoleManagers*>(m_managers.get());
managers->commandManager = std::make_unique<ConsoleCommandManager>(this);
managers->commandManager = std::make_unique<ConsoleCommandManager>(this);
managers->variableManager = std::make_unique<ConsoleVariableManager>(this);
if (m_fallbackContext == nullptr)
......@@ -104,7 +103,7 @@ void Context::ExecuteBuffer()
while (m_commandBuffer.length() > 0)
{
// parse the command up to the first occurrence of a newline/semicolon
int i = 0;
int i = 0;
bool inQuote = false;
size_t cbufLength = m_commandBuffer.length();
......@@ -161,9 +160,8 @@ static void SaveConfiguration(const std::string& path, ConsoleVariableManager* v
if (handle != INVALID_DEVICE_HANDLE)
{
auto writeLine = [&] (const std::string& line)
{
const char newLine[] = { '\r', '\n' };
auto writeLine = [&](const std::string& line) {
const char newLine[] = {'\r', '\n'};
device->Write(handle, line.c_str(), line.size());
device->Write(handle, newLine, sizeof(newLine));
......@@ -210,8 +208,7 @@ Context* GetDefaultContext()
static std::unique_ptr<Context> defaultContext;
static std::once_flag flag;
std::call_once(flag, [] ()
{
std::call_once(flag, []() {
// nullptr is important - we don't have ourselves to fall back on!
defaultContext = std::make_unique<Context>(nullptr);
});
......@@ -277,7 +274,7 @@ ProgramArguments Tokenize(const std::string& line)
// return if needed
if (i >= lineLength)
{
return ProgramArguments{ args };
return ProgramArguments{args};
}
// allegedly fixes issues with parsing
......@@ -289,7 +286,7 @@ ProgramArguments Tokenize(const std::string& line)
// skip comments
if ((line[i] == '/' && line[i + 1] == '/') || line[i] == '#') // full line is a comment
{
return ProgramArguments{ args };
return ProgramArguments{args};
}
// /* comments
......@@ -302,7 +299,7 @@ ProgramArguments Tokenize(const std::string& line)
if (i >= lineLength)
{
return ProgramArguments{ args };
return ProgramArguments{args};
}
i += 2;
......@@ -353,7 +350,7 @@ ProgramArguments Tokenize(const std::string& line)
if (i >= lineLength)
{
return ProgramArguments{ args };
return ProgramArguments{args};
}
continue;
......@@ -372,7 +369,7 @@ ProgramArguments Tokenize(const std::string& line)
{
if (line[i] == '#')
{
return ProgramArguments{ args };
return ProgramArguments{args};
}
}
......@@ -380,12 +377,12 @@ ProgramArguments Tokenize(const std::string& line)
{
if ((line[i] == '/' && line[i + 1] == '/'))
{
return ProgramArguments{ args };
return ProgramArguments{args};
}
if (line[i] == '/' && line[i + 1] == '*')
{
return ProgramArguments{ args };
return ProgramArguments{args};
}
}
......@@ -404,7 +401,7 @@ ProgramArguments Tokenize(const std::string& line)
if (i >= lineLength)
{
return ProgramArguments{ args };
return ProgramArguments{args};
}
}
}
......
......@@ -4,8 +4,6 @@
#undef DrawText
#endif
#include <fonts/Rect.h>
#include <fonts/RGBA.h>
#include <fonts/FontRendererAbstract.h>
namespace krt
......
#pragma once
#include "RGBA.h"
#include "FontRendererAllocator.h"
#include <fonts/Rect.h>
#include <fonts/RGBA.h>
namespace krt
{
enum class FontRendererTextureFormat
......@@ -27,11 +29,10 @@ struct FontRendererVertex : public FrpUseSequentialAllocator
FontRendererVertex()
{
}
FontRendererVertex(float x, float y, float u, float v, RGBA color)
: x(x), y(y), u(u), v(v), color(color)
: x(x), y(y), u(u), v(v), color(color)
{
}
};
......@@ -61,6 +62,6 @@ public:
virtual void UnsetTexture() = 0;
virtual void InvokeOnRender(void(*cb)(void*), void* arg) = 0;
virtual void InvokeOnRender(void (*cb)(void*), void* arg) = 0;
};
}
\ No newline at end of file
......@@ -21,7 +21,7 @@ public:
virtual void DrawIndexedVertices(int numVertices, int numIndices, FontRendererVertex* vertex, uint16_t* indices) override;
virtual void InvokeOnRender(void(*cb)(void*), void* arg) override;
virtual void InvokeOnRender(void (*cb)(void*), void* arg) override;
virtual void DrawRectangles(int numRectangles, const ResultingRectangle* rectangles) override;
......@@ -33,9 +33,8 @@ class KrtFontTexture : public FontRendererTexture
{
public:
KrtFontTexture(rw::Texture* texture)
: m_texture(texture)
: m_texture(texture)
{
}
~KrtFontTexture()
......@@ -50,14 +49,13 @@ private:
};
KrtGameInterface::KrtGameInterface(GameWindow* gameWindow)
: m_gameWindow(gameWindow)
: m_gameWindow(gameWindow)
{
}
FontRendererTexture* KrtGameInterface::CreateTexture(int width, int height, FontRendererTextureFormat format, void* pixelData)
{
rw::Raster* raster = rw::Raster::create(width, height, 32, 0x80, rw::PLATFORM_D3D9);
rw::Raster* raster = rw::Raster::create(width, height, 32, 0x80, rw::PLATFORM_D3D9);
rw::d3d::D3dRaster* ras = PLUGINOFFSET(rw::d3d::D3dRaster, raster, rw::d3d::nativeRasterOffset);
rw::d3d::allocateDXT(raster, 5, 1, true);
ras->customFormat = true;
......@@ -98,9 +96,9 @@ void KrtGameInterface::SetTexture(FontRendererTexture* texture)
rw::Matrix projMatrix;
projMatrix.setIdentity();
projMatrix.right = rw::V3d(2.0f / width, 0.0f, 0.0f);