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
dafe
presiyan
Natureknight
* DIABLO2 LOGO
Jose Pardilla (th3-prophetman)

View File

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

View File

@ -10,8 +10,10 @@ import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
)
// Screen is an exported interface
type Screen interface{}
// ScreenLoadHandler is an exported interface
type ScreenLoadHandler interface {
// 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
@ -19,14 +21,17 @@ type ScreenLoadHandler interface {
OnLoad(loading LoadingState)
}
// ScreenUnloadHandler is an exported interface
type ScreenUnloadHandler interface {
OnUnload() error
}
// ScreenRenderHandler is an exported interface
type ScreenRenderHandler interface {
Render(target d2interface.Surface) error
}
// ScreenAdvanceHandler is an exported interface
type ScreenAdvanceHandler interface {
Advance(elapsed float64) error
}
@ -38,10 +43,12 @@ var singleton struct {
currentScreen Screen
}
// SetNextScreen is about to set a given screen as next
func SetNextScreen(screen Screen) {
singleton.nextScreen = screen
}
// Advance updates the UI on every frame
func Advance(elapsed float64) error {
switch {
case singleton.loadingScreen != nil:
@ -97,6 +104,7 @@ func Advance(elapsed float64) error {
return nil
}
// Render renders the UI by a given surface
func Render(surface d2interface.Surface) error {
if handler, ok := singleton.currentScreen.(ScreenRenderHandler); ok {
if err := handler.Render(surface); err != nil {
@ -107,6 +115,7 @@ func Render(surface d2interface.Surface) error {
return nil
}
// LoadingState represents the loading state
type LoadingState struct {
updates chan loadingUpdate
}