void SimDataBlockEvent::unpack(NetConnection *cptr, BitStream *bstream) { if(bstream->readFlag()) { mProcess = true; id = bstream->readInt(DataBlockObjectIdBitSize) + DataBlockObjectIdFirst; S32 classId = bstream->readClassId(NetClassTypeDataBlock, cptr->getNetClassGroup()); mIndex = bstream->readInt(DataBlockObjectIdBitSize); mTotal = bstream->readInt(DataBlockObjectIdBitSize + 1); SimObject* ptr; if( Sim::findObject( id, ptr ) ) { // An object with the given ID already exists. Make sure it has the right class. AbstractClassRep* classRep = AbstractClassRep::findClassRep( cptr->getNetClassGroup(), NetClassTypeDataBlock, classId ); if( classRep && dStrcmp( classRep->getClassName(), ptr->getClassName() ) != 0 ) { Con::warnf( "A '%s' datablock with id: %d already existed. " "Clobbering it with new '%s' datablock from server.", ptr->getClassName(), id, classRep->getClassName() ); ptr->deleteObject(); ptr = NULL; } } if( !ptr ) ptr = ( SimObject* ) ConsoleObject::create( cptr->getNetClassGroup(), NetClassTypeDataBlock, classId ); mObj = dynamic_cast< SimDataBlock* >( ptr ); if( mObj != NULL ) { #ifdef DEBUG_SPEW Con::printf(" - SimDataBlockEvent: unpacking event of type: %s", mObj->getClassName()); #endif mObj->unpackData( bstream ); } else { #ifdef DEBUG_SPEW Con::printf(" - SimDataBlockEvent: INVALID PACKET! Could not create class with classID: %d", classId); #endif delete ptr; cptr->setLastError("Invalid packet in SimDataBlockEvent::unpack()"); } #ifdef TORQUE_DEBUG_NET U32 checksum = bstream->readInt(32); AssertISV( (checksum ^ DebugChecksum) == (U32)classId, avar("unpack did not match pack for event of class %s.", mObj->getClassName()) ); #endif } }
const char *SimDataBlockEvent::getDebugName() { SimObject *obj = Sim::findObject(id); static char buffer[256]; dSprintf(buffer, sizeof(buffer), "%s [%s - %s]", getClassName(), obj ? obj->getName() : "", obj ? obj->getClassName() : "NONE"); return buffer; }
char* SimTreeView::handleItemNameChange( HTREEITEM hItem, char *name ) { lockManager(); SimObject *obj = getObject( hItem ); if ( !obj ) return NULL; obj->assignName( name ); unlockManager(); return ( (char*)avar("%4i,\"%s\", %s",obj->getId(),obj->getName(),obj->getClassName()) ); }
void TamlBinaryReader::parseChildren( Stream& stream, TamlCallbacks* pCallbacks, SimObject* pSimObject, const U32 versionId ) { // Debug Profiling. PROFILE_SCOPE(TamlBinaryReader_ParseChildren); // Sanity! AssertFatal( pSimObject != NULL, "Taml: Cannot parse children on a NULL object." ); // Fetch children count. U32 childrenCount; stream.read( &childrenCount ); // Finish if no children. if ( childrenCount == 0 ) return; // Fetch the Taml children. TamlChildren* pChildren = dynamic_cast<TamlChildren*>( pSimObject ); // Is this a sim set? if ( pChildren == NULL ) { // No, so warn. Con::warnf("Taml: Child element found under parent but object cannot have children." ); return; } // Fetch any container child class specifier. AbstractClassRep* pContainerChildClass = pSimObject->getClassRep()->getContainerChildClass( true ); // Iterate children. for ( U32 index = 0; index < childrenCount; ++ index ) { // Parse child element. SimObject* pChildSimObject = parseElement( stream, versionId ); // Finish if child failed. if ( pChildSimObject == NULL ) return; // Do we have a container child class? if ( pContainerChildClass != NULL ) { // Yes, so is the child object the correctly derived type? if ( !pChildSimObject->getClassRep()->isClass( pContainerChildClass ) ) { // No, so warn. Con::warnf("Taml: Child element '%s' found under parent '%s' but object is restricted to children of type '%s'.", pChildSimObject->getClassName(), pSimObject->getClassName(), pContainerChildClass->getClassName() ); // NOTE: We can't delete the object as it may be referenced elsewhere! pChildSimObject = NULL; // Skip. continue; } } // Add child. pChildren->addTamlChild( pChildSimObject ); // Find Taml callbacks for child. TamlCallbacks* pChildCallbacks = dynamic_cast<TamlCallbacks*>( pChildSimObject ); // Do we have callbacks on the child? if ( pChildCallbacks != NULL ) { // Yes, so perform callback. mpTaml->tamlAddParent( pChildCallbacks, pSimObject ); } } }
void GuiInspectorDynamicField::renameField( const char* newFieldName ) { newFieldName = StringTable->insert( newFieldName ); if ( mDynField == NULL || mParent == NULL || mEdit == NULL ) { Con::warnf("GuiInspectorDynamicField::renameField - No target object or dynamic field data found!" ); return; } if ( !newFieldName ) { Con::warnf("GuiInspectorDynamicField::renameField - Invalid field name specified!" ); return; } // Only proceed if the name has changed if ( dStricmp( newFieldName, getFieldName() ) == 0 ) return; // Grab a pointer to our parent and cast it to GuiInspectorDynamicGroup GuiInspectorDynamicGroup *group = dynamic_cast<GuiInspectorDynamicGroup*>(mParent); if ( group == NULL ) { Con::warnf("GuiInspectorDynamicField::renameField - Unable to locate GuiInspectorDynamicGroup parent!" ); return; } const U32 numTargets = mInspector->getNumInspectObjects(); if( numTargets > 1 ) { mInspector->onBeginCompoundEdit_callback(); } const char* oldFieldName = getFieldName(); SimFieldDictionary::Entry* newEntry = NULL; for( U32 i = 0; i < numTargets; ++ i ) { SimObject* target = mInspector->getInspectObject( i ); // Make sure the new field is not already defined as a static field // on the object. if( target->isField( newFieldName ) ) { // New field is already defined. If we can, let the scripts handle // the error. Otherwise, just emit an error on the console and proceed. if( numTargets == 1 ) { mInspector->onFieldRenameAlreadyDefined_callback( target->getIdString(), oldFieldName, newFieldName ); } else { Con::errorf( "GuiInspectorDynamicField::renameField - field '%s' is already defined on %i:%s (%s)", newFieldName, target->getId(), target->getClassName(), target->getName() ); } // Reset the text entry. if( mRenameCtrl ) mRenameCtrl->setText( oldFieldName ); continue; } char currentValue[1024] = {0}; // Grab our current dynamic field value (we use a temporary buffer as this gets corrupted upon Con::eval) dSprintf( currentValue, sizeof( currentValue ), "%s", target->getDataField( oldFieldName, NULL ) ); // Unset the old field and set the new field. target->setDataField( oldFieldName, NULL, "" ); target->setDataField( newFieldName, NULL, currentValue ); // Notify script. mInspector->onFieldRenamed_callback( target->getIdString(), oldFieldName, newFieldName ); // Look up the new SimFieldDictionary entry. if( !newEntry ) { newEntry = target->getFieldDictionary()->findDynamicField( newFieldName ); if( !newEntry ) { Con::warnf( "GuiInspectorDynamicField::renameField - could not find new field '%s' on object %i:%s (%s)", newFieldName, target->getId(), target->getClassName(), target->getName() ); } mDynField = newEntry; } } if( numTargets > 1 ) { mInspector->onEndCompoundEdit_callback(); } // Lastly we need to reassign our validate field for our value edit control char szBuffer[1024]; dSprintf( szBuffer, sizeof( szBuffer ), "%d.apply(%d.getText());", getId(), mEdit->getId() ); mEdit->setField("validate", szBuffer ); if( mDeleteButton ) { dSprintf(szBuffer, sizeof( szBuffer ), "%d.apply("");%d.inspectGroup();", getId(), newFieldName, group->getId()); mDeleteButton->setField("Command", szBuffer); } }
void ProcessList::dumpToConsole() { for (ProcessObject * pobj = mHead.mProcessLink.next; pobj != &mHead; pobj = pobj->mProcessLink.next) { SimObject * obj = dynamic_cast<SimObject*>(pobj); if (obj) Con::printf("id %i, order guid %i, type %s", obj->getId(), pobj->mOrderGUID, obj->getClassName()); else Con::printf("---unknown object type, order guid %i", pobj->mOrderGUID); } }