-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoop.go
More file actions
113 lines (81 loc) · 2.32 KB
/
Loop.go
File metadata and controls
113 lines (81 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package bl
import (
"container/list"
"github.com/amortaza/go-bellina/debug"
"github.com/amortaza/go-bellina/funclist"
)
var g_buffersFilled = 0
var g_fps = debug.NewFPS()
func bl_onLoop() {
debug.Log("-------------------- Starting loop", debug.Loop)
g_fps.Tick()
// store the last frame
g_lastFrame_nodeById = g_nodeById
// Clear Nodes
debug.Log("-------------------- Clearning Nodes", debug.Loop)
g_nodeById = make(map[string] *Node)
Root_Node = nil
// Clear Short Term
g_shortTerm_callbacksByEventType = make(map[string] *list.List)
g_LifeCycle_AfterUser_Ticks_ShortTerm = funclist.New()
g_nodes_are_immutable = false
// long term ticks
g_LifeCycle_BeforeUser_Ticks_LongTerm.CallAll()
debug.Log("-------------------- Starting to build nodes", debug.Loop)
g_user_tick()
debug.Log("-------------------- Finished building nodes", debug.Loop)
//
sizeRootShadowToWindow()
// long term ticks
g_LifeCycle_AfterUser_Ticks_LongTerm.CallAll()
// short term ticks
g_LifeCycle_AfterUser_Ticks_ShortTerm.CallAll()
if Root_Node != nil {
stabilize(Root_Node)
syncFromShadow_Position_and_Dimension(Root_Node)
mark_new_and_changed_nodes_and_their_parents_dirty(Root_Node)
garbage_collect_removed_nodes_and_mark_their_parents_dirty()
if Root_Node.Dirty {
g_buffersFilled = 0
}
// on some machines without filling at least 2 buffers, the screen flashes
// I do not know what is causing this - but this is the workaround
if g_buffersFilled < 2 {
g_buffersFilled++
render()
}
}
if g_nodeStack.Size > 0 {
panic("Node stack memory leak")
}
g_nodes_are_immutable = true
debug.Log("<<<<<<<<<<<<<<<< exiting loop", debug.Loop)
}
func render() {
w, h := g_hal.GetWindowDim()
g_graphics.PushView(w, h)
g_graphics.Clear(.3, .3, .3)
canvas := renderCanvas(Root_Node)
canvas.Paint(true, 0, 0, g_four_ones)
g_graphics.PopView()
}
func stabilize(node *Node) {
if node.stabilize_funcs_pre_kids != nil {
node.stabilize_funcs_pre_kids.CallAll()
}
for k := node.Kids.Front(); k != nil; k = k.Next() {
kid := k.Value.(*Node)
stabilize(kid)
}
if node.stabilize_funcs_post_kids != nil {
node.stabilize_funcs_post_kids.CallAll()
}
}
func sizeRootShadowToWindow() {
if Root_Node == nil {
return
}
shadow := EnsureShadowById("ROOT")
shadow.Width = Window_Width
shadow.Height = Window_Height
}