2019-10-24 09:31:59 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-11-02 16:15:16 -04:00
|
|
|
"image"
|
2019-10-24 09:31:59 -04:00
|
|
|
"log"
|
|
|
|
|
2019-11-10 08:51:02 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2scene"
|
2019-12-28 16:46:08 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2surface"
|
2019-12-26 11:13:05 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2term"
|
2019-11-10 03:36:53 -05:00
|
|
|
|
2019-11-02 16:15:16 -04:00
|
|
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
|
|
|
|
2019-11-17 00:16:33 -05:00
|
|
|
"github.com/OpenDiablo2/D2Shared/d2common"
|
2019-11-02 16:15:16 -04:00
|
|
|
|
2019-11-17 00:16:33 -05:00
|
|
|
"github.com/OpenDiablo2/D2Shared/d2data/d2mpq"
|
2019-11-17 01:14:58 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core"
|
2019-10-24 09:31:59 -04:00
|
|
|
"github.com/hajimehoshi/ebiten"
|
2019-11-17 00:52:13 -05:00
|
|
|
"gopkg.in/alecthomas/kingpin.v2"
|
2019-10-24 09:31:59 -04:00
|
|
|
)
|
|
|
|
|
2019-11-06 22:12:15 -05:00
|
|
|
// GitBranch is set by the CI build process to the name of the branch
|
2019-11-02 16:15:16 -04:00
|
|
|
var GitBranch string
|
2019-11-06 22:12:15 -05:00
|
|
|
|
|
|
|
// GitCommit is set by the CI build process to the commit hash
|
2019-11-02 16:15:16 -04:00
|
|
|
var GitCommit string
|
2019-12-26 11:13:05 -05:00
|
|
|
var d2Engine *d2core.Engine
|
2019-10-24 09:31:59 -04:00
|
|
|
|
2019-11-17 00:52:13 -05:00
|
|
|
var region = kingpin.Arg("region", "Region type id").Int()
|
|
|
|
var preset = kingpin.Arg("preset", "Level preset").Int()
|
|
|
|
|
2019-10-24 09:31:59 -04:00
|
|
|
func main() {
|
2019-12-26 11:13:05 -05:00
|
|
|
d2term.Initialize()
|
|
|
|
d2term.BindLogger()
|
|
|
|
|
2019-11-17 01:14:58 -05:00
|
|
|
//procs := runtime.GOMAXPROCS(16)
|
|
|
|
//log.Printf("Setting gomaxprocs to 16, it was previously set to %d", procs)
|
2019-11-08 19:52:49 -05:00
|
|
|
//runtime.LockOSThread()
|
|
|
|
//defer runtime.UnlockOSThread()
|
2019-11-17 01:14:58 -05:00
|
|
|
//defer profile.Start(profile.ProfilePath(".")).Stop()
|
2019-11-02 16:15:16 -04:00
|
|
|
if len(GitBranch) == 0 {
|
|
|
|
GitBranch = "Local Build"
|
|
|
|
GitCommit = ""
|
|
|
|
}
|
2019-11-10 03:36:53 -05:00
|
|
|
d2common.SetBuildInfo(GitBranch, GitCommit)
|
2019-12-26 11:13:05 -05:00
|
|
|
log.SetFlags(log.Lshortfile)
|
2019-10-24 09:31:59 -04:00
|
|
|
log.Println("OpenDiablo2 - Open source Diablo 2 engine")
|
2019-11-02 16:15:16 -04:00
|
|
|
_, iconImage, err := ebitenutil.NewImageFromFile("d2logo.png", ebiten.FilterLinear)
|
|
|
|
if err == nil {
|
|
|
|
ebiten.SetWindowIcon([]image.Image{iconImage})
|
|
|
|
}
|
2019-11-10 08:51:02 -05:00
|
|
|
d2mpq.InitializeCryptoBuffer()
|
2019-11-10 03:36:53 -05:00
|
|
|
d2Engine = d2core.CreateEngine()
|
2019-11-17 00:52:13 -05:00
|
|
|
kingpin.Parse()
|
|
|
|
if *region == 0 {
|
2019-12-26 11:13:05 -05:00
|
|
|
d2Engine.SetNextScene(d2scene.CreateMainMenu(d2Engine, d2Engine.UIManager, d2Engine.SoundManager))
|
2019-11-17 00:52:13 -05:00
|
|
|
} else {
|
2019-12-26 11:13:05 -05:00
|
|
|
d2Engine.SetNextScene(d2scene.CreateMapEngineTest(d2Engine, d2Engine.UIManager, d2Engine.SoundManager, *region, *preset))
|
2019-11-17 00:52:13 -05:00
|
|
|
}
|
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)
|
2019-11-02 16:15:16 -04:00
|
|
|
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()
|
2019-12-28 16:46:08 -05:00
|
|
|
if !ebiten.IsDrawingSkipped() {
|
|
|
|
surface := d2surface.CreateSurface(screen)
|
|
|
|
d2Engine.Draw(surface)
|
|
|
|
if surface.GetDepth() > 0 {
|
|
|
|
panic("detected surface stack leak")
|
|
|
|
}
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
2019-12-28 16:46:08 -05:00
|
|
|
|
2019-10-24 09:31:59 -04:00
|
|
|
return nil
|
|
|
|
}
|