Zappy GUI
C++ graphic client: renderer, camera, network
Loading...
Searching...
No Matches
RaylibRenderer Class Reference

A renderer that uses Raylib to display the game state graphically. More...

#include <RaylibRenderer.hpp>

+ Inheritance diagram for RaylibRenderer:
+ Collaboration diagram for RaylibRenderer:

Classes

struct  WindowSnapshot
 

Public Member Functions

 RaylibRenderer ()=default
 
 ~RaylibRenderer () override=default
 
void init () override
 
void render () override
 
void handleInput () override
 
bool shouldClose () override
 
void shutdown () override
 
void setDevMode (bool dev, int port, const std::string &machine) override
 
std::optional< int > getPendingSpeedChange () override
 
- Public Member Functions inherited from ARenderer
void setState (const GameState &state) override final
 
- Public Member Functions inherited from IRenderer
virtual ~IRenderer ()=default
 

Private Member Functions

void _render3D ()
 
void _render2D ()
 
void _drawSelectionHighlight ()
 
void _initTeamColors ()
 
Color _getTeamColor (const std::string &teamName)
 
int _getScaledFontSize (int baseFontSize) const
 
void _updateSelection (float deltaTime)
 
void _performRaycast ()
 
void _drawBehaviorParticles (const VisualState &visual)
 
std::vector< std::vector< const Player * > > _groupPlayersByVisualProximity () const
 
Vector3 _groupLabelAnchor (const std::vector< const Player * > &group) const
 
void _drawSelectionArrow (Vector3 basePos, float modelTopY) const
 
void _drawSpeedSlider ()
 

Private Attributes

CameraController _cam
 
Model _playerModel = {}
 
Color _playerModelBaseMats [6] = {}
 
Model _eggModel = {}
 
Color _eggModelBaseMats [2] = {}
 
Model _foodModel = {}
 
Model _crystalModel = {}
 
Shader _lightingShader = {}
 
Light _sun = {}
 
int _shaderViewPosLoc = -1
 
std::unordered_map< std::string, Color > _teamColors
 
SelectionFinder::Selection _selection
 
TileSlotMap _tileSlotMap
 
SpeedSlider _speedSlider
 
WinScreen _winScreen
 
PlayerPanel _playerPanel
 
HudWidget _hudWidget
 
EntityTooltipWidget _entityTooltip
 
std::unique_ptr< IBackground_background
 
std::optional< int > _pendingSpeed
 
WindowSnapshot _savedWindow
 
bool _devMode = false
 
int _devPort = -1
 
std::string _devMachine
 

Static Private Attributes

static constexpr std::string_view PLAYER_MODEL_PATH = "gui/assets/models/rimuru.glb"
 
static constexpr std::string_view EGG_MODEL_PATH = "gui/assets/models/egg.glb"
 
static constexpr std::string_view FOOD_MODEL_PATH = "gui/assets/models/apple.glb"
 
static constexpr std::string_view CRYSTAL_MODEL_PATH = "gui/assets/models/crystal.glb"
 
static constexpr std::string_view FONT_PATH = "gui/assets/fonts/JetBrainsMono-Bold.ttf"
 
static constexpr float PLAYER_MODEL_SIZE = 0.25f
 
static constexpr float EGG_MODEL_SIZE = 0.15f
 
static constexpr float FOOD_MODEL_SIZE = 1.0f
 
static constexpr float CRYSTAL_MODEL_SIZE = 2.0f
 
static constexpr float RESOURCE_SPHERE_BASE_SIZE = 0.05f
 
static constexpr float TILE_SIZE = 1.0f
 
static constexpr float SELECTION_LINE_THICKNESS = 5.0f
 
static constexpr float SELECTION_WIREFRAME_THICKNESS = 5.0f
 
static constexpr Color SELECTION_COLOR = {128, 0, 128, 255}
 

Additional Inherited Members

- Protected Attributes inherited from ARenderer
const GameState_state = nullptr
 

Detailed Description

A renderer that uses Raylib to display the game state graphically.

Definition at line 26 of file RaylibRenderer.hpp.

Constructor & Destructor Documentation

◆ RaylibRenderer()

RaylibRenderer::RaylibRenderer ( )
default

◆ ~RaylibRenderer()

RaylibRenderer::~RaylibRenderer ( )
overridedefault

Member Function Documentation

◆ _drawBehaviorParticles()

void RaylibRenderer::_drawBehaviorParticles ( const VisualState visual)
private

Definition at line 284 of file RaylibRenderer.cpp.

References VisualState::behaviors.

Referenced by _render3D().

+ Here is the caller graph for this function:

◆ _drawSelectionArrow()

void RaylibRenderer::_drawSelectionArrow ( Vector3  basePos,
float  modelTopY 
) const
private

Definition at line 500 of file RaylibRenderer.cpp.

References SELECTION_COLOR.

Referenced by _drawSelectionHighlight().

+ Here is the caller graph for this function:

◆ _drawSelectionHighlight()

void RaylibRenderer::_drawSelectionHighlight ( )
private

◆ _drawSpeedSlider()

void RaylibRenderer::_drawSpeedSlider ( )
private

Definition at line 353 of file RaylibRenderer.cpp.

References _getScaledFontSize(), _speedSlider, ARenderer::_state, SpeedSlider::draw(), SpeedSlider::syncFromServer(), and GameState::timeUnit.

Referenced by _render2D().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getScaledFontSize()

int RaylibRenderer::_getScaledFontSize ( int  baseFontSize) const
private

Definition at line 423 of file RaylibRenderer.cpp.

Referenced by _drawSpeedSlider(), _render2D(), and render().

+ Here is the caller graph for this function:

◆ _getTeamColor()

Color RaylibRenderer::_getTeamColor ( const std::string &  teamName)
private

Definition at line 415 of file RaylibRenderer.cpp.

References _teamColors.

Referenced by _render2D(), _render3D(), handleInput(), and render().

+ Here is the caller graph for this function:

◆ _groupLabelAnchor()

Vector3 RaylibRenderer::_groupLabelAnchor ( const std::vector< const Player * > &  group) const
private

Definition at line 485 of file RaylibRenderer.cpp.

References ARenderer::_state, WorldState::height, TILE_SIZE, RenderingHelper::tileToWorld(), WorldState::width, GameState::world, Player::x, and Player::y.

Referenced by _render2D().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _groupPlayersByVisualProximity()

std::vector< std::vector< const Player * > > RaylibRenderer::_groupPlayersByVisualProximity ( ) const
private

Definition at line 450 of file RaylibRenderer.cpp.

References ARenderer::_state, WorldState::players, TILE_SIZE, and GameState::world.

Referenced by _render2D().

+ Here is the caller graph for this function:

◆ _initTeamColors()

void RaylibRenderer::_initTeamColors ( )
private

Definition at line 407 of file RaylibRenderer.cpp.

References ARenderer::_state, _teamColors, ColorPalette::getTeamColor(), WorldState::teams, and GameState::world.

Referenced by render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _performRaycast()

void RaylibRenderer::_performRaycast ( )
private

Definition at line 434 of file RaylibRenderer.cpp.

References _cam, _eggModel, _playerModel, _selection, ARenderer::_state, _tileSlotMap, CameraController::camera(), EGG_MODEL_SIZE, SelectionFinder::findFromRay(), SelectionFinder::getEmptySelection(), SelectionFinder::None, PLAYER_MODEL_SIZE, TILE_SIZE, and SelectionFinder::Selection::type.

Referenced by handleInput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _render2D()

void RaylibRenderer::_render2D ( )
private

Definition at line 303 of file RaylibRenderer.cpp.

References _cam, _drawSpeedSlider(), _entityTooltip, _getScaledFontSize(), _getTeamColor(), _groupLabelAnchor(), _groupPlayersByVisualProximity(), _playerPanel, _selection, ARenderer::_state, _winScreen, TooltipRenderer::Builder::addLine(), TooltipRenderer::BottomCenter, CameraController::camera(), TooltipRenderer::create(), EntityTooltipWidget::draw(), PlayerPanel::draw(), WinScreen::draw(), TooltipRenderer::Builder::draw(), GameState::gameDurationSeconds, GameState::gameDurationTicks, I18n::get(), WinScreen::handleInput(), CameraController::isFollowActive(), I18n::PLAYER_HEAD_LEVEL, PLAYER_MODEL_SIZE, TooltipRenderer::Builder::setAnchor(), TooltipRenderer::Builder::setBackgroundColor(), TooltipRenderer::Builder::setBorderColor(), TooltipRenderer::Builder::setBorderThickness(), WinScreen::setDuration(), EntityTooltipWidget::setFollowActive(), TooltipRenderer::Builder::setFontSize(), TooltipRenderer::Builder::setPadding(), EntityTooltipWidget::setSelection(), EntityTooltipWidget::setTeamColorFunc(), PlayerPanel::setTeamColorFunc(), WinScreen::setWinner(), EntityTooltipWidget::setWorld(), PlayerPanel::setWorld(), GameState::winnerTeam, and GameState::world.

Referenced by render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _render3D()

◆ _updateSelection()

void RaylibRenderer::_updateSelection ( float  deltaTime)
private

Definition at line 448 of file RaylibRenderer.cpp.

Referenced by render().

+ Here is the caller graph for this function:

◆ getPendingSpeedChange()

std::optional< int > RaylibRenderer::getPendingSpeedChange ( )
overridevirtual

Reimplemented from ARenderer.

Definition at line 400 of file RaylibRenderer.cpp.

References _pendingSpeed.

◆ handleInput()

◆ init()

◆ render()

◆ setDevMode()

void RaylibRenderer::setDevMode ( bool  dev,
int  port,
const std::string &  machine 
)
overridevirtual

Reimplemented from ARenderer.

Definition at line 197 of file RaylibRenderer.cpp.

References _devMachine, _devMode, _devPort, _hudWidget, and HudWidget::setDevMode().

+ Here is the call graph for this function:

◆ shouldClose()

bool RaylibRenderer::shouldClose ( )
overridevirtual

Implements IRenderer.

Definition at line 195 of file RaylibRenderer.cpp.

References _winScreen, and WinScreen::quitRequested().

+ Here is the call graph for this function:

◆ shutdown()

void RaylibRenderer::shutdown ( )
overridevirtual

Implements IRenderer.

Definition at line 205 of file RaylibRenderer.cpp.

References _background, _crystalModel, _eggModel, _foodModel, _lightingShader, _playerModel, _savedWindow, TextRenderer::unloadFont(), and RaylibRenderer::WindowSnapshot::width.

+ Here is the call graph for this function:

Member Data Documentation

◆ _background

std::unique_ptr<IBackground> RaylibRenderer::_background
private

Definition at line 81 of file RaylibRenderer.hpp.

Referenced by _render3D(), init(), render(), and shutdown().

◆ _cam

CameraController RaylibRenderer::_cam
private

Definition at line 56 of file RaylibRenderer.hpp.

Referenced by _performRaycast(), _render2D(), _render3D(), handleInput(), init(), and render().

◆ _crystalModel

Model RaylibRenderer::_crystalModel = {}
private

Definition at line 66 of file RaylibRenderer.hpp.

Referenced by _render3D(), init(), and shutdown().

◆ _devMachine

std::string RaylibRenderer::_devMachine
private

Definition at line 95 of file RaylibRenderer.hpp.

Referenced by handleInput(), and setDevMode().

◆ _devMode

bool RaylibRenderer::_devMode = false
private

Definition at line 93 of file RaylibRenderer.hpp.

Referenced by handleInput(), and setDevMode().

◆ _devPort

int RaylibRenderer::_devPort = -1
private

Definition at line 94 of file RaylibRenderer.hpp.

Referenced by handleInput(), and setDevMode().

◆ _eggModel

Model RaylibRenderer::_eggModel = {}
private

◆ _eggModelBaseMats

Color RaylibRenderer::_eggModelBaseMats[2] = {}
private

Definition at line 62 of file RaylibRenderer.hpp.

Referenced by _render3D(), and init().

◆ _entityTooltip

EntityTooltipWidget RaylibRenderer::_entityTooltip
private

Definition at line 80 of file RaylibRenderer.hpp.

Referenced by _render2D(), and handleInput().

◆ _foodModel

Model RaylibRenderer::_foodModel = {}
private

Definition at line 64 of file RaylibRenderer.hpp.

Referenced by _render3D(), init(), and shutdown().

◆ _hudWidget

HudWidget RaylibRenderer::_hudWidget
private

Definition at line 79 of file RaylibRenderer.hpp.

Referenced by handleInput(), render(), and setDevMode().

◆ _lightingShader

Shader RaylibRenderer::_lightingShader = {}
private

Definition at line 68 of file RaylibRenderer.hpp.

Referenced by init(), render(), and shutdown().

◆ _pendingSpeed

std::optional<int> RaylibRenderer::_pendingSpeed
private

Definition at line 82 of file RaylibRenderer.hpp.

Referenced by getPendingSpeedChange(), handleInput(), and init().

◆ _playerModel

Model RaylibRenderer::_playerModel = {}
private

◆ _playerModelBaseMats

Color RaylibRenderer::_playerModelBaseMats[6] = {}
private

Definition at line 59 of file RaylibRenderer.hpp.

Referenced by _render3D(), and init().

◆ _playerPanel

PlayerPanel RaylibRenderer::_playerPanel
private

Definition at line 78 of file RaylibRenderer.hpp.

Referenced by _render2D(), and handleInput().

◆ _savedWindow

WindowSnapshot RaylibRenderer::_savedWindow
private

Definition at line 91 of file RaylibRenderer.hpp.

Referenced by init(), and shutdown().

◆ _selection

SelectionFinder::Selection RaylibRenderer::_selection
private

◆ _shaderViewPosLoc

int RaylibRenderer::_shaderViewPosLoc = -1
private

Definition at line 70 of file RaylibRenderer.hpp.

Referenced by init(), and render().

◆ _speedSlider

SpeedSlider RaylibRenderer::_speedSlider
private

Definition at line 76 of file RaylibRenderer.hpp.

Referenced by _drawSpeedSlider(), handleInput(), and init().

◆ _sun

Light RaylibRenderer::_sun = {}
private

Definition at line 69 of file RaylibRenderer.hpp.

Referenced by init().

◆ _teamColors

std::unordered_map<std::string, Color> RaylibRenderer::_teamColors
private

Definition at line 72 of file RaylibRenderer.hpp.

Referenced by _getTeamColor(), and _initTeamColors().

◆ _tileSlotMap

TileSlotMap RaylibRenderer::_tileSlotMap
private

Definition at line 75 of file RaylibRenderer.hpp.

Referenced by _drawSelectionHighlight(), _performRaycast(), _render3D(), and init().

◆ _winScreen

WinScreen RaylibRenderer::_winScreen
private

Definition at line 77 of file RaylibRenderer.hpp.

Referenced by _render2D(), init(), and shouldClose().

◆ CRYSTAL_MODEL_PATH

constexpr std::string_view RaylibRenderer::CRYSTAL_MODEL_PATH = "gui/assets/models/crystal.glb"
staticconstexprprivate

Definition at line 43 of file RaylibRenderer.hpp.

Referenced by init().

◆ CRYSTAL_MODEL_SIZE

constexpr float RaylibRenderer::CRYSTAL_MODEL_SIZE = 2.0f
staticconstexprprivate

Definition at line 49 of file RaylibRenderer.hpp.

Referenced by _render3D().

◆ EGG_MODEL_PATH

constexpr std::string_view RaylibRenderer::EGG_MODEL_PATH = "gui/assets/models/egg.glb"
staticconstexprprivate

Definition at line 41 of file RaylibRenderer.hpp.

Referenced by init().

◆ EGG_MODEL_SIZE

constexpr float RaylibRenderer::EGG_MODEL_SIZE = 0.15f
staticconstexprprivate

Definition at line 47 of file RaylibRenderer.hpp.

Referenced by _drawSelectionHighlight(), _performRaycast(), and _render3D().

◆ FONT_PATH

constexpr std::string_view RaylibRenderer::FONT_PATH = "gui/assets/fonts/JetBrainsMono-Bold.ttf"
staticconstexprprivate

Definition at line 44 of file RaylibRenderer.hpp.

Referenced by init().

◆ FOOD_MODEL_PATH

constexpr std::string_view RaylibRenderer::FOOD_MODEL_PATH = "gui/assets/models/apple.glb"
staticconstexprprivate

Definition at line 42 of file RaylibRenderer.hpp.

Referenced by init().

◆ FOOD_MODEL_SIZE

constexpr float RaylibRenderer::FOOD_MODEL_SIZE = 1.0f
staticconstexprprivate

Definition at line 48 of file RaylibRenderer.hpp.

Referenced by _render3D().

◆ PLAYER_MODEL_PATH

constexpr std::string_view RaylibRenderer::PLAYER_MODEL_PATH = "gui/assets/models/rimuru.glb"
staticconstexprprivate

Definition at line 40 of file RaylibRenderer.hpp.

Referenced by init().

◆ PLAYER_MODEL_SIZE

constexpr float RaylibRenderer::PLAYER_MODEL_SIZE = 0.25f
staticconstexprprivate

Definition at line 46 of file RaylibRenderer.hpp.

Referenced by _drawSelectionHighlight(), _performRaycast(), _render2D(), and _render3D().

◆ RESOURCE_SPHERE_BASE_SIZE

constexpr float RaylibRenderer::RESOURCE_SPHERE_BASE_SIZE = 0.05f
staticconstexprprivate

Definition at line 50 of file RaylibRenderer.hpp.

Referenced by _render3D().

◆ SELECTION_COLOR

constexpr Color RaylibRenderer::SELECTION_COLOR = {128, 0, 128, 255}
staticconstexprprivate

Definition at line 54 of file RaylibRenderer.hpp.

Referenced by _drawSelectionArrow(), and _drawSelectionHighlight().

◆ SELECTION_LINE_THICKNESS

constexpr float RaylibRenderer::SELECTION_LINE_THICKNESS = 5.0f
staticconstexprprivate

Definition at line 52 of file RaylibRenderer.hpp.

Referenced by _drawSelectionHighlight().

◆ SELECTION_WIREFRAME_THICKNESS

constexpr float RaylibRenderer::SELECTION_WIREFRAME_THICKNESS = 5.0f
staticconstexprprivate

Definition at line 53 of file RaylibRenderer.hpp.

◆ TILE_SIZE

constexpr float RaylibRenderer::TILE_SIZE = 1.0f
staticconstexprprivate

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