Documentation
¶
Overview ¶
Code generated by internal/codegen/binary; DO NOT EDIT.
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 EncodeEmissionIntensity(value float64) (uint8, error)
- func MaterialIDs(d *Document) []uint32
- func SolidRendererTriangles(renderers *SolidRenderers) int
- func Validate(document *Document) error
- func ValidateAnimationPreset(p *AnimationPreset) error
- func ValidateAnimations(document *Document) error
- func ValidateEmission(document *Document) error
- func ValidateEnvironment(environment *Environment) error
- func ValidateEnvironmentSettings(settings EnvironmentSettings) error
- func ValidateLighting(lighting *Lighting) error
- func ValidateSolidRenderers(document *Document) error
- func ValidateStaticSolids(solids *StaticSolids) (err error)
- func ValidateSurfaceSecondary(s *SurfaceSecondary) error
- func ValidateSurfaceUV(mapping *SurfaceUV) error
- type Actor
- type AmbientCube
- type AnimationBinding
- type AnimationPreset
- type Animations
- type Content
- type Document
- type Emission
- type EmissionPulse
- type Environment
- type EnvironmentPalette
- type EnvironmentPreset
- type EnvironmentSettings
- type EnvironmentSun
- type FrameHorizontal
- type FramePiece
- type FrameVertical
- type LightMotion
- type Lighting
- type MaterialAnimation
- type MaterialEmission
- type MaterialLayers
- type MaterialMapping
- type Plane
- type PointLight
- type ResolvedEnvironment
- type Sector
- type Solid
- type SolidAttachment
- type SolidPrefab
- type SolidRenderers
- type Sprite
- type SpriteAlpha
- type SpriteFacing
- type StaticSolids
- type SurfaceSecondary
- type SurfaceUV
- type UVPlane
- type UVProjection
- type Vec2
- type Vec3
- type Wall
- type WallFrameConfig
- type WallFrameRegion
- type WallProfile
Constants ¶
const ( AnimationVersion = uint32(1) FeatureAnimations = cartridge.FeatureWorldAnimationsV1 MaxAnimationPresets = 64 MaxMaterialAnimations = 196 MaxAnimationFrames = 64 MaxAnimationSeconds = 86400.0 )
const ( FeatureEmission = cartridge.FeatureWorldEmissionV1 EmissionVersion = uint32(1) MaxEmissionMaterials = 196 MaxEmissionIntensity = 8.0 )
const ( DefaultEnvironmentTimeOfDay = 15.0 DefaultEnvironmentCloudAmount = .35 )
const ( MaterialMappingVersion = uint32(1) FeatureMaterialMapping = cartridge.FeatureWorldMaterialMappingV1 MaxUVProjectionValue = 1e12 UVWeightTolerance = 1e-9 )
const ( MaterialLayersVersion = uint32(1) FeatureMaterialLayers = cartridge.FeatureWorldMaterialLayersV1 FrameCoverageMain = "main" FrameCoverageOpaque = "opaque" FrameCoverageMasked = "masked" // Each wall has <=7 profile intervals, <=2 solid spans, <=2 band-overlap // branches, <=3 vertical columns and <=3 horizontal rows. Every cell is a quad. MaxFrameRegionsPerWall = 7 * 2 * 2 * 3 * 3 MaxFrameRegionVertices = 4 MaxFrameRegions = 32768 )
const ( SolidRenderersVersion = uint32(1) FeatureSolidRenderers = "world/solid-renderers@1" MaxSolidPrefabs = 64 MaxSolidRendererTriangles = 65536 )
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 EnvironmentVersion = uint32(1) FeatureEnvironment = cartridge.FeatureWorldEnvironmentV1 MaxEncodedSize = 8 * 1024 * 1024 MaxSectors = 256 MaxWalls = 8192 MaxWallsPerSector = 256 MaxContents = 4096 // MaxLights bounds authored sources, including lights compiled into an // offline lightmap. It does not enlarge the runtime direct-light budget. MaxLights = 4096 MaxRuntimeLights = 50 MinLightRadius = 0.001 MaxIdentifierBytes = 128 MaxKindBytes = 128 MaxTags = 8 MaxTagBytes = 64 MaxCoordinate = 1_000_000.0 MinEdgeLength = 1e-6 MinClearance = 1e-6 )
const BinaryMagic = "KWR1"
const SolidBinaryMagic = "KWR2"
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") ErrEnvironment = errors.New("world environment is invalid") ErrStaticSolids = errors.New("world static solids are invalid") ErrCanonical = errors.New("world payload is not canonical") )
Functions ¶
func EncodeEmissionIntensity ¶ added in v0.0.11
func MaterialIDs ¶ added in v0.0.10
MaterialIDs returns canonical deduplicated atlas order. All legacy primary references retain their original order, followed by secondary references, then non-main frame regions, in sector/floor/ceiling/wall order.
func SolidRendererTriangles ¶ added in v0.0.13
func SolidRendererTriangles(renderers *SolidRenderers) int
SolidRendererTriangles counts immutable triangles in validated extrusions: two triangles per side and n-2 triangles on each cap.
func Validate ¶
Validate checks a complete compiled document before a host prepares private indexes or publishes a mounted resource.
func ValidateAnimationPreset ¶ added in v0.0.11
func ValidateAnimationPreset(p *AnimationPreset) error
ValidateAnimationPreset checks kind-specific bounds and rejects fields from other kinds. Flipbook holds frame zero outside its optional repeat burst.
func ValidateAnimations ¶ added in v0.0.11
ValidateAnimations validates presets and bindings together, including complete actor references and nonrecursive frame targets. Texture existence is checked by the level compiler and host against packaged assets.
func ValidateEmission ¶ added in v0.0.11
func ValidateEnvironment ¶ added in v0.0.12
func ValidateEnvironment(environment *Environment) error
func ValidateEnvironmentSettings ¶ added in v0.0.12
func ValidateEnvironmentSettings(settings EnvironmentSettings) error
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 ValidateSolidRenderers ¶ added in v0.0.13
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 ValidateSurfaceSecondary ¶ added in v0.0.10
func ValidateSurfaceSecondary(s *SurfaceSecondary) error
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
Pitch float64
Roll float64
Scale Vec3
Sprite *Sprite
Tags []string
Animation *AnimationBinding
}
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
NegativeX Vec3
PositiveY Vec3
NegativeY Vec3
PositiveZ Vec3
NegativeZ Vec3
}
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 AnimationBinding ¶ added in v0.0.11
AnimationBinding selects a named preset and a nonnegative clock offset.
type AnimationPreset ¶ added in v0.0.11
type AnimationPreset struct {
Name string
Kind string
Frames []uint32
FPS float64
IntervalSeconds float64
Flow Vec2
Amplitude float64
SurfaceAmplitude float64
Opacity *float64
PixelSize uint32
Frequency float64
Speed float64
Axis Vec3
Pivot Vec3
Offset Vec3
PeriodSeconds float64
}
AnimationPreset contains exactly the fields relevant to Kind. Speeds are radians/second for spin and liquid; liquid flow and amplitude use UV units. SurfaceAmplitude is visual displacement in world metres on horizontal up-facing surfaces. Opacity defaults to 1; PixelSize defaults to 0 (continuous sampling). Axis, Pivot and Offset are actor-local, before actor scale and orientation.
type Animations ¶ added in v0.0.11
type Animations struct {
Version uint32
Presets []AnimationPreset
Materials []MaterialAnimation
}
Animations is the optional world/animations@1 payload in compiled world v3.
type Content ¶
type Content struct {
ID string
SourceID string
Instance string
Kind string
Sector uint32
Position Vec3
Actor *Actor
}
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
Sectors []Sector
Contents []Content
// 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
MaterialMapping *MaterialMapping
StaticSolids *StaticSolids
MaterialLayers *MaterialLayers
Animations *Animations
Emission *Emission
Environment *Environment
SolidRenderers *SolidRenderers
}
Document is one completely compiled world. Sector order is stable because portal references use sector indexes.
type Emission ¶ added in v0.0.11
type Emission struct {
Version uint32
Materials []MaterialEmission
}
Emission is an optional world/emission@1 payload. Intensity is an eight-bit linear-albedo multiplier, decoded as code*8/255. Pulse is independent of the material's optional flipbook/liquid animation; these are two bounded effects.
type EmissionPulse ¶ added in v0.0.11
EmissionPulse has depth is the fraction of intensity removed at the dimmest point. A cosine pulse begins at full brightness and reaches its minimum after half a period.
func (EmissionPulse) Validate ¶ added in v0.0.11
func (p EmissionPulse) Validate() error
type Environment ¶ added in v0.0.12
type Environment struct {
Version uint32
Preset EnvironmentPreset
Palette EnvironmentPalette
Sun *EnvironmentSun
TimeOfDay *float64
CloudAmount *float64
}
Environment is the optional world/environment@1 payload, available in compiled-world v3. Preset defaults are fixed by this payload version. Palette affects sky appearance only, independently of surface illumination.
type EnvironmentPalette ¶ added in v0.0.12
type EnvironmentPalette string
const ( EnvironmentPaletteDefault EnvironmentPalette = "default" EnvironmentPaletteViolet EnvironmentPalette = "violet" EnvironmentPaletteTwilight EnvironmentPalette = "twilight" )
type EnvironmentPreset ¶ added in v0.0.12
type EnvironmentPreset string
const ( EnvironmentDaylight EnvironmentPreset = "daylight" EnvironmentSpace EnvironmentPreset = "space" EnvironmentCartoon EnvironmentPreset = "cartoon" EnvironmentFantasy EnvironmentPreset = "fantasy" )
type EnvironmentSettings ¶ added in v0.0.12
EnvironmentSettings is a complete live override of the clock and cloud coverage. TimeOfDay is hours in [0,24); CloudAmount is in [0,1]. A live clock overrides the authored fixed sun. Preset and palette remain authored.
type EnvironmentSun ¶ added in v0.0.12
type EnvironmentSun struct {
Azimuth float64 `yaml:"azimuth"`
Elevation float64 `yaml:"elevation"`
}
EnvironmentSun supplies a fixed global sun direction in degrees. Azimuth is [0,360), measured from +X toward +Y. Elevation is [0,90] above the XY plane. If present both angles are explicit; omission selects the preset defaults.
type FrameHorizontal ¶ added in v0.0.10
type FrameHorizontal struct {
Height, Repeat float64
Offset Vec2
Piece FramePiece
}
type FramePiece ¶ added in v0.0.10
FramePiece is an already resolved sheet region and its tile coverage class.
type FrameVertical ¶ added in v0.0.10
type FrameVertical struct {
Width, Repeat, Phase float64
Offset Vec2
Piece FramePiece
}
type LightMotion ¶ added in v0.0.8
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
Ambient Vec3
Lights []PointLight
AmbientCube *AmbientCube
Actors bool
}
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 MaterialAnimation ¶ added in v0.0.11
type MaterialEmission ¶ added in v0.0.11
type MaterialEmission struct {
Material uint32
Intensity uint8
Pulse *EmissionPulse
Lights []string
}
type MaterialLayers ¶ added in v0.0.10
type MaterialLayers struct {
Version uint32
}
type MaterialMapping ¶ added in v0.0.8
type MaterialMapping struct {
Version uint32
}
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
Position Vec3
Color Vec3
Radius float64
Motion *LightMotion
}
PointLight is one bounded global light. ID is unique within Lighting; Radius is an influence radius in world units in [MinLightRadius, MaxCoordinate].
type ResolvedEnvironment ¶ added in v0.0.12
type ResolvedEnvironment struct {
Preset EnvironmentPreset
SkyZenith Vec3
SkyHorizon Vec3
SkyNadir Vec3
CloudColor Vec3
SunDiskColor Vec3
SunDirection Vec3
SunColor Vec3
SunIntensity float64
Ambient Vec3
AmbientCube AmbientCube
TimeOfDay float64
CloudAmount float64
}
ResolvedEnvironment supplies bounded linear RGB defaults to consumers without runtime allocation. SunDirection points toward the light; incoming rays travel in the opposite direction. AmbientCube is outdoor fill, not global indoor illumination. Consumers must restrict fill and sun visibility using sky openings and geometry. Decorative sky elements add no additional lights.
func ResolveEnvironment ¶ added in v0.0.12
func ResolveEnvironment(environment *Environment) (ResolvedEnvironment, error)
ResolveEnvironment validates and resolves the versioned preset. Palette overrides never modify the sun or ambient light defaults. Calling this at world preparation keeps preset work outside the render loop.
func ResolveEnvironmentSettings ¶ added in v0.0.12
func ResolveEnvironmentSettings(environment *Environment, settings EnvironmentSettings) (ResolvedEnvironment, error)
ResolveEnvironmentSettings applies a validated live clock to the authored style. It allocates no memory and never changes the authored payload.
type Sector ¶
type Sector struct {
ID string
SourceRoom string
Instance string
Walls []Wall
Floor Plane
Ceiling Plane
FloorMaterial uint32
CeilingMaterial uint32
FloorUV *SurfaceUV
CeilingUV *SurfaceUV
FloorSecondary *SurfaceSecondary
CeilingSecondary *SurfaceSecondary
// Sky opens the ceiling visually and to environment lighting. The finite
// ceiling plane still bounds navigation, portals and spatial queries.
Sky bool
}
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
Footprint []Vec2
Bottom Plane
Top Plane
SideMaterial uint32
TopMaterial uint32
BottomMaterial uint32
SideUV *SurfaceUV
TopUV *SurfaceUV
BottomUV *SurfaceUV
Collision bool
}
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 SolidAttachment ¶ added in v0.0.13
type SolidPrefab ¶ added in v0.0.13
type SolidRenderers ¶ added in v0.0.13
type SolidRenderers struct {
Version uint32
Prefabs []SolidPrefab
Actors []SolidAttachment
}
SolidRenderers retains reusable local solid geometry separately from static world geometry. Actors bind existing content identities to prefab identities.
type Sprite ¶ added in v0.0.6
type Sprite struct {
AssetID uint32
Facing SpriteFacing
Alpha SpriteAlpha
Width float64
Height float64
OriginX float64
OriginY float64
}
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 SurfaceSecondary ¶ added in v0.0.10
type SurfaceUV ¶ added in v0.0.8
type SurfaceUV struct {
Projections []UVProjection
Weights []float64
}
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
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
End Vec2
Portal int32
PortalWall uint16
Material uint32
SourceEdge string
UV *SurfaceUV
Secondary *SurfaceSecondary
FrameRegions []WallFrameRegion
// FrameCompiled preserves static-frame participation when a portal has no
// exposed solid spans and thus no region records.
FrameCompiled bool
// Sky is an opaque boundary rendered as the environment. It is valid only
// in a sky sector and cannot participate in a portal. Confinement remains.
Sky bool
}
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 WallFrameConfig ¶ added in v0.0.10
type WallFrameConfig struct {
Top, Bottom FrameHorizontal
Start, End FrameVertical
Patches [4]FramePiece
PerimeterOffset float64
}
WallFrameConfig is a build-time recipe; it is never serialized to the host. Patches are top/start, top/end, bottom/start, bottom/end in that order.
type WallFrameRegion ¶ added in v0.0.10
type WallFrameRegion struct {
Vertices []Vec2
Material uint32
UV *SurfaceUV
Coverage string
RepeatU bool
RepeatV bool
}
WallFrameRegion is one complete, nonoverlapping wall partition, already selected by the builder. Vertices use X=edge fraction and Y=world elevation, ordered counterclockwise in this two-dimensional coordinate system. Main regions retain the wall's mapping and have no region UV. Opaque regions sample their sole material; masked regions blend over the wall's main material.
func CompileWallFrame ¶ added in v0.0.10
func CompileWallFrame(w Wall, p WallProfile, f WallFrameConfig) ([]WallFrameRegion, error)
CompileWallFrame partitions visible solid spans into at most 252 convex regions. Bands follow affine floor/ceiling profiles; opposing envelopes crop proportionally when a face is shorter than their combined requested sizes. Original authored corners and texture IDs have already been resolved by the builder. The output contains every main and frame region with no overlap.
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.
func ProfileForWall ¶ added in v0.0.10
func ProfileForWall(d *Document, sector, index int) (WallProfile, error)
ProfileForWall resolves destination endpoints and elevation translation using the compiled portal pair. Callers validate the world before invoking it.