Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

146 Neutral

About tendifo

  • Rank
  1. tendifo

    std::ifstream not working?

    Quote:Original post by alvaro The line `in >> temp;' reads in an integer from the file, in decimal. If you want to read a single character you shouldn't use an int variable. I know. The format I'm using goes kind of like this.. 0 0 0 1 1 1 ... 0 1 0 0 0 0 ... ... The 0s and 1s are characters (.. with spaces as delimiters). If I understand correctly how ifstream works, then "in >> temp" will read either a 0 or a 1 into temp, which is what I want. Hopefully that makes sense.
  2. Some code of mine doesn't seem to be working (it compiles and runs, but doesn't output the right thing). I recreated the problem with the following code (I stripped out all the irrelevant code). #include <fstream> #include <vector> int main() { std::vector < std::vector < bool > > h; std::ifstream in; std::ofstream out; int temp; for (int x = 0; x < 1024; x++) { h.push_back(std::vector < bool > ()); for (int y = 0; y < 768; y++) { h[x].push_back(false); } } in.open("h.txt"); for (int y = 0; y < 768; y++) { for (int x = 0; x < 1024; x++) { in >> temp; if (temp == 1) { h[x][y] = true; } else { h[x][y] = false; } } } in.close(); out.open("whattheheck.txt"); for (int y = 0; y < 768; y++) { for (int x = 0; x < 1024; x++) { if (h[x][y] == true) { out << "1"; } else { out << "0"; } if (x < 1024 - 1) { out << " "; } } out << std::endl; } out.close(); return 0; } The file, h.txt, contains a huge array of 0s and 1s (768 lines with 1024 1s and 0s). I read them into an array (a vector of vectors). Then I try writing them back out into the file, whattheheck.txt, in the same format. Every time I run this, I get all 0s, even if the input file had a large number of 1s. What could be causing this? Should I try something besides a vector of vectors? Am I reading it in wrong? FYI, I'm running it on a SGI Octane2 running IRIX. Thanks. Edit: If it's not already obvious, this is C++.
  3. tendifo

    Advice on new 3d file format.

    I wouldn't blame the format because it is in ASCII. I don't think the performance loss is as great as you think.
  4. Quote:Original post by yacwroy Unfortunately, I'm not really a fan of shared_ptr though, and it's way too heavy for this use (not that that's too important). boost::shared_ptr is no more heavy than std::auto_ptr.
  5. tendifo

    C++ style

    I don't have the time to respond to all of these, but #4 and #5 caught my eye. #4) A pointer is 4 bytes wide. An int is (usually) 4 bytes wide. So passing one or the other makes no difference to speed. If you're so worried, do func(const int& blah). But really, this is pointless also. #5) Don't do that. There's no point to allocate 4 bytes (once again, usually) on the heap for one int. And the overhead of std::vector, std::list, etc is minimal. You shouldn't need to declare and allocate raw arrays on a normal basis. And in general.. 10,000 lines of code in one file is insane. Split it up into multiple files at least. I don't know how you even managed the code like that.
  6. tendifo

    measuring FPS

    Why not just keep a frame count, and after each second, spit it out, and reset it to zero?
  7. Computer Graphics: Principles and Practice by Foley, van Dam, Feiner, and Hughes Anything and everything related to computer graphics.
  8. tendifo

    convert char* to LPCWSTR

    Because the ASCII character set is a subset of most wide character sets, and still have the values 0-255 (the higher-order byte is just 0), this would work. std::string charstring = "hello, world"; std::wstring widestring; for (int i = 0; i < (int)charstring.length(); i++) widestring += (wchar_t)charstring; LPCWSTR lpcwstr = widestring.c_str(); Although, LessBread's method is probably safer to use.
  9. Quote:Original post by GenuineXP While I'm at it, are there versions of std::log for any base other than e and 10? I've been using this hack so far. float r = std::log(x) / std::log(2) This (I think) yields the log base 2 of x. Messy, eh? Not only that, but I didn't bother with the use of static_cast<> here. Also, this obviously isn't ideal since I'm taking the natural logarithm of two numbers! I've seen hints online of a std::log2 function, and haven't tried to use it, but I've also read online that it doesn't exist (i.e., isn't standard). That's not a "hack"; it's a legit way of doing logs. Most computers/calculators/etc with math functionality don't come with anything but base 10 and base e logarithms because you can just do what you're doing now and divide by the logarithm of the base you want. If you're so intent on having a log2 function, make your own that wraps up what you're doing there. As for using int-specific functions, you could wrap the float and/or double functions into int functions of your own. Then you don't need to cast in your actual code.
  10. tendifo

    Location of the * in pointers

    Take a look at this. http://en.wikipedia.org/wiki/Declaration_reflects_use I still prefer it this way, though: int* f; and not: int *f; But just my opinion.
  11. Quote:Original post by the_edd What's wrong with this: somebrush.draw_line(somesurface, x1, y1, x2, y2); ? I think it might get a bit tiring to type somesurface over and over again, especially if I'm drawing more than just a line or two.
  12. Quote:Original post by Spoonbender How about the obvious? Prevent the surface from getting destroyed while there are valid brushes attached to it? If this is C/C++, you can do that with smart pointers easily If I explicitely destroy the Surface, I want the Surface to be destroyed. I don't want it to stay alive as long as a Brush is using it. So it's not as simple as using a boost::shared_ptr or something like that. I may end up going with a variation of my (2); although, instead of having the Brush and Surface class handle the connection issues, I may push them into an auxillary connection class.
  13. I have two classes, Surface and Brush. The idea is that Surface provides a drawing surface (and handles all the system resources) and Brush does all the drawing on that surface. The way I want to do it is like so. Surface surf(500, 400); // Create a surface of size 500x400 Brush brush(surf); // Create a brush for the surface brush.draw_line(0, 0, 100, 100); // Draw a line from (0, 0) to (100, 100) I have this working quite nicely, but my concern here is that if we create a Brush somewhere and then the Surface gets destroyed, then we have a Brush that points to a Surface that no longer exists. I have two solutions for this. 1) Keep a running list of surfaces that still exist. Then the Brush can check if the surface it points to exists anymore. (This is how I'm doing it now). 2) Create a connection between the Brush and Surface. The Surface keeps track of which Brushes are assigned to it, and alerts them when it gets destroyed. (I was doing this, but switched to (1) after a while because it's simpler). What I'm wondering is which way is better or if there's a better method beyond these two. Connections betweens objects always seem messy in my opinion, so I'm leaning towards (1), but I'm open to other ideas. Thanks.
  14. Yea, I'll have to do something like that. I was just hoping C++ supported some special thing that would allow me to do it. Thanks anyway.
  15. Is there any easy way of making this work? I want the method do_something(), which is defined in a nested class, to have access to members of the parent class. #include <iostream> using namespace std; class some_class { public: int some_number; class { public: int do_something() { some_number++; } } some_object; some_class() { some_numer = 0; } }; int main() { some_class blah; blah.some_object.do_something(); cout << blah.some_number << endl; system("pause"); return 0; }
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!