RGSS Questions and Answers

Started by Blizzard, March 26, 2011, 10:02:39 am

Previous topic - Next topic

Blizzard

March 26, 2011, 10:02:39 am Last Edit: May 14, 2012, 05:14:01 pm by Blizzard
I have noticed that there are things in RGSS and RMXP that we actually don't know and that we should know. This topic is here to keep a list of all questions and answers about RGSS and RMXP that we will need to answer and implement. Feel free to edit this post when you add a new question and/or answer.



What are the max dimensions for the Table class?

The maximum capacity of the Table class depends on the OS.  The no single dimension can be large enough to have the Fixnum converted to a Bignum. This will vary between x86 and x64 processors, but here would be the formula to figure it out:
FIXNUM_MAX = (2**(0.size * 8 -2) -1)
FIXNUM_MIN = -(2**(0.size * 8 -2))


Other than that though, I do believe it is only limited to the computer's memory.



How exactly are Color, Tone, Rect and Table instances store in Ruby Marshal?

Color: ShowHide

 def _dump(d = 0)
    [@red, @green, @blue, @alpha].pack('d4')
 end
 def self._load(s)
    Color.new(*s.unpack('d4'))
 end


Tone: ShowHide

 def _dump(d = 0)
    [@red, @green, @blue, @gray].pack('d4')
 end
 def self._load(s)
    Tone.new(*s.unpack('d4'))
 end


Rect: ShowHide

 def _dump(d = 0)
    [@x, @y, @width, @height].pack('l4')
 end
 def self._load(s)
    Rect.new(*s.unpack('l4'))
 end


Table: ShowHide

 def _dump(d = 0)
    s = [3].pack('L')
    s += [@xsize].pack('L') + [@ysize].pack('L') + [@zsize].pack('L')
    s += [@xsize * @ysize * @zsize].pack('L')
    for z in 0...@zsize
       for y in 0...@ysize
          for x in 0...@xsize
             s += [@data[x + y * @xsize + z * @xsize * @ysize]].pack('S')
          end
       end
    end
    s
 end
 
 def self._load(s)
    size = s[0, 4].unpack('L')[0]
    nx = s[4, 4].unpack('L')[0]
    ny = s[8, 4].unpack('L')[0]
    nz = s[12, 4].unpack('L')[0]
    data = []
    pointer = 20
    loop do
       data.push(*s[pointer, 2].unpack('S'))
       pointer += 2
       break if pointer > s.size - 1
    end
    t = Table.new(nx, ny, nz)
    n = 0
    for z in 0...nz
       for y in 0...ny
          for x in 0...nx
             t[x, y, z] = data[n]
             n += 1
          end
       end
    end
    t
 end




Does Table limit x, y, z if they are specified out of bounds or does it throw an error?

If access is attempted outside the bounds of the table, the return value is nil.



How exactly is Table serialized as Marshal object?

http://forum.chaos-project.com/index.php/topic,9103.msg140249.html#msg140249



What happens with Sprite#src_rect when Sprite#bitmap is set to a Bitmap instance or nil?

The src_rect updates to the size of the bitmap bigger or smaller, when the bitmap is set to nil the src_rect is not changed.



What happens when you set Sprite#src_rect while Sprite#bitmap is nil?

Nothing, the src_rect is set as normal.



What happens when you set Sprite#src_rect outside of the boundaries of Sprite#bitmap?

Nothing, the src_rect is set as normal.



What is the z offset for the cursor, the bitmap size arrows, the pause graphic and the contents sprite?

It's 2.



Window#viewport returns nil by default. What is it for? Is there a way to make it return something else or is this unused?

Passing a viewport in a window does exactly the same like it does in a Sprite. It's just that this feature isn't used in RMXP.



What's the max value for number of frames in a transition?

Only Fixnum values can can be used. If they number is large enough to be converted to a Bignum, it will throw a RangeError.
The exact value will vary depending on the processor.



What is the pixel color formula for the color blending used by plane, sprite and viewport?

-



What is the pixel color formula for the tone blending used by plane, sprite and viewport?

-



What are the formulas for calculating the Quick Settings (A, B, C, D, E) for actor parameters?

-



What is the proper formula for the calculation of the new color value when using Bitmap#blt when any kind of opacity or alpha blending is involved?

-


What does Graphics#frame_reset do?

-
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

I can answer the color and tone question.
color
[@red, @green, @blue, @alpha].pack('d4')

tone
[@red, @green, @blue, @gray].pack('d4')

pack is an in-built ruby method that transforms an array into a byte string. Python has a module called struct that implements the same functionality.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

March 27, 2011, 05:17:05 am #2 Last Edit: March 27, 2011, 07:37:29 am by Blizzard
I know what pack is, but I didn't know it was used for this. Good, then making a dump method won't be a problem.
You should edit my first post and add that. :P

As for the dimensions question, I thought there was a size limit to it. If there is none, then we won't have to implement one.

EDIT: I have added more questions. Feel free to answer and/or add your own.
BTW, Ryex, you should have edited my first post and inserted your answer there as well.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

I answered the last question ind the _dump _load task
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

April 02, 2011, 08:53:15 am #4 Last Edit: April 02, 2011, 12:03:06 pm by Blizzard
Added a new question:

What happens with Sprite#src_rect when Sprite#bitmap is set to a Bitmap instance or nil?

EDIT:

What happens when you set Sprite#src_rect while Sprite#bitmap is nil?

What happens when you set Sprite#src_rect outside of the boundaries of Sprite#bitmap?

EDIT:

What is the z offset for the cursor, the bitmap size arrows, the pause graphic and the contents sprite?
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

did some testing and answered all the above except the z question
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Window#viewport returns nil by default. What is it for? Is there a way to make it return something else or is this unused?
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ForeverZer0

I think it is just there as a remnant of the sprite class. I suppose it could be used manually, but I really can't ever see a need to do that.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

I was thinking the same. I've seen somewhere that it was mentioned that the Window class is composed of several sprites. We will have to do the same approach sadly.
You can't even set the viewport, you can only get it and it's nil by default so I don't think it can have any use.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

modern algebra

I think the viewport is set when you initialize the window, and you can pass it as an argument to the initialize method. The only time I've ever used it is when I am showing a non-opaque window over another window that isn't the same size. I just changed the dimensions of the viewport so that it excluded the area where the new window popped up for as long as the new window was visible - that way, the contents of the bottom window didn't obscure the contents of the top one. There are probably more profitable uses.

ForeverZer0

No, the viewport remains "nil" after initialization. Were talking more about the internal Window class, not Window_Base, which I don't think anyone ever initializes using Ruby script. I'm pretty sure Window#viewport is not used at all in all of RGSS.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

modern algebra

April 26, 2011, 12:12:02 am #11 Last Edit: April 26, 2011, 12:14:37 am by modern algebra
I'm talking about Window too. It sets it to nil if you don't pass a viewport to the initialize method, but if you create the window like:


Window.new (viewport)


then the viewport method will return the viewport you passed and it will operate on the window. You might be right that it's never used though.

Blizzard

I've tested this myself over the weekend. Passing a viewport in a window does exactly the same like it does in a Sprite. It's just that this feature isn't used in RMXP.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Blizzard

May 19, 2011, 04:45:33 pm #13 Last Edit: August 13, 2011, 07:31:12 am by Blizzard
Added a new question.

What's the max value for number of frames in a transition?
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Blizzard

Added two new questions.

What is the pixel color formula for the color blending used by plane, sprite and viewport?

What is the pixel color formula for the tone blending used by plane, sprite and viewport?
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

I'm fairly certain that color blending is a strait blending

tone blending on the other hand I've done some experimentation with. and while it has a formula I have NO clue what it is it's not related to any Photoshop blending mode or a combination of them. I've been trying for a considerable amount of time and have not been able to replicate it. I'm almost certain that it has something to do with light sources or a existing filter.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Hm... Probably HSL is being used for blending.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ForeverZer0

Derp, added one for calculating the quick settings for actor parameters.
We can make our own even, but my math is getting a little rusty in my old age...
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

I've checked it out and I don't think it's that relevant. The was some randomness involved and it was basically a simple linear function. Just implement anything you like. In fact, I never even used the quick settings, I'm not sure it's needed.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Metalero

I donĀ“t know if you already got it, but what I used to for blend color and tone in sprites in my custom Player proyect was a custom pixel shader with this calculations


const char* pixelShader =
"float _alpha; \
float _colA; \
float _colR; \
float _colG; \
float _colB; \
float _toneR; \
float _toneG; \
float _toneB; \
float _toneGrey; \
sampler2D tex0; \
\
float4 main( float2 texCoord : TEXCOORD0): COLOR0 \
{ \
float4 color = tex2D( tex0, texCoord.xy ); \
if(color.a != 0) \
{ \
color.a = color.a * _alpha; \
\
if(_colA != 0) \
{ \
color.r = color.r * (1.0 - _colA) + (_colR * _colA); \
color.g = color.g * (1.0 - _colA) + (_colG * _colA); \
color.b = color.b * (1.0 - _colA) + (_colB * _colA); \
} \
\
if(_toneGrey == 0) \
{ \
color.r = color.r + _toneR; \
color.g = color.g + _toneG; \
color.b = color.b + _toneB; \
} \
else \
{ \
float grey = color.r * 0.299 + color.g * 0.587 + color.b * 0.114; \
float factor = 1.0 - _toneGrey; \
color.r = (color.r - grey) * factor + grey + _toneR + 0.5; \
color.g = (color.g - grey) * factor + grey + _toneG + 0.5; \
color.b = (color.b - grey) * factor + grey + _toneB + 0.5; \
} \
} \
return color; \
}";


Where:

color = the original (and then resultant) pixel color
_alpha = "opacity" propierty
_colX (with X = A R G B) = the "color" propierty
_toneX (with X =  R G B Grey) = "tone" propierty

Note: tone calculations were made originally by vgvgf (author of the abandoned ARGSS proyect)