What kind of performance difference is there between a game in C, and ASM? Is the bottle neck in the DX/OpenGL API, or in normal code? The reason I ask is that a few friends are trying to program a game, and I am getting involved. I don't have much ASM programming experience, and the others on the project have none! If there is a reasonable performance increase to be had from doing parts in ASM I _WILL_ learn how to do it, and "convince" (tell them in no uncertain terms) that it is a "good thing"TM ;) But I need numbers (not just made up ones either)! Are there any parts in particular that are better/worse/much more difficult, to do in ASM? Mirno
Posted on 2001-02-12 10:59:00 by Mirno
Well Mirno, its sure that ASM will be much faster then C/C++ code...but only well written code...:D However if you are going to use ONLY the DX API or OpenGL API and ONLY with HARDWARE Accelerated functions theere will be no big diffrence... Real problem comes in when you want to make a "special fx" that is not there "allready made" inside the API's...then ASM will show its power... A simple example is alpha blending in DirectDraw (DX does NOT support it) so you have to do it yourself (you can use 3D...but then your game in not 2D anymore and there are 3D examples also) and asm can help a lot there, about 3x up to 10x faster. AI is also a very computational intensive task so ASM will "pump up" the speed here also However doing Menus and combo_boxes and list_boxes or even push_buttons from zero..is not hard...but no much fun in asm also... However dont be fouled by claims of full C++ games...if that game is not a very simple one...it will have lots of ASM code included in it's core :) Allmost any modern (old ones also) game will need some help from ASM code sooner or latter...how much ASM you will use and where depends on your skils and speed requirements of your game
Posted on 2001-02-12 13:19:00 by BogdanOntanu
Bogdan has got it down pretty well. For me to sum that up, I'd say that computational loops, graphical effects and repetative calculations will show the real power of assembler, because even that one or two extra operations the C compiler may put in will end up costing you literally thousands of CPU cycles in a heavy loop. To expand on alpha blitting. This is an effect where you blend two pictures together at a varrying amount. So basically for every pixels in the two graphics you must get two pixels from memory (Memory operation are slow and should be avoided in these sort of loops) do a math calculation (Which is where assembler and MMX helps A LOT!!!) then place the final pixel. Also in asm you can easily use all registers in the whole loop, (registers take very few if not one clock cycle to write to if I recal correctly whereas memory variables can take up to like 35-70 clock cycles!). Also when doing AI like bogdan said, you must cycle through every unit in existance (A lot if it's an RTS or RPG) and do some sort of sorting and search algorithm, like organizing the units from highest vertical position down and using the A* algorithm to find there paths. In a 3d game you will also use lot's of ASM because of the matrix math, you have to do many calculations on 4x4 matrices of numbers many times over. So again as bogdan said the only boring part is programming things like buttons (assuming your not using a standard windows UI, because you want it to look cooler) Many commercial games are near half and half, which is what I'm now leaning towards, the reason for this is you can rapidly get a shell up and running in VC++ and then optimize it with asm routines, this is simply faster when developing a large RTS, than programming everything 100% asm (Which is what I did for several years). Hope this helped some. See ya, Ben
Posted on 2001-02-13 00:14:00 by cyberben
Bogdan and Ben have more or less said it all, making calls to functions is not much different in either C/C++ or asm. Where you will find the advantage is in areas that are not well addressed in either C or C++. A standard solution is to write modules for the C/C++ program in MASM and link them in at build. This allows you to do smart loop optimisation in a pure assembler environment and link it into a not so smart C/C++ front end. It will really depend on what you are writing. Assembler can do it all but there is a bit more work in the interface design although building yourself a library of bits will help here a lot. Good luck with the project.
Posted on 2001-02-13 00:28:00 by hutch--