-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.odin
211 lines (204 loc) · 8.87 KB
/
main.odin
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package main
import "core:log"
import "core:mem"
import "core:thread"
import "core:math"
import "core:math/linalg"
import "engine"
import "engine/ecs"
import "engine/platform"
import "engine/renderer"
import rt "engine/renderer/types"
Window_State :: struct {
x, y: i32,
width, height: u32,
window_id: platform.Window_Id,
window_context_handle: rt.Window_Context_Handle,
is_fullscreen: bool,
is_destroyed: bool,
is_created: bool,
}
//worker :: proc(t: ^thread.Thread) {
// windows := make(map[platform.Window_Id]Window_State)
// defer delete(windows)
//
// for i in 0..<1 {
// x := i < 2 ? 100 : 900
// y := i % 2 == 0 ? 100 : 700
// window_id := platform.create_window({"Chronicle", i32(x), i32(y), 800, 600})
// windows[window_id] = {window_id = window_id}
// }
//
//
// for {
// for event in platform.poll() {
// switch _ in event {
// case platform.Window_Close_Requested_Event:
// window_id := event.(platform.Window_Close_Requested_Event).window_id
// platform.destroy_window(window_id)
//
// window := windows[window_id]
// window.is_destroyed = true
// windows[window_id] = window
//
// case platform.Window_Created_Event:
// window_created_event := event.(platform.Window_Created_Event)
// //log.infof("Window created: %v", window_created_event)
//
// window := windows[window_created_event.window_id]
// window_context_handle, _ := renderer.init_window(window_created_event.instance,
// window_created_event.handle,
// window.width, window.height)
// window.window_context_handle = window_context_handle
// window.is_created = true
// windows[window_created_event.window_id] = window
//
// case platform.Window_Destroyed_Event:
// window_destroyed_event := event.(platform.Window_Destroyed_Event)
// //log.infof("Window destroyed: %v", window_destroyed_event)
//
// window := windows[window_destroyed_event.window_id]
// if window.window_context_handle != nil {
// renderer.destroy_window(window.window_context_handle)
// }
// delete_key(&windows, window_destroyed_event.window_id)
//
// case platform.Window_Moved_Event:
// window_move_event := event.(platform.Window_Moved_Event)
// //log.infof("Window moved: %v", window_move_event)
//
// case platform.Window_Resized_Event:
// window_resized_event := event.(platform.Window_Resized_Event)
// //log.infof("Window resized: %v", window_resized_event)
//
// window := windows[window_resized_event.window_id]
// window.width = u32(window_resized_event.width)
// window.height = u32(window_resized_event.height)
// // TODO: we need to resize the renderer here?
// if window.window_context_handle != nil {
// renderer.resize_window(window.window_context_handle,
// u32(window_resized_event.width),
// u32(window_resized_event.height))
// }
// windows[window_resized_event.window_id] = window
//
// case platform.Key_Event:
// key_event := event.(platform.Key_Event)
// log.infof("Key event: %v", key_event)
// #partial switch key_event.key {
// case .Key_0:
// platform.set_window_position(key_event.window_id, 0, 0)
// case .Key_1:
// platform.set_window_size(key_event.window_id, 1920, 1080)
// case .Key_2:
// platform.set_window_title(key_event.window_id, "New Title")
// case .Key_F:
// if key_event.pressed {
// window := windows[key_event.window_id]
// window.is_fullscreen = !window.is_fullscreen
// platform.set_window_fullscreen(key_event.window_id, window.is_fullscreen)
// windows[key_event.window_id] = window
// }
// case:
// }
// case platform.Char_Event:
// char_event := event.(platform.Char_Event)
// log.infof("Char event: %c", char_event.character)
// case platform.Mouse_Event:
// mouse_event := event.(platform.Mouse_Event)
// //log.infof("Mouse event: %v", mouse_event)
// case platform.Gamepad_Event:
// gamepad_event := event.(platform.Gamepad_Event)
// log.infof("Gamepad event: %v", gamepad_event)
// case platform.Gamepad_Button_Event:
// gamepad_button_event := event.(platform.Gamepad_Button_Event)
// log.infof("Gamepad button event: %v", gamepad_button_event)
// case platform.Gamepad_Axis_Event:
// gamepad_axis_event := event.(platform.Gamepad_Axis_Event)
// log.infof("Gamepad axis event: %v", gamepad_axis_event)
// }
// }
//
// all_closed := true
// for _, window in windows {
// if !window.is_destroyed {
// all_closed = false
// //break
//
// if window.is_created && window.window_context_handle != nil &&
// renderer.begin_frame(window.window_context_handle, 0.0) {
// projection := linalg.matrix4_perspective_f32(math.to_radians_f32(45.0), 800.0/600.0, 0.1, 1000.0)
// view := linalg.matrix4_translate_f32(linalg.Vector3f32{0, 0, 30})
// view = linalg.matrix4x4_inverse(view)
// renderer.update_global_state(window.window_context_handle,
// projection,
// view,
// linalg.Vector3f32(0),
// linalg.Vector4f32(1),
// 0)
//
// //model := linalg.matrix4_translate_f32(linalg.Vector3f32{0, 0, 0})
// //rotation := linalg.matrix4_rotate_f32(math.to_radians_f32(0), linalg.Vector3f32{0, 1, 0})
// @(static) angle := f32(0)
// angle += 0.001
// rotation := linalg.quaternion_angle_axis_f32(angle, linalg.Vector3f32{0, 0, -1})
// model := linalg.matrix4_from_trs_f32(linalg.Vector3f32{0, 0, 0}, rotation, linalg.Vector3f32{1, 1, 1})
// renderer.update_object(window.window_context_handle, model)
//
// renderer.end_frame(window.window_context_handle, 0.0)
// }
// }
// }
//
// if all_closed {
// break
// }
//
// thread.yield()
// }
//
// for _, window in windows {
// if window.window_context_handle != nil {
// renderer.destroy_window(window.window_context_handle)
// }
// }
//}
main :: proc() {
engine.run({"Chronicle", "0.1.0"})
//log_options := log.Options{.Level, .Date, .Time, .Procedure, .Line, .Terminal_Color} | log.Default_File_Logger_Opts
//context.logger = log.create_console_logger(opt=log_options)
//
//tracking_allocator: mem.Tracking_Allocator
//when ODIN_DEBUG {
// default_allocator := context.allocator
// mem.tracking_allocator_init(&tracking_allocator, default_allocator)
//
// context.allocator = mem.tracking_allocator(&tracking_allocator)
//}
//
//if !platform.init() {
// log.error("Failed to initialize platform")
// return
//}
//
//ecs.init()
//if !renderer.init(.Vulkan, "Chronicle") {
// log.error("Failed to initialize renderer")
// return
//}
//
//platform.run(worker)
//
//renderer.destroy()
//ecs.destroy()
//platform.destroy()
//
//free_all(context.temp_allocator)
//
//when ODIN_DEBUG {
// for _, value in tracking_allocator.allocation_map {
// log.errorf("%v: Leaked %v bytes", value.location, value.size)
// }
//}
//log.info("END OF PROGRAM")
}