bool CEditorCondition::Serialize(CArchive &ar, CChronoEventEditor* Ed) { CString ExpectedName = "CEditorCondition"; int Version = 2; if (!SerializeClassHeader(ExpectedName, Version, ar)) return false; if( ar.IsLoading()) { m_visible = true; m_Valid = true; ar >> mid; ar >> cndID; ar >> oid; if(Ed) Ed->RegisterObjectID(oid, ar); ar >> m_Negate; ar >> m_Family >> m_FamilyName; ar >> m_rect_default; ar >> m_select_default; ar >> m_select_default; ar >> m_Anim.Space; ar // //m_Text - note: must call EventSheetEditor::ReformatCondition >> m_Object >> m_Script; m_Anim.m_bDestroyed = false; m_Text = ""; int size = 0; ar >> size; for (int i = 0; i < size; i++) { CEditorParam* Param = new CEditorParam; Param->Serialize(ar, Ed); params.push_back(Param); } if (oid != -1) { CString name = ""; ar >> name; OINFO* o = GetOINFO(name); if (!o) { CErrorDlg Dlg; Dlg.Error("Error in condition.", "An invalid object in a condition was referenced."); return false; } DLLIndex = o->oID; }
bool CAnimation::Serialize(CArchive& Archive) { CString ExpectedName = "CAnimation"; int Version = 3; if (!SerializeClassHeader(ExpectedName, Version, Archive)) return false; if(Archive.IsLoading()) { Archive >> m_FixedID >> m_Name; if(Version >= 3) Archive >> m_Speed; else {
bool CEditorAction::Serialize(CArchive &ar, CChronoEventEditor* Ed ) { CString ExpectedName = "CEditorAction"; int Version = 2; if (!SerializeClassHeader(ExpectedName, Version, ar)) return false; if(ar.IsLoading()) { m_visible = true; m_Valid = true; ar >> m_Family >> m_FamilyName; ar >> actID; ar >> oid; if(Ed) Ed->RegisterObjectID(oid, ar); ar >> m_rect_default; ar >> m_select_default; ar >> m_Anim.Space; m_Anim.m_bDestroyed = false; ar //>> m_Text - note: must call EventSheetEditor::ReformatAction >> m_Object >> m_Script; ar >> mid; m_Text = ""; int size = 0; ar >> size; for (int i = 0; i < size; i++) { CEditorParam* Param = new CEditorParam; Param->Serialize(ar, Ed); params.push_back(Param); } CString name = ""; ar >> name; OINFO* o = GetOINFO(name); if(o) DLLIndex = o->oID; else DLLIndex = -1; if(Version >= 2) ar >> m_bEnabled; else
void DistributedNetworkObject::DestroyObjectOnNetwork( void ) { // These 3 lines of code will broadcast to destroy the object RakNet::BitStream bitStream; SerializeClassHeader( &bitStream, 0, 0, false, 0 ); BroadcastSerializedClass( &bitStream, UNASSIGNED_PLAYER_ID ); DistributedNetworkObjectManager::Instance()->UnregisterNetworkObject( this ); // OnDistributedObjectDestruction gets called on the clients from the broadcast. On the server we have to call it directly. if ( DistributedNetworkObjectManager::Instance()->GetRakServerInterface() ) { OnDistributedObjectDestruction( UNASSIGNED_PLAYER_ID ); return; } }
DistributedNetworkObject::~DistributedNetworkObject() { int heapNodeIndex; if ( DistributedNetworkObjectManager::Instance()->GetRakServerInterface() ) { // These 3 lines of code will broadcast to destroy the object RakNet::BitStream bitStream; SerializeClassHeader( &bitStream, 0, 0, false, 0 ); BroadcastSerializedClass( &bitStream, UNASSIGNED_PLAYER_ID ); } DistributedNetworkObjectManager::Instance()->UnregisterNetworkObject( this ); for ( heapNodeIndex = 0; heapNodeIndex < 256; heapNodeIndex++ ) { if ( heapNodeList[ heapNodeIndex ].lastWriteValue ) { delete [] heapNodeList[ heapNodeIndex ].lastWriteValue; heapNodeList[ heapNodeIndex ].lastWriteValue = 0; } } }
bool CLayout::Serialize(CArchive& ar) { CString ExpectedName = "CLayout"; int Version = 5; if (!SerializeClassHeader(ExpectedName, Version, ar)) return false; g_pFrame = this; if(ar.IsLoading()) { ar >> identifier >> m_w >> m_h >> m_Name >> m_clr >> m_unboundedScrolling >> application_background; m_ObjectFrameIsLockedTo = 0; m_oTemporyBehaviorInfo=0; // used inbetwen creation of tempory Behaviors for modifying properties - I use it so if an edittime function is called, we can work out from what object it is if the identifier is -1 m_pTempMovExt=0; // used inbetwen creation of tempory Behaviors for modifying properties - I use it so if an edittime function is called, we can work out from what object it is if the identifier is -1 m_oControlBehaviorInfo=0; // If you tell a Behavior to be in control of the frame editor this is used m_pControlBehaviorExt=0;// If you tell a Behavior to be in control of the frame editor this is used m_pControlBehaviorData=0; // If you tell a Behavior to be in control of the frame editor, this is used to serialize to once unlocked. m_pControlBehaviorDataSize=0; m_ParentObjectFrameIsLockedTo=0; objects.RemoveAll(); long objCnt; ar >> objCnt; CObj *o; int i; for (i = 0; i < objCnt; i++) { long nKey; ar >> nKey; o = new CObj(); if (!o->Serialize(ar)) return false; objects.SetAt(nKey, o); } ar >> objCnt; CLayer *layer; for (i = 0; i < objCnt; i++) { layer = new CLayer("", LAYER_NORMAL); if (!layer->Serialize(ar)) return false; layers.AddTail(layer); if (i == 1) current_layer = layer; } if (Version < 4) { // add non-layout layer if one doesn't exist if (layers.GetHead()->m_layerType != LAYER_NONFRAME) { CString layer_name; layer_name.Format("Non-layout"); CLayer* nonlayout_layer = new CLayer(layer_name, LAYER_NONFRAME); nonlayout_layer->m_state = LAYSTATE_HIDDEN; nonlayout_layer->m_layerID = application->m_layerID++; layers.AddHead(nonlayout_layer); } } ar >> temporary_event_sheet_id; // This changed in v2; make sure the function knows if (Version >= 2) layoutKeys.Serialize(ar, true); else layoutKeys.Serialize(ar, false); // V3: save grid details if (Version >= 3) { ar >> m_Grid >> m_SnapMovements >> m_SnapResize >> m_GridWidth >> m_GridHeight; }
void CEditorParam::Serialize( CArchive& ar, CChronoEventEditor* Ed) { CString ExpectedName = "CEditorParam"; int Version = 1; if (!SerializeClassHeader(ExpectedName, Version, ar)) return; if(!ar.IsLoading()) { valid = true; ar << m_type; ar << m_reserved; ar << oid; int size = ttokens.size(); ar << size; for( int a = 0; a < size; a ++ ) { ar << (int)ttokens[a].t; ar << ttokens[a].length; ar << ttokens[a].oidOwner; ar << ttokens[a].str; ar << ttokens[a].id; ar << (int)ttokens[a].tsub; if(Ed) { int oid = ttokens[a].oidOwner; Ed->RegisterObjectID(oid, ar); } } if(m_type == EDITORPARAM_OBJECT && ttokens.size() == 1) { if(ttokens[0].t == T_INTEGER) { int oid = ttokens[0].id; if(Ed) { Ed->RegisterObjectID(oid, ar); } } } } else { ar >> m_type; ar >> m_reserved; ar >> oid; ttokens.clear(); int size = 0; ar >> size; for( int a = 0; a < size; a ++ ) { int temp; ttokens.push_back(Token()); Token& tok = ttokens.back(); ar >> temp; tok.t = (ExpToken)temp; ar >> tok.length; ar >> tok.oidOwner; ar >> tok.str; ar >> tok.id; ar >> temp; tok.tsub = (TokenSubType)temp; if(Ed) { int oid = tok.oidOwner; Ed->RegisterObjectID(oid, ar); tok.oidOwner = oid; // Identifier tokens also seem to use oidOwner so i think its fine } } // Okay special exception...if m_type is object // and its a single token we can assume its the object selector param, and so that means we need to translate it // incase we are dragging between applications if(m_type == EDITORPARAM_OBJECT && ttokens.size() == 1) { if(ttokens[0].t == T_INTEGER) { int oid = ttokens[0].id; if(Ed) { Ed->RegisterObjectID(oid, ar); ttokens[0].id = oid; ttokens[0].str.Format("%d", oid); ttokens[0].length = ttokens[0].str.GetLength(); } } } } }
// This function cannot go in the constructor because the vtable won't be setup to call GetClassName void DistributedNetworkObject::UpdateDistributedObject( char *classID, bool isClassIDEncoded ) { bool serverProcess; bool dataWritten1, dataWritten2; if ( DistributedNetworkObjectManager::Instance()->GetRakServerInterface() && DistributedNetworkObjectManager::Instance()->GetRakServerInterface()->IsActive() ) serverProcess = true; else serverProcess = false; if ( ( DistributedNetworkObjectManager::Instance()->GetRakServerInterface() && DistributedNetworkObjectManager::Instance()->GetRakServerInterface()->IsActive() ) || ( DistributedNetworkObjectManager::Instance()->GetRakClientInterface() && DistributedNetworkObjectManager::Instance()->GetRakClientInterface()->IsConnected() ) ) { char classIdentifier[ MAXIMUM_CLASS_IDENTIFIER_LENGTH ]; RakNet::BitStream bitStream; if ( isClassIDEncoded ) memcpy( classIdentifier, classID, MAXIMUM_CLASS_IDENTIFIER_LENGTH ); else EncodeClassName( classID, classIdentifier ); bool firstTimeAddedToRegistry; // The only purpose of registering and unregistering network objects is so we can call SendAllDistributedObjects from // DistributedNetworkObjectManager to new players firstTimeAddedToRegistry = DistributedNetworkObjectManager::Instance()->RegisterNetworkObject( this, classIdentifier, localObjectIdentifier ); if ( serverProcess && firstTimeAddedToRegistry && isClassIDEncoded == false ) { // This is like a local echo - call OnDistributedObjectCreation for the server when it is not // created by the network if ( OnDistributedObjectCreation( UNASSIGNED_PLAYER_ID ) == false ) { DistributedNetworkObjectManager::Instance()->UnregisterNetworkObject( this ); return ; } } // This logic is correct - ProcessDistributedMemoryStack has a side effect of updating network memory to the last send so you don't // want to call it unnecessarily if ( firstTimeAddedToRegistry && ( localObject || DistributedNetworkObjectManager::Instance()->GetRakServerInterface() ) ) { SerializeClassHeader( &bitStream, classIdentifier, 2, firstTimeAddedToRegistry && DistributedNetworkObjectManager::Instance()->GetRakClientInterface(), localObjectIdentifier ); ProcessDistributedMemoryStack( &bitStream, true, true, serverProcess ); WriteToBitstreamFromHeap( &bitStream, true ); WriteCreationData( &bitStream ); BroadcastSerializedClass( &bitStream, UNASSIGNED_PLAYER_ID ); } else if ( ( localObject == false || DistributedNetworkObjectManager::Instance()->GetRakServerInterface() ) && RakNet::GetTime() > lastBroadcastTime + maximumUpdateFrequency ) { SerializeClassHeader( &bitStream, classIdentifier, 1, firstTimeAddedToRegistry && DistributedNetworkObjectManager::Instance()->GetRakClientInterface(), localObjectIdentifier ); dataWritten1 = ProcessDistributedMemoryStack( &bitStream, true, false, serverProcess ); dataWritten2 = WriteToBitstreamFromHeap( &bitStream, false ); if ( dataWritten1 || dataWritten2 ) { BroadcastSerializedClass( &bitStream, UNASSIGNED_PLAYER_ID ); } } } InterpolateDistributedMemory( serverProcess ); }