Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/RenderBuildingTests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../Protocol/ServerTypes.h"
2
3#include <cstdio>
4#include <cstring>
5#include <stdexcept>
6#include <string>
7#include <vector>
8
9// Compile the actual Networking.cpp case with recording terrain/render effects.
10// No live client, server, GPU or network connection is used.
11struct Logger { enum Level { Info, Debug, Warn, Error }; };
12struct Cell
13{
15 unsigned char zone = 0;
16 long layout1 = 0, layout2 = 0, layout3 = 0, layout4 = 0;
17 bool powered = false;
18 short buildzoneOrdinal = -1;
19 bool IsUserColony() const { return zone != 0; }
20};
21Cell gridarray[64][64];
22bool g_bAboveClouds = false;
23
24struct Grid
25{
26 VECTOR2SHORT tcp;
27 char cube = -1;
28 bool dataReady = false, geometryReady = true, makeBuildings = false;
29 char dataPending = 0;
30 int released = 0, recalculated = 0;
31 void RemoveBuildZone(short) { ++released; }
32 void CalculateInsideArray(short, short) { ++recalculated; }
33};
34struct Viewscreen { Grid* ptrGrid; };
35struct Game { Viewscreen* viewscreen; };
36struct Packet { unsigned char data[1 + sizeof(SRenderBuilding)]; unsigned length = sizeof data; };
37
38struct Handler
39{
40 Game* game;
41 char msg[999] = {};
42 int errors = 0;
43 std::vector<std::string> messages;
44 void Trace(const char* message, Logger::Level level = Logger::Info)
45 {
46 messages.emplace_back(message);
47 if (level == Logger::Error) ++errors;
48 }
49 void Receive(const SRenderBuilding& building)
50 {
51 Packet storage = {};
52 memcpy(storage.data + 1, &building, sizeof building);
53 Packet* packet = &storage;
54 switch (packet->length - 1)
55 {
56#include "RenderBuilding.generated.h"
57 }
58 }
59};
60
61void Check(bool condition, const char* message)
62{
63 if (!condition) throw std::runtime_error(message);
64}
65
66int main()
67{
68 try
69 {
70 static_assert(sizeof(SRenderBuilding) == 24, "Building wire size changed");
71 Grid terrain;
72 Viewscreen view = { &terrain };
73 Game game = { &view };
74 Handler handler = { &game };
75
76 // bravo's 2026-09-22 log: an airfield broadcast arrives during loading,
77 // before the first request, with default grid center (30000, 30000).
78 SRenderBuilding building = {};
79 building.tcp = VECTOR2SHORT(604, 1104);
80 building.zone = 1;
82 building.powered = true;
83 building.layout = { static_cast<long>(0xD88DAED5UL), 0x5555E1F5L, 0x52000000L, static_cast<long>(0xF0000000UL) };
84 handler.Receive(building);
85 Check(handler.errors == 0, "Startup broadcast raised the reported off-grid error");
86 Check(!terrain.makeBuildings && terrain.released == 0 && terrain.recalculated == 0,
87 "Startup broadcast touched render resources");
88 for (const auto& column : gridarray)
89 for (const auto& cell : column)
90 Check(cell.type == PlotType::NotZoned, "Startup broadcast changed the terrain grid");
91
92 // Once requested, layouts can be stored while the terrain response is pending.
93 terrain.tcp = building.tcp;
94 terrain.cube = 1;
95 terrain.dataPending = 64;
96 handler.Receive(building);
97 Cell& cell = gridarray[31][31];
98 Check(handler.errors == 0 && cell.type == PlotType::UserAirfield && cell.powered &&
99 cell.layout1 == building.layout.layout1 && cell.layout4 == building.layout.layout4,
100 "Pending initial terrain request lost its building layout");
101 Check(!terrain.makeBuildings && terrain.recalculated == 0, "Rebuilt before terrain was ready");
102
103 // The full response's current building packet must still apply after startup.
104 terrain.dataReady = true;
105 terrain.dataPending = 0;
106 building.powered = false;
107 handler.Receive(building);
108 Check(!cell.powered && terrain.makeBuildings, "Full-grid building refresh was lost");
109
110 // Keep the September 11 fix: pending edge requests do not block rebuilding.
111 terrain.makeBuildings = false;
112 terrain.dataPending = 2;
113 cell.buildzoneOrdinal = 3;
114 building.layout.layout4 = 0x70000000L;
115 handler.Receive(building);
116 Check(handler.errors == 0 && terrain.released == 1 && cell.buildzoneOrdinal == -1 &&
117 terrain.makeBuildings && !terrain.geometryReady && terrain.recalculated == 1024,
118 "Pending edge requests blocked airfield runway/building rebuild");
119
120 // A cleared grid may retain its old coordinates until the next request.
121 terrain.dataReady = false;
122 terrain.dataPending = 0;
123 terrain.makeBuildings = false;
124 building.layout.layout4 = 123;
125 handler.Receive(building);
126 Check(cell.layout4 == 0x70000000L && !terrain.makeBuildings && terrain.recalculated == 1024,
127 "Unrequested cleared grid accepted an obsolete update");
128
129 // Actual off-grid updates on initialized terrain still report an error,
130 // with grid diagnostics available before the error triggers trace upload.
131 terrain.dataReady = true;
132 building.tcp.u += 100;
133 handler.Receive(building);
134 Check(handler.errors == 1, "Real off-grid error was suppressed");
135 bool diagnosticBeforeError = false;
136 for (const auto& message : handler.messages)
137 {
138 if (message.find("Grid center u604 v1104") != std::string::npos) diagnosticBeforeError = true;
139 if (message.find("off grid reference") != std::string::npos)
140 Check(diagnosticBeforeError, "Off-grid error uploaded before the grid diagnostic");
141 }
142 std::puts("PASS: startup broadcast, initial request, full refresh, pending edges, cleared grid, off-grid diagnostics");
143 return 0;
144 }
145 catch (const std::exception& error)
146 {
147 std::fprintf(stderr, "FAIL: %s\n", error.what());
148 return 1;
149 }
150}
PlotType
@ UserAirfield
@ NotZoned
Level
Definition Logger.h:23
@ Debug
Definition Logger.h:27
@ Info
Definition Logger.h:25
@ Warn
Definition Logger.h:26
@ Error
Definition Logger.h:28
std::unique_ptr< grid > ptrGrid
Definition Viewscreen.h:426
bool g_bAboveClouds
Definition globals.cpp:16
LOCALGRID2 gridarray[64][64]
Definition globals.cpp:100
@ Game
Use the game audio system.
Definition discordpp.h:505
unsigned char type
VECTOR2SHORT tcp
unsigned char zone
long layout1
long layout4