📄 ttinterp.c
字号:
else { val = -( (compensation - distance + 32) & (-64) ); if ( val > 0 ) val = 0; } return val; }/******************************************************************* * * Function : Round_To_Half_Grid * * Description : Rounds value to half grid after adding engine * compensation. * * Input : distance : distance to round * compensation : engine compensation * * Output : Rounded distance. * *****************************************************************/ static TT_F26Dot6 Round_To_Half_Grid( EXEC_OPS TT_F26Dot6 distance, TT_F26Dot6 compensation ) { TT_F26Dot6 val; if ( distance >= 0 ) { val = ((distance + compensation) & (-64)) + 32; if ( val < 0 ) val = 0; } else { val = -( ((compensation - distance) & (-64)) + 32 ); if ( val > 0 ) val = 0; } return val; }/******************************************************************* * * Function : Round_Down_To_Grid * * Description : Rounds value down to grid after adding engine * compensation. * * Input : distance : distance to round * compensation : engine compensation * * Output : Rounded distance. * *****************************************************************/ static TT_F26Dot6 Round_Down_To_Grid( EXEC_OPS TT_F26Dot6 distance, TT_F26Dot6 compensation ) { TT_F26Dot6 val; if ( distance >= 0 ) { val = distance + compensation; if ( val > 0 ) val &= ~63; else val = 0; } else { val = -( (compensation - distance) & (-64) ); if ( val > 0 ) val = 0; } return val; }/******************************************************************* * * Function : Round_Up_To_Grid * * Description : Rounds value up to grid after adding engine * compensation. * * Input : distance : distance to round * compensation : engine compensation * * Output : Rounded distance. * *****************************************************************/ static TT_F26Dot6 Round_Up_To_Grid( EXEC_OPS TT_F26Dot6 distance, TT_F26Dot6 compensation ) { TT_F26Dot6 val; if ( distance >= 0 ) { val = distance + compensation + 63; if ( val > 0 ) val &= ~63; else val = 0; } else { val = -( (compensation - distance + 63) & (-64) ); if ( val > 0 ) val = 0; } return val; }/******************************************************************* * * Function : Round_To_Double_Grid * * Description : Rounds value to double grid after adding engine * compensation. * * Input : distance : distance to round * compensation : engine compensation * * Output : Rounded distance. * *****************************************************************/ static TT_F26Dot6 Round_To_Double_Grid( EXEC_OPS TT_F26Dot6 distance, TT_F26Dot6 compensation ) { TT_F26Dot6 val; if ( distance >= 0 ) { val = distance + compensation + 16; if ( val > 0 ) val &= ~31; else val = 0; } else { val = -( (compensation - distance + 16) & (-32) ); if ( val > 0 ) val = 0; } return val; }/******************************************************************* * * Function : Round_Super * * Description : Super-rounds value to grid after adding engine * compensation. * * Input : distance : distance to round * compensation : engine compensation * * Output : Rounded distance. * * NOTE : The spec says very few about the relationship between * rounding and engine compensation. However, it seems * from the description of super round that we should * should add the compensation before rounding. * *****************************************************************/ static TT_F26Dot6 Round_Super( EXEC_OPS TT_F26Dot6 distance, TT_F26Dot6 compensation ) { TT_F26Dot6 val; if ( distance >= 0 ) { val = (distance - CUR.phase + CUR.threshold + compensation) & (-CUR.period); if ( val < 0 ) val = 0; val += CUR.phase; } else { val = -( (CUR.threshold - CUR.phase - distance + compensation) & (-CUR.period) ); if ( val > 0 ) val = 0; val -= CUR.phase; } return val; }/******************************************************************* * * Function : Round_Super_45 * * Description : Super-rounds value to grid after adding engine * compensation. * * Input : distance : distance to round * compensation : engine compensation * * Output : Rounded distance. * * NOTE : There is a separate function for Round_Super_45 as we * may need a greater precision. * *****************************************************************/ static TT_F26Dot6 Round_Super_45( EXEC_OPS TT_F26Dot6 distance, TT_F26Dot6 compensation ) { TT_F26Dot6 val; if ( distance >= 0 ) { val = ( (distance - CUR.phase + CUR.threshold + compensation) / CUR.period ) * CUR.period; if ( val < 0 ) val = 0; val += CUR.phase; } else { val = -( ( (CUR.threshold - CUR.phase - distance + compensation) / CUR.period ) * CUR.period ); if ( val > 0 ) val = 0; val -= CUR.phase; } return val; }/******************************************************************* * Compute_Round * *****************************************************************/ static void Compute_Round( EXEC_OPS Byte round_mode ) { switch ( round_mode ) { case TT_Round_Off: CUR.func_round = (TRound_Function)Round_None; break; case TT_Round_To_Grid: CUR.func_round = (TRound_Function)Round_To_Grid; break; case TT_Round_Up_To_Grid: CUR.func_round = (TRound_Function)Round_Up_To_Grid; break; case TT_Round_Down_To_Grid: CUR.func_round = (TRound_Function)Round_Down_To_Grid; break; case TT_Round_To_Half_Grid: CUR.func_round = (TRound_Function)Round_To_Half_Grid; break; case TT_Round_To_Double_Grid: CUR.func_round = (TRound_Function)Round_To_Double_Grid; break; case TT_Round_Super: CUR.func_round = (TRound_Function)Round_Super; break; case TT_Round_Super_45: CUR.func_round = (TRound_Function)Round_Super_45; break; } }/******************************************************************* * * Function : SetSuperRound * * Description : Sets Super Round parameters. * * Input : GridPeriod Grid period * selector SROUND opcode * * Output : None. * *****************************************************************/ static void SetSuperRound( EXEC_OPS TT_F26Dot6 GridPeriod, Long selector ) { switch ( (Int)(selector & 0xC0) ) { case 0: CUR.period = GridPeriod / 2; break; case 0x40: CUR.period = GridPeriod; break; case 0x80: CUR.period = GridPeriod * 2; break; /* This opcode is reserved, but... */ case 0xC0: CUR.period = GridPeriod; break; } switch ( (Int)(selector & 0x30) ) { case 0: CUR.phase = 0; break; case 0x10: CUR.phase = CUR.period / 4; break; case 0x20: CUR.phase = CUR.period / 2; break; case 0x30: CUR.phase = GridPeriod * 3 / 4; break; } if ( (selector & 0x0F) == 0 ) CUR.threshold = CUR.period - 1; else CUR.threshold = ( (Int)(selector & 0x0F) - 4 ) * CUR.period / 8; CUR.period /= 256; CUR.phase /= 256; CUR.threshold /= 256; }/******************************************************************* * * Function : Project * * Description : Computes the projection of vector given by (v2-v1) * along the current projection vector. * * Input : v1, v2 input vector * * Output : Returns distance in F26dot6 format. * *****************************************************************/ static TT_F26Dot6 Project( EXEC_OPS TT_Vector* v1, TT_Vector* v2 ) { TT_Int64 T1, T2; MUL_64( v1->x - v2->x, CUR.GS.projVector.x, T1 ); MUL_64( v1->y - v2->y, CUR.GS.projVector.y, T2 ); ADD_64( T1, T2, T1 ); return (TT_F26Dot6)DIV_64( T1, 0x4000L ); }/******************************************************************* * * Function : Dual_Project * * Description : Computes the projection of the vector given by * (v2-v1) along the current dual vector. * * Input : v1, v2 input vector * * Output : Returns distance in F26dot6 format. * *****************************************************************/ static TT_F26Dot6 Dual_Project( EXEC_OPS TT_Vector* v1, TT_Vector* v2 ) { TT_Int64 T1, T2; MUL_64( v1->x - v2->x, CUR.GS.dualVector.x, T1 ); MUL_64( v1->y - v2->y, CUR.GS.dualVector.y, T2 ); ADD_64( T1, T2, T1 ); return (TT_F26Dot6)DIV_64( T1, 0x4000L ); }/******************************************************************* * * Function : Free_Project * * Description : Computes the projection of the vector given by * (v2-v1) along the current freedom vector. * * Input : v1, v2 input vector * * Output : Returns distance in F26dot6 format. * *****************************************************************/ static TT_F26Dot6 Free_Project( EXEC_OPS TT_Vector* v1, TT_Vector* v2 ) { TT_Int64 T1, T2; MUL_64( v1->x - v2->x, CUR.GS.freeVector.x, T1 ); MUL_64( v1->y - v2->y, CUR.GS.freeVector.y, T2 ); ADD_64( T1, T2, T1 ); return (TT_F26Dot6)DIV_64( T1, 0x4000L ); }/******************************************************************* * * Function : Project_x * * Input : Vx, Vy input vector * * Output : Returns Vx. * * Note : Used as a dummy function. * *****************************************************************/ static TT_F26Dot6 Project_x( EXEC_OPS TT_Vector* v1, TT_Vector* v2 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -