Howdy, those of you who remember me may be happy to know my 2D game engine was finished and I'm now working on a 3D engine.
My engine has been going rather spiffingly well, after some battles with DirectX and OpenGL i managed to get them working side-by-side. Wrote a working wavefront OBJ model loader (i'll happily hand that out sometime) and generally was having a great time.. Now here comes the problem.
Pretty-much all my code so far is cross platform, the parts that aren't have alternate versions for platforms (window management, etc). I'm about to impliment my Physics Engine but before I can i need to save model-data in my own format (for sheer speed of loading versus the general "oh lol i load existing format that has no relationship to my internal data structures via a impossibly slow single-platform library" approach.
Now the problem doesn't lie with my model saving loading, that's all hickity boo (that means good), my issue is with the portability.
I'm using ofstream in binary mode, and char* reinterpret casts to output my data. Just like i was taught.
The problem is when i'm outputing say... may bigass array of vertex data from a dynamic float array:
//first we past a reinterpreted pointer of the vert array (char) //then we need to allocate enough room in the stream. //this is pretty simple actually, the calulation is: // the number of verts X ( Size of a float X 3) //this is because each vert is made of three values. OutFile->write((char*) VertArray,NumVerts*(sizeof(float)*3));
Now here comes the problem, as far as I'm aware the exact defintion of the size of a float is pretty much 'Is bigger than an Int', it could be 24bits, 32bits, 64bits, over 9000bits. It's entirely up to the platform.
That's not a problem though you say, the code will work fine on any platform... and it will..
But the file data being output (my model files) will most likely be distributed with my game, I could recompile all the models for my target platform, sure... but I also want to be able to support model-transfer over a network, such as... the many hampster filled tubes of the internet! I don't want somone playing on a mac to only be able to connect with mac users. (though to be honest... playing games on a mac? heck owning a mac... the very idea makes me feel rather nausiated).
Thus the question comes.. How, without using a library written by someone else (I'm so dedicated to using my own code I wrote my own replacement for std::vector, that and a speed issue with resizing) can I possibly write my model files on one platform, and load on another without either: using text files, or wasting space in my file? (file size is obviously an issue when transfering over a network).
Anyhow hopefully my rant isn't too long to follow (or to wordy for the second-language-english-speakers (sorry >_<)) and someone will have the slightest clue what i'm waffeling on about.
on "//error checking saves your ass"
my ass isn't flapping in the wind so much any more! Just lightly fluttering....
Edited 6 Years Ago by DarthPJB: n/a