/// Finds a main point for a speciefic node void TradeGraph::FindMainPoint(const MapPoint tgn) { /// Calc size of this node rectangle MapCoord width, height; if(tgn.x == gwg->GetWidth() / TGN_SIZE || gwg->GetWidth() % TGN_SIZE == 0) width = gwg->GetWidth() % TGN_SIZE; else width = TGN_SIZE; if(tgn.y == gwg->GetHeight() / TGN_SIZE || gwg->GetHeight() % TGN_SIZE == 0) height = gwg->GetHeight() % TGN_SIZE; else height = TGN_SIZE; const unsigned POTENTIAL_MAIN_POINTS = 5; // We consider the following points as main points MapPoint ps[POTENTIAL_MAIN_POINTS] = { MapPoint(tgn.x* TGN_SIZE + width / 2, tgn.y* TGN_SIZE + height / 2), MapPoint(tgn.x* TGN_SIZE + width / 4, tgn.y* TGN_SIZE + height / 4), MapPoint(tgn.x* TGN_SIZE + width * 3 / 4, tgn.y* TGN_SIZE + height / 4), MapPoint(tgn.x* TGN_SIZE + width * 3 / 4, tgn.y* TGN_SIZE + height * 3 / 4), MapPoint(tgn.x* TGN_SIZE + width / 4, tgn.y* TGN_SIZE + height * 3 / 4) }; bool good_points[POTENTIAL_MAIN_POINTS]; for(unsigned i = 0; i < POTENTIAL_MAIN_POINTS; ++i) { MapPoint p = ps[i]; good_points[i] = gwg->IsNodeForFigures(p); // Valid point? Otherwise choose one around this one if(!gwg->IsNodeForFigures(p)) { for(unsigned d = 0; d < 6; ++d) { MapPoint pt(gwg->GetNeighbour(p, d)); if(gwg->IsNodeForFigures(pt)) { ps[i] = pt; good_points[i] = true; break; } } } } // Try to find paths to the other points if we reach at least 3/4 of the other points, choose // this point at once, otherwise choose the point with most connections unsigned best_connections = 0, best_id = 0; for(unsigned i = 0; i < POTENTIAL_MAIN_POINTS; ++i) { MapPoint p = ps[i]; unsigned connections = 0; for(unsigned j = 0; j < POTENTIAL_MAIN_POINTS; ++j) { if(i == j || !good_points[j]) continue; unsigned char next_dir = gwg->FindTradePath(p, ps[j], player, TG_PF_LENGTH, false, NULL, NULL, false); if(next_dir != 0xff) ++connections; } if(connections >= (POTENTIAL_MAIN_POINTS - 1) * 3 / 4) { best_id = i; break; } if(connections >= best_connections) { best_id = i; best_connections = connections; } } GetNode(tgn).main_pos = ps[best_id]; }
virtual wxString GetValueAsText(wxTreeItemId ti) { PropertyInfo *pi = &(((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo); return XmlReadValue(GetNode(), pi->Name).BeforeFirst(_T('d')); }
void PropEditCtrlTxt::WriteValue() { wxString newv = m_TextCtrl->GetValue(); XmlWriteValue(GetNode(), m_PropInfo->Name, newv); m_TreeCtrl->SetItemBold(m_TreeItem, TRUE); }
// Private void SectionFieldDescriptor::Parse() { if ( !GetNode()->HasProp(SIZE_ATTR) ) { throw wxString::Format(DESCRIPTOR_WRONG_XML + wxString(" %s"), wxString(GetNode()->GetName())); } m_size = atol(GetNode()->GetPropVal(SIZE_ATTR, "")); bool hasValue = GetNode()->HasProp(VALUE_ATTR); bool hasHeader = GetNode()->HasProp(HEADER_ATTR); bool hasDetail = GetNode()->HasProp(GRID_ATTR); if ( (hasValue && (hasHeader || hasDetail)) || (hasHeader && (hasDetail || hasValue)) || (hasDetail && (hasValue || hasHeader)) ) { throw wxString::Format(DESCRIPTOR_WRONG_XML + wxString(" %s"), wxString(GetNode()->GetName())); } m_sourceValue = new wxString(); if ( hasValue ) { m_fieldSource = FS_VALUE; *m_sourceValue << wxString(GetNode()->GetPropVal(VALUE_ATTR, "")); } else if (hasHeader) { m_fieldSource = FS_HEADER; *m_sourceValue << wxString(GetNode()->GetPropVal(HEADER_ATTR, "")); } else if (hasDetail) { m_fieldSource = FS_DETAIL; *m_sourceValue << wxString(GetNode()->GetPropVal(GRID_ATTR, "")); } else { m_fieldSource = FS_UNUSED; } m_alignment = ParseAlignment(wxString(GetNode()->GetPropVal(JUSTIFY_ATTR, "L"))); m_filler = wxString(GetNode()->GetPropVal(FILLER_ATTR, GetDefaultFiller()))[0]; }
void WireSim::TestInputNodes( int x, int y, bool& topLeftPoweredOut, bool& bottomLeftPoweredOut ) { bottomLeftPoweredOut = topLeftPoweredOut = false; topLeftPoweredOut = InRange( x - 1, y - 1 ) && ( GetNode( x, y, m_nextBuffer ).m_power > 0 ); bottomLeftPoweredOut = InRange( x - 1, y + 1 ) && ( GetNode( x, y, m_nextBuffer ).m_power > 0 ); }
void PhysicsBodyComponent::OnDisable() { GetNode()->GetScene()->GetPhysicsWorld()->GetBulletWorld()->removeRigidBody(mBody); }
const TCHAR* MorphByBone::fnGetSelectedMorph() { return GetMorphName(GetNode(currentBone),currentMorph); }
void TWayGraph::Dfs( const TSegment& point, size_t direction ) { if (!IsValid(point.GetPosition())) { return; } TNode& currentNode = GetNode( point.GetPosition().Column, point.GetPosition().Row, direction ); if (!currentNode.Available) { return; } if (currentNode.Color == EColor::BLACK) { return; } if (point == FinishPoint && direction == FinishDirection) { CurrentWay.push_back(FindCollisionDirection(point, direction)); AllWays.push_back(CurrentWay); CurrentWay.pop_back(); return; } currentNode.Color = EColor::BLACK; CurrentWay.push_back(EMoveOperations::SLIDE_EAST); auto next = point.Slide(EMoveOperations::SLIDE_EAST); Dfs(next, direction); CurrentWay.pop_back(); CurrentWay.push_back(EMoveOperations::SLIDE_WEST); next = point.Slide(EMoveOperations::SLIDE_WEST); Dfs(next, direction); CurrentWay.pop_back(); CurrentWay.push_back(EMoveOperations::SLIDE_SOUTHEAST); next = point.Slide(EMoveOperations::SLIDE_SOUTHEAST); Dfs(next, direction); CurrentWay.pop_back(); CurrentWay.push_back(EMoveOperations::SLIDE_SOUTHWEST); next = point.Slide(EMoveOperations::SLIDE_SOUTHWEST); Dfs(next, direction); CurrentWay.pop_back(); CurrentWay.push_back(EMoveOperations::ROTATE_CLOCKWISE); if (direction == 0) { Dfs(point, TurnDirections - 1); } else { Dfs(point, direction - 1); } CurrentWay.pop_back(); CurrentWay.push_back(EMoveOperations::ROTATE_ANTI_CLOCKWISE); if (direction == TurnDirections - 1) { Dfs(point, 0); } else { Dfs(point, direction + 1); } CurrentWay.pop_back(); //currentNode.Color = EColor::WHITE; }
void Ping6::Send () { NS_LOG_FUNCTION_NOARGS (); NS_ASSERT (m_sendEvent.IsExpired ()); Ptr<Packet> p = 0; uint8_t* data = new uint8_t[m_size]; Ipv6Address src; Ptr<Ipv6> ipv6 = GetNode ()->GetObject<Ipv6> (); if (m_ifIndex > 0) { /* hack to have ifIndex in Ipv6RawSocketImpl * maybe add a SetIfIndex in Ipv6RawSocketImpl directly */ Ipv6InterfaceAddress dstIa (m_peerAddress); for (uint32_t i = 0; i < GetNode ()->GetObject<Ipv6> ()->GetNAddresses (m_ifIndex); i++) { src = GetNode ()->GetObject<Ipv6> ()->GetAddress (m_ifIndex, i).GetAddress (); Ipv6InterfaceAddress srcIa (src); if ( srcIa.GetScope() == dstIa.GetScope() ) { break; } } } else { src = m_localAddress; } NS_ASSERT_MSG (m_size >= 4, "ICMPv6 echo request payload size must be >= 4"); data[0] = 0xDE; data[1] = 0xAD; data[2] = 0xBE; data[3] = 0xEF; p = Create<Packet> (data, 4); p->AddAtEnd (Create<Packet> (m_size - 4)); Icmpv6Echo req (1); req.SetId (0xBEEF); req.SetSeq (m_seq); m_seq++; /* we do not calculate pseudo header checksum here, because we are not sure about * source IPv6 address. Checksum is calculated in Ipv6RawSocketImpl. */ p->AddHeader (req); m_socket->Bind (Inet6SocketAddress (src, 0)); /* use Loose Routing (routing type 0) */ if (m_routers.size ()) { Ipv6ExtensionLooseRoutingHeader routingHeader; routingHeader.SetNextHeader (Ipv6Header::IPV6_ICMPV6); routingHeader.SetLength (m_routers.size () * 16 + 8); routingHeader.SetTypeRouting (0); routingHeader.SetSegmentsLeft (m_routers.size ()); routingHeader.SetRoutersAddress (m_routers); p->AddHeader (routingHeader); m_socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_EXT_ROUTING)); } m_socket->Send (p, 0); ++m_sent; NS_LOG_INFO ("Sent " << p->GetSize () << " bytes to " << m_peerAddress); if (m_sent < m_count) { ScheduleTransmit (m_interval); } delete[] data; }
void VideoVisualGoom::Draw(const QRect &area, MythPainter */*painter*/, QPaintDevice */*device*/) { if (m_disabled || !m_render || area.isEmpty()) return; QMutexLocker lock(mutex()); unsigned int* last = m_buffer; VisualNode *node = GetNode(); if (node) { int numSamps = 512; if (node->length < 512) numSamps = node->length; signed short int data[2][512]; int i= 0; for (; i < numSamps; i++) { data[0][i] = node->left[i]; data[1][i] = node->right ? node->right[i] : data[0][i]; } for (; i < 512; i++) { data[0][i] = 0; data[1][i] = 0; } m_buffer = goom_update(data, 0); } #ifdef USING_OPENGL if ((m_render->Type() == kRenderOpenGL1) || (m_render->Type() == kRenderOpenGL2) || (m_render->Type() == kRenderOpenGL2ES)) { MythRenderOpenGL *glrender = static_cast<MythRenderOpenGL*>(m_render); if (!m_surface && glrender && m_buffer) { m_surface = glrender->CreateTexture(m_area.size(), glrender->GetFeatures() & kGLExtPBufObj, 0, GL_UNSIGNED_BYTE, GL_RGBA, GL_RGBA8, GL_LINEAR_MIPMAP_LINEAR); } if (m_surface && glrender && m_buffer) { if (m_buffer != last) { bool copy = glrender->GetFeatures() & kGLExtPBufObj; void* buf = glrender->GetTextureBuffer(m_surface, copy); if (copy) memcpy(buf, m_buffer, m_area.width() * m_area.height() * 4); glrender->UpdateTexture(m_surface, (void*)m_buffer); } QRectF src(m_area); QRectF dst(area); glrender->DrawBitmap(&m_surface, 1, 0, &src, &dst, 0); } return; } #endif #ifdef USING_VDPAU if (m_render->Type() == kRenderVDPAU) { MythRenderVDPAU *render = static_cast<MythRenderVDPAU*>(m_render); if (!m_surface && render) m_surface = render->CreateBitmapSurface(m_area.size()); if (m_surface && render && m_buffer) { if (m_buffer != last) { void *plane[1] = { m_buffer }; uint32_t pitch[1] = { static_cast<uint32_t>(m_area.width() * 4) }; render->UploadBitmap(m_surface, plane, pitch); } render->DrawBitmap(m_surface, 0, nullptr, nullptr, kVDPBlendNull, 255, 255, 255, 255); } return; } #endif }
//---------------------------------------------------------------------------- void SkinnedBiped::CreateScene () { // Allow for toggle of wireframe. mWireState = new0 WireState(); mRenderer->SetOverrideWireState(mWireState); // The biped has materials assigned to its triangle meshes, so they need // lighting. mLight = new0 Light(Light::LT_DIRECTIONAL); mLight->Ambient = Float4(0.5f, 0.5f, 0.5f, 1.0f); mLight->Diffuse = mLight->Ambient; mLight->Specular = Float4(0.0f, 0.0f, 0.0f, 1.0f); mLight->Constant = 0.0f; mLight->Linear = 0.0f; mLight->Quadratic = 0.0f; mLight->Intensity = 1.0f; mLight->DVector = mCamera->GetDVector(); Node* biped = GetNode("Biped"); Node* pelvis = GetNode("Pelvis"); Node* spine = GetNode("Spine"); Node* spine1 = GetNode("Spine1"); Node* spine2 = GetNode("Spine2"); Node* spine3 = GetNode("Spine3"); Node* neck = GetNode("Neck"); Node* head = GetNode("Head"); Node* leftClavicle = GetNode("L_Clavicle"); Node* leftUpperArm = GetNode("L_UpperArm"); Node* leftForeArm = GetNode("L_Forearm"); Node* leftHand = GetNode("L_Hand"); Node* rightClavicle = GetNode("R_Clavicle"); Node* rightUpperArm = GetNode("R_UpperArm"); Node* rightForeArm = GetNode("R_Forearm"); Node* rightHand = GetNode("R_Hand"); Node* leftThigh = GetNode("L_Thigh"); Node* leftCalf = GetNode("L_Calf"); Node* leftFoot = GetNode("L_Foot"); Node* leftToe = GetNode("L_Toe"); Node* rightThigh = GetNode("R_Thigh"); Node* rightCalf = GetNode("R_Calf"); Node* rightFoot = GetNode("R_Foot"); Node* rightToe = GetNode("R_Toe"); biped->AttachChild(pelvis); pelvis->AttachChild(spine); spine->AttachChild(spine1); spine1->AttachChild(spine2); spine2->AttachChild(spine3); spine3->AttachChild(neck); neck->AttachChild(head); // head->AttachChild(hair); neck->AttachChild(leftClavicle); leftClavicle->AttachChild(leftUpperArm); leftUpperArm->AttachChild(leftForeArm); leftForeArm->AttachChild(leftHand); // leftUpperArm->AttachChild(leftArm); neck->AttachChild(rightClavicle); rightClavicle->AttachChild(rightUpperArm); rightUpperArm->AttachChild(rightForeArm); rightForeArm->AttachChild(rightHand); // rightUpperArm->AttachChild(rightArm); // spine3->AttachChild(face); pelvis->AttachChild(leftThigh); leftThigh->AttachChild(leftCalf); leftCalf->AttachChild(leftFoot); leftFoot->AttachChild(leftToe); // leftCalf->AttachChild(leftShoe); // leftThigh->AttachChild(leftLeg); // leftThigh->AttachChild(leftAngle); pelvis->AttachChild(rightThigh); rightThigh->AttachChild(rightCalf); rightCalf->AttachChild(rightFoot); rightFoot->AttachChild(rightToe); // rightCalf->AttachChild(rightShoe); // rightThigh->AttachChild(rightLeg); // rightThigh->AttachChild(rightAnkle); // pelvis->AttachChild(shirt); // pelvis->AttachChild(pants); // The vertex format is shared among all the triangle meshes. mVFormat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_NORMAL, VertexFormat::AT_FLOAT3, 0); // The TriMesh objects must be created after the Node tree is built, // because the TriMesh objects have to find the "bones" that correspond // to them. TriMesh* hair = GetMesh("Hair",biped); TriMesh* leftArm = GetMesh("L_Arm",biped); TriMesh* rightArm = GetMesh("R_Arm",biped); TriMesh* face = GetMesh("Face",biped); TriMesh* leftShoe = GetMesh("L_Shoe",biped); TriMesh* leftLeg = GetMesh("L_Leg",biped); TriMesh* leftAngle = GetMesh("L_Ankle",biped); TriMesh* rightShoe = GetMesh("R_Shoe",biped); TriMesh* rightLeg = GetMesh("R_Leg",biped); TriMesh* rightAnkle = GetMesh("R_Ankle",biped); TriMesh* shirt = GetMesh("Shirt",biped); TriMesh* pants = GetMesh("Pants",biped); head->AttachChild(hair); leftUpperArm->AttachChild(leftArm); rightUpperArm->AttachChild(rightArm); spine3->AttachChild(face); leftCalf->AttachChild(leftShoe); leftThigh->AttachChild(leftLeg); leftThigh->AttachChild(leftAngle); rightCalf->AttachChild(rightShoe); rightThigh->AttachChild(rightLeg); rightThigh->AttachChild(rightAnkle); pelvis->AttachChild(shirt); pelvis->AttachChild(pants); mScene = new0 Node(); mScene->LocalTransform.SetRotate(HMatrix(AVector::UNIT_Z, 0.25f*Mathf::PI)); mScene->AttachChild(biped); mScene->Update(); #if 0 // For regenerating the biped WMOF whenever engine streaming changes. OutStream target; target.Insert(mScene); target.Save("SkinnedBipedPN.wmof"); #endif }
ASPath ASPathCreate(const ASPathNodeSource *source, void *context, void *startNodeKey, void *goalNodeKey) { VisitedNodes visitedNodes; ASNeighborList neighborList; Node current; Node goalNode; ASPath path = NULL; if (!startNodeKey || !source || !source->nodeNeighbors || source->nodeSize == 0) { return NULL; } visitedNodes = VisitedNodesCreate(source, context); neighborList = NeighborListCreate(source); current = GetNode(visitedNodes, startNodeKey); goalNode = GetNode(visitedNodes, goalNodeKey); // mark the goal node as the goal SetNodeIsGoal(goalNode); // set the starting node's estimate cost to the goal and add it to the open set SetNodeEstimatedCost(current, GetPathCostHeuristic(current, goalNode)); AddNodeToOpenSet(current, 0, NodeNull); // perform the A* algorithm while (HasOpenNode(visitedNodes) && !NodeIsGoal((current = GetOpenNode(visitedNodes)))) { size_t n; if (source->earlyExit) { const int shouldExit = source->earlyExit(visitedNodes->nodeRecordsCount, GetNodeKey(current), goalNodeKey, context); if (shouldExit > 0) { SetNodeIsGoal(current); break; } else if (shouldExit < 0) { break; } } RemoveNodeFromOpenSet(current); AddNodeToClosedSet(current); neighborList->count = 0; source->nodeNeighbors(neighborList, GetNodeKey(current), context); for (n=0; n<neighborList->count; n++) { const float cost = GetNodeCost(current) + NeighborListGetEdgeCost(neighborList, n); Node neighbor = GetNode(visitedNodes, NeighborListGetNodeKey(neighborList, n)); if (!NodeHasEstimatedCost(neighbor)) { SetNodeEstimatedCost(neighbor, GetPathCostHeuristic(neighbor, goalNode)); } if (NodeIsInOpenSet(neighbor) && cost < GetNodeCost(neighbor)) { RemoveNodeFromOpenSet(neighbor); } if (NodeIsInClosedSet(neighbor) && cost < GetNodeCost(neighbor)) { RemoveNodeFromClosedSet(neighbor); } if (!NodeIsInOpenSet(neighbor) && !NodeIsInClosedSet(neighbor)) { AddNodeToOpenSet(neighbor, cost, current); } } } if (NodeIsNull(goalNode)) { SetNodeIsGoal(current); } if (NodeIsGoal(current)) { size_t count = 0; Node n = current; size_t i; while (!NodeIsNull(n)) { count++; n = GetParentNode(n); } CMALLOC(path, sizeof(struct __ASPath) + (count * source->nodeSize)); path->nodeSize = source->nodeSize; path->count = count; path->cost = GetNodeCost(current); n = current; for (i=count; i>0; i--) { memcpy(path->nodeKeys + ((i - 1) * source->nodeSize), GetNodeKey(n), source->nodeSize); n = GetParentNode(n); } } NeighborListDestroy(neighborList); VisitedNodesDestroy(visitedNodes); return path; }
int asCGarbageCollector::IdentifyGarbageWithCyclicRefs() { // This function will only be called within the critical section gcCollecting asASSERT(isProcessing); for(;;) { switch( detectState ) { case clearCounters_init: detectState = clearCounters_loop; break; case clearCounters_loop: { // Decrease reference counter for all objects removed from the map asSMapNode<void*, asSIntTypePair> *cursor = 0; gcMap.MoveFirst(&cursor); if( cursor ) { void *obj = gcMap.GetKey(cursor); asSIntTypePair it = gcMap.GetValue(cursor); engine->CallObjectMethod(obj, it.type->beh.release); ReturnNode(gcMap.Remove(cursor)); return 1; } detectState = buildMap_init; } break; case buildMap_init: detectIdx = 0; detectState = buildMap_loop; break; case buildMap_loop: { // Build a map of objects that will be checked, the map will // hold the object pointer as key, and the gcCount and the // object's type as value. As objects are added to the map the // gcFlag must be set in the objects, so we can be verify if // the object is accessed during the GC cycle. // If an object is removed from the gcObjects list during the // iteration of this step, it is possible that an object won't // be used during the analyzing for cyclic references. This // isn't a problem, as the next time the GC cycle starts the // object will be verified. if( detectIdx < gcOldObjects.GetLength() ) { // Add the gc count for this object asSObjTypePair gcObj = GetOldObjectAtIdx(detectIdx); int refCount = 0; if( gcObj.type->beh.gcGetRefCount ) refCount = engine->CallObjectMethodRetInt(gcObj.obj, gcObj.type->beh.gcGetRefCount); if( refCount > 1 ) { asSIntTypePair it = {refCount-1, gcObj.type}; gcMap.Insert(GetNode(gcObj.obj, it)); // Increment the object's reference counter when putting it in the map engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.addref); // Mark the object so that we can // see if it has changed since read engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.gcSetFlag); } detectIdx++; // Let the application work a little return 1; } else detectState = countReferences_init; } break; case countReferences_init: { gcMap.MoveFirst(&gcMapCursor); detectState = countReferences_loop; } break; case countReferences_loop: { // Call EnumReferences on all objects in the map to count the number // of references reachable from between objects in the map. If all // references for an object in the map is reachable from other objects // in the map, then we know that no outside references are held for // this object, thus it is a potential dead object in a circular reference. // If the gcFlag is cleared for an object we consider the object alive // and referenced from outside the GC, thus we don't enumerate its references. // Any new objects created after this step in the GC cycle won't be // in the map, and is thus automatically considered alive. if( gcMapCursor ) { void *obj = gcMap.GetKey(gcMapCursor); asCObjectType *type = gcMap.GetValue(gcMapCursor).type; gcMap.MoveNext(&gcMapCursor, gcMapCursor); if( engine->CallObjectMethodRetBool(obj, type->beh.gcGetFlag) ) { engine->CallObjectMethod(obj, engine, type->beh.gcEnumReferences); } // Allow the application to work a little return 1; } else detectState = detectGarbage_init; } break; case detectGarbage_init: { gcMap.MoveFirst(&gcMapCursor); liveObjects.SetLength(0); detectState = detectGarbage_loop1; } break; case detectGarbage_loop1: { // All objects that are known not to be dead must be removed from the map, // along with all objects they reference. What remains in the map after // this pass is sure to be dead objects in circular references. // An object is considered alive if its gcFlag is cleared, or all the // references were not found in the map. // Add all alive objects from the map to the liveObjects array if( gcMapCursor ) { asSMapNode<void*, asSIntTypePair> *cursor = gcMapCursor; gcMap.MoveNext(&gcMapCursor, gcMapCursor); void *obj = gcMap.GetKey(cursor); asSIntTypePair it = gcMap.GetValue(cursor); bool gcFlag = engine->CallObjectMethodRetBool(obj, it.type->beh.gcGetFlag); if( !gcFlag || it.i > 0 ) { liveObjects.PushLast(obj); } // Allow the application to work a little return 1; } else detectState = detectGarbage_loop2; } break; case detectGarbage_loop2: { // In this step we are actually removing the alive objects from the map. // As the object is removed, all the objects it references are added to the // liveObjects list, by calling EnumReferences. Only objects still in the map // will be added to the liveObjects list. if( liveObjects.GetLength() ) { void *gcObj = liveObjects.PopLast(); asCObjectType *type = 0; // Remove the object from the map to mark it as alive asSMapNode<void*, asSIntTypePair> *cursor = 0; if( gcMap.MoveTo(&cursor, gcObj) ) { type = gcMap.GetValue(cursor).type; ReturnNode(gcMap.Remove(cursor)); // We need to decrease the reference count again as we remove the object from the map engine->CallObjectMethod(gcObj, type->beh.release); // Enumerate all the object's references so that they too can be marked as alive engine->CallObjectMethod(gcObj, engine, type->beh.gcEnumReferences); } // Allow the application to work a little return 1; } else detectState = verifyUnmarked_init; } break; case verifyUnmarked_init: gcMap.MoveFirst(&gcMapCursor); detectState = verifyUnmarked_loop; break; case verifyUnmarked_loop: { // In this step we must make sure that none of the objects still in the map // has been touched by the application. If they have then we must run the // detectGarbage loop once more. if( gcMapCursor ) { void *gcObj = gcMap.GetKey(gcMapCursor); asCObjectType *type = gcMap.GetValue(gcMapCursor).type; bool gcFlag = engine->CallObjectMethodRetBool(gcObj, type->beh.gcGetFlag); if( !gcFlag ) { // The unmarked object was touched, rerun the detectGarbage loop detectState = detectGarbage_init; } else gcMap.MoveNext(&gcMapCursor, gcMapCursor); // Allow the application to work a little return 1; } else { // No unmarked object was touched, we can now be sure // that objects that have gcCount == 0 really is garbage detectState = breakCircles_init; } } break; case breakCircles_init: { gcMap.MoveFirst(&gcMapCursor); detectState = breakCircles_loop; } break; case breakCircles_loop: case breakCircles_haveGarbage: { // All objects in the map are now known to be dead objects // kept alive through circular references. To be able to free // these objects we need to force the breaking of the circle // by having the objects release their references. if( gcMapCursor ) { numDetected++; void *gcObj = gcMap.GetKey(gcMapCursor); asCObjectType *type = gcMap.GetValue(gcMapCursor).type; if( type->flags & asOBJ_SCRIPT_OBJECT ) { // For script objects we must call the class destructor before // releasing the references, otherwise the destructor may not // be able to perform the necessary clean-up as the handles will // be null. reinterpret_cast<asCScriptObject*>(gcObj)->CallDestructor(); } engine->CallObjectMethod(gcObj, engine, type->beh.gcReleaseAllReferences); gcMap.MoveNext(&gcMapCursor, gcMapCursor); detectState = breakCircles_haveGarbage; // Allow the application to work a little return 1; } else { // If no garbage was detected we can finish now if( detectState != breakCircles_haveGarbage ) { // Restart the GC detectState = clearCounters_init; return 0; } else { // Restart the GC detectState = clearCounters_init; return 1; } } } } // switch } // Shouldn't reach this point UNREACHABLE_RETURN; }
bool BasicSearchTree::FindNode(const string& s, nSearchTreeNode nparent, SearchTreePoint* result) { SearchTreeNode *parentnode, *childnode; nSearchTreeNode nchild; size_t top_depth = m_pNodes[nparent]->GetDepth(); size_t curpos = 0; /* Current position inside the string */ bool found = false; if(s.empty()) { if(result) { result->n = nparent; result->depth = m_pNodes[result->n]->GetDepth(); } return true; } do { parentnode = m_pNodes[nparent]; if(s.empty() || curpos >= s.length() ) // If string is empty, return the node and its vertex's length { if(result) { result->n = nparent; result->depth = top_depth + s.length(); } found = true; break; } nchild=parentnode->GetChild(s[curpos]); childnode = GetNode(nchild,true); if(!childnode) { if(result) { result->n = nparent; result->depth = parentnode->GetDepth(); } found = false; break; } unsigned int newdepth = childnode->GetDeepestMatchingPosition(this,s,top_depth); if(result) { result->n = nchild; result->depth = newdepth; } found =(newdepth == childnode->GetDepth() || newdepth == top_depth + s.length()); curpos = newdepth - top_depth; if(found) { nparent = nchild; } }while(found); return found; }
DWORD ReadString( LPCWSTR pszSection, LPCWSTR pszKey, LPWSTR pszValue, DWORD dwBufLength) { Node* pNode; if (pszSection == NULL) { pNode = m_pRoot; goto SetOfValues; } pNode = GetNode(&m_pRoot, pszSection, FIND_NODE); if (pNode == NULL) goto SetOfValues; if (pszKey == NULL) { pNode = pNode->pChild; goto SetOfValues; } pNode = GetNode(&pNode->pChild, pszKey, FIND_NODE); if (pNode == NULL) goto SetOfValues; pNode = pNode->pChild; SetOfValues: DWORD dwTotalLength = 0; BOOL fMultiple = (pszSection == NULL) || (pszKey == NULL) || (pNode == NULL); // Save space for the terminating '\0' if (fMultiple) { if (dwBufLength == 0) return 0; dwBufLength--; } while (pNode != NULL) { DWORD dwLength = pNode->dwSize / sizeof(WCHAR); if (dwLength >= dwBufLength) { if (dwBufLength == 0) break; dwLength = dwBufLength - 1; } memcpy(pszValue, &pNode->Value, dwLength * sizeof(WCHAR)); *(pszValue + dwLength) = '\0'; pszValue += (dwLength + 1); dwBufLength -= (dwLength + 1); dwTotalLength += dwLength; if (!fMultiple) break; // count the '\0' separator dwTotalLength++; pNode = pNode->pNext; } if (fMultiple) { // terminating '\0' *pszValue = '\0'; } return dwTotalLength; }
void CIntGraph::GenerateRandomConnections (DWORD dwStartNode, int iMinConnections, int iMaxConnections) // GenerateRandomConnections // // Generate random connection across all nodes. { int i, j; // We start by making sure every node is connected with one other node. // We keep track of the nodes that are connected and those that are not. TArray<int> Connected; TArray<int> NotConnected; // All the nodes are part of the not-connected group // (except for the start node) for (i = 0; i < m_Nodes.GetCount(); i++) if (i != dwStartNode && !NodeIsFree(GetNode(i))) NotConnected.Insert(i); Connected.Insert((int)dwStartNode); // Loop until all nodes are connected while (NotConnected.GetCount() > 0) { // Look for the shortest, non-overlapping distance // between a node in the connected list and a node in the // not-connected list. int iBestDist2 = MAX_DIST2; int iBestFrom = -1; int iBestTo = -1; for (i = 0; i < Connected.GetCount(); i++) { int iFrom = i; SNode *pFrom = GetNode(Connected[iFrom]); for (j = 0; j < NotConnected.GetCount(); j++) { int iTo = j; SNode *pTo = GetNode(NotConnected[iTo]); int xDist = pTo->x - pFrom->x; int yDist = pTo->y - pFrom->y; int iDist2 = xDist * xDist + yDist * yDist; if (iDist2 < iBestDist2 && !IsCrossingConnection(Connected[iFrom], NotConnected[iTo])) { iBestDist2 = iDist2; iBestFrom = iFrom; iBestTo = iTo; } } } // If we found a best distance, connect the two nodes if (iBestFrom != -1) { Connect(Connected[iBestFrom], NotConnected[iBestTo]); Connected.Insert(NotConnected[iBestTo]); NotConnected.Delete(iBestTo); } // If we did not find the best distance, then it means that we could not // connect without overlapping. In that case, just connect all the unconnected else { for (i = 0; i < NotConnected.GetCount(); i++) Connect(Connected[0], NotConnected[i]); NotConnected.DeleteAll(); } } }
int SCH_SCREEN::GetConnection( const wxPoint& aPosition, PICKED_ITEMS_LIST& aList, bool aFullConnection ) { SCH_ITEM* item; EDA_ITEM* tmp; EDA_ITEMS list; // Clear flags member for all items. ClearDrawingState(); if( GetNode( aPosition, list ) == 0 ) return 0; for( size_t i = 0; i < list.size(); i++ ) { item = (SCH_ITEM*) list[ i ]; item->SetFlags( SELECTEDNODE | STRUCT_DELETED ); /* Put this structure in the picked list: */ ITEM_PICKER picker( item, UR_DELETED ); aList.PushItem( picker ); } // Mark all wires, junctions, .. connected to the item(s) found. if( aFullConnection ) { SCH_LINE* segment; for( item = m_drawList.begin(); item; item = item->Next() ) { if( !(item->GetFlags() & SELECTEDNODE) ) continue; if( item->Type() != SCH_LINE_T ) continue; MarkConnections( (SCH_LINE*) item ); } // Search all attached wires (i.e wire with one new dangling end ) for( item = m_drawList.begin(); item; item = item->Next() ) { bool noconnect = false; if( item->GetFlags() & STRUCT_DELETED ) continue; // Already seen if( !(item->GetFlags() & CANDIDATE) ) continue; // not a candidate if( item->Type() != SCH_LINE_T ) continue; item->SetFlags( SKIP_STRUCT ); segment = (SCH_LINE*) item; /* If the wire start point is connected to a wire that was already found * and now is not connected, add the wire to the list. */ for( tmp = m_drawList.begin(); tmp; tmp = tmp->Next() ) { // Ensure tmp is a previously deleted segment: if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 ) continue; if( tmp->Type() != SCH_LINE_T ) continue; SCH_LINE* testSegment = (SCH_LINE*) tmp; // Test for segment connected to the previously deleted segment: if( testSegment->IsEndPoint( segment->GetStartPoint() ) ) break; } // when tmp != NULL, segment is a new candidate: // put it in deleted list if // the start point is not connected to an other item (like pin) if( tmp && !CountConnectedItems( segment->GetStartPoint(), true ) ) noconnect = true; /* If the wire end point is connected to a wire that has already been found * and now is not connected, add the wire to the list. */ for( tmp = m_drawList.begin(); tmp; tmp = tmp->Next() ) { // Ensure tmp is a previously deleted segment: if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 ) continue; if( tmp->Type() != SCH_LINE_T ) continue; SCH_LINE* testSegment = (SCH_LINE*) tmp; // Test for segment connected to the previously deleted segment: if( testSegment->IsEndPoint( segment->GetEndPoint() ) ) break; } // when tmp != NULL, segment is a new candidate: // put it in deleted list if // the end point is not connected to an other item (like pin) if( tmp && !CountConnectedItems( segment->GetEndPoint(), true ) ) noconnect = true; item->ClearFlags( SKIP_STRUCT ); if( noconnect ) { item->SetFlags( STRUCT_DELETED ); ITEM_PICKER picker( item, UR_DELETED ); aList.PushItem( picker ); item = m_drawList.begin(); } } for( item = m_drawList.begin(); item; item = item->Next() ) { if( item->GetFlags() & STRUCT_DELETED ) continue; if( item->Type() != SCH_LABEL_T ) continue; tmp = GetWireOrBus( ( (SCH_TEXT*) item )->GetPosition() ); if( tmp && ( tmp->GetFlags() & STRUCT_DELETED ) ) { item->SetFlags( STRUCT_DELETED ); ITEM_PICKER picker( item, UR_DELETED ); aList.PushItem( picker ); } } } ClearDrawingState(); return aList.GetCount(); }
bool CCharShape::CheckCollision (const TPolyhedron& ph) { TCharNode *node = GetNode(0); if (node == NULL) return false; const TMatrix<4, 4>& identity = TMatrix<4, 4>::getIdentity(); return CheckPolyhedronCollision(node, identity, identity, ph); }
INode* MorphByBone::fnGetSelectedBone() { INode *pnode = GetNode(currentBone); return pnode; }
void Weapon::Fire() { if (m_fCurrentCooldown <= 0.0f) { m_fCurrentCooldown = m_fCooldown; PhysicalObject *pOwner = GetOwner(); if (pOwner) { Node *pSourceNode = pOwner->GetNode(); if (pSourceNode) { Projectile *pNewProjectile = new Projectile(GetNode()); VECTOR3 vDirection; Matrix44 mat = pSourceNode->m_PosQuat.quat.ToMatrix(); float yDisp = -(pSourceNode->m_vScale.y / 2.0f + pNewProjectile->GetNode()->m_vScale.y / 2.0f); if (pSourceNode->GetNodeFlags() & NODE_RENDER_UPSIDEDOWN) { yDisp *= -1.0f; } pNewProjectile->GetNode()->m_PosQuat.pos.x = mat.m[4] * yDisp + pSourceNode->m_PosQuat.pos.x; pNewProjectile->GetNode()->m_PosQuat.pos.y = mat.m[5] * yDisp + pSourceNode->m_PosQuat.pos.y; pNewProjectile->GetNode()->m_PosQuat.pos.z = mat.m[6] * yDisp + pSourceNode->m_PosQuat.pos.z; //calculate actual firing direction based on aim, and weapon spread int dwRandom = GenerateRandomInt(9); float fSpread = 0.0f; if (dwRandom < 7) { fSpread = GenerateRandomFloat(0.05f); } else if (dwRandom < 9) { fSpread = GenerateRandomFloat(0.15f) + 0.05f; } else { fSpread = GenerateRandomFloat(0.30f) + 0.2f; } if (GenerateRandomInt(1)) { fSpread = -fSpread; } fSpread = fSpread * m_fFiringSpread; float fCos = cos(fSpread); float fSin = sin(fSpread); //vDirection.x = fCos * m_vAim.x + fSin * m_vAim.x; //vDirection.y = fCos * m_vAim.y - fSin * m_vAim.y; vDirection.x = fCos * m_vAim.x - fSin * m_vAim.y; vDirection.y = fSin * m_vAim.x + fCos * m_vAim.y; vDirection.z = 0.0f; NormalizeVECTOR3(vDirection); pNewProjectile->GetNode()->m_PosQuat.pos.z = pSourceNode->m_PosQuat.pos.z; pNewProjectile->SetMaxSpeed(m_fSpeed); pNewProjectile->SetVelocity(VECTOR3(m_fSpeed * vDirection.x, m_fSpeed * vDirection.y, m_fSpeed * vDirection.z)); pNewProjectile->SetCreator(pOwner); pNewProjectile->SetWeapon(this); Quat *quat = &(pNewProjectile->GetNode()->m_PosQuat.quat); Quat rotation; rotation.CreateFromRotationRADIANS(fSpread, 0.0f, 0.0f, 1.0f); *quat = rotation * *quat; TestFireEvent *pTestFireEvent = new TestFireEvent(); pTestFireEvent->SetProjectile(pNewProjectile); gEventManager()->AddEvent(pTestFireEvent); pTestFireEvent->Release(); pNewProjectile->Release(); } } } }
void NewMode(int selectedmode) { struct UnitNode *unit = NULL; struct ModeNode *mode = NULL; ULONG id = AHI_INVALID_ID; Fixed MinOutVol = 0, MaxOutVol = 0, MinMonVol = 0, MaxMonVol = 0; Fixed MinGain = 0, MaxGain = 0; double Min, Max, Current; int offset; state.ModeSelected = selectedmode; unit = (struct UnitNode *) GetNode(state.UnitSelected, UnitList); if( selectedmode != ~0 ) { mode = (struct ModeNode *) GetNode(selectedmode, ModeList); } if( mode != NULL ) { id = mode->ID; AHI_GetAudioAttrs(id, NULL, AHIDB_IndexArg, unit->prefs.ahiup_Frequency, AHIDB_Index, (ULONG) &state.FreqSelected, AHIDB_Frequencies, (ULONG) &state.Frequencies, AHIDB_MaxChannels, (ULONG) &state.Channels, AHIDB_Inputs, (ULONG) &state.Inputs, AHIDB_Outputs, (ULONG) &state.Outputs, AHIDB_MinOutputVolume, (ULONG) &MinOutVol, AHIDB_MaxOutputVolume, (ULONG) &MaxOutVol, AHIDB_MinMonitorVolume, (ULONG) &MinMonVol, AHIDB_MaxMonitorVolume, (ULONG) &MaxMonVol, AHIDB_MinInputGain, (ULONG) &MinGain, AHIDB_MaxInputGain, (ULONG) &MaxGain, AHIDB_BufferLen, 128, AHIDB_Author, (ULONG) authorBuffer, AHIDB_Copyright, (ULONG) copyrightBuffer, AHIDB_Driver, (ULONG) driverBuffer, AHIDB_Version, (ULONG) versionBuffer, AHIDB_Annotation, (ULONG) annotationBuffer, TAG_DONE); } state.ChannelsSelected = unit->prefs.ahiup_Channels; state.InputSelected = unit->prefs.ahiup_Input; state.OutputSelected = unit->prefs.ahiup_Output; // Limit channels state.Channels = min(state.Channels, 32); if(unit->prefs.ahiup_Unit == AHI_NO_UNIT) { state.ChannelsDisabled = TRUE; } else { state.ChannelsDisabled = FALSE; } if(MinOutVol == 0) { MinOutVol = 1; state.OutVolMute = TRUE; state.OutVols = 1; } else { state.OutVolMute = FALSE; state.OutVols = 0; } if(MinMonVol == 0) { MinMonVol = 1; state.MonVolMute = TRUE; state.MonVols = 1; } else { state.MonVolMute = FALSE; state.MonVols = 0; } if(MinGain == 0) { MinGain = 1; state.GainMute = TRUE; state.Gains = 1; } else { state.GainMute = FALSE; state.Gains = 0; } if(MaxOutVol == 0) { state.OutVolSelected = 0; state.OutVolOffset = 0; } else { Current = 20 * log10( unit->prefs.ahiup_OutputVolume / 65536.0 ); Min = floor(20 * log10( MinOutVol / 65536.0 ) / DBSTEP + 0.5) * DBSTEP; Max = floor(20 * log10( MaxOutVol / 65536.0 ) / DBSTEP + 0.5) * DBSTEP; state.OutVolSelected = (Current - Min) / DBSTEP + 0.5 + state.OutVols; state.OutVols += ((Max - Min) / DBSTEP) + 1; state.OutVolOffset = Min; } if(MaxMonVol == 0) { state.MonVolSelected = 0; state.MonVolOffset = 0; } else { Current = 20 * log10( unit->prefs.ahiup_MonitorVolume / 65536.0 ); Min = floor(20 * log10( MinMonVol / 65536.0 ) / DBSTEP + 0.5) * DBSTEP; Max = floor(20 * log10( MaxMonVol / 65536.0 ) / DBSTEP + 0.5) * DBSTEP; state.MonVolSelected = (Current - Min) / DBSTEP + 0.5 + state.MonVols; state.MonVols += ((Max - Min) / DBSTEP) + 1; state.MonVolOffset = Min; } if(MaxGain == 0) { state.GainSelected = 0; state.GainOffset = 0; } else { Current = 20 * log10( unit->prefs.ahiup_InputGain / 65536.0 ); Min = floor(20 * log10( MinGain / 65536.0 ) / DBSTEP + 0.5) * DBSTEP; Max = floor(20 * log10( MaxGain / 65536.0 ) / DBSTEP + 0.5) * DBSTEP; state.GainSelected = (Current - Min) / DBSTEP + 0.5 + state.Gains; state.Gains += ((Max - Min) / DBSTEP) + 1; state.GainOffset = Min; } // Make sure everything is within bounds! state.FreqSelected = max(state.FreqSelected, 0); state.FreqSelected = min(state.FreqSelected, state.Frequencies); state.ChannelsSelected = max(state.ChannelsSelected, 1); state.ChannelsSelected = min(state.ChannelsSelected, state.Channels); state.OutVolSelected = max(state.OutVolSelected, 0); state.OutVolSelected = min(state.OutVolSelected, state.OutVols); state.MonVolSelected = max(state.MonVolSelected, 0); state.MonVolSelected = min(state.MonVolSelected, state.MonVols); state.GainSelected = max(state.GainSelected, 0); state.GainSelected = min(state.GainSelected, state.Gains); state.InputSelected = max(state.InputSelected, 0); state.InputSelected = min(state.InputSelected, state.Inputs); state.OutputSelected = max(state.OutputSelected, 0); state.OutputSelected = min(state.OutputSelected, state.Outputs); // Remove any \r's or \n's from version string offset = strlen(versionBuffer); while((offset > 0) && ((versionBuffer[offset-1] == '\r') || (versionBuffer[offset-1] == '\n'))) { versionBuffer[offset-1] = '\0'; offset--; } FreeVec(Inputs); FreeVec(Outputs); Inputs = GetInputs(id); Outputs = GetOutputs(id); }
/* <486d8d> ../cstrike/dlls/hostage/hostage_localnav.cpp:304 */ node_index_t CLocalNav::FindPath(Vector &vecStart, Vector &vecDest, float flTargetRadius, int fNoMonsters) { node_index_t nIndexBest = FindDirectPath(vecStart, vecDest, flTargetRadius, fNoMonsters); if (nIndexBest != -1) { return nIndexBest; } localnode_t *node; Vector vecNodeLoc; float_precision flDistToDest; m_vecStartingLoc = vecStart; m_nindexAvailableNode = 0; AddPathNodes(-1, fNoMonsters); nIndexBest = GetBestNode(vecStart, vecDest); while (nIndexBest != -1) { node = GetNode(nIndexBest); node->fSearched = TRUE; vecNodeLoc = node->vecLoc; flDistToDest = (vecDest - node->vecLoc).Length2D(); if (flDistToDest <= flTargetRadius) break; if (flDistToDest <= HOSTAGE_STEPSIZE) break; if (((flDistToDest - flTargetRadius) > ((MAX_NODES - m_nindexAvailableNode) * HOSTAGE_STEPSIZE)) || m_nindexAvailableNode == MAX_NODES) { nIndexBest = -1; break; } AddPathNodes(nIndexBest, fNoMonsters); nIndexBest = GetBestNode(vecNodeLoc, vecDest); } if (m_nindexAvailableNode <= 10) nodeval += 2; else if (m_nindexAvailableNode <= 20) nodeval += 4; else if (m_nindexAvailableNode <= 30) nodeval += 8; else if (m_nindexAvailableNode <= 40) nodeval += 13; else if (m_nindexAvailableNode <= 50) nodeval += 19; else if (m_nindexAvailableNode <= 60) nodeval += 26; else if (m_nindexAvailableNode <= 70) nodeval += 34; else if (m_nindexAvailableNode <= 80) nodeval += 43; else if (m_nindexAvailableNode <= 90) nodeval += 53; else if (m_nindexAvailableNode <= 100) nodeval += 64; else if (m_nindexAvailableNode <= 110) nodeval += 76; else if (m_nindexAvailableNode <= 120) nodeval += 89; else if (m_nindexAvailableNode <= 130) nodeval += 103; else if (m_nindexAvailableNode <= 140) nodeval += 118; else if (m_nindexAvailableNode <= 150) nodeval += 134; else if (m_nindexAvailableNode <= 160) nodeval += 151; else nodeval += 169; return nIndexBest; }
void TextComponent::OnUpdate(double time_diff) { if(mRefresh && mFont != "") { // calculate the text width mTextWidth = 0; Ogre::Font* font = dynamic_cast<Ogre::Font*>(Ogre::FontManager::getSingleton().getByName(mFont).getPointer()); if(font == nullptr) { Logger::Get().Warning("Cannot find font: \"" + mFont + "\"."); } else { for(Ogre::String::iterator iter = mText.begin(); iter < mText.end(); ++iter) { if(*iter == 0x0020) { mTextWidth += font->getGlyphAspectRatio(0x0030); } else { mTextWidth += font->getGlyphAspectRatio(*iter); } } mTextWidth *= mFontSize; } mRefresh = false; } // set the position Ogre::Camera* camera = DisplayManager::Get()->GetMainCamera()->GetCamera(); Ogre::Vector3 screen_pos(camera->getProjectionMatrix() * camera->getViewMatrix() * GetNode()->GetPosition(Node::SCENE)); if(screen_pos.z >= 1) { // behind or in the camera, hide mOverlay->hide(); } else { mOverlay->show(); } float x = 1.0f - ((-screen_pos.x * 0.5f) + 0.5f); // 0 <= x <= 1 // left := 0,right := 1 float y = ((-screen_pos.y * 0.5f) + 0.5f); // 0 <= y <= 1 // bottom := 0,top := 1 x *= camera->getViewport()->getActualWidth(); y *= camera->getViewport()->getActualHeight(); mPanel->setMetricsMode(Ogre::GMM_PIXELS); mPanel->setWidth(mTextWidth + 2 * mPadding.x); mPanel->setHeight(mFontSize + 2 * mPadding.y); mPanel->setLeft(x - mTextWidth / 2 - mPadding.x); mPanel->setTop(y - mFontSize / 2 - mPadding.y); mLabel->setPosition(mPadding.x, mPadding.y); mLabel->setDimensions(mTextWidth, mFontSize); }
/* <486adb> ../cstrike/dlls/hostage/hostage_localnav.cpp:138 */ void CLocalNav::AddPathNode(node_index_t nindexSource, int offsetX, int offsetY, int fNoMonsters) { int bDepth; Vector vecSource, vecDest; int offsetXAbs, offsetYAbs; if (nindexSource == -1) { bDepth = 1; offsetXAbs = offsetX; offsetYAbs = offsetY; vecSource = m_vecStartingLoc; vecDest = vecSource + Vector(((float_precision)offsetX * HOSTAGE_STEPSIZE), ((float_precision)offsetY * HOSTAGE_STEPSIZE), 0); } else { localnode_t *nodeSource; localnode_t *nodeCurrent; node_index_t nindexCurrent; nodeCurrent = GetNode(nindexSource); offsetXAbs = offsetX + nodeCurrent->offsetX; offsetYAbs = offsetY + nodeCurrent->offsetY; nodeSource = GetNode(m_nindexAvailableNode); // if there exists a node, then to ignore adding a the new node if (NodeExists(offsetXAbs, offsetYAbs) != NODE_INVALID_EMPTY) { return; } vecSource = nodeCurrent->vecLoc; vecDest = vecSource + Vector(((float_precision)offsetX * HOSTAGE_STEPSIZE), ((float_precision)offsetY * HOSTAGE_STEPSIZE), 0); if (m_nindexAvailableNode) { nindexCurrent = m_nindexAvailableNode; do { nodeSource--; nindexCurrent--; offsetX = (nodeSource->offsetX - offsetXAbs); if (offsetX >= 0) { if (offsetX > 1) { continue; } } else { if (-offsetX > 1) { continue; } } offsetY = (nodeSource->offsetY - offsetYAbs); if (offsetY >= 0) { if (offsetY > 1) { continue; } } else { if (-offsetY > 1) { continue; } } if (PathTraversable(nodeSource->vecLoc, vecDest, fNoMonsters) != PATH_TRAVERSABLE_EMPTY) { nodeCurrent = nodeSource; nindexSource = nindexCurrent; } } while (nindexCurrent); } vecSource = nodeCurrent->vecLoc; bDepth = ((int)nodeCurrent->bDepth) + 1; } if (PathTraversable(vecSource, vecDest, fNoMonsters) != PATH_TRAVERSABLE_EMPTY) { AddNode(nindexSource, vecDest, offsetXAbs, offsetYAbs, bDepth); } }
virtual void ReadValue() { wxString s = XmlReadValue(GetNode(), m_PropInfo->Name); m_c = s.BeforeFirst(_T('d')); m_TextCtrl->SetValue(m_c); }
// find a node with the given string value, create one if it does not exist // and fCreate is specified Node* GetNode(Node** ppNode, LPCWSTR pszValue, Action action) { return GetNode(ppNode, (LPCVOID)pszValue, sizeof(WCHAR) * wcslen(pszValue), action); }
void PropEditCtrlTxt::ReadValue() { m_TextCtrl->SetValue(XmlReadValue(GetNode(), m_PropInfo->Name)); }
BOOL Load(LPCWSTR pszFileName) { DWORD dwSize, dwRead; DWORD dwSizeHigh; BOOL fRet = FALSE; PVOID pReadBuffer = NULL; WCHAR* pBuffer = NULL; Node* pSection = NULL; Node* pKey; WCHAR* p; WCHAR* pEnd; // read the ini file HANDLE hFile = CreateFileW(pszFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { return FALSE; } dwSize = GetFileSize(hFile, &dwSizeHigh); if ((dwSizeHigh == INVALID_FILE_SIZE) && GetLastError() != NO_ERROR) goto Error; if (dwSizeHigh != 0) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto Error; } pReadBuffer = malloc(dwSize); if (pReadBuffer == NULL) { SetLastError(ERROR_OUTOFMEMORY); goto Error; } if (!ReadFile(hFile, pReadBuffer, dwSize, &dwRead, NULL)) goto Error; if (dwRead != dwSize) { SetLastError(ERROR_READ_FAULT); goto Error; } pBuffer = (WCHAR*)malloc(dwSize * sizeof(WCHAR)); if (pBuffer == NULL) { SetLastError(ERROR_OUTOFMEMORY); goto Error; } dwSize = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pReadBuffer, dwSize, pBuffer, dwSize); p = pBuffer; pEnd = pBuffer + dwSize; for (;;) { WCHAR *pValueStart; WCHAR *pValueEnd; #define TEST(cond) ((p < pEnd) && (cond)) #define PARSE_UNTIL(ch) while (TEST((*p != ch) && !IsJunk(*p))) p++ #define PARSE_WHILE(pred) while (TEST(pred(*p))) p++ PARSE_WHILE(IsJunk); // are we done? if (p >= pEnd) break; if (TEST(*p == '[')) { p++; PARSE_WHILE(IsJunk); // we've got the section name pValueStart = p; PARSE_UNTIL(']'); pValueEnd = p; PARSE_WHILE(IsJunk); // better have closing bracket now if (!TEST(*p == ']')) goto ParseError; p++; pSection = GetNode(&m_pRoot, (LPCVOID)pValueStart, (BYTE*)pValueEnd - (BYTE*)pValueStart, CREATE_NODE); if (pSection == NULL) goto Error; continue; } else if (TEST(*p == ';') || TEST(*p == '#') || TEST(*p == '!')) { p++; // everything up to the end of the line is comment - ignored PARSE_WHILE(!IsEndOfLine); continue; } else { // we've got the key value pair pValueStart = p; PARSE_UNTIL('='); pValueEnd = p; PARSE_WHILE(IsJunk); // better have the equal sign now if (!TEST(*p == '=')) goto ParseError; p++; // no section to throw this in if (pSection == NULL) goto ParseError; pKey = GetNode(&(pSection->pChild), (LPCVOID)pValueStart, (BYTE*)pValueEnd - (BYTE*)pValueStart, CREATE_NODE); if (pKey == NULL) goto Error; // the value is everything till end of the line pValueStart = p; PARSE_WHILE(!IsEndOfLine); pValueEnd = p; // duplicate node if (pKey->pChild != NULL) goto ParseError; pKey->pChild = CreateNode((LPCVOID)pValueStart, (BYTE*)pValueEnd - (BYTE*)pValueStart); if (pKey->pChild == NULL) goto Error; continue; } ParseError: // We don't support more graceful recovery by skipping the current // line. Instead we bail out at the first instance of parse error. SetLastError(ERROR_FILE_INVALID); goto Error; } m_fDirty = FALSE; fRet = TRUE; Error: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); free(pReadBuffer); free(pBuffer); return fRet; }
/// Get the "youngest" FOWObject of all players who share the view with the local player const FOWObject* GameWorldViewer::GetYoungestFOWObject(const MapPoint pos) const { return GetNode(pos).fow[GetYoungestFOWNodePlayer(pos)].object; }
/// Find a path on the Trade Graph bool TradeGraph::FindPath(const MapPoint start, const MapPoint goal, std::vector<unsigned char>& route) const { // Todo list std::list< MapPoint > todo; todo.push_back(start); std::vector<TGN> nodes(size.x * size.y); nodes[start.y * size.x + start.x].route_length = 0; nodes[start.y * size.x + start.x].real_length = 0; while(!todo.empty()) { unsigned shortest_route = 0xFFFFFFFF; std::list<MapPoint >::iterator best_it; for(std::list<MapPoint >::iterator it = todo.begin(); it != todo.end(); ++it) { unsigned new_way = nodes[it->y * size.x + it->x].real_length + TGN_SIZE; if(new_way < shortest_route) { shortest_route = new_way; best_it = it; } } nodes[best_it->y * size.x + best_it->x].visited = true; for(unsigned i = 0; i < 8; ++i) { if(GetNode(*best_it).dirs[i] == NO_EDGE) continue; MapPoint new_pos(GetNodeAround(*best_it, i + 1)); if(nodes[new_pos.y * size.x + new_pos.x].visited) continue; if(new_pos == goal) { // Reached goal route.resize(nodes[best_it->y * size.x + best_it->x].route_length + 1); route[route.size() - 1] = i; MapPoint pos = *best_it; for(int z = route.size() - 2; z >= 0; --z, pos = GetNodeAround(pos, (nodes[pos.y * size.x + pos.x].dir + 4) % 8 + 1)) route[z] = nodes[pos.y * size.x + pos.x].dir; return true; } unsigned new_length = nodes[best_it->y * size.x + best_it->x].real_length + GetNode(*best_it).dirs[i]; if(new_length < nodes[new_pos.y * size.x + new_pos.x].real_length) { nodes[new_pos.y * size.x + new_pos.x].real_length = new_length; nodes[new_pos.y * size.x + new_pos.x].dir = i; nodes[new_pos.y * size.x + new_pos.x].route_length = nodes[best_it->y * size.x + best_it->x].route_length + 1; if(!nodes[new_pos.y * size.x + new_pos.x].in_list) { nodes[new_pos.y * size.x + new_pos.x].in_list = true; todo.push_back(new_pos); } } } // Knoten behandelt --> raus aus der todo Liste todo.erase(best_it); } return false; }