void KBBGraphic::moveSelection(int drow, int dcol) { if ( !dcol && !drow || !inputAccepted ) { return; } curCol += dcol; curRow += drow; updateElement( curCol - dcol, curRow - drow ); updateElement( curCol, curRow ); }
void MenuSystem::process() { ClientStateSystem* gameState = static_cast<ClientStateSystem*>( m_world->getSystem(SystemType::ClientStateSystem)); if(gameState->getStateDelta(GameStates::LOADING) == EnumGameDelta::ENTEREDTHISFRAME){ auto rocketEventManager = static_cast<LibRocketEventManagerSystem*>( m_world->getSystem(SystemType::LibRocketEventManagerSystem)); rocketEventManager->clearDocumentStack(); rocketEventManager->loadWindow("loading"); } else if(gameState->getStateDelta(GameStates::LOBBY) == EnumGameDelta::ENTEREDTHISFRAME){ auto rocketEventManager = static_cast<LibRocketEventManagerSystem*>( m_world->getSystem(SystemType::LibRocketEventManagerSystem)); static_cast<LobbySystem*>( m_world->getSystem(SystemType::LobbySystem))->resetAllPlayers(); auto rocketBackend = static_cast<LibRocketBackendSystem*>( m_world->getSystem(SystemType::LibRocketBackendSystem)); rocketBackend->updateElement(m_lobbyDocIdx, "player_ready", "Ready"); string temp = "Name: "; temp += m_tcpClient->getServerName(); rocketBackend->updateElement(m_lobbyDocIdx, "server_name", temp.c_str()); temp = "Round Time(sec): "; temp += toString(m_tcpClient->getServerGameTime()); rocketBackend->updateElement(m_lobbyDocIdx, "server_time", temp.c_str()); rocketEventManager->clearDocumentStack(); rocketEventManager->loadWindow("lobby"); SettingsSystem* settings = static_cast<SettingsSystem*> (m_world->getSystem(SystemType::SettingsSystem)); settings->writeSettingsFile(); } else if(gameState->getStateDelta(GameStates::MENU) == EnumGameDelta::ENTEREDTHISFRAME){ auto rocketEventManager = static_cast<LibRocketEventManagerSystem*>( m_world->getSystem(SystemType::LibRocketEventManagerSystem)); rocketEventManager->clearDocumentStack(); rocketEventManager->loadWindow("main_menu"); if (gameState->getStateDelta(GameStates::INGAME) == EnumGameDelta::EXITTHISFRAME){ auto menuBackgroundSys = static_cast<MenuBackgroundSceneSystem*>( m_world->getSystem(SystemType::MenuBackgroundSceneSystem)); menuBackgroundSys->setEnabled(true); } } }
std::string VCardUpdateSerializer::serializePayload(std::shared_ptr<VCardUpdate> vcardUpdate) const { XMLElement updateElement("x", "vcard-temp:x:update"); std::shared_ptr<XMLElement> photoElement(new XMLElement("photo")); photoElement->addNode(std::make_shared<XMLTextNode>(vcardUpdate->getPhotoHash())); updateElement.addNode(photoElement); return updateElement.serialize(); }
struct NumArray* NumArrayCreate(int *nums, int size) { struct NumArray *t = (struct NumArray*)malloc(sizeof(struct NumArray)); t->nums = (int*)malloc(sizeof(int)*size); memcpy(t->nums, nums, sizeof(int)*size); t->size = size; t->sums = (int*)malloc(sizeof(int)*(size+1)); memset(t->sums, 0, sizeof(int)*(size+1)); for(int i = 0; i <= size; i++) updateElement(t, i, nums[i]); return t; }
void KBBGraphic::keyPressEvent( QKeyEvent* e ) { if (inputAccepted) { int oldRow = curRow; int oldCol = curCol; switch( e->key() ) { // Look at the key code case Key_Left: // If 'left arrow'-key, if( curCol > 0 ) { // and cr't not in leftmost col curCol--; // set cr't to next left column } break; case Key_Right: // Correspondingly... if( curCol < numCols-1 ) { curCol++; } break; case Key_Up: if( curRow > 0 ) { curRow--; } break; case Key_Down: if( curRow < numRows-1 ) { curRow++; } break; case Key_Return: case Key_Enter: emit inputAt( curCol, curRow, LeftButton ); break; default: // If not an interesting key, e->ignore(); // we don't accept the event return; } updateElement( oldCol, oldRow ); updateElement( curCol, curRow ); } }
void KBBGraphic::mouseMoveEvent( QMouseEvent* e ) { if (inputAccepted) { int oldRow = curRow; int oldCol = curCol; QPoint pos = e->pos(); // extract pointer position int movRow = pos.y() / cellH; int movCol = pos.x() / cellW; // kdDebug(12009) << movRow << " " << curRow << endl; if ( (curRow != movRow) // if current cell has moved, || (curCol != movCol) ) { curRow = movRow; curCol = movCol; updateElement( oldCol, oldRow ); emit inputAt( curCol, curRow, e->state() ); } } }
/* Handles mouse press events for the KBBGraphic widget. */ void KBBGraphic::mousePressEvent( QMouseEvent* e ) { if (inputAccepted) { /* * Middle click finishes the game. */ if (e->button() == MidButton) { emit endMouseClicked(); return; } int oldRow = curRow; int oldCol = curCol; QPoint pos = e->pos(); // extract pointer position curRow = pos.y() / cellH; curCol = pos.x() / cellW; //kdDebug(12009) << e->state() << " " << LeftButton << " " << e->state()&LeftButton << endl; updateElement( oldCol, oldRow ); emit inputAt( curCol, curRow, e->button() ); } }
/* Set a property by name. */ static int setXmlListPropertyByName(Ejs *ejs, EjsXML *list, EjsName qname, EjsObj *value) { EjsXML *elt, *targetObject; int index; if (!isdigit((uchar) qname.name->value[0])) { return setAlphaPropertyByName(ejs, list, qname, value); } /* Numeric property */ targetObject = 0; if (list->targetObject) { /* Find the real underlying target object. May be an XML object or XMLList if it contains multiple elements. */ targetObject = resolve(ejs, list->targetObject); if (targetObject == 0) { /* Spec says so - TODO why no error? */ return 0; } } index = ejsAtoi(ejs, qname.name, 10); if (index >= mprGetListLength(list->elements)) { /* Create, then fall through to update */ elt = createElement(ejs, list, targetObject, qname, value); if (elt == 0) { return 0; } } else { elt = mprGetItem(list->elements, index); } assure(elt); updateElement(ejs, list, elt, index, value); return index; }
Mat solveEqs (LDU * factorTable, Mat * pMat) { //factorTable Mat L, D, U; //pMat int n; Elem * pCurrentB; //result: factorTable * result = B Mat result; //检测因子表指针是否为空 if ( factorTable == NULL ) { printf ("solveEqs:The point of factorTable is empty!!\n"); return NULL; } //检测因子表中LDU矩阵是否为空 U = (*factorTable)->matU; D = (*factorTable)->matD; L = (*factorTable)->matL; if ( MatIsEmpty (&L) || MatIsEmpty (&D) || MatIsEmpty (&U) ) { printf ("solveEqs:There is an empty Matix in the factorTable!!\n"); return NULL; } //检测pMat指针是否为空 if ( pMat == NULL ) { printf ("solveEqs: This is an empty pMat!!\n"); return NULL; } //检测矩阵是否为空 else if ( MatIsEmpty (pMat) ) { printf ("solveEqs: Matix is empty!!\n"); return NULL; } else { n = (*pMat)->Ni; pCurrentB = (*pMat)->HEAD; } //初始化Mat result InitMat (&result, n, 1); //复制pMat->result while ( pCurrentB != NULL ) { addElement (pCurrentB->VA, pCurrentB->IA, pCurrentB->JA, &result); pCurrentB = pCurrentB->NEXT; } //利用L矩阵进行前代运算 int i, k; double Dk, Lik, Bk, Bi, Uik; for ( k = 1; k <= n - 1; k++ ) { if ( (Bk = findElemValue (&result, k, 1)) != 0 ) { for ( i = k + 1; i <= n; i++ ) { if ( (Lik = findElemValue (&L, i, k)) !=0 ) { Bi = findElemValue (&result, i, 1); Bi = Bi - Lik*Bk; if ( Bi == 0 ) { if ( findElemValue (&result, i, 1) != 0 ) { removeElement (&result, i, 1); } } else { updateElement (Bi, i, 1, &result); } } } } } //利用D矩阵进行除法运算 for ( k = 1; k <= n; k++ ) { if ( (Dk = findElemValue (&D, k, k)) != 0 ) { if ( (Bk = findElemValue (&result, k, 1)) != 0) { Bk = Bk / Dk; updateElement (Bk, k, 1, &result); } else continue; } else { printf ("solveEqs: D[%d %d] is zero!!\n"); return NULL; } } //showMat (&result); //利用U矩阵进行回代运算 for ( k = n; k >= 2; k-- ) { if ( (Bk = findElemValue (&result, k, 1)) != 0 ) { for ( i = k - 1; i >= 1; i-- ) { if ( (Uik = findElemValue (&U, i, k)) != 0 ) { Bi = findElemValue (&result, i, 1); Bi = Bi - Uik*Bk; if ( Bi == 0 ) { if ( findElemValue (&result, i, 1) != 0 ) { removeElement (&result, i, 1); } } else { updateElement (Bi, i, 1, &result); } } } } else continue; } return result; }
LDU CalFactorT (const Mat * pMat) { int n, m, i, j, p; double Vpj1, Vpj2, Vpj, Vpp, Vij1, Vij2, Vij, Vip; Elem * pCurrent; //检测pMat指针是否为空 if ( pMat == NULL ) { printf ("CalFactorT: This is an empty pMat!!\n"); return NULL; } //检测矩阵是否为空 else if (MatIsEmpty (pMat)) { printf ("CalFactorT: Matix is empty!!\n"); return NULL; } else { n = (*pMat)->Ni; m = (*pMat)->Nj; if ( n != m ) { printf ("CalFactorT: Matix is [%d %d], can't calculate FactorTable!!\n", n, m); return NULL; } else { //初始化LDU因子表指针及其指向的因子表 LDU factorTable; factorTable = (matLDU *)malloc (sizeof(matLDU)); Mat matL, matD, matU; //初始化因子表中的稀疏矩阵 InitMat (&matL, n, m); InitMat (&matD, n, m); InitMat (&matU, n, m); //对LDU因子表中个稀疏矩阵进行赋值 factorTable->matL = matL; factorTable->matD = matD; factorTable->matU = matU; //因子表中L、D、U矩阵求解及赋值 //复制矩阵*pMat到matD pCurrent = (*pMat)->HEAD; while (pCurrent != NULL) { addElement (pCurrent->VA, pCurrent->IA, pCurrent->JA, &matD); pCurrent = pCurrent->NEXT; } //求FactorTable for ( p = 1; p <= n - 1; p++ ) { for ( j = p + 1; j <= m; j++ ) { if ( (Vpp = findElemValue (&matD, p, p)) != 0 ) { if ( (Vpj1 = findElemValue (&matD, p, j)) != 0 ) { Vpj2 = Vpj1 / Vpp; updateElement (Vpj2, p, j, &matD); } } else printf ("CalFactorTError: A[%d %d]=0, Division by zero!!\n", p, p); for ( i = p + 1; i <= n; i++ ) { if ( ((Vpj = findElemValue (&matD, p, j))== 0) | ((Vip = findElemValue (&matD, i, p)) == 0) ) { } else { Vij1 = findElemValue (&matD, i, j); Vij2 = Vij1 - Vpj*Vip; if ( (Vij2 != 0) & (Vij1 != 0) ) { updateElement (Vij2, i, j, &matD); } else if ( (Vij2 == 0) & (Vij1 != 0) ) { removeElement (&matD, i, j); } else if ( (Vij2 != 0) & (Vij1 == 0) ) { addElement (Vij2, i, j, &matD); } else { } } } } } //showMat (&matD); //分别求解matU,matL,matD //追加matL与matU矩阵元素 pCurrent = matD->HEAD; while (pCurrent != NULL) { i = pCurrent->IA; j = pCurrent->JA; Vij = pCurrent->VA; if ( i > j ) { Vij = Vij / findElemValue (&matD, j, j); addElement (Vij, i, j, &matL); } else if ( i < j ) { addElement (Vij, i, j, &matU); } else { addElement (1, i, j, &matU); addElement (1, i, j, &matL); } pCurrent = pCurrent->NEXT; } //matD矩阵单位化(删除非对角线元素) pCurrent = matD->HEAD; while (pCurrent != NULL) { i = pCurrent->IA; j = pCurrent->JA; if ( i != j ) { pCurrent = pCurrent->NEXT; removeElement (&matD, i, j); } else pCurrent = pCurrent->NEXT; } return factorTable; } } }
void update(struct NumArray* numArray, int i, int val) { int d = val-numArray->nums[i]; numArray->nums[i] = val; updateElement(numArray, i, d); }