Merge pull request #12 from mdiluz/fix-unstable-radar
Fix unstable radar
This commit is contained in:
commit
2ff4bcded7
3 changed files with 22 additions and 2 deletions
|
@ -3,6 +3,7 @@ package internal
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/mdiluz/rove/pkg/game"
|
||||
"github.com/mdiluz/rove/pkg/rove"
|
||||
|
@ -18,8 +19,6 @@ func (s *Server) ServerStatus(context.Context, *rove.ServerStatusRequest) (*rove
|
|||
CurrentTick: int32(s.world.CurrentTicks),
|
||||
}
|
||||
|
||||
// TODO: Verify the accountant is up and ready too
|
||||
|
||||
// If there's a schedule, respond with it
|
||||
if len(s.schedule.Entries()) > 0 {
|
||||
response.NextTick = s.schedule.Entries()[0].Next.Format("15:04:05")
|
||||
|
@ -30,6 +29,8 @@ func (s *Server) ServerStatus(context.Context, *rove.ServerStatusRequest) (*rove
|
|||
|
||||
// Register registers a new account for a gRPC request
|
||||
func (s *Server) Register(ctx context.Context, req *rove.RegisterRequest) (*rove.RegisterResponse, error) {
|
||||
log.Printf("Handling register request: %s\n", req.Name)
|
||||
|
||||
if len(req.Name) == 0 {
|
||||
return nil, fmt.Errorf("empty account name")
|
||||
}
|
||||
|
@ -55,6 +56,8 @@ func (s *Server) Register(ctx context.Context, req *rove.RegisterRequest) (*rove
|
|||
|
||||
// Status returns rover information for a gRPC request
|
||||
func (s *Server) Status(ctx context.Context, req *rove.StatusRequest) (response *rove.StatusResponse, err error) {
|
||||
log.Printf("Handling status request: %s\n", req.Account.Name)
|
||||
|
||||
if valid, err := s.accountant.VerifySecret(req.Account.Name, req.Account.Secret); err != nil {
|
||||
return nil, err
|
||||
|
||||
|
@ -110,6 +113,8 @@ func (s *Server) Status(ctx context.Context, req *rove.StatusRequest) (response
|
|||
|
||||
// Radar returns the radar information for a rover
|
||||
func (s *Server) Radar(ctx context.Context, req *rove.RadarRequest) (*rove.RadarResponse, error) {
|
||||
log.Printf("Handling radar request: %s\n", req.Account.Name)
|
||||
|
||||
if valid, err := s.accountant.VerifySecret(req.Account.Name, req.Account.Secret); err != nil {
|
||||
return nil, err
|
||||
|
||||
|
@ -140,6 +145,8 @@ func (s *Server) Radar(ctx context.Context, req *rove.RadarRequest) (*rove.Radar
|
|||
|
||||
// Command issues commands to the world based on a gRPC request
|
||||
func (s *Server) Command(ctx context.Context, req *rove.CommandRequest) (*rove.CommandResponse, error) {
|
||||
log.Printf("Handling command request: %s and %+v\n", req.Account.Name, req.Commands)
|
||||
|
||||
if valid, err := s.accountant.VerifySecret(req.Account.Name, req.Account.Secret); err != nil {
|
||||
return nil, err
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package atlas
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math/rand"
|
||||
|
||||
"github.com/mdiluz/rove/pkg/maths"
|
||||
|
@ -83,6 +84,7 @@ func (a *Atlas) QueryPosition(v vector.Vector) (byte, objects.Object) {
|
|||
chunk := a.Chunks[c]
|
||||
if chunk.Tiles == nil {
|
||||
chunk.populate(a.ChunkSize)
|
||||
a.Chunks[c] = chunk
|
||||
}
|
||||
i := a.chunkTileIndex(local)
|
||||
return chunk.Tiles[i], chunk.Objects[i]
|
||||
|
@ -218,6 +220,9 @@ func (a *Atlas) worldSpaceToChunkWithGrow(v vector.Vector) int {
|
|||
Chunks: make([]Chunk, size.X*size.Y),
|
||||
}
|
||||
|
||||
// Log that we're resizing
|
||||
log.Printf("Re-allocating world, old: %+v,%+v new: %+v,%+v\n", a.LowerBound, a.UpperBound, newAtlas.LowerBound, newAtlas.UpperBound)
|
||||
|
||||
// Copy all old chunks into the new atlas
|
||||
for chunk, chunkData := range a.Chunks {
|
||||
|
||||
|
|
|
@ -121,6 +121,14 @@ func TestWorld_RadarFromRover(t *testing.T) {
|
|||
// Test the expected values
|
||||
assert.Equal(t, byte(objects.Rover), objs[1+fullRange])
|
||||
assert.Equal(t, byte(objects.Rover), objs[4+4*fullRange])
|
||||
|
||||
// Check the radar results are stable
|
||||
radar1, objs1, err := world.RadarFromRover(a)
|
||||
assert.NoError(t, err)
|
||||
radar2, objs2, err := world.RadarFromRover(a)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, radar1, radar2)
|
||||
assert.Equal(t, objs1, objs2)
|
||||
}
|
||||
|
||||
func TestWorld_RoverStash(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue