aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 99ee5ae9d62d80333c445d0662029f8a27c0c26a
parent 1144050fe2e9bf982dc7e57d7dcc8ef2a767c9a8
Author: anon <anon@example.com>
Date:   Fri, 16 Oct 2026 06:37:54 +0000

Support emissive material source with Direct3D pixel comparisons

Diffstat:
Mdecompiled/runtime/linux_graphics.c | 13+++++++++----
Mdecompiled/runtime/linux_window.c | 4++--
Mdecompiled/tests/devices.c | 7++++++-
Mtools/reconstruction/test_portable_devices.py | 4++--
4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/decompiled/runtime/linux_graphics.c b/decompiled/runtime/linux_graphics.c @@ -64,6 +64,7 @@ static struct device_object { uint32_t texture_factor; uint32_t specular; float specular_power; + uint32_t emissive_source; uint32_t ambient, normalize_normals, material[17], viewport[6], transforms[5][16]; int scene; struct draw_object *owner; @@ -1568,7 +1569,8 @@ static uint32_t device_state(struct device_object *device, uint32_t state) case 140: return device->fog_vertex_mode; case 143: return device->normalize_normals; case 138: case 144: - case 147: case 148: case 151: case 152: return 0; + case 147: case 151: case 152: return 0; + case 148: return device->emissive_source; case 146: return 2; /* Specular material uses vertex color 2. */ case 7: return 1; /* Z enable. */ case 137: return device->lighting; @@ -1665,6 +1667,7 @@ static void device_set_state(void) else if (state == 139) device->ambient = value; else if (state == 140 && (value == 0 || value == 3)) device->fog_vertex_mode = value; else if (state == 143 && value <= 1) device->normalize_normals = value; + else if (state == 148 && value <= 2) device->emissive_source = value; else if (state == 19 && (value == 1 || value == 2 || value == 3 || value == 5 || value == 6)) device->source_blend = value; else if (state == 20 && (value == 1 || value == 2 || value == 3 || value == 5 || value == 6)) device->destination_blend = value; else if (value != device_state(device, state)) { @@ -1688,11 +1691,11 @@ static float normalize_vector(float vector[3]) return length; } -static void light_vertex(struct device_object *device, const float position[4], const float normal[3], const float diffuse_color[4], float color[4], float specular[3]) +static void light_vertex(struct device_object *device, const float position[4], const float normal[3], const float diffuse_color[4], const float emissive_color[3], float color[4], float specular[3]) { const float *material = (const float *)device->material; for (unsigned j = 0; j < 3; ++j) - color[j] = material[12 + j] + material[4 + j] * ((device->ambient >> (16 - j * 8)) & 255) / 255.0f; + color[j] = emissive_color[j] + material[4 + j] * ((device->ambient >> (16 - j * 8)) & 255) / 255.0f; color[3] = diffuse_color[3]; for (struct device_light *light = device->lights; light; light = light->next) { if (!light->enabled) continue; @@ -1801,7 +1804,9 @@ static void draw_primitive(struct device_object *device, uint32_t primitive, uin diffuse[3] = (color >> 24) / 255.0f; } else if (device->lighting) memcpy(diffuse, device->material, 16); else for (unsigned j = 0; j < 4; ++j) diffuse[j] = 1; - if (device->lighting) light_vertex(device, camera, normal, diffuse, vertices[i].color, vertices[i].specular); + /* Missing vertex color fields fall back to the material's emissive RGB. */ + const float *emissive = device->emissive_source == 1 && (fvf & 0x40) ? diffuse : (const float *)device->material + 12; + if (device->lighting) light_vertex(device, camera, normal, diffuse, emissive, vertices[i].color, vertices[i].specular); else memcpy(vertices[i].color, diffuse, 16); vertices[i].fog = 0; if (device->fog_vertex_mode == 3) { diff --git a/decompiled/runtime/linux_window.c b/decompiled/runtime/linux_window.c @@ -1028,9 +1028,9 @@ static int key_character(uint32_t key, int shift, int control, int alt, int caps } return -1; } - if (key >= '0' && key <= '9') return shift ? ")!@#$%^&*("[key - '0'] : key; + if (key >= '0' && key <= '9') return shift ? ")!@#$%^&*("[key - '0'] : (int)key; if (key == 3 || key == 8 || key == 9 || key == 13 || key == 27 || key == 32) return key; - if (key >= 0x60 && key <= 0x69) return shift ? -1 : key - 0x60 + '0'; + if (key >= 0x60 && key <= 0x69) return shift ? -1 : (int)key - 0x60 + '0'; if (key == 0x6a) return '*'; if (key == 0x6b) return '+'; if (key >= 0x6d && key <= 0x6f) return key - 0x6d + '-'; diff --git a/decompiled/tests/devices.c b/decompiled/tests/devices.c @@ -565,6 +565,7 @@ static void indexed_vertex_buffers_use_relative_indices(uint32_t draw, uint32_t static void untransformed_vertices_apply_camera_and_lighting(uint32_t device, uint32_t target, FILE *file) { + for (unsigned emissive = 0; emissive < 3; ++emissive) for (unsigned specular = 0; specular < 5; ++specular) for (unsigned colored = 0; colored <= 2; ++colored) for (unsigned sample = 0; sample < 17; ++sample) { uint32_t input = workspace() + 512, data = workspace() + 256, desc = workspace() + 128; @@ -578,6 +579,8 @@ static void untransformed_vertices_apply_camera_and_lighting(uint32_t device, ui material[16] = specular == 2 || specular == 4 ? 0 : specular == 3 ? 2 : 8; light[5] = .5f; light[6] = .6f; light[7] = .7f; assert(!invoke(device, 20, 3, 29u, specular ? 1u : 0u)); + assert(!invoke(device, 20, 3, 148u, emissive)); + assert(!invoke(device, 21, 3, 148u, data) && *memory(data) == emissive); uint32_t type = sample >= 9 && sample <= 10 ? 1 : sample >= 11 && sample <= 12 ? 2 : 3; if (sample == 1) { material[12] = .2f; material[13] = .4f; material[14] = .6f; } if (sample == 4 || sample == 5) for (unsigned i = 0; i < 3; ++i) vertices[i][5] = -2; @@ -626,7 +629,8 @@ static void untransformed_vertices_apply_camera_and_lighting(uint32_t device, ui assert(!invoke(target, 25, 5, 0u, desc, 0x11u, 0u)); uint32_t pixels = *memory(desc + 36), pitch = *memory(desc + 16); if (sample == 0) assert((*memory(pixels + 8 * pitch + 32) & 0xffffff) == (colored ? 0x4060a0 : 0xffffff)); - if (sample == 1) assert((*memory(pixels + 8 * pitch + 32) & 0xffffff) == 0x336699); + if (sample == 1) assert((*memory(pixels + 8 * pitch + 32) & 0xffffff) == + (emissive == 1 && colored ? 0x4060a0 : 0x336699)); unsigned char rgb[32 * 32 * 3]; for (unsigned y = 0; y < 32; ++y) for (unsigned x = 0; x < 32; ++x) { uint32_t pixel = *memory(pixels + y * pitch + x * 4); @@ -645,6 +649,7 @@ static void untransformed_vertices_apply_camera_and_lighting(uint32_t device, ui assert(!invoke(device, 20, 3, 140u, 0u)); assert(!invoke(device, 20, 3, 27u, 0u)); assert(!invoke(device, 20, 3, 29u, 0u)); + assert(!invoke(device, 20, 3, 148u, 0u)); } static void initial_device_states(uint32_t device) diff --git a/tools/reconstruction/test_portable_devices.py b/tools/reconstruction/test_portable_devices.py @@ -25,8 +25,8 @@ actual = subprocess.check_output(wsl + ["env", "GALLIUM_DRIVER=d3d12", linux_wor assert actual == expected, (expected, actual) windows_pixels = (work / "reference.rgb").read_bytes() linux_pixels = (work / "native.rgb").read_bytes() -assert len(windows_pixels) == len(linux_pixels) == 6426624 +assert len(windows_pixels) == len(linux_pixels) == 7993344 error = max(abs(a - b) for a, b in zip(windows_pixels, linux_pixels)) assert error <= 1, error print("Windows == Linux: " + actual.strip()) -print("All 2142208 pixels agree within one 8-bit channel step; maximum error:", error) +print("All 2664448 pixels agree within one 8-bit channel step; maximum error:", error)