func (e *Entity) initialize() {
	// Player positions are calculated differently
	if e.isPlayer() {
		xyProp := e.FindProperty(propVecOriginPlayerXY)
		zProp := e.FindProperty(propVecOriginPlayerZ)

		e.position = func() r3.Vector {
			xy := xyProp.value.VectorVal
			z := float64(zProp.value.FloatVal)
			return r3.Vector{
				X: xy.X,
				Y: xy.Y,
				Z: z,
			}
		}
	} else {
		cellBitsProp := e.FindProperty(propCellBits)
		cellXProp := e.FindProperty(propCellX)
		cellYProp := e.FindProperty(propCellY)
		cellZProp := e.FindProperty(propCellZ)
		offsetProp := e.FindProperty(propVecOrigin)

		e.position = func() r3.Vector {
			cellWidth := 1 << uint(cellBitsProp.value.IntVal)
			cellX := cellXProp.value.IntVal
			cellY := cellYProp.value.IntVal
			cellZ := cellZProp.value.IntVal
			offset := offsetProp.value.VectorVal

			return r3.Vector{
				X: coordFromCell(cellX, cellWidth, offset.X),
				Y: coordFromCell(cellY, cellWidth, offset.Y),
				Z: coordFromCell(cellZ, cellWidth, offset.Z),
			}
		}
	}
}
// Sets up the Entity.Position() function
// Necessary because FindProperty() is fairly slow
// This way we only need to find the necessary properties once
Sets up the Entity.Position() function
Necessary because FindProperty() is fairly slow
This way we only need to find the necessary properties once
// Sets up the Entity . Position () function // Necessary because FindProperty () is fairly slow // This way we only need to find the necessary properties once
func (e *Entity) initialize() {
	if e.isPlayer() {
		xyProp := e.FindProperty(propVecOriginPlayerXY)
		zProp := e.FindProperty(propVecOriginPlayerZ)
		e.position = func() r3.Vector {
			xy := xyProp.value.VectorVal
			z := float64(zProp.value.FloatVal)
			return r3.Vector{
				X: xy.X,
				Y: xy.Y,
				Z: z,
			}
		}
	} else {
		cellBitsProp := e.FindProperty(propCellBits)
		cellXProp := e.FindProperty(propCellX)
		cellYProp := e.FindProperty(propCellY)
		cellZProp := e.FindProperty(propCellZ)
		offsetProp := e.FindProperty(propVecOrigin)
		e.position = func() r3.Vector {
			cellWidth := 1 << uint(cellBitsProp.value.IntVal)
			cellX := cellXProp.value.IntVal
			cellY := cellYProp.value.IntVal
			cellZ := cellZProp.value.IntVal
			offset := offsetProp.value.VectorVal
			return r3.Vector{
				X: coordFromCell(cellX, cellWidth, offset.X),
				Y: coordFromCell(cellY, cellWidth, offset.Y),
				Z: coordFromCell(cellZ, cellWidth, offset.Z),
			}
		}
	}
}
func ( e * Entity ) initialize ( ) { if e . isPlayer ( ) { xyProp := e . FindProperty ( propVecOriginPlayerXY ) zProp := e . FindProperty ( propVecOriginPlayerZ ) e . position = func ( ) r3 . Vector { xy := xyProp . value . VectorVal z := float64 ( zProp . value . FloatVal ) return r3 . Vector { X : xy . X , Y : xy . Y , Z : z , } } } else { cellBitsProp := e . FindProperty ( propCellBits ) cellXProp := e . FindProperty ( propCellX ) cellYProp := e . FindProperty ( propCellY ) cellZProp := e . FindProperty ( propCellZ ) offsetProp := e . FindProperty ( propVecOrigin ) e . position = func ( ) r3 . Vector { cellWidth := 1 << uint ( cellBitsProp . value . IntVal ) cellX := cellXProp . value . IntVal cellY := cellYProp . value . IntVal cellZ := cellZProp . value . IntVal offset := offsetProp . value . VectorVal return r3 . Vector { X : coordFromCell ( cellX , cellWidth , offset . X ) , Y : coordFromCell ( cellY , cellWidth , offset . Y ) , Z : coordFromCell ( cellZ , cellWidth , offset . Z ) , } } } }
Sets up the Entity.Position() function
Necessary because FindProperty() is fairly slow
This way we only need to find the necessary properties once
Sets up the Entity . Position () function Necessary because FindProperty () is fairly slow This way we only need to find the necessary properties once
// Player positions are calculated differently