Singleton class of the world.
More...
#include <classes.hpp >
SDL_Window * window
SDL window.
SDL_Renderer * renderer
SDL renderer.
TTF_TextEngine * text_renderer
TTF engine what is tied to World::renderer to easly render text.
SDL_Texture * texture
SDL texture.
TTF_Font * font
Fonts that are used for the text on the screen.
Vector2 window_size
Window width and height in pixels devided by PIXEL_SIZE.
PixelMap pixel_map
PixelMap what contains all phical object pixels.
SDL_Color bg_color
Background color of the screen.
static World * instance = nullptr
Poiner to the one existing instance of the world.
Singleton class of the world.
Note Took this as a reference https://www.geeksforgeeks.org/cpp/implementation-of-singleton-class-in-cpp/
Author -inf (infgotoinf)
Date 2026/03/15
Todo Make this shit work faster it's toooooooo slow.
◆ checkIfCanMove()
Checks if position on the screen is avalible for movement.
Checks if pos out of window bounds, taken by pixel in World::pixel_map of pixel in new_pixel_map.
Parameters
[in] pos X,Y coordinates of the window that are being checked for movement.
[in] new_pixel_map PixelMap what is being created.
Returns true - if pos not avalible
false - overwise
◆ getIstance()
World * World::getIstance
(
)
inline static
Function what returns the worlds instance. If it's nullptr inwokes World() .
Note This is how singleton works.
Returns Pointer to World::instance .
◆ initWorld()
SDL_AppResult World::initWorld
(
)
◆ recalcWorld()
void World::recalcWorld
(
)
private
Recalculates position of each pixel in pixel_map according to their physic behavior.
Creates new_pixel_map and for each pixel in World::pixel_map checks on what coordinates it can move with checkIfCanMove() and inserts them in new_pixel_map. And after that replaces World::pixel_map with new_pixel_map.
Note Took this as a refference:
Todo Make sand fall under water and water lift above the snad.
◆ redrawWorld()
SDL_AppResult World::redrawWorld
(
)
Redraws pixels on the screen, calls recalcWorld() and addPixel() .
Returns SDL_APP_CONTINUE on success
SDL_APP_FAILURE on error
Todo (Not sure if we really need this but) Make screen resizing change pixel coordinates in pixel_map, so they don't go off the screen.
The documentation for this class was generated from the following files: