Recently, we have to work on Code The original directx8.1sdk library in is upgraded to 9.0.
The logic is as follows:
I. Unified naming
The internal details of D8 and D9 have changed a lot, but on the surface, the type function names of D8 and D9 have more or less
Difference, in order to integrate the previous Code, if the type name is changed one by one, the amount of code changes will be very huge. Macro naming
This will save a lot of time, for example:
# Ifdef d3dx9
# Include <d3dx9. h>
Typedef idirect3ddevice9 device;
Typedef idirect3d9 direct3d;
Typedef idirect3dvertexbuffer9 vertexbuffer;
Typedef idirect3dindexbuffer9 indexbuffer;
Typedef idirect3dtexture9 texture;
Typedef d3dmaterial9 material;
Typedef idirect3dsurface9 surface;
Typedef void yvoid;
# Define direct3dcreate direct3dcreate9
# Endif
# Ifdef d3dx8
# Include <d3dx8. h>
Typedef byte yvoid;
Typedef idirect3ddevice8 device;
Typedef idirect3d8 direct3d;
Typedef idirect3dvertexbuffer8 vertexbuffer;
Typedef idirect3dindexbuffer8 indexbuffer;
Typedef idirect3dtexture8 texture;
Typedef d3dmaterial8 material;
Typedef idirect3dsurface8 surface;
# Define direct3dcreate direct3dcreate8
# Endif
You can put it into a public file, such as a common. h file, and then use the file to include it. Similarly, the databases required by D8 and D9 cannot be connected. You can import the databases in the same way.
Ifdef d3dx9
# Pragma comment (Lib, "d3d9 ")
# Pragma comment (Lib, "d3dx9 ")
# Endif
# Ifdef d3dx8
# Pragma comment (Lib, "d3d8 ")
# Pragma comment (Lib, "d3dx8 ")
# Endif
Although the original game code is huge, macro naming will make the code structure simple. If you want to change it to another version, it will save a lot of work. Most of the remaining work will be to slightly adjust the details of each function and method attribute in different versions.