Difference between revisions of "Sort List Crash 2/3"

From Crash Bandicoot Hacking Wiki
Jump to navigation Jump to search
m
m (Polygon ID)
 
(6 intermediate revisions by 3 users not shown)
Line 27: Line 27:
 
Each Polygon ID has the following format:
 
Each Polygon ID has the following format:
  
<code>*WWWSSPPPPPPPPPP</code>
+
<code>WWWSSPPP PPPPPPPP</code>
 
* W = index of world model
 
* W = index of world model
 
* S = state of the polygon
 
* S = state of the polygon
Line 33: Line 33:
 
Since scenery entries in Crash 2/3 have lists for both triangles and quads, the polygon state is used to differentiate between an index for a triangle (SS = 0) and a quad (SS = 1-3).  
 
Since scenery entries in Crash 2/3 have lists for both triangles and quads, the polygon state is used to differentiate between an index for a triangle (SS = 0) and a quad (SS = 1-3).  
  
The polygon state also specifies whether to fully draw the quad or only draw half of it. A quad can be conceived as a combination of two triangles (ABC and BCD respectively) into a single polygon (ABCD). when only triangle ABC should be drawn, SS=1. If only triangle BCD should be drawn, SS=2. If the entire quad needs to drawn, SS=3.
+
The polygon state also specifies whether to fully draw the quad or only half of it. A quad can be conceived as a combination of two triangles (ABC and CDA respectively) into a single polygon (ABCD). When only triangle ABC needs to be drawn, SS=1. Should only triangle CDA be drawn, SS=2. Finally, if the entire quad needs to be drawn, SS=3.
  
== Introduction ==
+
=== Item 2 to N-1: Difference List ===
 +
{| class="article-table"
 +
!Offset
 +
!Field
 +
!Size
 +
!Value
 +
|-
 +
|0x0
 +
|List Size '''minus 2 '''(in hwords)
 +
|2 bytes
 +
|c + 2
 +
|-
 +
|0x2
 +
|List Type
 +
|2 bytes
 +
|1
 +
|-
 +
|0x4
 +
|Rel. Index of end of removing nodes '''minus 2'''Rel. Index of start of adding nodes '''minus 2'''
 +
|2 bytes
 +
|a + 2
 +
|-
 +
|0x6
 +
|Rel. Index of end of adding nodes '''minus 2'''Rel. Index of start of swapping nodes '''minus 2'''
 +
|2 bytes
 +
|r + 2
 +
|-
 +
| colspan="4" |Nodes/List
 +
|-
 +
|0x8
 +
|Removing Nodes
 +
|(a - 2) x 2 bytes
 +
|*
 +
|-
 +
|0x8 + ((a - 2) x 2)
 +
|Adding Nodes
 +
|(r-a-2) x 2 bytes
 +
|*
 +
|-
 +
|0x8 + ((r - 2) x 2)
 +
|Swapping Nodes
 +
|(c-r-a-2) x 2 bytes
 +
|*
 +
|}
 +
=== Adding/Removing Nodes ===
 +
Adding and Removing nodes have the same format:
 +
 
 +
<code>CCCCNNNN NNNNNNNN (WWWSSPPP PPPPPPPP x (C+1))</code>
 +
* <code>C</code> = add/skip count (this node contains C+1 polygon IDs, number of polygon IDs to add/skip)
 +
* <code>N</code> = add/skip index (the polygon IDs from this node will be added to the new list in a progression, or skipped and not added in a retrogression)
 +
* WSP = polygon ID(s) to add when inserting; other than in Crash 1 these polygon IDs in are the same as in the Source/Target lists since the copyflag functionality is abandoned in Crash 2/3.
 +
=== Swapping Nodes ===
 +
 
 +
<code>Format A: 1BBBBAAA AAAAAAAA [01CCCCCC CCCDDDDD] </code>
 +
 
 +
<code>Format B: 0000AAAA AAAAAAAA  0000BBBB BBBBBBBB [01CCCCCC CCCDDDDD]</code>
 +
* <code>A</code> = index of Polygon ID A
 +
* <code>B</code> = index of Polygon ID B relative to A + 1
 +
* <code>C</code> = index of Polygon ID C relative to A
 +
* <code>D</code> = index of Polygon ID D relative to C + 17
 +
Besides these swapping node formats familiair from Crash 1, there is another type of 'swapping node' in Crash 2/3 that accounts for the swapping of polygon states. They always come after the formats A - D, at the end of the difference list. The swapping is really a XOR-operation on the SS-value of the polygon ID that it refers to.
 +
 
 +
<code>Format E: 001XXPPP PPPPPPPP</code>
 +
* X = XOR mask; the new polygon ID <code>WWW**PPP PPPPPPPP</code> = <code>WWW00PPP PPPPPPPP + ((SS^XX) << 11)</code>
 +
* P = Targeted polygon index
 +
[[Category:Crash 2/3]]

Latest revision as of 20:17, 1 November 2019

 Introduction

The sort lists in Crash 2/3 are for the most part similar to the ones found in Crash 1. Therefore it is recommended to read the extensive article about Sort Lists in Crash 1 first before reading this article.

 Format

Item 1/Item N: Main Source/Target List 

Offset Field Size Value
0x0 List Size (polygon ID count) 2 bytes c
0x2 List Type 2 bytes 0
0x4 Polygon IDs c x 2 bytes *

Polygon ID

Each Polygon ID has the following format:

WWWSSPPP PPPPPPPP

  • W = index of world model
  • S = state of the polygon
  • P = index of polygon in world model

Since scenery entries in Crash 2/3 have lists for both triangles and quads, the polygon state is used to differentiate between an index for a triangle (SS = 0) and a quad (SS = 1-3).

The polygon state also specifies whether to fully draw the quad or only half of it. A quad can be conceived as a combination of two triangles (ABC and CDA respectively) into a single polygon (ABCD). When only triangle ABC needs to be drawn, SS=1. Should only triangle CDA be drawn, SS=2. Finally, if the entire quad needs to be drawn, SS=3.

 Item 2 to N-1: Difference List

Offset Field Size Value
0x0 List Size minus 2 (in hwords) 2 bytes c + 2
0x2 List Type 2 bytes 1
0x4 Rel. Index of end of removing nodes minus 2Rel. Index of start of adding nodes minus 2 2 bytes a + 2
0x6 Rel. Index of end of adding nodes minus 2Rel. Index of start of swapping nodes minus 2 2 bytes r + 2
Nodes/List
0x8 Removing Nodes (a - 2) x 2 bytes *
0x8 + ((a - 2) x 2) Adding Nodes (r-a-2) x 2 bytes *
0x8 + ((r - 2) x 2) Swapping Nodes (c-r-a-2) x 2 bytes *

 Adding/Removing Nodes

Adding and Removing nodes have the same format:

CCCCNNNN NNNNNNNN (WWWSSPPP PPPPPPPP x (C+1))

  • C = add/skip count (this node contains C+1 polygon IDs, number of polygon IDs to add/skip)
  • N = add/skip index (the polygon IDs from this node will be added to the new list in a progression, or skipped and not added in a retrogression)
  • WSP = polygon ID(s) to add when inserting; other than in Crash 1 these polygon IDs in are the same as in the Source/Target lists since the copyflag functionality is abandoned in Crash 2/3.

 Swapping Nodes

Format A: 1BBBBAAA AAAAAAAA [01CCCCCC CCCDDDDD]

Format B: 0000AAAA AAAAAAAA 0000BBBB BBBBBBBB [01CCCCCC CCCDDDDD]

  • A = index of Polygon ID A
  • B = index of Polygon ID B relative to A + 1
  • C = index of Polygon ID C relative to A
  • D = index of Polygon ID D relative to C + 17

Besides these swapping node formats familiair from Crash 1, there is another type of 'swapping node' in Crash 2/3 that accounts for the swapping of polygon states. They always come after the formats A - D, at the end of the difference list. The swapping is really a XOR-operation on the SS-value of the polygon ID that it refers to.

Format E: 001XXPPP PPPPPPPP

  • X = XOR mask; the new polygon ID WWW**PPP PPPPPPPP = WWW00PPP PPPPPPPP + ((SS^XX) << 11)
  • P = Targeted polygon index