yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_object_rendering_tests.cc
Go to the documentation of this file.
1// Integration tests for dungeon object rendering using ObjectDrawer
2// Updated for DungeonEditorV2 architecture - uses ObjectDrawer (production system)
3// instead of the obsolete ObjectRenderer
4
5#ifndef IMGUI_DEFINE_MATH_OPERATORS
6#define IMGUI_DEFINE_MATH_OPERATORS
7#endif
8
12
13#include <gtest/gtest.h>
14#include <memory>
15#include <vector>
16#include <chrono>
17
18#include "app/rom.h"
21#include "testing.h"
22#include "test_utils.h"
23
24namespace yaze {
25namespace test {
26
34 protected:
35 void SetUp() override {
36 BoundRomTest::SetUp();
37
38 // Create drawer
39 drawer_ = std::make_unique<zelda3::ObjectDrawer>(rom());
40
41 // Create background buffers
42 bg1_ = std::make_unique<gfx::BackgroundBuffer>(512, 512);
43 bg2_ = std::make_unique<gfx::BackgroundBuffer>(512, 512);
44
45 // Setup test palette
47 }
48
49 void TearDown() override {
50 bg2_.reset();
51 bg1_.reset();
52 drawer_.reset();
53 BoundRomTest::TearDown();
54 }
55
58 gfx::SnesPalette palette;
59
60 // Create standard dungeon palette
61 for (int i = 0; i < 16; i++) {
62 int intensity = i * 16;
63 palette.AddColor(gfx::SnesColor(intensity, intensity, intensity));
64 }
65
66 group.AddPalette(palette);
67 return group;
68 }
69
70 zelda3::RoomObject CreateTestObject(int id, int x, int y, int size = 0x12, int layer = 0) {
71 zelda3::RoomObject obj(id, x, y, size, layer);
72 obj.set_rom(rom());
74 return obj;
75 }
76
77 std::unique_ptr<zelda3::ObjectDrawer> drawer_;
78 std::unique_ptr<gfx::BackgroundBuffer> bg1_;
79 std::unique_ptr<gfx::BackgroundBuffer> bg2_;
81};
82
83// Test basic object drawing
84TEST_F(DungeonObjectRenderingTests, BasicObjectDrawing) {
85 std::vector<zelda3::RoomObject> objects;
86 objects.push_back(CreateTestObject(0x10, 5, 5, 0x12, 0)); // Wall
87 objects.push_back(CreateTestObject(0x20, 10, 10, 0x22, 0)); // Floor
88
89 bg1_->ClearBuffer();
90 bg2_->ClearBuffer();
91
92 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
93 ASSERT_TRUE(status.ok()) << "Drawing failed: " << status.message();
94
95 // Verify buffers have content
96 auto& bg1_bitmap = bg1_->bitmap();
97 EXPECT_TRUE(bg1_bitmap.is_active());
98 EXPECT_GT(bg1_bitmap.width(), 0);
99}
100
101// Test objects on different layers
102TEST_F(DungeonObjectRenderingTests, MultiLayerRendering) {
103 std::vector<zelda3::RoomObject> objects;
104 objects.push_back(CreateTestObject(0x10, 5, 5, 0x12, 0)); // BG1
105 objects.push_back(CreateTestObject(0x20, 10, 10, 0x22, 1)); // BG2
106 objects.push_back(CreateTestObject(0x30, 15, 15, 0x12, 2)); // BG3
107
108 bg1_->ClearBuffer();
109 bg2_->ClearBuffer();
110
111 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
112 ASSERT_TRUE(status.ok());
113
114 // Both buffers should be active
115 EXPECT_TRUE(bg1_->bitmap().is_active());
116 EXPECT_TRUE(bg2_->bitmap().is_active());
117}
118
119// Test empty object list
121 std::vector<zelda3::RoomObject> objects; // Empty
122
123 bg1_->ClearBuffer();
124 bg2_->ClearBuffer();
125
126 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
127 // Should succeed (drawing nothing is valid)
128 EXPECT_TRUE(status.ok());
129}
130
131// Test large object set
133 std::vector<zelda3::RoomObject> objects;
134
135 // Create 100 test objects
136 for (int i = 0; i < 100; i++) {
137 int x = (i % 10) * 5;
138 int y = (i / 10) * 5;
139 objects.push_back(CreateTestObject(0x10 + (i % 20), x, y, 0x12, i % 2));
140 }
141
142 bg1_->ClearBuffer();
143 bg2_->ClearBuffer();
144
145 auto start = std::chrono::high_resolution_clock::now();
146 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
147 auto end = std::chrono::high_resolution_clock::now();
148
149 ASSERT_TRUE(status.ok());
150
151 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
152 // Should complete in reasonable time
153 EXPECT_LT(duration.count(), 1000) << "Rendered 100 objects in " << duration.count() << "ms";
154}
155
156// Test boundary conditions
158 std::vector<zelda3::RoomObject> objects;
159
160 // Objects at boundaries
161 objects.push_back(CreateTestObject(0x10, 0, 0, 0x12, 0)); // Origin
162 objects.push_back(CreateTestObject(0x10, 63, 63, 0x12, 0)); // Max valid
163 objects.push_back(CreateTestObject(0x10, 32, 32, 0x12, 0)); // Center
164
165 bg1_->ClearBuffer();
166 bg2_->ClearBuffer();
167
168 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
169 EXPECT_TRUE(status.ok());
170}
171
172// Test various object types
174 // Test common object types
175 std::vector<int> object_types = {
176 0x00, 0x01, 0x02, 0x03, // Floor/wall objects
177 0x09, 0x0A, // Diagonal objects
178 0x10, 0x11, 0x12, // Standard objects
179 0x20, 0x21, // Decorative objects
180 0x34, // Solid block
181 };
182
183 for (int obj_type : object_types) {
184 std::vector<zelda3::RoomObject> objects;
185 objects.push_back(CreateTestObject(obj_type, 10, 10, 0x12, 0));
186
187 bg1_->ClearBuffer();
188 bg2_->ClearBuffer();
189
190 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
191 // Some object types might not be valid, that's okay
192 if (!status.ok()) {
193 std::cout << "Object type 0x" << std::hex << obj_type << std::dec
194 << " not renderable: " << status.message() << std::endl;
195 }
196 }
197}
198
199// Test error handling
201 // Test with null ROM
202 zelda3::ObjectDrawer null_drawer(nullptr);
203 std::vector<zelda3::RoomObject> objects;
204 objects.push_back(CreateTestObject(0x10, 5, 5));
205
206 bg1_->ClearBuffer();
207 bg2_->ClearBuffer();
208
209 auto status = null_drawer.DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
210 EXPECT_FALSE(status.ok());
211 EXPECT_EQ(status.code(), absl::StatusCode::kFailedPrecondition);
212}
213
214} // namespace test
215} // namespace yaze
216
SNES Color container.
Definition snes_color.h:38
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
void AddColor(const SnesColor &color)
Tests for ObjectDrawer with realistic dungeon scenarios.
std::unique_ptr< gfx::BackgroundBuffer > bg1_
zelda3::RoomObject CreateTestObject(int id, int x, int y, int size=0x12, int layer=0)
std::unique_ptr< gfx::BackgroundBuffer > bg2_
std::unique_ptr< zelda3::ObjectDrawer > drawer_
Draws dungeon objects to background buffers using game patterns.
absl::Status DrawObjectList(const std::vector< RoomObject > &objects, gfx::BackgroundBuffer &bg1, gfx::BackgroundBuffer &bg2, const gfx::PaletteGroup &palette_group)
Draw all objects in a room.
void set_rom(Rom *rom)
Definition room_object.h:67
TEST_F(DungeonObjectRenderingE2ETests, RunAllTests)
Main namespace for the application.
Represents a group of palettes.
void AddPalette(SnesPalette pal)