Archive for the ‘articles’ Category


reference counter based memory management + bitching about life

June 8, 2009

The bitching about life part comes first.  I believe the DCFC song “No Sunlight” sums up my rant in that regard nicely, so I won’t waste the space here.  Okay I’m done with that.

Now, on to the not depressing stuff.  I was thinking of ways I could potentially speed up memory management with threads.  I was basically thinking along these lines:  I should queue my object deletions so that I can delete them on the side while the next iteration is in progress.  So I came up with an interesting system.  I haven’t implemented the threading yet, but I have seperated object deletion from the main loop entirely and it’s just tacked on the end for now.

Basically I implemented a reference counter object management system.  Each ManagedObject has a grab() and drop() method, used to count references.  When the number of references reaches zero, the drop() method calls the queue_deletion() method in the ObjectManager singleton.  The ObjectManager also keeps track of ManagedObject’s that are still kicking, so that they can be cleaned up at the very end if they weren’t properly dropped.  This should keep memory leaks from being as bad, though that doesn’t mean I won’t bust my ass trying to find all of them.  So the current code for updating is as follows:

void Engine::RunMainLoop(double timestep)
while (running)
if (!Update(timestep)) running = false;
if (!Render()) running = false;

The ObjectManager deletes all things queued for deletion in CleanUp(). What I could do is simply start a cleanup thread that cleans up every second or so. For the threaded version it will lock the mutex for the queue to copy it over to a private queue and clear the public one so that it can be used again while the cleanup iterator goes through and deletes everything added previously. If you want the full classes, I shall have t3h c0dez in an article on custom memory management for C++ classes shortly.

EDIT: Okay, article’s up. It’s called “C++ custom memory management primer”. Link under My Articles in the sidebar.


omg done lol

December 23, 2008



so, yeah, read the article.


new article wip Direct3D 9 on the fly geometry

December 22, 2008

I’m commencing work on a cool article regarding on-the-fly geometry code. In OpenGL it’s really a snap (glBegin(), glEnd(), glVertex(), glNormal(), etc.) but in Direct3D it’s fucking impossible. You cannot do any of it on the fly. You consolidate everything down to a single call, (a few complex ones for vertex buffers) that requires all this pain-in-the-ass setup, and it’s STILL less efficient. I don’t get you fucking people at M$. ARB can do it, so you definitely can.

But anyway… I created a little class called GeometryInterfaceD3D9. It takes OpenGL style on-the-fly commands, then does the work for you. It’s not really fully optimized to the extent you can with D3D, but it works, and emulates OpenGL very well. Just avoid quads at all costs, because while I technically added emulation for them (quad primitives not available in D3D9 wtf?) they are DEADLY SLOW. I could fix this with a bit more preprocessing, but for now it just does multiple calls to RenderPrimitiveUP(), so it is, as I said, ridiculously slow. THIS IS NOT THE FINAL ITERATION, I WILL FIX IT KAY ZOMG.

The reason was that the main Renderer class and children RendererOpenGL and RendererD3D9 were initially designed for these calls. Then I eventually realized that this is not how you do it at all with Direct3D. But I firmly believe that these on-the-fly geometry instructions are the clean way of doing the API. So, I accepted a less efficient implementation on RendererD3D9. Don’t worry about the lack of efficiency there. Just as VertexBuffer and VertexBufferVBO are efficiency optimized for OpenGL, VertexBufferD3D9 will be optimized for Direct3D. And of course, all the specific implementations are invisible to the user of the library, so it is important to add layers that unify the API. So far this is going well.

Anyway. I will add most of this above text to the article page, and also the code. Please check it out when it is complete.


super article update time and WOG

October 5, 2008

thundercats yay snerf snerf snerf snerf o-lion-o!

no, no, no, NO, NO!  no.  NO.  no…


thundercats FAIL.

but they’re funny, so you can’t really hate them.  bawwww conk.

But the reason I’m posting is that I just updated the FreeType article with better code boxes plus proper vertical placement, a big thing I missed the first time like a total idiot!  The FreeType font article is already updated, will fix the code boxes on the others next.

WOG, that is to say, WORLD OF FUCKING AWESOME GOO, or for the uninitiated, World of Goo.  And it is COMING OUT on OCTOBER 13.  Yayuh.  If you pre-ordered, guess what, they send you a download link on the 6th.  Which means awesome times come sooner.