Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Merge pull request #676 from aap/master
VU0 collision
  • Loading branch information
aap committed Aug 7, 2020
2 parents 456cb01 + abb640c commit 0d7fa6df3c0e8ef53f06e8aa98d73ebc58f8929b

Large diffs are not rendered by default.

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


#include "templates.h" #include "templates.h"
#include "Game.h" // for eLevelName #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. // If you spawn many tanks at once, you will see that collisions of two entity exceeds 32.
#ifdef FIX_BUGS #ifdef FIX_BUGS
@@ -16,6 +19,28 @@ struct CompressedVector
int16 x, y, z; int16 x, y, z;
CVector Get(void) const { return CVector(x, y, z)/128.0f; }; 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; }; 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 #else
float x, y, z; float x, y, z;
CVector Get(void) const { return CVector(x, y, z); }; CVector Get(void) const { return CVector(x, y, z); };
@@ -25,6 +50,7 @@ struct CompressedVector


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


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


struct CColTrianglePlane 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; CVector normal;
float dist; float dist;
uint8 dir; 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 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; } void GetNormal(CVector &n) const { n = normal; }
float CalcPoint(const CVector &v) const { return DotProduct(normal, v) - dist; }; float CalcPoint(const CVector &v) const { return DotProduct(normal, v) - dist; };
#endif
}; };


struct CColPoint struct CColPoint
@@ -91,11 +152,29 @@ struct CColPoint
uint8 surfaceB; uint8 surfaceB;
uint8 pieceB; uint8 pieceB;
float depth; 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 struct CStoredCollPoly
{ {
#ifdef VU_COLLISION
CVuVector verts[3];
#else
CVector verts[3]; CVector verts[3];
#endif
bool valid; bool valid;
}; };


@@ -60,6 +60,11 @@ IsSeeThrough(uint8 surfType)
switch(surfType) switch(surfType)
case SURFACE_GLASS: case SURFACE_GLASS:
case SURFACE_TRANSPARENT_CLOTH: 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 true;
return false; return false;
} }
@@ -89,6 +89,16 @@ typedef uint16_t wchar;
#include <rpskin.h> #include <rpskin.h>
#endif #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)) #define ALIGNPTR(p) (void*)((((uintptr)(void*)p) + sizeof(void*)-1) & ~(sizeof(void*)-1))


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


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

#ifdef MASTER #ifdef MASTER
// only in master builds // only in master builds
#else #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

0 comments on commit 0d7fa6d

Please sign in to comment.