-
Notifications
You must be signed in to change notification settings - Fork 245
tweak(scorch): Increase scorch buffers to 16-bit limit #3186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
73f46a9
8e9e304
3ebf358
2482a6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,16 +162,17 @@ void W3DScorch::updateScorches(WorldHeightMap& map) | |
| // TheSuperHackers @info Scorches are written in reverse order to ensure that the last added scorches fit in the buffers. | ||
| for (std::deque<TScorch>::reverse_iterator it = m_scorches.rbegin(); it != m_scorches.rend(); ++it) | ||
| { | ||
| if (!writeScorchToBuffer(*it, map, diffuse, | ||
| vb + m_curNumScorchVertices, ib + m_curNumScorchIndices)) | ||
| if (writeScorchToBuffer(*it, map, diffuse, | ||
| vb + m_curNumScorchVertices, ib + m_curNumScorchIndices) == SCORCH_BUFFER_FULL) | ||
| { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Bool W3DScorch::writeScorchToBuffer(const TScorch& scorch, WorldHeightMap& map, UnsignedInt diffuse, | ||
| VertexFormatXYZDUV1* curVb, UnsignedShort* curIb) | ||
| W3DScorch::WriteScorchResult W3DScorch::writeScorchToBuffer(const TScorch& scorch, WorldHeightMap& map, | ||
| UnsignedInt diffuse, VertexFormatXYZDUV1* curVb, | ||
| UnsignedShort* curIb) | ||
| { | ||
| Real radius = scorch.radius; | ||
| Vector3 loc = scorch.location; | ||
|
|
@@ -196,14 +197,28 @@ Bool W3DScorch::writeScorchToBuffer(const TScorch& scorch, WorldHeightMap& map, | |
| { | ||
| maxY = map.getYExtent() - map.getBorderSizeInline(); | ||
| } | ||
|
|
||
| const Int vertexCountX = maxX - minX; | ||
| const Int vertexCountY = maxY - minY; | ||
| if (vertexCountX <= 0 || vertexCountY <= 0) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under what conditions does this hit? Maybe it should be an assert instead?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In ordinary gameplay I would not expect scorches outside the map, but it can happen in World Builder. This is just an early return, without it it would run through the for loops and end up writing nothing to the buffers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe return enum values to make the return meaning more explicit? |
||
| { | ||
| return SCORCH_SKIPPED; | ||
| } | ||
|
|
||
| const Int requiredVertices = vertexCountX * vertexCountY; | ||
| const Int requiredIndices = 6 * (vertexCountX - 1) * (vertexCountY - 1); | ||
| if (m_curNumScorchVertices + requiredVertices > MAX_SCORCH_VERTEX || | ||
| m_curNumScorchIndices + requiredIndices > MAX_SCORCH_INDEX) | ||
| { | ||
| return SCORCH_BUFFER_FULL; | ||
| } | ||
|
|
||
| Int startVertex = m_curNumScorchVertices; | ||
| Int i, j; | ||
| for (j = minY; j < maxY; j++) | ||
| { | ||
| for (i = minX; i < maxX; i++) | ||
| { | ||
| if (m_curNumScorchVertices >= MAX_SCORCH_VERTEX) | ||
| return false; | ||
| curVb->diffuse = diffuse; | ||
| Real theZ = amtToFloat + getMapHeight(map, i, j); | ||
| // The scorchmarks are spaced out by 1.5 in the texture. | ||
|
|
@@ -225,8 +240,6 @@ Bool W3DScorch::writeScorchToBuffer(const TScorch& scorch, WorldHeightMap& map, | |
| { | ||
| for (i = 0; i < maxX - minX - 1; i++) | ||
| { | ||
| if (m_curNumScorchIndices + 6 > MAX_SCORCH_INDEX) | ||
| return false; | ||
| Int xNdx = i + minX + map.getBorderSizeInline(); | ||
| Int yNdx = j + minY + map.getBorderSizeInline(); | ||
| Bool flipForBlend = map.getFlipState(xNdx, yNdx); | ||
|
|
@@ -257,5 +270,5 @@ Bool W3DScorch::writeScorchToBuffer(const TScorch& scorch, WorldHeightMap& map, | |
| } | ||
| } | ||
|
|
||
| return true; | ||
| return SCORCH_WRITTEN; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why the ratio is 2 to 1 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The precise ratio is a maximum of 22844 vertices needed for 65535 indices (more indices than vertices because of vertex sharing), and 32768 is the nearest power of two up from 22844.
Actually 65535/2 is wrong and will be off by one due to rounding down, will correct that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected 3 indices for 1 vertex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on the size of the scorch, for large scorches an inside vertex of the mesh is typically shared by 6 surrounding triangles and we get an average ratio of 6:1, while for small scorches the boundaries become more important where we have less vertex sharing (max 2 triangles in corners, max 4 at edges) and we see the ratio shrinking towards 3:1. The 32768 vertex limit gives a safe value with some margin.