Chaos Project

Featured Projects => Advanced RPG Creator => Tasks => Topic started by: Blizzard on March 26, 2011, 10:02:39 am

Title: RGSS Questions and Answers
Post by: Blizzard on March 26, 2011, 10:02:39 am
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?

-
Title: Re: RGSS Questions and Answers
Post by: Ryex on March 26, 2011, 10:53:45 pm
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.
Title: Re: RGSS Questions and Answers
Post by: Blizzard on March 27, 2011, 05:17:05 am
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.
Title: Re: RGSS Questions and Answers
Post by: Ryex on April 01, 2011, 09:20:41 pm
I answered the last question ind the _dump _load task
Title: Re: RGSS Questions and Answers
Post by: Blizzard on April 02, 2011, 08:53:15 am
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?
Title: Re: RGSS Questions and Answers
Post by: Ryex on April 02, 2011, 05:19:09 pm
did some testing and answered all the above except the z question
Title: Re: RGSS Questions and Answers
Post by: Blizzard on April 07, 2011, 07:55:19 am
Window#viewport returns nil by default. What is it for? Is there a way to make it return something else or is this unused?
Title: Re: RGSS Questions and Answers
Post by: ForeverZer0 on April 07, 2011, 07:25:38 pm
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.
Title: Re: RGSS Questions and Answers
Post by: Blizzard on April 08, 2011, 02:27:11 am
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.
Title: Re: RGSS Questions and Answers
Post by: modern algebra on April 25, 2011, 10:00:31 pm
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.
Title: Re: RGSS Questions and Answers
Post by: ForeverZer0 on April 25, 2011, 10:18:50 pm
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.
Title: Re: RGSS Questions and Answers
Post by: modern algebra on April 26, 2011, 12:12:02 am
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.
Title: Re: RGSS Questions and Answers
Post by: Blizzard on April 26, 2011, 02:20:01 am
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.
Title: Re: RGSS Questions and Answers
Post by: Blizzard on May 19, 2011, 04:45:33 pm
Added a new question.

What's the max value for number of frames in a transition?
Title: Re: RGSS Questions and Answers
Post by: Blizzard on August 13, 2011, 07:31:24 am
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?
Title: Re: RGSS Questions and Answers
Post by: Ryex on August 13, 2011, 12:53:02 pm
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.
Title: Re: RGSS Questions and Answers
Post by: Blizzard on August 13, 2011, 01:46:43 pm
Hm... Probably HSL is being used for blending.
Title: Re: RGSS Questions and Answers
Post by: ForeverZer0 on October 16, 2011, 02:28:08 pm
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...
Title: Re: RGSS Questions and Answers
Post by: Blizzard on October 16, 2011, 02:49:41 pm
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.
Title: Re: RGSS Questions and Answers
Post by: Metalero on November 16, 2011, 02:29:20 pm
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)
Title: Re: RGSS Questions and Answers
Post by: Ryex on November 16, 2011, 02:33:46 pm
wow, this will probably help us a lot! thanks for that Metalero!
Title: Re: RGSS Questions and Answers
Post by: Blizzard on November 16, 2011, 02:40:53 pm
You probably just saved me an hour of work or so. xD

EDIT: I just looked at the code and I can see that there is some RGB-HSL conversion going on. I was already expecting something like this because of the saturation effect that the gray parameter has. Now I don't have to experiment with the formula and compare the results with RMXP.
Title: Re: RGSS Questions and Answers
Post by: Blizzard on January 08, 2012, 03:45:07 pm
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?

Since we' switching to pixel shaders for some of the things, we can actually emulate RMXP's Bitmap#blt if we have the formula.
Title: Re: RGSS Questions and Answers
Post by: Blizzard on May 14, 2012, 05:14:20 pm
I have one that I require answered quickly.

What does Graphics#frame_reset do?
Title: Re: RGSS Questions and Answers
Post by: Ryex on May 14, 2012, 05:53:26 pm
I have no idea, nor do I have any idea how to test it...

the help file says

QuoteResets the screen refresh timing. After a time-consuming process, call this method to prevent extreme frame skips.


I'm not sure what that means. or how a function could prevent frame skips
Title: Re: RGSS Questions and Answers
Post by: ForeverZer0 on May 14, 2012, 10:49:42 pm
Likely need to force the game to lag while keeping an eye on the frame count.
I imagine its a worthless method without function. It would keep in style with Enterbrain.

I'll test a bit and see if I can figure something out.
Title: Re: RGSS Questions and Answers
Post by: Blizzard on May 15, 2012, 01:53:12 am
It's possible that Graphics#update doesn't do frame syncing after Graphics#freeze has been called since there is no rendering going on anyway. ARC always does frame syncing so Graphics#frame_reset probably becomes useless.