Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Spawn multiple balls in a frame when the throughput is greater than t…

…he frame rate.

readLog() is now called each frame but will only read entries while
entires.size() < buffer_row_count.

This is still a bit rough but it's an improvement over how it was.
  • Loading branch information...
commit da13fa6bedbcdb926d399a5122955e86f4f59eb1 1 parent 0258433
Andrew Caudwell authored

Showing 1 changed file with 20 additions and 10 deletions. Show diff stats Hide diff stats

  1. 30  src/logstalgia.cpp
30  src/logstalgia.cpp
@@ -481,14 +481,14 @@ BaseLog* Logstalgia::getLog() {
481 481
 std::string whitespaces (" \t\f\v\n\r");
482 482
 
483 483
 void Logstalgia::readLog() {
484  
-    debugLog("readLog()\n");
485  
-
  484
+    if(entries.size() >= buffer_row_count) return;
  485
+    
486 486
     int entries_read = 0;
487 487
 
488 488
     std::string linestr;
489 489
     BaseLog* baselog = getLog();
490 490
 
491  
-    while( baselog->getNextLine(linestr) ) {
  491
+    while( entries.size() < buffer_row_count && baselog->getNextLine(linestr) ) {
492 492
 
493 493
         //trim whitespace
494 494
         if(linestr.size()>0) {
@@ -542,8 +542,6 @@ void Logstalgia::readLog() {
542 542
                 entries_read++;
543 543
             }
544 544
         }
545  
-
546  
-        if(entries_read>=buffer_row_count) break;
547 545
     }
548 546
 
549 547
     if(entries.size()==0 && seeklog != 0) {
@@ -780,7 +778,8 @@ void Logstalgia::logic(float t, float dt) {
780 778
 
781 779
         spawn_speed = (items_to_spawn <= 0) ? 0.1f/simu_speed : (1.0f / items_to_spawn) / simu_speed;
782 780
         spawn_delay = 0.0f;
783  
-        //debugLog("spawn_speed = %.2f\n", spawn_speed);
  781
+
  782
+        //fprintf(stderr, "spawn_speed for %d items is %.2f\n", items_to_spawn, spawn_speed);
784 783
         profile_stop();
785 784
 
786 785
         //display date
@@ -802,20 +801,31 @@ void Logstalgia::logic(float t, float dt) {
802 801
 
803 802
     lasttime=currtime;
804 803
 
  804
+    int max_entries_per_frame = (int) std::max(1.0f, dt / spawn_speed);
  805
+
805 806
     //see if entries show appear
806 807
     if(entries.size() > 0 && spawn_delay<=0) {
807 808
         profile_start("add entries");
808 809
 
809  
-        LogEntry le = entries[0];
810  
-        if(le.timestamp < currtime) {
811  
-            addBall(le, -spawn_delay);
  810
+        int added=0;
  811
+
  812
+        while(added<max_entries_per_frame) {
  813
+            LogEntry le = entries[0];
  814
+            if(le.timestamp > currtime) break;
812 815
 
  816
+            added++;
  817
+            addBall(le, -(spawn_delay + (dt/(float)added)));
813 818
             entries.pop_front();
814 819
         }
815 820
 
  821
+        //fprintf(stderr, "added %d of maximum %d (spawn_speed = %.4f)\n", added, max_entries_per_frame, spawn_speed);
  822
+
816 823
         profile_stop();
817 824
     }
818 825
 
  826
+    readLog();
  827
+
  828
+    /*
819 829
     //read log if we run out
820 830
     if(entries.size()==0) {
821 831
         profile_start("readLog");
@@ -825,7 +835,7 @@ void Logstalgia::logic(float t, float dt) {
825 835
 
826 836
 
827 837
         profile_stop();
828  
-    }
  838
+    }*/
829 839
 
830 840
     spawn_delay -= sdt;
831 841
 

0 notes on commit da13fa6

Please sign in to comment.
Something went wrong with that request. Please try again.