Skip to content
This repository has been archived by the owner. It is now read-only.

VU0 collision #676

Merged
merged 1 commit into from Aug 7, 2020
Merged
Changes from all commits
Commits
File filter
Filter file types
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.

Always

Just for now

Large diffs are not rendered by default.

@@ -2,6 +2,9 @@

#include "templates.h"
#include "Game.h" // for eLevelName
#ifdef VU_COLLISION
#include "VuVector.h"
#endif

// If you spawn many tanks at once, you will see that collisions of two entity exceeds 32.
#ifdef FIX_BUGS
@@ -16,6 +19,28 @@ struct CompressedVector
int16 x, y, z;
CVector Get(void) const { return CVector(x, y, z)/128.0f; };
void Set(float x, float y, float z) { this->x = x*128.0f; this->y = y*128.0f; this->z = z*128.0f; };
#ifdef GTA_PS2
void Unpack(uint128 &qword) const {
__asm__ volatile (
"lh $8, 0(%1)\n"
"lh $9, 2(%1)\n"
"lh $10, 4(%1)\n"
"pextlw $10, $8\n"
"pextlw $2, $9, $10\n"
"sq $2, %0\n"
: "=m" (qword)
: "r" (this)
: "$8", "$9", "$10", "$2"
);
}
#else
void Unpack(int32 *qword) const {
qword[0] = x;
qword[1] = y;
qword[2] = z;
qword[3] = 0; // junk
}
#endif
#else
float x, y, z;
CVector Get(void) const { return CVector(x, y, z); };
@@ -25,6 +50,7 @@ struct CompressedVector

struct CColSphere
{
// NB: this has to be compatible with a CVuVector
CVector center;
float radius;
uint8 surface;
@@ -47,6 +73,7 @@ struct CColBox

struct CColLine
{
// NB: this has to be compatible with two CVuVectors
CVector p0;
int pad0;
CVector p1;
@@ -69,6 +96,39 @@ struct CColTriangle

struct CColTrianglePlane
{
#ifdef VU_COLLISION
CompressedVector normal;
int16 dist;

void Set(const CVector &va, const CVector &vb, const CVector &vc);
void Set(const CompressedVector *v, CColTriangle &tri) { Set(v[tri.a].Get(), v[tri.b].Get(), v[tri.c].Get()); }
void GetNormal(CVector &n) const { n.x = normal.x/4096.0f; n.y = normal.y/4096.0f; n.z = normal.z/4096.0f; }
float CalcPoint(const CVector &v) const { CVector n; GetNormal(n); return DotProduct(n, v) - dist/128.0f; };
#ifdef GTA_PS2
void Unpack(uint128 &qword) const {
__asm__ volatile (
"lh $8, 0(%1)\n"
"lh $9, 2(%1)\n"
"lh $10, 4(%1)\n"
"lh $11, 6(%1)\n"
"pextlw $10, $8\n"
"pextlw $11, $9\n"
"pextlw $2, $11, $10\n"
"sq $2, %0\n"
: "=m" (qword)
: "r" (this)
: "$8", "$9", "$10", "$11", "$2"
);
}
#else
void Unpack(int32 *qword) const {
qword[0] = normal.x;
qword[1] = normal.y;
qword[2] = normal.z;
qword[3] = dist;
}
#endif
#else
CVector normal;
float dist;
uint8 dir;
@@ -77,6 +137,7 @@ struct CColTrianglePlane
void Set(const CompressedVector *v, CColTriangle &tri) { Set(v[tri.a].Get(), v[tri.b].Get(), v[tri.c].Get()); }
void GetNormal(CVector &n) const { n = normal; }
float CalcPoint(const CVector &v) const { return DotProduct(normal, v) - dist; };
#endif
};

struct CColPoint
@@ -91,11 +152,29 @@ struct CColPoint
uint8 surfaceB;
uint8 pieceB;
float depth;

void Set(float depth, uint8 surfA, uint8 pieceA, uint8 surfB, uint8 pieceB) {
this->depth = depth;
this->surfaceA = surfA;
this->pieceA = pieceA;
this->surfaceB = surfB;
this->pieceB = pieceB;
}
void Set(uint8 surfA, uint8 pieceA, uint8 surfB, uint8 pieceB) {
this->surfaceA = surfA;
this->pieceA = pieceA;
this->surfaceB = surfB;
this->pieceB = pieceB;
}
};

struct CStoredCollPoly
{
#ifdef VU_COLLISION
CVuVector verts[3];
#else
CVector verts[3];
#endif
bool valid;
};

@@ -60,6 +60,11 @@ IsSeeThrough(uint8 surfType)
switch(surfType)
case SURFACE_GLASS:
case SURFACE_TRANSPARENT_CLOTH:
#if defined(FIX_BUGS) || defined(GTA_PS2)
case SURFACE_METAL_CHAIN_FENCE:
case SURFACE_TRANSPARENT_STONE:
case SURFACE_SCAFFOLD_POLE:
#endif
return true;
return false;
}
@@ -89,6 +89,16 @@ typedef uint16_t wchar;
#include <rpskin.h>
#endif

#ifdef __GNUC__
#define TYPEALIGN(n) __attribute__ ((aligned (n)))
#else
#ifdef _MSC_VER
#define TYPEALIGN(n) __declspec(align(n))
#else
#define TYPEALIGN(n) // unknown compiler...ignore
#endif
#endif

#define ALIGNPTR(p) (void*)((((uintptr)(void*)p) + sizeof(void*)-1) & ~(sizeof(void*)-1))

// PDP-10 like byte functions
@@ -158,7 +158,7 @@ enum Config {
#if defined GTA_PS2
# define GTA_PS2_STUFF
# define RANDOMSPLASH
# define COMPRESSED_COL_VECTORS
# define VU_COLLISION
#elif defined GTA_PC
# define GTA3_1_1_PATCH
//# define GTA3_STEAM_PATCH
@@ -170,6 +170,10 @@ enum Config {
#elif defined GTA_XBOX
#endif

#ifdef VU_COLLISION
#define COMPRESSED_COL_VECTORS // current need compressed vectors in this code
#endif

#ifdef MASTER
// only in master builds
#else
@@ -0,0 +1,21 @@
.align 4
.global Vu0CollisionDmaTag
Vu0CollisionDmaTag:
DMAcnt *
MPG 0, *
.vu
.include "vu0Collision_1.s"
.EndMPG
.EndDmaData
DMAend

.global Vu0Collision2DmaTag
Vu0Collision2DmaTag:
DMAcnt *
MPG 0, *
.vu
.include "vu0Collision_2.s"
.EndMPG
.EndDmaData
DMAend
.end