1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-11 18:20:42 +00:00

Check and start profiler first (#520)

This commit is contained in:
Intyre 2020-07-02 01:24:09 +02:00 committed by GitHub
parent c8ec4c018e
commit 8e2c7d1f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,10 +70,10 @@ const nSamplesTAlloc = 100
// Create creates a new instance of the application // Create creates a new instance of the application
func Create(gitBranch, gitCommit string, terminal d2interface.Terminal, audio d2interface.AudioProvider) *App { func Create(gitBranch, gitCommit string, terminal d2interface.Terminal, audio d2interface.AudioProvider) *App {
result := &App{ result := &App{
gitBranch: gitBranch, gitBranch: gitBranch,
gitCommit: gitCommit, gitCommit: gitCommit,
terminal: terminal, terminal: terminal,
audio: audio, audio: audio,
tAllocSamples: createZeroedRing(nSamplesTAlloc), tAllocSamples: createZeroedRing(nSamplesTAlloc),
} }
@ -82,8 +82,17 @@ func Create(gitBranch, gitCommit string, terminal d2interface.Terminal, audio d2
// Run executes the application and kicks off the entire game process // Run executes the application and kicks off the entire game process
func (p *App) Run() { func (p *App) Run() {
windowTitle := fmt.Sprintf("OpenDiablo2 (%s)", p.gitBranch) profileOption := kingpin.Flag("profile", "Profiles the program, one of (cpu, mem, block, goroutine, trace, thread, mutex)").String()
kingpin.Parse()
if len(*profileOption) > 0 {
profiler := enableProfiler(*profileOption)
if profiler != nil {
defer profiler.Stop()
}
}
windowTitle := fmt.Sprintf("OpenDiablo2 (%s)", p.gitBranch)
// If we fail to initialize, we will show the error screen // If we fail to initialize, we will show the error screen
if err := p.initialize(p.audio, p.terminal); err != nil { if err := p.initialize(p.audio, p.terminal); err != nil {
if gameErr := d2render.Run(updateInitError, 800, 600, windowTitle); gameErr != nil { if gameErr := d2render.Run(updateInitError, 800, 600, windowTitle); gameErr != nil {
@ -95,13 +104,6 @@ func (p *App) Run() {
return return
} }
if len(p.profileOption) > 0 {
profiler := enableProfiler(p.profileOption)
if profiler != nil {
defer profiler.Stop()
}
}
d2screen.SetNextScreen(d2gamescreen.CreateMainMenu(p.audio, p.terminal)) d2screen.SetNextScreen(d2gamescreen.CreateMainMenu(p.audio, p.terminal))
if p.gitBranch == "" { if p.gitBranch == "" {
@ -116,11 +118,6 @@ func (p *App) Run() {
} }
func (p *App) initialize(audioProvider d2interface.AudioProvider, term d2interface.Terminal) error { func (p *App) initialize(audioProvider d2interface.AudioProvider, term d2interface.Terminal) error {
profileOption := kingpin.Flag("profile", "Profiles the program, one of (cpu, mem, block, goroutine, trace, thread, mutex)").String()
kingpin.Parse()
p.profileOption = *profileOption
p.timeScale = 1.0 p.timeScale = 1.0
p.lastTime = d2common.Now() p.lastTime = d2common.Now()
p.lastScreenAdvance = p.lastTime p.lastScreenAdvance = p.lastTime
@ -462,7 +459,7 @@ func (p *App) update(target d2interface.Surface) error {
func (p *App) allocRate(totalAlloc uint64, fps float64) float64 { func (p *App) allocRate(totalAlloc uint64, fps float64) float64 {
p.tAllocSamples.Value = totalAlloc p.tAllocSamples.Value = totalAlloc
p.tAllocSamples = p.tAllocSamples.Next() p.tAllocSamples = p.tAllocSamples.Next()
deltaAllocPerFrame := float64(totalAlloc - p.tAllocSamples.Value.(uint64)) / nSamplesTAlloc deltaAllocPerFrame := float64(totalAlloc-p.tAllocSamples.Value.(uint64)) / nSamplesTAlloc
return deltaAllocPerFrame * fps / bytesToMegabyte return deltaAllocPerFrame * fps / bytesToMegabyte
} }