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