Refactoring item_airbox

This commit is contained in:
s1lent 2017-10-14 13:20:23 +07:00 committed by Dmitry Novikov
parent 96030a48ca
commit 8f913b1623
4 changed files with 30 additions and 24 deletions

View File

@ -38,30 +38,37 @@ void CItemAirBox::Spawn()
if (!m_iszSpriteName.IsNull())
{
m_pSprite = CSprite::SpriteCreate(m_iszSpriteName, pev->origin, FALSE);
m_pSprite->SetTransparency(m_rendermode, m_rendercolor.x, m_rendercolor.y, m_rendercolor.z, m_renderamt, m_renderfx);
m_pSprite->SetScale(m_scale);
m_pSprite->SetAttachment(edict(), pev->body);
m_pSprite->pev->spawnflags |= SF_SPRITE_STARTON;
m_hSprite.Remove();
m_pSprite->pev->framerate = m_frameRate;
m_pSprite->TurnOn();
m_hSprite = CSprite::SpriteCreate(m_iszSpriteName, pev->origin, FALSE);
m_hSprite->SetTransparency(m_rendermode, m_rendercolor.x, m_rendercolor.y, m_rendercolor.z, m_renderamt, m_renderfx);
m_hSprite->SetScale(m_scale);
m_hSprite->SetAttachment(edict(), pev->body);
m_hSprite->pev->spawnflags |= SF_SPRITE_STARTON;
m_hSprite->pev->framerate = m_frameRate;
m_hSprite->TurnOn();
}
if (m_flyup > 0 && m_delay > 0.01)
if (m_flyup > 0 && m_delay > 0.01f)
{
SetThink(&CItemAirBox::MoveUp);
pev->nextthink = gpGlobals->time + 1.0f;
}
}
void CItemAirBox::OnDestroy()
{
m_hSprite.Remove();
}
void CItemAirBox::Touch(CBaseEntity *pOther)
{
CArmoury::Touch(pOther);
// airbox was picked up, so sprite to turn off
if ((pev->effects & EF_NODRAW) == EF_NODRAW) {
m_pSprite->TurnOff();
m_hSprite->TurnOff();
}
}
@ -139,14 +146,3 @@ void CItemAirBox::MoveUp()
m_flyup = -m_flyup;
pev->nextthink = gpGlobals->time + m_delay;
}
void CItemAirBox::OnDestroy()
{
if (m_pSprite)
{
m_pSprite->SetTouch(nullptr);
m_pSprite->SetThink(&CBaseEntity::SUB_Remove);
m_pSprite->pev->nextthink = gpGlobals->time + 0.1f;
m_pSprite = nullptr;
}
}

View File

@ -42,7 +42,7 @@ protected:
void EXPORT MoveUp();
private:
CSprite *m_pSprite;
EntityHandle<CSprite> m_hSprite;
float m_flyup;
float m_delay;

View File

@ -28,8 +28,6 @@
#pragma once
#include "precompiled.h"
#define SF_SETORIGIN_CONST_UPDATE BIT(0) // The entity will constantly update position if set
#define SF_SETORIGIN_REMOVEFIRE BIT(2) // The entity will be removed after firing.
@ -56,7 +54,6 @@ const int MAX_SETORIGIN_ENTITIES = 64;
class CTriggerSetOrigin: public CBaseDelay {
public:
void Spawn() {};
void KeyValue(KeyValueData *pkvd);
int ObjectCaps() { return CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);

View File

@ -46,6 +46,7 @@ public:
edict_t *Get() const;
edict_t *Set(edict_t *pEdict);
void Remove();
bool IsValid() const;
int GetSerialNumber() const;
@ -133,6 +134,18 @@ inline edict_t *EntityHandle<T>::Set(edict_t *pEdict)
return pEdict;
}
template <typename T>
void EntityHandle<T>::Remove()
{
if (IsValid())
{
UTIL_Remove(*this);
}
m_edict = nullptr;
m_serialnumber = 0;
}
// Returns whether this handle is valid.
template <typename T>
inline bool EntityHandle<T>::IsValid() const