Advertisement
Guest User

timingTest

a guest
Oct 5th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. #include "testApp.h"
  2.  
  3. #define stageWidth 1920
  4.  
  5. bool linePos[stageWidth];
  6. double beltPos = 0;
  7. unsigned long lastUpdateTime;
  8.  
  9. ofFbo mainFBO;
  10. int fboHeight = 700;
  11. bool bShowLines = true;
  12.  
  13. float cnt = 0;
  14.  
  15. int cstep;
  16. unsigned long dur = 0;
  17.  
  18. int dstep;
  19. unsigned long ddur = 0;
  20.  
  21. //--------------------------------------------------------------
  22. void testApp::setup(){
  23.  
  24. ofSetVerticalSync(true);
  25. //ofSetFrameRate(30);
  26.  
  27. mainFBO.allocate(stageWidth,fboHeight,GL_RGBA);
  28.  
  29.  
  30. ofBackground(255, 255, 0);
  31. // ofSetBackgroundAuto(false);
  32. }
  33.  
  34. //--------------------------------------------------------------
  35. void testApp::update(){
  36.  
  37.  
  38. // unsigned long updateDT = ofGetElapsedTimeMicros() - lastUpdateTime;
  39. // lastUpdateTime = ofGetElapsedTimeMicros();
  40. // beltPos = beltPos + (beltSpeed * updateDT);
  41.  
  42.  
  43. // beltPos = (ofGetElapsedTimeMicros()/6000) % stageWidth;
  44. //1
  45. cout<<"upat";
  46. cout<<" "<<ofGetElapsedTimeMicros() - dur<<"\t";
  47. dur = ofGetElapsedTimeMicros();
  48. cstep++;
  49.  
  50. beltPos += ofGetLastFrameTime()*200;
  51.  
  52. if(beltPos > stageWidth) beltPos = 0;
  53.  
  54. if(bShowLines){
  55. if(beltPos == 0){
  56. for(int i=0; i<stageWidth; i++){
  57. linePos[i] = false;
  58. }
  59. }
  60. linePos[int(beltPos)] = true;
  61. }
  62.  
  63. //2
  64. cout<<" "<<ofGetElapsedTimeMicros() - dur<<"\t";
  65. dur = ofGetElapsedTimeMicros();
  66. cstep++;
  67.  
  68. mainFBO.begin();
  69.  
  70. //3
  71. cout<<" "<<ofGetElapsedTimeMicros() - dur<<"\t";
  72. dur = ofGetElapsedTimeMicros();
  73. cstep++;
  74.  
  75. ofClear(255, 255, 255);
  76.  
  77. //4
  78. cout<<" "<<ofGetElapsedTimeMicros() - dur<<"\t";
  79. dur = ofGetElapsedTimeMicros();
  80. cstep++;
  81.  
  82. // ofFill();
  83. // ofSetColor(255);
  84. // ofRect(0, 0, stageWidth, fboHeight);
  85.  
  86. if(bShowLines){
  87. ofSetColor(0, 0, 255);
  88. for(int i=0; i<stageWidth; i++){
  89. if(linePos[i] == true) ofLine(i,350,i,fboHeight);
  90.  
  91. }
  92. }
  93. //5
  94. cout<<" "<<ofGetElapsedTimeMicros() - dur<<"\t";
  95. dur = ofGetElapsedTimeMicros();
  96. cstep++;
  97.  
  98. mainFBO.end();
  99.  
  100. //6
  101. cout<<" "<<ofGetElapsedTimeMicros() - dur<<"\t";
  102. dur = ofGetElapsedTimeMicros();
  103. cstep++;
  104.  
  105. cnt+= 3.3;
  106. if(cnt > stageWidth) cnt = 0;
  107.  
  108. cstep=0;
  109. //cout<<endl;
  110. }
  111.  
  112. //--------------------------------------------------------------
  113. void testApp::draw(){
  114.  
  115.  
  116. //1
  117. cout<<"draw";
  118. cout<<" "<<ofGetElapsedTimeMicros() - ddur<<"\t";
  119. ddur = ofGetElapsedTimeMicros();
  120. dstep++;
  121.  
  122.  
  123. ofSetColor(255);
  124. mainFBO.draw(0,200,stageWidth,400);
  125.  
  126. //2
  127. cout<<" "<<ofGetElapsedTimeMicros() - ddur<<"\t";
  128. ddur = ofGetElapsedTimeMicros();
  129. dstep++;
  130.  
  131. if(bShowLines){
  132. ofSetColor(255, 0, 0);
  133. for(int i=0; i<stageWidth; i++){
  134. if(linePos[i] == true) ofLine(i,0,i,250);
  135. }
  136. }
  137.  
  138. //3
  139. cout<<" "<<ofGetElapsedTimeMicros() - ddur<<"\t";
  140. ddur = ofGetElapsedTimeMicros();
  141. dstep++;
  142.  
  143. ofSetColor(255, 0, 0);
  144. ofFill();
  145. //ofCircle(beltPos, 300, 50);
  146. ofRect(beltPos, 300, 50,50);
  147.  
  148. //4
  149. cout<<" "<<ofGetElapsedTimeMicros() - ddur<<"\t";
  150. ddur = ofGetElapsedTimeMicros();
  151. dstep++;
  152.  
  153. ofSetColor(0, 0, 255);
  154. // ofCircle(cnt, 350, 30);
  155. ofRect(cnt, 300, 30,30);
  156.  
  157. //4
  158. cout<<" "<<ofGetElapsedTimeMicros() - ddur<<"\t";
  159. ddur = ofGetElapsedTimeMicros();
  160. dstep++;
  161.  
  162. cout<<endl;
  163. dstep = 0;
  164. //ofCircle(mouseX,mouseY, 20, 20);
  165. }
  166.  
  167. //--------------------------------------------------------------
  168. void testApp::keyPressed(int key){
  169.  
  170. }
  171.  
  172. //--------------------------------------------------------------
  173. void testApp::keyReleased(int key){
  174. if(key == 'f') ofToggleFullscreen();
  175. if(key == ' ') bShowLines =!bShowLines;
  176. }
  177.  
  178. //--------------------------------------------------------------
  179. void testApp::mouseMoved(int x, int y){
  180.  
  181. }
  182.  
  183. //--------------------------------------------------------------
  184. void testApp::mouseDragged(int x, int y, int button){
  185.  
  186. }
  187.  
  188. //--------------------------------------------------------------
  189. void testApp::mousePressed(int x, int y, int button){
  190.  
  191. }
  192.  
  193. //--------------------------------------------------------------
  194. void testApp::mouseReleased(int x, int y, int button){
  195.  
  196. }
  197.  
  198. //--------------------------------------------------------------
  199. void testApp::windowResized(int w, int h){
  200.  
  201. }
  202.  
  203. //--------------------------------------------------------------
  204. void testApp::gotMessage(ofMessage msg){
  205.  
  206. }
  207.  
  208. //--------------------------------------------------------------
  209. void testApp::dragEvent(ofDragInfo dragInfo){
  210.  
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement