From 91e8f791b00f8e40917b41c7f92bb0b7f55bec48 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 14:01:52 +0100 Subject: [PATCH 01/24] Removed: Some test printfs I forgot to remove in last commit. --- src/engine/loaders/obj_loader.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index dcebc70..9ee95bb 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -84,7 +84,6 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ /* Vs, VTs and VNs all set */ case 9: { - printf("Case 9\n\n"); fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &coordIndex[0], &normalIndex[0], &vertexIndex[1], &coordIndex[1], &normalIndex[1], @@ -95,7 +94,6 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ /* Loaded only two digits (V, VT) succesfuly. Not setting VN. */ case 2: { - printf("Case 2\n"); fscanf(file, "%d/%d/ %d/%d/ %d/%d/\n", &vertexIndex[0], &coordIndex[0], &vertexIndex[1], &coordIndex[1], @@ -106,7 +104,6 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ /* Only V set. Checking for existance of VT or VN. */ case 1: { - printf("Case 1\n"); /* Check for existance of V/// configuration.. */ newerMatches = fscanf(file, "%d/// %d/// %d///\n",x,x,x); fsetpos(file,&start); From 37703e69d095bcd5cab699b2e89d431aaabe70af Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 14:45:57 +0100 Subject: [PATCH 02/24] Changed: Use VSCode auto-formatter. --- src/engine/loaders/obj_loader.cpp | 193 +++++++++++++++--------------- 1 file changed, 95 insertions(+), 98 deletions(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 9ee95bb..8016f43 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -72,71 +72,71 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ else if (strcmp(lineHeader, "f") == 0) { - int* x; + int *x; fpos_t start; - fgetpos(file,&start); - int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n",x,x,x,x,x,x,x,x,x); - fsetpos(file,&start); - int newerMatches =0; + fgetpos(file, &start); + int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", x, x, x, x, x, x, x, x, x); + fsetpos(file, &start); + int newerMatches = 0; - switch(matches) + switch (matches) { - /* Vs, VTs and VNs all set */ - case 9: + /* Vs, VTs and VNs all set */ + case 9: + { + fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", + &vertexIndex[0], &coordIndex[0], &normalIndex[0], + &vertexIndex[1], &coordIndex[1], &normalIndex[1], + &vertexIndex[2], &coordIndex[2], &normalIndex[2]); + } + break; + /* Loaded only two digits (V, VT) succesfuly. Not setting VN. */ + case 2: + { + fscanf(file, "%d/%d/ %d/%d/ %d/%d/\n", + &vertexIndex[0], &coordIndex[0], + &vertexIndex[1], &coordIndex[1], + &vertexIndex[2], &coordIndex[2]); + } + break; + /* Only V set. Checking for existance of VT or VN. */ + case 1: + { + /* Check for existance of V/// configuration.. */ + newerMatches = fscanf(file, "%d/// %d/// %d///\n", x, x, x); + fsetpos(file, &start); + if (newerMatches == 3) { - fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", - &vertexIndex[0], &coordIndex[0], &normalIndex[0], - &vertexIndex[1], &coordIndex[1], &normalIndex[1], - &vertexIndex[2], &coordIndex[2], &normalIndex[2]); - + /* Configuration confirmed. */ + fscanf(file, "%d/// %d/// %d///\n", &vertexIndex[0], &vertexIndex[1], &vertexIndex[2]); } - break; - /* Loaded only two digits (V, VT) succesfuly. Not setting VN. */ - case 2: + else { - fscanf(file, "%d/%d/ %d/%d/ %d/%d/\n", - &vertexIndex[0], &coordIndex[0], - &vertexIndex[1], &coordIndex[1], - &vertexIndex[2], &coordIndex[2]); - - } - break; - /* Only V set. Checking for existance of VT or VN. */ - case 1: - { - /* Check for existance of V/// configuration.. */ - newerMatches = fscanf(file, "%d/// %d/// %d///\n",x,x,x); - fsetpos(file,&start); - if(newerMatches==3){ - /* Configuration confirmed. */ - fscanf(file, "%d/// %d/// %d///\n",&vertexIndex[0],&vertexIndex[1],&vertexIndex[2]); - - }else + /* Failed, checking configuration V//VN */ + newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", x, x, x, x, x, x); + fsetpos(file, &start); + if (newerMatches == 6) { - /* Failed, checking configuration V//VN */ - newerMatches = fscanf(file, "%d//%d %d//%d %d//%d",x,x,x,x,x,x); - fsetpos(file,&start); - if(newerMatches==6){ - /* Configuration confirmed. */ - newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", - &vertexIndex[0], &normalIndex[0], - &vertexIndex[1], &normalIndex[1], - &vertexIndex[2], &normalIndex[2]); - } - else{ - /*Unknown configuration.*/ - PRINT_ERR("Unknown .obj face for .obj file!"); - printf("Obj file mentioned: \"%s\"\n",path); - } + /* Configuration confirmed. */ + newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", + &vertexIndex[0], &normalIndex[0], + &vertexIndex[1], &normalIndex[1], + &vertexIndex[2], &normalIndex[2]); + } + else + { + /*Unknown configuration.*/ + PRINT_ERR("Unknown .obj face for .obj file!"); + printf("Obj file mentioned: \"%s\"\n", path); } } - default: - PRINT_ERR("Unknown faces format in .obj file!"); - printf(" \"%s\"\n",path); - break; - } -/* if(ferror(file)) + default: + PRINT_ERR("Unknown faces format in .obj file!"); + printf(" \"%s\"\n", path); + break; + } + /* if(ferror(file)) PRINT_ERR("Failed to load .obj file \"%s\"."); else { @@ -147,64 +147,61 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ //if(fscanf }*/ - switch(matches) + switch (matches) { - case 9: + case 9: + { + o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); + + o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); + + o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); + o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); + o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); + faceI += 3; + break; + } + case 2: + { + o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); + + o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); + o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); + + break; + } + case 1: + { + if (newerMatches == 3) + { + o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); + o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); + } + else if (newerMatches == 6) { o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - - o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); - faceI += 3; - break; } - case 2: - { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - - o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); - - break; - } - case 1: - { - if(newerMatches==3) - { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - } - else if(newerMatches==6) - { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - - o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); - o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); - o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); - - } - break; - } - + break; + } } } } else break; - } o_result->calculateBoundingBoxes(); fclose(file); From 18db9875ad0c696693480a3cf564b0977e95fc2a Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 14:48:35 +0100 Subject: [PATCH 03/24] Removed: Redundant printf() calls below PRINT_ERR. --- src/engine/loaders/obj_loader.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 8016f43..0b19b24 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -127,13 +127,11 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ { /*Unknown configuration.*/ PRINT_ERR("Unknown .obj face for .obj file!"); - printf("Obj file mentioned: \"%s\"\n", path); } } } default: PRINT_ERR("Unknown faces format in .obj file!"); - printf(" \"%s\"\n", path); break; } /* if(ferror(file)) From 49713dc145ee15b2cce252bb5199655a89840adb Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 14:51:45 +0100 Subject: [PATCH 04/24] Added: Missing faceI integer increments. --- src/engine/loaders/obj_loader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 0b19b24..2e32eef 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -172,7 +172,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); - + faceI += 2; break; } case 1: @@ -182,6 +182,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); + faceI += 1; } else if (newerMatches == 6) { @@ -192,6 +193,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); + faceI += 2; } break; } From 607c2abc0c0cc41ffb081e27199f640f6b087018 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 15:42:33 +0100 Subject: [PATCH 05/24] Added: Information in mesh_frame on if STs/Normals are present, misc changes for PR #65 code review. --- src/engine/include/models/mesh_frame.hpp | 8 ++++++++ src/engine/loaders/obj_loader.cpp | 16 +++++++--------- src/engine/models/mesh_frame.cpp | 2 ++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index 99ec249..d078bca 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -119,6 +119,9 @@ public: const u8 &areMaterialsAllocated() const { return _areMaterialsAllocated; }; const u8 &isBoundingBoxCalculated() const { return _isBoundingBoxCalculated; }; + const u8 &areSTsPresent() const { return _areSTsPresent; }; + const u8 &areNormalsPresent() const { return _areNormalsPresent; }; + /** Set STs count and allocate memory. */ void allocateSTs(const u32 &t_val); @@ -131,6 +134,9 @@ public: /** Set materials count and allocate memory. */ void allocateMaterials(const u32 &t_val); + void setSTsPresent(const u8 &b) { _areSTsPresent = b; }; + void setNormalsPresent(const u8 &b) { _areNormalsPresent = b; }; + /** * Calculates bounding box (AABB) for frame and for materiaals. * Should be called by data loader, @@ -144,6 +150,8 @@ private: _areVerticesAllocated, _areNormalsAllocated, _areMaterialsAllocated, + _areSTsPresent, + _areNormalsPresent, _isBoundingBoxCalculated; u32 vertexCount, stsCount, normalsCount, materialsCount; MeshMaterial *materials; diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 2e32eef..7b161ef 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -145,9 +145,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ //if(fscanf }*/ - switch (matches) - { - case 9: + if (matches == 9) { o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); @@ -156,14 +154,15 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); + o_result->setSTsPresent(true); o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); + o_result->setNormalsPresent(true); faceI += 3; - break; } - case 2: + else if (matches == 2) { o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); @@ -172,10 +171,10 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); + o_result->setSTsPresent(true); faceI += 2; - break; } - case 1: + else if (matches == 1) { if (newerMatches == 3) { @@ -193,10 +192,9 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); + o_result->setNormalsPresent(true); faceI += 2; } - break; - } } } } diff --git a/src/engine/models/mesh_frame.cpp b/src/engine/models/mesh_frame.cpp index ff9883d..b193577 100644 --- a/src/engine/models/mesh_frame.cpp +++ b/src/engine/models/mesh_frame.cpp @@ -25,6 +25,8 @@ MeshFrame::MeshFrame() _areVerticesAllocated = false; _areNormalsAllocated = false; _areMaterialsAllocated = false; + _areSTsPresent = false; + _areNormalsPresent = false; } MeshFrame::~MeshFrame() From 3c827a407bec29af7186ae9f1acfb4b269af5d84 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 15:49:31 +0100 Subject: [PATCH 06/24] Removed: Commented out code bit. --- src/engine/loaders/obj_loader.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 7b161ef..6ccded8 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -134,17 +134,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ PRINT_ERR("Unknown faces format in .obj file!"); break; } - /* if(ferror(file)) - PRINT_ERR("Failed to load .obj file \"%s\"."); - else - { - int result=0; - char line [128]={'\0'}; - fgets(line,128,file); - - //if(fscanf - }*/ if (matches == 9) { o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); From bd11955fd4f79ca8e43a7dd7051db7a23fc61e62 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 16:09:06 +0100 Subject: [PATCH 07/24] Changed: Comments to fit doxygen standard. --- src/engine/loaders/obj_loader.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 6ccded8..5876e19 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -81,7 +81,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ switch (matches) { - /* Vs, VTs and VNs all set */ + /** Vs, VTs and VNs all set */ case 9: { fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", @@ -90,7 +90,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ &vertexIndex[2], &coordIndex[2], &normalIndex[2]); } break; - /* Loaded only two digits (V, VT) succesfuly. Not setting VN. */ + /** Loaded only two digits (V, VT) succesfuly. Not setting VN. */ case 2: { fscanf(file, "%d/%d/ %d/%d/ %d/%d/\n", @@ -99,25 +99,25 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ &vertexIndex[2], &coordIndex[2]); } break; - /* Only V set. Checking for existance of VT or VN. */ + /** Only V set. Checking for existance of VT or VN. */ case 1: { - /* Check for existance of V/// configuration.. */ + /** Check for existance of V/// configuration.. */ newerMatches = fscanf(file, "%d/// %d/// %d///\n", x, x, x); fsetpos(file, &start); if (newerMatches == 3) { - /* Configuration confirmed. */ + /** Configuration confirmed. */ fscanf(file, "%d/// %d/// %d///\n", &vertexIndex[0], &vertexIndex[1], &vertexIndex[2]); } else { - /* Failed, checking configuration V//VN */ + /** Failed, checking configuration V//VN */ newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", x, x, x, x, x, x); fsetpos(file, &start); if (newerMatches == 6) { - /* Configuration confirmed. */ + /** Configuration confirmed. */ newerMatches = fscanf(file, "%d//%d %d//%d %d//%d", &vertexIndex[0], &normalIndex[0], &vertexIndex[1], &normalIndex[1], @@ -125,7 +125,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ } else { - /*Unknown configuration.*/ + /**Unknown configuration.*/ PRINT_ERR("Unknown .obj face for .obj file!"); } } From 2d1d36ddcc8f751719d8443462a94f450c70e00c Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 16:23:39 +0100 Subject: [PATCH 08/24] Changed: Adjusted the if checks and reduced redundancy. --- src/engine/loaders/obj_loader.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 5876e19..1c017bd 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -135,17 +135,22 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ break; } - if (matches == 9) + if (matches == 9 || matches == 2 || matches == 1) { o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - + } + if (matches == 9 || matches == 2) + { o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); o_result->setSTsPresent(true); + } + if (matches == 9) + { o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); @@ -154,31 +159,16 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ } else if (matches == 2) { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - - o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); - o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); - o_result->setSTsPresent(true); faceI += 2; } else if (matches == 1) { if (newerMatches == 3) { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); faceI += 1; } else if (newerMatches == 6) { - o_result->getMaterial(materialsI).setVertexFace(faceI, vertexIndex[0] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 1, vertexIndex[1] - 1); - o_result->getMaterial(materialsI).setVertexFace(faceI + 2, vertexIndex[2] - 1); - o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); From 249c2431a2ee10d278f078ba07ee5a15df6fe607 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 17:12:56 +0100 Subject: [PATCH 09/24] Fixed: Missing break; in obj faces format recognition. --- src/engine/loaders/obj_loader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 1c017bd..518031f 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -79,6 +79,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ fsetpos(file, &start); int newerMatches = 0; + //return; switch (matches) { /** Vs, VTs and VNs all set */ @@ -129,6 +130,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ PRINT_ERR("Unknown .obj face for .obj file!"); } } + break; } default: PRINT_ERR("Unknown faces format in .obj file!"); From b8d31fc1cc5c80781665c34e7fd8be4feecfd242 Mon Sep 17 00:00:00 2001 From: Foxar Date: Thu, 17 Dec 2020 17:14:14 +0100 Subject: [PATCH 10/24] Removed: Commented out return statement. --- src/engine/loaders/obj_loader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 518031f..082cd3f 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -79,7 +79,6 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ fsetpos(file, &start); int newerMatches = 0; - //return; switch (matches) { /** Vs, VTs and VNs all set */ From 152bc7d6cf8764f4a9112cc7cedeb20a904144da Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 28 Dec 2020 13:39:56 +0100 Subject: [PATCH 11/24] fixed compilation warning --- src/engine/loaders/obj_loader.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index 96e2292..d95962c 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -36,6 +36,8 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ fseek(file, 0, SEEK_SET); u32 verticesI = 0, cordsI = 0, normalsI = 0, faceI = 0, vertexIndex[3], coordIndex[3], normalIndex[3]; s16 materialsI = -1; + Vector3 vector = Vector3(); + Point point = Point(); while (1) { char lineHeader[128]; // read the first word of the line @@ -44,13 +46,11 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ { if (strcmp(lineHeader, "v") == 0) { - Vector3 vector = Vector3(); fscanf(file, "%f %f %f\n", &vector.x, &vector.y, &vector.z); o_result->setVertex(verticesI++, vector * t_scale); } else if (strcmp(lineHeader, "vt") == 0) { - Point point = Point(); fscanf(file, "%f %f\n", &point.x, &point.y); if (t_invertT) point.y = 1.0F - point.y; @@ -58,7 +58,6 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ } else if (strcmp(lineHeader, "vn") == 0) { - Vector3 vector = Vector3(); fscanf(file, "%f %f %f\n", &vector.x, &vector.y, &vector.z); o_result->setNormal(normalsI++, vector); } @@ -71,7 +70,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ } else if (strcmp(lineHeader, "f") == 0) { - int *x = NULL; + int *x = &res; // random assignment, to disable compilation warning fpos_t start; fgetpos(file, &start); int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", x, x, x, x, x, x, x, x, x); From 6e09741d19899a2944f025a759a31ca771287513 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 28 Dec 2020 14:19:51 +0100 Subject: [PATCH 12/24] refactored texturelink, loadFrom(), mesh color --- CHANGELOG.MD | 14 +++++ src/engine/include/models/mesh.hpp | 7 +-- src/engine/include/models/mesh_frame.hpp | 26 ++++++++- src/engine/include/models/mesh_material.hpp | 22 +++++++- src/engine/include/models/texture.hpp | 51 +++++++---------- src/engine/include/models/texture_link.hpp | 9 +-- src/engine/include/modules/gif_sender.hpp | 4 +- .../include/modules/texture_repository.hpp | 19 ++----- src/engine/include/modules/vif_sender.hpp | 4 +- src/engine/models/mesh.cpp | 25 ++++----- src/engine/models/mesh_frame.cpp | 56 ++++++++++++++----- src/engine/models/mesh_material.cpp | 47 +++++++++++++--- src/engine/models/texture.cpp | 13 +---- src/engine/modules/gif_sender.cpp | 22 ++++---- src/engine/modules/renderer.cpp | 20 ++++--- src/engine/modules/texture_repository.cpp | 2 +- src/engine/modules/vif_sender.cpp | 22 ++++---- src/samples/dolphin/dolphin.cpp | 9 +-- src/samples/floors/managers/floor_manager.cpp | 17 +++--- src/samples/floors/ui.cpp | 4 +- 20 files changed, 239 insertions(+), 154 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index a08afdb..7908a61 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.?.?] - 2020-?-? + +### Added +- Id to MeshFrame + +### Changed +- Moved color from mesh to mesh material. +- OBJ Loader refactor +- Logic of loadFrom() + +### Removed +- Removed MeshId from TextureLink, TextureRepository + ## [1.29.1] - 2020-12-27 ### Added - Created libpacket2 in PS2SDK @@ -96,6 +109,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Makefile - Primitive floors sample +[1.?.?]: https://github.com/h4570/tyra/compare/v1.29.1-alpha...v1.?.?-alpha [1.29.1]: https://github.com/h4570/tyra/compare/1.1.0...v1.29.1-alpha [1.1.0]: https://github.com/h4570/tyra/compare/1.0.0...1.1.0 [1.0.0]: https://github.com/h4570/tyra/compare/1.0.0 diff --git a/src/engine/include/models/mesh.hpp b/src/engine/include/models/mesh.hpp index 1f9e7ea..64983fa 100644 --- a/src/engine/include/models/mesh.hpp +++ b/src/engine/include/models/mesh.hpp @@ -16,7 +16,6 @@ #include "./texture.hpp" #include "./mesh_frame.hpp" #include -#include #include #include #include "./anim_state.hpp" @@ -43,7 +42,6 @@ public: * When true, mesh materials are not drawn when they are outside of view frustum. */ u8 shouldBeFrustumCulled; - color_t color; clutbuffer_t clut; lod_t lod; @@ -176,6 +174,8 @@ public: void setAnimSpeed(const float &t_value) { animState.speed = t_value; } + const u8 &areFramesAllocated() const { return _areFramesAllocated; }; + /** * Check if this class loaded mesh data first. * Meshes which use loadFrom() method have false there. @@ -207,9 +207,8 @@ private: AnimState animState; MeshFrame *frames; u32 id, framesCount; - u8 _isMother; + u8 _isMother, _areFramesAllocated; Vector3 calc3Vectors[3]; - void setDefaultColor(); void setDefaultLODAndClut(); }; diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index da83909..e318831 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -35,6 +35,12 @@ public: // Getters // ---- + /** + * Auto generated unique Id. + * Core role of this variable is to select correct texture to draw + */ + const u32 &getId() const { return id; }; + const u32 &getVertexCount() const { return vertexCount; }; const u32 &getSTsCount() const { return stsCount; }; const u32 &getNormalsCount() const { return normalsCount; }; @@ -119,6 +125,18 @@ public: // Other // ---- + /** + * Check if this object is mother. + * Mother = object loaded with loadObj(), loadDff().. + * Have all mother data: vertex, st, etc.. + * Non-mother = object loaded with loadFrom(). + * Have reference copy to mother data: vertex, st, etc.. + * + * When you will destruct mother object, all vertex, st data will be deleted. + * When you will destruct non-mother object, all vertex, st data will be NOT deleted. + */ + const u8 &isMother() const { return _isMother; }; + const u8 &areSTsAllocated() const { return _areSTsAllocated; }; const u8 &areVerticesAllocated() const { return _areVerticesAllocated; }; const u8 &areNormalsAllocated() const { return _areNormalsAllocated; }; @@ -128,6 +146,9 @@ public: const u8 &areSTsPresent() const { return _areSTsPresent; }; const u8 &areNormalsPresent() const { return _areNormalsPresent; }; + /** Create reference copy (non-mother) */ + void copyFrom(MeshFrame *t_refCopy); + /** Set STs count and allocate memory. */ void allocateSTs(const u32 &t_val); @@ -152,14 +173,15 @@ public: private: BoundingBox *boundingBoxObj; - u8 _areSTsAllocated, + u8 _isMother, + _areSTsAllocated, _areVerticesAllocated, _areNormalsAllocated, _areMaterialsAllocated, _areSTsPresent, _areNormalsPresent, _isBoundingBoxCalculated; - u32 vertexCount, stsCount, normalsCount, materialsCount; + u32 vertexCount, stsCount, normalsCount, materialsCount, id; MeshMaterial *materials; Point __attribute__((aligned(16))) * sts; Vector3 __attribute__((aligned(16))) * vertices, *normals; diff --git a/src/engine/include/models/mesh_material.hpp b/src/engine/include/models/mesh_material.hpp index 3ba2621..d708c78 100644 --- a/src/engine/include/models/mesh_material.hpp +++ b/src/engine/include/models/mesh_material.hpp @@ -12,6 +12,7 @@ #define _TYRA_MESH_MATERIAL_ #include +#include #include "bounding_box.hpp" #include "./math/vector3.hpp" #include "./math/plane.hpp" @@ -29,6 +30,8 @@ public: MeshMaterial(); ~MeshMaterial(); + color_t color; + // ---- // Getters // ---- @@ -108,7 +111,23 @@ public: // Other // ---- + /** Create reference copy (non-mother) */ + void copyFrom(MeshMaterial *t_refCopy); + const u8 &isNameSet() const { return _isNameSet; }; + + /** + * Check if this object is mother. + * Mother = object loaded with loadObj(), loadDff().. + * Have all mother data: vertex faces, st faces, etc.. + * Non-mother = object loaded with loadFrom(). + * Have reference copy to mother data: vertex faces, st faces, etc.. + * + * When you will destruct mother object, all faces data will be deleted. + * When you will destruct non-mother object, all faces data will be NOT deleted. + */ + const u8 &isMother() const { return _isMother; }; + const u8 &areFacesAllocated() const { return _areFacesAllocated; }; /** Set faces count and allocate memory. */ @@ -125,10 +144,11 @@ public: u8 isInFrustum(Plane *t_frustumPlanes, const Vector3 &position); private: + void setDefaultColor(); BoundingBox *boundingBoxObj; u32 facesCount, id; u32 *vertexFaces, *stFaces, *normalFaces; - u8 _isNameSet, _areFacesAllocated, _isBoundingBoxCalculated; + u8 _isMother, _isNameSet, _areFacesAllocated, _isBoundingBoxCalculated; char *name; }; diff --git a/src/engine/include/models/texture.hpp b/src/engine/include/models/texture.hpp index 0b9aaaf..470c0b1 100644 --- a/src/engine/include/models/texture.hpp +++ b/src/engine/include/models/texture.hpp @@ -83,21 +83,18 @@ public: /** * Returns index of link. * -1 if not found. + * @param t_id + * For 3D: Mesh material id. + * For 2D: Sprite id. */ - const s32 getIndexOfLink(const u32 &t_meshId, const u32 &t_materialId) const + const s32 getIndexOfLink(const u32 &t_id) const { for (u32 i = 0; i < texLinks.size(); i++) - if (texLinks[i].materialId == t_materialId && texLinks[i].meshOrSpriteId == t_meshId) + if (texLinks[i].id == t_id) return i; return -1; }; - /** - * Returns index of link. - * -1 if not found. - */ - inline const s32 getIndexOfLink(const u32 &t_spriteId) const { return getIndexOfLink(t_spriteId, 0); }; - // ---- // Setters // ---- @@ -144,18 +141,15 @@ public: const u8 &isSizeSet() const { return _isSizeSet; }; - const u8 isLinkedWith(const u32 &t_meshId, const u32 &t_materialId) const + /** + * Check if texture is linked with Mesh/Sprite. + * @param t_id + * For 3D: Mesh material id. + * For 2D: Sprite id. + */ + const u8 isLinkedWith(const u32 &t_id) const { - s32 index = getIndexOfLink(t_meshId, t_materialId); - if (index != -1) - return true; - else - return false; - }; - - const u8 isLinkedWith(const u32 &t_spriteId) const - { - s32 index = getIndexOfLink(t_spriteId); + s32 index = getIndexOfLink(t_id); if (index != -1) return true; else @@ -164,18 +158,15 @@ public: void removeLinkByIndex(const u32 &t_index) { texLinks.erase(texLinks.begin() + t_index); } - void removeLinkBySprite(const u32 &t_spriteId) + /** + * Remove texture link with given Mesh/Sprite. + * @param t_id + * For 3D: Mesh material id. + * For 2D: Sprite id. + */ + void removeLinkById(const u32 &t_id) { - s32 index = getIndexOfLink(t_spriteId); - if (index != -1) - removeLinkByIndex(index); - else - PRINT_ERR("Cant remove link, because it was not found!"); - } - - void removeLinkByMesh(const u32 &t_meshId, const u32 &t_materialId) - { - s32 index = getIndexOfLink(t_meshId, t_materialId); + s32 index = getIndexOfLink(t_id); if (index != -1) removeLinkByIndex(index); else diff --git a/src/engine/include/models/texture_link.hpp b/src/engine/include/models/texture_link.hpp index 75c24b7..687c9c0 100644 --- a/src/engine/include/models/texture_link.hpp +++ b/src/engine/include/models/texture_link.hpp @@ -15,10 +15,11 @@ struct TextureLink { - /** Mesh id or sprite id */ - u32 meshOrSpriteId; - /** Mesh material id or 0 if is sprite */ - u32 materialId; + /** + * For 3D: Mesh material id. + * For 2D: Sprite id. + */ + u32 id; }; #endif diff --git a/src/engine/include/modules/gif_sender.hpp b/src/engine/include/modules/gif_sender.hpp index 0c7646b..baeee9c 100644 --- a/src/engine/include/modules/gif_sender.hpp +++ b/src/engine/include/modules/gif_sender.hpp @@ -34,7 +34,7 @@ public: ~GifSender(); void initPacket(u8 context); - void addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer); + void addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer, color_t *t_color); void addClear(zbuffer_t *t_zBuffer, color_t *t_rgb); void sendPacket(); void sendClear(zbuffer_t *t_zBuffer, color_t *t_rgb); @@ -54,7 +54,7 @@ private: float halfScreenW, halfScreenH; MATRIX localWorld, localScreen, localLight; - void calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount); + void calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount, color_t *t_color); void convertCalcs(u32 t_vertCount, VECTOR *t_vertices, VECTOR *t_colors, VECTOR *t_sts, color_t &t_color); void addCurrentCalcs(u32 &t_vertexCount); }; diff --git a/src/engine/include/modules/texture_repository.hpp b/src/engine/include/modules/texture_repository.hpp index b3e29ac..67cd672 100644 --- a/src/engine/include/modules/texture_repository.hpp +++ b/src/engine/include/modules/texture_repository.hpp @@ -45,23 +45,14 @@ public: /** * Returns single texture. * NULL if not found. + * @param t_id + * For 3D: Mesh material id. + * For 2D: Sprite id. */ - Texture *getBySprite(const u32 &t_spriteId) + Texture *getBySpriteOrMesh(const u32 &t_id) { for (u32 i = 0; i < textures.size(); i++) - if (textures[i]->isLinkedWith(t_spriteId)) - return textures[i]; - return NULL; - } - - /** - * Returns single texture. - * NULL if not found. - */ - Texture *getByMesh(const u32 &t_meshId, const u32 &t_materialId) - { - for (u32 i = 0; i < textures.size(); i++) - if (textures[i]->isLinkedWith(t_meshId, t_materialId)) + if (textures[i]->isLinkedWith(t_id)) return textures[i]; return NULL; } diff --git a/src/engine/include/modules/vif_sender.hpp b/src/engine/include/modules/vif_sender.hpp index c1fdbc6..f1db5fc 100644 --- a/src/engine/include/modules/vif_sender.hpp +++ b/src/engine/include/modules/vif_sender.hpp @@ -29,7 +29,7 @@ public: ~VifSender(); // TODO refactor - void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer); + void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer, color_t *t_color); void calcMatrix(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation); void drawTheSameWithOtherMatrices(const RenderData &t_renderData, Mesh **t_meshes, const u32 &t_skip, const u32 &t_count); void enableWait() { isDrawWaitEnabled = true; } @@ -41,7 +41,7 @@ private: Light *light; void uploadMicroProgram(); void setDoubleBufferAddStaticData(); - void drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_textureBuffer, u8 t_addDrawWait); + void drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_textureBuffer, u8 t_addDrawWait, color_t *t_color); packet2_t *packets[2] __attribute__((aligned(64))); packet2_t *currPacket; /** diff --git a/src/engine/models/mesh.cpp b/src/engine/models/mesh.cpp index 5a47159..2419b9b 100644 --- a/src/engine/models/mesh.cpp +++ b/src/engine/models/mesh.cpp @@ -28,6 +28,7 @@ Mesh::Mesh() shouldBeFrustumCulled = true; shouldBeBackfaceCulled = false; shouldBeLighted = false; + _areFramesAllocated = false; _isMother = false; scale = 1.0F; framesCount = 0; @@ -40,13 +41,12 @@ Mesh::Mesh() animState.isStayFrameSet = false; animState.nextFrame = 0; animState.speed = 0.1F; - setDefaultColor(); setDefaultLODAndClut(); } Mesh::~Mesh() { - if (_isMother) + if (_areFramesAllocated) delete[] frames; } @@ -59,6 +59,7 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, const float &t_scale, con ObjLoader loader = ObjLoader(); framesCount = 1; frames = new MeshFrame[framesCount]; + _areFramesAllocated = true; char *part1 = String::createConcatenated(t_subfolder, t_objFile); // "folder/object" char *finalPath = String::createConcatenated(part1, ".obj"); // "folder/object.obj" loader.load(&frames[0], finalPath, t_scale, t_invertT); @@ -78,6 +79,7 @@ void Mesh::loadObj(char *t_subfolder, char *t_objFile, const float &t_scale, con ObjLoader loader = ObjLoader(); framesCount = t_framesCount; frames = new MeshFrame[framesCount]; + _areFramesAllocated = true; char *part1 = String::createConcatenated(t_subfolder, t_objFile); // "folder/object" char *part2 = String::createConcatenated(part1, "_"); // "folder/object_" for (u32 i = 0; i < framesCount; i++) @@ -105,6 +107,7 @@ void Mesh::loadDff(char *t_subfolder, char *t_dffFile, const float &t_scale, con char *dffPath = String::createConcatenated(part1, ".dff"); framesCount = 1; frames = new MeshFrame[1]; + _areFramesAllocated = true; loader.load(frames, dffPath, t_scale, t_invertT); delete[] part1; delete[] dffPath; @@ -120,8 +123,11 @@ void Mesh::loadMD2(char *t_subfolder, char *t_md2File, const float &t_scale, con void Mesh::loadFrom(const Mesh &t_mesh) { - frames = t_mesh.frames; framesCount = t_mesh.framesCount; + frames = new MeshFrame[framesCount]; + _areFramesAllocated = true; + for (u32 i = 0; i < framesCount; i++) + frames[i].copyFrom(&t_mesh.getFrame(i)); } void Mesh::playAnimation(const u32 &t_startFrame, const u32 &t_endFrame) @@ -254,8 +260,7 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals "r"(nextVerts[vertFaces[faceI]].xyz), "r"(nextVerts[vertFaces[faceI + 1]].xyz), "r"(nextVerts[vertFaces[faceI + 2]].xyz), - "f"(animState.interpolation) - : "$10"); + "f"(animState.interpolation)); } else { @@ -375,16 +380,6 @@ u8 Mesh::isInFrustum(Plane *t_frustumPlanes) return boxResult; } -/** Set's default object color + no transparency */ -void Mesh::setDefaultColor() -{ - color.r = 0x80; - color.g = 0x80; - color.b = 0x80; - color.a = 0x80; - color.q = 1.0F; -} - /** Sets texture level of details settings and CLUT settings */ void Mesh::setDefaultLODAndClut() { diff --git a/src/engine/models/mesh_frame.cpp b/src/engine/models/mesh_frame.cpp index e337cd2..ba96f6f 100644 --- a/src/engine/models/mesh_frame.cpp +++ b/src/engine/models/mesh_frame.cpp @@ -8,6 +8,7 @@ # Sandro Sobczyński */ +#include #include "../include/models/mesh_frame.hpp" #include "../include/utils/debug.hpp" @@ -17,6 +18,7 @@ MeshFrame::MeshFrame() { + id = rand() % 1000000; vertexCount = 0; stsCount = 0; normalsCount = 0; @@ -27,19 +29,23 @@ MeshFrame::MeshFrame() _areMaterialsAllocated = false; _areSTsPresent = false; _areNormalsPresent = false; + _isMother = true; } MeshFrame::~MeshFrame() { - if (_areSTsAllocated) - delete[] sts; - if (_areVerticesAllocated) - delete[] vertices; - if (_areNormalsAllocated) - delete[] normals; + if (_isMother) + { + if (_areSTsAllocated) + delete[] sts; + if (_areVerticesAllocated) + delete[] vertices; + if (_areNormalsAllocated) + delete[] normals; + delete boundingBoxObj; + } if (_areMaterialsAllocated) delete[] materials; - delete boundingBoxObj; } // ---- @@ -96,14 +102,12 @@ void MeshFrame::allocateMaterials(const u32 &t_val) void MeshFrame::calculateBoundingBoxes() { - Vector3 boundingBox[8]; if (!_areVerticesAllocated) - { PRINT_ERR("Can't calculate bounding box, because vertices were not allocated!"); - return; - } + for (u32 i = 0; i < materialsCount; i++) materials->calculateBoundingBox(vertices, vertexCount); + float lowX, lowY, lowZ, hiX, hiY, hiZ; lowX = hiX = vertices[0].x; lowY = hiY = vertices[0].y; @@ -126,6 +130,7 @@ void MeshFrame::calculateBoundingBoxes() hiZ = vertices[i].z; } + Vector3 boundingBox[8]; boundingBox[0].set(lowX, lowY, lowZ); boundingBox[1].set(lowX, lowY, hiZ); boundingBox[2].set(lowX, hiY, lowZ); @@ -137,7 +142,32 @@ void MeshFrame::calculateBoundingBoxes() boundingBox[7].set(hiX, hiY, hiZ); _isBoundingBoxCalculated = true; - //BoundingBox is declared on the heap to prevent any ill-formed default - //constructor instantiated BoundingBox objects. + // BoundingBox is declared on the heap to prevent any ill-formed default + // constructor instantiated BoundingBox objects. boundingBoxObj = new BoundingBox(boundingBox); } + +void MeshFrame::copyFrom(MeshFrame *t_refCopy) +{ + vertexCount = t_refCopy->vertexCount; + stsCount = t_refCopy->stsCount; + normalsCount = t_refCopy->normalsCount; + materialsCount = t_refCopy->materialsCount; + materials = new MeshMaterial[materialsCount]; + for (u32 i = 0; i < materialsCount; i++) + materials[i].copyFrom(&t_refCopy->materials[i]); + _areSTsAllocated = true; + _areVerticesAllocated = true; + _areNormalsAllocated = true; + _areMaterialsAllocated = true; + _areSTsPresent = t_refCopy->_areSTsPresent; + _areNormalsPresent = t_refCopy->_areNormalsPresent; + vertices = t_refCopy->vertices; + sts = t_refCopy->sts; + normals = t_refCopy->normals; + + boundingBoxObj = t_refCopy->boundingBoxObj; + _isBoundingBoxCalculated = true; + + _isMother = false; +} diff --git a/src/engine/models/mesh_material.cpp b/src/engine/models/mesh_material.cpp index d6108da..d5e6efd 100644 --- a/src/engine/models/mesh_material.cpp +++ b/src/engine/models/mesh_material.cpp @@ -25,18 +25,23 @@ MeshMaterial::MeshMaterial() _isNameSet = false; _areFacesAllocated = false; _isBoundingBoxCalculated = false; + _isMother = true; + setDefaultColor(); } MeshMaterial::~MeshMaterial() { - if (_areFacesAllocated) + if (_isMother) { - delete[] vertexFaces; - delete[] stFaces; - delete[] normalFaces; + if (_areFacesAllocated) + { + delete[] vertexFaces; + delete[] stFaces; + delete[] normalFaces; + } + if (_isNameSet) + delete[] name; } - if (_isNameSet) - delete[] name; } // ---- @@ -102,7 +107,6 @@ u8 MeshMaterial::isInFrustum(Plane *t_frustumPlanes, const Vector3 &position) void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount) { - Vector3 boundingBox[8]; float lowX, lowY, lowZ, hiX, hiY, hiZ; lowX = hiX = t_vertices[vertexFaces[0]].x; lowY = hiY = t_vertices[vertexFaces[0]].y; @@ -124,6 +128,8 @@ void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount) if (hiZ < t_vertices[vertexFaces[i]].z) hiZ = t_vertices[vertexFaces[i]].z; } + + Vector3 boundingBox[8]; boundingBox[0].set(lowX, lowY, lowZ); boundingBox[1].set(lowX, lowY, hiZ); boundingBox[2].set(lowX, hiY, lowZ); @@ -139,3 +145,30 @@ void MeshMaterial::calculateBoundingBox(Vector3 *t_vertices, u32 t_vertCount) //constructor instantiated BoundingBox objects. boundingBoxObj = new BoundingBox(boundingBox); } + +void MeshMaterial::copyFrom(MeshMaterial *t_refCopy) +{ + _isNameSet = true; + name = t_refCopy->name; + + _isBoundingBoxCalculated = true; + boundingBoxObj = t_refCopy->boundingBoxObj; + + vertexFaces = t_refCopy->vertexFaces; + stFaces = t_refCopy->stFaces; + normalFaces = t_refCopy->normalFaces; + facesCount = t_refCopy->facesCount; + _areFacesAllocated = true; + + _isMother = false; +} + +/** Set's default object color + no transparency */ +void MeshMaterial::setDefaultColor() +{ + color.r = 0x80; + color.g = 0x80; + color.b = 0x80; + color.a = 0x80; + color.q = 1.0F; +} diff --git a/src/engine/models/texture.cpp b/src/engine/models/texture.cpp index 8bfb78d..1c247b3 100644 --- a/src/engine/models/texture.cpp +++ b/src/engine/models/texture.cpp @@ -82,18 +82,9 @@ void Texture::setWrapSettings(const WrapSettings t_horizontal, const WrapSetting wrapSettings.vertical = t_vertical; } -void Texture::addLink(const u32 &t_meshId, const u32 &t_materialId) +void Texture::addLink(const u32 &t_id) { TextureLink link; - link.materialId = t_materialId; - link.meshOrSpriteId = t_meshId; - texLinks.push_back(link); -} - -void Texture::addLink(const u32 &t_spriteId) -{ - TextureLink link; - link.materialId = 0; - link.meshOrSpriteId = t_spriteId; + link.id = t_id; texLinks.push_back(link); } diff --git a/src/engine/modules/gif_sender.cpp b/src/engine/modules/gif_sender.cpp index ab55fc1..cf0eac5 100644 --- a/src/engine/modules/gif_sender.cpp +++ b/src/engine/modules/gif_sender.cpp @@ -131,16 +131,16 @@ void GifSender::addClear(zbuffer_t *t_zBuffer, color_t *t_rgb) } /** Adds meshes to current packet */ -void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer) +void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer, color_t *t_color) { packet2_chain_open_cnt(currentPacket, 0, 0, 0); packet2_update(currentPacket, draw_texture_sampling(currentPacket->next, 0, &t_mesh.lod)); packet2_update(currentPacket, draw_texturebuffer(currentPacket->next, 0, textureBuffer, &t_mesh.clut)); - packet2_update(currentPacket, draw_prim_start(currentPacket->next, 0, t_renderData->prim, &t_mesh.color)); + packet2_update(currentPacket, draw_prim_start(currentPacket->next, 0, t_renderData->prim, t_color)); xyz = new xyz_t[vertexCount]; rgbaq = new color_t[vertexCount]; st = new texel_t[vertexCount]; - calc3DObject(*t_renderData->projection, t_mesh, vertexCount, vertices, normals, coordinates, t_renderData, t_bulbs, t_bulbsCount); + calc3DObject(*t_renderData->projection, t_mesh, vertexCount, vertices, normals, coordinates, t_renderData, t_bulbs, t_bulbsCount, t_color); addCurrentCalcs(vertexCount); delete[] xyz; delete[] rgbaq; @@ -152,7 +152,7 @@ void GifSender::addObject(RenderData *t_renderData, Mesh &t_mesh, u32 vertexCoun /** Calculates 3D object data into xyz, rgbq, st * After it addCurrentCalcs() can be done */ -void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount) +void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount, color_t *t_color) { VECTOR *colors = new VECTOR[vertexCount]; VECTOR position, rotation; @@ -187,9 +187,9 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount for (u32 i = 0; i < vertexCount; i++) { // Apply the light value to the colour. - colors[i][0] = (t_mesh.color.r * lights[i][0]); - colors[i][1] = (t_mesh.color.g * lights[i][1]); - colors[i][2] = (t_mesh.color.b * lights[i][2]); + colors[i][0] = (t_color->r * lights[i][0]); + colors[i][1] = (t_color->g * lights[i][1]); + colors[i][2] = (t_color->b * lights[i][2]); vector_clamp(colors[i], colors[i], 0.00F, 1.99F); } @@ -201,14 +201,14 @@ void GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, u32 vertexCount else for (u32 i = 0; i < vertexCount; i++) { - colors[i][0] = t_mesh.color.r / 128.0F; - colors[i][1] = t_mesh.color.g / 128.0F; - colors[i][2] = t_mesh.color.b / 128.0F; + colors[i][0] = t_color->r / 128.0F; + colors[i][1] = t_color->g / 128.0F; + colors[i][2] = t_color->b / 128.0F; } calculate_vertices(vertices, vertexCount, vertices, localScreen); - convertCalcs(vertexCount, vertices, colors, coordinates, t_mesh.color); + convertCalcs(vertexCount, vertices, colors, coordinates, *t_color); delete[] colors; } diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index b76c8be..635b611 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -105,7 +105,7 @@ void Renderer::changeTexture(Texture *t_tex) void Renderer::draw(Sprite &t_sprite) { - Texture *texture = textureRepo.getBySprite(t_sprite.getId()); + Texture *texture = textureRepo.getBySpriteOrMesh(t_sprite.getId()); texrect_t rect; float sizeX, sizeY; if (t_sprite.getMode() == MODE_REPEAT) @@ -242,17 +242,18 @@ void Renderer::drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) t_mesh.animate(); for (u32 i = 0; i < t_mesh.getMaterialsCount(); i++) { - if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position)) + MeshMaterial *material = &t_mesh.getMaterial(i); + if (t_mesh.shouldBeFrustumCulled && !material->isInFrustum(renderData.frustumPlanes, t_mesh.position)) return; - Texture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId()); + Texture *tex = textureRepo.getBySpriteOrMesh(material->getId()); changeTexture(tex); gifSender->initPacket(context); - u32 vertCount = t_mesh.getMaterial(i).getFacesCount(); + u32 vertCount = material->getFacesCount(); VECTOR *vertices = new VECTOR[vertCount]; VECTOR *normals = new VECTOR[vertCount]; VECTOR *coordinates = new VECTOR[vertCount]; vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition); - gifSender->addObject(&renderData, t_mesh, vertCount, vertices, normals, coordinates, t_bulbs, t_bulbsCount, &textureBuffer); + gifSender->addObject(&renderData, t_mesh, vertCount, vertices, normals, coordinates, t_bulbs, t_bulbsCount, &textureBuffer, &material->color); gifSender->sendPacket(); delete[] vertices; delete[] normals; @@ -315,16 +316,17 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) t_mesh.animate(); for (u32 i = 0; i < t_mesh.getMaterialsCount(); i++) { - if (t_mesh.shouldBeFrustumCulled && !t_mesh.getMaterial(i).isInFrustum(renderData.frustumPlanes, t_mesh.position)) + MeshMaterial *material = &t_mesh.getMaterial(i); + if (t_mesh.shouldBeFrustumCulled && !material->isInFrustum(renderData.frustumPlanes, t_mesh.position)) return; - u32 vertCount = t_mesh.getMaterial(i).getFacesCount(); + u32 vertCount = material->getFacesCount(); VECTOR vertices[vertCount] __attribute__((aligned(16))); VECTOR normals[vertCount] __attribute__((aligned(16))); VECTOR coordinates[vertCount] __attribute__((aligned(16))); - Texture *tex = textureRepo.getByMesh(t_mesh.getId(), t_mesh.getMaterial(i).getId()); + Texture *tex = textureRepo.getBySpriteOrMesh(material->getId()); changeTexture(tex); vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera); - vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer); + vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer, &material->color); } } diff --git a/src/engine/modules/texture_repository.cpp b/src/engine/modules/texture_repository.cpp index 44112be..2b4f816 100644 --- a/src/engine/modules/texture_repository.cpp +++ b/src/engine/modules/texture_repository.cpp @@ -57,7 +57,7 @@ void TextureRepository::addByMesh(char *t_path, Mesh &mesh, TextureFormat t_form else pngLoader.load(*texture, t_path, mesh.getMaterial(i).getName(), ".png"); texture->setName(mesh.getMaterial(i).getName()); - texture->addLink(mesh.getId(), mesh.getMaterial(i).getId()); + texture->addLink(mesh.getMaterial(i).getId()); textures.push_back(texture); } } diff --git a/src/engine/modules/vif_sender.cpp b/src/engine/modules/vif_sender.cpp index 394c653..88f88f5 100644 --- a/src/engine/modules/vif_sender.cpp +++ b/src/engine/modules/vif_sender.cpp @@ -83,7 +83,7 @@ void VifSender::calcMatrix(const RenderData &t_renderData, const Vector3 &t_posi modelViewProj = *t_renderData.projection * modelViewProj; } -void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer) +void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer, color_t *t_color) { // we have to split 3D object into small parts, because of small memory of VU1 @@ -97,7 +97,7 @@ void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 ver i -= 3; const u32 endI = i + (VU1_PACKAGE_VERTS_PER_BUFF - 1) > vertCount2 ? vertCount2 : i + (VU1_PACKAGE_VERTS_PER_BUFF - 1); - drawVertices(t_mesh, i, endI, vertices, coordinates, t_renderData->prim, textureBuffer, isDrawWaitEnabled ? endI == vertCount2 : false); + drawVertices(t_mesh, i, endI, vertices, coordinates, t_renderData->prim, textureBuffer, isDrawWaitEnabled ? endI == vertCount2 : false, t_color); if (endI == vertCount2) // if there are no more vertices to draw, break { i = vertCount2; @@ -130,7 +130,7 @@ void VifSender::setDoubleBufferAddStaticData() } /** Draw using PATH1 */ -void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_texBuff, u8 t_addDrawWait) +void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_texBuff, u8 t_addDrawWait, color_t *t_color) { const u32 vertCount = t_end - t_start; lastVertCount = vertCount; @@ -143,10 +143,10 @@ void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_ver packet2_utils_gs_add_lod(currPacket, &t_mesh.lod); packet2_utils_gs_add_texbuff_clut(currPacket, t_texBuff, &t_mesh.clut); packet2_utils_gs_add_prim_giftag(currPacket, t_prim, vertCount, DRAW_STQ2_REGLIST, 3, 0); - packet2_add_u32(currPacket, t_mesh.color.r); - packet2_add_u32(currPacket, t_mesh.color.g); - packet2_add_u32(currPacket, t_mesh.color.b); - packet2_add_u32(currPacket, t_mesh.color.a); + packet2_add_u32(currPacket, t_color->r); + packet2_add_u32(currPacket, t_color->g); + packet2_add_u32(currPacket, t_color->b); + packet2_add_u32(currPacket, t_color->a); u32 vif_added_bytes = packet2_utils_vu_close_unpack(currPacket); packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_vertices + t_start, vertCount, true); vif_added_bytes += vertCount; @@ -183,10 +183,10 @@ void VifSender::drawTheSameWithOtherMatrices(const RenderData &t_renderData, Mes packet2_utils_vu_close_unpack(currMPacket); packet2_utils_vu_open_unpack(currMPacket, VU1_RGBA_ADDRESS, true); { - packet2_add_u32(currMPacket, t_meshes[i]->color.r); - packet2_add_u32(currMPacket, t_meshes[i]->color.g); - packet2_add_u32(currMPacket, t_meshes[i]->color.b); - packet2_add_u32(currMPacket, t_meshes[i]->color.a); + packet2_add_u32(currMPacket, t_meshes[i]->getMaterial(0).color.r); + packet2_add_u32(currMPacket, t_meshes[i]->getMaterial(0).color.g); + packet2_add_u32(currMPacket, t_meshes[i]->getMaterial(0).color.b); + packet2_add_u32(currMPacket, t_meshes[i]->getMaterial(0).color.a); } packet2_utils_vu_close_unpack(currMPacket); diff --git a/src/samples/dolphin/dolphin.cpp b/src/samples/dolphin/dolphin.cpp index f016115..be6f6a8 100755 --- a/src/samples/dolphin/dolphin.cpp +++ b/src/samples/dolphin/dolphin.cpp @@ -88,8 +88,7 @@ void Dolphin::onInit() water[i].shouldBeFrustumCulled = true; water[i].shouldBeBackfaceCulled = false; water[i].position.set(WATER_TILE_SCALE * 2.0F * spirals[i].x, WATER_LEVEL, WATER_TILE_SCALE * 2.0F * spirals[i].y); - texRepo->getByMesh(water[0].getId(), water[0].getMaterial(0).getId()) - ->addLink(water[i].getId(), water[i].getMaterial(0).getId()); + texRepo->getBySpriteOrMesh(water[0].getMaterial(0).getId())->addLink(water[i].getMaterial(0).getId()); waterDrawList[i] = &water[i]; } @@ -123,8 +122,7 @@ void Dolphin::onInit() oysters[i].mesh.loadFrom(oysters[0].mesh); oysters[i].mesh.shouldBeBackfaceCulled = false; oysters[i].mesh.shouldBeFrustumCulled = false; - texRepo->getByMesh(oysters[0].mesh.getId(), oysters[0].mesh.getMaterial(0).getId()) - ->addLink(oysters[i].mesh.getId(), oysters[i].mesh.getMaterial(0).getId()); + texRepo->getBySpriteOrMesh(oysters[0].mesh.getMaterial(0).getId())->addLink(oysters[i].mesh.getMaterial(0).getId()); oysters[i].mesh.position.set(i * -100, 5.0F, i * -100); } @@ -141,8 +139,7 @@ void Dolphin::onInit() mines[i].mesh.loadFrom(mines[0].mesh); mines[i].mesh.shouldBeBackfaceCulled = false; mines[i].mesh.shouldBeFrustumCulled = false; - texRepo->getByMesh(mines[0].mesh.getId(), mines[0].mesh.getMaterial(0).getId()) - ->addLink(mines[i].mesh.getId(), mines[i].mesh.getMaterial(0).getId()); + texRepo->getBySpriteOrMesh(mines[0].mesh.getMaterial(0).getId())->addLink(mines[i].mesh.getMaterial(0).getId()); mines[i].mesh.position.set(i * -10, 0.0F, i * -68); } diff --git a/src/samples/floors/managers/floor_manager.cpp b/src/samples/floors/managers/floor_manager.cpp index 2662527..d5f29ae 100644 --- a/src/samples/floors/managers/floor_manager.cpp +++ b/src/samples/floors/managers/floor_manager.cpp @@ -91,8 +91,7 @@ void FloorManager::initFloors() { floors[i].mesh.shouldBeFrustumCulled = true; floors[i].init(floors[0].mesh, spirals[i], i); - texRepo->getByMesh(floors[0].mesh.getId(), floors[0].mesh.getMaterial(0).getId()) - ->addLink(floors[i].mesh.getId(), floors[i].mesh.getMaterial(0).getId()); + texRepo->getBySpriteOrMesh(floors[0].mesh.getMaterial(0).getId())->addLink(floors[i].mesh.getMaterial(0).getId()); meshes[i] = &floors[i].mesh; } PRINT_LOG("Floors initialized!"); @@ -123,18 +122,18 @@ void FloorManager::update(Player &t_player) for (u16 i = 0; i < floorAmount; i++) { floors[i].animate(t_player); - + MeshMaterial *material = &floors[i].mesh.getMaterial(0); if (floors[i].isByAudioTriggered) { - floors[i].mesh.color.r = trigColor.r; - floors[i].mesh.color.g = trigColor.g; - floors[i].mesh.color.b = trigColor.b; + material->color.r = trigColor.r; + material->color.g = trigColor.g; + material->color.b = trigColor.b; } else { - floors[i].mesh.color.r = defaultColor.r; - floors[i].mesh.color.g = defaultColor.g; - floors[i].mesh.color.b = defaultColor.b; + material->color.r = defaultColor.r; + material->color.g = defaultColor.g; + material->color.b = defaultColor.b; } } } diff --git a/src/samples/floors/ui.cpp b/src/samples/floors/ui.cpp index 52c43ff..d398cd9 100644 --- a/src/samples/floors/ui.cpp +++ b/src/samples/floors/ui.cpp @@ -66,13 +66,13 @@ void Ui::update(const Player &player) if (!isTask1Done && player.getJumpCount() >= 10) { isTask1Done = true; - grayCheckboxTex->removeLinkBySprite(task1Checkbox.getId()); + grayCheckboxTex->removeLinkById(task1Checkbox.getId()); blueCheckboxTex->addLink(task1Checkbox.getId()); } if (!isTask2Done && player.getKilledEnemiesCount() >= 10) { isTask2Done = true; - grayCheckboxTex->removeLinkBySprite(task2Checkbox.getId()); + grayCheckboxTex->removeLinkById(task2Checkbox.getId()); blueCheckboxTex->addLink(task2Checkbox.getId()); } } From 1b6e1e94ee5c9d8a9b8fca8f1a47f0e294e4fb35 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 28 Dec 2020 14:23:51 +0100 Subject: [PATCH 13/24] commented out drawByPath3() (obsolete) --- src/engine/include/modules/renderer.hpp | 58 ++++++++++---------- src/engine/modules/renderer.cpp | 72 +++++++++++++------------ 2 files changed, 67 insertions(+), 63 deletions(-) diff --git a/src/engine/include/modules/renderer.hpp b/src/engine/include/modules/renderer.hpp index f86d07b..9066081 100644 --- a/src/engine/include/modules/renderer.hpp +++ b/src/engine/include/modules/renderer.hpp @@ -64,39 +64,39 @@ public: /** 2D draw. */ void draw(Sprite &t_sprite); - /// --- Draw: PATH3 + /// --- OBSOLETE - /** - * WARNING: THIS FUNC CAUSE VISUAL ARTIFACTS! - * Draw many meshes with lighting information. - * Slowest way of rendering (PATH 3, using EE and GIF). - * NOTICE: Animation supported, lighting supported - */ - void drawByPath3(Mesh *t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount); + // /** + // * WARNING: THIS FUNC CAUSE VISUAL ARTIFACTS! + // * Draw many meshes with lighting information. + // * Slowest way of rendering (PATH 3, using EE and GIF). + // * NOTICE: Animation supported, lighting supported + // */ + // void drawByPath3(Mesh *t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount); - /** - * WARNING: THIS FUNC CAUSE VISUAL ARTIFACTS! - * Draw mesh with lighting information. - * Slowest way of rendering (PATH 3, using EE and GIF). - * NOTICE: Animation supported, lighting supported - */ - void drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount); + // /** + // * WARNING: THIS FUNC CAUSE VISUAL ARTIFACTS! + // * Draw mesh with lighting information. + // * Slowest way of rendering (PATH 3, using EE and GIF). + // * NOTICE: Animation supported, lighting supported + // */ + // void drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount); - /** - * WARNING: THIS FUNC CAUSE VISUAL ARTIFACTS! - * Draw many meshes without lighting information. - * Slowest way of rendering (PATH 3, using EE and GIF). - * NOTICE: Animation supported, lighting supported - */ - void drawByPath3(Mesh *t_meshes, u16 t_amount); + // /** + // * WARNING: THIS FUNC CAUSE VISUAL ARTIFACTS! + // * Draw many meshes without lighting information. + // * Slowest way of rendering (PATH 3, using EE and GIF). + // * NOTICE: Animation supported, lighting supported + // */ + // void drawByPath3(Mesh *t_meshes, u16 t_amount); - /** - * WARNING: THIS FUNC CAUSE VISUAL ARTIFACTS! - * Draw mesh without lighting information. - * Slowest way of rendering (PATH 3, using EE and GIF). - * NOTICE: Animation supported, lighting supported - */ - void drawByPath3(Mesh &t_mesh); + // /** + // * WARNING: THIS FUNC CAUSE VISUAL ARTIFACTS! + // * Draw mesh without lighting information. + // * Slowest way of rendering (PATH 3, using EE and GIF). + // * NOTICE: Animation supported, lighting supported + // */ + // void drawByPath3(Mesh &t_mesh); /// --- Draw: PATH1 diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index 635b611..b5c5b70 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -227,43 +227,47 @@ void Renderer::allocateBuffers(int t_screenW, int t_screenH) /// --- Draw: PATH3 -void Renderer::drawByPath3(Mesh *t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount) -{ - for (u16 i = 0; i < t_amount; i++) - drawByPath3(t_meshes[i], t_bulbs, t_bulbsCount); -} +// Obsolete +// void Renderer::drawByPath3(Mesh *t_meshes, u16 t_amount, LightBulb *t_bulbs, u16 t_bulbsCount) +// { +// for (u16 i = 0; i < t_amount; i++) +// drawByPath3(t_meshes[i], t_bulbs, t_bulbsCount); +// } -void Renderer::drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) -{ - beginFrameIfNeeded(); - if (!t_mesh.isDataLoaded()) - PRINT_ERR("Can't draw, because no mesh data was loaded!"); - if (t_mesh.getCurrentAnimationFrame() != t_mesh.getNextAnimationFrame()) - t_mesh.animate(); - for (u32 i = 0; i < t_mesh.getMaterialsCount(); i++) - { - MeshMaterial *material = &t_mesh.getMaterial(i); - if (t_mesh.shouldBeFrustumCulled && !material->isInFrustum(renderData.frustumPlanes, t_mesh.position)) - return; - Texture *tex = textureRepo.getBySpriteOrMesh(material->getId()); - changeTexture(tex); - gifSender->initPacket(context); - u32 vertCount = material->getFacesCount(); - VECTOR *vertices = new VECTOR[vertCount]; - VECTOR *normals = new VECTOR[vertCount]; - VECTOR *coordinates = new VECTOR[vertCount]; - vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition); - gifSender->addObject(&renderData, t_mesh, vertCount, vertices, normals, coordinates, t_bulbs, t_bulbsCount, &textureBuffer, &material->color); - gifSender->sendPacket(); - delete[] vertices; - delete[] normals; - delete[] coordinates; - } -} +// Obsolete +// void Renderer::drawByPath3(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) +// { +// beginFrameIfNeeded(); +// if (!t_mesh.isDataLoaded()) +// PRINT_ERR("Can't draw, because no mesh data was loaded!"); +// if (t_mesh.getCurrentAnimationFrame() != t_mesh.getNextAnimationFrame()) +// t_mesh.animate(); +// for (u32 i = 0; i < t_mesh.getMaterialsCount(); i++) +// { +// MeshMaterial *material = &t_mesh.getMaterial(i); +// if (t_mesh.shouldBeFrustumCulled && !material->isInFrustum(renderData.frustumPlanes, t_mesh.position)) +// return; +// Texture *tex = textureRepo.getBySpriteOrMesh(material->getId()); +// changeTexture(tex); +// gifSender->initPacket(context); +// u32 vertCount = material->getFacesCount(); +// VECTOR *vertices = new VECTOR[vertCount]; +// VECTOR *normals = new VECTOR[vertCount]; +// VECTOR *coordinates = new VECTOR[vertCount]; +// vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition); +// gifSender->addObject(&renderData, t_mesh, vertCount, vertices, normals, coordinates, t_bulbs, t_bulbsCount, &textureBuffer, &material->color); +// gifSender->sendPacket(); +// delete[] vertices; +// delete[] normals; +// delete[] coordinates; +// } +// } -void Renderer::drawByPath3(Mesh *t_meshes, u16 t_amount) { drawByPath3(t_meshes, t_amount, NULL, 0); } +// Obsolete +// void Renderer::drawByPath3(Mesh *t_meshes, u16 t_amount) { drawByPath3(t_meshes, t_amount, NULL, 0); } -void Renderer::drawByPath3(Mesh &t_mesh) { drawByPath3(t_mesh, NULL, 0); } +// Obsolete +// void Renderer::drawByPath3(Mesh &t_mesh) { drawByPath3(t_mesh, NULL, 0); } /// --- Draw: PATH1 From ad43a4bfd38ea4e9873bc0199e5ed39529c660b0 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 28 Dec 2020 16:05:48 +0100 Subject: [PATCH 14/24] moved sts/normals present --- src/engine/include/models/mesh_frame.hpp | 8 ------- src/engine/include/models/mesh_material.hpp | 23 ++++++++++++++++++++- src/engine/loaders/obj_loader.cpp | 7 ++++--- src/engine/models/mesh_frame.cpp | 4 ---- src/engine/models/mesh_material.cpp | 4 ++++ 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/engine/include/models/mesh_frame.hpp b/src/engine/include/models/mesh_frame.hpp index e318831..48cc772 100644 --- a/src/engine/include/models/mesh_frame.hpp +++ b/src/engine/include/models/mesh_frame.hpp @@ -143,9 +143,6 @@ public: const u8 &areMaterialsAllocated() const { return _areMaterialsAllocated; }; const u8 &isBoundingBoxCalculated() const { return _isBoundingBoxCalculated; }; - const u8 &areSTsPresent() const { return _areSTsPresent; }; - const u8 &areNormalsPresent() const { return _areNormalsPresent; }; - /** Create reference copy (non-mother) */ void copyFrom(MeshFrame *t_refCopy); @@ -161,9 +158,6 @@ public: /** Set materials count and allocate memory. */ void allocateMaterials(const u32 &t_val); - void setSTsPresent(const u8 &b) { _areSTsPresent = b; }; - void setNormalsPresent(const u8 &b) { _areNormalsPresent = b; }; - /** * Calculates bounding box (AABB) for frame and for materiaals. * Should be called by data loader, @@ -178,8 +172,6 @@ private: _areVerticesAllocated, _areNormalsAllocated, _areMaterialsAllocated, - _areSTsPresent, - _areNormalsPresent, _isBoundingBoxCalculated; u32 vertexCount, stsCount, normalsCount, materialsCount, id; MeshMaterial *materials; diff --git a/src/engine/include/models/mesh_material.hpp b/src/engine/include/models/mesh_material.hpp index d708c78..03bbeeb 100644 --- a/src/engine/include/models/mesh_material.hpp +++ b/src/engine/include/models/mesh_material.hpp @@ -107,10 +107,26 @@ public: /** Set material name. */ void setName(char *t_val); + /** + * Do not call this method unless you know what you do. + * Should be called by data loader. + */ + void setSTsPresent(const u8 &b) { _areSTsPresent = b; }; + + /** + * Do not call this method unless you know what you do. + * Should be called by data loader. + */ + void setNormalsPresent(const u8 &b) { _areNormalsPresent = b; }; + // ---- // Other // ---- + const u8 &areSTsPresent() const { return _areSTsPresent; }; + + const u8 &areNormalsPresent() const { return _areNormalsPresent; }; + /** Create reference copy (non-mother) */ void copyFrom(MeshMaterial *t_refCopy); @@ -148,7 +164,12 @@ private: BoundingBox *boundingBoxObj; u32 facesCount, id; u32 *vertexFaces, *stFaces, *normalFaces; - u8 _isMother, _isNameSet, _areFacesAllocated, _isBoundingBoxCalculated; + u8 _isMother, + _isNameSet, + _areFacesAllocated, + _isBoundingBoxCalculated, + _areSTsPresent, + _areNormalsPresent; char *name; }; diff --git a/src/engine/loaders/obj_loader.cpp b/src/engine/loaders/obj_loader.cpp index d95962c..7c7662d 100644 --- a/src/engine/loaders/obj_loader.cpp +++ b/src/engine/loaders/obj_loader.cpp @@ -145,7 +145,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ o_result->getMaterial(materialsI).setSTFace(faceI, coordIndex[0] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 1, coordIndex[1] - 1); o_result->getMaterial(materialsI).setSTFace(faceI + 2, coordIndex[2] - 1); - o_result->setSTsPresent(true); + o_result->getMaterial(materialsI).setSTsPresent(true); } if (matches == 9) @@ -153,7 +153,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); - o_result->setNormalsPresent(true); + o_result->getMaterial(materialsI).setNormalsPresent(true); faceI += 3; } else if (matches == 2) @@ -171,7 +171,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ o_result->getMaterial(materialsI).setNormalFace(faceI, normalIndex[0] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 1, normalIndex[1] - 1); o_result->getMaterial(materialsI).setNormalFace(faceI + 2, normalIndex[2] - 1); - o_result->setNormalsPresent(true); + o_result->getMaterial(materialsI).setNormalsPresent(true); faceI += 2; } } @@ -180,6 +180,7 @@ void ObjLoader::load(MeshFrame *o_result, char *t_filename, float t_scale, u8 t_ else break; } + o_result->calculateBoundingBoxes(); fclose(file); delete[] path; diff --git a/src/engine/models/mesh_frame.cpp b/src/engine/models/mesh_frame.cpp index ba96f6f..4fc959f 100644 --- a/src/engine/models/mesh_frame.cpp +++ b/src/engine/models/mesh_frame.cpp @@ -27,8 +27,6 @@ MeshFrame::MeshFrame() _areVerticesAllocated = false; _areNormalsAllocated = false; _areMaterialsAllocated = false; - _areSTsPresent = false; - _areNormalsPresent = false; _isMother = true; } @@ -160,8 +158,6 @@ void MeshFrame::copyFrom(MeshFrame *t_refCopy) _areVerticesAllocated = true; _areNormalsAllocated = true; _areMaterialsAllocated = true; - _areSTsPresent = t_refCopy->_areSTsPresent; - _areNormalsPresent = t_refCopy->_areNormalsPresent; vertices = t_refCopy->vertices; sts = t_refCopy->sts; normals = t_refCopy->normals; diff --git a/src/engine/models/mesh_material.cpp b/src/engine/models/mesh_material.cpp index d5e6efd..b758840 100644 --- a/src/engine/models/mesh_material.cpp +++ b/src/engine/models/mesh_material.cpp @@ -25,6 +25,8 @@ MeshMaterial::MeshMaterial() _isNameSet = false; _areFacesAllocated = false; _isBoundingBoxCalculated = false; + _areSTsPresent = false; + _areNormalsPresent = false; _isMother = true; setDefaultColor(); } @@ -158,6 +160,8 @@ void MeshMaterial::copyFrom(MeshMaterial *t_refCopy) stFaces = t_refCopy->stFaces; normalFaces = t_refCopy->normalFaces; facesCount = t_refCopy->facesCount; + _areSTsPresent = t_refCopy->_areSTsPresent; + _areNormalsPresent = t_refCopy->_areNormalsPresent; _areFacesAllocated = true; _isMother = false; From b053504623be1395f7dd632a8e1aa3c368b449a7 Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 28 Dec 2020 16:06:22 +0100 Subject: [PATCH 15/24] added rgba only option to vu progrm --- src/engine/include/modules/vif_sender.hpp | 5 +- src/engine/modules/renderer.cpp | 2 +- src/engine/modules/vif_sender.cpp | 26 ++- src/engine/vu1_progs/draw3D.vclpp | 73 ++++-- src/engine/vu1_progs/draw3D.vsm | 270 ++++++++++------------ 5 files changed, 191 insertions(+), 185 deletions(-) diff --git a/src/engine/include/modules/vif_sender.hpp b/src/engine/include/modules/vif_sender.hpp index f1db5fc..65020ab 100644 --- a/src/engine/include/modules/vif_sender.hpp +++ b/src/engine/include/modules/vif_sender.hpp @@ -29,7 +29,7 @@ public: ~VifSender(); // TODO refactor - void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer, color_t *t_color); + void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer, color_t *t_color, u8 t_rgbaOnly); void calcMatrix(const RenderData &t_renderData, const Vector3 &t_position, const Vector3 &t_rotation); void drawTheSameWithOtherMatrices(const RenderData &t_renderData, Mesh **t_meshes, const u32 &t_skip, const u32 &t_count); void enableWait() { isDrawWaitEnabled = true; } @@ -37,11 +37,12 @@ public: private: u32 lastVertCount; // needed for drawTheSameWithOtherMatrices() + u8 isLastRGBAOnly; // needed for drawTheSameWithOtherMatrices() u8 isDrawWaitEnabled; Light *light; void uploadMicroProgram(); void setDoubleBufferAddStaticData(); - void drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_textureBuffer, u8 t_addDrawWait, color_t *t_color); + void drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_textureBuffer, u8 t_addDrawWait, color_t *t_color, u8 t_rgbaOnly); packet2_t *packets[2] __attribute__((aligned(64))); packet2_t *currPacket; /** diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index b5c5b70..f554b82 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -330,7 +330,7 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) Texture *tex = textureRepo.getBySpriteOrMesh(material->getId()); changeTexture(tex); vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera); - vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer, &material->color); + vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer, &material->color, !material->areSTsPresent()); } } diff --git a/src/engine/modules/vif_sender.cpp b/src/engine/modules/vif_sender.cpp index 88f88f5..b078fd9 100644 --- a/src/engine/modules/vif_sender.cpp +++ b/src/engine/modules/vif_sender.cpp @@ -83,7 +83,7 @@ void VifSender::calcMatrix(const RenderData &t_renderData, const Vector3 &t_posi modelViewProj = *t_renderData.projection * modelViewProj; } -void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer, color_t *t_color) +void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount, texbuffer_t *textureBuffer, color_t *t_color, u8 t_rgbaOnly) { // we have to split 3D object into small parts, because of small memory of VU1 @@ -97,7 +97,7 @@ void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 ver i -= 3; const u32 endI = i + (VU1_PACKAGE_VERTS_PER_BUFF - 1) > vertCount2 ? vertCount2 : i + (VU1_PACKAGE_VERTS_PER_BUFF - 1); - drawVertices(t_mesh, i, endI, vertices, coordinates, t_renderData->prim, textureBuffer, isDrawWaitEnabled ? endI == vertCount2 : false, t_color); + drawVertices(t_mesh, i, endI, vertices, coordinates, t_renderData->prim, textureBuffer, isDrawWaitEnabled ? endI == vertCount2 : false, t_color, t_rgbaOnly); if (endI == vertCount2) // if there are no more vertices to draw, break { i = vertCount2; @@ -130,28 +130,34 @@ void VifSender::setDoubleBufferAddStaticData() } /** Draw using PATH1 */ -void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_texBuff, u8 t_addDrawWait, color_t *t_color) +void VifSender::drawVertices(Mesh &t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim, texbuffer_t *t_texBuff, u8 t_addDrawWait, color_t *t_color, u8 t_rgbaOnly) { const u32 vertCount = t_end - t_start; lastVertCount = vertCount; + isLastRGBAOnly = t_rgbaOnly; packet2_utils_vu_open_unpack(currPacket, 0, true); packet2_add_data(currPacket, modelViewProj.data, 4); packet2_add_u32(currPacket, t_addDrawWait); // Draw finish? packet2_add_u32(currPacket, vertCount); // Vertex count packet2_add_u32(currPacket, vertCount / 3); // Triangles count - packet2_add_u32(currPacket, 0); // Free + packet2_add_u32(currPacket, t_rgbaOnly); // 0 = STQ+RGBA, 1 = RGBA packet2_utils_gs_add_lod(currPacket, &t_mesh.lod); packet2_utils_gs_add_texbuff_clut(currPacket, t_texBuff, &t_mesh.clut); - packet2_utils_gs_add_prim_giftag(currPacket, t_prim, vertCount, DRAW_STQ2_REGLIST, 3, 0); + if (t_rgbaOnly) + packet2_utils_gs_add_prim_giftag(currPacket, t_prim, vertCount, DRAW_RGBAQ_REGLIST, 2, 0); + else + packet2_utils_gs_add_prim_giftag(currPacket, t_prim, vertCount, DRAW_STQ2_REGLIST, 3, 0); packet2_add_u32(currPacket, t_color->r); packet2_add_u32(currPacket, t_color->g); packet2_add_u32(currPacket, t_color->b); packet2_add_u32(currPacket, t_color->a); u32 vif_added_bytes = packet2_utils_vu_close_unpack(currPacket); packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_vertices + t_start, vertCount, true); - vif_added_bytes += vertCount; - packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_coordinates + t_start, vertCount, true); - vif_added_bytes += vertCount; + if (!t_rgbaOnly) + { + vif_added_bytes += vertCount; + packet2_utils_vu_add_unpack_data(currPacket, vif_added_bytes, t_coordinates + t_start, vertCount, true); + } packet2_utils_vu_add_start_program(currPacket, 0); } @@ -203,7 +209,7 @@ void VifSender::drawTheSameWithOtherMatrices(const RenderData &t_renderData, Mes packet2_add_u32(currMPacket, true); // Draw wait finish? packet2_add_u32(currMPacket, lastVertCount); // Vertex count packet2_add_u32(currMPacket, lastVertCount / 3); // Triangles count - packet2_add_u32(currMPacket, 0); // Free + packet2_add_u32(currMPacket, isLastRGBAOnly); // 0 = STQ+RGBA, 1 = RGBA } packet2_utils_vu_close_unpack(currMPacket); packet2_utils_vu_add_start_program(currMPacket, 0); // and start program @@ -231,7 +237,7 @@ void VifSender::drawTheSameWithOtherMatrices(const RenderData &t_renderData, Mes packet2_add_u32(currMPacket, true); // Draw wait finish? packet2_add_u32(currMPacket, lastVertCount); // Vertex count packet2_add_u32(currMPacket, lastVertCount / 3); // Triangles count - packet2_add_u32(currMPacket, 0); // Free + packet2_add_u32(currMPacket, isLastRGBAOnly); // 0 = STQ+RGBA, 1 = RGBA } packet2_utils_vu_close_unpack(currMPacket); packet2_utils_vu_add_start_program(currMPacket, 0); diff --git a/src/engine/vu1_progs/draw3D.vclpp b/src/engine/vu1_progs/draw3D.vclpp index f50a7be..7cbe82a 100644 --- a/src/engine/vu1_progs/draw3D.vclpp +++ b/src/engine/vu1_progs/draw3D.vclpp @@ -23,6 +23,7 @@ ; TODO ; - Add dynamic lighting (feature) ; - Add --cont + MSCNT instead of alltime MSCAL +; - Split this program into two (RBA/STQ), so we can get better performance #include "/repos/tyra/src/engine/vu1_progs/geometry.inc" #include "/repos/tyra/src/engine/vu1_progs/matrix.inc" @@ -51,6 +52,7 @@ MatrixLoad{ matrix, 0, double_buffer } ilw.x do_draw_finish, 4(double_buffer) ; Add draw finish tag? (sync) ilw.y vertex_count, 4(double_buffer) ; Vertex count ilw.z triangles_count, 4(double_buffer) ; Triangles count +ilw.w rgba_only, 4(double_buffer) ; RGBA (1) or STQ+RGBA (0) lq tex_gif_tag_1, 5(double_buffer) ; GIF tag - texture LOD lq tex_gif_tag_2, 6(double_buffer) ; GIF tag - texture buffer & CLUT lq prim_tag, 7(double_buffer) ; GIF tag - tell GS how many data we will send @@ -70,10 +72,10 @@ sqi gif_set_tag, (dest_address++) ; sqi tex_gif_tag_1, (dest_address++) ; texture LOD tag sqi gif_set_tag, (dest_address++) ; sqi tex_gif_tag_2, (dest_address++) ; texture buffer & CLUT tag -iblez do_draw_finish, kick +iblez do_draw_finish, prim_tag_l sqi gif_set_tag, (dest_address++) ; sqi gif_draw_finish_tag, (dest_address++) ; do draw_finish is needed -kick: +prim_tag_l: sqi prim_tag, (dest_address++) ; prim + tell gs how many data will be ;//////////////////////////////////////////// @@ -87,52 +89,87 @@ iaddiu triangle_counter, vi00, 0 ; Reset counter triangle_loop: --LoopCS 1,3 ;//////////////// VERTEX 1 ////////////////// + vec1: VectorLoad{ vertex, vertex_data, 0 } - VectorLoad{ stq1, stq_data, 0 } MatrixXForm{ xformed_vertex, matrix, vertex } VectorClip{ gs_vertex, xformed_vertex } VectorPerspectiveDivide{ xformed_vertex } VectorAddGSScales{ gs_vertex, xformed_vertex, gs_scale } - VectorTexturePerspectiveCorrection{ pers_stq, stq1 } - VectorStore{ pers_stq, dest_address, 0 } - VectorStore{ rgba, dest_address, 1 } - VectorStore{ gs_vertex, dest_address, 2 } + + ibgtz rgba_only, vec_1_rgba + + vec_1_stq_rgba: + VectorLoad{ stq1, stq_data, 0 } + VectorTexturePerspectiveCorrection{ pers_stq, stq1 } + VectorStore{ pers_stq, dest_address, 0 } + VectorStore{ rgba, dest_address, 1 } + VectorStore{ gs_vertex, dest_address, 2 } + ibeq vi00, vi00, vec2 + + vec_1_rgba: + VectorStore{ rgba, dest_address, 0 } + VectorStore{ gs_vertex, dest_address, 1 } + ;//////////////////////////////////////////// ;//////////////// VERTEX 2 ////////////////// + vec2: VectorLoad{ vertex, vertex_data, 1 } - VectorLoad{ stq2, stq_data, 1 } MatrixXForm{ xformed_vertex, matrix, vertex } VectorClip{ gs_vertex, xformed_vertex } VectorPerspectiveDivide{ xformed_vertex } VectorAddGSScales{ gs_vertex, xformed_vertex, gs_scale } - VectorTexturePerspectiveCorrection{ pers_stq, stq2 } - VectorStore{ pers_stq, dest_address, 3 } - VectorStore{ rgba, dest_address, 4 } - VectorStore{ gs_vertex, dest_address, 5 } + + ibgtz rgba_only, vec_2_rgba + + vec_2_stq_rgba: + VectorLoad{ stq2, stq_data, 1 } + VectorTexturePerspectiveCorrection{ pers_stq, stq2 } + VectorStore{ pers_stq, dest_address, 3 } + VectorStore{ rgba, dest_address, 4 } + VectorStore{ gs_vertex, dest_address, 5 } + ibeq vi00, vi00, vec3 + + vec_2_rgba: + VectorStore{ rgba, dest_address, 2 } + VectorStore{ gs_vertex, dest_address, 3 } + ;//////////////////////////////////////////// ;//////////////// VERTEX 3 ////////////////// + vec3: VectorLoad{ vertex, vertex_data, 2 } - VectorLoad{ stq3, stq_data, 2 } MatrixXForm{ xformed_vertex, matrix, vertex } VectorClip{ gs_vertex, xformed_vertex } VectorPerspectiveDivide{ xformed_vertex } VectorAddGSScales{ gs_vertex, xformed_vertex, gs_scale } - VectorTexturePerspectiveCorrection{ pers_stq, stq3 } - VectorStore{ pers_stq, dest_address, 6 } - VectorStore{ rgba, dest_address, 7 } fcand vi01, 0x03FFFF iaddiu new_adc_bit, vi01, 0x7FFF mfir.w gs_vertex, new_adc_bit - VectorStore{ gs_vertex, dest_address, 8 } + + ibgtz rgba_only, vec_3_rgba + + vec_3_stq_rgba: + VectorLoad{ stq3, stq_data, 2 } + VectorTexturePerspectiveCorrection{ pers_stq, stq3 } + VectorStore{ pers_stq, dest_address, 6 } + VectorStore{ rgba, dest_address, 7 } + VectorStore{ gs_vertex, dest_address, 8 } + iaddiu dest_address, dest_address, 9 // Loop control + ibeq vi00, vi00, loop_ctrl + + vec_3_rgba: + VectorStore{ rgba, dest_address, 4 } + VectorStore{ gs_vertex, dest_address, 5 } + iaddiu dest_address, dest_address, 6 // Loop control + ;//////////////////////////////////////////// ;////////////// LOOP CONTROL //////////////// + loop_ctrl: iaddiu vertex_data, vertex_data, 3 iaddiu stq_data, stq_data, 3 - iaddiu dest_address, dest_address, 9 iaddiu triangle_counter, triangle_counter, 1 // Incrementing this // by other value than 1 is causing HUGE problems, but.. why? diff --git a/src/engine/vu1_progs/draw3D.vsm b/src/engine/vu1_progs/draw3D.vsm index e312e7e..b1c0afa 100644 --- a/src/engine/vu1_progs/draw3D.vsm +++ b/src/engine/vu1_progs/draw3D.vsm @@ -3,10 +3,6 @@ ;-----VCL CODE------------ ;------------------------- ;------------------------- -; === __LP__ EXPL_draw3D_vcl_triangle_loop__MAIN_LOOP: -; === hDown : optimal=30 clid=0 mlid=2 size=(31) -; === dUp : optimal=30 clid=0 mlid=2 size=(31) -; === another : optimal=30 clid=0 mlid=2 size=(31) ; ================================================= ; flowMon::Emit() vcl 1.4beta7 produced this code: .vu @@ -15,171 +11,137 @@ .global VU1Draw3D_CodeEnd VU1Draw3D_CodeStart: __v_draw3D_vcl_4: -; _LNOPT_w=[ normal2 ] 26 [26 0] 26 [__v_draw3D_vcl_4] - NOP xtop VI05 +; _LNOPT_w=[ normal2 ] 27 [27 0] 27 [__v_draw3D_vcl_4] + NOP xtop VI06 NOP lq VF02,1(VI00) NOP lq VF01,0(VI00) - NOP ilw.x VI01,4(VI05) - NOP ilw.y VI07,4(VI05) - NOP lq VF03,0(VI05) - NOP lq VF08,5(VI05) - NOP lq VF10,6(VI05) - NOP lq VF04,1(VI05) - NOP lq VF05,2(VI05) - NOP iaddiu VI03,VI05,0x00000009 - NOP iadd VI04,VI03,VI07 - NOP lq VF06,3(VI05) - NOP iadd VI06,VI04,VI07 + NOP ilw.x VI01,4(VI06) + NOP ilw.y VI08,4(VI06) + NOP lq VF03,0(VI06) + NOP lq VF04,1(VI06) + NOP lq VF08,5(VI06) + NOP lq VF10,6(VI06) + NOP lq VF05,2(VI06) + NOP lq VF06,3(VI06) + NOP iaddiu VI04,VI06,0x00000009 + NOP iadd VI05,VI04,VI08 + NOP ilw.z VI02,4(VI06) + NOP iadd VI07,VI05,VI08 NOP loi 0x44fff000 - NOP ilw.z VI02,4(VI05) - NOP lq VF07,7(VI05) - NOP sqi VF02,(VI06++) - NOP sqi VF08,(VI06++) - NOP sqi VF02,(VI06++) - NOP lq VF08,8(VI05) - NOP iadd VI05,VI04,VI07 + NOP ilw.w VI03,4(VI06) + NOP lq VF07,7(VI06) + NOP sqi VF02,(VI07++) + NOP sqi VF08,(VI07++) + NOP sqi VF02,(VI07++) + NOP lq VF08,8(VI06) + NOP iadd VI06,VI05,VI08 addi.xy VF09,VF00,I loi 0x492aaaaa NOP fcset 0 - NOP iblez VI01,kick - addi.z VF09,VF00,I sqi VF10,(VI06++) + NOP iblez VI01,prim_tag_l + addi.z VF09,VF00,I sqi VF10,(VI07++) ; _LNOPT_w=[ normal2 ] 2 [2 0] 2 [__v_draw3D_vcl_5] - NOP sqi VF02,(VI06++) - NOP sqi VF01,(VI06++) -kick: -; _LNOPT_w=[ normal2 ] 27 [27 0] 32 [kick] - NOP sqi VF07,(VI06++) - NOP lq VF07,0(VI03) - mulax ACC,VF03,VF07x lq VF14,1(VI03) ; STALL_LATENCY ?3 - madday ACC,VF04,VF07y sq VF08,1(VI06) - maddaz ACC,VF05,VF07z sq VF08,7(VI06) - maddw VF11,VF06,VF07w NOP - mulax ACC,VF03,VF14x lq VF07,2(VI03) - madday ACC,VF04,VF14y NOP - maddaz ACC,VF05,VF14z NOP - maddw VF14,VF06,VF14w div Q,VF00w,VF11w - mulax ACC,VF03,VF07x NOP - madday ACC,VF04,VF07y iaddiu VI07,VI00,0x00007fff - maddaz ACC,VF05,VF07z iaddiu VI07,VI07,0x00000001 - maddw VF07,VF06,VF07w iaddiu VI08,VI00,0 - clipw.xyz VF11xyz,VF11w iaddiu VI04,VI04,0 - clipw.xyz VF14xyz,VF14w div Q,VF00w,VF14w ; STALL_THRUPUT ?1 - clipw.xyz VF07xyz,VF07w lq VF15,0(VI04) - mulq.xyz VF02,VF11,Q sq VF08,4(VI06) - mulaw.xyz ACC,VF09,VF00w iaddiu VI03,VI03,0 - mulq VF11,VF15,Q iaddiu VI06,VI06,0 ; STALL_LATENCY ?1 - madd.xyz VF01,VF02,VF09 lq VF02,1(VI04) - NOP div Q,VF00w,VF07w - mulq.xyz VF15,VF14,Q iaddiu VI08,VI08,0x00000001 - mulaw.xyz ACC,VF09,VF00w sq VF11,0(VI06) - mulq VF14,VF02,Q mfir.w VF11,VI07 - ftoi4.xyz VF11,VF01 ibeq VI08,VI02,EXPL_draw3D_vcl_triangle_loop__EPI1 - madd.xyz VF02,VF15,VF09 lq VF15,2(VI04) -; _LNOPT_w=[ ] 31 [29 0] 31 [EXPL_draw3D_vcl_triangle_loop__PRO1] - NOP lq VF12,3(VI03) + NOP sqi VF02,(VI07++) + NOP sqi VF01,(VI07++) +prim_tag_l: +; _LNOPT_w=[ normal2 ] 4 [4 0] 4 [prim_tag_l] + NOP iaddiu VI08,VI00,0x00007fff + NOP sqi VF07,(VI07++) + NOP iaddiu VI08,VI08,0x00000001 + NOP iaddiu VI09,VI00,0 +triangle_loop: +; _LNOPT_w=[ normal2 ] 11 [27 0] 27 [triangle_loop] + NOP lq VF02,0(VI04) + mulax ACC,VF03,VF02x mfir.w VF01,VI08 ; STALL_LATENCY ?3 + madday ACC,VF04,VF02y NOP + maddaz ACC,VF05,VF02z NOP + maddw VF02,VF06,VF02w NOP + clipw.xyz VF02xyz,VF02w div Q,VF00w,VF02w ; STALL_LATENCY ?3 + mulq.xyz VF02,VF02,Q waitq ; STALL_LATENCY ?6 + mulaw.xyz ACC,VF09,VF00w NOP + madd.xyz VF02,VF02,VF09 NOP ; STALL_LATENCY ?2 + NOP ibgtz VI03,vec_1_rgba + ftoi4.xyz VF01,VF02 NOP ; STALL_LATENCY ?2 +; _LNOPT_w=[ normal2 ] 5 [9 0] 9 [vec_1_stq_rgba] + NOP lq VF02,0(VI05) + mulq VF01,VF02,Q sq VF01,2(VI07) ; STALL_LATENCY ?3 + NOP sq VF08,1(VI07) + NOP b vec2 + NOP sq VF01,0(VI07) ; STALL_LATENCY ?1 +vec_1_rgba: +; _LNOPT_w=[ normal2 ] 4 [2 0] 4 [vec_1_rgba] NOP NOP - mulq.xyz VF01,VF07,Q NOP - mulq VF11,VF15,Q sq VF11,2(VI06) - mulax ACC,VF03,VF12x lq VF10,4(VI03) - madday ACC,VF04,VF12y NOP - maddaz ACC,VF05,VF12z NOP - maddw VF11,VF06,VF12w sq VF11,6(VI06) - mulax ACC,VF03,VF10x lq VF07,5(VI03) - madday ACC,VF04,VF10y sq VF14,3(VI06) - maddaz ACC,VF05,VF10z sq VF08,10(VI06) - maddw VF10,VF06,VF10w div Q,VF00w,VF11w - mulax ACC,VF03,VF07x sq VF08,13(VI06) - madday ACC,VF04,VF07y sq VF08,16(VI06) - maddaz ACC,VF05,VF07z iaddiu VI03,VI03,0x00000006 - maddw VF07,VF06,VF07w iaddiu VI04,VI04,0x00000006 - clipw.xyz VF11xyz,VF11w lq VF12,-3(VI04) - clipw.xyz VF10xyz,VF10w iaddiu VI06,VI06,0x00000012 - mulq.xyz VF14,VF11,Q div Q,VF00w,VF10w - clipw.xyz VF07xyz,VF07w fcand VI01,262143 - mulq VF12,VF12,Q iaddiu VI08,VI08,0x00000001 - ftoi4.xyz VF11,VF02 iaddiu VI01,VI01,0x00007fff - mulaw.xyz ACC,VF09,VF00w mfir.w VF11,VI07 - madd.xyz VF14,VF14,VF09 mfir.w VF10,VI01 - mulaw.xyz ACC,VF09,VF00w lq VF02,-2(VI04) - madd.xyz VF01,VF01,VF09 div Q,VF00w,VF07w - mulq.xyz VF10,VF10,Q lq VF15,-1(VI04) - ftoi4.xyz VF11,VF14 sq VF11,-13(VI06) - mulq VF14,VF02,Q sq VF12,-9(VI06) - mulaw.xyz ACC,VF09,VF00w ibeq VI08,VI02,EXPL_draw3D_vcl_triangle_loop__EPI0 - madd.xyz VF02,VF10,VF09 mfir.w VF11,VI07 -EXPL_draw3D_vcl_triangle_loop__MAIN_LOOP: -; _LPOPT_w=[ hDown ] 31 [30 30] 31 [EXPL_draw3D_vcl_triangle_loop__MAIN_LOOP] - ftoi4.xyz VF10,VF01 lq VF13,0(VI03) - NOP lq VF12,1(VI03) - mulq.xyz VF01,VF07,Q sq VF14,-6(VI06) - mulq VF11,VF15,Q sq VF11,-7(VI06) - mulax ACC,VF03,VF13x sq VF10,-10(VI06) - madday ACC,VF04,VF13y sq VF08,1(VI06) - maddaz ACC,VF05,VF13z NOP - maddw VF11,VF06,VF13w sq VF11,-3(VI06) - mulax ACC,VF03,VF12x lq VF07,2(VI03) - madday ACC,VF04,VF12y sq VF08,4(VI06) - maddaz ACC,VF05,VF12z sq VF08,7(VI06) - maddw VF10,VF06,VF12w div Q,VF00w,VF11w - mulax ACC,VF03,VF07x NOP - madday ACC,VF04,VF07y iaddiu VI03,VI03,0x00000003 - maddaz ACC,VF05,VF07z NOP - maddw VF07,VF06,VF07w iaddiu VI04,VI04,0x00000003 - clipw.xyz VF11xyz,VF11w lq VF12,-3(VI04) - clipw.xyz VF10xyz,VF10w iaddiu VI06,VI06,0x00000009 - mulq.xyz VF13,VF11,Q fcand VI01,262143 - clipw.xyz VF07xyz,VF07w div Q,VF00w,VF10w - mulq VF12,VF12,Q iaddiu VI08,VI08,0x00000001 - ftoi4.xyz VF11,VF02 iaddiu VI01,VI01,0x00007fff - mulaw.xyz ACC,VF09,VF00w mfir.w VF10,VI01 - madd.xyz VF13,VF13,VF09 mfir.w VF11,VI07 - mulaw.xyz ACC,VF09,VF00w lq VF02,-2(VI04) - madd.xyz VF01,VF01,VF09 sq VF12,-9(VI06) - mulq.xyz VF10,VF10,Q div Q,VF00w,VF07w - ftoi4.xyz VF11,VF13 sq VF11,-13(VI06) - mulq VF14,VF02,Q mfir.w VF11,VI07 - mulaw.xyz ACC,VF09,VF00w ibne VI08,VI02,EXPL_draw3D_vcl_triangle_loop__MAIN_LOOP - madd.xyz VF02,VF10,VF09 lq VF15,-1(VI04) -EXPL_draw3D_vcl_triangle_loop__EPI0: -; _LNOPT_w=[ ] 13 [13 0] 15 [EXPL_draw3D_vcl_triangle_loop__EPI0] NOP NOP - ftoi4.xyz VF10,VF01 fcand VI01,262143 - mulq.xyz VF01,VF07,Q sq VF14,-6(VI06) - mulq VF11,VF15,Q sq VF11,-7(VI06) - mulaw.xyz ACC,VF09,VF00w iaddiu VI01,VI01,0x00007fff - madd.xyz VF01,VF01,VF09 sq VF10,-10(VI06) ; STALL_LATENCY ?1 - ftoi4.xyz VF11,VF02 sq VF11,-3(VI06) - NOP mfir.w VF11,VI07 - NOP mfir.w VF10,VI01 - ftoi4.xyz VF10,VF01 NOP - NOP sq VF11,-4(VI06) ; STALL_LATENCY ?1 - NOP b EXPL_draw3D_vcl_triangle_loop__EXIT_POINT - NOP sq VF10,-1(VI06) -EXPL_draw3D_vcl_triangle_loop__EPI1: -; _LNOPT_w=[ ] 12 [13 0] 14 [EXPL_draw3D_vcl_triangle_loop__EPI1] + NOP sq VF08,0(VI07) + NOP sq VF01,1(VI07) +vec2: +; _LNOPT_w=[ normal2 ] 11 [27 0] 27 [vec2] + NOP lq VF02,1(VI04) + mulax ACC,VF03,VF02x mfir.w VF01,VI08 ; STALL_LATENCY ?3 + madday ACC,VF04,VF02y NOP + maddaz ACC,VF05,VF02z NOP + maddw VF02,VF06,VF02w NOP + clipw.xyz VF02xyz,VF02w div Q,VF00w,VF02w ; STALL_LATENCY ?3 + mulq.xyz VF02,VF02,Q waitq ; STALL_LATENCY ?6 + mulaw.xyz ACC,VF09,VF00w NOP + madd.xyz VF02,VF02,VF09 NOP ; STALL_LATENCY ?2 + NOP ibgtz VI03,vec_2_rgba + ftoi4.xyz VF01,VF02 NOP ; STALL_LATENCY ?2 +; _LNOPT_w=[ normal2 ] 5 [9 0] 9 [vec_2_stq_rgba] + NOP lq VF02,1(VI05) + mulq VF01,VF02,Q sq VF01,5(VI07) ; STALL_LATENCY ?3 + NOP sq VF08,4(VI07) + NOP b vec3 + NOP sq VF01,3(VI07) ; STALL_LATENCY ?1 +vec_2_rgba: +; _LNOPT_w=[ normal2 ] 4 [2 0] 4 [vec_2_rgba] NOP NOP - mulq.xyz VF14,VF07,Q sq VF14,3(VI06) NOP NOP - mulq VF11,VF15,Q sq VF11,2(VI06) - mulaw.xyz ACC,VF09,VF00w fcand VI01,262143 - madd.xyz VF14,VF14,VF09 iaddiu VI01,VI01,0x00007fff - NOP mfir.w VF14,VI01 - ftoi4.xyz VF11,VF02 sq VF11,6(VI06) - NOP mfir.w VF11,VI07 - ftoi4.xyz VF14,VF14 NOP - NOP sq VF11,5(VI06) ; STALL_LATENCY ?2 - NOP sq VF14,8(VI06) -EXPL_draw3D_vcl_triangle_loop__EXIT_POINT: -; _LNOPT_w=[ ] 0 [0 0] 0 [EXPL_draw3D_vcl_triangle_loop__EXIT_POINT] -; _LNOPT_w=[ normal2 ] 3 [1 0] 3 [__v_draw3D_vcl_9] - NOP xgkick VI05 + NOP sq VF08,2(VI07) + NOP sq VF01,3(VI07) +vec3: +; _LNOPT_w=[ normal2 ] 13 [27 0] 27 [vec3] + NOP lq VF01,2(VI04) + mulax ACC,VF03,VF01x NOP ; STALL_LATENCY ?3 + madday ACC,VF04,VF01y NOP + maddaz ACC,VF05,VF01z NOP + maddw VF01,VF06,VF01w NOP + clipw.xyz VF01xyz,VF01w div Q,VF00w,VF01w ; STALL_LATENCY ?3 + mulq.xyz VF01,VF01,Q waitq ; STALL_LATENCY ?6 + mulaw.xyz ACC,VF09,VF00w NOP + madd.xyz VF01,VF01,VF09 fcand VI01,262143 ; STALL_LATENCY ?2 + NOP iaddiu VI01,VI01,0x00007fff + NOP mfir.w VF01,VI01 + NOP ibgtz VI03,vec_3_rgba + ftoi4.xyz VF01,VF01 NOP +; _LNOPT_w=[ normal2 ] 6 [9 0] 9 [vec_3_stq_rgba] + NOP lq VF02,2(VI05) + mulq VF01,VF02,Q sq VF01,8(VI07) ; STALL_LATENCY ?3 + NOP sq VF08,7(VI07) + NOP iaddiu VI07,VI07,0x00000009 + NOP b loop_ctrl + NOP sq VF01,-3(VI07) +vec_3_rgba: +; _LNOPT_w=[ normal2 ] 4 [3 0] 4 [vec_3_rgba] + NOP NOP + NOP sq VF08,4(VI07) + NOP iaddiu VI07,VI07,0x00000006 + NOP sq VF01,-1(VI07) +loop_ctrl: +; _LNOPT_w=[ normal2 ] 4 [4 0] 4 [loop_ctrl] + NOP iaddiu VI09,VI09,0x00000001 + NOP iaddiu VI04,VI04,0x00000003 + NOP ibne VI09,VI02,triangle_loop + NOP iaddiu VI05,VI05,0x00000003 +; _LNOPT_w=[ normal2 ] 3 [1 0] 3 [__v_draw3D_vcl_21] + NOP xgkick VI06 NOP[E] NOP NOP NOP .align 4 VU1Draw3D_CodeEnd: -; iCount=145 +; iCount=103 ; register stats: -; 9 VU User integer -; 16 VU User floating point +; 10 VU User integer +; 11 VU User floating point ;------------------------- ;------------------------- ;------------------------- From 67bbe2e674c54cf458535388ad2df402f5dd734d Mon Sep 17 00:00:00 2001 From: h4570 Date: Mon, 28 Dec 2020 16:59:10 +0100 Subject: [PATCH 16/24] added note to changelog --- CHANGELOG.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 7908a61..496911c 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Id to MeshFrame +- Non textured rendering (RGBA only) ### Changed - Moved color from mesh to mesh material. From bc41afdf8957f8bccb8285bfa91598d0b94d5760 Mon Sep 17 00:00:00 2001 From: h4570 Date: Tue, 12 Jan 2021 19:34:30 +0100 Subject: [PATCH 17/24] gcc porting - successful compilation --- src/engine/Makefile.pref | 6 +- src/engine/include/utils/math.hpp | 10 +- src/engine/models/math/matrix.cpp | 190 +++++++++--------- src/engine/models/math/vector3.cpp | 160 +++++++-------- src/engine/models/mesh.cpp | 116 +++++------ src/engine/modules/audio.cpp | 2 + src/engine/modules/renderer.cpp | 1 + src/engine/utils/math.cpp | 11 - src/engine/utils/string.cpp | 1 + src/samples/dolphin/dolphin.cpp | 2 +- src/samples/floors/managers/floor_manager.cpp | 3 +- src/samples/floors/objects/enemy.cpp | 1 + 12 files changed, 249 insertions(+), 254 deletions(-) diff --git a/src/engine/Makefile.pref b/src/engine/Makefile.pref index 574715b..24f0306 100644 --- a/src/engine/Makefile.pref +++ b/src/engine/Makefile.pref @@ -1,8 +1,8 @@ -EE_LIBS := $(EE_LIBS) -ldraw -lgraph -lmath3d -lpacket -ldma -lpacket2 -lpad -laudsrv -lc -lstdc++ -lpng -lz +EE_LIBS := $(EE_LIBS) -ldraw -lcdvd -lgraph -lmath3d -lpacket -ldma -lpacket2 -lpad -laudsrv -lc -lstdc++ -lpng -lz EE_INCS := -I$(TYRA_DIR)/include -I$(PS2SDK)/ports/include $(EE_INCS) EE_LDFLAGS := -L$(PS2SDK)/ports/lib -L$(TYRA_DIR) $(EE_LDFLAGS) -EE_CFLAGS := -DHAVE_LIBPNG -DHAVE_ZLIB $(EE_CFLAGS) -EE_CXXFLAGS := -DHAVE_LIBPNG -DHAVE_ZLIB $(EE_CXXFLAGS) +EE_CFLAGS := -DHAVE_LIBPNG -D_XCDVD -DHAVE_ZLIB $(EE_CFLAGS) +EE_CXXFLAGS := -DHAVE_LIBPNG -D_XCDVD -DHAVE_ZLIB $(EE_CXXFLAGS) EE_DVP = dvp-as EE_VCL = vcl EE_VCLPP = vclpp diff --git a/src/engine/include/utils/math.hpp b/src/engine/include/utils/math.hpp index 3218047..5e97299 100644 --- a/src/engine/include/utils/math.hpp +++ b/src/engine/include/utils/math.hpp @@ -14,6 +14,7 @@ #include #include #include "../models/math/vector3.hpp" +#include class Vector3; // Forward definition @@ -24,16 +25,15 @@ class Math { public: - const static float HALF_ANG2RAD = 3.14159265358979323846F / 360.0F; - const static float ANG2RAD = 3.14159265358979323846F / 180.0F; - const static float PI = 3.1415926535897932384626433832795F; - const static float HALF_PI = 1.5707963267948966192313216916398F; + constexpr static float HALF_ANG2RAD = 3.14159265358979323846F / 360.0F; + constexpr static float ANG2RAD = 3.14159265358979323846F / 180.0F; + constexpr static float PI = 3.1415926535897932384626433832795F; + constexpr static float HALF_PI = 1.5707963267948966192313216916398F; static float cos(float x); static float asin(float x); static float mod(float x, float y); static inline float sin(float x) { return cos(x - HALF_PI); }; static inline float tan(float x) { return sin(x) / cos(x); } - static float sqrt(float x); static float invSqrt(float x); static inline u32 max(u32 a, u32 b) { return (a > b) ? a : b; } static inline s32 max(s32 a, s32 b) { return (a > b) ? a : b; } diff --git a/src/engine/models/math/matrix.cpp b/src/engine/models/math/matrix.cpp index 41896a5..c39ad20 100644 --- a/src/engine/models/math/matrix.cpp +++ b/src/engine/models/math/matrix.cpp @@ -58,16 +58,16 @@ Vector3 Matrix::operator*(const Vector3 &v) const float a[4] = {v.x, v.y, v.z, 1.0F}; float res[4]; asm volatile( - "lqc2 vf4, 0x00(%1) \n\t" - "lqc2 vf5, 0x10(%1) \n\t" - "lqc2 vf6, 0x20(%1) \n\t" - "lqc2 vf7, 0x30(%1) \n\t" - "lqc2 vf8, 0x00(%2) \n\t" - "vmulax.xyzw ACC, vf4, vf8 \n\t" - "vmadday.xyzw ACC, vf5, vf8 \n\t" - "vmaddaz.xyzw ACC, vf6, vf8 \n\t" - "vmaddw.xyzw vf9, vf7, vf8 \n\t" - "sqc2 vf9, 0x00(%0) \n\t" + "lqc2 $vf4, 0x00(%1) \n\t" + "lqc2 $vf5, 0x10(%1) \n\t" + "lqc2 $vf6, 0x20(%1) \n\t" + "lqc2 $vf7, 0x30(%1) \n\t" + "lqc2 $vf8, 0x00(%2) \n\t" + "vmulax.xyzw $ACC, $vf4, $vf8 \n\t" + "vmadday.xyzw $ACC, $vf5, $vf8 \n\t" + "vmaddaz.xyzw $ACC, $vf6, $vf8 \n\t" + "vmaddw.xyzw $vf9, $vf7, $vf8 \n\t" + "sqc2 $vf9, 0x00(%0) \n\t" : : "r"(res), "r"(this->data), "r"(a)); return Vector3(res[0], res[1], res[2]); @@ -80,15 +80,15 @@ Vector3 Matrix::operator*(const Vector3 &v) const void Matrix::identity() { asm volatile( - "vsub.xyzw vf4, vf0, vf0 \n\t" - "vadd.w vf4, vf4, vf0 \n\t" - "vmr32.xyzw vf5, vf4 \n\t" - "vmr32.xyzw vf6, vf5 \n\t" - "vmr32.xyzw vf7, vf6 \n\t" - "sqc2 vf4, 0x30(%0) \n\t" - "sqc2 vf5, 0x20(%0) \n\t" - "sqc2 vf6, 0x10(%0) \n\t" - "sqc2 vf7, 0x0(%0) \n\t" + "vsub.xyzw $vf4, $vf0, $vf0 \n\t" + "vadd.w $vf4, $vf4, $vf0 \n\t" + "vmr32.xyzw $vf5, $vf4 \n\t" + "vmr32.xyzw $vf6, $vf5 \n\t" + "vmr32.xyzw $vf7, $vf6 \n\t" + "sqc2 $vf4, 0x30(%0) \n\t" + "sqc2 $vf5, 0x20(%0) \n\t" + "sqc2 $vf6, 0x10(%0) \n\t" + "sqc2 $vf7, 0x0(%0) \n\t" : : "r"(this->data)); } @@ -131,17 +131,17 @@ void Matrix::lookAt(const Vector3 &t_position, const Vector3 &t_target) VECTOR eye = {t_position.x, t_position.y, t_position.z, 1.0F}; VECTOR obj = {t_target.x, t_target.y, t_target.z, 1.0F}; asm volatile( - "lqc2 vf4, 0x00(%2) # eye \n\t" - "lqc2 vf5, 0x00(%3) # obj \n\t" - "vsub.xyz vf7, vf4, vf5 # view_vec = vf7 \n\t" - "vmove.xyzw vf6, vf0 \n\t" - "vaddw.y vf6, vf0, vf0 # vf6 = { 0.0f, 1.0f, 0.0f, 1.0f } \n\t" - "vopmula.xyz ACC, vf6, vf7 \n\t" - "vopmsub.xyz vf9, vf7, vf6 # vec = vf9 \n\t" - "vopmula.xyz ACC, vf7, vf9 \n\t" - "vopmsub.xyz vf8, vf9, vf7 # up_vec = vf8 \n\t" - "sqc2 vf7, 0x00(%0) # view_vec \n\t" - "sqc2 vf6, 0x00(%1) # up_vec \n\t" + "lqc2 $vf4, 0x00(%2) # eye \n\t" + "lqc2 $vf5, 0x00(%3) # obj \n\t" + "vsub.xyz $vf7, $vf4, $vf5 # view_vec = $vf7 \n\t" + "vmove.xyzw $vf6, $vf0 \n\t" + "vaddw.y $vf6, $vf0, $vf0 # $vf6 = { 0.0f, 1.0f, 0.0f, 1.0f } \n\t" + "vopmula.xyz $ACC, $vf6, $vf7 \n\t" + "vopmsub.xyz $vf9, $vf7, $vf6 # vec = $vf9 \n\t" + "vopmula.xyz $ACC, $vf7, $vf9 \n\t" + "vopmsub.xyz $vf8, $vf9, $vf7 # up_vec = $vf8 \n\t" + "sqc2 $vf7, 0x00(%0) # view_vec \n\t" + "sqc2 $vf6, 0x00(%1) # up_vec \n\t" : : "r"(view_vec), "r"(up_vec), "r"(eye), "r"(obj)); Matrix temp; @@ -270,45 +270,45 @@ void Matrix::setScale(const Vector3 &t_val) void Matrix::setCamera(const float t_pos[4], const float t_vz[4], const float t_vy[4]) { - // Matrix vf4, vf5, vf6, vf7 - // t_pos vf8 - // t_vz vf9 - // t_vy vf10 - // vtmp vf11 + // Matrix $vf4, $vf5, $vf6, $vf7 + // t_pos $vf8 + // t_vz $vf9 + // t_vy $vf10 + // vtmp $vf11 asm volatile( - "lqc2 vf9, 0x00(%2) \n\t" - "lqc2 vf10, 0x00(%3) \n\t" + "lqc2 $vf9, 0x00(%2) \n\t" + "lqc2 $vf10, 0x00(%3) \n\t" // mtmp.unit() - "vsub.w vf5, vf0, vf0 # mtmp[1][PW] = 0.0F \n\t" + "vsub.w $vf5, $vf0, $vf0 # mtmp[1][PW] = 0.0F \n\t" // vtmp.outerProduct(vy, vz); - "vopmula.xyz ACC, vf10, vf9 \n\t" - "vopmsub.xyz vf11, vf9, vf10 \n\t" + "vopmula.xyz $ACC, $vf10, $vf9 \n\t" + "vopmsub.xyz $vf11, $vf9, $vf10 \n\t" // mtmp[0] = vtmp.normalize(); - "vmul.xyz vf12, vf11, vf11 \n\t" - "vaddy.x vf12, vf12, vf12 \n\t" - "vaddz.x vf12, vf12, vf12 \n\t" - "vrsqrt Q, vf0w, vf12x \n\t" - "vsub.xyzw vf4, vf0, vf0 \n\t" + "vmul.xyz $vf12, $vf11, $vf11 \n\t" + "vaddy.x $vf12, $vf12, $vf12 \n\t" + "vaddz.x $vf12, $vf12, $vf12 \n\t" + "vrsqrt $Q, $vf0w, $vf12x \n\t" + "vsub.xyzw $vf4, $vf0, $vf0 \n\t" "vwaitq \n\t" - "vmulq.xyz vf4, vf11, Q \n\t" + "vmulq.xyz $vf4, $vf11, $Q \n\t" // mtmp[2] = vz.normalize(); - "vmul.xyz vf12, vf9, vf9 \n\t" - "vaddy.x vf12, vf12, vf12 \n\t" - "vaddz.x vf12, vf12, vf12 \n\t" - "vrsqrt Q, vf0w, vf12x \n\t" - "vsub.xyzw vf6, vf0, vf0 \n\t" + "vmul.xyz $vf12, $vf9, $vf9 \n\t" + "vaddy.x $vf12, $vf12, $vf12 \n\t" + "vaddz.x $vf12, $vf12, $vf12 \n\t" + "vrsqrt $Q, $vf0w, $vf12x \n\t" + "vsub.xyzw $vf6, $vf0, $vf0 \n\t" "vwaitq \n\t" - "vmulq.xyz vf6, vf9, Q \n\t" + "vmulq.xyz $vf6, $vf9, $Q \n\t" // mtmp[1].outerProduct(mtmp[2], mtmp[0]); - "vopmula.xyz ACC, vf6, vf4 \n\t" - "vopmsub.xyz vf5, vf4, vf6 \n\t" + "vopmula.xyz $ACC, $vf6, $vf4 \n\t" + "vopmsub.xyz $vf5, $vf4, $vf6 \n\t" // mtmp.transpose(pos); - "lqc2 vf7, 0x00(%1) \n\t" + "lqc2 $vf7, 0x00(%1) \n\t" // m = mtmp.inverse(); - "qmfc2.ni $11, vf0 \n\t" - "qmfc2.ni $8, vf4 \n\t" - "qmfc2.ni $9, vf5 \n\t" - "qmfc2.ni $10, vf6 \n\t" + "qmfc2.ni $11, $vf0 \n\t" + "qmfc2.ni $8, $vf4 \n\t" + "qmfc2.ni $9, $vf5 \n\t" + "qmfc2.ni $10, $vf6 \n\t" "pextlw $12, $9, $8 \n\t" "pextuw $13, $9, $8 \n\t" @@ -318,18 +318,18 @@ void Matrix::setCamera(const float t_pos[4], const float t_vz[4], const float t_ "pcpyud $9, $12, $14 \n\t" "pcpyld $10, $15, $13 \n\t" - "qmtc2.ni $8, vf16 \n\t" - "qmtc2.ni $9, vf17 \n\t" - "qmtc2.ni $10, vf18 \n\t" - "vmulax.xyz ACC, vf16, vf7 \n\t" - "vmadday.xyz ACC, vf17, vf7 \n\t" - "vmaddz.xyz vf5, vf18, vf7 \n\t" - "vsub.xyzw vf5, vf0, vf5 \n\t" + "qmtc2.ni $8, $vf16 \n\t" + "qmtc2.ni $9, $vf17 \n\t" + "qmtc2.ni $10, $vf18 \n\t" + "vmulax.xyz $ACC, $vf16, $vf7 \n\t" + "vmadday.xyz $ACC, $vf17, $vf7 \n\t" + "vmaddz.xyz $vf5, $vf18, $vf7 \n\t" + "vsub.xyzw $vf5, $vf0, $vf5 \n\t" "sq $8, 0x00(%0) \n\t" "sq $9, 0x10(%0) \n\t" "sq $10, 0x20(%0) \n\t" - "sqc2 vf5, 0x30(%0) \n\t" + "sqc2 $vf5, 0x30(%0) \n\t" : : "r"(this->data), "r"(t_pos), "r"(t_vz), "r"(t_vy)); } @@ -337,34 +337,34 @@ void Matrix::setCamera(const float t_pos[4], const float t_vz[4], const float t_ void Matrix::cross(float res[16], const float a[16], const float b[16]) const { asm volatile( - "lqc2 vf1, 0x00(%1) \n\t" - "lqc2 vf2, 0x10(%1) \n\t" - "lqc2 vf3, 0x20(%1) \n\t" - "lqc2 vf4, 0x30(%1) \n\t" - "lqc2 vf5, 0x00(%2) \n\t" - "lqc2 vf6, 0x10(%2) \n\t" - "lqc2 vf7, 0x20(%2) \n\t" - "lqc2 vf8, 0x30(%2) \n\t" - "vmulax.xyzw ACC, vf5, vf1 \n\t" - "vmadday.xyzw ACC, vf6, vf1 \n\t" - "vmaddaz.xyzw ACC, vf7, vf1 \n\t" - "vmaddw.xyzw vf1, vf8, vf1 \n\t" - "vmulax.xyzw ACC, vf5, vf2 \n\t" - "vmadday.xyzw ACC, vf6, vf2 \n\t" - "vmaddaz.xyzw ACC, vf7, vf2 \n\t" - "vmaddw.xyzw vf2, vf8, vf2 \n\t" - "vmulax.xyzw ACC, vf5, vf3 \n\t" - "vmadday.xyzw ACC, vf6, vf3 \n\t" - "vmaddaz.xyzw ACC, vf7, vf3 \n\t" - "vmaddw.xyzw vf3, vf8, vf3 \n\t" - "vmulax.xyzw ACC, vf5, vf4 \n\t" - "vmadday.xyzw ACC, vf6, vf4 \n\t" - "vmaddaz.xyzw ACC, vf7, vf4 \n\t" - "vmaddw.xyzw vf4, vf8, vf4 \n\t" - "sqc2 vf1, 0x00(%0) \n\t" - "sqc2 vf2, 0x10(%0) \n\t" - "sqc2 vf3, 0x20(%0) \n\t" - "sqc2 vf4, 0x30(%0) \n\t" + "lqc2 $vf1, 0x00(%1) \n\t" + "lqc2 $vf2, 0x10(%1) \n\t" + "lqc2 $vf3, 0x20(%1) \n\t" + "lqc2 $vf4, 0x30(%1) \n\t" + "lqc2 $vf5, 0x00(%2) \n\t" + "lqc2 $vf6, 0x10(%2) \n\t" + "lqc2 $vf7, 0x20(%2) \n\t" + "lqc2 $vf8, 0x30(%2) \n\t" + "vmulax.xyzw $ACC, $vf5, $vf1 \n\t" + "vmadday.xyzw $ACC, $vf6, $vf1 \n\t" + "vmaddaz.xyzw $ACC, $vf7, $vf1 \n\t" + "vmaddw.xyzw $vf1, $vf8, $vf1 \n\t" + "vmulax.xyzw $ACC, $vf5, $vf2 \n\t" + "vmadday.xyzw $ACC, $vf6, $vf2 \n\t" + "vmaddaz.xyzw $ACC, $vf7, $vf2 \n\t" + "vmaddw.xyzw $vf2, $vf8, $vf2 \n\t" + "vmulax.xyzw $ACC, $vf5, $vf3 \n\t" + "vmadday.xyzw $ACC, $vf6, $vf3 \n\t" + "vmaddaz.xyzw $ACC, $vf7, $vf3 \n\t" + "vmaddw.xyzw $vf3, $vf8, $vf3 \n\t" + "vmulax.xyzw $ACC, $vf5, $vf4 \n\t" + "vmadday.xyzw $ACC, $vf6, $vf4 \n\t" + "vmaddaz.xyzw $ACC, $vf7, $vf4 \n\t" + "vmaddw.xyzw $vf4, $vf8, $vf4 \n\t" + "sqc2 $vf1, 0x00(%0) \n\t" + "sqc2 $vf2, 0x10(%0) \n\t" + "sqc2 $vf3, 0x20(%0) \n\t" + "sqc2 $vf4, 0x30(%0) \n\t" : : "r"(res), "r"(b), "r"(a) : "memory"); diff --git a/src/engine/models/math/vector3.cpp b/src/engine/models/math/vector3.cpp index 57f4303..6d71a91 100644 --- a/src/engine/models/math/vector3.cpp +++ b/src/engine/models/math/vector3.cpp @@ -30,10 +30,10 @@ Vector3 Vector3::operator+(const Vector3 &v) const { Vector3 result; asm volatile( // VU0 Macro program - "lqc2 vf4, 0x0(%1) \n\t" - "lqc2 vf5, 0x0(%2) \n\t" - "vadd.xyz vf6, vf4, vf5 \n\t" - "sqc2 vf6, 0x0(%0) \n\t" + "lqc2 $vf4, 0x0(%1) \n\t" + "lqc2 $vf5, 0x0(%2) \n\t" + "vadd.xyz $vf6, $vf4, $vf5 \n\t" + "sqc2 $vf6, 0x0(%0) \n\t" : : "r"(result.xyz), "r"(this->xyz), "r"(v.xyz)); return result; @@ -43,10 +43,10 @@ Vector3 Vector3::operator-(const Vector3 &v) const { Vector3 result; asm volatile( // VU0 Macro program - "lqc2 vf4, 0x0(%1) \n\t" - "lqc2 vf5, 0x0(%2) \n\t" - "vsub.xyz vf6, vf4, vf5 \n\t" - "sqc2 vf6, 0x0(%0) \n\t" + "lqc2 $vf4, 0x0(%1) \n\t" + "lqc2 $vf5, 0x0(%2) \n\t" + "vsub.xyz $vf6, $vf4, $vf5 \n\t" + "sqc2 $vf6, 0x0(%0) \n\t" : : "r"(result.xyz), "r"(this->xyz), "r"(v.xyz)); return result; @@ -55,13 +55,13 @@ Vector3 Vector3::operator-(const Vector3 &v) const Vector3 Vector3::operator*(const Vector3 &v) const { Vector3 res; - asm volatile( // VU0 Macro program - "lqc2 vf4, 0x0(%1) \n\t" // vf4 = this - "lqc2 vf5, 0x0(%2) \n\t" // vf5 = v - "vopmula.xyz ACC, vf4, vf5 \n\t" - "vopmsub.xyz vf8, vf5, vf4 \n\t" - "vsub.w vf8, vf00, vf00 \n\t" - "sqc2 vf8, 0x0(%0) \n\t" // vf8 = res + asm volatile( // VU0 Macro program + "lqc2 $vf4, 0x0(%1) \n\t" // $vf4 = this + "lqc2 $vf5, 0x0(%2) \n\t" // $vf5 = v + "vopmula.xyz $ACC, $vf4, $vf5 \n\t" + "vopmsub.xyz $vf8, $vf5, $vf4 \n\t" + "vsub.w $vf8, $vf0, $vf0 \n\t" + "sqc2 $vf8, 0x0(%0) \n\t" // $vf8 = res : : "r"(res.xyz), "r"(this->xyz), "r"(v.xyz)); // result.x = y * v.z - z * v.y; @@ -74,11 +74,11 @@ Vector3 Vector3::operator*(const float &t) const { Vector3 result; asm volatile( - "lqc2 vf4, 0x0(%1) \n\t" + "lqc2 $vf4, 0x0(%1) \n\t" "mfc1 $8, %2 \n\t" - "qmtc2 $8, vf5 \n\t" - "vmulx.xyz vf6, vf4, vf5 \n\t" - "sqc2 vf6, 0x0(%0) \n\t" + "qmtc2 $8, $vf5 \n\t" + "vmulx.xyz $vf6, $vf4, $vf5 \n\t" + "sqc2 $vf6, 0x0(%0) \n\t" : : "r"(result.xyz), "r"(this->xyz), "f"(t)); return result; @@ -96,10 +96,10 @@ Vector3 Vector3::operator/(const float &t) const void Vector3::operator+=(const Vector3 &t) { asm volatile( // VU0 Macro program - "lqc2 vf4, 0x0(%0) \n\t" - "lqc2 vf5, 0x0(%1) \n\t" - "vadd.xyz vf4, vf4, vf5 \n\t" - "sqc2 vf4, 0x0(%0) \n\t" + "lqc2 $vf4, 0x0(%0) \n\t" + "lqc2 $vf5, 0x0(%1) \n\t" + "vadd.xyz $vf4, $vf4, $vf5 \n\t" + "sqc2 $vf4, 0x0(%0) \n\t" : : "r"(this->xyz), "r"(t.xyz)); } @@ -107,11 +107,11 @@ void Vector3::operator+=(const Vector3 &t) void Vector3::operator*=(const float &t) { asm volatile( - "lqc2 vf4, 0x0(%0) \n\t" + "lqc2 $vf4, 0x0(%0) \n\t" "mfc1 $8, %1 \n\t" - "qmtc2 $8, vf5 \n\t" - "vmulx.xyz vf4, vf4, vf5 \n\t" - "sqc2 vf4, 0x0(%0) \n\t" + "qmtc2 $8, $vf5 \n\t" + "vmulx.xyz $vf4, $vf4, $vf5 \n\t" + "sqc2 $vf4, 0x0(%0) \n\t" : : "r"(this->xyz), "f"(t)); } @@ -140,12 +140,12 @@ float Vector3::innerProduct(const Vector3 &v) const { float result; asm volatile( // VU0 Macro program - "lqc2 vf4, 0x0(%1) \n\t" - "lqc2 vf5, 0x0(%2) \n\t" - "vmul.xyz vf6, vf4, vf5 \n\t" - "vaddy.x vf6, vf6, vf6 \n\t" - "vaddz.x vf6, vf6, vf6 \n\t" - "qmfc2 $2, vf6 \n\t" + "lqc2 $vf4, 0x0(%1) \n\t" + "lqc2 $vf5, 0x0(%2) \n\t" + "vmul.xyz $vf6, $vf4, $vf5 \n\t" + "vaddy.x $vf6, $vf6, $vf6 \n\t" + "vaddz.x $vf6, $vf6, $vf6 \n\t" + "qmfc2 $2, $vf6 \n\t" "mtc1 $2, %0 \n\t" : "=f"(result) : "r"(this->xyz), "r"(v.xyz)); @@ -157,14 +157,14 @@ float Vector3::length() const { float result; asm volatile( // VU0 Macro program - "lqc2 vf4, 0x0(%1) \n\t" - "vmul.xyz vf5, vf4, vf4 \n\t" - "vaddy.x vf5, vf5, vf5 \n\t" - "vaddz.x vf5, vf5, vf5 \n\t" - "vsqrt Q , vf5x \n\t" + "lqc2 $vf4, 0x0(%1) \n\t" + "vmul.xyz $vf5, $vf4, $vf4 \n\t" + "vaddy.x $vf5, $vf5, $vf5 \n\t" + "vaddz.x $vf5, $vf5, $vf5 \n\t" + "vsqrt $Q , $vf5x \n\t" "vwaitq \n\t" - "vaddq.x vf8, vf0, Q \n\t" - "qmfc2 $2, vf8 \n\t" + "vaddq.x $vf8, $vf0, $Q \n\t" + "qmfc2 $2, $vf8 \n\t" "mtc1 $2, %0 \n\t" : "=f"(result) : "r"(this->xyz)); @@ -175,17 +175,17 @@ float Vector3::length() const void Vector3::normalize() { asm volatile( // VU0 Macro program - "lqc2 vf4, 0x0(%0) \n\t" - "vmul.xyz vf5, vf4, vf4 \n\t" - "vaddy.x vf5, vf5, vf5 \n\t" - "vaddz.x vf5, vf5, vf5 \n\t" - "vrsqrt Q, vf0w, vf5x \n\t" + "lqc2 $vf4, 0x0(%0) \n\t" + "vmul.xyz $vf5, $vf4, $vf4 \n\t" + "vaddy.x $vf5, $vf5, $vf5 \n\t" + "vaddz.x $vf5, $vf5, $vf5 \n\t" + "vrsqrt $Q, $vf0w, $vf5x \n\t" "vwaitq \n\t" - "vsub.xyz vf6, vf0, vf0 \n\t" - "vaddw.xyz vf6, vf6, vf4 \n\t" + "vsub.xyz $vf6, $vf0, $vf0 \n\t" + "vaddw.xyz $vf6, $vf6, $vf4 \n\t" "vwaitq \n\t" - "vmulq.xyz vf6, vf4, Q \n\t" - "sqc2 vf6, 0x0(%0) \n\t" + "vmulq.xyz $vf6, $vf4, $Q \n\t" + "sqc2 $vf6, 0x0(%0) \n\t" : : "r"(this->xyz)); } @@ -194,16 +194,16 @@ float Vector3::distanceTo(const Vector3 &v) const { register float result; asm volatile( // VU0 Macro program - "lqc2 vf4, 0x0(%1) \n\t" - "lqc2 vf5, 0x0(%2) \n\t" - "vsub.xyz vf6, vf4, vf5 \n\t" - "vmul.xyz vf7, vf6, vf6 \n\t" - "vaddy.x vf7, vf7, vf7 \n\t" - "vaddz.x vf7, vf7, vf7 \n\t" - "vsqrt Q , vf7x \n\t" + "lqc2 $vf4, 0x0(%1) \n\t" + "lqc2 $vf5, 0x0(%2) \n\t" + "vsub.xyz $vf6, $vf4, $vf5 \n\t" + "vmul.xyz $vf7, $vf6, $vf6 \n\t" + "vaddy.x $vf7, $vf7, $vf7 \n\t" + "vaddz.x $vf7, $vf7, $vf7 \n\t" + "vsqrt $Q , $vf7x \n\t" "vwaitq \n\t" - "vaddq.x vf8, vf0, Q \n\t" - "qmfc2 $2, vf8 \n\t" + "vaddq.x $vf8, $vf0, $Q \n\t" + "qmfc2 $2, $vf8 \n\t" "mtc1 $2, %0 \n\t" : "=f"(result) : "r"(this->xyz), "r"(v.xyz)); @@ -217,20 +217,20 @@ u8 Vector3::shouldBeBackfaceCulled(const Vector3 *t_cameraPos, const Vector3 *t_ { register float dot; asm volatile( - "lqc2 vf4, 0x0(%1) \n\t" // vf4 = cameraPos - "lqc2 vf5, 0x0(%2) \n\t" // vf5 = v0 - "lqc2 vf6, 0x0(%3) \n\t" // vf6 = v1 - "lqc2 vf7, 0x0(%4) \n\t" // vf7 = v2 - "vsub.xyz vf8, vf7, vf5 \n\t" // vf8 = vf7(v2) - vf5(v0) - "vsub.xyz vf9, vf6, vf5 \n\t" // vf9 = vf6(v1) - vf5(v0) - "vopmula.xyz ACC, vf8, vf9 \n\t" // vf6 = cross(vf8, vf9) - "vopmsub.xyz vf6, vf9, vf8 \n\t" - "vsub.w vf6, vf6, vf6 \n\t" - "vsub.xyz vf7, vf5, vf4 \n\t" // vf7 = vf5(v0) - vf4(cameraPos) - "vmul.xyz vf5, vf7, vf6 \n\t" // vf5 = dot(vf7, vf6) - "vaddy.x vf5, vf5, vf5 \n\t" - "vaddz.x vf5, vf5, vf5 \n\t" - "qmfc2 $2, vf5 \n\t" // store result on `dot` variable + "lqc2 $vf4, 0x0(%1) \n\t" // $vf4 = cameraPos + "lqc2 $vf5, 0x0(%2) \n\t" // $vf5 = v0 + "lqc2 $vf6, 0x0(%3) \n\t" // $vf6 = v1 + "lqc2 $vf7, 0x0(%4) \n\t" // $vf7 = v2 + "vsub.xyz $vf8, $vf7, $vf5 \n\t" // $vf8 = $vf7(v2) - $vf5(v0) + "vsub.xyz $vf9, $vf6, $vf5 \n\t" // $vf9 = $vf6(v1) - $vf5(v0) + "vopmula.xyz $ACC, $vf8, $vf9 \n\t" // $vf6 = cross($vf8, $vf9) + "vopmsub.xyz $vf6, $vf9, $vf8 \n\t" + "vsub.w $vf6, $vf6, $vf6 \n\t" + "vsub.xyz $vf7, $vf5, $vf4 \n\t" // $vf7 = $vf5(v0) - $vf4(cameraPos) + "vmul.xyz $vf5, $vf7, $vf6 \n\t" // $vf5 = dot($vf7, $vf6) + "vaddy.x $vf5, $vf5, $vf5 \n\t" + "vaddz.x $vf5, $vf5, $vf5 \n\t" + "qmfc2 $2, $vf5 \n\t" // store result on `dot` variable "mtc1 $2, %0 \n\t" : "=f"(dot) : "r"(t_cameraPos->xyz), "r"(t_v0->xyz), "r"(t_v1->xyz), "r"(t_v2->xyz)); @@ -240,14 +240,14 @@ u8 Vector3::shouldBeBackfaceCulled(const Vector3 *t_cameraPos, const Vector3 *t_ void Vector3::setByLerp(const Vector3 &t_v1, const Vector3 &t_v2, const float &t_interp, const float &t_scale) { asm volatile( - "lqc2 vf4, 0x0(%1) \n\t" // vf4 = v1 - "lqc2 vf5, 0x0(%2) \n\t" // vf5 = v2 - "mfc1 $8, %3 \n\t" // vf6 = t - "qmtc2 $8, vf6 \n\t" // lerp: - "vsub.xyz vf7, vf5, vf4 \n\t" // vf7 = v2 - v1 - "vmulx.xyz vf8, vf7, vf6 \n\t" // vf8 = vf7 * t - "vadd.xyz vf9, vf8, vf4 \n\t" // vf9 = vf8 + vf4 - "sqc2 vf9, 0x0(%0) \n\t" // v0 = vf9 + "lqc2 $vf4, 0x0(%1) \n\t" // $vf4 = v1 + "lqc2 $vf5, 0x0(%2) \n\t" // $vf5 = v2 + "mfc1 $8, %3 \n\t" // $vf6 = t + "qmtc2 $8, $vf6 \n\t" // lerp: + "vsub.xyz $vf7, $vf5, $vf4 \n\t" // $vf7 = v2 - v1 + "vmulx.xyz $vf8, $vf7, $vf6 \n\t" // $vf8 = $vf7 * t + "vadd.xyz $vf9, $vf8, $vf4 \n\t" // $vf9 = $vf8 + $vf4 + "sqc2 $vf9, 0x0(%0) \n\t" // v0 = $vf9 : : "r"(&this->xyz), "r"(&t_v1.xyz), "r"(&t_v2.xyz), "f"(t_interp)); operator*=(t_scale); diff --git a/src/engine/models/mesh.cpp b/src/engine/models/mesh.cpp index 2419b9b..4f6364d 100644 --- a/src/engine/models/mesh.cpp +++ b/src/engine/models/mesh.cpp @@ -195,7 +195,7 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals asm volatile( // VU0 macro program: // Load vector with 1.0F values to VF21 - "lqc2 vf21, 0x0(%0) \n\t" // load "one vec" + "lqc2 $vf21, 0x0(%0) \n\t" // load "one vec" : : "r"(ONE_VEC)); @@ -221,34 +221,34 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals // Calculate lerp() and store data into calc3Vectors // Vertex 0 - "lqc2 vf4, 0x0(%3) \n\t" // vf4 = v1 - "lqc2 vf5, 0x0(%6) \n\t" // vf5 = v2 - "mfc1 $10, %9 \n\t" // vf6 = t - "qmtc2 $10, vf6 \n\t" // lerp: - "vsub.xyz vf7, vf5, vf4 \n\t" // vf7 = v2 - v1 - "vmulx.xyz vf8, vf7, vf6 \n\t" // vf8 = vf7 * t - "vadd.xyz vf9, vf8, vf4 \n\t" // vf9 = vf8 + vf4 - "sqc2 vf9, 0x0(%0) \n\t" // v0 = vf9 + "lqc2 $vf4, 0x0(%3) \n\t" // $vf4 = v1 + "lqc2 $vf5, 0x0(%6) \n\t" // $vf5 = v2 + "mfc1 $10, %9 \n\t" // $vf6 = t + "qmtc2 $10, $vf6 \n\t" // lerp: + "vsub.xyz $vf7, $vf5, $vf4 \n\t" // $vf7 = v2 - v1 + "vmulx.xyz $vf8, $vf7, $vf6 \n\t" // $vf8 = $vf7 * t + "vadd.xyz $vf9, $vf8, $vf4 \n\t" // $vf9 = $vf8 + $vf4 + "sqc2 $vf9, 0x0(%0) \n\t" // v0 = $vf9 // Vertex 1 - "lqc2 vf4, 0x0(%4) \n\t" // vf4 = v1 - "lqc2 vf5, 0x0(%7) \n\t" // vf5 = v2 - "mfc1 $10, %9 \n\t" // vf6 = t - "qmtc2 $10, vf6 \n\t" // lerp: - "vsub.xyz vf7, vf5, vf4 \n\t" // vf7 = v2 - v1 - "vmulx.xyz vf8, vf7, vf6 \n\t" // vf8 = vf7 * t - "vadd.xyz vf9, vf8, vf4 \n\t" // vf9 = vf8 + vf4 - "sqc2 vf9, 0x0(%1) \n\t" // v0 = vf9 + "lqc2 $vf4, 0x0(%4) \n\t" // $vf4 = v1 + "lqc2 $vf5, 0x0(%7) \n\t" // $vf5 = v2 + "mfc1 $10, %9 \n\t" // $vf6 = t + "qmtc2 $10, $vf6 \n\t" // lerp: + "vsub.xyz $vf7, $vf5, $vf4 \n\t" // $vf7 = v2 - v1 + "vmulx.xyz $vf8, $vf7, $vf6 \n\t" // $vf8 = $vf7 * t + "vadd.xyz $vf9, $vf8, $vf4 \n\t" // $vf9 = $vf8 + $vf4 + "sqc2 $vf9, 0x0(%1) \n\t" // v0 = $vf9 // Vertex 2 - "lqc2 vf4, 0x0(%5) \n\t" // vf4 = v1 - "lqc2 vf5, 0x0(%8) \n\t" // vf5 = v2 - "mfc1 $10, %9 \n\t" // vf6 = t - "qmtc2 $10, vf6 \n\t" // lerp: - "vsub.xyz vf7, vf5, vf4 \n\t" // vf7 = v2 - v1 - "vmulx.xyz vf8, vf7, vf6 \n\t" // vf8 = vf7 * t - "vadd.xyz vf9, vf8, vf4 \n\t" // vf9 = vf8 + vf4 - "sqc2 vf9, 0x0(%2) \n\t" // v0 = vf9 + "lqc2 $vf4, 0x0(%5) \n\t" // $vf4 = v1 + "lqc2 $vf5, 0x0(%8) \n\t" // $vf5 = v2 + "mfc1 $10, %9 \n\t" // $vf6 = t + "qmtc2 $10, $vf6 \n\t" // lerp: + "vsub.xyz $vf7, $vf5, $vf4 \n\t" // $vf7 = v2 - v1 + "vmulx.xyz $vf8, $vf7, $vf6 \n\t" // $vf8 = $vf7 * t + "vadd.xyz $vf9, $vf8, $vf4 \n\t" // $vf9 = $vf8 + $vf4 + "sqc2 $vf9, 0x0(%2) \n\t" // v0 = $vf9 : : "r"(calc3Vectors[0].xyz), @@ -267,12 +267,12 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals asm volatile( // VU0 macro program // Copy 0,1,2 vertices - "lqc2 vf1, 0x0(%3) \n\t" // load vert - "lqc2 vf2, 0x0(%4) \n\t" // load normal - "lqc2 vf3, 0x0(%5) \n\t" // load st - "sqc2 vf1, 0x0(%0) \n\t" // store vert - "sqc2 vf2, 0x0(%1) \n\t" // store normal - "sqc2 vf3, 0x0(%2) \n\t" // store st + "lqc2 $vf1, 0x0(%3) \n\t" // load vert + "lqc2 $vf2, 0x0(%4) \n\t" // load normal + "lqc2 $vf3, 0x0(%5) \n\t" // load st + "sqc2 $vf1, 0x0(%0) \n\t" // store vert + "sqc2 $vf2, 0x0(%1) \n\t" // store normal + "sqc2 $vf3, 0x0(%2) \n\t" // store st : : "r"(calc3Vectors[0].xyz), "r"(calc3Vectors[1].xyz), @@ -291,37 +291,37 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals // Copy data and set vert/normal "w" and st "z"+"w" to 1.0F // Vertex 0 - "lqc2 vf1, 0x0(%3) \n\t" // load vert - "lqc2 vf2, 0x0(%4) \n\t" // load normal - "lqc2 vf3, 0x0(%5) \n\t" // load st - "vadd.w vf1, vf20, vf21 \n\t" // set vert.w to 1.0F - "vadd.w vf2, vf20, vf21 \n\t" // set normal.W to 1.0F - "vadd.zw vf3, vf20, vf21 \n\t" // set st.zw to 1.0F - "sqc2 vf1, 0x0(%0) \n\t" // store vert - "sqc2 vf2, 0x0(%1) \n\t" // store normal - "sqc2 vf3, 0x0(%2) \n\t" // store st + "lqc2 $vf1, 0x0(%3) \n\t" // load vert + "lqc2 $vf2, 0x0(%4) \n\t" // load normal + "lqc2 $vf3, 0x0(%5) \n\t" // load st + "vadd.w $vf1, $vf20, $vf21 \n\t" // set vert.w to 1.0F + "vadd.w $vf2, $vf20, $vf21 \n\t" // set normal.W to 1.0F + "vadd.zw $vf3, $vf20, $vf21 \n\t" // set st.zw to 1.0F + "sqc2 $vf1, 0x0(%0) \n\t" // store vert + "sqc2 $vf2, 0x0(%1) \n\t" // store normal + "sqc2 $vf3, 0x0(%2) \n\t" // store st // Vertex 1 - "lqc2 vf1, 0x0(%9) \n\t" // load vert - "lqc2 vf2, 0x0(%10) \n\t" // load normal - "lqc2 vf3, 0x0(%11) \n\t" // load st - "vadd.w vf1, vf20, vf21 \n\t" // set vert.w to 1.0F - "vadd.w vf2, vf20, vf21 \n\t" // set normal.W to 1.0F - "vadd.zw vf3, vf20, vf21 \n\t" // set st.zw to 1.0F - "sqc2 vf1, 0x0(%6) \n\t" // store vert - "sqc2 vf2, 0x0(%7) \n\t" // store normal - "sqc2 vf3, 0x0(%8) \n\t" // store st + "lqc2 $vf1, 0x0(%9) \n\t" // load vert + "lqc2 $vf2, 0x0(%10) \n\t" // load normal + "lqc2 $vf3, 0x0(%11) \n\t" // load st + "vadd.w $vf1, $vf20, $vf21 \n\t" // set vert.w to 1.0F + "vadd.w $vf2, $vf20, $vf21 \n\t" // set normal.W to 1.0F + "vadd.zw $vf3, $vf20, $vf21 \n\t" // set st.zw to 1.0F + "sqc2 $vf1, 0x0(%6) \n\t" // store vert + "sqc2 $vf2, 0x0(%7) \n\t" // store normal + "sqc2 $vf3, 0x0(%8) \n\t" // store st // Vertex 2 - "lqc2 vf1, 0x0(%15) \n\t" // load vert - "lqc2 vf2, 0x0(%16) \n\t" // load normal - "lqc2 vf3, 0x0(%17) \n\t" // load st - "vadd.w vf1, vf20, vf21 \n\t" // set vert.w to 1.0F - "vadd.w vf2, vf20, vf21 \n\t" // set normal.W to 1.0F - "vadd.zw vf3, vf20, vf21 \n\t" // set st.zw to 1.0F - "sqc2 vf1, 0x0(%12) \n\t" // store vert - "sqc2 vf2, 0x0(%13) \n\t" // store normal - "sqc2 vf3, 0x0(%14) \n\t" // store st + "lqc2 $vf1, 0x0(%15) \n\t" // load vert + "lqc2 $vf2, 0x0(%16) \n\t" // load normal + "lqc2 $vf3, 0x0(%17) \n\t" // load st + "vadd.w $vf1, $vf20, $vf21 \n\t" // set vert.w to 1.0F + "vadd.w $vf2, $vf20, $vf21 \n\t" // set normal.W to 1.0F + "vadd.zw $vf3, $vf20, $vf21 \n\t" // set st.zw to 1.0F + "sqc2 $vf1, 0x0(%12) \n\t" // store vert + "sqc2 $vf2, 0x0(%13) \n\t" // store normal + "sqc2 $vf3, 0x0(%14) \n\t" // store st : : "r"(o_vertices[addedFaces]), diff --git a/src/engine/modules/audio.cpp b/src/engine/modules/audio.cpp index 369413c..0c8b052 100644 --- a/src/engine/modules/audio.cpp +++ b/src/engine/modules/audio.cpp @@ -178,6 +178,8 @@ void Audio::startThread(FileService *t_fileService) /** Main thread loop */ void Audio::threadLoop() { + if (songPlaying) + songPlaying = 1; // GCC11: wtf? we need to put some code there, because song is not playing.. if (!songPlaying || !songLoaded) return; if (songFinished) diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index f554b82..a07f7f2 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -328,6 +328,7 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) VECTOR normals[vertCount] __attribute__((aligned(16))); VECTOR coordinates[vertCount] __attribute__((aligned(16))); Texture *tex = textureRepo.getBySpriteOrMesh(material->getId()); + // printf("TexId:%d\n", tex->getId()); changeTexture(tex); vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera); vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer, &material->color, !material->areSTsPresent()); diff --git a/src/engine/utils/math.cpp b/src/engine/utils/math.cpp index 5c4846e..e9bd11d 100644 --- a/src/engine/utils/math.cpp +++ b/src/engine/utils/math.cpp @@ -11,7 +11,6 @@ #include "../include/utils/math.hpp" #include -#include float Math::cos(float x) { @@ -72,16 +71,6 @@ float Math::cos(float x) return r; } -float Math::sqrt(float x) -{ - float r; - __asm__ volatile( - "sqrt.s %0, %1 \n\t" - : "=&f"(r) - : "f"(x)); - return r; -} - float Math::invSqrt(float x) { return 1.0F / sqrt(x); } /** Converts Vector3 to PS2SDK's Vector4 */ diff --git a/src/engine/utils/string.cpp b/src/engine/utils/string.cpp index d928673..60381c3 100644 --- a/src/engine/utils/string.cpp +++ b/src/engine/utils/string.cpp @@ -11,6 +11,7 @@ #include "../include/utils/string.hpp" #include "../include/utils/debug.hpp" #include +#define CHAR_BIT 8 char *String::createU32ToString(u32 a) { diff --git a/src/samples/dolphin/dolphin.cpp b/src/samples/dolphin/dolphin.cpp index be6f6a8..fb19346 100755 --- a/src/samples/dolphin/dolphin.cpp +++ b/src/samples/dolphin/dolphin.cpp @@ -73,7 +73,7 @@ void Dolphin::onInit() printf("Loading water...\n"); - u32 spiralOffset = (u32)Math::sqrt(WATER_TILES_COUNT); + u32 spiralOffset = (u32)sqrt(WATER_TILES_COUNT); waterDrawList = new Mesh *[WATER_TILES_COUNT]; calcSpiral(spiralOffset, spiralOffset); water[0].loadObj("water/", "water", WATER_TILE_SCALE, false); diff --git a/src/samples/floors/managers/floor_manager.cpp b/src/samples/floors/managers/floor_manager.cpp index d5f29ae..cc2e0ae 100644 --- a/src/samples/floors/managers/floor_manager.cpp +++ b/src/samples/floors/managers/floor_manager.cpp @@ -12,6 +12,7 @@ #include #include +#include // ---- // Constructors/Destructors @@ -26,7 +27,7 @@ FloorManager::FloorManager(int t_floorAmount, TextureRepository *t_texRepo) texRepo = t_texRepo; floorAmount = t_floorAmount; spirals = new Point[t_floorAmount]; - int floorSpiralMaxOffset = (int)Math::sqrt(t_floorAmount); + int floorSpiralMaxOffset = (int)sqrt(t_floorAmount); calcSpiral(floorSpiralMaxOffset, floorSpiralMaxOffset); initFloors(); trick = 0.0F; diff --git a/src/samples/floors/objects/enemy.cpp b/src/samples/floors/objects/enemy.cpp index 57bf4b9..2e8aa42 100644 --- a/src/samples/floors/objects/enemy.cpp +++ b/src/samples/floors/objects/enemy.cpp @@ -16,6 +16,7 @@ #include #include #include +#include // ---- // Constructors/Destructors From a973c47321c656fc4ddee04f24cd61e9ab05089d Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 6 Feb 2021 18:21:11 +0100 Subject: [PATCH 18/24] set normals/sts as present in md2/dff --- src/engine/loaders/dff_loader.cpp | 2 ++ src/engine/loaders/md2_loader.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/engine/loaders/dff_loader.cpp b/src/engine/loaders/dff_loader.cpp index abddbcd..23f73d7 100644 --- a/src/engine/loaders/dff_loader.cpp +++ b/src/engine/loaders/dff_loader.cpp @@ -244,6 +244,8 @@ void DffLoader::readGeometryExtension(MeshFrame *o_frame, char **materialNames, { u32 facesCount = readDwordFromArrayLE(t_buffer, t_ptrPos); u32 materialIndex = readDwordFromArrayLE(t_buffer, t_ptrPos); + o_frame->getMaterial(i).setSTsPresent(true); + o_frame->getMaterial(i).setNormalsPresent(true); o_frame->getMaterial(i).allocateFaces(facesCount); o_frame->getMaterial(i).setName(materialNames[materialIndex]); for (u32 j = 0; j < facesCount; j++) diff --git a/src/engine/loaders/md2_loader.cpp b/src/engine/loaders/md2_loader.cpp index d7a8924..d459c00 100644 --- a/src/engine/loaders/md2_loader.cpp +++ b/src/engine/loaders/md2_loader.cpp @@ -138,6 +138,8 @@ MeshFrame *MD2Loader::load(u32 &o_framesCount, char *t_subpath, char *t_nameWith { for (u32 x = 0; x < framesCount; x++) { + resultFrames[x].getMaterial(0).setSTsPresent(true); + resultFrames[x].getMaterial(0).setNormalsPresent(true); resultFrames[x].getMaterial(0).setVertexFace((i * 3) + j, triangle->index_xyz[j]); resultFrames[x].getMaterial(0).setSTFace((i * 3) + j, triangle->index_st[j]); resultFrames[x].getMaterial(0).setNormalFace((i * 3) + j, triangle->index_xyz[j]); From c72393b236a8920517e336d209d281709ddfc011 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 6 Feb 2021 18:21:28 +0100 Subject: [PATCH 19/24] fixed asm reg alloc bug --- src/engine/models/mesh.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/models/mesh.cpp b/src/engine/models/mesh.cpp index 4f6364d..e4dd355 100644 --- a/src/engine/models/mesh.cpp +++ b/src/engine/models/mesh.cpp @@ -260,7 +260,8 @@ u32 Mesh::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals "r"(nextVerts[vertFaces[faceI]].xyz), "r"(nextVerts[vertFaces[faceI + 1]].xyz), "r"(nextVerts[vertFaces[faceI + 2]].xyz), - "f"(animState.interpolation)); + "f"(animState.interpolation) + : "$10"); } else { From e5c2aa15486b9c80d95c2b3928e2ac24388901af Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 6 Feb 2021 18:21:35 +0100 Subject: [PATCH 20/24] removed unecessary comment --- src/engine/modules/renderer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index a07f7f2..f554b82 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -328,7 +328,6 @@ void Renderer::draw(Mesh &t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) VECTOR normals[vertCount] __attribute__((aligned(16))); VECTOR coordinates[vertCount] __attribute__((aligned(16))); Texture *tex = textureRepo.getBySpriteOrMesh(material->getId()); - // printf("TexId:%d\n", tex->getId()); changeTexture(tex); vertCount = t_mesh.getDrawData(i, vertices, normals, coordinates, rotatedCamera); vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount, &textureBuffer, &material->color, !material->areSTsPresent()); From c0bb78f1c9931b4afb14ec76b6d6190e79ab6fa0 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 6 Feb 2021 18:26:09 +0100 Subject: [PATCH 21/24] added latest changes --- CHANGELOG.MD | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 496911c..caba760 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.?.?] - 2020-?-? +## [1.31.2] - 2021-02-06 ### Added - Id to MeshFrame @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved color from mesh to mesh material. - OBJ Loader refactor - Logic of loadFrom() +- Migrated to GCC9 (valid with latest PS2SDK) ### Removed - Removed MeshId from TextureLink, TextureRepository From 35fc8aea7345b095994c07128b6a1e06a4cd1831 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 6 Feb 2021 18:33:50 +0100 Subject: [PATCH 22/24] changed uris --- README.MD | 13 +++++-------- src/samples/dolphin/README.MD | 4 ++-- src/samples/floors/README.MD | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.MD b/README.MD index 1c03075..f3c2777 100644 --- a/README.MD +++ b/README.MD @@ -9,7 +9,7 @@ Logo -

Tyra - alpha 1.29.1

+

Tyra - alpha 1.31.2

Open source game engine for PlayStation 2™ @@ -45,10 +45,7 @@ ## About The Project -sample - -### Contributors wanted [![Discord](https://img.shields.io/badge/discord-Tyra-brightgreen?logo=discord)](https://discord.gg/NhhTmg3Gm5) -We will be grateful for any help. If you dont know PS2.. don't worry, we are open to explain how things work. +sample ### Samples * [Dolphin](https://github.com/h4570/tyra/tree/master/src/samples/dolphin) @@ -87,7 +84,7 @@ In our Discord channel, there is detailed tutorial which will help you with sett This is an example of how to list things you need to use the software. * PS2 DEV environment - [PS2DEV](https://github.com/ps2dev/ps2dev) -* At least #674b6f4 PS2SDK (01.12.2020) - [PS2SDK](https://github.com/ps2dev/ps2sdk) +* At least #e8e9edb PS2SDK (06.02.2021) - [PS2SDK](https://github.com/ps2dev/ps2sdk) * PS2 Emulator. For example [PCSX2](https://pcsx2.net/) ## Extra info @@ -98,7 +95,7 @@ This is an example of how to list things you need to use the software. ## Roadmap ### Roadmap for next master release: -[January 2021 Roadmap](https://github.com/h4570/tyra/projects/4) +[Next release roadmap](https://github.com/h4570/tyra/projects/4) ## Tyra team @@ -139,7 +136,7 @@ Distributed under the Apache License 2.0 License. See `LICENSE` for more informa Without these guys, everything would be harder: * Dr Henry Fortuna - for code sources * Rick Gaiser - for help and new GCC! -* Lukasz D.K. - for huge archive of PS2 stuff- +* Lukasz D.K. - for huge archive of PS2 stuff * Guilherme Lampert - for code sources * Jesper Svennevid, Daniel Collin - for openvcl's code samples * Whole PS2DEV team diff --git a/src/samples/dolphin/README.MD b/src/samples/dolphin/README.MD index 85b23e6..884ccc5 100644 --- a/src/samples/dolphin/README.MD +++ b/src/samples/dolphin/README.MD @@ -11,10 +11,10 @@ - Usage of draw() in array mode (for water tiles, very fast) ### Assets -[Download](http://apgcglz.cluster028.hosting.ovh.net/tyra/1.29.1/samples/dolphin/assets.zip) +[Download](http://apgcglz.cluster028.hosting.ovh.net/tyra/1.31.2/samples/dolphin/assets.zip) ### Screenshot [![Dolphin screenshot][dolphin-screenshot]](#) -[dolphin-screenshot]: http://apgcglz.cluster028.hosting.ovh.net/tyra/1.29.1/samples/dolphin/dolphin.gif +[dolphin-screenshot]: http://apgcglz.cluster028.hosting.ovh.net/tyra/1.31.2/samples/dolphin/dolphin.gif diff --git a/src/samples/floors/README.MD b/src/samples/floors/README.MD index 626159b..30d0602 100644 --- a/src/samples/floors/README.MD +++ b/src/samples/floors/README.MD @@ -10,10 +10,10 @@ - Usage of draw() in array mode (for floors, very fast) ### Assets -[Download](http://apgcglz.cluster028.hosting.ovh.net/tyra/1.29.1/samples/floors/assets.zip) +[Download](http://apgcglz.cluster028.hosting.ovh.net/tyra/1.31.2/samples/floors/assets.zip) ### Screenshot [![Floors screenshot][floors-screenshot]](#) -[floors-screenshot]: http://apgcglz.cluster028.hosting.ovh.net/tyra/1.29.1/samples/floors/floors.gif +[floors-screenshot]: http://apgcglz.cluster028.hosting.ovh.net/tyra/1.31.2/samples/floors/floors.gif From 4146df48a96de9ad99368d9e7c4e09843be49200 Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 6 Feb 2021 18:45:03 +0100 Subject: [PATCH 23/24] fixed audio playing - dirty way --- src/engine/include/modules/audio.hpp | 1 + src/engine/modules/audio.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/engine/include/modules/audio.hpp b/src/engine/include/modules/audio.hpp index be2709a..1899cd7 100644 --- a/src/engine/include/modules/audio.hpp +++ b/src/engine/include/modules/audio.hpp @@ -126,6 +126,7 @@ public: private: u8 songLoaded, volume, realVolume, songPlaying, songInLoop, songFinished; + u8 hack; // TODO std::vector songListeners; FILE *wav; audsrv_fmt_t format; diff --git a/src/engine/modules/audio.cpp b/src/engine/modules/audio.cpp index 0c8b052..f7b51c0 100644 --- a/src/engine/modules/audio.cpp +++ b/src/engine/modules/audio.cpp @@ -178,8 +178,20 @@ void Audio::startThread(FileService *t_fileService) /** Main thread loop */ void Audio::threadLoop() { - if (songPlaying) - songPlaying = 1; // GCC11: wtf? we need to put some code there, because song is not playing.. + // --- + // TODO - bug here, GCC11 is doing some optimizations and this method probably think that + // "songPlaying" is false + on real PS2 I see that program tries to turn on this + // method as rarely as possible (slow, flickering sound). On GCC 3.2.3 this one was fine lol!. + if (songPlaying) // HACK1 - im not proud of that + songPlaying = 1; + if (songLoaded) + songLoaded = 1; + if (hack == 1) // HACK2 - lets give some work to gcc lol + hack = 2; + else + hack = 1; + // --- + if (!songPlaying || !songLoaded) return; if (songFinished) From 8bd5476d6119fe4ddda0eab4163bcd8ede7ff43a Mon Sep 17 00:00:00 2001 From: h4570 Date: Sat, 6 Feb 2021 19:02:10 +0100 Subject: [PATCH 24/24] link fix --- CHANGELOG.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index caba760..7d58e4d 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -111,7 +111,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Makefile - Primitive floors sample -[1.?.?]: https://github.com/h4570/tyra/compare/v1.29.1-alpha...v1.?.?-alpha +[1.31.2]: https://github.com/h4570/tyra/compare/v1.29.1-alpha...v1.31.2-alpha [1.29.1]: https://github.com/h4570/tyra/compare/1.1.0...v1.29.1-alpha [1.1.0]: https://github.com/h4570/tyra/compare/1.0.0...1.1.0 [1.0.0]: https://github.com/h4570/tyra/compare/1.0.0