summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2025-02-02 01:05:35 -0600
committerKiritoDv <kiritodev01@gmail.com>2025-02-02 01:05:35 -0600
commit2d803af01f6c9d218af75884e267b057f69cfc80 (patch)
treeb7cd22a14459853a17d2e039922e8a6bf9cb22cd
parent7fe51d2f9f1725a0fdbaad69889c800cde8eb230 (diff)
Added support for scrolling HD textures
-rw-r--r--src/engine/fox_std_lib.c134
-rw-r--r--src/port/Engine.cpp13
-rw-r--r--src/port/Engine.h1
3 files changed, 109 insertions, 39 deletions
diff --git a/src/engine/fox_std_lib.c b/src/engine/fox_std_lib.c
index 506d7bf9..73754785 100644
--- a/src/engine/fox_std_lib.c
+++ b/src/engine/fox_std_lib.c
@@ -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;
-
- 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;
+ // LTodo: [HD-Textures] This could be handled better
+ s32 newWidth;
+ s32 newHeight;
+ float scale;
+ bool custom;
+ GameEngine_GetTextureInfo(texture, &newWidth, &newHeight, &scale, &custom);
+
+ 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
diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp
index dd6f825b..98492a67 100644
--- a/src/port/Engine.cpp
+++ b/src/port/Engine.cpp
@@ -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);
}
diff --git a/src/port/Engine.h b/src/port/Engine.h
index 628e354a..f0153fc1 100644
--- a/src/port/Engine.h
+++ b/src/port/Engine.h
@@ -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 \ No newline at end of file