From be0cc2f3d569defd77f71fa67ed16c0d6607c2a1 Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Mon, 27 Feb 2017 01:48:54 +0700 Subject: [PATCH] Switch to Visual Studio 2015 compiler. Test some features with Delegate class --- sfall/Delegate.h | 89 +++++++++++++++++----------------- sfall/Modules/LoadGameHook.cpp | 3 +- sfall/ddraw.vcxproj | 4 +- sfall/version.h | 2 + sfall/version.rc | 2 +- 5 files changed, 51 insertions(+), 49 deletions(-) diff --git a/sfall/Delegate.h b/sfall/Delegate.h index aaf1a3f1..9b9b10d8 100644 --- a/sfall/Delegate.h +++ b/sfall/Delegate.h @@ -3,63 +3,62 @@ #include #include - -typedef std::function Functor; // std::function -typedef std::vector FunctorCollection; - -// template +template class Delegate { public: - Delegate() : _functors() {} // Delegate() + using Functor = std::function; + using FunctorCollection = std::vector; - void add(Functor func) { - _functors.emplace_back(std::move(func)); - } + Delegate() {} - /*void add(const Delegate& other) - { - for (auto& func : other.functors()) - { - add(func); - } - }*/ + void add(Functor func) { + _functors.emplace_back(std::move(func)); + } - void clear() { - _functors.clear(); - } + void add(const Delegate& other) + { + for (auto& func : other.functors()) + { + add(func); + } + } - void invoke() { // invoke(ArgT... args) - for (auto it = _functors.begin(); it != _functors.end(); ++it) { - (*it)(); // args... - } - } + void clear() { + _functors.clear(); + } - const FunctorCollection& functors() const { - return _functors; - } + void invoke(ArgT... args) { + for (auto& func : _functors) { + func(args...); + } + } - Delegate operator =(Functor func) { - clear(); - add(std::move(func)); - return *this; - } + const FunctorCollection& functors() const { + return _functors; + } - Delegate operator=(std::nullptr_t) { - clear(); - return *this; - } + Delegate operator =(Functor func) { + clear(); + add(std::move(func)); + return *this; + } - Delegate operator +=(Functor func) { - add(std::move(func)); - return *this; - } + Delegate operator=(std::nullptr_t) { + clear(); + return *this; + } - Delegate operator +=(const Delegate other) { - add(other); - return *this; - } + Delegate operator +=(Functor func) { + add(std::move(func)); + return *this; + } + + Delegate operator +=(const Delegate other) { + add(other); + return *this; + } private: - FunctorCollection _functors; + FunctorCollection _functors; }; diff --git a/sfall/Modules/LoadGameHook.cpp b/sfall/Modules/LoadGameHook.cpp index 21368ef8..180cfb5e 100644 --- a/sfall/Modules/LoadGameHook.cpp +++ b/sfall/Modules/LoadGameHook.cpp @@ -18,6 +18,7 @@ #include "..\main.h" +#include "..\Delegate.h" #include "..\FalloutEngine\Fallout2.h" #include "..\InputFuncs.h" #include "..\Logging.h" @@ -43,7 +44,7 @@ #include "Sound.h" #include "ExtraSaveSlots.h" -//static Delegate OnBeforeLoadGame; +static Delegate<> OnBeforeLoadGame; //static Delegate OnAfterLoadGame; #define MAX_GLOBAL_SIZE (MaxGlobalVars * 12 + 4) diff --git a/sfall/ddraw.vcxproj b/sfall/ddraw.vcxproj index 239a08ce..a72667b3 100644 --- a/sfall/ddraw.vcxproj +++ b/sfall/ddraw.vcxproj @@ -24,7 +24,7 @@ DynamicLibrary NotSet true - v100 + v140 DynamicLibrary @@ -35,7 +35,7 @@ DynamicLibrary NotSet - v100 + v140 diff --git a/sfall/version.h b/sfall/version.h index 8901c0a3..1c81d685 100644 --- a/sfall/version.h +++ b/sfall/version.h @@ -20,6 +20,8 @@ #define TARGETVERSION "Fallout 2 v1.02 US" +#define LEGAL_COPYRIGHT "Copyright (C) 2006-2017, sfall team" + #define VERSION_MAJOR 4 #define VERSION_MINOR 0 #define VERSION_BUILD 0 diff --git a/sfall/version.rc b/sfall/version.rc index 30f16c66..3bde0d2c 100644 --- a/sfall/version.rc +++ b/sfall/version.rc @@ -11,7 +11,7 @@ BEGIN VALUE "FileDescription", "sfall, built for " TARGETVERSION VALUE "FileVersion", VERSION_STRING VALUE "InternalName", "sfall" - VALUE "LegalCopyright", "Copyright (C) 2006-2017, Timeslip" + VALUE "LegalCopyright", LEGAL_COPYRIGHT VALUE "ProductName", "sfall" VALUE "ProductVersion", VERSION_STRING END