FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added GetEntityFactoryDictionary() · jaredballou/Source.Python@b90ce60 · GitHub

Repository navigation

Commit b90ce60

Browse files
committed
Added GetEntityFactoryDictionary()
This will import factory_dictionary only once
1 parent e060bb1 commit b90ce60

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎src/core/modules/entities/entities_entity.cpp‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@
3737
#include ENGINE_INCLUDE_PATH(entities_datamaps_wrap.h)
3838

3939

40+
// ============================================================================
41+
// >> GetEntityFactoryDictionary
42+
// ============================================================================
43+
// TODO: Move this to entities_factories.cpp
44+
CEntityFactoryDictionary* GetEntityFactoryDictionary()
45+
{
46+
static CEntityFactoryDictionary* entity_factory_dictionary = NULL;
47+
if (entity_factory_dictionary != NULL)
48+
return entity_factory_dictionary;
49+
50+
entity_factory_dictionary = extract<CEntityFactoryDictionary*>(
51+
boost::python::import("entities.factories").attr("factory_dictionary"));
52+
53+
if (!entity_factory_dictionary)
54+
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "factory_dictionary is NULL.")
55+
56+
return entity_factory_dictionary;
57+
}
58+
59+
4060
// ============================================================================
4161
// >> CBaseEntityWrapper
4262
// ============================================================================
@@ -86,12 +106,7 @@ CBaseEntity* CBaseEntityWrapper::find_or_create(const char* name)
86106

87107
IEntityFactory* CBaseEntityWrapper::get_factory(const char* name)
88108
{
89-
IEntityFactoryDictionary* factories = extract<CEntityFactoryDictionary*>(
90-
boost::python::import("entities.factories").attr("factory_dictionary"));
91-
if (!factories)
92-
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "factory_dictionary is NULL.")
93-
94-
IEntityFactory* pFactory = factories->FindFactory(name);
109+
IEntityFactory* pFactory = GetEntityFactoryDictionary()->FindFactory(name);
95110
if (!pFactory)
96111
BOOST_RAISE_EXCEPTION(PyExc_ValueError, "'%s' is not a valid entity class name.", name)
97112

‎src/core/modules/entities/entities_factories.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class CEntityFactoryDictionary : public IEntityFactoryDictionary
4646
CUtlDict<IEntityFactory *, unsigned short> m_Factories;
4747
};
4848

49+
CEntityFactoryDictionary* GetEntityFactoryDictionary();
50+
4951

5052
//-----------------------------------------------------------------------------
5153
// CEntityFactoryDictionary extension class.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL