Skip to content

utils

FreeBodyEngine.utils #

HAS_NUMBA = True module-attribute #

abstractmethod(func) #

Decorator marking a method as abstract: the decorated method always raises NotImplementedError when called, naming both the method and the instance's class - func's own body is never executed, regardless of what it contains.

add(obj) #

add(node: Node)
add(element: UIElement)

Adds a object to the correct service. e.g. giving a Node2D object would add it to the current scene in the scene manager service.

fbjit(signature=None, *args, **kwargs) #

JIT-compiles the decorated function with numba.jit(signature, **kwargs) when numba is installed; otherwise warns once and falls back to the no-op decorator below, which returns the function unchanged - lets call sites use @fbjit unconditionally regardless of whether numba is available.

fbnjit(*args, **kwargs) #

JIT-compiles the decorated function in nopython mode via numba.njit(*args, **kwargs) when numba is installed; otherwise warns once and falls back to the no-op decorator below, which returns the function unchanged.

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.

load_dlls() #

Locates this engine's bundled native library directory for the current platform/architecture (under sys._MEIPASS when running as a PyInstaller-frozen build, else next to the installed package) and adds it to the OS's dynamic library search path (os.add_dll_directory on Windows, DYLD_LIBRARY_PATH on macOS, LD_LIBRARY_PATH on Linux). Returns the resolved directory.

Raises:

Type Description
RuntimeError

if the host platform isn't win32/darwin/linux/web.

FileNotFoundError

if the expected library directory doesn't exist.