Skip to content

Commit

Permalink
add Data to aoi
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaonanln committed Dec 4, 2017
1 parent f7bfad5 commit ee65808
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions XZListAOIManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func (aoiman *XZListAOIManager) adjust(aoi *xzaoi) {
} else { // markVal < 2
// was neighbor, but not any more
delete(aoi.neighbors, neighbor)
aoi.aoi.Callback.OnLeaveAOI(neighbor.aoi)
aoi.aoi.callback.OnLeaveAOI(neighbor.aoi)
delete(neighbor.neighbors, aoi)
neighbor.aoi.Callback.OnLeaveAOI(aoi.aoi)
neighbor.aoi.callback.OnLeaveAOI(aoi.aoi)
}
}

Expand Down
8 changes: 5 additions & 3 deletions aoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ type AOI struct {
x Coord
y Coord
dist Coord
Callback AOICallback
Data interface{}

callback AOICallback
implData interface{}

//// Fields for XZListAOIManager
Expand All @@ -17,9 +18,10 @@ type AOI struct {
//markVal int
}

func InitAOI(aoi *AOI, dist Coord, callback AOICallback) {
func InitAOI(aoi *AOI, dist Coord, data interface{}, callback AOICallback) {
aoi.dist = dist
aoi.Callback = callback
aoi.Data = data
aoi.callback = callback
}

type AOICallback interface {
Expand Down
5 changes: 2 additions & 3 deletions aoi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"runtime/pprof"
"testing"
"time"
"unsafe"
)

const (
Expand Down Expand Up @@ -72,7 +71,7 @@ func (obj *TestObj) String() string {
}

func (obj *TestObj) getObj(aoi *AOI) *TestObj {
return (*TestObj)(unsafe.Pointer(aoi))
return aoi.Data.(*TestObj)
}

func randCoord(min, max Coord) Coord {
Expand All @@ -83,7 +82,7 @@ func testAOI(t *testing.T, manname string, aoiman AOIManager, numAOI int) {
objs := []*TestObj{}
for i := 0; i < numAOI; i++ {
obj := &TestObj{Id: i + 1, neighbors: map[*TestObj]struct{}{}}
InitAOI(&obj.aoi, _DEFAULT_AOI_DISTANCE, obj)
InitAOI(&obj.aoi, _DEFAULT_AOI_DISTANCE, obj, obj)
objs = append(objs, obj)
aoiman.Enter(&obj.aoi, randCoord(MIN_X, MAX_X), randCoord(MIN_Y, MAX_Y))
}
Expand Down
12 changes: 6 additions & 6 deletions tower_aoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (t *tower) addObj(obj *aoiobj, fromOtherTower *tower) {
if watcher == obj {
continue
}
watcher.aoi.Callback.OnEnterAOI(obj.aoi)
watcher.aoi.callback.OnEnterAOI(obj.aoi)
}
} else {
// obj moved from other tower to this tower
Expand All @@ -168,7 +168,7 @@ func (t *tower) addObj(obj *aoiobj, fromOtherTower *tower) {
if _, ok := t.watchers[watcher]; ok {
continue
}
watcher.aoi.Callback.OnLeaveAOI(obj.aoi)
watcher.aoi.callback.OnLeaveAOI(obj.aoi)
}
for watcher := range t.watchers {
if watcher == obj {
Expand All @@ -177,7 +177,7 @@ func (t *tower) addObj(obj *aoiobj, fromOtherTower *tower) {
if _, ok := fromOtherTower.watchers[watcher]; ok {
continue
}
watcher.aoi.Callback.OnEnterAOI(obj.aoi)
watcher.aoi.callback.OnEnterAOI(obj.aoi)
}
}
}
Expand All @@ -190,7 +190,7 @@ func (t *tower) removeObj(obj *aoiobj, notifyWatchers bool) {
if watcher == obj {
continue
}
watcher.aoi.Callback.OnLeaveAOI(obj.aoi)
watcher.aoi.callback.OnLeaveAOI(obj.aoi)
}
}
}
Expand All @@ -205,7 +205,7 @@ func (t *tower) addWatcher(obj *aoiobj) {
if neighbor == obj {
continue
}
obj.aoi.Callback.OnEnterAOI(neighbor.aoi)
obj.aoi.callback.OnEnterAOI(neighbor.aoi)
}
}

Expand All @@ -219,7 +219,7 @@ func (t *tower) removeWatcher(obj *aoiobj) {
if neighbor == obj {
continue
}
obj.aoi.Callback.OnLeaveAOI(neighbor.aoi)
obj.aoi.callback.OnLeaveAOI(neighbor.aoi)
}
}

Expand Down
8 changes: 4 additions & 4 deletions xAOIList.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ func (sl *xAOIList) GetClearMarkedNeighbors(aoi *xzaoi) {
for prev != nil && prev.aoi.x >= minCoord {
if prev.markVal == 2 {
aoi.neighbors[prev] = struct{}{}
aoi.aoi.Callback.OnEnterAOI(prev.aoi)
aoi.aoi.callback.OnEnterAOI(prev.aoi)
prev.neighbors[aoi] = struct{}{}
prev.aoi.Callback.OnEnterAOI(aoi.aoi)
prev.aoi.callback.OnEnterAOI(aoi.aoi)
}
prev.markVal = 0
prev = prev.xPrev
Expand All @@ -163,9 +163,9 @@ func (sl *xAOIList) GetClearMarkedNeighbors(aoi *xzaoi) {
for next != nil && next.aoi.x <= maxCoord {
if next.markVal == 2 {
aoi.neighbors[next] = struct{}{}
aoi.aoi.Callback.OnEnterAOI(next.aoi)
aoi.aoi.callback.OnEnterAOI(next.aoi)
next.neighbors[aoi] = struct{}{}
next.aoi.Callback.OnEnterAOI(aoi.aoi)
next.aoi.callback.OnEnterAOI(aoi.aoi)
}
next.markVal = 0
next = next.xNext
Expand Down

0 comments on commit ee65808

Please sign in to comment.