00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 ***************************************************************************/ 00008 /*************************************************************************** 00009 * RCS INFORMATION: 00010 * 00011 * $RCSfile: CaveScene.C,v $ 00012 * $Author: johns $ $Locker: $ $State: Exp $ 00013 * $Revision: 1.55 $ $Date: 2020/02/26 15:51:10 $ 00014 * 00015 ***************************************************************************/ 00029 #include <stdlib.h> 00030 #include <cave_ogl.h> 00031 00032 #include "CaveScene.h" 00033 #include "CaveRoutines.h" 00034 #include "DisplayDevice.h" 00035 #include "Inform.h" 00036 #include "utilities.h" 00037 #include "VMDApp.h" // for VMDexit(); 00038 00039 #define CAVEUSERWLOCK 1 00040 00042 CaveScene::CaveScene(VMDApp *vmdapp) : app(vmdapp) { 00043 #if defined(CAVEUSERWLOCK) 00044 msgInfo << "Creating R/W lock for shared mem access sync.\n" << sendmsg; 00045 draw_rwlock = CAVENewLock(); // allocate a new CAVE lock 00046 CAVESetWriteLock(draw_rwlock); // start out locked for writing 00047 #else 00048 msgInfo << "Creating draw barrier for " << CAVEConfig->ActiveWalls 00049 << " active CAVE walls and master process.\n" << sendmsg; 00050 00051 // setup the drawing barrier used to control slave rendering processes 00052 draw_barrier =(wkf_barrier_t *) malloc_from_CAVE_memory(sizeof(wkf_barrier_t)); 00053 if (draw_barrier == NULL) { 00054 msgErr << "CANNOT ALLOCATE SHARED MEMORY FOR CaveScene CLASS !!!" 00055 << sendmsg; 00056 } 00057 memset(draw_barrier, 0, sizeof(wkf_barrier_t)); 00058 00059 if (getenv("VMDCAVEDRAWPROCS") != NULL) { 00060 wkf_thread_barrier_init_proc_shared(draw_barrier, atoi(getenv("VMDCAVEDRAWPROCS")) + 1); 00061 } else { 00062 wkf_thread_barrier_init_proc_shared(draw_barrier, CAVEConfig->ActiveWalls + 1); 00063 } 00064 #endif 00065 } 00066 00068 CaveScene::~CaveScene(void) { 00069 #if defined(CAVEUSERWLOCK) 00070 CAVEFreeLock(draw_rwlock); // delete the drawing rwlock 00071 #else 00072 // free things allocated from shared memory 00073 free_to_CAVE_memory(draw_barrier); 00074 #endif 00075 00076 } 00077 00078 // Called by CAVElib, on each of the child rendering processes 00079 void CaveScene::draw(DisplayDevice *display) { 00080 #if defined(CAVEUSERWLOCK) 00081 if (display->is_renderer_process()) { 00082 CAVESetReadLock(draw_rwlock); 00083 Scene::draw(display); // draw the scene 00084 CAVEUnsetReadLock(draw_rwlock); 00085 } else { 00086 CAVEUnsetWriteLock(draw_rwlock); 00087 vmd_msleep(1); // give 'em 1 millisecond to draw before re-locking 00088 CAVESetWriteLock(draw_rwlock); 00089 } 00090 #else 00091 // Barrier synchronization for all drawing processes and the master 00092 wkf_thread_barrier(draw_barrier, 0); // wait for start of drawing 00093 Scene::draw(display); // draw the scene 00094 wkf_thread_barrier(draw_barrier, 0); // wait for end of drawing. 00095 #endif 00096 } 00097 00098 // called in VMDupdate, this updates the values of numDisplayable[23]D 00099 // this is called by the parent! 00100 int CaveScene::prepare() { 00101 // check if the ESC key is being pressed; if so, quit 00102 // note: THIS IS A HACK, just for Bill Sherman ;-) 00103 if(CAVEgetbutton(CAVE_ESCKEY)) { 00104 CAVEExit(); 00105 app->VMDexit("Exiting due to Cave escape key being pressed.", 10, 4); 00106 } 00107 00108 return Scene::prepare(); // call regular scene prepare method 00109 } 00110 00111 void *CaveScene::operator new(size_t s) { 00112 return malloc_from_CAVE_memory(s); 00113 } 00114 00115 void CaveScene::operator delete(void *p, size_t) { 00116 free_to_CAVE_memory(p); 00117 } 00118