From 5e71e122019804a13e7f3838cc6b746b2ba97d47 Mon Sep 17 00:00:00 2001 From: captainurist <73941350+captainurist@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:55:06 +0100 Subject: [PATCH] Dropped HWLContainer --- src/Engine/Graphics/CMakeLists.txt | 2 - src/Engine/Graphics/HWLContainer.cpp | 134 --------------------------- src/Engine/Graphics/HWLContainer.h | 39 -------- 3 files changed, 175 deletions(-) delete mode 100644 src/Engine/Graphics/HWLContainer.cpp delete mode 100644 src/Engine/Graphics/HWLContainer.h diff --git a/src/Engine/Graphics/CMakeLists.txt b/src/Engine/Graphics/CMakeLists.txt index 57fffacf30be..ccb034806d26 100644 --- a/src/Engine/Graphics/CMakeLists.txt +++ b/src/Engine/Graphics/CMakeLists.txt @@ -9,7 +9,6 @@ set(ENGINE_GRAPHICS_SOURCES DecalBuilder.cpp DecorationList.cpp FrameLimiter.cpp - HWLContainer.cpp IRenderFactory.cpp Image.cpp ImageLoader.cpp @@ -48,7 +47,6 @@ set(ENGINE_GRAPHICS_HEADERS DecorationList.h FaceEnums.h FrameLimiter.h - HWLContainer.h IRender.h IRenderFactory.h Image.h diff --git a/src/Engine/Graphics/HWLContainer.cpp b/src/Engine/Graphics/HWLContainer.cpp deleted file mode 100644 index d5a9469c4715..000000000000 --- a/src/Engine/Graphics/HWLContainer.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "Engine/Graphics/HWLContainer.h" - -#include -#include -#include - -#include "Engine/EngineIocContainer.h" -#include "Library/Compression/Compression.h" -#include "Library/Logger/Logger.h" -#include "Utility/String.h" - -#pragma pack(push, 1) -struct HWLHeader { - uint32_t uSignature; - uint32_t uDataOffset; -}; -#pragma pack(pop) - -HWLContainer::HWLContainer() { - log = EngineIocContainer::ResolveLogger(); -} - -HWLContainer::~HWLContainer() { - if (pFile != nullptr) { - fclose(this->pFile); - } -} - -bool HWLContainer::Open(const std::string &pFilename) { - assert(!pFile); - - pFile = fopen(pFilename.c_str(), "rb"); - if (!pFile) { - log->warning("Failed to open file: {}", pFilename); - return false; - } - - HWLHeader header; - if (fread(&header, sizeof(HWLHeader), 1, pFile) != 1) - return false; - - if (memcmp(&header.uSignature, "D3DT", 4) != 0) { - log->warning("Invalid format: {}", pFilename); - return false; - } - fseek(pFile, header.uDataOffset, SEEK_SET); - - typedef struct HWLNode { - std::string sName; - size_t uOffset = 0; - } HWLNode; - std::vector vNodes; - - uint32_t uNumItems = 0; - if (fread(&uNumItems, 4, 1, pFile) != 1) - return false; - - char tmpName[21]; - for (unsigned int i = 0; i < uNumItems; ++i) { - if (fread(tmpName, 20, 1, pFile) != 1) - return false; - tmpName[20] = 0; - HWLNode node; - node.sName = toLower(std::string(tmpName)); - node.uOffset = 0; - vNodes.push_back(node); - } - - for (unsigned int i = 0; i < uNumItems; ++i) { - uint32_t uOffset = 0; - if (fread(&uOffset, 4, 1, pFile) != 1) - return false; - vNodes[i].uOffset = uOffset; - } - - for (HWLNode &node : vNodes) { - mNodes[node.sName] = node.uOffset; - } - - return true; -} - -#pragma pack(push, 1) -struct HWLTextureHeader { - uint32_t uCompressedSize; - uint32_t uBufferWidth; - uint32_t uBufferHeight; - uint32_t uAreaWidth; - uint32_t uAreaHeigth; - uint32_t uWidth; - uint32_t uHeight; - uint32_t uAreaX; - uint32_t uAreaY; -}; -#pragma pack(pop) - -HWLTexture *HWLContainer::LoadTexture(const std::string &pName) { - if (mNodes.size() == 0) { - return nullptr; - } - - std::map::iterator it = mNodes.find(toLower(pName)); - if (it == mNodes.end()) { - return nullptr; - } - size_t uOffset = it->second; - - fseek(pFile, uOffset, SEEK_SET); - - HWLTextureHeader textureHeader; - if (fread(&textureHeader, sizeof(HWLTextureHeader), 1, pFile) != 1) - return nullptr; - - HWLTexture *pTex = new HWLTexture; - pTex->uBufferWidth = textureHeader.uBufferWidth; - pTex->uBufferHeight = textureHeader.uBufferHeight; - pTex->uAreaWidth = textureHeader.uAreaWidth; - pTex->uAreaHeigth = textureHeader.uAreaHeigth; - pTex->uWidth = textureHeader.uWidth; - pTex->uHeight = textureHeader.uHeight; - pTex->uAreaX = textureHeader.uAreaX; - pTex->uAreaY = textureHeader.uAreaY; - - pTex->pPixels = new uint16_t[pTex->uWidth * pTex->uHeight]; - if (textureHeader.uCompressedSize) { - Blob buffer = zlib::uncompress(Blob::read(pFile, textureHeader.uCompressedSize)); - memcpy(pTex->pPixels, buffer.data(), buffer.size()); // TODO: gotta check size here. - } else { - if (fread(pTex->pPixels, 2 * pTex->uWidth * pTex->uHeight, 1, pFile) != 1) - return nullptr; - } - - return pTex; -} diff --git a/src/Engine/Graphics/HWLContainer.h b/src/Engine/Graphics/HWLContainer.h deleted file mode 100644 index 031f7d4beee5..000000000000 --- a/src/Engine/Graphics/HWLContainer.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -class HWLTexture { - public: - inline HWLTexture() {} - - int uBufferWidth = 0; - int uBufferHeight = 0; - int uAreaWidth = 0; - int uAreaHeigth = 0; - unsigned int uWidth = 0; - unsigned int uHeight = 0; - int uAreaX = 0; - int uAreaY = 0; - uint16_t *pPixels = nullptr; -}; - -class Logger; - -// TODO(captainurist): currently unused, can drop. -class HWLContainer { - public: - HWLContainer(); - virtual ~HWLContainer(); - - bool Open(const std::string &pFilename); - - HWLTexture *LoadTexture(const std::string &pName); - - protected: - FILE *pFile = nullptr; - Logger *log = nullptr; - std::map mNodes; -};