- Improved sc function binder.

- Improved GLGSRender.
This commit is contained in:
DH 2013-06-30 11:46:29 +03:00
parent 3bb7a299ca
commit 5753edf6ef
133 changed files with 13624 additions and 3898 deletions

View file

@ -23,6 +23,7 @@ public:
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;
@ -44,57 +45,71 @@ public:
return true;
}
bool Insert(const u32 pos, T* data)
{
if(!InsertRoom(pos, 1)) return false;
memmove(m_array + pos, data, sizeof(T));
return true;
}
bool Insert(const u32 pos, T& data)
{
return Insert(pos, &data);
}
bool InsertCpy(const u32 pos, const T* data)
inline bool Move(const u32 pos, T* data)
{
if(!InsertRoom(pos, 1)) return false;
memcpy(m_array + pos, data, sizeof(T));
free(data);
return true;
}
bool InsertCpy(const u32 pos, const T& data)
{
return InsertCpy(pos, &data);
}
inline u32 Add(T* data)
{
_InsertRoomEnd(1);
memmove(m_array + GetCount() - 1, data, sizeof(T));
return m_count - 1;
}
inline u32 Add(T& data)
{
return Add(&data);
}
inline u32 AddCpy(const T* data)
inline u32 Move(T* data)
{
_InsertRoomEnd(1);
memcpy(m_array + GetCount() - 1, data, sizeof(T));
free(data);
return m_count - 1;
}
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;
}
inline u32 Add(T*& data)
{
_InsertRoomEnd(1);
memcpy(m_array + GetCount() - 1, data, sizeof(T));
free(data);
data = m_array + GetCount() - 1;
return m_count - 1;
}
inline bool AddCpy(const u32 pos, const T* data, u64 count = 1)
{
if(!InsertRoom(pos, count)) return false;
memcpy(m_array + pos, data, sizeof(T) * count);
return true;
}
inline bool AddCpy(const u32 pos, const T& data)
{
return AddCpy(pos, &data);
}
inline u32 AddCpy(const T* data, u64 count = 1)
{
_InsertRoomEnd(count);
memcpy(m_array + m_count - count, data, sizeof(T)*count);
return m_count - count;
}
inline u32 AddCpy(const T& data)
{
return AddCpy(&data);
@ -102,7 +117,9 @@ public:
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);
}
@ -144,8 +161,20 @@ public:
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)
{
@ -180,7 +209,6 @@ template<typename T> struct Stack : public Array<T>
}
};
template<typename T> class ArrayF
{
u32 m_count;
@ -193,7 +221,7 @@ public:
{
}
~ArrayF()
virtual ~ArrayF()
{
Clear();
}
@ -262,6 +290,53 @@ public:
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;
}
};

View file

@ -128,7 +128,7 @@ public:
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;

View file

@ -1,6 +1,19 @@
#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;
@ -8,22 +21,77 @@ void ThreadBase::Start()
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;
}

View file

@ -9,33 +9,41 @@ protected:
wxString m_name;
bool m_detached;
public:
wxMutex m_main_mutex;
protected:
ThreadBase(bool detached = true, const wxString& name = "Unknown ThreadBase")
: m_detached(detached)
, m_name(name)
, m_executor(nullptr)
{
}
ThreadBase(bool detached = true, const wxString& name = "Unknown ThreadBase");
public:
ThreadExec* m_executor;
virtual void Task()=0;
void Start();
void Stop(bool wait = true);
virtual void Start();
virtual void Resume();
virtual void Pause();
virtual void Stop(bool wait = true);
bool IsAlive();
bool TestDestroy();
virtual bool Wait() const;
virtual bool IsRunning() const;
virtual bool IsPaused() const;
virtual bool IsAlive() const;
virtual bool TestDestroy() const;
virtual wxString GetThreadName() const;
virtual void SetThreadName(const wxString& name);
};
ThreadBase* GetCurrentNamedThread();
class ThreadExec : public wxThread
{
ThreadBase* m_parent;
wxSemaphore m_wait_for_exit;
wxCriticalSection m_wait_for_exit;
volatile bool m_alive;
public:
ThreadBase* m_parent;
ThreadExec(bool detached, ThreadBase* parent)
: wxThread(detached ? wxTHREAD_DETACHED : wxTHREAD_JOINABLE)
, m_parent(parent)
@ -50,20 +58,26 @@ public:
if(!m_alive) return;
m_parent = nullptr;
Delete();
if(wait && m_alive) m_wait_for_exit.Wait();
//if(wait)
{
Delete();
//wxCriticalSectionLocker lock(m_wait_for_exit);
}
}
ExitCode Entry()
{
//wxCriticalSectionLocker lock(m_wait_for_exit);
m_parent->Task();
m_alive = false;
m_wait_for_exit.Post();
if(m_parent) m_parent->m_executor = nullptr;
return (ExitCode)0;
}
};
//ThreadBase* GetCurrentThread();
template<typename T> class MTPacketBuffer
{
protected:
@ -71,6 +85,7 @@ protected:
volatile u32 m_put, m_get;
Array<u8> m_buffer;
u32 m_max_buffer_size;
mutable wxCriticalSection m_cs_main;
void CheckBusy()
{
@ -91,18 +106,43 @@ public:
void Flush()
{
wxCriticalSectionLocker lock(m_cs_main);
m_put = m_get = 0;
m_buffer.Clear();
m_busy = false;
}
virtual void Push(const T& v) = 0;
virtual T Pop() = 0;
private:
virtual void _push(const T& v) = 0;
virtual T _pop() = 0;
bool HasNewPacket() const { return m_put != m_get; }
public:
void Push(const T& v)
{
wxCriticalSectionLocker lock(m_cs_main);
_push(v);
}
T Pop()
{
wxCriticalSectionLocker lock(m_cs_main);
return _pop();
}
bool HasNewPacket() const { wxCriticalSectionLocker lock(m_cs_main); return m_put != m_get; }
bool IsBusy() const { return m_busy; }
};
static __forceinline bool SemaphorePostAndWait(wxSemaphore& sem)
{
if(sem.TryWait() != wxSEMA_BUSY) return false;
sem.Post();
sem.Wait();
return true;
}
/*
class StepThread : public ThreadBase
{