Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import (

"cityio/internal/cluster"
"cityio/internal/config"
"cityio/internal/constants"
"cityio/internal/database"
"cityio/internal/logger"
"cityio/internal/metrics"
"cityio/internal/persistence"
"cityio/internal/rpc"
"cityio/internal/setup"
"cityio/internal/world"
)

func main() {
Expand All @@ -43,13 +45,20 @@ func main() {
slog.InfoContext(ctx, "starting cityio backend")

db := database.NewDB(ctx, cfg.DatabaseDSN())
store := persistence.New(db)

// The map is regenerated from a fixed seed on every boot rather than
// persisted, so it survives the reset that wipes everything else.
gameWorld := world.Generate(constants.MapSize, constants.MapSize, constants.WorldSeed)
slog.InfoContext(ctx, "generated world", "width", gameWorld.Width, "height", gameWorld.Height, "seed", gameWorld.Seed)

store := persistence.New(db, gameWorld)
store.Start(ctx)
cl := cluster.NewRuntime(ctx, store, cfg.Environment)

setup.Run(ctx, &setup.Deps{
DB: db,
Cluster: cl,
World: gameWorld,
})

// shutdownCtx is cancelled when we receive SIGINT/SIGTERM. The RPC server
Expand All @@ -63,7 +72,7 @@ func main() {
// gauges.
metrics.StartSnapshot(shutdownCtx, store)

server := rpc.NewServer(shutdownCtx, cl, store, cfg.JWTSecret)
server := rpc.NewServer(shutdownCtx, cl, store, gameWorld, cfg.JWTSecret)
handler := cors.New(cors.Options{
AllowOriginFunc: func(origin string) bool {
if origin == "http://localhost:5173" || origin == "http://localhost:4173" {
Expand Down
6 changes: 6 additions & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ const (
TroopMovementDuration = 1 // time it takes to cross 1 tile

VisionRadius = 3 // Chebyshev distance beyond owned city edges that a player can see

// WorldSeed fixes the shape of the map. Terrain is regenerated from it on
// every boot rather than persisted, so the world survives restarts even
// though everything else is wiped. Changing it reshapes the map for
// everyone.
WorldSeed = 0xc17e0
)

type TownConfig struct {
Expand Down
Loading
Loading