/// <summary> /// generic signature to be called in getData of syncables /// meant to pass specific balancing data on object generation /// DO NOT MANAGE idcard /// </summary> static public NwkSyncableData createData(this iNwkPack instance, float syncTime, short PID = -1) { NwkSyncableData data = new NwkSyncableData(instance, syncTime); data.idCard.syncPID = PID; return(data); }
/// <summary> /// bridge when receiving new message /// </summary> public void applyMessage(NwkMessageFull msg) { string header = msg.header.getHeader(); string[] split = header.Split(MSG_HEADER_SPEARATOR); // IID , CONN ID ? short iid = short.Parse(split[0]); NwkSyncableData data = getDataByIID(iid); if (data == null) { Debug.LogWarning("no sync data found for msg " + header); short oType = short.Parse(split[1]); data = solveUnknownData(msg.getIdCard().getMessageSender(), iid, oType); if (data == null) { log("don't have object " + msg.header.getHeader() + " sent by : " + msg.getIdCard().getMessageSender()); } } //must have data here ? if (data == null) { Debug.LogError("no data, must have some here"); return; } data.unpackMessage(msg); // tell object to treat inc data }
public NwkSyncableData sub(iNwkSync sync) { if (hasBroad(sync)) { Debug.LogError("already has that sync ? " + sync); return(null); } // at this point the generated IID is not final, it can be overritten just after sub (if copy) NwkSyncableData data = sync.getData(); if (data != null) { broadcasters.Add(data); //on sub l'objet que si c'est un objet local if (data.syncNwkClientUID == NwkClient.nwkUid) { frequencers.Add(data); } Debug.Log("sub '" + sync + "' to syncer"); } else { Debug.LogWarning(sync + " was not sub to syncer ?"); } return(data); }
public NwkSyncableData getData() { if (syncData == null) { syncData = new NwkSyncableData(this, 1f); // mod controller } return(syncData); }
void solveStack() { for (int i = 0; i < frequencers.Count; i++) { //NwkSyncableData data = syncs[i].getData(); NwkSyncableData data = frequencers[i]; //check if timer reached target (and is rebooted) if (data.updateFreqTimer(Time.deltaTime)) { stack.Add(data.packMessage()); data.resetFreqTimer(); } //else Debug.Log(data.handle+" => "+data.getRemainingTime()); } }
/// <summary> /// basic message for sync /// </summary> static public NwkMessageFull nwkSyncInject(NwkSyncableData syncData) { NwkMessageFull msg = new NwkMessageFull(); msg.getIdCard().setupId(NwkClient.nwkUid, (int)eNwkMessageType.SYNC); //header is body of message (not sender uid) string header = syncData.idCard.syncIID.ToString(); header += "-" + syncData.idCard.syncPID; msg.header.setupHeader(header); msg.bytes.setByteData(syncData.handle.pack()); return(msg); }
NwkSyncableData getDataByIID(short iid) { NwkSyncableData data = null; for (int i = 0; i < broadcasters.Count; i++) { if (broadcasters[i] == null) { Debug.LogError(i + " is null (count ? " + broadcasters.Count + ") ? iid " + iid); } //if (syncs[i].idCard == null) Debug.LogError("no id card ?"); if (broadcasters[i].idCard.syncIID == iid) { data = broadcasters[i]; } } return(data); }
protected NwkSyncableData solveUnknownData(int cUID, int oIID, int oPID) { GameObject copy = factoryDb.copy(oPID); if (copy == null) { Debug.LogWarning("no copy possible with PID : " + oPID); return(null); } copy.name += oIID.ToString(); Debug.Log(Time.frameCount + " => copy ? " + copy); //find ref of component of that sync in newly created object NwkSyncableData curSyncData = null; iNwkSync sync = filterSyncableOnInstance(copy, factoryDb.items[oPID].type); if (sync == null) { Debug.LogError("no sync found in copy ?"); return(null); } //forcing object to generate it's data curSyncData = sync.getData(); //but won't have owner info yet, so we need to inject id info here //inject none-local stuff curSyncData.overrideData(cUID, oIID, oPID); Debug.Log(Time.frameCount + " => data ? " + curSyncData); bubbleSyncableToListeners(copy, sync); return(curSyncData); }