Fix instabilities caused by random rocks
This commit is contained in:
parent
520f78b5c3
commit
aae668fb57
7 changed files with 19 additions and 16 deletions
|
@ -39,9 +39,11 @@ func NewWorld(size int, chunkSize int) *World {
|
|||
}
|
||||
|
||||
// SpawnWorld spawns a border at the edge of the world atlas
|
||||
func (w *World) SpawnWorld() error {
|
||||
if err := w.Atlas.SpawnRocks(); err != nil {
|
||||
return err
|
||||
func (w *World) SpawnWorld(fillWorld bool) error {
|
||||
if fillWorld {
|
||||
if err := w.Atlas.SpawnRocks(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return w.Atlas.SpawnWalls()
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestHandleStatus(t *testing.T) {
|
|||
response := httptest.NewRecorder()
|
||||
|
||||
s := NewServer()
|
||||
s.Initialise()
|
||||
s.Initialise(true)
|
||||
s.router.ServeHTTP(response, request)
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
|
||||
|
@ -46,7 +46,7 @@ func TestHandleRegister(t *testing.T) {
|
|||
response := httptest.NewRecorder()
|
||||
|
||||
s := NewServer()
|
||||
s.Initialise()
|
||||
s.Initialise(true)
|
||||
s.router.ServeHTTP(response, request)
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
|
||||
|
@ -60,7 +60,7 @@ func TestHandleRegister(t *testing.T) {
|
|||
|
||||
func TestHandleSpawn(t *testing.T) {
|
||||
s := NewServer()
|
||||
s.Initialise()
|
||||
s.Initialise(true)
|
||||
a, err := s.accountant.RegisterAccount("test")
|
||||
assert.NoError(t, err, "Error registering account")
|
||||
data := rove.SpawnData{}
|
||||
|
@ -85,12 +85,13 @@ func TestHandleSpawn(t *testing.T) {
|
|||
|
||||
func TestHandleCommand(t *testing.T) {
|
||||
s := NewServer()
|
||||
s.Initialise()
|
||||
s.Initialise(false) // Leave the world empty with no obstacles
|
||||
a, err := s.accountant.RegisterAccount("test")
|
||||
assert.NoError(t, err, "Error registering account")
|
||||
|
||||
// Spawn the rover rover for the account
|
||||
_, inst, err := s.SpawnRoverForAccount(a.Id)
|
||||
assert.NoError(t, s.world.WarpRover(inst, game.Vector{}))
|
||||
|
||||
attribs, err := s.world.RoverAttributes(inst)
|
||||
assert.NoError(t, err, "Couldn't get rover position")
|
||||
|
@ -135,7 +136,7 @@ func TestHandleCommand(t *testing.T) {
|
|||
|
||||
func TestHandleRadar(t *testing.T) {
|
||||
s := NewServer()
|
||||
s.Initialise()
|
||||
s.Initialise(false) // Spawn a clean world
|
||||
a, err := s.accountant.RegisterAccount("test")
|
||||
assert.NoError(t, err, "Error registering account")
|
||||
|
||||
|
@ -189,7 +190,7 @@ func TestHandleRadar(t *testing.T) {
|
|||
|
||||
func TestHandleRover(t *testing.T) {
|
||||
s := NewServer()
|
||||
s.Initialise()
|
||||
s.Initialise(true)
|
||||
a, err := s.accountant.RegisterAccount("test")
|
||||
assert.NoError(t, err, "Error registering account")
|
||||
|
||||
|
|
|
@ -104,13 +104,13 @@ func NewServer(opts ...ServerOption) *Server {
|
|||
}
|
||||
|
||||
// Initialise sets up internal state ready to serve
|
||||
func (s *Server) Initialise() (err error) {
|
||||
func (s *Server) Initialise(fillWorld bool) (err error) {
|
||||
|
||||
// Add to our sync
|
||||
s.sync.Add(1)
|
||||
|
||||
// Spawn a border on the default world
|
||||
if err := s.world.SpawnWorld(); err != nil {
|
||||
if err := s.world.SpawnWorld(fillWorld); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ func TestServer_Run(t *testing.T) {
|
|||
server := NewServer()
|
||||
if server == nil {
|
||||
t.Error("Failed to create server")
|
||||
} else if err := server.Initialise(); err != nil {
|
||||
} else if err := server.Initialise(true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ func TestServer_RunPersistentData(t *testing.T) {
|
|||
server := NewServer(OptionPersistentData())
|
||||
if server == nil {
|
||||
t.Error("Failed to create server")
|
||||
} else if err := server.Initialise(); err != nil {
|
||||
} else if err := server.Initialise(true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue