Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /examples/iso2d-demo/main.c
ViewVC logotype

Diff of /examples/iso2d-demo/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1917, Thu Jun 7 12:34:40 2012 UTC revision 1918, Thu Jun 7 12:37:38 2012 UTC
# Line 17  Line 17 
17  #endif  #endif
18  #include "util.h"  #include "util.h"
19  #include "load-png.h"  #include "load-png.h"
20    #include "iso2d.h"
21    
22  /* pixel dimensions of output */  /* pixel dimensions of output */
23  #define WIDTH   512  #define WIDTH   512
24  #define HEIGHT  512  #define HEIGHT  512
25    
26    #define STEP_SIZE       1
27    
28  static inline void CheckError ()  static inline void CheckError ()
29  {  {
30      GLenum errCode;      GLenum errCode;
# Line 150  Line 153 
153      }      }
154  }  }
155    
156    void GetData (ISO_World_t *wrld, Nrrd *nData)
157    {
158      // get snapshot of state
159        if (ISO_Snapshot_pos (wrld, nData)) {
160          // error
161            fprintf(stderr, "Error getting nrrd data\n");
162            exit(1);
163        }
164    }
165    
166  int main (int argc, const char **argv)  int main (int argc, const char **argv)
167  {  {
168      State_t     state = { .running = 0 };      State_t     state = { .running = 0 };
# Line 194  Line 207 
207    // load Diderot image for background texture    // load Diderot image for background texture
208      InitTexture ();      InitTexture ();
209    
210    // Main loop (repeated while window is not closed and [ESC] is not pressed)    // initialize the Diderot program
     while (glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC)) {  
         Draw(0);  
     }  
   
 #ifdef DIDEROT_CODE  
211      ISO_World_t *wrld = ISO_Init ();      ISO_World_t *wrld = ISO_Init ();
   
212      ISO_Initially (wrld);      ISO_Initially (wrld);
213    
214      // nrrd for getting computational state
215      Nrrd *nData = nrrdNew();      Nrrd *nData = nrrdNew();
216      do {  
217        // get snapshot of state    // get and render initial state
218          if (ISO_Sapshot_outRGBA (wrld, nData)) {      GetData (wrld, nData);
           // error  
             fprintf(stderr, "Error getting nrrd data\n");  
             return 1;  
         }  
       // render the state  
219          Draw (nData);          Draw (nData);
       // step the computation  
         uint32_t nSteps = ISO_Run (wrld, 1);  
     } while (ISO_NumActive() > 0);  
220    
221      // Main loop (repeated while window is not closed and [ESC] is not pressed)
222        while (glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC)) {
223            if (state.running != 0) {
224                while ((state.running != 0) && (ISO_NumActive(wrld) > 0)) {
225                  // step the computation
226                    NumSteps += ISO_Run (wrld, STEP_SIZE);
227    printf("%d steps, %d active\n", NumSteps, ISO_NumActive(wrld));
228                  // get and render the state
229                    GetData (wrld, nData);
230                    Draw (nData);
231                }
232                if (ISO_NumActive(wrld) == 0) {
233    // get and render final state    // get and render final state
234      if (ISO_OutputGet_outRGBA (wrld, nData)) {                  if (ISO_OutputGet_pos (wrld, nData)) {
235        // error        // error
236          fprintf(stderr, "Error getting nrrd data\n");          fprintf(stderr, "Error getting nrrd data\n");
237          return 1;                      exit(1);
238                    }
239                    Draw (nData);
240                }
241      }      }
242            else {
243                glfwWaitEvents();
244      Draw (nData);      Draw (nData);
245            }
246        }
247    
248      // shutdown the world
249      ISO_Shutdown (wrld);      ISO_Shutdown (wrld);
 #endif  
250    
251    // Terminate AntTweakBar and GLFW    // Terminate AntTweakBar and GLFW
252      TwTerminate();      TwTerminate();

Legend:
Removed from v.1917  
changed lines
  Added in v.1918

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0