Permalink
Browse files

BaseEntityOutput is now wrapped on the c++ side.

Added entities.EventActionGenerator.
Added BaseEntityOutput.event_actions that returns an EventActionGenerator.
Added BaseEntity.get_output that returns the BaseEntityOutput instance matching the given name.
  • Loading branch information...
invincibleqc committed Dec 3, 2018
1 parent 678cbd0 commit ac3071f1d80f0b103203b6556156dd4918bc5f60
@@ -3,16 +3,6 @@
binary = server
srv_check = False
[instance_attribute]
[[variant]]
type = POINTER
offset = 0
[[event_action]]
type = POINTER
offset = 20
[function]
[[fire_output]]
identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
@@ -2,16 +2,6 @@
binary = server
[instance_attribute]
[[variant]]
type = POINTER
offset = 0
[[event_action]]
type = POINTER
offset = 20
[function]
[[fire_output]]
identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
@@ -3,16 +3,6 @@
binary = server
srv_check = False
[instance_attribute]
[[variant]]
type = POINTER
offset = 0
[[event_action]]
type = POINTER
offset = 20
[function]
[[fire_output]]
# identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
@@ -2,16 +2,6 @@
binary = server
[instance_attribute]
[[variant]]
type = POINTER
offset = 0
[[event_action]]
type = POINTER
offset = 20
[function]
[[fire_output]]
identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
@@ -2,16 +2,6 @@
binary = server
[instance_attribute]
[[variant]]
type = POINTER
offset = 0
[[event_action]]
type = POINTER
offset = 20
[function]
[[fire_output]]
identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
@@ -2,16 +2,6 @@
binary = server
[instance_attribute]
[[variant]]
type = POINTER
offset = 0
[[event_action]]
type = POINTER
offset = 20
[function]
[[fire_output]]
identifier_linux = _ZN17CBaseEntityOutput10FireOutputE9variant_tP11CBaseEntityS2_f
@@ -154,12 +154,15 @@ def setup_data():
GameConfigObj(SP_DATA_PATH / 'client' / 'CBaseClient.ini'))
import entities
entities.BaseEntityOutput = manager.create_type_from_dict(
entities._BaseEntityOutput = manager.create_type_from_dict(
'BaseEntityOutput',
GameConfigObj(SP_DATA_PATH / 'entity_output' / 'CBaseEntityOutput.ini'))
try:
_fire_output = entities.BaseEntityOutput.fire_output
_fire_output = entities._BaseEntityOutput.fire_output
from _entities import BaseEntityOutput
BaseEntityOutput.fire_output = _fire_output
except AttributeError:
from warnings import warn
warn(
@@ -17,12 +17,14 @@
# Entities
from _entities import BaseEntityGenerator
from _entities import BaseEntityHandle
from _entities import BaseEntityOutput
from _entities import CheckTransmitInfo
from _entities import Collideable
from _entities import Edict
from _entities import EntityGenerator
from _entities import EntityListener
from _entities import EventAction
from _entities import EventActionGenerator
from _entities import GlobalEntityList
from _entities import HandleEntity
from _entities import ServerClassGenerator
@@ -44,6 +46,7 @@
'EntityGenerator',
'EntityListener',
'EventAction',
'EventActionGenerator',
'GlobalEntityList',
'HandleEntity',
'ServerClassGenerator',
@@ -33,6 +33,7 @@
#include "modules/memory/memory_tools.h"
#include "utilities/conversions.h"
#include "entities_entity.h"
#include "entities_generator.h"
// SDK
#include "edict.h"
@@ -246,4 +247,31 @@ class EventActionExt
}
};
//-----------------------------------------------------------------------------
// CBaseEntityOutput wrapper class.
//-----------------------------------------------------------------------------
class CBaseEntityOutputWrapper: public CBaseEntityOutput
{
public:
static CEventAction *get_event_action(CBaseEntityOutputWrapper *pBaseEntityOutput)
{
return pBaseEntityOutput->m_ActionList;
}
static void set_event_action(CBaseEntityOutputWrapper *pBaseEntityOutput, CEventAction *pEventAction)
{
pBaseEntityOutput->m_ActionList = pEventAction;
}
static object get_event_actions(CBaseEntityOutputWrapper *pBaseEntityOutput)
{
return import("_entities").attr("EventActionGenerator")(boost::ref(pBaseEntityOutput->m_ActionList));
}
public:
using CBaseEntityOutput::m_Value;
using CBaseEntityOutput::m_ActionList;
};
#endif // _ENTITIES_H
@@ -95,6 +95,31 @@ CBaseEntity* CBaseEntityWrapper::find_or_create(const char* name)
return entity;
}
CBaseEntityOutputWrapper* CBaseEntityWrapper::get_output(const char* name)
{
// TODO: Caching?
datamap_t* pDatamap = GetDataDescMap();
while (pDatamap)
{
for (int iCurrentIndex=0; iCurrentIndex < pDatamap->dataNumFields; ++iCurrentIndex)
{
typedescription_t& pCurrentDataDesc = pDatamap->dataDesc[iCurrentIndex];
if (pCurrentDataDesc.externalName && strcmp(name, pCurrentDataDesc.externalName) == 0)
{
if (!(pCurrentDataDesc.flags & FTYPEDESC_OUTPUT))
BOOST_RAISE_EXCEPTION(PyExc_TypeError, "'%s' is not a valid output.", name);
return (CBaseEntityOutputWrapper *)((unsigned long)this + TypeDescriptionExt::get_offset(pCurrentDataDesc));
}
}
pDatamap = pDatamap->baseMap;
}
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "Failed to retrieve offset of '%s'.", name);
return NULL;
}
IEntityFactory* CBaseEntityWrapper::get_factory(const char* name)
{
IEntityFactory* pFactory = GetEntityFactoryDictionary()->FindFactory(name);
@@ -48,6 +48,7 @@ using namespace boost::python;
//-----------------------------------------------------------------------------
class CPointer;
class IPhysicsObjectWrapper;
class CBaseEntityOutputWrapper;
//-----------------------------------------------------------------------------
@@ -98,6 +99,7 @@ class CBaseEntityWrapper: public IServerEntity
static CBaseEntity* find(const char* name);
static CBaseEntity* find_or_create(const char* name);
CBaseEntityOutputWrapper* get_output(const char* name);
static IEntityFactory* get_factory(const char* name);
IEntityFactory* get_factory();
void remove();
@@ -32,6 +32,7 @@
#include "utilities/conversions.h"
#include "entities_entity.h"
#include "modules/physics/physics.h"
#include "entities.h"
//-----------------------------------------------------------------------------
@@ -451,6 +452,14 @@ void export_base_entity(scope _entity)
":rtype: DataMap"
);
BaseEntity.def("get_output",
&CBaseEntityWrapper::get_output,
"Return the output instance matching the given name.\n\n"
":param str name: The name of the output.\n"
":rtype: BaseEntityOutput",
reference_existing_object_policy()
);
BaseEntity.add_property("factory",
make_function(GET_METHOD(IEntityFactory*, CBaseEntityWrapper, get_factory), reference_existing_object_policy()),
"Return the entity's factory.\n\n"
@@ -33,6 +33,7 @@
#include "utilities/conversions.h"
#include "toolframework/itoolentity.h"
#include "eiface.h"
#include "game/server/entityoutput.h"
//-----------------------------------------------------------------------------
@@ -232,3 +233,29 @@ ServerClass* CServerClassGenerator::getNext()
m_pCurrentServerClass = m_pCurrentServerClass->m_pNext;
return result;
}
// ----------------------------------------------------------------------------
// CEventActionGenerator
// ----------------------------------------------------------------------------
CEventActionGenerator::CEventActionGenerator( PyObject* self, CEventAction *pFirstEventAction ):
IPythonGenerator<CEventAction>(self)
{
m_pCurrentEventAction = pFirstEventAction;
}
CEventActionGenerator::CEventActionGenerator( PyObject* self, const CEventActionGenerator& rhs ):
IPythonGenerator<CEventAction>(self)
{
m_pCurrentEventAction = rhs.m_pCurrentEventAction;
}
CEventAction* CEventActionGenerator::getNext()
{
if (!m_pCurrentEventAction)
return NULL;
CEventAction* result = m_pCurrentEventAction;
m_pCurrentEventAction = m_pCurrentEventAction->m_pNext;
return result;
}
@@ -35,6 +35,7 @@
#include "utilities/baseentity.h"
#include "entities_entity.h"
#include "eiface.h"
#include "game/server/entityoutput.h"
// ----------------------------------------------------------------------------
// Forward declaration.
@@ -112,4 +113,24 @@ class CServerClassGenerator: public IPythonGenerator<ServerClass>
BOOST_SPECIALIZE_HAS_BACK_REFERENCE(CServerClassGenerator)
// ----------------------------------------------------------------------------
// CEventActionGenerator
// ----------------------------------------------------------------------------
class CEventActionGenerator: public IPythonGenerator<CEventAction>
{
public:
CEventActionGenerator(PyObject* self, CEventAction *pFirstEventAction);
CEventActionGenerator(PyObject* self, const CEventActionGenerator& rhs);
virtual ~CEventActionGenerator() {}
protected:
virtual CEventAction* getNext();
private:
CEventAction* m_pCurrentEventAction;
};
BOOST_SPECIALIZE_HAS_BACK_REFERENCE(CEventActionGenerator)
#endif // _ENTITIES_GENERATOR_H
@@ -60,6 +60,8 @@ void export_baseentity_generator(scope);
void export_server_class_generator(scope);
void export_collideable(scope);
void export_event_action(scope);
void export_event_action_generator(scope);
void export_base_entity_output(scope);
//-----------------------------------------------------------------------------
@@ -82,6 +84,8 @@ DECLARE_SP_MODULE(_entities)
export_server_class_generator(_entities);
export_collideable(_entities);
export_event_action(_entities);
export_event_action_generator(_entities);
export_base_entity_output(_entities);
}
@@ -664,3 +668,56 @@ void export_event_action(scope _entities)
EventAction ADD_MEM_TOOLS(CEventAction);
}
//-----------------------------------------------------------------------------
// Exports CEventActionGenerator.
//-----------------------------------------------------------------------------
void export_event_action_generator(scope _entities)
{
class_<CEventActionGenerator>("EventActionGenerator", init<CEventAction *>())
.def("__iter__",
&CEventActionGenerator::iter,
"Returns the iterable object."
)
.def("__next__",
&CEventActionGenerator::next,
"Returns the next valid instance.",
reference_existing_object_policy()
)
;
}
//-----------------------------------------------------------------------------
// Exports CBaseEntityOutput.
//-----------------------------------------------------------------------------
void export_base_entity_output(scope _entities)
{
class_<CBaseEntityOutputWrapper, boost::noncopyable> BaseEntityOutput("BaseEntityOutput", no_init);
BaseEntityOutput.def_readwrite(
"variant",
&CBaseEntityOutputWrapper::m_Value,
"Current variant value for this output."
);
BaseEntityOutput.add_property(
"event_action",
make_function(&CBaseEntityOutputWrapper::get_event_action, reference_existing_object_policy()),
&CBaseEntityOutputWrapper::set_event_action,
"Linked list of registered event actions for this output."
);
BaseEntityOutput.add_property(
"event_actions",
&CBaseEntityOutputWrapper::get_event_actions,
"Returns a generator iterating over registered event actions for this output."
);
BaseEntityOutput.NOT_IMPLEMENTED("fire_output");
BaseEntityOutput ADD_MEM_TOOLS(CBaseEntityOutputWrapper);
}

0 comments on commit ac3071f

Please sign in to comment.