/* This is called to indicate to the render loop that it should * stop as soon as possible. */ void Java_com_example_SanAngeles_DemoGLSurfaceView_nativePause( JNIEnv* env ) { sDemoStopped = !sDemoStopped; if (sDemoStopped) { /* we paused the animation, so store the current * time in sTimeStopped for future nativeRender calls */ sTimeStopped = _getTime(); } else { /* we resumed the animation, so adjust the time offset * to take care of the pause interval. */ sTimeOffset -= _getTime() - sTimeStopped; } }
/* This is called to indicate to the render loop that it should * stop as soon as possible. */ void Java_foam_nebogeo_nomadic_FluxusGLSurfaceView_nativePause( JNIEnv* env ) { sDemoStopped = !sDemoStopped; if (sDemoStopped) { /* we paused the animation, so store the current * time in sTimeStopped for future nativeRender calls */ sTimeStopped = _getTime(); } else { /* we resumed the animation, so adjust the time offset * to take care of the pause interval. */ sTimeOffset -= _getTime() - sTimeStopped; } }
/* This is called to indicate to the render loop that it should * stop as soon as possible. */ void Java_cc_co_androidzoo_jplayerg_PlayerRenderer_nativePause( JNIEnv* env ) { sDemoStopped = !sDemoStopped; if (sDemoStopped) { /* we paused the animation, so store the current * time in sTimeStopped for future nativeRender calls */ sTimeStopped = _getTime(); } else { /* we resumed the animation, so adjust the time offset * to take care of the pause interval. */ sTimeOffset -= _getTime() - sTimeStopped; } }
void _resume() { /* we resumed the animation, so adjust the time offset * to take care of the pause interval. */ sDemoStopped = 0; sTimeOffset -= _getTime() - sTimeStopped; }
void doStep(ModelInstance* comp, fmi2IntegerTime hLocal, int inBetween) { if (inBetween == 0) { } else { if ((comp->eventInfo.nextEventTimeDefined && (comp->time == comp->eventInfo.nextEventTime)) || getEventIndicator(comp) < 0) { fmi2IntegerTime currentTime = comp->time; if (_isTime(comp)) { _removeLast(comp); comp->eventInfo.nextEventTimeDefined = fmi2False; } if (!_isEmpty(comp)) { Event nextEvent = _getLast(comp); comp->eventInfo.nextEventTime = nextEvent.time; comp->eventInfo.nextEventTimeDefined = fmi2True; } if (hr(input_) == present_) { _addEvent(comp, r(input_), currentTime + i(delay_)); comp->eventInfo.nextEventTimeDefined = fmi2True; comp->eventInfo.nextEventTime = _getTime(comp); } } comp->time += hLocal; if (hLocal > 0) comp->microstep = 0; else comp->microstep++; } }
/* * Class: jetdrone_nalib_NGLView * Method: nRender * Signature: (I)Z */ static jboolean nRender(JNIEnv *env, jclass clazz, jint pRef, jint dx, jint dy, jint buttons, jfloat sensor_x, jfloat sensor_y, jfloat sensor_z) { if(pRef) { naAppState *instance = (naAppState *) pRef; if(instance->userData) { if (!instance->pause) { long curTick = _getTime(); instance->elapsedTime = (curTick - instance->lastTick) / 1000.f; instance->lastTick = curTick; jboolean result = naRender(instance->userData); /* Update the input struct (for the next update) */ instance->input.dx = dx; instance->input.dy = dy; instance->input.buttons = buttons; instance->input.sensor[0] = sensor_x; instance->input.sensor[1] = sensor_y; instance->input.sensor[2] = sensor_z; if(pthread_cond_signal(&instance->vsyncCond)) { return JNI_FALSE; } return result; } } } return JNI_FALSE; }
void _pause() { /* we paused the animation, so store the current * time in sTimeStopped for future nativeRender calls */ sDemoStopped = 1; sTimeStopped = _getTime(); }
bool _isTime(ModelInstance *comp) { if (_isEmpty()) { return false; } if (comp->time == _getTime() && i(microstep_) == _getIndex()){ return true; } else { return false; } }
fmi2Boolean _isTime(ModelInstance *comp) { if (_isEmpty(comp)) { return fmi2False; } if (comp->time == _getTime(comp) && comp->microstep == _getIndex(comp)){ return fmi2True; } else { return fmi2False; } }
/* * Class: jetdrone_nalib_NGLView * Method: nResume * Signature: (I)Z */ static jboolean nResume(JNIEnv *env, jclass clazz, jint pRef) { if(pRef) { naAppState *instance = (naAppState *) pRef; if (instance->pause) { instance->lastTick = _getTime(); instance->pause = FALSE; } return JNI_TRUE; } return JNI_FALSE; }
/* * Class: jetdrone_nalib_NGLView * Method: nResize * Signature: (III)Z */ static jboolean nResize(JNIEnv *env, jclass clazz, jint pRef, jint w, jint h) { if(pRef) { naAppState *instance = (naAppState *) pRef; if(instance->userData) { /* update freq */ instance->lastTick = _getTime(); instance->elapsedTime = 0.f; return naResize(instance->userData, w, h); } } return JNI_FALSE; }
// Used to set the next time event, if any. void eventUpdate(ModelInstance* comp, fmi2EventInfo* eventInfo, int isTimeEvent) { long currentTime = comp->time; if (_isTime(comp)) { _removeLast(comp); eventInfo->nextEventTimeDefined = fmi2False; } if (!_isEmpty(comp)) { Event nextEvent = _getLast(comp); comp->eventInfo.nextEventTime = nextEvent.time; eventInfo->nextEventTimeDefined = fmi2True; } if (hr(input_) == present_) { _addEvent(comp, r(input_), currentTime + i(delay_)); eventInfo->nextEventTimeDefined = fmi2True; comp->eventInfo.nextEventTime = _getTime(comp); } }
void Java_com_example_SanAngeles_DemoRenderer_nativeRender( JNIEnv* env ) { long curTime; if (sDemoStopped) { curTime = sTimeStopped + sTimeOffset; } else { curTime = _getTime() + sTimeOffset; if (sTimeOffsetInit == 0) { sTimeOffsetInit = 1; sTimeOffset = -curTime; curTime = 0; } } appRender(curTime, sWindowWidth, sWindowHeight); }
/* Call to render the next GL frame */ void Java_com_example_SanAngeles_DemoRenderer_nativeRender( JNIEnv* env ) { long curTime; /* NOTE: if sDemoStopped is TRUE, then we re-render the same frame * on each iteration. */ if (sDemoStopped) { curTime = sTimeStopped + sTimeOffset; } else { curTime = _getTime() + sTimeOffset; if (sTimeOffsetInit == 0) { sTimeOffsetInit = 1; sTimeOffset = -curTime; curTime = 0; } } //__android_log_print(ANDROID_LOG_INFO, "SanAngeles", "curTime=%ld", curTime); appRender(curTime, sWindowWidth, sWindowHeight); }
void Log(const char *who, const char *fmt, ...) { FILE *fp = fpLog?fpLog:stdout; if(fp) { char strTime[30]; va_list va; #if 0 time_t t; time(&t); strftime( strTime, sizeof(strTime), "%Y-%m-%d %H:%M:%S", localtime( &t) ); #else _getTime(strTime); #endif fprintf(fp, "[%s] [%s] ", strTime, who); va_start(va, fmt); vfprintf(fp, fmt, va); va_end(va); fprintf(fp, "\n"); } }
/* * Class: jetdrone_nalib_NGLView * Method: nCreate * Signature: (Ljetdrone/nalib/JNI;)I */ static jint nCreate(JNIEnv *env, jclass clazz, jobject cb) { naAppState *instance = malloc(sizeof(naAppState)); if(instance) { instance->pause = 0; /* update freq */ instance->lastTick = _getTime(); instance->elapsedTime = 0.f; /* init pthreads */ instance->done = FALSE; pthread_cond_init(&instance->vsyncCond, NULL); pthread_mutex_init(&instance->vsyncMutex, NULL); /* Clean User Input struct */ instance->input.dx = 0.f; instance->input.dy = 0.f; instance->input.buttons = 0; instance->input.sensor[0] = 0.f; instance->input.sensor[1] = 0.f; instance->input.sensor[2] = 0.f; /* User Data */ void * userData = naCreate(cb); if(userData) { instance->userData = userData; if(!pthread_create(&instance->updateThread, NULL, update_thread, instance)) { return (jint) ((jint *) instance); } } free(instance); return 0; } return 0; }
// ------------------ calcBestVariant ---------------------- void CBriefcase::calcBestVariant() { _setTime(); for (int i=1; i<=ITER_COUNT; i++) { NoUsedProfit = 0; BestCost = 0; BestProfit = 0; CurCost = 0; CurProfit = 0; for (int i=0; i<(int)NumItem; i++) { NoUsedProfit += invest[i].profit; cur[i] = false; best[i] = false; } search(); } _getTime(); }
// Used to set the next time event, if any. void eventUpdate(ModelInstance* comp, fmi2EventInfo* eventInfo, int isTimeEvent) { long currentTime = comp->time; // printf("DELAY: eventUpdate, time = %ld, _isTime(comp) = %d\n", comp->time, _isTime(comp)); if (_isTime(comp)) { _removeLast(); eventInfo->nextEventTimeDefined = fmi2False; } if (!_isEmpty()) { Event nextEvent = _getLast(); comp->eventInfo.nextEventTime = nextEvent.time; eventInfo->nextEventTimeDefined = fmi2True; // printf("- not empty\n"); // printf("- eventInfo->nextEventTimeDefined = fmi2True\n"); // printf("- addedEvent at time %ld, %ld\n", _getTime(), _getIndex()); } if (hr(input_) == present_) { _addEvent(comp, r(input_), currentTime + i(delay_)); eventInfo->nextEventTimeDefined = fmi2True; comp->eventInfo.nextEventTime = _getTime(); // printf("- present\n"); // printf("- eventInfo->nextEventTimeDefined = fmi2True\n"); // printf("- addedEvent at time %ld, %ld\n", _getTime(), _getIndex()); } }
void _resume() { sDemoStopped = 0; sTimeOffset -= _getTime() - sTimeStopped; }
void _pause() { sDemoStopped = 1; sTimeStopped = _getTime(); }
int CmdController::Execute() { int return_code = CMD_SUCCESS; try { switch (_cmd) { case CMD_PUT: { WorkProc::getInstance().getQueue()->push(_getQueueName(), _getPriority(), _getData()); _result = std::string("ok\n"); break; } case CMD_GET: { std::string *data = WorkProc::getInstance().getQueue()->pop(_getQueueName()); if (data != NULL) { _result = std::string(*data); delete data; } else { _result = std::string("::no tasks::\n"); } break; } case CMD_POSTPONED: { WorkProc::getInstance().getQueue()->push_postponed(_getQueueName(), _getTime(), _getData()); _result = std::string("ok\n"); break; } case CMD_LENGTH: { _result = std::to_string(WorkProc::getInstance().getQueue()->length(_getQueueName())); break; } case CMD_LIST: _result = WorkProc::getInstance().getQueue()->getQueueList(); break; case CMD_CLEAR: WorkProc::getInstance().getQueue()->clear(_getQueueName()); _result = std::string("ok\n"); break; case CMD_COUNTERS_GET: _result = std::to_string(WorkProc::getInstance().getCounters()->get(_getQueueName())); break; case CMD_COUNTERS_INC: WorkProc::getInstance().getCounters()->inc(_getQueueName()); _result = std::string("ok\n"); break; case CMD_COUNTERS_DEC: WorkProc::getInstance().getCounters()->dec(_getQueueName()); _result = std::string("ok\n"); break; case CMD_COUNTERS_CLEAR: WorkProc::getInstance().getCounters()->clear(_getQueueName()); _result = std::string("ok\n"); break; case CMD_COUNTERS_LIST: _result = WorkProc::getInstance().getCounters()->getList(); break; default: { _result = std::string("Unknown command\n"); return_code = CMD_ERROR; break; } } } catch (const std::exception &ex) { _result = std::string(ex.what()); return_code = CMD_ERROR; } return return_code; }
int CmdController::_getPriority() { //return _buf[_buf[1] + 2]; return _getTime(); }