From ab69ba28e39c6d0501561ebbb5ab9ffc381f65ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Sobczy=C5=84ski?= Date: Thu, 29 Oct 2020 19:23:03 +0100 Subject: [PATCH] removed unecessary colors arr --- src/engine/include/models/dff_model.hpp | 4 ++-- src/engine/include/models/md2_model.hpp | 2 +- src/engine/include/models/mesh.hpp | 2 +- src/engine/include/models/obj_model.hpp | 2 +- src/engine/include/modules/gif_sender.hpp | 2 +- src/engine/include/modules/vif_sender.hpp | 4 ++-- src/engine/models/dff_model.cpp | 11 +++------ src/engine/models/md2_model.cpp | 7 +----- src/engine/models/mesh.cpp | 8 +++---- src/engine/models/obj_model.cpp | 9 ++------ src/engine/modules/gif_sender.cpp | 28 +++++++++++++++++------ src/engine/modules/renderer.cpp | 16 ++++++------- src/engine/modules/vif_sender.cpp | 6 ++--- 13 files changed, 49 insertions(+), 52 deletions(-) diff --git a/src/engine/include/models/dff_model.hpp b/src/engine/include/models/dff_model.hpp index 0f04bfc..38ebad6 100644 --- a/src/engine/include/models/dff_model.hpp +++ b/src/engine/include/models/dff_model.hpp @@ -24,11 +24,11 @@ public: DffModel(); ~DffModel(); - u32 getDrawData(u32 splitIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled); + u32 getDrawData(u32 splitIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled); RwClump clump; private: - void fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, u8 geometry, u32 t_getI, u32 t_setI); + void fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, u8 geometry, u32 t_getI, u32 t_setI); u8 isMemoryAllocated; }; diff --git a/src/engine/include/models/md2_model.hpp b/src/engine/include/models/md2_model.hpp index e57a178..1d4cbda 100644 --- a/src/engine/include/models/md2_model.hpp +++ b/src/engine/include/models/md2_model.hpp @@ -38,7 +38,7 @@ public: char *filename; MD2Model(char *t_md2File); ~MD2Model(); - u32 getCurrentFrameData(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled); + u32 getCurrentFrameData(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled); void allocateMemory(); private: diff --git a/src/engine/include/models/mesh.hpp b/src/engine/include/models/mesh.hpp index 4189137..aa5ead6 100644 --- a/src/engine/include/models/mesh.hpp +++ b/src/engine/include/models/mesh.hpp @@ -48,7 +48,7 @@ public: void playAnimation(u32 t_startFrame, u32 t_endFrame); u32 getVertexCount(); void setAnimSpeed(float t_value); - u32 getDrawData(u32 splitIndex, VECTOR *t_vertices, VECTOR *t_normals, VECTOR *t_coordinates, VECTOR *t_colors, Vector3 &t_cameraPos); + u32 getDrawData(u32 splitIndex, VECTOR *t_vertices, VECTOR *t_normals, VECTOR *t_coordinates, Vector3 &t_cameraPos); u8 isInFrustum(Plane *t_frustumPlanes); u8 isMd2Loaded, isObjLoaded, isDffLoaded, isSpecInitialized; diff --git a/src/engine/include/models/obj_model.hpp b/src/engine/include/models/obj_model.hpp index faac561..cafeef2 100644 --- a/src/engine/include/models/obj_model.hpp +++ b/src/engine/include/models/obj_model.hpp @@ -55,7 +55,7 @@ public: ObjModel(char *t_objFile); ~ObjModel(); void animate(); - u32 getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled); + u32 getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled); u32 getFacesCount(); u8 isMemoryAllocated; diff --git a/src/engine/include/modules/gif_sender.hpp b/src/engine/include/modules/gif_sender.hpp index e7c1385..a154b16 100644 --- a/src/engine/include/modules/gif_sender.hpp +++ b/src/engine/include/modules/gif_sender.hpp @@ -54,7 +54,7 @@ private: MATRIX localWorld, localScreen, localLight; u32 calc3DObject(Matrix t_perspective, Mesh &t_mesh, RenderData *t_renderData, LightBulb *t_bulbs, u16 t_bulbsCount); - void convertCalcs(u32 t_vertCount, VECTOR *t_vertices, VECTOR *t_colors, VECTOR *t_sts, u8 t_alpha); + 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/vif_sender.hpp b/src/engine/include/modules/vif_sender.hpp index 9aab112..b03cf7d 100644 --- a/src/engine/include/modules/vif_sender.hpp +++ b/src/engine/include/modules/vif_sender.hpp @@ -28,10 +28,10 @@ public: ~VifSender(); // TODO refactor - void drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, VECTOR *colors, Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount); + 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); private: - void drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_colors, VECTOR *t_coordinates, prim_t *t_prim); + void drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim); MATRIX localWorld, localScreen; VECTOR position, rotation; diff --git a/src/engine/models/dff_model.cpp b/src/engine/models/dff_model.cpp index 191cbe5..df520d6 100644 --- a/src/engine/models/dff_model.cpp +++ b/src/engine/models/dff_model.cpp @@ -24,18 +24,18 @@ DffModel::~DffModel() {} // Methods // ---- -u32 DffModel::getDrawData(u32 splitIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled) +u32 DffModel::getDrawData(u32 splitIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled) { u32 result = 0; for (u32 i = 0; i < clump.geometryList.geometries[0].extension.materialSplit.splitInformation[splitIndex].faceIndex; i++) - fillNextFace(o_vertices, o_normals, o_coordinates, o_colors, 0, + fillNextFace(o_vertices, o_normals, o_coordinates, 0, clump.geometryList.geometries[0].extension.materialSplit.splitInformation[splitIndex].vertexInformation[i].vertex1, result++); return result; } -void DffModel::fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, u8 geometry, u32 t_getI, u32 t_setI) +void DffModel::fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, u8 geometry, u32 t_getI, u32 t_setI) { o_vertices[t_setI][0] = clump.geometryList.geometries[geometry].data.vertexInformation[t_getI].x; o_vertices[t_setI][1] = clump.geometryList.geometries[geometry].data.vertexInformation[t_getI].y; @@ -51,9 +51,4 @@ void DffModel::fillNextFace(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coo o_coordinates[t_setI][1] = 1.0F - clump.geometryList.geometries[geometry].data.textureMappingInformation[t_getI].v; o_coordinates[t_setI][2] = 1.0F; o_coordinates[t_setI][3] = 1.0F; - - o_colors[t_setI][0] = 1.0F; - o_colors[t_setI][1] = 1.0F; - o_colors[t_setI][2] = 1.0F; - o_colors[t_setI][3] = 1.0F; } diff --git a/src/engine/models/md2_model.cpp b/src/engine/models/md2_model.cpp index 3267981..505bbaf 100644 --- a/src/engine/models/md2_model.cpp +++ b/src/engine/models/md2_model.cpp @@ -53,7 +53,7 @@ MD2Model::~MD2Model() // Methods // ---- -u32 MD2Model::getCurrentFrameData(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled) +u32 MD2Model::getCurrentFrameData(VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled) { u32 i = 0; animState.interpolation += animState.speed; @@ -109,11 +109,6 @@ u32 MD2Model::getCurrentFrameData(VECTOR *o_vertices, VECTOR *o_normals, VECTOR o_coordinates[i][1] = 1.0F - coordinates[CURR_COORD].y; o_coordinates[i][2] = 1.0F; o_coordinates[i][3] = 1.0F; - - o_colors[i][0] = 1.0F; - o_colors[i][1] = 1.0F; - o_colors[i][2] = 1.0F; - o_colors[i][3] = 1.0F; i++; } } diff --git a/src/engine/models/mesh.cpp b/src/engine/models/mesh.cpp index 680c491..ce57d77 100644 --- a/src/engine/models/mesh.cpp +++ b/src/engine/models/mesh.cpp @@ -208,14 +208,14 @@ void Mesh::loadTextures(char *t_subfolder, char *t_extension) } // TODO refactor -u32 Mesh::getDrawData(u32 splitIndex, VECTOR *t_vertices, VECTOR *t_normals, VECTOR *t_coordinates, VECTOR *t_colors, Vector3 &t_cameraPos) +u32 Mesh::getDrawData(u32 splitIndex, VECTOR *t_vertices, VECTOR *t_normals, VECTOR *t_coordinates, Vector3 &t_cameraPos) { if (isMd2Loaded) - return md2->getCurrentFrameData(t_vertices, t_normals, t_coordinates, t_colors, t_cameraPos, scale, shouldBeBackfaceCulled); + return md2->getCurrentFrameData(t_vertices, t_normals, t_coordinates, t_cameraPos, scale, shouldBeBackfaceCulled); else if (isObjLoaded) - return obj->getDrawData(splitIndex, t_vertices, t_normals, t_coordinates, t_colors, t_cameraPos, scale, shouldBeBackfaceCulled); + return obj->getDrawData(splitIndex, t_vertices, t_normals, t_coordinates, t_cameraPos, scale, shouldBeBackfaceCulled); else if (isDffLoaded) - return dff->getDrawData(splitIndex, t_vertices, t_normals, t_coordinates, t_colors, t_cameraPos, scale, shouldBeBackfaceCulled); + return dff->getDrawData(splitIndex, t_vertices, t_normals, t_coordinates, t_cameraPos, scale, shouldBeBackfaceCulled); PRINT_ERR("Can't get draw data, because no 3D model was loaded!"); return 0; } diff --git a/src/engine/models/obj_model.cpp b/src/engine/models/obj_model.cpp index a49c620..65ebe92 100644 --- a/src/engine/models/obj_model.cpp +++ b/src/engine/models/obj_model.cpp @@ -72,7 +72,7 @@ void ObjModel::animate() } } -u32 ObjModel::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, VECTOR *o_colors, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled) +u32 ObjModel::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_normals, VECTOR *o_coordinates, Vector3 &t_cameraPos, float t_scale, u8 t_shouldBeBackfaceCulled) { #define CURR_FRAME frames[animState.currentFrame] #define NEXT_FRAME frames[animState.nextFrame] @@ -107,12 +107,7 @@ u32 ObjModel::getDrawData(u32 t_materialIndex, VECTOR *o_vertices, VECTOR *o_nor o_coordinates[addedFaces][0] = CURR_FRAME.coordinates[MATERIAL.getStFace(matI + vertI)].x; o_coordinates[addedFaces][1] = CURR_FRAME.coordinates[MATERIAL.getStFace(matI + vertI)].y; o_coordinates[addedFaces][2] = 1.0F; - o_coordinates[addedFaces][3] = 1.0F; - - o_colors[addedFaces][0] = 1.0F; - o_colors[addedFaces][1] = 1.0F; - o_colors[addedFaces][2] = 1.0F; - o_colors[addedFaces++][3] = 1.0F; + o_coordinates[addedFaces++][3] = 1.0F; } } return addedFaces; diff --git a/src/engine/modules/gif_sender.cpp b/src/engine/modules/gif_sender.cpp index 2c8d04c..16fbc12 100644 --- a/src/engine/modules/gif_sender.cpp +++ b/src/engine/modules/gif_sender.cpp @@ -177,7 +177,7 @@ u32 GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, RenderData *t_re VECTOR *normals = new VECTOR[vertexCount]; VECTOR *coordinates = new VECTOR[vertexCount]; VECTOR *colors = new VECTOR[vertexCount]; - vertexCount = t_mesh.getDrawData(0, vertices, normals, coordinates, colors, *t_renderData->cameraPosition); + vertexCount = t_mesh.getDrawData(0, vertices, normals, coordinates, *t_renderData->cameraPosition); xyz = new xyz_t[vertexCount]; rgbaq = new color_t[vertexCount]; @@ -195,7 +195,7 @@ u32 GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, RenderData *t_re if (SHOULD_BE_LIGHTED) create_local_light(localLight, rotation); - // I cant put perspective from renderData here. PS2SDK bug? + // I cant put perspective from renderData here. ee-gcc bug? create_local_screen(localScreen, localWorld, t_renderData->worldView->data, t_perspective.data); if (SHOULD_BE_LIGHTED) @@ -212,27 +212,41 @@ u32 GifSender::calc3DObject(Matrix t_perspective, Mesh &t_mesh, RenderData *t_re calculate_lights(lights, vertexCount, normals, lightDirections, lightColors, lightTypes, lightsCount); - calculate_colours(colors, vertexCount, colors, lights); + 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]); + vector_clamp(colors[i], colors[i], 0.00f, 1.99f); + } delete[] lightDirections; delete[] lightColors; delete[] lightTypes; delete[] lights; } + 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; + } calculate_vertices(vertices, vertexCount, vertices, localScreen); - convertCalcs(vertexCount, vertices, colors, coordinates, t_mesh.color.a); + convertCalcs(vertexCount, vertices, colors, coordinates, t_mesh.color); delete[] vertices; delete[] normals; - delete[] coordinates; delete[] colors; + delete[] coordinates; return vertexCount; } -void GifSender::convertCalcs(u32 t_vertexCount, VECTOR *t_vertices, VECTOR *t_colors, VECTOR *t_sts, u8 t_alpha) +void GifSender::convertCalcs(u32 t_vertexCount, VECTOR *t_vertices, VECTOR *t_colors, VECTOR *t_sts, color_t &t_color) { // TODO get this via screensettings const s32 centerX = ftoi4(2048); @@ -254,7 +268,7 @@ void GifSender::convertCalcs(u32 t_vertexCount, VECTOR *t_vertices, VECTOR *t_co rgbaq[i].r = (u8)(t_colors[i][0] * 128.0F); rgbaq[i].g = (u8)(t_colors[i][1] * 128.0F); rgbaq[i].b = (u8)(t_colors[i][2] * 128.0F); - rgbaq[i].a = t_alpha; + rgbaq[i].a = t_color.a; rgbaq[i].q = q; } } diff --git a/src/engine/modules/renderer.cpp b/src/engine/modules/renderer.cpp index e70a1f1..e02a72e 100644 --- a/src/engine/modules/renderer.cpp +++ b/src/engine/modules/renderer.cpp @@ -143,9 +143,9 @@ void Renderer::drawByPath3(Mesh **t_meshes, u16 t_amount, LightBulb *t_bulbs, u1 void Renderer::drawByPath3(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) { beginFrameIfNeeded(); + changeTexture(t_mesh, 0); gifSender->initPacket(context); // TODO - changeTexture(t_mesh, 0); gifSender->addObjects(&renderData, &t_mesh, 1, t_bulbs, t_bulbsCount); gifSender->sendPacket(); draw_wait_finish(); @@ -179,35 +179,33 @@ void Renderer::draw(Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) VECTOR *vertices = new VECTOR[vertCount]; VECTOR *normals = new VECTOR[vertCount]; VECTOR *coordinates = new VECTOR[vertCount]; - VECTOR *colors = new VECTOR[vertCount]; if (t_mesh->isObjLoaded) { t_mesh->obj->animate(); for (u32 i = 0; i < t_mesh->obj->frames[0].materialsCount; i++) { changeTexture(t_mesh, i); - vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, colors, *renderData.cameraPosition); - vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, colors, t_mesh, t_bulbs, t_bulbsCount); + vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition); + vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount); } } else if (t_mesh->isMd2Loaded) { changeTexture(t_mesh, 0); - vertCount = t_mesh->getDrawData(0, vertices, normals, coordinates, colors, *renderData.cameraPosition); - vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, colors, t_mesh, t_bulbs, t_bulbsCount); + vertCount = t_mesh->getDrawData(0, vertices, normals, coordinates, *renderData.cameraPosition); + vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount); } else if (t_mesh->isDffLoaded) for (u32 i = 0; i < t_mesh->dff->clump.geometryList.geometries[0].extension.materialSplit.header.splitCount; i++) { const u32 currentTexI = t_mesh->dff->clump.geometryList.geometries[0].extension.materialSplit.splitInformation[i].materialIndex; changeTexture(t_mesh, currentTexI); - vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, colors, *renderData.cameraPosition); - vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, colors, t_mesh, t_bulbs, t_bulbsCount); + vertCount = t_mesh->getDrawData(i, vertices, normals, coordinates, *renderData.cameraPosition); + vifSender->drawMesh(&renderData, perspective, vertCount, vertices, normals, coordinates, t_mesh, t_bulbs, t_bulbsCount); } delete[] vertices; delete[] normals; delete[] coordinates; - delete[] colors; } /** PATH1 Many */ diff --git a/src/engine/modules/vif_sender.cpp b/src/engine/modules/vif_sender.cpp index 6bd9f4e..4035989 100644 --- a/src/engine/modules/vif_sender.cpp +++ b/src/engine/modules/vif_sender.cpp @@ -37,7 +37,7 @@ VifSender::~VifSender() {} // Methods // ---- -void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 vertCount2, VECTOR *vertices, VECTOR *normals, VECTOR *coordinates, VECTOR *colors, Mesh *t_mesh, LightBulb *t_bulbs, u16 t_bulbsCount) +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) { if (t_mesh->shouldBeFrustumCulled == 1 && !t_mesh->isInFrustum(t_renderData->frustumPlanes)) return; @@ -60,7 +60,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, colors, coordinates, t_renderData->prim); + drawVertices(t_mesh, i, endI, vertices, coordinates, t_renderData->prim); if (endI == vertCount2) // if there are no more vertices to draw, break { i = vertCount2; @@ -74,7 +74,7 @@ void VifSender::drawMesh(RenderData *t_renderData, Matrix t_perspective, u32 ver } /** Draw using PATH1 */ -void VifSender::drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_colors, VECTOR *t_coordinates, prim_t *t_prim) +void VifSender::drawVertices(Mesh *t_mesh, u32 t_start, u32 t_end, VECTOR *t_vertices, VECTOR *t_coordinates, prim_t *t_prim) { const u32 vertCount = t_end - t_start; vu1.addListBeginning();