module Smalruby3

Constants

VERSION

Public Class Methods

s2dx() click to toggle source
# File lib/smalruby3.rb, line 48
def s2dx
  world.s2dx
end
start() click to toggle source
# File lib/smalruby3.rb, line 32
def start
  @started = true
  begin
    start_window_application
  rescue SystemExit
  end
end
started?() click to toggle source
# File lib/smalruby3.rb, line 40
def started?
  @started
end
wait() click to toggle source
# File lib/smalruby3.rb, line 52
def wait
  if Thread.current == Thread.main
    sleep(1.0 / 15)
  else
    @draw_mutex.synchronize do
      @draw_cv.wait(@draw_mutex)
    end
  end
end
world() click to toggle source
# File lib/smalruby3.rb, line 44
def world
  World.instance
end

Private Class Methods

activate_window() click to toggle source
# File lib/smalruby3.rb, line 80
def activate_window
  if !Util.windows?
    return
  end

  require "Win32API"

  # see http://f.orzando.net/pukiwiki-plus/index.php?Programming%2FTips
  hwnd_active =
    Win32API.new("user32", "GetForegroundWindow", nil, "i").call
  this_thread_id =
    Win32API.new("Kernel32", "GetCurrentThreadId", nil, "i").call
  active_thread_id =
    Win32API.new("user32", "GetWindowThreadProcessId", %w(i p), "i").call(hwnd_active, 0)
  attach_thread_input =
    begin
      Win32API.new("user32", "AttachThreadInput", %w(i i i), "v")
    rescue
      Win32API.new("user32", "AttachThreadInput", %w(i i i), "i")
    end
  attach_thread_input.call(this_thread_id, active_thread_id, 1)
  Win32API.new("user32", "BringWindowToTop", %w(i), "i").call(DXRuby::Window.hWnd)
  attach_thread_input.call(this_thread_id, active_thread_id, 0)

  hwnd_topmost = -1
  swp_nosize = 0x0001
  swp_nomove = 0x0002
  Win32API.new("user32", "SetWindowPos", %w(i i i i i i i), "i").
    call(DXRuby::Window.hWnd, hwnd_topmost, 0, 0, 0, 0, swp_nosize | swp_nomove)
end
init_window_application() click to toggle source
# File lib/smalruby3.rb, line 64
def init_window_application
  DXRuby::Window.caption = File.basename($PROGRAM_NAME)
  DXRuby::Window.width = s2dx.window_width
  DXRuby::Window.height = s2dx.window_height
  DXRuby::Window.fps = s2dx.fps
  DXRuby::Window.bgcolor = [255, 255, 255]

  # HACK: for DXRuby. occur error if didn't initialize DirectSound.
  begin
    DXRuby::Sound.new("")
  rescue
  end

  activate_window
end
lock() { || ... } click to toggle source
# File lib/smalruby3.rb, line 136
def lock
  @draw_mutex.synchronize do
    yield
    @draw_cv.broadcast
  end
end
start_window_application() click to toggle source
# File lib/smalruby3.rb, line 111
def start_window_application
  init_window_application

  first = true
  DXRuby::Window.loop do
    lock do
      if DXRuby::Input.key_down?(DXRuby::K_ESCAPE)
        exit
      end

      if first
        world.targets.each do |o|
          o.fire(:flag_clicked)
        end
        first = false
      end

      world.targets.each do |o|
        o.draw
        o.join_threads
      end
    end
  end
end

Public Instance Methods

sprite(name) click to toggle source
# File lib/smalruby3.rb, line 27
def sprite(name)
  Smalruby3.world.sprite(name)
end