mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-06-18 07:45:21 -04:00
progress
This commit is contained in:
+12
-4
@@ -324,16 +324,24 @@ void GameEngine::StartFrame() const {
|
||||
// Instance->context->GetWindow()->MainLoop(run_one_game_iter);
|
||||
// }
|
||||
|
||||
void GameEngine::RunCommands(Gfx* Commands) {
|
||||
void GameEngine::RunCommands(Gfx* Commands, const std::vector<std::unordered_map<Mtx*, MtxF>>& mtx_replacements) {
|
||||
auto wnd = std::dynamic_pointer_cast<Fast::Fast3dWindow>(Ship::Context::GetInstance()->GetWindow());
|
||||
|
||||
if (nullptr == wnd) {
|
||||
if (wnd == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto interpreter = wnd->GetInterpreterWeak().lock().get();
|
||||
|
||||
// Process window events for resize, mouse, keyboard events
|
||||
wnd->HandleEvents();
|
||||
|
||||
wnd->DrawAndRunGraphicsCommands(Commands, {});
|
||||
interpreter->mInterpolationIndex = 0;
|
||||
|
||||
for (const auto& m : mtx_replacements) {
|
||||
wnd->DrawAndRunGraphicsCommands(Commands, m);
|
||||
interpreter->mInterpolationIndex++;
|
||||
}
|
||||
|
||||
bool curAltAssets = CVarGetInteger("gEnhancements.Mods.AlternateAssets", 0);
|
||||
if (prevAltAssets != curAltAssets) {
|
||||
@@ -379,7 +387,7 @@ void GameEngine::ProcessGfxCommands(Gfx* commands) {
|
||||
wnd->SetTargetFps(CVarGetInteger("gInterpolationFPS", 30));
|
||||
wnd->SetMaximumFrameLatency(1);
|
||||
}
|
||||
RunCommands(commands);
|
||||
RunCommands(commands, mtx_replacements);
|
||||
}
|
||||
|
||||
// Audio
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ class GameEngine {
|
||||
static uint32_t GetInterpolationFPS();
|
||||
static uint32_t GetInterpolationFrameCount();
|
||||
void StartFrame() const;
|
||||
static void RunCommands(Gfx* Commands);
|
||||
static void RunCommands(Gfx* Commands, const std::vector<std::unordered_map<Mtx*, MtxF>>& mtx_replacements);
|
||||
void ProcessFrame(void (*run_one_game_iter)()) const;
|
||||
static void Destroy();
|
||||
static void ProcessGfxCommands(Gfx* commands);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <unordered_map>
|
||||
#include <math.h>
|
||||
#include "port/Engine.h"
|
||||
#include <math_util.h>
|
||||
#include <math_util_2.h>
|
||||
#include "FrameInterpolation.h"
|
||||
|
||||
@@ -89,8 +90,7 @@ union Data {
|
||||
|
||||
struct {
|
||||
Mat4* matrix;
|
||||
f32 x, y, z;
|
||||
u8 mode;
|
||||
Vec3f b;
|
||||
} matrix_translate, matrix_scale;
|
||||
|
||||
struct {
|
||||
@@ -181,9 +181,12 @@ Data& append(Op op) {
|
||||
return m.emplace_back();
|
||||
}
|
||||
|
||||
extern "C" {extern Mat4* gInterpolationMatrix;}
|
||||
extern "C" {
|
||||
extern Mat4* gInterpolationMatrix;
|
||||
void mtxf_translate(Mat4, Vec3f);
|
||||
}
|
||||
|
||||
MtxF* Matrix_GetCurrent(){
|
||||
MtxF* Matrix_GetCurrent() {
|
||||
return (MtxF*) gInterpolationMatrix;
|
||||
}
|
||||
|
||||
@@ -245,15 +248,15 @@ struct InterpolateCtx {
|
||||
s16 interpolate_angle(s16 os, s16 ns) {
|
||||
if (os == ns)
|
||||
return ns;
|
||||
int o = (u16)os;
|
||||
int n = (u16)ns;
|
||||
int o = (u16) os;
|
||||
int n = (u16) ns;
|
||||
u16 res;
|
||||
int diff = o - n;
|
||||
if (-0x8000 <= diff && diff <= 0x8000) {
|
||||
if (diff < -0x4000 || diff > 0x4000) {
|
||||
return ns;
|
||||
}
|
||||
res = (u16)(w * o + step * n);
|
||||
res = (u16) (w * o + step * n);
|
||||
} else {
|
||||
if (o < n) {
|
||||
o += 0x10000;
|
||||
@@ -264,9 +267,9 @@ struct InterpolateCtx {
|
||||
if (diff < -0x4000 || diff > 0x4000) {
|
||||
return ns;
|
||||
}
|
||||
res = (u16)(w * o + step * n);
|
||||
res = (u16) (w * o + step * n);
|
||||
}
|
||||
if (os / 327 == ns / 327 && (s16)res / 327 != os / 327) {
|
||||
if (os / 327 == ns / 327 && (s16) res / 327 != os / 327) {
|
||||
int bp = 0;
|
||||
}
|
||||
return res;
|
||||
@@ -317,11 +320,11 @@ struct InterpolateCtx {
|
||||
// Matrix_Pop(&gInterpolationMatrix);
|
||||
break;
|
||||
|
||||
// Unused on SF64
|
||||
// case Op::MatrixPut:
|
||||
// interpolate_mtxf(&tmp_mtxf, &old_op.matrix_put.src, &new_op.matrix_put.src);
|
||||
// Matrix_Put(&tmp_mtxf);
|
||||
// break;
|
||||
// Unused on SF64
|
||||
// case Op::MatrixPut:
|
||||
// interpolate_mtxf(&tmp_mtxf, &old_op.matrix_put.src, &new_op.matrix_put.src);
|
||||
// Matrix_Put(&tmp_mtxf);
|
||||
// break;
|
||||
|
||||
case Op::MatrixMult:
|
||||
interpolate_mtxf(&tmp_mtxf, &old_op.matrix_mult.mf, &new_op.matrix_mult.mf);
|
||||
@@ -329,16 +332,26 @@ struct InterpolateCtx {
|
||||
break;
|
||||
|
||||
case Op::MatrixTranslate:
|
||||
// Matrix_Translate(gInterpolationMatrix, lerp(old_op.matrix_translate.x, new_op.matrix_translate.x),
|
||||
// Matrix_Translate(gInterpolationMatrix, lerp(old_op.matrix_translate.x,
|
||||
// new_op.matrix_translate.x),
|
||||
// lerp(old_op.matrix_translate.y, new_op.matrix_translate.y),
|
||||
// lerp(old_op.matrix_translate.z, new_op.matrix_translate.z),
|
||||
// new_op.matrix_translate.mode);
|
||||
|
||||
Vec3f temp;
|
||||
|
||||
temp[0] = lerp(old_op.matrix_translate.b[0], new_op.matrix_translate.b[0]);
|
||||
temp[1] = lerp(old_op.matrix_translate.b[1], new_op.matrix_translate.b[1]);
|
||||
temp[2] = lerp(old_op.matrix_translate.b[2], new_op.matrix_translate.b[2]);
|
||||
|
||||
mtxf_translate(*gInterpolationMatrix, temp);
|
||||
break;
|
||||
|
||||
case Op::MatrixScale:
|
||||
// Matrix_Scale(gInterpolationMatrix, lerp(old_op.matrix_scale.x, new_op.matrix_scale.x),
|
||||
// lerp(old_op.matrix_scale.y, new_op.matrix_scale.y),
|
||||
// lerp(old_op.matrix_scale.z, new_op.matrix_scale.z), new_op.matrix_scale.mode);
|
||||
// lerp(old_op.matrix_scale.z, new_op.matrix_scale.z),
|
||||
// new_op.matrix_scale.mode);
|
||||
break;
|
||||
|
||||
case Op::MatrixRotate1Coord: {
|
||||
@@ -361,14 +374,18 @@ struct InterpolateCtx {
|
||||
break;
|
||||
}
|
||||
case Op::MatrixMultVec3fNoTranslate: {
|
||||
interpolate_vecs(&tmp_vec3f, &old_op.matrix_vec_no_translate.src, &new_op.matrix_vec_no_translate.src);
|
||||
interpolate_vecs(&tmp_vec3f2, &old_op.matrix_vec_no_translate.dest, &new_op.matrix_vec_no_translate.dest);
|
||||
interpolate_vecs(&tmp_vec3f, &old_op.matrix_vec_no_translate.src,
|
||||
&new_op.matrix_vec_no_translate.src);
|
||||
interpolate_vecs(&tmp_vec3f2, &old_op.matrix_vec_no_translate.dest,
|
||||
&new_op.matrix_vec_no_translate.dest);
|
||||
// Matrix_MultVec3fNoTranslate(gInterpolationMatrix, &tmp_vec3f, &tmp_vec3f2);
|
||||
break;
|
||||
}
|
||||
case Op::MatrixMultVec3f: {
|
||||
interpolate_vecs(&tmp_vec3f, &old_op.matrix_vec_translate.src, &new_op.matrix_vec_translate.src);
|
||||
interpolate_vecs(&tmp_vec3f2, &old_op.matrix_vec_translate.dest, &new_op.matrix_vec_translate.dest);
|
||||
interpolate_vecs(&tmp_vec3f, &old_op.matrix_vec_translate.src,
|
||||
&new_op.matrix_vec_translate.src);
|
||||
interpolate_vecs(&tmp_vec3f2, &old_op.matrix_vec_translate.dest,
|
||||
&new_op.matrix_vec_translate.dest);
|
||||
// Matrix_MultVec3f(gInterpolationMatrix, &tmp_vec3f, &tmp_vec3f2);
|
||||
break;
|
||||
}
|
||||
@@ -393,8 +410,10 @@ struct InterpolateCtx {
|
||||
|
||||
case Op::MatrixRotateAxis: {
|
||||
lerp_vec3f(&tmp_vec3f, &old_op.matrix_rotate_axis.axis, &new_op.matrix_rotate_axis.axis);
|
||||
auto tmp = interpolate_angle(old_op.matrix_rotate_axis.angle, new_op.matrix_rotate_axis.angle);
|
||||
// Matrix_RotateAxis((Matrix*) &tmp_vec3f, tmp, 1.0f, 1.0f, 1.0f, new_op.matrix_rotate_axis.mode);
|
||||
auto tmp =
|
||||
interpolate_angle(old_op.matrix_rotate_axis.angle, new_op.matrix_rotate_axis.angle);
|
||||
// Matrix_RotateAxis((Matrix*) &tmp_vec3f, tmp, 1.0f, 1.0f, 1.0f,
|
||||
// new_op.matrix_rotate_axis.mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -466,7 +485,7 @@ void FrameInterpolation_DontInterpolateCamera(void) {
|
||||
}
|
||||
|
||||
int FrameInterpolation_GetCameraEpoch(void) {
|
||||
return (int)camera_epoch;
|
||||
return (int) camera_epoch;
|
||||
}
|
||||
|
||||
void FrameInterpolation_RecordActorPosRotMatrix(void) {
|
||||
@@ -498,7 +517,7 @@ void FrameInterpolation_RecordMatrixPop(Mat4** matrix) {
|
||||
void FrameInterpolation_RecordMatrixPut(MtxF* src) {
|
||||
if (!is_recording)
|
||||
return;
|
||||
// append(Op::MatrixPut).matrix_put = { matrix, *src };
|
||||
// append(Op::MatrixPut).matrix_put = { matrix, *src };
|
||||
}
|
||||
|
||||
void FrameInterpolation_RecordMatrixMult(Mat4* matrix, MtxF* mf, u8 mode) {
|
||||
@@ -507,25 +526,26 @@ void FrameInterpolation_RecordMatrixMult(Mat4* matrix, MtxF* mf, u8 mode) {
|
||||
append(Op::MatrixMult).matrix_mult = { matrix, *mf, mode };
|
||||
}
|
||||
|
||||
void FrameInterpolation_RecordMatrixTranslate(Mat4* matrix, f32 x, f32 y, f32 z, u8 mode) {
|
||||
void FrameInterpolation_RecordMatrixTranslate(Mat4* matrix, Vec3f b) {
|
||||
if (!is_recording)
|
||||
return;
|
||||
append(Op::MatrixTranslate).matrix_translate = { matrix, x, y, z, mode };
|
||||
|
||||
append(Op::MatrixTranslate).matrix_translate = { matrix, b[0] };
|
||||
}
|
||||
|
||||
void FrameInterpolation_RecordMatrixScale(Mat4* matrix, f32 x, f32 y, f32 z, u8 mode) {
|
||||
if (!is_recording)
|
||||
return;
|
||||
append(Op::MatrixScale).matrix_scale = { matrix, x, y, z, mode };
|
||||
// append(Op::MatrixScale).matrix_scale = { matrix, x, y, z, mode };
|
||||
}
|
||||
|
||||
void FrameInterpolation_RecordMatrixMultVec3fNoTranslate(Mat4* matrix, Vec3f src, Vec3f dest){
|
||||
void FrameInterpolation_RecordMatrixMultVec3fNoTranslate(Mat4* matrix, Vec3f src, Vec3f dest) {
|
||||
if (!is_recording)
|
||||
return;
|
||||
// append(Op::MatrixMultVec3fNoTranslate).matrix_vec_no_translate = { matrix, src, dest };
|
||||
}
|
||||
|
||||
void FrameInterpolation_RecordMatrixMultVec3f(Mat4* matrix, Vec3f src, Vec3f dest){
|
||||
void FrameInterpolation_RecordMatrixMultVec3f(Mat4* matrix, Vec3f src, Vec3f dest) {
|
||||
if (!is_recording)
|
||||
return;
|
||||
// append(Op::MatrixMultVec3f).matrix_vec_translate = { matrix, src, dest };
|
||||
|
||||
@@ -41,7 +41,7 @@ void FrameInterpolation_RecordActorPosRotMatrix(void);
|
||||
|
||||
//void FrameInterpolation_RecordMatrixMult(Matrix* matrix, MtxF* mf, u8 mode);
|
||||
|
||||
//void FrameInterpolation_RecordMatrixTranslate(Matrix* matrix, f32 x, f32 y, f32 z, u8 mode);
|
||||
void FrameInterpolation_RecordMatrixTranslate(Mat4* matrix, Vec3f b);
|
||||
|
||||
//void FrameInterpolation_RecordMatrixScale(Matrix* matrix, f32 x, f32 y, f32 z, u8 mode);
|
||||
|
||||
|
||||
+15
-15
@@ -244,21 +244,21 @@ void PortMenu::AddSettings() {
|
||||
.DefaultValue(1));
|
||||
#endif
|
||||
|
||||
// AddWidget(path, "Current FPS: %d", WIDGET_CVAR_SLIDER_INT)
|
||||
// .CVar("gInterpolationFPS")
|
||||
// .Callback([](WidgetInfo& info) {
|
||||
// int32_t defaultValue = std::static_pointer_cast<IntSliderOptions>(info.options)->defaultValue;
|
||||
// if (CVarGetInteger(info.cVar, defaultValue) == defaultValue) {
|
||||
// info.name = "Current FPS: Original (%d)";
|
||||
// } else {
|
||||
// info.name = "Current FPS: %d";
|
||||
// }
|
||||
// })
|
||||
// .PreFunc([](WidgetInfo& info) {
|
||||
// if (mPortMenu->disabledMap.at(DISABLE_FOR_MATCH_REFRESH_RATE_ON).active)
|
||||
// info.activeDisables.push_back(DISABLE_FOR_MATCH_REFRESH_RATE_ON);
|
||||
// })
|
||||
// .Options(IntSliderOptions().Tooltip(tooltip).Min(20).Max(maxFps).DefaultValue(20));
|
||||
AddWidget(path, "Current FPS: %d", WIDGET_CVAR_SLIDER_INT)
|
||||
.CVar("gInterpolationFPS")
|
||||
.Callback([](WidgetInfo& info) {
|
||||
int32_t defaultValue = std::static_pointer_cast<IntSliderOptions>(info.options)->defaultValue;
|
||||
if (CVarGetInteger(info.cVar, defaultValue) == defaultValue) {
|
||||
info.name = "Current FPS: Original (%d)";
|
||||
} else {
|
||||
info.name = "Current FPS: %d";
|
||||
}
|
||||
})
|
||||
.PreFunc([](WidgetInfo& info) {
|
||||
if (mPortMenu->disabledMap.at(DISABLE_FOR_MATCH_REFRESH_RATE_ON).active)
|
||||
info.activeDisables.push_back(DISABLE_FOR_MATCH_REFRESH_RATE_ON);
|
||||
})
|
||||
.Options(IntSliderOptions().Tooltip(tooltip).Min(20).Max(maxFps).DefaultValue(20));
|
||||
AddWidget(path, "Match Refresh Rate", WIDGET_BUTTON)
|
||||
.Callback([](WidgetInfo& info) {
|
||||
int hz = Ship::Context::GetInstance()->GetWindow()->GetCurrentRefreshRate();
|
||||
|
||||
@@ -222,6 +222,7 @@ UNUSED void add_translate_mat4_vec3f_lite(Mat4 mat, Mat4 dest, Vec3f pos) {
|
||||
|
||||
// create a translation matrix
|
||||
void mtxf_translate(Mat4 dest, Vec3f b) {
|
||||
FrameInterpolation_RecordMatrixTranslate(dest, b);
|
||||
mtxf_identity(dest);
|
||||
dest[3][0] = b[0];
|
||||
dest[3][1] = b[1];
|
||||
|
||||
Reference in New Issue
Block a user