Fetch the repository succeeded.
package entity
import (
"bytes"
"github.com/xiaonanln/goworld/engine/common"
)
// EntityMap is the data structure for maintaining entity IDs to entities
type EntityMap map[common.EntityID]*Entity
// Add adds a new entity to EntityMap
func (em EntityMap) Add(entity *Entity) {
em[entity.ID] = entity
}
// Del deletes an entity from EntityMap
func (em EntityMap) Del(id common.EntityID) {
delete(em, id)
}
// Get returns the Entity of specified entity ID in EntityMap
func (em EntityMap) Get(id common.EntityID) *Entity {
return em[id]
}
// EntitySet is the data structure for a set of entities
type EntitySet map[*Entity]struct{}
// Add adds an entity to the EntitySet
func (es EntitySet) Add(entity *Entity) {
es[entity] = struct{}{}
}
// Del deletes an entity from the EntitySet
func (es EntitySet) Del(entity *Entity) {
delete(es, entity)
}
// Contains returns if the entity is in the EntitySet
func (es EntitySet) Contains(entity *Entity) bool {
_, ok := es[entity]
return ok
}
func (es EntitySet) String() string {
b := bytes.Buffer{}
b.WriteString("{")
first := true
for entity := range es {
if !first {
b.WriteString(", ")
} else {
first = false
}
b.WriteString(entity.String())
}
b.WriteString("}")
return b.String()
}
// EntityIDSet is the data structure for a set of entity IDs
type EntityIDSet map[common.EntityID]struct{}
// Add adds an entity ID to EntityIDSet
func (es EntityIDSet) Add(id common.EntityID) {
es[id] = struct{}{}
}
// Del removes an entity ID from EntityIDSet
func (es EntityIDSet) Del(id common.EntityID) {
delete(es, id)
}
// Contains checks if entity ID is in EntityIDSet
func (es EntityIDSet) Contains(id common.EntityID) bool {
_, ok := es[id]
return ok
}
// ToList convert EntityIDSet to a slice of entity IDs
func (es EntityIDSet) ToList() []common.EntityID {
list := make([]common.EntityID, 0, len(es))
for eid := range es {
list = append(list, eid)
}
return list
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。