From 3fc16e8b6b382a0529e42965a7c22c2a6fb88e26 Mon Sep 17 00:00:00 2001 From: Nick Blakely Date: Mon, 21 Dec 2020 00:38:20 -0800 Subject: [PATCH] Update SDK and server console example. --- Sdk/Include/DataTypes.h | 165 ++++++++++++++++++++ Sdk/Include/MasterServer/IGiantsApiClient.h | 2 +- ServerConsoleExample/ServerConsole.rc | Bin 10702 -> 10712 bytes ServerConsoleExample/ServerConsole.vcxproj | 4 +- ServerConsoleExample/ServerConsoleApp.cpp | 10 +- ServerConsoleExample/ServerConsoleApp.h | 2 +- ServerConsoleExample/ServerDialog.cpp | 6 +- ServerConsoleExample/ServerDialog.h | 2 +- ServerConsoleExample/Utils.cpp | 12 -- ServerConsoleExample/Utils.h | 5 - 10 files changed, 178 insertions(+), 30 deletions(-) create mode 100644 Sdk/Include/DataTypes.h delete mode 100644 ServerConsoleExample/Utils.cpp delete mode 100644 ServerConsoleExample/Utils.h diff --git a/Sdk/Include/DataTypes.h b/Sdk/Include/DataTypes.h new file mode 100644 index 0000000..59458e5 --- /dev/null +++ b/Sdk/Include/DataTypes.h @@ -0,0 +1,165 @@ +#pragma once + +#include +#include +#include +#include +#include + +////////////////////////////////////////////////////////////////////////////////////// +// 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; +}; \ No newline at end of file diff --git a/Sdk/Include/MasterServer/IGiantsApiClient.h b/Sdk/Include/MasterServer/IGiantsApiClient.h index 071c5d3..50604e9 100644 --- a/Sdk/Include/MasterServer/IGiantsApiClient.h +++ b/Sdk/Include/MasterServer/IGiantsApiClient.h @@ -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; }; diff --git a/ServerConsoleExample/ServerConsole.rc b/ServerConsoleExample/ServerConsole.rc index 3ea14696c5028ca0d9113111aed649cfa6782d18..95290df2544cf29a9d38233d0c21770870af47d4 100644 GIT binary patch delta 71 zcmX>Xd?R>61wV5VgTZ7*A@RvugylAG;8$XkRA8uKP+$mW2xf=};z%I&WpHKiV+fsm YQB<7UogtGUks*(vgrRsdv)E~20IjwWr2qf` delta 79 zcmcZ+d@guH1wXSBgTZ7*A@RvugylAG;8$WZ2)zJceQ*nZuB}nOE$zFaY>-5qtrue stdcpplatest MultiThreadedDebugDLL + true Windows @@ -158,6 +159,7 @@ true stdcpplatest MultiThreadedDLL + true Windows @@ -213,7 +215,6 @@ - @@ -226,7 +227,6 @@ - diff --git a/ServerConsoleExample/ServerConsoleApp.cpp b/ServerConsoleExample/ServerConsoleApp.cpp index 3df4ec7..67ef676 100644 --- a/ServerConsoleExample/ServerConsoleApp.cpp +++ b/ServerConsoleExample/ServerConsoleApp.cpp @@ -1,5 +1,4 @@ #include "pch.h" -#include #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, + 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); } \ No newline at end of file diff --git a/ServerConsoleExample/ServerConsoleApp.h b/ServerConsoleExample/ServerConsoleApp.h index 1386dc1..4a22f85 100644 --- a/ServerConsoleExample/ServerConsoleApp.h +++ b/ServerConsoleExample/ServerConsoleApp.h @@ -18,7 +18,7 @@ public: BOOL InitInstance() override; BOOL ExitInstance() override; - IGameServerConsole* InitializeDialog(IComponentContainer* container); + IGameServerConsole* InitializeDialog(HWND hWndParent, IComponentContainer* container); DECLARE_MESSAGE_MAP() }; diff --git a/ServerConsoleExample/ServerDialog.cpp b/ServerConsoleExample/ServerDialog.cpp index c6a78d0..e7a0b6a 100644 --- a/ServerConsoleExample/ServerDialog.cpp +++ b/ServerConsoleExample/ServerDialog.cpp @@ -2,7 +2,6 @@ #include "ServerConsoleApp.h" #include "ServerDialog.h" -#include "Utils.h" IMPLEMENT_DYNAMIC(ServerDialog, CDialogEx) @@ -109,10 +108,11 @@ void ServerDialog::OnOK() 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() diff --git a/ServerConsoleExample/ServerDialog.h b/ServerConsoleExample/ServerDialog.h index 2e992c6..8ee4503 100644 --- a/ServerConsoleExample/ServerDialog.h +++ b/ServerConsoleExample/ServerDialog.h @@ -14,7 +14,7 @@ class ServerDialog : public CDialogEx, public ComponentBase public: ~ServerDialog(); - ServerDialog(IComponentContainer* container, CWnd* parent = nullptr); + ServerDialog(IComponentContainer* container, CWnd* parent); void CreateColumns(); void RefreshPlayers(); diff --git a/ServerConsoleExample/Utils.cpp b/ServerConsoleExample/Utils.cpp deleted file mode 100644 index 471bbea..0000000 --- a/ServerConsoleExample/Utils.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "pch.h" - -#include - -#include "Utils.h" - -std::wstring to_wstring(const std::string_view& sourceString) -{ - std::wstring_convert> converter; - - return converter.from_bytes(sourceString.data()); -} \ No newline at end of file diff --git a/ServerConsoleExample/Utils.h b/ServerConsoleExample/Utils.h deleted file mode 100644 index cb59597..0000000 --- a/ServerConsoleExample/Utils.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -std::wstring to_wstring(const std::string_view& sourceString);