forked from isledecomp/isle-portable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request isledecomp#15 from WamWooWam/mxautolocker
lego1: implement MxAutoLocker, MxTimer + dependencies
- Loading branch information
Showing
18 changed files
with
487 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "mxautolocker.h" | ||
|
||
MxAutoLocker::MxAutoLocker(MxCriticalSection *critsect) | ||
{ | ||
this->m_criticalSection = critsect; | ||
if (this->m_criticalSection != 0) | ||
this->m_criticalSection->Enter(); | ||
} | ||
|
||
MxAutoLocker::~MxAutoLocker() | ||
{ | ||
if (this->m_criticalSection != 0) | ||
this->m_criticalSection->Leave(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef MXAUTOLOCKER_H | ||
#define MXAUTOLOCKER_H | ||
|
||
#include "mxcriticalsection.h" | ||
|
||
class MxAutoLocker | ||
{ | ||
public: | ||
MxAutoLocker(MxCriticalSection* cs); | ||
virtual ~MxAutoLocker(); | ||
private: | ||
MxCriticalSection* m_criticalSection; | ||
}; | ||
|
||
#endif // MXAUTOLOCKER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,7 @@ | |
|
||
typedef unsigned char MxBool; | ||
|
||
#define MX_TRUE 1 | ||
#define MX_FALSE 0 | ||
|
||
#endif // MXBOOL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "mxomni.h" | ||
|
||
MxResult MxOmni::Create(const MxOmniCreateParam &p) | ||
{ | ||
if (p.CreateFlags().CreateTimer()) | ||
{ | ||
MxTimer *timer = new MxTimer(); | ||
this->m_Timer = timer; | ||
|
||
if (timer == NULL) | ||
return FAILURE; | ||
} | ||
|
||
return SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
#ifndef MXOMNI_H | ||
#define MXOMNI_H | ||
|
||
#include "mxresult.h" | ||
#include "mxomnicreateparam.h" | ||
#include "mxomnicreateflags.h" | ||
#include "mxtimer.h" | ||
|
||
class MxOmni | ||
{ | ||
public: | ||
__declspec(dllexport) static void DestroyInstance(); | ||
__declspec(dllexport) static const char * GetCD(); | ||
__declspec(dllexport) static const char * GetHD(); | ||
__declspec(dllexport) static MxOmni * GetInstance(); | ||
__declspec(dllexport) static const char *GetCD(); | ||
__declspec(dllexport) static const char *GetHD(); | ||
__declspec(dllexport) static MxOmni *GetInstance(); | ||
__declspec(dllexport) static unsigned char IsSound3D(); | ||
__declspec(dllexport) static void SetCD(const char *s); | ||
__declspec(dllexport) static void SetHD(const char *s); | ||
__declspec(dllexport) static void SetSound3D(unsigned char); | ||
|
||
MxResult MxOmni::Create(const MxOmniCreateParam &p); | ||
|
||
MxTimer* GetTimer() const { return this->m_Timer; } | ||
|
||
private: | ||
char padding[0x3c]; | ||
MxTimer* m_Timer; | ||
}; | ||
|
||
#endif // MXOMNI_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "mxomnicreateflags.h" | ||
|
||
MxOmniCreateFlags::MxOmniCreateFlags() | ||
{ | ||
this->CreateObjectFactory(MX_TRUE); | ||
this->CreateVariableTable(MX_TRUE); | ||
this->CreateTickleManager(MX_TRUE); | ||
this->CreateNotificationManager(MX_TRUE); | ||
this->CreateVideoManager(MX_TRUE); | ||
this->CreateSoundManager(MX_TRUE); | ||
this->CreateMusicManager(MX_TRUE); | ||
this->CreateEventManager(MX_TRUE); | ||
|
||
this->CreateTimer(MX_TRUE); | ||
this->CreateStreamer(MX_TRUE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,56 @@ | ||
#ifndef MXOMNICREATEFLAGS_H | ||
#define MXOMNICREATEFLAGS_H | ||
|
||
#include "mxbool.h" | ||
|
||
class MxOmniCreateFlags | ||
{ | ||
public: | ||
enum LowFlags { | ||
Flag_CreateObjectFactory = 0x01, | ||
Flag_CreateVariableTable = 0x02, | ||
Flag_CreateTickleManager = 0x04, | ||
Flag_CreateNotificationManager = 0x08, | ||
Flag_CreateVideoManager = 0x10, | ||
Flag_CreateSoundManager = 0x20, | ||
Flag_CreateMusicManager = 0x40, | ||
Flag_CreateEventManager = 0x80 | ||
}; | ||
|
||
enum HighFlags { | ||
Flag_CreateTimer = 0x02, | ||
Flag_CreateStreamer = 0x04 | ||
}; | ||
|
||
__declspec(dllexport) MxOmniCreateFlags(); | ||
|
||
const inline MxBool CreateObjectFactory() const { return this->m_flags1 & Flag_CreateObjectFactory; } | ||
const inline MxBool CreateVariableTable() const { return this->m_flags1 & Flag_CreateVariableTable; } | ||
const inline MxBool CreateTickleManager() const { return this->m_flags1 & Flag_CreateTickleManager; } | ||
const inline MxBool CreateNotificationManager() const { return this->m_flags1 & Flag_CreateNotificationManager; } | ||
const inline MxBool CreateVideoManager() const { return this->m_flags1 & Flag_CreateVideoManager; } | ||
const inline MxBool CreateSoundManager() const { return this->m_flags1 & Flag_CreateSoundManager; } | ||
const inline MxBool CreateMusicManager() const { return this->m_flags1 & Flag_CreateMusicManager; } | ||
const inline MxBool CreateEventManager() const { return this->m_flags1 & Flag_CreateEventManager; } | ||
|
||
private: | ||
unsigned short m_flags; | ||
const inline MxBool CreateTimer() const { return this->m_flags2 & Flag_CreateTimer; } | ||
const inline MxBool CreateStreamer() const { return this->m_flags2 & Flag_CreateStreamer; } | ||
|
||
inline void CreateObjectFactory(MxBool b) { this->m_flags1 = (b == MX_TRUE ? this->m_flags1 | Flag_CreateObjectFactory : this->m_flags1 & ~Flag_CreateObjectFactory); } | ||
inline void CreateVariableTable(MxBool b) { this->m_flags1 = (b == MX_TRUE ? this->m_flags1 | Flag_CreateVariableTable : this->m_flags1 & ~Flag_CreateVariableTable); } | ||
inline void CreateTickleManager(MxBool b) { this->m_flags1 = (b == MX_TRUE ? this->m_flags1 | Flag_CreateTickleManager : this->m_flags1 & ~Flag_CreateTickleManager); } | ||
inline void CreateNotificationManager(MxBool b) { this->m_flags1 = (b == MX_TRUE ? this->m_flags1 | Flag_CreateNotificationManager : this->m_flags1 & ~Flag_CreateNotificationManager); } | ||
inline void CreateVideoManager(MxBool b) { this->m_flags1 = (b == MX_TRUE ? this->m_flags1 | Flag_CreateVideoManager : this->m_flags1 & ~Flag_CreateVideoManager); } | ||
inline void CreateSoundManager(MxBool b) { this->m_flags1 = (b == MX_TRUE ? this->m_flags1 | Flag_CreateSoundManager : this->m_flags1 & ~Flag_CreateSoundManager); } | ||
inline void CreateMusicManager(MxBool b) { this->m_flags1 = (b == MX_TRUE ? this->m_flags1 | Flag_CreateMusicManager : this->m_flags1 & ~Flag_CreateMusicManager); } | ||
inline void CreateEventManager(MxBool b) { this->m_flags1 = (b == MX_TRUE ? this->m_flags1 | Flag_CreateEventManager : this->m_flags1 & ~Flag_CreateEventManager); } | ||
|
||
inline void CreateTimer(MxBool b) { this->m_flags2 = (b == MX_TRUE ? this->m_flags2 | Flag_CreateTimer : this->m_flags2 & ~Flag_CreateTimer); } | ||
inline void CreateStreamer(MxBool b) { this->m_flags2 = (b == MX_TRUE ? this->m_flags2 | Flag_CreateStreamer : this->m_flags2 & ~Flag_CreateStreamer); } | ||
|
||
private: | ||
unsigned char m_flags1; | ||
unsigned char m_flags2; | ||
}; | ||
|
||
#endif // MXOMNICREATEFLAGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "mxomnicreateparam.h" | ||
|
||
MxOmniCreateParam::MxOmniCreateParam(const char *mediaPath, HWND windowHandle, MxVideoParam &vparam, MxOmniCreateFlags flags) | ||
{ | ||
this->m_mediaPath = mediaPath; | ||
this->m_windowHandle = windowHandle; | ||
this->m_videoParam = vparam; | ||
this->m_createFlags = flags; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "mxstring.h" | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
MxString::MxString() | ||
{ | ||
// Set string to one char in length and set that char to null terminator | ||
this->m_data = (char *)malloc(1); | ||
this->m_data[0] = 0; | ||
this->m_length = 0; | ||
} | ||
|
||
// TODO: this *mostly* matches, again weird with the comparison | ||
const MxString &MxString::operator=(const char *param) | ||
{ | ||
if (this->m_data != param) | ||
{ | ||
free(this->m_data); | ||
this->m_length = strlen(param); | ||
this->m_data = (char *)malloc(this->m_length + 1); | ||
strcpy(this->m_data, param); | ||
} | ||
|
||
return *this; | ||
} | ||
|
||
MxString::~MxString() | ||
{ | ||
free(this->m_data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "mxtimer.h" | ||
|
||
#include <windows.h> | ||
|
||
long MxTimer::s_LastTimeCalculated = 0; | ||
long MxTimer::s_LastTimeTimerStarted = 0; | ||
|
||
MxTimer::MxTimer() | ||
{ | ||
this->m_isRunning = MX_FALSE; | ||
MxTimer::s_LastTimeCalculated = timeGetTime(); | ||
this->m_startTime = MxTimer::s_LastTimeCalculated; | ||
} | ||
|
||
void MxTimer::Start() | ||
{ | ||
this->m_isRunning = MX_TRUE; | ||
MxTimer::s_LastTimeTimerStarted = timeGetTime(); | ||
} | ||
|
||
void MxTimer::Stop() | ||
{ | ||
long elapsed = this->GetRealTime(); | ||
long startTime = elapsed - MxTimer::s_LastTimeTimerStarted; | ||
this->m_isRunning = MX_FALSE; | ||
// this feels very stupid but it's what the assembly does | ||
this->m_startTime = this->m_startTime + startTime - 5; | ||
} | ||
|
||
long MxTimer::GetRealTime() | ||
{ | ||
MxTimer::s_LastTimeCalculated = timeGetTime(); | ||
return MxTimer::s_LastTimeCalculated - this->m_startTime; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
#ifndef MXTIMER_H | ||
#define MXTIMER_H | ||
|
||
class MxTimer | ||
#include "mxcore.h" | ||
|
||
class MxTimer : public MxCore | ||
{ | ||
public: | ||
MxTimer(); | ||
|
||
void Start(); | ||
void Stop(); | ||
|
||
__declspec(dllexport) long GetRealTime(); | ||
|
||
long GetTime() inline | ||
{ | ||
if (this->m_isRunning) | ||
return s_LastTimeCalculated; | ||
else | ||
return s_LastTimeCalculated - this->m_startTime; | ||
} | ||
|
||
private: | ||
long m_startTime; | ||
MxBool m_isRunning; | ||
static long s_LastTimeCalculated; | ||
static long s_LastTimeTimerStarted; | ||
}; | ||
|
||
#endif // MXTIMER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "mxvideoparam.h" | ||
|
||
MxVideoParam::MxVideoParam() | ||
{ | ||
this->m_flags = MxVideoParamFlags(); | ||
this->m_right = 640; | ||
this->m_bottom = 480; | ||
this->m_left = 0; | ||
this->m_top = 0; | ||
this->m_palette = 0; | ||
this->m_backBuffers = 0; | ||
this->m_unk1c = 0; | ||
this->m_deviceId = 0; | ||
} | ||
|
||
MxVideoParam &MxVideoParam::operator=(const MxVideoParam &other) | ||
{ | ||
m_flags = MxVideoParamFlags(); | ||
m_left = other.m_left; | ||
m_top = other.m_top; | ||
m_right = other.m_right; | ||
m_bottom = other.m_bottom; | ||
m_palette = other.m_palette; | ||
m_backBuffers = other.m_backBuffers; | ||
m_flags = other.m_flags; | ||
m_unk1c = other.m_unk1c; | ||
m_deviceId = other.m_deviceId; | ||
SetDeviceName(other.m_deviceId); | ||
|
||
return *this; | ||
} | ||
|
||
void MxVideoParam::SetDeviceName(char *id) | ||
{ | ||
if (this->m_deviceId != 0) | ||
free(this->m_deviceId); | ||
|
||
if (id != 0) | ||
{ | ||
this->m_deviceId = (char *)malloc(strlen(id) + 1); | ||
|
||
if (this->m_deviceId != 0) { | ||
strcpy(this->m_deviceId, id); | ||
} | ||
} | ||
else { | ||
this->m_deviceId = 0; | ||
} | ||
} | ||
|
||
MxVideoParam::~MxVideoParam() | ||
{ | ||
if (this->m_deviceId != 0) | ||
free(this->m_deviceId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include "mxvideoparamflags.h" | ||
|
||
MxVideoParamFlags::MxVideoParamFlags() | ||
{ | ||
// TODO: convert to EnableXXX function calls | ||
unsigned char bVar1 = this->m_flags1; | ||
this->m_flags1 = bVar1 & 0xfe; | ||
this->m_flags1 = bVar1 & 0xfc; | ||
this->m_flags1 = bVar1 & 0xf8; | ||
this->m_flags1 = bVar1 & 0xf0; | ||
this->m_flags1 = bVar1 & 0xe0; | ||
this->m_flags2 = this->m_flags2 | 2; | ||
this->m_flags1 = bVar1 & 0xc0; | ||
this->m_flags1 = bVar1 & 0xc0 | 0x40; | ||
this->m_flags1 = 0xc0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#ifndef MXVIDEOPARAMFLAGS_H | ||
#define MXVIDEOPARAMFLAGS_H | ||
|
||
#include <windows.h> | ||
|
||
class MxVideoParamFlags | ||
{ | ||
public: | ||
|
Oops, something went wrong.