Skip to content

Instantly share code, notes, and snippets.

View Groogy's full-sized avatar

Groogy Groogy

View GitHub Profile
class FooBar
def initialize(@value = 0)
end
def value
@value
end
protected def value=(val)
@value = val
struct Vector2(Type)
SIZE = 2
TYPE = Type
ZERO = self.new()
ONE = self.new(1, 1)
property :x, :y
@x : Type
@y : Type
private macro do_math(operator, times)
self[{{SIZE - times}}].{{operator}}(other[{{SIZE - times}})]
{% if times != 0 %}
, do_math({{operator}}, {{times - 1}})
{% end %}
end
def +(other : Vector(Type, Size))
self.class.new(do_math(:+, SIZE))
end
def self.translate(matrix : Matrix(T, 4, 16), translation : Vector(T, 3)) forall T
cpy = matrix.dup
cpy[3, 0] = translation.x
cpy[3, 1] = translation.y
cpy[3, 2] = translation.z
cpy
end
def self.translate(matrix : Matrix(T, 4, 16), translation : Vector(T, 3)) forall T
matrix[3, 0] = translation.x
module Boleite
abstract struct Configuration
end
abstract class Application
getter :configuration
@configuration : Configuration
def initialize()
# Binding code
type Monitor = Void*
type Window = Void*
type Cursor = Void*
# My code
module Boleite
# Forward declaration
class RenderTarget
receiver = Boleite::InputReceiver.new
receiver.action_table << Boleite::DefaultAction.new :close
receiver.action_table << Boleite::MoveCameraAction.new :player_camera
receiver.register :close, ->() { puts "Closing!" }
receiver.register :player_camera, ->(x : Float64, y : Float64) { puts "Moving camera!" }
receiver.process Boleite::ClosedEvent.new
receiver.process Boleite::MouseMovedEvent.new(some_x, some_y)
abstract class Glue
abstract def interested?(input) : Bool
abstract def execute(input) : Nil
end
class GlueImp(T, P) < Glue
def initialize(@bar : T, @callback : P)
end
def interested?(input) : Bool
if LibGLFW3.init != 0
error_callback = ->(error : Int32, description : Int8*) {
puts "Error #{error}: #{String.new(description.as(UInt8*))}"
}
LibGLFW3.setErrorCallback(error_callback)
LibGLFW3.windowHint(LibGLFW3::OPENGL_PROFILE, LibGLFW3::OPENGL_CORE_PROFILE)
LibGLFW3.windowHint(LibGLFW3::OPENGL_FORWARD_COMPAT, 1)
LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MAJOR, 4)
LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MINOR, 2)
if LibGLFW3.init != 0
error_callback = ->(error : Int32, description : Int8*) {
puts "Error #{error}: #{String.new(description.as(UInt8*))}"
}
LibGLFW3.setErrorCallback(error_callback)
LibGLFW3.windowHint(LibGLFW3::OPENGL_PROFILE, LibGLFW3::OPENGL_CORE_PROFILE)
LibGLFW3.windowHint(LibGLFW3::OPENGL_FORWARD_COMPAT, 1)
LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MAJOR, 4)
LibGLFW3.windowHint(LibGLFW3::CONTEXT_VERSION_MINOR, 2)