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 "absl/strings/string_view.h"
11#include "app/gfx/core/bitmap.h"
12#include "rom/rom.h"
13#include "zelda3/dungeon/room.h"
14#include "zelda3/game_data.h"
15
16namespace yaze {
17namespace app {
18namespace service {
19
20// Overlay bitmask — callers OR these together in RenderRequest::overlay_flags.
21// Adding new overlays costs nothing for existing callers.
22namespace RenderOverlay {
23constexpr uint32_t kNone = 0;
24constexpr uint32_t kCollision = 1 << 0; // custom collision tile IDs
25constexpr uint32_t kSprites = 1 << 1; // sprite positions
26constexpr uint32_t kObjects = 1 << 2; // tile object extents
27constexpr uint32_t kTrack = 1 << 3; // minecart track tiles
28constexpr uint32_t kCameraQuads = 1 << 4; // camera quadrant boundaries
29constexpr uint32_t kGrid = 1 << 5; // 8×8 tile grid
30constexpr uint32_t kAll = ~0u;
31} // namespace RenderOverlay
32
34 int room_id = 0;
36 float scale = 1.0f; // Finite [0.25, 8.0]; 1.0 = 512×512 native.
37};
38
39// Shared strict parser for CLI/API scale input. Rejects malformed, non-finite,
40// and out-of-range values instead of silently clamping or using a default.
41absl::StatusOr<float> ParseRenderScale(absl::string_view value);
42
44 std::vector<uint8_t> png_data;
45 int width = 0;
46 int height = 0;
47};
48
49// Metadata about a dungeon room — no rendering required.
51 int room_id = 0;
52 uint8_t blockset = 0;
53 uint8_t spriteset = 0;
54 uint8_t palette = 0;
55 int layout_id = 0;
56 int effect = 0;
57 int collision = 0;
58 int tag1 = 0;
59 int tag2 = 0;
60 uint16_t message_id = 0;
62 int object_count = 0;
63 int sprite_count = 0;
64};
65
66// Renders dungeon rooms to PNG images headlessly (no ImGui or GPU required).
67// rom and game_data are non-owning; caller must keep them alive.
68// Thread-safe: each RenderDungeonRoom call is protected by an internal mutex.
70 public:
71 RenderService(Rom* rom, zelda3::GameData* game_data);
72
73 // Render room_id to PNG with the requested overlays at the given scale.
74 absl::StatusOr<RenderResult> RenderDungeonRoom(const RenderRequest& req);
75
76 // Return metadata for a room without rendering.
77 absl::StatusOr<RoomMetadata> GetDungeonRoomMetadata(int room_id);
78
79 private:
80 // Convert the composite Bitmap's indexed+palette surface to an RGBA buffer.
81 absl::StatusOr<std::vector<uint8_t>> BitmapToRgba(const gfx::Bitmap& bitmap,
82 int width, int height);
83
84 // Paint requested overlays into an RGBA buffer (CPU rasterizer).
85 void ApplyOverlays(std::vector<uint8_t>& rgba, int width, int height,
86 const zelda3::Room& room, uint32_t flags, float scale);
87
88 // Encode an RGBA buffer to PNG bytes.
89 absl::StatusOr<std::vector<uint8_t>> EncodePng(
90 const std::vector<uint8_t>& rgba, int width, int height);
91
92 Rom* rom_; // non-owning
94 mutable std::mutex mu_;
95};
96
97} // namespace service
98} // namespace app
99} // namespace yaze
100
101#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:69
absl::StatusOr< float > ParseRenderScale(absl::string_view value)
std::vector< uint8_t > png_data