1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-10-31 16:27:18 -04:00
OpenDiablo2/main.go

56 lines
1.5 KiB
Go
Raw Normal View History

2019-10-24 09:31:59 -04:00
package main
import (
"image"
2019-10-24 09:31:59 -04:00
"log"
"github.com/hajimehoshi/ebiten/ebitenutil"
2019-11-06 22:12:15 -05:00
"github.com/OpenDiablo2/OpenDiablo2/common"
2019-11-06 22:12:15 -05:00
"github.com/OpenDiablo2/OpenDiablo2/core"
"github.com/OpenDiablo2/OpenDiablo2/mpq"
2019-10-24 09:31:59 -04:00
"github.com/hajimehoshi/ebiten"
)
2019-11-06 22:12:15 -05:00
// GitBranch is set by the CI build process to the name of the branch
var GitBranch string
2019-11-06 22:12:15 -05:00
// GitCommit is set by the CI build process to the commit hash
var GitCommit string
2019-11-06 22:12:15 -05:00
var d2Engine *core.Engine
2019-10-24 09:31:59 -04:00
func main() {
if len(GitBranch) == 0 {
GitBranch = "Local Build"
GitCommit = ""
}
2019-11-06 22:12:15 -05:00
common.SetBuildInfo(GitBranch, GitCommit)
log.SetFlags(log.Ldate | log.LUTC | log.Lmicroseconds | log.Llongfile)
2019-10-24 09:31:59 -04:00
log.Println("OpenDiablo2 - Open source Diablo 2 engine")
_, iconImage, err := ebitenutil.NewImageFromFile("d2logo.png", ebiten.FilterLinear)
if err == nil {
ebiten.SetWindowIcon([]image.Image{iconImage})
}
2019-11-06 22:12:15 -05:00
mpq.InitializeCryptoBuffer()
d2Engine = core.CreateEngine()
2019-10-24 09:31:59 -04:00
ebiten.SetCursorVisible(false)
ebiten.SetFullscreen(d2Engine.Settings.FullScreen)
ebiten.SetRunnableInBackground(d2Engine.Settings.RunInBackground)
ebiten.SetVsyncEnabled(d2Engine.Settings.VsyncEnabled)
ebiten.SetMaxTPS(d2Engine.Settings.TicksPerSecond)
if err := ebiten.Run(update, 800, 600, d2Engine.Settings.Scale, "OpenDiablo 2 ("+GitBranch+")"); err != nil {
2019-10-24 09:31:59 -04:00
log.Fatal(err)
}
}
func update(screen *ebiten.Image) error {
d2Engine.Update()
if ebiten.IsDrawingSkipped() {
return nil
}
d2Engine.Draw(screen)
//ebitenutil.DebugPrint(screen, "FPS:"+strconv.Itoa(int(ebiten.CurrentFPS())))
2019-10-24 09:31:59 -04:00
return nil
}