Flickering ground polygons fix (SCASM tweak)

From FSDeveloper Wiki
Revision as of 10:11, 6 July 2008 by Arno (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

A scenery that worked fine in Fs2000 sometimes has bleed through problems with the ground polygons. Usually these polygons where then made with a program like FSDS. This is because such programs use SCASM code that is meant for 3D objects and when this code is used for ground polygons the scenery engine gets confused. The fix for the problem is then also to change the SCASM code used to the one for ground polygons. How to do this will be explained in the rest of this document.

Simple API

For a simple API, that is a API that only contains a ground polygon and nothing else, the following changes must be made.

This is an example of the code as FSDS makes it:

Area( 5 %1 %2 %3 )
IfVarRange( :Exit 0346 %12 5 )
PerspectiveCall( :PCall )
ShadowCall( :PC02 )
Jump( :Exit )
:PCall
Perspective
:PC02
mif( %11 )
RefPoint( 2 :Skip %4 %1 %2 E= %11 v1= %10 V2= 400 )
melse
RefPoint( 7 :Skip %4 %1 %2 v1= %10 v2= 400 )
mifend
RotatedCall( :B 0 0 %5 )
Return
:B
Call32( :Part0 )
:Skip
Return
:Exit
Jump32( :End )
;
; Part: Polygon
:Part0
Points( 0 
       0     0   100       ; 0
     100     0     0       ; 1
       0     0   -99       ; 2
     -99     0     0       ; 3
    )
;RGBSColor( ef 121 121 121 )
Dwx( 2d ) ; color command
Dbd( 121 ) ; red
Dbx( ef ) ; flag/transparency
Dbd( 121 ) ; green
Dbd( 121 ) ; blue
Poly( 0 32767 0 0.00   0   1   2   3   )
Return
:End
EndA

To get the SCASM code for ground polygons the PerspectiveCall and the ShadowCall should be replaced by a LayerCall. The beginning of the changed API looks like this:

Area( 5 %1 %2 %3 )
IfVarRange( :Exit 0346 %12 5 )
;PerspectiveCall( :PCall )
;ShadowCall( :PC02 )
LayerCall( :PC02 8 )
Jump( :Exit )
;:PCall
;Perspective
:PC02
mif( %11 )
RefPoint( 2 :Skip %4 %1 %2 E= %11 v1= %10 V2= 400 )
melse
RefPoint( 7 :Skip %4 %1 %2 v1= %10 v2= 400 )
mifend
RotatedCall( :B 0 0 %5 )
Return
:B

In the above code I have commented out the PerspectiveCall and ShadowCall commands, as these are not needed. Also the Perspective command has been commented, because this command is obsolete since Fs2000. After the ShadowCall I have added the LayerCall, the same label where the ShadowCall refered to is used for the LayerCall and the next parameter is the layer number, 8 in this example. This layer number can of course be changed if another layer is needed in the scenery.

Complex API

For a more complex API the principles are the same, but in such a macro also other object code is there which should not get a LayerCall. Therefore we need to have both a PerspectiveCall and a LayerCall.

Here is an example of such a code from FSDS:

Area( 5 %1 %2 %3 )
IfVarRange( :Exit 0346 %12 5 )
PerspectiveCall( :PCall )
ShadowCall( :PC02 )
Jump( :Exit )
:PCall
Perspective
:PC02
mif( %11 )
RefPoint( 2 :Skip %4 %1 %2 E= %11 v1= %10 V2= 500 )
melse
RefPoint( 7 :Skip %4 %1 %2 v1= %10 v2= 500 )
mifend
RotatedCall( :B 0 0 %5 )
Return
:B
Call32( :Part0 )
Call32( :Part1 )
Call32( :Part2 )
:Skip
Return
:Exit
Jump32( :End )
;
; Part: Polygon
:Part0
Points( 0 
       0     0   100       ; 0
     100     0     0       ; 1
       0     0   -99       ; 2
     -99     0     0       ; 3
    )
;RGBSColor( ef 121 121 121 )
Dwx( 2d ) ; color command
Dbd( 121 ) ; red
Dbx( ef ) ; flag/transparency
Dbd( 121 ) ; green
Dbd( 121 ) ; blue
Poly( 0 32767 0 -0.00   0   1   2   3   )
Return
;
; Part: Box
:Part1
Points( 0 
      75     0   -24       ; 0
      75    50   -24       ; 1
     125    50   -24       ; 2
     125     0   -24       ; 3
      75     0    25       ; 4
      75    50    25       ; 5
     125    50    25       ; 6
     125     0    25       ; 7
    )
;RGBSColor( ef 121 121 121 )
Dwx( 2d ) ; color command
Dbd( 121 ) ; red
Dbx( ef ) ; flag/transparency
Dbd( 121 ) ; green
Dbd( 121 ) ; blue
Poly( 0 0 -32767 25.00   0   1   2   3   )
Poly( 0 0 32767 25.00   7   6   5   4   )
Poly( -32767 0 0 -75.00   5   1   0   4   )
Poly( 32767 0 0 125.00   2   6   7   3   )
Poly( 0 32767 0 50.00   5   6   2   1   )
Poly( 0 -32767 0 0.00   0   3   7   4   )
Return
;
; Part: Box.1
:Part2
Points( 0 
    -124     0   -24       ; 0
    -124    50   -24       ; 1
     -74    50   -24       ; 2
     -74     0   -24       ; 3
    -124     0    25       ; 4
    -124    50    25       ; 5
     -74    50    25       ; 6
     -74     0    25       ; 7
    )
;RGBSColor( ef 121 121 121 )
Dwx( 2d ) ; color command
Dbd( 121 ) ; red
Dbx( ef ) ; flag/transparency
Dbd( 121 ) ; green
Dbd( 121 ) ; blue
Poly( 0 0 -32767 25.00   0   1   2   3   )
Poly( 0 0 32767 25.00   7   6   5   4   )
Poly( -32767 0 0 125.00   5   1   0   4   )
Poly( 32767 0 0 -75.00   2   6   7   3   )
Poly( 0 32767 0 50.00   5   6   2   1   )
Poly( 0 -32767 0 0.00   0   3   7   4   )
Return
:End
EndA

In this case Part0 is the ground polygon and Part1 and Part2 are the 3D parts of the object.

The corrected code now looks like this:

Area( 5 %1 %2 %3 )
IfVarRange( :Exit 0346 %12 5 )
LayerCall( :L 8 )
PerspectiveCall( :PC02 )
ShadowCall( :PC02 )
Jump( :Exit )
:PCall
;Perspective
:PC02
mif( %11 )
RefPoint( 2 :Skip %4 %1 %2 E= %11 v1= %10 V2= 500 )
melse
RefPoint( 7 :Skip %4 %1 %2 v1= %10 v2= 500 )
mifend
RotatedCall( :B 0 0 %5 )
Return
:B
Call32( :Part1 )
Call32( :Part2 )
Return
:L
mif( %11 )
RefPoint( 2 :Skip %4 %1 %2 E= %11 v1= %10 V2= 500 )
melse
RefPoint( 7 :Skip %4 %1 %2 v1= %10 v2= 500 )
mifend
RotatedCall( :B2 0 0 %5 )
Return
:B2
Call32( :Part0 )
:Skip
Return
:Exit
Jump32( :End )

Here I copied the structure and the RefPoint information from the PerspectiveCall part and also used that for the LayerCall part. The actual LayerCall is at the top and it calls the code at the bottom. I hope you can spot the differences between the origional and the changed source and that is enough for you to be able to do the same.