Module: Engine
- Defined in:
- lib/engine/gl.rb,
lib/engine/font.rb,
lib/engine/mesh.rb,
lib/engine/path.rb,
lib/engine/debug.rb,
lib/engine/input.rb,
lib/engine/camera.rb,
lib/engine/cursor.rb,
lib/engine/engine.rb,
lib/engine/shader.rb,
lib/engine/window.rb,
lib/engine/texture.rb,
lib/engine/ui/rect.rb,
lib/engine/material.rb,
lib/engine/component.rb,
lib/engine/debugging.rb,
lib/engine/autoloader.rb,
lib/engine/quaternion.rb,
lib/engine/video_mode.rb,
lib/engine/game_object.rb,
lib/engine/metal/device.rb,
lib/engine/polygon_mesh.rb,
lib/engine/screenshoter.rb,
lib/engine/compute_shader.rb,
lib/engine/matrix_helpers.rb,
lib/engine/compute_texture.rb,
lib/engine/importers/obj_file.rb,
lib/engine/tangent_calculator.rb,
lib/engine/metal/compute_shader.rb,
lib/engine/metal/metal_bindings.rb,
lib/engine/metal/compute_texture.rb,
lib/engine/opengl/compute_shader.rb,
lib/engine/standard_objects/cube.rb,
lib/engine/importers/obj_importer.rb,
lib/engine/opengl/compute_texture.rb,
lib/engine/standard_objects/plane.rb,
lib/engine/importers/font_importer.rb,
lib/engine/standard_objects/sphere.rb,
lib/engine/standard_meshes/quad_mesh.rb,
lib/engine/serialization/serializable.rb,
lib/engine/serialization/graph_serializer.rb,
lib/engine/serialization/yaml_persistence.rb,
lib/engine/serialization/object_serializer.rb,
lib/engine/standard_objects/default_material.rb
Defined Under Namespace
Modules: AutoLoader, Components, Debug, Debugging, GL, MatrixHelpers, Metal, OpenGL, Physics, Serializable, Serialization, StandardObjects, UI
Classes: Camera, Component, ComputeShader, ComputeTexture, Cursor, Font, FontImporter, GameObject, Input, Material, Mesh, NoEarsException, ObjFile, ObjImporter, Path, PolygonMesh, QuadMesh, Quaternion, Screenshoter, Shader, TangentCalculator, Texture, VideoMode, Window
Class Method Summary
collapse
Class Method Details
.close ⇒ Object
95
96
97
98
99
100
|
# File 'lib/engine/engine.rb', line 95
def self.close
GameObject.destroy_all
Component.erase_destroyed_components
GameObject.erase_destroyed_objects
GLFW.SetWindowShouldClose(Window.window, 1)
end
|
.engine_started? ⇒ Boolean
20
21
22
|
# File 'lib/engine/engine.rb', line 20
def self.engine_started?
@engine_started
end
|
.fps ⇒ Object
91
92
93
|
# File 'lib/engine/engine.rb', line 91
def self.fps
@fps
end
|
.main_game_loop(&first_frame_block) ⇒ Object
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
|
# File 'lib/engine/engine.rb', line 45
def self.main_game_loop(&first_frame_block)
@game_stopped = false
@old_time = Time.now
@time = Time.now
@fps = 0
Window.get_framebuffer_size
Engine::GL.Clear(Engine::GL::COLOR_BUFFER_BIT | Engine::GL::DEPTH_BUFFER_BIT)
until GLFW.WindowShouldClose(Window.window) == GLFW::TRUE || @game_stopped
if first_frame_block
first_frame_block.call
first_frame_block = nil
end
@old_time = @time || Time.now
@time = Time.now
delta_time = @time - @old_time
print_fps(delta_time)
Physics::PhysicsResolver.resolve
GameObject.update_all(delta_time)
@swap_buffers_promise.wait! if @swap_buffers_promise
Rendering::RenderPipeline.draw unless @game_stopped
if Screenshoter.scheduled_screenshot
Screenshoter.take_screenshot
end
Window.get_framebuffer_size
if OS.windows?
GLFW.SwapBuffers(Window.window)
else
@swap_buffers_promise = Concurrent::Promise.new do
GLFW.SwapBuffers(Window.window)
end
@swap_buffers_promise.execute
end
Engine::Input.update_key_states
GLFW.PollEvents
end
end
|
.open_window ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/engine/engine.rb', line 24
def self.open_window
@old_time = Time.now
@time = Time.now
Window.create_window
GLFW.MakeContextCurrent(Window.window)
Engine::GL.InitGLEW
Input.init
Rendering::GpuTimer.enable if ENV['GPU_PROFILE']
set_opengl_blend_mode
@engine_started = true
Engine::GL.ClearColor(0.0, 0.0, 0.0, 1.0)
Engine::GL.Enable(Engine::GL::CULL_FACE)
Engine::GL.CullFace(Engine::GL::BACK)
GLFW.SwapInterval(0)
end
|
.print_fps(delta_time) ⇒ Object
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/engine/engine.rb', line 117
def self.print_fps(delta_time)
@time_since_last_fps_print = (@time_since_last_fps_print || 0) + delta_time
@frame = (@frame || 0) + 1
if @time_since_last_fps_print > 1
@fps = @frame / @time_since_last_fps_print
puts "FPS: #{@fps}"
@time_since_last_fps_print = 0
@frame = 0
end
end
|
.set_opengl_blend_mode ⇒ Object
128
129
130
131
|
# File 'lib/engine/engine.rb', line 128
def self.set_opengl_blend_mode
Engine::GL.Enable(Engine::GL::BLEND)
Engine::GL.BlendFunc(Engine::GL::SRC_ALPHA, Engine::GL::ONE_MINUS_SRC_ALPHA)
end
|
.start(close_key: Input::KEY_ESCAPE, debug_key: nil, fullscreen_key: nil, &first_frame_block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/engine/engine.rb', line 7
def self.start(close_key: Input::KEY_ESCAPE, debug_key: nil, fullscreen_key: nil, &first_frame_block)
Engine::AutoLoader.load
return if ENV["BUILDING"] == "true"
Input.close_key = close_key
Input.debug_key = debug_key
Input.fullscreen_key = fullscreen_key
open_window
main_game_loop(&first_frame_block)
terminate
end
|
.stop_game ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/engine/engine.rb', line 102
def self.stop_game
@game_stopped = true
@swap_buffers_promise.wait! if @swap_buffers_promise && !@swap_buffers_promise.complete?
GameObject.destroy_all
Component.erase_destroyed_components
GameObject.erase_destroyed_objects
end
|
.terminate ⇒ Object
112
113
114
115
|
# File 'lib/engine/engine.rb', line 112
def self.terminate
GLFW.DestroyWindow(Window.window)
GLFW.Terminate
end
|