This is deeply nasty code, but I've managed to bring some measure of sanity to it. Many things wrong with the original implementation, so strap in cos it's going to be a bumpy ride.
First thing was that DirectQ doesn't use the old handles-based filesystem that FRIK_FILE depends on (the main reason why it wasn't implemented before), meaning that I needed to either reimplement the handles system just for this, or rewrite it to use FILE * pointers. I actually did both, first of all a reimplementation of the handles system to ensure that it compiled OK and cohabited cleanly, then a rewrite for FILE *.
Secondly, and as anybody who's implemented FRIK_FILE knows, opening a file in append mode is messy. First it tries to open it in read mode, then if it succeeded it reads it into a temp buffer (allocated in the zone, with all the size limits that implies), then it reopens in write mode, writes out the temp buffer if necessary, then returns. Yuck. It surely wasn't that difficult to write a Sys_FileOpenAppend, was it? Anyway, switching it to FILE * restored a huge chunk of sanity there, and as a bonus I got Sys_FileOpenAppend for RMQ.
The end result is now MUCH cleaner (and therefore more maintainable) than the original, with the only piece of semi-mess remaining from that part of the code being the use of a -1 to signify a file open failure. Unfortunately that's a compatibility requirement, but on the whole it's Not Too Bad.
There's still quite a bit of ugliness (and dependency on ugliness from the original ID Quake) in the code overall, but I'm going to suck it down for now.
Sunday, January 16, 2011
FRIK_FILE is done
Posted by
mhquake
at
11:42 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment