Added support for scrolling HD textures

This commit is contained in:
KiritoDv 2025-02-02 01:05:35 -06:00
parent 7fe51d2f9f
commit 2d803af01f
3 changed files with 108 additions and 38 deletions

@ -26,49 +26,105 @@ s32 Graphics_Printf(const char* fmt, ...) {
}
void Lib_Texture_Scroll(u16* texture, s32 width, s32 height, u8 mode) {
// LTodo: [HD-Textures] This is broken
u16* pixel = SEGMENTED_TO_VIRTUAL(texture);
u16 tempPxl;
s32 u;
s32 v;
// LTodo: [HD-Textures] This could be handled better
s32 newWidth;
s32 newHeight;
float scale;
bool custom;
GameEngine_GetTextureInfo(texture, &newWidth, &newHeight, &scale, &custom);
switch (mode) {
case 0:
for (u = 0; u < width; u++) {
tempPxl = pixel[u];
for (v = 1; v < height; v++) {
pixel[(v - 1) * width + u] = pixel[(v) *width + u];
}
pixel[(height - 1) * width + u] = tempPxl;
if(custom) {
u32* pixel = SEGMENTED_TO_VIRTUAL(texture);
u32 tempPxl;
s32 u;
s32 v;
width = newWidth;
height = newHeight;
for(s32 i = 0; i < (s32) scale; i++){
switch (mode) {
case 0:
for (u = 0; u < width; u++) {
tempPxl = pixel[u];
for (v = 1; v < height; v++) {
pixel[(v - 1) * width + u] = pixel[(v) *width + u];
}
pixel[(height - 1) * width + u] = tempPxl;
}
break;
case 1:
for (u = 0; u < width; u++) {
tempPxl = pixel[(height - 1) * width + u];
for (v = height - 2; v >= 0; v--) {
pixel[(v + 1) * width + u] = pixel[(v) *width + u];
}
pixel[u] = tempPxl;
}
break;
case 2:
for (v = 0; v < height; v++) {
tempPxl = pixel[v * width + width - 1];
for (u = width - 2; u >= 0; u--) {
pixel[v * width + u + 1] = pixel[v * width + u];
}
pixel[v * width] = tempPxl;
}
break;
case 3:
for (v = 0; v < height; v++) {
tempPxl = pixel[v * width];
for (u = 1; u < width; u++) {
pixel[v * width + u - 1] = pixel[v * width + u];
}
pixel[v * width + width - 1] = tempPxl;
}
break;
}
break;
case 1:
for (u = 0; u < width; u++) {
tempPxl = pixel[(height - 1) * width + u];
for (v = height - 2; v >= 0; v--) {
pixel[(v + 1) * width + u] = pixel[(v) *width + u];
}
} else {
u16* pixel = SEGMENTED_TO_VIRTUAL(texture);
u16 tempPxl;
s32 u;
s32 v;
switch (mode) {
case 0:
for (u = 0; u < width; u++) {
tempPxl = pixel[u];
for (v = 1; v < height; v++) {
pixel[(v - 1) * width + u] = pixel[(v) *width + u];
}
pixel[(height - 1) * width + u] = tempPxl;
}
pixel[u] = tempPxl;
}
break;
case 2:
for (v = 0; v < height; v++) {
tempPxl = pixel[v * width + width - 1];
for (u = width - 2; u >= 0; u--) {
pixel[v * width + u + 1] = pixel[v * width + u];
break;
case 1:
for (u = 0; u < width; u++) {
tempPxl = pixel[(height - 1) * width + u];
for (v = height - 2; v >= 0; v--) {
pixel[(v + 1) * width + u] = pixel[(v) *width + u];
}
pixel[u] = tempPxl;
}
pixel[v * width] = tempPxl;
}
break;
case 3:
for (v = 0; v < height; v++) {
tempPxl = pixel[v * width];
for (u = 1; u < width; u++) {
pixel[v * width + u - 1] = pixel[v * width + u];
break;
case 2:
for (v = 0; v < height; v++) {
tempPxl = pixel[v * width + width - 1];
for (u = width - 2; u >= 0; u--) {
pixel[v * width + u + 1] = pixel[v * width + u];
}
pixel[v * width] = tempPxl;
}
pixel[v * width + width - 1] = tempPxl;
}
break;
break;
case 3:
for (v = 0; v < height; v++) {
tempPxl = pixel[v * width];
for (u = 1; u < width; u++) {
pixel[v * width + u - 1] = pixel[v * width + u];
}
pixel[v * width + width - 1] = tempPxl;
}
break;
}
}
// LTodo: we should only invalidate one texture

@ -584,6 +584,19 @@ extern "C" uint8_t GameEngine_OTRSigCheck(const char* data) {
return strncmp(data, sOtrSignature, strlen(sOtrSignature)) == 0;
}
extern "C" void GameEngine_GetTextureInfo(const char* path, int32_t* width, int32_t* height, float* scale, bool* custom) {
if(GameEngine_OTRSigCheck(path) != 1){
*custom = false;
return;
}
std::shared_ptr<Fast::Texture> tex = std::static_pointer_cast<Fast::Texture>(
Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(path));
*width = tex->Width;
*height = tex->Height;
*scale = tex->VPixelScale;
*custom = tex->Flags & (1 << 0);
}
extern "C" float __cosf(float angle) throw() {
return cosf(angle);
}

@ -79,5 +79,6 @@ int16_t OTRGetRectDimensionFromRightEdgeOverride(float v);
uint32_t OTRGetGameRenderWidth();
uint32_t OTRGetGameRenderHeight();
void* GameEngine_Malloc(size_t size);
void GameEngine_GetTextureInfo(const char* path, int32_t* width, int32_t* height, float* scale, bool* custom);
#define memalloc(size) GameEngine_Malloc(size)
#endif