Continue ghost
This commit is contained in:
parent
dc66182afb
commit
bcf692d471
3 changed files with 93 additions and 102 deletions
1
TODO.txt
1
TODO.txt
|
@ -23,6 +23,7 @@
|
|||
|
||||
=========== BUGS =================
|
||||
|
||||
- why does the ghost stop in front of the finish?
|
||||
- drawing dithered transparent objects fills z-buffer in the transparent parts
|
||||
and then the geometry behind it isn't drawn <- PARTIALLY FIXED NOW
|
||||
|
||||
|
|
120
game.h
120
game.h
|
@ -355,45 +355,36 @@ void _LCR_gameGetNthGhostSample(unsigned int n,
|
|||
{
|
||||
n *= LCR_GHOST_SAMPLE_SIZE;
|
||||
|
||||
position[0] = LCR_game.ghost.samples[n];
|
||||
n++;
|
||||
position[0] = LCR_game.ghost.samples[n];
|
||||
n++;
|
||||
|
||||
position[0] |=
|
||||
((LCR_GameUnit) (LCR_game.ghost.samples[n] & 0x01)) << 8;
|
||||
position[1] = LCR_game.ghost.samples[n] >> 1;
|
||||
position[0] |= ((LCR_GameUnit) (LCR_game.ghost.samples[n] & 0x01)) << 8;
|
||||
position[1] = LCR_game.ghost.samples[n] >> 1;
|
||||
|
||||
n++;
|
||||
n++;
|
||||
position[1] |= ((LCR_GameUnit) (LCR_game.ghost.samples[n] & 0x07)) << 7;
|
||||
position[2] = LCR_game.ghost.samples[n] >> 3;
|
||||
|
||||
position[1] |=
|
||||
((LCR_GameUnit) (LCR_game.ghost.samples[n] & 0x07)) << 7;
|
||||
position[2] = LCR_game.ghost.samples[n] >> 3;
|
||||
n++;
|
||||
position[2] |= ((LCR_GameUnit) (LCR_game.ghost.samples[n] & 0x0f)) << 5;
|
||||
rotation[0] = LCR_game.ghost.samples[n] >> 4;
|
||||
|
||||
n++;
|
||||
n++;
|
||||
rotation[1] = LCR_game.ghost.samples[n] & 0x0f;
|
||||
rotation[2] = LCR_game.ghost.samples[n] >> 4;
|
||||
|
||||
position[2] |=
|
||||
((LCR_GameUnit) (LCR_game.ghost.samples[n] & 0x0f)) << 5;
|
||||
|
||||
rotation[0] = LCR_game.ghost.samples[n] >> 4;
|
||||
|
||||
n++;
|
||||
|
||||
rotation[1] = LCR_game.ghost.samples[n] & 0x0f;
|
||||
rotation[2] = LCR_game.ghost.samples[n] >> 4;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (i != 2)
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
if (i != 1)
|
||||
position[i] <<= 1;
|
||||
|
||||
position[i] = (position[i] * LCR_GAME_UNIT) / 16;
|
||||
|
||||
position[i] -=
|
||||
(LCR_MAP_SIZE_BLOCKS / 2) *
|
||||
position[i] -= (LCR_MAP_SIZE_BLOCKS / 2) *
|
||||
(i == 1 ? LCR_GAME_UNIT / 2 : LCR_GAME_UNIT);
|
||||
|
||||
rotation[i] = (rotation[i] * LCR_GAME_UNIT) / 16;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void LCR_gameGhostGetTransform(uint32_t frame,
|
||||
|
@ -401,34 +392,38 @@ void LCR_gameGhostGetTransform(uint32_t frame,
|
|||
{
|
||||
unsigned int n = ((frame >> LCR_game.ghost.stretch) / LCR_SETTING_GHOST_STEP);
|
||||
|
||||
_LCR_gameGetNthGhostSample(n % 64,position,rotation);
|
||||
_LCR_gameGetNthGhostSample(n % 64,position,rotation);
|
||||
|
||||
|
||||
if (n < LCR_SETTING_GHOST_MAX_SAMPLES - 1)
|
||||
{
|
||||
if (n < LCR_SETTING_GHOST_MAX_SAMPLES - 1)
|
||||
{
|
||||
LCR_GameUnit carTransform[6];
|
||||
|
||||
// interpolate
|
||||
|
||||
// interpolate:
|
||||
_LCR_gameGetNthGhostSample((n % 64) + 1,carTransform,carTransform + 3);
|
||||
|
||||
n = (frame >> LCR_game.ghost.stretch) % LCR_SETTING_GHOST_STEP;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
position[i] = position[i] +
|
||||
((carTransform[i] - position[i]) * n) /
|
||||
position[i] = position[i] + ((carTransform[i] - position[i]) * n) /
|
||||
LCR_SETTING_GHOST_STEP;
|
||||
|
||||
// rotations are a bit harder to interpolate (e.g. 1 -> 359 deg.)
|
||||
carTransform[3 + i] -= rotation[i];
|
||||
|
||||
if ((carTransform[3 + i] > LCR_GAME_UNIT / 2) ||
|
||||
(carTransform[3 + i] < -1 * LCR_GAME_UNIT / 2))
|
||||
carTransform[3 + i] = -1 *(
|
||||
carTransform[3 + i] > 0 ?
|
||||
LCR_GAME_UNIT - carTransform[3 + i] :
|
||||
(-1 * LCR_GAME_UNIT - carTransform[3 + i]));
|
||||
|
||||
rotation[i] = (LCR_GAME_UNIT + (rotation[i] + (n * carTransform[3 + i])
|
||||
/ LCR_SETTING_GHOST_STEP)) % LCR_GAME_UNIT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void _LCR_gamePrepareGhost(void)
|
||||
{
|
||||
LCR_GameUnit carTransform[6];
|
||||
|
@ -448,44 +443,39 @@ void _LCR_gamePrepareGhost(void)
|
|||
LCR_game.ghost.stretch++;
|
||||
}
|
||||
|
||||
while (!LCR_replayHasFinished())
|
||||
while (1)
|
||||
{
|
||||
if (LCR_racing.tick % (LCR_SETTING_GHOST_STEP << LCR_game.ghost.stretch)
|
||||
== 0)
|
||||
== 0 || LCR_replayHasFinished())
|
||||
{
|
||||
LCR_racingGetCarTransform(carTransform,carTransform + 3,0);
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
carTransform[i] += (LCR_MAP_SIZE_BLOCKS / 2) * (i == 1 ? LCR_GAME_UNIT
|
||||
/ 2 : LCR_GAME_UNIT); // make non-negative
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
// convert positions to unsigned 10 bit values
|
||||
// convert to 10 bit value:
|
||||
carTransform[i] = (carTransform[i] * 16) / LCR_GAME_UNIT;
|
||||
|
||||
carTransform[i] += // make non-negative
|
||||
(LCR_MAP_SIZE_BLOCKS / 2) * (i == 1 ? LCR_GAME_UNIT / 2 : LCR_GAME_UNIT);
|
||||
|
||||
// convert to 10 bit value
|
||||
carTransform[i] = (carTransform[i] * 16) / LCR_GAME_UNIT;
|
||||
|
||||
// conv. rots to 4 bits, we rely on them being non-negative!
|
||||
carTransform[3 + i] =
|
||||
(carTransform[3 + i] * 16) / LCR_GAME_UNIT;
|
||||
}
|
||||
// conv. rotations to 4 bits, we rely on them being non-negative!
|
||||
carTransform[3 + i] = (carTransform[3 + i] * 16) / LCR_GAME_UNIT;
|
||||
}
|
||||
|
||||
// format: XXXXXXXX YYYYYYYX ZZZZZYYY AAAAZZZZ CCCCBBBB
|
||||
|
||||
currentSample[0] = carTransform[0] >> 1;
|
||||
currentSample[1] =
|
||||
((carTransform[0] >> 9) & 0x01) |
|
||||
(carTransform[1] << 1);
|
||||
((carTransform[0] >> 9) & 0x01) | (carTransform[1] << 1);
|
||||
currentSample[2] =
|
||||
((carTransform[1] >> 7) & 0x07) |
|
||||
((carTransform[2] << 2) & 0xf8);
|
||||
((carTransform[1] >> 7) & 0x07) | ((carTransform[2] << 2) & 0xf8);
|
||||
currentSample[3] =
|
||||
((carTransform[2] >> 5) & 0x0f) |
|
||||
(carTransform[3] << 4);
|
||||
((carTransform[2] >> 6) & 0x0f) | (carTransform[3] << 4);
|
||||
currentSample[4] =
|
||||
(carTransform[4] & 0x0f) |
|
||||
(carTransform[5] << 4);
|
||||
(carTransform[4] & 0x0f) | (carTransform[5] << 4);
|
||||
|
||||
if (LCR_replayHasFinished())
|
||||
break;
|
||||
|
||||
currentSample += LCR_GHOST_SAMPLE_SIZE;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue