terrain

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package terrain implements decoders for the WDT and ADT terrain formats.

Index

Constants

View Source
const (
	BlockSize = 533.33333
	ChunkSize = BlockSize / 16
)
View Source
const ChunkBufferSize = 9*9 + 8*8

Variables

View Source
var (
	MapVersion               = chunked.ID("MVER")
	MainTileIndex            = chunked.ID("MAIN")
	MapIndexHeader           = chunked.ID("MPHD")
	MapObject                = chunked.ID("MWMO")
	MapChunkInfo             = chunked.ID("MCIN")
	MapTextures              = chunked.ID("MTEX")
	BlockHeader              = chunked.ID("MHDR")
	MapModels                = chunked.ID("MMDX")
	MapModelFilenamesOffsets = chunked.ID("MMID")
	MapObjectFilenameOffsets = chunked.ID("MWID")
	DoodadDefs               = chunked.ID("MDDF")
	MapObjectDefs            = chunked.ID("MODF")
	Chunk                    = chunked.ID("MCNK")
	Normals                  = chunked.ID("MCNR")
	Heights                  = chunked.ID("MCVT")
	Layer                    = chunked.ID("MCLY")
	CollisionObjects         = chunked.ID("MCRF")
	ShadowMap                = chunked.ID("MCSH")
	Alpha                    = chunked.ID("MCAL")
	Liquids                  = chunked.ID("MCLQ")
	SoundEmitters            = chunked.ID("MCSE")
)
View Source
var (
	DefaultMap = MapParam{
		BlockSize: tempest.C2iVector{
			X: 64,
			Y: 64,
		},
	}
)

Functions

func CalcBlockCornerPos

func CalcBlockCornerPos(m *MapParam, bi BlockIndex) (pos tempest.C2Vector, err error)

Using a BlockIndex, return the in-world XY position of the corner of this. Note that this does not return the CENTER of the block, only the lowest corner. For instance, 32,32 -> 0,0

Types

type BlockIndex

type BlockIndex tempest.C2iVector

func CalcBlockIndex

func CalcBlockIndex(m *MapParam, pos tempest.C2Vector) (bi BlockIndex, err error)

Using map parameters, calculate what the block index of a position is. Will error if pos is out of bounds.

type ChunkAlphaMap

type ChunkAlphaMap [64 * 64]byte

type ChunkData

type ChunkData struct {
	ChunkHeader

	// MCNR
	Normals    [ChunkBufferSize][3]byte
	NormalsPad [13]byte

	// MCVT
	Heights [ChunkBufferSize]float32

	// MCLY
	Layer []ChunkLayer

	// MCRF
	CollisionDoodads []uint32
	CollisionWMOs    []uint32

	// MCSH
	ShadowMap [64]uint64

	// MCAL
	AlphaMaps []ChunkAlphaMap

	// MCLQ
	Liquids ChunkLiquids

	// MCSE
	OldSoundEmitters []ChunkOldSoundEmitter
}

type ChunkHeader

type ChunkHeader struct {
	Flags  uint32
	IndexX uint32
	IndexY uint32
	// Radius            float32
	NumLayers         uint32
	NumDoodadRefs     uint32
	OffsetHeight      uint32
	OffsetNormal      uint32
	OffsetLayer       uint32
	OffsetRefs        uint32
	OffsetAlpha       uint32
	SizeAlpha         uint32
	OffsetShadow      uint32
	SizeShadow        uint32
	AreaID            uint32
	NumMapObjRefs     uint32
	Holes             uint16
	Pad0              uint16
	PredTex           [8]uint16
	NumEffectDoodad   [8]byte
	OffsetSndEmitters uint32
	NumSndEmitters    uint32
	OffsetLiquid      uint32
	SizeLiquid        uint32
	Position          tempest.C3Vector
	OffsetMCCV        uint32
	Unused1           uint32
	Unused2           uint32
}

type ChunkIndex

type ChunkIndex tempest.C2iVector

func CalcChunkIndex

func CalcChunkIndex(m *MapParam, pos tempest.C2Vector) (ci ChunkIndex, err error)

Using 2d position vector, determine what chunk slot this position falls into. Pos must be a valid position before calling. Call CalcBlockIndex to be sure.

type ChunkInfo

type ChunkInfo struct {
	Offset uint32
	Size   uint32
	Flags  uint32
	Pad    uint32
}

ChunkInfo Pointers to MCNK chunks and their sizes.

type ChunkLayer

type ChunkLayer struct {
	TextureID   uint32
	Flags       uint32 // only use_alpha_map is implemented
	OffsetAlpha uint32
	EffectID    uint16
	Pad         uint16
}

type ChunkLiquids

type ChunkLiquids struct {
	MinHeight float32
	MaxHeight float32

	Verts [9 * 9]struct {
		Data      [4]byte
		FloatData float32
	}

	Tiles         [8 * 8]byte
	NumFlowValues uint32

	FlowValues [2]struct {
		Sphere    tempest.CAaSphere
		Direction tempest.C3Vector
		Velocity  float32
		Amplitude float32
		Frequency float32
	}
}

type ChunkOldSoundEmitter

type ChunkOldSoundEmitter struct {
	SoundPointID     uint32
	SoundNameID      uint32
	Position         tempest.C3Vector
	MinDistance      float32
	MaxDistance      float32
	CutoffDistance   float32
	StartTime        uint16
	EndTime          uint16
	Mode             uint16
	GroupSilenceMin  uint16
	GroupSilenceMax  uint16
	PlayInstancesMin uint16
	PlayInstancesMax uint16
	LoopCountMin     byte
	LoopCountMax     byte
	InterSoundGapMin uint16
	InterSoundGapMax uint16
}

type Dir

type Dir struct {
	Location string
}

func (*Dir) Exists

func (d *Dir) Exists(at string) bool

func (*Dir) ReadFile

func (d *Dir) ReadFile(at string) (io.ReadCloser, error)

type DoodadDef

type DoodadDef struct {
	// NameID references an entry in the MMID chunk, specifying the model to use.
	NameID   uint32 // 0x00
	UniqueID uint32 // 0x04

	Position tempest.C3Vector // 0x08
	Rotation tempest.C3Vector // 0x14

	Scale uint16 // 0x20
	Flags uint16 // 0x22
}

DoodadDef Placement information for doodads (M2 models). Additional to this, the models to render are referenced in each MCRF chunk.

type HeaderFlags

type HeaderFlags uint32
const (
	WDTUsesGlobalWMO HeaderFlags = 1 << iota
	ADTHasMCCV
	ADTHasBigAlpha
)

type Index

type Index struct {
	// MVER
	Version uint32

	// MPHD
	HeaderFlags HeaderFlags

	// MAIN
	Tiles [64 * 64]TileIndex
}

type MapBlock

type MapBlock struct {
	// MVER
	Version uint32

	// MHDR
	Flags uint32

	// MCIN
	ChunkInfo [16 * 16]ChunkInfo

	// MTEX
	Textures []string

	// MMDX
	MapModels []byte // m2 files

	// MMID
	MapModelFilenameOffsets []uint32

	// MWMO
	MapObjects []byte // wmo files

	// MWID
	MapObjectFilenameOffsets []uint32

	// MDDF
	DoodadDefs []DoodadDef

	// MODF
	MapObjectDefs []WMODef

	// MCNK * 16 * 16
	ChunkData [16][16]*ChunkData
}

type MapParam

type MapParam struct {
	BlockSize tempest.C2iVector
}

type MapReader

type MapReader struct {
	Name string
	Source
	Index
}

func NewMapReader

func NewMapReader(src Source, build vsn.Build, name string) (*MapReader, error)

func (*MapReader) ReadBlock

func (mr *MapReader) ReadBlock(x, y int) (*MapBlock, error)

type Source

type Source interface {
	ReadFile(at string) (io.ReadCloser, error)
	Exists(at string) bool
}

type TileFlags

type TileFlags uint64
const (
	TileHasTerrain TileFlags = 1 << iota
)

type TileIndex

type TileIndex struct {
	// Exists bool
	// Flags  uint32
	// Unk3   uint32
	Flags TileFlags
}

type WMODef

type WMODef struct {
	NameID   uint32
	UniqueID uint32

	Position tempest.C3Vector
	Rotation tempest.C3Vector

	Extent    tempest.CAaBox
	Flags     uint16
	DoodadSet uint16
	NameSet   uint16
	Scale     uint16
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL