Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * Tehadon - Game Engine
- * Copyright (c) T-Team / Benedikt Eggers
- * Version 3.0 / August 2011
- * C++ / Try
- *
- */
- // ====================================================================
- // Includes
- #include "RegionComponent.h"
- // ====================================================================
- namespace TGE
- {
- namespace Gfx
- {
- // ====================================================================
- // Constructor
- RegionComponent::RegionComponent()
- {
- myBasicMapComponentList = new std::vector<BasicMapComponent*>();
- SetPosition(new Vector3());
- SetMapComponentStatus(MapComponentStatus::COMPONENT_UNLOADED);
- }
- // ====================================================================
- // ====================================================================
- /// Destructor
- RegionComponent::~RegionComponent()
- {
- delete myBasicMapComponentList;
- }
- // ====================================================================
- // ====================================================================
- // Load all properties
- void RegionComponent::LoadProperties(TiXmlNode* Node, unsigned int Indent)
- {
- //Check if the Parent really exist
- if(!Node)
- {
- return;
- }
- //
- TiXmlNode* cChild;
- TiXmlText* cText;
- int ElementType = Node->Type();
- std::string cName;
- cName = "";
- //Switch throught all types
- switch(ElementType)
- {
- case TiXmlNode::NodeType::TINYXML_DOCUMENT:
- //printf( "Document" );
- break;
- case TiXmlNode::NodeType::TINYXML_ELEMENT:
- cName = Node->Value();
- LoadAttributes(Node->ToElement(), cName, Indent + 1);
- break;
- case TiXmlNode::NodeType::TINYXML_COMMENT:
- //printf( "Unknown" );
- break;
- case TiXmlNode::NodeType::TINYXML_UNKNOWN:
- //cText = Parent->ToText();
- //printf( "Text: [%s]", cText->Value() );
- break;
- case TiXmlNode::NodeType::TINYXML_TEXT:
- break;
- case TiXmlNode::NodeType::TINYXML_DECLARATION:
- //printf( "Declaration" );
- break;
- default:
- break;
- }
- // Call all childs
- for ( cChild = Node->FirstChild(); cChild != 0; cChild = cChild->NextSibling())
- {
- LoadProperties( cChild, Indent + 1 );
- }
- }
- // Load attribute
- void RegionComponent::LoadAttributes(TiXmlElement* Element, std::string Name, unsigned int Indent)
- {
- // Check if there are any Attributes
- if(!Element)
- {
- return;
- }
- TiXmlAttribute* cAttribute = Element->FirstAttribute();
- //Iterate thrwought all attributes
- while(cAttribute)
- {
- std::string cName = cAttribute->Name();
- std::string cValue = cAttribute->Value();
- //Read the Settings
- if(Name == "Kind")
- {
- if(cName == "value")
- {
- myKind = cValue;
- }
- }
- else if(Name == "Name")
- {
- if(cName == "value")
- {
- SetName(cValue);
- }
- }
- else if(Name == "ID")
- {
- if(cName == "value")
- {
- SetID(atoi(cValue.c_str()));
- }
- }
- else if(Name == "Radius")
- {
- if(cName == "value")
- {
- myRadius = atof(cValue.c_str());
- }
- }
- else if(Name == "Position")
- {
- if(cName == "x")
- {
- Vector3* cVector = GetPosition();
- cVector->x = atof(cValue.c_str());
- }
- if(cName == "y")
- {
- Vector3* cVector = GetPosition();
- cVector->y = atof(cValue.c_str());
- }
- if(cName == "z")
- {
- Vector3* cVector = GetPosition();
- cVector->z = atof(cValue.c_str());
- SetPosition(cVector);
- }
- }
- //Get next attrubute
- cAttribute = cAttribute->Next();
- }
- }
- // ====================================================================
- // ====================================================================
- // Update-Queue-Commands
- void RegionComponent::Update(Vector3* SourcePosition)
- {
- //If Regionkind = simpleradius
- if(myKind == "simpleradius")
- {
- //Calculate distance
- float cDistance = ((*SourcePosition) - (*GetPosition())).length();
- cDistance < 0 ? -cDistance : cDistance;
- if(cDistance <= myRadius)
- {
- //If it isn't loaded, then load the Region
- if(GetMapComponentStatus() == MapComponentStatus::COMPONENT_UNLOADED)
- {
- //Load the Region
- SetMapComponentStatus(MapComponentStatus::COMPONENT_LOADING);
- Load();
- }
- }
- else
- {
- //Load the Region
- SetMapComponentStatus(MapComponentStatus::COMPONENT_UNLOADING);
- UnLoad();
- }
- }
- }
- void RegionComponent::Load()
- {
- std::vector<BasicMapComponent*>::iterator itr;
- for ( itr = myBasicMapComponentList->begin(); itr < myBasicMapComponentList->end(); ++itr )
- {
- //Load Sub-Component
- (*itr)->SetMapComponentStatus(MapComponentStatus::COMPONENT_LOADING);
- (*itr)->Load();
- }
- //Loading completet
- SetMapComponentStatus(MapComponentStatus::COMPONENT_LOADED);
- }
- void RegionComponent::UnLoad()
- {
- std::vector<BasicMapComponent*>::iterator itr;
- for ( itr = myBasicMapComponentList->begin(); itr < myBasicMapComponentList->end(); ++itr )
- {
- //Load Sub-Component
- (*itr)->SetMapComponentStatus(MapComponentStatus::COMPONENT_UNLOADING);
- (*itr)->UnLoad();
- }
- //UnLoading completet
- SetMapComponentStatus(MapComponentStatus::COMPONENT_LOADED);
- }
- // ====================================================================
- }
- }
Add Comment
Please, Sign In to add comment