mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Fix temporary buffer for scripting conversions.
This commit is contained in:
parent
478a04bea8
commit
c16b88d709
4 changed files with 32 additions and 7 deletions
|
|
@ -633,6 +633,7 @@ bool StandardMainLoop::doMainLoop()
|
||||||
|
|
||||||
ThreadPool::processMainThreadWorkItems();
|
ThreadPool::processMainThreadWorkItems();
|
||||||
Sampler::endFrame();
|
Sampler::endFrame();
|
||||||
|
ConsoleValue::resetConversionBuffer();
|
||||||
PROFILE_END_NAMED(MainLoop);
|
PROFILE_END_NAMED(MainLoop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,21 +46,29 @@
|
||||||
extern StringStack STR;
|
extern StringStack STR;
|
||||||
extern ConsoleValueStack<4096> gCallStack;
|
extern ConsoleValueStack<4096> gCallStack;
|
||||||
|
|
||||||
char ConsoleValue::sConversionBuffer[ConversionBufferSize];
|
Vector<ConsoleValue::ConversionBuffer> ConsoleValue::sConversionBuffer;
|
||||||
|
|
||||||
void ConsoleValue::init()
|
void ConsoleValue::init()
|
||||||
{
|
{
|
||||||
dMemset(sConversionBuffer, '\0', ConversionBufferSize);
|
sConversionBuffer.reserve(8192);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleValue::resetConversionBuffer()
|
||||||
|
{
|
||||||
|
sConversionBuffer.resetAndTreatAsScratchBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
char* ConsoleValue::convertToBuffer() const
|
char* ConsoleValue::convertToBuffer() const
|
||||||
{
|
{
|
||||||
|
ConversionBuffer conversion;
|
||||||
|
|
||||||
if (type == ConsoleValueType::cvFloat)
|
if (type == ConsoleValueType::cvFloat)
|
||||||
dSprintf(sConversionBuffer, ConversionBufferSize, "%.9g", f);
|
dSprintf(conversion.buffer, ConversionBufferStride, "%.9g", f);
|
||||||
else
|
else
|
||||||
dSprintf(sConversionBuffer, ConversionBufferSize, "%lld", i);
|
dSprintf(conversion.buffer, ConversionBufferStride, "%lld", i);
|
||||||
|
|
||||||
return sConversionBuffer;
|
sConversionBuffer.push_back(std::move(conversion));
|
||||||
|
return sConversionBuffer.last().buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* ConsoleValue::getConsoleData() const
|
const char* ConsoleValue::getConsoleData() const
|
||||||
|
|
|
||||||
|
|
@ -148,10 +148,15 @@ class ConsoleValue
|
||||||
|
|
||||||
enum Constants
|
enum Constants
|
||||||
{
|
{
|
||||||
ConversionBufferSize = 32
|
ConversionBufferStride = 32
|
||||||
};
|
};
|
||||||
|
|
||||||
static char sConversionBuffer[ConversionBufferSize];
|
struct ConversionBuffer
|
||||||
|
{
|
||||||
|
char buffer[ConversionBufferStride];
|
||||||
|
};
|
||||||
|
|
||||||
|
static Vector<ConversionBuffer> sConversionBuffer;
|
||||||
|
|
||||||
char* convertToBuffer() const;
|
char* convertToBuffer() const;
|
||||||
|
|
||||||
|
|
@ -387,6 +392,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
|
static void resetConversionBuffer();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Transparently converts ConsoleValue[] to const char**
|
// Transparently converts ConsoleValue[] to const char**
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,7 @@ class Vector
|
||||||
void erase(U32 index, U32 count);
|
void erase(U32 index, U32 count);
|
||||||
void erase_fast(iterator);
|
void erase_fast(iterator);
|
||||||
void clear();
|
void clear();
|
||||||
|
void resetAndTreatAsScratchBuffer();
|
||||||
void compact();
|
void compact();
|
||||||
void sort(compare_func f);
|
void sort(compare_func f);
|
||||||
void fill( const T& value );
|
void fill( const T& value );
|
||||||
|
|
@ -529,6 +530,15 @@ template<class T> inline void Vector<T>::clear()
|
||||||
mElementCount = 0;
|
mElementCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This method sets the vector as its 0 and will overwrite memory on subsequent usage.
|
||||||
|
/// Note that the current memory in use is never freed or deallocated, so only use this if the vector
|
||||||
|
/// is being used as a scratch buffer only.
|
||||||
|
template<class T> inline
|
||||||
|
void Vector<T>::resetAndTreatAsScratchBuffer()
|
||||||
|
{
|
||||||
|
mElementCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T> inline void Vector<T>::compact()
|
template<class T> inline void Vector<T>::compact()
|
||||||
{
|
{
|
||||||
resize(mElementCount);
|
resize(mElementCount);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue