English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 25 November 2019, 16:04   #1
deimos
Registered User

 
Join Date: Jul 2018
Location: France
Posts: 537
Drawing the ground in my flight sim game

Edit: I think I've fixed it.

Last edited by deimos; 26 November 2019 at 09:18.
deimos is offline  
Old 26 November 2019, 09:19   #2
deimos
Registered User

 
Join Date: Jul 2018
Location: France
Posts: 537
My question is now, can anyone see any obvious ways to improve this code (bearing in mind that it's only executed once per frame, and the optimiser will get its chance too)?

Also, how should I adapt this to make best use of a blitter fill? I'm thinking I might not need to consider horizontal edges like the top and bottom of the screen?

Code:
void Renderer_RenderGround(const Camera * camera) {
    WORD displayHeight = display.displayMode == SPLIT_SCREEN_DISPLAY_MODE ? SPLIT_SCREEN_MAIN_DISPLAY_HEIGHT :
                                                                            DISPLAY_HEIGHT;

    Point2D poly[10];

    LONG a = ((Entity *) camera)->transformation.rotation.value[0][1];
    LONG b = ((Entity *) camera)->transformation.rotation.value[1][1];

    LONG cz = ((Entity *) camera)->transformation.rotation.value[2][1] << 8; // 2^8 = 256 = viewing distance

    LONG topY = displayHeight / 2 - 1;
    LONG rightX = DISPLAY_WIDTH / 2 - 1;
    LONG bottomY = -displayHeight / 2;
    LONG leftX = -DISPLAY_WIDTH / 2;

    BOOL includeTopLeft = a * leftX + b * topY + cz < 0;
    BOOL includeTopRight = a * rightX + b * topY + cz < 0;
    BOOL includeBottomRight = a * rightX + b * bottomY + cz < 0;
    BOOL includeBottomLeft = a * leftX + b * bottomY + cz < 0;

    UWORD c = 0;

    if (includeTopLeft) {
        poly[c].value[X] = 0;
        poly[c].value[Y] = 0;
        c++;
    }

    if (includeTopLeft != includeBottomLeft) {
        WORD y = topY + (cz - a * rightX) / b;
        if ((includeTopLeft && y != 0) || (includeBottomLeft && y != displayHeight - 1)) {
            poly[c].value[X] = 0;
            poly[c].value[Y] = y;
            c++;
        }
    }

    if (includeBottomLeft) {
        poly[c].value[X] = 0;
        poly[c].value[Y] = displayHeight - 1;
        c++;
    }

    if (includeBottomLeft != includeBottomRight) {
        WORD x = rightX - (cz - b * topY) / a;

        if ((includeBottomLeft && x != 0) || (includeBottomRight && x != DISPLAY_WIDTH - 1)) {
            poly[c].value[X] = x;
            poly[c].value[Y] = displayHeight - 1;
            c++;
        }
    }

    if (includeBottomRight) {
        poly[c].value[X] = DISPLAY_WIDTH - 1;
        poly[c].value[Y] = displayHeight - 1;
        c++;
    }

    if (includeBottomRight != includeTopRight) {
        WORD y = topY + (cz + a * rightX) / b;

        if ((includeBottomRight && y != displayHeight - 1) || (includeTopRight && y != 0)) {
            poly[c].value[X] = DISPLAY_WIDTH - 1;
            poly[c].value[Y] = y;
            c++;
        }
    }

    if (includeTopRight) {
        poly[c].value[X] = DISPLAY_WIDTH - 1;
        poly[c].value[Y] = 0;
        c++;
    }

    if (includeTopRight != includeTopLeft) {
        WORD x = rightX - (cz + b * topY) / a;
        if ((includeTopRight && x != DISPLAY_WIDTH - 1) || (includeTopLeft && x != 0)) {
            poly[c].value[X] = x;
            poly[c].value[Y] = 0;
            c++;
        }
    }

    ClipAndFillPolygon2D(c, poly, MAIN_GROUND);
}

Last edited by deimos; 26 November 2019 at 10:50.
deimos is offline  
Old 26 November 2019, 12:14   #3
hooverphonique
ex. demoscener "Bigmama"

 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,041
if you're doing a split sky/ground with one color for each, maybe you could combine it with a copper color change so you only need to blitter fill the triangle that has a non-horizontal edge..
hooverphonique is offline  
Old 26 November 2019, 12:34   #4
deimos
Registered User

 
Join Date: Jul 2018
Location: France
Posts: 537
Quote:
Originally Posted by hooverphonique View Post
if you're doing a split sky/ground with one color for each, maybe you could combine it with a copper color change so you only need to blitter fill the triangle that has a non-horizontal edge..
It's an interesting idea, but my copper list is already complicated and fragile, and my blitter fill is also taking care of one bitplane's worth of clearing the screen.
deimos is offline  
Old 26 November 2019, 13:56   #5
deimos
Registered User

 
Join Date: Jul 2018
Location: France
Posts: 537
I've finished adding the code to use the blitter to draw the ground polygon that's calculated by the above code. I first use the blitter to clear the first three bitplanes (in one blit, they're allocated as one chunk of memory), then I blit one-dot-per-row lines into a scratch buffer, then I blit fill from that scratch buffer straight into my fourth bitplane, which also has the effect of clearing the bits that aren't set. Finally I clear the lines.

I have the small problem that the top row of my screen never gets filled. I know this is because of the way my lines are drawn, which was correct for blitting normal, small, polygons, but needs to be adjusted for this use. But I'm not sure of the best way.

My lines are currently drawn using xor mode, with the first pixel lost by setting BLTDPT to a scratch buffer. I draw them all from top to bottom by swapping the end points if necessary. I then fill using inclusive or mode.

Any hints? It seems to me that I'm handling a special case, and I should be able to use that to my advantage, somehow. Like, drawing a single line only and using blitter features to take care of how to fill above and below it. But maybe, thinking more, that's not a fight worth fighting, and I should just ask for help with my top row.
Attached Thumbnails
Click image for larger version

Name:	no-top-row.png
Views:	36
Size:	10.8 KB
ID:	65322  

Last edited by deimos; 26 November 2019 at 15:42.
deimos is offline  
Old 26 November 2019, 17:10   #6
deimos
Registered User

 
Join Date: Jul 2018
Location: France
Posts: 537
I've added more keyboard controls to allow better testing. I think I've fixed all the bugs and can now return to drawing the ground efficiently.

Attached is the latest executable (and source).
  • WASD, Q & E to spin the jet
  • Cursor keys, comma and fullstop to spin the camera.
  • H to toggle full screen.
Attached Files
File Type: zip game-cleaned-up-28-11-19.zip (214.8 KB, 10 views)

Last edited by deimos; 28 November 2019 at 18:25. Reason: Always good to have an offsite backup.
deimos is offline  
Old 26 November 2019, 17:59   #7
hooverphonique
ex. demoscener "Bigmama"

 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,041
If I'm not crazy, I'd say you can draw your single ground/sky line without any linedraw tricks, i.e. no xor, no first/last pixel removal.
hooverphonique is offline  
Old 26 November 2019, 18:27   #8
deimos
Registered User

 
Join Date: Jul 2018
Location: France
Posts: 537
Quote:
Originally Posted by hooverphonique View Post
If I'm not crazy, I'd say you can draw your single ground/sky line without any linedraw tricks, i.e. no xor, no first/last pixel removal.
I think I agree with you.

Last edited by deimos; 28 November 2019 at 18:26.
deimos is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
AGA Flight Sim mistermsk support.Games 1 25 October 2013 17:24
Your FAVE flight sim...... Fred the Fop Nostalgia & memories 231 22 March 2010 16:01
best helicopter flight sim' game? lost_lemming Retrogaming General Discussion 20 23 February 2010 01:34
T.F.X Flight sim Faerytale request.Old Rare Games 1 19 May 2005 13:22
WWII flight sim Noo_Noo Looking for a game name ? 9 30 June 2002 00:46

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:13.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.07240 seconds with 16 queries