mirror of
https://github.com/gwdevhub/gMod.git
synced 2026-07-15 23:19:30 +00:00
a7e36fc965
* remove GUI parts as those will not be updated * move to header/source * add cmakelist to create solution * Change Readme * Implement modlist.txt loading * Setup versioning and CD pipeline * Setup DirectX in pipeline * Make uMod load from uMod.dll directory * Fix file loading * Remove break * Fix CD pipeline (#1) * Test cd pipeline * See what's in Lib directory * See inside lib/x86 * Manually adjust the build environment * Disable CD pipeline in PRs Create CI pipeline * Fix slashes in path * Fix build call * Attempt to fix paths * Copy dx headers inside the /header folder * Use ps * Change cache location * Path changes * Improve CMake to look for lib and header files * Fix missing Lib folder * Move changes to CD pipeline * Disable CI on merge and fix CD (#2) * Fix CD tag (#4) * Hijack existing DirectX calls (#5) * Create a dll without listener (#6) * Fix asset creation in CD pipeline (#7) * Setup file loading * create necessary files * merge latest changes, set output dir * Change main to master in pipelines Add fallback for DX libs in CMakeLists * Setup new generator * formatting * remove listener * Change CD to pick the dll from bin Change release name to gMod * more formatting * add editorconfig * Setup versioning * Remove CODEOWNERS --------- Co-authored-by: Alex Macocian <amacocian@yahoo.com>
100 lines
2.7 KiB
C++
100 lines
2.7 KiB
C++
#include "uMod_Main.h"
|
|
|
|
|
|
|
|
|
|
|
|
uMod_FileHandler::uMod_FileHandler()
|
|
{
|
|
Message("uMod_FileHandler(): %lu\n", this);
|
|
Number = 0;
|
|
FieldCounter = 0;
|
|
Files = nullptr;
|
|
}
|
|
|
|
uMod_FileHandler::~uMod_FileHandler()
|
|
{
|
|
Message("~uMod_FileHandler(): %lu\n", this);
|
|
if (Files != nullptr) {
|
|
for (int i = 0; i < FieldCounter; i++) {
|
|
delete [] Files[i];
|
|
}
|
|
delete [] Files;
|
|
}
|
|
}
|
|
|
|
int uMod_FileHandler::Add(TextureFileStruct* file)
|
|
{
|
|
Message("uMod_FileHandler::Add(%lu): %lu\n", file, this);
|
|
if (gl_ErrorState & uMod_ERROR_FATAL) {
|
|
return RETURN_FATAL_ERROR;
|
|
}
|
|
|
|
if (file->Reference >= 0) {
|
|
return RETURN_UPDATE_ALLREADY_ADDED;
|
|
}
|
|
|
|
if (Number / FieldLength == FieldCounter) // get more memory
|
|
{
|
|
TextureFileStruct*** temp = nullptr;
|
|
try { temp = new TextureFileStruct**[FieldCounter + 10]; }
|
|
catch (...) {
|
|
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
|
|
return RETURN_NO_MEMORY;
|
|
}
|
|
|
|
for (int i = 0; i < FieldCounter; i++) {
|
|
temp[i] = Files[i]; //copy to new allocated memory
|
|
}
|
|
|
|
for (int i = FieldCounter; i < FieldCounter + 10; i++) {
|
|
temp[i] = nullptr; // initialize unused parts to zero
|
|
}
|
|
|
|
FieldCounter += 10;
|
|
|
|
delete [] Files;
|
|
|
|
Files = temp;
|
|
}
|
|
if (Number % FieldLength == 0) // maybe we need to get more memory
|
|
{
|
|
try {
|
|
if (Files[Number / FieldLength] == nullptr) {
|
|
Files[Number / FieldLength] = new TextureFileStruct*[FieldLength];
|
|
}
|
|
}
|
|
catch (...) {
|
|
Files[Number / FieldLength] = nullptr;
|
|
gl_ErrorState |= uMod_ERROR_MEMORY | uMod_ERROR_TEXTURE;
|
|
return RETURN_NO_MEMORY;
|
|
}
|
|
}
|
|
|
|
Files[Number / FieldLength][Number % FieldLength] = file;
|
|
file->Reference = Number++; //set the reference for a fast deleting
|
|
|
|
return RETURN_OK;
|
|
}
|
|
|
|
|
|
int uMod_FileHandler::Remove(TextureFileStruct* file)
|
|
{
|
|
Message("uMod_FileHandler::Remove(%lu): %lu\n", file, this);
|
|
if (gl_ErrorState & uMod_ERROR_FATAL) {
|
|
return RETURN_FATAL_ERROR;
|
|
}
|
|
const int ref = file->Reference;
|
|
|
|
if (ref < 0) {
|
|
return RETURN_OK; // returning if no Reference is set
|
|
}
|
|
file->Reference = -1; //set reference outside of bound
|
|
if (ref < (--Number)) //if reference is unequal to Number-1 we copy the last entry to the index "ref"
|
|
{
|
|
Files[ref / FieldLength][ref % FieldLength] = Files[Number / FieldLength][Number % FieldLength];
|
|
Files[ref / FieldLength][ref % FieldLength]->Reference = ref; //set the new reference entry
|
|
}
|
|
return RETURN_OK;
|
|
}
|