Esempio n. 1
0
/* This function compares the particles position to the center of the parent
   (or cell) box and chooses the appropriate child to move down to, until
   either a child box or a null pointer is reached. In the first case, the box
   is returned, and in the second, a new child box is created for the parent,
   and that box is returned. */
box *
FindHome (long my_id, particle *p, box *current_home)
{
   box *pb;

   pb = FindInitialRoot(p, current_home);
   while (pb->type == PARENT) {
      if (p->pos.y > pb->y_center) {
	 if (p->pos.x > pb->x_center) {
	    if (pb->children[0] == NULL)
	       CreateChild(my_id, pb, 0);
	    pb = pb->children[0];
	 }
	 else {
	    if (pb->children[1] == NULL)
	       CreateChild(my_id, pb, 1);
	    pb = pb->children[1];
	 }
      }
      else {
	 if (p->pos.x > pb->x_center) {
	    if (pb->children[3] == NULL)
	       CreateChild(my_id, pb, 3);
	    pb = pb->children[3];
	 }
	 else {
	    if (pb->children[2] == NULL)
	       CreateChild(my_id, pb, 2);
	    pb = pb->children[2];
	 }
      }
   }
   return pb;
}
Esempio n. 2
0
void TreeBuilder::AddRandomChildren( 
  Node& node, bool bUseTerminal, bool bUseNode, unsigned int nDepth, unsigned int nMaxDepth ) {
  assert( bUseTerminal || bUseNode ); // use one or both
  assert( nDepth <= nMaxDepth ); 
  NodeType::E nt( node.ChildType() );
  switch ( node.NodeCount() ) {
  case 0: // nothing, this is terminal node
    assert( node.IsTerminal() );
    break;
  case 1:
    node.AddCenter( CreateChild( nt, bUseTerminal, bUseNode, nDepth, nMaxDepth ) );
    if ( !node.ChildCenter().IsTerminal() ) {
      AddRandomChildren( node.ChildCenter(), bUseTerminal, bUseNode, nDepth + 1, nMaxDepth );
    }
    break;
  case 2: 
    node.AddLeft( CreateChild( nt, bUseTerminal, bUseNode, nDepth, nMaxDepth ) );
    if ( !node.ChildLeft().IsTerminal() ) {
      AddRandomChildren( node.ChildLeft(), bUseTerminal, bUseNode, nDepth + 1, nMaxDepth );
    }
    node.AddRight( CreateChild( nt, bUseTerminal, bUseNode, nDepth, nMaxDepth ) );
    if ( !node.ChildRight().IsTerminal() ) {
      AddRandomChildren( node.ChildRight(), bUseTerminal, bUseNode, nDepth + 1, nMaxDepth );
    }
    break;
  }
}
Esempio n. 3
0
void XMLNode::CopyFrom(XMLNode* from)
{
  Clear();
  SetType(from->Type());
  for (int i = 0; i < from->ChildCount(); ++i)
    CreateChild("")->CopyFrom(from->Child(i));
}
Esempio n. 4
0
void CWorldState::SetString(const char * entityName,  char * valueName , string value)
{
//	CryLog("CWorldState::SetString()");
	if(worldStateXml)
	{
		XmlNodeRef entityNode = worldStateXml->findChild(entityName);

		if(!entityNode)
		{
			CreateChild(entityName);
			entityNode = worldStateXml->findChild(entityName);
		}
		const uint32 Count = entityNode->getChildCount();

		for (uint32 Index = 0; Index < Count; ++Index)
		{
			XmlNodeRef child = entityNode->getChild(Index);

			if(strcmp(child->getTag(),valueName)==0)
			{
				child->setAttr("value",value);
				worldStateXml->saveToFile(szSaveFile);
				return;
			}
		}

		//CryLog("CWorldState::CreateString()");

		XmlNodeRef child = entityNode->newChild(valueName);
		child->setAttr("value",value);
		worldStateXml->saveToFile(szSaveFile);
	}
	else
		return;
}
Esempio n. 5
0
XMLElement XMLElement::GetOrCreateChild(const char* name)
{
    XMLElement child = GetChild(name);
    if (child.NotNull())
        return child;
    else
        return CreateChild(name);
}
Esempio n. 6
0
void JSONValue::AddVariant(const Variant& value)
{
    // Create child object for variant
    JSONValue child = CreateChild(JSON_OBJECT);
    // Set type
    child.SetString("type", value.GetTypeName());
    // Set value
    child.SetVariantValue("value", value);
}
Esempio n. 7
0
void XmlNode::CopyFrom(XmlNode* from)
{
  if (m_Type != from->Type())
    throw "";
  Clear();
  SetName(from->Name());
  SetValue(from->Value());
  for (int i = 0; i < from->ChildCount(); ++i)
    CreateChild()->CopyFrom(from->Child(i));
}
Esempio n. 8
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	g_hInstance = hInstance;
	Register( "Main", WndProc );
	HWND hWnd = CreateMain( "Main", "window" );
	Register( "CHILD", DefWindowProc );
	HWND hChild1 = CreateChild( "CHILD", "C1", hWnd );
	HWND hChild2 = CreateChild( "CHILD", "C2", hWnd );
	Display( hWnd );
	MoveWindow( hChild1, 300, 100, 200, 200, TRUE );
	MoveWindow( hChild2, 500, 100, 200, 200, TRUE );
	SetExtra( hChild1 );
	GetExtra( hChild2 );
	Message( );
	return 0;
}
Esempio n. 9
0
// 创建外壳进程并用目标进程替换它然后执行   
HANDLE CExeMemory::AttachPE(char *CmdParam, PIMAGE_NT_HEADERS peH, PIMAGE_SECTION_HEADERS peSecH, void *Ptr, unsigned long ImageSize, unsigned long &ProcId)   
{   
    HANDLE res = INVALID_HANDLE_VALUE;   
    CONTEXT Ctx;   
    HANDLE Thrd;   
    unsigned long Addr, Size;   
    char *s = PrepareShellExe(CmdParam, peH->OptionalHeader.ImageBase, ImageSize);   
    if(s==NULL) return res;   
    if(CreateChild(s, Ctx, res, Thrd, ProcId, Addr, Size)){   
        void *p = NULL;   
        unsigned long old;   
        if((peH->OptionalHeader.ImageBase == Addr) && (Size >= ImageSize)){// 外壳进程可以容纳目标进程并且加载地址一致   
            p = (void *)Addr;   
            VirtualProtectEx(res, p, Size, PAGE_EXECUTE_READWRITE, &old);   
        }   
        else {   
            if(UnloadShell(res, Addr)){// 卸载外壳进程占有内存   
                p = VirtualAllocEx(res, (void *)peH->OptionalHeader.ImageBase, ImageSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);   
            }   
            if((p == NULL) && HasRelocationTable(peH)){// 分配内存失败并且目标进程支持重定向   
                p = VirtualAllocEx(res, NULL, ImageSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);   
                if(p) DoRelocation(peH, Ptr, p); // 重定向   
            }   
        }   
        if(p){   
            WriteProcessMemory(res, (void *)(Ctx.Ebx+8), &p, sizeof(DWORD), &old); // 重置目标进程运行环境中的基址   
            peH->OptionalHeader.ImageBase = (unsigned long)p;   
            if(WriteProcessMemory(res, p, Ptr, ImageSize, &old)){// 复制PE数据到目标进程   
                Ctx.ContextFlags = CONTEXT_FULL;   
                if((unsigned long)p == Addr)   
                    Ctx.Eax = peH->OptionalHeader.ImageBase + peH->OptionalHeader.AddressOfEntryPoint; // 重置运行环境中的入口地址   
                else  
                    Ctx.Eax = (unsigned long)p + peH->OptionalHeader.AddressOfEntryPoint;   
                SetThreadContext(Thrd, &Ctx);// 更新运行环境   
                ResumeThread(Thrd);// 执行   
                CloseHandle(Thrd);   
            }   
            else{// 加载失败,杀掉外壳进程   
                TerminateProcess(res, 0);   
                CloseHandle(Thrd);   
                CloseHandle(res);   
                res = INVALID_HANDLE_VALUE;   
            }   
        }   
        else{// 加载失败,杀掉外壳进程   
            TerminateProcess(res, 0);   
            CloseHandle(Thrd);   
            CloseHandle(res);   
            res = INVALID_HANDLE_VALUE;   
        }   
    }   
    delete[] s;   
    return res;   
}   
Esempio n. 10
0
void CModuleControl::Create(HWND hParent, RECT& rect)
{
  CWindowImpl<CModuleControl>::Create(hParent, rect);

  RECT captionRect = { 0, 0, CAPTION_WIDTH, GetCaptionHeight() };
  MapDialogRect(hParent, &captionRect);
  m_hCaption.Create(TEXT("STATIC"), *this, captionRect, m_strCaption.c_str(), WS_CHILD | WS_VISIBLE);

  RECT childRect = { CAPTION_WIDTH, 0, CAPTION_WIDTH + CHILD_WIDTH, GetChildHeight() };
  MapDialogRect(hParent, &childRect);
  CreateChild(*this, childRect);
};
Esempio n. 11
0
/* Looks at all the particles of the parent box and distributes them amongst
   the children. If the child does not exist, one is created. */
void
SubdivideBox (long my_id, box *b)
{
   particle *p;
   box *child;
   long i;

   for (i = 0; i < b->num_particles; i++) {
      p = b->particles[i];
      if (p->pos.y > b->y_center) {
	 if (p->pos.x > b->x_center) {
	    child = b->children[0];
	    if (child == NULL)
	       child = CreateChild(my_id, b, 0);
	 }
	 else {
	    child = b->children[1];
	    if (child == NULL)
	       child = CreateChild(my_id, b, 1);
	 }
      }
      else {
	 if (p->pos.x > b->x_center) {
	    child = b->children[3];
	    if (child == NULL)
	       child = CreateChild(my_id, b, 3);
	 }
	 else {
	    child = b->children[2];
	    if (child == NULL)
	       child = CreateChild(my_id, b, 2);
	 }
      }
      child->particles[child->num_particles++] = p;
      b->particles[i] = NULL;
   }
   b->num_particles = 0;
   b->type = PARENT;
}
Esempio n. 12
0
bool XMLElement::SetStringVector(const StringVector& value)
{
    if (!RemoveChildren("string"))
        return false;

    for (auto i = value.begin(); i != value.end(); ++i)
    {
        XMLElement stringElem = CreateChild("string");
        if (!stringElem)
            return false;
        stringElem.SetAttribute("value", *i);
    }

    return true;
}
Esempio n. 13
0
bool XMLElement::SetVariantMap(const VariantMap& value)
{
    if (!RemoveChildren("variant"))
        return false;

    for (auto i = value.begin(); i != value.end(); ++i)
    {
        XMLElement variantElem = CreateChild("variant");
        if (!variantElem)
            return false;
        variantElem.SetUInt("hash", i->first.Value());
        variantElem.SetVariant(i->second);
    }

    return true;
}
Esempio n. 14
0
bool XMLElement::SetVariantMap(const VariantMap& value)
{
    if (!RemoveChildren("variant"))
        return false;

    for (VariantMap::ConstIterator i = value.Begin(); i != value.End(); ++i)
    {
        XMLElement variantElem = CreateChild("variant");
        if (!variantElem)
            return false;
        variantElem.SetInt("hash", i->first_.Value());
        variantElem.SetVariant(i->second_);
    }

    return true;
}
Esempio n. 15
0
bool XMLElement::SetVariantVector(const VariantVector& value)
{
    // Must remove all existing variant child elements (if they exist) to not cause confusion
    if (!RemoveChildren("variant"))
        return false;

    for (auto i = value.begin(); i != value.end(); ++i)
    {
        XMLElement variantElem = CreateChild("variant");
        if (!variantElem)
            return false;
        variantElem.SetVariant(*i);
    }

    return true;
}
Esempio n. 16
0
void	quadsquare::EnableChild(int index, const quadcornerdata& cd)
// Enable the indexed child node.  { ne, nw, sw, se }
// Causes dependent edge vertices to be enabled.
{
//	if (Enabled[index + 4] == false) {
    if ((EnabledFlags & (16 << index)) == 0) {
//		Enabled[index + 4] = true;
	EnabledFlags |= (16 << index);
	EnableEdgeVertex(index, true, cd);
	EnableEdgeVertex((index + 1) & 3, true, cd);
		
	if (Child[index] == 0) {
	    CreateChild(index, cd);
	}
    }
}
Esempio n. 17
0
bool Node::LoadXML(const XMLElement& source, SceneResolver& resolver, bool readChildren, bool rewriteIDs, CreateMode mode)
{
    // Remove all children and components first in case this is not a fresh load
    RemoveAllChildren();
    RemoveAllComponents();
    
    if (!Serializable::LoadXML(source))
        return false;
    
    XMLElement compElem = source.GetChild("component");
    while (compElem)
    {
        String typeName = compElem.GetAttribute("type");
        unsigned compID = compElem.GetInt("id");
        Component* newComponent = CreateComponent(ShortStringHash(typeName),
            (mode == REPLICATED && compID < FIRST_LOCAL_ID) ? REPLICATED : LOCAL, rewriteIDs ? 0 : compID);
        if (newComponent)
        {
            resolver.AddComponent(compID, newComponent);
            if (!newComponent->LoadXML(compElem))
                return false;
        }
        
        compElem = compElem.GetNext("component");
    }
    
    if (!readChildren)
        return true;
    
    XMLElement childElem = source.GetChild("node");
    while (childElem)
    {
        unsigned nodeID = childElem.GetInt("id");
        Node* newNode = CreateChild(rewriteIDs ? 0 : nodeID, (mode == REPLICATED && nodeID < FIRST_LOCAL_ID) ? REPLICATED :
            LOCAL);
        resolver.AddNode(nodeID, newNode);
        if (!newNode->LoadXML(childElem, resolver, readChildren, rewriteIDs, mode))
            return false;
        
        childElem = childElem.GetNext("node");
    }
    
    return true;
}
Esempio n. 18
0
		HRESULT XMLHelper::SetChildText(MSXML2::IXMLDOMNode *pNode, const TCHAR *pChild, const TCHAR *pText)
		{
			BSTR xpath = SysAllocString(pChild);
			MSXML2::IXMLDOMNode *pChildNode = 0;
			HRESULT hr = pNode->selectSingleNode(xpath, &pChildNode);
			SysFreeString(xpath);
			if(hr == S_OK && pChildNode) //replace existing text
			{
				BSTR text = SysAllocString(pText);
				hr = pChildNode->put_text(text);
				SysFreeString(text);
			}
			else if(hr == S_FALSE)  //if there is no node make a new one
			{
				hr = CreateChild(pNode, &pChildNode, pChild, pText);
				if(pChildNode)pChildNode->Release();
			}
			return hr;
		}
Esempio n. 19
0
bool Node::Load(Deserializer& source, SceneResolver& resolver, bool readChildren, bool rewriteIDs, CreateMode mode)
{
    // Remove all children and components first in case this is not a fresh load
    RemoveAllChildren();
    RemoveAllComponents();
    
    // ID has been read at the parent level
    if (!Serializable::Load(source))
        return false;
    
    unsigned numComponents = source.ReadVLE();
    for (unsigned i = 0; i < numComponents; ++i)
    {
        VectorBuffer compBuffer(source, source.ReadVLE());
        ShortStringHash compType = compBuffer.ReadShortStringHash();
        unsigned compID = compBuffer.ReadUInt();
        Component* newComponent = CreateComponent(compType,
            (mode == REPLICATED && compID < FIRST_LOCAL_ID) ? REPLICATED : LOCAL, rewriteIDs ? 0 : compID);
        if (newComponent)
        {
            resolver.AddComponent(compID, newComponent);
            if (!newComponent->Load(compBuffer))
                return false;
        }
    }
    
    if (!readChildren)
        return true;
    
    unsigned numChildren = source.ReadVLE();
    for (unsigned i = 0; i < numChildren; ++i)
    {
        unsigned nodeID = source.ReadUInt();
        Node* newNode = CreateChild(rewriteIDs ? 0 : nodeID, (mode == REPLICATED && nodeID < FIRST_LOCAL_ID) ? REPLICATED :
            LOCAL);
        resolver.AddNode(nodeID, newNode);
        if (!newNode->Load(source, resolver, readChildren, rewriteIDs, mode))
            return false;
    }
    
    return true;
}
Esempio n. 20
0
        // Called when the state needs to load itself
        void GameState::Load()
        {
            auto cache = GetSubsystem<Urho3D::ResourceCache>();
            
            // Setup Scene
            _scene = new Urho3D::Scene(context_);
            
            // Add Scene components
            _scene->CreateComponent<Urho3D::Octree>();
			_scene->CreateComponent<Urho3D::DebugRenderer>();
			_scene->CreateComponent<Urho3D::PhysicsWorld>();
            
            // Add custom Scene components
            auto saveData = _scene->CreateComponent<SaveData>();
            auto dungeon = _scene->CreateComponent<Dungeon>();
            auto playerInterface = _scene->CreateComponent<PlayerInterface>();
            
            // Create Character
            auto characterNode = _scene->CreateChild("Character");
            characterNode->SetPosition(Urho3D::Vector3(0.f, 1.f, 0.f));
            characterNode->SetScale(Urho3D::Vector3(.45f, .85f, .45f));
            
            auto character = characterNode->CreateComponent<Character>();
            auto characterModel = characterNode->CreateComponent<Urho3D::StaticModel>();
            characterModel->SetModel(cache->GetResource<Urho3D::Model>("Models/Sphere.mdl"));
            characterModel->SetMaterial(cache->GetResource<Urho3D::Material>("Materials/Stone.xml"));
            
            // Attach spotlight node to Character
            auto lightNode = characterNode->CreateChild("Character");
            lightNode->SetPosition(Urho3D::Vector3(0.f, 10.f, -10.f));
            lightNode->LookAt(Urho3D::Vector3(0, 0, 0));
            
            // Create directional light
            auto light = lightNode->CreateComponent<Urho3D::Light>();
            light->SetLightType(Urho3D::LIGHT_DIRECTIONAL);
            
        }
Esempio n. 21
0
SceneNode* SceneNode::CreateChildSceneNode( const String& name, const float3& translate, const Quaternionf& rotate )
{
	return static_cast<SceneNode*>( CreateChild(name, translate, rotate) );
}
Esempio n. 22
0
void gui::FsTreeMenuTree::OnCreateSymLinkTriggered()
{
	CreateChild(tr("New symlink"), tr("Create symbolic link"), dbc::ElementTypeSymLink);
}
Esempio n. 23
0
XMLElement XMLElement::CreateChild(const String& name)
{
    return CreateChild(name.CString());
}
Esempio n. 24
0
void gui::FsTreeMenuTree::OnCreateDirectLinkTriggered()
{
	CreateChild(tr("New direct link"), tr("Create direct link"), dbc::ElementTypeDirectLink);
}
EAbcResult CAbcOPolyMesh::CreateFaceSet( IAbcOFaceSet** out_ppOFaceSet, const char* in_pszName )
{
	return CreateChild( (IAbcOObject**)out_ppOFaceSet, EOObject_FaceSet, in_pszName );
}
Esempio n. 26
0
void gui::FsTreeMenuTree::OnCreateFolderTriggered()
{
	CreateChild(tr("New folder"), tr("Create folder"), dbc::ElementTypeFolder);
}
Esempio n. 27
0
int main()
{
  //int createChild = 1;
  char cwd[1024];
  int status;

  printf("Flooder program starting\n");

  while(1)
  {
    // Check the listen directory for a file
    printf("Checking for files...\n");
    int isEmpty =  IsDirectoryEmpty(LISTEN_DIR);
    if (isEmpty)
      printf("Directory 'listen' is empty\n");
    else
      printf("Directory 'listen' is not empty\n");

    // Process any files found in 'listen' directory
    if (!isEmpty)
    {
      // Change to the listen directory
      if (strcmp(getcwd(cwd, sizeof(cwd)), LISTEN_DIR) != 0)
      {
        if (chdir(LISTEN_DIR) != 0)
          perror("Error changing to listening directory\n");
      }

      switch(GetFile())
      {
        case 1:
          printf("...found 'start' file...\n");
          // Parse the file
          flooder f = ParseStartFile(); 

          // Delete the file 
          if (remove(START_FILE) != 0)
            perror("Error deleting 'start' file\n");

          //CreateChild();
          CreateChild(f);
          waitpid(-1, &status, WNOHANG);
          break;

        case 2:
          printf("...found 'stop' file...\n");
          // Delete the file 
          if (remove(STOP_FILE) != 0)
            perror("Error deleting 'stop' file\n");
          break;
          printf("Killing child pid %d\n", getpid());
          if (KillChildPid(getpid()) == 0)
            printf("Child pid successfully killed\n");
          else
            printf("Error killing child pid\n");
          break;

        default:
          printf("...found unknown file...\n");
          // Delete the file 
          if (remove(UNKNOWN_FILE) != 0)
            perror("Error deleting unknown file\n");
          break;
      }
    }

    sleep(5); 

  }

  exit(0);
}
Esempio n. 28
0
Node* Node::CreateChild(const String& name, CreateMode mode)
{
    Node* newNode = CreateChild(0, mode);
    newNode->SetName(name);
    return newNode;
}
Esempio n. 29
0
XMLElement XMLElement::CreateChild(const ea::string& name)
{
    return CreateChild(name.c_str());
}
Esempio n. 30
0
void gui::FsTreeMenuTree::OnCreateFileTriggered()
{
	CreateChild(tr("New file"), tr("Create file"), dbc::ElementTypeFile);
}