mirror of
https://github.com/UberGames/rpgxEF.git
synced 2025-04-19 07:21:12 +00:00
Started adding some new common types
- started adding some new common types - removed some unused files - added some missing files to ui project - added a unit test runner - added some unit tests
This commit is contained in:
parent
79dff5963f
commit
37f1a0edd9
22 changed files with 4237 additions and 2157 deletions
26
code/common_game/Position2D.h
Normal file
26
code/common_game/Position2D.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Common
|
||||
{
|
||||
namespace Detail
|
||||
{
|
||||
template<typename T>
|
||||
class Position2DImpl
|
||||
{
|
||||
public:
|
||||
T& X() { return m_Coords[0]; }
|
||||
T& Y() { return m_Coords[1]; }
|
||||
const T& X() const { return m_Coords[0]; }
|
||||
const T& Y() const { return m_Coords[1]; }
|
||||
T& operator[](size_t Index) { return Index >= 1 ? m_Coords[1] : m_Coords[0]; }
|
||||
const T& operator[](size_t Index) const { return Index >= 1 ? m_Coords[1] : m_Coords[0]; }
|
||||
|
||||
protected:
|
||||
T m_Coords[2] = { 0, 0 };
|
||||
};
|
||||
}
|
||||
|
||||
using Position2D = Detail::Position2DImpl<int32_t>;
|
||||
}
|
368
code/common_game/String.cpp
Normal file
368
code/common_game/String.cpp
Normal file
|
@ -0,0 +1,368 @@
|
|||
#include "String.h"
|
||||
#include "../doctest/parts/doctest_fwd.h"
|
||||
|
||||
namespace Common
|
||||
{
|
||||
String& Common::ToLower(String& Str)
|
||||
{
|
||||
transform(Str.begin(), Str.end(), Str.begin(), [](char_t C) { return static_cast<char_t>(tolower(static_cast<int32_t>(C))); });
|
||||
|
||||
return Str;
|
||||
}
|
||||
|
||||
|
||||
String Common::ToLower(const String& Str)
|
||||
{
|
||||
auto Copy(Str);
|
||||
ToLower(Copy);
|
||||
return Copy;
|
||||
}
|
||||
|
||||
|
||||
String& ToUpper(String& Str)
|
||||
{
|
||||
transform(Str.begin(), Str.end(), Str.begin(), [](char_t C) { return static_cast<char_t>(toupper(static_cast<int32_t>(C))); });
|
||||
|
||||
return Str;
|
||||
}
|
||||
|
||||
|
||||
String ToUpper(const String& Str)
|
||||
{
|
||||
auto Copy(Str);
|
||||
ToUpper(Copy);
|
||||
return Copy;
|
||||
}
|
||||
|
||||
String& TrimLeft(String& Str)
|
||||
{
|
||||
const auto It = std::find_if(Str.begin(), Str.end(), [](char_t C) { return !Detail::IsWhiteSpace(C); });
|
||||
|
||||
if(It != Str.end())
|
||||
Str = Str.substr(std::distance(Str.begin(), It));
|
||||
|
||||
return Str;
|
||||
}
|
||||
|
||||
String TrimLeft(const String& Str)
|
||||
{
|
||||
auto Copy(Str);
|
||||
TrimLeft(Copy);
|
||||
return Copy;
|
||||
}
|
||||
|
||||
String& TrimRight(String& Str)
|
||||
{
|
||||
const auto It = std::find_if(Str.rbegin(), Str.rend(), [](char_t C) { return !Detail::IsWhiteSpace(C); });
|
||||
|
||||
if(It != Str.rend())
|
||||
Str = Str.substr(0, Str.length() - std::distance(Str.rbegin(), It));
|
||||
|
||||
return Str;
|
||||
}
|
||||
|
||||
String TrimRight(const String& Str)
|
||||
{
|
||||
auto Copy(Str);
|
||||
TrimRight(Copy);
|
||||
return Copy;
|
||||
}
|
||||
|
||||
String& Trim(String& Str)
|
||||
{
|
||||
TrimLeft(Str);
|
||||
TrimRight(Str);
|
||||
return Str;
|
||||
}
|
||||
|
||||
String Trim(const String& Str)
|
||||
{
|
||||
auto Copy(Str);
|
||||
TrimLeft(Copy);
|
||||
TrimRight(Copy);
|
||||
return Copy;
|
||||
}
|
||||
|
||||
bool EqualNoCase(const String& A, const String& B)
|
||||
{
|
||||
return ToLower(A) == ToLower(B);
|
||||
}
|
||||
|
||||
int32_t CompareNoCase(const String& A, const String& B)
|
||||
{
|
||||
return ToLower(A).compare(ToLower(B));
|
||||
}
|
||||
|
||||
namespace Detail
|
||||
{
|
||||
bool IsWhiteSpace(char_t C)
|
||||
{
|
||||
for(const auto& W : WHITE_SPACE_CHARS)
|
||||
if(W == C)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class ToUpperToLowerFixture
|
||||
{
|
||||
public:
|
||||
enum class EStringType
|
||||
{
|
||||
Upper,
|
||||
Lower,
|
||||
Mixed
|
||||
};
|
||||
|
||||
String m_Str1 = UPPER;
|
||||
String m_Str2 = LOWER;
|
||||
String m_Str3 = MIXED;
|
||||
|
||||
const String& GetConstString(EStringType Type) const
|
||||
{
|
||||
switch(Type)
|
||||
{
|
||||
case EStringType::Upper:
|
||||
{
|
||||
return m_Str1;
|
||||
}
|
||||
case EStringType::Lower:
|
||||
{
|
||||
return m_Str2;
|
||||
}
|
||||
case EStringType::Mixed:
|
||||
{
|
||||
return m_Str3;
|
||||
}
|
||||
default:
|
||||
return m_Str1;
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once CppMemberFunctionMayBeStatic
|
||||
const char_t* GetConstRawString(EStringType Type) const
|
||||
{
|
||||
switch(Type)
|
||||
{
|
||||
case EStringType::Upper:
|
||||
{
|
||||
return UPPER;
|
||||
}
|
||||
case EStringType::Lower:
|
||||
{
|
||||
return LOWER;
|
||||
}
|
||||
case EStringType::Mixed:
|
||||
{
|
||||
return MIXED;
|
||||
}
|
||||
default:
|
||||
return _T("");
|
||||
}
|
||||
}
|
||||
|
||||
char_t* RAW_UPPER = _T("UPPER");
|
||||
char_t* RAW_LOWER = _T("lower");
|
||||
char_t* RAW_MIXED = _T("MiXeD");
|
||||
|
||||
static constexpr const char_t* UPPER = _T("UPPER");
|
||||
static constexpr const char_t* LOWER = _T("lower");
|
||||
static constexpr const char_t* MIXED = _T("MiXeD");
|
||||
static constexpr const char_t* TO_UPPER_EXPECTED_UPPER = _T("UPPER");
|
||||
static constexpr const char_t* TO_UPPER_EXPECTED_LOWER = _T("LOWER");
|
||||
static constexpr const char_t* TO_UPPER_EXPECTED_MIXED = _T("MIXED");
|
||||
static constexpr const char_t* TO_LOWER_EXPECTED_UPPER = _T("upper");
|
||||
static constexpr const char_t* TO_LOWER_EXPECTED_LOWER = _T("lower");
|
||||
static constexpr const char_t* TO_LOWER_EXPECTED_MIXED = _T("mixed");
|
||||
};
|
||||
|
||||
|
||||
TEST_CASE_FIXTURE(ToUpperToLowerFixture, "String ToUpper")
|
||||
{
|
||||
REQUIRE(ToUpper(m_Str1) == TO_UPPER_EXPECTED_UPPER);
|
||||
REQUIRE(ToUpper(m_Str2) == TO_UPPER_EXPECTED_LOWER);
|
||||
REQUIRE(ToUpper(m_Str3) == TO_UPPER_EXPECTED_MIXED);
|
||||
|
||||
REQUIRE(ToUpper(GetConstString(EStringType::Upper)) == TO_UPPER_EXPECTED_UPPER);
|
||||
REQUIRE(ToUpper(GetConstString(EStringType::Lower)) == TO_UPPER_EXPECTED_LOWER);
|
||||
REQUIRE(ToUpper(GetConstString(EStringType::Mixed)) == TO_UPPER_EXPECTED_MIXED);
|
||||
|
||||
REQUIRE(ToUpper(GetConstRawString(EStringType::Upper)) == TO_UPPER_EXPECTED_UPPER);
|
||||
REQUIRE(ToUpper(GetConstRawString(EStringType::Lower)) == TO_UPPER_EXPECTED_LOWER);
|
||||
REQUIRE(ToUpper(GetConstRawString(EStringType::Mixed)) == TO_UPPER_EXPECTED_MIXED);
|
||||
|
||||
REQUIRE(ToUpper(RAW_UPPER) == TO_UPPER_EXPECTED_UPPER);
|
||||
REQUIRE(ToUpper(RAW_LOWER) == TO_UPPER_EXPECTED_LOWER);
|
||||
REQUIRE(ToUpper(RAW_MIXED) == TO_UPPER_EXPECTED_MIXED);
|
||||
|
||||
REQUIRE(ToUpper(_T("UPPER")) == TO_UPPER_EXPECTED_UPPER);
|
||||
REQUIRE(ToUpper(_T("lower")) == TO_UPPER_EXPECTED_LOWER);
|
||||
REQUIRE(ToUpper(_T("MiXeD")) == TO_UPPER_EXPECTED_MIXED);
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(ToUpperToLowerFixture, "String ToLower")
|
||||
{
|
||||
REQUIRE(ToLower(m_Str1) == TO_LOWER_EXPECTED_UPPER);
|
||||
REQUIRE(ToLower(m_Str2) == TO_LOWER_EXPECTED_LOWER);
|
||||
REQUIRE(ToLower(m_Str3) == TO_LOWER_EXPECTED_MIXED);
|
||||
|
||||
REQUIRE(ToLower(GetConstString(EStringType::Upper)) == TO_LOWER_EXPECTED_UPPER);
|
||||
REQUIRE(ToLower(GetConstString(EStringType::Lower)) == TO_LOWER_EXPECTED_LOWER);
|
||||
REQUIRE(ToLower(GetConstString(EStringType::Mixed)) == TO_LOWER_EXPECTED_MIXED);
|
||||
|
||||
REQUIRE(ToLower(GetConstRawString(EStringType::Upper)) == TO_LOWER_EXPECTED_UPPER);
|
||||
REQUIRE(ToLower(GetConstRawString(EStringType::Lower)) == TO_LOWER_EXPECTED_LOWER);
|
||||
REQUIRE(ToLower(GetConstRawString(EStringType::Mixed)) == TO_LOWER_EXPECTED_MIXED);
|
||||
|
||||
REQUIRE(ToLower(RAW_UPPER) == TO_LOWER_EXPECTED_UPPER);
|
||||
REQUIRE(ToLower(RAW_LOWER) == TO_LOWER_EXPECTED_LOWER);
|
||||
REQUIRE(ToLower(RAW_MIXED) == TO_LOWER_EXPECTED_MIXED);
|
||||
|
||||
REQUIRE(ToLower(_T("UPPER")) == TO_LOWER_EXPECTED_UPPER);
|
||||
REQUIRE(ToLower(_T("lower")) == TO_LOWER_EXPECTED_LOWER);
|
||||
REQUIRE(ToLower(_T("MiXeD")) == TO_LOWER_EXPECTED_MIXED);
|
||||
}
|
||||
|
||||
TEST_CASE("String TrimLeft")
|
||||
{
|
||||
String Str1 = _T("NoWS");
|
||||
String Str2 = _T(" WS");
|
||||
String Str3 = _T("\tWS");
|
||||
String Str4 = _T(" \t \tWS ");
|
||||
|
||||
REQUIRE(TrimLeft(Str1) == _T("NoWS"));
|
||||
REQUIRE(TrimLeft(Str2) == _T("WS"));
|
||||
REQUIRE(TrimLeft(Str3) == _T("WS"));
|
||||
REQUIRE(TrimLeft(Str4) == _T("WS "));
|
||||
|
||||
const String Str5 = _T("NoWS");
|
||||
const String Str6 = _T(" WS");
|
||||
const String Str7 = _T("\tWS");
|
||||
const String Str8 = _T(" \t \tWS ");
|
||||
|
||||
REQUIRE(TrimLeft(Str5) == _T("NoWS"));
|
||||
REQUIRE(TrimLeft(Str6) == _T("WS"));
|
||||
REQUIRE(TrimLeft(Str7) == _T("WS"));
|
||||
REQUIRE(TrimLeft(Str8) == _T("WS "));
|
||||
}
|
||||
|
||||
TEST_CASE("String TrimRight")
|
||||
{
|
||||
String Str1 = _T("NoWS");
|
||||
String Str2 = _T(" WS ");
|
||||
String Str3 = _T("\tWS\t");
|
||||
String Str4 = _T(" \t \tWS \t ");
|
||||
|
||||
REQUIRE(TrimRight(Str1) == _T("NoWS"));
|
||||
REQUIRE(TrimRight(Str2) == _T(" WS"));
|
||||
REQUIRE(TrimRight(Str3) == _T("\tWS"));
|
||||
REQUIRE(TrimRight(Str4) == _T(" \t \tWS"));
|
||||
|
||||
const String Str5 = _T("NoWS");
|
||||
const String Str6 = _T(" WS ");
|
||||
const String Str7 = _T("\tWS\t");
|
||||
const String Str8 = _T(" \t \tWS \t ");
|
||||
|
||||
REQUIRE(TrimRight(Str5) == _T("NoWS"));
|
||||
REQUIRE(TrimRight(Str6) == _T(" WS"));
|
||||
REQUIRE(TrimRight(Str7) == _T("\tWS"));
|
||||
REQUIRE(TrimRight(Str8) == _T(" \t \tWS"));
|
||||
}
|
||||
|
||||
TEST_CASE("String Trim")
|
||||
{
|
||||
String Str1 = _T("NoWS");
|
||||
String Str2 = _T(" WS ");
|
||||
String Str3 = _T("\tWS\t");
|
||||
String Str4 = _T(" \t \tWS \t ");
|
||||
|
||||
REQUIRE(Trim(Str1) == _T("NoWS"));
|
||||
REQUIRE(Trim(Str2) == _T("WS"));
|
||||
REQUIRE(Trim(Str3) == _T("WS"));
|
||||
REQUIRE(Trim(Str4) == _T("WS"));
|
||||
|
||||
const String Str5 = _T("NoWS");
|
||||
const String Str6 = _T(" WS ");
|
||||
const String Str7 = _T("\tWS\t");
|
||||
const String Str8 = _T(" \t \tWS \t ");
|
||||
|
||||
REQUIRE(Trim(Str5) == _T("NoWS"));
|
||||
REQUIRE(Trim(Str6) == _T("WS"));
|
||||
REQUIRE(Trim(Str7) == _T("WS"));
|
||||
REQUIRE(Trim(Str8) == _T("WS"));
|
||||
}
|
||||
|
||||
TEST_CASE("String EqualNoCase")
|
||||
{
|
||||
const String Str1 = _T("Str");
|
||||
const String Str2 = _T("Str");
|
||||
const String Str3 = _T("str");
|
||||
const String Str4 = _T("StR");
|
||||
|
||||
REQUIRE(EqualNoCase(Str1, Str1));
|
||||
REQUIRE(EqualNoCase(Str2, Str2));
|
||||
REQUIRE(EqualNoCase(Str3, Str3));
|
||||
REQUIRE(EqualNoCase(Str4, Str4));
|
||||
|
||||
REQUIRE(EqualNoCase(Str1, Str2));
|
||||
REQUIRE(EqualNoCase(Str1, Str3));
|
||||
REQUIRE(EqualNoCase(Str1, Str4));
|
||||
|
||||
REQUIRE(EqualNoCase(Str2, Str1));
|
||||
REQUIRE(EqualNoCase(Str2, Str3));
|
||||
REQUIRE(EqualNoCase(Str2, Str4));
|
||||
|
||||
REQUIRE(EqualNoCase(Str3, Str1));
|
||||
REQUIRE(EqualNoCase(Str3, Str2));
|
||||
REQUIRE(EqualNoCase(Str3, Str4));
|
||||
|
||||
REQUIRE(EqualNoCase(Str4, Str1));
|
||||
REQUIRE(EqualNoCase(Str4, Str2));
|
||||
REQUIRE(EqualNoCase(Str4, Str3));
|
||||
|
||||
const String Str5 = _T("Ha");
|
||||
|
||||
REQUIRE(!EqualNoCase(Str1, Str5));
|
||||
REQUIRE(!EqualNoCase(Str2, Str5));
|
||||
REQUIRE(!EqualNoCase(Str3, Str5));
|
||||
REQUIRE(!EqualNoCase(Str4, Str5));
|
||||
}
|
||||
|
||||
TEST_CASE("String CompareNoCase")
|
||||
{
|
||||
const String Str1 = _T("Str");
|
||||
const String Str2 = _T("Str");
|
||||
const String Str3 = _T("str");
|
||||
const String Str4 = _T("StR");
|
||||
|
||||
REQUIRE(CompareNoCase(Str1, Str1) == 0);
|
||||
REQUIRE(CompareNoCase(Str2, Str2) == 0);
|
||||
REQUIRE(CompareNoCase(Str3, Str3) == 0);
|
||||
REQUIRE(CompareNoCase(Str4, Str4) == 0);
|
||||
|
||||
REQUIRE(CompareNoCase(Str1, Str2) == 0);
|
||||
REQUIRE(CompareNoCase(Str1, Str3) == 0);
|
||||
REQUIRE(CompareNoCase(Str1, Str4) == 0);
|
||||
|
||||
REQUIRE(CompareNoCase(Str2, Str1) == 0);
|
||||
REQUIRE(CompareNoCase(Str2, Str3) == 0);
|
||||
REQUIRE(CompareNoCase(Str2, Str4) == 0);
|
||||
|
||||
REQUIRE(CompareNoCase(Str3, Str1) == 0);
|
||||
REQUIRE(CompareNoCase(Str3, Str2) == 0);
|
||||
REQUIRE(CompareNoCase(Str3, Str4) == 0);
|
||||
|
||||
REQUIRE(CompareNoCase(Str4, Str1) == 0);
|
||||
REQUIRE(CompareNoCase(Str4, Str2) == 0);
|
||||
REQUIRE(CompareNoCase(Str4, Str3) == 0);
|
||||
|
||||
const String Str5 = _T("Ha");
|
||||
|
||||
REQUIRE(CompareNoCase(Str1, Str5) == 1);
|
||||
REQUIRE(CompareNoCase(Str2, Str5) == 1);
|
||||
REQUIRE(CompareNoCase(Str3, Str5) == 1);
|
||||
REQUIRE(CompareNoCase(Str4, Str5) == 1);
|
||||
}
|
||||
}
|
||||
|
50
code/common_game/String.h
Normal file
50
code/common_game/String.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <locale>
|
||||
#include <algorithm>
|
||||
|
||||
#if defined (UNICODE)
|
||||
#define _T(X) L##X
|
||||
#else
|
||||
#define _T(X) X
|
||||
#endif
|
||||
|
||||
namespace Common
|
||||
{
|
||||
#if defined (UNICODE)
|
||||
using char_t = wchar_t;
|
||||
#else
|
||||
using char_t = char;
|
||||
#endif
|
||||
|
||||
using String = std::basic_string<char_t>;
|
||||
using StringView = std::basic_string_view<char_t>;
|
||||
using StringStream = std::basic_stringstream<char_t>;
|
||||
|
||||
String& ToLower(String& Str);
|
||||
String ToLower(const String& Str);
|
||||
|
||||
String& ToUpper(String& Str);
|
||||
String ToUpper(const String& Str);
|
||||
|
||||
namespace Detail
|
||||
{
|
||||
static constexpr const char_t WHITE_SPACE_CHARS[2] = { _T(' '), _T('\t') };
|
||||
|
||||
bool IsWhiteSpace(char_t C);
|
||||
}
|
||||
|
||||
String& TrimLeft(String& Str);
|
||||
String TrimLeft(const String& Str);
|
||||
|
||||
String& TrimRight(String& Str);
|
||||
String TrimRight(const String& Str);
|
||||
|
||||
String& Trim(String& Str);
|
||||
String Trim(const String& Str);
|
||||
|
||||
bool EqualNoCase(const String& A, const String& B);
|
||||
|
||||
int32_t CompareNoCase(const String& A, const String& B);
|
||||
}
|
3461
code/doctest/doctest.h
Normal file
3461
code/doctest/doctest.h
Normal file
File diff suppressed because it is too large
Load diff
11
code/doctest/runner.h
Normal file
11
code/doctest/runner.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef UNICODE
|
||||
typedef int(*UnitTestRun)(int argc, char* argv[]);
|
||||
|
||||
constexpr const char* RUNNER_FUNC_NAME = "RunUnutTests";
|
||||
#else
|
||||
typedef int(*UnitTestRun)(int argc, wchar_t* argv[]);
|
||||
|
||||
constexpr const wchar_t* RUNNER_FUNC_NAME = L"RunUnutTests";
|
||||
#endif
|
|
@ -1,3 +1,4 @@
|
|||
EXPORTS
|
||||
vmMain
|
||||
dllEntry
|
||||
RunUnutTests
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
<Import Project="..\..\misc\msvc10\base_game\base_game.vcxitems" Label="Shared" />
|
||||
<Import Project="..\..\misc\msvc10\common_game\common_game.vcxitems" Label="Shared" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
|
@ -118,7 +119,7 @@
|
|||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;UI_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;UI_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions);CATCH_CONFIG_RUNNER</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<StructMemberAlignment>4Bytes</StructMemberAlignment>
|
||||
|
@ -251,6 +252,7 @@
|
|||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">WIN32;NDEBUG;_WINDOWS;_MBCS;_USRDLL;UI_EXPORTS</PreprocessorDefinitions>
|
||||
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui_holodeck.cpp" />
|
||||
<ClCompile Include="ui_ingame.cpp">
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">WIN32;_DEBUG;_WINDOWS;_MBCS;_USRDLL;UI_EXPORTS</PreprocessorDefinitions>
|
||||
|
@ -329,7 +331,7 @@
|
|||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">WIN32;NDEBUG;_WINDOWS;_MBCS;_USRDLL;UI_EXPORTS</PreprocessorDefinitions>
|
||||
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui_playersettings.cp">
|
||||
<ClCompile Include="ui_playersettings.cpp">
|
||||
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">WIN32;_DEBUG;_WINDOWS;_MBCS;_USRDLL;UI_EXPORTS</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
|
||||
|
@ -431,11 +433,11 @@
|
|||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">WIN32;NDEBUG;_WINDOWS;_MBCS;_USRDLL;UI_EXPORTS</PreprocessorDefinitions>
|
||||
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
|
||||
</ClCompile>
|
||||
<ClCompile Include="unittest_runner.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="keycodes.h" />
|
||||
<ClInclude Include="..\qcommon\stv_version.h" />
|
||||
<ClInclude Include="..\cgame\tr_types.h" />
|
||||
<ClInclude Include="ui_local.h" />
|
||||
<ClInclude Include="ui_public.h" />
|
||||
<ClInclude Include="ui_logger.h" />
|
||||
|
|
|
@ -80,9 +80,6 @@
|
|||
<ClCompile Include="ui_players.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui_playersettings.cp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui_preferences.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@ -119,6 +116,15 @@
|
|||
<ClCompile Include="ui_video.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui_playersettings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui_holodeck.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="unittest_runner.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="keycodes.h">
|
||||
|
@ -127,9 +133,6 @@
|
|||
<ClInclude Include="..\qcommon\stv_version.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\cgame\tr_types.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ui_local.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>C:\Users\Walter\Source\Repos\rpgxEF\Build\Debug\unit_test_ui.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
</Project>
|
1701
code/ui/ui_library.c
1701
code/ui/ui_library.c
File diff suppressed because it is too large
Load diff
|
@ -1,443 +0,0 @@
|
|||
/**********************************************************************
|
||||
UI_TACTICAL.C
|
||||
|
||||
User interface trigger from within game
|
||||
**********************************************************************/
|
||||
#include "ui_local.h"
|
||||
#include "ui_logger.h"
|
||||
|
||||
typedef struct {
|
||||
char weaponName[MAX_QPATH];
|
||||
int32_t weaponMaxCount;
|
||||
int32_t weaponCurrentCount;
|
||||
char weaponTarget[MAX_QPATH];
|
||||
int32_t weaponNum;
|
||||
} weaponData_t;
|
||||
|
||||
typedef struct {
|
||||
menuframework_s menu;
|
||||
int32_t maxWeapons;
|
||||
int32_t choosenWeapon;
|
||||
int32_t highLightedWeapon;
|
||||
sfxHandle_t openingVoice;
|
||||
sfxHandle_t fireVoice;
|
||||
menubitmap_s quitmenu;
|
||||
menubitmap_s fire;
|
||||
menubitmap_s weap1;
|
||||
menubitmap_s weap2;
|
||||
menubitmap_s weap3;
|
||||
menubitmap_s weap4;
|
||||
menubitmap_s weap5;
|
||||
menubitmap_s weap6;
|
||||
|
||||
weaponData_t weaponData[MAX_TACTICAL_WEAPONS];
|
||||
int32_t numWeapons;
|
||||
} tactical_t;
|
||||
|
||||
tactical_t s_tactical;
|
||||
|
||||
void TacticalMenu_LoadText (void);
|
||||
|
||||
#define ID_COMPUTERVOISE 6
|
||||
#define ID_QUIT 10
|
||||
#define ID_WEAP1 11
|
||||
#define ID_WEAP2 12
|
||||
#define ID_WEAP3 13
|
||||
#define ID_WEAP4 14
|
||||
#define ID_WEAP5 15
|
||||
#define ID_WEAP6 16
|
||||
#define ID_FIRE 100
|
||||
|
||||
void UI_TacticalMenu_Cache (void);
|
||||
|
||||
/*
|
||||
=================
|
||||
M_Tactical_Event
|
||||
=================
|
||||
*/
|
||||
static void M_Tactical_Event (void* ptr, int32_t notification) {
|
||||
int32_t id;
|
||||
menubitmap_s *holdWeapon;
|
||||
|
||||
UI_LogFuncBegin();
|
||||
|
||||
id = ((menucommon_s*)ptr)->id;
|
||||
|
||||
switch(id)
|
||||
{
|
||||
case ID_QUIT:
|
||||
if(notification == QM_ACTIVATED)
|
||||
UI_PopMenu();
|
||||
trap_Cmd_ExecuteText(EXEC_APPEND, "ui_tactical_free");
|
||||
break;
|
||||
case ID_WEAP1:
|
||||
case ID_WEAP2:
|
||||
case ID_WEAP3:
|
||||
case ID_WEAP4:
|
||||
case ID_WEAP5:
|
||||
case ID_WEAP6:
|
||||
if(notification == QM_ACTIVATED) {
|
||||
if(s_tactical.choosenWeapon >= 0) {
|
||||
holdWeapon = &s_tactical.weap1;
|
||||
holdWeapon += s_tactical.choosenWeapon;
|
||||
holdWeapon->textcolor = CT_BLACK;
|
||||
}
|
||||
|
||||
s_tactical.choosenWeapon = id - ID_WEAP1;
|
||||
s_tactical.fire.generic.flags = QMF_HIGHLIGHT_IF_FOCUS;
|
||||
|
||||
holdWeapon = &s_tactical.weap1;
|
||||
holdWeapon += s_tactical.choosenWeapon;
|
||||
} else if(notification == QM_GOTFOCUS) {
|
||||
s_tactical.highLightedWeapon = id - ID_WEAP1;
|
||||
}
|
||||
break;
|
||||
case ID_FIRE:
|
||||
if(notification == QM_ACTIVATED) {
|
||||
//UI_ForceMenuOff();
|
||||
trap_Cmd_ExecuteText( EXEC_APPEND, va( "tactical %s", s_tactical.weaponData[s_tactical.choosenWeapon].weaponTarget ));
|
||||
}
|
||||
break;
|
||||
}
|
||||
UI_LogFuncEnd();
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
TacticalMenu_Key
|
||||
=================
|
||||
*/
|
||||
sfxHandle_t TacticalMenu_Key (int32_t key) {
|
||||
return ( Menu_DefaultKey( &s_tactical.menu, key ) );
|
||||
}
|
||||
|
||||
extern qhandle_t leftRound;
|
||||
qhandle_t tactical;
|
||||
qhandle_t square_rl;
|
||||
qhandle_t square_rr;
|
||||
qhandle_t corner_tact_ul;
|
||||
qhandle_t corner_tact_ll;
|
||||
|
||||
/*
|
||||
=================
|
||||
M_TacticalMenu_Graphics
|
||||
=================
|
||||
*/
|
||||
static void M_TacticalMenu_Graphics (void) {
|
||||
menubitmap_s *holdWeapon;
|
||||
|
||||
UI_LogFuncBegin();
|
||||
|
||||
vec4_t bgColor = { 0.1, 0.1, 0.1, .75 };
|
||||
|
||||
// background
|
||||
//UI_DrawRect(75, 420, 490, 50, bgColor);
|
||||
trap_R_SetColor(bgColor);
|
||||
UI_DrawHandlePic(150, 375, 100, 100, square_rl);
|
||||
UI_DrawHandlePic(250, 375, 140, 100, uis.whiteShader);
|
||||
UI_DrawHandlePic(390, 375, 100, 100, square_rr);
|
||||
|
||||
// upper left
|
||||
trap_R_SetColor(colorTable[CT_DKPURPLE1]);
|
||||
UI_DrawHandlePic(151, 376, 75, 50, corner_tact_ul);
|
||||
UI_DrawHandlePic(218, 376, 270, 28, uis.whiteShader);
|
||||
UI_LogFuncEnd();
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
TacticalMenu_Draw
|
||||
===============
|
||||
*/
|
||||
static void TacticalMenu_Draw(void)
|
||||
{
|
||||
UI_LogFuncBegin();
|
||||
// Draw graphics particular to Main Menu
|
||||
M_TacticalMenu_Graphics();
|
||||
|
||||
Menu_Draw( &s_tactical.menu );
|
||||
UI_LogFuncEnd();
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
UI_TacticalMenu_Cache
|
||||
===============
|
||||
*/
|
||||
void UI_TacticalMenu_Cache (void)
|
||||
{
|
||||
UI_LogFuncBegin();
|
||||
leftRound = trap_R_RegisterShaderNoMip("menu/common/halfroundl_24.tga");
|
||||
tactical = trap_R_RegisterShaderNoMip("menu/common/lift_button.tga");
|
||||
square_rl = trap_R_RegisterShaderNoMip("menu/common/square_rounded_left.tga");
|
||||
square_rr = trap_R_RegisterShaderNoMip("menu/common/square_rounded_right.tga");
|
||||
corner_tact_ll = trap_R_RegisterShaderNoMip("menu/common/corner_tact_ll.tga");
|
||||
corner_tact_ul = trap_R_RegisterShaderNoMip("menu/common/corner_ul_18_50.tga");
|
||||
UI_LogFuncEnd();
|
||||
}
|
||||
|
||||
static void UI_TacticalMenu_LoadWeapons( void )
|
||||
{
|
||||
char buffer[MAX_TOKEN_CHARS];
|
||||
int32_t i;
|
||||
char *temp;
|
||||
|
||||
UI_LogFuncBegin();
|
||||
s_tactical.numWeapons = 0;
|
||||
|
||||
//load the string
|
||||
trap_GetConfigString( CS_TACTICAL_DATA, buffer, sizeof( buffer ) );
|
||||
|
||||
if ( !buffer[0] ){
|
||||
UI_LogFuncEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
memset( &s_tactical.weaponData, 0, sizeof( s_tactical.weaponData ) );
|
||||
|
||||
for ( i=0; i < MAX_TACTICAL_WEAPONS; i++ )
|
||||
{
|
||||
temp = Info_ValueForKey( buffer, va( "d%i", i ) );
|
||||
|
||||
if ( !temp[0] )
|
||||
break;
|
||||
|
||||
s_tactical.weaponData[ s_tactical.numWeapons ].weaponNum = atoi( temp );
|
||||
|
||||
temp = Info_ValueForKey( buffer, va( "n%i", i ) );
|
||||
|
||||
Q_strncpyz( s_tactical.weaponData[ s_tactical.numWeapons ].weaponName, temp, sizeof( s_tactical.weaponData[ s_tactical.numWeapons ].weaponName ) );
|
||||
|
||||
s_tactical.numWeapons++;
|
||||
}
|
||||
UI_LogFuncEnd();
|
||||
}
|
||||
|
||||
static void UI_ManageWeaponLoading( void )
|
||||
{
|
||||
char fileRoute[MAX_QPATH];
|
||||
char mapRoute[MAX_QPATH];
|
||||
char info[MAX_TOKEN_CHARS];
|
||||
fileHandle_t f;
|
||||
int32_t file_len;
|
||||
char *textPtr;
|
||||
char buffer[20000];
|
||||
char *token;
|
||||
|
||||
UI_LogFuncBegin();
|
||||
//get the map name
|
||||
trap_GetConfigString( CS_SERVERINFO, info, sizeof( info ) );
|
||||
Com_sprintf( mapRoute, sizeof( fileRoute ), "maps/%s", Info_ValueForKey( info, "mapname" ) );
|
||||
|
||||
//check for language
|
||||
UI_LanguageFilename( mapRoute, "tactical", fileRoute );
|
||||
|
||||
file_len = trap_FS_FOpenFile( fileRoute, &f, FS_READ );
|
||||
|
||||
if ( file_len <= 1 )
|
||||
{
|
||||
//UI_Logger( LL_WARN, "Attempted to load %s, but wasn't found.\n", fileRoute );
|
||||
UI_TacticalMenu_LoadWeapons();
|
||||
UI_LogFuncEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
trap_FS_Read( buffer, file_len, f );
|
||||
trap_FS_FCloseFile( f );
|
||||
|
||||
if ( !buffer[0] )
|
||||
{
|
||||
UI_Logger( LL_ERROR, "Attempted to load %s, but no data was read.\n", fileRoute );
|
||||
UI_TacticalMenu_LoadWeapons();
|
||||
UI_LogFuncEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
s_tactical.numWeapons = 0;
|
||||
memset( &s_tactical.weaponData, 0, sizeof( s_tactical.weaponData ) );
|
||||
buffer[file_len] = '\0';
|
||||
|
||||
COM_BeginParseSession();
|
||||
textPtr = buffer;
|
||||
|
||||
//UI_Logger( LL_DEBUG, "Beginning Parse\n" );
|
||||
|
||||
//expected format is 'weapon num' <space> 'weapon desc' <space> 'weapon target'
|
||||
while( 1 )
|
||||
{
|
||||
token = COM_Parse( &textPtr );
|
||||
if ( !token[0] )
|
||||
break;
|
||||
|
||||
//UI_Logger( LL_DEBUG, "First Token: %s\n", token );
|
||||
|
||||
//grab the weapon number
|
||||
s_tactical.weaponData[s_tactical.numWeapons].weaponNum = atoi( token );
|
||||
|
||||
token = COM_ParseExt( &textPtr, qfalse );
|
||||
if (!token[0])
|
||||
continue;
|
||||
|
||||
//UI_Logger( LL_DEBUG, "Second Token: %s\n", token );
|
||||
|
||||
Q_strncpyz( s_tactical.weaponData[s_tactical.numWeapons].weaponName,
|
||||
token,
|
||||
sizeof( s_tactical.weaponData[s_tactical.numWeapons].weaponName ) );
|
||||
|
||||
token = COM_ParseExt( &textPtr, qfalse );
|
||||
if(!token[0])
|
||||
continue;
|
||||
|
||||
Q_strncpyz( s_tactical.weaponData[s_tactical.numWeapons].weaponTarget,
|
||||
token,
|
||||
sizeof(s_tactical.weaponData[s_tactical.numWeapons].weaponTarget) );
|
||||
|
||||
s_tactical.numWeapons++;
|
||||
|
||||
|
||||
}
|
||||
UI_LogFuncEnd();
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
TacticalMenu_Init
|
||||
===============
|
||||
*/
|
||||
void TacticalMenu_Init(void)
|
||||
{
|
||||
int32_t y,pad,x;
|
||||
menubitmap_s *holdWeapon;
|
||||
int32_t i,width;
|
||||
|
||||
UI_LogFuncBegin();
|
||||
UI_ManageWeaponLoading();
|
||||
|
||||
s_tactical.menu.fullscreen = qfalse;
|
||||
s_tactical.menu.nobackground = qtrue;
|
||||
|
||||
s_tactical.menu.nitems = 0;
|
||||
s_tactical.menu.draw = TacticalMenu_Draw;
|
||||
s_tactical.menu.key = TacticalMenu_Key;
|
||||
s_tactical.menu.wrapAround = qtrue;
|
||||
s_tactical.menu.descX = MENU_DESC_X;
|
||||
s_tactical.menu.descY = MENU_DESC_Y;
|
||||
s_tactical.menu.titleX = MENU_TITLE_X;
|
||||
s_tactical.menu.titleY = MENU_TITLE_Y;
|
||||
|
||||
s_tactical.choosenWeapon = -1;
|
||||
s_tactical.highLightedWeapon = -1;
|
||||
|
||||
pad = PROP_BIG_HEIGHT + 10;
|
||||
y = 72;
|
||||
x = 319;
|
||||
width = MENU_BUTTON_MED_WIDTH-20;
|
||||
|
||||
s_tactical.maxWeapons = MAX_TACTICAL_WEAPONS;
|
||||
holdWeapon = &s_tactical.weap1;
|
||||
|
||||
for (i=0;i<s_tactical.maxWeapons;i++)
|
||||
{
|
||||
holdWeapon->generic.type = MTYPE_BITMAP;
|
||||
holdWeapon->generic.flags = QMF_HIGHLIGHT_IF_FOCUS;
|
||||
holdWeapon->generic.x = x;
|
||||
holdWeapon->generic.y = y;
|
||||
holdWeapon->generic.name = GRAPHIC_BUTTONRIGHT;
|
||||
holdWeapon->generic.id = ID_WEAP1 + i;
|
||||
holdWeapon->generic.callback = M_Tactical_Event;
|
||||
holdWeapon->width = width;
|
||||
holdWeapon->height = PROP_BIG_HEIGHT;
|
||||
holdWeapon->color = CT_DKPURPLE1;//CT_VDKRED1;//CT_DKGOLD1;
|
||||
holdWeapon->color2 = CT_LTPURPLE1;//CT_DKRED1;//CT_LTGOLD1;
|
||||
holdWeapon->textX = MENU_BUTTON_TEXT_X;
|
||||
holdWeapon->textY = 12;
|
||||
holdWeapon->textEnum = MBT_WEAPON;
|
||||
holdWeapon->textcolor = CT_BLACK;
|
||||
holdWeapon->textcolor2 = CT_WHITE;
|
||||
holdWeapon->textStyle = UI_TINYFONT;
|
||||
|
||||
holdWeapon++;
|
||||
y += pad;
|
||||
|
||||
// Start the next column
|
||||
if (i == ((s_tactical.maxWeapons-1)/2))
|
||||
{
|
||||
x += width + 90;
|
||||
y = 80;
|
||||
}
|
||||
}
|
||||
|
||||
s_tactical.fire.generic.type = MTYPE_BITMAP;
|
||||
s_tactical.fire.generic.flags = QMF_GRAYED;
|
||||
s_tactical.fire.generic.x = 110;
|
||||
s_tactical.fire.generic.y = 72 + (pad * 5);
|
||||
s_tactical.fire.generic.name = GRAPHIC_BUTTONRIGHT;
|
||||
s_tactical.fire.generic.id = ID_FIRE;
|
||||
s_tactical.fire.generic.callback = M_Tactical_Event;
|
||||
s_tactical.fire.width = width;
|
||||
s_tactical.fire.height = PROP_BIG_HEIGHT;
|
||||
s_tactical.fire.color = CT_DKORANGE;
|
||||
s_tactical.fire.color2 = CT_LTORANGE;
|
||||
s_tactical.fire.textX = MENU_BUTTON_TEXT_X;
|
||||
s_tactical.fire.textY = 6;
|
||||
s_tactical.fire.textEnum = MBT_FIRE;
|
||||
s_tactical.fire.textcolor = CT_BLACK;
|
||||
s_tactical.fire.textcolor2 = CT_WHITE;
|
||||
|
||||
s_tactical.quitmenu.generic.type = MTYPE_BITMAP;
|
||||
s_tactical.quitmenu.generic.flags = QMF_HIGHLIGHT_IF_FOCUS;
|
||||
s_tactical.quitmenu.generic.x = 110;
|
||||
s_tactical.quitmenu.generic.y = 72 + (pad * 7);
|
||||
s_tactical.quitmenu.generic.name = GRAPHIC_BUTTONRIGHT;
|
||||
s_tactical.quitmenu.generic.id = ID_QUIT;
|
||||
s_tactical.quitmenu.generic.callback = M_Tactical_Event;
|
||||
s_tactical.quitmenu.width = width;
|
||||
s_tactical.quitmenu.height = PROP_BIG_HEIGHT;
|
||||
s_tactical.quitmenu.color = CT_DKORANGE;
|
||||
s_tactical.quitmenu.color2 = CT_LTORANGE;
|
||||
s_tactical.quitmenu.textX = MENU_BUTTON_TEXT_X;
|
||||
s_tactical.quitmenu.textY = 6;
|
||||
s_tactical.quitmenu.textEnum = MBT_RETURNMENU;//MBT_RETURN;
|
||||
s_tactical.quitmenu.textcolor = CT_BLACK;
|
||||
s_tactical.quitmenu.textcolor2 = CT_WHITE;
|
||||
|
||||
Menu_AddItem( &s_tactical.menu, &s_tactical.fire );
|
||||
Menu_AddItem( &s_tactical.menu, &s_tactical.quitmenu );
|
||||
|
||||
holdWeapon = &s_tactical.weap1;
|
||||
for (i=0;i<s_tactical.maxWeapons;i++)
|
||||
{
|
||||
if (s_tactical.weaponData[i].weaponName[0])
|
||||
{
|
||||
Menu_AddItem( &s_tactical.menu, holdWeapon );
|
||||
}
|
||||
holdWeapon++;
|
||||
}
|
||||
UI_LogFuncEnd();
|
||||
}
|
||||
|
||||
/*
|
||||
===============
|
||||
UI_TacticalMenu
|
||||
===============
|
||||
*/
|
||||
void UI_TacticalMenu ( void )
|
||||
{
|
||||
UI_LogFuncBegin();
|
||||
memset( &s_tactical, 0, sizeof( s_tactical ) );
|
||||
|
||||
uis.menusp = 0;
|
||||
|
||||
ingameFlag = qtrue; // true when in game menu is in use
|
||||
|
||||
Mouse_Show();
|
||||
|
||||
UI_TacticalMenu_Cache();
|
||||
|
||||
TacticalMenu_Init();
|
||||
|
||||
UI_PushMenu( &s_tactical.menu );
|
||||
|
||||
Menu_AdjustCursor( &s_tactical.menu, 1 );
|
||||
UI_LogFuncEnd();
|
||||
}
|
3
code/ui/unittest.cpp
Normal file
3
code/ui/unittest.cpp
Normal file
|
@ -0,0 +1,3 @@
|
|||
#define CATCH_CONFIG_MAIN
|
||||
#include "../common_game/catch.hpp"
|
||||
|
10
code/ui/unittest_runner.cpp
Normal file
10
code/ui/unittest_runner.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#define DOCTEST_CONFIG_IMPLEMENT
|
||||
#include "../doctest/doctest.h"
|
||||
#include "../common_game/String.h"
|
||||
|
||||
int RunUnutTests(int argc, Common::char_t* argv[])
|
||||
{
|
||||
doctest::Context Ctx(argc, argv);
|
||||
return Ctx.run();
|
||||
}
|
||||
|
63
code/unit_test_runner/main.cpp
Normal file
63
code/unit_test_runner/main.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include <cstdlib>
|
||||
#include <windows.h>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <tchar.h>
|
||||
|
||||
#include "../doctest/runner.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
namespace std
|
||||
{
|
||||
namespace filesystem = experimental::filesystem;
|
||||
}
|
||||
#endif
|
||||
|
||||
constexpr const TCHAR* ARG_AUTO_1 = _T("-autoclose");
|
||||
constexpr const TCHAR* ARG_AUTO_2 = _T("/autoclose");
|
||||
|
||||
struct Settings
|
||||
{
|
||||
bool m_AutoClose = false;
|
||||
};
|
||||
|
||||
int main(int argc, TCHAR* argv[])
|
||||
{
|
||||
Settings Settings;
|
||||
auto Result = EXIT_SUCCESS;
|
||||
std::filesystem::path CurrentPath(argv[0]);
|
||||
CurrentPath = CurrentPath.remove_filename();
|
||||
|
||||
for(auto i = 0; i < argc; i++)
|
||||
{
|
||||
if(_tcsicmp(ARG_AUTO_1, argv[i]) == 0 || _tcsicmp(ARG_AUTO_2, argv[i]) == 0)
|
||||
Settings.m_AutoClose = true;
|
||||
}
|
||||
|
||||
for(const auto& Path : std::filesystem::directory_iterator(CurrentPath))
|
||||
{
|
||||
if(!is_regular_file(Path) || Path.path().extension() != _T(".dll"))
|
||||
continue;
|
||||
|
||||
const auto Lib = LoadLibraryW(Path.path().c_str());
|
||||
if(Lib == NULL)
|
||||
continue;
|
||||
|
||||
const auto Func = reinterpret_cast<UnitTestRun>(GetProcAddress(Lib, RUNNER_FUNC_NAME));
|
||||
if(Func == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << _T("Running unit test in: ") << Path.path().filename() << _T("\n");
|
||||
if(Func(argc, argv) != 0)
|
||||
Result = EXIT_FAILURE;
|
||||
std::cout << _T("\n\n");
|
||||
}
|
||||
|
||||
if(!Settings.m_AutoClose)
|
||||
getchar();
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
22
misc/doctest/doctest.vcxitems
Normal file
22
misc/doctest/doctest.vcxitems
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<ItemsProjectGuid>{6d53174b-907f-41e8-88b9-b1bec8dc0be0}</ItemsProjectGuid>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectCapability Include="SourceItemsFromImports" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\code\doctest\doctest.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\code\doctest\parts\doctest_fwd.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\code\doctest\parts\doctest_impl.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\code\doctest\runner.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
17
misc/doctest/doctest.vcxitems.filters
Normal file
17
misc/doctest/doctest.vcxitems.filters
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="parts">
|
||||
<UniqueIdentifier>{31695460-c20b-42b4-8b5c-98254770f436}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="C:\Users\Walter\Source\Repos\rpgxEF\misc\doctest\..\..\code\doctest\parts\doctest_impl.h">
|
||||
<Filter>parts</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="C:\Users\Walter\Source\Repos\rpgxEF\misc\doctest\..\..\code\doctest\parts\doctest_fwd.h">
|
||||
<Filter>parts</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\code\doctest\runner.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<ItemsProjectGuid>{2c33fecb-cbc5-4ff8-abde-0b61e70e751e}</ItemsProjectGuid>
|
||||
<ItemsProjectGuid>{c11ca1bb-3a5c-4794-b006-81fc2a716074}</ItemsProjectGuid>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
|
@ -13,4 +13,11 @@
|
|||
<ItemGroup>
|
||||
<ProjectCapability Include="SourceItemsFromImports" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\code\common_game\Position2D.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\code\common_game\String.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\code\common_game\String.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -12,9 +12,22 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ui", "..\..\code\ui\ui.vcxp
|
|||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "base_game", "base_game\base_game.vcxitems", "{DDF6F925-EDC6-46A8-85B4-B612BBD39D4B}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common_game", "common_game\common_game.vcxitems", "{C11CA1BB-3A5C-4794-B006-81FC2A716074}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doctest", "..\doctest\doctest.vcxitems", "{6D53174B-907F-41E8-88B9-B1BEC8DC0BE0}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unit_test_runner", "unit_test_runner\unit_test_runner.vcxproj", "{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{A4AF2332-2A45-4CE7-953D-FFB0FC490AA9} = {A4AF2332-2A45-4CE7-953D-FFB0FC490AA9}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
..\doctest\doctest.vcxitems*{2d4c9db7-b005-490e-88af-4d2c192a14c8}*SharedItemsImports = 4
|
||||
..\doctest\doctest.vcxitems*{6d53174b-907f-41e8-88b9-b1bec8dc0be0}*SharedItemsImports = 9
|
||||
base_game\base_game.vcxitems*{a4af2332-2a45-4ce7-953d-ffb0fc490aa9}*SharedItemsImports = 4
|
||||
common_game\common_game.vcxitems*{a4af2332-2a45-4ce7-953d-ffb0fc490aa9}*SharedItemsImports = 4
|
||||
common_game\common_game.vcxitems*{c11ca1bb-3a5c-4794-b006-81fc2a716074}*SharedItemsImports = 9
|
||||
base_game\base_game.vcxitems*{ddf6f925-edc6-46a8-85b4-b612bbd39d4b}*SharedItemsImports = 9
|
||||
base_game\base_game.vcxitems*{ebb0d9e9-00fc-4dba-af4a-4052fe9b17b1}*SharedItemsImports = 4
|
||||
base_game\base_game.vcxitems*{f4a59392-23bd-4787-a7d5-aac517803246}*SharedItemsImports = 4
|
||||
|
@ -82,6 +95,22 @@ Global
|
|||
{A4AF2332-2A45-4CE7-953D-FFB0FC490AA9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{A4AF2332-2A45-4CE7-953D-FFB0FC490AA9}.Release|Win32.Build.0 = Release|Win32
|
||||
{A4AF2332-2A45-4CE7-953D-FFB0FC490AA9}.Release|x64.ActiveCfg = Release|Win32
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Debug TA|Win32.ActiveCfg = Debug|Win32
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Debug TA|Win32.Build.0 = Debug|Win32
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Debug TA|x64.ActiveCfg = Debug|x64
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Debug TA|x64.Build.0 = Debug|x64
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Debug|x64.Build.0 = Debug|x64
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Release TA|Win32.ActiveCfg = Release|Win32
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Release TA|Win32.Build.0 = Release|Win32
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Release TA|x64.ActiveCfg = Release|x64
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Release TA|x64.Build.0 = Release|x64
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Release|Win32.Build.0 = Release|Win32
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Release|x64.ActiveCfg = Release|x64
|
||||
{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
125
misc/msvc10/unit_test_runner/unit_test_runner.vcxproj
Normal file
125
misc/msvc10/unit_test_runner/unit_test_runner.vcxproj
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\code\unit_test_runner\main.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{2D4C9DB7-B005-490E-88AF-4D2C192A14C8}</ProjectGuid>
|
||||
<RootNamespace>unit_test_runner</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
<Import Project="..\..\doctest\doctest.vcxitems" Label="Shared" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)..\..\Build\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)..\..\Build\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\code\unit_test_runner\main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in a new issue