Skip to content

Commit

Permalink
Merge pull request #11 from Galaco/dev
Browse files Browse the repository at this point in the history
Merge: dev->master
  • Loading branch information
Galaco authored Nov 5, 2018
2 parents b9ba153 + 3e574ae commit 06e43c6
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 77 deletions.
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![GoDoc](https://godoc.org/github.com/Galaco/bsp?status.svg)](https://godoc.org/github.com/Galaco/bsp)
[![Go report card](https://goreportcard.com/badge/github.com/galaco/bsp)](https://goreportcard.com/badge/github.com/galaco/bsp)

# Bsp
Go library for manipulating Source Engine .bsp map files.

Expand Down
4 changes: 2 additions & 2 deletions lump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"testing"
)

func TestgetReferenceLumpByIndex(t *testing.T) {
func TestGetReferenceLumpByIndex(t *testing.T) {
for i := 0; i < 64; i++ {
lump, _ := getReferenceLumpByIndex(i, 20)
if lump != getExpectedLump(i) {
t.Errorf("Lump type does not match expected for identifer: %i\n", i)
t.Errorf("Lump type does not match expected for identifer: %d\n", i)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lumps/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (lump *Game) GetStaticPropLump() *primitives.StaticPropLump {
case 11:
propLumpSize = int(unsafe.Sizeof(primitives.StaticPropV11{})) * int(numProps)
vprops := make([]primitives.StaticPropV11, numProps)
err = binary.Read(bytes.NewBuffer(sprpLump.Data[offset:offset+propLumpSize]), binary.LittleEndian, &vprops)
err = binary.Read(bytes.NewBuffer(sprpLump.Data[offset:]), binary.LittleEndian, &vprops)
if err != nil {
return nil
}
Expand Down
10 changes: 9 additions & 1 deletion lumps/lumps.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func (lump *LumpGeneric) ToBytes() []byte {
Helper info for a lump
*/
type LumpInfo struct {
length int32
length int32
version int32
}

/**
Expand All @@ -50,3 +51,10 @@ Set lump import length in bytes
func (info LumpInfo) SetLength(length int32) {
info.length = length
}

/**
Set bsp version of lump
*/
func (info LumpInfo) SetVersion(version int32) {
info.version = version
}
8 changes: 4 additions & 4 deletions primitives/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

type ColorRGBExponent32 struct {
R byte
G byte
B byte
Exponent byte
R uint8
G uint8
B uint8
Exponent int8
}

const MAX_POINTS_ON_FIXED_WINDING = 12
Expand Down
45 changes: 0 additions & 45 deletions primitives/game/game.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package game

import (
"github.com/go-gl/mathgl/mgl32"
)

const StaticPropLumpId = 1936749168

type Header struct {
Expand All @@ -29,44 +25,3 @@ type GenericGameLump struct {
Length int32
Data []byte
}

type StaticPropLump struct {
DictLump StaticPropDictLump
LeafLump StaticPropLeafLump
PropLumps []IStaticPropDataLump
}

// Note: Nothing below here is actually implemented, as its primarily game/version specific data.
type StaticPropDictLump struct {
DictEntries int32
Name []string // Slice length must equal dictEntries. Validation to be added
}
type StaticPropLeafLump struct {
LeafEntries int32
Leaf []uint16 // Slice length must equal leafEntries. Validation to be added
}

type IStaticPropDataLump interface {
GetOrigin() mgl32.Vec3
GetAngles() mgl32.Vec3
GetUniformScale() float32 //v11 onwards
GetPropType() uint16
GetFirstLeaf() uint16
GetLeafCount() uint16
GetSolid() uint8
GetFlags() uint8
GetSkin() int32
GetFadeMinDist() float32
GetFadeMaxDist() float32
GetLightingOrigin() mgl32.Vec3
GetForcedFadeScale() float32
GetMinDXLevel() uint16
GetMaxDXLevel() uint16
GetMinCPULevel() uint8
GetMaxCPULevel() uint8
GetMinGPULevel() uint8
GetMaxGPULevel() uint8
GetDiffuseModulation() float32 //v7 onwards
GetUnknown() float32 //v10 onwards
GetDisableXBox360() bool //v9 onwards
}
46 changes: 46 additions & 0 deletions primitives/game/staticprop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package game

import (
"github.com/go-gl/mathgl/mgl32"
)

type StaticPropLump struct {
DictLump StaticPropDictLump
LeafLump StaticPropLeafLump
PropLumps []IStaticPropDataLump
}

// Note: Nothing below here is actually implemented, as its primarily game/version specific data.
type StaticPropDictLump struct {
DictEntries int32
Name []string // Slice length must equal dictEntries. Validation to be added
}
type StaticPropLeafLump struct {
LeafEntries int32
Leaf []uint16 // Slice length must equal leafEntries. Validation to be added
}

type IStaticPropDataLump interface {
GetOrigin() mgl32.Vec3
GetAngles() mgl32.Vec3
GetUniformScale() float32 // v11 onwards
GetPropType() uint16
GetFirstLeaf() uint16
GetLeafCount() uint16
GetSolid() uint8
GetFlags() uint8
GetSkin() int32
GetFadeMinDist() float32
GetFadeMaxDist() float32
GetLightingOrigin() mgl32.Vec3
GetForcedFadeScale() float32 // v5 onwards
GetMinDXLevel() uint16 // v6+7 only
GetMaxDXLevel() uint16 // v6+7 only
GetMinCPULevel() uint8
GetMaxCPULevel() uint8
GetMinGPULevel() uint8
GetMaxGPULevel() uint8
GetDiffuseModulation() float32 // v7 onwards
GetUnknown() float32 // v10 onwards
GetDisableXBox360() bool // v9 onwards
}
7 changes: 3 additions & 4 deletions primitives/game/staticpropv10.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ type StaticPropV10 struct {
MaxGPULevel uint8
DiffuseModulation float32
Unknown float32
DisableXBox360 bool
_ [3]byte
//DisableXBox360 bool
}

func (l *StaticPropV10) GetOrigin() mgl32.Vec3 {
Expand Down Expand Up @@ -108,9 +107,9 @@ func (l *StaticPropV10) GetDiffuseModulation() float32 {
}

func (l *StaticPropV10) GetUnknown() float32 {
return l.Unknown
return 0
}

func (l *StaticPropV10) GetDisableXBox360() bool {
return l.DisableXBox360
return true
}
6 changes: 3 additions & 3 deletions primitives/game/staticpropv11.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
type StaticPropV11 struct {
Origin mgl32.Vec3
Angles mgl32.Vec3
UniformScale float32
PropType uint16
FirstLeaf uint16
LeafCount uint16
Expand All @@ -23,8 +22,9 @@ type StaticPropV11 struct {
MinGPULevel uint8
MaxGPULevel uint8
DiffuseModulation float32
Unknown float32
DisableXBox360 bool
UniformScale float32
_ [7]byte
}

func (l *StaticPropV11) GetOrigin() mgl32.Vec3 {
Expand Down Expand Up @@ -108,7 +108,7 @@ func (l *StaticPropV11) GetDiffuseModulation() float32 {
}

func (l *StaticPropV11) GetUnknown() float32 {
return l.Unknown
return 0
}

func (l *StaticPropV11) GetDisableXBox360() bool {
Expand Down
2 changes: 1 addition & 1 deletion primitives/visibility/visibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ func (vis *Vis) GetPVSForCluster(clusterId int16) []bool {
}

return visibleClusterIds
}
}
10 changes: 2 additions & 8 deletions versions/v19.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import (
"github.com/galaco/bsp/lumps"
)

// Returns an empty bsp v19 lump for the specified lump id
func Getv19Lump(index int) (lumps.ILump, error) {
var ret lumps.ILump
var err error
switch index {
default:
return Getv20Lump(index)
}

return ret, err
return Getv20Lump(index)
}
10 changes: 2 additions & 8 deletions versions/v21.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import (
"github.com/galaco/bsp/lumps"
)

// Returns an empty bsp v19 lump for the specified lump id
func Getv21Lump(index int) (lumps.ILump, error) {
var ret lumps.ILump
var err error
switch index {
default:
return Getv20Lump(index)
}

return ret, err
return Getv20Lump(index)
}
3 changes: 3 additions & 0 deletions versions/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package versions

import "github.com/galaco/bsp/lumps"

// Returns an empty bsp lump for the specified bsp version and lump id
// If a version is not 19,20,21 then a generic lump that holds
// raw bytes only ([]byte) is returned.
func GetLumpForVersion(bspVersion int, lumpId int) (lumps.ILump, error) {
switch bspVersion {
case 19:
Expand Down

0 comments on commit 06e43c6

Please sign in to comment.