Improved connecting
This commit is contained in:
		
							parent
							
								
									5ee5debf35
								
							
						
					
					
						commit
						6356769aa9
					
				
							
								
								
									
										27
									
								
								Sensor.cpp
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								Sensor.cpp
									
									
									
									
									
								
							| @ -14,20 +14,27 @@ void Sensor::SetParent(Thing *parent) { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void Sensor::ConnectTo(Thing *thing) { | ||||
|   this->name = thing->name; | ||||
|   this->id = thing->id; | ||||
| void Sensor::ConnectTo(Thing *oldThing) { | ||||
|   this->name = oldThing->name; | ||||
|   this->id = oldThing->id; | ||||
| 
 | ||||
|   Thing *thingParent = thing->GetParent(); | ||||
|   thingParent->RemoveChild(thing); | ||||
|   thingParent->AddChild(this); | ||||
|   this->children = thing->GetChildren(); | ||||
|   this->position = thing->position; | ||||
|   this->orientation = thing->orientation; | ||||
|   Thing *oldParent = oldThing->GetParent(); | ||||
| 
 | ||||
|   oldParent->RemoveChild(oldThing); | ||||
|   oldParent->AddChild(this); | ||||
| 
 | ||||
|   for (int childIx = 0; childIx < oldThing->childCount; childIx++) { | ||||
|     Thing *child = oldThing->GetChild(childIx); | ||||
|     this->AddChild(child); | ||||
|   } | ||||
| 
 | ||||
|   this->position = oldThing->position; | ||||
|   this->orientation = oldThing->orientation; | ||||
|   // delete (thing); // can we do this?
 | ||||
| } | ||||
| 
 | ||||
| void Sensor::ConnectTo(Thing *rootThing, const char *thingName) { | ||||
|   Thing *thing = rootThing->FindChild(thingName); | ||||
|   this->ConnectTo(thing); | ||||
|   if (thing != nullptr) | ||||
|     this->ConnectTo(thing); | ||||
| } | ||||
|  | ||||
| @ -65,12 +65,13 @@ void Thing::AddChild(Thing *child) { | ||||
|   this->childCount++; | ||||
| } | ||||
| 
 | ||||
| Thing *Passer::RoboidControl::Thing::RemoveChild(Thing *child) { | ||||
|   Thing **newChildren = new Thing *[this->childCount - 1]; | ||||
| Thing *Thing::RemoveChild(Thing *child) { | ||||
|   int newChildCount = this->childCount - 1; | ||||
|   Thing **newChildren = new Thing *[newChildCount]; | ||||
|   unsigned char newChildIx = 0; | ||||
|   for (unsigned char childIx = 0; childIx < this->childCount; childIx++) { | ||||
|     if (this->children[childIx] != child) { | ||||
|       if (newChildIx == this->childCount - 1) { // We did not find the child
 | ||||
|       if (newChildIx == newChildCount) { // We did not find the child
 | ||||
|         // stop copying and return nothing
 | ||||
|         delete[] newChildren; | ||||
|         return nullptr; | ||||
| @ -83,7 +84,7 @@ Thing *Passer::RoboidControl::Thing::RemoveChild(Thing *child) { | ||||
| 
 | ||||
|   delete[] this->children; | ||||
|   this->children = newChildren; | ||||
|   this->childCount--; | ||||
|   this->childCount = newChildCount; | ||||
| 
 | ||||
|   return child; | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pascal Serrarens
						Pascal Serrarens