1 Star 0 Fork 0

wuzpdev/goworld

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
entity_map.go 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
seis 提交于 7年前 . SetGameID
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()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzpdev/goworld.git
git@gitee.com:wuzpdev/goworld.git
wuzpdev
goworld
goworld
v0.1.6

搜索帮助