resonance 1.0.1
Loading...
Searching...
No Matches
tunnel.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <stddef.h>
5#include <vector>
6
7#include "math/transform.h"
8#include "os/hxstr.h"
9#include "rnd/animatable.h"
10#include "rnd/collideable.h"
11#include "rnd/drawable.h"
12#include "rnd/lodmesh.h"
13#include "rnd/manager.h"
14#include "rnd/raytest.h"
15#include "rnd/tunnelevent.h"
16#include "rnd/tunnelseeker.h"
17
18namespace Rnd {
19class Dbg;
20class Mesh;
21class Object;
22class Stream;
23class TransAnim;
24} // namespace Rnd
25
26namespace Rnd {
27
72class Tunnel : public Drawable, public Animatable, public Collideable {
73public:
84 Tunnel(const HxStr &name);
85
90 virtual ~Tunnel();
91
100 static void *operator new(size_t nSize);
101
109 static void operator delete(void *pBlock);
110
122 virtual void DumpText(Dbg &sink);
123
131 virtual void Save(Stream &stream);
132
141 virtual void Replace(Object *pFrom, Object *pTo);
142
150 virtual const HxStr &ClassName() const;
151
160 virtual void Copy(const Object *pSource, unsigned nFlags);
161
172 virtual void Load(Stream &stream);
173
184 virtual void FindCollisions(const Segment &ray, std::list<Collision> &collisions);
185
192 void Update();
193
205 Mesh *GetRingSection(int nSlice);
206
219 Mesh *GetRingSection(int nRing, int nSlice);
220
234 void LerpRingSectionTangent(int nRing, Vector3 *pOut, float flWeight);
235
251 void GetRingXfm(int nRing, Transform *pOut, float flFrame, float flBlend);
252
271 int nRing, Transform *pOut, float flAnimFrame, float flRingBlend, float flTangentScale);
272
283
296 void AdvanceRing(int nSlice);
297
314 void ApplyMeshLodScreenSizes(const std::vector<float> &screenSizes);
315
329 void AddEvent(Drawable *pObject, float flFrame, int nId, int nUser);
330
344 int MoveEvent(int nId, float flFrame);
345
356 int RemoveEvent(int nId);
357
367 int RemoveEventsInRange(float flFrom, float flTo);
368
379 void ForEachEvent(void (*pfnVisit)(Drawable *pObject, float flFrame, int nId, void *pUser),
380 void *pUser);
381
393 void SetPath(TransAnim *pPath);
394
406 void GetPathXfm(Transform *pOut, float flFrame);
407
415 void SetLaneChangeFrames(float flFrames);
416
425 TunnelSeeker *GetSeeker(unsigned nIndex);
426
436 void ResizeSeekers(unsigned nCount);
437
455 void Configure(float flRingRadius,
456 int nRingCount,
457 int nSliceCount,
458 int nLodCount,
459 float flFloorPull,
460 float flLaneEdgeGap,
461 float flFloorEdgeWeight,
462 float flCellEdgeBlendPerStep);
463
474 int FrameToSlice(float flFrame);
475
488 void SetLaneDividerColor(int nRing, int nSlice, const Color &color);
489
497 void SetLaneFloorColor(const Color &color);
498
499protected:
509 virtual int DrawShowing();
510
520 virtual void SetFrameSelf(float flFrame);
521
522private:
532 void ReleaseRefs();
533
540 void SaveSectionMaterials(Stream &stream);
541
552 void LoadSectionMaterials(Stream &stream);
553
564 void BuildMesh();
565
575 void BuildSliceMeshes();
576
586 void BuildLaneMeshes();
587
596 void BuildCellMeshes();
597
604 void ClearMaterialSectionLists();
605
617 void SetRingSectionFrames();
618
619 // A signed remainder moved into [0, nCount), the form every ring and slice lookup uses.
620 static int WrapIndex(int nIndex, int nCount) {
621 const int nRemainder = nIndex % nCount;
622 return nRemainder > -1 ? nRemainder : nRemainder + nCount;
623 }
624
625 // The cross-section of one lane in the ring frame, a trough of three segments. mPoints[0] and
626 // mPoints[3] are the lane edges, drawn from the ring translations towards the neighbouring
627 // rings by mLaneEdgeGap. mPoints[1] and mPoints[2] blend each edge by mFloorEdgeWeight with the
628 // ring translation pulled towards the axis by mFloorPull. mNormals[i] is the unit normal of the
629 // segment from mPoints[i] to mPoints[i + 1] in the plane of the ring. The record is 0x70 bytes.
630 struct LaneProfile {
631 Vector3 mPoints[4];
632 Vector3 mNormals[3];
633 };
634
635 // No class derives from Rnd::Tunnel. The three seek records read its members as friends, and
636 // Renderer reads the two public counts. The order below is the recovered offset order. The
637 // initial value each member receives from the constructor is part of the evidence about it. A
638 // member with no recorded value is one the constructor does not write, or one it fills through
639 // a container allocation.
640
641 float mRingRadius; // +0x38 Starts at 1.0f. The ring radius BuildMesh() places the rings at.
642
643public:
652
653private:
654 // +0x44 Starts at 2. The level count of every generated chain and the length of
655 // mLodScreenSizes.
656 int mLodCount;
657 float mFloorPull; // +0x48 Starts at 0.1f. The inward pull of the lane floor.
658 // +0x4c Starts at 0.1f. The gap between each lane edge and the ring boundary.
659 float mLaneEdgeGap;
660 float mFloorEdgeWeight; // +0x50 Starts at 0.25f. The weight of the edge in the floor points.
661 float mCellEdgeBlendPerStep; // +0x54 Starts at 0.01f. The cell edge blend per slice step.
662public:
668
669private:
670 // +0x5c Starts at 0, and Copy() copies it where Save() writes mWindowStartSlice. No other
671 // routine reads it. The name is inferred from that position.
672 int mStartSlice;
673
674public:
679
680private:
681 // +0x64 Starts at 480.0f. The tunnel frames a seeker takes to move one ring, which
682 // TunnelSeeker::UpdateLane() divides the elapsed frames by.
683 float mLaneChangeFrames;
684
685public:
691 std::vector<float> mLodScreenSizes;
692
693 // +0x74 Starts at 1. DrawShowing() draws the "_lat" slice meshes only while it is set. The
694 // hx.nolattice script command at 0x0044a080 cycles it with mDrawPanels. Public because that
695 // command writes it with no accessor in the image.
697 // +0x78 Starts at 1. DrawShowing() draws the "_pan" cell meshes and the seeker sections only
698 // while it is set. Public because the hx.nolattice script command writes it with no accessor
699 // in the image.
701
702private:
703 // +0x7c Starts at 99999999, which is a hand-written sentinel in the same style as the
704 // -9999999.0f Rnd::ParticleSys uses for an unset frame. The ring advance at 0x00476fe0 compares
705 // the requested slice against it and writes the same sentinel into the mPlacedSlices entry of
706 // the slice it retires.
707 int mPlacingSlice;
708 // +0x80 Starts at 0. The path frame of the column being placed. The ring advance reloads it
709 // with the slice scaled by mSliceFrames and adds mSliceFrames / mSliceSteps per column.
710 float mPlacingFrame;
711 // +0x84 Starts at 0. The column being placed, which the ring advance counts down from
712 // mSliceSteps.
713 int mPlacingColumn;
714 // +0x88 One slice identifier per slice, which the scroll at 0x00476f48 reads, the ring advance
715 // writes, and SetPath() fills with the 99999999 sentinel.
716 std::vector<int> mPlacedSlices;
717 // +0x94 mCellEdgeBlendPerStep times mSliceSteps, set by BuildMesh(). SetRingSectionFrames()
718 // blends the end vertices of each cell towards their neighbours by it.
719 float mCellEdgeBlend;
720 // +0x98 Starts at 0, and BuildMesh() sets it to the reciprocal of mSliceFrames.
721 float mSlicesPerFrame;
722 // +0x9c Starts at 0, and BuildMesh() sets it to 1920. The frames one slice spans.
723 float mSliceFrames;
724 // +0xa0 The columns of a slice less one, which BuildMesh() sets to 2 to the power of one less
725 // than mLodCount. The ring advance places one column per step.
726 int mSliceSteps;
727 // +0xa4 The mesh grid, one chain per cell, addressed as `slice * mRingCount + ring` by the
728 // lookup at 0x00477388, which then returns the finest level of the chain. The 0xc-byte stride
729 // and the clear at 0x0046acf0 destroying each slot through the chain destructor at 0x00476a80
730 // are what establish the element type.
731 std::vector<LodMesh> mCellChains;
732 // +0xb0 One chain per slice, addressed as `[slice % mSliceCount]` by the lookup at 0x004773e8
733 // on the same evidence as mCellChains.
734 std::vector<LodMesh> mSliceChains;
735 // +0xbc Starts at 0. The first slice of the window the scroll at 0x00476f48 walks, which runs
736 // mSliceCount slices from here.
737 int mWindowStartSlice;
738 // +0xc0 One transform per ring. The tangent interpolation at 0x00477538 reads the translation
739 // row of entry `i` and entry `(i + 1) % mRingCount` and blends the two on the vector unit.
740 std::vector<Transform> mRingXfms;
741 // +0xcc One lane profile per ring, generated by BuildMesh().
742 std::vector<LaneProfile> mLaneProfiles;
743 // +0xd8 Drawables scheduled by frame, kept in ascending frame order by AddEvent(). Update()
744 // walks it taking a reference on every entry, and Copy() assigns it through the list assignment
745 // operator at 0x004727b0.
746 std::list<TunnelEvent> mEvents;
747 // +0xdc Update() calls TunnelSeeker::SetTunnel() once per element, and Copy() assigns the
748 // vector through the assignment operator at 0x004728e8.
749 std::vector<TunnelSeeker> mSeekers;
750
751 friend class TunnelSeekSection;
752 friend class TunnelSeekStrip;
753 friend class TunnelSeeker;
754};
755
767Tunnel *NewTunnel(const HxStr &name);
768
781
789
802
812extern int g_nTunnelLoadVersion;
813
814} // namespace Rnd
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Animatable()
Construct an animatable with no children, no filters, and a zero frame.
Collideable()
Construct a collideable with no children.
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
Drawable()
Construct a visible drawable with no children.
Indexed triangle mesh with one material.
Definition mesh.h:46
Base of every object the renderer can load, resolve by name, and serialise.
Definition object.h:43
Byte stream that every renderer object serialises itself through.
Definition stream.h:31
Animation that drives one transformable from three keyframe channels.
Definition transanim.h:49
Procedural tunnel the game flies the player through.
Definition tunnel.h:72
virtual void SetFrameSelf(float flFrame)
Advance the tunnel to a frame.
virtual void FindCollisions(const Segment &ray, std::list< Collision > &collisions)
Test a ray against the tunnel and append what it strikes to sink.
void ApplyMeshLodScreenSizes(const std::vector< float > &screenSizes)
Replace the level of detail thresholds and apply them to every generated mesh.
virtual const HxStr & ClassName() const
Return the registered class name, "Tunnel".
int mRingCount
Definition tunnel.h:647
virtual void Copy(const Object *pSource, unsigned nFlags)
Copy another tunnel over this one.
friend class TunnelSeekStrip
Definition tunnel.h:752
void ResizeSeekers(unsigned nCount)
Set the number of seekers and attach each one to this tunnel.
void ScrollRings()
Bring every slice of the current window up to the advanced slice.
std::vector< float > mLodScreenSizes
Definition tunnel.h:691
void SetLaneChangeFrames(float flFrames)
Set mLaneChangeFrames.
TransAnim * mPath
Definition tunnel.h:667
void SetPath(TransAnim *pPath)
Replace the path the tunnel follows.
Mesh * GetRingSection(int nRing, int nSlice)
Report the first mesh of one ring of one slice.
void LerpRingSectionTangent(int nRing, Vector3 *pOut, float flWeight)
Blend the translation of one ring transform towards the next.
virtual void Save(Stream &stream)
Serialise the tunnel.
void AddEvent(Drawable *pObject, float flFrame, int nId, int nUser)
Schedule a drawable at a frame.
virtual void Load(Stream &stream)
Load the tunnel.
int mSliceCount
Definition tunnel.h:651
int MoveEvent(int nId, float flFrame)
Move the first event with an identifier to a new frame.
TunnelSeeker * GetSeeker(unsigned nIndex)
Report one seeker.
void GetPathXfm(Transform *pOut, float flFrame)
Evaluate the path at a frame.
void AdvanceRing(int nSlice)
Advance one slice and refresh the section frames.
void Update()
Regenerate the geometry that the current state calls for.
int RemoveEventsInRange(float flFrom, float flTo)
Remove every event whose frame lies in a half open range, dropping each reference.
int RemoveEvent(int nId)
Remove the first event with an identifier and drop its reference.
friend class TunnelSeeker
Definition tunnel.h:753
virtual void Replace(Object *pFrom, Object *pTo)
Replace one object reference with another.
void ForEachEvent(void(*pfnVisit)(Drawable *pObject, float flFrame, int nId, void *pUser), void *pUser)
Call a function once for every event, in frame order.
int mDrawPanels
Definition tunnel.h:700
Mesh * GetRingSection(int nSlice)
Report the first mesh of one slice.
int mDrawLattice
Definition tunnel.h:696
void Configure(float flRingRadius, int nRingCount, int nSliceCount, int nLodCount, float flFloorPull, float flLaneEdgeGap, float flFloorEdgeWeight, float flCellEdgeBlendPerStep)
Set the shape parameters and rebuild the geometry.
void SetLaneDividerColor(int nRing, int nSlice, const Color &color)
Colour the wall between one lane and the next on one slice.
void SetLaneFloorColor(const Color &color)
Colour the floor and the second end cap of every lane on every slice.
virtual void DumpText(Dbg &sink)
Write the tunnel to the engine text sink.
void ProjectSectionToCameraSpace(int nRing, Transform *pOut, float flAnimFrame, float flRingBlend, float flTangentScale)
Build the frame of a point on one ring at a path frame, with the ring pushed outwards.
int FrameToSlice(float flFrame)
Convert a frame to a slice.
void GetRingXfm(int nRing, Transform *pOut, float flFrame, float flBlend)
Build the frame of a point on one ring at a path frame.
int mCulledFarSlices
Definition tunnel.h:678
virtual ~Tunnel()
friend class TunnelSeekSection
Definition tunnel.h:751
virtual int DrawShowing()
Draw the tunnel.
Tunnel(const HxStr &name)
Construct a tunnel with no sections.
The rendering engine.
Definition animhelper.h:3
HxStr g_tunnelClassName
Registered class name of Rnd::Tunnel, the string "Tunnel".
int g_nTunnelLoadVersion
Stream revision of the tunnel currently being read.
Manager TheManager
The renderer's object registry.
void RegisterTunnelClass()
Register the "Tunnel" class with Rnd::Manager.
Definition tunnel.h:799
Object * CreateRegisteredTunnel(const HxStr &name)
Build a tunnel for the registered "Tunnel" class.
Tunnel * NewTunnel(const HxStr &name)
Allocate and construct a tunnel.
Linear colour with four float components.
Definition color.h:10
Line segment a collision query is run along.
Definition collideable.h:22
Affine transform stored as three basis rows and a translation row.
Definition transform.h:14
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:12