Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/LandingLightCollisionChecks.h

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

1// Included inside the test namespace, using the production-function fixture.
2// Existing collision cases specify acceleration samples; supply their discrete
3// delta-v explicitly while keeping each test's occupant load independent.
4void CrashImpulseSample(Viewscreen& view, const RiseMath::Vector3& load, float dt=1.f/60)
5{
7 view.UpdateCrashDamage(load,dt);
8}
9
10void LongFrameStructuralChecks()
11{
12 // Bill's six recorded severities/timesteps. The log does not identify the
13 // dominant axis, so reproduce the underlying load on all six directions.
14 for (auto sample : {std::pair<float,float>{1.432f,.415889f},{1.522f,.363998f},
15 {1.339f,.361211f},{2.767f,.385156f},{3.544f,.355792f},{1.108f,.363179f}})
16 for (auto threshold : {RiseMath::Vector3(9,0,0),RiseMath::Vector3(-9,0,0),
17 RiseMath::Vector3(0,20,0),RiseMath::Vector3(0,-15,0),
18 RiseMath::Vector3(0,0,33.2f),RiseMath::Vector3(0,0,-22.5f)})
19 {
21 LampGameFixture game;Viewscreen view;view.gameclass=&game;
24 view.sumofforces=threshold*(sample.first/(60*sample.second));
26 view.sumofforces.y,view.sumofforces.z,sample.second))>0,
27 "recorded long-frame loads reproduce the previous false-damage calculation");
28 view.UpdateCrashDamage(view.sumofforces,sample.second);
31 "all six trace loads are harmless without a collision, on every possible dominant axis");
32 }
33 for (float dt : {1.f/144,1.f/60,1.f/30,.355792f,.385156f,.415889f,1.f,2.f})
34 {
36 LampGameFixture game;Viewscreen view;view.gameclass=&game;view.advanceframe=false;
38 const RiseMath::Vector3 sustained(0,1.149f,0);
39 view.sumofforces=sustained;
40 view.UpdateCrashDamage(sustained,dt);
41 Check(ourcockpit.vdat.hullintegrity==127,"steady support/lift cannot become an impact during a stall");
42
43 // Exercise production impulse accumulation with a 60 km/h frontal stop.
44 view.sumofforces=sustained*(dt/oneOvergForceKmssC);
45 view.ApplyCollisionImpulse({0,0,-60.f/3600});
46 const auto frameLoad=view.sumofforces*(oneOvergForceKmssC/dt);
47 view.sumofforces=frameLoad;
48 view.UpdateCrashDamage(frameLoad,dt);
50 "real impacts retain identical hull/glass damage even during a two-second stall");
51 Check(RiseMath::Vec3Length(&view.structuralImpactImpulse)==0,"impact is consumed after evaluation");
53 game.bus->ProgramTime=2.1;view.sumofforces=sustained;
54 view.UpdateCrashDamage(sustained,dt);
55 Check(ourcockpit.vdat.hullintegrity==127,"a consumed impact cannot replay on a later frame");
56
57 view.ClearCollisionEffects();view.sumofforces={18,0,0};
58 view.UpdateCrashDamage(view.sumofforces,dt);
59 Check(ourcockpit.vdat.hullintegrity==103,"genuine sustained overload retains its acceleration threshold at every timestep");
60 }
62 LampGameFixture game;Viewscreen view;view.gameclass=&game;
64 view.ApplyCollisionImpulse({0,0,-.02f});
66 Check(RiseMath::Vec3Length(&view.structuralImpactImpulse)==0,"simulator entry clears pending impact");
67 view.ApplyCollisionImpulse({0,0,-.02f});
68 Check(RiseMath::Vec3Length(&view.structuralImpactImpulse)==0,"simulator contacts do not accumulate exterior impulses");
69 view.sumofforces={0,1.149f,0};view.UpdateCrashDamage(view.sumofforces,2);
70 Check(ourcockpit.vdat.hullintegrity==127,"simulator support retains original unscaled behavior");
72 view.UpdateCrashDamage(view.sumofforces,2);
73 Check(ourcockpit.vdat.hullintegrity==127,"simulator exit cannot replay contact damage");
74 view.ApplyCollisionImpulse({0,0,-.02f});deathinhibit=1;
75 view.UpdateCrashDamage({0,0,-127});deathinhibit=0;
76 Check(RiseMath::Vec3Length(&view.structuralImpactImpulse)==0,"inhibited impacts are discarded");
77 std::cout<<"PASS: six trace regressions, long-frame steady loads, real impacts, sustained overload and simulator transitions\n";
78}
79
80void CrashTimingChecks()
81{
82 for (auto force : {RiseMath::Vector3(9,0,0), RiseMath::Vector3(-9,0,0),
83 RiseMath::Vector3(0,-15,0), RiseMath::Vector3(0,20,0),
84 RiseMath::Vector3(0,0,-22.5f), RiseMath::Vector3(0,0,33.2f)})
85 Check(std::abs(CollisionDamage::Severity(force.x,force.y,force.z)-1.f)<.00001f,
86 "fault severity retains every existing directional crash threshold");
87 for (unsigned severity=1;severity<=4;++severity)
88 Check(CollisionDamage::FaultProbability(float(severity))==float(severity)*.25f,
89 "fault probability scales from 25 percent to 100 percent with impact severity");
90 unsigned triggered=0;
91 for(unsigned roll=0;roll<=32767;++roll)
92 {
93 const bool mild=CollisionDamage::TriggersFault(1,roll,32767);
94 const bool moderate=CollisionDamage::TriggersFault(2,roll,32767);
95 const bool severe=CollisionDamage::TriggersFault(4,roll,32767);
96 Check((!mild || moderate) && severe,"stronger impacts cannot reduce fault chance");
97 triggered+=moderate?1:0;
98 }
99 Check(triggered==16384,"twice-threshold impact has exactly 50 percent fault chance");
100 Check(CollisionDamage::TriggersFault(CollisionDamage::Severity(0,0,-126.658607f),32767,32767),
101 "recorded C-2 impact guarantees an eligible control upset");
102 for (int windshield : {-1,0,33,127})
103 {
105 LampGameFixture game;Viewscreen view;view.gameclass=&game;
106 ourcockpit.vdat.windshield=char(windshield);
108 view.sumofforces={0,1,-127};view.advanceframe=false;
109 CrashImpulseSample(view,{0,1,0}); // Occupant jolt without frame distortion.
110 Check(playerships[0].rainProtectionEnabled && !playerships[0].crashHornFault,
111 "occupant jolt can hit the stalk but cannot create a persistent horn fault");
113 "an occupant jolt alone cannot damage the frame or glass");
114 view.SetRainProtection(false);
115 view.SetCrashHornFault(true);
116 const auto events=game.net.events.size();
117 CrashImpulseSample(view,{0,1,0});
118 view.SetCrashHornFault(true);
119 Check(!playerships[0].rainProtectionEnabled && game.net.events.size()==events,
120 "turning wipers off survives the same jolt and a latched horn");
121 game.bus->ProgramTime=.51;
122 CrashImpulseSample(view,{0,1,0});
123 Check(playerships[0].rainProtectionEnabled,"a separate occupant jolt can hit the stalk again");
124 }
125 for (unsigned seed=0;seed<64;++seed)
126 {
128 LampGameFixture game;Viewscreen view;view.gameclass=&game;
130 view.sumofforces={0,1,0};view.advanceframe=false;srand(seed);
131 CrashImpulseSample(view,{0,1,-127}); // Frame load without a control upset.
133 "glass follows actual frame loss rather than an independent random damage roll");
134 Check(!playerships[0].rainProtectionEnabled,
135 "frame and glass damage alone do not hit the wiper stalk");
136 for (int event : game.net.events) Check(event==EventType::EVENT_WINDSHIELD_FAULT,
137 "structural damage can only emit a horn fault, not a wiper command");
138 }
139 for (int hull : {-1,0})
140 {
142 LampGameFixture game;Viewscreen view;view.gameclass=&game;
144 view.sumofforces={0,1,0};CrashImpulseSample(view,{0,1,-127});
145 Check(ourcockpit.vdat.windshield==127,"missing or unchanged frame health cannot manufacture glass damage");
146 }
147 for (int guard=0;guard<3;++guard)
148 {
150 LampGameFixture game;Viewscreen view;view.gameclass=&game;
151 view.sumofforces={0,1,-127};
152 view.hasAnimatedWipers=guard!=0;
153 playerships[0].groundvehicle=guard!=1;
154 game.gui.player[0].frame=guard==2?1:0;
155 CrashImpulseSample(view,{0,1,0});
156 Check(playerships[0].rainProtectionEnabled==(guard==1),
157 "stalk upset needs fitted wipers and an occupant at the controls");
158 Check(!playerships[0].crashHornFault,"occupant-only jolts never latch the horn");
159 }
160 unsigned outcomes=0;
161 for(unsigned seed=0;seed<128;++seed)
162 {
164 LampGameFixture game;Viewscreen view;view.gameclass=&game;
165 view.sumofforces={0,1,-45};srand(seed*16777213u);
166 CrashImpulseSample(view,{0,1,0});
167 const unsigned outcome=(playerships[0].rainProtectionEnabled?1u:0u) | (playerships[0].crashHornFault?2u:0u);
168 outcomes|=1u<<outcome;
169 }
170 Check(outcomes==3,"moderate occupant-only jolts can hit or miss the stalk, never latch the horn");
171 outcomes=0;
172 for(unsigned seed=0;seed<256;++seed)
173 {
175 LampGameFixture game;Viewscreen view;view.gameclass=&game;
177 view.sumofforces={0,1,-45};srand(seed*16777213u);
178 CrashImpulseSample(view,view.sumofforces);
179 const unsigned outcome=(playerships[0].rainProtectionEnabled?1u:0u) | (playerships[0].crashHornFault?2u:0u);
180 outcomes|=1u<<outcome;
181 }
182 Check(outcomes==15,"combined occupant and structural loads allow wipers only, horn only, both or neither");
183 for (unsigned fps : {30u,60u,144u})
184 {
186 LampGameFixture game;Viewscreen view;view.gameclass=&game;
187 view.advanceframe=false;
189 view.sumofforces={0,1,-127};
190 srand(37);
191 CrashImpulseSample(view,view.sumofforces);
192 Check(ourcockpit.vdat.windshield<127,"single-frame crash damages windshield between animation ticks");
193 const int windshield=ourcockpit.vdat.windshield;
194 const int hull=ourcockpit.vdat.hullintegrity;
195 for (unsigned frame=1;frame<fps*2;++frame)
196 {
197 game.bus->ProgramTime=double(frame)/fps;
198 CrashImpulseSample(view,view.sumofforces);
199 }
200 Check(ourcockpit.vdat.windshield==windshield && ourcockpit.vdat.hullintegrity==hull,
201 "continuing contact is charged once at every tested frame rate");
203 game.bus->ProgramTime+=.51;
204 CrashImpulseSample(view,view.sumofforces);
205 Check(ourcockpit.vdat.windshield<127,"separate crash rearms damage");
206 }
208 LampGameFixture game;Viewscreen view;view.gameclass=&game;
209 view.advanceframe=false;view.sumofforces={0,1,-127};
210 for (unsigned seed=0;seed<64;++seed)
211 {
212 view.ClearCollisionEffects();ourcockpit.vdat.windshield=127;srand(seed);
213 CrashImpulseSample(view,view.sumofforces);
214 Check(!playerships[0].crashHornFault && playerships[0].rainProtectionEnabled && !dead,
215 "severe jolt hits the stalk while alive but cannot short a horn without new hull damage");
216 }
217 view.SetCrashHornFault(true);
218 const auto events=game.net.events.size();
219 view.SetCrashHornFault(true);
220 Check(game.net.events.size()==events,"latched fault cannot resend or toggle the wipers off");
222 playerships[0].isSimulator=true;
224 Check(!playerships[0].crashHornFault && !playerships[1].crashHornFault &&
225 !playerships[0].rainProtectionEnabled && view.crashDamageEpisode.lastContact<0,
226 "simulator entry clears local and remote crash faults and contact memory");
227 Check(view.controlJoltEpisode.lastContact<0,"simulator entry clears occupant-jolt memory too");
228 view.SetCrashHornFault(true);
229 ReceiveCrashFaultFixture(1,1.f);
230 Check(!playerships[1].crashHornFault,"received crash faults cannot latch while in simulator");
231 Check(!playerships[0].crashHornFault && game.net.events.size()==events,
232 "simulator cannot emit a crash fault or wiper event");
234 CrashImpulseSample(view,view.sumofforces);
235 Check(ourcockpit.vdat.windshield==127,"simulator retains animation cadence");
236 view.advanceframe=true;CrashImpulseSample(view,view.sumofforces);
238 "simulator baseline structural damage remains, without exterior fault activation");
239 playerships[0].isSimulator=false;view.advanceframe=false;
240 Check(!playerships[0].crashHornFault && !playerships[0].rainProtectionEnabled,
241 "exit cannot replay a cached crash fault");
242 ReceiveCrashFaultFixture(1,1.f);
243 Check(playerships[1].crashHornFault,"new remote crash fault works outside simulator");
244 playerships[1].isSimulator=true;ReceiveCrashFaultFixture(1,1.f);
245 Check(!playerships[1].crashHornFault,"simulated remote vehicles cannot latch crash faults");
246 ourcockpit.vdat.windshield=ourcockpit.vdat.hullintegrity=127;CrashImpulseSample(view,view.sumofforces);
247 Check(ourcockpit.vdat.windshield<127,"new real-world impact works immediately after exit");
248 for (int guard=0;guard<3;++guard)
249 {
251 dead=guard==0;deathinhibit=guard==1?1.f:0.f;
253 CrashImpulseSample(view,view.sumofforces);
254 Check(ourcockpit.vdat.windshield==127,"death, spawn protection and interiors remain protected");
255 Check(!playerships[0].rainProtectionEnabled && !playerships[0].crashHornFault,
256 "death, spawn protection and interiors suppress occupant control upsets");
257 }
258 dead=false;deathinhibit=0;
259 std::cout<<"PASS: occupant stalk activation and structural horn/glass damage, animation timing, contact grouping and simulator transitions\n";
260}
261
262void StructuralCrushChecks()
263{
264 for (unsigned fps : {30u,60u,144u})
265 for (unsigned seed=0;seed<64;++seed)
266 {
268 LampGameFixture game;Viewscreen view;view.gameclass=&game;view.advanceframe=false;
272 game.bus->ProgramTime=1;
273 view.DamageLandingLight(1,0,7.75f,"left corner");
274 const float dt=1.f/fps;
275 const RiseMath::Vector3 load(0,1.149f,-(60.f/3.6f)/(9.80665f*dt));
276 view.sumofforces=load;srand(seed);game.bus->ProgramTime+=dt;
277 CrashImpulseSample(view,load,dt);
279 ourcockpit.vdat.landing[1]==0 && ourcockpit.vdat.landing[0]==127,
280 "60 km/h left-corner impulse gives identical hull/glass loss and lamp destruction at every FPS and RNG seed");
281 game.bus->ProgramTime+=dt;CrashImpulseSample(view,load,dt);
282 Check(ourcockpit.vdat.hullintegrity==42,"duplicate crash report cannot stack structural damage");
283 }
284 for (auto sample : {std::pair<float,float>{103.320786f,.0168485995f}, {103.346191f,.0165435001f}})
285 {
286 const int loss=CollisionDamage::HullDamage(CollisionDamage::ImpactSeverity(0,0,-sample.first,sample.second));
287 Check(loss>=85 && loss<=87,"both recorded C-2 crashes have comparable major structural damage");
288 }
289 int previous=0;
290 for (unsigned speed=0;speed<=100;++speed)
291 {
293 -(speed/3.6f)/(9.80665f/60),1.f/60));
294 Check(damage>=previous,"increasing speed cannot reduce deterministic structural damage");
295 previous=damage;
296 }
298 episode.Begin(1);
299 int hull=episode.Apply(127,2);
300 Check(hull==103,"milder collision causes less structural damage");
301 episode.Begin(1.05);hull=episode.Apply(hull,4.6f);
302 Check(hull==41,"a stronger sample in the same crash charges only additional peak damage");
303 episode.Begin(1.1);Check(episode.Apply(hull,4.6f)==41,"peak damage is not charged twice");
304 episode.Begin(2);Check(episode.Apply(hull,2)==17,"a separate collision causes new structural damage");
305 Check(episode.Apply(-1,5)==-1 && episode.Apply(0,5)==0,"absent and destroyed hull remain unchanged");
306 for(float dt : {0.f,-1.f,std::numeric_limits<float>::quiet_NaN()})
307 Check(CollisionDamage::ImpactSeverity(0,0,-127,dt)==0,"invalid timesteps cannot manufacture impulse damage");
308 Check(CollisionDamage::HornFaultProbability(4.59f,127,41)>0 &&
310 "recorded front crush can short the horn but does not guarantee a closed circuit");
311 for (int loss=1;loss<=127;++loss)
312 {
313 const auto mild=CollisionDamage::HornFaultProbability(2,127,127-loss);
314 const auto severe=CollisionDamage::HornFaultProbability(4,127,127-loss);
315 Check(mild<=severe && severe>=CollisionDamage::HornFaultProbability(4,127,128-loss),
316 "horn fault chance grows with frontal severity and fresh structural damage");
317 }
318 for (auto load : {RiseMath::Vector3(0,1,127),RiseMath::Vector3(127,1,0),
319 RiseMath::Vector3(0,-127,0)})
320 for (unsigned seed=0;seed<64;++seed)
321 {
323 LampGameFixture game;Viewscreen view;view.gameclass=&game;
324 ourcockpit.vdat.hullintegrity=127;srand(seed);
325 CrashImpulseSample(view,load);
327 "rear, side and vertical structural loads cannot create a front-circuit fault");
328 }
329 for (int guard=0;guard<4;++guard)
330 for (unsigned seed=0;seed<32;++seed)
331 {
333 LampGameFixture game;Viewscreen view;view.gameclass=&game;
334 playerships[0].groundvehicle=guard!=0;
335 game.gui.player[0].frame=guard==1?1:0;
336 ourcockpit.vdat.hullintegrity=guard==2?0:guard==3?-1:127;
337 srand(seed);CrashImpulseSample(view,{0,1,-127});
338 Check(!playerships[0].crashHornFault,
339 "structural horn faults require a ground vehicle, controlled vessel and fresh hull loss");
340 }
341 bool reproduced=false;
342 for (unsigned seed=0;seed<256;++seed)
343 {
345 auto& ship=playerships[0];
346 RiseMath::Matrix pitch,yaw;
349 ship.matrixBase=pitch*yaw;
350 RiseMath::MatrixIdentity(&ship.matrixExterior);
352 Check(ourcockpit.landingLightCount==2,"trace replay reads the actual C-2 lamp mounts");
354 LampGameFixture game;LampWeatherFixture weather;LampMaterialFixture material;
355 game.graphics->g_pEffect=&material;
356 Viewscreen view;view.gameclass=&game;view.ptrWeather=&weather;view.advanceframe=false;
357 game.bus->ProgramTime=10;
358 view.DamageLandingLight(1,0,8.34f,"recorded left contact");
359 Check(ourcockpit.vdat.landing[1]==98,"reproduce the trace's initial left lamp strike");
360 game.bus->ProgramTime+=.085;
361 view.sumofforces={0,1.1492306f,-103.320786f};srand(seed);
362 CrashImpulseSample(view,view.sumofforces);
363 Check(ourcockpit.vdat.landing[0]==127,"front-left crush never transfers damage to the uncontacted right lamp");
365 Check(ourcockpit.vdat.landing[1]==0,"major frame damage destroys the contacted lamp assembly");
367 {
368 reproduced=true;
369 Check(ourcockpit.vdat.windshield==41 && ourcockpit.vdat.landing[1]==0,
370 "recorded 127-to-41 hull loss destroys the struck left lamp");
371 view.UpdateLandingLights(game.bus->ProgramTime);
372 Check(material.count==1 && ourcockpit.landingLightBrightness[1]==0 &&
374 "trace replay removes the crushed left beam and leaves the right beam at full brightness");
375 Check(ourcockpit.vdatChanged && ourcockpit.vdatTime==5,"structural lamp loss queues persistence");
376 }
377 }
378 Check(reproduced,"production crash replay includes the recorded hull damage outcome");
379 for (int guard=0;guard<6;++guard)
380 {
382 LampGameFixture game;Viewscreen view;view.gameclass=&game;
385 game.bus->ProgramTime=10;
386 if (guard!=0) view.DamageLandingLight(1,0,8.34f,"prior contact");
387 const int before=ourcockpit.vdat.landing[1];
388 if (guard==1) game.bus->ProgramTime+=.501;
389 if (guard==2) game.bus->ProgramTime=9;
390 if (guard==3) ourcockpit.landingDamageVehicleId=-1;
391 if (guard==4) game.gui.player[0].frame=1;
392 if (guard==5) {playerships[0].isSimulator=true;view.ClearCollisionEffects();}
393 view.sumofforces={0,1,-127};CrashImpulseSample(view,view.sumofforces);
394 Check(ourcockpit.vdat.landing[1]==before && ourcockpit.vdat.landing[0]==127,
395 "no contact, expired contact, clock reset, pending snapshot, occupant exit and simulator cannot inherit crush");
396 }
398 int health=contact.Apply(127,0,8.34f,0);
399 health=contact.ApplyFrameDamage(health,32,.085);
400 Check(health==63,"moderate frame damage adds only loss beyond the initial strike");
401 for (unsigned frame=6;frame<30;++frame)
402 health=contact.ApplyFrameDamage(health,32,double(frame)/60);
403 Check(health==63,"repeated structural reports do not multiply lamp damage");
404 Check(contact.ApplyFrameDamage(-1,86,.49)==-1 && contact.ApplyFrameDamage(0,86,.49)==0,
405 "absent and destroyed lamps remain unchanged");
406 Check(contact.ApplyFrameDamage(health,86,std::numeric_limits<double>::quiet_NaN())==health,
407 "nonfinite timestamps cannot link contacts to frame damage");
408 std::cout<<"PASS: recorded C-2 corner crush, surviving opposite lamp, beam removal, damage correlation guards and structural horn fault chances\n";
409}
410
411void CollisionCheck(const char* name, bool overlay, float yawAngle)
412{
413 for (unsigned vehicleId : {1u,2u,460u,1000u})
414 for (int side : {-1,0,1})
415 for (float heading : {0.f,.9f})
416 for (unsigned fps : {30u,60u,144u})
417 {
419 auto& ship=playerships[0];
420 ship.vehicleId=static_cast<unsigned short>(vehicleId);
422 RiseMath::Matrix pitch,yaw,toBody,toWorld;
424 RiseMath::MatrixRotationY(&yaw,yawAngle);ship.matrixBase=pitch*yaw;
425 RiseMath::QuaternionRotationYawPitchRoll(&ship.orientation,heading,0,0);
426 RiseMath::MatrixRotationQuaternion(&toBody,&ship.orientation);
427 RiseMath::MatrixInverse(&toWorld,nullptr,&toBody);
429 Check(ourcockpit.landingLightCount==2,"two authored lamp mounts");
430 RiseMath::Vector3 mounts[2];
431 for(unsigned i=0;i<2;++i)
432 RiseMath::Vec3TransformCoord(&mounts[i],&ourcockpit.landingLights[i].origin,&ship.matrixBase);
433 // Determine driver-visible sides through the actual production
434 // projection. Raw body X has the opposite sign after its pi roll.
435 const auto projection=ForwardProjectionFixture();
436 RiseMath::Vector3 projected[2];
437 for(unsigned i=0;i<2;++i) RiseMath::Vec3TransformCoord(&projected[i],&mounts[i],&projection);
438 const unsigned left=projected[0].x<projected[1].x?0:1;
439 if (std::string(name)=="Meshes/C-2 Dasher.daw")
440 Check(left==1,"C-2 trace lamp 1 is the driver's left headlight");
441 Check(std::string(LandingLights::BodySide(mounts[left].x))=="left" &&
442 std::string(LandingLights::BodySide(mounts[1-left].x))=="right",
443 "diagnostic sides match the driver's projected view");
444 const float z=(std::min)(mounts[0].z,mounts[1].z)-.0003f;
445 const float extent=(std::max)(std::abs(mounts[0].x),std::abs(mounts[1].x))*3;
446 const float minX=side<0?0.f:-extent,maxX=side>0?0.f:extent;
447 const float y=(mounts[0].y+mounts[1].y)*.5f;
448 LampBufferFixture buffer;
449 for(auto p : {RiseMath::Vector3(minX,y-.01f,z),RiseMath::Vector3(maxX,y-.01f,z),
450 RiseMath::Vector3(maxX,y+.01f,z),RiseMath::Vector3(minX,y-.01f,z),
451 RiseMath::Vector3(maxX,y+.01f,z),RiseMath::Vector3(minX,y+.01f,z)})
452 {
453 RiseMath::Vec3TransformNormal(&p,&p,&toWorld);
454 buffer.vertices.push_back({p.x,p.y,p.z});
455 }
456 LampZoneFixture zone;zone.VB=&buffer;zone.drawBatches.push_back({0,0,2,0,0,{}});
457 for (const auto& p:buffer.vertices) {zone.bounds.Include(p);zone.drawBatches[0].bounds.Include(p);}
458 // Exact double subtraction on the planet must leave the same local hit.
459 zone.terpos={1000,2000,1000};ship.precisionx=-1000;ship.precisiony=-2000;ship.precisionz=-1000;
460 LampGameFixture game;Viewscreen view;view.gameclass=&game;view.advanceframe=false;
461 buildings city;city.viewscreen=&view;city.buildzones.push_back(zone);
462 RiseMath::Vector3 networkVelocity(0,0,.02f);
463 RiseMath::Vec3TransformNormal(&networkVelocity,&networkVelocity,&toWorld);
464 for(unsigned frame=0;frame<fps/10;++frame)
465 {
466 game.bus->ProgramTime=double(frame)/fps;
467 city.DamageLandingLightContacts(networkVelocity,1.f/fps);
468 ship.precisionx+=double(networkVelocity.x)/fps;
469 ship.precisiony+=double(networkVelocity.y)/fps;
470 ship.precisionz+=double(networkVelocity.z)/fps;
471 }
472 ship.precisionx=-1000;ship.precisiony=-2000;ship.precisionz=-1000;
473 Check(ourcockpit.vdat.landing[left]==(side>0?127:0),"left lamp follows left-front geometry, independent of vehicle ID and animation phase");
474 Check(ourcockpit.vdat.landing[1-left]==(side<0?127:0),"right lamp follows right-front geometry; centered crash can break both");
475 Check(ourcockpit.vdatChanged && ourcockpit.vdatTime==5,"mesh contact queues persistence");
477 view.ClearCollisionEffects();ship.isSimulator=true;
478 city.DamageLandingLightContacts(networkVelocity,1.f/60);
479 view.DamageLandingLight(left,0,20,"simulator diagnostic");
480 Check(ourcockpit.vdat.landing[0]==127 && ourcockpit.vdat.landing[1]==127,"mesh and direct lamp impacts are suppressed in simulator");
481 ship.isSimulator=false;
482 // Exercise the production vehicle-contact path with a small obstacle
483 // directly in front of the left lamp; right lamp is physically clear.
484 const auto sphere=mounts[left]+RiseMath::Vector3(0,0,-.0005f);
485 view.DamageLandingLightsAgainstSphere(sphere,.00025f,{0,0,-.02f},1.f/60);
486 Check(ourcockpit.vdat.landing[left]==0 && ourcockpit.vdat.landing[1-left]==127,
487 "left-front vehicle contact damages only the contacted lamp");
490 city.DamageLandingLightContacts(networkVelocity,1.f/60);
491 Check(ourcockpit.vdat.landing[0]==127 && ourcockpit.vdat.landing[1]==127,"spawn guard blocks mesh damage");
493 city.DamageLandingLightContacts(networkVelocity,1.f/60);
494 Check(ourcockpit.vdat.landing[0]==127,"pending vehicle snapshot cannot damage previous occupant");
495 }
496 std::cout<<"PASS: finite building and vehicle contacts, actual left/right mounts, IDs, heading and simulator guards: "<<name<<'\n';
497}
498
499void ContactGeometryChecks()
500{
501 const RiseMath::Vector3 a(-1,-1,0),b(1,-1,0),c(0,1,0);
502 Check(LandingLights::Sweep{{0,0,.01f},{0,0,-1},.02f}.Triangle(a,b,c)>0,"sweep catches a thin face crossed entirely in one frame");
503 Check(LandingLights::Sweep{{2,0,.01f},{0,0,-1},.02f}.Triangle(a,b,c)==0,"finite face excludes opposite corner");
504 Check(LandingLights::Sweep{{0,0,.01f},{1,0,0},.02f}.Triangle(a,b,c)==0,"tangential motion cannot damage a lamp");
505 Check(LandingLights::Sweep{{0,0,.01f},{0,0,1},.02f}.Triangle(a,b,c)==0,"receding contact cannot damage a lamp");
506 Check(LandingLights::Sweep{{0,0,.01f},{0,0,-1},.001f}.Triangle(a,b,c)==0,"distant face cannot damage a lamp before contact");
507 Check(LandingLights::Sweep{{0,0,.01f},{0,0,-1},.02f}.Triangle(a,a,c)==0,"degenerate face is harmless");
508 Check(LandingLights::Sweep{{0,0,.01f},{0,0,-1},.02f}.Triangle(c,b,a)>0,"triangle winding cannot swap the damaged side");
509
513 ourcockpit.landingLights[0].origin={-.001f,0,-.002f};
514 ourcockpit.landingLights[1].origin={.001f,0,-.002f};
515 LampGameFixture game;Viewscreen view;view.gameclass=&game;view.advanceframe=false;
516 view.DamageLandingLights({0,-1,0},.03f,{0,.01f,0},"normal landing");
517 Check(!ourcockpit.vdatChanged,"normal wheel touchdown keeps lamps clear of terrain");
518 view.DamageLandingLights({0,0,1},.002f,{0,0,-.007f},"slow nose strike");
519 Check(ourcockpit.vdat.landing[0]==107 && ourcockpit.vdat.landing[1]==107,
520 "slow contact dims both equally without the vehicle-ID resilience rule");
522 view.DamageLandingLights({0,0,1},.002f,{0,0,-.014f},"moderate nose strike");
523 Check(ourcockpit.vdat.landing[0]==39 && ourcockpit.vdat.landing[1]==39,
524 "moderate contact retains the established flicker damage stage");
525 const auto health=ourcockpit.vdat.landing[0];
526 view.DamageLandingLights({0,0,1},.002f,{0,0,-.014f},"duplicate solver contact");
527 Check(ourcockpit.vdat.landing[0]==health,"duplicate plane contact cannot double-charge damage");
529 playerships[0].pitch=-10;
530 view.DamageLandingLights({0,-1,0},0,{},"rotating nose");
531 Check(ourcockpit.vdat.landing[0]<127,"nose rotation can damage lamps with stationary CG");
533 view.DamageLandingLights({0,-1,0},0,{},"already broken");
534 Check(ourcockpit.vdat.landing[0]==-1 && ourcockpit.vdat.landing[1]==0,"absent and broken lamps retain their state");
535}
@ EVENT_WINDSHIELD_FAULT
Definition Networking.h:68
@ REF_BUILDING
Definition ServerTypes.h:46
@ REF_ONGROUND
Definition ServerTypes.h:43
bool advanceframe
Definition Viewscreen.h:375
void DamageLandingLight(unsigned lamp, float clearanceKm, float closingMps, const char *cause)
bool hasAnimatedWipers
Definition Viewscreen.h:410
void ApplyCollisionImpulse(const RiseMath::Vector3 &impulseKms)
void DamageLandingLightsAgainstSphere(const RiseMath::Vector3 &centerBody, float radiusKm, const RiseMath::Vector3 &velocityBody, float seconds)
GameClass * gameclass
Definition Viewscreen.h:439
void SetRainProtection(bool enabled)
std::unique_ptr< weather > ptrWeather
Definition Viewscreen.h:434
void SetCrashHornFault(bool enabled)
void UpdateCrashDamage(const RiseMath::Vector3 &frameForces, float seconds)
void DamageLandingLights(const RiseMath::Vector3 &surfaceNormalBody, float planeDistanceKm, const RiseMath::Vector3 &impactVelocityBody, const char *cause)
RiseMath::Vector3 sumofforces
Definition Viewscreen.h:108
CollisionDamage::StructuralEpisode crashDamageEpisode
Definition Viewscreen.h:338
void UpdateLandingLights(double seconds)
Definition framemove.cpp:23
CollisionDamage::Episode controlJoltEpisode
Definition Viewscreen.h:339
void ClearCollisionEffects()
RiseMath::Vector3 structuralImpactImpulse
Definition Viewscreen.h:111
void DamageLandingLightContacts(const RiseMath::Vector3 &velocity, float seconds) const
std::vector< BUILDZONE > buildzones
Definition buildings.h:87
Viewscreen * viewscreen
Definition buildings.h:84
DeathType dead
Definition globals.cpp:37
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
float deathinhibit
Definition globals.cpp:39
Scockpit ourcockpit
Definition globals.cpp:114
#define oneOvergForceKmssC
Definition globals.h:109
float Severity(float x, float y, float z)
int HullDamage(float severity)
float FaultProbability(float severity)
bool TriggersFault(float severity, unsigned roll, unsigned maxRoll)
float HornFaultProbability(float frontalSeverity, int hullBefore, int hullAfter)
float ImpactSeverity(float x, float y, float z, float seconds)
unsigned FromModel(const Effects &effects, std::array< Light, MaxLights > &lights)
const char * BodySide(float x)
float Vec3Length(const Vector3 *a)
Definition ClientMath.h:95
Vector3 * Vec3TransformCoord(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:109
Matrix * MatrixRotationX(Matrix *out, float value)
Definition ClientMath.h:126
Matrix * MatrixRotationQuaternion(Matrix *out, const Quaternion *q)
Definition ClientMath.h:135
Quaternion * QuaternionRotationYawPitchRoll(Quaternion *out, float yaw, float pitch, float roll)
Definition ClientMath.h:169
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:107
Matrix * MatrixRotationY(Matrix *out, float value)
Definition ClientMath.h:127
Matrix * MatrixInverse(Matrix *out, float *determinant, const Matrix *a)
Definition ClientMath.h:118
Matrix * MatrixIdentity(Matrix *out)
Definition ClientMath.h:115
constexpr float HalfPi
Definition ClientMath.h:12
int Apply(int health, float severity)
int Apply(int health, float clearanceKm, float closingMps, double seconds)
int ApplyFrameDamage(int health, int hullLoss, double seconds)
float Triangle(const RiseMath::Vector3 &a, const RiseMath::Vector3 &b, const RiseMath::Vector3 &c) const
Definition LampContact.h:15
char hullintegrity
char windshield
char landing[2]
int landingDamageVehicleId
Definition globals.h:606
SVesselDC vdat
Definition globals.h:664
std::array< float, LandingLights::MaxLights > landingLightBrightness
Definition globals.h:609
std::array< LandingLights::Light, LandingLights::MaxLights > landingLights
Definition globals.h:604
bool vdatChanged
Definition globals.h:665
float vdatTime
Definition globals.h:666
unsigned landingLightCount
Definition globals.h:605
bool rainProtectionEnabled
Definition globals.h:532
unsigned short vehicleId
Definition globals.h:537