World: Re-use RectangleShapes for rendering
sf::RectangleShapes were created brand new each frame, which takes a lot of time. Instead, keep an array of them available and update them instead of creating new ones. This also allows a nice optimization of only updating them if needed, by checking their previous value. Update the available number of rects when the window resizes.
This commit is contained in:
parent
c875adfcbb
commit
10d0dee35d
3 changed files with 23 additions and 8 deletions
3
main.cpp
3
main.cpp
|
@ -15,10 +15,12 @@ int main()
|
|||
World world(32,32);
|
||||
world.setBlock(BlockType::AIR,1,1,30,30);
|
||||
world.setBlock(BlockType::WALL,4,4,2,2);
|
||||
world.setBlock(BlockType::WALL, 4, 6, 1, 10);
|
||||
world.player.move(2,2);
|
||||
std::cout << world << std::endl;
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode(1000,1000),"Da raycasting");
|
||||
world.resizeWindow(sf::FloatRect(0,0, 1000, 1000));
|
||||
#ifdef IMGUI
|
||||
if (!ImGui::SFML::Init(window)) {
|
||||
std::cout << "Failed to init Dear ImGui SFML" << std::endl;
|
||||
|
@ -47,6 +49,7 @@ int main()
|
|||
static_cast<float>(event.size.width),
|
||||
static_cast<float>(event.size.height));
|
||||
window.setView(sf::View(newView));
|
||||
world.resizeWindow(newView);
|
||||
continue;
|
||||
}
|
||||
#ifdef IMGUI
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue