Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
bomberman::sim Namespace Reference

Shared simulation primitives and constants used by both the client and the authoritative server. More...

Classes

struct  SpawnSlotCell
 One multiplayer spawn slot expressed in tile-cell coordinates. More...
 
struct  TilePos
 Tile-space Q8 position representing the CENTER of the entity. More...
 

Typedefs

using TileMap = Tile[tileArrayHeight][tileArrayWidth]
 Read-only view of a runtime tile map (same layout as LevelScene::tiles).
 

Enumerations

enum class  PowerupType : uint8_t { SpeedBoost = 0 , Invincibility = 1 , BombRangeBoost = 2 , MaxBombsBoost = 3 }
 Supported temporary multiplayer powerup effects.
 

Functions

bool isWalkable (const TileMap &map, int col, int row)
 Returns true if the given tile coordinate is passable.
 
bool overlapsWall (const TileMap &map, int32_t xQ, int32_t yQ)
 Returns true if the AABB centered at (xQ, yQ) with half-extent kHitboxHalfQ overlaps any solid tile.
 
TilePos stepMovement (TilePos pos, int8_t moveX, int8_t moveY, int32_t speedQ=kPlayerSpeedQ)
 Advances a position by one simulation tick given a directional input.
 
TilePos stepMovementWithCollision (TilePos pos, int8_t moveX, int8_t moveY, const TileMap &map, int32_t speedQ=kPlayerSpeedQ)
 Advances a position by one tick with tile-map collision.
 
int tileQToScreen (int32_t tileQ, int fieldPx, int scaledTile, int cameraPx)
 Converts a center tile-Q8 coordinate to the screen pixel at that center.
 
int tileQToScreenTopLeft (int32_t tileQ, int fieldPx, int scaledTile, int cameraPx)
 Converts a center tile-Q8 coordinate to the screen top-left pixel for sprite rendering.
 
constexpr bool isValidPowerupType (const uint8_t rawType)
 Returns true when a raw byte encodes one of the defined powerup types.
 
constexpr std::string_view powerupTypeName (const PowerupType type)
 Returns a human-readable name for one powerup type.
 
constexpr std::size_t powerupTypeIndex (const PowerupType type)
 Returns the stable array index used for per-type powerup stats.
 
constexpr uint32_t powerupEffectDurationTicks (const PowerupType type)
 Returns the configured lifetime for one powerup effect.
 
constexpr SpawnSlotCell spawnSlotCellForPlayerId (const uint8_t playerId)
 Returns the default spawn slot assigned to the given player id.
 
constexpr TilePos spawnSlotTilePos (const SpawnSlotCell slot)
 Converts one tile-cell spawn slot to a center-position tile-Q8 coordinate.
 
constexpr TilePos spawnTilePosForPlayerId (const uint8_t playerId)
 Returns the default center-position tile-Q8 spawn for the given player id.
 
void generateTileMap (uint32_t seed, Tile outTiles[tileArrayHeight][tileArrayWidth])
 Populates outTiles with a procedurally generated tile map.
 

Variables

constexpr int32_t kPlayerSpeedQ = static_cast<int32_t>(kPlayerSpeedTilesPerSecond * 256.0 / kTickRate + 0.5)
 Player movement speed in tile-Q8 units per simulation tick.
 
constexpr int32_t kHitboxHalfQ = static_cast<int32_t>(kPlayerHitboxScale * 256.0f / 2.0f)
 Player hitbox half-extent in tile-Q8 units.
 
constexpr std::size_t kPowerupTypeCount = 4
 Number of defined multiplayer powerup types.
 
constexpr std::array< PowerupType, 4 > kRoundPowerupPlacements
 Stable per-round hidden placements seeded under random bricks.
 
constexpr uint8_t kPowerupsPerRound = static_cast<uint8_t>(kRoundPowerupPlacements.size())
 Number of hidden powerups seeded into each round when enabled.
 
constexpr uint32_t kDefaultPowerupDurationTicks = static_cast<uint32_t>(kTickRate) * 10u
 Default temporary powerup lifetime in simulation ticks.
 
constexpr uint32_t kInvincibilityDurationTicks = kDefaultPowerupDurationTicks
 Invincibility lifetime in simulation ticks.
 
constexpr uint32_t kSpeedBoostDurationTicks = kDefaultPowerupDurationTicks
 Speed boost lifetime in simulation ticks.
 
constexpr uint32_t kBombRangeBoostDurationTicks = kDefaultPowerupDurationTicks
 Bomb-range boost lifetime in simulation ticks.
 
constexpr uint32_t kMaxBombsBoostDurationTicks = kDefaultPowerupDurationTicks
 Max-bombs boost lifetime in simulation ticks.
 
constexpr double kSpeedBoostTilesPerSecond = 5.5
 Future movement-speed target while the speed boost is active.
 
constexpr int32_t kSpeedBoostPlayerSpeedQ
 Movement speed in tile-Q8 units per simulation tick while the speed boost is active.
 
constexpr uint8_t kBombRangeBoostAmount = 1
 Additional blast radius applied to bombs placed during the range boost.
 
constexpr uint8_t kBoostedMaxBombs = 2
 Bomb-cap target while the max-bombs boost is active.
 
constexpr uint32_t kPowerupPlacementSeedSalt = 0x9E3779B9u
 Deterministic salt mixed into round placement RNG so repeated map seeds can still vary by round.
 
constexpr int16_t kTickRate = 60
 Simulation tick rate in Hz.
 
constexpr uint8_t kDefaultPlayerMaxBombs = 1
 Default number of simultaneously active bombs a player may own.
 
constexpr uint8_t kDefaultPlayerBombRange = 1
 Default explosion radius in tiles for newly placed bombs.
 
constexpr uint32_t kDefaultBombFuseTicks = static_cast<uint32_t>(kTickRate) * 3u / 2u
 Default authoritative bomb fuse in simulation ticks.
 
constexpr double kPlayerSpeedTilesPerSecond = 4.0
 Player movement speed in tiles per second.
 
constexpr float kPlayerHitboxScale = 0.5f
 Player hitbox size as a fraction of the tile size.
 
constexpr int32_t kMaxFrameClampMs = 250
 Maximum milliseconds the fixed-step accumulator will simulate in one frame.
 
constexpr int32_t kMaxStepsPerFrame = 8
 Maximum simulation steps taken within a single frame even if the accumulator exceeds the limit.
 
constexpr int32_t kDefaultServerInputLeadTicks = 1
 Default server-side input lead in ticks for authoritative input scheduling.
 
constexpr int32_t kDefaultServerSnapshotIntervalTicks = 1
 Default server snapshot interval in simulation ticks (1 = every tick / 60 Hz).
 
constexpr uint8_t kLeftSpawnCol = 1
 
constexpr uint8_t kRightSpawnCol = static_cast<uint8_t>(tileArrayWidth - 2)
 
constexpr uint8_t kTopSpawnRow = 1
 
constexpr uint8_t kBottomSpawnRow = 9
 
constexpr std::array< SpawnSlotCell, 4 > kDefaultSpawnSlots
 Default player-id keyed spawn slots for the current arena layout.
 

Detailed Description

Shared simulation primitives and constants used by both the client and the authoritative server.

Function Documentation

◆ generateTileMap()

void bomberman::sim::generateTileMap ( uint32_t  seed,
Tile  outTiles[tileArrayHeight][tileArrayWidth] 
)
inline

Populates outTiles with a procedurally generated tile map.

Parameters
seed32-bit seed for the internal std::mt19937 PRNG.
outTilesOutput array, must be [tileArrayHeight][tileArrayWidth].

◆ isWalkable()

bool bomberman::sim::isWalkable ( const TileMap map,
int  col,
int  row 
)
inline

Returns true if the given tile coordinate is passable.

Stone and Brick are solid. Out-of-bounds is treated as solid (world boundary). Bomb is intentionally excluded here - bomb collision is a gameplay layer above sim.

◆ stepMovement()

TilePos bomberman::sim::stepMovement ( TilePos  pos,
int8_t  moveX,
int8_t  moveY,
int32_t  speedQ = kPlayerSpeedQ 
)
inline

Advances a position by one simulation tick given a directional input.

Parameters
posCurrent position in tile-Q8.
moveXHorizontal input in {-1, 0, 1}.
moveYVertical input in {-1, 0, 1}.
speedQMovement speed in tile-Q8 units per simulation tick.

◆ stepMovementWithCollision()

TilePos bomberman::sim::stepMovementWithCollision ( TilePos  pos,
int8_t  moveX,
int8_t  moveY,
const TileMap map,
int32_t  speedQ = kPlayerSpeedQ 
)
inline

Advances a position by one tick with tile-map collision.

Resolves X and Y axes independently so the player slides along walls instead of stopping dead when hitting a corner.

Parameters
posCurrent position in tile-Q8.
moveXHorizontal input in {-1, 0, 1}.
moveYVertical input in {-1, 0, 1}.
mapRead-only tile map to check collision against.
speedQMovement speed in tile-Q8 units per simulation tick.
Returns
New position, guaranteed not to overlap any solid tile.

◆ tileQToScreen()

int bomberman::sim::tileQToScreen ( int32_t  tileQ,
int  fieldPx,
int  scaledTile,
int  cameraPx 
)
inline

Converts a center tile-Q8 coordinate to the screen pixel at that center.

Use for debug overlays, hit indicators, etc.

Parameters
tileQCenter position in tile-Q8 (entity center, not top-left).
fieldPxField origin in screen pixels.
scaledTileRendered tile size in pixels.
cameraPxCamera offset in the same axis.
Returns
Screen pixel coordinate of the center.

◆ tileQToScreenTopLeft()

int bomberman::sim::tileQToScreenTopLeft ( int32_t  tileQ,
int  fieldPx,
int  scaledTile,
int  cameraPx 
)
inline

Converts a center tile-Q8 coordinate to the screen top-left pixel for sprite rendering.

Sprites are positioned by their top-left corner. Given a center Q8 position, subtract half a tile (128 Q8 units = 0.5 tiles) before converting to get the top-left.

Parameters
tileQCenter position in tile-Q8.
fieldPxField origin in screen pixels.
scaledTileRendered tile size in pixels.
cameraPxCamera offset in the same axis.
Returns
Screen pixel coordinate of the sprite's top-left corner.

Variable Documentation

◆ kDefaultSpawnSlots

constexpr std::array<SpawnSlotCell, 4> bomberman::sim::kDefaultSpawnSlots
constexpr
Initial value:
{{
{kLeftSpawnCol, kTopSpawnRow},
{kLeftSpawnCol, kBottomSpawnRow},
{kRightSpawnCol, kTopSpawnRow},
{kRightSpawnCol, kBottomSpawnRow},
}}

Default player-id keyed spawn slots for the current arena layout.

These slots assume the existing rectangular border and stone-grid layout. Player ids beyond the four default seats currently wrap this corner table until a dedicated larger-match layout exists.

◆ kPlayerHitboxScale

constexpr float bomberman::sim::kPlayerHitboxScale = 0.5f
constexpr

Player hitbox size as a fraction of the tile size.

Used by both the Q8 simulation and the SDL float collision system.

◆ kRoundPowerupPlacements

constexpr std::array<PowerupType, 4> bomberman::sim::kRoundPowerupPlacements
constexpr
Initial value:
{{
PowerupType::SpeedBoost,
PowerupType::Invincibility,
PowerupType::BombRangeBoost,
PowerupType::MaxBombsBoost
}}

Stable per-round hidden placements seeded under random bricks.

The array length defines how many powerups are hidden in each round. Repeating a type here increases its frequency without needing a separate weighted-RNG system.

◆ kSpeedBoostPlayerSpeedQ

constexpr int32_t bomberman::sim::kSpeedBoostPlayerSpeedQ
constexpr
Initial value:
=
static_cast<int32_t>(kSpeedBoostTilesPerSecond * 256.0 / kTickRate + 0.5)
constexpr int16_t kTickRate
Simulation tick rate in Hz.
Definition SimConfig.h:14
constexpr double kSpeedBoostTilesPerSecond
Future movement-speed target while the speed boost is active.
Definition PowerupConfig.h:62

Movement speed in tile-Q8 units per simulation tick while the speed boost is active.