Module: Engine
- Defined in:
- lib/engine/gl.rb,
lib/engine/font.rb,
lib/engine/mesh.rb,
lib/engine/path.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, 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
- .close ⇒ Object
- .engine_started? ⇒ Boolean
- .fps ⇒ Object
- .main_game_loop(&first_frame_block) ⇒ Object
- .open_window ⇒ Object
- .print_fps(delta_time) ⇒ Object
- .set_opengl_blend_mode ⇒ Object
- .start(&first_frame_block) ⇒ Object
- .stop_game ⇒ Object
- .terminate ⇒ Object
Class Method Details
.close ⇒ Object
90 91 92 93 94 95 |
# File 'lib/engine/engine.rb', line 90 def self.close GameObject.destroy_all Component.erase_destroyed_components GameObject.erase_destroyed_objects GLFW.SetWindowShouldClose(Window.window, 1) end |
.engine_started? ⇒ Boolean
16 17 18 |
# File 'lib/engine/engine.rb', line 16 def self.engine_started? @engine_started end |
.fps ⇒ Object
86 87 88 |
# File 'lib/engine/engine.rb', line 86 def self.fps @fps end |
.main_game_loop(&first_frame_block) ⇒ Object
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 |
# File 'lib/engine/engine.rb', line 40 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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/engine/engine.rb', line 20 def self.open_window @old_time = Time.now @time = Time.now Window.create_window GLFW.MakeContextCurrent(Window.window) 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
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/engine/engine.rb', line 112 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
123 124 125 126 |
# File 'lib/engine/engine.rb', line 123 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(&first_frame_block) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/engine/engine.rb', line 7 def self.start(&first_frame_block) Engine::AutoLoader.load return if ENV["BUILDING"] == "true" open_window main_game_loop(&first_frame_block) terminate end |
.stop_game ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/engine/engine.rb', line 97 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 |