代码拉取完成,页面将自动刷新
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]
}
// Keys return keys of the EntityMap in a slice
func (em EntityMap) Keys() (keys []common.EntityID) {
for eid := range em {
keys = append(keys, eid)
}
return
}
// Values return values of the EntityMap in a slice
func (em EntityMap) Values() (vals []*Entity) {
for _, e := range em {
vals = append(vals, e)
}
return
}
// 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()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。