chore(bc): switch BlizzardCore to bc lib

This commit is contained in:
fallenoak 2023-03-04 11:29:25 -06:00 committed by GitHub
parent 34bcb5c134
commit 2282b8a54a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 28 additions and 478 deletions

3
.gitmodules vendored
View File

@ -10,3 +10,6 @@
[submodule "lib/system"]
path = lib/system
url = https://github.com/whoahq/system.git
[submodule "lib/bc"]
path = lib/bc
url = https://github.com/whoahq/bc

View File

@ -1,4 +1,5 @@
add_subdirectory(common)
add_subdirectory(squall)
add_subdirectory(system)
add_subdirectory(squall)
add_subdirectory(typhoon)
add_subdirectory(bc)
add_subdirectory(common)

1
lib/bc Submodule

@ -0,0 +1 @@
Subproject commit 39f4bd35a3b0cfb4792360b590c4675722dabecf

View File

@ -4,7 +4,7 @@
#include "gx/gll/CGxDeviceGLL.hpp"
#include "gx/Device.hpp"
#include "gx/Window.hpp"
#include "util/BlizzardCore.hpp"
#include <bc/Debug.hpp>
void MacOnKeyDown(NSEvent* event) {
BLIZZARD_ASSERT(false);

View File

@ -21,6 +21,7 @@ target_link_libraries(client
util
world
PUBLIC
bc
common
storm
)

View File

@ -11,10 +11,10 @@
#include "net/Poll.hpp"
#include "ui/FrameScript.hpp"
#include "ui/FrameXML.hpp"
#include "util/BlizzardCore.hpp"
#include "util/CVar.hpp"
#include "world/World.hpp"
#include <cstring>
#include <bc/Debug.hpp>
#include <common/Prop.hpp>
#include <storm/Error.hpp>

View File

@ -29,6 +29,7 @@ target_link_libraries(gx
ui
util
PUBLIC
bc
freetype-2.0
storm
tempest

View File

@ -10,6 +10,7 @@
#include <cmath>
#include <cstdio>
#include <cstring>
#include <bc/Debug.hpp>
GLEnum CGxDeviceGLL::s_glCubeMapFaces[] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X,

View File

@ -1,7 +1,8 @@
#include "gx/gll/GLBuffer.h"
#include "gx/gll/GLDevice.h"
#include "gx/gll/GLPool.h"
#include "util/BlizzardCore.hpp"
#include <bc/Debug.hpp>
#include <bc/Memory.hpp>
bool GLBuffer::m_UsingVBO = 1;

View File

@ -3,12 +3,12 @@
#include "gx/gll/GLAbstractWindow.h"
#include "gx/gll/GLTypes.h"
#include "util/BlizzardCore.hpp"
#include <cstdint>
#include <map>
#include <string>
#include <vector>
#include <CoreFoundation/CoreFoundation.h>
#include <bc/Thread.hpp>
#ifdef __OBJC__
#include <AppKit/AppKit.h>

View File

@ -1,6 +1,7 @@
#include "gx/gll/GLContext.h"
#include "gx/gll/GLDevice.h"
#include "util/Autorelease.hpp"
#include <bc/Debug.hpp>
NSOpenGLContext* GLContext::s_MainContext;
Blizzard::Thread::TLSSlot GLContext::s_CurrentContext;

View File

@ -7,6 +7,7 @@
#include <cstring>
#include <type_traits>
#include <ApplicationServices/ApplicationServices.h>
#include <bc/Debug.hpp>
#define GL_MAX_STREAM 4

View File

@ -15,11 +15,11 @@
#include "gx/gll/GLTypes.h"
#include "gx/gll/GLVertexArray.h"
#include "gx/gll/GLWorker.h"
#include "util/BlizzardCore.hpp"
#include <cstdint>
#include <list>
#include <string>
#include <vector>
#include <bc/Thread.hpp>
class GLDevice {
public:

View File

@ -3,6 +3,7 @@
#include "gx/gll/GLMipmap.h"
#include "gx/gll/GLPool.h"
#include "gx/gll/GLTypes.h"
#include <bc/Debug.hpp>
GLFramebuffer* GLFramebuffer::Create(bool a1) {
GLFramebuffer* framebuffer = new GLFramebuffer(a1);

View File

@ -2,6 +2,7 @@
#include "gx/gll/GLCommand.h"
#include "gx/gll/GLDevice.h"
#include "gx/gll/GLFramebuffer.h"
#include <bc/Debug.hpp>
int32_t GLMipmap::GetDepthBits() {
return this->m_DepthBits;

View File

@ -1,5 +1,5 @@
#include "gx/gll/GLObject.h"
#include "util/BlizzardCore.hpp"
#include <bc/Debug.hpp>
void GLObject::AddRefTwin() {
}

View File

@ -3,6 +3,7 @@
#include "gx/gll/GLPixelShader.h"
#include "gx/gll/GLPool.h"
#include "gx/gll/GLVertexShader.h"
#include <bc/Debug.hpp>
// TODO
// - threaded compiler support

View File

@ -5,6 +5,8 @@
#include "gx/gll/GLUtil.h"
#include "gx/texture/CGxTex.hpp"
#include <deque>
#include <bc/Debug.hpp>
#include <bc/Memory.hpp>
Blizzard::Thread::TLSSlot GLTexture::m_Bindings[4];

View File

@ -4,9 +4,9 @@
#include "gx/gll/GL.h"
#include "gx/gll/GLObject.h"
#include "gx/gll/GLTypes.h"
#include "util/BlizzardCore.hpp"
#include <list>
#include <vector>
#include <bc/Thread.hpp>
#define GLTFLAG_RENDERTARGET 0x1
#define GLTFLAG_DEPTH 0x2

View File

@ -1,5 +1,5 @@
#include "gx/gll/GLUtil.h"
#include "util/BlizzardCore.hpp"
#include <bc/Debug.hpp>
uint32_t GLLTextureTypeToIndex(GLEnum textureType) {
uint32_t index;

View File

@ -1,5 +1,6 @@
#include "gx/gll/GLVertexArray.h"
#include "gx/gll/GLDevice.h"
#include <bc/Debug.hpp>
bool GLVertexArray::s_VertexArrayEnable = false;

View File

@ -3,6 +3,7 @@
#include "gx/gll/GLLayerView.h"
#include "util/Autorelease.hpp"
#include <cmath>
#include <bc/Debug.hpp>
GLWindowCallbacks DefaultCallbacks = {
// TODO

View File

@ -1,334 +0,0 @@
#include "util/BlizzardCore.hpp"
#include <cstring>
#include <ctime>
#include <map>
#include <storm/Memory.hpp>
#if defined(WHOA_SYSTEM_MAC)
#include <libkern/OSAtomic.h>
#elif defined(WHOA_SYSTEM_LINUX)
#include <atomic>
#endif
Blizzard::System_Debug::AssertCallback Blizzard::System_Debug::s_assertCallback = nullptr;
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
bool Blizzard::System_Thread::s_initialized;
Blizzard::Lock::DoOnceData Blizzard::System_Lock::s_initMutexAttrOnce;
Blizzard::System_Lock::MutexAttr Blizzard::System_Lock::s_mutexattr;
Blizzard::Thread::ThreadRecord* Blizzard::System_Thread::s_mainThread;
Blizzard::Lock::Mutex Blizzard::System_Thread::s_mutex;
Blizzard::Lock::Mutex Blizzard::System_Thread::s_registryMutex;
Blizzard::Thread::TLSSlot Blizzard::System_Thread::s_stackTraceEntryPointTLS;
Blizzard::Thread::TLSSlot Blizzard::System_Thread::s_threadRecordTLS;
std::map<Blizzard::Thread::ThreadRecord*, Blizzard::Thread::ThreadRecord*>* Blizzard::System_Thread::s_threadRegistry;
Blizzard::Thread::TLSSlot* Blizzard::System_Thread::s_slotList[128];
int32_t Blizzard::System_Thread::s_slotListUsed;
#endif
void Blizzard::Debug::Assert(const char* a1, const char* a2, uint32_t a3) {
if (System_Debug::s_assertCallback) {
System_Debug::s_assertCallback(a1, "", a2, a3);
}
}
void Blizzard::Debug::SetAssertHandler(Blizzard::System_Debug::AssertCallback callback) {
System_Debug::s_assertCallback = callback;
}
void* Blizzard::Memory::Allocate(uint32_t bytes) {
return SMemAlloc(bytes, __FILE__, __LINE__, 0);
}
void* Blizzard::Memory::Allocate(uint32_t a1, uint32_t a2, const char* a3, uint32_t a4, const char* a5) {
// TODO
// - what is a5?
// - arg order?
// - flag manipluation?
return SMemAlloc(a1, a3, a4, a2);
}
void Blizzard::Memory::Free(void* ptr) {
SMemFree(ptr);
}
int32_t Blizzard::String::Copy(char* dst, const char* src, size_t len) {
if (!len || !dst) {
return 0;
}
if (!src) {
*dst = 0;
return 0;
}
char* v3 = dst + len - 1;
char v4;
const char* v5;
char* v6;
int32_t result;
if (dst < v3 && (v4 = *src, v5 = src, v6 = dst, *src)) {
do {
*v6++ = v4;
if (v3 <= v6) {
break;
}
v4 = (v5++)[1];
} while ( v4 );
result = v6 - dst;
} else {
v6 = dst;
result = 0;
}
*v6 = 0;
return result;
}
uint32_t Blizzard::String::Length(const char* a1) {
if (a1) {
return strlen(a1);
} else {
return 0;
}
}
void Blizzard::String::MemFill(void* a1, uint32_t a2, unsigned char a3) {
memset(a1, a3, a2);
}
void Blizzard::Process::Sleep(uint32_t duration) {
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
struct timespec request;
request.tv_sec = 0;
request.tv_nsec = duration * 1000000;
nanosleep(&request, nullptr);
#endif
}
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
void Blizzard::Lock::DoOnce(DoOnceData& a1, void (*a2)(void*), void* a3) {
if (!a1.done) {
if (Blizzard::Lock::Atomic::Increment(&a1.atomic) == 1) {
a2(a3);
a1.done = true;
} else {
while (!a1.done) {
Blizzard::Process::Sleep(1);
}
}
}
}
bool Blizzard::Lock::MutexCreate(Blizzard::Lock::Mutex& a1) {
Blizzard::Lock::DoOnce(System_Lock::s_initMutexAttrOnce, System_Lock::InitAttr, 0);
bool result = pthread_mutex_init(&a1, &System_Lock::s_mutexattr);
// Blizzard::Debug::Assert(result == 0);
return result;
}
bool Blizzard::Lock::MutexEnter(Blizzard::Lock::Mutex& a1) {
bool result = pthread_mutex_lock(&a1);
// Blizzard::Debug::Assert(result == 0);
return result;
}
bool Blizzard::Lock::MutexLeave(Blizzard::Lock::Mutex& a1) {
bool result = pthread_mutex_unlock(&a1);
// Blizzard::Debug::Assert(result == 0);
return result;
}
int32_t Blizzard::Lock::Atomic::Increment(volatile int32_t* value) {
#if defined(WHOA_SYSTEM_MAC)
return OSAtomicAdd32(1, value);
#elif defined(WHOA_SYSTEM_LINUX)
volatile std::atomic<int32_t> atom(*value);
std::atomic_fetch_add<int32_t>(&atom, 1);
return atom;
#endif
}
void Blizzard::System_Lock::InitAttr(void* a1) {
pthread_mutexattr_init(&System_Lock::s_mutexattr);
pthread_mutexattr_settype(&System_Lock::s_mutexattr, PTHREAD_MUTEX_RECURSIVE);
}
void Blizzard::Thread::AllocateLocalStorage(TLSSlot* slot) {
System_Thread::AllocateLocalStorage(slot, 0);
}
void* Blizzard::Thread::RegisterLocalStorage(TLSSlot* slot, void* (*constructor)(void*), void* userData, void (*destructor)(void*)) {
if (!System_Thread::TLSSlotIsAllocated(slot) && !System_Thread::AllocateTLSSlot(slot, destructor)) {
// Blizzard::Debug::Assert(!"Unable to allocate thread-local storage");
}
void* value;
value = System_Thread::InternalGetLocalStorage(slot);
if (value) {
return value;
}
value = constructor(userData);
System_Thread::InternalSetLocalStorage(slot, value);
return value;
}
void Blizzard::Thread::SetLocalStorage(const TLSSlot* slot, const void* value) {
BLIZZARD_ASSERT(Blizzard::Thread::TLSSlotIsAllocated(slot));
System_Thread::InternalSetLocalStorage(slot, value);
}
bool Blizzard::Thread::TLSSlotIsAllocated(const TLSSlot* slot) {
return System_Thread::TLSSlotIsAllocated(slot);
}
void Blizzard::System_Thread::AddToRegistry(Thread::ThreadRecord* thread) {
Blizzard::Lock::MutexEnter(System_Thread::s_registryMutex);
if (!System_Thread::s_threadRegistry) {
auto m = Blizzard::Memory::Allocate(sizeof(std::map<Thread::ThreadRecord*, Thread::ThreadRecord*>), 0, __FILE__, __LINE__, nullptr);
System_Thread::s_threadRegistry = new (m) std::map<Thread::ThreadRecord*, Thread::ThreadRecord*>();
}
System_Thread::s_threadRegistry->insert(std::pair<Thread::ThreadRecord*, Thread::ThreadRecord*>(thread, thread));
Blizzard::Lock::MutexLeave(System_Thread::s_registryMutex);
}
bool Blizzard::System_Thread::AllocateLocalStorage(Thread::TLSSlot* slot, void (*destructor)(void*)) {
System_Thread::InitThreadSystem();
BLIZZARD_ASSERT(!System_Thread::TLSSlotIsAllocated(slot));
int32_t result;
if (System_Thread::InternalAllocateLocalStorage(slot, destructor)) {
slot->destructor = destructor;
Blizzard::Lock::MutexEnter(System_Thread::s_mutex);
int32_t v3 = System_Thread::s_slotListUsed;
System_Thread::s_slotList[System_Thread::s_slotListUsed] = slot;
System_Thread::s_slotListUsed = v3 + 1;
Blizzard::Lock::MutexLeave(System_Thread::s_mutex);
result = 1;
} else {
BLIZZARD_ASSERT(!"failed to allocate TLS");
result = 0;
}
return result;
}
bool Blizzard::System_Thread::AllocateTLSSlot(Thread::TLSSlot* slot, void (*destructor)(void*)) {
System_Thread::InitThreadSystem();
Blizzard::Lock::MutexEnter(System_Thread::s_mutex);
int32_t result = 0;
if (System_Thread::TLSSlotIsAllocated(slot) || System_Thread::AllocateLocalStorage(slot, destructor)) {
result = 1;
}
Blizzard::Lock::MutexLeave(System_Thread::s_mutex);
return result;
}
void Blizzard::System_Thread::InitThreadSystem() {
if (System_Thread::s_initialized) {
return;
}
System_Thread::s_initialized = true;
Blizzard::Lock::MutexCreate(System_Thread::s_mutex);
Blizzard::Lock::MutexCreate(System_Thread::s_registryMutex);
Blizzard::Thread::AllocateLocalStorage(&System_Thread::s_threadRecordTLS);
Blizzard::Thread::AllocateLocalStorage(&System_Thread::s_stackTraceEntryPointTLS);
System_Thread::s_mainThread = System_Thread::NewThread(nullptr, nullptr, nullptr);
Blizzard::Thread::SetLocalStorage(&System_Thread::s_threadRecordTLS, System_Thread::s_mainThread);
System_Thread::s_mainThread->unkC = 1;
System_Thread::s_mainThread->unk10 = 1;
}
bool Blizzard::System_Thread::InternalAllocateLocalStorage(Thread::TLSSlot* slot, void (*destructor)(void*)) {
if (!pthread_key_create(&slot->key, destructor)) {
slot->allocated = true;
return 1;
} else {
return 0;
}
}
void* Blizzard::System_Thread::InternalGetLocalStorage(const Thread::TLSSlot* slot) {
return pthread_getspecific(slot->key);
}
void Blizzard::System_Thread::InternalSetLocalStorage(const Thread::TLSSlot* slot, const void* value) {
int32_t err = pthread_setspecific(slot->key, value);
BLIZZARD_ASSERT(err == 0);
}
Blizzard::Thread::ThreadRecord* Blizzard::System_Thread::NewThread(uint32_t (*a1)(void*), void* a2, const char* a3) {
const char* v3 = a3;
if (!a3) {
v3 = "";
}
int32_t v4 = Blizzard::String::Length(v3);
Blizzard::Thread::ThreadRecord* thread = static_cast<Blizzard::Thread::ThreadRecord*>(
Blizzard::Memory::Allocate(sizeof(Blizzard::Thread::ThreadRecord) + v4 + 1, 0, __FILE__, __LINE__, nullptr)
);
Blizzard::String::MemFill(thread, sizeof(Blizzard::Thread::ThreadRecord), 0);
thread->unk4 = a2;
thread->unk8 = a1;
thread->unkC = 0;
thread->unk10 = 2;
Blizzard::String::Copy(thread->unk2C, v3, v4 + 1);
System_Thread::AddToRegistry(thread);
return thread;
}
bool Blizzard::System_Thread::TLSSlotIsAllocated(const Thread::TLSSlot* slot) {
return slot->allocated;
}
#endif

View File

@ -1,134 +0,0 @@
#ifndef UTIL_BLIZZARD_CORE_HPP
#define UTIL_BLIZZARD_CORE_HPP
#include <cstdint>
#include <map>
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
#include <pthread.h>
#endif
#if defined(NDEBUG)
#define BLIZZARD_ASSERT(x) if (!(x)) { return 0; }
#else
#define BLIZZARD_ASSERT(x) if (!(x)) { Blizzard::Debug::Assert(#x, __FILE__, __LINE__); }
#endif
namespace Blizzard {
namespace Memory {
// Functions
void* Allocate(uint32_t);
void* Allocate(uint32_t, uint32_t, const char*, uint32_t, const char*);
void Free(void*);
};
namespace String {
// Functions
int32_t Copy(char*, const char*, size_t);
uint32_t Length(const char*);
void MemFill(void*, uint32_t, unsigned char);
};
namespace Process {
// Functions
void Sleep(uint32_t);
}
namespace System_Debug {
// Types
typedef void (*AssertCallback)(const char*, const char*, const char*, uint32_t);
// Variables
extern AssertCallback s_assertCallback;
}
namespace Debug {
// Functions
void Assert(const char*, const char*, uint32_t);
void SetAssertHandler(Blizzard::System_Debug::AssertCallback);
}
#if defined(WHOA_SYSTEM_MAC) || defined(WHOA_SYSTEM_LINUX)
namespace Lock {
// Types
typedef pthread_mutex_t Mutex;
struct DoOnceData {
bool done;
int32_t atomic;
};
// Functions
void DoOnce(DoOnceData&, void (*)(void*), void*);
bool MutexCreate(Mutex&);
bool MutexEnter(Mutex&);
bool MutexLeave(Mutex&);
namespace Atomic {
int32_t Increment(volatile int32_t*);
}
}
namespace System_Lock {
// Types
typedef pthread_mutexattr_t MutexAttr;
// Variables
extern Lock::DoOnceData s_initMutexAttrOnce;
extern MutexAttr s_mutexattr;
// Functions
void InitAttr(void*);
}
namespace Thread {
// Types
struct ThreadRecord {
pthread_t unk0;
void* unk4;
uint32_t (*unk8)(void*);
int32_t unkC;
int32_t unk10;
char* unk2C;
};
struct TLSSlot {
pthread_key_t key;
void (*destructor)(void*);
bool allocated;
};
// Functions
void AllocateLocalStorage(TLSSlot*);
void* RegisterLocalStorage(TLSSlot*, void* (*)(void*), void*, void (*)(void*));
void SetLocalStorage(const TLSSlot*, const void*);
bool TLSSlotIsAllocated(const TLSSlot*);
};
namespace System_Thread {
// Variables
extern bool s_initialized;
extern Thread::ThreadRecord* s_mainThread;
extern Lock::Mutex s_mutex;
extern Lock::Mutex s_registryMutex;
extern Thread::TLSSlot s_stackTraceEntryPointTLS;
extern Thread::TLSSlot s_threadRecordTLS;
extern std::map<Thread::ThreadRecord*, Thread::ThreadRecord*>* s_threadRegistry;
extern Thread::TLSSlot* s_slotList[128];
extern int32_t s_slotListUsed;
// Functions
void AddToRegistry(Thread::ThreadRecord*);
bool AllocateLocalStorage(Thread::TLSSlot*, void (*)(void*));
bool AllocateTLSSlot(Thread::TLSSlot*, void (*)(void*));
void InitThreadSystem(void);
bool InternalAllocateLocalStorage(Thread::TLSSlot*, void (*)(void*));
void* InternalGetLocalStorage(const Thread::TLSSlot*);
void InternalSetLocalStorage(const Thread::TLSSlot*, const void*);
Thread::ThreadRecord* NewThread(uint32_t (*)(void*), void*, const char*);
bool TLSSlotIsAllocated(const Thread::TLSSlot*);
};
#endif
};
#endif