package tstorages import ( "fmt" "joylink.club/rtsssimulation/repository/model/proto" "joylink.club/rtsssimulation/system" ) // 共享仓库映射 var ShareStoragesMapper *ModelStoragesMapper = &ModelStoragesMapper{storages: make(map[string]*ModelStorage)} //////////////////////////////////////////////// type StorageKey struct { LineId string Version string } func (me *StorageKey) Key() string { return fmt.Sprintf("%s||%s", me.LineId, me.Version) } //////////////////////////////////// type ModelStoragesMapper struct { //共享模型仓库 //key-StorageKey storages map[string]*ModelStorage } func (me *ModelStoragesMapper) FindShareModelStorage(skey StorageKey) *ModelStorage { return me.storages[skey.Key()] } func (me *ModelStoragesMapper) AddShareModelStorage(skey StorageKey, storage *ModelStorage) { me.storages[skey.Key()] = storage } // 通过共享模型仓库创建world模型仓库 func (me *ModelStoragesMapper) CreateWorldStorageWithShare(skey StorageKey, links *ModelStorage) *WorldModelStorage { return &WorldModelStorage{Share: me.storages[skey.Key()], Links: links} } /////////////////////////////////// // 仿真world的模型仓库 type WorldModelStorage struct { // 对公共模型的指针 Share *ModelStorage // 该world独享的轨道模型 Links *ModelStorage } // 根据模型的复合id获取模型数据 func (me *WorldModelStorage) FindById(id string) system.IDeviceModel { md := me.Links.FindModelById(id) if md != nil { return md } md = me.Share.FindModelById(id) if md != nil { return md } return nil } // 获取某类型设备的所有模型数据 func (me *WorldModelStorage) FindByType(deviceType system.DeviceType) []system.IDeviceModel { if proto.DeviceType_DeviceType_Link == deviceType { return me.Links.FindModelsByType(deviceType) } else { return me.Share.FindModelsByType(deviceType) } }