1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-22 22:25:37 +01:00

Update SDK and server console example.

This commit is contained in:
Nick Blakely 2020-12-21 00:38:20 -08:00
parent 18fe4087ad
commit 3fc16e8b6b
10 changed files with 178 additions and 30 deletions

165
Sdk/Include/DataTypes.h Normal file
View File

@ -0,0 +1,165 @@
#pragma once
#include <float.h>
#include <math.h>
#include <memory>
#include <string>
#include <string_view>
//////////////////////////////////////////////////////////////////////////////////////
// Basic game data types and macros
typedef unsigned int uint;
typedef unsigned char UBYTE;
typedef signed char SBYTE;
typedef unsigned short UWORD;
typedef int BOOL;
typedef unsigned long ULONG;
typedef unsigned long DWORD;
typedef std::int64_t int64;
typedef std::uint64_t uint64;
#ifdef UNICODE
typedef std::wstring tstring;
typedef std::wstring_view tstring_view;
#else
typedef std::string tstring;
typedef std::string_view tstring_view;
#endif
#define countof(array) (sizeof((array)) / sizeof((array)[0]))
#define FlagSet(b, f) ((b) |= (f))
#define FlagClear(b, f) ((b) &= ~(f))
#define FlagIsClear(b, f) (!FlagIsSet(b, f))
#define FlagFlip(b, f) ((b) ^= (f))
#define FlagIsSet(b, f) (((b) & (f)) != 0)
//////////////////////////////////////////////////////////////////////////////////////
// Vectors
struct P3D
{
float x;
float y;
float z;
inline const P3D& operator -= (const P3D& rhs)
{
x -= rhs.x;
y -= rhs.y;
z -= rhs.z;
return *this;
}
inline const P3D& operator += (const P3D& rhs)
{
x += rhs.x;
y += rhs.y;
z += rhs.z;
return *this;
}
inline P3D operator - (const P3D& rhs)
{
P3D result;
result.x = x - rhs.x;
result.y = y - rhs.y;
result.z = z - rhs.z;
return result;
}
inline P3D Cross(const P3D& v2)
{
P3D result;
result.x = y * v2.z - z * v2.y;
result.y = z * v2.x - x * v2.z;
result.z = x * v2.y - y * v2.x;
return result;
}
inline float Dot(const P3D& v2)
{
return x * v2.x + y * v2.y + z * v2.z;
}
inline float Length()
{
return (float)(sqrt(x * x + y * y + z * z));
}
inline P3D Scale(float scale)
{
x *= scale;
y *= scale;
z *= scale;
return *this;
}
inline P3D Normalize()
{
float length = Length();
P3D normalized = *this;
float factor;
if (length)
{
factor = 1 / length;
}
else
{
factor = 1.0f;
}
normalized.x *= factor;
normalized.y *= factor;
normalized.z *= factor;
return normalized;
}
bool IsNaN() const
{
return (_isnan(x) || _isnan(y) || _isnan(z));
}
bool Finite() const
{
return (_finite(x) && _finite(y) && _finite(z));
}
};
#pragma pack (push, 1)
// Optimized 3D vector for network packets.
struct NetP3D
{
short x, y, z;
};
#pragma pack (pop)
//////////////////////////////////////////////////////////////////////////////////////
struct RGBFloat
{
float r{};
float g{};
float b{};
};
struct VertRGB
{
unsigned char r;
unsigned char g;
unsigned char b;
};
struct UV
{
float u, v;
};

View File

@ -16,7 +16,7 @@ struct IGiantsApiClient : IComponent
{
virtual ~IGiantsApiClient() = default;
virtual void STDMETHODCALLTYPE DeleteServerInformationAsync() = 0;
virtual void STDMETHODCALLTYPE DeleteServerInformationAsync(tstring_view gameName, int hostPort) = 0;
virtual ServerInfoFuture STDMETHODCALLTYPE GetServerInformationAsync() = 0;
virtual void STDMETHODCALLTYPE PostServerInformationAsync(const njson& requestBody) = 0;
};

View File

@ -104,6 +104,7 @@
<EnablePREfast>true</EnablePREfast>
<LanguageStandard>stdcpplatest</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -158,6 +159,7 @@
<EnablePREfast>true</EnablePREfast>
<LanguageStandard>stdcpplatest</LanguageStandard>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@ -213,7 +215,6 @@
</ClCompile>
<ClCompile Include="ServerDialog.cpp" />
<ClCompile Include="ServerConsoleApp.cpp" />
<ClCompile Include="Utils.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="res\ServerConsole.rc2" />
@ -226,7 +227,6 @@
<ClInclude Include="ServerDialog.h" />
<ClInclude Include="ServerConsoleApp.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="Utils.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ServerConsole.rc" />

View File

@ -1,5 +1,4 @@
#include "pch.h"
#include <initguid.h>
#include "ServerConsoleApp.h"
#include "ServerDialog.h"
@ -32,18 +31,19 @@ BOOL ServerConsoleApp::ExitInstance()
return CWinApp::ExitInstance();
}
IGameServerConsole* ServerConsoleApp::InitializeDialog(IComponentContainer* container)
IGameServerConsole* ServerConsoleApp::InitializeDialog(HWND hWndParent, IComponentContainer* container)
{
// Create the server console window.
// As this is also a Component, Giants will clean up this object automatically once
// it is no longer needed (i.e, there is no need to call delete).
auto* dialog = new ServerDialog(container);
auto* dialog = new ServerDialog(container, CWnd::FromHandle(hWndParent));
m_pMainWnd = dialog;
return dialog;
}
__declspec(dllexport) void CreateServerConsole(
int apiVersion,
HWND hWnd,
IComponentContainer* container)
{
if (apiVersion > 1)
@ -52,5 +52,5 @@ __declspec(dllexport) void CreateServerConsole(
}
AFX_MANAGE_STATE(AfxGetStaticModuleState());
ConsoleApp.InitializeDialog(container);
ConsoleApp.InitializeDialog(hWnd, container);
}

View File

@ -18,7 +18,7 @@ public:
BOOL InitInstance() override;
BOOL ExitInstance() override;
IGameServerConsole* InitializeDialog(IComponentContainer* container);
IGameServerConsole* InitializeDialog(HWND hWndParent, IComponentContainer* container);
DECLARE_MESSAGE_MAP()
};

View File

@ -2,7 +2,6 @@
#include "ServerConsoleApp.h"
#include "ServerDialog.h"
#include "Utils.h"
IMPLEMENT_DYNAMIC(ServerDialog, CDialogEx)
@ -110,9 +109,10 @@ void ServerDialog::OnCancel()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
KillTimer((UINT_PTR)this);
ShowWindow(SW_HIDE);
DestroyWindow();
KillTimer((UINT_PTR)this);
m_pParentWnd->SendMessage(WM_CLOSE, 0, 0);
}
void ServerDialog::RefreshPlayers()

View File

@ -14,7 +14,7 @@ class ServerDialog : public CDialogEx, public ComponentBase<IGameServerConsole>
public:
~ServerDialog();
ServerDialog(IComponentContainer* container, CWnd* parent = nullptr);
ServerDialog(IComponentContainer* container, CWnd* parent);
void CreateColumns();
void RefreshPlayers();

View File

@ -1,12 +0,0 @@
#include "pch.h"
#include <codecvt>
#include "Utils.h"
std::wstring to_wstring(const std::string_view& sourceString)
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.from_bytes(sourceString.data());
}

View File

@ -1,5 +0,0 @@
#pragma once
#include <string>
std::wstring to_wstring(const std::string_view& sourceString);