Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
renderer.h
Go to the documentation of this file.
1#pragma once
2
8
9#include <map>
10#include <memory>
11
12class SDL_Renderer; // NOLINT
13class SDL_Window; // NOLINT
14
15using SdlRendererPtr = std::unique_ptr<SDL_Renderer, void (*)(SDL_Renderer*)>;
16using SdlWindowPtr = std::unique_ptr<SDL_Window, void (*)(SDL_Window*)>;
17
25class Renderer final : public IEngineService {
26 private:
27 friend class RenderingManager;
28 friend class AssetService;
29 friend class SdlStrategyFactory;
30
31 SdlRendererPtr sdl_renderer_;
32 SdlWindowPtr sdl_window_;
33 // I tried just storing a Window& here, but that caused issues because the can
34 // never be a proper init value...
35 std::optional<Window> window_;
36
37 bool vsync_enabled_{false};
38
39 public:
40 explicit Renderer();
41 explicit Renderer(int min_aspect_width, int min_aspect_height,
42 const std::string& title, RendererFlags flags);
43
53 void render(
54 const std::map<
55 int, std::multimap<int, std::reference_wrapper<Renderable>>>& objects,
56 const Scene& scene);
57
62 [[nodiscard]] bool vsync() const;
63
68 void vsync(bool enabled);
69
75 void clear() const;
77};
Service responsible for managing game assets such as textures and spritesheets.
Definition assetService.h:20
Definition iEngineService.h:4
Service responsible for rendering game objects to the screen.
Definition renderer.h:25
Window & window()
void render(const std::map< int, std::multimap< int, std::reference_wrapper< Renderable > > > &objects, const Scene &scene)
Renders a collection of game objects to the screen. Renders a given collection of game objects to the...
void vsync(bool enabled)
Toggles vertical synchronization (VSync) which limits fps to the monitor's refresh rate.
bool vsync() const
Checks if vertical synchronization (VSync) is enabled.
Renderer(int min_aspect_width, int min_aspect_height, const std::string &title, RendererFlags flags)
void clear() const
Clears the rendering target with the drawing color. Clears the current rendering target with the draw...
friend class RenderingManager
Definition renderer.h:27
Represents a scene within the engine. A scene contains multiple GameObjects and manages their lifecyc...
Definition scene.h:19
Factory for creating SDL rendering strategies.
Definition sdl_strategy_factory.h:13
Represents the game window and provides methods to modify its properties. The window encapsulates an ...
Definition window.h:15
std::unique_ptr< SDL_Window, void(*)(SDL_Window *)> SdlWindowPtr
Definition renderer.h:16
std::unique_ptr< SDL_Renderer, void(*)(SDL_Renderer *)> SdlRendererPtr
Definition renderer.h:15
RendererFlags
Definition rendererFlags.h:4