XP_Bool newg_store( NewGameCtx* ngc, CurGameInfo* gi, XP_Bool XP_UNUSED_STANDALONE(warn) ) { XP_U16 player; XP_Bool consistent = checkConsistent( ngc, warn ); if ( consistent ) { XP_Bool makeLocal = XP_FALSE; gi->nPlayers = ngc->nPlayersShown; #ifndef XWFEATURE_STANDALONE_ONLY gi->serverRole = ngc->role; makeLocal = ngc->role != SERVER_ISSERVER; #endif for ( player = 0; player < MAX_NUM_PLAYERS; ++player ) { storePlayer( ngc, player, &gi->players[player] ); if ( makeLocal ) { gi->players[player].isLocal = XP_TRUE; } } } return consistent; } /* newg_store */
// Please note that the edge to be flipped here is the 2nd and 4th parameters. // // flip <abd>,<dbc> adds 2 children to each, <abc>,<acd> // // the shared edge bd gets replaced with shared edge ac void DirectedGraph::flipTriangles(int pIdx1, int pIdx2, int pIdx3, int pIdx4) { // XXX finish rename in DGraph::flipTri // shared edge ij; 124=kij is ccw, 423=jil is ccw. int kIdx = pIdx1; int iIdx = pIdx2; int lIdx = pIdx3; int jIdx = pIdx4; #ifdef DIRECTEDGRAPH_CHECK cout << "DAG::flipTris, args=" << pIdx1 << "," << pIdx2 << "," << pIdx3 << "," << pIdx4 << "." << endl; cout << "Points: " << endl; cout << " 1. " << pointSet_[pIdx1] << endl; cout << " 2. " << pointSet_[pIdx2] << endl; cout << " 3. " << pointSet_[pIdx3] << endl; cout << " 4. " << pointSet_[pIdx4] << endl; assert(containsTri(dagNodes_, pIdx1, pIdx2, pIdx4)); assert(isTriangleCCW(pointSet_, TriRecord(pIdx1, pIdx2, pIdx4))); assert(containsTri(dagNodes_, pIdx4, pIdx2, pIdx3)); assert(isTriangleCCW(pointSet_, TriRecord(pIdx4, pIdx2, pIdx3))); #endif // Seek the lowest DAGNode which contains the point. vector<shared_ptr<DAGNode>> nodes = DAGNode::leafNodesContainingEdge(root_, pointSet_, pIdx2, pIdx4); #ifdef DIRECTEDGRAPH_CHECK // cout << "DAG.flipTriangles, numLeafNodes containing edge: " << nodes.size() << endl; // outputTriList(nodes); assert(nodes.size() == 2); #endif // Ensure nodeIJK is the one with kIdx int nodesIJKIdx = (nodes[0]->tri_.hasPointIndex(kIdx)) ? 0 : 1; int nodesJILIdx = 1 - nodesIJKIdx; shared_ptr<DAGNode> nodeIJK = nodes[nodesIJKIdx]; shared_ptr<DAGNode> nodeJIL = nodes[nodesJILIdx]; // impl ASSUMPTION that TriR(x,y,z) == TriR(x,z,y), etc. // (as used in DirectedGraph). // swap 24 edge with 13 edge // ASSUMPTION that points for TriRecord are CCW // flip <abd>,<dbc> adds 2 children to each, <abc>,<acd> (preserves CCW) TriRecord triILK(iIdx, lIdx, kIdx); TriRecord triLJK(lIdx, jIdx, kIdx); #ifdef DIRECTEDGRAPH_CHECK assert(isTriangleCCW(pointSet_, triILK)); assert(isTriangleCCW(pointSet_, triLJK)); #endif shared_ptr<DAGNode> nodeILK(new DAGNode(triILK)); shared_ptr<DAGNode> nodeLJK(new DAGNode(triLJK)); nodeIJK->children_.push_back(nodeILK); nodeIJK->children_.push_back(nodeLJK); nodeJIL->children_.push_back(nodeILK); nodeJIL->children_.push_back(nodeLJK); // Add to instance's list of dagNodes dagNodes_.push_back(nodeILK); dagNodes_.push_back(nodeLJK); // Update triangulation delaunay::flipTriangles(trist_, nodeIJK->fIndex_, nodeJIL->fIndex_, nodeILK, nodeLJK); #ifdef DIRECTEDGRAPH_CHECK checkConsistent(); #endif // legalizeEdge[FLIPTRIANGLE] legalizeEdge(pIdx1, pIdx2, pIdx3); legalizeEdge(pIdx1, pIdx3, pIdx4); }
void DirectedGraph::addVertex(int pIdx) { #ifdef DIRECTEDGRAPH_CHECK cout << "DAG.addVertex(" << pIdx << ")" << endl; #endif // Seek the lowest DAGNode which contains the point. vector<shared_ptr<DAGNode>> leaves = DAGNode::leafNodesContainingPoint(root_, pointSet_, pIdx); #ifdef DIRECTEDGRAPH_CHECK cout << "DAG.addVertex, numLeafNodes containing pt: " << leaves.size() << endl; assert(leaves.size() == 1 || leaves.size() == 2); #endif if (leaves.size() == 1) { // New point fits cleanly within another triangle, // split the triangle into three. shared_ptr<DAGNode> node = leaves[0]; // IJK TriRecord parentTri = node->tri_; int parentIdx1, parentIdx2, parentIdx3; parentTri.get(parentIdx1, parentIdx2, parentIdx3); // Construct 3 TriRecords, one for each child triangle // ASSUMPTION that points for TriRecord are CCW shared_ptr<DAGNode> child1(new DAGNode(TriRecord(pIdx, parentIdx1, parentIdx2))); // RIJ shared_ptr<DAGNode> child2(new DAGNode(TriRecord(pIdx, parentIdx2, parentIdx3))); // RJK shared_ptr<DAGNode> child3(new DAGNode(TriRecord(pIdx, parentIdx3, parentIdx1))); // RKI node->children_.push_back(child1); node->children_.push_back(child2); node->children_.push_back(child3); // Add to instance's list of dagNodes dagNodes_.push_back(child1); dagNodes_.push_back(child2); dagNodes_.push_back(child3); // Update triangulation addVertexInTri(trist_, node->fIndex_, child1, child2, child3); #ifdef DIRECTEDGRAPH_CHECK checkConsistent(); #endif // legalizeEdge[ADDVERT(A)] /// edges 12, 13, 23 are the "link" of the inserted point. /// So, here we 'flip edges' until things are locally delaunday. legalizeEdge(pIdx, parentIdx1, parentIdx2); legalizeEdge(pIdx, parentIdx2, parentIdx3); legalizeEdge(pIdx, parentIdx3, parentIdx1); } else if (leaves.size() == 2) { // New point on the edge of other triangles, // split the two triangles to get four triangles total. // new point R lies on edge IJ shared_ptr<DAGNode> nodeIJK = leaves[0]; shared_ptr<DAGNode> nodeILJ = leaves[1]; // need to sort out the point indices int iIdx, jIdx, kIdx, lIdx; getIndicesKIJL(nodeIJK->tri_, nodeILJ->tri_, kIdx, iIdx, jIdx, lIdx); // Create triangles RJK, RKI, RIL, RLJ shared_ptr<DAGNode> nodeRJK(new DAGNode(TriRecord(pIdx, jIdx, kIdx))); shared_ptr<DAGNode> nodeRKI(new DAGNode(TriRecord(pIdx, kIdx, iIdx))); shared_ptr<DAGNode> nodeRIL(new DAGNode(TriRecord(pIdx, iIdx, lIdx))); shared_ptr<DAGNode> nodeRLJ(new DAGNode(TriRecord(pIdx, lIdx, jIdx))); nodeIJK->children_.push_back(nodeRJK); nodeIJK->children_.push_back(nodeRKI); nodeILJ->children_.push_back(nodeRIL); nodeILJ->children_.push_back(nodeRLJ); dagNodes_.push_back(nodeRJK); dagNodes_.push_back(nodeRKI); dagNodes_.push_back(nodeRIL); dagNodes_.push_back(nodeRLJ); // Update triangulation addVertexOnEdge(trist_, nodeIJK->fIndex_, nodeILJ->fIndex_, nodeRJK, nodeRKI, nodeRIL, nodeRLJ); #ifdef DIRECTEDGRAPH_CHECK checkConsistent(); #endif // legalizeEdge[ADDVERT(B)] // legalize il, lj, jk, ki legalizeEdge(pIdx, jIdx, kIdx); legalizeEdge(pIdx, kIdx, iIdx); legalizeEdge(pIdx, iIdx, lIdx); legalizeEdge(pIdx, lIdx, jIdx); } }