Services Module
Dook is an inherently service based system as mentioned in Working with Services, these classes are how.
Service Locator
-
class ServiceLocator
Get services safely.
Public Static Functions
-
static void provide(std::unique_ptr<LevelService> service)
Register a level service.
- Parameters:
service – Level service unique ptr.
-
static void provide(std::unique_ptr<GraphicsService> service)
Register a graphics service.
- Parameters:
service – Graphics service to register.
-
static void provide(std::unique_ptr<LoggerService> service)
Register a logger service.
- Parameters:
service – Logger service to register.
-
static void provide(std::unique_ptr<InputService> service)
Register an input service.
- Parameters:
service – Input Service to register.
-
static LevelService &level()
Get the level service.
- Returns:
LevelService& Reference to level service.
-
static GraphicsService &graphics()
Get the registered graphics service.
- Returns:
GraphicsService& Reference to graphics server.
-
static LoggerService &logger()
Get the registered logger.
- Returns:
LoggerService& Reference to the logger.
-
static InputService &input()
Get the registered input service.
- Returns:
InputService& Regerence to the input processor service.
-
static void provide(std::unique_ptr<LevelService> service)
Abstract & Null Services
These services are the ones that need to be extended with concrete implementations before being used, each has a null variant which is by default registered to the service locator.
-
class GraphicsService
This service handles the drawing and rendering.
Subclassed by dook::NullGraphicsService, dook::SDLGraphicsService
Public Functions
-
inline GraphicsService(Camera viewport)
Construct a new Graphics Service object.
Constructs the window object as well.
- Parameters:
viewport – the size of the “screen” and its offset in the total texture.
-
virtual ~GraphicsService() = default
Destroy the Graphics Service object.
Deallocate the window resources as well.
-
void tick()
Re-draw the screen.
-
inline GraphicsService(Camera viewport)
-
class InputService
This service user input.
Fun fact, I planned to implement this in co_await, co_yield. This plan was sadly destroyed when I see the boilerplate to do so, and no, I am NOT adding a library for this purpose.
Subclassed by dook::NullInputService, dook::SDLInputService
Public Functions
-
virtual std::unique_ptr<Command> tick() = 0
Process the next user input.
- Returns:
A unique ptr that either includes a user input or nullptr if not available.
- Returns:
false otherwise.
-
virtual bool quit() = 0
Check if the user have inputted a keycharacter that causes the game to be quit.
- Returns:
true When user have requested game to quit.
- Returns:
false Otherwise.
-
virtual std::unique_ptr<Command> tick() = 0
-
class LevelService
This service handles level mainloops.
Loads levels, and keeps track of the current level.
Subclassed by dook::NullLevelService
-
class LoggerService
Used to log events.
Subclassed by dook::CommonLoggerService, dook::NullLoggerService
-
class NullGraphicsService : public dook::GraphicsService
Noop graphics service.
-
class NullInputService : public dook::InputService
Null placeholder for input generation.
-
class NullLevelService : public dook::LevelService
-
class NullLoggerService : public dook::LoggerService
Common Services
Some services are so common accross various domains that, their concrete implementations are also written in the module.
-
class CommonLoggerService : public dook::LoggerService