Skip to content

Commit

Permalink
- Improved sc function binder.
Browse files Browse the repository at this point in the history
- Improved GLGSRender.
  • Loading branch information
DHrpcs3 committed Jun 30, 2013
1 parent 3bb7a29 commit 5753edf
Show file tree
Hide file tree
Showing 133 changed files with 13,620 additions and 3,894 deletions.
117 changes: 96 additions & 21 deletions Utilities/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ template<typename T> class Array
const u32 to = from + count;
if(to > GetCount()) return false;

for(u32 i=0; i<count; ++i) m_array[from + i].~T();
memmove(m_array + from, m_array + to, (m_count-to) * sizeof(T));
m_count -= count;

Expand All @@ -44,55 +45,69 @@ template<typename T> class Array
return true;
}

bool Insert(const u32 pos, T* data)
inline bool Move(const u32 pos, T* data)
{
if(!InsertRoom(pos, 1)) return false;

memmove(m_array + pos, data, sizeof(T));
memcpy(m_array + pos, data, sizeof(T));
free(data);

return true;
}

bool Insert(const u32 pos, T& data)
inline u32 Move(T* data)
{
return Insert(pos, &data);
_InsertRoomEnd(1);

memcpy(m_array + GetCount() - 1, data, sizeof(T));
free(data);

return m_count - 1;
}

bool InsertCpy(const u32 pos, const T* data)
inline bool Add(const u32 pos, T*& data)
{
if(!InsertRoom(pos, 1)) return false;

memcpy(m_array + pos, data, sizeof(T));

free(data);
data = m_array + pos;

return true;
}

bool InsertCpy(const u32 pos, const T& data)
{
return InsertCpy(pos, &data);
}

inline u32 Add(T* data)
inline u32 Add(T*& data)
{
_InsertRoomEnd(1);

memmove(m_array + GetCount() - 1, data, sizeof(T));
memcpy(m_array + GetCount() - 1, data, sizeof(T));
free(data);
data = m_array + GetCount() - 1;

return m_count - 1;
}

inline u32 Add(T& data)
inline bool AddCpy(const u32 pos, const T* data, u64 count = 1)
{
return Add(&data);
if(!InsertRoom(pos, count)) return false;

memcpy(m_array + pos, data, sizeof(T) * count);

return true;
}

inline u32 AddCpy(const T* data)
inline bool AddCpy(const u32 pos, const T& data)
{
_InsertRoomEnd(1);
return AddCpy(pos, &data);
}

memcpy(m_array + GetCount() - 1, data, sizeof(T));
inline u32 AddCpy(const T* data, u64 count = 1)
{
_InsertRoomEnd(count);

return m_count - 1;
memcpy(m_array + m_count - count, data, sizeof(T)*count);

return m_count - count;
}

inline u32 AddCpy(const T& data)
Expand All @@ -102,7 +117,9 @@ template<typename T> class Array

inline void Clear()
{
u32 count = m_count;
m_count = 0;
for(u32 i=0; i<count; ++i) m_array[i].~T();
safe_delete(m_array);
}

Expand Down Expand Up @@ -144,8 +161,20 @@ template<typename T> class Array
AppendFrom(src);
}

inline T* GetPtr() { return m_array; }

T& operator[](u32 num) const { return m_array[num]; }

T* operator + (u32 right) const
{
return m_array + right;
}

T* operator ->()
{
return m_array;
}

protected:
void _InsertRoomEnd(const u32 size)
{
Expand Down Expand Up @@ -180,7 +209,6 @@ template<typename T> struct Stack : public Array<T>
}
};


template<typename T> class ArrayF
{
u32 m_count;
Expand All @@ -193,7 +221,7 @@ template<typename T> class ArrayF
{
}

~ArrayF()
virtual ~ArrayF()
{
Clear();
}
Expand Down Expand Up @@ -262,6 +290,53 @@ template<typename T> class ArrayF
return *m_array[num];
}

T** operator + (u32 right) const
{
return m_array + right;
}

T* operator ->()
{
return *m_array;
}

inline T** GetPtr()
{
return m_array;
}

inline u32 GetCount() const { return m_count; }
T& operator[](u32 num) const { return *m_array[num]; }
};

template<typename T> struct ScopedPtr
{
private:
T* m_ptr;

public:
ScopedPtr() : m_ptr(nullptr)
{
}

ScopedPtr(T* ptr) : m_ptr(ptr)
{
}

~ScopedPtr()
{
Swap(nullptr);
}

operator T*() { return m_ptr; }
operator const T*() const { return m_ptr; }

T* operator ->() { return m_ptr; }
const T* operator ->() const { return m_ptr; }

void Swap(T* ptr)
{
delete m_ptr;
m_ptr = ptr;
}
};
2 changes: 1 addition & 1 deletion Utilities/IdManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class IdManager
id.m_used = false;
id.m_attr = 0;
id.m_name.Clear();
if(free_data) free(id.m_data);
if(free_data) delete id.m_data;
id.m_data = NULL;
if(IDToNum(_id) == IDs.GetCount()-1) Cleanup();
return true;
Expand Down
76 changes: 72 additions & 4 deletions Utilities/Thread.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,97 @@
#include "stdafx.h"
#include "Thread.h"

ThreadBase* GetCurrentNamedThread()
{
ThreadExec* thr = (ThreadExec*)::wxThread::This();
return thr ? thr->m_parent : nullptr;
}

ThreadBase::ThreadBase(bool detached, const wxString& name)
: m_detached(detached)
, m_name(name)
, m_executor(nullptr)
{
}

void ThreadBase::Start()
{
if(m_executor) return;

m_executor = new ThreadExec(m_detached, this);
}

void ThreadBase::Resume()
{
if(m_executor)
{
m_executor->Resume();
}
}

void ThreadBase::Pause()
{
if(m_executor)
{
m_executor->Pause();
}
}

void ThreadBase::Stop(bool wait)
{
if(!m_executor) return;
ThreadExec* exec = m_executor;
m_executor = nullptr;
exec->Stop(wait);

if(!m_detached)
{
if(wait)
{
exec->Wait();
}

exec->Stop(false);
delete exec;
}
else
{
exec->Stop(wait);
}
}

bool ThreadBase::IsAlive()
bool ThreadBase::Wait() const
{
return m_executor != nullptr && m_executor->Wait() != (wxThread::ExitCode)-1;
}

bool ThreadBase::IsRunning() const
{
return m_executor != nullptr && m_executor->IsRunning();
}

bool ThreadBase::IsPaused() const
{
return m_executor != nullptr && m_executor->IsPaused();
}

bool ThreadBase::IsAlive() const
{
return m_executor != nullptr;
}

bool ThreadBase::TestDestroy()
bool ThreadBase::TestDestroy() const
{
if(!m_executor) return true;
if(!m_executor || !m_executor->m_parent) return true;

return m_executor->TestDestroy();
}

wxString ThreadBase::GetThreadName() const
{
return m_name;
}

void ThreadBase::SetThreadName(const wxString& name)
{
m_name = name;
}
Loading

0 comments on commit 5753edf

Please sign in to comment.