Skip to content

hot_reload

FreeBodyEngine.core.files.hot_reload #

Dev-mode-only hot reload: a path-keyed registry of live Texture/Material/ Sprite objects (each of loaders/texture.py, loaders/material.py, and loaders/sprite.py registers what it creates here, and returns the cached object on a repeat load_file() for the same path instead of creating a second, independent instance - hot reload only has anything to update in place if every consumer of a given asset path is actually sharing one object), and the FILE_CHANGE -> reload dispatch DevFileSystem wires up to its FileWatcher.

Reloading always mutates the SAME live object in place (same GL texture id, same Shader's GL program, same Material/Sprite Python object) rather than creating a new one - nothing tracks who's holding a reference to a loaded asset, so an in-place update is the only way an edit becomes visible without restarting the game.

Never active outside dev mode (is_enabled() gates on the DEVMODE flag) - a release build's AssetPackFileSystem has no FileWatcher and never calls into this module at all, but the loaders guard on is_enabled() too rather than just "am I DevFileSystem", so the cache doesn't change a release build's "always a fresh object" behavior even if that ever became reachable another way.

MATERIAL = 'material' module-attribute #

SPRITE = 'sprite' module-attribute #

TEXTURE = 'texture' module-attribute #

get_cached(path, kind) #

Returns the live object at path if one was already registered as this same kind, else None (a fresh load is needed - either nothing's been loaded from path yet, or it was loaded as a different kind, e.g. a texture stack sharing an image path with an ordinary sprite texture).

is_enabled() #

Whether hot reload's cache/registry should be used at all - gates on the DEVMODE flag, since a release build has no FileWatcher to ever trigger a reload from.

register(path, kind, obj) #

Records obj (as the given kind - TEXTURE/MATERIAL/SPRITE) as the live object loaded from path, so a later edit to path can find and mutate it in place. Overwrites any previous registration for path.

reload_asset(path) #

Called for every FILE_CHANGE - a no-op for any path that was never loaded (or loaded but never registered here, e.g. a texture stack's layers), which is most files in an asset directory on most changes.

reload_shader_source(path) #

Called for every FILE_CHANGE too, separately from reload_asset(): a changed .fbvert/.fbfrag/.fbgeom isn't itself a registered asset (it has no single Material of its own - the same shader file is very commonly shared across many materials, e.g. every material using the engine's default_shader.fb{vert,frag}), so this instead recompiles every currently registered Material whose shader was built from this exact path, in place, one by one.