2 Commits

Author SHA1 Message Date
Michael Fabian Dirks 86e7b2d137 Stuff? 2016-07-20 02:06:53 +02:00
Michael Fabain Dirks ae85c04677 Update README.md 2016-07-01 13:55:25 +02:00
14 changed files with 565 additions and 40 deletions
+8 -2
View File
@@ -158,16 +158,19 @@
<ClInclude Include="Container\TypeList.h" />
<ClInclude Include="Database\SQLite\SQLite.h" />
<ClInclude Include="Database\SQLite\sqlite3.h" />
<ClInclude Include="Timer.h" />
<ClInclude Include="System\FileSystem.h" />
<ClInclude Include="System\Threading.h" />
<ClInclude Include="Time\HighResolutionClock.h" />
<ClInclude Include="Time\SystemClock.h" />
<ClInclude Include="Time\Time.h" />
<ClInclude Include="Time\Timer.h" />
<ClInclude Include="Utility\MassOp.h" />
<ClInclude Include="Type\Double.h" />
<ClInclude Include="Type\Long.h" />
<ClInclude Include="Utility\IndexerV1.h" />
<ClInclude Include="Utility\DisplayEnumerator.h" />
<ClInclude Include="Utility\IndexerV2.h" />
<ClInclude Include="Utility\ThreadWrapper.h" />
<ClInclude Include="Utility\WindowMessageHandler.h" />
</ItemGroup>
<ItemGroup>
@@ -175,10 +178,12 @@
<ClCompile Include="Container\List.cpp" />
<ClCompile Include="Database\SQLite\SQLite.cpp" />
<ClCompile Include="Database\SQLite\sqlite3.c" />
<ClCompile Include="Timer.cpp" />
<ClCompile Include="System\FileSystem.cpp" />
<ClCompile Include="System\Threading.cpp" />
<ClCompile Include="Time\HighResolutionClock.cpp" />
<ClCompile Include="Time\SystemClock.cpp" />
<ClCompile Include="Time\Time.cpp" />
<ClCompile Include="Time\Timer.cpp" />
<ClCompile Include="Type\Double.cpp" />
<ClCompile Include="Type\Long.cpp" />
<ClCompile Include="Utility\IndexerV1.cpp" />
@@ -186,6 +191,7 @@
<ClCompile Include="Utility\DisplayEnumerator.cpp" />
<ClCompile Include="Utility\IndexerV2.cpp" />
<ClCompile Include="Utility\MassOp.cpp" />
<ClCompile Include="Utility\ThreadWrapper.cpp" />
<ClCompile Include="Utility\WindowMessageHandler.cpp" />
</ItemGroup>
<ItemGroup>
+26 -2
View File
@@ -48,6 +48,12 @@
<Filter Include="Resource Files">
<UniqueIdentifier>{13f1a82e-2123-4652-a573-2dd8235ae033}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\System">
<UniqueIdentifier>{5545a0db-1127-4588-8522-680ec51473e0}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\System">
<UniqueIdentifier>{c14c025c-cae9-4d80-abe0-f04895a8f944}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Utility\WindowMessageHandler.cpp">
@@ -95,9 +101,18 @@
<ClCompile Include="Type\Long.cpp">
<Filter>Source Files\Type</Filter>
</ClCompile>
<ClCompile Include="Timer.cpp">
<ClCompile Include="Utility\ThreadWrapper.cpp">
<Filter>Source Files\Utility</Filter>
</ClCompile>
<ClCompile Include="System\Threading.cpp">
<Filter>Source Files\System</Filter>
</ClCompile>
<ClCompile Include="Time\Timer.cpp">
<Filter>Source Files\Time</Filter>
</ClCompile>
<ClCompile Include="System\FileSystem.cpp">
<Filter>Source Files\System</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BlitzUtility.h">
@@ -145,9 +160,18 @@
<ClInclude Include="Type\Long.h">
<Filter>Header Files\Type</Filter>
</ClInclude>
<ClInclude Include="Timer.h">
<ClInclude Include="Utility\ThreadWrapper.h">
<Filter>Header Files\Utility</Filter>
</ClInclude>
<ClInclude Include="System\Threading.h">
<Filter>Header Files\System</Filter>
</ClInclude>
<ClInclude Include="Time\Timer.h">
<Filter>Header Files\Time</Filter>
</ClInclude>
<ClInclude Include="System\FileSystem.h">
<Filter>Header Files\System</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Resources\BlitzUtility.bb">
+11 -1
View File
@@ -1,4 +1,5 @@
# BlitzUtility
BlitzUtility is aimed at extending Blitz beyond it's initial capabilities and is a sub-project of BlitzExtensions.
All functions assume that you are passing valid parameters and do no extra checking to reduce performance impact.
@@ -170,4 +171,13 @@ Easily handle messages sent to Blitz windows using these functions. May not work
* BU_WindowMessageHandler_Uninstall(hwnd%)
* Count% = BU_WindowMessageHandler_Message_Close%(hwnd%)
* Count% = BU_WindowMessageHandler_Message_Destroy%(hwnd%)
* Count% = BU_WindowMessageHandler_Message_Resize%(hwnd%, point*)
* Count% = BU_WindowMessageHandler_Message_Resize%(hwnd%, point*)
# License
Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
+7 -1
View File
@@ -86,7 +86,7 @@ End Type
Function BU_Helper_Window_LockPointer(HWND% = 0)
If HWND = 0 Then
BU_User32_ClipCursor(0)
BU_User32_ClipCursorEx(0)
Else
Local tRect.BU_Rectangle = New BU_Rectangle
@@ -105,6 +105,8 @@ Function BU_Helper_Window_LockPointer(HWND% = 0)
End Function
Function BU_Helper_Window_LockPointerAuto(HWND=0)
If HWND = 0 Then HWND = SystemProperty("AppHwnd")
If BU_User32_GetActiveWindow() = HWND Then
BU_Helper_Window_LockPointer(HWND)
Else
@@ -159,6 +161,8 @@ Function BU_Helper_Window_MakeBorderless(HWND=0)
End Function
Function BU_Helper_Window_Center(HWND=0, Monitor=0)
If HWND = 0 Then HWND = SystemProperty("AppHwnd")
Local displayEnumerator = BU_DisplayEnumerator_Create()
Local displayAmount = BU_DisplayEnumerator_Enumerate(displayEnumerator)
If Monitor >= displayAmount Then Monitor = displayAmount - 1
@@ -195,6 +199,8 @@ Function BU_Helper_Window_Center(HWND=0, Monitor=0)
End Function
Function BU_Helper_Window_Fill(HWND=0, Monitor=0)
If HWND = 0 Then HWND = SystemProperty("AppHwnd")
Local displayEnumerator = BU_DisplayEnumerator_Create()
Local displayAmount = BU_DisplayEnumerator_Enumerate(displayEnumerator)
If Monitor >= displayAmount Then Monitor = displayAmount - 1
+98 -26
View File
@@ -15,8 +15,9 @@
; along with this program. If not, see <http:;www.gnu.org/licenses/>.
.lib "BlitzUtility.dll"
; Container -------------------------------------------------------------------
; -- List (Single Element)
;----------------------------------------------------------------
;! Container - List (Element-wide)
;----------------------------------------------------------------
BU_List_Create%(element*)
BU_List_Destroy%(list%)
BU_List_First%(list%)
@@ -28,12 +29,100 @@ BU_List_After%(list%, other*)
BU_List_Insert(list%, element*)
BU_List_InsertEx(list%, element*, other*)
BU_List_Remove(list%, element*)
; -- TypeList (Single Type)
;----------------------------------------------------------------
;! Container - TypeList (Type-wide)
;----------------------------------------------------------------
BU_TypeList_Create%(obj*)
BU_TypeList_Activate(list%)
BU_TypeList_Deactivate(list%)
BU_TypeList_Destroy(list%)
;----------------------------------------------------------------
;! System - FileSystem
;----------------------------------------------------------------
BU_FileSystem_WriteFile%(Path$)
;@desc: Opens or creates a file for writing only. Truncates existing content.
BU_FileSystem_OpenFile%(Path$)
;@desc: Opens an existing file for reading or writing.
BU_FileSystem_ReadFile%(Path$)
;@desc: Opens an existing file for reading only.
BU_FileSystem_CloseFile(File%)
;@desc: Closes an open file.
BU_FileSystem_FlushFile(File%)
;@desc: Flushes all buffers to disk for the file.
BU_FileSystem_EOF%(File%)
;@desc: Checks if the File handle is valid and not at the end of the file.
;@return:
; 0 = Good, Not End Of File
; 1 = End Of File
; -1 = Bad File Handle
; -2 = Failed to do internal action.
BU_FileSystem_SeekFile(File%, Pos%)
BU_FileSystem_SeekFileIn(File%, Pos%)
BU_FileSystem_SeekFileOut(File%, Pos%)
BU_FileSystem_FilePos%(File%) : "BU_FileSystem_FilePosIn"
BU_FileSystem_FilePosIn%(File%)
BU_FileSystem_FilePosOut%(File%)
BU_FileSystem_WriteByte(File%, Value%)
BU_FileSystem_ReadByte%(File%)
BU_FileSystem_WriteShort(File%, Value%)
BU_FileSystem_ReadShort%(File%)
BU_FileSystem_WriteInt(File%, Value%)
BU_FileSystem_ReadInt%(File%)
BU_FileSystem_WriteFloat(File%, Value#) : "BU_FileSystem_WriteInt"
BU_FileSystem_ReadFloat#(File%) : "BU_FileSystem_ReadInt"
;----------------------------------------------------------------
;! System - Threading
;----------------------------------------------------------------
BU_Thread_Create%(pFunction%, pData%, uiStackSize%, bIsSuspended%)
BU_Thread_Destroy(pThread%)
BU_Thread_Terminate(pThread%, iExitCode%)
BU_Thread_Suspend%(pThread%)
BU_Thread_Resume%(pThread%)
BU_Thread_Wait%(pThread%, iTimeout%)
BU_Thread_GetExitCode%(pThread%)
BU_Thread_Exit(iExitCode%)
BU_Mutex_Create%()
BU_Mutex_Destroy(pMutex%)
BU_Mutex_Lock%(pMutex%, iTimeout%)
BU_Mutex_Unlock%(pMutex%)
;----------------------------------------------------------------
;! Time - Time
;----------------------------------------------------------------
BU_Time_Now%()
BU_Time_Create%(seconds%, minutes%, hours%, days%, months%, years%, isDST%)
BU_Time_Destroy(pTime%)
BU_Time_Format$(pTime%, formatString$)
;----------------------------------------------------------------
;! Time - Timer
;----------------------------------------------------------------
BU_Timer_Create%(Interval%, hwnd%) : "_BU_Timer_Create@8"
BU_Timer_Destroy%(Timer%) : "_BU_Timer_Destroy@4"
BU_Timer_Wait%(Timer%) : "_BU_Timer_Wait@4"
;----------------------------------------------------------------
;! Time - SystemClock
;----------------------------------------------------------------
BU_SystemClock_Now%()
BU_SystemClock_Destroy(pSystemClock%)
BU_SystemClock_FromTime%(pTime%)
BU_SystemClock_AsTime%(pSystemClock%)
;----------------------------------------------------------------
;! Time - HighResolutionClock
;----------------------------------------------------------------
BU_HighResolutionClock_Now%()
BU_HighResolutionClock_Destroy(pHighResolutionClock%)
BU_HighResolutionClock_Duration%(pHighResolutionClock%, pOther%)
BU_HighResolutionClock_DurationLL%(pHighResolutionClock%, pOther%)
BU_HighResolutionClock_DurationF#(pHighResolutionClock%, pOther%)
BU_HighResolutionClock_DurationD%(pHighResolutionClock%, pOther%)
; Database --------------------------------------------------------------------
; -- SQLite3
; Core
@@ -144,29 +233,6 @@ BU_SQLite_Value_SubType%(pValue%)
BU_SQLite_Value_Duplicate%(pValue%)
BU_SQLite_Value_Free(pValue%)
; Time ------------------------------------------------------------------------
; -- Time
BU_Time_Now%()
BU_Time_Create%(seconds%, minutes%, hours%, days%, months%, years%, isDST%)
BU_Time_Destroy(pTime%)
BU_Time_Format$(pTime%, formatString$)
; -- Timer
BU_Timer_Create%(Interval%, hwnd%) : "_BU_Timer_Create@8"
BU_Timer_Destroy%(Timer%) : "_BU_Timer_Destroy@4"
BU_Timer_Wait%(Timer%) : "_BU_Timer_Wait@4"
; -- SystemClock
BU_SystemClock_Now%()
BU_SystemClock_Destroy(pSystemClock%)
BU_SystemClock_FromTime%(pTime%)
BU_SystemClock_AsTime%(pSystemClock%)
; -- HighResolutionClock
BU_HighResolutionClock_Now%()
BU_HighResolutionClock_Destroy(pHighResolutionClock%)
BU_HighResolutionClock_Duration%(pHighResolutionClock%, pOther%)
BU_HighResolutionClock_DurationLL%(pHighResolutionClock%, pOther%)
BU_HighResolutionClock_DurationF#(pHighResolutionClock%, pOther%)
BU_HighResolutionClock_DurationD%(pHighResolutionClock%, pOther%)
; Types - Long ----------------------------------------------------------------
BU_Long_New%() :"_BU_Long_New@0"
BU_Long_Copy%(pThis%) :"_BU_Long_Copy@4"
@@ -267,6 +333,9 @@ BU_MassOp_Create%(length%)
BU_MassOp_Destroy(massop%)
BU_MassOp_Instruction(massop%, index%, type%, code%, leftOperand%, rightOperand%, result%)
BU_MassOp_Run(massop%)
; -- ThreadWrapper
BU_ThreadWrapper_Create%(pFunction%, pData%)
BU_ThreadWrapper_Destroy(pThreadWrapper%)
; -- Window Message Handler
BU_WindowMessageHandler_Install(hwnd%)
BU_WindowMessageHandler_Uninstall(hwnd%)
@@ -274,6 +343,7 @@ BU_WindowMessageHandler_Message_Close%(hwnd%)
BU_WindowMessageHandler_Message_Destroy%(hwnd%)
BU_WindowMessageHandler_Message_Resize%(hwnd%, point*)
; Helpers ---------------------------------------------------------------------
.lib " "
; -- Blitz Functions
@@ -282,6 +352,7 @@ BU_Helper_Window_LockPointerAuto(HWND%)
BU_Helper_Window_MakeBorderless(HWND%)
BU_Helper_Window_Center(HWND%, Monitor%)
BU_Helper_Window_Fill(HWND%, Monitor%)
; -- Windows API (User32)
.lib "User32.dll"
BU_User32_ClientToScreen%(hwnd%, point*) : "ClientToScreen"
@@ -298,6 +369,7 @@ BU_User32_GetClientRect%(hwnd%, rect*) : "GetClientRect"
BU_User32_GetClientRectEx%(hwnd%, rect%) : "GetClientRect"
BU_User32_SetWindowPos%(hwnd%, hWndInsertAfter%, x%, y%, cx%, cy%, wFlags%) : "SetWindowPos"
BU_User32_MessageBox%(hwnd%, lpText$, lpCaption$, uType%) : "MessageBoxA"
; -- Windows API (Kernel32)
.lib "Kernel32.dll"
BU_Kernel32_FlushFileBuffers%(hFile%) : "FlushFileBuffers"
+128
View File
@@ -0,0 +1,128 @@
// BlitzUtility - Expanding the normal Blitz functionality.
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "FileSystem.h"
using namespace std;
DLL_FUNCTION(std::fstream*) BU_FileSystem_WriteFile(const char* path) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_WriteFile=_BU_FileSystem_WriteFile@4")
std::fstream* file = new std::fstream();
file->open(path, ios::in | ios::out || ios::trunc | ios::binary);
return file;
}
DLL_FUNCTION(std::fstream*) BU_FileSystem_OpenFile(const char* path) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_OpenFile=_BU_FileSystem_OpenFile@4")
std::fstream* file = new std::fstream();
file->open(path, ios::in | ios::out | ios::binary);
return file;
}
DLL_FUNCTION(std::fstream*) BU_FileSystem_ReadFile(const char* path) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_ReadFile=_BU_FileSystem_ReadFile@4")
std::fstream* file = new std::fstream();
file->open(path, ios::in | ios::binary);
return file;
}
DLL_FUNCTION(void) BU_FileSystem_CloseFile(std::fstream* file) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_CloseFile=_BU_FileSystem_CloseFile@4")
file->close();
delete file;
}
DLL_FUNCTION(void) BU_FileSystem_FlushFile(std::fstream* file) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_FlushFile=_BU_FileSystem_FlushFile@4")
file->flush();
}
DLL_FUNCTION(int32_t) BU_FileSystem_EOF(std::fstream* file) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_EOF=_BU_FileSystem_EOF@4")
if (file->eof())
return 1;
if (file->bad())
return -1;
if (file->fail())
return -2;
return 0;
}
DLL_FUNCTION(void) BU_FileSystem_SeekFile(std::fstream* file, int32_t pos) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_SeekFile=_BU_FileSystem_SeekFile@8")
file->seekg(pos);
file->seekp(pos);
}
DLL_FUNCTION(void) BU_FileSystem_SeekFileIn(std::fstream* file, int32_t pos) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_SeekFileIn=_BU_FileSystem_SeekFileIn@8")
file->seekg(pos);
}
DLL_FUNCTION(void) BU_FileSystem_SeekFileOut(std::fstream* file, int32_t pos) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_SeekFileOut=_BU_FileSystem_SeekFileOut@8")
file->seekp(pos);
}
DLL_FUNCTION(int32_t) BU_FileSystem_FilePosIn(std::fstream* file) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_FilePosIn=_BU_FileSystem_FilePosIn@4")
return (int32_t)file->tellg();
}
DLL_FUNCTION(int32_t) BU_FileSystem_FilePosOut(std::fstream* file) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_FilePosOut=_BU_FileSystem_FilePosOut@4")
return (int32_t)file->tellp();
}
DLL_FUNCTION(void) BU_FileSystem_WriteByte(std::fstream* file, int32_t value) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_WriteByte=_BU_FileSystem_WriteByte@8")
char myVal[1] = { value & 0xFF};
file->write(myVal, 1);
}
DLL_FUNCTION(int32_t) BU_FileSystem_ReadByte(std::fstream* file) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_ReadByte=_BU_FileSystem_ReadByte@4")
char myVal[1] = { 0 };
file->read(myVal, 1);
return myVal[0];
}
DLL_FUNCTION(void) BU_FileSystem_WriteShort(std::fstream* file, int32_t value) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_WriteShort=_BU_FileSystem_WriteShort@8")
char myVal[2] = { value & 0xFF, (value >> 8) & 0xFF};
file->write(myVal, 2);
}
DLL_FUNCTION(int32_t) BU_FileSystem_ReadShort(std::fstream* file) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_ReadShort=_BU_FileSystem_ReadShort@4")
char myVal[2] = { 0, 0 };
file->read(myVal, 2);
return (myVal[1] << 8) + myVal[0];
}
DLL_FUNCTION(void) BU_FileSystem_WriteInt(std::fstream* file, int32_t value) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_WriteInt=_BU_FileSystem_WriteInt@8")
char myVal[4] = { value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF , (value >> 24) & 0xFF };
file->write(myVal, 4);
}
DLL_FUNCTION(int32_t) BU_FileSystem_ReadInt(std::fstream* file) {
#pragma comment(linker, "/EXPORT:BU_FileSystem_ReadInt=_BU_FileSystem_ReadInt@4")
char myVal[4] = { 0, 0, 0, 0 };
file->read(myVal, 4);
return (myVal[3] << 24) + (myVal[2] << 16) + (myVal[1] << 8) + myVal[0];
}
+21
View File
@@ -0,0 +1,21 @@
// Blitz - Steam wrapper for Blitz.
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include "BlitzUtility.h"
#include <mutex>
#include <iostream>
#include <fstream>
+143
View File
@@ -0,0 +1,143 @@
// BlitzUtility - Expanding the normal Blitz functionality.
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Threading.h"
// Types of Blitz Functions.
typedef int32_t(__stdcall *BP_BlitzFunction1_t)(int32_t);
int32_t BP_CallFunction1(BP_BlitzFunction1_t lpFunctionPointer, int32_t p1) {
int32_t returnValue, StackPointer;
__asm { // Store Stack Pointer
mov StackPointer, esp;
}
returnValue = lpFunctionPointer(p1);
__asm { // Restore Stack Pointer
mov esp, StackPointer;
}
return returnValue;
}
BlitzThread::BlitzThread(void* ptr, void* data, uint32_t uiStackSize, bool bIsSuspended) {
this->ptr = ptr;
this->data = data;
this->thread = CreateThread(NULL, uiStackSize, &ThreadMain, this, (bIsSuspended ? CREATE_SUSPENDED : 0), NULL);
}
BlitzThread::~BlitzThread() {
this->Terminate(-1);
}
void BlitzThread::Terminate(int32_t exitCode) {
if (this->thread) {
TerminateThread(this->thread, -1);
this->thread = 0;
}
}
int32_t BlitzThread::Suspend() {
return SuspendThread(this->thread);
}
int32_t BlitzThread::Resume() {
return ResumeThread(this->thread);
}
int32_t BlitzThread::Wait(int32_t timeout) {
return WaitForSingleObject(this->thread, timeout);
}
int32_t BlitzThread::GetExitCode() {
DWORD pExitCode;
GetExitCodeThread(this->thread, &pExitCode);
return pExitCode;
}
DWORD WINAPI BlitzThread::ThreadMain(LPVOID pData) {
BlitzThread* pThis = reinterpret_cast<BlitzThread*>(pData);
try {
return BP_CallFunction1((BP_BlitzFunction1_t)pThis->ptr, reinterpret_cast<int32_t>(pThis->data));
} catch (std::exception e) {
return -2;
} catch (...) {
return -1;
}
}
DLL_FUNCTION(BlitzThread*) BU_Thread_Create(void* pFunction, void* pData, uint32_t uiStackSize, uint32_t bIsSuspended) {
#pragma comment(linker, "/EXPORT:BU_Thread_Create=_BU_Thread_Create@16")
return new BlitzThread(pFunction, pData, uiStackSize, !!bIsSuspended);
}
DLL_FUNCTION(void) BU_Thread_Destroy(BlitzThread* pThread) {
#pragma comment(linker, "/EXPORT:BU_Thread_Destroy=_BU_Thread_Destroy@4")
delete pThread;
}
DLL_FUNCTION(void) BU_Thread_Terminate(BlitzThread* pThread, int32_t exitCode) {
#pragma comment(linker, "/EXPORT:BU_Thread_Terminate=_BU_Thread_Terminate@8")
pThread->Terminate(exitCode);
delete pThread;
}
DLL_FUNCTION(int32_t) BU_Thread_Suspend(BlitzThread* pThread) {
#pragma comment(linker, "/EXPORT:BU_Thread_Suspend=_BU_Thread_Suspend@4")
return pThread->Suspend();
}
DLL_FUNCTION(int32_t) BU_Thread_Resume(BlitzThread* pThread) {
#pragma comment(linker, "/EXPORT:BU_Thread_Resume=_BU_Thread_Resume@4")
return pThread->Resume();
}
DLL_FUNCTION(int32_t) BU_Thread_Wait(BlitzThread* pThread, int32_t timeout) {
#pragma comment(linker, "/EXPORT:BU_Thread_Wait=_BU_Thread_Wait@8")
return pThread->Wait(timeout);
}
DLL_FUNCTION(int32_t) BU_Thread_GetExitCode(BlitzThread* pThread) {
#pragma comment(linker, "/EXPORT:BU_Thread_GetExitCode=_BU_Thread_GetExitCode@4")
return pThread->GetExitCode();
}
DLL_FUNCTION(void) BU_Thread_Exit(int32_t exitCode) {
#pragma comment(linker, "/EXPORT:BU_Thread_Exit=_BU_Thread_Exit@4")
ExitThread(exitCode);
}
DLL_FUNCTION(HANDLE) BU_Mutex_Create(int32_t bInitialOwner) {
#pragma comment(linker, "/EXPORT:BU_Mutex_Create=_BU_Mutex_Create@4")
return CreateMutex(NULL, !!bInitialOwner, NULL);
}
DLL_FUNCTION(void) BU_Mutex_Destroy(HANDLE mutex) {
#pragma comment(linker, "/EXPORT:BU_Mutex_Destroy=_BU_Mutex_Destroy@4")
CloseHandle(mutex);
}
DLL_FUNCTION(int32_t) BU_Mutex_Lock(HANDLE mutex, int32_t timeout) {
#pragma comment(linker, "/EXPORT:BU_Mutex_Lock=_BU_Mutex_Lock@8")
return WaitForSingleObject(mutex, timeout);
}
DLL_FUNCTION(int32_t) BU_Mutex_Unlock(HANDLE mutex) {
#pragma comment(linker, "/EXPORT:BU_Mutex_Unlock=_BU_Mutex_Unlock@4")
return ReleaseMutex(mutex);
}
+44
View File
@@ -0,0 +1,44 @@
// Blitz - Steam wrapper for Blitz.
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include "BlitzUtility.h"
#include <mutex>
#include <chrono>
class BlitzThread {
public:
BlitzThread(void* ptr, void* data, uint32_t uiStackSize, bool bIsSuspended);
~BlitzThread();
void Terminate(int32_t exitCode);
int32_t Suspend();
int32_t Resume();
int32_t Wait(int32_t timeout);
int32_t GetExitCode();
static DWORD WINAPI ThreadMain(LPVOID pData);
private:
void *ptr, *data;
std::exception* ex;
HANDLE thread;
};
+4 -8
View File
@@ -44,18 +44,14 @@ DLL_FUNCTION(void) BU_Time_Destroy(time_t* pTime) {
delete pTime;
}
char* BU_Time_Format_Buffer = new char[1024];
DLL_FUNCTION(const char*) BU_Time_Format(time_t* pTime, const char* pchFormatString) {
#pragma comment(linker, "/EXPORT:BU_Time_Format=_BU_Time_Format@8")
std::string buffer;
tm* pTM = new tm;
localtime_s(pTM, pTime);
uint32_t length = strlen(pchFormatString);
buffer.resize(length);
while (strftime(&buffer[0], buffer.size(), pchFormatString, pTM) == 0) {
buffer.resize(buffer.size() * 2);
}
strftime(BU_Time_Format_Buffer, 1024, pchFormatString, pTM);
delete pTM;
return buffer.c_str();
return BU_Time_Format_Buffer;
}
View File
View File
+53
View File
@@ -0,0 +1,53 @@
// BlitzUtility - Expanding the normal Blitz functionality.
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ThreadWrapper.h"
class ThreadWrapper {
public:
ThreadWrapper(void* ptr, void* data) {
this->ptr = ptr;
this->data = data;
}
~ThreadWrapper() {
}
static int Core(ThreadWrapper* data) {
try {
BP_CallFunction1((BP_BlitzFunction1_t)data->ptr, reinterpret_cast<int32_t>(data->data));
} catch (const std::exception& e) {
std::stringstream ss;
ss << e.what();
MessageBoxA(0, ss.str().c_str(), "ThreadWrapper", 0);
throw;
}
}
private:
void *ptr, *data;
std::exception lastException;
};
DLL_FUNCTION(ThreadWrapper*) BU_ThreadWrapper_Create(void* ptr, void* data) {
#pragma comment(linker, "/EXPORT:BU_ThreadWrapper_Create=_BU_ThreadWrapper_Create@8")
return new ThreadWrapper(ptr, data);
}
DLL_FUNCTION(void) BU_ThreadWrapper_Destroy(ThreadWrapper* pThreadWrapper) {
#pragma comment(linker, "/EXPORT:BU_ThreadWrapper_Destroy=_BU_ThreadWrapper_Destroy@4")
delete pThreadWrapper;
}
+22
View File
@@ -0,0 +1,22 @@
// Blitz - Steam wrapper for Blitz.
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include "BlitzUtility.h"
// Types of Blitz Functions.
typedef int32_t(__stdcall *BP_BlitzFunction1_t)(int32_t);
int32_t BP_CallFunction1(BP_BlitzFunction1_t lpFunctionPointer, int32_t p1);