Update Bitmap pointer management

This commit is contained in:
scawful
2022-07-12 00:01:54 -04:00
parent 9919397692
commit 79d535b99a
5 changed files with 25 additions and 25 deletions

View File

@@ -222,9 +222,9 @@ void Editor::DrawGraphicsSheet(int offset) {
((rom_.data()[0x513E + offset]))));
pc_addr = core::SnesToPc(snes_addr);
std::cout << "Decompressing..." << std::endl;
char *decomp = rom_.Decompress(pc_addr);
auto decomp = rom_.Decompress(pc_addr);
std::cout << "Converting to 8bpp sheet..." << std::endl;
sheet_buffer = rom_.SNES3bppTo8bppSheet((uchar *)decomp);
sheet_buffer = rom_.SNES3bppTo8bppSheet(decomp);
std::cout << "Assigning pixel data..." << std::endl;
surface->pixels = sheet_buffer;
std::cout << "Creating texture from surface..." << std::endl;

View File

@@ -2,6 +2,8 @@
#include <SDL2/SDL.h>
#include <memory>
#include "app/core/constants.h"
#include "app/gfx/snes_palette.h"
@@ -50,6 +52,8 @@ void Bitmap::Create(int width, int height, int depth, int size) {
surface_->format->palette->colors[i].g = i * 31;
surface_->format->palette->colors[i].b = i * 31;
}
pixel_data_ = (uchar *)SDL_malloc(size);
surface_->pixels = pixel_data_;
}
@@ -57,9 +61,7 @@ void Bitmap::CreateTexture(std::shared_ptr<SDL_Renderer> renderer) {
texture_ = SDL_CreateTextureFromSurface(renderer.get(), surface_);
}
void Bitmap::ApplyPalette(const SNESPalette& palette) {
palette_ = palette;
}
void Bitmap::ApplyPalette(const SNESPalette &palette) { palette_ = palette; }
} // namespace gfx
} // namespace app

View File

@@ -3,6 +3,8 @@
#include <SDL2/SDL.h>
#include <memory>
#include "app/core/constants.h"
#include "app/gfx/snes_palette.h"
@@ -18,9 +20,9 @@ class Bitmap {
void Create(int width, int height, int depth, uchar *data);
void Create(int width, int height, int depth, int data_size);
void CreateTexture(std::shared_ptr<SDL_Renderer> renderer);
void ApplyPalette(const SNESPalette& palette);
void ApplyPalette(const SNESPalette &palette);
int GetWidth() const { return width_; }
int GetHeight() const { return height_; }
uchar *GetData() const { return pixel_data_; }

View File

@@ -12,10 +12,8 @@ using namespace gfx;
void Overworld::Load(ROM& rom) {
rom_ = rom;
overworldMapPointer = std::make_shared<uchar[]>(0x40000);
mapblockset16 = std::make_shared<uchar[]>(1048576);
currentOWgfx16Ptr = std::make_shared<uchar[]>((128 * 512) / 2);
mapblockset16.Create(128, 8192, 8, 1048576);
currentOWgfx16.Create(128, 512, 4, (128 * 512) / 2);
AssembleMap32Tiles();
AssembleMap16Tiles();
@@ -30,9 +28,9 @@ void Overworld::Load(ROM& rom) {
auto size = tiles16.size();
for (int i = 0; i < 160; i++) {
overworld_maps_[i].BuildMap(mapParent, size, gameState, allmapsTilesLW,
allmapsTilesDW, allmapsTilesSP,
currentOWgfx16Ptr.get(), mapblockset16.get());
overworld_maps_[i].BuildMap(
mapParent, size, gameState, allmapsTilesLW, allmapsTilesDW,
allmapsTilesSP, currentOWgfx16.GetData(), mapblockset16.GetData());
}
isLoaded = true;
@@ -252,9 +250,8 @@ void Overworld::FetchLargeMaps() {
}
void Overworld::LoadOverworldMap() {
overworldMapBitmap.Create(128, 128, 8, overworldMapPointer.get());
auto ptr = overworldMapPointer;
overworldMapBitmap.Create(128, 128, 8, 0x40000);
auto ptr = overworldMapBitmap.GetData();
int pos = 0;
for (int sy = 0; sy < 16; sy++) {

View File

@@ -9,6 +9,7 @@
#include "app/core/constants.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/psuedo_vram.h"
#include "app/gfx/snes_tile.h"
#include "app/rom.h"
#include "app/zelda3/overworld_map.h"
@@ -21,8 +22,8 @@ class Overworld {
public:
void Load(ROM& rom);
auto GetTiles16() const { return tiles16; }
auto GetCurrentGfxSetPtr() { return currentOWgfx16Ptr; }
auto GetMapBlockset16Ptr() { return mapblockset16; }
auto GetCurrentGfxSetPtr() { return currentOWgfx16.GetData(); }
auto GetMapBlockset16Ptr() { return mapblockset16.GetData(); }
private:
ushort GenerateTile32(int i, int k, int dimension);
@@ -41,17 +42,15 @@ class Overworld {
std::vector<std::vector<ushort>> allmapsTilesDW; // 64 maps * (32*32 tiles)
std::vector<std::vector<ushort>> allmapsTilesSP; // 32 maps * (32*32 tiles)
std::shared_ptr<uchar[]> mapblockset16;
std::shared_ptr<uchar[]> currentOWgfx16Ptr;
gfx::Bitmap mapblockset16;
gfx::Bitmap currentOWgfx16;
gfx::Bitmap overworldMapBitmap;
std::vector<gfx::Tile16> tiles16;
std::vector<gfx::Tile32> tiles32;
std::vector<gfx::Tile32> map16tiles;
std::vector<OverworldMap> overworld_maps_;
gfx::Bitmap overworldMapBitmap;
std::shared_ptr<uchar[]> overworldMapPointer;
const int map32address[4] = {
core::constants::map32TilesTL, core::constants::map32TilesTR,
core::constants::map32TilesBL, core::constants::map32TilesBR};