mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
loop: Reduce defer for performance and readability
This commit is contained in:
parent
9f98ccc611
commit
56a17a7f79
@ -47,26 +47,28 @@ var (
|
||||
|
||||
func (c *runContext) startRunning() {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
c.running = true
|
||||
c.m.Unlock()
|
||||
}
|
||||
|
||||
func (c *runContext) isRunning() bool {
|
||||
c.m.RLock()
|
||||
defer c.m.RUnlock()
|
||||
return c.running
|
||||
v := c.running
|
||||
c.m.RUnlock()
|
||||
return v
|
||||
}
|
||||
|
||||
func (c *runContext) endRunning() {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
c.running = false
|
||||
c.m.Unlock()
|
||||
}
|
||||
|
||||
func (c *runContext) getCurrentFPS() float64 {
|
||||
c.m.RLock()
|
||||
defer c.m.RUnlock()
|
||||
if !c.running {
|
||||
v := c.running
|
||||
c.m.RUnlock()
|
||||
if !v {
|
||||
// TODO: Should panic here?
|
||||
return 0
|
||||
}
|
||||
@ -75,8 +77,8 @@ func (c *runContext) getCurrentFPS() float64 {
|
||||
|
||||
func (c *runContext) updateFPS(fps float64) {
|
||||
c.m.Lock()
|
||||
defer c.m.Unlock()
|
||||
c.currentFPS = fps
|
||||
c.m.Unlock()
|
||||
}
|
||||
|
||||
type GraphicsContext interface {
|
||||
|
Loading…
Reference in New Issue
Block a user