diff --git a/app/src/main/cpp/graphic/bitmap_render.cpp b/app/src/main/cpp/graphic/bitmap_render.cpp index 2612ceb..2e125da 100644 --- a/app/src/main/cpp/graphic/bitmap_render.cpp +++ b/app/src/main/cpp/graphic/bitmap_render.cpp @@ -5,6 +5,7 @@ #include "bitmap_render.h" #include "../opt/mem_opt.h" #include "palette_data.h" +#include "../logic/logic.h" /** * @@ -21,10 +22,21 @@ byte *renderBitmap(byte *originData, int x, int y, byte *result) { int offset = y * 256 + x; + int realWidth = width; + int startX = 0; + if(x < 0) { + realWidth += x; + startX = -x; + } else if(x > 240) { + realWidth -= (x - 240); + } for (int i = 0; i < height; i++) { - __memcpy_aarch64_simd(result + i * 256 + offset, - originData + i * width, - width); + if (i + y < 0 || i + y > 240) { + continue; + } + __memcpy_aarch64_simd(result + i * 256 + offset + startX, + originData + i * width + startX, + realWidth); } return result; } @@ -41,36 +53,106 @@ byte *renderBitmap(byte *originData, * @param result * @return */ -byte *renderBitmapColorOffset(byte *originData, int colorOffset, - int width, int height, - int x, int y, - byte *result) { +byte *renderBitmapWithTrans(byte *originData, + int width, int height, + int x, int y, + byte *result) { + int realWidth = width;//16 + int startX = 0; + if(x < 0) { + realWidth += x;//16 + -3 = 13 + startX = -x;//3 + } else if(x > 240) { + realWidth -= (x - 240); + } + int offset = y * 256 + x; for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - if(originData[i * width + j] + colorOffset == TRANSPARENT) { + if (i + y < 0 || i + y > 240) { + continue; + } + for (int j = startX; j < startX + realWidth; j++) { + if (originData[i * width + j] == TRANSPARENT) { //skip trans color! continue; } else { - result[i * 256 + offset + j] = originData[i * width + j] + colorOffset; + result[i * 256 + offset + j] = originData[i * width + j]; } } } return result; } -byte *renderBitmapWithScroll(byte *originData, - int width, int height, - int x, int y, - byte *result) { - int offset = y * 256 + x; - for (int i = 0; i < width; i++) { - for (int j = 0; j < height; j++) { - if(originData[i * width + j] == TRANSPARENT) { - //skip trans color! +byte *renderBitmapWithScroll(byte *originData, byte direct, + int width, int height, + int x, int y, + byte *result) { + if (direct & up) { + renderBitmapWithTrans(originData, + width, height, + x, y, + result); + } + if (direct & down) { + int realWidth = width;//16 + int startX = 0; + if(x < 0) { + realWidth += x;//16 + -3 = 13 + startX = -x;//3 + } else if(x > 240) { + realWidth -= (x - 240); + } + + int offset = y * 256 + x; + for (int i = 0; i < height; i++) { + if ((15 - i) + y < 0 || (15 - i) + y > 240) { continue; - } else { - result[i * 256 + offset + j] = originData[j * width + i]; + } + for (int j = startX; j < startX + realWidth; j++) { + if (originData[i * width + j] == TRANSPARENT) { + //skip trans color! + continue; + } else { + result[(15 - i) * 256 + offset + j] = originData[i * width + j]; + } + } + } + } + if (direct & left) { + int offset = y * 256 + x; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + if (j + y < 0 || j + y > 240) { + continue; + } + if (i + x < 0 || i + x > 255) { + continue; + } + if (originData[i * width + j] == TRANSPARENT) { + //skip trans color! + continue; + } else { + result[j * 256 + offset + i] = originData[i * width + j]; + } + } + } + } + if (direct & right) { + int offset = y * 256 + x; + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + if (j + y < 0 || j + y > 240) { + continue; + } + if ((width - 1 - i) + x < 0 || (width - 1 - i) + x > 255) { + continue; + } + if (originData[i * width + j] == TRANSPARENT) { + //skip trans color! + continue; + } else { + result[j * 256 + offset + (width - 1 - i)] = originData[i * width + j]; + } } } } diff --git a/app/src/main/cpp/graphic/bitmap_render.h b/app/src/main/cpp/graphic/bitmap_render.h index 8162973..8c9d211 100644 --- a/app/src/main/cpp/graphic/bitmap_render.h +++ b/app/src/main/cpp/graphic/bitmap_render.h @@ -11,11 +11,11 @@ byte *renderBitmap(byte *originData, int width, int height, int x, int y, byte *result); -byte *renderBitmapColorOffset(byte *originData, int colorOffset, - int width, int height, - int x, int y, - byte *result); -byte *renderBitmapWithScroll(byte *originData, +byte *renderBitmapWithTrans(byte *originData, + int width, int height, + int x, int y, + byte *result); +byte *renderBitmapWithScroll(byte *originData, byte direct, int width, int height, int x, int y, byte *result); diff --git a/app/src/main/cpp/logic/render_debug.cpp b/app/src/main/cpp/logic/render_debug.cpp index 30d43b2..ee7fd57 100644 --- a/app/src/main/cpp/logic/render_debug.cpp +++ b/app/src/main/cpp/logic/render_debug.cpp @@ -102,11 +102,11 @@ void DebugRender::renderDebugInfo(byte *screenBuffer) const { getDefaultPlayer()->godMode?"T":"F"); renderAsciText(screenBuffer, info, 10, 36); int mapId = getCurrentMap(); - int map_width = map_size[mapId * 2 + 1]; sprintf(info, "POS X=%d, Y=%d, TILE=%d ", getDefaultPlayer()->x, getDefaultPlayer()->y, - short_map_data[mapId][getDefaultPlayer()->y * map_width + getDefaultPlayer()->x]); + getTileIdx(getDefaultPlayer()->x, + getDefaultPlayer()->y)); renderAsciText(screenBuffer, info, 10, 44); } diff --git a/app/src/main/cpp/logic/render_map.cpp b/app/src/main/cpp/logic/render_map.cpp index 5b64810..d333861 100644 --- a/app/src/main/cpp/logic/render_map.cpp +++ b/app/src/main/cpp/logic/render_map.cpp @@ -66,10 +66,10 @@ byte *MapRender::render(byte *screenBuffer) { } pthread_mutex_lock(&changeMapMutex); Character *player = getDefaultPlayer(); - posX = player->renderX - 127; - posY = player->renderY - 127; + posX = player->renderX - 128; + posY = player->renderY - 128; screenBuffer = renderMap(posX, posY, screenBuffer); -// renderWater(screenBuffer); + renderWater(screenBuffer); renderDoor(screenBuffer); renderSprite(screenBuffer); renderPlayers(screenBuffer, player); @@ -78,54 +78,45 @@ byte *MapRender::render(byte *screenBuffer) { } void MapRender::renderPlayers(byte *screenBuffer, Character *player) const { - renderBitmapColorOffset(player->currentBitmap, 0, - 16, 16, - 127, 127, screenBuffer); + renderBitmapWithTrans(player->currentBitmap, + 16, 16, + 128, 128, screenBuffer); } -int water_status_map[4] = {1,2,3,2}; +int water_status_map[4] = {1, 2, 3, 2}; byte water_status = 0; int water_status_clk = 0; -bool isTileWater(unsigned short tileId) { - for(int i = 0;i 0 && renderX < 240 && renderY > 0 && renderY < 224) { - renderBitmapColorOffset(water[water_status_map[water_status] - 1],0, - 16, 16, - renderX, renderY, - screenBuffer); - } - byte direct = 0; - if (!isTileWater(short_map_data[mapId][(y - 1) * map_width + (x)])) { - direct |= up; - } - if (!isTileWater(short_map_data[mapId][(y + 1) * map_width + (x)])) { - direct |= down; - } - if (!isTileWater(short_map_data[mapId][(y) * map_width + (x - 1)])) { - direct |= left; - } - if (!isTileWater(short_map_data[mapId][(y) * map_width + (x + 1)])) { - direct |= right; + if (renderX > -16 && renderX < 272 && renderY > -16 && renderY < 256) { + renderBitmap(water[water_status_map[water_status] - 1], + 16, 16, + renderX, renderY, + screenBuffer); + byte direct = 0; + if (!isWater(getTileIdx(x, y - 1))) { + direct |= up; + } + if (!isWater(getTileIdx(x, y + 1))) { + direct |= down; + } + if (!isWater(getTileIdx(x - 1, y))) { + direct |= left; + } + if (!isWater(getTileIdx(x + 1, y))) { + direct |= right; + } + renderWave(direct, water_status_map[water_status] - 1, screenBuffer, renderX, + renderY); } - renderWave(direct, water_status_map[water_status] - 1, screenBuffer, renderX, renderY); } } } @@ -138,12 +129,12 @@ void MapRender::renderSprite(byte *screenBuffer) const { byte y = map_sprite[mapId][i * 3 + 1] - 1; int renderY = y * 16 - posY; int renderX = x * 16 - posX; - if (renderX > 0 && renderX < 240 && renderY > 0 && renderY < 224) { + if (renderX > -16 && renderX < 272 && renderY > -16 && renderY < 256) { byte spriteBmpId = map_sprite[mapId][i * 3 + 2]; - renderBitmapColorOffset(sprites[spriteBmpId], 0, - 16, 16, - renderX, renderY, - screenBuffer); + renderBitmapWithTrans(sprites[spriteBmpId], + 16, 16, + renderX, renderY, + screenBuffer); } } } @@ -249,7 +240,7 @@ void MapRender::tikLogic() { entranceAnimation--; } water_status_clk++; - if(water_status_clk > 60) { + if (water_status_clk > 60) { water_status_clk = 0; water_status++; water_status %= 4; diff --git a/app/src/main/cpp/maps/active_tile_bmp.cpp b/app/src/main/cpp/maps/active_tile_bmp.cpp index eac869f..c546641 100644 --- a/app/src/main/cpp/maps/active_tile_bmp.cpp +++ b/app/src/main/cpp/maps/active_tile_bmp.cpp @@ -6,6 +6,7 @@ #include "../logic/status/character.h" #include "../graphic/bitmap_render.h" #include "../logic/logic.h" +#include "../graphic/palette_data.h" unsigned short water_block_id[WATER_BLOCK_COUNT] = { 13,15,31,35,39,47,85,112,154,190, @@ -22,26 +23,33 @@ unsigned short pure_water_block_id[32] = { 1864,1881, }; +bool isWater(unsigned short tileId) { + for(int i = 0;i= map_height + || y < 0 + || x >= map_width + || x < 0) { + return current_fill; + } return short_current_map[y * (map_width) + x]; }