void MainWindow::createMenu() { QMenu *menuFile = new QMenu("File"); menuFile->addAction( "Open base", this, SLOT( openBS() ) ); menuFile->addAction( "Create base", this, SLOT( createBS() ) ); menuFile->addSeparator(); menuFile->addAction( "Close base", this, SLOT( closeBS() ) ); menuFile->addAction( "Clear base", this, SLOT( clearBS() ) ); menuFile->addSeparator(); menuFile->addAction( "Quit", this, SLOT( close() ) ); QMenu *menuEdit = new QMenu("Edit"); menuEdit->addAction( "Add record", this, SLOT( addRS() ) ); menuEdit->addAction( "Edit record", this, SLOT( editRS() ) ); menuEdit->addAction( "Show record", this, SLOT( showRS() ) ); menuEdit->addAction( "Select records", this, SLOT( selectRS() ) ); menuEdit->addSeparator(); menuEdit->addAction( "Delete record", this, SLOT( delRS() ) ); QMenu *menuDraw = new QMenu("Draw"); menuDraw->addAction( "Diagram", this, SLOT( diagramS() ) ); menuDraw->addAction( "Fun", this, SLOT( funS() ) ); menuBar()->addMenu(menuFile); menuBar()->addMenu(menuEdit); menuBar()->addMenu(menuDraw); menuBar()->addAction( "Help", this, SLOT( helpS() ) ); }
void MainWindow::setConnect() { QObject::connect( openBase, SIGNAL( pressed() ), this, SLOT( openBS() ) ); QObject::connect( closeBase, SIGNAL( pressed() ), this, SLOT( closeBS() ) ); QObject::connect( createBase, SIGNAL( pressed() ), this, SLOT( createBS() ) ); QObject::connect( clearBase, SIGNAL( pressed() ), this, SLOT( clearBS() ) ); QObject::connect( addRecord, SIGNAL( pressed() ), this, SLOT( addRS() ) ); QObject::connect( deleteRecord, SIGNAL( pressed() ), this, SLOT( delRS() ) ); QObject::connect( editRecord, SIGNAL( pressed() ), this, SLOT( editRS() ) ); QObject::connect( showRecord, SIGNAL( pressed() ), this, SLOT( showRS() ) ); QObject::connect( selectRecord, SIGNAL( pressed() ), this, SLOT( selectRS() ) ); QObject::connect( diagram, SIGNAL( pressed() ), this, SLOT( diagramS() ) ); }
AI_Waypoint_t *CAI_Pathfinder::FindBestPath(int startID, int endID) { if ( !GetNetwork()->NumNodes() ) return NULL; int nNodes = GetNetwork()->NumNodes(); CAI_Node **pAInode = GetNetwork()->AccessNodes(); CVarBitVec openBS(nNodes); CVarBitVec closeBS(nNodes); // ------------- INITIALIZE ------------------------ float* nodeG = (float *)stackalloc( nNodes * sizeof(float) ); float* nodeH = (float *)stackalloc( nNodes * sizeof(float) ); float* nodeF = (float *)stackalloc( nNodes * sizeof(float) ); int* nodeP = (int *)stackalloc( nNodes * sizeof(int) ); // Node parent for (int node=0;node<nNodes;node++) { nodeG[node] = FLT_MAX; nodeP[node] = -1; } nodeG[startID] = 0; nodeH[startID] = 0.1*(pAInode[startID]->GetPosition(GetHullType())-pAInode[endID]->GetPosition(GetHullType())).Length(); // Don't want to over estimate nodeF[startID] = nodeG[startID] + nodeH[startID]; openBS.Set(startID); closeBS.Set( startID ); // --------------- FIND BEST PATH ------------------ while (!openBS.IsAllClear()) { int smallestID = CAI_Network::FindBSSmallest(&openBS,nodeF,nNodes); openBS.Clear(smallestID); CAI_Node *pSmallestNode = pAInode[smallestID]; if (GetOuter()->IsUnusableNode(smallestID, pSmallestNode->m_pHint)) continue; if (smallestID == endID) { AI_Waypoint_t* route = MakeRouteFromParents(&nodeP[0], endID); return route; } // Check this if the node is immediately in the path after the startNode // that it isn't blocked for (int link=0; link < pSmallestNode->NumLinks();link++) { CAI_Link *nodeLink = pSmallestNode->GetLinkByIndex(link); if (!IsLinkUsable(nodeLink,smallestID)) continue; // FIXME: the cost function should take into account Node costs (danger, flanking, etc). int moveType = nodeLink->m_iAcceptedMoveTypes[GetHullType()] & CapabilitiesGet(); int testID = nodeLink->DestNodeID(smallestID); Vector r1 = pSmallestNode->GetPosition(GetHullType()); Vector r2 = pAInode[testID]->GetPosition(GetHullType()); float dist = GetOuter()->GetNavigator()->MovementCost( moveType, r1, r2 ); // MovementCost takes ref parameters!! if ( dist == FLT_MAX ) continue; float new_g = nodeG[smallestID] + dist; if ( !closeBS.IsBitSet(testID) || (new_g < nodeG[testID]) ) { nodeP[testID] = smallestID; nodeG[testID] = new_g; nodeH[testID] = (pAInode[testID]->GetPosition(GetHullType())-pAInode[endID]->GetPosition(GetHullType())).Length(); nodeF[testID] = nodeG[testID] + nodeH[testID]; closeBS.Set( testID ); openBS.Set( testID ); } } } return NULL; }