ruby_rpg 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 330046e92f39eef55aa6eb2a9e3af5661d1fb32980caa763f7ab74271a34453b
4
- data.tar.gz: 7ac94c71a7603d20a403a987f9dd7ade66a965aeb55a10c27fc8b6316f0b8eac
3
+ metadata.gz: bb76dd99560004e92918ecdb5910847e8939eb844488d04b2267c1f1cf044d10
4
+ data.tar.gz: 899699b008c112d351ae98e9ac2162995af0e83e5d001bbfebabc1f470f3821f
5
5
  SHA512:
6
- metadata.gz: 72447d06c63adfb058bdfba8743bd7254480729758f1145d2f66e671aac0051c2e978bf986d96822920a9b120d3b963458817c515c0e483eb25699b82f980863
7
- data.tar.gz: d6014f3da11f6a6694dfc31977b4ceb1f5140c08a5f27bb0b7045225b3362f709e81cfc12c2539ee415232d999540697f0510ce3dd5ba4b4b4653d2c00033d47
6
+ metadata.gz: d3a81d3ea6a574b25e7e17de6cf736becfbb2cfba20a82e90c7f0044bc37ab0c282bef5f07cbdb414ff037fe8d9151c281291bf86db9c081ddb3b973961ba8d4
7
+ data.tar.gz: 3141f56c495b22b7ffc587a1b3d136b8546c9da599a7391d63cb5cdee05a20bd0116fe25931365d1c93c4016fda32de1b96074bab7c970d05f3a97039fe32527
@@ -2,6 +2,10 @@
2
2
 
3
3
  require 'mkmf'
4
4
 
5
+ # A GL call with no prototype gets an implicit int return, which truncates
6
+ # pointers on 64-bit — fail the build instead
7
+ $CFLAGS << " -Werror=implicit-function-declaration" unless RUBY_PLATFORM =~ /mswin/
8
+
5
9
  # Find OpenGL
6
10
  case RUBY_PLATFORM
7
11
  when /darwin/
@@ -9,6 +13,7 @@ when /darwin/
9
13
  $CFLAGS << " -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Headers"
10
14
  when /linux/
11
15
  have_library('GL') or abort "OpenGL not found"
16
+ have_library('GLEW') or abort "GLEW not found (install libglew-dev)"
12
17
  when /mingw|mswin/
13
18
  glew_dir = File.expand_path('../../../vendor/glew-2.2.0-win32', __FILE__)
14
19
  $CFLAGS << " -I#{glew_dir}/include"
@@ -6,7 +6,7 @@
6
6
  extern void glBindImageTexture(GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format);
7
7
  extern void glDispatchCompute(GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z);
8
8
  extern void glMemoryBarrier(GLbitfield barriers);
9
- #elif defined(_WIN32) || defined(__MINGW32__)
9
+ #elif defined(_WIN32) || defined(__MINGW32__) || defined(__linux__)
10
10
  #include <GL/glew.h>
11
11
  #else
12
12
  #include <GL/gl.h>
@@ -490,9 +490,9 @@ static VALUE rb_gl_memory_barrier(VALUE self, VALUE barriers) {
490
490
  return Qnil;
491
491
  }
492
492
 
493
- /* Initialize GLEW (Windows only) */
493
+ /* Initialize GLEW (Windows and Linux) */
494
494
  static VALUE rb_gl_init_glew(VALUE self) {
495
- #if defined(_WIN32) || defined(__MINGW32__)
495
+ #if defined(_WIN32) || defined(__MINGW32__) || defined(__linux__)
496
496
  GLenum err = glewInit();
497
497
  if (err != GLEW_OK) {
498
498
  rb_raise(rb_eRuntimeError, "Failed to initialize GLEW: %s", glewGetErrorString(err));
@@ -579,6 +579,6 @@ void Init_gl_native(void) {
579
579
  rb_define_module_function(mGLNative, "dispatch_compute", rb_gl_dispatch_compute, 3);
580
580
  rb_define_module_function(mGLNative, "memory_barrier", rb_gl_memory_barrier, 1);
581
581
 
582
- /* GLEW initialization (Windows only, no-op on other platforms) */
582
+ /* GLEW initialization (Windows and Linux, no-op on macOS) */
583
583
  rb_define_module_function(mGLNative, "init_glew", rb_gl_init_glew, 0);
584
584
  }
@@ -52,6 +52,7 @@ typedef const GLFWvidmode* (*PFN_glfwGetVideoMode)(GLFWmonitor*);
52
52
  typedef const GLFWvidmode* (*PFN_glfwGetVideoModes)(GLFWmonitor*, int*);
53
53
  typedef void (*PFN_glfwSetInputMode)(GLFWwindow*, int, int);
54
54
  typedef int (*PFN_glfwGetInputMode)(GLFWwindow*, int);
55
+ typedef int (*PFN_glfwGetError)(const char**);
55
56
 
56
57
  /* Function pointers storage */
57
58
  static PFN_glfwInit pfn_glfwInit = NULL;
@@ -78,6 +79,7 @@ static PFN_glfwGetVideoMode pfn_glfwGetVideoMode = NULL;
78
79
  static PFN_glfwGetVideoModes pfn_glfwGetVideoModes = NULL;
79
80
  static PFN_glfwSetInputMode pfn_glfwSetInputMode = NULL;
80
81
  static PFN_glfwGetInputMode pfn_glfwGetInputMode = NULL;
82
+ static PFN_glfwGetError pfn_glfwGetError = NULL;
81
83
 
82
84
  /* Library handle */
83
85
  static void* glfw_lib = NULL;
@@ -145,6 +147,7 @@ static VALUE rb_glfw_load_lib(VALUE self, VALUE path) {
145
147
  pfn_glfwGetVideoModes = (PFN_glfwGetVideoModes)load_func("glfwGetVideoModes");
146
148
  pfn_glfwSetInputMode = (PFN_glfwSetInputMode)load_func("glfwSetInputMode");
147
149
  pfn_glfwGetInputMode = (PFN_glfwGetInputMode)load_func("glfwGetInputMode");
150
+ pfn_glfwGetError = (PFN_glfwGetError)load_func("glfwGetError");
148
151
 
149
152
  return Qtrue;
150
153
  }
@@ -215,6 +218,14 @@ static VALUE rb_glfw_set_window_monitor(VALUE self, VALUE window, VALUE monitor,
215
218
  return Qnil;
216
219
  }
217
220
 
221
+ /* GetError() */
222
+ static VALUE rb_glfw_get_error(VALUE self) {
223
+ if (!pfn_glfwGetError) return Qnil;
224
+ const char* description = NULL;
225
+ int code = pfn_glfwGetError(&description);
226
+ return rb_ary_new3(2, INT2NUM(code), description ? rb_str_new2(description) : Qnil);
227
+ }
228
+
218
229
  /* WindowShouldClose(window) */
219
230
  static VALUE rb_glfw_window_should_close(VALUE self, VALUE window) {
220
231
  if (!pfn_glfwWindowShouldClose) rb_raise(rb_eRuntimeError, "GLFW not loaded");
@@ -424,6 +435,7 @@ void Init_glfw_native(void) {
424
435
  rb_define_module_function(mGLFWNative, "set_window_attrib", rb_glfw_set_window_attrib, 3);
425
436
  rb_define_module_function(mGLFWNative, "set_window_title", rb_glfw_set_window_title, 2);
426
437
  rb_define_module_function(mGLFWNative, "set_window_monitor", rb_glfw_set_window_monitor, 7);
438
+ rb_define_module_function(mGLFWNative, "get_error", rb_glfw_get_error, 0);
427
439
  rb_define_module_function(mGLFWNative, "window_should_close", rb_glfw_window_should_close, 1);
428
440
  rb_define_module_function(mGLFWNative, "set_window_should_close", rb_glfw_set_window_should_close, 2);
429
441
  rb_define_module_function(mGLFWNative, "focus_window", rb_glfw_focus_window, 1);
data/lib/engine/engine.rb CHANGED
@@ -4,10 +4,11 @@ GAME_DIR = File.expand_path(File.dirname($PROGRAM_NAME))
4
4
  ENGINE_DIR = File.expand_path(File.dirname(__FILE__))
5
5
 
6
6
  module Engine
7
- def self.start(close_key: Input::KEY_ESCAPE, debug_key: nil, fullscreen_key: nil, &first_frame_block)
7
+ def self.start(close_key: Input::KEY_ESCAPE, debug_key: nil, fullscreen_key: nil, opengl_version: nil, &first_frame_block)
8
8
  Engine::AutoLoader.load
9
9
  return if ENV["BUILDING"] == "true"
10
10
 
11
+ Window.opengl_version = opengl_version if opengl_version
11
12
  Input.close_key = close_key
12
13
  Input.debug_key = debug_key
13
14
  Input.fullscreen_key = fullscreen_key
@@ -39,7 +40,7 @@ module Engine
39
40
  Engine::GL.Enable(Engine::GL::CULL_FACE)
40
41
  Engine::GL.CullFace(Engine::GL::BACK)
41
42
 
42
- GLFW.SwapInterval(OS.windows? ? 1 : 0)
43
+ GLFW.SwapInterval(OS.mac? ? 0 : 1)
43
44
  end
44
45
 
45
46
  def self.main_game_loop(&first_frame_block)
@@ -74,13 +75,16 @@ module Engine
74
75
 
75
76
  Window.get_framebuffer_size
76
77
 
77
- if OS.windows?
78
- GLFW.SwapBuffers(Window.window)
79
- else
78
+ if OS.mac?
79
+ # Async swap keeps the main thread free while waiting on the display link
80
80
  @swap_buffers_promise = Concurrent::Promise.new do
81
81
  GLFW.SwapBuffers(Window.window)
82
82
  end
83
83
  @swap_buffers_promise.execute
84
+ else
85
+ # GLX requires SwapBuffers on the thread owning the context, so
86
+ # Windows and Linux swap synchronously
87
+ GLFW.SwapBuffers(Window.window)
84
88
  end
85
89
 
86
90
  Engine::Input.update_key_states
data/lib/engine/gl.rb CHANGED
@@ -377,6 +377,7 @@ module Engine
377
377
  READ_FRAMEBUFFER = 0x8CA8
378
378
  READ_WRITE = 0x88BA
379
379
  REPEAT = 0x2901
380
+ RENDERER = 0x1F01
380
381
  REPLACE = 0x1E01
381
382
  RGB = 0x1907
382
383
  RGB16F = 0x881B
@@ -408,6 +409,7 @@ module Engine
408
409
  UNSIGNED_BYTE = 0x1401
409
410
  UNSIGNED_INT = 0x1405
410
411
  UNSIGNED_INT_24_8 = 0x84FA
412
+ VENDOR = 0x1F00
411
413
  VERTEX_SHADER = 0x8B31
412
414
  VERSION = 0x1F02
413
415
 
data/lib/engine/glfw.rb CHANGED
@@ -54,6 +54,10 @@ module GLFW
54
54
  GLFWNative.terminate
55
55
  end
56
56
 
57
+ def GetError
58
+ GLFWNative.get_error
59
+ end
60
+
57
61
  def CreateWindow(width, height, title, monitor, share)
58
62
  GLFWNative.create_window(width, height, title, monitor, share)
59
63
  end
data/lib/engine/window.rb CHANGED
@@ -8,6 +8,7 @@ module Engine
8
8
  class << self
9
9
  attr_accessor :full_screen, :window, :window_title
10
10
  attr_reader :framebuffer_height, :framebuffer_width
11
+ attr_writer :opengl_version
11
12
 
12
13
  def create_window
13
14
  set_opengl_version
@@ -18,6 +19,10 @@ module Engine
18
19
  @window = GLFW.CreateWindow(
19
20
  initial_video_mode.width, initial_video_mode.height, DEFAULT_TITLE, nil, nil
20
21
  )
22
+ if @window.nil?
23
+ code, description = GLFW.GetError
24
+ raise "Failed to create GLFW window (error #{code}: #{description})"
25
+ end
21
26
  GLFW.SetWindowMonitor(
22
27
  @window, nil, 0, 0,
23
28
  initial_video_mode.width, initial_video_mode.height,
@@ -114,9 +119,14 @@ module Engine
114
119
  @framebuffer_height = height_buf.unpack1('L')
115
120
  end
116
121
 
122
+ def opengl_version
123
+ @opengl_version || (OS.mac? ? "4.1" : "4.3")
124
+ end
125
+
117
126
  def set_opengl_version
118
- GLFW.WindowHint(GLFW::CONTEXT_VERSION_MAJOR, 4)
119
- GLFW.WindowHint(GLFW::CONTEXT_VERSION_MINOR, OS.mac? ? 1 : 3)
127
+ major, minor = opengl_version.split(".").map { |part| Integer(part) }
128
+ GLFW.WindowHint(GLFW::CONTEXT_VERSION_MAJOR, major)
129
+ GLFW.WindowHint(GLFW::CONTEXT_VERSION_MINOR, minor)
120
130
  GLFW.WindowHint(GLFW::OPENGL_PROFILE, GLFW::OPENGL_CORE_PROFILE)
121
131
  GLFW.WindowHint(GLFW::OPENGL_FORWARD_COMPAT, GLFW::TRUE)
122
132
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_rpg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Hatfull
@@ -312,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
312
312
  - !ruby/object:Gem::Version
313
313
  version: '0'
314
314
  requirements: []
315
- rubygems_version: 4.0.10
315
+ rubygems_version: 4.0.16
316
316
  specification_version: 4
317
317
  summary: A game engine written in Ruby
318
318
  test_files: []