Skip to content

Commit

Permalink
gfx: Correct GetFramecount call (#258)
Browse files Browse the repository at this point in the history
- Update `gfx.GetFramecount` to correctly call `SDL_getFramecount`
- Add `gfx` to the makefile package list (so gfx tests are run)
- Add tests for the FPSmanager
  • Loading branch information
pglass authored and veeableful committed Sep 22, 2017
1 parent e0f6315 commit ac5c42f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SRCDIR= ${CURDIR}
ALLDIRS!= find ${SRCDIR} -type d -not -path "./.git*"
# Packages
ROOTPKG= $(subst ${GOPATH}/src/,,${SRCDIR})
PACKAGES= sdl img mix ttf
PACKAGES= sdl img mix ttf gfx
# Some cleanups
CLEANUP= *.cache *.core *~ *.orig

Expand Down
2 changes: 1 addition & 1 deletion gfx/sdl_gfx.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func GetFramerate(manager *FPSmanager) (int, bool) {
}

func GetFramecount(manager *FPSmanager) (int, bool) {
count := int(C.SDL_getFramerate(manager.cptr()))
count := int(C.SDL_getFramecount(manager.cptr()))
return count, count >= 0
}

Expand Down
26 changes: 26 additions & 0 deletions gfx/sdl_gfx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,29 @@ func TestMin(t *testing.T) {
t.Fail()
}
}

func TestFPSmanager(t *testing.T) {
fpsManager := FPSmanager{}
InitFramerate(&fpsManager)

if !SetFramerate(&fpsManager, 60) {
t.Errorf("gfx.SetFramerate failed")
}

if fps, ok := GetFramerate(&fpsManager); !ok || fps != 60 {
t.Errorf("gfx.GetFramerate() = (%v, %v) - want (60, true)", fps, ok)
}

// frame count is initialized to 0
if count, ok := GetFramecount(&fpsManager); !ok || count != 0 {
t.Errorf("gfx.GetFramecount() = (%v, %v) - want (0, true)", count, ok)
}

// count one frame
FramerateDelay(&fpsManager)

// frame count should now be 1
if count, ok := GetFramecount(&fpsManager); !ok || count != 1 {
t.Errorf("gfx.Framecount() = (%v, %v) - want (1, true)", count, ok)
}
}

0 comments on commit ac5c42f

Please sign in to comment.