entitywrap

This commit is contained in:
nullifiedcat 2017-03-18 14:37:46 +03:00
parent 7d0af8c413
commit 77ca6d3145
2 changed files with 45 additions and 0 deletions

22
src/entitywrap.cpp Normal file
View File

@ -0,0 +1,22 @@
/*
* entitywrap.cpp
*
* Created on: Mar 18, 2017
* Author: nullifiedcat
*/
#include "entitywrap.h"
#include "common.h"
EntityWrapper::EntityWrapper(int idx) : idx(idx) {}
bool EntityWrapper::good() const {
return idx < g_IEntityList->GetHighestEntityIndex() && g_IEntityList->GetClientEntity(idx);
}
IClientEntity* EntityWrapper::operator ->() const {
IClientEntity* ret = g_IEntityList->GetClientEntity(idx);
if (!ret) throw std::runtime_error("referencing null entity");
return ret;
}

23
src/entitywrap.h Normal file
View File

@ -0,0 +1,23 @@
/*
* entitywrap.h
*
* Created on: Mar 18, 2017
* Author: nullifiedcat
*/
#ifndef ENTITYWRAP_H_
#define ENTITYWRAP_H_
class IClientEntity;
class EntityWrapper {
public:
EntityWrapper(int idx);
bool good() const;
IClientEntity* operator->() const;
const int idx;
};
#endif /* ENTITYWRAP_H_ */