Advertisement

Programming FML

Started by January 04, 2011 03:45 AM
13 comments, last by Oberon_Command 13 years, 10 months ago
Quote: Original post by Koobazaur
Yes, I could create a complete streaming abstraction layer with classes deriving from the std::stream class, handling every possible scenario and in case of errors, of course, throw a new custom set of exceptions that will be handled at each level of my file loading mechanism.

Or... I could actually finish making my game. But I guess YMMV


Or you could just do what ToohrVyk and fpsgamer said:

std::istream& operator >>(std::istream& stream, CVector3& dest){   float x, y, z;   stream >> x >> y >> z;   dest = KMath::CVector3(x, y, z);   return stream;}fileStream >> vertices[vertI].mLocation;


Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

The file isn't formatted in a way that can be parsed using the standard << operators of a std::streams.

What now?
Comrade, Listen! The Glorious Commonwealth's first Airship has been compromised! Who is the saboteur? Who can be saved? Uncover what the passengers are hiding and write the grisly conclusion of its final hours in an open-ended, player-driven adventure. Dziekujemy! -- Karaski: What Goes Up...
Advertisement
I don't think it should matter how the file is formatted. You can have the stream operator do anything you really want. You can have it read a single byte or an array of objects from the file.

So, you could just have the stream operator read 3 floats from the file and assign them into the vector. Then, just don't attempt to stream into the vector when it's not appropriate to the file.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Quote: Original post by Koobazaur
The file isn't formatted in a way that can be parsed using the standard << operators of a std::streams.

What now?


you just rewrite his code snippet to overload your >> operator to do what your getNextFloat() does.
Quote: Original post by way2lazy2care
Quote: Original post by Koobazaur
The file isn't formatted in a way that can be parsed using the standard << operators of a std::streams.

What now?


you just rewrite his code snippet to overload your >> operator to do what your getNextFloat() does.


He could also just do this and not bother with overloading anything.

    float x = DMF::GetNextFloat(fileStream);    float y = DMF::GetNextFloat(fileStream);    float z = DMF::GetNextFloat(fileStream);    vertices[vertI].mLocation = KMath::CVector3(x, y, z);

This topic is closed to new replies.

Advertisement