|
| 1 | +=== C++ Development Patterns |
| 2 | + |
| 3 | +This section covers common patterns for extending and developing with the FIFE engine in C++. |
| 4 | + |
| 5 | +==== Extending FIFE Classes |
| 6 | + |
| 7 | +FIFE uses virtual methods and interfaces for extensibility. Common patterns: |
| 8 | + |
| 9 | +* *Subclass and override* — Create a derived class and override virtual methods (e.g., `RendererBase`, `MouseListener`). |
| 10 | +* *Register your implementation* — Pass your subclass to the appropriate manager or subsystem. |
| 11 | +* *Use existing patterns* — Follow the observer/listener pattern for events, the manager pattern for resources. |
| 12 | + |
| 13 | +==== Implementing a Custom Renderer |
| 14 | + |
| 15 | +To create a custom renderer: |
| 16 | + |
| 17 | +1. Subclass `fife::RendererBase`: |
| 18 | ++ |
| 19 | +[source,cpp] |
| 20 | +---- |
| 21 | +class MyRenderer : public fife::RendererBase { |
| 22 | +public: |
| 23 | + MyRenderer() : fife::RendererBase("MyRenderer") {} |
| 24 | + void render(fife::RenderBackend& backend, fife::Layer* layer) override { |
| 25 | + // Custom rendering logic |
| 26 | + } |
| 27 | +}; |
| 28 | +---- |
| 29 | + |
| 30 | +2. Register with the view: |
| 31 | ++ |
| 32 | +[source,cpp] |
| 33 | +---- |
| 34 | +view->addRenderer(new MyRenderer()); |
| 35 | +---- |
| 36 | + |
| 37 | +==== Adding a New Pathfinder Algorithm |
| 38 | + |
| 39 | +1. Create a new class in `engine/core/pathfinder/` inheriting from the pathfinder interface. |
| 40 | +2. Implement the search method (A*, Dijkstra, etc.). |
| 41 | +3. Register in the pathfinder router so it can be selected via `RoutePather::setPathingStrategy()`. |
| 42 | + |
| 43 | +==== Adding a New Resource Type |
| 44 | + |
| 45 | +1. Create a resource class (e.g., `MyResource`) with load/release methods. |
| 46 | +2. Create a manager class (`MyResourceManager`) following the pattern of `ImageManager`. |
| 47 | +3. Register the manager in the engine initialization. |
| 48 | + |
| 49 | +==== Key Internal Classes |
| 50 | + |
| 51 | +[cols="1,3", options="header"] |
| 52 | +|=== |
| 53 | +| Class | Purpose |
| 54 | + |
| 55 | +| `Engine` |
| 56 | +| Entry point; owns all subsystems, manages lifecycle |
| 57 | + |
| 58 | +| `Model` |
| 59 | +| Game world container; owns maps, layers, instances |
| 60 | + |
| 61 | +| `Map` |
| 62 | +| A single game map; owns layers and cameras |
| 63 | + |
| 64 | +| `Layer` |
| 65 | +| A grid of instances; provides spatial queries |
| 66 | + |
| 67 | +| `Instance` |
| 68 | +| A placed object in the world; has position, rotation, animation |
| 69 | + |
| 70 | +| `Object` |
| 71 | +| Template/archetype defining instance properties |
| 72 | + |
| 73 | +| `RendererBase` |
| 74 | +| Base class for all renderers |
| 75 | + |
| 76 | +| `View` |
| 77 | +| Manages cameras and renderer pipeline |
| 78 | +|=== |
| 79 | + |
| 80 | +For the complete API, see the https://fifengine.github.io/fifengine/api/[C++ API Documentation]. |
0 commit comments