# Class GameWorld

java.lang.Object
com.codename1.gaming.level.GameWorld

public class GameWorld extends Object
A large game space made of linked `Region`s, 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.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GameWorld()`
  `GameWorld(RegionProvider provider)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `GameWorld`
  `addRegion(Region r)`
  `static GameWorld`
  `fromMap(Map<String,Object> root)`
  `Region`
  `getActiveRegion()`
  `int`
  `getKeepRadius()`
  How many neighbour links away from the active region stay resident.
  `RegionProvider`
  `getProvider()`
  `Region`
  `getRegion(String id)`
  Returns a resident region, paging it in through the provider if needed.
  `List<Region>`
  `residentRegions()`
  Currently-resident regions.
  `GameWorld`
  `setActiveRegion(String id)`
  `GameWorld`
  `setKeepRadius(int keepRadius)`
  `GameWorld`
  `setProvider(RegionProvider provider)`
  `String`
  `toJson()`
  Serializes the resident regions + active region as a JSON object.
  `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.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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.