Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/fast/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct GfxExecStack {
std::stack<F3DGfx*> cmd_stack = {};
// This is also a dlist stack but a std::vector is used to make it possible
// to iterate on the elements.
// The purpose of this is to identify an instruction at a poin in time
// The purpose of this is to identify an instruction at a point in time
// which would not be possible with just a F3DGfx* because a dlist can be called multiple times
// what we do instead is store the call path that leads to the instruction (including branches)
std::vector<const F3DGfx*> gfx_path = {};
Expand Down Expand Up @@ -515,8 +515,8 @@ class Interpreter {
const std::unordered_map<Mtx*, MtxF>* mCurMtxReplacements;
bool mMarkerOn; // This was originally a debug feature. Now it seems to control s2dex?
std::vector<std::string> shader_ids;
int mInterpolationIndex;
int mInterpolationIndexTarget;
uint32_t mInterpolationIndex;
uint32_t mInterpolationCount;
Comment on lines +518 to +519
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to verify no ports are relying on being able to pass in negative values here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interpolation index is generally a value from 0-16

};

void gfx_set_target_ucode(UcodeHandlers ucode);
Expand Down
3 changes: 1 addition & 2 deletions include/fast/lus_gbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ constexpr int8_t OTR_G_REGBLENDEDTEX = OPCODE(0x3f);
constexpr int8_t OTR_G_SETINTENSITY = OPCODE(0x40);
constexpr int8_t OTR_G_MOVEMEM_HASH = OPCODE(0x42);
constexpr int8_t OTR_G_LOAD_SHADER = OPCODE(0x43);
constexpr int8_t RDP_G_SETTILESIZE_INTERP = OPCODE(0x44);
constexpr int8_t RDP_G_SETTARGETINTERPINDEX = OPCODE(0x45);
constexpr int8_t RDP_G_SCROLL_TEXTURE = OPCODE(0x44);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very much a breaking change. i'd want to either see a migration guide for people using the previous opcode defs or for this to be handled in a non-breaking way


/*
* The following commands are the "generated" RDP commands; the user
Expand Down
30 changes: 20 additions & 10 deletions include/libultraship/libultra/gbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@
#define G_READFB 0x3e
#define G_SETINTENSITY 0x40
#define G_LOAD_SHADER 0x43
#define G_SETTILESIZE_INTERP 0x44
#define G_SETTARGETINTERPINDEX 0x45
#define G_SCROLL_TEXTURE 0x44
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/*
* The following commands are the "generated" RDP commands; the user
Expand Down Expand Up @@ -3213,16 +3212,27 @@ typedef union Gfx {
_SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | _SHIFTL(lrt, 0, 12) \
}

#define gDPSetInterpolation(pkt, index) \
_DW({ \
Gfx* _g = (Gfx*)(pkt); \
\
_g->words.w0 = G_SETTARGETINTERPINDEX << 24; \
_g->words.w1 = index; \
#define gDPScrollTexture(pkt, t, uls, ult, lrs, lrt, stepX, stepY) \
_DW({ \
Gfx* _g = (Gfx*)(pkt); \
if (pkt) \
; \
_g->words.w0 = (_SHIFTL(G_SCROLL_TEXTURE, 24, 8) | _SHIFTL(tile, 0, 12)); \
_g->words.w1 = (_SHIFTL(stepX, 32, 32) | _SHIFTL(stepY, 0, 32)); \
_g++; \
_g->words.w0 = (_SHIFTL(uls, 32, 32) | _SHIFTL(ult, 0, 32)); \
_g->words.w1 = (_SHIFTL(lrs, 32, 32) | _SHIFTL(lrt, 0, 32)); \
})

#define __gDPSetTileSizeInterp(pkt, t, uls, ult, lrs, lrt) \
gDPLoadTileGeneric(pkt, G_SETTILESIZE_INTERP, t, uls, ult, lrs, lrt)
#define gsDPScrollTexture(t, uls, ult, lrs, lrt, stepX, stepY) \
{ \
(_SHIFTL(G_SCROLL_TEXTURE, 24, 8) | _SHIFTL(tile, 0, 12)), \
(_SHIFTL(stepX, 32, 32) | _SHIFTL(stepY, 0, 32)), \
}, \
{ \
(_SHIFTL(uls, 32, 32) | _SHIFTL(ult, 0, 32)), (_SHIFTL(lrs, 32, 32) | _SHIFTL(lrt, 0, 32)), \
}

Comment on lines -3216 to +3235
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. breaking changes (same comment as https://github.com/Kenix3/libultraship/pull/969/changes#r2678862060)
  2. there are some hardcoded magic numbers in here which makes me think this is removing control/flexibility from ports.

#define gDPSetTileSize(pkt, t, uls, ult, lrs, lrt) gDPLoadTileGeneric(pkt, G_SETTILESIZE, t, uls, ult, lrs, lrt)
#define gsDPSetTileSize(t, uls, ult, lrs, lrt) gsDPLoadTileGeneric(G_SETTILESIZE, t, uls, ult, lrs, lrt)
#define gDPLoadTile(pkt, t, uls, ult, lrs, lrt) gDPLoadTileGeneric(pkt, G_LOADTILE, t, uls, ult, lrs, lrt)
Expand Down
1 change: 1 addition & 0 deletions include/ship/window/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Window {
int32_t GetMouseCaptureScancode();
void SetFullscreenScancode(int32_t scancode);
void SetMouseCaptureScancode(int32_t scancode);
uint64_t mFrameCount;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-identifier-naming ⚠️
invalid case style for public member mFrameCount

Suggested change
uint64_t mFrameCount;
uint64_t MFrameCount;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tidy is right to be mad about this. it shouldn't be public. make it private and add a public getter and from what i can tell you should be able to use a protected setter


protected:
void SetWindowBackend(WindowBackend backend);
Expand Down
1 change: 1 addition & 0 deletions src/fast/Fast3dWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ bool Fast3dWindow::DrawAndRunGraphicsCommands(Gfx* commands, const std::unordere
}

void Fast3dWindow::HandleEvents() {
mFrameCount += 1;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this in HandleEvents?

mWindowManagerApi->HandleEvents();
}

Expand Down
116 changes: 71 additions & 45 deletions src/fast/interpreter.cpp
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "fast/backends/gfx_window_manager_api.h"
#include "fast/backends/gfx_rendering_api.h"

#include "ship/window/Window.h"
#include "ship/window/gui/Gui.h"
#include "ship/resource/ResourceManager.h"
#include "ship/utils/Utils.h"
Expand Down Expand Up @@ -3617,32 +3618,60 @@ bool gfx_set_tile_size_handler_rdp(F3DGfx** cmd0) {
return false;
}

bool gfx_set_tile_size_interp_handler_rdp(F3DGfx** cmd0) {
bool gfx_scroll_texture_handler_rdp(F3DGfx** cmd0) {
F3DGfx* cmd = *cmd0;
Interpreter* gfx = mInstance.lock().get();
uint64_t frameCount = Ship::Context::GetInstance()->GetWindow()->mFrameCount;
uint32_t tile = C0(0, 12);
float uls, ult, lrs, lrt;
float incX, incY;

if (gfx->mInterpolationIndex == gfx->mInterpolationIndexTarget) {
int tile = C1(24, 3);
gfx->GfxDpSetTileSize(C1(24, 3), C0(12, 12), C0(0, 12), C1(12, 12), C1(0, 12));
++(*cmd0);
memcpy(&gfx->mRdp->texture_tile[tile].uls, &(*cmd0)->words.w0, sizeof(float));
memcpy(&gfx->mRdp->texture_tile[tile].ult, &(*cmd0)->words.w1, sizeof(float));
++(*cmd0);
memcpy(&gfx->mRdp->texture_tile[tile].lrs, &(*cmd0)->words.w0, sizeof(float));
memcpy(&gfx->mRdp->texture_tile[tile].lrt, &(*cmd0)->words.w1, sizeof(float));
} else {
// Verify the frame should be interpolated
if (gfx->mInterpolationIndex >= gfx->mInterpolationCount) {
++(*cmd0);
++(*cmd0);
return false;
}

return false;
}
int32_t stepX = (int32_t)C1(32, 32);
int32_t stepY = (int32_t)C1(0, 32);

bool gfx_set_interpolation_index_target(F3DGfx** cmd0) {
F3DGfx* cmd = *cmd0;
Interpreter* gfx = mInstance.lock().get();
++(*cmd0);

int32_t origin_uls = (int32_t)C0(32, 32);
int32_t origin_ult = (int32_t)C0(0, 32);
int32_t origin_lrs = (int32_t)C1(32, 32);
int32_t origin_lrt = (int32_t)C1(0, 32);

/** Calculate Interpolation **/
origin_uls += stepX;
origin_ult += stepY;

uls = (origin_uls * frameCount) % 2048;
ult = (origin_ult * frameCount) % 2048;

incX = (float)stepX / (float)gfx->mInterpolationCount;
incY = (float)stepY / (float)gfx->mInterpolationCount;

uls += incX * gfx->mInterpolationIndex;
ult += incY * gfx->mInterpolationIndex;

// x + width
lrs = (uls + (origin_lrs));
lrt = (ult + (origin_lrt));

// Apply values to texture
gfx->mRdp->texture_tile[tile].uls = uls;
gfx->mRdp->texture_tile[tile].ult = ult;
gfx->mRdp->texture_tile[tile].lrs = lrs;
gfx->mRdp->texture_tile[tile].lrt = lrt;

// This isn't strictly necessary, but a port can
// overwrite the tile size command making this necessary
gfx->mRdp->textures_changed[0] = true;
gfx->mRdp->textures_changed[1] = true;
// printf("Scroll: uls %f ult %f lrs %f lrt %f interp count %d\n", uls, ult, lrs, lrt, gfx->mInterpolationIndex);

gfx->mInterpolationIndexTarget = cmd->words.w1;
return false;
}

Expand Down Expand Up @@ -3910,34 +3939,31 @@ class UcodeHandler {
};

static constexpr UcodeHandler rdpHandlers = {
{ RDP_G_SETTARGETINTERPINDEX,
{ "G_SETTARGETINTERPINDEX", gfx_set_interpolation_index_target } }, // G_SETTARGETINTERPINDEX
{ RDP_G_SETTILESIZE_INTERP,
{ "G_SETTILESIZE_INTERP", gfx_set_tile_size_interp_handler_rdp } }, // G_SETTILESIZE_INTERP
{ RDP_G_TEXRECT, { "G_TEXRECT", gfx_tex_rect_and_flip_handler_rdp } }, // G_TEXRECT (-28)
{ RDP_G_TEXRECTFLIP, { "G_TEXRECTFLIP", gfx_tex_rect_and_flip_handler_rdp } }, // G_TEXRECTFLIP (-27)
{ RDP_G_RDPLOADSYNC, { "mRdpLOADSYNC", gfx_stubbed_command_handler } }, // mRdpLOADSYNC (-26)
{ RDP_G_RDPPIPESYNC, { "mRdpPIPESYNC", gfx_stubbed_command_handler } }, // mRdpPIPESYNC (-25)
{ RDP_G_RDPTILESYNC, { "mRdpTILESYNC", gfx_stubbed_command_handler } }, // mRdpPIPESYNC (-24)
{ RDP_G_RDPFULLSYNC, { "mRdpFULLSYNC", gfx_stubbed_command_handler } }, // mRdpFULLSYNC (-23)
{ RDP_G_SETSCISSOR, { "G_SETSCISSOR", gfx_SetScissor_handler_rdp } }, // G_SETSCISSOR (-19)
{ RDP_G_SETPRIMDEPTH, { "G_SETPRIMDEPTH", gfx_set_prim_depth_handler_rdp } }, // G_SETPRIMDEPTH (-18)
{ RDP_G_RDPSETOTHERMODE, { "mRdpSETOTHERMODE", gfx_rdp_set_other_mode_rdp } }, // mRdpSETOTHERMODE (-17)
{ RDP_G_LOADTLUT, { "G_LOADTLUT", gfx_load_tlut_handler_rdp } }, // G_LOADTLUT (-16)
{ RDP_G_SETTILESIZE, { "G_SETTILESIZE", gfx_set_tile_size_handler_rdp } }, // G_SETTILESIZE (-14)
{ RDP_G_LOADBLOCK, { "G_LOADBLOCK", gfx_load_block_handler_rdp } }, // G_LOADBLOCK (-13)
{ RDP_G_LOADTILE, { "G_LOADTILE", gfx_load_tile_handler_rdp } }, // G_LOADTILE (-12)
{ RDP_G_SETTILE, { "G_SETTILE", gfx_set_tile_handler_rdp } }, // G_SETTILE (-11)
{ RDP_G_FILLRECT, { "G_FILLRECT", gfx_fill_rect_handler_rdp } }, // G_FILLRECT (-10)
{ RDP_G_SETFILLCOLOR, { "G_SETFILLCOLOR", gfx_set_fill_color_handler_rdp } }, // G_SETFILLCOLOR (-9)
{ RDP_G_SETFOGCOLOR, { "G_SETFOGCOLOR", gfx_set_fog_color_handler_rdp } }, // G_SETFOGCOLOR (-8)
{ RDP_G_SETBLENDCOLOR, { "G_SETBLENDCOLOR", gfx_set_blend_color_handler_rdp } }, // G_SETBLENDCOLOR (-7)
{ RDP_G_SETPRIMCOLOR, { "G_SETPRIMCOLOR", gfx_set_prim_color_handler_rdp } }, // G_SETPRIMCOLOR (-6)
{ RDP_G_SETENVCOLOR, { "G_SETENVCOLOR", gfx_set_env_color_handler_rdp } }, // G_SETENVCOLOR (-5)
{ RDP_G_SETCOMBINE, { "G_SETCOMBINE", gfx_set_combine_handler_rdp } }, // G_SETCOMBINE (-4)
{ RDP_G_SETTIMG, { "G_SETTIMG", gfx_set_timg_handler_rdp } }, // G_SETTIMG (-3)
{ RDP_G_SETZIMG, { "G_SETZIMG", gfx_set_z_img_handler_rdp } }, // G_SETZIMG (-2)
{ RDP_G_SETCIMG, { "G_SETCIMG", gfx_set_c_img_handler_rdp } }, // G_SETCIMG (-1)
{ RDP_G_SCROLL_TEXTURE, { "G_SCROLL_TEXTURE", gfx_scroll_texture_handler_rdp } }, // G_SCROLL_TEXTURE
{ RDP_G_TEXRECT, { "G_TEXRECT", gfx_tex_rect_and_flip_handler_rdp } }, // G_TEXRECT (-28)
{ RDP_G_TEXRECTFLIP, { "G_TEXRECTFLIP", gfx_tex_rect_and_flip_handler_rdp } }, // G_TEXRECTFLIP (-27)
{ RDP_G_RDPLOADSYNC, { "mRdpLOADSYNC", gfx_stubbed_command_handler } }, // mRdpLOADSYNC (-26)
{ RDP_G_RDPPIPESYNC, { "mRdpPIPESYNC", gfx_stubbed_command_handler } }, // mRdpPIPESYNC (-25)
{ RDP_G_RDPTILESYNC, { "mRdpTILESYNC", gfx_stubbed_command_handler } }, // mRdpPIPESYNC (-24)
{ RDP_G_RDPFULLSYNC, { "mRdpFULLSYNC", gfx_stubbed_command_handler } }, // mRdpFULLSYNC (-23)
{ RDP_G_SETSCISSOR, { "G_SETSCISSOR", gfx_SetScissor_handler_rdp } }, // G_SETSCISSOR (-19)
{ RDP_G_SETPRIMDEPTH, { "G_SETPRIMDEPTH", gfx_set_prim_depth_handler_rdp } }, // G_SETPRIMDEPTH (-18)
{ RDP_G_RDPSETOTHERMODE, { "mRdpSETOTHERMODE", gfx_rdp_set_other_mode_rdp } }, // mRdpSETOTHERMODE (-17)
{ RDP_G_LOADTLUT, { "G_LOADTLUT", gfx_load_tlut_handler_rdp } }, // G_LOADTLUT (-16)
{ RDP_G_SETTILESIZE, { "G_SETTILESIZE", gfx_set_tile_size_handler_rdp } }, // G_SETTILESIZE (-14)
{ RDP_G_LOADBLOCK, { "G_LOADBLOCK", gfx_load_block_handler_rdp } }, // G_LOADBLOCK (-13)
{ RDP_G_LOADTILE, { "G_LOADTILE", gfx_load_tile_handler_rdp } }, // G_LOADTILE (-12)
{ RDP_G_SETTILE, { "G_SETTILE", gfx_set_tile_handler_rdp } }, // G_SETTILE (-11)
{ RDP_G_FILLRECT, { "G_FILLRECT", gfx_fill_rect_handler_rdp } }, // G_FILLRECT (-10)
{ RDP_G_SETFILLCOLOR, { "G_SETFILLCOLOR", gfx_set_fill_color_handler_rdp } }, // G_SETFILLCOLOR (-9)
{ RDP_G_SETFOGCOLOR, { "G_SETFOGCOLOR", gfx_set_fog_color_handler_rdp } }, // G_SETFOGCOLOR (-8)
{ RDP_G_SETBLENDCOLOR, { "G_SETBLENDCOLOR", gfx_set_blend_color_handler_rdp } }, // G_SETBLENDCOLOR (-7)
{ RDP_G_SETPRIMCOLOR, { "G_SETPRIMCOLOR", gfx_set_prim_color_handler_rdp } }, // G_SETPRIMCOLOR (-6)
{ RDP_G_SETENVCOLOR, { "G_SETENVCOLOR", gfx_set_env_color_handler_rdp } }, // G_SETENVCOLOR (-5)
{ RDP_G_SETCOMBINE, { "G_SETCOMBINE", gfx_set_combine_handler_rdp } }, // G_SETCOMBINE (-4)
{ RDP_G_SETTIMG, { "G_SETTIMG", gfx_set_timg_handler_rdp } }, // G_SETTIMG (-3)
{ RDP_G_SETZIMG, { "G_SETZIMG", gfx_set_z_img_handler_rdp } }, // G_SETZIMG (-2)
{ RDP_G_SETCIMG, { "G_SETCIMG", gfx_set_c_img_handler_rdp } }, // G_SETCIMG (-1)
};

static constexpr UcodeHandler otrHandlers = {
Expand Down
1 change: 1 addition & 0 deletions src/ship/window/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Window::Window(std::shared_ptr<Gui> gui) {
mGui = gui;
mAvailableWindowBackends = std::make_shared<std::vector<WindowBackend>>();
mConfig = Context::GetInstance()->GetConfig();
mFrameCount = 0;
}

Window::Window(std::vector<std::shared_ptr<GuiWindow>> guiWindows) : Window(std::make_shared<Gui>(guiWindows)) {
Expand Down
Loading