mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-09 20:24:16 +00:00
chore: Speed up and cleanup level and zone loading; Add safer asset buffer reading (#1314)
* Remove std::couts littered throughout the base * working End of optimizations for now going faster * Remove extraneous compare function std::less<LWOSCENEID> already does this in a map. * gaming * Update Zone.cpp * dlu is moving to bitbucket again * Update Level.cpp --------- Co-authored-by: Jettford <mrjettbradford@gmail.com>
This commit is contained in:
@@ -25,6 +25,10 @@ struct AssetMemoryBuffer : std::streambuf {
|
||||
this->setg(base, base, base + n);
|
||||
}
|
||||
|
||||
~AssetMemoryBuffer() {
|
||||
free(m_Base);
|
||||
}
|
||||
|
||||
pos_type seekpos(pos_type sp, std::ios_base::openmode which) override {
|
||||
return seekoff(sp - pos_type(off_type(0)), std::ios_base::beg, which);
|
||||
}
|
||||
@@ -40,9 +44,17 @@ struct AssetMemoryBuffer : std::streambuf {
|
||||
setg(eback(), eback() + off, egptr());
|
||||
return gptr() - eback();
|
||||
}
|
||||
};
|
||||
|
||||
void close() {
|
||||
free(m_Base);
|
||||
struct AssetStream : std::istream {
|
||||
AssetStream(char* base, std::ptrdiff_t n, bool success) : std::istream(new AssetMemoryBuffer(base, n, success)) {}
|
||||
|
||||
~AssetStream() {
|
||||
delete rdbuf();
|
||||
}
|
||||
|
||||
operator bool() {
|
||||
return reinterpret_cast<AssetMemoryBuffer*>(rdbuf())->m_Success;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -56,7 +68,7 @@ public:
|
||||
|
||||
bool HasFile(const char* name);
|
||||
bool GetFile(const char* name, char** data, uint32_t* len);
|
||||
AssetMemoryBuffer GetFileAsBuffer(const char* name);
|
||||
AssetStream GetFile(const char* name);
|
||||
|
||||
private:
|
||||
void LoadPackIndex();
|
||||
|
Reference in New Issue
Block a user