public T NewObject <T>(int id) where T : BaseSnapObject, new() { if (_snapshotItems.Count + 1 >= MAX_SNAPSHOT_ITEMS) { Debug.Warning("snapshots", "too many items"); return(null); } var obj = new T(); if (obj.Type <= Enums.SnapObject.INVALID || obj.Type >= Enums.SnapObject.NUM) { Debug.Warning("snapshots", "wrong object type"); return(null); } var itemSize = obj.SerializeLength * sizeof(int); if (_currentSize + itemSize >= MAX_SNAPSHOT_SIZE) { Debug.Warning("snapshots", "too much data"); return(null); } var item = new SnapshotItem((int)obj.Type << 16 | id, itemSize, obj); _currentSize += itemSize; _snapshotItems.Add(item); return((T)item.Object); }
public bool AddItem(BaseSnapshotItem obj, int id) { if (obj == null) { Debug.Warning("snapshots", "add null object"); return(false); } if (SnapshotItems.Count + 1 >= MaxItems) { Debug.Warning("snapshots", "too many items"); return(false); } var itemSize = SnapshotItemsInfo.GetSize(obj.GetType()); if (SnapshotSize + itemSize >= Snapshot.MaxSize) { Debug.Warning("snapshots", "too much data"); return(false); } var item = new SnapshotItem(id, obj); SnapshotSize += itemSize; SnapshotItems.Add(item); return(true); }
public bool AddItem <T>(T obj, int id) where T : BaseSnapObject { if (obj == null) { Debug.Warning("snapshots", "add null object"); return(false); } if (_snapshotItems.Count + 1 >= MAX_SNAPSHOT_ITEMS) { Debug.Warning("snapshots", "too many items"); return(false); } if (obj.Type <= Enums.SnapObject.INVALID || obj.Type >= Enums.SnapObject.NUM) { Debug.Warning("snapshots", "wrong object type"); return(false); } var itemSize = obj.SerializeLength * sizeof(int); if (_currentSize + itemSize >= MAX_SNAPSHOT_SIZE) { Debug.Warning("snapshots", "too much data"); return(false); } var item = new SnapshotItem((int)obj.Type << 16 | id, itemSize, obj); _currentSize += itemSize; _snapshotItems.Add(item); return(true); }
public T NewItem <T>(int id) where T : BaseSnapshotItem, new() { if (SnapshotItems.Count + 1 >= MaxItems) { Debug.Warning("snapshots", "too many items"); return(null); } var itemSize = SnapshotItemsInfo.GetSize <T>(); if (SnapshotSize + itemSize >= Snapshot.MaxSize) { Debug.Warning("snapshots", "too much data"); return(null); } var item = new SnapshotItem(id, new T()); SnapshotSize += itemSize; SnapshotItems.Add(item); return((T)item.Item); }