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

#include <RenderingManager.hpp>

Inheritance diagram for Botcraft::Renderer::RenderingManager:
ProtocolCraft::Handler ProtocolCraft::GenericHandler< Message, AllMessages >

Public Member Functions

 RenderingManager (std::shared_ptr< World > world_, std::shared_ptr< InventoryManager > inventory_manager_, std::shared_ptr< EntityManager > entity_manager_, const unsigned int &window_width, const unsigned int &window_height, const unsigned int section_height_=16, const bool headless=false)
 
 ~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 SetPosOrientation (const double x_, const double y_, const double z_, const float yaw_, const float pitch_)
 
void Screenshot (const std::string &path)
 
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
 

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

bool Init (const bool headless)
 
void Run (const bool headless)
 
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< Worldworld
 
std::shared_ptr< InventoryManagerinventory_manager
 
std::shared_ptr< EntityManagerentity_manager
 
std::shared_ptr< LocalPlayerlocal_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 has_proj_changed
 
float day_time
 
std::unique_ptr< Shadermy_shader
 
std::unique_ptr< WorldRendererworld_renderer
 
std::unique_ptr< BehaviourRendererbehaviour_renderer
 
std::function< void(double, double)> MouseCallback
 
std::function< void(std::array< bool, static_cast< int >(KEY_CODE::NUMBER_OF_KEYS)>, double)> KeyboardCallback
 
std::string screenshot_path
 
bool take_screenshot
 
bool running
 
std::unordered_set< Positionchunks_to_udpate
 
std::unordered_set< int > entities_to_update
 
std::mutex mutex_updating
 
std::condition_variable condition_update
 
std::thread thread_updating_renderable
 

Detailed Description

Definition at line 50 of file RenderingManager.hpp.

Constructor & Destructor Documentation

◆ RenderingManager()

Botcraft::Renderer::RenderingManager::RenderingManager ( std::shared_ptr< World world_,
std::shared_ptr< InventoryManager inventory_manager_,
std::shared_ptr< EntityManager entity_manager_,
const unsigned int &  window_width,
const unsigned int &  window_height,
const unsigned int  section_height_ = 16,
const bool  headless = false 
)

◆ ~RenderingManager()

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

Member Function Documentation

◆ AddChunkToUpdate()

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

Definition at line 599 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 406 of file RenderingManager.cpp.

References behaviour_renderer.

◆ BehaviourStartTick()

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

Definition at line 401 of file RenderingManager.cpp.

References behaviour_renderer.

◆ BehaviourTickChild()

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

Definition at line 411 of file RenderingManager.cpp.

References behaviour_renderer.

◆ Close()

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

Definition at line 369 of file RenderingManager.cpp.

References running, and window.

◆ Handle() [1/13]

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

Definition at line 754 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 736 of file RenderingManager.cpp.

References AddChunkToUpdate().

◆ Handle() [4/13]

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

Definition at line 748 of file RenderingManager.cpp.

◆ Handle() [5/13]

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

Definition at line 792 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Handle() [6/13]

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

Definition at line 797 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Handle() [7/13]

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

Definition at line 802 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Handle() [8/13]

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

Definition at line 823 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Handle() [9/13]

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

Definition at line 837 of file RenderingManager.cpp.

References world_renderer.

◆ Handle() [10/13]

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

Definition at line 727 of file RenderingManager.cpp.

References AddChunkToUpdate().

◆ Handle() [11/13]

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

Definition at line 807 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 832 of file RenderingManager.cpp.

References day_time.

◆ Handle() [13/13]

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

Definition at line 780 of file RenderingManager.cpp.

References AddEntityToUpdate().

◆ Init()

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

◆ InternalMouseCallback()

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

Definition at line 518 of file RenderingManager.cpp.

References behaviour_open, first_mouse, inventory_open, mouse_last_x, mouse_last_y, MouseCallback, and window.

Referenced by Init().

◆ InternalProcessInput()

◆ IsBehaviourGUIPaused()

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

Definition at line 416 of file RenderingManager.cpp.

References behaviour_renderer.

◆ RemoveBlackboardValue()

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

Definition at line 431 of file RenderingManager.cpp.

References behaviour_renderer.

◆ ResetBehaviourState()

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

Definition at line 396 of file RenderingManager.cpp.

References behaviour_renderer.

◆ ResetBlackboard()

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

Definition at line 421 of file RenderingManager.cpp.

References behaviour_renderer.

◆ ResizeCallback()

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

Definition at line 509 of file RenderingManager.cpp.

References current_window_height, current_window_width, has_proj_changed, and window.

Referenced by Init().

◆ Run()

void Botcraft::Renderer::RenderingManager::Run ( const bool  headless)
private

Definition at line 109 of file RenderingManager.cpp.

References behaviour_open, behaviour_renderer, color_day(), color_night(), 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, 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, my_shader, Botcraft::Logger::RegisterThread(), screenshot_path, Botcraft::Utilities::SleepUntil(), take_screenshot, window, world, world_renderer, Botcraft::Renderer::WriteImage(), Botcraft::Vector3< T >::x, Botcraft::Vector3< T >::y, and Botcraft::Vector3< T >::z.

Referenced by RenderingManager().

◆ Screenshot()

void Botcraft::Renderer::RenderingManager::Screenshot ( const std::string &  path)

Definition at line 385 of file RenderingManager.cpp.

References screenshot_path, and take_screenshot.

◆ SetCurrentBehaviourTree()

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

Definition at line 391 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 380 of file RenderingManager.cpp.

References KeyboardCallback.

◆ SetMouseCallback()

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

Definition at line 375 of file RenderingManager.cpp.

References MouseCallback.

◆ SetPosOrientation()

void Botcraft::Renderer::RenderingManager::SetPosOrientation ( const double  x_,
const double  y_,
const double  z_,
const float  yaw_,
const float  pitch_ 
)

Definition at line 619 of file RenderingManager.cpp.

References world_renderer.

◆ UpdateBlackboardValue()

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

Definition at line 426 of file RenderingManager.cpp.

References behaviour_renderer.

◆ WaitForRenderingUpdate()

Member Data Documentation

◆ behaviour_open

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

◆ behaviour_renderer

◆ chunks_to_udpate

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

Definition at line 190 of file RenderingManager.hpp.

Referenced by AddChunkToUpdate(), and WaitForRenderingUpdate().

◆ condition_update

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

◆ current_window_height

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

Definition at line 172 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 171 of file RenderingManager.hpp.

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

◆ day_time

float Botcraft::Renderer::RenderingManager::day_time
private

Definition at line 176 of file RenderingManager.hpp.

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

◆ deltaTime

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

Definition at line 167 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 191 of file RenderingManager.hpp.

Referenced by AddEntityToUpdate(), and WaitForRenderingUpdate().

◆ entity_manager

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

Definition at line 153 of file RenderingManager.hpp.

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

◆ first_mouse

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

Definition at line 165 of file RenderingManager.hpp.

Referenced by InternalMouseCallback(), and RenderingManager().

◆ has_proj_changed

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

Definition at line 173 of file RenderingManager.hpp.

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

◆ inventory_manager

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

Definition at line 152 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 156 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 168 of file RenderingManager.hpp.

Referenced by RenderingManager(), and Run().

◆ local_player

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

Definition at line 154 of file RenderingManager.hpp.

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

◆ mouse_last_x

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

Definition at line 163 of file RenderingManager.hpp.

Referenced by InternalMouseCallback(), and RenderingManager().

◆ mouse_last_y

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

Definition at line 164 of file RenderingManager.hpp.

Referenced by InternalMouseCallback(), and RenderingManager().

◆ MouseCallback

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

◆ 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 178 of file RenderingManager.hpp.

Referenced by Init(), and Run().

◆ rendering_thread

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

Definition at line 161 of file RenderingManager.hpp.

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

◆ running

bool Botcraft::Renderer::RenderingManager::running
private

◆ screenshot_path

std::string Botcraft::Renderer::RenderingManager::screenshot_path
private

Definition at line 185 of file RenderingManager.hpp.

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

◆ take_screenshot

bool Botcraft::Renderer::RenderingManager::take_screenshot
private

Definition at line 186 of file RenderingManager.hpp.

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

◆ thread_updating_renderable

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

Definition at line 195 of file RenderingManager.hpp.

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

◆ window

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

◆ world

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

Definition at line 151 of file RenderingManager.hpp.

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

◆ world_renderer

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

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