From 0a1ab4b51dabe6d809bf1463584ed8a831b97ac0 Mon Sep 17 00:00:00 2001 From: ABelliqueux Date: Mon, 2 Aug 2021 14:03:41 +0200 Subject: [PATCH] Fix actor/prop respawn --- common.mk | 4 ++-- src/graphics.c | 3 ++- src/main.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/common.mk b/common.mk index b184cea..7a26a66 100644 --- a/common.mk +++ b/common.mk @@ -5,8 +5,8 @@ THISDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) SRCS += $(THISDIR)thirdparty/nugget/common/crt0/crt0.s -CPPFLAGS += -I$(THISDIR)thirdparty/nugget/psyq/include -I$(THISDIR)psyq-4_7-converted/include -I$(THISDIR)psyq-4.7-converted-full/include -I$(THISDIR)psyq/include -LDFLAGS += -L$(THISDIR)thirdparty/nugget/psyq/lib -L$(THISDIR)psyq-4_7-converted/lib -L$(THISDIR)psyq-4.7-converted-full/lib -L$(THISDIR)psyq/lib +CPPFLAGS += -I$(THISDIR)thirdparty/nugget/psyq/include -I$(THISDIR)psyq-4_7-converted/include -I$(THISDIR)psyq-4.7-converted-full/include -I$(THISDIR)psyq/include -I$(THISDIR)../psyq/include +LDFLAGS += -L$(THISDIR)thirdparty/nugget/psyq/lib -L$(THISDIR)psyq-4_7-converted/lib -L$(THISDIR)psyq-4.7-converted-full/lib -L$(THISDIR)psyq/lib -L$(THISDIR)../psyq/lib # add support for NDR008's VScode setup CPPFLAGS += -I$(THISDIR)../third_party/psyq/include LDFLAGS += -L$(THISDIR)../third_party/psyq/lib diff --git a/src/graphics.c b/src/graphics.c index 36b6922..1ba3907 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -165,6 +165,7 @@ void set3Prism(POLY_GT3 * poly, MESH * mesh, DRAWENV * draw, char * db, int i, i //~ } // Use Drawenv's Tpages 0,0 and 0,256 setTPage( poly, 2, 0, 0, !(*db)<<8); + //~ setShadeTex(poly, 1); // Use projected coordinates (results from RotAverage...) as UV coords and clamp them to 0-255,0-224 -> 240 - 16 // ( 256 * 4096 ) / 320 ) => 3277 // ( 240 * 4096 ) / 256 ) => 3840 @@ -177,7 +178,7 @@ void set3Prism(POLY_GT3 * poly, MESH * mesh, DRAWENV * draw, char * db, int i, i ((poly->y2 * 3840) >> 12) - (!(*db) << 4) ); // Add color tint - CVECTOR prismCol = {0,70,255, 0}; + CVECTOR prismCol = {0x40,0x40,0xff,0x0}; // work color vectors CVECTOR outCol, outCol1, outCol2; // Find local color from normal and prismCol diff --git a/src/main.c b/src/main.c index 17ac432..04f1616 100644 --- a/src/main.c +++ b/src/main.c @@ -83,7 +83,14 @@ VECTOR fVecActor = {0,0,0,0}; u_long triCount = 0; LEVEL curLvl = {0}; LEVEL * loadLvl; -VECTOR lvlStartPos = {0}; +// Actor start position +VECTOR actorStartPos = {0}; +VECTOR actorStartRot = {0}; +NODE * actorStartNode; +// Prop start position +VECTOR propStartPos = {0}; +VECTOR propStartRot = {0}; +NODE * propStartNode; // Callback function is used for pads void callback(); // variable FPS @@ -154,7 +161,13 @@ int main() { triCount += curLvl.meshes[k]->tmesh->len; } // Save actor starting pos - copyVector(&lvlStartPos, &curLvl.actorPtr->body->position); + copyVector(&actorStartPos, &curLvl.actorPtr->body->position); + copyVector(&actorStartRot, &curLvl.actorPtr->rot); + actorStartNode = curLvl.curNode; + // Save prop starting pos + copyVector(&propStartPos, &curLvl.propPtr->body->position); + copyVector(&propStartRot, &curLvl.propPtr->rot); + propStartNode = curLvl.propPtr->node; // Set camera starting pos setCameraPos(&camera, &curLvl.camPtr->campos->pos, &curLvl.camPtr->campos->rot); @@ -198,6 +211,15 @@ int main() { LoadLevelCD( overlayFile, &load_all_overlays_here ); #endif SwitchLevel( &curLvl, loadLvl); + // Save actor starting pos + copyVector(&actorStartPos, &curLvl.actorPtr->body->position); + copyVector(&actorStartRot, &curLvl.actorPtr->rot); + actorStartNode = curLvl.curNode; + // Save prop starting pos + copyVector(&propStartPos, &curLvl.propPtr->body->position); + copyVector(&propStartRot, &curLvl.propPtr->rot); + propStartNode = curLvl.propPtr->node; + // Set level lighting setLightEnv(draw, curLvl.BGc, curLvl.BKc); levelWas = level; } @@ -208,18 +230,35 @@ int main() { if (time % timediv == 0){ atime ++; } + // Reset player pos + if(curLvl.actorPtr->pos.vy >= 200){ + copyVector(&curLvl.actorPtr->body->position, &actorStartPos ); + copyVector(&curLvl.actorPtr->rot, &actorStartRot ); + curLvl.curNode = actorStartNode; + curLvl.levelPtr = curLvl.curNode->plane; + } + if(curLvl.propPtr->pos.vy >= 200){ + copyVector(&curLvl.propPtr->body->position, &propStartPos ); + copyVector(&curLvl.propPtr->rot, &propStartRot ); + curLvl.propPtr->node = propStartNode; + } // Spatial partitioning if (curLvl.curNode){ for ( int msh = 0; msh < curLvl.curNode->siblings->index; msh ++ ) { - // Actor + // Set Actor node + // If actor is out of plane's X,Z coordinates... if ( !getIntCollision( *curLvl.actorPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vx && !getIntCollision( *curLvl.actorPtr->body , *curLvl.curNode->siblings->list[msh]->plane->body).vz ) { + // if current node is not already pointing to a sibling if ( curLvl.curNode != curLvl.curNode->siblings->list[msh] ) { + // make it point to siblings curLvl.curNode = curLvl.curNode->siblings->list[msh]; + // set current plane curLvl.levelPtr = curLvl.curNode->plane; } } + // Set Prop node if ( !getIntCollision( *curLvl.propPtr->body , *curLvl.curNode->plane->body).vx && !getIntCollision( *curLvl.propPtr->body , *curLvl.curNode->plane->body).vz ) { curLvl.propPtr->node = curLvl.curNode; @@ -266,10 +305,6 @@ int main() { ClearOTagR(otdisc[db], OT2LEN); // Clear Secondary OT ClearOTagR(ot[db], OTLEN); - - if(curLvl.actorPtr->pos.vy >= 200){ - copyVector(&curLvl.actorPtr->body->position, &lvlStartPos ); - } // Set camera according to mode setCameraMode(&curLvl, &camera, &posToActor, &angle, &angleCam, curCamAngle, camMode, &lerping); // Render scene