mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Simplify m_headers init, hardcode 128 less
I don't know how no one realized that the for-loop to (poorly) initialize m_headers was basically unnecessary, and that the memset() should've just been used instead. Well, except it should also be replaced with SDL_memset(), but that's besides the point. Also, I decided to hardcode the 128 thing less, in case people want to fork the source code and make a build where it's changed.
This commit is contained in:
parent
fc03fca838
commit
36e38027d8
1 changed files with 10 additions and 19 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <SDL.h>
|
||||
|
||||
/* FIXME: Abstract to FileSystemUtils! */
|
||||
#include <physfs.h>
|
||||
|
@ -10,16 +10,7 @@
|
|||
binaryBlob::binaryBlob()
|
||||
{
|
||||
numberofHeaders = 0;
|
||||
for (int i = 0; i < 128; i += 1)
|
||||
{
|
||||
m_headers[i].valid = false;
|
||||
|
||||
for (int j = 0; j < 48; j += 1)
|
||||
{
|
||||
m_headers[i].name[j] = '\0';
|
||||
}
|
||||
}
|
||||
::memset(m_headers, 0, 128 * sizeof(resourceheader));
|
||||
SDL_memset(m_headers, 0, sizeof(m_headers));
|
||||
}
|
||||
|
||||
#ifdef VVV_COMPILEMUSIC
|
||||
|
@ -63,7 +54,7 @@ void binaryBlob::writeBinaryBlob(const char* _name)
|
|||
FILE *file = fopen(_name, "wb");
|
||||
if (file != NULL)
|
||||
{
|
||||
fwrite((char*) &m_headers, 1, sizeof(resourceheader) * 128, file);
|
||||
fwrite((char*) &m_headers, 1, sizeof(m_headers), file);
|
||||
|
||||
for (int i = 0; i < numberofHeaders; i += 1)
|
||||
{
|
||||
|
@ -92,11 +83,11 @@ bool binaryBlob::unPackBinary(const char* name)
|
|||
|
||||
size = PHYSFS_fileLength(handle);
|
||||
|
||||
PHYSFS_readBytes(handle, &m_headers, sizeof(resourceheader) * 128);
|
||||
PHYSFS_readBytes(handle, &m_headers, sizeof(m_headers));
|
||||
|
||||
int offset = 0 + (sizeof(resourceheader) * 128);
|
||||
int offset = 0 + (sizeof(m_headers));
|
||||
|
||||
for (int i = 0; i < 128; i += 1)
|
||||
for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1)
|
||||
{
|
||||
/* Name can be stupid, just needs to be terminated */
|
||||
m_headers[i].name[47] = '\0';
|
||||
|
@ -128,7 +119,7 @@ bool binaryBlob::unPackBinary(const char* name)
|
|||
|
||||
printf("The complete reloaded file size: %lli\n", size);
|
||||
|
||||
for (int i = 0; i < 128; i += 1)
|
||||
for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1)
|
||||
{
|
||||
if (m_headers[i].valid == false)
|
||||
{
|
||||
|
@ -143,7 +134,7 @@ bool binaryBlob::unPackBinary(const char* name)
|
|||
|
||||
void binaryBlob::clear()
|
||||
{
|
||||
for (int i = 0; i < 128; i += 1)
|
||||
for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1)
|
||||
{
|
||||
if (m_headers[i].valid)
|
||||
{
|
||||
|
@ -155,7 +146,7 @@ void binaryBlob::clear()
|
|||
|
||||
int binaryBlob::getIndex(const char* _name)
|
||||
{
|
||||
for (int i = 0; i < 128; i += 1)
|
||||
for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1)
|
||||
{
|
||||
if (strcmp(_name, m_headers[i].name) == 0)
|
||||
{
|
||||
|
@ -178,7 +169,7 @@ char* binaryBlob::getAddress(int _index)
|
|||
std::vector<int> binaryBlob::getExtra()
|
||||
{
|
||||
std::vector<int> result;
|
||||
for (int i = 0; i < 128; i += 1)
|
||||
for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1)
|
||||
{
|
||||
if (m_headers[i].valid
|
||||
#define FOREACH_TRACK(track_name) && strcmp(m_headers[i].name, track_name) != 0
|
||||
|
|
Loading…
Reference in a new issue