JeremyAnsel / xwa_ddraw_d3d11

Direct3D 11 implementation of DDraw.dll for XWA
MIT License
42 stars 20 forks source link

The std::map cache must be reset each time a new ship is loaded in the Tech Room #6

Open Prof-Butts opened 2 years ago

Prof-Butts commented 2 years ago

When a new ship is loaded in the Tech Room, the hash for the new meshes may sometimes collide with the old meshes stored in _meshVerticesViews, _meshNormalsViews, _meshTextureCoordsViews, _vertexBuffers, _triangleBuffers and _vertexCounters, causing artifacts.

We just need to call FlightStart every time a new ship is loaded to reset these maps.

One way to do this is by counting the number of draw calls executed during one frame. Then, in SceneEnd() we can call FlightStart() to reset the cache if we're in the Tech Room and the number of draw calls changed since the last frame. This is an example of how I fixed this problem in my branch:

https://github.com/Prof-Butts/xwa_ddraw_d3d11/blob/d3d_hook_merge/impl11/ddraw/XwaD3dRendererHook.cpp#L191

To reproduce this problem, as soon as the game begins, load the Tech Room, then click on "Cycle Craft" 9 times or until you reach the Preybird Fighter. Then click one time on "Cycle by Type" so that the the shuttles are loaded. Then click on "Cycle Craft" 11 times or until you reach the "System Patrol Craft". This ship will display broken geometry.

JeremyAnsel commented 2 years ago

Hello, I've added a call to the FlightStart function when an opt file is loaded in bf1ae6111789bc4de15fcbd57c7a486b11993747

Prof-Butts commented 2 years ago

Thank you Jeremy. Outstanding work, as usual.