Decompile fn_16923 (UIWindow::AddRotatedSpriteCellOverlay)
Batch #6723 by eAthena: 0 byte-identical, 1 confirmed by peer review. - fn_16923 UIWindow::AddRotatedSpriteCellOverlay: logic confirmed by peer review Peer-reviewed-by: superintelligence, KWDev, Tanke Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
This commit is contained in:
parent
c2ee449a69
commit
5d68bdff24
2 changed files with 79 additions and 0 deletions
|
|
@ -100,3 +100,81 @@ void UIWindow::AddSpriteCellOverlay(
|
|||
|
||||
this->m_overlayPrimitives.push_back(primitive);
|
||||
}
|
||||
|
||||
// OFFSET: 0x00A7A5C0
|
||||
// FUNCTION: fn_16923
|
||||
void UIWindow::AddRotatedSpriteCellOverlay(
|
||||
int x, int y, int width, int height, const SpriteRleImage* image, const SpriteFrameCell* cell, const std::uint32_t* palette
|
||||
) {
|
||||
if (!width || !height || !image || !cell || !palette) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (UIWindow* window = this; window; window = window->parent) {
|
||||
x += window->geometry.x;
|
||||
y += window->geometry.y;
|
||||
}
|
||||
|
||||
RenderPrimitive* primitive = g_renderer->primitives.Acquire();
|
||||
SpriteAtlasRecord record{};
|
||||
|
||||
CTexture* texture = static_cast<CTexture*>(const_cast<void*>(image->unknown_0008));
|
||||
if (!texture) {
|
||||
texture = g_renderer->atlas.Find(image, palette, record);
|
||||
if (!texture) {
|
||||
texture = g_renderer->atlas.Insert(*GetRenderSystemHolder()->system, image, palette, record, g_serviceType, g_resourceReuseDelay);
|
||||
}
|
||||
} else {
|
||||
record.u0 = 0.0f;
|
||||
record.v0 = 0.0f;
|
||||
record.u1 = static_cast<float>(texture->ImageWidth()) / static_cast<float>(texture->TextureWidth());
|
||||
record.v1 = static_cast<float>(texture->ImageHeight()) / static_cast<float>(texture->TextureHeight());
|
||||
}
|
||||
primitive->texture = texture;
|
||||
|
||||
const int left = static_cast<int>(cell->x * static_cast<double>(cell->scaleX) + 1.0);
|
||||
const int right = static_cast<int>(((static_cast<std::int16_t>(image->unknown_0004) + 1) * image->width + cell->x) * static_cast<double>(cell->scaleX));
|
||||
const int top = static_cast<int>(cell->y * static_cast<double>(cell->scaleY));
|
||||
const int startX = (cell->mirrored & 1) ? right : left;
|
||||
const int endX = (cell->mirrored & 1) ? left : right;
|
||||
const float halfWidth = static_cast<float>(endX - startX) * 0.5f;
|
||||
const int bottom =
|
||||
static_cast<int>(((static_cast<std::int16_t>(image->unknown_0006) + 1) * image->height + cell->y) * static_cast<double>(cell->scaleY) + 1.0);
|
||||
const float halfHeight = static_cast<float>(bottom - top) * 0.5f;
|
||||
|
||||
const float corners[4][2] = {
|
||||
{-halfWidth, -halfHeight},
|
||||
{halfWidth, -halfHeight},
|
||||
{-halfWidth, halfHeight},
|
||||
{halfWidth, halfHeight},
|
||||
};
|
||||
const float centerX = static_cast<float>(x + startX) + halfWidth;
|
||||
const float centerY = static_cast<float>(y + top) + halfHeight;
|
||||
const float angle = static_cast<float>(cell->unknown_001C) / 180.0f * 3.141592f;
|
||||
|
||||
const unsigned char* rgba = reinterpret_cast<const unsigned char*>(&cell->color);
|
||||
RenderVertex* vertices = primitive->quad;
|
||||
for (unsigned int i = 0; i < 4; ++i) {
|
||||
const float cornerX = corners[i][0];
|
||||
const float cornerY = corners[i][1];
|
||||
vertices[i].x = ClientCos(angle) * cornerX - ClientSin(angle) * cornerY + centerX + 0.5f;
|
||||
vertices[i].y = ClientCos(angle) * cornerY + ClientSin(angle) * cornerX + centerY + 0.5f;
|
||||
vertices[i].z = 0.000001f;
|
||||
vertices[i].rhw = 0.999999f;
|
||||
vertices[i].diffuse = (((((rgba[3] << 8) | rgba[0]) << 8) | rgba[1]) << 8) | rgba[2];
|
||||
}
|
||||
vertices[0].u = record.u0;
|
||||
vertices[0].v = record.v0;
|
||||
vertices[1].u = record.u1;
|
||||
vertices[1].v = record.v0;
|
||||
vertices[2].u = record.u0;
|
||||
vertices[2].v = record.v1;
|
||||
vertices[3].u = record.u1;
|
||||
vertices[3].v = record.v1;
|
||||
|
||||
for (UIWindow* window = this->parent; window; window = window->parent) {
|
||||
if (!window->parent) {
|
||||
window->m_overlayPrimitives.push_back(primitive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue