void DemoApp::render() { keyHandler(); GameEngine::update(); h3dutDumpMessages(); }
void UI::inGameLoop () { initializeGame(); bool quit = false; while (!quit) { if (keyEvent || timeEvent) { string canvas = buildLayout(); system ("cls"); cout << canvas; } updateClock (); timeEvent = false; keyEvent = false; if (timePassed >= fallInterval) { if (engine->translatePiece (0, -1) ); else { int cleared = engine->clearCompleteLines(); if (cleared > 0) { totalLines += cleared; lineProgress += cleared; score += 15 * (level+1) * (calculateExpo(2 , cleared) ); } if (lineProgress >= 10) { lineProgress = lineProgress - 10; level++; fallInterval = 1000 - (100 * level); } if (engine->placeNewPiece(nextPieceCode, 4, 19) ) { nextPiece->clearPiece (); nextPieceCode = rand()%7; nextPiece->placeNewPiece (nextPieceCode, 3, 3); } else quit = true; } timeEvent = true; setClock (); updateClock (); } keyEvent = keyHandler(); Sleep (1); } }
int main(void) { DDRB = 0x0F; int keyboardPushed = 0; int confirmed = 0; int col = 0; int keyIndex = -100; int keyboard[16] = { 7, 8, 9, 47, 4, 5, 6, 42, 1, 2, 3, 45, -1, 0, -2, 43 }; uint8_t columnIndexes[4] = { 0b11111110, 0b11111101, 0b11111011, 0b11110111 }; lcd_init(); lcd_clrscr(); lcd_home(); while (1) { PORTB = columnIndexes[col]; keyboardPushed = isKeyboardPushed(); keyIndex = getKeyIndex(col); if (keyIndex == -100) { displayValues(); } if (keyboardPushed == 1 && confirmed == 0 && keyIndex != -100) { confirmed = 1; keyHandler(keyboard[keyIndex]); } else if (keyboardPushed == 0 && confirmed == 1) { confirmed = 0; } _delay_ms(25); if (keyboardPushed == 0 && ++col==4) { col=0; } } }
void QVFbViewProtocol::sendKeyboardData(QString unicode, int keycode, int modifiers, bool press, bool repeat) { if (keyHandler()) keyHandler()->sendKeyboardData(unicode, keycode, modifiers, press, repeat); }
void Window::OnKey(GLFWwindow * window, int key, int scancode, int action, int mods) { auto ptr = reinterpret_cast<Window *>(glfwGetWindowUserPointer(window)); if(ptr->keyHandler) ptr->keyHandler(key, scancode, action, mods); }
//============================================================================= // METHOD : SPELLwsDictDataHandler::write() //============================================================================= void SPELLwsDictDataHandler::write() { if (getObject() == NULL) { getStorage()->storeLong( -1 ); return; } assert( PyDict_Check(getObject())); SPELLpyHandle keys = PyDict_Keys( getObject() ); unsigned int numItems = PyList_Size( keys.get() ); DEBUG("[DDH] Storing dictionary items (total " + ISTR(numItems) + ") address " + PSTR(getObject())); PyObject* key = NULL; PyObject* item = NULL; long toStore = 0; // Calculate the number of items to store // Store each list item DEBUG("[DDH] Keys of the dictionary:"); for( unsigned int index = 0; index < numItems; index++) { key = PyList_GetItem( keys.get(), index ); item = PyDict_GetItem( getObject(), key ); if (SPELLwsWarmStartImpl::shouldFilter(key,item)) { continue; } else { DEBUG(" - " + PYSSTR(key)); } toStore++; } DEBUG("[DDH] Will store " + ISTR(toStore) + " keys"); // Store the number of items getStorage()->storeLong( (long) toStore ); DEBUG("[DDH] Start checking items"); if (toStore>0) { // Store each list item for( unsigned int index = 0; index < numItems; index++) { key = PyList_GetItem( keys.get(), index ); item = PyDict_GetItem( getObject(), key ); DEBUG("[DDH] Checking item " + PYCREPR(key)); // Do not consider filtered values if (SPELLwsWarmStartImpl::shouldFilter(key,item)) continue; SPELLpythonHelper::instance().checkError(); DEBUG(" [DDH] Key index " + ISTR(index)); DEBUG(" [DDH] Key to use" + PYREPR(key)); DEBUG(" [DDH] Item type:" + PYREPR(PyObject_Type(item))); // Handler for the key SPELLwsObjectDataHandler keyHandler(key); keyHandler.setStorage(getStorage()); DEBUG(" [DDH] Creating handler"); // Create a handler for the item SPELLwsDataHandler* handler = SPELLwsDataHandlerFactory::createDataHandler(item); handler->setStorage(getStorage()); // Store the key DEBUG(" [DDH] Storing key: " + PYREPR(key)); keyHandler.write(); // Store the item data code in order to recognise it later DEBUG(" [DDH] Storing data code: " + SPELLwsData::codeStr(handler->getCode())); handler->storeDataCode(); // IMPORTANT in the case of lists and dictionaries, we want to be able to continue // the storage even if there is a problem in the handler processing at this point. // If that is the case, a fake empty object will be replaced by the object being // processed by the handler, and the dumping of this collection will continue. try { if (handler->getCode() == SPELLwsData::DATA_CUSTOM_TYPE ) { std::string msg = "WARNING! warm start not supported for custom Python types (" + PYREPR(key) + "=" + PYREPR(item) + ")"; LOG_WARN(msg); SPELLexecutor::instance().getCIF().warning(msg); storeFakeObject( SPELLwsData::DATA_NONE ); } else { // Store the value DEBUG(" [DDH] Storing value: " + PYREPR(item)); handler->write(); DEBUG(" [DDH] Storing value done"); } } catch(SPELLcoreException& ex) { std::string msg = "WARNING! WS storage of element " + ISTR(index) + " failed: " + ex.what(); LOG_WARN(msg); SPELLexecutor::instance().getCIF().warning(msg); storeFakeObject( handler->getCode() ); } delete handler; } } DEBUG("[DDH] Storing dictionary done"); }
//============================================================================= // METHOD : SPELLwsDictDataHandler::read() //============================================================================= void SPELLwsDictDataHandler::read() { DEBUG("[DDH] Loading dictionary items"); // Load the number of items int numItems = getStorage()->loadLong(); DEBUG("[DDH] Number of items " + ISTR(numItems)); if (numItems == -1) { setObject(NULL); return; } // Create a dictionary PyObject* dictObject = PyDict_New(); for( unsigned int index = 0; index < (unsigned) numItems; index++) { // We know that first an Object comes, as the key. So make the handler directly. SPELLwsObjectDataHandler keyHandler(NULL); keyHandler.setStorage(getStorage()); DEBUG(" [DDH] Loading key"); keyHandler.read(); PyObject* key = keyHandler.getObject(); DEBUG(" [DDH] Loaded key " + PYREPR(key)); // Load the item code DEBUG(" [DDH] Loading data code"); SPELLwsData::Code code = loadDataCode(); DEBUG(" [DDH] Loaded data code " + SPELLwsData::codeStr(code)); if (code == SPELLwsData::DATA_CUSTOM_TYPE ) { std::string msg = "WARNING! warm start not supported for custom Python types (" + PYREPR(key) + ")"; LOG_WARN(msg); SPELLexecutor::instance().getCIF().warning(msg); getStorage()->loadObject(); // Load none PyDict_SetItem(dictObject, key, Py_None); } else { // Create an appropriate handler SPELLwsDataHandler* handler = SPELLwsDataHandlerFactory::createDataHandler(code); handler->setStorage(getStorage()); try { // Read the data DEBUG(" [DDH] Loading value"); handler->read(); DEBUG(" [DDH] Value loaded " + PYREPR(handler->getObject())); // Add the item to the dictionary PyDict_SetItem(dictObject, key, handler->getObject()); } catch(SPELLcoreException& ex) { std::string msg = "Failed to recover dictionary item " + PYREPR(key) + ": " + ex.what(); LOG_WARN(msg); SPELLexecutor::instance().getCIF().warning(msg); PyDict_SetItem(dictObject, key, Py_None); } delete handler; DEBUG(" [DDH] "); } } DEBUG("[DDH] Dictionary loaded"); // Set it as associated object setObject( dictObject ); }
void Application::mainLoop( float timeSinceLastFrame ) { keyHandler( timeSinceLastFrame ); // Set camera parameters h3dSetNodeTransform( _cam, _x, _y, _z, _rx ,_ry, 0, 1, 1, 1 ); _lightTimer += timeSinceLastFrame; // Has it gone a second since the light changed color? if( _lightTimer >= 1.0f ) { // Set a random light color switch( rand() % 6 ) { case 0: // Red h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f ); break; case 1: // Green h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f ); break; case 2: // Blue h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f ); break; case 3: // Yellow h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f ); break; case 4: // Purple h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f ); break; case 5: // Cyan h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f ); h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f ); break; } // Reset the timer _lightTimer = 0.0f; } // Show stats h3dutShowFrameStats( _fontMatRes, _panelMatRes, _statMode ); if( _statMode > 0 ) { displaySoundInfo(); } // Show logo const float ww = (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportWidthI ) / (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportHeightI ); const float ovLogo[] = { ww-0.4f, 0.8f, 0, 1, ww-0.4f, 1, 0, 0, ww, 1, 1, 0, ww, 0.8f, 1, 1 }; h3dShowOverlays( ovLogo, 4, 1.f, 1.f, 1.f, 1.f, _logoMatRes, 0 ); // Render scene h3dRender( _cam ); // Finish rendering of frame h3dFinalizeFrame(); // Remove all overlays h3dClearOverlays(); // Write all mesages to log file h3dutDumpMessages(); }
void TentacleApplication::mainLoop( float fps ) { _curFPS = fps; _timer += 1 / fps; keyHandler(); h3dSetOption( H3DOptions::DebugViewMode, _debugViewMode ? 1.0f : 0.0f ); h3dSetOption( H3DOptions::WireframeMode, _wireframeMode ? 1.0f : 0.0f ); if( !_freeze ) { float tx,ty,tz,foo; h3dGetNodeTransform(_fly,&tx,&ty,&tz,&foo,&foo,&foo,&foo,&foo,&foo); if (!_freezeFly) { // routhly simulates the random fly of a fly if((rand() % 100)>95) { _dx = ((ranf()))/50.0f; _dy = ((ranf()))/50.0f; _dz = ((ranf()))/50.0f; } // change fly position h3dSetNodeTransform( _fly, tx+_dx, ty+_dy, tz+_dz, 0, 0, 0, 0.2f, 0.2f, 0.2f ); if (tx < -4.0) _dx = 0.05f; if (tx > 4.0) _dx = -0.05f; if (ty < 0.0) _dy = 0.05f; if (ty > 6.0) _dy = -0.05f; if (tz < -4.0) _dz = 0.05f; if (tz > 4.0) _dz = -0.05f; h3dGetNodeTransform(_fly,&tx,&ty,&tz,&foo,&foo,&foo,&foo,&foo,&foo); //update constraint position according to fly position _ikConstraint->setPosition(SMRVector3(tx, ty, tz)); } if (!_freezeIK || _ikStep) { //Compute inverse kinematics _currentSolver->process(); // update tentacle's joint (IK) updateTentacle(); _ikStep = false; } } // Set camera parameters h3dSetNodeTransform( _cam, _x, _y, _z, _rx ,_ry, 0, 1, 1, 1 ); if( _showFPS ) { // Avoid updating FPS text every frame to make it readable if( _timer > 0.3f ) { _fpsText.str( "" ); _fpsText << "FPS: " << fixed << setprecision( 2 ) << _curFPS; _timer = 0; } // Show text //h3dutShowText( _fpsText.str().c_str(), 0, 0.95f, 0.03f, 0, _fontMatRes ); } // Show title //h3dutShowText( "Comparing Standard IK algorithms.", 0.0f, 0.90f, 0.03f, 0, _fontMatRes ); // Show IK method //h3dutShowText( _ikMethodString, 0.6f, 0.80f, 0.03f, 0, _fontMatRes ); // Show logo //h3dShowOverlay( 0.7f, 0.2, 0, 0, // 1, 0.2, 1, 0, // 1, 0.6f, 1, 1, // 0.7f, 0.6f, 0, 1, // 7, _invJacMatRes ); // Render scene h3dRender( _cam ); // Remove all overlays h3dClearOverlays(); // Write all mesages to log file h3dutDumpMessages(); }