yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
dungeon_object_rendering_tests_new.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
8
9#include <gtest/gtest.h>
10#include <memory>
11#include <vector>
12#include <chrono>
13
14#include "app/rom.h"
17#include "testing.h"
18#include "test_utils.h"
19
20namespace yaze {
21namespace test {
22
29class DungeonObjectRenderingTests : public TestRomManager::BoundRomTest {
30 protected:
31 void SetUp() override {
32 BoundRomTest::SetUp();
33
34 // Create drawer
35 drawer_ = std::make_unique<zelda3::ObjectDrawer>(rom());
36
37 // Create background buffers
38 bg1_ = std::make_unique<gfx::BackgroundBuffer>(512, 512);
39 bg2_ = std::make_unique<gfx::BackgroundBuffer>(512, 512);
40
41 // Setup test palette
43 }
44
45 void TearDown() override {
46 bg2_.reset();
47 bg1_.reset();
48 drawer_.reset();
49 BoundRomTest::TearDown();
50 }
51
54 gfx::SnesPalette palette;
55
56 // Create standard dungeon palette
57 for (int i = 0; i < 16; i++) {
58 int intensity = i * 16;
59 palette.AddColor(gfx::SnesColor(intensity, intensity, intensity));
60 }
61
62 group.AddPalette(palette);
63 return group;
64 }
65
66 zelda3::RoomObject CreateTestObject(int id, int x, int y, int size = 0x12, int layer = 0) {
67 zelda3::RoomObject obj(id, x, y, size, layer);
68 obj.set_rom(rom());
70 return obj;
71 }
72
73 std::unique_ptr<zelda3::ObjectDrawer> drawer_;
74 std::unique_ptr<gfx::BackgroundBuffer> bg1_;
75 std::unique_ptr<gfx::BackgroundBuffer> bg2_;
77};
78
79// Test basic object drawing
80TEST_F(DungeonObjectRenderingTests, BasicObjectDrawing) {
81 std::vector<zelda3::RoomObject> objects;
82 objects.push_back(CreateTestObject(0x10, 5, 5, 0x12, 0)); // Wall
83 objects.push_back(CreateTestObject(0x20, 10, 10, 0x22, 0)); // Floor
84
85 bg1_->ClearBuffer();
86 bg2_->ClearBuffer();
87
88 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
89 ASSERT_TRUE(status.ok()) << "Drawing failed: " << status.message();
90
91 // Verify buffers have content
92 auto& bg1_bitmap = bg1_->bitmap();
93 EXPECT_TRUE(bg1_bitmap.is_active());
94 EXPECT_GT(bg1_bitmap.width(), 0);
95}
96
97// Test objects on different layers
98TEST_F(DungeonObjectRenderingTests, MultiLayerRendering) {
99 std::vector<zelda3::RoomObject> objects;
100 objects.push_back(CreateTestObject(0x10, 5, 5, 0x12, 0)); // BG1
101 objects.push_back(CreateTestObject(0x20, 10, 10, 0x22, 1)); // BG2
102 objects.push_back(CreateTestObject(0x30, 15, 15, 0x12, 2)); // BG3
103
104 bg1_->ClearBuffer();
105 bg2_->ClearBuffer();
106
107 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
108 ASSERT_TRUE(status.ok());
109
110 // Both buffers should be active
111 EXPECT_TRUE(bg1_->bitmap().is_active());
112 EXPECT_TRUE(bg2_->bitmap().is_active());
113}
114
115// Test empty object list
116TEST_F(DungeonObjectRenderingTests, EmptyObjectList) {
117 std::vector<zelda3::RoomObject> objects; // Empty
118
119 bg1_->ClearBuffer();
120 bg2_->ClearBuffer();
121
122 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
123 // Should succeed (drawing nothing is valid)
124 EXPECT_TRUE(status.ok());
125}
126
127// Test large object set
128TEST_F(DungeonObjectRenderingTests, LargeObjectSet) {
129 std::vector<zelda3::RoomObject> objects;
130
131 // Create 100 test objects
132 for (int i = 0; i < 100; i++) {
133 int x = (i % 10) * 5;
134 int y = (i / 10) * 5;
135 objects.push_back(CreateTestObject(0x10 + (i % 20), x, y, 0x12, i % 2));
136 }
137
138 bg1_->ClearBuffer();
139 bg2_->ClearBuffer();
140
141 auto start = std::chrono::high_resolution_clock::now();
142 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
143 auto end = std::chrono::high_resolution_clock::now();
144
145 ASSERT_TRUE(status.ok());
146
147 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
148 // Should complete in reasonable time
149 EXPECT_LT(duration.count(), 1000) << "Rendered 100 objects in " << duration.count() << "ms";
150}
151
152// Test boundary conditions
153TEST_F(DungeonObjectRenderingTests, BoundaryObjects) {
154 std::vector<zelda3::RoomObject> objects;
155
156 // Objects at boundaries
157 objects.push_back(CreateTestObject(0x10, 0, 0, 0x12, 0)); // Origin
158 objects.push_back(CreateTestObject(0x10, 63, 63, 0x12, 0)); // Max valid
159 objects.push_back(CreateTestObject(0x10, 32, 32, 0x12, 0)); // Center
160
161 bg1_->ClearBuffer();
162 bg2_->ClearBuffer();
163
164 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
165 EXPECT_TRUE(status.ok());
166}
167
168// Test various object types
169TEST_F(DungeonObjectRenderingTests, VariousObjectTypes) {
170 // Test common object types
171 std::vector<int> object_types = {
172 0x00, 0x01, 0x02, 0x03, // Floor/wall objects
173 0x09, 0x0A, // Diagonal objects
174 0x10, 0x11, 0x12, // Standard objects
175 0x20, 0x21, // Decorative objects
176 0x34, // Solid block
177 };
178
179 for (int obj_type : object_types) {
180 std::vector<zelda3::RoomObject> objects;
181 objects.push_back(CreateTestObject(obj_type, 10, 10, 0x12, 0));
182
183 bg1_->ClearBuffer();
184 bg2_->ClearBuffer();
185
186 auto status = drawer_->DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
187 // Some object types might not be valid, that's okay
188 if (!status.ok()) {
189 std::cout << "Object type 0x" << std::hex << obj_type << std::dec
190 << " not renderable: " << status.message() << std::endl;
191 }
192 }
193}
194
195// Test error handling
196TEST_F(DungeonObjectRenderingTests, ErrorHandling) {
197 // Test with null ROM
198 zelda3::ObjectDrawer null_drawer(nullptr);
199 std::vector<zelda3::RoomObject> objects;
200 objects.push_back(CreateTestObject(0x10, 5, 5));
201
202 bg1_->ClearBuffer();
203 bg2_->ClearBuffer();
204
205 auto status = null_drawer.DrawObjectList(objects, *bg1_, *bg2_, palette_group_);
206 EXPECT_FALSE(status.ok());
207 EXPECT_EQ(status.code(), absl::StatusCode::kFailedPrecondition);
208}
209
210} // namespace test
211} // namespace yaze
212
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)
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_
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)