FreeBodyEngine
FreeBodyEngine
#
FreeBodyEngine created by ollie80
ALLOW_DISK_WRITE = 'ALLOW_DISK_WRITE'
module-attribute
#
DEFAULT_NAME = 'FREEBODY_PROJECT'
module-attribute
#
DEVMODE = 'DEVMODE'
module-attribute
#
DLL_DIRECTORY = None
module-attribute
#
FORCE_RENDERER = 'FORCE_RENDERER'
module-attribute
#
HEADLESS = 'HEADLESS'
module-attribute
#
MAX_FPS = 'MAX_FPS'
module-attribute
#
MAX_TPS = 'MAX_TPS'
module-attribute
#
NAME = 'NAME'
module-attribute
#
PRE_FLAGS = {}
module-attribute
#
PROFILER = 'PROFILER'
module-attribute
#
PROJECT_PATH = 'PROJECT_PATH'
module-attribute
#
QUIT = 'QUIT'
module-attribute
#
SUPRESS_ERRORS = 'SUPRESS_ERRORS'
module-attribute
#
SUPRESS_LOGS = 'SUPRESS_LOGS'
module-attribute
#
SUPRESS_WARNINGS = 'SUPRESS_WARNINGS'
module-attribute
#
TEST_WINDOW = 'TEST_WINDOW'
module-attribute
#
add_scene(scene)
#
Registers scene with the scene_manager service. Shorthand for
get_service('scene_manager').add_scene(scene).
cooldown(seconds)
#
Decorator to add a cooldown to functions.
create_cursor(image)
#
Creates a platform cursor from image via the active window backend, or a dummy Cursor in headless mode.
delta()
#
Get deltatime for the current frame in seconds.
emit_event(name, *callback_args, **callback_kwargs)
#
Emits event name, invoking every callback registered on it with the
given arguments. A no-op if the "event" service isn't registered.
error(msg)
#
Throws an error. See warning()'s own docstring for why this falls
back to plain print() before a Main/'logger' service exists.
fbquit()
#
Requests an orderly engine shutdown by emitting the QUIT event.
get_action_pressed(name)
#
Returns whether the action name is currently pressed.
get_action_released(name)
#
Returns whether the action name was released this frame.
get_action_strength(name)
#
Returns the action name's current analog strength.
get_action_vector(neg_x, pos_x, neg_y, pos_y)
#
Get a vector from the strengths of four actions.
get_flag(key, default)
#
Gets the value of global flag key, or default if it isn't set.
Works both before and after init(): before a Main exists, flags live
in the temporary PRE_FLAGS store; afterwards they're read from the
live Main.flags, which is seeded from PRE_FLAGS on startup.
get_main(throw_error=True)
#
Returns the global Main instance.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
if no |
get_mouse()
#
Returns the registered "mouse" service.
get_platform()
#
Returns the identifier for the current host platform, or None if it isn't one of the ones recognized here (other platforms - e.g. iOS, console - aren't handled yet).
sys.platform reports "emscripten" under Pyodide (a browser tab
running this engine compiled to WASM - see core/window/web.py) -
normalized to "web" here so the rest of the engine (graphics.
get_renderer(), core/window/init.py's get_window()) has one
consistent name to branch on instead of every call site needing to
know the raw sys.platform string Pyodide happens to report.
Android needs its own check before the plain sys.platform one,
and unconditionally - not gated behind any particular sys.platform
value. This used to check sys.platform == 'linux' first, on the
assumption that python-for-android's CPython build always reports
plain "linux" there (a real Linux kernel underneath, with no
Android-specific value at all) - true for some p4a Python recipe
versions, but NOT a safe assumption in general (confirmed the hard
way: PyOpenGL's own platform auto-detection still picked the desktop
GLX backend over the EGL one on a real device, because this exact
gate made get_platform() return None instead of 'android' there,
which means sys.platform was actually something else). Checking
ANDROID_ARGUMENT on its own, with no precondition, is both simpler
and correct regardless of whatever string sys.platform happens to
report on a given p4a/CPython combination - it's also exactly what
Kivy itself does, the same precedent this check was already following.
get_service(name)
#
Returns the registered service named name, or None if no such service exists.
get_service_locator()
#
Returns the engine's global ServiceLocator.
get_time()
#
Returns the current engine time in seconds.
init()
#
Initialise FreeBodyEngine
log(*msg)
#
Logs any number of messages to the console.
main_exists()
#
Returns whether the global Main instance has been created yet.
physics_cooldown(seconds)
#
Decorator to add a cooldown to physics based functions.
physics_delta()
#
Returns the fixed physics timestep in seconds (see UpdateCoordinator.physics_timestep).
register_event(name, *categories)
#
Registers a new event named name, filed under categories.
A no-op if the "event" service isn't registered yet.
register_event_callback(event_name, callable)
#
Registers callable to be invoked whenever event_name is emitted.
A no-op if the "event" service isn't registered yet.
register_event_category(name, priority=0)
#
Registers a new event category named name at the given priority.
A no-op if the "event" service isn't registered yet.
register_service(service)
#
Registers service with the global service locator, making it
retrievable afterwards via get_service(service.name).
register_service_update(phase, callback, priority=0)
#
Registers callback to run every phase of the main update loop.
Higher priority callbacks run first within the same phase - see
UpdateCoordinator.register.
remove_scene(name)
#
Unregisters the scene named name. Shorthand for
get_service('scene_manager').remove_scene(name).
service_exists(name)
#
Returns whether a service named name is currently registered.
set_cursor(cursor)
#
Sets the active window's cursor to cursor; warns and does nothing in headless mode.
set_flag(key, value)
#
Sets global flag key to value.
Before init() creates a Main, this writes into the temporary
PRE_FLAGS store (later consumed by Main.__init__) instead of a live
GlobalFlags, so flags can be set ahead of engine startup.
set_scene(name)
#
Makes the scene named name the active one. Shorthand for
get_service('scene_manager').set_scene(name).
unregister_event(name)
#
Unregisters the event named name. A no-op if the "event" service isn't registered.
unregister_event_callback(event_name, callable)
#
Unregisters callable from event_name, previously registered with
register_event_callback. A no-op if the "event" service isn't registered.
unregister_event_category(name)
#
Unregisters the event category named name. A no-op if the "event" service isn't registered.
unregister_service(name)
#
Unregisters and destroys the service registered under name.
unregister_service_update(phase, callback)
#
Removes a callback previously registered for phase with register_service_update.
warning(msg)
#
Raises an warning.
Falls back to a plain print() if no Main/'logger' service exists
yet - a module can legitimately call this from its own top-level
import-time code (e.g. utils.fbnjit()'s "numba isn't installed"
notice, hit whenever a module using it is imported anywhere before
numba-dependent code runs, not just after fb.init()), and get_service()
itself requires a live Main to even ask whether 'logger' is
registered. This used to crash instead (AttributeError on
None.warning(...), since get_service() returns None rather than
raising when the service or the Main it needs doesn't exist) -
surfaced by the web platform specifically (see core/tilemap/
renderer.py's own comment: numba is never installed there, so this
fallback path - previously untested on any platform that has numba -
ran for the first time and crashed the whole import chain instead of
just printing a warning like every other platform silently never
exercised this line to notice).