The RayCastWorld Engine - Inherit from this, implement abstract methods, call Update() and Render() when required
| 126 | // The RayCastWorld Engine - Inherit from this, implement abstract |
| 127 | // methods, call Update() and Render() when required |
| 128 | class Engine : public olc::PGEX |
| 129 | { |
| 130 | public: |
| 131 | // Identifies side of cell |
| 132 | enum class CellSide |
| 133 | { |
| 134 | North, |
| 135 | East, |
| 136 | South, |
| 137 | West, |
| 138 | Top, |
| 139 | Bottom, |
| 140 | }; |
| 141 | |
| 142 | public: |
| 143 | // Construct world rednering parameters |
| 144 | Engine(const int screen_w, const int screen_h, const float fov); |
| 145 | |
| 146 | protected: |
| 147 | // ABSTRACT - User must return a suitable olc::Pixel depending on world location information provided |
| 148 | virtual olc::Pixel SelectSceneryPixel(const int tile_x, const int tile_y, const olc::rcw::Engine::CellSide side, const float sample_x, const float sample_y, const float distance) = 0; |
| 149 | |
| 150 | // ABSTRACT - User must return a boolean indicating if the tile is solid or not |
| 151 | virtual bool IsLocationSolid(const float tile_x, const float tile_y) = 0; |
| 152 | |
| 153 | // ABSTRACT - User must return sizes of requested objects in Unit Cell Size |
| 154 | virtual float GetObjectWidth(const uint32_t id) = 0; |
| 155 | virtual float GetObjectHeight(const uint32_t id) = 0; |
| 156 | |
| 157 | // ABSTRACT - User must return suitable olc::Pixel for object sprite sample location |
| 158 | virtual olc::Pixel SelectObjectPixel(const uint32_t id, const float sample_x, const float sample_y, const float distance, const float angle) = 0; |
| 159 | |
| 160 | // OPTIONAL - User can handle collsiion response with scenery should they choose to |
| 161 | virtual void HandleObjectVsScenery(std::shared_ptr<olc::rcw::Object> object, const int tile_x, const int tile_y, const olc::rcw::Engine::CellSide side, const float offset_x, const float offset_y); |
| 162 | |
| 163 | // OPTIONAL - User can handle collsiion response with objects should they choose to |
| 164 | virtual void HandleObjectVsObject(std::shared_ptr<olc::rcw::Object> object1, std::shared_ptr<olc::rcw::Object> object2); |
| 165 | |
| 166 | |
| 167 | |
| 168 | public: |
| 169 | // Sets In-Game Camera position |
| 170 | void SetCamera(const olc::vf2d& pos, const float heading); |
| 171 | |
| 172 | // Called to update world state |
| 173 | virtual void Update(float fElapsedTime); |
| 174 | |
| 175 | // Called to draw the world and its contents |
| 176 | void Render(); |
| 177 | |
| 178 | public: |
| 179 | std::unordered_map<uint32_t, std::shared_ptr<olc::rcw::Object>> mapObjects; |
| 180 | |
| 181 | private: |
| 182 | // A convenient utility struct to store all the info required to understand how a ray |
| 183 | // has hit a specific tile |
| 184 | struct sTileHit |
| 185 | { |
nothing calls this directly
no outgoing calls
no test coverage detected