using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using ProtoCSStruct; using Sog; using Sog.Data; namespace World { public struct HomeCacheInfoStruct : IStructObject { public int m_objectID; public int GetObjectID() { return m_objectID; } public void SetObjectID(int id) { m_objectID = id; } public bool IsNull() { return m_objectID == -1; } public bool NeedSave; public void SetNeedSave(bool needSave) { NeedSave = needSave; if (needSave) { GetDataSeqSave().MakeDirty(); } } public bool GetNeedSave() { return NeedSave || dataSeqSave.IsDirty(); } //最后一次访问时间,用来淘汰 public long LastAccessTime; //领地版本号 public int homeVer; //保存DB private DataSeqSave dataSeqSave; public DataSeqSave GetDataSeqSave() { if (dataSeqSave == null) { return dataSeqSave = new DataSeqSave(); } return dataSeqSave; } } public class WorldHomePlayerData { public bool notifyClient;//后续是否需要通知客户端 public List homeAdjoinUidList = new List();//玩家相邻领地列表临时存储 public List homeEnemyUidList = new List();//玩家仇人领地列表临时存储 public Dictionary homeUidDbList = new Dictionary();//玩家领地去查询数据库临时存储 } public class WorldHomeData : IServerDataObj { public override int GetDataType() { return WorldDataObjType.WorldHomeData; } public Dictionary m_homeIDMap; //uid->index 用于快速查找m_cacheStructHomeInfo中数据 public StructMemoryCache m_cacheStructHomeInfo;//cache home public Dictionary m_homePlayerMap; //uid->WorldHomePlayerData 用于临时存储玩家相邻领地和仇人领地 //来回切换 public int curSaveHomeIdx; public Dictionary m_saveHomeIDMap; //key:uid 找 m_homeIDMap->index 用于快速保存数据索引 public Dictionary m_saveHomeIDMap1; //key:uid 找 m_homeIDMap->index 用于快速保存数据索引 public bool isLoadFileDataSuccess;//是否加载文件数据成功 public bool isFreeFullCache; //是否正在定时淘汰cache public int maxCacheCount;//最多能支持的cache总数 public int autoRefreshIdx;//当前自动刷新的索引 public WorldHomeData(int cacheCount) { curSaveHomeIdx = 0; isLoadFileDataSuccess = false; isFreeFullCache = false; maxCacheCount = cacheCount; autoRefreshIdx = 0; m_homeIDMap = new Dictionary(); m_saveHomeIDMap = new Dictionary(); m_saveHomeIDMap1 = new Dictionary(); m_cacheStructHomeInfo = new StructMemoryCache(cacheCount); m_homePlayerMap = new Dictionary(); } //cache是否快满了 public bool CacheIsFull() { //差不多满了,可以删除部分 if (m_homeIDMap.Count + 500 >= maxCacheCount) { return true; } return false; } //获取当前正在保存cache map public ref Dictionary GetWorldHomeSaveMap() { if (curSaveHomeIdx == 0) { return ref m_saveHomeIDMap; } else { return ref m_saveHomeIDMap1; } } //切换正在保存的cache map 索引 public void ChgCurWorldHomeSaveMap(ref int oldSaveHomeIdx) { oldSaveHomeIdx = curSaveHomeIdx; if (curSaveHomeIdx == 0) { curSaveHomeIdx = 1; } else { curSaveHomeIdx = 0; } } //该玩家后面需要保存了 public int AddUid2WorldHomeSaveMap(long uid) { if (curSaveHomeIdx == 0) { if (!m_saveHomeIDMap.ContainsKey(uid)) m_saveHomeIDMap[uid] = 1; } else { if (!m_saveHomeIDMap1.ContainsKey(uid)) m_saveHomeIDMap1[uid] = 1; } return 0; } //清除当前cache map public int ClearWorldHomeSaveMap(int clearSaveMapIdx) { if (clearSaveMapIdx == 0) { m_saveHomeIDMap.Clear(); } else { m_saveHomeIDMap1.Clear(); } return 0; } //是否cache数据都保存好了 public bool IsAllDataSave() { if (curSaveHomeIdx == 0) { if (m_saveHomeIDMap.Count > 0) return false; } else { if (m_saveHomeIDMap1.Count > 0) return false; } return true; } } }