Skip to content

Commit f730a62

Browse files
committed
Improved some Entity's methods by avoiding repeated attribute retrievals.
1 parent b9e8826 commit f730a62

File tree

1 file changed

+14
-7
lines changed
  • addons/source-python/packages/source-python/entities

1 file changed

+14
-7
lines changed

addons/source-python/packages/source-python/entities/_base.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,11 @@ def get_model(self):
374374
``None`` if the entity has no model.
375375
:rtype: Model
376376
"""
377-
if not self.model_name:
377+
model_name = self.model_name
378+
if not model_name:
378379
return None
379380

380-
return Model(self.model_name)
381+
return Model(model_name)
381382

382383
def set_model(self, model):
383384
"""Set the entity's model to the given model.
@@ -449,18 +450,21 @@ def delay(
449450
The delay instance.
450451
:rtype: Delay
451452
"""
453+
# Get the index of the entity
454+
index = self.index
455+
452456
# TODO: Ideally, we want to subclass Delay and cleanup on cancel() too
453457
# in case the caller manually cancel the returned Delay.
454458
def _callback(*args, **kwargs):
455459
"""Called when the delay is executed."""
456460
# Remove the delay from the global dictionary...
457-
_entity_delays[self.index].remove(delay)
461+
_entity_delays[index].remove(delay)
458462

459463
# Was this the last pending delay for the entity?
460-
if not _entity_delays[self.index]:
464+
if not _entity_delays[index]:
461465

462466
# Remove the entity from the dictionary...
463-
del _entity_delays[self.index]
467+
del _entity_delays[index]
464468

465469
# Call the callback...
466470
callback(*args, **kwargs)
@@ -469,7 +473,7 @@ def _callback(*args, **kwargs):
469473
delay = Delay(delay, _callback, args, kwargs, cancel_on_level_end)
470474

471475
# Add the delay to the dictionary...
472-
_entity_delays[self.index].add(delay)
476+
_entity_delays[index].add(delay)
473477

474478
# Return the delay instance...
475479
return delay
@@ -610,8 +614,11 @@ def is_in_solid(
610614
:class:`BaseEntity` instances that are ignored by the ray.
611615
:rtype: bool
612616
"""
617+
# Get the entity's origin
618+
origin = self.origin
619+
613620
# Get a Ray object of the entity physic box
614-
ray = Ray(self.origin, self.origin, self.mins, self.maxs)
621+
ray = Ray(origin, origin, self.mins, self.maxs)
615622

616623
# Get a new GameTrace instance
617624
trace = GameTrace()

0 commit comments

Comments
 (0)