Sandbox 1
Sandbox game that emulates different material physics
Loading...
Searching...
No Matches
World Class Reference

Singleton class of the world. More...

#include <classes.hpp>

Collaboration diagram for World:

Public Member Functions

 World (const World &obj)=delete
 Remove copy constructor.
void clearWorld ()
 Complitely clears pixel_map.
SDL_AppResult initWorld ()
 Function what defines World::window, World::texture and World::font.
SDL_AppResult redrawWorld ()
 Redraws pixels on the screen, calls recalcWorld() and addPixel().

Static Public Member Functions

static WorldgetIstance ()
 Function what returns the worlds instance. If it's nullptr inwokes World().

Public Attributes

bool mouse_is_down = false
 Stores current state of the mouse button, used in redrawWorld() to detect then addPixel() should be inwoked.
PixelType selected_pixel_type
 Currently selected PixelType, used in addPixel().

Private Member Functions

 World ()
 Class constructor, here we define World::bg_color and World::selected_pixel_type.
bool checkIfCanMove (Vector2 pos, PixelMap *new_pixel_map)
 Checks if position on the screen is avalible for movement.
void recalcWorld ()
 Recalculates position of each pixel in pixel_map according to their physic behavior.
void addPixel ()
 Adds new pixel to pixel_map in a radius of BRUSH_SPREAD.

Private Attributes

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 Private Attributes

static Worldinstance = nullptr
 Poiner to the one existing instance of the world.

Detailed Description

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.

Member Function Documentation

◆ checkIfCanMove()

bool World::checkIfCanMove ( Vector2 pos,
PixelMap * new_pixel_map )
private

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]posX,Y coordinates of the window that are being checked for movement.
[in]new_pixel_mapPixelMap what is being created.
Returns
true - if pos not avalible
false - overwise

◆ getIstance()

World * World::getIstance ( )
inlinestatic

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 ( )

Function what defines World::window, World::texture and World::font.

Returns
SDL_APP_CONTINUE on success
SDL_APP_FAILURE on error

◆ 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.
Here is the call graph for this function:

The documentation for this class was generated from the following files: