Skip to content

Commit

Permalink
docs: move attribute explanation to relevant function docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoran56 committed May 28, 2024
1 parent 847a009 commit 62b9650
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
6 changes: 0 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ The World context
.. autofunction:: esper.clear_cache
.. autofunction:: esper.clear_dead_entities

Attributes
----------
.. currentmodule:: esper
.. autoattribute:: current_world
.. autoattribute:: process_times

Events
------
For convenience, **esper** includes functionality for
Expand Down
23 changes: 8 additions & 15 deletions esper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,8 @@ def process(self, *args: _Any, **kwargs: _Any) -> None:
_processors: _List[Processor] = []
event_registry: _Dict[str, _Any] = {}
process_times: _Dict[str, int] = {}
"""A dictionary containing Processor timings.
After each call to :py:func:`esper.timed_process`, the class name
and elapsed call time (in millisections) for each Processor will
be recorded in this dictionary. The times are replaced with each
call.
"""
current_world: str = "default"
"""The name of the currently active World context.

This attribute can be checked to confirm the name of the
currently active World context. Modifying this has no effect;
to switch Worlds, use the :py:func:`~switch_world` function.
"""

# {context_name: (entity_count, components, entities, dead_entities,
# comp_cache, comps_cache, processors, process_times, event_registry)}
Expand Down Expand Up @@ -513,7 +501,8 @@ def timed_process(*args: _Any, **kwargs: _Any) -> None:
This function is identical to :py:func:`esper.process`, but
it additionally records the elapsed time of each processor
call (in milliseconds) in the`esper.process_times` dictionary.
(in milliseconds) in the :py:attr:`~process_times` dictionary
after each call.
"""
clear_dead_entities()
for processor in _processors:
Expand Down Expand Up @@ -548,13 +537,17 @@ def switch_world(name: str) -> None:
Esper can have one or more "Worlds". Each World is a dedicated
context, and does not share Entities, Components, events, etc.
Some game designs can benefit from using a dedicated World
for each scene. For other designs, a single World may
be sufficient.
for each scene. For other designs, a single World may be sufficient.
This function will allow you to create and switch between as
many World contexts as required. If the requested name does not
exist, a new context is created automatically with that name.
The name of the currently active World context can be checked
at any time by examining the :py:attr:`esper.current_world`.
This attribute gets updated whenever you switch Worlds, and
modifying it has no effect.
.. note:: At startup, a "default" World context is active.
"""
if name not in _context_map:
Expand Down

0 comments on commit 62b9650

Please sign in to comment.