Advertisement
Zeriab

[RGSS][Special] Code for loading font resources

Nov 6th, 2016
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.72 KB | None | 0 0
  1. # Used read parts of http://pastebin.com/mdW8D8fi
  2. module Utility
  3.   #############
  4.   # DLL STUFF #
  5.   #############
  6.   READ_INI         = Win32API.new('kernel32',  'GetPrivateProfileStringA',
  7.                                   %w(p p p p l p), 'l')
  8.   ##
  9.   # Read from system ini
  10.   # Note: Default app_name changed to 'Launcher'
  11.   #
  12.   def self.read_ini(key_name, app_name = 'Launcher', filename = 'Launcher.ini',
  13.                     buffer_size = 256, default = '')
  14.     buffer = "\0" * buffer_size
  15.     READ_INI.call(app_name, key_name, default, buffer, buffer_size - 1,
  16.                   ".\\" + filename)
  17.     return buffer.delete("\0")
  18.   end
  19. end
  20.  
  21. def create_sprite
  22.   sprite = Sprite.new
  23.   sprite.bitmap = Bitmap.new(640, 480)
  24.   return sprite
  25. end
  26.  
  27.  
  28. def update_sprite
  29.   @sprite ||= create_sprite
  30.   @sprite.bitmap.clear
  31.   @sprite.bitmap.draw_text(0, 0, 640, 480, "Loading fonts", 1)
  32. end
  33.  
  34. ##
  35. # Trying to load too many fonts may lead to "Script is Hanging" error
  36. # For mitigating that create a thread which will call Graphics.update
  37. # every second.
  38. #
  39. # Note: Each font load call is blocking, so there is still a risk of the
  40. # error occuring, the likelihood should hopefully be significantly reduced.
  41. #
  42. Thread.new {
  43.   loop do
  44.     # Lets the thread sleep for a while to minimize CPU usage
  45.     sleep 1
  46.     update_sprite
  47.     # Update the graphics to reset the "Script is Hanging" timer
  48.     Graphics.update
  49.   end
  50. }
  51.  
  52. # Read all .ttf file from the Fonts folder
  53. AddFontResource = Win32API.new('Gdi32', 'AddFontResource', 'p', 'l')
  54.  
  55. for filename in Dir.glob('Fonts/*.[Tt][Tt][Ff]')
  56.   AddFontResource.call(filename)
  57. end
  58.  
  59. # Run the actual game executable.
  60. game_name = Utility.read_ini('Game')
  61. Thread.new {system game_name}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement