Botcraft 26.3
Loading...
Searching...
No Matches
Botcraft::Renderer::RenderingManager Class Reference

#include <RenderingManager.hpp>

Inheritance diagram for Botcraft::Renderer::RenderingManager:
ProtocolCraft::Handler ProtocolCraft::GenericHandler< Packet, AllPackets >

Public Member Functions

 ~RenderingManager ()
 
void Close ()
 
void SetMouseCallback (std::function< void(double, double)> callback)
 
void SetKeyboardCallback (std::function< void(std::array< bool, static_cast< int >(KEY_CODE::NUMBER_OF_KEYS)>, double)> callback)
 
void AddChunkToUpdate (const int x, const int z)
 
void AddEntityToUpdate (const int id)
 
void SetCurrentBehaviourTree (const BaseNode *root) const
 
void ResetBehaviourState () const
 
void BehaviourStartTick () const
 
void BehaviourEndTick (const bool b) const
 
void BehaviourTickChild (const size_t i) const
 
bool IsBehaviourGUIPaused () const
 
void ResetBlackboard () const
 
void UpdateBlackboardValue (const std::string &key, const std::any &value) const
 
void RemoveBlackboardValue (const std::string &key) const
 

Static Public Member Functions

static std::shared_ptr< RenderingManager > CreateRenderingManagerIfPossible (std::shared_ptr< World > world_, std::shared_ptr< InventoryManager > inventory_manager_, std::shared_ptr< EntityManager > entity_manager_)
 

Protected Member Functions

void WaitForRenderingUpdate ()
 
virtual void Handle (ProtocolCraft::ClientboundBlockUpdatePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundSectionBlocksUpdatePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundForgetLevelChunkPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundLevelChunkWithLightPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundAddEntityPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundTeleportEntityPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundMoveEntityPacketPos &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundMoveEntityPacketPosRot &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundMoveEntityPacketRot &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundSetEntityDataPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundRemoveEntitiesPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundSetTimePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundRespawnPacket &msg) override
 

Private Member Functions

 RenderingManager (std::shared_ptr< World > world_, std::shared_ptr< InventoryManager > inventory_manager_, std::shared_ptr< EntityManager > entity_manager_)
 
bool Init ()
 
void Run ()
 
void InternalProcessInput (GLFWwindow *window)
 

Static Private Member Functions

static void ResizeCallback (GLFWwindow *window, int width, int height)
 
static void InternalMouseCallback (GLFWwindow *window, double xpos, double ypos)
 

Private Attributes

std::shared_ptr< World > world
 
std::shared_ptr< InventoryManager > inventory_manager
 
std::shared_ptr< EntityManager > entity_manager
 
std::shared_ptr< LocalPlayer > local_player
 
std::array< bool, static_cast< int >(KEY_CODE::NUMBER_OF_KEYS)> is_key_pressed {}
 
bool inventory_open
 
bool behaviour_open
 
std::thread rendering_thread
 
double mouse_last_x
 
double mouse_last_y
 
bool first_mouse
 
double deltaTime
 
double lastFrameTime
 
GLFWwindow * window
 
int current_window_width
 
int current_window_height
 
bool current_window_headless
 
bool current_vsync
 
bool has_proj_changed
 
std::atomic< float > day_time
 
std::unique_ptr< Shader > my_shader
 
std::unique_ptr< WorldRenderer > world_renderer
 
std::unique_ptr< BehaviourRenderer > behaviour_renderer
 
std::function< void(double, double)> MouseCallback
 
std::function< void(std::array< bool, static_cast< int >(KEY_CODE::NUMBER_OF_KEYS)>, double)> KeyboardCallback
 
std::mutex callbacks_mutex
 
std::atomic< bool > running
 
std::unordered_set< Position > chunks_to_udpate
 
std::unordered_set< int > entities_to_update
 
std::mutex mutex_updating
 
std::condition_variable condition_update
 
std::thread thread_updating_renderable
 

Static Private Attributes

static std::weak_ptr< RenderingManager > current_instance
 
static std::mutex instance_mutex
 

Detailed Description

Definition at line 51 of file RenderingManager.hpp.

Constructor & Destructor Documentation

◆ RenderingManager()

◆ ~RenderingManager()

Botcraft::Renderer::RenderingManager::~RenderingManager ( )

Definition at line 116 of file RenderingManager.cpp.

References condition_update, mutex_updating, rendering_thread, and running.

Member Function Documentation

◆ AddChunkToUpdate()

void Botcraft::Renderer::RenderingManager::AddChunkToUpdate ( const int  x,
const int  z 
)

Definition at line 734 of file RenderingManager.cpp.

References chunks_to_udpate, condition_update, and mutex_updating.

Referenced by Handle(), Handle(), and Handle().

◆ AddEntityToUpdate()

void Botcraft::Renderer::RenderingManager::AddEntityToUpdate ( const int  id)

◆ BehaviourEndTick()

void Botcraft::Renderer::RenderingManager::BehaviourEndTick ( const bool  b) const

Definition at line 516 of file RenderingManager.cpp.

References behaviour_renderer.

◆ BehaviourStartTick()

void Botcraft::Renderer::RenderingManager::BehaviourStartTick ( ) const

Definition at line 511 of file RenderingManager.cpp.

References behaviour_renderer.

◆ BehaviourTickChild()

void Botcraft::Renderer::RenderingManager::BehaviourTickChild ( const size_t  i) const

Definition at line 521 of file RenderingManager.cpp.

References behaviour_renderer.

◆ Close()

void Botcraft::Renderer::RenderingManager::Close ( )

Definition at line 480 of file RenderingManager.cpp.

References condition_update, mutex_updating, and running.

◆ CreateRenderingManagerIfPossible()

std::shared_ptr< RenderingManager > Botcraft::Renderer::RenderingManager::CreateRenderingManagerIfPossible ( std::shared_ptr< World >  world_,
std::shared_ptr< InventoryManager >  inventory_manager_,
std::shared_ptr< EntityManager >  entity_manager_ 
)
static

Definition at line 51 of file RenderingManager.cpp.

References current_instance, and instance_mutex.

Referenced by Botcraft::ManagersClient::Handle().

◆ Handle() [1/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundAddEntityPacket &  msg)
overrideprotectedvirtual

Definition at line 849 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Handle() [2/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundBlockUpdatePacket &  msg)
overrideprotectedvirtual

◆ Handle() [3/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundForgetLevelChunkPacket &  msg)
overrideprotectedvirtual

Definition at line 831 of file RenderingManager.cpp.

References AddChunkToUpdate().

◆ Handle() [4/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundLevelChunkWithLightPacket &  msg)
overrideprotectedvirtual

Definition at line 843 of file RenderingManager.cpp.

◆ Handle() [5/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundMoveEntityPacketPos &  msg)
overrideprotectedvirtual

Definition at line 887 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Handle() [6/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundMoveEntityPacketPosRot &  msg)
overrideprotectedvirtual

Definition at line 892 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Handle() [7/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundMoveEntityPacketRot &  msg)
overrideprotectedvirtual

Definition at line 897 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Handle() [8/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundRemoveEntitiesPacket &  msg)
overrideprotectedvirtual

Definition at line 918 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Handle() [9/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundRespawnPacket &  msg)
overrideprotectedvirtual

Definition at line 960 of file RenderingManager.cpp.

References world_renderer.

◆ Handle() [10/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundSectionBlocksUpdatePacket &  msg)
overrideprotectedvirtual

Definition at line 822 of file RenderingManager.cpp.

References AddChunkToUpdate().

◆ Handle() [11/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundSetEntityDataPacket &  msg)
overrideprotectedvirtual

Definition at line 902 of file RenderingManager.cpp.

References AddEntityToUpdate(), entity_manager, and local_player.

◆ Handle() [12/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundSetTimePacket &  msg)
overrideprotectedvirtual

Definition at line 927 of file RenderingManager.cpp.

References day_time, and world.

◆ Handle() [13/13]

void Botcraft::Renderer::RenderingManager::Handle ( ProtocolCraft::ClientboundTeleportEntityPacket &  msg)
overrideprotectedvirtual

Definition at line 875 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Init()

bool Botcraft::Renderer::RenderingManager::Init ( )
private

◆ InternalMouseCallback()

void Botcraft::Renderer::RenderingManager::InternalMouseCallback ( GLFWwindow *  window,
double  xpos,
double  ypos 
)
staticprivate

◆ InternalProcessInput()

◆ IsBehaviourGUIPaused()

bool Botcraft::Renderer::RenderingManager::IsBehaviourGUIPaused ( ) const

Definition at line 526 of file RenderingManager.cpp.

References behaviour_renderer.

◆ RemoveBlackboardValue()

void Botcraft::Renderer::RenderingManager::RemoveBlackboardValue ( const std::string &  key) const

Definition at line 541 of file RenderingManager.cpp.

References behaviour_renderer.

◆ ResetBehaviourState()

void Botcraft::Renderer::RenderingManager::ResetBehaviourState ( ) const

Definition at line 506 of file RenderingManager.cpp.

References behaviour_renderer.

◆ ResetBlackboard()

void Botcraft::Renderer::RenderingManager::ResetBlackboard ( ) const

Definition at line 531 of file RenderingManager.cpp.

References behaviour_renderer.

◆ ResizeCallback()

void Botcraft::Renderer::RenderingManager::ResizeCallback ( GLFWwindow *  window,
int  width,
int  height 
)
staticprivate

◆ Run()

void Botcraft::Renderer::RenderingManager::Run ( )
private

Definition at line 131 of file RenderingManager.cpp.

References behaviour_open, behaviour_renderer, color_day(), color_night(), condition_update, current_vsync, current_window_headless, current_window_height, current_window_width, day_time, deltaTime, entity_manager, Botcraft::Blockstate::GetFluidHeight(), Botcraft::Blockstate::GetFriction(), Botcraft::Blockstate::GetHardness(), Botcraft::AssetsManager::getInstance(), Botcraft::Logger::GetInstance(), Botcraft::Blockstate::GetName(), has_proj_changed, Botcraft::Renderer::Settings::headless, Botcraft::Renderer::Settings::height, Init(), InternalProcessInput(), Botcraft::Window::INVENTORY_ARMOR_START, Botcraft::Window::INVENTORY_CRAFTING_INPUT_START, Botcraft::Window::INVENTORY_CRAFTING_OUTPUT_INDEX, Botcraft::Window::INVENTORY_HOTBAR_START, inventory_manager, Botcraft::Window::INVENTORY_OFFHAND_INDEX, inventory_open, Botcraft::Window::INVENTORY_STORAGE_START, Botcraft::Blockstate::IsAir(), Botcraft::Blockstate::IsBed(), Botcraft::Blockstate::IsBerryBush(), Botcraft::Blockstate::IsClimbable(), Botcraft::Blockstate::IsCobweb(), Botcraft::Blockstate::IsDownBubbleColumn(), Botcraft::Blockstate::IsFluidFalling(), Botcraft::Blockstate::IsHazardous(), Botcraft::Blockstate::IsHoney(), Botcraft::Blockstate::IsLava(), Botcraft::Blockstate::IsPowderSnow(), Botcraft::Blockstate::IsScaffolding(), Botcraft::Blockstate::IsSlime(), Botcraft::Blockstate::IsSolid(), Botcraft::Blockstate::IsSoulSand(), Botcraft::Blockstate::IsTransparent(), Botcraft::Blockstate::IsUpBubbleColumn(), Botcraft::Blockstate::IsWater(), Botcraft::Blockstate::IsWaterlogged(), Botcraft::AssetsManager::Items(), lastFrameTime, local_player, LOG_ERROR, mutex_updating, my_shader, Botcraft::Logger::RegisterThread(), running, Botcraft::Renderer::Settings::screenhsot_path, Botcraft::Renderer::Settings::screenshot_callback, Botcraft::Renderer::Settings::screenshot_mutex, Botcraft::Utilities::SleepFor(), Botcraft::Renderer::Settings::target_fps, thread_updating_renderable, Botcraft::Renderer::Settings::vsync, WaitForRenderingUpdate(), Botcraft::Renderer::Settings::width, window, world, world_renderer, Botcraft::Renderer::WriteImage(), Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

Referenced by RenderingManager().

◆ SetCurrentBehaviourTree()

void Botcraft::Renderer::RenderingManager::SetCurrentBehaviourTree ( const BaseNode *  root) const

Definition at line 501 of file RenderingManager.cpp.

References behaviour_renderer.

◆ SetKeyboardCallback()

void Botcraft::Renderer::RenderingManager::SetKeyboardCallback ( std::function< void(std::array< bool, static_cast< int >(KEY_CODE::NUMBER_OF_KEYS)>, double)>  callback)

Definition at line 495 of file RenderingManager.cpp.

References callbacks_mutex, and KeyboardCallback.

◆ SetMouseCallback()

void Botcraft::Renderer::RenderingManager::SetMouseCallback ( std::function< void(double, double)>  callback)

Definition at line 489 of file RenderingManager.cpp.

References callbacks_mutex, and MouseCallback.

◆ UpdateBlackboardValue()

void Botcraft::Renderer::RenderingManager::UpdateBlackboardValue ( const std::string &  key,
const std::any &  value 
) const

Definition at line 536 of file RenderingManager.cpp.

References behaviour_renderer.

◆ WaitForRenderingUpdate()

void Botcraft::Renderer::RenderingManager::WaitForRenderingUpdate ( )
protected

Member Data Documentation

◆ behaviour_open

bool Botcraft::Renderer::RenderingManager::behaviour_open
private

◆ behaviour_renderer

◆ callbacks_mutex

std::mutex Botcraft::Renderer::RenderingManager::callbacks_mutex
private

◆ chunks_to_udpate

std::unordered_set<Position> Botcraft::Renderer::RenderingManager::chunks_to_udpate
private

Definition at line 196 of file RenderingManager.hpp.

Referenced by AddChunkToUpdate(), and WaitForRenderingUpdate().

◆ condition_update

std::condition_variable Botcraft::Renderer::RenderingManager::condition_update
private

◆ current_instance

std::weak_ptr< RenderingManager > Botcraft::Renderer::RenderingManager::current_instance
staticprivate

Definition at line 69 of file RenderingManager.hpp.

Referenced by CreateRenderingManagerIfPossible().

◆ current_vsync

bool Botcraft::Renderer::RenderingManager::current_vsync
private

Definition at line 180 of file RenderingManager.hpp.

Referenced by Init(), RenderingManager(), and Run().

◆ current_window_headless

bool Botcraft::Renderer::RenderingManager::current_window_headless
private

Definition at line 179 of file RenderingManager.hpp.

Referenced by Init(), RenderingManager(), and Run().

◆ current_window_height

int Botcraft::Renderer::RenderingManager::current_window_height
private

Definition at line 178 of file RenderingManager.hpp.

Referenced by Init(), RenderingManager(), ResizeCallback(), and Run().

◆ current_window_width

int Botcraft::Renderer::RenderingManager::current_window_width
private

Definition at line 177 of file RenderingManager.hpp.

Referenced by Init(), RenderingManager(), ResizeCallback(), and Run().

◆ day_time

std::atomic<float> Botcraft::Renderer::RenderingManager::day_time
private

Definition at line 184 of file RenderingManager.hpp.

Referenced by Handle(), RenderingManager(), and Run().

◆ deltaTime

double Botcraft::Renderer::RenderingManager::deltaTime
private

Definition at line 173 of file RenderingManager.hpp.

Referenced by InternalProcessInput(), RenderingManager(), and Run().

◆ entities_to_update

std::unordered_set<int> Botcraft::Renderer::RenderingManager::entities_to_update
private

Definition at line 197 of file RenderingManager.hpp.

Referenced by AddEntityToUpdate(), and WaitForRenderingUpdate().

◆ entity_manager

std::shared_ptr<EntityManager> Botcraft::Renderer::RenderingManager::entity_manager
private

Definition at line 159 of file RenderingManager.hpp.

Referenced by Handle(), RenderingManager(), Run(), and WaitForRenderingUpdate().

◆ first_mouse

bool Botcraft::Renderer::RenderingManager::first_mouse
private

Definition at line 171 of file RenderingManager.hpp.

Referenced by InternalMouseCallback(), and RenderingManager().

◆ has_proj_changed

bool Botcraft::Renderer::RenderingManager::has_proj_changed
private

Definition at line 181 of file RenderingManager.hpp.

Referenced by RenderingManager(), ResizeCallback(), and Run().

◆ instance_mutex

std::mutex Botcraft::Renderer::RenderingManager::instance_mutex
staticprivate

Definition at line 70 of file RenderingManager.hpp.

Referenced by CreateRenderingManagerIfPossible().

◆ inventory_manager

std::shared_ptr<InventoryManager> Botcraft::Renderer::RenderingManager::inventory_manager
private

Definition at line 158 of file RenderingManager.hpp.

Referenced by RenderingManager(), and Run().

◆ inventory_open

bool Botcraft::Renderer::RenderingManager::inventory_open
private

◆ is_key_pressed

std::array<bool, static_cast<int>(KEY_CODE::NUMBER_OF_KEYS)> Botcraft::Renderer::RenderingManager::is_key_pressed {}
private

Definition at line 162 of file RenderingManager.hpp.

Referenced by InternalProcessInput(), and RenderingManager().

◆ KeyboardCallback

std::function<void(std::array<bool, static_cast<int>(KEY_CODE::NUMBER_OF_KEYS)>, double)> Botcraft::Renderer::RenderingManager::KeyboardCallback
private

◆ lastFrameTime

double Botcraft::Renderer::RenderingManager::lastFrameTime
private

Definition at line 174 of file RenderingManager.hpp.

Referenced by RenderingManager(), and Run().

◆ local_player

std::shared_ptr<LocalPlayer> Botcraft::Renderer::RenderingManager::local_player
private

Definition at line 160 of file RenderingManager.hpp.

Referenced by Handle(), RenderingManager(), and Run().

◆ mouse_last_x

double Botcraft::Renderer::RenderingManager::mouse_last_x
private

Definition at line 169 of file RenderingManager.hpp.

Referenced by InternalMouseCallback(), and RenderingManager().

◆ mouse_last_y

double Botcraft::Renderer::RenderingManager::mouse_last_y
private

Definition at line 170 of file RenderingManager.hpp.

Referenced by InternalMouseCallback(), and RenderingManager().

◆ MouseCallback

std::function<void(double, double)> Botcraft::Renderer::RenderingManager::MouseCallback
private

Definition at line 190 of file RenderingManager.hpp.

Referenced by InternalMouseCallback(), RenderingManager(), and SetMouseCallback().

◆ mutex_updating

std::mutex Botcraft::Renderer::RenderingManager::mutex_updating
private

◆ my_shader

std::unique_ptr<Shader> Botcraft::Renderer::RenderingManager::my_shader
private

Definition at line 186 of file RenderingManager.hpp.

Referenced by Init(), and Run().

◆ rendering_thread

std::thread Botcraft::Renderer::RenderingManager::rendering_thread
private

Definition at line 167 of file RenderingManager.hpp.

Referenced by RenderingManager(), and ~RenderingManager().

◆ running

std::atomic<bool> Botcraft::Renderer::RenderingManager::running
private

◆ thread_updating_renderable

std::thread Botcraft::Renderer::RenderingManager::thread_updating_renderable
private

Definition at line 201 of file RenderingManager.hpp.

Referenced by Run().

◆ window

GLFWwindow* Botcraft::Renderer::RenderingManager::window
private

◆ world

std::shared_ptr<World> Botcraft::Renderer::RenderingManager::world
private

Definition at line 157 of file RenderingManager.hpp.

Referenced by Handle(), RenderingManager(), Run(), and WaitForRenderingUpdate().

◆ world_renderer

std::unique_ptr<WorldRenderer> Botcraft::Renderer::RenderingManager::world_renderer
private

Definition at line 187 of file RenderingManager.hpp.

Referenced by Handle(), Init(), RenderingManager(), Run(), and WaitForRenderingUpdate().


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