public void RemoveCar(ref CarHandle handle) { if (m_cars.Count > handle.ID && m_cars[handle.ID].Size != -1) { // remove from list if it is the last car in list if (handle.ID == m_cars.Count - 1) { m_cars.RemoveAt(m_cars.Count - 1); } else { // if we remove this item from the list, it would invalidate // all handles after this index, so we just remember that we // can reuse this slot m_removedCars.Add(handle.ID); m_cars[handle.ID] = new CarData() { Size = -1, Speed = -1 }; } } // invalidate the handle so it cannot be used again handle.m_id = -1; }
public int GetSize(CarHandle handle) { // TODO: add error checking! return(m_cars[handle.ID].Size); }