fixed linting issues in d2screen and d2render (#487) (#512)

This commit is contained in:
Natureknight 2020-07-01 15:59:24 +03:00 committed by GitHub
parent 5b26624cb8
commit 04ed9466f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View File

@ -19,6 +19,7 @@ Maxime "malavv" Lavigne
Ripolak Ripolak
dafe dafe
presiyan presiyan
Natureknight
* DIABLO2 LOGO * DIABLO2 LOGO
Jose Pardilla (th3-prophetman) Jose Pardilla (th3-prophetman)

View File

@ -8,13 +8,17 @@ import (
) )
var ( var (
ErrWasInit = errors.New("rendering system is already initialized") // ErrWasInit holding an error instance for initialized rendering system
ErrNotInit = errors.New("rendering system has not been initialized") ErrWasInit = errors.New("rendering system is already initialized")
// ErrNotInit holding an error instance for non-initialized rendering system
ErrNotInit = errors.New("rendering system has not been initialized")
// ErrInvalidRenderer holding an error instance for invalid rendering system specification
ErrInvalidRenderer = errors.New("invalid rendering system specified") ErrInvalidRenderer = errors.New("invalid rendering system specified")
) )
var singleton d2interface.Renderer var singleton d2interface.Renderer
// Initialize the renderer
func Initialize(rend d2interface.Renderer) error { func Initialize(rend d2interface.Renderer) error {
verifyNotInit() verifyNotInit()
singleton = rend singleton = rend
@ -22,57 +26,68 @@ func Initialize(rend d2interface.Renderer) error {
return nil return nil
} }
// SetWindowIcon sets the window icon by a given file name as string
func SetWindowIcon(fileName string) { func SetWindowIcon(fileName string) {
verifyWasInit() verifyWasInit()
singleton.SetWindowIcon(fileName) singleton.SetWindowIcon(fileName)
} }
// Run will run the renderer
func Run(f func(d2interface.Surface) error, width, height int, title string) error { func Run(f func(d2interface.Surface) error, width, height int, title string) error {
verifyWasInit() verifyWasInit()
singleton.Run(f, width, height, title) singleton.Run(f, width, height, title)
return nil return nil
} }
// IsDrawingSkipped checks whether the drawing is skipped
func IsDrawingSkipped() bool { func IsDrawingSkipped() bool {
verifyWasInit() verifyWasInit()
return singleton.IsDrawingSkipped() return singleton.IsDrawingSkipped()
} }
// CreateSurface creates a new surface, which returns the newly created surface or error
func CreateSurface(surface d2interface.Surface) (d2interface.Surface, error) { func CreateSurface(surface d2interface.Surface) (d2interface.Surface, error) {
verifyWasInit() verifyWasInit()
return singleton.CreateSurface(surface) return singleton.CreateSurface(surface)
} }
// NewSurface adds a new surface, and returns the new surface or error
func NewSurface(width, height int, filter d2interface.Filter) (d2interface.Surface, error) { func NewSurface(width, height int, filter d2interface.Filter) (d2interface.Surface, error) {
verifyWasInit() verifyWasInit()
return singleton.NewSurface(width, height, filter) return singleton.NewSurface(width, height, filter)
} }
// IsFullScreen checks whether the window is on full screen
func IsFullScreen() bool { func IsFullScreen() bool {
verifyWasInit() verifyWasInit()
return singleton.IsFullScreen() return singleton.IsFullScreen()
} }
// SetFullScreen sets the window in fullscreen or windowed mode depending on the fullScreen flag
func SetFullScreen(fullScreen bool) { func SetFullScreen(fullScreen bool) {
verifyWasInit() verifyWasInit()
singleton.SetFullScreen(fullScreen) singleton.SetFullScreen(fullScreen)
} }
// SetVSyncEnabled sets or unsets the VSync depending on the given vsync parameter flag
func SetVSyncEnabled(vsync bool) { func SetVSyncEnabled(vsync bool) {
verifyWasInit() verifyWasInit()
singleton.SetVSyncEnabled(vsync) singleton.SetVSyncEnabled(vsync)
} }
// GetVSyncEnabled checks whether the VSync is enabled or not
func GetVSyncEnabled() bool { func GetVSyncEnabled() bool {
verifyWasInit() verifyWasInit()
return singleton.GetVSyncEnabled() return singleton.GetVSyncEnabled()
} }
// GetCursorPos returns the exact current position of the cursor
func GetCursorPos() (int, int) { func GetCursorPos() (int, int) {
verifyWasInit() verifyWasInit()
return singleton.GetCursorPos() return singleton.GetCursorPos()
} }
// CurrentFPS returns the current frames per second
func CurrentFPS() float64 { func CurrentFPS() float64 {
verifyWasInit() verifyWasInit()
return singleton.CurrentFPS() return singleton.CurrentFPS()

View File

@ -10,8 +10,10 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui" "github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
) )
// Screen is an exported interface
type Screen interface{} type Screen interface{}
// ScreenLoadHandler is an exported interface
type ScreenLoadHandler interface { type ScreenLoadHandler interface {
// OnLoad performs all necessary loading to prepare a screen to be shown such as loading assets, placing and binding // OnLoad performs all necessary loading to prepare a screen to be shown such as loading assets, placing and binding
// of ui elements, etc. This loading is done asynchronously. The provided channel will allow implementations to // of ui elements, etc. This loading is done asynchronously. The provided channel will allow implementations to
@ -19,14 +21,17 @@ type ScreenLoadHandler interface {
OnLoad(loading LoadingState) OnLoad(loading LoadingState)
} }
// ScreenUnloadHandler is an exported interface
type ScreenUnloadHandler interface { type ScreenUnloadHandler interface {
OnUnload() error OnUnload() error
} }
// ScreenRenderHandler is an exported interface
type ScreenRenderHandler interface { type ScreenRenderHandler interface {
Render(target d2interface.Surface) error Render(target d2interface.Surface) error
} }
// ScreenAdvanceHandler is an exported interface
type ScreenAdvanceHandler interface { type ScreenAdvanceHandler interface {
Advance(elapsed float64) error Advance(elapsed float64) error
} }
@ -38,10 +43,12 @@ var singleton struct {
currentScreen Screen currentScreen Screen
} }
// SetNextScreen is about to set a given screen as next
func SetNextScreen(screen Screen) { func SetNextScreen(screen Screen) {
singleton.nextScreen = screen singleton.nextScreen = screen
} }
// Advance updates the UI on every frame
func Advance(elapsed float64) error { func Advance(elapsed float64) error {
switch { switch {
case singleton.loadingScreen != nil: case singleton.loadingScreen != nil:
@ -97,6 +104,7 @@ func Advance(elapsed float64) error {
return nil return nil
} }
// Render renders the UI by a given surface
func Render(surface d2interface.Surface) error { func Render(surface d2interface.Surface) error {
if handler, ok := singleton.currentScreen.(ScreenRenderHandler); ok { if handler, ok := singleton.currentScreen.(ScreenRenderHandler); ok {
if err := handler.Render(surface); err != nil { if err := handler.Render(surface); err != nil {
@ -107,6 +115,7 @@ func Render(surface d2interface.Surface) error {
return nil return nil
} }
// LoadingState represents the loading state
type LoadingState struct { type LoadingState struct {
updates chan loadingUpdate updates chan loadingUpdate
} }