yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
render_service.h
Go to the documentation of this file.
1#ifndef YAZE_APP_SERVICE_RENDER_SERVICE_H_
2#define YAZE_APP_SERVICE_RENDER_SERVICE_H_
3
4#include <cstdint>
5#include <mutex>
6#include <string>
7#include <vector>
8
9#include "absl/status/statusor.h"
10#include "app/gfx/core/bitmap.h"
11#include "rom/rom.h"
12#include "zelda3/dungeon/room.h"
13#include "zelda3/game_data.h"
14
15namespace yaze {
16namespace app {
17namespace service {
18
19// Overlay bitmask — callers OR these together in RenderRequest::overlay_flags.
20// Adding new overlays costs nothing for existing callers.
21namespace RenderOverlay {
22constexpr uint32_t kNone = 0;
23constexpr uint32_t kCollision = 1 << 0; // custom collision tile IDs
24constexpr uint32_t kSprites = 1 << 1; // sprite positions
25constexpr uint32_t kObjects = 1 << 2; // tile object extents
26constexpr uint32_t kTrack = 1 << 3; // minecart track tiles
27constexpr uint32_t kCameraQuads = 1 << 4; // camera quadrant boundaries
28constexpr uint32_t kGrid = 1 << 5; // 8×8 tile grid
29constexpr uint32_t kAll = ~0u;
30} // namespace RenderOverlay
31
33 int room_id = 0;
35 float scale = 1.0f; // Output pixel scale (1.0 = 512×512 native)
36};
37
39 std::vector<uint8_t> png_data;
40 int width = 0;
41 int height = 0;
42};
43
44// Metadata about a dungeon room — no rendering required.
46 int room_id = 0;
47 uint8_t blockset = 0;
48 uint8_t spriteset = 0;
49 uint8_t palette = 0;
50 int layout_id = 0;
51 int effect = 0;
52 int collision = 0;
53 int tag1 = 0;
54 int tag2 = 0;
55 uint16_t message_id = 0;
57 int object_count = 0;
58 int sprite_count = 0;
59};
60
61// Renders dungeon rooms to PNG images headlessly (no ImGui or GPU required).
62// rom and game_data are non-owning; caller must keep them alive.
63// Thread-safe: each RenderDungeonRoom call is protected by an internal mutex.
65 public:
66 RenderService(Rom* rom, zelda3::GameData* game_data);
67
68 // Render room_id to PNG with the requested overlays at the given scale.
69 absl::StatusOr<RenderResult> RenderDungeonRoom(const RenderRequest& req);
70
71 // Return metadata for a room without rendering.
72 absl::StatusOr<RoomMetadata> GetDungeonRoomMetadata(int room_id);
73
74 private:
75 // Convert the composite Bitmap's indexed+palette surface to an RGBA buffer.
76 absl::StatusOr<std::vector<uint8_t>> BitmapToRgba(const gfx::Bitmap& bitmap,
77 int width, int height);
78
79 // Paint requested overlays into an RGBA buffer (CPU rasterizer).
80 void ApplyOverlays(std::vector<uint8_t>& rgba, int width, int height,
81 const zelda3::Room& room, uint32_t flags, float scale);
82
83 // Encode an RGBA buffer to PNG bytes.
84 absl::StatusOr<std::vector<uint8_t>> EncodePng(
85 const std::vector<uint8_t>& rgba, int width, int height);
86
87 Rom* rom_; // non-owning
89 mutable std::mutex mu_;
90};
91
92} // namespace service
93} // namespace app
94} // namespace yaze
95
96#endif // YAZE_APP_SERVICE_RENDER_SERVICE_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
absl::StatusOr< std::vector< uint8_t > > EncodePng(const std::vector< uint8_t > &rgba, int width, int height)
RenderService(Rom *rom, zelda3::GameData *game_data)
absl::StatusOr< RoomMetadata > GetDungeonRoomMetadata(int room_id)
void ApplyOverlays(std::vector< uint8_t > &rgba, int width, int height, const zelda3::Room &room, uint32_t flags, float scale)
absl::StatusOr< std::vector< uint8_t > > BitmapToRgba(const gfx::Bitmap &bitmap, int width, int height)
absl::StatusOr< RenderResult > RenderDungeonRoom(const RenderRequest &req)
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
std::vector< uint8_t > png_data