Quicker Horizontal screen drawings

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Quicker Horizontal screen drawings

virote328
This post was updated on .
My screen class is complete.  And what better way to test it than to use the squareGame!

And to my surprise, the square moves like a slug when it travels left or right. (or maybe pac man)

But when it moves up and down its quick!

So I need a quicker way to print the rectangle.  I don't like that slug motion.  Any suggestions?

Here is the link to the video.


ps: yes, I know there are vertical line artifacts.  I'll figure out how to kill that bug later

PSs: I should also add some info on how I Implemented the rectangle.

drawRectangle(){
    while( top line != botomt line){
        //draw top line by connecting top left corner to top right corner
        //draw bottom line by connecting bottom left corner to bottom right corner
        //increment top line
        //decrement bottom line
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

cadet1620
Administrator
The video's all black for me 8-(

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

virote328

I will re upload it.  


Derrick Ho


On Thu, Apr 4, 2013 at 9:56 AM, cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:

The video's all black for me 8-(

--Mark


To unsubscribe from Quicker Horizontal screen drawings, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

virote328
The link should work now
Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

cadet1620
Administrator
This post was updated on .
In reply to this post by virote328
I took a look at the SquareGame code and when it's moving the square vertically, it erases and draws rectangles that are 2 pixels high and the width of the square. When the square is moving horizontally, it draws rectangles that are 2 pixels wide and the height of the square.

I'd look at the left and right end handling of you horizontal line code. If it's inefficient it's going to have far more effect on horizontal motion than on vertical.

[Now that I see the video, this is pretty clearly what's happening. You can see how slowly the thin vertical rectangles are being erased and drawn.]

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

virote328
Hey Mr cadet

So I made changes to how I handle the Left and right side of a horizontal line that is shorter than 16. I called it a partial bar.

I've optimized it as much as I can ( I think and if there is a better way I'd like to hear about it).  

this is what the code looks like more or less:

function partialbar( x1, y1, x2, y2, startmm, endmm){
    ...
    let startmm[0]= startmm[0] | ((arrMask[x1 & 15]) & (~(arrMask[(x2 & 15) +1])));
    ///////////////////
    //alternatively...
    //do Memory.poke( startmm, Memory.peek(startmm) | ((arrMask[x1 & 15]) & (~(arrMask[(x2 & 15) +1]))));
    //////////////////
    ....
}

where startmm and endmm represent a specific Memory map of screen. ie 16384
where arrMask is an array that holds  specific values used for masking
ie
arrMask[0] = xFFFF;
arrMask[1] = xFFFE;
arrMask[1] = xFFFC;
...
arrMask[15] = x8000
arrMask[16] = x0000

--------------------------------
I have also taken measures to make the other parts of rectangle drawing better. Such as ensuring multiplication is used as few times as possible.

This is my implementation of rectangle:

function void drawRectangle(int x1, int y1, int x2, int y2) {
...  
        let startmm = Screen.screenBase() + ( TLY << 5) + ( TLX >> 4);
        let endmm = Screen.screenBase() + ( TRY << 5) + ( TRX >> 4);
        while ( ~(TLY > BLY)){
                if( (endmm - startmm) > 1){
                        do Screen.drawMultBars( startmm + 1, endmm -1);
                }
                do Screen.drawPartialBar( TLX, TLY, TRX, TRY, startmm, endmm);
                let startmm = startmm + 32; //there are 32 bars per rows, this will bring it down a row
                let endmm = endmm + 32;
                let TLY = TLY + 1;
        }
...
}

where drawMultbars simply makes the entire range of MemoryMaps equal to either -1 or or 0
where TLX and TLY stand for the top left point
where TRX and TRY stand for the top right point
where BLY stand for the bottom left row
where lines are always drawn LEFT to RIGHT ( or startmm to endmm respectively)

This link will show you a video where i am comparing the vigor of my implementation verse the given version ( mine is on the left)

clickHere

ps: graphical speed is very important.  Especially when I try to make tetris!
pss: it is weird how the center of the square sparkles when it shrinks or grows in size.  No Idea what is causing that
Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

cadet1620
Administrator
Answered by email.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

virote328
affirmative

On Apr 7, 2013, at 6:07 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] wrote:

Answered by email.

--Mark


To unsubscribe from Quicker Horizontal screen drawings, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

virote328
In reply to this post by cadet1620
Thank you for letting me see your code.  A lot of it is quite similar to my implementation although yours does look cleaner.

The speed looks about the same as mine.  Perhaps the VMemulator is a bit slow?

On Apr 7, 2013, at 6:07 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] wrote:

Answered by email.

--Mark


To unsubscribe from Quicker Horizontal screen drawings, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

cadet1620
Administrator
virote328 wrote
Thank you for letting me see your code.  A lot of it is quite similar to my implementation although yours does look cleaner.

The speed looks about the same as mine.  Perhaps the VMemulator is a bit slow?
Are you comparing your (and my) Screen.vm to the simulator's built in OS? If so then you are seeing the difference between Java native code speed and emulated VM speed.

A better comparison would be to compare your Screen.vm to tools/OS/Screen.vm.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

virote328

ooo so I was chasing an almost impossible standard.


Derrick Ho


On Sun, Apr 7, 2013 at 9:20 PM, cadet1620 [via Nand2Tetris Questions and Answers Forum] <[hidden email]> wrote:

virote328 wrote
Thank you for letting me see your code.  A lot of it is quite similar to my implementation although yours does look cleaner.

The speed looks about the same as mine.  Perhaps the VMemulator is a bit slow?
Are you comparing your (and my) Screen.vm to the simulator's built in OS? If so then you are seeing the difference between Java native code speed and emulated VM speed.

A better comparison would be to compare your Screen.vm to tools/OS/Screen.vm.

--Mark



To unsubscribe from Quicker Horizontal screen drawings, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Quicker Horizontal screen drawings

virote328
Well, I believe I have hit a limit in terms of optimization.  thanks to your tips i've been able to make it much faster then it was before. This should be good enough for tetris (i hope)

link