forked from xiaonanln/goworld
/
space_ops.go
50 lines (43 loc) · 1.47 KB
/
space_ops.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package entity
import (
"strconv"
"github.com/xiaonanln/goworld/engine/common"
"github.com/xiaonanln/goworld/engine/gwlog"
"github.com/xiaonanln/goworld/engine/uuid"
)
// CreateSpaceLocally creates a space in the local game server
func CreateSpaceLocally(kind int) *Space {
if kind == 0 {
gwlog.Panicf("Can not create nil space with kind=0. Game will create 1 nil space automatically.")
}
e := createEntity(_SPACE_ENTITY_TYPE, nil, Vector3{}, "", map[string]interface{}{
_SPACE_KIND_ATTR_KEY: kind,
})
return e.AsSpace()
}
// CreateSpaceSomewhere creates a space in any game server
func CreateSpaceSomewhere(gameid uint16, kind int) common.EntityID {
if kind == 0 {
gwlog.Panicf("Can not create nil space with kind=0. Game will create 1 nil space automatically.")
}
return createEntitySomewhere(gameid, _SPACE_ENTITY_TYPE, map[string]interface{}{
_SPACE_KIND_ATTR_KEY: kind,
})
}
// CreateNilSpace creates the nil space
func CreateNilSpace(gameid uint16) *Space {
spaceID := GetNilSpaceID(gameid)
e := createEntity(_SPACE_ENTITY_TYPE, nil, Vector3{}, spaceID, map[string]interface{}{
_SPACE_KIND_ATTR_KEY: 0,
})
return e.AsSpace()
}
// GetNilSpaceEntityID returns the EntityID for Nil Space on the specified game
// GoWorld uses fixed EntityID for nil spaces on each game
func GetNilSpaceID(gameid uint16) common.EntityID {
gameidStr := strconv.Itoa(int(gameid))
return common.EntityID(uuid.GenFixedUUID([]byte(gameidStr)))
}
func GetNilSpace() *Space {
return nilSpace
}