From 06652bfa0d6701cf64e5534cb3de2d894d6d3c1f Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Tue, 19 Feb 2013 12:37:56 +0000 Subject: [PATCH] Network stuff and Utils Engine --- UtilsEngine/UtilsEngine.vcxproj | 5 +++-- include/Engine.h | 10 ++++++++++ include/Utils/Console/console.h | 2 ++ include/Utils/Network/Network.h | 1 + include/Utils/ThreadUtils.h | 4 +++- src/Utils/Console/Console.cpp | 3 +++ src/Utils/Network/Network.cpp | 8 ++++---- src/Utils/SerializeInterface/SerializeInterface.cpp | 8 ++++++++ src/Utils/ThreadUtils.cpp | 2 ++ src/Utils/WinApi/WinApi.cpp | 12 ++++++------ 10 files changed, 42 insertions(+), 13 deletions(-) diff --git a/UtilsEngine/UtilsEngine.vcxproj b/UtilsEngine/UtilsEngine.vcxproj index 7647468..b60ec6f 100644 --- a/UtilsEngine/UtilsEngine.vcxproj +++ b/UtilsEngine/UtilsEngine.vcxproj @@ -41,7 +41,7 @@ Level3 Disabled - $(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510 + $(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include UTILS_ENGINE;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG @@ -54,7 +54,7 @@ MaxSpeed true true - $(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510 + $(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include UTILS_ENGINE;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501 @@ -75,6 +75,7 @@ + diff --git a/include/Engine.h b/include/Engine.h index f447442..7651c8a 100644 --- a/include/Engine.h +++ b/include/Engine.h @@ -1,6 +1,14 @@ #ifndef ENGINE_H_INCLUDED #define ENGINE_H_INCLUDED + +#ifdef UTILS_ENGINE + +#include "include/Utils/Utils.h" + +#else + + #ifdef TARGET_WIN32 #include "SalmonEngineWindows.h" #endif @@ -13,4 +21,6 @@ #include "include/SalmonEngineIos.h" #endif +#endif + #endif //ENGINE_H_INCLUDED \ No newline at end of file diff --git a/include/Utils/Console/console.h b/include/Utils/Console/console.h index af4c035..1b2f08d 100644 --- a/include/Utils/Console/console.h +++ b/include/Utils/Console/console.h @@ -60,7 +60,9 @@ public: virtual std::string GetHistory(); +#ifndef UTILS_ENGINE virtual void Draw(); +#endif }; diff --git a/include/Utils/Network/Network.h b/include/Utils/Network/Network.h index c41dd41..86e260e 100644 --- a/include/Utils/Network/Network.h +++ b/include/Utils/Network/Network.h @@ -81,6 +81,7 @@ public: typedef boost::variant> TAuthorizationVariant; + class TClientSocket : public boost::enable_shared_from_this { protected: diff --git a/include/Utils/ThreadUtils.h b/include/Utils/ThreadUtils.h index 2caa83f..eb9f321 100644 --- a/include/Utils/ThreadUtils.h +++ b/include/Utils/ThreadUtils.h @@ -7,7 +7,7 @@ namespace SE { - + #ifndef UTILS_ENGINE struct TFuncToPerform { private: @@ -34,6 +34,8 @@ namespace SE template RETURNTYPE PerformInMainThread(boost::function f); +#endif + } //namespace SE #endif \ No newline at end of file diff --git a/src/Utils/Console/Console.cpp b/src/Utils/Console/Console.cpp index 17753f2..93172ff 100644 --- a/src/Utils/Console/Console.cpp +++ b/src/Utils/Console/Console.cpp @@ -12,6 +12,8 @@ const int CONST_ROW_WIDTH = 14; const std::string CONST_CONSOLE_TEX_NAME = "console_bkg.bmp"; +#ifndef UTILS_ENGINE + void TSimpleConsole::Draw() { @@ -59,6 +61,7 @@ void TSimpleConsole::Draw() } +#endif void TSimpleConsole::CutHistory() { diff --git a/src/Utils/Network/Network.cpp b/src/Utils/Network/Network.cpp index 67bf6a7..d740795 100644 --- a/src/Utils/Network/Network.cpp +++ b/src/Utils/Network/Network.cpp @@ -93,7 +93,7 @@ TSimpleAuthorization::TSimpleAuthorization(boost::asio::io_service& ioService, b void TSimpleAuthorization::Authorize() { - std::shared_ptr dataReader(new TDataReader(Socket)); + boost::shared_ptr dataReader(new TDataReader(Socket)); dataReader->DataReadSignal.connect(boost::bind(&TSimpleAuthorization::HandleGetData, this, _1)); @@ -115,8 +115,8 @@ void TSimpleAuthorization::HandleGetData(boost::property_tree::ptree pTree) { if (pTree.find("OnHello") != pTree.not_found()) { - Login = p.get("OnHello.Login"); - Password = p.get("OnHello.Password"); + Login = pTree.get("OnHello.Login"); + Password = pTree.get("OnHello.Password"); SaveLoginPasswordSignal(Login, Password); AuthorizedSignal(); @@ -172,7 +172,7 @@ void TClientSocket::Open(const std::string address, const std::string& port) return; } - boost::asio::async_connect(Socket, iterator, boost::bind(&TClientSocket::HandleConnect, shared_from_this(), boost::asio::placeholders::error)); + boost::asio::async_connect(Socket, iterator, boost::bind(&TClientSocket::HandleConnect, this, boost::asio::placeholders::error)); ConnectionTimeoutTimer = boost::shared_ptr(new boost::asio::deadline_timer(IoService, boost::posix_time::seconds(CONST_CONNECTION_TIMEOUT_SECONDS))); diff --git a/src/Utils/SerializeInterface/SerializeInterface.cpp b/src/Utils/SerializeInterface/SerializeInterface.cpp index cdd80ff..8927ad7 100644 --- a/src/Utils/SerializeInterface/SerializeInterface.cpp +++ b/src/Utils/SerializeInterface/SerializeInterface.cpp @@ -53,7 +53,11 @@ boost::property_tree::ptree::iterator ReplaceIncludeFile(boost::property_tree::p } } +#ifdef UTILS_ENGINE + xmlFileArr = CreateMemFromFile(fileName, xmlFileSize); +#else xmlFileArr = CreateMemFromFile(ResourceManager->PathToResources + fileName, xmlFileSize); +#endif std::string xmlString = std::string(&xmlFileArr[0], &xmlFileArr[xmlFileSize]); @@ -143,7 +147,11 @@ std::shared_ptr FileToPropertyTree(const std::strin { cardinal byteCount; +#ifdef UTILS_ENGINE + boost::shared_array file = CreateMemFromFile(fileName, byteCount); +#else boost::shared_array file = CreateMemFromFile(ResourceManager->PathToResources + fileName, byteCount); +#endif return FileToPropertyTree(file, byteCount, replaceMap); } diff --git a/src/Utils/ThreadUtils.cpp b/src/Utils/ThreadUtils.cpp index 285ceba..52894d3 100644 --- a/src/Utils/ThreadUtils.cpp +++ b/src/Utils/ThreadUtils.cpp @@ -3,6 +3,7 @@ namespace SE { +#ifndef UTILS_ENGINE void AssertIfInMainThread() { if (boost::this_thread::get_id() != ResourceManager->MainThreadId) @@ -30,5 +31,6 @@ namespace SE ResourceManager->MainThreadAsyncFunctionArr.push_back(f); } } +#endif } //namespace SE \ No newline at end of file diff --git a/src/Utils/WinApi/WinApi.cpp b/src/Utils/WinApi/WinApi.cpp index 1fd6029..63a3a22 100644 --- a/src/Utils/WinApi/WinApi.cpp +++ b/src/Utils/WinApi/WinApi.cpp @@ -8,27 +8,27 @@ Here goes all functions that are platform-specific When I make iOS/Mac/Linux port, I will make same API pair h/cpp */ -void GetWindowWidthHeight(int& width, int& height) +void GetWindowWidthHeight(HWND hwnd, int& width, int& height) { RECT rc; - GetClientRect(Hwnd, &rc); + GetClientRect(hwnd, &rc); width = rc.right; height = rc.bottom; } -int GetWindowWidth() +int GetWindowWidth(HWND hwnd) { RECT rc; - GetClientRect(Hwnd, &rc); + GetClientRect(hwnd, &rc); return rc.right; } -int GetWindowHeight() +int GetWindowHeight(HWND hwnd) { RECT rc; - GetClientRect(Hwnd, &rc); + GetClientRect(hwnd, &rc); return rc.bottom; }