99*
1010********************************************************************************************/
1111
12- #include " raylib-cpp.hpp "
12+ #include < list >
1313
14- #define MAX_BUNNIES 100000 // 100K bunnies limit
14+ #include " raylib-cpp.hpp "
1515
1616// This is the maximum amount of elements (quads) per batch
1717// NOTE: This value is defined in [rlgl] module and can be changed there
1818#define MAX_BATCH_ELEMENTS 8192
1919
20- #include < vector>
21-
2220class Bunny {
2321 public:
2422 Bunny () {
@@ -58,7 +56,7 @@ int main(void)
5856 // Load bunny texture
5957 raylib::Texture2D texBunny (" resources/wabbit_alpha.png" );
6058
61- std::vector <Bunny> bunnies;
59+ std::list <Bunny> bunnies;
6260
6361 SetTargetFPS (60 ); // Set our game to run at 60 frames-per-second
6462 // --------------------------------------------------------------------------------------
@@ -67,15 +65,10 @@ int main(void)
6765 while (!window.ShouldClose ()) { // Detect window close button or ESC key
6866 // Update
6967 // ----------------------------------------------------------------------------------
70- if (IsMouseButtonDown (MOUSE_LEFT_BUTTON))
71- {
68+ if (IsMouseButtonDown (MOUSE_LEFT_BUTTON)) {
7269 // Create more bunnies
73- for (int i = 0 ; i < 100 ; i++)
74- {
75- if (bunnies.size () < MAX_BUNNIES)
76- {
77- bunnies.emplace_back ();
78- }
70+ for (int i = 0 ; i < 100 ; i++) {
71+ bunnies.emplace_back ();
7972 }
8073 }
8174
@@ -92,14 +85,14 @@ int main(void)
9285 {
9386 window.ClearBackground (RAYWHITE);
9487
95- for (Bunny& bunny: bunnies) {
88+ for (Bunny& bunny : bunnies) {
9689 // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
9790 // a draw call is launched and buffer starts being filled again;
9891 // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
9992 // Process of sending data is costly and it could happen that GPU data has not been completely
10093 // processed for drawing while new data is tried to be sent (updating current in-use buffers)
10194 // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies
102- texBunny.Draw (bunny.position . x , bunny. position . y , bunny.color );
95+ texBunny.Draw (bunny.position , bunny.color );
10396 }
10497
10598 DrawRectangle (0 , 0 , screenWidth, 40 , BLACK);
0 commit comments