mirror of
https://github.com/s1lentq/ReGameDLL_CS.git
synced 2025-02-05 10:10:30 +03:00
env_render: reset entity on start round
This commit is contained in:
parent
f0409ce468
commit
721624bf92
@ -52,16 +52,6 @@ TYPEDESCRIPTION CEnvSpark::m_SaveData[] =
|
|||||||
|
|
||||||
#endif // HOOK_GAMEDLL
|
#endif // HOOK_GAMEDLL
|
||||||
|
|
||||||
|
|
||||||
#ifdef REGAMEDLL_FIXES
|
|
||||||
|
|
||||||
TYPEDESCRIPTION CRotButton::m_SaveData[] =
|
|
||||||
{
|
|
||||||
DEFINE_FIELD(CRotButton, m_vecSpawn, FIELD_VECTOR),
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
IMPLEMENT_SAVERESTORE(CEnvGlobal, CBaseEntity)
|
IMPLEMENT_SAVERESTORE(CEnvGlobal, CBaseEntity)
|
||||||
LINK_ENTITY_TO_CLASS(env_global, CEnvGlobal, CCSEnvGlobal)
|
LINK_ENTITY_TO_CLASS(env_global, CEnvGlobal, CCSEnvGlobal)
|
||||||
|
|
||||||
@ -842,6 +832,17 @@ void CBaseButton::ButtonBackHome()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef REGAMEDLL_FIXES
|
||||||
|
|
||||||
|
TYPEDESCRIPTION CRotButton::m_SaveData[] =
|
||||||
|
{
|
||||||
|
DEFINE_FIELD(CRotButton, m_vecSpawn, FIELD_VECTOR),
|
||||||
|
};
|
||||||
|
|
||||||
|
IMPLEMENT_SAVERESTORE(CRotButton, CBaseButton)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
LINK_ENTITY_TO_CLASS(func_rot_button, CRotButton, CCSRotButton)
|
LINK_ENTITY_TO_CLASS(func_rot_button, CRotButton, CCSRotButton)
|
||||||
|
|
||||||
void CRotButton::Spawn()
|
void CRotButton::Spawn()
|
||||||
|
@ -78,7 +78,8 @@ public:
|
|||||||
|
|
||||||
#ifdef REGAMEDLL_FIXES
|
#ifdef REGAMEDLL_FIXES
|
||||||
virtual void Restart();
|
virtual void Restart();
|
||||||
|
virtual int Save(CSave &save);
|
||||||
|
virtual int Restore(CRestore &restore);
|
||||||
public:
|
public:
|
||||||
static TYPEDESCRIPTION m_SaveData[1];
|
static TYPEDESCRIPTION m_SaveData[1];
|
||||||
Vector m_vecSpawn;
|
Vector m_vecSpawn;
|
||||||
|
@ -695,6 +695,7 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(CleanUpMap)()
|
|||||||
#ifdef REGAMEDLL_FIXES
|
#ifdef REGAMEDLL_FIXES
|
||||||
UTIL_RestartOther("func_button");
|
UTIL_RestartOther("func_button");
|
||||||
UTIL_RestartOther("func_rot_button");
|
UTIL_RestartOther("func_rot_button");
|
||||||
|
UTIL_RestartOther("env_render");
|
||||||
UTIL_RestartOther("trigger_push");
|
UTIL_RestartOther("trigger_push");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -403,30 +403,87 @@ void CRenderFxManager::Spawn()
|
|||||||
pev->solid = SOLID_NOT;
|
pev->solid = SOLID_NOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef REGAMEDLL_FIXES
|
||||||
|
|
||||||
|
void CRenderFxManager::UpdateOnRemove()
|
||||||
|
{
|
||||||
|
m_RenderGroups.RemoveAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRenderFxManager::Restart()
|
||||||
|
{
|
||||||
|
if (FStringNull(pev->target))
|
||||||
|
return;
|
||||||
|
|
||||||
|
edict_t *pentTarget = nullptr;
|
||||||
|
while ((pentTarget = FIND_ENTITY_BY_TARGETNAME(pentTarget, STRING(pev->target))))
|
||||||
|
{
|
||||||
|
if (FNullEnt(pentTarget))
|
||||||
|
break;
|
||||||
|
|
||||||
|
entvars_t *pevTarget = VARS(pentTarget);
|
||||||
|
|
||||||
|
// find render groups in our list of backup
|
||||||
|
int index = m_RenderGroups.Find(ENTINDEX(pevTarget));
|
||||||
|
if (index == m_RenderGroups.InvalidIndex()) {
|
||||||
|
// not found
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderGroup_t *pGroup = &m_RenderGroups[ index ];
|
||||||
|
if (!(pev->spawnflags & SF_RENDER_MASKFX))
|
||||||
|
pevTarget->renderfx = pGroup->renderfx;
|
||||||
|
|
||||||
|
if (!(pev->spawnflags & SF_RENDER_MASKAMT))
|
||||||
|
pevTarget->renderamt = pGroup->renderamt;
|
||||||
|
|
||||||
|
if (!(pev->spawnflags & SF_RENDER_MASKMODE))
|
||||||
|
pevTarget->rendermode = pGroup->rendermode;
|
||||||
|
|
||||||
|
if (!(pev->spawnflags & SF_RENDER_MASKCOLOR))
|
||||||
|
pevTarget->rendercolor = pGroup->rendercolor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // REGAMEDLL_FIXES
|
||||||
|
|
||||||
void CRenderFxManager::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
|
void CRenderFxManager::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
|
||||||
{
|
{
|
||||||
if (!FStringNull(pev->target))
|
if (FStringNull(pev->target))
|
||||||
|
return;
|
||||||
|
|
||||||
|
edict_t *pentTarget = nullptr;
|
||||||
|
while ((pentTarget = FIND_ENTITY_BY_TARGETNAME(pentTarget, STRING(pev->target))))
|
||||||
{
|
{
|
||||||
edict_t *pentTarget = NULL;
|
if (FNullEnt(pentTarget))
|
||||||
while ((pentTarget = FIND_ENTITY_BY_TARGETNAME(pentTarget, STRING(pev->target))) != NULL)
|
break;
|
||||||
{
|
|
||||||
if (FNullEnt(pentTarget))
|
|
||||||
break;
|
|
||||||
|
|
||||||
entvars_t *pevTarget = VARS(pentTarget);
|
entvars_t *pevTarget = VARS(pentTarget);
|
||||||
|
|
||||||
if (!(pev->spawnflags & SF_RENDER_MASKFX))
|
#ifdef REGAMEDLL_FIXES
|
||||||
pevTarget->renderfx = pev->renderfx;
|
RenderGroup_t group;
|
||||||
|
group.renderfx = pevTarget->renderfx;
|
||||||
|
group.renderamt = pevTarget->renderamt;
|
||||||
|
group.rendermode = pevTarget->rendermode;
|
||||||
|
group.rendercolor = pevTarget->rendercolor;
|
||||||
|
|
||||||
if (!(pev->spawnflags & SF_RENDER_MASKAMT))
|
int entityIndex = ENTINDEX(pevTarget);
|
||||||
pevTarget->renderamt = pev->renderamt;
|
if (m_RenderGroups.Find(entityIndex) == m_RenderGroups.InvalidIndex()) {
|
||||||
|
m_RenderGroups.Insert(entityIndex, group);
|
||||||
if (!(pev->spawnflags & SF_RENDER_MASKMODE))
|
|
||||||
pevTarget->rendermode = pev->rendermode;
|
|
||||||
|
|
||||||
if (!(pev->spawnflags & SF_RENDER_MASKCOLOR))
|
|
||||||
pevTarget->rendercolor = pev->rendercolor;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!(pev->spawnflags & SF_RENDER_MASKFX))
|
||||||
|
pevTarget->renderfx = pev->renderfx;
|
||||||
|
|
||||||
|
if (!(pev->spawnflags & SF_RENDER_MASKAMT))
|
||||||
|
pevTarget->renderamt = pev->renderamt;
|
||||||
|
|
||||||
|
if (!(pev->spawnflags & SF_RENDER_MASKMODE))
|
||||||
|
pevTarget->rendermode = pev->rendermode;
|
||||||
|
|
||||||
|
if (!(pev->spawnflags & SF_RENDER_MASKCOLOR))
|
||||||
|
pevTarget->rendercolor = pev->rendercolor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "utlmap.h"
|
||||||
|
|
||||||
#define GRENADETYPE_SMOKE 1
|
#define GRENADETYPE_SMOKE 1
|
||||||
#define GRENADETYPE_FLASH 2
|
#define GRENADETYPE_FLASH 2
|
||||||
|
|
||||||
@ -197,6 +199,22 @@ class CRenderFxManager: public CBaseEntity
|
|||||||
public:
|
public:
|
||||||
virtual void Spawn();
|
virtual void Spawn();
|
||||||
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
|
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
|
||||||
|
|
||||||
|
#ifdef REGAMEDLL_FIXES
|
||||||
|
virtual void Restart();
|
||||||
|
virtual void UpdateOnRemove();
|
||||||
|
|
||||||
|
public:
|
||||||
|
struct RenderGroup_t
|
||||||
|
{
|
||||||
|
int rendermode;
|
||||||
|
float renderamt;
|
||||||
|
Vector rendercolor;
|
||||||
|
int renderfx;
|
||||||
|
};
|
||||||
|
CUtlMap<int, RenderGroup_t> m_RenderGroups;
|
||||||
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBaseTrigger: public CBaseToggle
|
class CBaseTrigger: public CBaseToggle
|
||||||
|
@ -66,6 +66,8 @@ class CRotButton: public CBaseButton {
|
|||||||
public:
|
public:
|
||||||
virtual void Spawn() = 0;
|
virtual void Spawn() = 0;
|
||||||
virtual void Restart() = 0;
|
virtual void Restart() = 0;
|
||||||
|
virtual int Save(CSave &save) = 0;
|
||||||
|
virtual int Restore(CRestore &restore) = 0;
|
||||||
public:
|
public:
|
||||||
Vector m_vecSpawn;
|
Vector m_vecSpawn;
|
||||||
};
|
};
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "utlmap.h"
|
||||||
|
|
||||||
#define GRENADETYPE_SMOKE 1
|
#define GRENADETYPE_SMOKE 1
|
||||||
#define GRENADETYPE_FLASH 2
|
#define GRENADETYPE_FLASH 2
|
||||||
|
|
||||||
@ -140,7 +142,18 @@ public:
|
|||||||
class CRenderFxManager: public CBaseEntity {
|
class CRenderFxManager: public CBaseEntity {
|
||||||
public:
|
public:
|
||||||
virtual void Spawn() = 0;
|
virtual void Spawn() = 0;
|
||||||
|
virtual void Restart() = 0;
|
||||||
|
virtual void UpdateOnRemove() = 0;
|
||||||
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0;
|
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0;
|
||||||
|
public:
|
||||||
|
struct RenderGroup_t
|
||||||
|
{
|
||||||
|
int rendermode;
|
||||||
|
float renderamt;
|
||||||
|
Vector rendercolor;
|
||||||
|
int renderfx;
|
||||||
|
};
|
||||||
|
CUtlMap<int, RenderGroup_t> m_RenderGroups;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBaseTrigger: public CBaseToggle {
|
class CBaseTrigger: public CBaseToggle {
|
||||||
|
261
regamedll/public/utlmap.h
Normal file
261
regamedll/public/utlmap.h
Normal file
@ -0,0 +1,261 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* 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 2 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, write to the Free Software Foundation,
|
||||||
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the author gives permission to
|
||||||
|
* link the code of this program with the Half-Life Game Engine ("HL
|
||||||
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
||||||
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
||||||
|
* respects for all of the code used other than the HL Engine and MODs
|
||||||
|
* from Valve. If you modify this file, you may extend this exception
|
||||||
|
* to your version of the file, but you are not obligated to do so. If
|
||||||
|
* you do not wish to do so, delete this exception statement from your
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "tier0/dbg.h"
|
||||||
|
#include "utlrbtree.h"
|
||||||
|
|
||||||
|
// Purpose: An associative container. Pretty much identical to std::map.
|
||||||
|
// This is a useful macro to iterate from start to end in order in a map
|
||||||
|
#define FOR_EACH_MAP(mapName, iteratorName)\
|
||||||
|
for (int iteratorName = (mapName).FirstInorder(); (mapName).IsUtlMap && iteratorName != (mapName).InvalidIndex(); iteratorName = (mapName).NextInorder(iteratorName))
|
||||||
|
|
||||||
|
// faster iteration, but in an unspecified order
|
||||||
|
#define FOR_EACH_MAP_FAST(mapName, iteratorName)\
|
||||||
|
for (int iteratorName = 0; (mapName).IsUtlMap && iteratorName < (mapName).MaxElement(); ++iteratorName) if (!(mapName).IsValidIndex(iteratorName)) continue; else
|
||||||
|
|
||||||
|
struct base_utlmap_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// This enum exists so that FOR_EACH_MAP and FOR_EACH_MAP_FAST cannot accidentally
|
||||||
|
// be used on a type that is not a CUtlMap. If the code compiles then all is well.
|
||||||
|
// The check for IsUtlMap being true should be free.
|
||||||
|
// Using an enum rather than a static const bool ensures that this trick works even
|
||||||
|
// with optimizations disabled on gcc.
|
||||||
|
enum CompileTimeCheck
|
||||||
|
{
|
||||||
|
IsUtlMap = 1
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename K, typename T, typename I = unsigned short>
|
||||||
|
class CUtlMap: public base_utlmap_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef K KeyType_t;
|
||||||
|
typedef T ElemType_t;
|
||||||
|
typedef I IndexType_t;
|
||||||
|
|
||||||
|
// Less func typedef
|
||||||
|
// Returns true if the first parameter is "less" than the second
|
||||||
|
typedef bool (*LessFunc_t)(const KeyType_t &, const KeyType_t &);
|
||||||
|
|
||||||
|
// constructor, destructor
|
||||||
|
// Left at growSize = 0, the memory will first allocate 1 element and double in size
|
||||||
|
// at each increment.
|
||||||
|
// LessFunc_t is required, but may be set after the constructor using SetLessFunc() below
|
||||||
|
CUtlMap(int growSize = 0, int initSize = 0, LessFunc_t lessfunc = 0)
|
||||||
|
: m_Tree(growSize, initSize, CKeyLess(lessfunc))
|
||||||
|
{
|
||||||
|
if (!lessfunc) {
|
||||||
|
SetLessFunc(DefLessFunc(K));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CUtlMap(LessFunc_t lessfunc)
|
||||||
|
: m_Tree(CKeyLess(lessfunc))
|
||||||
|
{
|
||||||
|
if (!lessfunc) {
|
||||||
|
SetLessFunc(DefLessFunc(K));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnsureCapacity(int num) { m_Tree.EnsureCapacity(num); }
|
||||||
|
|
||||||
|
// gets particular elements
|
||||||
|
ElemType_t & Element(IndexType_t i) { return m_Tree.Element(i).elem; }
|
||||||
|
const ElemType_t & Element(IndexType_t i) const { return m_Tree.Element(i).elem; }
|
||||||
|
ElemType_t & operator[](IndexType_t i) { return m_Tree.Element(i).elem; }
|
||||||
|
const ElemType_t & operator[](IndexType_t i) const { return m_Tree.Element(i).elem; }
|
||||||
|
KeyType_t & Key(IndexType_t i) { return m_Tree.Element(i).key; }
|
||||||
|
const KeyType_t & Key(IndexType_t i) const { return m_Tree.Element(i).key; }
|
||||||
|
|
||||||
|
|
||||||
|
// Num elements
|
||||||
|
unsigned int Count() const { return m_Tree.Count(); }
|
||||||
|
|
||||||
|
// Max "size" of the vector
|
||||||
|
IndexType_t MaxElement() const { return m_Tree.MaxElement(); }
|
||||||
|
|
||||||
|
// Checks if a node is valid and in the map
|
||||||
|
bool IsValidIndex(IndexType_t i) const { return m_Tree.IsValidIndex(i); }
|
||||||
|
|
||||||
|
// Checks if the map as a whole is valid
|
||||||
|
bool IsValid() const { return m_Tree.IsValid(); }
|
||||||
|
|
||||||
|
// Invalid index
|
||||||
|
static IndexType_t InvalidIndex() { return CTree::InvalidIndex(); }
|
||||||
|
|
||||||
|
// Sets the less func
|
||||||
|
void SetLessFunc(LessFunc_t func)
|
||||||
|
{
|
||||||
|
m_Tree.SetLessFunc(CKeyLess(func));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert method (inserts in order)
|
||||||
|
IndexType_t Insert(const KeyType_t &key, const ElemType_t &insert)
|
||||||
|
{
|
||||||
|
Node_t node;
|
||||||
|
node.key = key;
|
||||||
|
node.elem = insert;
|
||||||
|
return m_Tree.Insert(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexType_t Insert(const KeyType_t &key)
|
||||||
|
{
|
||||||
|
Node_t node;
|
||||||
|
node.key = key;
|
||||||
|
return m_Tree.Insert(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find method
|
||||||
|
IndexType_t Find(const KeyType_t &key) const
|
||||||
|
{
|
||||||
|
Node_t dummyNode;
|
||||||
|
dummyNode.key = key;
|
||||||
|
return m_Tree.Find(dummyNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove methods
|
||||||
|
void RemoveAt(IndexType_t i) { m_Tree.RemoveAt(i); }
|
||||||
|
bool Remove(const KeyType_t &key)
|
||||||
|
{
|
||||||
|
Node_t dummyNode;
|
||||||
|
dummyNode.key = key;
|
||||||
|
return m_Tree.Remove(dummyNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveAll() { m_Tree.RemoveAll(); }
|
||||||
|
void Purge() { m_Tree.Purge(); }
|
||||||
|
|
||||||
|
// Purges the list and calls delete on each element in it.
|
||||||
|
void PurgeAndDeleteElements();
|
||||||
|
|
||||||
|
// Iteration
|
||||||
|
IndexType_t FirstInorder() const { return m_Tree.FirstInorder(); }
|
||||||
|
IndexType_t NextInorder(IndexType_t i) const { return m_Tree.NextInorder(i); }
|
||||||
|
IndexType_t PrevInorder(IndexType_t i) const { return m_Tree.PrevInorder(i); }
|
||||||
|
IndexType_t LastInorder() const { return m_Tree.LastInorder(); }
|
||||||
|
|
||||||
|
// If you change the search key, this can be used to reinsert the
|
||||||
|
// element into the map.
|
||||||
|
void Reinsert(const KeyType_t &key, IndexType_t i)
|
||||||
|
{
|
||||||
|
m_Tree[i].key = key;
|
||||||
|
m_Tree.Reinsert(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexType_t InsertOrReplace(const KeyType_t &key, const ElemType_t &insert)
|
||||||
|
{
|
||||||
|
IndexType_t i = Find(key);
|
||||||
|
if (i != InvalidIndex())
|
||||||
|
{
|
||||||
|
Element(i) = insert;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Insert(key, insert);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Swap(CUtlMap<K, T, I> &that)
|
||||||
|
{
|
||||||
|
m_Tree.Swap(that.m_Tree);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Node_t
|
||||||
|
{
|
||||||
|
Node_t()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Node_t(const Node_t &from)
|
||||||
|
: key(from.key),
|
||||||
|
elem(from.elem)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyType_t key;
|
||||||
|
ElemType_t elem;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CKeyLess
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CKeyLess(LessFunc_t lessFunc) : m_LessFunc(lessFunc) {}
|
||||||
|
|
||||||
|
bool operator!() const
|
||||||
|
{
|
||||||
|
return !m_LessFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator()(const Node_t &left, const Node_t &right) const
|
||||||
|
{
|
||||||
|
return m_LessFunc(left.key, right.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
LessFunc_t m_LessFunc;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef CUtlRBTree<Node_t, I, CKeyLess> CTree;
|
||||||
|
|
||||||
|
CTree *AccessTree() { return &m_Tree; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CTree m_Tree;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Purges the list and calls delete on each element in it.
|
||||||
|
template <typename K, typename T, typename I>
|
||||||
|
inline void CUtlMap<K, T, I>::PurgeAndDeleteElements()
|
||||||
|
{
|
||||||
|
for (I i = 0; i < MaxElement(); ++i)
|
||||||
|
{
|
||||||
|
if (!IsValidIndex(i))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
delete Element(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
Purge();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is horrible and slow and meant to be used only when you're dealing with really
|
||||||
|
// non-time/memory-critical code and desperately want to copy a whole map element-by-element
|
||||||
|
// for whatever reason.
|
||||||
|
template <typename K, typename T, typename I>
|
||||||
|
void DeepCopyMap(const CUtlMap<K, T, I> &pmapIn, CUtlMap<K, T, I> *out_pmapOut)
|
||||||
|
{
|
||||||
|
Assert(out_pmapOut);
|
||||||
|
|
||||||
|
out_pmapOut->Purge();
|
||||||
|
FOR_EACH_MAP_FAST(pmapIn, i)
|
||||||
|
{
|
||||||
|
out_pmapOut->Insert(pmapIn.Key(i), pmapIn.Element(i));
|
||||||
|
}
|
||||||
|
}
|
@ -26,12 +26,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef UTLMEMORY_H
|
|
||||||
#define UTLMEMORY_H
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "osconfig.h"
|
#include "osconfig.h"
|
||||||
#include "tier0/dbg.h"
|
#include "tier0/dbg.h"
|
||||||
@ -40,55 +35,56 @@
|
|||||||
#pragma warning (disable:4100)
|
#pragma warning (disable:4100)
|
||||||
#pragma warning (disable:4514)
|
#pragma warning (disable:4514)
|
||||||
|
|
||||||
/*template <class T>
|
|
||||||
inline void Construct(T *pMemory)
|
|
||||||
{
|
|
||||||
::new(pMemory) T;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline void CopyConstruct(T *pMemory,T const& src)
|
|
||||||
{
|
|
||||||
::new(pMemory) T(src);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class T>
|
|
||||||
inline void Destruct(T *pMemory)
|
|
||||||
{
|
|
||||||
pMemory->~T();
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
memset(pMemory,0xDD,sizeof(T));
|
|
||||||
#endif
|
|
||||||
}*/
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// The CUtlMemory class:
|
// The CUtlMemory class:
|
||||||
// A growable memory class which doubles in size by default.
|
// A growable memory class which doubles in size by default.
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I = int>
|
||||||
template< class T >
|
|
||||||
class CUtlMemory
|
class CUtlMemory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructor, destructor
|
// constructor, destructor
|
||||||
CUtlMemory(int nGrowSize = 0, int nInitSize = 0);
|
CUtlMemory(int nGrowSize = 0, int nInitSize = 0);
|
||||||
CUtlMemory(T* pMemory, int numElements);
|
CUtlMemory(T *pMemory, int numElements);
|
||||||
~CUtlMemory();
|
~CUtlMemory();
|
||||||
|
|
||||||
|
// Set the size by which the memory grows
|
||||||
|
void Init(int nGrowSize = 0, int nInitSize = 0);
|
||||||
|
|
||||||
|
class Iterator_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Iterator_t(I i) : m_index(i) {}
|
||||||
|
I m_index;
|
||||||
|
|
||||||
|
bool operator==(const Iterator_t it) const { return m_index == it.m_index; }
|
||||||
|
bool operator!=(const Iterator_t it) const { return m_index != it.m_index; }
|
||||||
|
};
|
||||||
|
|
||||||
|
Iterator_t First() const { return Iterator_t(IsIdxValid(0) ? 0 : InvalidIndex()); }
|
||||||
|
Iterator_t Next(const Iterator_t &it) const { return Iterator_t(IsIdxValid(it.index + 1) ? it.index + 1 : InvalidIndex()); }
|
||||||
|
I GetIndex(const Iterator_t &it) const { return it.index; }
|
||||||
|
bool IsIdxAfter(I i, const Iterator_t &it) const { return i > it.index; }
|
||||||
|
bool IsValidIterator(const Iterator_t &it) const { return IsIdxValid(it.index); }
|
||||||
|
Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex()); }
|
||||||
|
|
||||||
// element access
|
// element access
|
||||||
T& operator[](int i);
|
T& Element(I i);
|
||||||
T const& operator[](int i) const;
|
T const& Element(I i) const;
|
||||||
T& Element(int i);
|
T& operator[](I i);
|
||||||
T const& Element(int i) const;
|
T const& operator[](I i) const;
|
||||||
|
|
||||||
// Can we use this index?
|
// Can we use this index?
|
||||||
bool IsIdxValid(int i) const;
|
bool IsIdxValid(I i) const;
|
||||||
|
|
||||||
|
// Specify the invalid ('null') index that we'll only return on failure
|
||||||
|
static const I INVALID_INDEX = (I)-1; // For use with COMPILE_TIME_ASSERT
|
||||||
|
static I InvalidIndex() { return INVALID_INDEX; }
|
||||||
|
|
||||||
// Gets the base address (can change when adding elements!)
|
// Gets the base address (can change when adding elements!)
|
||||||
T* Base();
|
T *Base();
|
||||||
T const* Base() const;
|
T const *Base() const;
|
||||||
|
|
||||||
// Attaches the buffer to external memory....
|
// Attaches the buffer to external memory....
|
||||||
void SetExternalBuffer(T* pMemory, int numElements);
|
void SetExternalBuffer(T *pMemory, int numElements);
|
||||||
|
|
||||||
// Size
|
// Size
|
||||||
int NumAllocated() const;
|
int NumAllocated() const;
|
||||||
@ -115,46 +111,54 @@ private:
|
|||||||
EXTERNAL_BUFFER_MARKER = -1,
|
EXTERNAL_BUFFER_MARKER = -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
T* m_pMemory;
|
T *m_pMemory;
|
||||||
int m_nAllocationCount;
|
int m_nAllocationCount;
|
||||||
int m_nGrowSize;
|
int m_nGrowSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// constructor, destructor
|
// constructor, destructor
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
CUtlMemory<T, I>::CUtlMemory(int nGrowSize, int nInitSize) : m_pMemory(0),
|
||||||
CUtlMemory<T>::CUtlMemory(int nGrowSize, int nInitAllocationCount) : m_pMemory(0),
|
m_nAllocationCount(nInitSize), m_nGrowSize(nGrowSize)
|
||||||
m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize)
|
|
||||||
{
|
{
|
||||||
Assert((nGrowSize >= 0) && (nGrowSize != EXTERNAL_BUFFER_MARKER));
|
Assert((nGrowSize >= 0) && (nGrowSize != EXTERNAL_BUFFER_MARKER));
|
||||||
if (m_nAllocationCount)
|
if (m_nAllocationCount)
|
||||||
{
|
{
|
||||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template <class T, class I>
|
||||||
CUtlMemory<T>::CUtlMemory(T* pMemory, int numElements) : m_pMemory(pMemory),
|
CUtlMemory<T, I>::CUtlMemory(T *pMemory, int numElements) : m_pMemory(pMemory),
|
||||||
m_nAllocationCount(numElements)
|
m_nAllocationCount(numElements)
|
||||||
{
|
{
|
||||||
// Special marker indicating externally supplied memory
|
// Special marker indicating externally supplied memory
|
||||||
m_nGrowSize = EXTERNAL_BUFFER_MARKER;
|
m_nGrowSize = EXTERNAL_BUFFER_MARKER;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template <class T, class I>
|
||||||
CUtlMemory<T>::~CUtlMemory()
|
CUtlMemory<T, I>::~CUtlMemory()
|
||||||
{
|
{
|
||||||
Purge();
|
Purge();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class I>
|
||||||
|
void CUtlMemory<T,I>::Init(int nGrowSize, int nInitSize)
|
||||||
|
{
|
||||||
|
Purge();
|
||||||
|
|
||||||
|
m_nGrowSize = nGrowSize;
|
||||||
|
m_nAllocationCount = nInitSize;
|
||||||
|
Assert(nGrowSize >= 0);
|
||||||
|
if (m_nAllocationCount)
|
||||||
|
{
|
||||||
|
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Attaches the buffer to external memory....
|
// Attaches the buffer to external memory....
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
void CUtlMemory<T, I>::SetExternalBuffer(T *pMemory, int numElements)
|
||||||
void CUtlMemory<T>::SetExternalBuffer(T* pMemory, int numElements)
|
|
||||||
{
|
{
|
||||||
// Blow away any existing allocated memory
|
// Blow away any existing allocated memory
|
||||||
Purge();
|
Purge();
|
||||||
@ -166,110 +170,91 @@ void CUtlMemory<T>::SetExternalBuffer(T* pMemory, int numElements)
|
|||||||
m_nGrowSize = EXTERNAL_BUFFER_MARKER;
|
m_nGrowSize = EXTERNAL_BUFFER_MARKER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// element access
|
// element access
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
inline T& CUtlMemory<T, I>::operator[](I i)
|
||||||
inline T& CUtlMemory<T>::operator[](int i)
|
|
||||||
{
|
{
|
||||||
Assert(IsIdxValid(i));
|
Assert(IsIdxValid(i));
|
||||||
return m_pMemory[i];
|
return m_pMemory[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template <class T, class I>
|
||||||
inline T const& CUtlMemory<T>::operator[](int i) const
|
inline T const& CUtlMemory<T, I>::operator[](I i) const
|
||||||
{
|
{
|
||||||
Assert(IsIdxValid(i));
|
Assert(IsIdxValid(i));
|
||||||
return m_pMemory[i];
|
return m_pMemory[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template <class T, class I>
|
||||||
inline T& CUtlMemory<T>::Element(int i)
|
inline T& CUtlMemory<T, I>::Element(I i)
|
||||||
{
|
{
|
||||||
Assert(IsIdxValid(i));
|
Assert(IsIdxValid(i));
|
||||||
return m_pMemory[i];
|
return m_pMemory[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template <class T, class I>
|
||||||
inline T const& CUtlMemory<T>::Element(int i) const
|
inline T const& CUtlMemory<T, I>::Element(I i) const
|
||||||
{
|
{
|
||||||
Assert(IsIdxValid(i));
|
Assert(IsIdxValid(i));
|
||||||
return m_pMemory[i];
|
return m_pMemory[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// is the memory externally allocated?
|
// is the memory externally allocated?
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
bool CUtlMemory<T, I>::IsExternallyAllocated() const
|
||||||
bool CUtlMemory<T>::IsExternallyAllocated() const
|
|
||||||
{
|
{
|
||||||
return m_nGrowSize == EXTERNAL_BUFFER_MARKER;
|
return m_nGrowSize == EXTERNAL_BUFFER_MARKER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class I>
|
||||||
template< class T >
|
void CUtlMemory<T, I>::SetGrowSize(int nSize)
|
||||||
void CUtlMemory<T>::SetGrowSize(int nSize)
|
|
||||||
{
|
{
|
||||||
Assert((nSize >= 0) && (nSize != EXTERNAL_BUFFER_MARKER));
|
Assert((nSize >= 0) && (nSize != EXTERNAL_BUFFER_MARKER));
|
||||||
m_nGrowSize = nSize;
|
m_nGrowSize = nSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Gets the base address (can change when adding elements!)
|
// Gets the base address (can change when adding elements!)
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
inline T *CUtlMemory<T, I>::Base()
|
||||||
inline T* CUtlMemory<T>::Base()
|
|
||||||
{
|
{
|
||||||
return m_pMemory;
|
return m_pMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template <class T, class I>
|
||||||
inline T const* CUtlMemory<T>::Base() const
|
inline T const *CUtlMemory<T, I>::Base() const
|
||||||
{
|
{
|
||||||
return m_pMemory;
|
return m_pMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Size
|
// Size
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
inline int CUtlMemory<T, I>::NumAllocated() const
|
||||||
inline int CUtlMemory<T>::NumAllocated() const
|
|
||||||
{
|
{
|
||||||
return m_nAllocationCount;
|
return m_nAllocationCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class T >
|
template <class T, class I>
|
||||||
inline int CUtlMemory<T>::Count() const
|
inline int CUtlMemory<T, I>::Count() const
|
||||||
{
|
{
|
||||||
return m_nAllocationCount;
|
return m_nAllocationCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Is element index valid?
|
// Is element index valid?
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
inline bool CUtlMemory<T, I>::IsIdxValid(I i) const
|
||||||
inline bool CUtlMemory<T>::IsIdxValid(int i) const
|
|
||||||
{
|
{
|
||||||
return (i >= 0) && (i < m_nAllocationCount);
|
return (((int)i) >= 0) && (((int) i) < m_nAllocationCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Grows the memory
|
// Grows the memory
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
void CUtlMemory<T, I>::Grow(int num)
|
||||||
void CUtlMemory<T>::Grow(int num)
|
|
||||||
{
|
{
|
||||||
Assert(num > 0);
|
Assert(num > 0);
|
||||||
|
|
||||||
if (IsExternallyAllocated())
|
if (IsExternallyAllocated())
|
||||||
{
|
{
|
||||||
// Can't grow a buffer whose memory was externally allocated
|
// Can't grow a buffer whose memory was externally allocated
|
||||||
Assert(0);
|
Assert(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -300,27 +285,24 @@ void CUtlMemory<T>::Grow(int num)
|
|||||||
|
|
||||||
if (m_pMemory)
|
if (m_pMemory)
|
||||||
{
|
{
|
||||||
m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
m_pMemory = (T *)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Makes sure we've got at least this much memory
|
// Makes sure we've got at least this much memory
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
inline void CUtlMemory<T, I>::EnsureCapacity(int num)
|
||||||
inline void CUtlMemory<T>::EnsureCapacity(int num)
|
|
||||||
{
|
{
|
||||||
if (m_nAllocationCount >= num)
|
if (m_nAllocationCount >= num)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (IsExternallyAllocated())
|
if (IsExternallyAllocated())
|
||||||
{
|
{
|
||||||
// Can't grow a buffer whose memory was externally allocated
|
// Can't grow a buffer whose memory was externally allocated
|
||||||
Assert(0);
|
Assert(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -328,30 +310,25 @@ inline void CUtlMemory<T>::EnsureCapacity(int num)
|
|||||||
m_nAllocationCount = num;
|
m_nAllocationCount = num;
|
||||||
if (m_pMemory)
|
if (m_pMemory)
|
||||||
{
|
{
|
||||||
m_pMemory = (T*)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
m_pMemory = (T *)realloc(m_pMemory, m_nAllocationCount * sizeof(T));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_pMemory = (T*)malloc(m_nAllocationCount * sizeof(T));
|
m_pMemory = (T *)malloc(m_nAllocationCount * sizeof(T));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Memory deallocation
|
// Memory deallocation
|
||||||
//-----------------------------------------------------------------------------
|
template <class T, class I>
|
||||||
template< class T >
|
void CUtlMemory<T, I>::Purge()
|
||||||
void CUtlMemory<T>::Purge()
|
|
||||||
{
|
{
|
||||||
if (!IsExternallyAllocated())
|
if (!IsExternallyAllocated())
|
||||||
{
|
{
|
||||||
if (m_pMemory)
|
if (m_pMemory)
|
||||||
{
|
{
|
||||||
free((void*)m_pMemory);
|
free((void *)m_pMemory);
|
||||||
m_pMemory = 0;
|
m_pMemory = 0;
|
||||||
}
|
}
|
||||||
m_nAllocationCount = 0;
|
m_nAllocationCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // UTLMEMORY_H
|
|
||||||
|
1172
regamedll/public/utlrbtree.h
Normal file
1172
regamedll/public/utlrbtree.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user