mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
indent
This commit is contained in:
parent
2763cfbd46
commit
294ca5ffd2
10 changed files with 1776 additions and 1840 deletions
|
@ -25,9 +25,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#ifndef __CLASS_H__
|
||||
#define __CLASS_H__
|
||||
|
||||
#include "q_shared.h"
|
||||
#include "container.h"
|
||||
#include "con_set.h"
|
||||
#include "container.h"
|
||||
#include "q_shared.h"
|
||||
#include "str.h"
|
||||
|
||||
#include "const_str.h"
|
||||
|
@ -41,12 +41,9 @@ class Event;
|
|||
#ifndef NO_SCRIPTENGINE
|
||||
|
||||
#define CLASS_DECLARATION(parentclass, classname, classid) \
|
||||
ClassDef classname::ClassInfo \
|
||||
( \
|
||||
#classname, classid, #parentclass, \
|
||||
ClassDef classname::ClassInfo(#classname, classid, #parentclass, \
|
||||
(ResponseDef<Class>*)classname::Responses, \
|
||||
classname::_newInstance, sizeof( classname ) \
|
||||
); \
|
||||
classname::_newInstance, sizeof(classname)); \
|
||||
void* classname::_newInstance(void) \
|
||||
{ \
|
||||
return new classname; \
|
||||
|
@ -103,12 +100,9 @@ class Event;
|
|||
#else
|
||||
|
||||
#define CLASS_DECLARATION(parentclass, classname, classid) \
|
||||
ClassDef classname::ClassInfo \
|
||||
( \
|
||||
#classname, classid, #parentclass, \
|
||||
ClassDef classname::ClassInfo(#classname, classid, #parentclass, \
|
||||
(ResponseDef<Class>*)classname::Responses, \
|
||||
classname::_newInstance, sizeof( classname ) \
|
||||
); \
|
||||
classname::_newInstance, sizeof(classname)); \
|
||||
void* classname::_newInstance(void) \
|
||||
{ \
|
||||
return new classname; \
|
||||
|
@ -194,11 +188,15 @@ public:
|
|||
#endif
|
||||
|
||||
/* Create-a-class function */
|
||||
ClassDef( const char *classname, const char *classID, const char *superclass, ResponseDef<Class> *responses,
|
||||
ClassDef(const char* classname, const char* classID, const char* superclass,
|
||||
ResponseDef<Class>* responses, void* (*newInstance)(void),
|
||||
int classSize);
|
||||
void CreateInternal(const char* classname, const char* classID,
|
||||
const char* superclass, ResponseDef<Class>* responses,
|
||||
void* (*newInstance)(void), int classSize);
|
||||
void CreateInternal( const char *classname, const char *classID, const char *superclass, ResponseDef<Class> *responses,
|
||||
void *( *newInstance )( void ), int classSize );
|
||||
void CreateInternalWin( const char *classname, const char *classID, const char *superclass, ResponseDef<Class> *responses,
|
||||
void CreateInternalWin(const char* classname, const char* classID,
|
||||
const char* superclass,
|
||||
ResponseDef<Class>* responses,
|
||||
void* (*newInstance)(void), int classSize);
|
||||
|
||||
EventDef* GetDef(int eventnum);
|
||||
|
|
|
@ -47,15 +47,10 @@ typedef struct configSection_s {
|
|||
Container<configKey_t*> key;
|
||||
} configSection_t;
|
||||
|
||||
enum {
|
||||
LINE_EMPTY,
|
||||
LINE_COMMENT,
|
||||
LINE_SECTION,
|
||||
LINE_VALUE,
|
||||
LINE_ERROR
|
||||
};
|
||||
enum { LINE_EMPTY, LINE_COMMENT, LINE_SECTION, LINE_VALUE, LINE_ERROR };
|
||||
|
||||
class Configurator : public Class {
|
||||
class Configurator : public Class
|
||||
{
|
||||
private:
|
||||
str m_filename;
|
||||
bool m_bNoWrite;
|
||||
|
@ -66,12 +61,14 @@ private:
|
|||
|
||||
private:
|
||||
size_t GetLine(char* dest, const char* data, size_t size);
|
||||
str GetValue( const char *section, const char *key, str defaultValue, int index = -1 );
|
||||
str GetValue(const char* section, const char* key, str defaultValue,
|
||||
int index = -1);
|
||||
configKey_t* GetKey(const char* section, const char* key, int index = -1);
|
||||
|
||||
int CutLine(char* data);
|
||||
bool SetupLine(char* line, int& lineno, size_t& len, size_t& last);
|
||||
bool FindData( int type, const char *section, const char *key, size_t *offset, const char *data, size_t size );
|
||||
bool FindData(int type, const char* section, const char* key,
|
||||
size_t* offset, const char* data, size_t size);
|
||||
void ParseData(const char* data, size_t size);
|
||||
void WriteData(char** data, size_t* size);
|
||||
void WriteData2(char** data, size_t* size);
|
||||
|
@ -81,7 +78,8 @@ private:
|
|||
configSection_t* FindSection(const char* section);
|
||||
int GetKeyArray(char* key);
|
||||
int GetKeyArray(str& key);
|
||||
configKey_t *CreateKey( configSection_t *section, const char *key, unsigned int *index );
|
||||
configKey_t* CreateKey(configSection_t* section, const char* key,
|
||||
unsigned int* index);
|
||||
configKey_t* FindKey(configSection_t* section, const char* key);
|
||||
void RemoveSection(configSection_t* section);
|
||||
void RemoveKey(configSection_t* section, configKey_t* key);
|
||||
|
@ -97,12 +95,18 @@ public:
|
|||
void Close();
|
||||
void SetWrite(bool bWrite);
|
||||
|
||||
str GetString( const char *section, const char *key, str defaultValue, int index = -1 );
|
||||
int GetInteger( const char *section, const char *key, int defaultValue, int index = -1 );
|
||||
float GetFloat( const char *section, const char *key, float defaultValue, int index = -1 );
|
||||
void SetString( const char *section, const char *key, str value, int index = -1 );
|
||||
void SetInteger( const char *section, const char *key, int value, int index = -1 );
|
||||
void SetFloat( const char *section, const char *key, float value, int index = -1 );
|
||||
str GetString(const char* section, const char* key, str defaultValue,
|
||||
int index = -1);
|
||||
int GetInteger(const char* section, const char* key, int defaultValue,
|
||||
int index = -1);
|
||||
float GetFloat(const char* section, const char* key, float defaultValue,
|
||||
int index = -1);
|
||||
void SetString(const char* section, const char* key, str value,
|
||||
int index = -1);
|
||||
void SetInteger(const char* section, const char* key, int value,
|
||||
int index = -1);
|
||||
void SetFloat(const char* section, const char* key, float value,
|
||||
int index = -1);
|
||||
};
|
||||
|
||||
void test_config(void);
|
||||
|
|
|
@ -38,7 +38,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define CONTAINER_Error( id, text ) glbprintf( text ); assert( 0 );
|
||||
#define CONTAINER_Error(id, text) \
|
||||
glbprintf(text); \
|
||||
assert(0);
|
||||
#else
|
||||
#define CONTAINER_Error(id, text) throw(text) // gi.Error
|
||||
#endif
|
||||
|
@ -115,8 +117,9 @@ Container<Type>::~Container()
|
|||
template<class Type>
|
||||
int Container<Type>::AddObject(const Type& obj)
|
||||
{
|
||||
if ( !objlist )
|
||||
if (!objlist) {
|
||||
Resize(10);
|
||||
}
|
||||
|
||||
if (numobjects >= maxobjects) {
|
||||
Resize(numobjects * 2);
|
||||
|
@ -145,11 +148,13 @@ int Container<Type>::AddUniqueObject( const Type& obj )
|
|||
template<class Type>
|
||||
void Container<Type>::AddObjectAt(int index, const Type& obj)
|
||||
{
|
||||
if ( index > maxobjects )
|
||||
if (index > maxobjects) {
|
||||
Resize(index);
|
||||
}
|
||||
|
||||
if ( index > numobjects )
|
||||
if (index > numobjects) {
|
||||
numobjects = index;
|
||||
}
|
||||
|
||||
SetObjectAt(index, obj);
|
||||
}
|
||||
|
@ -158,7 +163,9 @@ template< class Type >
|
|||
Type* Container<Type>::AddressOfObjectAt(int index)
|
||||
{
|
||||
if (index > maxobjects) {
|
||||
CONTAINER_Error( ERR_DROP, "Container::AddressOfObjectAt : index is greater than maxobjects" );
|
||||
CONTAINER_Error(
|
||||
ERR_DROP,
|
||||
"Container::AddressOfObjectAt : index is greater than maxobjects");
|
||||
}
|
||||
|
||||
if (index > numobjects) {
|
||||
|
@ -177,12 +184,10 @@ void Container<Type>::Archive( Archiver &arc )
|
|||
template<class Type>
|
||||
void Container<Type>::ClearObjectList(void)
|
||||
{
|
||||
if ( objlist && numobjects )
|
||||
{
|
||||
if (objlist && numobjects) {
|
||||
delete[] objlist;
|
||||
|
||||
if ( maxobjects == 0 )
|
||||
{
|
||||
if (maxobjects == 0) {
|
||||
objlist = NULL;
|
||||
return;
|
||||
}
|
||||
|
@ -202,8 +207,7 @@ void Container<Type>::Fix( void )
|
|||
Type* newlist = new Type[numobjects];
|
||||
int j = 0;
|
||||
|
||||
for( int i = 0; i < numobjects; i++ )
|
||||
{
|
||||
for (int i = 0; i < numobjects; i++) {
|
||||
if (objlist[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
@ -243,10 +247,8 @@ int Container<Type>::IndexOfObject( const Type& obj )
|
|||
return 0;
|
||||
}
|
||||
|
||||
for ( i = 0; i < numobjects; i++ )
|
||||
{
|
||||
if ( objlist[i] == obj )
|
||||
{
|
||||
for (i = 0; i < numobjects; i++) {
|
||||
if (objlist[i] == obj) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
@ -257,28 +259,24 @@ int Container<Type>::IndexOfObject( const Type& obj )
|
|||
template<class Type>
|
||||
void Container<Type>::InsertObjectAt(int index, const Type& obj)
|
||||
{
|
||||
if ( ( index <= 0 ) || ( index > numobjects + 1 ) )
|
||||
{
|
||||
CONTAINER_Error( ERR_DROP, "Container::InsertObjectAt : index out of range" );
|
||||
if ((index <= 0) || (index > numobjects + 1)) {
|
||||
CONTAINER_Error(ERR_DROP,
|
||||
"Container::InsertObjectAt : index out of range");
|
||||
return;
|
||||
}
|
||||
|
||||
numobjects++;
|
||||
int arrayIndex = index - 1;
|
||||
|
||||
if ( numobjects > maxobjects )
|
||||
{
|
||||
if (numobjects > maxobjects) {
|
||||
maxobjects = numobjects;
|
||||
if (!objlist) {
|
||||
objlist = new Type[maxobjects];
|
||||
objlist[arrayIndex] = obj;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Type* temp = objlist;
|
||||
if ( maxobjects < numobjects )
|
||||
{
|
||||
if (maxobjects < numobjects) {
|
||||
maxobjects = numobjects;
|
||||
}
|
||||
|
||||
|
@ -296,9 +294,7 @@ void Container<Type>::InsertObjectAt( int index, const Type& obj )
|
|||
|
||||
delete[] temp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
for (int i = numobjects - 1; i > arrayIndex; i--) {
|
||||
objlist[i] = objlist[i - 1];
|
||||
}
|
||||
|
@ -343,18 +339,21 @@ void Container<Type>::RemoveObjectAt( int index )
|
|||
{
|
||||
int i;
|
||||
|
||||
if ( !objlist )
|
||||
if (!objlist) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( index <= 0 ) || ( index > numobjects ) )
|
||||
if ((index <= 0) || (index > numobjects)) {
|
||||
return;
|
||||
}
|
||||
|
||||
i = index - 1;
|
||||
numobjects--;
|
||||
|
||||
for ( i = index - 1; i < numobjects; i++ )
|
||||
for (i = index - 1; i < numobjects; i++) {
|
||||
objlist[i] = objlist[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
void Container<Type>::RemoveObject(const Type& obj)
|
||||
|
@ -364,8 +363,7 @@ void Container<Type>::RemoveObject( const Type& obj )
|
|||
index = IndexOfObject(obj);
|
||||
|
||||
assert(index);
|
||||
if ( !index )
|
||||
{
|
||||
if (!index) {
|
||||
CONTAINER_WDPrintf("Container::RemoveObject : Object not in list\n");
|
||||
return;
|
||||
}
|
||||
|
@ -387,19 +385,15 @@ void Container<Type>::Resize( int maxelements )
|
|||
Type* temp;
|
||||
int i;
|
||||
|
||||
if ( maxelements <= 0 )
|
||||
{
|
||||
if (maxelements <= 0) {
|
||||
FreeObjectList();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !objlist )
|
||||
{
|
||||
if (!objlist) {
|
||||
maxobjects = maxelements;
|
||||
objlist = new Type[maxobjects];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
temp = objlist;
|
||||
|
||||
maxobjects = maxelements;
|
||||
|
@ -421,11 +415,13 @@ void Container<Type>::Resize( int maxelements )
|
|||
template<class Type>
|
||||
void Container<Type>::SetObjectAt(int index, const Type& obj)
|
||||
{
|
||||
if ( !objlist )
|
||||
if (!objlist) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((index <= 0) || (index > numobjects)) {
|
||||
CONTAINER_Error( ERR_DROP, "Container::SetObjectAt : index out of range" );
|
||||
CONTAINER_Error(ERR_DROP,
|
||||
"Container::SetObjectAt : index out of range");
|
||||
}
|
||||
|
||||
objlist[index - 1] = obj;
|
||||
|
|
|
@ -27,7 +27,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include "container.h"
|
||||
|
||||
template<class Type>
|
||||
class ContainerClass : public Class {
|
||||
class ContainerClass : public Class
|
||||
{
|
||||
Container<Type> value;
|
||||
|
||||
public:
|
||||
|
@ -37,14 +38,23 @@ public:
|
|||
|
||||
int AddObject(const Type& obj) { return value.AddObject(obj); }
|
||||
int AddUniqueObject(const Type& obj) { return value.AddUniqueObject(obj); }
|
||||
void AddObjectAt( int index, const Type& obj ) { return value.AddObjectAt( index, obj ); }
|
||||
Type *AddressOfObjectAt( int index ) { return value.AddressOfObjectAt( index ); }
|
||||
void AddObjectAt(int index, const Type& obj)
|
||||
{
|
||||
return value.AddObjectAt(index, obj);
|
||||
}
|
||||
Type* AddressOfObjectAt(int index)
|
||||
{
|
||||
return value.AddressOfObjectAt(index);
|
||||
}
|
||||
|
||||
void ClearObjectList(void) { return value.ClearObjectList(); }
|
||||
void Fix(void) { return value.Fix(); }
|
||||
void FreeObjectList(void) { return value.FreeObjectList(); }
|
||||
int IndexOfObject(const Type& obj) { return value.IndexOfObject(obj); }
|
||||
void InsertObjectAt( int index, const Type& obj ) { return value.InsertObjectAt( index, obj ); }
|
||||
void InsertObjectAt(int index, const Type& obj)
|
||||
{
|
||||
return value.InsertObjectAt(index, obj);
|
||||
}
|
||||
int NumObjects(void) const { return value.NumObjects(); }
|
||||
Type& ObjectAt(const size_t index) const { return value.ObjectAt(index); }
|
||||
bool ObjectInList(const Type& obj) { return value.ObjectInList(obj); }
|
||||
|
@ -52,8 +62,17 @@ public:
|
|||
void RemoveObject(const Type& obj) { return value.RemoveObject(obj); }
|
||||
void Reset(void) { return value.Reset(); }
|
||||
void Resize(int maxelements) { return value.Resize(maxelements); }
|
||||
void SetObjectAt( int index, const Type& obj ) { return value.SetObjectAt( index, obj ); }
|
||||
void Sort( int( *compare )( const void *elem1, const void *elem2 ) ) { return value.Sort( compare ); }
|
||||
void SetObjectAt(int index, const Type& obj)
|
||||
{
|
||||
return value.SetObjectAt(index, obj);
|
||||
}
|
||||
void Sort(int (*compare)(const void* elem1, const void* elem2))
|
||||
{
|
||||
return value.Sort(compare);
|
||||
}
|
||||
Type& operator[](const int index) const { return value[index]; }
|
||||
Container<Type>& operator=( const Container<Type>& container ) { return value = container; }
|
||||
Container<Type>& operator=(const Container<Type>& container)
|
||||
{
|
||||
return value = container;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,28 +26,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#include "g_local.h"
|
||||
|
||||
void *MEM_Alloc( int size )
|
||||
{
|
||||
return gi.Malloc( size );
|
||||
}
|
||||
void* MEM_Alloc(int size) { return gi.Malloc(size); }
|
||||
|
||||
void MEM_Free( void *ptr )
|
||||
{
|
||||
return gi.Free( ptr );
|
||||
}
|
||||
void MEM_Free(void* ptr) { return gi.Free(ptr); }
|
||||
|
||||
#else
|
||||
|
||||
#include "qcommon.h"
|
||||
|
||||
void* MEM_Alloc(int size)
|
||||
{
|
||||
return Z_Malloc(size);
|
||||
}
|
||||
void* MEM_Alloc(int size) { return Z_Malloc(size); }
|
||||
|
||||
void MEM_Free(void* ptr)
|
||||
{
|
||||
return Z_Free(ptr);
|
||||
}
|
||||
void MEM_Free(void* ptr) { return Z_Free(ptr); }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -36,23 +36,19 @@ void MEM_Free( void *ptr );
|
|||
|
||||
static constexpr size_t DefaultBlock = 256;
|
||||
|
||||
enum class alloc_source_e
|
||||
{
|
||||
SourceBlock = 174,
|
||||
SourceMalloc
|
||||
};
|
||||
enum class alloc_source_e { SourceBlock = 174, SourceMalloc };
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
class MEM_BlockAlloc_enum;
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
class block_s {
|
||||
class block_s
|
||||
{
|
||||
private:
|
||||
static constexpr size_t bitsNeeded =
|
||||
blocksize <= 0x80 ? 8 :
|
||||
blocksize <= 0x8000 ? 16 :
|
||||
blocksize <= 0x80000000 ? 32 :
|
||||
64;
|
||||
static constexpr size_t bitsNeeded = blocksize <= 0x80 ? 8
|
||||
: blocksize <= 0x8000 ? 16
|
||||
: blocksize <= 0x80000000 ? 32
|
||||
: 64;
|
||||
|
||||
public:
|
||||
block_s();
|
||||
|
@ -66,10 +62,22 @@ public:
|
|||
template<size_t bits>
|
||||
struct selectType_t;
|
||||
|
||||
template<> struct selectType_t<8> { using type = uint8_t; };
|
||||
template<> struct selectType_t<16> { using type = uint16_t; };
|
||||
template<> struct selectType_t<32> { using type = uint32_t; };
|
||||
template<> struct selectType_t<64> { using type = uint64_t; };
|
||||
template<>
|
||||
struct selectType_t<8> {
|
||||
using type = uint8_t;
|
||||
};
|
||||
template<>
|
||||
struct selectType_t<16> {
|
||||
using type = uint16_t;
|
||||
};
|
||||
template<>
|
||||
struct selectType_t<32> {
|
||||
using type = uint32_t;
|
||||
};
|
||||
template<>
|
||||
struct selectType_t<64> {
|
||||
using type = uint64_t;
|
||||
};
|
||||
|
||||
using offset_t = typename selectType_t<bitsNeeded>::type;
|
||||
|
||||
|
@ -109,8 +117,7 @@ block_s<aclass, blocksize>::block_s()
|
|||
{
|
||||
info_t* header;
|
||||
offset_t curr;
|
||||
for (curr = 0; curr < blocksize - 1; ++curr)
|
||||
{
|
||||
for (curr = 0; curr < blocksize - 1; ++curr) {
|
||||
offset_t next = curr + 1;
|
||||
header = &data[curr];
|
||||
header->source = alloc_source_e::SourceBlock;
|
||||
|
@ -131,21 +138,20 @@ block_s<aclass, blocksize>::block_s()
|
|||
has_used_data = false;
|
||||
}
|
||||
#else
|
||||
: prev_block(nullptr)
|
||||
, next_block(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
: prev_block(nullptr), next_block(nullptr)
|
||||
{}
|
||||
#endif
|
||||
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
template<typename aclass, size_t blocksize>
|
||||
bool block_s<aclass, blocksize>::usedDataAvailable() const {
|
||||
bool block_s<aclass, blocksize>::usedDataAvailable() const
|
||||
{
|
||||
return has_used_data;
|
||||
}
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
bool block_s<aclass, blocksize>::freeDataAvailable() const {
|
||||
bool block_s<aclass, blocksize>::freeDataAvailable() const
|
||||
{
|
||||
return has_free_data;
|
||||
}
|
||||
#endif
|
||||
|
@ -154,6 +160,7 @@ template<typename aclass, size_t blocksize = DefaultBlock>
|
|||
class MEM_BlockAlloc
|
||||
{
|
||||
static_assert(blocksize >= 2, "Minimum 2x class preallocation required!!");
|
||||
|
||||
public:
|
||||
MEM_BlockAlloc();
|
||||
~MEM_BlockAlloc();
|
||||
|
@ -193,10 +200,7 @@ public:
|
|||
aclass* NextElement();
|
||||
aclass* CurrentElement();
|
||||
|
||||
enum blockType_e {
|
||||
used,
|
||||
full
|
||||
};
|
||||
enum blockType_e { used, full };
|
||||
|
||||
private:
|
||||
using block_t = block_s<aclass, blocksize>;
|
||||
|
@ -214,8 +218,7 @@ private:
|
|||
template<typename a, size_t b>
|
||||
MEM_BlockAlloc<a, b>::MEM_BlockAlloc()
|
||||
#if !_DEBUG_MEMBLOCK
|
||||
: m_StartUsedBlock()
|
||||
, m_StartFullBlock()
|
||||
: m_StartUsedBlock(), m_StartFullBlock()
|
||||
{
|
||||
m_FreeBlock = nullptr;
|
||||
m_BlockCount = 0;
|
||||
|
@ -248,37 +251,33 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
block_offset_t free_data;
|
||||
block_offset_t next_data;
|
||||
|
||||
if (m_StartUsedBlock)
|
||||
{
|
||||
if (m_StartUsedBlock) {
|
||||
used_block = m_StartUsedBlock;
|
||||
|
||||
free_data = used_block->free_data;
|
||||
next_data = used_block->next_data[free_data];
|
||||
|
||||
if (next_data == free_data)
|
||||
{
|
||||
// Move the block to the next block list as there is no space available
|
||||
if (next_data == free_data) {
|
||||
// Move the block to the next block list as there is no space
|
||||
// available
|
||||
m_StartUsedBlock = used_block->next_block;
|
||||
|
||||
LL_SafeRemoveRoot(m_StartUsedBlock, used_block, next_block, prev_block);
|
||||
LL_SafeAddFirst(m_StartFullBlock, used_block, next_block, prev_block);
|
||||
LL_SafeRemoveRoot(m_StartUsedBlock, used_block, next_block,
|
||||
prev_block);
|
||||
LL_SafeAddFirst(m_StartFullBlock, used_block, next_block,
|
||||
prev_block);
|
||||
|
||||
used_block->has_free_data = false;
|
||||
return TakeFree(used_block, free_data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_FreeBlock)
|
||||
{
|
||||
} else {
|
||||
if (m_FreeBlock) {
|
||||
// start from the free block
|
||||
used_block = m_FreeBlock;
|
||||
m_FreeBlock = nullptr;
|
||||
free_data = used_block->free_data;
|
||||
next_data = used_block->next_data[free_data];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_BlockCount++;
|
||||
// allocate and construct a new block
|
||||
used_block = new (MEM_Alloc(sizeof(block_t))) block_t();
|
||||
|
@ -297,8 +296,7 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
used_block->free_data = next_data;
|
||||
used_block->has_free_data = true;
|
||||
|
||||
if (!used_block->usedDataAvailable())
|
||||
{
|
||||
if (!used_block->usedDataAvailable()) {
|
||||
used_block->used_data = free_data;
|
||||
used_block->has_used_data = true;
|
||||
used_block->next_data[free_data] = free_data;
|
||||
|
@ -311,7 +309,8 @@ void* MEM_BlockAlloc<a, b>::Alloc()
|
|||
}
|
||||
|
||||
template<typename aclass, size_t blocksize>
|
||||
void* MEM_BlockAlloc<aclass, blocksize>::TakeFree(block_t* block, uintptr_t free_data)
|
||||
void* MEM_BlockAlloc<aclass, blocksize>::TakeFree(block_t* block,
|
||||
uintptr_t free_data)
|
||||
{
|
||||
const block_offset_t used_data = block->used_data;
|
||||
const block_offset_t prev_data = block->prev_data[used_data];
|
||||
|
@ -335,17 +334,19 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
MEM::Free(block);
|
||||
#else
|
||||
// get the header of the pointer
|
||||
typename block_t::info_t* header = reinterpret_cast<typename block_t::info_t*>(static_cast<unsigned char*>(ptr) - block_t::headersize);
|
||||
typename block_t::info_t* header =
|
||||
reinterpret_cast<typename block_t::info_t*>(
|
||||
static_cast<unsigned char*>(ptr) - block_t::headersize);
|
||||
const block_offset_t used_data = header->index;
|
||||
// get the block from the header
|
||||
block_t* const block = (block_t*)((uint8_t*)header - used_data * block_t::datasize - block_t::dataoffset);
|
||||
block_t* const block =
|
||||
(block_t*)((uint8_t*)header - used_data * block_t::datasize -
|
||||
block_t::dataoffset);
|
||||
const block_offset_t next_data = block->next_data[used_data];
|
||||
if (next_data == used_data)
|
||||
{
|
||||
if (next_data == used_data) {
|
||||
LL_SafeRemoveRoot(m_StartUsedBlock, block, next_block, prev_block);
|
||||
|
||||
if (m_FreeBlock)
|
||||
{
|
||||
if (m_FreeBlock) {
|
||||
// deallocate the free block because of another deallocation
|
||||
--m_BlockCount;
|
||||
MEM_Free(m_FreeBlock);
|
||||
|
@ -362,9 +363,7 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
block->prev_data[free_data] = used_data;
|
||||
block->next_data[used_data] = free_data;
|
||||
block->prev_data[used_data] = prev_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
const block_offset_t prev_data = block->prev_data[used_data];
|
||||
|
||||
block->next_data[prev_data] = next_data;
|
||||
|
@ -372,8 +371,7 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
block->used_data = next_data;
|
||||
block->has_used_data = true;
|
||||
|
||||
if (block->freeDataAvailable())
|
||||
{
|
||||
if (block->freeDataAvailable()) {
|
||||
const block_offset_t free_data = block->free_data;
|
||||
const block_offset_t prev_data = block->prev_data[free_data];
|
||||
|
||||
|
@ -384,8 +382,7 @@ void MEM_BlockAlloc<a, b>::Free(void* ptr) noexcept
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_StartFullBlock == block)
|
||||
{
|
||||
if (m_StartFullBlock == block) {
|
||||
m_StartFullBlock = block->next_block;
|
||||
}
|
||||
|
||||
|
@ -406,8 +403,7 @@ void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
|||
block_t* block;
|
||||
#if _DEBUG_MEMBLOCK
|
||||
block_t* next = m_Block.Root();
|
||||
for (block = next; block; block = next)
|
||||
{
|
||||
for (block = next; block; block = next) {
|
||||
next = block->next_block;
|
||||
m_BlockCount--;
|
||||
a* ptr = (a*)block->data;
|
||||
|
@ -416,10 +412,8 @@ void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
|||
}
|
||||
m_Block.Reset();
|
||||
#else
|
||||
while((block = m_StartFullBlock) != nullptr)
|
||||
{
|
||||
if (block->usedDataAvailable())
|
||||
{
|
||||
while ((block = m_StartFullBlock) != nullptr) {
|
||||
if (block->usedDataAvailable()) {
|
||||
a* ptr = (a*)block->data[block->used_data].data;
|
||||
ptr->~a();
|
||||
Free(ptr);
|
||||
|
@ -427,18 +421,15 @@ void MEM_BlockAlloc<a, b>::FreeAll() noexcept
|
|||
}
|
||||
}
|
||||
|
||||
while ((block = m_StartUsedBlock) != nullptr)
|
||||
{
|
||||
if (block->usedDataAvailable())
|
||||
{
|
||||
while ((block = m_StartUsedBlock) != nullptr) {
|
||||
if (block->usedDataAvailable()) {
|
||||
a* ptr = (a*)block->data[block->used_data].data;
|
||||
ptr->~a();
|
||||
Free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_FreeBlock)
|
||||
{
|
||||
if (m_FreeBlock) {
|
||||
m_BlockCount--;
|
||||
MEM_Free(m_FreeBlock);
|
||||
m_FreeBlock = nullptr;
|
||||
|
@ -451,25 +442,21 @@ size_t MEM_BlockAlloc<a, b>::Count(const block_t* list)
|
|||
{
|
||||
int count = 0;
|
||||
#if _DEBUG_MEMBLOCK
|
||||
for (const block_t* block = list; block; block = block->next_block)
|
||||
{
|
||||
for (const block_t* block = list; block; block = block->next_block) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
|
||||
for (const block_t* block = list; block; block = block->next_block)
|
||||
{
|
||||
if (!block->usedDataAvailable())
|
||||
{
|
||||
for (const block_t* block = list; block; block = block->next_block) {
|
||||
if (!block->usedDataAvailable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const block_offset_t used_data = block->used_data;
|
||||
block_offset_t current_used_data = used_data;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
count++;
|
||||
current_used_data = block->next_data[current_used_data];
|
||||
} while (current_used_data != used_data);
|
||||
|
@ -501,7 +488,6 @@ size_t MEM_BlockAlloc<a, b>::BlockMemory()
|
|||
return sizeof(block_s<a, b>);
|
||||
}
|
||||
|
||||
|
||||
template<typename a, size_t b>
|
||||
MEM_BlockAlloc_enum<a, b>::MEM_BlockAlloc_enum(MEM_BlockAlloc<a, b>& owner)
|
||||
{
|
||||
|
@ -516,21 +502,16 @@ template<typename a, size_t b>
|
|||
a* MEM_BlockAlloc_enum<a, b>::NextElement()
|
||||
{
|
||||
#if _DEBUG_MEMBLOCK
|
||||
if (!m_CurrentBlock)
|
||||
{
|
||||
if (!m_CurrentBlock) {
|
||||
m_CurrentBlock = m_Owner->m_Block.Root();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
m_CurrentBlock = m_CurrentBlock->next_block;
|
||||
}
|
||||
return (a*)m_CurrentBlock;
|
||||
#else
|
||||
// search for a valid block type
|
||||
while (!m_CurrentBlock)
|
||||
{
|
||||
switch (m_CurrentBlockType)
|
||||
{
|
||||
while (!m_CurrentBlock) {
|
||||
switch (m_CurrentBlockType) {
|
||||
case blockType_e::used:
|
||||
m_CurrentBlock = m_Owner->m_StartUsedBlock;
|
||||
break;
|
||||
|
@ -544,20 +525,18 @@ a* MEM_BlockAlloc_enum<a, b>::NextElement()
|
|||
reinterpret_cast<uint8_t&>(m_CurrentBlockType)++;
|
||||
|
||||
_label:
|
||||
for (; m_CurrentBlock; m_CurrentBlock = m_CurrentBlock->next_block)
|
||||
{
|
||||
if (m_CurrentBlock->usedDataAvailable())
|
||||
{
|
||||
for (; m_CurrentBlock; m_CurrentBlock = m_CurrentBlock->next_block) {
|
||||
if (m_CurrentBlock->usedDataAvailable()) {
|
||||
m_CurrentData = m_CurrentBlock->used_data;
|
||||
return reinterpret_cast<a*>(m_CurrentBlock->data[m_CurrentData].data);
|
||||
return reinterpret_cast<a*>(
|
||||
m_CurrentBlock->data[m_CurrentData].data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_CurrentData = m_CurrentBlock->next_data[m_CurrentData];
|
||||
|
||||
if (m_CurrentData == m_CurrentBlock->used_data)
|
||||
{
|
||||
if (m_CurrentData == m_CurrentBlock->used_data) {
|
||||
// found an object
|
||||
m_CurrentBlock = m_CurrentBlock->next_block;
|
||||
goto _label;
|
||||
|
|
|
@ -56,29 +56,24 @@ MEM_TempAlloc::MEM_TempAlloc()
|
|||
|
||||
void* MEM_TempAlloc::Alloc(size_t len)
|
||||
{
|
||||
if (m_CurrentMemoryBlock && m_CurrentMemoryPos + len <= m_BlockSize)
|
||||
{
|
||||
if (m_CurrentMemoryBlock && m_CurrentMemoryPos + len <= m_BlockSize) {
|
||||
void* data = m_CurrentMemoryBlock->GetData(m_CurrentMemoryPos);
|
||||
m_LastPos = m_CurrentMemoryPos;
|
||||
m_CurrentMemoryPos += len;
|
||||
return data;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return CreateBlock(len);
|
||||
}
|
||||
}
|
||||
|
||||
void* MEM_TempAlloc::Alloc(size_t len, size_t alignment)
|
||||
{
|
||||
if (m_CurrentMemoryBlock)
|
||||
{
|
||||
if (m_CurrentMemoryBlock) {
|
||||
if (m_CurrentMemoryPos % alignment != 0) {
|
||||
m_CurrentMemoryPos += alignment - m_CurrentMemoryPos % alignment;
|
||||
}
|
||||
|
||||
if (m_CurrentMemoryPos + len <= m_BlockSize)
|
||||
{
|
||||
if (m_CurrentMemoryPos + len <= m_BlockSize) {
|
||||
void* data = m_CurrentMemoryBlock->GetData(m_CurrentMemoryPos);
|
||||
m_LastPos = m_CurrentMemoryPos;
|
||||
m_CurrentMemoryPos += len;
|
||||
|
@ -91,8 +86,7 @@ void* MEM_TempAlloc::Alloc(size_t len, size_t alignment)
|
|||
|
||||
void MEM_TempAlloc::FreeAll(void)
|
||||
{
|
||||
while (m_CurrentMemoryBlock)
|
||||
{
|
||||
while (m_CurrentMemoryBlock) {
|
||||
tempBlock_t* prev_block = m_CurrentMemoryBlock->prev;
|
||||
MEM_TempFree(m_CurrentMemoryBlock);
|
||||
m_CurrentMemoryBlock = prev_block;
|
||||
|
@ -105,17 +99,12 @@ void* MEM_TempAlloc::CreateBlock(size_t len)
|
|||
|
||||
// allocate a new block
|
||||
tempBlock_t* prev_block = m_CurrentMemoryBlock;
|
||||
m_CurrentMemoryBlock = (tempBlock_t*)MEM_TempAllocate(sizeof(tempBlock_t) + max(m_BlockSize, len));
|
||||
m_CurrentMemoryBlock = (tempBlock_t*)MEM_TempAllocate(
|
||||
sizeof(tempBlock_t) + max(m_BlockSize, len));
|
||||
m_CurrentMemoryBlock->prev = prev_block;
|
||||
return m_CurrentMemoryBlock->GetData();
|
||||
}
|
||||
|
||||
void* tempBlock_t::GetData()
|
||||
{
|
||||
return (void*)(this + 1);
|
||||
}
|
||||
void* tempBlock_t::GetData() { return (void*)(this + 1); }
|
||||
|
||||
void* tempBlock_t::GetData(size_t pos)
|
||||
{
|
||||
return (uint8_t*)(this + 1) + pos;
|
||||
}
|
||||
void* tempBlock_t::GetData(size_t pos) { return (uint8_t*)(this + 1) + pos; }
|
||||
|
|
|
@ -28,7 +28,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
class tempBlock_t;
|
||||
|
||||
class MEM_TempAlloc {
|
||||
class MEM_TempAlloc
|
||||
{
|
||||
public:
|
||||
MEM_TempAlloc();
|
||||
|
||||
|
|
|
@ -64,15 +64,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
typedef unsigned char byte;
|
||||
|
||||
CLASS_DECLARATION( Class, Script, NULL )
|
||||
{
|
||||
CLASS_DECLARATION(Class, Script, NULL){
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Script::~Script()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
Script::~Script() { Close(); }
|
||||
|
||||
Script::Script(const char* filename /*= 0*/)
|
||||
{
|
||||
|
@ -85,9 +81,10 @@ Script::Script(const char* filename /*= 0*/)
|
|||
tokenready = false;
|
||||
token[0] = 0;
|
||||
|
||||
if ( filename != 0 )
|
||||
if (filename != 0) {
|
||||
LoadFile(filename);
|
||||
}
|
||||
}
|
||||
|
||||
Script::Script()
|
||||
{
|
||||
|
@ -103,8 +100,7 @@ Script::Script()
|
|||
|
||||
void Script::Close(void)
|
||||
{
|
||||
if ( releaseBuffer && buffer )
|
||||
{
|
||||
if (releaseBuffer && buffer) {
|
||||
FILE_Free((void*)buffer);
|
||||
}
|
||||
|
||||
|
@ -117,10 +113,8 @@ void Script::Close( void )
|
|||
token[0] = 0;
|
||||
|
||||
// Loop Through the macro container and delete (del33t -hehe) them all
|
||||
for( int i = 1; i <= macrolist.NumObjects(); i++)
|
||||
{
|
||||
if (macrolist.ObjectAt( i ) )
|
||||
{
|
||||
for (int i = 1; i <= macrolist.NumObjects(); i++) {
|
||||
if (macrolist.ObjectAt(i)) {
|
||||
delete macrolist.ObjectAt(i);
|
||||
macrolist.ObjectAt(i) = 0;
|
||||
}
|
||||
|
@ -135,10 +129,7 @@ void Script::Close( void )
|
|||
==============
|
||||
*/
|
||||
|
||||
const char *Script::Filename( void )
|
||||
{
|
||||
return filename.c_str();
|
||||
}
|
||||
const char* Script::Filename(void) { return filename.c_str(); }
|
||||
|
||||
/*
|
||||
==============
|
||||
|
@ -148,10 +139,7 @@ const char *Script::Filename( void )
|
|||
==============
|
||||
*/
|
||||
|
||||
int Script::GetLineNumber( void )
|
||||
{
|
||||
return line;
|
||||
}
|
||||
int Script::GetLineNumber(void) { return line; }
|
||||
|
||||
/*
|
||||
==============
|
||||
|
@ -205,8 +193,7 @@ void Script::RestorePosition( const scriptmarker_t *mark )
|
|||
strcpy(token, mark->token);
|
||||
|
||||
assert(script_p <= end_p);
|
||||
if ( script_p > end_p )
|
||||
{
|
||||
if (script_p > end_p) {
|
||||
script_p = end_p;
|
||||
}
|
||||
}
|
||||
|
@ -221,15 +208,12 @@ void Script::RestorePosition( const scriptmarker_t *mark )
|
|||
|
||||
qboolean Script::SkipToEOL(void)
|
||||
{
|
||||
if ( script_p >= end_p )
|
||||
{
|
||||
if (script_p >= end_p) {
|
||||
return true;
|
||||
}
|
||||
|
||||
while( *script_p != TOKENEOL )
|
||||
{
|
||||
if ( script_p >= end_p )
|
||||
{
|
||||
while (*script_p != TOKENEOL) {
|
||||
if (script_p >= end_p) {
|
||||
return true;
|
||||
}
|
||||
script_p++;
|
||||
|
@ -247,9 +231,10 @@ qboolean Script::SkipToEOL( void )
|
|||
|
||||
void Script::CheckOverflow(void)
|
||||
{
|
||||
if ( script_p >= end_p )
|
||||
{
|
||||
FILE_Error( ERR_DROP, "End of token file reached prematurely reading %s\n", filename.c_str() );
|
||||
if (script_p >= end_p) {
|
||||
FILE_Error(ERR_DROP,
|
||||
"End of token file reached prematurely reading %s\n",
|
||||
filename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,13 +253,11 @@ void Script::SkipWhiteSpace( qboolean crossline )
|
|||
//
|
||||
CheckOverflow();
|
||||
|
||||
while( *script_p <= TOKENSPACE )
|
||||
{
|
||||
if ( *script_p++ == TOKENEOL )
|
||||
{
|
||||
if ( !crossline )
|
||||
{
|
||||
FILE_Error( ERR_DROP, "Line %i is incomplete in file %s\n", line, filename.c_str() );
|
||||
while (*script_p <= TOKENSPACE) {
|
||||
if (*script_p++ == TOKENEOL) {
|
||||
if (!crossline) {
|
||||
FILE_Error(ERR_DROP, "Line %i is incomplete in file %s\n", line,
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
line++;
|
||||
|
@ -285,29 +268,24 @@ void Script::SkipWhiteSpace( qboolean crossline )
|
|||
|
||||
qboolean Script::AtComment(void)
|
||||
{
|
||||
if ( script_p >= end_p )
|
||||
{
|
||||
if (script_p >= end_p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( *script_p == TOKENCOMMENT )
|
||||
{
|
||||
if (*script_p == TOKENCOMMENT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( *script_p == TOKENCOMMENT2 )
|
||||
{
|
||||
if (*script_p == TOKENCOMMENT2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Two or more character comment specifiers
|
||||
if ( ( script_p + 1 ) >= end_p )
|
||||
{
|
||||
if ((script_p + 1) >= end_p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ( *script_p == '/' ) && ( *( script_p + 1 ) == '/' ) )
|
||||
{
|
||||
if ((*script_p == '/') && (*(script_p + 1) == '/')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -328,8 +306,7 @@ void Script::SkipNonToken( qboolean crossline )
|
|||
// skip space and comments
|
||||
//
|
||||
SkipWhiteSpace(crossline);
|
||||
while( AtComment() )
|
||||
{
|
||||
while (AtComment()) {
|
||||
SkipToEOL();
|
||||
SkipWhiteSpace(crossline);
|
||||
}
|
||||
|
@ -353,43 +330,33 @@ void Script::SkipNonToken( qboolean crossline )
|
|||
|
||||
qboolean Script::TokenAvailable(qboolean crossline)
|
||||
{
|
||||
if ( script_p >= end_p )
|
||||
{
|
||||
if (script_p >= end_p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
while ( *script_p <= TOKENSPACE )
|
||||
{
|
||||
if ( *script_p == TOKENEOL )
|
||||
{
|
||||
if ( !crossline )
|
||||
{
|
||||
while (1) {
|
||||
while (*script_p <= TOKENSPACE) {
|
||||
if (*script_p == TOKENEOL) {
|
||||
if (!crossline) {
|
||||
return (false);
|
||||
}
|
||||
line++;
|
||||
}
|
||||
|
||||
script_p++;
|
||||
if ( script_p >= end_p )
|
||||
{
|
||||
if (script_p >= end_p) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( AtComment() )
|
||||
{
|
||||
if (AtComment()) {
|
||||
qboolean done;
|
||||
|
||||
done = SkipToEOL();
|
||||
if ( done )
|
||||
{
|
||||
if (done) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -411,20 +378,16 @@ qboolean Script::CommentAvailable( qboolean crossline )
|
|||
|
||||
searchptr = script_p;
|
||||
|
||||
if ( searchptr >= end_p )
|
||||
{
|
||||
if (searchptr >= end_p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while ( *searchptr <= TOKENSPACE )
|
||||
{
|
||||
if ( ( *searchptr == TOKENEOL ) && ( !crossline ) )
|
||||
{
|
||||
while (*searchptr <= TOKENSPACE) {
|
||||
if ((*searchptr == TOKENEOL) && (!crossline)) {
|
||||
return false;
|
||||
}
|
||||
searchptr++;
|
||||
if ( searchptr >= end_p )
|
||||
{
|
||||
if (searchptr >= end_p) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -449,10 +412,7 @@ GetToken (false);
|
|||
==============
|
||||
*/
|
||||
|
||||
void Script::UnGetToken( void )
|
||||
{
|
||||
tokenready = true;
|
||||
}
|
||||
void Script::UnGetToken(void) { tokenready = true; }
|
||||
|
||||
/*
|
||||
==============
|
||||
|
@ -540,8 +500,7 @@ const char *Script::GetToken( qboolean crossline )
|
|||
qboolean is_Macro = false;
|
||||
|
||||
// is a token already waiting?
|
||||
if ( tokenready )
|
||||
{
|
||||
if (tokenready) {
|
||||
tokenready = false;
|
||||
return token;
|
||||
}
|
||||
|
@ -550,12 +509,10 @@ const char *Script::GetToken( qboolean crossline )
|
|||
|
||||
token_p = GrabNextToken(crossline);
|
||||
|
||||
if ( is_Macro && ( token_p != "$include" ) )
|
||||
{
|
||||
if (is_Macro && (token_p != "$include")) {
|
||||
|
||||
// Check to see if we need to add any definitions
|
||||
while ( ( token_p == "$define" ) || ( token_p == "$Define" ) )
|
||||
{
|
||||
while ((token_p == "$define") || (token_p == "$Define")) {
|
||||
AddMacroDefinition(crossline);
|
||||
is_Macro = isMacro();
|
||||
// if ( !is_Macro )
|
||||
|
@ -564,11 +521,10 @@ const char *Script::GetToken( qboolean crossline )
|
|||
}
|
||||
|
||||
// Check to see if we need return any defines strings
|
||||
if( is_Macro && ( token_p != "$include" ) && ( token_p[token_p.length() - 1] == '$' ) )
|
||||
{
|
||||
if (is_Macro && (token_p != "$include") &&
|
||||
(token_p[token_p.length() - 1] == '$')) {
|
||||
return GetMacroString(token_p);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return token;
|
||||
|
@ -593,45 +549,49 @@ const char *Script::GrabNextToken( qboolean crossline )
|
|||
//
|
||||
// copy token
|
||||
//
|
||||
if ( *script_p == '"' )
|
||||
{
|
||||
if (*script_p == '"') {
|
||||
return GetString(crossline);
|
||||
}
|
||||
|
||||
token_p = token;
|
||||
while( ( *script_p > TOKENSPACE ) && !AtComment() )
|
||||
{
|
||||
if ( ( *script_p == '\\' ) && ( script_p < ( end_p - 1 ) ) )
|
||||
{
|
||||
while ((*script_p > TOKENSPACE) && !AtComment()) {
|
||||
if ((*script_p == '\\') && (script_p < (end_p - 1))) {
|
||||
script_p++;
|
||||
switch( *script_p )
|
||||
{
|
||||
case 'n' : *token_p++ = '\n'; break;
|
||||
case 'r' : *token_p++ = '\n'; break;
|
||||
case '\'' : *token_p++ = '\''; break;
|
||||
case '\"' : *token_p++ = '\"'; break;
|
||||
case '\\' : *token_p++ = '\\'; break;
|
||||
default: *token_p++ = *script_p; break;
|
||||
switch (*script_p) {
|
||||
case 'n':
|
||||
*token_p++ = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
*token_p++ = '\n';
|
||||
break;
|
||||
case '\'':
|
||||
*token_p++ = '\'';
|
||||
break;
|
||||
case '\"':
|
||||
*token_p++ = '\"';
|
||||
break;
|
||||
case '\\':
|
||||
*token_p++ = '\\';
|
||||
break;
|
||||
default:
|
||||
*token_p++ = *script_p;
|
||||
break;
|
||||
}
|
||||
script_p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*token_p++ = *script_p++;
|
||||
}
|
||||
|
||||
if ( token_p == &token[ MAXTOKEN ] )
|
||||
{
|
||||
FILE_Error( ERR_DROP, "Token too large on line %i in file %s\n", line, filename.c_str() );
|
||||
if (token_p == &token[MAXTOKEN]) {
|
||||
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n",
|
||||
line, filename.c_str());
|
||||
}
|
||||
|
||||
if ( script_p == end_p )
|
||||
{
|
||||
if (script_p == end_p) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*token_p = 0;
|
||||
|
||||
return token;
|
||||
|
@ -648,25 +608,27 @@ void Script::AddMacroDefinition( qboolean crossline )
|
|||
{
|
||||
macro* theMacro;
|
||||
|
||||
//Create a new macro structure. This new macro will be deleted in the script close()
|
||||
// Create a new macro structure. This new macro will be deleted in the
|
||||
// script close()
|
||||
theMacro = new macro;
|
||||
|
||||
// Grab the macro name
|
||||
theMacro->macroName = "$";
|
||||
theMacro->macroName.append(GrabNextToken(crossline));
|
||||
theMacro->macroName.append( "$" ); //<-- Adding closing ($) to keep formatting consistant
|
||||
theMacro->macroName.append(
|
||||
"$"); //<-- Adding closing ($) to keep formatting consistant
|
||||
|
||||
// Grab the macro string
|
||||
str tmpstr;
|
||||
tmpstr = GrabNextToken(crossline);
|
||||
// Check to see if we need return any defines strings
|
||||
if( ( tmpstr != "$include" ) && ( tmpstr[tmpstr.length() - 1] == '$' ) )
|
||||
if ((tmpstr != "$include") && (tmpstr[tmpstr.length() - 1] == '$')) {
|
||||
theMacro->macroText = GetMacroString(tmpstr);
|
||||
else
|
||||
} else {
|
||||
theMacro->macroText = tmpstr;
|
||||
}
|
||||
|
||||
macrolist.AddObject(theMacro);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -681,21 +643,20 @@ const char *Script::GetMacroString( const char *theMacroName )
|
|||
|
||||
macro* theMacro = 0; // Initialize this puppy
|
||||
|
||||
for( int i = 1; i <= macrolist.NumObjects(); i++)
|
||||
{
|
||||
for (int i = 1; i <= macrolist.NumObjects(); i++) {
|
||||
theMacro = macrolist.ObjectAt(i);
|
||||
|
||||
if(!theMacro->macroName.cmp(theMacro->macroName.c_str(), theMacroName))
|
||||
{
|
||||
if (!theMacro->macroName.cmp(theMacro->macroName.c_str(),
|
||||
theMacroName)) {
|
||||
const char* text = theMacro->macroText.c_str();
|
||||
|
||||
// If our define value is another define...
|
||||
if( text[0] == '$' )
|
||||
if (text[0] == '$') {
|
||||
return EvaluateMacroString(text);
|
||||
else
|
||||
} else {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
char tmpstr[255], *sptr = tmpstr;
|
||||
|
@ -704,9 +665,9 @@ const char *Script::GetMacroString( const char *theMacroName )
|
|||
sptr++;
|
||||
|
||||
// We didn't find what we were looking for
|
||||
FILE_Error( ERR_DROP, "No Macro Text found for %s in file %s\n", theMacroName, filename.c_str() );
|
||||
FILE_Error(ERR_DROP, "No Macro Text found for %s in file %s\n",
|
||||
theMacroName, filename.c_str());
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
//================================================================
|
||||
|
@ -721,10 +682,7 @@ const char *Script::GetMacroString( const char *theMacroName )
|
|||
// Returns: None
|
||||
//
|
||||
//================================================================
|
||||
void Script::AddMacro(const char *name, const char *value)
|
||||
{
|
||||
|
||||
}
|
||||
void Script::AddMacro(const char* name, const char* value) {}
|
||||
|
||||
/*
|
||||
==============
|
||||
|
@ -742,20 +700,33 @@ char *Script::EvaluateMacroString( const char *theMacroString )
|
|||
float value = 0.0f, val = 0.0f;
|
||||
memset(buffer, 0, 255);
|
||||
|
||||
for ( i=0;i<=strlen(theMacroString);i++ )
|
||||
{
|
||||
if ( theMacroString[i] == '+' ) { haveoper = true; newoper = '+'; }
|
||||
if ( theMacroString[i] == '-' ) { haveoper = true; newoper = '-'; }
|
||||
if ( theMacroString[i] == '*' ) { haveoper = true; newoper = '*'; }
|
||||
if ( theMacroString[i] == '/' ) { haveoper = true; newoper = '/'; }
|
||||
if ( theMacroString[i] == 0 ) haveoper = true;
|
||||
for (i = 0; i <= strlen(theMacroString); i++) {
|
||||
if (theMacroString[i] == '+') {
|
||||
haveoper = true;
|
||||
newoper = '+';
|
||||
}
|
||||
if (theMacroString[i] == '-') {
|
||||
haveoper = true;
|
||||
newoper = '-';
|
||||
}
|
||||
if (theMacroString[i] == '*') {
|
||||
haveoper = true;
|
||||
newoper = '*';
|
||||
}
|
||||
if (theMacroString[i] == '/') {
|
||||
haveoper = true;
|
||||
newoper = '/';
|
||||
}
|
||||
if (theMacroString[i] == 0) {
|
||||
haveoper = true;
|
||||
}
|
||||
|
||||
if ( haveoper )
|
||||
{
|
||||
if ( buffer[0] == '$' )
|
||||
if (haveoper) {
|
||||
if (buffer[0] == '$') {
|
||||
val = atof(GetMacroString(buffer));
|
||||
else
|
||||
} else {
|
||||
val = atof(buffer);
|
||||
}
|
||||
|
||||
value = EvaluateMacroMath(value, val, oper);
|
||||
oper = newoper;
|
||||
|
@ -784,12 +755,19 @@ char *Script::EvaluateMacroString( const char *theMacroString )
|
|||
*/
|
||||
float Script::EvaluateMacroMath(float value, float newval, char oper)
|
||||
{
|
||||
switch ( oper )
|
||||
{
|
||||
case '+' : value += newval; break;
|
||||
case '-' : value -= newval; break;
|
||||
case '*' : value *= newval; break;
|
||||
case '/' : value /= newval; break;
|
||||
switch (oper) {
|
||||
case '+':
|
||||
value += newval;
|
||||
break;
|
||||
case '-':
|
||||
value -= newval;
|
||||
break;
|
||||
case '*':
|
||||
value *= newval;
|
||||
break;
|
||||
case '/':
|
||||
value /= newval;
|
||||
break;
|
||||
}
|
||||
|
||||
return value;
|
||||
|
@ -804,12 +782,12 @@ float Script::EvaluateMacroMath(float value, float newval, char oper)
|
|||
*/
|
||||
qboolean Script::isMacro(void)
|
||||
{
|
||||
if ( !TokenAvailable( true ) )
|
||||
if (!TokenAvailable(true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkipNonToken(true);
|
||||
if ( *script_p == TOKENSPECIAL )
|
||||
{
|
||||
if (*script_p == TOKENSPECIAL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -830,8 +808,7 @@ const char *Script::GetLine( qboolean crossline )
|
|||
int size;
|
||||
|
||||
// is a token already waiting?
|
||||
if ( tokenready )
|
||||
{
|
||||
if (tokenready) {
|
||||
tokenready = false;
|
||||
return token;
|
||||
}
|
||||
|
@ -847,14 +824,12 @@ const char *Script::GetLine( qboolean crossline )
|
|||
start = script_p;
|
||||
SkipToEOL();
|
||||
size = script_p - start;
|
||||
if ( size < ( MAXTOKEN - 1 ) )
|
||||
{
|
||||
if (size < (MAXTOKEN - 1)) {
|
||||
memcpy(token, start, size);
|
||||
token[size] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE_Error( ERR_DROP, "Token too large on line %i in file %s\n", line, filename.c_str() );
|
||||
} else {
|
||||
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line,
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
return token;
|
||||
|
@ -884,14 +859,12 @@ const char *Script::GetRaw( void )
|
|||
start = script_p;
|
||||
SkipToEOL();
|
||||
size = script_p - start;
|
||||
if ( size < ( MAXTOKEN - 1 ) )
|
||||
{
|
||||
if (size < (MAXTOKEN - 1)) {
|
||||
memset(token, 0, sizeof(token));
|
||||
memcpy(token, start, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
FILE_Error( ERR_DROP, "Token too large on line %i in file %s\n", line, filename.c_str() );
|
||||
} else {
|
||||
FILE_Error(ERR_DROP, "Token too large on line %i in file %s\n", line,
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
return token;
|
||||
|
@ -911,8 +884,7 @@ const char *Script::GetString( qboolean crossline )
|
|||
char* token_p;
|
||||
|
||||
// is a token already waiting?
|
||||
if ( tokenready )
|
||||
{
|
||||
if (tokenready) {
|
||||
tokenready = false;
|
||||
return token;
|
||||
}
|
||||
|
@ -922,50 +894,61 @@ const char *Script::GetString( qboolean crossline )
|
|||
//
|
||||
SkipNonToken(crossline);
|
||||
|
||||
if ( *script_p != '"' )
|
||||
{
|
||||
FILE_Error( ERR_DROP, "Expecting string on line %i in file %s\n", line, filename.c_str() );
|
||||
if (*script_p != '"') {
|
||||
FILE_Error(ERR_DROP, "Expecting string on line %i in file %s\n", line,
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
script_p++;
|
||||
|
||||
startline = line;
|
||||
token_p = token;
|
||||
while( *script_p != '"' )
|
||||
{
|
||||
if ( *script_p == TOKENEOL )
|
||||
{
|
||||
FILE_Error( ERR_DROP, "Line %i is incomplete while reading string in file %s\n", line, filename.c_str() );
|
||||
while (*script_p != '"') {
|
||||
if (*script_p == TOKENEOL) {
|
||||
FILE_Error(
|
||||
ERR_DROP,
|
||||
"Line %i is incomplete while reading string in file %s\n", line,
|
||||
filename.c_str());
|
||||
}
|
||||
|
||||
if ( ( *script_p == '\\' ) && ( script_p < ( end_p - 1 ) ) )
|
||||
{
|
||||
if ((*script_p == '\\') && (script_p < (end_p - 1))) {
|
||||
script_p++;
|
||||
switch( *script_p )
|
||||
{
|
||||
case 'n' : *token_p++ = '\n'; break;
|
||||
case 'r' : *token_p++ = '\n'; break;
|
||||
case '\'' : *token_p++ = '\''; break;
|
||||
case '\"' : *token_p++ = '\"'; break;
|
||||
case '\\' : *token_p++ = '\\'; break;
|
||||
default: *token_p++ = *script_p; break;
|
||||
switch (*script_p) {
|
||||
case 'n':
|
||||
*token_p++ = '\n';
|
||||
break;
|
||||
case 'r':
|
||||
*token_p++ = '\n';
|
||||
break;
|
||||
case '\'':
|
||||
*token_p++ = '\'';
|
||||
break;
|
||||
case '\"':
|
||||
*token_p++ = '\"';
|
||||
break;
|
||||
case '\\':
|
||||
*token_p++ = '\\';
|
||||
break;
|
||||
default:
|
||||
*token_p++ = *script_p;
|
||||
break;
|
||||
}
|
||||
script_p++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*token_p++ = *script_p++;
|
||||
}
|
||||
|
||||
if ( script_p >= end_p )
|
||||
{
|
||||
FILE_Error( ERR_DROP, "End of token file reached prematurely while reading string on\n"
|
||||
"line %d in file %s\n", startline, filename.c_str() );
|
||||
if (script_p >= end_p) {
|
||||
FILE_Error(ERR_DROP,
|
||||
"End of token file reached prematurely while reading "
|
||||
"string on\n"
|
||||
"line %d in file %s\n",
|
||||
startline, filename.c_str());
|
||||
}
|
||||
|
||||
if ( token_p == &token[ MAXTOKEN ] )
|
||||
{
|
||||
FILE_Error( ERR_DROP, "String too large on line %i in file %s\n", line, filename.c_str() );
|
||||
if (token_p == &token[MAXTOKEN]) {
|
||||
FILE_Error(ERR_DROP, "String too large on line %i in file %s\n",
|
||||
line, filename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -987,15 +970,12 @@ const char *Script::GetString( qboolean crossline )
|
|||
|
||||
qboolean Script::GetSpecific(const char* string)
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( !TokenAvailable( true ) )
|
||||
{
|
||||
do {
|
||||
if (!TokenAvailable(true)) {
|
||||
return false;
|
||||
}
|
||||
GetToken(true);
|
||||
}
|
||||
while( strcmp( token, string ) );
|
||||
} while (strcmp(token, string));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1017,10 +997,11 @@ qboolean Script::GetSpecific( const char *string )
|
|||
qboolean Script::GetBoolean(qboolean crossline)
|
||||
{
|
||||
GetToken(crossline);
|
||||
if ( Q_stricmp( token, "true" ) == 0 )
|
||||
if (Q_stricmp(token, "true") == 0) {
|
||||
return true;
|
||||
else if( Q_stricmp( token, "1" ) == 0 )
|
||||
} else if (Q_stricmp(token, "1") == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1105,8 +1086,7 @@ int Script::LinesInFile( void )
|
|||
numentries = 0;
|
||||
|
||||
Reset();
|
||||
while( TokenAvailable( true ) )
|
||||
{
|
||||
while (TokenAvailable(true)) {
|
||||
GetLine(true);
|
||||
numentries++;
|
||||
}
|
||||
|
@ -1159,8 +1139,7 @@ void Script::LoadFile( const char *name )
|
|||
|
||||
hasError = false;
|
||||
|
||||
if ( length < 0 )
|
||||
{
|
||||
if (length < 0) {
|
||||
hasError = true;
|
||||
return;
|
||||
}
|
||||
|
@ -1201,17 +1180,8 @@ void Script::LoadFile( const char *name, int length, const char *buf )
|
|||
releaseBuffer = true;
|
||||
}
|
||||
|
||||
qboolean Script::isValid()
|
||||
{
|
||||
return !hasError;
|
||||
}
|
||||
qboolean Script::isValid() { return !hasError; }
|
||||
|
||||
qboolean Script::EndOfFile( void )
|
||||
{
|
||||
return script_p >= end_p;
|
||||
}
|
||||
qboolean Script::EndOfFile(void) { return script_p >= end_p; }
|
||||
|
||||
const char *Script::Token( void )
|
||||
{
|
||||
return token;
|
||||
}
|
||||
const char* Script::Token(void) { return token; }
|
||||
|
|
|
@ -42,16 +42,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#define MAXTOKEN 512
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
qboolean tokenready;
|
||||
int offset;
|
||||
int line;
|
||||
char token[MAXTOKEN];
|
||||
} scriptmarker_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
// const char *macroName;
|
||||
// const char *macroText;
|
||||
str macroName;
|
||||
|
@ -141,34 +139,28 @@ class Script : public Class
|
|||
|
||||
#if defined(ARCHIVE_SUPPORTED)
|
||||
|
||||
inline void Script::Archive
|
||||
(
|
||||
Archiver &arc
|
||||
)
|
||||
inline void Script::Archive(Archiver& arc)
|
||||
{
|
||||
int pos;
|
||||
|
||||
arc.ArchiveBoolean(&tokenready);
|
||||
|
||||
arc.ArchiveString(&filename);
|
||||
if ( arc.Loading() )
|
||||
{
|
||||
if (arc.Loading()) {
|
||||
//
|
||||
// load the file in
|
||||
//
|
||||
LoadFile(filename.c_str());
|
||||
}
|
||||
|
||||
if ( !arc.Loading() )
|
||||
{
|
||||
if (!arc.Loading()) {
|
||||
//
|
||||
// save out current pointer as an offset
|
||||
//
|
||||
pos = script_p - buffer;
|
||||
}
|
||||
arc.ArchiveInteger(&pos);
|
||||
if ( arc.Loading() )
|
||||
{
|
||||
if (arc.Loading()) {
|
||||
//
|
||||
// restore the script pointer
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue