Optimize a bit
This commit is contained in:
parent
2241b4d635
commit
880ae3c805
6 changed files with 120 additions and 25 deletions
44
renderer.h
44
renderer.h
|
@ -151,7 +151,8 @@ S3L_Index _LCR_addMapVertex(S3L_Unit x, S3L_Unit y, S3L_Unit z)
|
|||
return LCR_renderer.mapModel->vertexCount - 1;
|
||||
}
|
||||
|
||||
// TODO: error print
|
||||
LCR_log("couldn't add map vertex!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -247,13 +248,18 @@ uint8_t _LCR_rendererCheckMapTriangleCover(const S3L_Index *t1,
|
|||
|
||||
uint8_t result = 0;
|
||||
int plane = -1;
|
||||
S3L_Unit *vertices[6];
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
if (LCR_renderer.mapVertices[3 * t1[0] + i] == LCR_renderer.mapVertices[3 * t1[1] + i] &&
|
||||
LCR_renderer.mapVertices[3 * t1[1] + i] == LCR_renderer.mapVertices[3 * t1[2] + i] &&
|
||||
LCR_renderer.mapVertices[3 * t1[2] + i] == LCR_renderer.mapVertices[3 * t2[0] + i] &&
|
||||
LCR_renderer.mapVertices[3 * t2[0] + i] == LCR_renderer.mapVertices[3 * t2[1] + i] &&
|
||||
LCR_renderer.mapVertices[3 * t2[1] + i] == LCR_renderer.mapVertices[3 * t2[2] + i])
|
||||
{
|
||||
vertices[i] = LCR_renderer.mapVertices + 3 * t1[i];
|
||||
vertices[3 + i] = LCR_renderer.mapVertices + 3 * t2[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
if (vertices[0][i] == vertices[1][i] && vertices[1][i] == vertices[2][i] &&
|
||||
vertices[2][i] == vertices[3][i] && vertices[3][i] == vertices[4][i] &&
|
||||
vertices[4][i] == vertices[5][i])
|
||||
{
|
||||
plane = i;
|
||||
break;
|
||||
|
@ -270,10 +276,10 @@ uint8_t _LCR_rendererCheckMapTriangleCover(const S3L_Index *t1,
|
|||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
points2D[i * 2] = LCR_renderer.mapVertices[3 * t1[i] + coordX];
|
||||
points2D[i * 2 + 1] = LCR_renderer.mapVertices[3 * t1[i] + coordY];
|
||||
points2D[6 + i * 2] = LCR_renderer.mapVertices[3 * t2[i] + coordX];
|
||||
points2D[6 + i * 2 + 1] = LCR_renderer.mapVertices[3 * t2[i] + coordY];
|
||||
points2D[i * 2] = vertices[i][coordX];
|
||||
points2D[i * 2 + 1] = vertices[i][coordY];
|
||||
points2D[6 + i * 2] = vertices[3 + i][coordX];
|
||||
points2D[6 + i * 2 + 1] = vertices[3 + i][coordY];
|
||||
}
|
||||
|
||||
points2D[12] = (4 * points2D[6] + 3 * points2D[8] + points2D[10]) / 8;
|
||||
|
@ -325,9 +331,18 @@ uint8_t _LCR_rendererCheckMapTriangleCover(const S3L_Index *t1,
|
|||
}
|
||||
}
|
||||
|
||||
// now swap both triangles and do it all again:
|
||||
|
||||
const S3L_Index *tmp = t1;
|
||||
t1 = t2;
|
||||
t2 = tmp;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
S3L_Unit *tmpCoord = vertices[i];
|
||||
vertices[i] = vertices[3 + i];
|
||||
vertices[3 + i] = tmpCoord;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,6 +356,8 @@ uint8_t _LCR_rendererCheckMapTriangleCover(const S3L_Index *t1,
|
|||
*/
|
||||
void _LCR_rendererCullHiddenMapTriangles(void)
|
||||
{
|
||||
LCR_log("culling invisible triangles");
|
||||
|
||||
int n = 0; // number of removed elements
|
||||
int i = 0;
|
||||
|
||||
|
@ -432,6 +449,8 @@ void _LCR_rendererCullHiddenMapTriangles(void)
|
|||
*/
|
||||
uint8_t _LCR_rendererBuildMapModel(void)
|
||||
{
|
||||
LCR_log("building map model");
|
||||
|
||||
uint8_t blockShapeBytes[LCR_MAP_BLOCK_SHAPE_MAX_BYTES];
|
||||
uint8_t blockShapeByteCount;
|
||||
|
||||
|
@ -439,6 +458,9 @@ uint8_t _LCR_rendererBuildMapModel(void)
|
|||
|
||||
for (int j = 0; j < LCR_currentMap.blockCount; ++j)
|
||||
{
|
||||
if ((j + 1) % LCR_SETTING_TRIANGLE_CULLING_PERIOD == 0)
|
||||
_LCR_rendererCullHiddenMapTriangles();
|
||||
|
||||
S3L_Unit originOffset = -1 * LCR_MAP_SIZE_BLOCKS / 2 * LCR_RENDERER_UNIT;
|
||||
S3L_Index triangleIndices[3];
|
||||
const uint8_t *block = LCR_currentMap.blocks + j * LCR_BLOCK_SIZE;
|
||||
|
@ -552,6 +574,8 @@ uint8_t _LCR_rendererBuildMapModel(void)
|
|||
|
||||
uint8_t LCR_rendererInit(void)
|
||||
{
|
||||
LCR_log("initializing renderer");
|
||||
|
||||
LCR_renderer.mapModel = LCR_renderer.models3D;
|
||||
|
||||
if (!_LCR_rendererBuildMapModel())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue