diff --git a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp index 985066e345..3ac18f90ae 100644 --- a/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp +++ b/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsStream.h" #include "hsTimer.h" +#include + #include "pnKeyedObject/plKeyImp.h" #include "plAgeDescription/plAgeManifest.h" diff --git a/Sources/Plasma/CoreLib/CMakeLists.txt b/Sources/Plasma/CoreLib/CMakeLists.txt index 7fdb8b375b..6a45faf245 100644 --- a/Sources/Plasma/CoreLib/CMakeLists.txt +++ b/Sources/Plasma/CoreLib/CMakeLists.txt @@ -9,10 +9,8 @@ set(CoreLib_SOURCES hsGeometry3.cpp hsMatrix33.cpp hsMatrix44.cpp - hsMemory.cpp hsQuat.cpp hsRefCnt.cpp - hsSTLStream.cpp hsStream.cpp hsStringTokenizer.cpp hsSystemInfo.cpp @@ -49,13 +47,11 @@ set(CoreLib_HEADERS hsLockGuard.h hsMatrix44.h hsMatrixMath.h - hsMemory.h hsPoint2.h hsPoolVector.h hsQuat.h hsRefCnt.h hsSIMD.h - hsSTLStream.h hsStream.h hsStringTokenizer.h hsSystemInfo.h diff --git a/Sources/Plasma/CoreLib/hsMemory.cpp b/Sources/Plasma/CoreLib/hsMemory.cpp deleted file mode 100644 index cd1e0dcac1..0000000000 --- a/Sources/Plasma/CoreLib/hsMemory.cpp +++ /dev/null @@ -1,667 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#include "hsMemory.h" -#include "hsExceptions.h" - -#include - -#define DO_MEMORY_REPORTS // dumps memory reports upon start up of engine - -struct hsAppenderHead { - struct hsAppenderHead* fNext; - struct hsAppenderHead* fPrev; - void* fFirst; - void* fStop; - void* fBottom; - - void* GetTop() const { return (char*)this + sizeof(*this); } - void* GetBottom() const { return fBottom; } - void* GetStop() const { return fStop; } - - void* GetFirst() const { return fFirst; } - void* GetLast(size_t elemSize) const { return (char*)fStop - elemSize; } - size_t GetSize() const { return (char*)fStop - (char*)fFirst; } - - bool CanPrepend() const { return fFirst != this->GetTop(); } - size_t PrependSize() const { return (char*)fFirst - (char*)this->GetTop(); } - bool CanAppend() const { return fStop != this->GetBottom(); } - size_t AppendSize() const { return (char*)this->GetBottom() - (char*)fStop; } - - void* Prepend(size_t elemSize) - { - hsAssert(this->CanPrepend(), "bad prepend"); - fFirst = (char*)fFirst - elemSize; - hsAssert((char*)fFirst >= (char*)this->GetTop(), "bad elemSize"); - return fFirst; - } - void* Append(size_t elemSize) - { - hsAssert(this->CanAppend(), "bad append"); - void* data = fStop; - fStop = (char*)fStop + elemSize; - hsAssert((char*)fStop <= (char*)fBottom, "bad elemSize"); - return data; - } - bool PopHead(size_t elemSize, void* data) - { - hsAssert(fFirst != fStop, "Empty"); - if (data) - memmove(data, fFirst, elemSize); - fFirst = (char*)fFirst + elemSize; - return fFirst == fStop; - } - bool PopTail(size_t elemSize, void* data) - { - hsAssert(fFirst != fStop, "Empty"); - fStop = (char*)fStop - elemSize; - if (data) - memmove(data, fStop, elemSize); - return fFirst == fStop; - } - - static hsAppenderHead* NewAppend(size_t elemSize, size_t elemCount, hsAppenderHead* prev) - { - size_t dataSize = elemSize * elemCount; - hsAppenderHead* head = (hsAppenderHead*)malloc(sizeof(hsAppenderHead) + dataSize); - - head->fNext = nullptr; - head->fPrev = prev; - head->fFirst = head->GetTop(); - head->fStop = head->fFirst; - head->fBottom = (char*)head->fFirst + dataSize; - return head; - } - static hsAppenderHead* NewPrepend(size_t elemSize, size_t elemCount, hsAppenderHead* next) - { - size_t dataSize = elemSize * elemCount; - hsAppenderHead* head = (hsAppenderHead*)malloc(sizeof(hsAppenderHead) + dataSize); - - head->fNext = next; - head->fPrev = nullptr; - head->fBottom = (char*)head->GetTop() + dataSize; - head->fFirst = head->fBottom; - head->fStop = head->fBottom; - return head; - } -}; - -//////////////////////////////////////////////////////////////////////////////////////// - -size_t hsAppender::CopyInto(void* data) const -{ - if (data) { - const hsAppenderHead* head = fFirstBlock; - hsDebugCode(size_t totalSize = 0;) - - while (head != nullptr) { - size_t size = head->GetSize(); - memmove(data, head->GetFirst(), size); - - data = (char*)data + size; - head = head->fNext; - hsDebugCode(totalSize += size;) - } - hsAssert(totalSize == fCount * fElemSize, "bad size"); - } - return fCount * fElemSize; -} - -void hsAppender::Reset() -{ - hsAppenderHead* head = fFirstBlock; - - while (head != nullptr) { - hsAppenderHead* next = head->fNext; - free(head); - head = next; - } - - fCount = 0; - fFirstBlock = nullptr; - fLastBlock = nullptr; -} - -void* hsAppender::PushHead() -{ - if (fFirstBlock == nullptr) { - fFirstBlock = hsAppenderHead::NewPrepend(fElemSize, fElemCount, nullptr); - fLastBlock = fFirstBlock; - } - else if (fFirstBlock->CanPrepend() == false) - fFirstBlock = hsAppenderHead::NewPrepend(fElemSize, fElemCount, fFirstBlock); - - fCount += 1; - return fFirstBlock->Prepend(fElemSize); -} - -void hsAppender::PushHead(const void* data) -{ - void* addr = this->PushHead(); - if (data) - memmove(addr, data, fElemSize); -} - -void* hsAppender::PeekHead() const -{ - if (fFirstBlock) - return (char*)fFirstBlock->fFirst; - else - return nullptr; -} - -bool hsAppender::PopHead(void* data) -{ - if (fCount == 0) - return false; - - fCount -= 1; - - if (fFirstBlock->PopHead(fElemSize, data)) { - hsAppenderHead* next = fFirstBlock->fNext; - if (next) - next->fPrev = nullptr; - free(fFirstBlock); - fFirstBlock = next; - if (next == nullptr) - fLastBlock = nullptr; - } - return true; -} - -size_t hsAppender::PopHead(size_t count, void* data) -{ - hsThrowIfBadParam(count >= 0); - - size_t sizeNeeded = count * fElemSize; - size_t origCount = fCount; - - while (fCount > 0) { - size_t size = fFirstBlock->GetSize(); - if (size > sizeNeeded) - size = sizeNeeded; - - if (fFirstBlock->PopHead(size, data)) { - hsAppenderHead* next = fFirstBlock->fNext; - if (next) - next->fPrev = nullptr; - free(fFirstBlock); - fFirstBlock = next; - if (next == nullptr) - fLastBlock = nullptr; - } - - if (data) - data = (void*)((char*)data + size); - sizeNeeded -= size; - fCount -= size / fElemSize; - hsAssert(hsSsize_t(fCount) >= 0, "bad fElemSize"); - } - return origCount - fCount; // return number of elements popped -} - -void* hsAppender::PushTail() -{ - if (fFirstBlock == nullptr) { - fFirstBlock = hsAppenderHead::NewAppend(fElemSize, fElemCount, nullptr); - fLastBlock = fFirstBlock; - } - else if (fLastBlock->CanAppend() == false) { - fLastBlock->fNext = hsAppenderHead::NewAppend(fElemSize, fElemCount, fLastBlock); - fLastBlock = fLastBlock->fNext; - } - - fCount += 1; - return fLastBlock->Append(fElemSize); -} - -void hsAppender::PushTail(const void* data) -{ - void* addr = this->PushTail(); - if (data) - memmove(addr, data, fElemSize); -} - -void hsAppender::PushTail(size_t count, const void* data) -{ - hsThrowIfBadParam(count < 0); - - size_t sizeNeeded = count * fElemSize; - - while (sizeNeeded > 0) { - if (fFirstBlock == nullptr) { - hsAssert(fCount == 0, "uninited count"); - fFirstBlock = hsAppenderHead::NewAppend(fElemSize, fElemCount, nullptr); - fLastBlock = fFirstBlock; - } - else if (!fLastBlock->CanAppend()) { - fLastBlock->fNext = hsAppenderHead::NewAppend(fElemSize, fElemCount, fLastBlock); - fLastBlock = fLastBlock->fNext; - } - - size_t size = fLastBlock->AppendSize(); - hsAssert(size > 0, "bad appendsize"); - if (size > sizeNeeded) - size = sizeNeeded; - void* dst = fLastBlock->Append(size); - - if (data) { - memmove(dst, data, size); - data = (char*)data + size; - } - sizeNeeded -= size; - } - fCount += count; -} - -void* hsAppender::PeekTail() const -{ - if (fLastBlock) - return (char*)fLastBlock->fStop - fElemSize; - else - return nullptr; -} - -bool hsAppender::PopTail(void* data) -{ - if (fCount == 0) - return false; - - fCount -= 1; - - if (fLastBlock->PopTail(fElemSize, data)) { - hsAppenderHead* prev = fLastBlock->fPrev; - if (prev) - prev->fNext = nullptr; - free(fLastBlock); - fLastBlock = prev; - if (prev == nullptr) - fFirstBlock = nullptr; - } - return true; -} - -////////////////////////////////////////////////////////////////////////// - -hsAppenderIterator::hsAppenderIterator(const hsAppender* list) - : fCurrItem() -{ - this->ResetToHead(list); -} - -void hsAppenderIterator::ResetToHead(const hsAppender* list) -{ - fAppender = list; - fCurrBlock = nullptr; - - if (fAppender) { - fCurrBlock = fAppender->fFirstBlock; - if (fCurrBlock) - fCurrItem = fCurrBlock->GetFirst(); - } -} - -void hsAppenderIterator::ResetToTail(const hsAppender* list) -{ - fAppender = list; - fCurrBlock = nullptr; - - if (fAppender) { - fCurrBlock = fAppender->fLastBlock; - if (fCurrBlock) - fCurrItem = fCurrBlock->GetLast(fAppender->fElemSize); - } -} - -void* hsAppenderIterator::Next() -{ - void* item = nullptr; - - if (fCurrBlock) { - item = fCurrItem; - fCurrItem = (char*)fCurrItem + fAppender->fElemSize; - if (fCurrItem == fCurrBlock->GetBottom()) { - fCurrBlock = fCurrBlock->fNext; - if (fCurrBlock) - fCurrItem = fCurrBlock->GetFirst(); - } - else if (fCurrItem == fCurrBlock->GetStop()) { - hsAssert(fCurrBlock->fNext == nullptr, "oops"); - fCurrBlock = nullptr; - } - } - return item; -} - -bool hsAppenderIterator::Next(void* data) -{ - void* addr = this->Next(); - if (addr) { - if (data) - memmove(data, addr, fAppender->fElemSize); - return true; - } - return false; -} - -size_t hsAppenderIterator::Next(size_t count, void* data) -{ - size_t origCount = count; - - while (count > 0 && this->Next(data)) { - if (data) - data = (void*)((char*)data + fAppender->fElemSize); - count -= 1; - } - return origCount - count; -} - -void* hsAppenderIterator::Prev() -{ - void* item = nullptr; - - if (fCurrBlock) { - item = fCurrItem; - fCurrItem = (char*)fCurrItem - fAppender->fElemSize; - if (item == fCurrBlock->GetTop()) { - fCurrBlock = fCurrBlock->fPrev; - if (fCurrBlock) - fCurrItem = fCurrBlock->GetLast(fAppender->fElemSize); - } - else if (item == fCurrBlock->GetFirst()) { - hsAssert(fCurrBlock->fPrev == nullptr, "oops"); - fCurrBlock = nullptr; - } - } - return item; -} - -bool hsAppenderIterator::Prev(void* data) -{ - void* addr = this->Prev(); - if (addr) { - if (data) - memmove(data, addr, fAppender->fElemSize); - return true; - } - return false; -} - -//------------------------------------------------------------- -// -// MEMORY USE REPORTING CODE -// -//------------------------------------------------------------- - -#if 1//!(defined(HS_DEBUGGING)&&(HS_BUILD_FOR_WIN32)&& defined(HS_FIND_MEM_LEAKS)) - // EMPTY STUB -void SortNDumpUnfreedMemory(const char *, bool ) // file name base, and FULL report indicator -{ -} - -#else - -typedef struct _CrtMemBlockHeader -{ -// Pointer to the block allocated just before this one: - struct _CrtMemBlockHeader *pBlockHeaderNext; -// Pointer to the block allocated just after this one: - struct _CrtMemBlockHeader *pBlockHeaderPrev; - char *szFileName; // File name - int nLine; // Line number - size_t nDataSize; // Size of user block - int nBlockUse; // Type of block - long lRequest; // Allocation number -// Buffer just before (lower than) the user's memory: - unsigned char gap[4]; -} _CrtMemBlockHeader; - -/* In an actual memory block in the debug heap, - * this structure is followed by: - * unsigned char data[nDataSize]; - * unsigned char anotherGap[4]; - */ - -// -// Dump formatted string to OutputDebugString -// -void __cdecl DebugMsg( LPSTR fmt, ... ) -{ - - char buff[256]; - wvsprintf(buff, fmt, (char *)(&fmt+1)); - hsStatusMessage(buff); - -} - -char *TrimFileName(char *name) // Trim file name of leading Directories -{ - int len = 0; - char *ptr; - if (!name) - return nullptr; - - len = strlen(name); - ptr = name + len; - for ( ptr--; ptr > name; ptr--) - { - if (*ptr == '\\') - { - ptr++; - break; - } - } - return ptr; -} - -// -// Loop thru all unfreed blocks in the heap and dump out detailed info -// - -struct looktbl { - char * fName; // Name of file -// long fAllocs; // Number of Alloc calls - long fBytes; // Total Bytes Alloc'd -}; -#define LTBLMAX 300 - -//--------------------------------------------------------------------------- -// This routine will report on the memory used in the engine. -// If argument full is true, it gives a full dump from the start of the program -// if !full, then each time the routine is called it remembers where it finishes off, then the next -// call with !full, it will (attempt) to report on the newest allocations, backward to the last checkpoint -//-------------------------------------------------------------------------- - -void SortNDumpUnfreedMemory(const char *nm, bool full) // file name base, and FULL report indicator -{ -#ifndef DO_MEMORY_REPORTS - if (!full) // full is launched by control M...partials are called each time the engine starts - return; -#endif - - char fname[512]; - snprintf(fname, std::size(fname), "%s_dmp.txt", nm); - char *errStr = ""; - - - _CrtMemState heap_state; -static uint32_t GrandTotal =0; -static _CrtMemBlockHeader *cmbh_last; // Remember this header for next incremental check DANGER this - // could break if this is freed...(gives bad report) - _CrtMemBlockHeader *cmbh_last_good; - - _CrtMemBlockHeader *cmbh; - // Get Current heap state - - _CrtMemCheckpoint(&heap_state); - - cmbh = heap_state.pBlockHeader; - - long totsize= 0; // Track Total Bytes - long normsize = 0; // Track total of NORMAL Blocks - - looktbl *ltb = new looktbl[LTBLMAX]; - long tblEnd=1; // first is "NULL"; - - memset((void *)ltb,0,sizeof(looktbl) * LTBLMAX); // clear table area - - char *ftrim; - - - ltb[0].fName = "NULL"; // Use first Table Pos for NULL - - long tblpos; - while (cmbh != nullptr) // Accumulate Stats to table - { - if (cmbh == cmbh_last && !full) // full indicates ignore last "checkpoint", stop at last checkpoint if !full - break; - cmbh_last_good = cmbh; - totsize += cmbh->nDataSize; - if (cmbh->nBlockUse == _NORMAL_BLOCK) - { - normsize += cmbh->nDataSize; - - if (cmbh->szFileName != nullptr) // Shorten to just the file name, looks better, and strcmps faster - { - ftrim = TrimFileName(cmbh->szFileName); - for (tblpos = 1; tblpos < tblEnd; tblpos++) // find the name in the table - { - if (!strcmp(ftrim,ltb[tblpos].fName)) - break; // found it - } - } - else - { - tblpos = 0; // Use "NULL", first pos of table - } - - if (tblpos == tblEnd) // Did not find it...add it - { - tblEnd++; - if (tblEnd >= LTBLMAX) - { DebugMsg("DumpUnfreedMemoryInfo: EXCEED MAX TABLE LENGTH\n"); - tblEnd--; - break; - } - ltb[tblpos].fName = ftrim; // Add name - } - // Add Stats -// ltb[tblpos].fAllocs++; - ltb[tblpos].fBytes += cmbh->nDataSize; - - - } - cmbh = cmbh->pBlockHeaderNext; - - } - // This Code relies on the _CrtMemBlockHeader *cmbh_last_good for the "last" checkpoint to still be around... - // If the following occurs, that chunk has been deleted. we could fix this by allocating our own - // chunk and keeping it (watch for mem leaks though) or figuring out an "approximat" re syncying routine - // that works before we run thru collecting data. PBG - - if (cmbh_last && !full && cmbh == nullptr) - { - //hsAssert(0,"Stats error: incremental mem check point has been deleted"); - errStr = "CHECK POINT ERROR, Results Inacurate"; - } - - if (normsize) // Don't write out about nothing - { - - CreateDirectory("Reports", nullptr); // stick em in a sub directory - char fnm[512]; - snprintf(fnm, std::size(fnm), "Reports\\%s", fname); - - FILE * DumpLogFile = fopen( fnm, "w" ); -// long allocs=0; - if (DumpLogFile != nullptr) - { - // Print Stats - fprintf(DumpLogFile, "Filename Total=%ld(k) %s\n",(normsize + 500)/1000,errStr); - for (int i = 0; i < tblEnd; i++) - { //fprintf(DumpLogFile,"%s\t%ld\n",ltb[i].fName, (ltb[i].fBytes+500)/1000);//,ltb[i].fAllocs); - fprintf(DumpLogFile,"%s ",ltb[i].fName); - int len = strlen(ltb[i].fName); - - for(int x=len; x < 25; x++) - fputc(' ',DumpLogFile); // make even columns - fprintf(DumpLogFile,"%5ld K\n",(uint32_t)( ltb[i].fBytes+500)/1000);//,ltb[i].fAllocs); - - //allocs += ltb[i].fAllocs; - } - - DebugMsg("MEMORY USE FILE DUMPED TO %s \n",fname); - DebugMsg("MEMORY Check: Total size %ld, Normal Size: %ld\n",totsize,normsize); - - fclose(DumpLogFile); - } - static int first=1; - if (!full) // if this is a partial mem dump, write to the ROOMS.txt file a summary - { - snprintf(fnm, std::size(fnm), "Reports\\%s", "ROOMS.txt"); - - if (first) - { DumpLogFile = fopen( fnm, "w" ); // first time clobber the old - if (DumpLogFile) - fprintf(DumpLogFile, "Filename Memory-Used(K) RunningTotal\n");// \tAllocation Calls \n" ); - first = 0; - } - else - DumpLogFile = fopen( fnm, "a+" ); - if( DumpLogFile) - { fprintf(DumpLogFile,"%s ",nm); - int len = strlen(nm); - GrandTotal += (uint32_t)(normsize+500)/1000; - - for(int x=len; x < 25; x++) - fputc(' ',DumpLogFile); // make even columns - fprintf(DumpLogFile,"%5ld K %5ld %s\n",(uint32_t)(normsize+500)/1000,GrandTotal,errStr);//, allocs); - fclose(DumpLogFile); - } - } - } - - - cmbh_last = heap_state.pBlockHeader; - delete ltb; -} -#endif diff --git a/Sources/Plasma/CoreLib/hsMemory.h b/Sources/Plasma/CoreLib/hsMemory.h deleted file mode 100644 index 80a4c1665c..0000000000 --- a/Sources/Plasma/CoreLib/hsMemory.h +++ /dev/null @@ -1,174 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#ifndef hsMemoryDefined -#define hsMemoryDefined - -#include "HeadSpin.h" - -class hsAppender { - struct hsAppenderHead* fFirstBlock, *fLastBlock; - size_t fElemSize, fElemCount, fCount; - - friend class hsAppenderIterator; -public: - hsAppender(size_t elemSize, size_t elemCount = 16) - : fFirstBlock(), fLastBlock(), fElemSize(elemSize), fElemCount(elemCount), fCount() { } - ~hsAppender() { this->Reset(); }; - - size_t ElemSize() const { return fElemSize; } - size_t Count() const { return fCount; } - bool IsEmpty() const { return fCount == 0; } - void Reset(); - - size_t CopyInto(void* data = nullptr) const; // return size of data array in bytes - - void* PushHead(); - void PushHead(const void* data); - void* PushTail(); - void PushTail(const void* data); - void PushTail(size_t count, const void* data); // data[] = count * fElemSize - void* PeekHead() const; - void* PeekTail() const; - bool PopHead(void* data = nullptr); - size_t PopHead(size_t count, void* data = nullptr); // data[] = count * fElemSize - bool PopTail(void* data = nullptr); - - // Alternate interfaces - - void* Prepend() { return this->PushHead(); } - void* Append() { return this->PushTail(); } - - void* Push() { return this->PushHead(); } - void Push(const void* data) { this->PushHead(data); } - bool Pop(void* data = nullptr) { return this->PopHead(data); } - - void* Enqueue() { return this->PushTail(); }; - void Enqueue(const void* data) { this->PushTail(data); } - void Enqueue(size_t count, const void* data) { this->PushTail(count, data); } - bool Dequeue(void* data = nullptr) { return this->PopHead(data); } - size_t Dequeue(size_t count, void* data = nullptr) { return this->PopHead(count, data); } -}; - -class hsAppenderIterator { - const hsAppender* fAppender; - const struct hsAppenderHead* fCurrBlock; - void* fCurrItem; - -public: - hsAppenderIterator(const hsAppender* list = nullptr); - - void ResetToHead(const hsAppender* list = nullptr); - void ResetToTail(const hsAppender* list = nullptr); - void* Next(); - bool Next(void* data); - size_t Next(size_t count, void* data); - void* Prev(); - bool Prev(void* data); - - // Obsolete interface - void Reset(const hsAppender* list = nullptr) { this->ResetToHead(list); } -}; - -/////////////////////////////////////////////////////////////////////////////// - -template class hsTAppender : hsAppender { -public: - hsTAppender() : hsAppender(sizeof(T)) {} - hsTAppender(size_t minCount) : hsAppender(sizeof(T), minCount) {} - - hsAppender* GetAppender() { return this; } - const hsAppender* GetAppender() const { return this; } - - size_t Count() const { return hsAppender::Count(); } - bool IsEmpty() const { return hsAppender::IsEmpty(); } - void Reset() { hsAppender::Reset(); } - - size_t CopyInto(T copy[]) const { return hsAppender::CopyInto(copy); } - - T* PushHead() { return (T*)hsAppender::PushHead(); } - void PushHead(const T& item) { *this->PushHead() = item; } - T* PushTail() { return (T*)hsAppender::PushTail(); } - void PushTail(const T& item) { *this->PushTail() = item; }; - void PushTail(size_t count, const T item[]) { this->hsAppender::PushTail(count, item); }; - T* PeekHead() const { return (T*)hsAppender::PeekHead(); } - T* PeekTail() const { return (T*)hsAppender::PeekTail(); } - bool PopHead(T* item = nullptr) { return hsAppender::PopHead(item); } - size_t PopHead(size_t count, T item[] = nullptr) { return hsAppender::PopHead(count, item); } - bool PopTail(T* item = nullptr) { return hsAppender::PopTail(item); } - - // Alternate intefaces - - T* Prepend() { return this->PushHead(); } - T* Append() { return this->PushTail(); } - void PrependItem(const T& item) { this->PushHead(item); } - void AppendItem(const T& item) { this->PushTail(item); } - - T* Push() { return this->PushHead(); } - void Push(const T& item) { this->PushHead(item); } - bool Pop(T* item = nullptr) { return this->PopHead(item); } - - T* Enqueue() { return this->PushTail(); }; - void Enqueue(const T& item) { this->PushTail(item); } - void Enqueue(size_t count, const T item[]) { this->PushTail(count, item); } - bool Dequeue(T* item = nullptr) { return this->PopHead(item); } - size_t Dequeue(size_t count, T item[] = nullptr) { return this->PopHead(count, item); } -}; - -template class hsTAppenderIterator : hsAppenderIterator { -public: - hsTAppenderIterator() : hsAppenderIterator() {} - hsTAppenderIterator(const hsTAppender* list) : hsAppenderIterator(list->GetAppender()) {} - - void ResetToHead() { hsAppenderIterator::ResetToHead(nullptr); } - void ResetToHead(const hsTAppender* list) { hsAppenderIterator::ResetToHead(list->GetAppender()); } - void ResetToTail() { hsAppenderIterator::ResetToTail(nullptr); } - void ResetToTail(const hsTAppender* list) { hsAppenderIterator::ResetToTail(list->GetAppender()); } - T* Next() { return (T*)hsAppenderIterator::Next(); } - int Next(T* item) { return hsAppenderIterator::Next(item); } - T* Prev() { return (T*)hsAppenderIterator::Prev(); } - bool Prev(T* item) { return hsAppenderIterator::Prev(item); } - - // Obsolete interfaces - void Reset() { this->ResetToHead(); } - void Reset(const hsTAppender* list) { this->ResetToHead(list); } -}; -#endif diff --git a/Sources/Plasma/CoreLib/hsSTLStream.cpp b/Sources/Plasma/CoreLib/hsSTLStream.cpp deleted file mode 100644 index cd0f5c6d1d..0000000000 --- a/Sources/Plasma/CoreLib/hsSTLStream.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#include "hsSTLStream.h" - -bool hsVectorStream::AtEnd() -{ - return (fBytesRead >= fEnd); -} - -uint32_t hsVectorStream::Read(uint32_t byteCount, void *buffer) -{ - if (fBytesRead + byteCount > fEnd) - { -// hsStatusMessageF("Reading past end of hsVectorStream (read %u of %u requested bytes)", fEnd-fBytesRead, byteCount); - byteCount = fEnd - fBytesRead; - } - - memcpy(buffer, &fVector[fBytesRead], byteCount); - - fBytesRead += byteCount; - fPosition += byteCount; - - return byteCount; -} - -uint32_t hsVectorStream::Write(uint32_t byteCount, const void* buffer) -{ - // If we are at the end of the vector, we can just do a block insert of the data - if (fPosition == fVector.size()) - fVector.insert(fVector.end(), (uint8_t*)buffer, (uint8_t*)buffer+byteCount); - // If we are in the middle, I don't know how to just overwrite a block of the vector. - // So, we make sure there is enough space and copy the elements one by one - else - { - fVector.reserve(fPosition+byteCount); - for (uint32_t i = 0; i < byteCount; i++) - fVector[fPosition+i] = ((uint8_t*)buffer)[i]; - } - - fPosition += byteCount; - - if (fPosition > fEnd) - fEnd = fPosition; - - return byteCount; -} - -void hsVectorStream::Skip(uint32_t deltaByteCount) -{ - fBytesRead += deltaByteCount; - fPosition += deltaByteCount; -} - -void hsVectorStream::Rewind() -{ - fBytesRead = 0; - fPosition = 0; -} - -void hsVectorStream::FastFwd() -{ - fBytesRead = fPosition = fEnd; -} - -void hsVectorStream::Truncate() -{ - fVector.erase(fVector.begin()+fPosition, fVector.end()); - fEnd = fPosition-1; -} - -uint32_t hsVectorStream::GetEOF() -{ - return fEnd; -} - -void hsVectorStream::CopyToMem(void* mem) -{ - memcpy(mem, &fVector[0], fEnd); -} - -void hsVectorStream::Erase(uint32_t bytes) -{ - hsAssert(fPosition+bytes <= fEnd, "Erasing past end of stream"); - - fVector.erase(fVector.begin()+fPosition, fVector.begin()+fPosition+bytes); - fEnd -= bytes; -} - -void hsVectorStream::Reset() -{ - fBytesRead = 0; - fPosition = 0; - fEnd = 0; - fVector.clear(); -} - -const void *hsVectorStream::GetData() -{ - if (fVector.size() > 0) - return &fVector[0]; - else - return nullptr; -} diff --git a/Sources/Plasma/CoreLib/hsSTLStream.h b/Sources/Plasma/CoreLib/hsSTLStream.h deleted file mode 100644 index 0c166713dd..0000000000 --- a/Sources/Plasma/CoreLib/hsSTLStream.h +++ /dev/null @@ -1,87 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#ifndef _hsSTLStream_h_inc_ -#define _hsSTLStream_h_inc_ - -#include "hsStream.h" - -// -// In-memory only -// Erase function lets you cut a chunk out of the middle of the stream -// -class hsVectorStream : public hsStream -{ -protected: - std::vector fVector; - uint32_t fEnd; // End of file (one past the last byte) - -public: - hsVectorStream() : fEnd() { } - hsVectorStream(uint32_t chunkSize) : fEnd() { fVector.reserve(chunkSize); }; - - bool Open(const plFileName &, const char *) override { hsAssert(0, "hsVectorStream::Open Not Implemented"); return false; } - bool Close() override { hsAssert(0, "hsVectorStream::Close Not Implemented"); return false; } - - bool AtEnd() override; - uint32_t Read(uint32_t byteCount, void * buffer) override; - uint32_t Write(uint32_t byteCount, const void* buffer) override; - void Skip(uint32_t deltaByteCount) override; - void Rewind() override; - void FastFwd() override; - void Truncate() override; - - uint32_t GetEOF() override; - void CopyToMem(void* mem) override; - - virtual void Reset(); // clears the buffers - - // Erase number of bytes at the current position - virtual void Erase(uint32_t bytes); - // A pointer to the beginning of the data in the stream. This is only valid - // until someone modifies the stream. - const void *GetData(); - // In case you want to try and be efficient with your memory allocations - void Reserve(uint32_t bytes) { fVector.reserve(bytes); } -}; - -#endif // _hsSTLStream_h_inc_ diff --git a/Sources/Plasma/CoreLib/hsStream.cpp b/Sources/Plasma/CoreLib/hsStream.cpp index 7ae63ec6be..19c26e6653 100644 --- a/Sources/Plasma/CoreLib/hsStream.cpp +++ b/Sources/Plasma/CoreLib/hsStream.cpp @@ -43,23 +43,17 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsStream.h" #include "hsExceptions.h" -#include "hsMemory.h" #include #if HS_BUILD_FOR_WIN32 # include #endif #include +#include #if HS_BUILD_FOR_UNIX #include #endif -////////////////////////////////////////////////////////////////////////////////// - -void hsStream::FastFwd() -{ - hsThrow("FastFwd unimplemented by subclass of stream"); -} uint32_t hsStream::GetPosition() const { @@ -74,11 +68,6 @@ void hsStream::SetPosition(uint32_t position) Skip(position); } -void hsStream::Truncate() -{ - hsThrow("Truncate unimplemented by subclass of stream"); -} - uint32_t hsStream::GetSizeLeft() { uint32_t ret = 0; @@ -96,19 +85,6 @@ uint32_t hsStream::GetSizeLeft() ////////////////////////////////////////////////////////////////////////////////// -uint32_t hsStream::GetEOF() -{ - hsThrow( "GetEOF() unimplemented by subclass of stream"); - return 0; -} - -void hsStream::CopyToMem(void* mem) -{ - hsThrow( "CopyToMem unimplemented by subclass of stream"); -} - -////////////////////////////////////////////////////////////////////////////////// - uint32_t hsStream::WriteSafeString(const ST::string &string) { size_t len = string.size(); @@ -217,12 +193,6 @@ uint8_t hsStream::ReadByte() return value; } -bool hsStream::AtEnd() -{ - hsAssert(0,"No hsStream::AtEnd() implemented for this stream class"); - return false; -} - bool hsStream::IsTokenSeparator(char c) { return (isspace(static_cast(c)) || c==',' || c=='='); @@ -473,8 +443,6 @@ bool hsUNIXStream::Close() if (fRef) rtn = fclose(fRef); fRef = nullptr; - delete [] fBuff; - fBuff = nullptr; return !rtn; } @@ -484,7 +452,6 @@ uint32_t hsUNIXStream::Read(uint32_t bytes, void* buffer) if (!fRef || !bytes) return 0; size_t numItems = ::fread(buffer, 1 /*size*/, bytes /*count*/, fRef); - fBytesRead += numItems; fPosition += numItems; if (numItems < bytes) { @@ -519,7 +486,6 @@ void hsUNIXStream::SetPosition(uint32_t position) { if (!fRef || (position == fPosition)) return; - fBytesRead = position; fPosition = position; (void)::fseek(fRef, position, SEEK_SET); } @@ -528,7 +494,6 @@ void hsUNIXStream::Skip(uint32_t delta) { if (!fRef) return; - fBytesRead += delta; fPosition += delta; (void)::fseek(fRef, delta, SEEK_CUR); } @@ -537,7 +502,6 @@ void hsUNIXStream::Rewind() { if (!fRef) return; - fBytesRead = 0; fPosition = 0; (void)::fseek(fRef, 0, SEEK_SET); } @@ -547,7 +511,7 @@ void hsUNIXStream::FastFwd() if (!fRef) return; (void)::fseek(fRef, 0, SEEK_END); - fBytesRead = fPosition = ftell(fRef); + fPosition = ftell(fRef); } uint32_t hsUNIXStream::GetEOF() @@ -660,54 +624,36 @@ uint32_t plReadOnlySubStream::GetEOF() ////////////////////////////////////////////////////////////////////////////////////// -#define kRAMStreamChunkSize 1024 - -hsRAMStream::hsRAMStream() : fAppender(1, kRAMStreamChunkSize) -{ - fIter.ResetToHead(&fAppender); -} - -hsRAMStream::hsRAMStream(uint32_t chunkSize) : fAppender(1, chunkSize) -{ - fIter.ResetToHead(&fAppender); -} - -hsRAMStream::~hsRAMStream() -{ -} - -void hsRAMStream::Reset() -{ - fBytesRead = 0; - fPosition = 0; - - fAppender.Reset(); - fIter.ResetToHead(&fAppender); -} - bool hsRAMStream::AtEnd() { - return (fBytesRead >= fAppender.Count() * fAppender.ElemSize()); + return (fPosition >= fVector.size()); } uint32_t hsRAMStream::Read(uint32_t byteCount, void * buffer) { - if (fBytesRead + byteCount > fAppender.Count() * fAppender.ElemSize()) - byteCount = (fAppender.Count() * fAppender.ElemSize()) - fBytesRead; + if (fPosition + byteCount > fVector.size()) { + byteCount = fVector.size() - fPosition; + } + + memcpy(buffer, fVector.data() + fPosition, byteCount); - fBytesRead += byteCount; fPosition += byteCount; - fIter.Next(byteCount, buffer); - return byteCount; } uint32_t hsRAMStream::Write(uint32_t byteCount, const void* buffer) { - fPosition += byteCount; + size_t spaceUntilEof = fVector.size() - fPosition; + if (byteCount <= spaceUntilEof) { + memcpy(fVector.data() + fPosition, buffer, byteCount); + } else { + memcpy(fVector.data() + fPosition, buffer, spaceUntilEof); + auto buf = static_cast(buffer); + fVector.insert(fVector.end(), buf + spaceUntilEof, buf + byteCount); + } - fAppender.PushTail(byteCount, buffer); + fPosition += byteCount; return byteCount; } @@ -715,33 +661,58 @@ uint32_t hsRAMStream::Write(uint32_t byteCount, const void* buffer) void hsRAMStream::Skip(uint32_t deltaByteCount) { fPosition += deltaByteCount; - fIter.Next(deltaByteCount, nullptr); } void hsRAMStream::Rewind() { - fBytesRead = 0; fPosition = 0; - fIter.ResetToHead(&fAppender); +} + +void hsRAMStream::FastFwd() +{ + fPosition = fVector.size(); } void hsRAMStream::Truncate() { - Reset(); + fVector.resize(fPosition); } uint32_t hsRAMStream::GetEOF() { - return fAppender.Count() * fAppender.ElemSize(); + return fVector.size(); } void hsRAMStream::CopyToMem(void* mem) { - (void)fAppender.CopyInto(mem); + memcpy(mem, fVector.data(), fVector.size()); +} + +void hsRAMStream::Erase(uint32_t bytes) +{ + hsAssert(fPosition+bytes <= fVector.size(), "Erasing past end of stream"); + + fVector.erase(fVector.begin()+fPosition, fVector.begin()+fPosition+bytes); +} + +void hsRAMStream::Reset() +{ + fPosition = 0; + fVector.clear(); +} + +const void *hsRAMStream::GetData() +{ + return fVector.data(); } ////////////////////////////////////////////////////////////////////// +bool hsNullStream::AtEnd() +{ + return true; +} + uint32_t hsNullStream::Read(uint32_t byteCount, void * buffer) { hsThrow("hsNullStream: Can't read from this stream!"); @@ -750,7 +721,6 @@ uint32_t hsNullStream::Read(uint32_t byteCount, void * buffer) uint32_t hsNullStream::Write(uint32_t byteCount, const void* buffer) { - fBytesRead += byteCount; fPosition += byteCount; return byteCount; @@ -758,16 +728,17 @@ uint32_t hsNullStream::Write(uint32_t byteCount, const void* buffer) void hsNullStream::Skip(uint32_t deltaByteCount) { - fBytesRead += deltaByteCount; fPosition += deltaByteCount; } void hsNullStream::Rewind() { - fBytesRead = 0; fPosition = 0; } +void hsNullStream::FastFwd() +{} + void hsNullStream::Truncate() { } @@ -789,7 +760,6 @@ uint32_t hsReadOnlyStream::Read(uint32_t byteCount, void* buffer) memmove(buffer, fData, byteCount); fData += byteCount; - fBytesRead += byteCount; fPosition += byteCount; return byteCount; } @@ -802,7 +772,6 @@ uint32_t hsReadOnlyStream::Write(uint32_t byteCount, const void* buffer) void hsReadOnlyStream::Skip(uint32_t deltaByteCount) { - fBytesRead += deltaByteCount; fPosition += deltaByteCount; fData += deltaByteCount; if (fData > fStop) @@ -811,11 +780,16 @@ void hsReadOnlyStream::Skip(uint32_t deltaByteCount) void hsReadOnlyStream::Rewind() { - fBytesRead = 0; fPosition = 0; fData = fStart; } +void hsReadOnlyStream::FastFwd() +{ + fPosition = GetEOF(); + fData = fStop; +} + void hsReadOnlyStream::Truncate() { hsThrow( "can't write to a readonly stream"); @@ -841,7 +815,6 @@ uint32_t hsWriteOnlyStream::Write(uint32_t byteCount, const void* buffer) hsThrow("Write past end of stream"); memmove(fData, buffer, byteCount); fData += byteCount; - fBytesRead += byteCount; fPosition += byteCount; return byteCount; } @@ -946,6 +919,11 @@ void hsQueueStream::FastFwd() fReadCursor = fWriteCursor; } +void hsQueueStream::Truncate() +{ + fWriteCursor = fReadCursor; +} + bool hsQueueStream::AtEnd() { return fReadCursor == fWriteCursor; @@ -1036,10 +1014,10 @@ bool hsBufferedStream::Close() if (fBufferReadIn + fReadDirect > 0) wasted -= int((float(fBufferReadOut+fReadDirect) / float(fBufferReadIn+fReadDirect)) * 100.f); - s.WriteFmt("{},{},{},{},{},{},{},{}\n", + s.WriteString(ST::format("{},{},{},{},{},{},{},{}\n", fFilename, fBufferHits, fBufferMisses, fBufferReadIn, fBufferReadOut, fReadDirect, wasted, - fCloseReason ? fCloseReason : "Unknown"); + fCloseReason ? fCloseReason : "Unknown")); s.Close(); #endif // LOG_BUFFERED @@ -1213,6 +1191,13 @@ void hsBufferedStream::Rewind() fPosition = 0; } +void hsBufferedStream::FastFwd() +{ + fseek(fRef, 0, SEEK_END); + fBufferLen = 0; + fPosition = ftell(fRef); +} + uint32_t hsBufferedStream::GetEOF() { if (fWriteBufferUsed) diff --git a/Sources/Plasma/CoreLib/hsStream.h b/Sources/Plasma/CoreLib/hsStream.h index 00131e7bb6..137c306267 100644 --- a/Sources/Plasma/CoreLib/hsStream.h +++ b/Sources/Plasma/CoreLib/hsStream.h @@ -43,9 +43,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define hsStream_Defined #include "HeadSpin.h" -#include "hsMemory.h" #include "plFileSystem.h" -#include + +#include +#include class hsStream { public: @@ -54,37 +55,31 @@ enum { kComment = '#' }; protected: - uint32_t fBytesRead; uint32_t fPosition; bool IsTokenSeparator(char c); public: - hsStream() : fBytesRead(0), fPosition(0) {} + hsStream() : fPosition(0) {} virtual ~hsStream() { } virtual bool Open(const plFileName &, const char * = "rb") = 0; virtual bool Close()=0; - virtual bool AtEnd(); + virtual bool AtEnd() = 0; virtual uint32_t Read(uint32_t byteCount, void * buffer) = 0; virtual uint32_t Write(uint32_t byteCount, const void* buffer) = 0; virtual void Skip(uint32_t deltaByteCount) = 0; virtual void Rewind() = 0; - virtual void FastFwd(); + virtual void FastFwd() = 0; virtual uint32_t GetPosition() const; virtual void SetPosition(uint32_t position); - virtual void Truncate(); + virtual void Truncate() = 0; virtual void Flush() {} - virtual uint32_t GetEOF(); + virtual uint32_t GetEOF() = 0; uint32_t GetSizeLeft(); - virtual void CopyToMem(void* mem); - virtual bool IsCompressed() { return false; } uint32_t WriteString(const ST::string & string) { return Write((uint32_t)string.size(), string.c_str()); } - template - uint32_t WriteFmt(const char * fmt, _Args&&... args) { return WriteString(ST::format(fmt, std::forward<_Args>(args)...)); } - uint32_t WriteSafeString(const ST::string &string); uint32_t WriteSafeWString(const ST::string &string); ST::string ReadSafeString(); @@ -158,10 +153,9 @@ class hsStreamable { class hsUNIXStream: public hsStream { FILE* fRef; - char* fBuff; public: - hsUNIXStream(): fRef(), fBuff() { } + hsUNIXStream() : fRef() {} ~hsUNIXStream(); bool Open(const plFileName& name, const char* mode = "rb") override; bool Close() override; @@ -211,13 +205,17 @@ class plReadOnlySubStream: public hsStream uint32_t GetEOF() override; }; -class hsRAMStream : public hsStream { - hsAppender fAppender; - hsAppenderIterator fIter; +// +// In-memory only +// Erase function lets you cut a chunk out of the middle of the stream +// +class hsRAMStream : public hsStream +{ + std::vector fVector; + public: - hsRAMStream(); - hsRAMStream(uint32_t chunkSize); - virtual ~hsRAMStream(); + hsRAMStream() {} + hsRAMStream(uint32_t chunkSize) { fVector.reserve(chunkSize); } bool Open(const plFileName &, const char *) override { hsAssert(0, "hsRAMStream::Open NotImplemented"); return false; } bool Close() override { return false; } @@ -228,12 +226,21 @@ class hsRAMStream : public hsStream { uint32_t Write(uint32_t byteCount, const void* buffer) override; void Skip(uint32_t deltaByteCount) override; void Rewind() override; + void FastFwd() override; void Truncate() override; uint32_t GetEOF() override; - void CopyToMem(void* mem) override; + void CopyToMem(void* mem); void Reset(); // clears the buffers + + // Erase number of bytes at the current position + void Erase(uint32_t bytes); + // A pointer to the beginning of the data in the stream. This is only valid + // until someone modifies the stream. + const void* GetData(); + // In case you want to try and be efficient with your memory allocations + void Reserve(uint32_t bytes) { fVector.reserve(bytes); } }; class hsNullStream : public hsStream { @@ -242,14 +249,16 @@ class hsNullStream : public hsStream { bool Open(const plFileName &, const char *) override { return true; } bool Close() override { return true; } + bool AtEnd() override; uint32_t Read(uint32_t byteCount, void * buffer) override; // throws exception uint32_t Write(uint32_t byteCount, const void* buffer) override; void Skip(uint32_t deltaByteCount) override; void Rewind() override; + void FastFwd() override; void Truncate() override; - uint32_t GetBytesWritten() const { return fBytesRead; } - void Reset( ) { fBytesRead = 0; } + uint32_t GetEOF() override { return fPosition; } + void Reset() { fPosition = 0; } }; // read only mem stream @@ -270,10 +279,10 @@ class hsReadOnlyStream : public hsStream { uint32_t Write(uint32_t byteCount, const void* buffer) override; // throws exception void Skip(uint32_t deltaByteCount) override; void Rewind() override; + void FastFwd() override; void Truncate() override; - virtual uint32_t GetBytesRead() const { return fBytesRead; } uint32_t GetEOF() override { return (uint32_t)(fStop-fStart); } - void CopyToMem(void* mem) override; + void CopyToMem(void* mem); }; // write only mem stream @@ -286,8 +295,6 @@ class hsWriteOnlyStream : public hsReadOnlyStream { bool Close() override { hsAssert(0, "hsWriteOnlyStream::Close NotImplemented"); return false; } uint32_t Read(uint32_t byteCount, void * buffer) override; // throws exception uint32_t Write(uint32_t byteCount, const void* buffer) override; - uint32_t GetBytesRead() const override { return 0; } - virtual uint32_t GetBytesWritten() const { return fBytesRead; } }; // circular queue stream @@ -310,8 +317,10 @@ class hsQueueStream : public hsStream { void Skip(uint32_t deltaByteCount) override; void Rewind() override; void FastFwd() override; + void Truncate() override; bool AtEnd() override; + uint32_t GetEOF() override { return fWriteCursor - fReadCursor; } uint32_t GetSize() { return fSize; } const char* GetQueue() { return fQueue; } uint32_t GetReadCursor() { return fReadCursor; } @@ -352,6 +361,7 @@ class hsBufferedStream : public hsStream uint32_t Write(uint32_t byteCount, const void* buffer) override; void Skip(uint32_t deltaByteCount) override; void Rewind() override; + void FastFwd() override; void Truncate() override; uint32_t GetEOF() override; diff --git a/Sources/Plasma/FeatureLib/pfAnimation/plAnimDebugList.cpp b/Sources/Plasma/FeatureLib/pfAnimation/plAnimDebugList.cpp index 5f58c45ef2..2c8525899e 100644 --- a/Sources/Plasma/FeatureLib/pfAnimation/plAnimDebugList.cpp +++ b/Sources/Plasma/FeatureLib/pfAnimation/plAnimDebugList.cpp @@ -45,6 +45,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsResMgr.h" #include "hsTimer.h" +#include + #include "pnSceneObject/plSceneObject.h" #include "plAnimation/plAGAnim.h" diff --git a/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp b/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp index df25a5fe1b..e016264f9c 100644 --- a/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp +++ b/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp @@ -278,6 +278,7 @@ class pfPatcherStream : public plZlibStream uint32_t GetPosition() const override { return fOutput->GetPosition(); } uint32_t Read(uint32_t count, void* buf) override { return fOutput->Read(count, buf); } void Rewind() override { fOutput->Rewind(); } + void FastFwd() override { fOutput->FastFwd(); } void SetPosition(uint32_t pos) override { fOutput->SetPosition(pos); } void Skip(uint32_t deltaByteCount) override { fOutput->Skip(deltaByteCount); } diff --git a/Sources/Plasma/NucleusLib/pnFactory/plFactory.cpp b/Sources/Plasma/NucleusLib/pnFactory/plFactory.cpp index 3f9acb3136..c47b856326 100644 --- a/Sources/Plasma/NucleusLib/pnFactory/plFactory.cpp +++ b/Sources/Plasma/NucleusLib/pnFactory/plFactory.cpp @@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // For class names #include "plCreatableStrings.h" +#include static plFactory* theFactory = nullptr; diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp index 25bed41130..f3151f2135 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp @@ -41,6 +41,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include +#include #include "plNetAddress.h" #include "pnNetCommon.h" diff --git a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp index bc1d701879..ab3f48bd4c 100644 --- a/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeDescription/plAgeDescription.cpp @@ -51,7 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include #include - +#include const uint32_t plAgePage::kInvalidSeqSuffix = (uint32_t)-1; diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp index b1b0855d64..1b92e67cfe 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeLoader/plResPatcher.cpp @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsResMgr.h" #include "plgDispatch.h" +#include + #include "plAgeLoader.h" #include "plFile/plEncryptedStream.h" #include "plFile/plStreamSource.h" diff --git a/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp b/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp index b334a9f3a8..ecd9290285 100644 --- a/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp +++ b/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.cpp @@ -181,6 +181,11 @@ void plZlibStream::FastFwd() hsAssert(0, "FastFwd not supported"); } +void plZlibStream::Truncate() +{ + hsAssert(false, "Truncate not supported"); +} + uint32_t plZlibStream::GetEOF() { hsAssert(0, "GetEOF not supported"); diff --git a/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h b/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h index 0b65eee25e..8ded7cc5be 100644 --- a/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h +++ b/Sources/Plasma/PubUtilLib/plCompression/plZlibStream.h @@ -79,6 +79,7 @@ class plZlibStream : public hsStream void Skip(uint32_t deltaByteCount) override; void Rewind() override; void FastFwd() override; + void Truncate() override; uint32_t GetEOF() override; }; diff --git a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp index 2826b5cc5e..cdba2c60da 100644 --- a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp +++ b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.cpp @@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include #include +#include const ST::string& plConfigInfo::GlobalSection() { diff --git a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h index 6688a5f5e9..7f289dee07 100644 --- a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h +++ b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfo.h @@ -43,11 +43,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define plConfigInfo_h_inc #include "plKeysAndValues.h" -#include - -///////////////////////////////////////////////// -namespace ST { class string; } +#include +#include typedef std::vector plStringList; diff --git a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfoLogging.cpp b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfoLogging.cpp index 4666ced4aa..591d518f88 100644 --- a/Sources/Plasma/PubUtilLib/plContainer/plConfigInfoLogging.cpp +++ b/Sources/Plasma/PubUtilLib/plContainer/plConfigInfoLogging.cpp @@ -41,6 +41,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "plConfigInfo.h" +#include + plConfigInfoLogging::plConfigInfoLogging() { } diff --git a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp index 708e23ce43..fdba009b17 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.cpp @@ -41,8 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "plEncryptedStream.h" -#include "hsSTLStream.h" - #include #include #include @@ -147,7 +145,7 @@ bool plEncryptedStream::Open(const plFileName& name, const char* mode) } else if (strcmp(mode, "wb") == 0) { - fRAMStream = new hsVectorStream; + fRAMStream = new hsRAMStream; fWriteFileName = name; fPosition = 0; @@ -198,7 +196,6 @@ uint32_t plEncryptedStream::IRead(uint32_t bytes, void* buffer) if (!fRef) return 0; int numItems = (int)(::fread(buffer, 1 /*size*/, bytes /*count*/, fRef)); - fBytesRead += numItems; fPosition += numItems; if ((unsigned)numItems < bytes) { if (feof(fRef)) { @@ -216,7 +213,7 @@ uint32_t plEncryptedStream::IRead(uint32_t bytes, void* buffer) void plEncryptedStream::IBufferFile() { - fRAMStream = new hsVectorStream; + fRAMStream = new hsRAMStream; char buf[1024]; while (!AtEnd()) { @@ -248,7 +245,6 @@ void plEncryptedStream::Skip(uint32_t delta) } else if (fRef) { - fBytesRead += delta; fPosition += delta; fseek(fRef, delta, SEEK_CUR); } @@ -263,7 +259,6 @@ void plEncryptedStream::Rewind() } else if (fRef) { - fBytesRead = 0; fPosition = 0; fseek(fRef, kFileStartOffset, SEEK_SET); } @@ -279,8 +274,18 @@ void plEncryptedStream::FastFwd() else if (fRef) { fseek(fRef, kFileStartOffset+fActualFileSize, SEEK_SET); - fBytesRead = fPosition = ftell(fRef); + fPosition = ftell(fRef); + } +} + +void plEncryptedStream::Truncate() +{ + if (fOpenMode != kOpenWrite) { + hsAssert(false, "Trying to write to a read stream"); + return; } + + return fRAMStream->Truncate(); } uint32_t plEncryptedStream::GetEOF() diff --git a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h index 1ace5c2f8d..a978c1a80f 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h +++ b/Sources/Plasma/PubUtilLib/plFile/plEncryptedStream.h @@ -91,6 +91,7 @@ class plEncryptedStream : public hsStream void Skip(uint32_t deltaByteCount) override; void Rewind() override; void FastFwd() override; + void Truncate() override; uint32_t GetEOF() override; uint32_t GetActualFileSize() const { return fActualFileSize;} diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp index cd568ced7f..7efec02bc0 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.cpp @@ -45,8 +45,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plSecureStream.h" #include "hsWindows.h" -#include "hsSTLStream.h" - #if !HS_BUILD_FOR_WIN32 #include #define INVALID_HANDLE_VALUE nullptr @@ -219,7 +217,7 @@ bool plSecureStream::Open(const plFileName& name, const char* mode) } else if (strcmp(mode, "wb") == 0) { - fRAMStream = new hsVectorStream; + fRAMStream = new hsRAMStream; fWriteFileName = name; fPosition = 0; @@ -313,7 +311,6 @@ uint32_t plSecureStream::IRead(uint32_t bytes, void* buffer) numItems = fread(buffer, bytes, 1, fRef); bool success = numItems != 0; #endif - fBytesRead += numItems; fPosition += numItems; if ((unsigned)numItems < bytes) { @@ -338,7 +335,7 @@ uint32_t plSecureStream::IRead(uint32_t bytes, void* buffer) void plSecureStream::IBufferFile() { - fRAMStream = new hsVectorStream; + fRAMStream = new hsRAMStream; char buf[1024]; while (!AtEnd()) { @@ -374,7 +371,6 @@ void plSecureStream::Skip(uint32_t delta) } else if (fRef != INVALID_HANDLE_VALUE) { - fBytesRead += delta; fPosition += delta; #if HS_BUILD_FOR_WIN32 SetFilePointer(fRef, delta, nullptr, FILE_CURRENT); @@ -393,7 +389,6 @@ void plSecureStream::Rewind() } else if (fRef != INVALID_HANDLE_VALUE) { - fBytesRead = 0; fPosition = 0; #if HS_BUILD_FOR_WIN32 SetFilePointer(fRef, kFileStartOffset, nullptr, FILE_BEGIN); @@ -413,13 +408,23 @@ void plSecureStream::FastFwd() else if (fRef != INVALID_HANDLE_VALUE) { #if HS_BUILD_FOR_WIN32 - fBytesRead = fPosition = SetFilePointer(fRef, kFileStartOffset + fActualFileSize, nullptr, FILE_BEGIN); + fPosition = SetFilePointer(fRef, kFileStartOffset + fActualFileSize, nullptr, FILE_BEGIN); #elif HS_BUILD_FOR_UNIX - fBytesRead = fPosition = fseek(fRef, 0, SEEK_END); + fPosition = fseek(fRef, 0, SEEK_END); #endif } } +void plSecureStream::Truncate() +{ + if (fOpenMode != kOpenWrite) { + hsAssert(false, "Trying to write to a read stream"); + return; + } + + return fRAMStream->Truncate(); +} + uint32_t plSecureStream::GetEOF() { return fActualFileSize; diff --git a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h index 88f79b8619..c568a4ec6d 100644 --- a/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h +++ b/Sources/Plasma/PubUtilLib/plFile/plSecureStream.h @@ -103,6 +103,7 @@ class plSecureStream: public hsStream void Skip(uint32_t deltaByteCount) override; void Rewind() override; void FastFwd() override; + void Truncate() override; uint32_t GetEOF() override; uint32_t GetActualFileSize() const {return fActualFileSize;} diff --git a/Sources/Plasma/PubUtilLib/plGImage/plMipmap.cpp b/Sources/Plasma/PubUtilLib/plGImage/plMipmap.cpp index 579dbe954b..21536f363a 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plMipmap.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plMipmap.cpp @@ -561,12 +561,12 @@ void plMipmap::IWriteJPEGImage( hsStream *stream ) hsNullStream *nullStream = new hsNullStream(); IWriteRLEImage(nullStream,this); - if (nullStream->GetBytesWritten() < 5120) // we use RLE if it can get the image size under 5k, otherwise we use JPEG + if (nullStream->GetPosition() < 5120) // we use RLE if it can get the image size under 5k, otherwise we use JPEG flags |= kColorDataRLE; delete nullStream; nullStream = new hsNullStream(); IWriteRLEImage(nullStream,alpha); - if (nullStream->GetBytesWritten() < 5120) + if (nullStream->GetPosition() < 5120) flags |= kAlphaDataRLE; delete nullStream; stream->WriteByte(flags); diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp b/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp index 18eee1a2e4..3ad3560935 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp @@ -275,7 +275,7 @@ void plCreatableListHelper::Write( hsStream* s, hsResMgr* mgr ) } } - ram.Truncate(); + ram.Reset(); ram.WriteByte(fFlags); ram.WriteLE32(bufSz); diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMsgHelpers.cpp b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMsgHelpers.cpp index 8e5eab7af6..9e50842cc1 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMsgHelpers.cpp +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMsgHelpers.cpp @@ -240,7 +240,7 @@ void plNetMsgStreamHelper::IAllocStream(uint32_t len) fStreamBuf = new uint8_t[len]; } -void plNetMsgStreamHelper::CopyStream(hsStream* ssStream) +void plNetMsgStreamHelper::CopyStream(hsRAMStream* ssStream) { uint32_t len=ssStream->GetEOF(); IAllocStream(len); diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMsgHelpers.h b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMsgHelpers.h index 6f0f4b830a..f3970ab976 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMsgHelpers.h +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMsgHelpers.h @@ -59,6 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetCommon/plClientGuid.h" class plKey; +class hsRAMStream; class hsStream; class hsStreamable; @@ -157,7 +158,7 @@ class plNetMsgStreamHelper : public plCreatable // copiers void CopyFrom(const plNetMsgStreamHelper* other); - void CopyStream(hsStream* ssStream); // copies to fStream + void CopyStream(hsRAMStream* ssStream); // copies to fStream void CopyStream(int32_t len, const void* buf); // copies to fStream // setters diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp b/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp index 35caa607d7..a244f8e1c6 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp +++ b/Sources/Plasma/PubUtilLib/plPhysX/plGenericPhysical.cpp @@ -48,7 +48,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plProfile.h" #include "hsQuat.h" #include "hsResMgr.h" -#include "hsSTLStream.h" #include "hsTimer.h" #include "pnMessage/plCorrectionMsg.h" diff --git a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.h b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.h index cfdeb4bd45..9ae4312c51 100644 --- a/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.h +++ b/Sources/Plasma/PubUtilLib/plPhysX/plPXPhysical.h @@ -63,11 +63,11 @@ class plPhysicalProxy; struct hsPlane3; struct hsPoint3; class hsQuat; +class hsRAMStream; class plPhysicalSndGroup; class plSceneObject; class plSDLModifier; class plSimulationMsg; -class hsVectorStream; namespace physx { @@ -106,7 +106,7 @@ class PhysRecipe hsPoint3 bDimensions; hsPoint3 bOffset; - std::unique_ptr meshStream; + std::unique_ptr meshStream; PhysRecipe(); ~PhysRecipe(); diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp index 795fbf2d24..2005765758 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -46,7 +46,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plResManagerHelper.h" #include "plResMgrSettings.h" -#include "hsSTLStream.h" #include "hsTimer.h" #include "plTimerCallbackManager.h" diff --git a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp index 310c13ed65..a86694f62b 100644 --- a/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp +++ b/Sources/Plasma/PubUtilLib/plStatGather/plProfileManagerFull.cpp @@ -45,6 +45,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsStream.h" +#include + #include "plPipeline/plDebugText.h" #include "plPipeline/plPlates.h" #include "plUnifiedTime/plUnifiedTime.h" diff --git a/Sources/Plasma/PubUtilLib/plVault/Pch.h b/Sources/Plasma/PubUtilLib/plVault/Pch.h index 0bf0e52ec3..7ef02ffad5 100644 --- a/Sources/Plasma/PubUtilLib/plVault/Pch.h +++ b/Sources/Plasma/PubUtilLib/plVault/Pch.h @@ -63,7 +63,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include "hsGeometry3.h" -#include "hsSTLStream.h" #include "hsStringTokenizer.h" #include "hsTimer.h" diff --git a/Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp b/Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp index c68c0ea814..1f5cbcfdbd 100644 --- a/Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp +++ b/Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp @@ -456,7 +456,7 @@ void VaultMarkerGameNode::GetMarkerData(std::vector& data) const //============================================================================ void VaultMarkerGameNode::SetMarkerData(const std::vector& data) { - hsVectorStream stream; + hsRAMStream stream; stream.WriteLE32((uint32_t)data.size()); for (const VaultMarker& marker : data) { stream.WriteLE32(marker.id); diff --git a/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp b/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp index 0860c535e7..a26c8f2190 100644 --- a/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp +++ b/Sources/Tools/MaxComponent/plMultistageBehComponent.cpp @@ -489,8 +489,11 @@ class MaxStream : public hsStream // Don't support any of this bool Open(const plFileName &, const char * = "rb") override { hsAssert(0, "Not supported"); return false; } bool Close() override { hsAssert(0, "Not supported"); return false; } + bool AtEnd() override { hsAssert(false, "Not supported"); return false; } void Skip(uint32_t deltaByteCount) override { hsAssert(0, "Not supported"); } void Rewind() override { hsAssert(0, "Not supported"); } + void FastFwd() override { hsAssert(false, "Not supported"); } + void Truncate() override { hsAssert(false, "Not supported"); } uint32_t GetEOF() override { return (uint32_t)fLoad->CurChunkLength(); } diff --git a/Sources/Tools/MaxExport/plExportDlg.cpp b/Sources/Tools/MaxExport/plExportDlg.cpp index 2ac68eee04..36dc62390d 100644 --- a/Sources/Tools/MaxExport/plExportDlg.cpp +++ b/Sources/Tools/MaxExport/plExportDlg.cpp @@ -46,7 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "MaxMain/MaxAPI.h" #include -#include +#include #include #include "plExportDlg.h" @@ -413,7 +413,7 @@ static bool AutoExportDir(const plFileName& inputDir, const plFileName& outputDi hsUNIXStream log; if (log.Open(outputLog, "ab")) { - log.WriteFmt("{}\r\n", iter->GetFileName()); + log.WriteString(ST::format("{}\r\n", iter->GetFileName())); log.Close(); } diff --git a/Sources/Tools/MaxMain/Pch.h b/Sources/Tools/MaxMain/Pch.h index aa7e67d680..e3c9a7c3fc 100644 --- a/Sources/Tools/MaxMain/Pch.h +++ b/Sources/Tools/MaxMain/Pch.h @@ -66,7 +66,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plLoadMask.h" #include "hsMatrix44.h" #include "plRenderLevel.h" -#include "hsSTLStream.h" #include "hsStream.h" #include "hsStringTokenizer.h" #include "plFileSystem.h" diff --git a/Sources/Tools/MaxMain/plMaxNode.cpp b/Sources/Tools/MaxMain/plMaxNode.cpp index 5f9b2e5c95..0d25f7af2b 100644 --- a/Sources/Tools/MaxMain/plMaxNode.cpp +++ b/Sources/Tools/MaxMain/plMaxNode.cpp @@ -47,7 +47,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsFastMath.h" #include "pnKeyedObject/plKey.h" #include "plRenderLevel.h" -#include "hsSTLStream.h" #include "plMaxNode.h" #include "plMaxNodeData.h" @@ -708,7 +707,7 @@ bool plMaxNode::MakePhysical(plErrorMsg *pErrMsg, plConvertSettings *settings) case plSimDefs::kProxyBounds: case plSimDefs::kExplicitBounds: { - recipe.meshStream = std::make_unique(); + recipe.meshStream = std::make_unique(); plPXCooking::WriteTriMesh(recipe.meshStream.get(), mesh.fNumFaces, mesh.fFaces, mesh.fNumVerts, mesh.fVerts); recipe.meshStream->Rewind(); @@ -741,7 +740,7 @@ bool plMaxNode::MakePhysical(plErrorMsg *pErrMsg, plConvertSettings *settings) break; case plSimDefs::kHullBounds: { - recipe.meshStream = std::make_unique(); + recipe.meshStream = std::make_unique(); plPXCooking::WriteConvexHull(recipe.meshStream.get(), mesh.fNumVerts, mesh.fVerts); recipe.meshStream->Rewind();