diff --git a/projs/shadow/shadow-engine/shadow-assets/src/fs/file.cpp b/projs/shadow/shadow-engine/shadow-assets/src/fs/file.cpp index 6af0083..6b944c0 100644 --- a/projs/shadow/shadow-engine/shadow-assets/src/fs/file.cpp +++ b/projs/shadow/shadow-engine/shadow-assets/src/fs/file.cpp @@ -1,13 +1,34 @@ #include #include #include "management/synchronization.h" -#include "../../../../../../cmake-build-debug/_deps/spdlog-src/include/spdlog/spdlog.h" +#include #include #include #include namespace ShadowEngine { + // Because fuck Linux? Need platform-specific source files! +#ifdef _WIN32 + +#define WIN32_LEAN_AND_MEAN +#include + + FileInput::FileInput() { + handle = (void*) INVALID_HANDLE_VALUE; + } + + FileOutput::FileOutput() { + error = false; + handle = (void*) INVALID_HANDLE_VALUE; + } + + bool FileOutput::open(std::string& path) { + + } + +#endif + /** * An async operation to be performed. * For reading files from disk into memory. diff --git a/projs/shadow/shadow-engine/shadow-assets/src/fs/file.h b/projs/shadow/shadow-engine/shadow-assets/src/fs/file.h index 9c6750a..0bc97ae 100644 --- a/projs/shadow/shadow-engine/shadow-assets/src/fs/file.h +++ b/projs/shadow/shadow-engine/shadow-assets/src/fs/file.h @@ -75,7 +75,7 @@ namespace ShadowEngine { // Create a Virtual Filesystem based on the given path. static std::unique_ptr createVFS(std::string& basePath); - virtual ~FileSystem() {} + virtual ~FileSystem() = default; // Open a file for reading. virtual bool open(std::string& path, FileInput& input) = 0; @@ -103,7 +103,7 @@ namespace ShadowEngine { virtual bool hasWork() = 0; // Write new content to a file synchronously. The thread will be blocked when doing this. - virtual bool saveSync(const Path& file, const uint8_t* content, const size_t size) = 0; + virtual bool saveSync(const Path& file, const uint8_t* content, size_t size) = 0; // Read content from a file synchronously. The thread will be blocked when doing this. virtual bool readSync(const Path& file, struct OutputMemoryStream& content) = 0; diff --git a/projs/shadow/shadow-engine/shadow-assets/src/fs/iostream.cpp b/projs/shadow/shadow-engine/shadow-assets/src/fs/iostream.cpp index 2c268a4..a8c1e93 100644 --- a/projs/shadow/shadow-engine/shadow-assets/src/fs/iostream.cpp +++ b/projs/shadow/shadow-engine/shadow-assets/src/fs/iostream.cpp @@ -1,4 +1,5 @@ #include +#include namespace ShadowEngine { @@ -13,15 +14,16 @@ namespace ShadowEngine { str.free(); } - void OutputMemoryStream::operator=(ShadowEngine::OutputMemoryStream &&str) noexcept { + OutputMemoryStream& OutputMemoryStream::operator=(ShadowEngine::OutputMemoryStream &&str) noexcept { capacity = str.capacity; buffer = str.buffer; usage = str.usage; str.free(); + return *this; } - void OutputMemoryStream::operator=(const ShadowEngine::OutputMemoryStream &rhs) noexcept { + OutputMemoryStream& OutputMemoryStream::operator=(const ShadowEngine::OutputMemoryStream &rhs) noexcept { usage = rhs.usage; if (rhs.capacity > 0) { @@ -32,6 +34,8 @@ namespace ShadowEngine { buffer = nullptr; capacity = 0; } + + return *this; } OutputMemoryStream::OutputMemoryStream(const ShadowEngine::OutputMemoryStream &rhs) noexcept { diff --git a/projs/shadow/shadow-engine/shadow-assets/src/management/synchronization.cpp b/projs/shadow/shadow-engine/shadow-assets/src/management/synchronization.cpp new file mode 100644 index 0000000..985109e --- /dev/null +++ b/projs/shadow/shadow-engine/shadow-assets/src/management/synchronization.cpp @@ -0,0 +1,73 @@ +#include + +// This doesn't work on Linux. Sucks to be you? dpeter won't let me do system-specific source files. +#ifdef _WIN32 + +#include +#define WIN32_LEAN_AND_MEAN +#include + + +namespace ShadowEngine { struct NewPlaceholder {}; } +inline void* operator new(size_t, ShadowEngine::NewPlaceholder, void* where) { return where; } +inline void operator delete(void*, ShadowEngine::NewPlaceholder, void*) { } + +namespace ShadowEngine { + + Semaphore::Semaphore(int initCount, int maxCount) { + id = ::CreateSemaphore(nullptr, initCount, maxCount, nullptr); + } + + Semaphore::~Semaphore() { + ::CloseHandle(id); + } + + void Semaphore::raise() { + ::ReleaseSemaphore(id, 1, nullptr); + } + + void Semaphore::wait() { + ::WaitForSingleObject(id, INFINITE); + } + + ConditionVariable::ConditionVariable() { + memset(data, 0, sizeof(data)); + auto* var = new (NewPlaceholder(), data) CONDITION_VARIABLE; + InitializeConditionVariable(var); + } + + ConditionVariable::~ConditionVariable() { + ((CONDITION_VARIABLE*)data)->~CONDITION_VARIABLE(); + } + + void ConditionVariable::sleep(ShadowEngine::Mutex &mut) { + ::SleepConditionVariableSRW((CONDITION_VARIABLE*) data, (SRWLOCK*) mut.data, INFINITE, 0); + } + + void ConditionVariable::wake() { + ::WakeConditionVariable((CONDITION_VARIABLE*) data); + } + + Mutex::Mutex() { + memset(data, 0, sizeof(data)); + auto* lock = new (NewPlaceholder(), data) SRWLOCK; + ::InitializeSRWLock(lock); + } + + Mutex::~Mutex() { + auto* lock = (SRWLOCK*) data; + lock->~SRWLOCK(); + } + + void Mutex::enter() { + auto* lock = (SRWLOCK*) data; + ::AcquireSRWLockExclusive(lock); + } + + void Mutex::exit() { + auto* lock = (SRWLOCK*) data; + ::ReleaseSRWLockExclusive(lock); + } +} + +#endif \ No newline at end of file diff --git a/projs/shadow/shadow-engine/shadow-assets/src/management/synchronization.h b/projs/shadow/shadow-engine/shadow-assets/src/management/synchronization.h index 3d3278e..364bf4f 100644 --- a/projs/shadow/shadow-engine/shadow-assets/src/management/synchronization.h +++ b/projs/shadow/shadow-engine/shadow-assets/src/management/synchronization.h @@ -18,7 +18,7 @@ namespace ShadowEngine { void exit(); private: #ifdef _WIN32 - uint8_t data[8]; + uint8_t data[8] {}; #else pthread_mutex_t mutex; #endif diff --git a/projs/shadow/shadow-engine/shadow-assets/src/resource/Resource.cpp b/projs/shadow/shadow-engine/shadow-assets/src/resource/Resource.cpp index 409e68d..46a2323 100644 --- a/projs/shadow/shadow-engine/shadow-assets/src/resource/Resource.cpp +++ b/projs/shadow/shadow-engine/shadow-assets/src/resource/Resource.cpp @@ -174,4 +174,21 @@ namespace ShadowEngine { checkState(); } + + static std::string type("prefab"); + const ResourceType PrefabResource::TYPE(type); + + PrefabResource::PrefabResource(const ShadowEngine::Path &path, + ShadowEngine::ResourceTypeManager &resource_manager) : Resource(path, resource_manager) {} + + ResourceType PrefabResource::getType() const { return TYPE; } + + void PrefabResource::unload() { data.clear(); } + + bool PrefabResource::load(size_t size, const uint8_t *mem) { + data.resize(size); + memcpy(data.dataMut(), mem, size); + hash = StableHash(mem, size); + return true; + } } \ No newline at end of file diff --git a/projs/shadow/shadow-engine/shadow-assets/src/resource/Resource.h b/projs/shadow/shadow-engine/shadow-assets/src/resource/Resource.h index c91b2a4..a26af60 100644 --- a/projs/shadow/shadow-engine/shadow-assets/src/resource/Resource.h +++ b/projs/shadow/shadow-engine/shadow-assets/src/resource/Resource.h @@ -23,7 +23,8 @@ namespace ShadowEngine { }; // A Resource Type that is guaranteed to be invalid. - const ResourceType INVALID_RESOURCE((std::string &) ""); + static std::string empty; + const ResourceType INVALID_RESOURCE(empty); // A specialization of HashFunc for ResourceTypes, since they already have a HeapHash within. template<> struct HashFunc { @@ -125,4 +126,15 @@ namespace ShadowEngine { State state; bool hooked = false; }; + + struct PrefabResource : Resource { + PrefabResource(const Path& path, ResourceTypeManager& resource_manager); + ResourceType getType() const override; + void unload() override; + bool load(size_t size, const uint8_t* data) override; + + OutputMemoryStream data; + StableHash hash; + static const ResourceType TYPE; + }; } \ No newline at end of file diff --git a/projs/shadow/shadow-engine/shadow-assets/src/resource/ResourceManager.cpp b/projs/shadow/shadow-engine/shadow-assets/src/resource/ResourceManager.cpp index 8aa98bf..163183d 100644 --- a/projs/shadow/shadow-engine/shadow-assets/src/resource/ResourceManager.cpp +++ b/projs/shadow/shadow-engine/shadow-assets/src/resource/ResourceManager.cpp @@ -191,5 +191,4 @@ namespace ShadowEngine { for (auto manager : managers) manager.second->reload(path); } - } \ No newline at end of file