Skip to content

Commit

Permalink
Merge pull request #132 from oakmound/release/2.4.0
Browse files Browse the repository at this point in the history
Release/2.4.0
  • Loading branch information
200sc committed Aug 15, 2020
2 parents 34e40df + 988c336 commit 828120f
Show file tree
Hide file tree
Showing 62 changed files with 1,352 additions and 443 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ jobs:
run: ./cover.sh

- name: Push to codecov
run: bash <(curl -s https://codecov.io/bash)
uses: codecov/codecov-action@v1.0.2
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./coverage.txt
5 changes: 5 additions & 0 deletions collision/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ func NewFullSpace(x, y, w, h float64, l Label, cID event.CID) *Space {
}
}

// NewRect2Space returns a space with an associated caller id from a rect2
func NewRect2Space(rect floatgeom.Rect2, cID event.CID) *Space {
return NewSpace(rect.Min.X(), rect.Min.Y(), rect.W(), rect.H(), cID)
}

// NewRectSpace creates a colliison space with the specified 3D rectangle
func NewRectSpace(rect floatgeom.Rect3, l Label, cID event.CID) *Space {
return &Space{
Expand Down
14 changes: 13 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
conf = Config{
Assets: Assets{"assets/", "audio/", "images/", "font/"},
Debug: Debug{"", "ERROR"},
Screen: Screen{0, 0, 480, 640, 1},
Screen: Screen{0, 0, 480, 640, 1, 0, 0},
Font: Font{"none", 12.0, 72.0, "", "white"},
FrameRate: 60,
DrawFrameRate: 60,
Expand Down Expand Up @@ -86,6 +86,12 @@ type Screen struct {
Height int `json:"height"`
Width int `json:"width"`
Scale int `json:"scale"`
// Target sets the expected dimensions of the monitor the game will be opened on, in pixels.
// If Fullscreen is false, then a scaling will be applied to correct the game screen size to be
// appropriate for the Target size. If no TargetWidth or Height is provided, scaling will not
// be adjusted.
TargetWidth int `json:"targetHeight"`
TargetHeight int `json:"targetWidth"`
}

// Font is a json type storing the default font settings
Expand Down Expand Up @@ -153,6 +159,12 @@ func initConfScreen() {
if SetupConfig.Screen.Scale != 0 {
conf.Screen.Scale = SetupConfig.Screen.Scale
}
if SetupConfig.Screen.TargetWidth != 0 {
conf.Screen.TargetWidth = SetupConfig.Screen.TargetWidth
}
if SetupConfig.Screen.TargetHeight != 0 {
conf.Screen.TargetHeight = SetupConfig.Screen.TargetHeight
}
}

func initConfFont() {
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestDefaultConfig(t *testing.T) {
SetupConfig = Config{
Assets: Assets{"a/", "a/", "i/", "f/"},
Debug: Debug{"FILTER", "INFO"},
Screen: Screen{0, 0, 240, 320, 2},
Screen: Screen{0, 0, 240, 320, 2, 0, 0},
Font: Font{"hint", 20.0, 36.0, "luxisr.ttf", "green"},
FrameRate: 30,
DrawFrameRate: 30,
Expand Down
39 changes: 22 additions & 17 deletions cover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,83 +9,88 @@ echo "" > coverage.txt
#
# Don't run coverage on examples, just test that they compile
go test ./examples/...
go test -coverprofile=profile.out -covermode=atomic ./shape
go test -coverprofile=profile.out -covermode=atomic ./alg
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./oakerr
go test -coverprofile=profile.out -covermode=atomic ./alg/intgeom
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./timing
go test -coverprofile=profile.out -covermode=atomic ./alg/floatgeom
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./physics
go test -coverprofile=profile.out -covermode=atomic ./collision
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./event
go test -coverprofile=profile.out -covermode=atomic ./collision/ray
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./render
go test -coverprofile=profile.out -covermode=atomic ./dlog
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./render/mod
go test -coverprofile=profile.out -covermode=atomic ./event
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./render/particle
go test -coverprofile=profile.out -covermode=atomic ./fileutil
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./alg
go test -coverprofile=profile.out -covermode=atomic ./mouse
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./alg/intgeom
go test -coverprofile=profile.out -covermode=atomic ./oakerr
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./alg/floatgeom
go test -coverprofile=profile.out -covermode=atomic ./physics
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./collision
go test -coverprofile=profile.out -covermode=atomic ./render
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./collision/ray
go test -coverprofile=profile.out -covermode=atomic ./render/mod
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./fileutil
go test -coverprofile=profile.out -covermode=atomic ./render/particle
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./mouse
go test -coverprofile=profile.out -covermode=atomic ./scene
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
go test -coverprofile=profile.out -covermode=atomic ./scene
go test -coverprofile=profile.out -covermode=atomic ./shape
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
fi
go test -coverprofile=profile.out -covermode=atomic ./timing
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
11 changes: 8 additions & 3 deletions dlog/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"time"
)

var (
_ FullLogger = &logger{}
)

type logger struct {
byt *bytes.Buffer
debugLevel Level
Expand Down Expand Up @@ -99,11 +103,12 @@ func truncateFileName(f string) string {
}

func (l *logger) checkFilter(f string, in ...interface{}) bool {
ret := false
for _, elem := range in {
ret = ret || strings.Contains(fmt.Sprintf("%s", elem), l.debugFilter)
if strings.Contains(fmt.Sprintf("%s", elem), l.debugFilter) {
return true
}
}
return ret || strings.Contains(f, l.debugFilter)
return strings.Contains(f, l.debugFilter)
}

// SetDebugFilter sets the string which determines
Expand Down
4 changes: 3 additions & 1 deletion dlog/dlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ var oakLogger Logger

// ErrorCheck checks that the input is not nil, then calls Error on it if it is
// not. Otherwise it does nothing.
func ErrorCheck(in error) {
// Emits the input error as is for additional processing if desired.
func ErrorCheck(in error) error {
if in != nil {
Error(in)
}
return in
}

// Error will write a log if the debug level is not NONE
Expand Down
182 changes: 182 additions & 0 deletions dlog/regexLogger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package dlog

import (
"bytes"
"fmt"
"io"
"os"
"regexp"
"runtime"
"strconv"
"strings"
"time"
)

var (
_ FullLogger = &RegexLogger{}
)

// RegexLogger is a logger implementation that offers some
// additional features on top of the default logger.
// Todo v3: combine logger implementations.
type RegexLogger struct {
debugLevel Level

debugFilter string
filterRegex *regexp.Regexp
// FilterOverrideLevel is the log level at which
// logs will be shown regardless of the filter.
FilterOverrideLevel Level

writer io.Writer
file io.Writer
}

// NewRegexLogger returns a custom logger that writes to os.Stdout and
// overrides filters on WARN or higher messages.
func NewRegexLogger(level Level) *RegexLogger {
return &RegexLogger{
debugLevel: level,
writer: os.Stdout,
FilterOverrideLevel: WARN,
}
}

// GetLogLevel returns the current log level, i.e WARN or INFO...
func (l *RegexLogger) GetLogLevel() Level {
return l.debugLevel
}

// dLog, the primary function of the package,
// prints out and writes to file a string
// containing the logged data separated by spaces,
// prepended with file and line information.
// It only includes logs which pass the current filters.
func (l *RegexLogger) dLog(w io.Writer, override bool, in ...interface{}) {
//(pc uintptr, file string, line int, ok bool)
_, f, line, ok := runtime.Caller(2)
if strings.Contains(f, "dlog") {
_, f, line, ok = runtime.Caller(3)
}
if ok {
var bldr strings.Builder
f = truncateFileName(f)
// Note on errors: these functions all return
// errors, but they are always nil.
bldr.WriteRune('[')
bldr.WriteString(f)
bldr.WriteRune(':')
bldr.WriteString(strconv.Itoa(line))
bldr.WriteString("] ")
bldr.WriteString(logLevels[l.GetLogLevel()])
bldr.WriteRune(':')
for _, elem := range in {
bldr.WriteString(fmt.Sprintf("%v ", elem))
}
bldr.WriteRune('\n')
fullLog := []byte(bldr.String())

if !override && !l.checkFilter(fullLog) {
return
}

_, err := w.Write(fullLog)
if err != nil {
fmt.Println("Logging error", err)
}
}
}

func (l *RegexLogger) checkFilter(fullLog []byte) bool {
if l.debugFilter == "" {
return true
}
if l.filterRegex != nil {
return l.filterRegex.Match(fullLog)
}
return bytes.Contains(fullLog, []byte(l.debugFilter))
}

// SetDebugFilter sets the string which determines
// what debug messages get printed. Only messages
// which contain the filer as a pseudo-regex
func (l *RegexLogger) SetDebugFilter(filter string) {
l.debugFilter = filter
var err error
l.filterRegex, err = regexp.Compile(filter)
if err != nil {
l.Error("could not compile filter regex", err)
}
}

// SetDebugLevel sets what message levels of debug
// will be printed.
func (l *RegexLogger) SetDebugLevel(dL Level) {
if dL < NONE || dL > VERBOSE {
l.Warn("Unknown debug level: ", dL)
l.debugLevel = NONE
} else {
l.debugLevel = dL
}
}

// CreateLogFile creates a file in the 'logs' directory
// of the starting point of this program to write logs to
func (l *RegexLogger) CreateLogFile() {
file := "logs/dlog"
file += time.Now().Format("_Jan_2_15-04-05_2006")
file += ".txt"
var err error
l.file, err = os.Create(file)
if err != nil {
fmt.Println("[oak]-------- No logs directory found. No logs will be written to file.")
return
}
l.writer = io.MultiWriter(l.file, l.writer)
}

// FileWrite acts just like a regular write on a RegexLogger. It does
// not respect overrides.
func (l *RegexLogger) FileWrite(in ...interface{}) {
if l.file == nil {
return
}
l.dLog(l.file, true, in...)
}

// Error will write a dlog if the debug level is not NONE
func (l *RegexLogger) Error(in ...interface{}) {
if l.debugLevel > NONE {
l.dLog(l.writer, l.FilterOverrideLevel > NONE, in)
}
}

// Warn will write a dLog if the debug level is higher than ERROR
func (l *RegexLogger) Warn(in ...interface{}) {
if l.debugLevel > ERROR {
l.dLog(l.writer, l.FilterOverrideLevel > ERROR, in)
}
}

// Info will write a dLog if the debug level is higher than WARN
func (l *RegexLogger) Info(in ...interface{}) {
if l.debugLevel > WARN {
l.dLog(l.writer, l.FilterOverrideLevel > WARN, in)
}
}

// Verb will write a dLog if the debug level is higher than INFO
func (l *RegexLogger) Verb(in ...interface{}) {
if l.debugLevel > INFO {
l.dLog(l.writer, l.FilterOverrideLevel > INFO, in)
}
}

// SetWriter sets the writer that RegexLogger logs to
func (l *RegexLogger) SetWriter(w io.Writer) error {
if w == nil {
return fmt.Errorf("cannot write to nil writer")
}
l.writer = w
return nil
}

0 comments on commit 828120f

Please sign in to comment.