terrain

package
v0.0.0-...-382259f Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const ChunkBufferSize = 9*9 + 8*8
View Source
const ChunkSize = TileSize / 16
View Source
const TileSize = 533.33333

Variables

View Source
var (
	MapVersion         = chunked.CnkID("MVER")
	MainTileIndex      = chunked.CnkID("MAIN")
	MapIndexHeader     = chunked.CnkID("MPHD")
	MapWMO             = chunked.CnkID("MWMO")
	MapChunkInfo       = chunked.CnkID("MCIN")
	MapTextures        = chunked.CnkID("MTEX")
	TileHeader         = chunked.CnkID("MHDR")
	M2Models           = chunked.CnkID("MMDX")
	M2FilenameOffsets  = chunked.CnkID("MMID")
	WMOFilenameOffsets = chunked.CnkID("MWID")
	DoodadDefs         = chunked.CnkID("MDDF")
	WMODefs            = chunked.CnkID("MODF")
	Chunk              = chunked.CnkID("MCNK")
	Normals            = chunked.CnkID("MCNR")
	Heights            = chunked.CnkID("MCVT")
	Layer              = chunked.CnkID("MCLY")
	CollisionObjects   = chunked.CnkID("MCRF")
	ShadowMap          = chunked.CnkID("MCSH")
	Alpha              = chunked.CnkID("MCAL")
	Liquids            = chunked.CnkID("MCLQ")
	SoundEmitters      = chunked.CnkID("MCSE")
)

Functions

This section is empty.

Types

type C3Vector

type C3Vector [3]float32

type CAaBox

type CAaBox struct {
	Min C3Vector
	Max C3Vector
}

type CAaSphere

type CAaSphere struct {
	Position C3Vector
	Radius   float32
}

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          C3Vector
	OffsetMCCV        uint32
	Unused1           uint32
	Unused2           uint32
}

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    CAaSphere
		Direction C3Vector
		Velocity  float32
		Amplitude float32
		Frequency float32
	}
}

type ChunkOldSoundEmitter

type ChunkOldSoundEmitter struct {
	SoundPointID     uint32
	SoundNameID      uint32
	Position         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 C3Vector // 0x08
	Rotation 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 MapReader

type MapReader struct {
	Name string
	Source
	Index
}

func NewMapReader

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

func (*MapReader) GetChunkByIndex

func (mr *MapReader) GetChunkByIndex(idx *TileChunkLookupIndex) (*ChunkData, error)

func (*MapReader) GetChunkByPos

func (mr *MapReader) GetChunkByPos(x, y float32) (*ChunkData, error)

func (*MapReader) ReadTile

func (mr *MapReader) ReadTile(x, y int) (*MapTile, error)

type MapTile

type MapTile struct {
	// MVER
	Version uint32

	// MHDR
	Flags uint32

	// MCIN
	ChunkInfo [16 * 16]ChunkInfo

	// MTEX
	Textures []string

	// MMDX
	M2Models []byte

	// MMID
	M2FilenameOffsets []uint32

	// MWMO
	WMOModels []byte

	// MWID
	WMOFilenameOffsets []uint32

	// MDDF
	DoodadDefs []DoodadDef

	// MODF
	WMODefs []WMODef

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

type Source

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

type TileChunkLookupIndex

type TileChunkLookupIndex struct {
	TileIndexX, TileIndexY   int
	ChunkIndexX, ChunkIndexY int
}

func FindTileChunkIndex

func FindTileChunkIndex(x, y float32) (*TileChunkLookupIndex, error)

Since maps are split into a hierarchy of tiles and chunks, we have to find their path from global coordinates.

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 C3Vector
	Rotation C3Vector

	Extent    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