public class GameWorld

  1. Object
  2. GameWorld
A large game space made of linked Regions, streamed in and out around the player so the world can exceed memory while transitions stay seamless. Hold the regions directly (small worlds) or supply a RegionProvider to page them by id. Call #update(double,double) each frame with the player’s world position: the world keeps the containing region active, loads its linked neighbours, and unloads (saving) regions beyond #getKeepRadius() links away.

Constructors

public GameWorld()
public GameWorld(RegionProvider provider)

Methods

public RegionProvider getProvider()
public GameWorld setProvider(RegionProvider provider)
public int getKeepRadius()How many neighbour links away from the active region stay resident.
public GameWorld setKeepRadius(int keepRadius)
public String toJson()Serializes the resident regions + active region as a JSON object.
public static GameWorld fromMap(Map<String, Object> root)
public GameWorld addRegion(Region r)
public Region getRegion(String id)Returns a resident region, paging it in through the provider if needed.
public Region getActiveRegion()
public GameWorld setActiveRegion(String id)
public List<Region> residentRegions()Currently-resident regions.
public void update(double playerWorldX, double playerWorldZ)Drives streaming: picks the region containing the player (preferring a neighbour of the current active region for seamless crossings), loads neighbours within #getKeepRadius() and unloads (persisting) the rest.

Inherited methods

Constructor details

GameWorld

public GameWorld()

GameWorld

public GameWorld(RegionProvider provider)

Method details

getProvider

public RegionProvider getProvider()

setProvider

public GameWorld setProvider(RegionProvider provider)

getKeepRadius

public int getKeepRadius()
How many neighbour links away from the active region stay resident.

setKeepRadius

public GameWorld setKeepRadius(int keepRadius)

toJson

public String toJson()
Serializes the resident regions + active region as a JSON object. (A provider-backed world persists individual regions through its RegionProvider; this inline form suits small/medium worlds embedded in a level file.)

fromMap

public static GameWorld fromMap(Map<String, Object> root)

addRegion

public GameWorld addRegion(Region r)

getRegion

public Region getRegion(String id)
Returns a resident region, paging it in through the provider if needed.

getActiveRegion

public Region getActiveRegion()

setActiveRegion

public GameWorld setActiveRegion(String id)

residentRegions

public List<Region> residentRegions()
Currently-resident regions.

update

public void update(double playerWorldX, double playerWorldZ)
Drives streaming: picks the region containing the player (preferring a neighbour of the current active region for seamless crossings), loads neighbours within #getKeepRadius() and unloads (persisting) the rest.