Documentation
¶
Overview ¶
Package world defines the bounded compiled sector format shared by level compilers and Karty hosts. It contains data contracts and validation only.
Index ¶
- Constants
- Variables
- func Encode(document Document) ([]byte, error)
- func Validate(document *Document) error
- func ValidateLighting(lighting *Lighting) error
- func ValidateStaticSolids(solids *StaticSolids) (err error)
- func ValidateSurfaceUV(mapping *SurfaceUV) error
- type Actor
- type AmbientCube
- type Content
- type Document
- type LightMotion
- type Lighting
- type MaterialMapping
- type Plane
- type PointLight
- type Sector
- type Solid
- type Sprite
- type SpriteAlpha
- type SpriteFacing
- type StaticSolids
- type SurfaceUV
- type UVPlane
- type UVProjection
- type Vec2
- type Vec3
- type Wall
- type WallProfile
Constants ¶
const ( MaterialMappingVersion = uint32(1) FeatureMaterialMapping = cartridge.FeatureWorldMaterialMappingV1 MaxUVProjectionValue = 1e12 UVWeightTolerance = 1e-9 )
const ( StaticSolidsVersion = uint32(1) FeatureStaticSolids = cartridge.FeatureWorldStaticSolidsV1 MaxStaticSolids = 1024 MaxSolidVertices = 64 )
const ( LegacyVersion = uint16(1) ActorVersion = uint16(2) Version = uint16(3) LightingVersion = uint32(1) EntryName = "@world/main" Feature = cartridge.FeatureWorldSectorsV1 FeatureLighting = cartridge.FeatureWorldLightingV1 MaxEncodedSize = 8 * 1024 * 1024 MaxSectors = 256 MaxWalls = 8192 MaxWallsPerSector = 256 MaxContents = 4096 MaxLights = 50 MinLightRadius = 0.001 MaxIdentifierBytes = 128 MaxKindBytes = 128 MaxTags = 8 MaxTagBytes = 64 MaxCoordinate = 1_000_000.0 MinEdgeLength = 1e-6 MinClearance = 1e-6 )
Variables ¶
var ( ErrSize = errors.New("world payload size is invalid") ErrSyntax = errors.New("world payload syntax is invalid") ErrVersion = errors.New("world payload version is unsupported") ErrBounds = errors.New("world payload exceeds a declared bound") ErrIdentity = errors.New("world identity is invalid") ErrGeometry = errors.New("world geometry is invalid") ErrPortal = errors.New("world portal is invalid") ErrContent = errors.New("world content is invalid") ErrMaterialMapping = errors.New("world material mapping is invalid") ErrLighting = errors.New("world lighting is invalid") ErrStaticSolids = errors.New("world static solids are invalid") ErrCanonical = errors.New("world payload is not canonical") )
Functions ¶
func Validate ¶
Validate checks a complete compiled document before a host prepares private indexes or publishes a mounted resource.
func ValidateLighting ¶ added in v0.0.8
ValidateLighting checks the complete lighting payload without requiring sector geometry. Optional absence is represented by Document.Lighting == nil; passing nil here is invalid. Capability/world consistency is the consumer's responsibility because the payload does not contain a cartridge manifest.
func ValidateStaticSolids ¶ added in v0.0.8
func ValidateStaticSolids(solids *StaticSolids) (err error)
ValidateStaticSolids validates every item, including the last, before mounting. Solids may overlap each other and sectors; sector validation is unchanged.
func ValidateSurfaceUV ¶ added in v0.0.8
ValidateSurfaceUV validates complete bounded projection and weight lists.
Types ¶
type Actor ¶ added in v0.0.6
type Actor struct {
Yaw float64 `json:"yaw"`
Pitch float64 `json:"pitch"`
Roll float64 `json:"roll"`
Scale Vec3 `json:"scale"`
Sprite *Sprite `json:"sprite,omitempty"`
Tags []string `json:"tags,omitempty"`
}
Actor is the optional typed ECS payload introduced by compiled-world v2. Position remains on Content so actor and non-rendered gameplay contents share the same stable identity and sector assignment.
type AmbientCube ¶ added in v0.0.8
type AmbientCube struct {
PositiveX Vec3 `json:"positive_x"`
NegativeX Vec3 `json:"negative_x"`
PositiveY Vec3 `json:"positive_y"`
NegativeY Vec3 `json:"negative_y"`
PositiveZ Vec3 `json:"positive_z"`
NegativeZ Vec3 `json:"negative_z"`
}
AmbientCube supplies six world-space directional ambient colors. It replaces Ambient when present; squared unit-normal components weight each selected face. Colors are finite linear RGB intensities in [0,1].
type Content ¶
type Content struct {
ID string `json:"id"`
SourceID string `json:"source_id"`
Instance string `json:"instance"`
Kind string `json:"kind"`
Sector uint32 `json:"sector"`
Position Vec3 `json:"position"`
Actor *Actor `json:"actor,omitempty"`
}
Content retains both its compiled identity and authored/prefab provenance. The component payload is deliberately deferred to its own versioned format.
type Document ¶
type Document struct {
Version uint16 `json:"version"`
Sectors []Sector `json:"sectors"`
Contents []Content `json:"contents"`
// Lighting is opt-in in compiled v3 and requires FeatureLighting in addition
// to Feature. Nil preserves the legacy wire encoding and runtime behavior.
Lighting *Lighting `json:"lighting,omitempty"`
MaterialMapping *MaterialMapping `json:"material_mapping,omitempty"`
StaticSolids *StaticSolids `json:"static_solids,omitempty"`
}
Document is one completely compiled world. Sector order is stable because portal references use sector indexes.
type LightMotion ¶ added in v0.0.8
type LightMotion struct {
Version uint32 `json:"version"`
Offset Vec3 `json:"offset"`
PeriodSeconds float64 `json:"period_seconds"`
}
LightMotion version 1 moves a light smoothly from Position to Position+Offset and back once per PeriodSeconds. It is runtime direct lighting, never baked. The complete segment must stay within the ordinary light coordinate bounds.
type Lighting ¶ added in v0.0.8
type Lighting struct {
Version uint32 `json:"version"`
Ambient Vec3 `json:"ambient"`
Lights []PointLight `json:"lights"`
AmbientCube *AmbientCube `json:"ambient_cube,omitempty"`
Actors bool `json:"actors,omitempty"`
}
Lighting is the independently versioned world/lighting@1 payload. Ambient and point colors are linear RGB intensities in [0,1]. Lights retain authored order and global world coordinates, without sector assignment, prefab transforms, shadows, portal transport or PBR parameters.
type MaterialMapping ¶ added in v0.0.8
type MaterialMapping struct {
Version uint32 `json:"version"`
}
MaterialMapping opts a compiled v3 world into world/material-mapping@1. Every floor, ceiling and wall must then supply complete baked projections. Projection setup, authoring modes and anchors belong to the compiler.
type PointLight ¶ added in v0.0.8
type PointLight struct {
ID string `json:"id"`
Position Vec3 `json:"position"`
Color Vec3 `json:"color"`
Radius float64 `json:"radius"`
Motion *LightMotion `json:"motion,omitempty"`
}
PointLight is one bounded global light. ID is unique within Lighting; Radius is an influence radius in world units in [MinLightRadius, MaxCoordinate].
type Sector ¶
type Sector struct {
ID string `json:"id"`
SourceRoom string `json:"source_room"`
Instance string `json:"instance"`
Walls []Wall `json:"walls"`
Floor Plane `json:"floor"`
Ceiling Plane `json:"ceiling"`
FloorMaterial uint32 `json:"floor_material"`
CeilingMaterial uint32 `json:"ceiling_material"`
FloorUV *SurfaceUV `json:"floor_uv,omitempty"`
CeilingUV *SurfaceUV `json:"ceiling_uv,omitempty"`
}
Sector is a strictly convex CCW cell. SourceRoom and Instance retain the authoring identity after prefab expansion and decomposition.
type Solid ¶ added in v0.0.8
type Solid struct {
ID string `json:"id"`
Footprint []Vec2 `json:"footprint"`
Bottom Plane `json:"bottom"`
Top Plane `json:"top"`
SideMaterial uint32 `json:"side_material"`
TopMaterial uint32 `json:"top_material"`
BottomMaterial uint32 `json:"bottom_material"`
SideUV *SurfaceUV `json:"side_uv,omitempty"`
TopUV *SurfaceUV `json:"top_uv,omitempty"`
BottomUV *SurfaceUV `json:"bottom_uv,omitempty"`
Collision bool `json:"collision,omitempty"`
}
Solid is a strictly convex CCW extrusion between two elevation planes. Collision blocks movement but never makes Top a walkable floor. Optional mappings are shared by the indicated surface group; SideUV is not per-edge.
type Sprite ¶ added in v0.0.6
type Sprite struct {
AssetID uint32 `json:"asset_id"`
Facing SpriteFacing `json:"facing"`
Alpha SpriteAlpha `json:"alpha"`
Width float64 `json:"width"`
Height float64 `json:"height"`
OriginX float64 `json:"origin_x"`
OriginY float64 `json:"origin_y"`
}
type SpriteAlpha ¶ added in v0.0.6
type SpriteAlpha string
const ( SpriteCutout SpriteAlpha = "cutout" SpriteBlend SpriteAlpha = "blend" )
type SpriteFacing ¶ added in v0.0.6
type SpriteFacing string
const ( SpriteCameraFacing SpriteFacing = "camera-facing" SpriteUpright SpriteFacing = "upright" SpriteCross SpriteFacing = "cross" SpriteFixed SpriteFacing = "fixed" )
type StaticSolids ¶ added in v0.0.8
StaticSolids contains independently placed opaque volumes. They never alter the sector/portal graph. Hosts must advertise FeatureStaticSolids.
type SurfaceUV ¶ added in v0.0.8
type SurfaceUV struct {
Projections []UVProjection `json:"projections"`
Weights []float64 `json:"weights"`
}
SurfaceUV contains one planar/wrapped projection or three blended projections. Weights are constant per surface, finite, nonnegative and normalized to one within UVWeightTolerance. They apply to all material channels, not just color.
type UVPlane ¶ added in v0.0.8
type UVPlane struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Z float64 `json:"z"`
Offset float64 `json:"offset"`
}
UVPlane evaluates X*position.X+Y*position.Y+Z*position.Z+Offset. All coefficients and Offset are finite with absolute value at most 1e12.
type UVProjection ¶ added in v0.0.8
UVProjection is an authored-position affine mapping to texture repeats. Hosts evaluate these planes before clipping; no projection setup is inferred.
type Wall ¶
type Wall struct {
Start Vec2 `json:"start"`
End Vec2 `json:"end"`
Portal int32 `json:"portal"`
PortalWall uint16 `json:"portal_wall,omitempty"`
Material uint32 `json:"material"`
SourceEdge string `json:"source_edge"`
UV *SurfaceUV `json:"uv,omitempty"`
}
Wall is one directed sector boundary. Portal is the adjacent sector index, or -1 for an opaque wall. PortalWall is one plus the reciprocal wall index in compiled-world v3; zero is reserved for v1/v2 coincident portals and opaque walls. The paired directed edges define a rigid destination-to-source portal transform. SourceEdge is empty only for compiler-generated internal decomposition edges.
type WallProfile ¶ added in v0.0.8
WallProfile divides a wall where any of its four linear elevation functions cross. Heights 0/1 are source floor/ceiling; 2/3 are destination elevations already transformed into the source coordinate frame. It contains no mesh or renderer state and can be used by public builders and private hosts alike.
func NewWallProfile ¶ added in v0.0.8
func NewWallProfile(heights [4][2]float64, tolerance float64) (WallProfile, error)
NewWallProfile requires finite endpoint heights and a finite positive tolerance. The four pairs have at most six interior crossings.