RMXP - HBGE (0.0.4)

Quote:
All sounds great mate, but I'd suggest making sure when you get to the end you spell out in very simple terms everything this baby will be capable of! I don't want any of your guys hard work to be missed out on for lack of knowing or understanding. I'm sure you have all your bases covered. This sounds like something that should replace 100% of all RM new games.

I'm very interested in this graphic module... I don't understand it, but I'm very interested! 640 x 480 limitation is my biggest turn off for using RM at the moment. Will this graphics module be relatively Plug and Play? So basically if I make higher resolution tiles I can display at 1024 x 768 by default, or am I way off here?


Good to see some support for this. I hate the 640x480 resolution as well. It is so tiny. And yes, this will support any resolution such as 1024x768. It works just like in VX "Graphics.resize(width, height). If you used Sewlyn's Resolution system, if you ever performed a transition, only the original 640x480 area would be effected. Via. the screenshot script (which is now located in the Graphics module as snap_to_bitmap), transitions can be performed at any resolution. The only real difficulty I am having is creating a fast enough process that makes transformations via. Transition files happen more quickly. I wrote a transform method for the Sprite class, but it checks bitmaps on both files and actually takes awhile since the bitmap.get_pixel and set_pixel are slow. Works, just need to come up with a faster method.

The only other problem is the Tilemap class. I have fixed my last version so its bug free (I hope) (and am working on merging it to allow even more layer's via a program called Tiled) but it is still slower than the default C coded Tilemap class XP uses. I am going to try to learn some C and re-write this class or something to make performance not take a hit when dealing with higher resolutions.

Quote:
To require from the game directory I use
$LOAD_PATH << "."
require "Scripts/your_dir/script"

Is that what you want


I actually tried that as well, but it still errored. Not sure if I just corrupted my file or what the deal was, but I have a few ideas why its not working.

Quote:
In my opinion, the whole thing with trying to change the way that scripts are included with one another is a bad idea. In your example, the TripleTriad script would have been just fine if it was broken up into multiple files. A card is not a player, and therefore they should not have occupied the same file, or in this case script entry. I hope you at least plan to not break the original way, right?


Actually, those functions aren't for loading single files. I will have 3 functions, 1 that reads a directory and all sub directory and loads every file through all directories. Such as HBGE.load_library('Scripts/Ruby') and sub-folders with classes and modules with folders in those that it loads each .rb file. Second is just a lower level that reads files within a directory and loads .rb files. Lastly just a single file require.

Quote:
As for require, AFAIK Ruby just does an in-place evaluation. at the line that you put require. I think you'd get pretty close to what require does if you wrote it so that it loads the given file into a string and eval's it right there.


That's what I was going to end up doing when writing the functions for loading .rb files was using eval. Simple enough.

Quote:
As for graphics, did you replace the RMXP renderer, or just put the functions to resize the window? RMXP's default renderer is just GDI, so it's using software rendering. On my old P4 3.06Ghz HT 1024 x 768 was like 15 FPS, even if there were no sprites or anything else in the scene. Even just clearing that many pixels is difficult for it (It has to clear pixels one by one). I'm sure most people have better processors than that, but it's still something to watch out for.


I actually didn't touch the default Graphics#update method for the rendering. Every other method can be modified to work for higher resolution without destroying anything. If you are interested, current Graphics module code (I still have some work to do on it)
  1. #==============================================================================
  2. # ** Graphics
  3. #------------------------------------------------------------------------------
  4. # * Library
  5. #
  6. # Graphics:
  7. # ---------------------------------------------------------------------------
  8. # Graphics.screenshot
  9. # Graphics.snap_to_bitmap
  10. # Graphics.width
  11. # Graphics.height
  12. # Graphics.resize
  13. # Graphics.fullscreen
  14. # Graphics.size
  15. #==============================================================================
  16.  
  17. #==============================================================================
  18. # ** Graphics
  19. #==============================================================================
  20.  
  21. module Graphics
  22.   #--------------------------------------------------------------------------
  23.   # * Screenshot File Directory
  24.   #--------------------------------------------------------------------------
  25.   Screenshot_Dir = ''
  26.   #--------------------------------------------------------------------------
  27.   # * Screenshot (By Andreas21 & Cybersam)
  28.   #
  29.   #   image_type : 0 - bmp, 1 - jpg, 2 - png
  30.   #--------------------------------------------------------------------------
  31.   def self.screenshot(filename = 'screenshot', image_type = 2)
  32.     # Adds File Extension
  33.     filename += image_type == 0 ? '.bmp' : image_type == 1 ? '.jpg' : '.png'
  34.     # Create True Filename
  35.     file_name = Screenshot_Dir + filename
  36.     # Make Screenshot
  37.     API::Screenshot.Screenshot(0, 0, self.width, self.height, file_name,
  38.       API.hwnd, image_type)
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # * Snap to Bitmap
  42.   #--------------------------------------------------------------------------
  43.   def self.snap_to_bitmap
  44.     # Take Screenshot
  45.     self.screenshot('snap_to_bitmap')
  46.     # Load Bitmap
  47.     bitmap = Bitmap.new('snap_to_bitmap')
  48.     # Delete Screenshot
  49.     File.delete('snap_to_bitmap.png')
  50.     # Return Bitmap
  51.     return bitmap
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # * Width
  55.   #--------------------------------------------------------------------------
  56.   def self.width
  57.     return @width == nil ? 640 : @width
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # * Height
  61.   #--------------------------------------------------------------------------
  62.   def self.height
  63.     return @height == nil ? 480 : @height
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # * Resize
  67.   #--------------------------------------------------------------------------
  68.   def self.resize(width = Default_Width, height = Default_Height,
  69.       fs = @fullscreen)
  70.     # Saves Width & Height
  71.     @width, @height = width, height
  72.     # Modify Transition Viewport
  73.     @transition_viewport.dispose
  74.     @transition_sprite.dispose
  75.     @transition_viewport = Viewport.new(0, 0, @width, @height)
  76.     @transition_viewport.z = 99999
  77.     @transition_sprite = Sprite.new(@transition_viewport)
  78.     # Set Resolution
  79.     self.set_resolution(fs)
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # * Set Resolution
  83.   #--------------------------------------------------------------------------
  84.   private
  85.   def self.set_resolution(fullscreen = !@fullscreen)
  86.     if fullscreen
  87.       API::User32.SetWindowLong.call(API.hwnd, API::User32::GWL_STYLE, API::User32::WS_VISIBLE|API::User32::WS_CLIPSIBLINGS)
  88.       API::User32.SetWindowPos.call(API.hwnd, HWND_TOPMOST, 0, 0, @width, @height, API::User32::SWP_SHOWWINDOW)
  89.       API::Display.Set_Res.call(@width, @height, 4)
  90.     else
  91.       w = @width + (2 * API::User32.GetSystemMetrics(API::User32::SM_CXFIXEDFRAME))
  92.       h = @height + (2 * API::User32.GetSystemMetrics(API::User32::SM_CYFIXEDFRAME)) +
  93.         API::User32.GetSystemMetrics(API::User32::SM_CYCAPTION)
  94.       x = (@default_size[0] - w) / 2
  95.       y = (@default_size[1] - h) / 2
  96.       API::User32.SetWindowLong(API.hwnd, API::User32::GWL_STYLE,
  97.         API::User32::WS_VISIBLE|API::User32::WS_CLIPSIBLINGS|API::User32::WS_CAPTION|API::User32::WS_SYSMENU|API::User32::WS_MINIMIZEBOX)
  98.       API::User32.SetWindowPos(API.hwnd, API::User32::HWND_TOP, x, y, w, h, API::User32::SWP_SHOWWINDOW)
  99.       self.update
  100.       API::Display.SetResolution(@default_size[0], @default_size[1], 0)
  101.     end
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # * Size
  105.   #--------------------------------------------------------------------------
  106.   private
  107.   def self.size
  108.     return API::User32.GetSystemMetrics(0), API::User32.GetSystemMetrics(1)
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * Resized?
  112.   #--------------------------------------------------------------------------
  113.   private
  114.   def self.resized?
  115.     return @width > 640 || @height > 480
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # * Save Default Instances
  119.   #--------------------------------------------------------------------------
  120.   @default_size = self.size
  121.   @width        = self.width
  122.   @height       = self.height
  123.   @fullscreen   = false
  124.   #--------------------------------------------------------------------------
  125.   # * Tranisition Viewport & Sprite
  126.   #--------------------------------------------------------------------------
  127.   @transition_viewport = Viewport.new(0, 0, @width, @height)
  128.   @transition_viewport.z = 99999
  129.   @transition_sprite = Sprite.new(@transition_viewport)
  130. end
  131.  
  132. # Resize
  133. Graphics.resize
Expand to see the code.


What is left is keeping it from changing resolution when Alt+Enter is pressed. I tried quite a few ways for doing this (disabling key enter while Alt is pressed via various API), but couldn't figure it out).

Quote:
Alright, so I took a look in eval.c of the Ruby 1.8.6 source code, and for .rb files, require does just what I said. So you can emulate that aspect of require with just a simple eval() of the contents of the file you want to require. As for .so objects, I forget whether Enterbrain just undefined the ruby method "require" or whether they legit gimped the C function rb_require. I do not have RMXP installed, so I can't do it myself, but the first thing I would try is to write a DLL which redefines the ruby function require to call rb_require. If that doesn't work, then I would take a look at the rb_require file in eval.c of the ruby source code and recreate that function and define the ruby function "require" to call your recreated function.


Yeah, I ended up writing my own method for requiring files. Thanks for the info. :thumb:

Quote:
One reason I was trying to avoid the AWorks input was because it completely destroys the original module. That means you can't use the original module for stuff like game controllers anymore. It also requires a patch to fix events. As for your Graphics module, do you know how to add to the default module without breaking it?


Really? I tested it and it still checks the computer keys just fine. I've never had a problem with it at all. I believe there is a function that updates the Input constants when keys are configured when the user presses F1. I think all we would have to do is add something in the something like Input.update to check if a key is pressed (F1 or something) and it would call the function to update constants based off the registry values. Unless I am miss understanding something here... Shouldn't be a problem.

With what I posted above with a re-write of the Graphics module, its more of a update to the Graphics module to include a few more methods and functions (like found in VX). It shouldn't ever become a problem I would think.
SephirothSpawn wrote:

Quote:
As for graphics, did you replace the RMXP renderer, or just put the functions to resize the window? RMXP's default renderer is just GDI, so it's using software rendering. On my old P4 3.06Ghz HT 1024 x 768 was like 15 FPS, even if there were no sprites or anything else in the scene. Even just clearing that many pixels is difficult for it (It has to clear pixels one by one). I'm sure most people have better processors than that, but it's still something to watch out for.


I actually didn't touch the default Graphics#update method for the rendering. Every other method can be modified to work for higher resolution without destroying anything. If you are interested, current Graphics module code (I still have some work to do on it)
  1. #==============================================================================
  2. # ** Graphics
  3. #------------------------------------------------------------------------------
  4. # * Library
  5. #
  6. # Graphics:
  7. # ---------------------------------------------------------------------------
  8. # Graphics.screenshot
  9. # Graphics.snap_to_bitmap
  10. # Graphics.width
  11. # Graphics.height
  12. # Graphics.resize
  13. # Graphics.fullscreen
  14. # Graphics.size
  15. #==============================================================================
  16.  
  17. #==============================================================================
  18. # ** Graphics
  19. #==============================================================================
  20.  
  21. module Graphics
  22.   #--------------------------------------------------------------------------
  23.   # * Screenshot File Directory
  24.   #--------------------------------------------------------------------------
  25.   Screenshot_Dir = ''
  26.   #--------------------------------------------------------------------------
  27.   # * Screenshot (By Andreas21 & Cybersam)
  28.   #
  29.   #   image_type : 0 - bmp, 1 - jpg, 2 - png
  30.   #--------------------------------------------------------------------------
  31.   def self.screenshot(filename = 'screenshot', image_type = 2)
  32.     # Adds File Extension
  33.     filename += image_type == 0 ? '.bmp' : image_type == 1 ? '.jpg' : '.png'
  34.     # Create True Filename
  35.     file_name = Screenshot_Dir + filename
  36.     # Make Screenshot
  37.     API::Screenshot.Screenshot(0, 0, self.width, self.height, file_name,
  38.       API.hwnd, image_type)
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # * Snap to Bitmap
  42.   #--------------------------------------------------------------------------
  43.   def self.snap_to_bitmap
  44.     # Take Screenshot
  45.     self.screenshot('snap_to_bitmap')
  46.     # Load Bitmap
  47.     bitmap = Bitmap.new('snap_to_bitmap')
  48.     # Delete Screenshot
  49.     File.delete('snap_to_bitmap.png')
  50.     # Return Bitmap
  51.     return bitmap
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # * Width
  55.   #--------------------------------------------------------------------------
  56.   def self.width
  57.     return @width == nil ? 640 : @width
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # * Height
  61.   #--------------------------------------------------------------------------
  62.   def self.height
  63.     return @height == nil ? 480 : @height
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # * Resize
  67.   #--------------------------------------------------------------------------
  68.   def self.resize(width = Default_Width, height = Default_Height,
  69.       fs = @fullscreen)
  70.     # Saves Width & Height
  71.     @width, @height = width, height
  72.     # Modify Transition Viewport
  73.     @transition_viewport.dispose
  74.     @transition_sprite.dispose
  75.     @transition_viewport = Viewport.new(0, 0, @width, @height)
  76.     @transition_viewport.z = 99999
  77.     @transition_sprite = Sprite.new(@transition_viewport)
  78.     # Set Resolution
  79.     self.set_resolution(fs)
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # * Set Resolution
  83.   #--------------------------------------------------------------------------
  84.   private
  85.   def self.set_resolution(fullscreen = !@fullscreen)
  86.     if fullscreen
  87.       API::User32.SetWindowLong.call(API.hwnd, API::User32::GWL_STYLE, API::User32::WS_VISIBLE|API::User32::WS_CLIPSIBLINGS)
  88.       API::User32.SetWindowPos.call(API.hwnd, HWND_TOPMOST, 0, 0, @width, @height, API::User32::SWP_SHOWWINDOW)
  89.       API::Display.Set_Res.call(@width, @height, 4)
  90.     else
  91.       w = @width + (2 * API::User32.GetSystemMetrics(API::User32::SM_CXFIXEDFRAME))
  92.       h = @height + (2 * API::User32.GetSystemMetrics(API::User32::SM_CYFIXEDFRAME)) +
  93.         API::User32.GetSystemMetrics(API::User32::SM_CYCAPTION)
  94.       x = (@default_size[0] - w) / 2
  95.       y = (@default_size[1] - h) / 2
  96.       API::User32.SetWindowLong(API.hwnd, API::User32::GWL_STYLE,
  97.         API::User32::WS_VISIBLE|API::User32::WS_CLIPSIBLINGS|API::User32::WS_CAPTION|API::User32::WS_SYSMENU|API::User32::WS_MINIMIZEBOX)
  98.       API::User32.SetWindowPos(API.hwnd, API::User32::HWND_TOP, x, y, w, h, API::User32::SWP_SHOWWINDOW)
  99.       self.update
  100.       API::Display.SetResolution(@default_size[0], @default_size[1], 0)
  101.     end
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # * Size
  105.   #--------------------------------------------------------------------------
  106.   private
  107.   def self.size
  108.     return API::User32.GetSystemMetrics(0), API::User32.GetSystemMetrics(1)
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * Resized?
  112.   #--------------------------------------------------------------------------
  113.   private
  114.   def self.resized?
  115.     return @width > 640 || @height > 480
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # * Save Default Instances
  119.   #--------------------------------------------------------------------------
  120.   @default_size = self.size
  121.   @width        = self.width
  122.   @height       = self.height
  123.   @fullscreen   = false
  124.   #--------------------------------------------------------------------------
  125.   # * Tranisition Viewport & Sprite
  126.   #--------------------------------------------------------------------------
  127.   @transition_viewport = Viewport.new(0, 0, @width, @height)
  128.   @transition_viewport.z = 99999
  129.   @transition_sprite = Sprite.new(@transition_viewport)
  130. end
  131.  
  132. # Resize
  133. Graphics.resize
Expand to see the code.


What is left is keeping it from changing resolution when Alt+Enter is pressed. I tried quite a few ways for doing this (disabling key enter while Alt is pressed via various API), but couldn't figure it out).


Hehe, well, the good news is, I know how to disable Alt+Enter, and it is a matter of just catching and eating that set of keystrokes in C. I already have a DLL that does it made up for RMXP. If you can be patient, I will try to get RMXP installed ASAP and then I will modify the DLL to do specifically this. Let me know what other input-related things you want to do for it and I can add it in.

Oh, also, I will hopefully soon release my Input Complete script/dll combo, and maybe that can be used instead of Aleworks. Mine is specifically designed to be a drop-in replacement for RGSS Input module. It provides a 1:1 rewrite of all original features, plus it has full mouse, input and joystick/game controller support.

SephirothSpawn wrote:

Quote:
Alright, so I took a look in eval.c of the Ruby 1.8.6 source code, and for .rb files, require does just what I said. So you can emulate that aspect of require with just a simple eval() of the contents of the file you want to require. As for .so objects, I forget whether Enterbrain just undefined the ruby method "require" or whether they legit gimped the C function rb_require. I do not have RMXP installed, so I can't do it myself, but the first thing I would try is to write a DLL which redefines the ruby function require to call rb_require. If that doesn't work, then I would take a look at the rb_require file in eval.c of the ruby source code and recreate that function and define the ruby function "require" to call your recreated function.


Yeah, I ended up writing my own method for requiring files. Thanks for the info. :thumb:


Well, you still don't have .so requiring. Dunno if you want it (Wuuld let you do stuff like include the original Ruby socket library). I might be able to do it if you need it.

Also, for the graphics, it looks like your module only knows that it has been resized if the width and height are greater than 640 x 480. What if it is resized to 320 x 240? Or from 320 x 240 back up to 640 x 480?
Quote:
Hehe, well, the good news is, I know how to disable Alt+Enter, and it is a matter of just catching and eating that set of keystrokes in C. I already have a DLL that does it made up for RMXP. If you can be patient, I will try to get RMXP installed ASAP and then I will modify the DLL to do specifically this. Let me know what other input-related things you want to do for it and I can add it in.

Oh, also, I will hopefully soon release my Input Complete script/dll combo, and maybe that can be used instead of Aleworks. Mine is specifically designed to be a drop-in replacement for RGSS Input module. It provides a 1:1 rewrite of all original features, plus it has full mouse, input and joystick/game controller support.


That would be great. The alt-enter doesn't need to be removed, just modified to call the new resize method to toggle fullscreen status. There is no real rush here. If you can get it done within a month, that's all we really need. I would greatly appreciate it.

Input module rewrite sounds great. I guess it has full keyboard support correct? At first I did not like how the Keys module was made separate from the Input module (in Aleworks), but truth be told, I find it beneficial to have a separate module to hold the key constants so they do not interferer with the Input constants (Input C vs. Keyboard C).

Quote:
Well, you still don't have .so requiring. Dunno if you want it (Wuuld let you do stuff like include the original Ruby socket library). I might be able to do it if you need it.

Also, for the graphics, it looks like your module only knows that it has been resized if the width and height are greater than 640 x 480. What if it is resized to 320 x 240? Or from 320 x 240 back up to 640 x 480?


Personally I have never used .so files, just because my coding experience outside of Ruby is very limited. I have only got into API over the last year, but nothing extensive. Anything you can do to add to this that would allow others benefit would be great.

And as far as resizing testing, I just simply haven't fully finished that aspect. It was a quick a simple conditional I threw in there so if the resolution was greater than what was supported in the transition process, to run the custom process. The only purpose I can see for changing this to support lower resolutions would be to just resize the Transition files, but would that really need to be required? If a person makes a game in a certain resolution, I am sure there transition files will be that resolution and as is, it supports resolutions less than 640x480.
Heh, well then in that case, maybe it was just poor nomenclature on that function. Perhaps self.enlarged would work better?

I forget the specifics of the constants in my Input module (It's been a couple months since I looked at it) but I believe the original virtual buttons are the same (Input::C, Input::B) and the others have a KEY_ prefix (Input::KEY_C, Input::KEY_B). The joystick has it's own module, because the joystick has to be done a different way. I believe I currently have those functions in Input::Joystick. I may have only moved internal variables to the other module, I forget.

Also, yes, it has full keyboard support (Currently, I believe about 100 keys have constants, but adding more keys is as simple as defining more constants) full mouse support (Only will understand 3 buttons, so I guess that doesn't quite count as full.) and full gamepad/joystick support (6 axes, 2 POV and 32 buttons. That's what DirectInput understands.) Currently, only one joystick is supported, but I could add support for more for like multiplayer games, but I figure no one plays multiplayer PC games on one PC.

For the .so files, I was thinking not necessary along the lines of people making their own libraries, but re-including RMXP's default library. For instance, some people are trying to make web browsers in RMXP using that RGSS socket library floating around. Net::HTTP (which is removed from RGSS) could be re-included from the Ruby core (the .so files for each of the libraries that were removed can be found in the src directory of the Ruby distribution) However, I am not entirely sure yet how it could be worked in. I don't know if you can hijack ruby through a DLL the way you can a window.
Updates:

I have the requiring working. I found that XP doesn't like if you put all the default editor classes in .rb files and then try to call them. I am not 100% sure why, but shouldn't case us any problems.

I am currently updating all files to use RDoc formatting. I won't do them all before the next update just so I can get this update posted so others can begin work on it. This is all just to keep formatting minimal while at the same time providing constant documentation on what we got going on here.

Update:

Updated to Version 0.0.4. See main post for details.
I have fixed the 0.0.4 download link :cute:
I'm glad this progresses nicely... I tried to get to some scripting once in a while, but I'm kind of busy with the rest of my armful of projects... :blank:

If it doesn't work out for me anytime soon, I guess I'll be only here to nag about how to improve it from a very unique and not quite necessary perfectionist's viewpoint :p But yeah... I'll try!
That's just what this project needs: perfectionist. Luckily I am a pretty big one myself, but getting a mass opinion on perfection and collaborated input makes this usually more "perfect."
I guess this project is going to be a good one. BTW, I just wanted to tell you there's a small modification anyone can do in this method.

  1.  def Math.A(m,n)
  2.     raise ArgumentError.new('Ackermann: No negative values allowed.') if m < 0 or n < 0
  3.     return n + 1 if m == 0
  4.     return Math.A(m - 1, 1) if n == 0
  5.     return Math.A(m - 1, Math.A(m, n - 1))
  6.   end
Expand to see the code.


  1.  def Math.A(m,n)
  2.     raise ArgumentError, 'Ackermann: No negative values allowed.' if m < 0 or n < 0
  3.     return n + 1 if m == 0
  4.     return Math.A(m - 1, 1) if n == 0
  5.     return Math.A(m - 1, Math.A(m, n - 1))
  6.   end
Expand to see the code.


It's just a very simple thing, I know, but it makes it quite unnecessary to create a new ArgumentError class there.
I'm not sure if you're still working on this, but I would highly recommend using a more recent version of RDoc, as the templating system has been re-designed from scratch and is much, much better now, both in terms of aesthetics and usability.

Use RubyForge's most recent RDoc: http://rdoc.rubyforge.org/
ha ha, i like it, thanks hbgames.
This seams pretty neat, you think there is a possibility this project might break off from being constricted to RM? It seems like this could possibly evolve into something brand new, seeing as your making your own database stuffs :huh:

I wanted to check it out, but unfortunately the links were down :fap:

Well, either way this sounds like it could be a pretty sickmade project, maybe I'll crawl out of my gutter and put some work in... maybe :tongue:

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=70229