@@ -20,6 +20,9 @@ export class PixelPipeline {
20
20
// When Cycles == 1, we will step the fetcher.
21
21
static cycles : i32 = 0 ;
22
22
23
+ // The X index of the previous sprite that was fetched
24
+ static previousSpriteIndex : i32 = - 1 ;
25
+
23
26
// The last recorded scrollX value
24
27
// Useful for checking background pixels
25
28
static previousScrollX : i32 = 0 ;
@@ -39,10 +42,6 @@ export class PixelPipeline {
39
42
cpuCycles = cpuCycles >> ( < i32 > Cpu . GBCDoubleSpeed ) ;
40
43
41
44
for ( let pixelPipelineCyclesStepped : i32 = 0 ; pixelPipelineCyclesStepped < cpuCycles ; pixelPipelineCyclesStepped ++ ) {
42
- // Debug:
43
- // The problem with sprites is that we are still pushing pixels, while we are trying to fetch sprites.
44
- // We need to do checks, and then proceed down a certain path
45
-
46
45
// Push our a pixel
47
46
PixelFifo . step ( ) ;
48
47
@@ -64,11 +63,12 @@ export class PixelPipeline {
64
63
}
65
64
*/
66
65
67
- // DEBUG: Just do sprites and BG
66
+ // Figure out what we should be fetching next
67
+ // First check if we should fetch a sprite
68
68
if ( _tryToFetchSprite ( ) ) {
69
69
// We are fetching a sprite!
70
70
PixelFifo . startSpriteIdle ( ) ;
71
- } else {
71
+ } else if ( ! isFetchingSprite ( ) ) {
72
72
PixelFifo . stopSpriteIdle ( ) ;
73
73
_tryToFetchBackground ( ) ;
74
74
}
@@ -90,9 +90,15 @@ export class PixelPipeline {
90
90
PixelFifo . reset ( ) ;
91
91
92
92
PixelPipeline . cycles = 0 ;
93
+ PixelPipeline . previousScrollX = 0 ;
94
+ PixelPipeline . previousSpriteIndex = - 1 ;
93
95
}
94
96
}
95
97
98
+ function isFetchingSprite ( ) : boolean {
99
+ return PixelFetcher . isSprite && PixelFetcher . currentStatus !== 0 ;
100
+ }
101
+
96
102
// Returns if we started fetching / we are fetching sprites
97
103
function _tryToFetchSprite ( ) : boolean {
98
104
// Check if sprites are enabled
@@ -107,6 +113,11 @@ function _tryToFetchSprite(): boolean {
107
113
return false ;
108
114
}
109
115
116
+ // Can only show one sprite per x value
117
+ if ( PixelFifo . currentIndex <= PixelPipeline . previousSpriteIndex ) {
118
+ return false ;
119
+ }
120
+
110
121
for ( let i = 0 ; i < Sprites . numberOfVisibleSprites ; i ++ ) {
111
122
// Grab our sprite info from our visible sprites
112
123
let spriteIndex : i32 = Sprites . getVisibleSpriteIndex ( i ) ;
@@ -138,25 +149,15 @@ function _tryToFetchSprite(): boolean {
138
149
if ( PixelFifo . currentIndex === spriteXPosition ) {
139
150
// We need to fetch this sprite!
140
151
141
- // Debug: also need to fix tile line in the fetcher!!!
142
- // getting off train
143
-
144
152
// Get which line of the 8x8 or 8x16 tile.
145
- // Need to sub tract 16 from the total because of the tile height, to get the line
146
- // Debug, may need to put the sprite height here in stead of 16.
147
- let spriteTileLine = Graphics . scanlineRegister - spriteYPosition - 16 ;
153
+ let spriteTileLine = Graphics . scanlineRegister - spriteYPosition ;
148
154
149
155
// Check if we are already fetching the sprite,
150
156
// If not, start fetching it
151
157
if ( ! PixelFetcher . isFetchingSpriteTileLine ( spriteTileLine , spriteIndex ) ) {
152
- // Debug: We are fetching this sprite
153
- // But which line and things?
154
- let spriteHeight : i32 = Lcd . tallSpriteSize ? 16 : 8 ;
155
- log ( Graphics . scanlineRegister , spriteYPosition ) ;
156
- log ( 0x01 , spriteHeight ) ;
157
-
158
- // Just reset everything, and start fetching the sprite
158
+ // Start fetching the sprite
159
159
PixelFetcher . startSpriteFetch ( spriteTileLine , spriteIndex ) ;
160
+ PixelPipeline . previousSpriteIndex = PixelFifo . currentIndex ;
160
161
}
161
162
162
163
return true ;
0 commit comments