void Communication::reactOnMessage(Message_t* message) { if (message == NULL) return; #ifndef TILES_COMPATABLE react((char*)&message->data[0], message); #else react((char*)&message->data[1], message); #endif }
void gen_board_remove(struct board_data *board, struct creature *ch, char *argument) { struct creature *player; PGresult *res; int idx; if (IS_PC(ch)) player = ch; else if (ch->desc && ch->desc->original) player = ch->desc->original; else { send_to_char(ch, "You're a mob. Go awei.\r\n"); return; } idx = atoi(argument) - 1; if (idx < 0) { send_to_char(ch, "That is not a valid message.\r\n"); return; } // First we find the idnum of the thing we want to destroy res = sql_query ("select idnum, author from board_messages where board='%s' order by idnum limit 1 offset %d", tmp_sqlescape(board->name), idx); if (PQntuples(res) != 1) { send_to_char(ch, "That posting doesn't exist!\r\n"); return; } if (ALLOW != react(board->read_perms, player) || ALLOW != react(board->post_perms, player)) { send_to_char(ch, "%s\r\n", board->deny_remove); return; } if (GET_IDNUM(player) != atol(PQgetvalue(res, 0, 1)) && ALLOW != react(board->remove_perms, player)) { send_to_char(ch, "%s\r\n", board->not_author); return; } sql_exec("delete from board_messages where idnum=%s", PQgetvalue(res, 0, 0)); act("$n rips a post off of the board.", true, ch, NULL, NULL, TO_ROOM); send_to_char(ch, "The posting was deleted.\r\n"); }
bool eventFilter(QObject *watched, QEvent *event) override { Q_ASSERT(watched->isWidgetType()); if (event->type() == QEvent::Resize || event->type() == QEvent::Move || event->type() == QEvent::ActivationChange) react(static_cast<QWidget*>(watched)); else if (event->type() == QEvent::Show) { react(static_cast<QWidget*>(watched)); show(); } else if (event->type() == QEvent::Hide) hide(); else if (event->type() == QEvent::Close) close(); return false; }
void gen_board_write(struct board_data *board, struct creature *ch, char *argument) { struct creature *player; if (IS_PC(ch)) player = ch; else if (ch->desc && ch->desc->original) player = ch->desc->original; else { send_to_char(ch, "You're a mob. Go awei.\r\n"); return; } if (ALLOW != react(board->post_perms, player)) { send_to_char(ch, "%s\r\n", board->deny_post); return; } if (!*argument) { send_to_char(ch, "If you wish to post a message, write <subject of message>\r\n"); return; } act("$n starts to write on the board.", true, ch, NULL, NULL, TO_ROOM); SET_BIT(PLR_FLAGS(ch), PLR_WRITING); start_editing_board(ch->desc, board->name, -1, argument, NULL); }
void FuzzyAbstractController::update() { unsigned long now = millis(); gyro -> update(); currentPitch = (int)(gyro -> getPitch() * 1800 / M_PI); pitchDifference = currentPitch - previousPitch; if (now - lastReactionMillis >= reactInterval) { react(); lastReactionMillis = now; } previousPitch = currentPitch; }
void gen_board_read(struct board_data *board, struct creature *ch, char *argument) { struct creature *player; PGresult *res; time_t post_time; char time_buf[30]; int idx; if (IS_PC(ch)) player = ch; else if (ch->desc && ch->desc->original) player = ch->desc->original; else { send_to_char(ch, "You're a mob. Go awei.\r\n"); return; } if (ALLOW != react(board->read_perms, player)) { send_to_char(ch, "%s\r\n", board->deny_read); return; } idx = atoi(argument) - 1; if (idx < 0) { send_to_char(ch, "That is not a valid message.\r\n"); return; } res = sql_query ("select extract(epoch from post_time), name, subject, body from board_messages where board='%s' order by idnum limit 1 offset %d", tmp_sqlescape(board->name), idx); if (PQntuples(res) == 0) { send_to_char(ch, "That message does not exist on this board.\r\n"); return; } acc_string_clear(); post_time = atol(PQgetvalue(res, 0, 0)); strftime(time_buf, 30, "%a %b %e %Y", localtime(&post_time)); acc_sprintf("%sMessage %s : %s %-12s :: %s%s\r\n\r\n%s\r\n", CCBLD(ch, C_CMP), argument, time_buf, tmp_sprintf("(%s)", PQgetvalue(res, 0, 1)), CCNRM(ch, C_CMP), PQgetvalue(res, 0, 2), PQgetvalue(res, 0, 3)); page_string(ch->desc, acc_get_string()); }
int thinkAI() { unsigned char x,y,size,owner; signed int tmp,score; unsigned int result; enableTurbo(); size = SIZEX * SIZEY; // compute the field score for the opposing player score = -32000; for(x = 0; x < SIZEX; ++x) { for(y = 0; y < SIZEY; ++y) { owner = getOwner(field, x, y); if(owner == PLAYERAI || owner == 0) { // we can use this cell memcpy(fieldAI, field, size); // create working copy tmp = 0; // it makes little sense to add atoms to endangered cells // unless they can start a chain reaction if(computeDanger(fieldAI, PLAYERAI, x, y) > 0 && isCritical(fieldAI, x, y) == 0) { tmp -= 10; } // let the reaction run putAtom(fieldAI, PLAYERAI, x, y, 0); react(fieldAI, 0); // evaluate the resulting field constellation tmp += evaluateField(fieldAI, PLAYERAI); if(tmp > score || (tmp == score && (rand() & 0x01))) { score = tmp; result = (x << 8) | y; } } } } disableTurbo(); return result; }
void gen_board_edit(struct board_data *board, struct creature *ch, char *argument) { struct creature *player; PGresult *res; int idx; if (IS_PC(ch)) player = ch; else if (ch->desc && ch->desc->original) player = ch->desc->original; else { send_to_char(ch, "You're a mob. Go awei.\r\n"); return; } if (ALLOW != react(board->edit_perms, player)) { send_to_char(ch, "%s\r\n", board->deny_edit); return; } idx = atoi(tmp_getword(&argument)) - 1; if (idx < 0) { send_to_char(ch, "That is not a valid message.\r\n"); return; } res = sql_query ("select idnum, subject, body from board_messages where board='%s' order by idnum limit 1 offset %d", tmp_sqlescape(board->name), idx); if (PQntuples(res) == 0) { send_to_char(ch, "That message does not exist on this board.\r\n"); return; } act("$n starts to write on the board.", true, ch, NULL, NULL, TO_ROOM); start_editing_board(ch->desc, board->name, atoi(PQgetvalue(res, 0, 0)), *argument ? argument : PQgetvalue(res, 0, 1), PQgetvalue(res, 0, 2)); }
int main() { SysTick_Config(SystemCoreClock/100); magazyn = malloc(sizeof(Element)*1200); Timer3Conf(); Joystick_Initialize(); Buttons_Initialize(); initDisplay(); lcdClean(); Timer3Disable(); Timer1Conf(); lcdMenu(); while(1) { while(tickCounter<10); tickCounter=0; switch(Buttons_GetState()) { case BUTTON_INT0: //lcdClean(); initSnake(); game = 1; while(game == 1) { //while(tickCounter<10); //tickCounter=0; inputControl = 0; switch(Joystick_GetState()) { case JOYSTICK_UP: inputControl = 1; break; case JOYSTICK_LEFT: inputControl = 2; break; case JOYSTICK_DOWN: inputControl = 4; break; case JOYSTICK_RIGHT: inputControl = 8; break; default: inputControl = oldControl; } if(inputControl == forbidden) inputControl = oldControl; if(reactCount > 0) { game = react(inputControl); --reactCount; } } lcdString(250, 150, "Koniec gry"); while(1); break; case BUTTON_KEY1: lcdString(250, 150, "Opcja 2"); while(1); break; case BUTTON_KEY2: lcdString(250, 150, "Opcja 3"); while(1); break; } } return 0; }
void WindowList::react(UserAction action) { react(action, [] (UserAction) {} ); }
/* accumulate the residual force on the specified node */ void FSDielectricElastomer2DT::AddNodalForce(const FieldT& field, int node, dArrayT& force) { /* not my field */ // if (&field != &(Field())) return; /* quick exit */ bool hasnode = false; for (int i=0; i < fBlockData.Length() && !hasnode; i++) if (fConnectivities[i]->HasValue(node)) hasnode = true; if (!hasnode) return; /* set components and weights */ double constMa = 0.0; double constKd = 0.0; /* components dicated by the algorithm */ int formMa = fIntegrator->FormMa(constMa); int formKd = fIntegrator->FormKd(constKd); /* body forces */ int formBody = 0; if (fMassType != kNoMass && (fBodySchedule && fBody.Magnitude() > kSmall)) { cout << "\nWarning: Body forces not yet implemented in DielectricElastomer2DT"; if (!formMa) constMa = 1.0; /* override */ } /* override controller */ if (fMassType == kNoMass) formMa = 0; /* temp for nodal force */ dArrayT nodalforce; bool axisymmetric = Axisymmetric(); Top(); while (NextElement()) { int nodeposition; const iArrayT& nodes_u = CurrentElement().NodesU(); if (nodes_u.HasValue(node, nodeposition)) { /* initialize */ fRHS = 0.0; /* global shape function values */ SetGlobalShape(); /* internal force contribution */ if (formKd) FormKd(constKd); /* inertia forces */ if (formMa) { SetLocalU(fLocAcc); FormMa(fMassType, constMa*fCurrMaterial->Density(), axisymmetric, &fLocAcc, NULL, NULL); } /* mechanical and electrical reaction forces */ double mr1, mr2, er1; dArrayT react(2); /* loop over nodes (double-noding OK) */ int dex = 0; int dex2 = 0; for (int i = 0; i < nodes_u.Length(); i++) { if (nodes_u[i] == node) { /* not my field - electrical */ if (&field != &(Field())) { er1 = fRHS[dex2+2*NumElementNodes()]; react[0] = er1; } else // otherwise do mechanical { mr1 = fRHS[dex]; mr2 = fRHS[dex+1]; react[0] = mr1; react[1] = mr2; } /* components for node - mechanical + electrical DOFs */ nodalforce.Set(TotalNumDOF(), react.Pointer(0)); /* accumulate */ force += nodalforce; } dex += NumDOF(); dex2 += 1; } } } }
void Component::run() { try { std::cerr << "starting component " << name << "..." << std::endl; startIO(); std::cerr << " ... " << name << " ready." << std::endl; } catch (std::exception & ex) { log->error("Cannot startup component:", &ex); try { state = STATE_FAILURE; meta.reportState(state, "Cannot startup component:", &ex); } catch (CMSException & me) { log->error("cannot report failure state", & me); } requestExit(); } while (!exitRequested()) { // Report that we are alive before we check system ready status, // (in case we were stalled due to a long act() or react() this // means we "report back" to the rest of the system) meta.IamAlive(); //printf("run %i\n",exitRequested()); // Check at every loop that the total system is ready bool exitFlag = false; synchronized (&meta) { if (!meta.isSystemReady()) { log->info("waiting for system to become ready"); } while (!meta.isSystemReady()) { try { meta.wait(1000); } catch (decaf::lang::Exception & ie) { ie.printStackTrace(); } if (meta.isSystemReady()) { log->info("system ready - let's go"); } if (exitRequested()) { exitFlag = true; break; } } } if (exitFlag) break; try { // Check if we should do something proactively: long long before = System::currentTimeMillis(); act(); long long timeSpentInAct = System::currentTimeMillis() - before; meta.statistics()->actTime((long)timeSpentInAct); } catch (std::exception & e) { log->error("error when trying to act", & e); try { state = STATE_FAILURE; meta.reportState(state, "error when trying to act", &e); } catch (CMSException & me) { log->error("cannot report failure state", & me); } requestExit(); return; } Receiver * r = NULL; synchronized (&mutex) { if (inputWaiting.empty()) { // block until input becomes available mutex.wait(waitingTime); } // check again if (!inputWaiting.empty()) { r = inputWaiting.front(); inputWaiting.pop(); } } if (r == NULL) continue; //assert(receivers.contains(r)); // the receiver that alerted us is not one of our receivers; SEMAINEMessage * message = r->getMessage(); assert(message != NULL); // Receiver alerted me but has no message meta.statistics()->countMessageReceived(); try { // time that the message travelled, in "user" time (ms since system startup -- this should be independent of clock asynchrony) long long timeMessageTravelled = meta.getTime() - message->getUsertime(); meta.statistics()->transmitTime((long)timeMessageTravelled); // Now, do something meaningful with the message, // and possibly send output via the Senders. long long before = System::currentTimeMillis(); react(message); delete message; long long timeSpentInReact = System::currentTimeMillis() - before; meta.statistics()->reactTime((long)timeSpentInReact); } catch (std::exception & e) { log->error("error when trying to react", &e); try { state = STATE_FAILURE; std::string errMsg = CMSLogger::toLogMessageText("error when trying to react", &e) + "(message was: " + CMSLogger::message2logString(message) + ")"; meta.reportState(state, errMsg); } catch (CMSException & me) { log->error("cannot report failure state", & me); } requestExit(); return; } } }