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

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

1#include <algorithm>
2#include <iostream>
3#include <stdexcept>
4#include <string>
5#include <vector>
6#include <cstring>
7#include <climits>
8
9namespace Rendering { struct RenderTexture {}; }
10namespace RiseMath { struct Vector4 { float x, y, z, w; }; }
11struct Vehicle { int logoOrdinal = -1; int VB = 0; float cloaking = 1; } playerships[4];
12struct Model { bool overlay = true; } polyobjects[2];
13struct SPacketBig
14{
16 char msg[84];
17};
18struct Network
19{
20 std::vector<SPacketBig> requests;
21 void SendToServer(SPacketBig* packet, size_t, bool reliable)
22 {
23 if (!reliable) throw std::runtime_error("logo download request must be reliable");
24 requests.push_back(*packet);
25 }
26};
27struct Effect
28{
29 Rendering::RenderTexture* overlay = nullptr;
30 void SetTexture(const char* name, Rendering::RenderTexture* texture)
31 {
32 if (std::strcmp(name, "OverlayMap")) throw std::runtime_error("wrong texture binding");
33 overlay = texture;
34 }
35};
36struct Graphics { Effect* g_pEffect; };
37struct Game { Network* networking; Graphics* graphics; };
38struct Viewscreen
39{
41 std::vector<std::string> logofiles;
42 std::vector<Rendering::RenderTexture*> m_pddsLogos;
43 void CheckLogo(unsigned char array, char* logofile);
44};
45#define V(expression) (expression)
46#include "VehicleLogo.generated.h"
47
48void Check(bool ok, const char* message)
49{
50 if (!ok) throw std::runtime_error(message);
51}
52
53int main()
54{
55 try
56 {
57 Network network;
58 Effect effect;
59 Graphics graphics{ &effect };
60 Game game{ &network, &graphics };
61 Viewscreen view{ &game };
62 Rendering::RenderTexture fedex, rana;
63 auto assign = [&](unsigned char slot, const char* name)
64 {
65 char filename[9];
66 strcpy_s(filename, name);
67 view.CheckLogo(slot, filename);
68 };
69 auto draw = [&](int slot, Rendering::RenderTexture* expected)
70 {
71 const float enabled = BindLogo(&view, slot);
72 Check(effect.overlay == expected, "vehicle inherited another vehicle's logo texture");
73 Check(enabled == (expected ? 1.f : 0.f), "overlay enabled without an assigned, loaded logo");
74 };
75
76 assign(1, "fedex");
77 Check(network.requests.size() == 1 && network.requests[0].type == 15 &&
78 network.requests[0].vehicleId == 0 && std::string(network.requests[0].msg) == "fedex",
79 "new assignment did not request the correct logo/cache slot");
80 draw(1, nullptr); // Download is pending.
81 view.m_pddsLogos[0] = &fedex;
82 draw(1, &fedex);
83 draw(0, nullptr); // Unassigned car follows a branded vehicle.
84
85 assign(2, "rana");
86 Check(network.requests.size() == 2 && network.requests[1].vehicleId == 1,
87 "second logo reused the first request's cache slot");
88 draw(1, &fedex);
89 draw(2, nullptr); // Pending logo must also clear previous draw state.
90 view.m_pddsLogos[1] = &rana;
91 for (int preceding : { 1, 2, 1, 2 })
92 {
93 draw(preceding, preceding == 1 ? &fedex : &rana);
94 draw(0, nullptr); // Camera culling changes which branded vehicle precedes the car.
95 }
96
97 assign(0, "fedex");
98 draw(0, &fedex);
99 Check(network.requests.size() == 2, "cached logo was requested again");
100 assign(0, "_"); // Same slot receives an unbranded vehicle's metadata.
101 draw(0, nullptr);
102 Check(playerships[0].logoOrdinal == -1, "no-logo metadata retained the old assignment");
103 assign(0, "rana");
104 draw(0, &rana);
105 assign(0, "");
106 draw(0, nullptr);
107 Check(network.requests.size() == 2, "empty/no-logo metadata requested a download");
108
109 assign(3, "late");
110 const int pending = playerships[3].logoOrdinal;
111 assign(3, "_");
112 view.m_pddsLogos[pending] = &fedex; // Old request arrives after removal.
113 draw(3, nullptr);
114
115 polyobjects[1].overlay = false;
116 playerships[1].VB = 1;
117 draw(2, &rana);
118 draw(1, nullptr); // Model does not support logo coordinates.
119 for (int invalid : { -2, static_cast<int>(view.m_pddsLogos.size()), INT_MAX })
120 {
121 playerships[0].logoOrdinal = invalid;
122 draw(2, &rana);
123 draw(0, nullptr);
124 }
125 std::cout << "Vehicle logo assignment, draw-order isolation, pending downloads, slot reuse, and bounds tests passed.\n";
126 return 0;
127 }
128 catch (const std::exception& error)
129 {
130 std::cerr << error.what() << '\n';
131 return 1;
132 }
133}
Rendering::RenderMaterial * g_pEffect
Definition Graphics.h:30
std::vector< std::string > logofiles
Definition Viewscreen.h:308
GameClass * gameclass
Definition Viewscreen.h:439
std::vector< Rendering::RenderTexture * > m_pddsLogos
Definition Viewscreen.h:307
void CheckLogo(unsigned char array, char *logofile)
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
s_polygon_object polyobjects[maxpolyC]
Definition globals.cpp:106
std::vector< Segment > Network(float width, float height, uint32_t seed)
@ Game
Use the game audio system.
Definition discordpp.h:505
unsigned char array
unsigned char ship
unsigned char inarray
unsigned char type