Chaos Project

Featured Projects => Tasks => Advanced RPG Creator => Finished Tasks => Topic started by: Blizzard on April 07, 2011, 11:08:10 am

Title: [Finished] [RGSS] RGSS::Viewport Behavior
Post by: Blizzard on April 07, 2011, 11:08:10 am
RGSS::Viewport Behavior




Description

RGSS::Viewport is one of the nasty classes because it seems to have been implemented without much thought. From what I know, if you create a couple of sprites with a specific viewport, when you dispose the viewport, all sprites are disposed as well. This can be inconvenient.
Another thing is that I remember that two viewports with the same dimensions would act like just one viewport. Basically if you create sprite A1 with viewport A2 and sprite B1 with viewport B2 where A2 and B2 have the same dimensions, once you dispose either A2 or B2, things will go wacko.
This stuff needs to be tested and checked. We have to know exactly how viewport behaves.

This task is a research task. Post your results and this task can be marked as finished.



Priority

Critical.



Prerequisites

None.



Assigned

Ryex



Everything else

This task is critical because big parts of our system depend on it. Sure, we can basically implement the whole thing and add viewports at the very end, but I have a feeling that implementing the Viewport class earlier could turn out to be useful later.
Title: Re: RGSS::Viewport Behavior
Post by: Ryex on April 07, 2011, 07:10:30 pm

begin
def loop_graphics
 while true
   Input.update
   Graphics.update
   if Input.trigger?(Input::C)
     puts "loop break"
     break
   end
 end
end
def give_bitmap(sprite)
 sprite.bitmap = Bitmap.new(32, 32)
 sprite.bitmap.fill_rect(0, 0, 32, 32, Color.new(255, 0, 0))
 return sprite.bitmap
end
v1 = Viewport.new(0, 0, 200, 200)
v2 = Viewport.new(0, 0, 640, 480)
v3 = Viewport.new(0, 0, 640, 480)
s1 = Sprite.new(v1)
bitmap1 = give_bitmap(s1)
s1.x = s1.y = 10
s2 = Sprite.new(v2)
bitmap2 = give_bitmap(s2)
s2.x = s2.y = 20
s3 = Sprite.new(v3)
bitmap3 = give_bitmap(s3)
s3.x = s3.y = 30
puts "begining"
loop_graphics
v1.dispose
puts "viewport disposed"
loop_graphics
puts "s1", s1.disposed?
puts "b1", bitmap1.disposed?
puts "after print"
loop_graphics
v2.dispose
puts "second dispose"
loop_graphics
puts "s2", s2.disposed?
puts "b2", bitmap2.disposed?
puts "s3", s3.disposed?
puts "b3", bitmap3.disposed?
puts "testing last loop"
loop_graphics
puts "testing compleate"
end


thats the code I used.

disposing the view-port disposes the attached sprite as expected but the viewports with the same position and dimensions didn't do anything strange (I moved them around and everything)

one behavior I noticed that I didn't know before was that a sprite's position is relative to the upper left corner of the view port not the screen.

knowing this I might just redesign my mouse window API
Title: Re: RGSS::Viewport Behavior
Post by: Blizzard on April 08, 2011, 02:39:51 am
I implemented the relative position already, that's not a problem. Only the cutting-off of graphics remains (and obviously the stuff like color, tone, etc.).

Alright, then I will just have to double check my code once more to be sure that attached sprites are disposed when the viewport is disposed. Good that two different viewports with the same dimensions are really two different viewports. Implementing anything else would have been quite nasty.
Once the Renderable and SourceRenderer class have been fully implemented, we will have to implement the RGSSError calls when methods are accessed even though they are disposed.