Skip to content

Commit

Permalink
Improved test coverage, better code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Galaco committed Mar 21, 2019
1 parent 1eed777 commit 91a5bef
Show file tree
Hide file tree
Showing 56 changed files with 2,326 additions and 240 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![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)
[![GolangCI](https://golangci.com/badges/github.com/galaco/bsp.svg)](https://golangci.com)
[![Build Status](https://travis-ci.com/Galaco/bsp.svg?branch=dev)](https://travis-ci.com/Galaco/bsp)
[![Build Status](https://travis-ci.com/Galaco/bsp.svg?branch=master)](https://travis-ci.com/Galaco/bsp)
[![CircleCI](https://circleci.com/gh/Galaco/bsp.svg?style=svg)](https://circleci.com/gh/Galaco/bsp)

# Bsp
Expand Down Expand Up @@ -105,8 +105,9 @@ func main() {
```

## Real World examples
* Replace game_text newline placeholder characters (avoids Hammer crash) as a compile step: [https://github.com/Galaco/CS-GO-game_text-newline-inserter/tree/golang](https://github.com/Galaco/CS-GO-game_text-newline-inserter/tree/golang)
* Proof of concept BSP viewer: [https://github.com/Galaco/Gource-Engine](https://github.com/Galaco/Gource-Engine)
* Insert game_text newline placeholder characters (avoids Hammer crash) as a compile step: [https://github.com/Galaco/CS-GO-game_text-newline-inserter/tree/golang](https://github.com/Galaco/CS-GO-game_text-newline-inserter/tree/golang)
* Bspzip filelist generator from a mountable resource directory: [https://github.com/Galaco/bspzip-traverser](https://github.com/Galaco/bspzip-traverser)
* Proof of concept BSP viewer: [https://github.com/Galaco/Lambda-Client](https://github.com/Galaco/Lambda-Client)


# Contributing
Expand Down
5 changes: 5 additions & 0 deletions internal/versions/v20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ func TestGetv20Lump(t *testing.T) {
reflect.TypeOf(l),
reflect.TypeOf(lumps.Visibility{}))
}

_, err := Getv20Lump(65)
if err == nil {
t.Error("invalid lump index provided, but not error returned")
}
}
4 changes: 2 additions & 2 deletions lump.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package bsp

import (
"fmt"
"github.com/galaco/bsp/internal/versions"
"github.com/galaco/bsp/lumps"
"log"
)

// Container for a lump. Also includes metadata about the lump.
Expand Down Expand Up @@ -58,7 +58,7 @@ func (l *Lump) GetLength() int32 {
// Return an instance of a Lump for a given offset.
func getReferenceLumpByIndex(index int, version int32) (lumps.ILump, error) {
if index < 0 || index > 63 {
log.Fatalf("Invalid lump index: %d provided\n", index)
return nil, fmt.Errorf("invalid lump index: %d provided", index)
}

return versions.GetLumpForVersion(int(version), index)
Expand Down
44 changes: 44 additions & 0 deletions lump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,50 @@ func TestGetReferenceLumpByIndex(t *testing.T) {
}
}

_, err := getReferenceLumpByIndex(65, 20)
if err == nil {
t.Error("invalid lump provided, but no error returned")
}
}

func TestLump_GetContents(t *testing.T) {

}

func TestLump_GetLength(t *testing.T) {
sut := Lump{}
sut.length = 32
if sut.GetLength() != 32 {
t.Error("incorrect length returned for lump")
}
}

func TestLump_GetRawContents(t *testing.T) {
t.Skip()
}

func TestLump_SetContents(t *testing.T) {
t.Skip()
}

func TestLump_SetId(t *testing.T) {
sut := Lump{}
sut.SetId(LumpPakfile)

if sut.index != LumpPakfile {
t.Error("incorrect lump id")
}
}

func TestLump_SetRawContents(t *testing.T) {
sut := Lump{}
data := []byte{0, 1, 4, 3, 2}
sut.SetRawContents(data)
for idx, b := range sut.GetRawContents() {
if data[idx] != b {
t.Error("raw lump data mismatch")
}
}
}

func getExpectedLump(index int) lumps.ILump {
Expand Down
5 changes: 3 additions & 2 deletions lumps/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (lump *Game) Unmarshall(raw []byte, length int32) {

// First reconstruct the header to be of the right size
lumpCount := binary.LittleEndian.Uint32(raw[:4])
lump.Header = lump.Header.SetLumpCount(int32(lumpCount))
lump.Header.SetLumpCount(int32(lumpCount))

// Read header
lump.Header.GameLumps = make([]primitives.LumpDef, lumpCount)
Expand Down Expand Up @@ -84,14 +84,15 @@ func (lump *Game) Marshall() ([]byte, error) {
return buf.Bytes(), err
}

// This update the lumps offsets to be relative to the lump, rather
// UpdateInternalOffsets updates the lumps offsets to be relative to the lump, rather
// than the bsp start
func (lump *Game) UpdateInternalOffsets(fileOffset int32) *Game {
lump.LumpOffset = fileOffset

return lump
}

// GetStaticPropLump returns the staticprop lump
func (lump *Game) GetStaticPropLump() *primitives.StaticPropLump {
for i, gameLump := range lump.Header.GameLumps {
if gameLump.Id == primitives.StaticPropLumpId {
Expand Down
5 changes: 4 additions & 1 deletion primitives/area/area.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package area

// Area
type Area struct {
NumAreaPortals int32
// NumAreaPortals number of AreaPortals in this area
NumAreaPortals int32
// FirstAreaPortal index of first AreaPortal
FirstAreaPortal int32
}
16 changes: 11 additions & 5 deletions primitives/areaportal/areaportal.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package areaportal

// AreaPortal
type AreaPortal struct {
PortalKey uint16 // Entities have a key called portal number (and in vbsp a variable called areaportalnum) to bind them to the area portals by comparing this value
OtherArea uint16 // The area this portal looks into
FirstClipPortalVert uint16 // Portal geometry
NumClipPortalVerts uint16

// PortalKey - entities have a key called portal number (and in vbsp a variable called areaportalnum) to bind
// them to the area portals by comparing this value
PortalKey uint16
// OtherArea is the area this portal looks into
OtherArea uint16
// FirstClipPortalVert Portal geometry
FirstClipPortalVert uint16
// NumClipPortalVerts number of geometry verts
NumClipPortalVerts uint16
// PlaneNum
PlaneNum int32
}
8 changes: 6 additions & 2 deletions primitives/brush/brush.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package brush

// Brush
type Brush struct {
// FirstSide index of first side of a brush
FirstSide int32
NumSides int32
Contents int32
// NumSides is number of sides this brush has
NumSides int32
// Contents
Contents int32
}
9 changes: 7 additions & 2 deletions primitives/brushside/brushside.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package brushside

// BrushSide
type BrushSide struct {
// PlaneNum is index into planes
PlaneNum uint16
TexInfo int16
// TexInfo is index into TexInfo slice
TexInfo int16
// DispInfo is index into DispInfo slice
DispInfo int16
Bevel int16
// Bevel
Bevel int16
}
121 changes: 80 additions & 41 deletions primitives/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,100 @@ import (
"github.com/go-gl/mathgl/mgl32"
)

// ColorRGBExponent32 is a 4 byte color representation (RGBExp)
type ColorRGBExponent32 struct {
R uint8
G uint8
B uint8
// R red
R uint8
// G green
G uint8
// B blue
B uint8
// Exponent exponent
Exponent int8
}

const MAX_POINTS_ON_FIXED_WINDING = 12

//const MAX_DISPVERTS = 0
//const MAX_DISPTRIS = 0

// Winding
type Winding struct {
Original int32 // qboolean = int32
// Original
Original int32 // qboolean = int32
// NumPoints
NumPoints int32
Points []mgl32.Vec3
// Points
Points []mgl32.Vec3
}

// Side
type Side struct {
PlaneNum int32
TexInfo int32
MapDisp *MapDispInfo
Winding *Winding
Original *Side
Contents int32
Surf int32
Visible int32
Tested int32
Bevel int32
Next *Side
OrigIndex int32
Id int32
SmoothingGroups uint32
AOverlayIds []int32
AWaterOverlayIds []int32
// PlaneNum
PlaneNum int32
// TexInfo
TexInfo int32
// MapDisp
MapDisp *MapDispInfo
// Winding
Winding *Winding
// Original
Original *Side
// Contents
Contents int32
// Surf
Surf int32
// Visible
Visible int32
// Tested
Tested int32
// Bevel
Bevel int32
// Next
Next *Side
// OrigIndex
OrigIndex int32
// Id is side Id
Id int32
// SmoothingGroups
SmoothingGroups uint32
// AOverlayIds
AOverlayIds []int32
// AWaterOverlayIds
AWaterOverlayIds []int32
// DynamicShadowsEnabled are dynamic shadows enabled for this side
DynamicShadowsEnabled bool
}

// MapDispInfo
type MapDispInfo struct {
Face face.Face
EntityNum int32
Power int32
MinTess int32
// Face
Face face.Face
// EntityNum
EntityNum int32
// Power is power of this displacement (normally 2-4)
Power int32
// MinTess
MinTess int32
// SmoothingAngle
SmoothingAngle float32
UAxis mgl32.Vec3
VAxis mgl32.Vec3
StartPosition mgl32.Vec3
AlphaValues []float32
MaxDispDist float32
DispDists []float32
VectorDisps []mgl32.Vec3
VectorOffsets []mgl32.Vec3
Contents int32
BrushSideID int32
Flags int32
// UAxis
UAxis mgl32.Vec3
// VAxis
VAxis mgl32.Vec3
// StartPosition
StartPosition mgl32.Vec3
// AlphaValues
AlphaValues []float32
// MaxDispDist
MaxDispDist float32
// DispDists
DispDists []float32
// VectorDisps
VectorDisps []mgl32.Vec3
// VectorOffsets
VectorOffsets []mgl32.Vec3
// Contents
Contents int32
// BrushSideID
BrushSideID int32
// Flags
Flags int32

// #ifdef VSVMFIO
// Elevation float32
Expand Down
8 changes: 6 additions & 2 deletions primitives/cubemap/cubemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import (
"github.com/go-gl/mathgl/mgl32"
)

// CubemapSample
type CubemapSample struct {
Origin mgl32.Vec3
Size byte
// Origin is sample location
Origin mgl32.Vec3
// Size
Size byte
// AlignmentPadding - probably unused, likely exists for ensure 4byte alignment during read/write.
AlignmentPadding [3]byte
}
Loading

0 comments on commit 91a5bef

Please sign in to comment.