private static void Serialize(TreeManager.Data data, DataSerializer s) { Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.BeginSerialize(s, "TreeManager"); TreeInstance[] mBuffer = Singleton<TreeManager>.instance.m_trees.m_buffer; int num = 262144; EncodedArray.UShort num1 = EncodedArray.UShort.BeginWrite(s); for (int i = 1; i < num; i++) { num1.Write(mBuffer[i].m_flags); } num1.EndWrite(); try { PrefabCollection<TreeInfo>.BeginSerialize(s); for (int j = 1; j < num; j++) { if (mBuffer[j].m_flags != 0) { PrefabCollection<TreeInfo>.Serialize(mBuffer[j].m_infoIndex); } } } finally { PrefabCollection<TreeInfo>.EndSerialize(s); } EncodedArray.Short num2 = EncodedArray.Short.BeginWrite(s); for (int k = 1; k < num; k++) { if (mBuffer[k].m_flags != 0) { num2.Write(mBuffer[k].m_posX); } } num2.EndWrite(); EncodedArray.Short num3 = EncodedArray.Short.BeginWrite(s); for (int l = 1; l < num; l++) { if (mBuffer[l].m_flags != 0) { num3.Write(mBuffer[l].m_posZ); } } num3.EndWrite(); Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.EndSerialize(s, "TreeManager"); }
/// <summary> /// Custom serialize call /// </summary> /// <param name="idxList"> ByRef to the List of ints representing tree indexes that should be serialised</param> /// <param name="s">ByRef to The DataSerializer object </param> internal static void Serialize(ref List <int> idxList, ref DataSerializer s) { //Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.BeginSerialize(s, "TreeManager"); if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { if (idxList == null) { Logger.dbgLog("idxlist is null. lastsaveusedpacking: " + LoadingExtension.LastSaveUsedPacking.ToString()); } else { Logger.dbgLog("idxlist count: " + idxList.Count + " lastsaveusedpacking: " + LoadingExtension.LastSaveUsedPacking.ToString()); } if (OptionsWrapper <Configuration> .Options.GhostModeEnabled) { Logger.dbgLog("Ghost Mode is activated!"); } } TreeInstance[] mBuffer = Singleton <TreeManager> .instance.m_trees.m_buffer; FastList <TreeManager.BurningTree> tmburning = Singleton <TreeManager> .instance.m_burningTrees; int num = Mod.DEFAULT_TREE_COUNT; //262144 //if (idxList != null && idxList.Count >= Mod.DEFAULT_TREE_COUNT) //custom one. if (idxList != null && idxList.Count > 1) //always use custom one unless problem. { if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Start using packer seralizer for first 262144 realones."); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && idxList.Count < 262144) { Logger.dbgLog(string.Format("tree seralizer will serialize first {0} trees then dummy up the rest.", idxList.Count)); } LoadingExtension.LastSaveUsedPacking = true; if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Loader.LastSaveUsedPacking now set to True."); } EncodedArray.UShort num1 = EncodedArray.UShort.BeginWrite(s); //remember idxlist index entry 0 is also zeroed'd to account for treebuffer starting at 1 not 0) for (int i = 1; i < num; i++) { if (i < idxList.Count) { num1.Write(mBuffer[idxList[i]].m_flags); } else { num1.Write(0); } } num1.EndWrite(); //now lets process the treeinfo try { PrefabCollection <TreeInfo> .BeginSerialize(s); // int limit = Math.Min(num, idxList.Count); for (int j = 1; j < limit; j++) { if (j < idxList.Count) //pretty sure I had this here for a reason as count could be 0 or 1 in cases of error or no real trees. { if (mBuffer[idxList[j]].m_flags != 0) { PrefabCollection <TreeInfo> .Serialize(mBuffer[idxList[j]].m_infoIndex); } } else { Logger.dbgLog("j >= idxList.Count Do we ever hit this?? No real trees to save."); } } //Thale5's cool refcounter work around --THANKS!! // This is the easiest (and only) way to create a dummy DataSerializer that writes to Stream.Null. // This will simply call RefCounter.Serialize() below. try { if (idxList.Count > limit) { if ((OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)) { Logger.dbgLog("Incrementing related reference counts for prefabs for trees > " + limit.ToString()); } DataSerializer.Serialize(System.IO.Stream.Null, DataSerializer.Mode.Memory, 0, new RefCounter(limit, idxList)); } } catch (Exception ex) { Logger.dbgLog("RefCounter caused an error:", ex, true); } } finally { PrefabCollection <TreeInfo> .EndSerialize(s); } EncodedArray.Short num2 = EncodedArray.Short.BeginWrite(s); for (int k = 1; k < num; k++) { if (k < idxList.Count) { if (mBuffer[idxList[k]].m_flags != 0) { num2.Write(mBuffer[idxList[k]].m_posX); } } } num2.EndWrite(); EncodedArray.Short num3 = EncodedArray.Short.BeginWrite(s); for (int l = 1; l < num; l++) { if (l < idxList.Count) { if (mBuffer[idxList[l]].m_flags != 0) { num3.Write(mBuffer[idxList[l]].m_posZ); } } } num3.EndWrite(); //reorder if neccessary if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("reordering burning trees indexes for our seralizer. (packed)"); } if ((uint)tmburning.m_size > 0) { FastList <TreeManager.BurningTree> returnedMatchingBurnList; int retval = ReOrderBurningTrees(ref idxList, out returnedMatchingBurnList); FastList <TreeManager.BurningTree> orgBurningTrees; //used below holds tmp copy of burningtrees; //we only need burning tress with indexes < 262144k. orgBurningTrees = CopyBurningTreesList(ref returnedMatchingBurnList, 1); //create 2 fastlists of burning trees from idxlist //one with indexes 0 -> 262143 one with indexes > 262144 //save 0-262k list as usual //save 262k+ list to our own storage devices via customer serializer class that gets called before this. if (orgBurningTrees == null) { Logger.dbgLog("orgBurningTrees is null, copyburningtrees retuned null array."); orgBurningTrees = new FastList <TreeManager.BurningTree>(); Logger.dbgLog("We dummied up a fake 0 count one."); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Adjusted burning trees for our seralizer.(packed-reorderedlist)"); } // s.WriteUInt24((uint)orgBurningTrees.m_size); for (int m = 0; m < orgBurningTrees.m_size; m++) { s.WriteUInt24(orgBurningTrees.m_buffer[m].m_treeIndex); s.WriteUInt8(orgBurningTrees.m_buffer[m].m_fireIntensity); s.WriteUInt8(orgBurningTrees.m_buffer[m].m_fireDamage); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Saved " + orgBurningTrees.m_size.ToString() + " packed burning trees"); } } else { //There are supposedly no burningtree so just exec the original code untouched. //org s.WriteUInt24((uint)tmburning.m_size); for (int m = 0; m < tmburning.m_size; m++) { s.WriteUInt24(tmburning.m_buffer[m].m_treeIndex); s.WriteUInt8(tmburning.m_buffer[m].m_fireIntensity); s.WriteUInt8(tmburning.m_buffer[m].m_fireDamage); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Saved " + tmburning.m_size.ToString() + " org burning trees (pack but empty)"); } } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("End using packer seralizer. " + DateTime.Now.ToString(Mod.DTMilli)); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled()) { Logger.dbgLog("Tree saving process completed. (packed) " + DateTime.Now.ToString(Mod.DTMilli)); } } else //use original. we can hit this when we're active but packer either didn't get used or we are in ghost mode. { if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("idxList was Null or idxList.Count was < 2"); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Start using original seralizer."); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Loader.LastSaveUsedPacking state = " + LoadingExtension.LastSaveUsedPacking.ToString()); } EncodedArray.UShort num1 = EncodedArray.UShort.BeginWrite(s); for (int i = 1; i < num; i++) { num1.Write(mBuffer[i].m_flags); } num1.EndWrite(); try { PrefabCollection <TreeInfo> .BeginSerialize(s); for (int j = 1; j < num; j++) { if (mBuffer[j].m_flags != 0) { PrefabCollection <TreeInfo> .Serialize(mBuffer[j].m_infoIndex); } } } finally { PrefabCollection <TreeInfo> .EndSerialize(s); } EncodedArray.Short num2 = EncodedArray.Short.BeginWrite(s); for (int k = 1; k < num; k++) { if (mBuffer[k].m_flags != 0) { num2.Write(mBuffer[k].m_posX); } } num2.EndWrite(); EncodedArray.Short num3 = EncodedArray.Short.BeginWrite(s); for (int l = 1; l < num; l++) { if (mBuffer[l].m_flags != 0) { num3.Write(mBuffer[l].m_posZ); } } num3.EndWrite(); if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Adjusting burning trees for original seralizer."); } //12-4 KH - you know we could ecapsilate this with above. // save some code, for now leaving it though. //Since we are not packing we don't need to reorder, but we do //need just trees < 262144k //we feed it the real TreeManager.burningtrees. get back 0-262k if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("No reordering of trees indexes used."); } if (tmburning.m_size > 0) { FastList <TreeManager.BurningTree> orgBurningTrees2; //used below holds tmp copy of burningtrees; orgBurningTrees2 = CopyBurningTreesList(ref tmburning, 1); if (orgBurningTrees2 != null) { Logger.dbgLog("orgBurningTrees2 is null, copyburning returned null? Dummy up new one don't save burning"); orgBurningTrees2 = new FastList <TreeManager.BurningTree>(); } s.WriteUInt24((uint)orgBurningTrees2.m_size); for (int m = 0; m < orgBurningTrees2.m_size; m++) { s.WriteUInt24(orgBurningTrees2.m_buffer[m].m_treeIndex); s.WriteUInt8(orgBurningTrees2.m_buffer[m].m_fireIntensity); s.WriteUInt8(orgBurningTrees2.m_buffer[m].m_fireDamage); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Saved " + orgBurningTrees2.m_size.ToString() + " org burning trees"); } } else { //use real original cause it' empty anyway? s.WriteUInt24((uint)tmburning.m_size); for (int m = 0; m < tmburning.m_size; m++) { s.WriteUInt24(tmburning.m_buffer[m].m_treeIndex); s.WriteUInt8(tmburning.m_buffer[m].m_fireIntensity); s.WriteUInt8(tmburning.m_buffer[m].m_fireDamage); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("Saved " + tmburning.m_size.ToString() + " org burning trees (org empty)"); } } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1) { Logger.dbgLog("End using original seralizer. " + DateTime.Now.ToString(Mod.DTMilli)); } if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled()) { Logger.dbgLog("Tree saving process completed. (original) " + DateTime.Now.ToString(Mod.DTMilli)); } } // Singleton<LoadingManager>.instance.m_loadingProfilerSimulation.EndSerialize(s, "TreeManager"); }