2019-10-24 09:31:59 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-02-22 23:59:45 -05:00
|
|
|
"bytes"
|
2020-02-08 21:02:37 -05:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2020-02-22 23:59:45 -05:00
|
|
|
"image"
|
|
|
|
"image/gif"
|
|
|
|
"image/png"
|
2019-10-24 09:31:59 -04:00
|
|
|
"log"
|
2020-02-08 21:02:37 -05:00
|
|
|
"os"
|
|
|
|
"runtime"
|
2020-06-20 21:07:36 -04:00
|
|
|
"runtime/pprof"
|
2020-02-08 21:02:37 -05:00
|
|
|
"strconv"
|
2020-06-22 12:43:26 -04:00
|
|
|
"strings"
|
2020-02-22 23:59:45 -05:00
|
|
|
"sync"
|
2019-10-24 09:31:59 -04:00
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
ebiten_input "github.com/OpenDiablo2/OpenDiablo2/d2core/d2input/ebiten"
|
|
|
|
|
2020-06-28 19:31:10 -04:00
|
|
|
ebiten2 "github.com/OpenDiablo2/OpenDiablo2/d2core/d2audio/ebiten"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2data/d2datadict"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
2020-02-01 21:06:22 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2config"
|
2020-02-08 21:02:37 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
2020-06-22 12:43:26 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render/ebiten"
|
2020-06-22 12:43:26 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2term"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
2020-06-22 12:43:26 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2gamescreen"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2script"
|
|
|
|
"github.com/pkg/profile"
|
|
|
|
"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-10-24 09:31:59 -04:00
|
|
|
|
2020-02-22 23:59:45 -05:00
|
|
|
type captureState int
|
|
|
|
|
|
|
|
const (
|
|
|
|
captureStateNone captureState = iota
|
|
|
|
captureStateFrame
|
|
|
|
captureStateGif
|
|
|
|
)
|
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
var singleton struct {
|
2020-06-22 00:48:51 -04:00
|
|
|
lastTime float64
|
|
|
|
lastScreenAdvance float64
|
|
|
|
showFPS bool
|
|
|
|
timeScale float64
|
2020-02-22 23:59:45 -05:00
|
|
|
|
|
|
|
captureState captureState
|
|
|
|
capturePath string
|
|
|
|
captureFrames []*image.RGBA
|
2020-02-08 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2020-06-28 21:40:52 -04:00
|
|
|
var terminal_hack d2interface.Terminal // we need to make this available inside of advance/update/render
|
|
|
|
|
2019-10-24 09:31:59 -04:00
|
|
|
func main() {
|
2020-02-02 14:59:47 -05:00
|
|
|
region := kingpin.Arg("region", "Region type id").Int()
|
|
|
|
preset := kingpin.Arg("preset", "Level preset").Int()
|
2020-06-22 22:17:54 -04:00
|
|
|
profileOption := kingpin.Flag("profile", "Profiles the program, one of (cpu, mem, block, goroutine, trace, thread, mutex)").String()
|
2020-06-22 12:43:26 -04:00
|
|
|
|
2020-02-02 14:59:47 -05:00
|
|
|
kingpin.Parse()
|
|
|
|
|
2020-01-31 23:18:11 -05:00
|
|
|
log.SetFlags(log.Lshortfile)
|
|
|
|
log.Println("OpenDiablo2 - Open source Diablo 2 engine")
|
|
|
|
|
2020-06-28 19:31:10 -04:00
|
|
|
// Initialize our providers
|
|
|
|
audioProvider, err := ebiten2.CreateAudio()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2020-06-28 21:40:52 -04:00
|
|
|
d2input.Initialize(ebiten_input.InputService{}) // TODO d2input singleton must be init before d2term
|
|
|
|
term, err := d2term.Initialize()
|
|
|
|
terminal_hack = term // needs to be used in advance, no easy way for that right now
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := initialize(audioProvider, term); err != nil {
|
2020-06-24 14:42:39 -04:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
run(updateInitError)
|
|
|
|
}
|
2020-01-31 23:18:11 -05:00
|
|
|
log.Fatal(err)
|
2019-11-02 16:15:16 -04:00
|
|
|
}
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-06-22 22:17:54 -04:00
|
|
|
if len(*profileOption) > 0 {
|
2020-06-23 14:49:46 -04:00
|
|
|
profiler := enableProfiler(*profileOption)
|
|
|
|
if profiler != nil {
|
|
|
|
defer profiler.Stop()
|
|
|
|
}
|
2020-06-22 12:43:26 -04:00
|
|
|
}
|
|
|
|
|
2019-11-17 00:52:13 -05:00
|
|
|
if *region == 0 {
|
2020-06-28 21:40:52 -04:00
|
|
|
d2screen.SetNextScreen(d2gamescreen.CreateMainMenu(audioProvider, term))
|
2019-11-17 00:52:13 -05:00
|
|
|
} else {
|
2020-06-28 21:40:52 -04:00
|
|
|
d2screen.SetNextScreen(d2gamescreen.CreateMapEngineTest(*region, *preset, term))
|
2020-01-31 23:18:11 -05:00
|
|
|
}
|
2020-02-02 14:59:47 -05:00
|
|
|
|
2020-06-24 14:42:39 -04:00
|
|
|
run(update)
|
2019-10-24 09:31:59 -04:00
|
|
|
}
|
|
|
|
|
2020-06-28 21:40:52 -04:00
|
|
|
func initialize(audioProvider d2interface.AudioProvider, term d2interface.Terminal) error {
|
2020-02-08 21:02:37 -05:00
|
|
|
singleton.timeScale = 1.0
|
|
|
|
singleton.lastTime = d2common.Now()
|
2020-06-22 00:48:51 -04:00
|
|
|
singleton.lastScreenAdvance = singleton.lastTime
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-02-20 08:41:41 -05:00
|
|
|
if err := d2config.Load(); err != nil {
|
2020-02-08 21:02:37 -05:00
|
|
|
return err
|
2020-01-31 23:18:11 -05:00
|
|
|
}
|
|
|
|
|
2020-02-09 14:12:04 -05:00
|
|
|
config := d2config.Get()
|
2020-02-08 21:02:37 -05:00
|
|
|
d2resource.LanguageCode = config.Language
|
|
|
|
|
|
|
|
renderer, err := ebiten.CreateRenderer()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := d2render.Initialize(renderer); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-09 14:12:04 -05:00
|
|
|
d2render.SetWindowIcon("d2logo.png")
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindLogger()
|
|
|
|
term.BindAction("dumpheap", "dumps the heap to pprof/heap.pprof", func() {
|
2020-06-22 22:17:54 -04:00
|
|
|
os.Mkdir("./pprof/", 0755)
|
|
|
|
fileOut, _ := os.Create("./pprof/heap.pprof")
|
2020-06-20 21:07:36 -04:00
|
|
|
pprof.WriteHeapProfile(fileOut)
|
|
|
|
fileOut.Close()
|
|
|
|
})
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("fullscreen", "toggles fullscreen", func() {
|
2020-02-09 14:12:04 -05:00
|
|
|
fullscreen := !d2render.IsFullScreen()
|
|
|
|
d2render.SetFullScreen(fullscreen)
|
2020-06-28 21:40:52 -04:00
|
|
|
term.OutputInfo("fullscreen is now: %v", fullscreen)
|
2020-02-08 21:02:37 -05:00
|
|
|
})
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("capframe", "captures a still frame", func(path string) {
|
2020-02-22 23:59:45 -05:00
|
|
|
singleton.captureState = captureStateFrame
|
|
|
|
singleton.capturePath = path
|
|
|
|
singleton.captureFrames = nil
|
|
|
|
})
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("capgifstart", "captures an animation (start)", func(path string) {
|
2020-02-22 23:59:45 -05:00
|
|
|
singleton.captureState = captureStateGif
|
|
|
|
singleton.capturePath = path
|
|
|
|
singleton.captureFrames = nil
|
|
|
|
})
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("capgifstop", "captures an animation (stop)", func() {
|
2020-02-22 23:59:45 -05:00
|
|
|
singleton.captureState = captureStateNone
|
|
|
|
})
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("vsync", "toggles vsync", func() {
|
2020-02-09 14:12:04 -05:00
|
|
|
vsync := !d2render.GetVSyncEnabled()
|
|
|
|
d2render.SetVSyncEnabled(vsync)
|
2020-06-28 21:40:52 -04:00
|
|
|
term.OutputInfo("vsync is now: %v", vsync)
|
2020-02-08 21:02:37 -05:00
|
|
|
})
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("fps", "toggle fps counter", func() {
|
2020-02-08 21:02:37 -05:00
|
|
|
singleton.showFPS = !singleton.showFPS
|
2020-06-28 21:40:52 -04:00
|
|
|
term.OutputInfo("fps counter is now: %v", singleton.showFPS)
|
2020-02-08 21:02:37 -05:00
|
|
|
})
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("timescale", "set scalar for elapsed time", func(timeScale float64) {
|
2020-02-08 21:02:37 -05:00
|
|
|
if timeScale <= 0 {
|
2020-06-28 21:40:52 -04:00
|
|
|
term.OutputError("invalid time scale value")
|
2020-02-08 21:02:37 -05:00
|
|
|
} else {
|
2020-06-28 21:40:52 -04:00
|
|
|
term.OutputInfo("timescale changed from %f to %f", singleton.timeScale, timeScale)
|
2020-02-08 21:02:37 -05:00
|
|
|
singleton.timeScale = timeScale
|
|
|
|
}
|
|
|
|
})
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("quit", "exits the game", func() {
|
2020-02-08 21:02:37 -05:00
|
|
|
os.Exit(0)
|
|
|
|
})
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("screen-gui", "enters the gui playground screen", func() {
|
2020-06-13 20:36:20 -04:00
|
|
|
d2screen.SetNextScreen(d2gamescreen.CreateGuiTestMain())
|
2020-02-24 22:35:21 -05:00
|
|
|
})
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-06-28 21:40:52 -04:00
|
|
|
if err := d2asset.Initialize(term); err != nil {
|
2020-02-08 21:02:37 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-09 14:12:04 -05:00
|
|
|
if err := d2gui.Initialize(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-28 19:31:10 -04:00
|
|
|
audioProvider.SetVolumes(config.BgmVolume, config.SfxVolume)
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
if err := loadDataDict(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := loadStrings(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-13 18:32:09 -04:00
|
|
|
d2inventory.LoadHeroObjects()
|
|
|
|
|
2020-06-28 19:31:10 -04:00
|
|
|
d2ui.Initialize(audioProvider)
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-06-18 14:11:04 -04:00
|
|
|
d2script.CreateScriptEngine()
|
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
func run(updateFunc func(d2interface.Surface) error) {
|
2020-06-24 14:42:39 -04:00
|
|
|
if len(GitBranch) == 0 {
|
|
|
|
GitBranch = "Local Build"
|
|
|
|
}
|
|
|
|
d2common.SetBuildInfo(GitBranch, GitCommit)
|
|
|
|
windowTitle := fmt.Sprintf("OpenDiablo2 (%s)", GitBranch)
|
|
|
|
if err := d2render.Run(updateFunc, 800, 600, windowTitle); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
func update(target d2interface.Surface) error {
|
2020-02-08 21:02:37 -05:00
|
|
|
currentTime := d2common.Now()
|
|
|
|
elapsedTime := (currentTime - singleton.lastTime) * singleton.timeScale
|
|
|
|
singleton.lastTime = currentTime
|
|
|
|
|
2020-06-22 00:48:51 -04:00
|
|
|
if err := advance(elapsedTime, currentTime); err != nil {
|
2020-02-08 21:02:37 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if target.GetDepth() > 0 {
|
|
|
|
return errors.New("detected surface stack leak")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
func updateInitError(target d2interface.Surface) error {
|
2020-06-24 14:42:39 -04:00
|
|
|
width, height := target.GetSize()
|
|
|
|
target.PushTranslation(width/5, height/2)
|
|
|
|
target.DrawText("Could not find the MPQ files in the directory: %s\nPlease put the files and re-run the game.", d2config.Get().MpqPath)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-22 00:48:51 -04:00
|
|
|
const FPS_25 = 0.04 // 1/25
|
|
|
|
|
|
|
|
func advance(elapsed, current float64) error {
|
|
|
|
elapsedLastScreenAdvance := (current - singleton.lastScreenAdvance) * singleton.timeScale
|
|
|
|
|
|
|
|
if elapsedLastScreenAdvance > FPS_25 {
|
|
|
|
singleton.lastScreenAdvance = current
|
|
|
|
if err := d2screen.Advance(elapsedLastScreenAdvance); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-08 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
d2ui.Advance(elapsed)
|
|
|
|
|
|
|
|
if err := d2input.Advance(elapsed); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := d2gui.Advance(elapsed); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-28 21:40:52 -04:00
|
|
|
if err := terminal_hack.Advance(elapsed); err != nil {
|
2020-02-08 21:02:37 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
func render(target d2interface.Surface) error {
|
2020-06-13 20:36:20 -04:00
|
|
|
if err := d2screen.Render(target); err != nil {
|
2020-02-08 21:02:37 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
d2ui.Render(target)
|
|
|
|
|
|
|
|
if err := d2gui.Render(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-22 23:59:45 -05:00
|
|
|
if err := renderDebug(target); err != nil {
|
2020-02-08 21:02:37 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-22 23:59:45 -05:00
|
|
|
if err := renderCapture(target); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-28 21:40:52 -04:00
|
|
|
if err := terminal_hack.Render(target); err != nil {
|
2020-02-08 21:02:37 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
func renderCapture(target d2interface.Surface) error {
|
2020-02-22 23:59:45 -05:00
|
|
|
cleanupCapture := func() {
|
|
|
|
singleton.captureState = captureStateNone
|
|
|
|
singleton.capturePath = ""
|
|
|
|
singleton.captureFrames = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
switch singleton.captureState {
|
|
|
|
case captureStateFrame:
|
|
|
|
defer cleanupCapture()
|
|
|
|
|
|
|
|
fp, err := os.Create(singleton.capturePath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer fp.Close()
|
|
|
|
|
|
|
|
screenshot := target.Screenshot()
|
|
|
|
if err := png.Encode(fp, screenshot); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("saved frame to %s", singleton.capturePath)
|
|
|
|
case captureStateGif:
|
|
|
|
screenshot := target.Screenshot()
|
|
|
|
singleton.captureFrames = append(singleton.captureFrames, screenshot)
|
|
|
|
case captureStateNone:
|
|
|
|
if len(singleton.captureFrames) > 0 {
|
|
|
|
defer cleanupCapture()
|
|
|
|
|
|
|
|
fp, err := os.Create(singleton.capturePath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer fp.Close()
|
|
|
|
|
|
|
|
var (
|
|
|
|
framesTotal = len(singleton.captureFrames)
|
|
|
|
framesPal = make([]*image.Paletted, framesTotal)
|
|
|
|
frameDelays = make([]int, framesTotal)
|
|
|
|
framesPerCpu = framesTotal / runtime.NumCPU()
|
|
|
|
)
|
|
|
|
|
|
|
|
var waitGroup sync.WaitGroup
|
|
|
|
for i := 0; i < framesTotal; i += framesPerCpu {
|
|
|
|
waitGroup.Add(1)
|
|
|
|
go func(start, end int) {
|
|
|
|
defer waitGroup.Done()
|
|
|
|
|
|
|
|
for j := start; j < end; j++ {
|
|
|
|
var buffer bytes.Buffer
|
|
|
|
if err := gif.Encode(&buffer, singleton.captureFrames[j], nil); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
framePal, err := gif.Decode(&buffer)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
framesPal[j] = framePal.(*image.Paletted)
|
|
|
|
frameDelays[j] = 5
|
|
|
|
}
|
|
|
|
}(i, d2common.MinInt(i+framesPerCpu, framesTotal))
|
|
|
|
}
|
|
|
|
|
|
|
|
waitGroup.Wait()
|
|
|
|
|
|
|
|
if err := gif.EncodeAll(fp, &gif.GIF{Image: framesPal, Delay: frameDelays}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("saved animation to %s", singleton.capturePath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
func renderDebug(target d2interface.Surface) error {
|
2020-02-08 21:02:37 -05:00
|
|
|
if singleton.showFPS {
|
2020-02-09 14:12:04 -05:00
|
|
|
vsyncEnabled := d2render.GetVSyncEnabled()
|
|
|
|
fps := d2render.CurrentFPS()
|
|
|
|
cx, cy := d2render.GetCursorPos()
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
target.PushTranslation(5, 565)
|
|
|
|
target.DrawText("vsync:" + strconv.FormatBool(vsyncEnabled) + "\nFPS:" + strconv.Itoa(int(fps)))
|
|
|
|
target.Pop()
|
|
|
|
|
|
|
|
var m runtime.MemStats
|
|
|
|
runtime.ReadMemStats(&m)
|
|
|
|
target.PushTranslation(680, 0)
|
|
|
|
target.DrawText("Alloc " + strconv.FormatInt(int64(m.Alloc)/1024/1024, 10))
|
|
|
|
target.PushTranslation(0, 16)
|
|
|
|
target.DrawText("Pause " + strconv.FormatInt(int64(m.PauseTotalNs/1024/1024), 10))
|
|
|
|
target.PushTranslation(0, 16)
|
|
|
|
target.DrawText("HeapSys " + strconv.FormatInt(int64(m.HeapSys/1024/1024), 10))
|
|
|
|
target.PushTranslation(0, 16)
|
|
|
|
target.DrawText("NumGC " + strconv.FormatInt(int64(m.NumGC), 10))
|
|
|
|
target.PushTranslation(0, 16)
|
|
|
|
target.DrawText("Coords " + strconv.FormatInt(int64(cx), 10) + "," + strconv.FormatInt(int64(cy), 10))
|
|
|
|
target.PopN(5)
|
2020-01-31 23:18:11 -05:00
|
|
|
}
|
2020-02-02 14:59:47 -05:00
|
|
|
|
|
|
|
return nil
|
2020-01-31 23:18:11 -05:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:59:47 -05:00
|
|
|
func loadDataDict() error {
|
|
|
|
entries := []struct {
|
|
|
|
path string
|
|
|
|
loader func(data []byte)
|
|
|
|
}{
|
|
|
|
{d2resource.LevelType, d2datadict.LoadLevelTypes},
|
|
|
|
{d2resource.LevelPreset, d2datadict.LoadLevelPresets},
|
|
|
|
{d2resource.LevelWarp, d2datadict.LoadLevelWarps},
|
|
|
|
{d2resource.ObjectType, d2datadict.LoadObjectTypes},
|
|
|
|
{d2resource.ObjectDetails, d2datadict.LoadObjects},
|
|
|
|
{d2resource.Weapons, d2datadict.LoadWeapons},
|
|
|
|
{d2resource.Armor, d2datadict.LoadArmors},
|
|
|
|
{d2resource.Misc, d2datadict.LoadMiscItems},
|
|
|
|
{d2resource.UniqueItems, d2datadict.LoadUniqueItems},
|
|
|
|
{d2resource.Missiles, d2datadict.LoadMissiles},
|
|
|
|
{d2resource.SoundSettings, d2datadict.LoadSounds},
|
|
|
|
{d2resource.AnimationData, d2data.LoadAnimationData},
|
|
|
|
{d2resource.MonStats, d2datadict.LoadMonStats},
|
2020-06-29 12:37:11 -04:00
|
|
|
{d2resource.MonStats2, d2datadict.LoadMonStats2},
|
2020-06-27 23:15:20 -04:00
|
|
|
{d2resource.MonPreset, d2datadict.LoadMonPresets},
|
2020-05-08 12:33:37 -04:00
|
|
|
{d2resource.MagicPrefix, d2datadict.LoadMagicPrefix},
|
|
|
|
{d2resource.MagicSuffix, d2datadict.LoadMagicSuffix},
|
2020-06-13 19:52:22 -04:00
|
|
|
{d2resource.ItemStatCost, d2datadict.LoadItemStatCosts},
|
2020-06-18 22:42:38 -04:00
|
|
|
{d2resource.CharStats, d2datadict.LoadCharStats},
|
2020-06-20 11:52:55 -04:00
|
|
|
{d2resource.Hireling, d2datadict.LoadHireling},
|
2020-06-19 20:56:04 -04:00
|
|
|
{d2resource.Experience, d2datadict.LoadExperienceBreakpoints},
|
2020-06-20 11:54:23 -04:00
|
|
|
{d2resource.Gems, d2datadict.LoadGems},
|
2020-06-20 15:59:20 -04:00
|
|
|
{d2resource.DifficultyLevels, d2datadict.LoadDifficultyLevels},
|
2020-06-20 19:53:29 -04:00
|
|
|
{d2resource.AutoMap, d2datadict.LoadAutoMaps},
|
2020-06-21 16:45:22 -04:00
|
|
|
{d2resource.LevelDetails, d2datadict.LoadLevelDetails},
|
2020-06-21 18:48:53 -04:00
|
|
|
{d2resource.LevelMaze, d2datadict.LoadLevelMazeDetails},
|
2020-06-21 18:41:28 -04:00
|
|
|
{d2resource.LevelSubstitutions, d2datadict.LoadLevelSubstitutions},
|
2020-06-23 02:02:35 -04:00
|
|
|
{d2resource.CubeRecipes, d2datadict.LoadCubeRecipes},
|
2020-06-23 09:30:39 -04:00
|
|
|
{d2resource.SuperUniques, d2datadict.LoadSuperUniques},
|
2020-02-02 14:59:47 -05:00
|
|
|
}
|
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
d2datadict.InitObjectRecords()
|
|
|
|
|
2020-02-02 14:59:47 -05:00
|
|
|
for _, entry := range entries {
|
|
|
|
data, err := d2asset.LoadFile(entry.path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-02-02 14:59:47 -05:00
|
|
|
entry.loader(data)
|
2020-01-31 23:18:11 -05:00
|
|
|
}
|
|
|
|
|
2020-02-02 14:59:47 -05:00
|
|
|
return nil
|
|
|
|
}
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
func loadStrings() error {
|
|
|
|
tablePaths := []string{
|
|
|
|
d2resource.PatchStringTable,
|
|
|
|
d2resource.ExpansionStringTable,
|
|
|
|
d2resource.StringTable,
|
2020-01-31 23:18:11 -05:00
|
|
|
}
|
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
for _, tablePath := range tablePaths {
|
|
|
|
data, err := d2asset.LoadFile(tablePath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-06-22 17:36:45 -04:00
|
|
|
d2common.LoadTextDictionary(data)
|
2020-01-31 23:18:11 -05:00
|
|
|
}
|
|
|
|
|
2019-10-24 09:31:59 -04:00
|
|
|
return nil
|
|
|
|
}
|
2020-06-22 22:17:54 -04:00
|
|
|
|
2020-06-23 14:49:46 -04:00
|
|
|
func enableProfiler(profileOption string) interface{ Stop() } {
|
2020-06-22 22:17:54 -04:00
|
|
|
var options []func(*profile.Profile)
|
|
|
|
switch strings.ToLower(strings.Trim(profileOption, " ")) {
|
|
|
|
case "cpu":
|
|
|
|
log.Printf("CPU profiling is enabled.")
|
|
|
|
options = append(options, profile.CPUProfile)
|
|
|
|
case "mem":
|
|
|
|
log.Printf("Memory profiling is enabled.")
|
|
|
|
options = append(options, profile.MemProfile)
|
|
|
|
case "block":
|
|
|
|
log.Printf("Block profiling is enabled.")
|
|
|
|
options = append(options, profile.BlockProfile)
|
|
|
|
case "goroutine":
|
|
|
|
log.Printf("Goroutine profiling is enabled.")
|
|
|
|
options = append(options, profile.GoroutineProfile)
|
|
|
|
case "trace":
|
|
|
|
log.Printf("Trace profiling is enabled.")
|
|
|
|
options = append(options, profile.TraceProfile)
|
|
|
|
case "thread":
|
|
|
|
log.Printf("Thread creation profiling is enabled.")
|
|
|
|
options = append(options, profile.ThreadcreationProfile)
|
|
|
|
case "mutex":
|
|
|
|
log.Printf("Mutex profiling is enabled.")
|
|
|
|
options = append(options, profile.MutexProfile)
|
|
|
|
}
|
|
|
|
options = append(options, profile.ProfilePath("./pprof/"))
|
|
|
|
|
|
|
|
if len(options) > 1 {
|
2020-06-23 14:49:46 -04:00
|
|
|
return profile.Start(options...)
|
2020-06-22 22:17:54 -04:00
|
|
|
}
|
2020-06-23 14:49:46 -04:00
|
|
|
return nil
|
2020-06-22 22:17:54 -04:00
|
|
|
}
|