1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-28 23:48:30 +02:00
VVVVVV/desktop_version/src/BinaryBlob.h
Misa 141181dee7 Refactor extra binary blob tracks to not use STL data marshalling
Just like I refactored text splitting to no longer use std::vectors,
std::strings, or temporary heap allocations, decreasing memory usage and
improving performance; there's no reason to use a temporary
heap-allocated std::vector to grab all extra binary blob indices, when
instead the iteration can just be more immediate.

Instead, what I've done is replaced binaryBlob::getExtra() with
binaryBlob::nextExtra(), which takes in a pointer to an index variable,
and will increment the index variable until it reaches an extra track.
After the caller processes the extra track, it is the caller's
responsibility to increment the variable again before passing it back to
getExtra().

This avoids all heap allocations and brings down the memory usage of
processing extra tracks.
2021-02-19 07:07:39 -05:00

68 lines
1.7 KiB
C++

#ifndef BINARYBLOB_H
#define BINARYBLOB_H
#include <stddef.h>
/* Laaaazyyyyyyy -flibit */
// #define VVV_COMPILEMUSIC
#define TRACK_NAMES(blob) \
FOREACH_TRACK(blob, "data/music/0levelcomplete.ogg") \
FOREACH_TRACK(blob, "data/music/1pushingonwards.ogg") \
FOREACH_TRACK(blob, "data/music/2positiveforce.ogg") \
FOREACH_TRACK(blob, "data/music/3potentialforanything.ogg") \
FOREACH_TRACK(blob, "data/music/4passionforexploring.ogg") \
FOREACH_TRACK(blob, "data/music/5intermission.ogg") \
FOREACH_TRACK(blob, "data/music/6presentingvvvvvv.ogg") \
FOREACH_TRACK(blob, "data/music/7gamecomplete.ogg") \
FOREACH_TRACK(blob, "data/music/8predestinedfate.ogg") \
FOREACH_TRACK(blob, "data/music/9positiveforcereversed.ogg") \
FOREACH_TRACK(blob, "data/music/10popularpotpourri.ogg") \
FOREACH_TRACK(blob, "data/music/11pipedream.ogg") \
FOREACH_TRACK(blob, "data/music/12pressurecooker.ogg") \
FOREACH_TRACK(blob, "data/music/13pacedenergy.ogg") \
FOREACH_TRACK(blob, "data/music/14piercingthesky.ogg") \
FOREACH_TRACK(blob, "data/music/predestinedfatefinallevel.ogg")
struct resourceheader
{
char name[48];
int start_UNUSED;
int size;
bool valid;
};
class binaryBlob
{
public:
binaryBlob();
#ifdef VVV_COMPILEMUSIC
void AddFileToBinaryBlob(const char* _path);
void writeBinaryBlob(const char* _name);
#endif
bool unPackBinary(const char* _name);
int getIndex(const char* _name);
int getSize(int _index);
bool nextExtra(size_t* start);
char* getAddress(int _index);
void clear();
static const int max_headers = 128;
private:
int numberofHeaders;
resourceheader m_headers[max_headers];
char* m_memblocks[max_headers];
};
#endif /* BINARYBLOB_H */