From 4ab377b16dc80fb3be3e27ff2aa03e743b9dc6f4 Mon Sep 17 00:00:00 2001 From: Daniel Monteiro Date: Sun, 30 Jun 2024 18:16:24 +0100 Subject: [PATCH] [MZ] Some tweaks to UI rendering --- mz_frontend/CMakeLists.txt | 2 +- mz_frontend/Makefile.286 | 2 +- mz_frontend/Makefile.atari | 2 +- mz_frontend/Makefile.ocs | 2 +- mz_frontend/Makefile.sm4 | 2 +- mz_frontend/include/Renderer.h | 11 ---- mz_frontend/src/AtariVersion/AtariRenderer.c | 10 ++++ mz_frontend/src/Crawler.c | 9 ++-- mz_frontend/src/KeyboardUI.c | 2 +- mz_frontend/src/MSDOSVersion/msdos.c | 10 ++++ mz_frontend/src/MegaDriveVersion/megadrive.c | 9 ++++ mz_frontend/src/UI.c | 57 +++++++++++++++++++- 12 files changed, 93 insertions(+), 25 deletions(-) diff --git a/mz_frontend/CMakeLists.txt b/mz_frontend/CMakeLists.txt index 43613c2e3..b8e36228f 100644 --- a/mz_frontend/CMakeLists.txt +++ b/mz_frontend/CMakeLists.txt @@ -9,7 +9,7 @@ include_directories(src ../core/src ../core/include include ../common/include ${SDL2_INCLUDE_DIR} ) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDLW -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DUSE_OWN_MIN_MAX -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=192 -ggdb3 -DEMIT_QUIT_OPTION -DENDIANESS_AWARE -DSDL_DISABLE_IMMINTRIN_H") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDLW -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DUSE_OWN_MIN_MAX -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=160 -ggdb3 -DEMIT_QUIT_OPTION -DENDIANESS_AWARE -DSDL_DISABLE_IMMINTRIN_H") find_package(SDL2 REQUIRED) diff --git a/mz_frontend/Makefile.286 b/mz_frontend/Makefile.286 index 463b7bf20..46e7dac83 100644 --- a/mz_frontend/Makefile.286 +++ b/mz_frontend/Makefile.286 @@ -1,7 +1,7 @@ CFLAGS = -fomit-frame-pointer -fno-exceptions -ffast-math \ -Iinclude -I../core/include -I../common/include -IEngine3D \ -DMSDOS -DCLI_BUILD -DRES128X128 -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DENDIANESS_AWARE -DXRES=128 -DYRES=128\ - -DSDLW -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=192 -DENDIANESS_AWARE \ + -DSDLW -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=160 -DENDIANESS_AWARE \ -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DENDIANESS_AWARE -DUSE_OWN_MIN_MAX \ -Iinclude -I../common/include -I../core/include -I../common/include -IEngine3D -I../core/include \ -I../common/include -I../core/include -Imenu/include -ISoundSystem -I../core/include -IEngine3D diff --git a/mz_frontend/Makefile.atari b/mz_frontend/Makefile.atari index b441ed5a2..64863bdfd 100644 --- a/mz_frontend/Makefile.atari +++ b/mz_frontend/Makefile.atari @@ -3,7 +3,7 @@ CC = m68k-atari-mint-gcc STRIP=m68k-atari-mint-strip CFLAGS = -std=c99 -c -m68000 -s -fexpensive-optimizations -fomit-frame-pointer -Ofast \ -DATARIST -DCLI_BUILD -DRES128X128 -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DENDIANESS_AWARE -DXRES=128 -DYRES=128\ - -DSDLW -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=192 -DENDIANESS_AWARE \ + -DSDLW -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=160 -DENDIANESS_AWARE \ -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DUSE_OWN_MIN_MAX \ -Iinclude -I../common/include -IAmigaVersion -I../core/include -I../common/include -IEngine3D -I../core/include -Isrc/AtariVersion \ -I../common/include -I../core/include -Imenu/include -ISoundSystem -IAtariVersion -I../core/include -IEngine3D diff --git a/mz_frontend/Makefile.ocs b/mz_frontend/Makefile.ocs index 29e05c978..0de71b4c5 100644 --- a/mz_frontend/Makefile.ocs +++ b/mz_frontend/Makefile.ocs @@ -7,7 +7,7 @@ CFLAGS = \ -Isrc -I../core/src -I../core/include -Iinclude -I../common/include \ -I../common/include -IAmigaVersion -I../core/include -I../common/include -IEngine3D -I../core/include -Isrc/AmigaVersion \ -Imenu/include -ISoundSystem \ - -DSDLW -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=192 -DENDIANESS_AWARE \ + -DSDLW -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=160 -DENDIANESS_AWARE \ -DCLI_BUILD -DINCLUDE_ITEM_DESCRIPTIONS -DAGA5BPP -DRES128X128 -DTRACE_OBJECTS_OVER_FLOOR -DUSE_OWN_MIN_MAX \ -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DUSE_FILLED_POLYS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DENDIANESS_AWARE diff --git a/mz_frontend/Makefile.sm4 b/mz_frontend/Makefile.sm4 index 230b51a2e..39b7b803f 100644 --- a/mz_frontend/Makefile.sm4 +++ b/mz_frontend/Makefile.sm4 @@ -49,7 +49,7 @@ CCFLAGS = -m68000 -Wall -Wextra -std=c99 -ffreestanding -fcommon -Ofast -Wno-un -DSMD -fomit-frame-pointer -fno-exceptions -ffast-math \ -Iinclude -I../core/include -I../common/include -IEngine3D \ -DRES128X128 -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DENDIANESS_AWARE -DXRES=128 -DYRES=128\ - -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=192 -DENDIANESS_AWARE \ + -DENDIANESS_AWARE -DMONOCHROME_VECTORS -DEMBEDDED_DATA -DRLE_COMPRESSED_MAPS -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_HACKING_MINIGAME -DTRACE_OBJECTS_OVER_FLOOR -DCAN_PICK_OBJECT_AT_ANY_DISTANCE -DRES128X128 -Wall -Wextra -pedantic -Wunused-parameter -DXRES_FRAMEBUFFER=256 -DYRES_FRAMEBUFFER=160 -DENDIANESS_AWARE \ -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DSUPPORTS_ROOM_TRANSITION_ANIMATION -DENDIANESS_AWARE \ -Iinclude -I../common/include -I../core/include -I../common/include -IEngine3D -I../core/include \ -I../common/include -I../core/include -Imenu/include -ISoundSystem -I../core/include -IEngine3D diff --git a/mz_frontend/include/Renderer.h b/mz_frontend/include/Renderer.h index 8d84045ac..3de08007d 100644 --- a/mz_frontend/include/Renderer.h +++ b/mz_frontend/include/Renderer.h @@ -39,17 +39,6 @@ enum DIRECTION { #define STIPPLE_COLOUR_THRESHOLD 8 - -/* not rendered and blocks visibility */ -#define BLOCK_CELL '#' - -struct CellPattern { - uint8_t ceiling: 4; - uint8_t elementsMask: 4; - uint8_t geometryType: 7; - uint8_t blockMovement: 1; -}; - #define getPaletteEntry(c) (( (c) - 0xFF000000 ) % 3) void clearGraphics(void); diff --git a/mz_frontend/src/AtariVersion/AtariRenderer.c b/mz_frontend/src/AtariVersion/AtariRenderer.c index 6cf1d42cb..d912be8d7 100644 --- a/mz_frontend/src/AtariVersion/AtariRenderer.c +++ b/mz_frontend/src/AtariVersion/AtariRenderer.c @@ -276,6 +276,16 @@ void drawLine(uint16_t x0, uint8_t y0, uint16_t x1, uint8_t y1, uint8_t colour) } } +void fillRect(uint16_t x0, uint8_t y0, uint16_t x1, uint8_t y1, uint8_t colour, uint8_t stipple) { + int x, y; + for (y = y0; y < y1; ++y) { + for (x = x0; x < x1; ++x) { + realPut(x, y, colour); + } + } +} + + void drawTextAtWithMarginWithFiltering(const int x, const int y, int margin, const char *text, const uint8_t fg, char charToReplaceHifenWith) { diff --git a/mz_frontend/src/Crawler.c b/mz_frontend/src/Crawler.c index cd107e452..b96400479 100644 --- a/mz_frontend/src/Crawler.c +++ b/mz_frontend/src/Crawler.c @@ -45,13 +45,10 @@ void HUD_refresh(void) { needsToRedrawHUD = 0; drawWindow(0, - (128 / 8), + (YRES / 8) + 1, (XRES_FRAMEBUFFER / 8) / 2, - (YRES_FRAMEBUFFER / 8) - 17, - "Status"); - - drawTextAt(1, YRES_TEXT - 7, "In room:", 2); - drawTextAt(1, YRES_TEXT - 4, "In hand:", 2); + 5, + "In hand:"); struct Item *item; diff --git a/mz_frontend/src/KeyboardUI.c b/mz_frontend/src/KeyboardUI.c index 492d4d948..45164383a 100644 --- a/mz_frontend/src/KeyboardUI.c +++ b/mz_frontend/src/KeyboardUI.c @@ -35,7 +35,7 @@ void HUD_initialPaint(void) { drawWindowWithOptions( 1 + (XRES_FRAMEBUFFER / 2) / 8, - (YRES_FRAMEBUFFER / 8) - 3 - /*kMainMenuOptionsCount*/ 6, + (YRES_FRAMEBUFFER / 8) - 3 - 5, (XRES_FRAMEBUFFER / 8) - (1 + (XRES_FRAMEBUFFER / 2) / 8) - 1, (YRES_FRAMEBUFFER / 8) - ((YRES_FRAMEBUFFER / 8) - 3 - /*kMainMenuOptionsCount*/ 6 - 1) - 2, "Actions", diff --git a/mz_frontend/src/MSDOSVersion/msdos.c b/mz_frontend/src/MSDOSVersion/msdos.c index 188c04deb..118d5121f 100644 --- a/mz_frontend/src/MSDOSVersion/msdos.c +++ b/mz_frontend/src/MSDOSVersion/msdos.c @@ -322,6 +322,16 @@ void startFrame(int x, int y, int width, int height) { } +void fillRect(uint16_t x0, uint8_t y0, uint16_t x1, uint8_t y1, uint8_t colour, uint8_t stipple) { + int x, y; + for (y = y0; y < y1; ++y) { + for (x = x0; x < x1; ++x) { + realPut(x, y, colour); + } + } +} + + void endFrame(void) { uint8_t *bufferPtr = &imageBuffer[0]; diff --git a/mz_frontend/src/MegaDriveVersion/megadrive.c b/mz_frontend/src/MegaDriveVersion/megadrive.c index 22f25fcc5..91d92aeab 100644 --- a/mz_frontend/src/MegaDriveVersion/megadrive.c +++ b/mz_frontend/src/MegaDriveVersion/megadrive.c @@ -90,6 +90,15 @@ void realPut(int x, int y, uint8_t colour) { BMP_setPixelFast(x, y, colour); } +void fillRect(uint16_t x0, uint8_t y0, uint16_t x1, uint8_t y1, uint8_t colour, uint8_t stipple) { + int x, y; + for (y = y0; y < y1; ++y) { + for (x = x0; x < x1; ++x) { + realPut(x, y, colour); + } + } +} + void vLine(int16_t x0, int16_t y0, int16_t y1, uint16_t colour) { if (y0 > y1) { diff --git a/mz_frontend/src/UI.c b/mz_frontend/src/UI.c index ecb263e29..06e6cdfee 100644 --- a/mz_frontend/src/UI.c +++ b/mz_frontend/src/UI.c @@ -1,7 +1,17 @@ /* Created by Daniel Monteiro on 11/07/2023. */ +#ifdef WIN32 +#include "Win32Int.h" +#else +#ifndef SMD #include +#include +#else +#include +typedef unsigned long size_t; +#endif +#endif #include "Enums.h" #include "UI.h" @@ -9,13 +19,15 @@ #include "Renderer.h" #include "Engine.h" #include "SoundSystem.h" +#include "Common.h" +#include "MapWithCharKey.h" +#include "FixP.h" +#include "CTile3DProperties.h" extern uint8_t playerLocation; extern int8_t cursorPosition; -extern const struct CellPattern patterns[127]; - extern int8_t map[32][32]; uint8_t waitForKey = 0; @@ -24,6 +36,8 @@ uint8_t redrawMap; uint8_t needsToRedrawHUD; +extern struct MapWithCharKey tileProperties; + void drawGraphic(int x, int y, int dx, int dy, const uint8_t *graphic) { const uint8_t *ptr = graphic; @@ -65,8 +79,47 @@ void showMessage(const char *message) { waitForKey = 1; } +uint8_t isPositionAllowed(int8_t x, int8_t y) { + uint8_t pattern = map[y][x]; + struct CTile3DProperties *prop = + (struct CTile3DProperties *) getFromMap(&tileProperties, pattern); + + return prop->mBlockMovement; +} + + void drawMap(void) { + uint8_t x, y; + + if (!redrawMap) { + return; + } + if (playerLocation == 0) { + return; + } + + redrawMap = 0; + + drawWindow((XRES_FRAMEBUFFER / 8) / 2, + 0, + (XRES_FRAMEBUFFER / 8) / 2 - 1, + (YRES_FRAMEBUFFER / 8) / 2 + 1, + ""); + + for (y = 0; y < 32; ++y) { + for (x = 0; x < 32; ++x) { + + if (isPositionAllowed(x, y)) { + fillRect((XRES_FRAMEBUFFER / 2) + (x * 3), + (y * 3), + (XRES_FRAMEBUFFER / 2) + (x * 3) + 3, + (y * 3) + 3, + 2, + 0); + } + } + } } void performAction(void) {