|
| 1 | +== Core Concepts |
| 2 | + |
| 3 | +This chapter provides an overview of FIFE's architecture and how the major subsystems connect. |
| 4 | +Understanding the core architecture helps when working with maps, rendering, input, and other engine features. |
| 5 | + |
| 6 | +=== Engine |
| 7 | + |
| 8 | +The `Engine` class is the central entry point to all engine subsystems. |
| 9 | +It initializes, manages, and provides access to all major components. |
| 10 | + |
| 11 | +==== Initialization |
| 12 | + |
| 13 | +Before using any engine features, the `Engine` must be initialized: |
| 14 | + |
| 15 | +[source,python] |
| 16 | +---- |
| 17 | +engine = fife.Engine() |
| 18 | +engine.init() |
| 19 | +---- |
| 20 | + |
| 21 | +During initialization, the engine creates and connects the following subsystems: |
| 22 | + |
| 23 | +[horizontal] |
| 24 | +*SoundManager*:: Handles audio playback |
| 25 | +*EventManager*:: Manages input and game events |
| 26 | +*TimeManager*:: Controls timing and frame rate |
| 27 | +*Model*:: Contains the game world (maps, layers, objects) |
| 28 | +*VFS*:: Virtual file system for loading assets |
| 29 | +*RenderBackend*:: Graphics rendering (SDL or OpenGL) |
| 30 | +*IGUIManager*:: GUI system integration |
| 31 | + |
| 32 | +==== Game Loop |
| 33 | + |
| 34 | +FIFE uses a pump-based game loop. Call `pump()` repeatedly in your main loop: |
| 35 | + |
| 36 | +[source,python] |
| 37 | +---- |
| 38 | +# Initialize engine pumping |
| 39 | +engine.initializePumping() |
| 40 | +
|
| 41 | +# Main game loop |
| 42 | +running = True |
| 43 | +while running: |
| 44 | + engine.pump() # Process one frame |
| 45 | + # Update game logic here |
| 46 | +
|
| 47 | +# Clean up |
| 48 | +engine.finalizePumping() |
| 49 | +engine.destroy() |
| 50 | +---- |
| 51 | + |
| 52 | +The `pump()` method processes all pending events, updates the model, and renders the frame. |
| 53 | + |
| 54 | +==== Accessing Subsystems |
| 55 | + |
| 56 | +The `Engine` class provides getter methods for each subsystem: |
| 57 | + |
| 58 | +[source,python] |
| 59 | +---- |
| 60 | +sound_manager = engine.getSoundManager() |
| 61 | +event_manager = engine.getEventManager() |
| 62 | +time_manager = engine.getTimeManager() |
| 63 | +model = engine.getModel() |
| 64 | +vfs = engine.getVFS() |
| 65 | +render_backend = engine.getRenderBackend() |
| 66 | +gui_manager = engine.getGuiManager() |
| 67 | +---- |
| 68 | + |
| 69 | +=== Engine Settings |
| 70 | + |
| 71 | +The `EngineSettings` class controls initialization parameters before calling `engine.init()`. |
| 72 | + |
| 73 | +==== Display Settings |
| 74 | + |
| 75 | +[source,python] |
| 76 | +---- |
| 77 | +settings = engine.getSettings() |
| 78 | +
|
| 79 | +# Screen dimensions |
| 80 | +settings.setScreenWidth(1024) |
| 81 | +settings.setScreenHeight(768) |
| 82 | +
|
| 83 | +# Display mode |
| 84 | +settings.setFullScreen(True) |
| 85 | +settings.setBitsPerPixel(32) |
| 86 | +settings.setVSync(True) |
| 87 | +settings.setRefreshRate(60) |
| 88 | +
|
| 89 | +# Render backend |
| 90 | +settings.setRenderBackend("OpenGL") # or "SDL" |
| 91 | +---- |
| 92 | + |
| 93 | +==== Window Settings |
| 94 | + |
| 95 | +[source,python] |
| 96 | +---- |
| 97 | +settings.setWindowTitle("My Game") |
| 98 | +settings.setWindowIcon("icon.png") |
| 99 | +---- |
| 100 | + |
| 101 | +==== Audio Settings |
| 102 | + |
| 103 | +[source,python] |
| 104 | +---- |
| 105 | +settings.setInitialVolume(0.8) # 80% volume |
| 106 | +---- |
| 107 | + |
| 108 | +==== OpenGL-Specific Settings |
| 109 | + |
| 110 | +[source,python] |
| 111 | +---- |
| 112 | +# Texture filtering |
| 113 | +settings.setGLTextureFiltering("nearest") # or "linear" |
| 114 | +
|
| 115 | +# Texture compression |
| 116 | +settings.setGLCompressImages(True) |
| 117 | +
|
| 118 | +# Mipmapping |
| 119 | +settings.setGLUseMipmapping(True) |
| 120 | +
|
| 121 | +# Framebuffer effects |
| 122 | +settings.setGLUseFramebuffer(True) |
| 123 | +---- |
| 124 | + |
| 125 | +=== Subsystem Overview |
| 126 | + |
| 127 | +FIFE's architecture consists of several interconnected subsystems: |
| 128 | + |
| 129 | +[horizontal] |
| 130 | +*Model*:: The game world containing maps, layers, and instances. See xref:chapter07[Model and Instances]. |
| 131 | +*View*:: Rendering pipeline including cameras and renderers. See xref:chapter06[Rendering]. |
| 132 | +*Video*:: Low-level graphics backend (SDL/OpenGL). |
| 133 | +*Audio*:: Sound management and playback. See xref:chapter09[Audio]. |
| 134 | +*EventChannel*:: Input handling and event distribution. See xref:chapter08[Input and Events]. |
| 135 | +*GUI*:: Graphical user interface integration. See xref:chapter10[GUI]. |
| 136 | +*Pathfinder*:: Pathfinding and movement. See xref:chapter11[Pathfinding]. |
| 137 | +*VFS*:: Virtual file system for asset loading. See xref:chapter12[Virtual Filesystem]. |
| 138 | + |
| 139 | +=== Resource Managers |
| 140 | + |
| 141 | +FIFE uses resource managers to cache and manage loaded assets: |
| 142 | + |
| 143 | +[horizontal] |
| 144 | +*ImageManager*:: Caches loaded images |
| 145 | +*AnimationManager*:: Caches animations |
| 146 | +*SoundClipManager*:: Caches sound clips |
| 147 | + |
| 148 | +These managers implement lazy loading, so resources are loaded only when first accessed. |
| 149 | + |
| 150 | +[source,python] |
| 151 | +---- |
| 152 | +image_manager = engine.getImageManager() |
| 153 | +animation_manager = engine.getAnimationManager() |
| 154 | +sound_clip_manager = engine.getSoundClipManager() |
| 155 | +---- |
| 156 | + |
| 157 | +=== Time Management |
| 158 | + |
| 159 | +The `TimeManager` provides timing information for frame-rate independent updates: |
| 160 | + |
| 161 | +[source,python] |
| 162 | +---- |
| 163 | +time_manager = engine.getTimeManager() |
| 164 | +dt = time_manager.getTimeDelta() # Time since last frame in seconds |
| 165 | +---- |
| 166 | + |
| 167 | +Use `dt` to scale movement and animation speeds for consistent behavior regardless of frame rate. |
| 168 | + |
| 169 | +=== Log Modules |
| 170 | + |
| 171 | +FIFE uses a hierarchical logging system. Each subsystem is a log module: |
| 172 | + |
| 173 | +- `LM_AUDIO` - Audio subsystem |
| 174 | +- `LM_MODEL` - Game model |
| 175 | +- `LM_VIDEO` - Video/rendering |
| 176 | +- `LM_VIEW` - View system |
| 177 | +- `LM_CAMERA` - Camera |
| 178 | +- `LM_PATHFINDER` - Pathfinding |
| 179 | +- `LM_GUI` - GUI system |
| 180 | +- `LM_VFS` - Virtual file system |
| 181 | + |
| 182 | +Configure logging levels to filter debug output during development. |
0 commit comments