|
resonance 1.0.1
|
PlayStation 2 mesh, which draws through VU1 and the GS. More...
#include <psmesh.h>


Public Member Functions | |
| PsMesh (const HxStr &name) | |
| Construct an empty PlayStation 2 mesh. | |
| virtual | ~PsMesh () |
| int | EmitMultiMeshFaceRun () |
| Upload the first face run of mFacesOwner to VU1 once, for Rnd::PsMultiMesh to draw per instance. | |
| Public Member Functions inherited from Rnd::Mesh | |
| Mesh (const HxStr &name) | |
| Construct an empty mesh that owns its own geometry. | |
| virtual | ~Mesh () |
| void * | operator new (size_t nSize) |
| Allocate a mesh from the tagged heap under the tag "Rnd::Mesh". | |
| void | operator delete (void *pBlock) |
| Release a mesh to the tagged heap under the same tag. | |
| virtual void | DumpText (Dbg &sink) |
| Write the mesh to the engine text sink. | |
| virtual void | Save (Stream &stream) |
| Serialise the mesh. | |
| virtual void | Replace (Object *pFrom, Object *pTo) |
| Replace one object reference with another. | |
| virtual const HxStr & | ClassName () const |
| Return the registered class name, "Mesh". | |
| virtual void | Copy (const Object *pSource, unsigned nFlags) |
| Copy another mesh over this one. | |
| virtual void | Load (Stream &stream) |
| Load the mesh. | |
| void | SetMat (Mat *pMat) |
| Point the mesh at a material. | |
| void | SetTransOwner (Transformable *pOwner) |
| Point the mesh at the transform it draws with. | |
| void | SetNext (Mesh *pNext, float flMinScreen) |
| Set the smallest screen size to draw at, and the mesh to draw in its place below it. | |
| void | SetTrans1Owner (Transformable *pOwner) |
| Point the mesh at its second transform owner. | |
| void | SetTrans2Owner (Transformable *pOwner) |
| Point the mesh at its third transform owner. | |
| Sphere | WorldSphere () |
| Report the bounding sphere in world space. | |
| void | ForwardSync () |
| Dispatch Sync(). | |
| Sphere | BoundingSphere () |
| Compute a bounding sphere of the vertices. | |
| Box | BoundingBox () |
| Compute the bounding box of the vertices. | |
| void | MakeCube (float flHalfSize) |
| Replace the geometry with an axis-aligned cube. | |
| void | ComputeNormals (bool bPositionOnly) |
| Recompute the vertex normals of mVertsOwner from the faces of mFacesOwner. | |
| void | WeldVerts (bool bAverageColors) |
| Merge duplicate vertices and remove the faces and edges the merge makes redundant. | |
| void | SetVertsOwner (Mesh *pOwner) |
| Point the mesh at the mesh whose vertices it draws. | |
| void | SetFacesOwner (Mesh *pOwner) |
| Point the mesh at the mesh whose triangles and edges it draws. | |
| void | SetMaterialChain (Mat *pMat) |
| Set the material of this mesh and of every coarser level of its mNext chain. | |
| void | SetDepthChain (ZMode zMode, ZFunc zFunc) |
| Set the depth mode and comparison of this mesh and of every coarser level of its mNext chain. | |
| void | SetVertexColor (const Color &color) |
| Give every vertex of mVertsOwner one colour and report the change through SyncChanged(). | |
| void | MirrorX () |
| Mirror the mesh across its local x axis by negating the x row of its local transform, and mark the transform dirty. | |
| void | ScaleUniform (float flScale) |
| Scale the three basis rows of the local transform by one factor, and mark the transform dirty. | |
| void | AddQuad (unsigned short nV0, unsigned short nV1, unsigned short nV2, unsigned short nV3) |
| Append the two triangles of a quad to the faces of mFacesOwner. | |
| void | AddQuadStrip (int nRowA, int nRowB, int nCount, int nStep) |
| Append the quads between two rows of vertices with AddQuad(). | |
| int | PrepareDraw (Sphere &worldSphere) |
| Decide whether this mesh draws, and yield its world bounding sphere. | |
| virtual void | FindCollisions (const Segment &ray, std::list< Collision > &collisions) |
| Test a ray against this mesh and append what it strikes to sink. | |
| virtual void | SyncChanged (int nMask) |
| Report which parts of the mesh have changed. | |
| virtual void | SyncAll () |
| Report every part of the mesh as changed. | |
| Public Member Functions inherited from Rnd::Drawable | |
| Drawable () | |
| Construct a visible drawable with no children. | |
| virtual | ~Drawable () |
| Drop this object's references on its children. | |
| void | Draw () |
| Draw this object followed by each of its children. | |
| Drawable * | Parent () |
| Report the drawable that draws this one. | |
| void | AddDraw (Drawable *pDraw, Drawable *pBefore) |
| Insert pDraw into mDraws in front of pBefore. | |
| void | AddDraw (Drawable *pDraw) |
| Insert pDraw at the front of mDraws. | |
| void | RemoveDraw (Drawable *pDraw) |
| Erase pDraw from mDraws. | |
| void | RemoveAllDraws () |
| Empty mDraws, dropping this object's reference on every entry. | |
| void | MoveDraw (Drawable *pDraw, int nSteps) |
| Move pDraw nSteps places later in mDraws, or earlier for a negative count. | |
| virtual void | SetShowing (int nShowing) |
| Set whether this object draws at all. | |
| void | SetShowingRecursive (int nShowing) |
| Set whether this object and every drawable beneath it in mDraws draw at all. | |
| virtual void | SetHighlight (int nHighlight) |
| Set whether this object draws with its highlight treatment. | |
| int | GetHighlight () const |
| Report the highlight flag. | |
| int | GetShowing () const |
| Report the showing flag. | |
| std::list< Drawable * > & | GetDraws () |
| Report the child list. | |
| Public Member Functions inherited from Rnd::Object | |
| Object () | |
| Construct an unnamed object. | |
| Object (const HxStr &name) | |
| Construct an object and register it under name. | |
| virtual | ~Object () |
| Erase the registry entry and release the name buffer. | |
| void | SetName (const HxStr &name) |
| Re-register this object under a different name. | |
| void | AddRef (Object *pReferrer) |
| Register pReferrer as a store of a pointer to this object. | |
| void | RemoveRef (Object *pReferrer) |
| Drop one registration made by AddRef(). | |
| Public Member Functions inherited from Rnd::Transformable | |
| Transformable () | |
| Construct a dirty transformable with identity transforms and no children. | |
| virtual | ~Transformable () |
| Drop this object's references on its children. | |
| void | AddTrans (Transformable *pTrans) |
| Append pTrans to mTransList and mark it dirty. | |
| void | RemoveTrans (Transformable *pTrans) |
| Erase pTrans from mTransList. | |
| void | RemoveAllTranses () |
| Drop this object's reference on every mTransList entry and empty the list. | |
| Transformable * | Parent () |
| Report the transformable that positions this one. | |
| virtual void | SetBillboard (int nBillboard) |
| Set the billboard mode and mark the transform dirty. | |
| virtual int | UpdateWorldXfm (Transformable *pParent, int nForce) |
| Compose mWorldXfm from mLocalXfm and the parent's world transform. | |
| void | SetOrigin (const float *pOrigin) |
| Set the origin row and mark the transform dirty. | |
| float * | GetDrawXfm () |
| Build the transform this object draws with and return it. | |
| Public Member Functions inherited from Rnd::Collideable | |
| Collideable () | |
| Construct a collideable with no children. | |
| virtual | ~Collideable () |
| Drop this object's references on its children. | |
| Collideable * | Parent () |
| Report the collideable that hit-tests this one. | |
| void | AddCollide (Collideable *pCollide) |
| Append pCollide to mCollides. | |
| void | RemoveCollide (Collideable *pCollide) |
| Erase pCollide from mCollides. | |
| virtual void | FindCollisions (const Vector2 &point, std::list< Collision > &collisions) |
| Test a screen point against this object and append what it strikes to collisions. | |
Static Public Member Functions | |
| static void | SelectDepthRegsForPass (const Mesh &mesh, int nPass) |
| Write the GS depth mask and depth test a mesh needs for one material pass. | |
| Static Public Member Functions inherited from Rnd::Drawable | |
| static Drawable * | Find (const HxStr &name) |
| Resolve a registry key to a drawable. | |
Protected Member Functions | |
| virtual int | DrawShowing () |
| Draw the mesh. | |
| virtual void | Sync () |
| Rebuild the draw runs from the face and the edge vectors. | |
| virtual void | AddRefObjects () |
| Restore the references, resynchronise, and clamp every vertex colour to the unit range. | |
| Protected Member Functions inherited from Rnd::Drawable | |
| void | ReleaseDrawsRefs () |
| Drop this object's reference on every mDraws entry without emptying the list. | |
| Protected Member Functions inherited from Rnd::Object | |
| void | ReleaseAllRefs () |
| Tell every referrer to drop its pointer to this object. | |
| Protected Member Functions inherited from Rnd::Transformable | |
| void | AdoptXfmFrom (const Transformable &owner) |
| Adopt the transform of an owner this object is being detached from. | |
| void | ReleaseTransRefs () |
| Drop this object's reference on every mTransList entry without emptying the list. | |
| Protected Member Functions inherited from Rnd::Collideable | |
| void | ReleaseCollidesRefs () |
| Drop this object's reference on every mCollides entry without emptying the list. | |
Additional Inherited Members | |
| Public Types inherited from Rnd::Mesh | |
| enum | ZMode { kZModeDisable = 0 , kZModeZReadOnly = 1 , kZModeZReadWrite = 2 , kZModeWReadOnly = 3 , kZModeWReadWrite = 4 } |
| Depth buffer read and write mode, as the text dump labels the values. More... | |
| enum | ZFunc { kZFuncNever = 0 , kZFuncLess = 1 , kZFuncEqual = 2 , kZFuncLessEqual = 3 , kZFuncGreater = 4 , kZFuncNotEqual = 5 , kZFuncGreaterEqual = 6 , kZFuncAlways = 7 } |
| Depth comparison, as the text dump labels the values. More... | |
| enum | { kSyncAllMask = 0x7f } |
| Every bit SyncAll() reports as changed. More... | |
| enum | { kSyncPoints = 0x01 , kSyncNorms = 0x08 , kSyncColors = 0x10 , kSyncTexs = 0x20 } |
| Bits of the changed-parts mask SyncChanged() receives. More... | |
| enum | { kCopyShareVerts = 0x08 , kCopyShareFaces = 0x10 , kCopyShareTransforms = 0x20 } |
| Bits of the copy flags Copy() tests. More... | |
| enum | { kSerialVersion = 10 } |
| Serial version this build writes, and the highest version it loads. More... | |
| Public Types inherited from Rnd::Transformable | |
| enum | Billboard { kBillboardNone = 0 , kBillboardX = 1 , kBillboardY = 2 , kBillboardZ = 4 , kBillboardXZ = 8 , kBillboardXYZ = 16 , kBillboardSimpleXYZ = 32 , kBillboardLocalRotate = 64 , kBillboardScaleX = 129 , kBillboardScaleY = 130 , kBillboardScaleZ = 132 , kBillboardScaleXZ = 136 , kBillboardScaleXYZ = 144 , kBillboardScaleSimpleXYZ = 160 } |
| Mode mBillboard selects, recovered from the name dumper at 0x004f26f0. More... | |
| Public Attributes inherited from Rnd::Mesh | |
| ZMode | mZMode |
| ZFunc | mZFunc |
| std::vector< MeshVert > | mVerts |
| std::vector< MeshFace > | mFaces |
| std::vector< MeshEdge > | mEdges |
| Mat * | mMat |
| Mesh * | mVertsOwner |
| Mesh * | mFacesOwner |
| float | mMinScreen |
| Mesh * | mNext |
| Public Attributes inherited from Rnd::Drawable | |
| int | mShowing |
| Public Attributes inherited from Rnd::Object | |
| HxStr | mName |
| int | mInternal |
| Public Attributes inherited from Rnd::Transformable | |
| float | mLocalXfm [kXfmRowCount][kXfmRowFloatCount] |
| Transform this object is positioned by, before the parent transform is applied. | |
| float | mWorldXfm [kXfmRowCount][kXfmRowFloatCount] |
| Composed world transform. | |
| int | mDirty |
| Set by every writer of a transform field and cleared once UpdateWorldXfm has recomposed. | |
| Static Public Attributes inherited from Rnd::Mesh | |
| static Mesh *(* | sNew )(const HxStr &name) |
| Creator the registered "Mesh" class builds through. | |
| static HxStr | sClassName |
| Registered class name of Rnd::Mesh, the string "Mesh". | |
| Protected Attributes inherited from Rnd::Mesh | |
| Sphere | mSphere |
| Transformable * | mTransOwner |
| int | mMaxVerts |
| Protected Attributes inherited from Rnd::Object | |
| std::list< Object * > | mRefs |
| Protected Attributes inherited from Rnd::Transformable | |
| float | mOrigin [kXfmRowFloatCount] |
| int | mBillboard |
PlayStation 2 mesh, which draws through VU1 and the GS.
Its RTTI descriptor is at 0x008efd60. It has Rnd::Mesh as its one public base at offset 0. The shared Rnd::Object subobject moves to +0x160 and the factory allocates 0x180 bytes. The two lists below therefore occupy +0x150 through +0x15f.
The subclass supplies the drawing the base class omits. Its Sync() converts the face vector into triangle strips, and AddRefObjects() runs the base fix-up and then clamps every vertex colour. GfxDevice::Init() installs the creator at 0x00606928 over the mesh creator hook, so a mesh loaded from a file is a PsMesh.
Both the constructor body and the destructor body are empty. The constructor at 0x00602600 is the virtual-base and vptr setup, the Rnd::Mesh constructor, and the two list members, and the destructor at 0x00605f48 is the two list members followed by the whole inlined Rnd::Mesh destructor.
Sync() rebuilds the cache on whichever mesh owns the faces rather than on this one. It reads mFacesOwner and works through that mesh's two lists, iterating to the owner's edge vector end at +0x104, so a mesh that shares its geometry also shares the strips built from it. The cache is a bit array allocated in 16-byte groups, one group per eight halfwords of index. Sync() makes no contact with the VU1 microcode; it emits no VIF code and calls no microprogram, so the geometry half of the draw path is recoverable from the MIPS text alone.
The VU1 paths upload geometry rather than register state. Both walk the 16-bit index list, scaling each index by 0x40 to reach an Rnd::MeshVert, and copy the vertex into an UNPACK V4-32 batch whose VIFcode header they reserve ahead of the data and patch once the count is known. The face path closes and reopens that batch every 252 quadwords. Each index list travels separately in its packed form, UNPACK V3-16 for faces and V2-16 for edges, addressed immediately after the vertex data rather than to VU address 0. A face batch enters the microprogram through MSCAL on the first run of the list alone and MSCNT on every run after it, and an edge batch enters through MSCAL 0x1c2 every time.
How much of a vertex reaches VU1 depends on Rnd::g_nStageTextureBound, which Rnd::PsMat::BindStageTexture() sets to 1 when a stage has a texture and 0 when it does not. With a texture, DrawFacesVU1() uploads all four quadwords per vertex under STCYCL 1:1 and calls microprogram address 0; without one it uploads three under STCYCL 4:3, leaving every fourth destination quadword untouched, and calls 0x4ce. The write cycle retains the destination stride of four either way, so the fourth quadword of Rnd::MeshVert is the texture coordinate and the untextured path simply omits it.
Neither path builds a GIFtag itself, and the microprogram cannot store one: the whole .vutext section is 1140 instruction pairs with exactly three literals, all three 255.0f. The GIFtags travel in the setup block EmitFaceVu1Setup() or EmitEdgeVu1Setup() sends to VU address 0 ahead of the runs, built there from the cached material state. The parameter quadword the EE unpacks to VU address 8 for edges and 0x12 for faces holds the vertex count, the primitive count, the microprogram entry EmitFaceVu1Setup() chose for the lighting, and the clipping flag.
Every member of the class is reconstructed. Sync() at 0x00600590 is 793 instructions, of which the strip builder is the part that belongs here and the rest is inlined container work.
The routines between 0x00604da0 and 0x00606678, along with 0x00607170 and 0x00607198, are std::vector, std::list, std::fill_n, and std::find instantiations over unsigned short and over the list element below. All of them are toolchain code, so none is reconstructed here.
| Rnd::PsMesh::PsMesh | ( | const HxStr & | name | ) |
Construct an empty PlayStation 2 mesh.
The body is empty. Rnd::NewPsMesh() is the only construction site.
| name | The object name, passed to the Rnd::Object constructor. |
|
virtual |
|
static |
Write the GS depth mask and depth test a mesh needs for one material pass.
Does nothing while the current camera renders to a texture, and nothing from the third pass onward. DrawShowing() expands the same decision inline for its own passes, and this out-of-line copy exists because Rnd::PsMultiMesh::DrawShowing() in another translation unit is its only caller. Static rather than an instance method because the mesh arrives as an argument, and the body reads only the two Rnd::Mesh depth fields.
| mesh | The mesh whose depth mode and depth function decide the registers. |
| nPass | The material pass index, counted from zero. |
| int Rnd::PsMesh::EmitMultiMeshFaceRun | ( | ) |
Upload the first face run of mFacesOwner to VU1 once, for Rnd::PsMultiMesh to draw per instance.
One UNPACK to VU address 0 carries the projection g_viewProjectXfm, the colour scale, the viewport scale and offset, the texture coordinate transform, a triangle GIFtag without fog, the material colours and vertex colour flags when lighting is on, the parameter quadword, and the run's vertices at four quadwords each. The packed index data follows under its own UNPACK V3-16. Only the first run is sent, whatever the mesh holds.
The routine lies in the Rnd::PsCam unit beside the other VU1 setup emitters. The name is inferred.
|
protectedvirtual |
Draw the mesh.
Rejects the mesh through Mesh::CheckDrawVisible(), which also yields the world bounding sphere, then tests that sphere against the view frustum to decide whether the draw needs clipping. The face pass repeats once per material pass: it reserves GIF space, programs ZBUF_1.ZMSK and TEST_1.ZTST from mZMode and mZFunc, selects the material, and submits either DrawFacesVU1() or the software path fronted by TransformAndLightMeshVerts(). The edge pass repeats the same shape once, always with depth writes masked off and with the material forced to source-alpha blending.
Reimplemented from Rnd::Drawable.
|
protectedvirtual |
Rebuild the draw runs from the face and the edge vectors.
Each run is filled until the next primitive would not fit in the VU1 data memory a run may occupy, then closed and a fresh one started. A vertex already in the run is reused rather than sent twice, which is what makes a run a strip rather than a list of separate triangles. The budget is expressed in VU1 destination quadwords, four for a face vertex and two for an edge vertex, which agrees with the write cycle each VU1 batch programs, plus one per primitive for its indices. A primitive that does not fit is un-done and reprocessed at the head of the next run.
The runs are built on mFacesOwner, so a mesh that shares its geometry shares them.
Reimplemented from Rnd::Mesh.
|
protectedvirtual |
Restore the references, resynchronise, and clamp every vertex colour to the unit range.
Reimplemented from Rnd::Mesh.