mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-02-04 12:50:57 +00:00
Slightly change readarrayfromfile so that attempting to read arrays of a size that does not evenly divide into the requested type rounds up instead of down and zero-pads the difference.
This should help hackish persuits such as reading map files through this command. git-svn-id: https://svn.eduke32.com/eduke32@6394 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
201ee80f87
commit
32ed49e5c5
2 changed files with 5 additions and 3 deletions
|
@ -4398,6 +4398,7 @@ finish_qsprintf:
|
||||||
if (numElements > 0)
|
if (numElements > 0)
|
||||||
{
|
{
|
||||||
size_t const newBytes = Gv_GetArrayAllocSizeForCount(arrayNum, numElements);
|
size_t const newBytes = Gv_GetArrayAllocSizeForCount(arrayNum, numElements);
|
||||||
|
size_t const readBytes = min(newBytes, filelength);
|
||||||
size_t const oldBytes = Gv_GetArrayAllocSize(arrayNum);
|
size_t const oldBytes = Gv_GetArrayAllocSize(arrayNum);
|
||||||
|
|
||||||
intptr_t *& pValues = aGameArrays[arrayNum].pValues;
|
intptr_t *& pValues = aGameArrays[arrayNum].pValues;
|
||||||
|
@ -4419,7 +4420,7 @@ finish_qsprintf:
|
||||||
{
|
{
|
||||||
void * const pArray = Xcalloc(1, newBytes);
|
void * const pArray = Xcalloc(1, newBytes);
|
||||||
|
|
||||||
kread(kFile, pArray, newBytes);
|
kread(kFile, pArray, readBytes);
|
||||||
|
|
||||||
if (flags & GAMEARRAY_UNSIGNED)
|
if (flags & GAMEARRAY_UNSIGNED)
|
||||||
{
|
{
|
||||||
|
@ -4437,7 +4438,8 @@ finish_qsprintf:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
kread(kFile, pValues, newBytes);
|
memset((char *)pValues + readBytes, 0, newBytes - readBytes);
|
||||||
|
kread(kFile, pValues, readBytes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -602,7 +602,7 @@ size_t __fastcall Gv_GetArrayCountFromFile(int const arrayIdx, size_t const file
|
||||||
|
|
||||||
size_t const elementSize = Gv_GetArrayElementSize(arrayIdx);
|
size_t const elementSize = Gv_GetArrayElementSize(arrayIdx);
|
||||||
size_t const denominator = min(elementSize, sizeof(uint32_t));
|
size_t const denominator = min(elementSize, sizeof(uint32_t));
|
||||||
return filelength / denominator;
|
return (filelength + denominator - 1) / denominator;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __fastcall Gv_GetArrayValue(int const id, int index)
|
int __fastcall Gv_GetArrayValue(int const id, int index)
|
||||||
|
|
Loading…
Reference in a new issue