funfriend/src/funfriend.cr

77 lines
1.4 KiB
Crystal
Raw Normal View History

2023-05-30 15:47:50 +02:00
require "crystglfw"
require "lib_glfw"
require "crystgl"
require "crystimage"
require "./log.cr"
require "./gl.cr"
require "./textureman.cr"
require "./fontman.cr"
2023-05-31 12:14:38 +02:00
require "./soundman.cr"
2023-05-30 15:47:50 +02:00
require "./window_context.cr"
require "./funfriend_context.cr"
require "./funfriend_renderer.cr"
require "./chatter_context.cr"
require "./text_renderer.cr"
include CrystGLFW
include CrystGL
2023-05-29 14:55:38 +02:00
module Funfriend
VERSION = "0.1.0"
2023-05-30 15:47:50 +02:00
LOG = ::Log.for("")
@@contexts = [] of WindowContext
@@main_context : WindowContext?
def self.should_close?
@@main_context && @@main_context.not_nil!.window.should_close?
end
def self.init_contexts
add_context(FunfriendContext.new)
@@main_context = @@contexts[0]
2023-05-31 12:14:38 +02:00
at_exit { contexts.each &.destroy }
2023-05-30 15:47:50 +02:00
end
def self.add_context(context : WindowContext)
@@contexts << context
end
def self.contexts
@@contexts
end
def self.run
Logging.init
2023-05-31 12:14:38 +02:00
SoundMan.init
2023-05-30 15:47:50 +02:00
CrystGLFW.run do
init_contexts
last_t = CrystGLFW.time
until should_close?
dt = CrystGLFW.time - last_t
last_t = CrystGLFW.time
@@contexts = @@contexts.select do |context|
if context.window.should_close?
context.close
2023-05-31 12:14:38 +02:00
at_exit { context.clean_up }
2023-05-30 15:47:50 +02:00
false
else
context.update(dt)
true
end
end
CrystGLFW.wait_events(1/120)
end
end
end
2023-05-29 14:55:38 +02:00
end
2023-05-30 15:47:50 +02:00
Funfriend.run