yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
inventory.cc
Go to the documentation of this file.
1#include "inventory.h"
2
4#include "app/core/window.h"
5#include "app/gfx/bitmap.h"
6#include "app/gfx/snes_tile.h"
7#include "app/rom.h"
8
9namespace yaze {
10namespace zelda3 {
11
12absl::Status Inventory::Create() {
13 data_.reserve(256 * 256);
14 for (int i = 0; i < 256 * 256; i++) {
15 data_.push_back(0xFF);
16 }
18 for (int i = 0; i < 0x500; i += 0x08) {
19 ASSIGN_OR_RETURN(auto t1, rom()->ReadWord(i + kBowItemPos));
20 ASSIGN_OR_RETURN(auto t2, rom()->ReadWord(i + kBowItemPos + 0x02));
21 ASSIGN_OR_RETURN(auto t3, rom()->ReadWord(i + kBowItemPos + 0x04));
22 ASSIGN_OR_RETURN(auto t4, rom()->ReadWord(i + kBowItemPos + 0x06));
23 tiles_.push_back(gfx::GetTilesInfo(t1));
24 tiles_.push_back(gfx::GetTilesInfo(t2));
25 tiles_.push_back(gfx::GetTilesInfo(t3));
26 tiles_.push_back(gfx::GetTilesInfo(t4));
27 }
28 const int offsets[] = {0x00, 0x08, 0x800, 0x808};
29 auto xx = 0;
30 auto yy = 0;
31
32 int i = 0;
33 for (const auto& tile : tiles_) {
34 int offset = offsets[i];
35 for (auto y = 0; y < 0x08; ++y) {
36 for (auto x = 0; x < 0x08; ++x) {
37 int mx = x;
38 int my = y;
39
40 if (tile.horizontal_mirror_ != 0) {
41 mx = 0x07 - x;
42 }
43
44 if (tile.vertical_mirror_ != 0) {
45 my = 0x07 - y;
46 }
47
48 int xpos = ((tile.id_ % 0x10) * 0x08);
49 int ypos = (((tile.id_ / 0x10)) * 0x400);
50 int source = ypos + xpos + (x + (y * 0x80));
51
52 auto destination = xx + yy + offset + (mx + (my * 0x100));
53 data_[destination] = (test_[source] & 0x0F) + tile.palette_ * 0x08;
54 }
55 }
56
57 if (i == 4) {
58 i = 0;
59 xx += 0x10;
60 if (xx >= 0x100) {
61 yy += 0x1000;
62 xx = 0;
63 }
64 } else {
65 i++;
66 }
67 }
68
69 bitmap_.Create(256, 256, 8, data_);
71 // TODO: Queue texture for later rendering.
72 // Renderer::Get().RenderBitmap(&bitmap_);
73 return absl::OkStatus();
74}
75
77 tilesheets_.reserve(6 * 0x2000);
78 for (int i = 0; i < 6 * 0x2000; i++) tilesheets_.push_back(0xFF);
80 std::vector<uint8_t> test;
81 for (int i = 0; i < 0x4000; i++) {
82 test_.push_back(tilesheets_[i]);
83 }
84 for (int i = 0x8000; i < +0x8000 + 0x2000; i++) {
85 test_.push_back(tilesheets_[i]);
86 }
87 tilesheets_bmp_.Create(128, 0x130, 64, test_);
88 auto hud_pal_group = rom()->palette_group().hud;
89 palette_ = hud_pal_group[0];
91 // TODO: Queue texture for later rendering.
92 // Renderer::Get().RenderBitmap(&tilesheets_bmp_);
93 return absl::OkStatus();
94}
95
96} // namespace zelda3
97} // namespace yaze
void Create(int width, int height, int depth, std::span< uint8_t > data)
Create a bitmap with the given dimensions and data.
Definition bitmap.cc:162
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap.
Definition bitmap.cc:292
absl::Status BuildTileset()
Definition inventory.cc:76
gfx::SnesPalette palette_
Definition inventory.h:36
std::vector< uint8_t > data_
Definition inventory.h:30
gfx::Bitmap tilesheets_bmp_
Definition inventory.h:35
std::vector< uint8_t > test_
Definition inventory.h:34
absl::Status Create()
Definition inventory.cc:12
std::vector< gfx::TileInfo > tiles_
Definition inventory.h:40
std::vector< uint8_t > tilesheets_
Definition inventory.h:33
#define RETURN_IF_ERROR(expression)
Definition macro.h:53
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:61
TileInfo GetTilesInfo(uint16_t tile)
Definition snes_tile.cc:354
constexpr int kBowItemPos
Definition inventory.h:14
Main namespace for the application.
absl::StatusOr< std::vector< uint8_t > > Load2BppGraphics(const Rom &rom)
Loads 2bpp graphics from Rom data.
Definition rom.cc:76
Room transition destination.
Definition zelda.h:447