void SceneGraph::updateRoute(Node *eventOutNode, Field *eventOutField) { for (Route *route = Parser::getRoutes(); route; route = route->next()) { if (route->getEventOutNode() == eventOutNode && route->getEventOutField() == eventOutField) { route->update(); route->getEventInNode()->update(); updateRoute(route->getEventInNode(), route->getEventInField()); } } }
void MainWindow::createActions() { connect(ui->action_refreshRoute, SIGNAL(triggered()), &arpWatcher, SLOT(updateRoute())); minimizeAction = new QAction(tr("Mi&nimize"), this); connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); restoreAction = new QAction(tr("&Restore"), this); connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(ui->action_Quitter, SIGNAL(triggered()), this, SLOT(quit())); }
/*public*/ SetTrainIconRouteFrame::SetTrainIconRouteFrame(QString routeName, QWidget* parent) : OperationsFrame(tr("Train Icon"),parent) { //super(tr("MenuSetTrainIcon")); log = new Logger("SetTrainIconRouteFrame"); value = QMessageBox::No; //JOptionPane.NO_OPTION; FORWARD = 1; BACK = -1; NONE = 0; routeManager = RouteManager::instance(); // labels textX = new JLabel(" X "); textY = new JLabel(" Y "); routeLocationName = new JLabel(); // text field // check boxes // major buttons previousButton = new QPushButton(tr("Previous")); nextButton = new QPushButton(tr("Next")); placeButton = new QPushButton(tr("Place Test Icon")); applyButton = new QPushButton(tr("Apply")); saveButton = new QPushButton(tr("Save")); // combo boxes // Spinners spinTrainIconX = new QSpinBox(); //(new SpinnerNumberModel(0, 0, 10000, 1)); spinTrainIconX->setMinimum(0); spinTrainIconX->setMaximum(10000); spinTrainIconX->setValue(0); spinTrainIconX->setSingleStep(1); spinTrainIconY = new QSpinBox(); //(new SpinnerNumberModel(0, 0, 10000, 1)); spinTrainIconY->setMinimum(0); spinTrainIconY->setMaximum(10000); spinTrainIconY->setValue(0); spinTrainIconY->setSingleStep(1); _routeIndex = 0; _tIon = NULL; // create route if (routeName == NULL) { return; } _route = RouteManager::instance()->getRouteByName(routeName); //_route.addPropertyChangeListener(this); connect(_route->pcs, SIGNAL(propertyChange(PropertyChangeEvent*)), this, SLOT(propertyChange(PropertyChangeEvent*))); // general GUI config //getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); getContentPane()->setLayout(new QVBoxLayout); // set tool tips placeButton->setToolTip(tr("Places a set of train icons on panel") + " " + Setup::getPanelName()); applyButton->setToolTip(tr("Update route with the new coordinates")); saveButton->setToolTip(tr("Saves the train icon coordinates for the selected location")); // Set up the panels QGroupBox* pRoute = new QGroupBox(); // pRoute.setBorder(BorderFactory // .createTitledBorder(tr("Route") + " " + _route.getName())); pRoute->setStyleSheet(gbStyleSheet); pRoute->setTitle(tr("Route")); pRoute->setLayout(new GridBagLayout()); addItem(pRoute, previousButton, 0, 0); addItem(pRoute, routeLocationName, 1, 0); addItem(pRoute, nextButton, 2, 0); QGroupBox* pSpin = new QGroupBox(); pSpin->setLayout(new GridBagLayout()); //pSpin.setBorder(BorderFactory.createTitledBorder(tr("TrainIcon"))); pSpin->setStyleSheet(gbStyleSheet); pSpin->setTitle(tr("Train Icon")); addItem(pSpin, textX, 0, 0); addItem(pSpin, spinTrainIconX, 1, 0); addItem(pSpin, textY, 2, 0); addItem(pSpin, spinTrainIconY, 3, 0); QGroupBox* pControl = new QGroupBox(); pControl->setLayout(new GridBagLayout()); //pControl.setBorder(BorderFactory.createTitledBorder("")); pControl->setStyleSheet(gbStyleSheet); pControl->setTitle(tr("Route")); addItem(pControl, placeButton, 0, 0); addItem(pControl, applyButton, 1, 0); addItem(pControl, saveButton, 2, 0); getContentPane()->layout()->addWidget(pRoute); getContentPane()->layout()->addWidget(pSpin); getContentPane()->layout()->addWidget(pControl); // add help menu to window addHelpMenu("package.jmri.jmrit.operations.Operations_SetTrainIconCoordinates", true); // NOI18N // setup buttons addButtonAction(previousButton); addButtonAction(nextButton); addButtonAction(placeButton); addButtonAction(applyButton); addButtonAction(saveButton); // start off with save button disabled saveButton->setEnabled(false); updateRoute(); // setup spinners addSpinnerChangeListerner(spinTrainIconX); addSpinnerChangeListerner(spinTrainIconY); initMinimumSize(QSize(Control::panelWidth400, Control::panelHeight400)); }
bool BinaryConnection::updateMap(Map* map) { char name[500]; char description[5000]; char texture[500]; strcpy_s(name, 500, map->getName().c_str()); strcpy_s(description, 5000, map->getDescription().c_str()); strcpy_s(texture, 500, map->getTexture().c_str()); unsigned int id = map->getID(), sizeX = map->getSize().x, sizeZ = map->getSize().z; unsigned int terSizeX = map->getTerrainSize().x, terSizeZ = map->getTerrainSize().z; double lat = map->getCenter().latitude, lon = map->getCenter().longitude; float zoom = map->getZoom(); mFile.write((char*)&id, sizeof(id)); mFile.write(name, 500); mFile.write(description, 5000); mFile.write((char*)&sizeX, sizeof(sizeX)); mFile.write((char*)&sizeZ, sizeof(sizeZ)); mFile.write((char*)&terSizeX, sizeof(terSizeX)); mFile.write((char*)&terSizeZ, sizeof(terSizeZ)); mFile.write((char*)&lat, sizeof(lat)); mFile.write((char*)&lon, sizeof(lon)); mFile.write((char*)&zoom, sizeof(zoom)); mFile.write((char*)&texture, 500); float* buffer = new float[terSizeX * terSizeZ]; for (unsigned int i = 0; i < terSizeX * terSizeZ; ++i) { buffer[i] = map->getTerrainData()[i]; } mFile.write((char*)buffer, terSizeX * terSizeZ * sizeof(float)); delete[] buffer; unsigned int objectCount = (unsigned int)map->getObjects().size(); mFile.write((char*)&objectCount, sizeof(unsigned int)); ObjectList::const_iterator i = map->getObjects().begin(); for (; i != map->getObjects().end(); ++i) { unsigned int type = i->second->getType(); mFile.write((char*)&type, sizeof(unsigned int)); switch (i->second->getType()) { case OT_BUILDING: { if (updateBuilding(static_cast<Building*>(i->second)) == false) { return false; } break; } case OT_JUNCTION: { if (updateJunction(static_cast<Junction*>(i->second)) == false) { return false; } break; } case OT_PLANT: { if (updatePlant(static_cast<Plant*>(i->second)) == false) { return false; } break; } case OT_ROUTE: { if (updateRoute(static_cast<Route*>(i->second)) == false) { return false; } break; } case OT_STREET: { if (updateStreet(static_cast<Street*>(i->second)) == false) { return false; } break; } case OT_WATER_OBJECT: { if (updateWaterObject(static_cast<WaterObject*>(i->second)) == false) { return false; } break; } } } return true; }
void GameState::update( float dtFixed ) { // If the car is out of route points, generate a route updateRoute(); // check for win int currPosX, currPosY; currPosX = (int)m_carPos.x; currPosY = (int)m_carPos.y; if ((currPosX >= 0) && (currPosY>=0) && (currPosX < m_boardSizeX) && (currPosY < m_boardSizeY) && (m_tile[currPosX][currPosY].target)) { // win! nextLevel(); } // Move the car along the route vec2f targPos, targDir; if (m_carRoute.size()== 0 ) updateRoute(); targPos = m_carRoute.front(); targDir = targPos - m_carPos; if (LengthSquared(targDir) < 0.01) { // we've reached this route point, discard it m_carRoute.pop_front(); // update route to make sure there is data available updateRoute(); targPos = m_carRoute.front(); targDir = targPos - m_carPos; } targDir.Normalize(); // Adjust car dir float turnrate = 0.4f; // not entirely true, but close enough m_carDir = Lerp( m_carDir, targDir, turnrate ); m_carDir.Normalize(); // Update car pos float speed = 2.0; m_carPos += m_carDir * dtFixed * speed; // Now update player's tiles if (m_pickTiles.size() < m_maxTiles) { m_newTileTimeout -= dtFixed; if (m_newTileTimeout <= 0.0f) { // pick a tile at random (scrabble probabilities) const char *tiles = "AAAAAAAAABBCCDDDDEEEEEEEEEEEEFFGGHHIIIIIIIIIJKLLLLMMNNNNNNOOOOOOOOPPQRRRRRRSSSSTTTTTTUUUUVVWWXYYZ"; char letter = tiles[ (int)( ((float)rand() / (float)RAND_MAX) * strlen(tiles) ) ]; PickTile newtile; newtile.letter = letter; newtile.xpos = m_maxTiles; newtile.pending = false; m_pickTiles.push_back( newtile ); m_newTileTimeout = NEW_TILE_TIMEOUT; } } // fade error foreach_tile { if (m_tile[i][j].error > 0.0) { m_tile[i][j].error -= 0.01; } else { m_tile[i][j].error = 0.0; } } }
void driver() { Driver me; initDriver(&me, 1); unsigned int naggCount = 0; unsigned int updateStoppingDistanceCount = 0; for (;;) { int tid = -1; DriverMsg msg; msg.data2 = -1; msg.data3 = -1; msg.replyTid = -1; Receive(&tid, (char*)&msg, sizeof(DriverMsg)); if (tid != me.delayer && tid != me.stopDelayer) { Reply(tid, (char*)1, 0); } const int replyTid = msg.replyTid; switch (msg.type) { case SET_SPEED: { //TrainDebug(&me, "Set speed from msg"); trainSetSpeed(msg.data2, getStoppingTime(&me), (msg.data3 == DELAYER), &me); if (msg.data3 != DELAYER) { //TrainDebug(&me, "Replied to %d", replyTid); Reply(replyTid, (char*)1, 0); sendUiReport(&me); break; } else if (me.route.length != 0) { // Delayer came back. Reverse command completed me.stopCommited = 0; // We're moving again. // We've completed everything up to the reverse node. me.routeRemaining = me.stopNode+1; me.previousStopNode = me.routeRemaining; me.distanceFromLastSensorAtPreviousStopNode = me.distanceFromLastSensor; // Calculate the next stop node. updateStopNode(&me); me.nextSetSwitchNode = -1; updateSetSwitch(&me); // if the reverse is last node, nothing to do // if it isn't.. it should speed up again. } } case DELAYER: { //TrainDebug(&me, "delayer come back."); break; } case STOP_DELAYER: { // To prevent the first receive from this delayer if (me.lastSensorActualTime > 0 && me.speed == 0 && !me.isAding) { TrainDebug(&me, "releasing reserveration"); int reserveStatus = reserveMoreTrack(&me, 1, 0); if (reserveStatus == RESERVE_FAIL) { TrainDebug(&me, "WARNING: unable to reserve during init"); } } break; } case SENSOR_TRIGGER: { // only handle sensor reports in primary + secondary prediction if not position finding int sensorReportValid = 0; TrackLandmark conditionLandmark; int condition; int isSensorReserved = QueryIsSensorReserved(&me, msg.data2, msg.data3); if (me.positionFinding) { sensorReportValid = 1; me.lastSensorUnexpected = 1; //FinishPositionFinding(me.trainNum, me.trainController); } else if (isSensorReserved) { //TrainDebug(&me, "Predictions."); for (int i = 0; i < me.numPredictions; i ++) { TrackLandmark predictedSensor = me.predictions[i].sensor; //printLandmark(&me, &predictedSensor); if (predictedSensor.type == LANDMARK_SENSOR && predictedSensor.num1 == msg.data2 && predictedSensor.num2 == msg.data3) { sensorReportValid = 1; if (i != 0) { TrainDebug(&me, "Trigger Secondary"); // secondary prediction, need to do something about them conditionLandmark = me.predictions[i].conditionLandmark; condition = me.predictions[i].condition; me.lastSensorUnexpected = 1; if (conditionLandmark.type == LANDMARK_SWITCH) { TrackMsg setSwitch; setSwitch.type = UPDATE_SWITCH_STATE; TrainDebug(&me, "UPDATE SWITCH STATE"); setSwitch.landmark1 = conditionLandmark; setSwitch.data = condition; Send(me.trackManager, (char*)&setSwitch, sizeof(TrackMsg), (char *)1, 0); } // Stop and then try to reroute. reroute(&me); } else { me.lastSensorUnexpected = 0; } } } } if (sensorReportValid) { updateRoute(&me, msg.data2, msg.data3); me.lastSensorBox = msg.data2; // Box me.lastSensorVal = msg.data3; // Val me.lastSensorIsTerminal = 0; me.lastSensorActualTime = msg.timestamp; dynamicCalibration(&me); me.lastSensorPredictedTime = me.nextSensorPredictedTime; TrackNextSensorMsg trackMsg; QueryNextSensor(&me, &trackMsg); // Reserve the track above train and future (covers case of init) for (int i = 0; i < trackMsg.numPred; i++) { me.predictions[i] = trackMsg.predictions[i]; } me.numPredictions = trackMsg.numPred; int reserveStatus = reserveMoreTrack(&me, me.positionFinding, getStoppingDistance(&me)); if (reserveStatus == RESERVE_FAIL) { if (!me.positionFinding) { reroute(&me); } else { TrainDebug(&me, "WARNING: unable to reserve during init"); } } TrackSensorPrediction primaryPrediction = me.predictions[0]; me.calibrationStart = msg.timestamp; me.calibrationDistance = primaryPrediction.dist; int dPos = 50 * getVelocity(&me) / 100000.0; me.lastSensorDistanceError = -(int)me.distanceToNextSensor - dPos; me.distanceFromLastSensor = dPos; me.distanceToNextSensor = primaryPrediction.dist - dPos; me.lastPosUpdateTime = msg.timestamp; if (primaryPrediction.sensor.type != LANDMARK_SENSOR && primaryPrediction.sensor.type != LANDMARK_END) { TrainDebug(&me, "QUERY_NEXT_SENSOR_FROM_SENSOR ..bad"); } me.nextSensorIsTerminal = (primaryPrediction.sensor.type == LANDMARK_END); me.nextSensorBox = primaryPrediction.sensor.num1; me.nextSensorVal = primaryPrediction.sensor.num2; me.nextSensorPredictedTime = msg.timestamp + me.distanceToNextSensor*100000 / getVelocity(&me); updatePosition(&me, msg.timestamp); sendUiReport(&me); if (me.positionFinding) { trainSetSpeed(0, getStoppingTime(&me), 0, &me); // Found position, stop. me.positionFinding = 0; me.currentlyLost = 0; } } break; } case NAVIGATE_NAGGER: { updatePosition(&me, msg.timestamp); if (me.routeRemaining != -1) { if (!me.stopCommited) { if (shouldStopNow(&me)) { if (me.route.nodes[me.stopNode].num == REVERSE) { //TrainDebug(&me, "Navi reversing."); const int speed = -1; trainSetSpeed(speed, getStoppingTime(&me), 0, &me); } else { //TrainDebug(&me, "Navi Nagger stopping."); const int speed = 0; // Set speed zero. trainSetSpeed(speed, getStoppingTime(&me), 0, &me); me.route.length = 0; // Finished the route. me.testMode = 0; } me.stopCommited = 1; me.useLastSensorNow = 0; me.stopNow = 0; me.stopSensorHit = 0; } else { if ((++updateStoppingDistanceCount & 15) == 0) updateStopNode(&me); } } } if (me.nextSetSwitchNode != -1 && (++me.setSwitchNaggerCount & 3) == 0) { trySetSwitch_and_getNextSwitch(&me); } if (me.rerouteCountdown-- == 0) { if (me.testMode) { int reserveStatus = reserveMoreTrack(&me, 0, me.d[8][ACCELERATE][MAX_VAL]); // moving if (reserveStatus == RESERVE_FAIL) { reroute(&me); } else { me.nextSetSwitchNode = -1; updateSetSwitch(&me); trainSetSpeed(8, 0, 0, &me); } } else { // reroute if (me.route.length != 0) { setRoute(&me, &(me.routeMsg)); } } } if ((++naggCount & 15) == 0) sendUiReport(&me); break; } case SET_ROUTE: { Reply(replyTid, (char*)1, 0); me.routeMsg = msg; setRoute(&me, &msg); break; } case BROADCAST_UPDATE_PREDICTION: { updatePrediction(&me); int reserveStatus = reserveMoreTrack(&me, 0, getStoppingDistance(&me)); // moving if (reserveStatus == RESERVE_FAIL) { reroute(&me); } break; } case BROADCAST_TEST_MODE: { me.testMode = 1; setRoute(&me, &msg); break; } case FIND_POSITION: { me.positionFinding = 1; trainSetSpeed(5, 0, 0, &me); break; } default: { TrainDebug(&me, "Not suppported train message type."); } } } }