Bregma

GDNet+ Basic
  • Content count

    2988
  • Joined

  • Last visited

  1. Just one more suggestion. If you're using a compiler that supports the current C++ standard (and is not limited to an old superseded version of the language) you can just use a fixed enum type as your index type. #include <cstdint> enum AnimalId: std::uint32_t; enum TreeId: std::uint32_t; void f(AnimalId) { } int main() { AnimalId aid{1000}; TreeId tid{42}; // tid = aid; -- will fail to compile because the types are different f(aid); // -- OK // f(tid); -- will fail to compile because there is no valid conversion }
  2. C++ Making an UI in c++

    What does a plastic shiny wrapper around the real tools have to do with human memory, and why do you think it would speed up a team to have all that fluff and facepaint to wade through to do real work?
  3. Are there differences in terms of the efficiency of generated code? Probably not. Are there differences in terms of meaning? Definitely. You inherit to be reused. Unless you plan on using your Ids through a pointer or reference to their common base class (and it's not clear why you'd ever want to do that, since weak typing was the root of your troubles to start with), you should stay away from using inheritance and stick with the type alias. Note that instead of using struct AnimalIdTag{} you could also use an enumeration or strongly-typed enumeration (an enum or an enum class) or set of constexpr constants and a non-type template parameter. Again, it won't make any difference in terms of code efficiency, but it might be better in terms of code clarity. enum class ObjectType { Animal, Tree, }; template<ObjectType T, typename ValueType = std::uint32_t> struct IdType { ValueType value; // member functions as desired }; using AnimalId = IdType<ObjectType::Animal>;
  4. I'm afraid I can't even. Could you possibly try rephrasing what you just typed? By the way, your betweenorequal() could be simplified. #include <algorithm> template <class type, class type2> bool betweenorequal(type2 x1, type2 x2, type x0) { return std::min(x1, x2) <= x0 && x0 <= std::max(x1, x2); }
  5. C++ buffer or vector issue

    Well, I'd assume the bug is that you're changing the loop index "it" inside the loop. Can you really reason correctly about the loop invariant if the loop invariant changes in the middle of the loop? You can see the effects of calling std::vector::erase here. Pay special attention to the bit that says Invalidates iterators and references at or after the point of the erase, including the end() iterator.
  6. So... read the warning message. Look at the code. Read the warning message again and see how it applies to the the code. Change the code to eliminate the problem described in the warning message, using the suggestion contained in the warning message.
  7. Input on Adult Content

    I think this is key. If you're going for telling a good story, the rule is "show don't tell" -- which means in a visual medium like a video game, the explicit bits take place offscreen and you just see the reactions and results. A little bit of titillation never hurts and can set the scene to advance the story, but a graphic depiction of adult acts is just porn and ruins the story (just as any other tell instead of show would). On the other hand, I always add unpixelate patches to The Sims because the not-telling there is overboard. People are all naked under their clothes, adding pixellation just titillates where it's unnecessary to advance the story. Remember the other golden rule: always leave them wanting more. If people achieve the (cognitive) satisfaction of a visceral reward in the middle of a game, why continue with the playthrough? Tease them. Make them want the ending, but hold off on it for as long as you can. Make them say your name.
  8. Over-ambitious projects

    We are the music-makers, And we are the dreamers of dreams, Wandering by lone sea-breakers And sitting by desolate streams; World losers and world forsakers, On whom the pale moon gleams: Yet we are the movers and shakers Of the world for ever, it seems. With wonderful deathless ditties We build up the world’s great cities. And out of a fabulous story We fashion an empire’s glory: One man with a dream, at pleasure, Shall go forth and conquer a crown; And three with a new song’s measure Can trample an empire down. We, in the ages lying In the buried past of the earth, Built Nineveh with our sighing, And Babel itself with our mirth; And o’erthrew them with prophesying To the old of the new world’s worth; For each age is a dream that is dying, Or one that is coming to birth. From "Ode" by Arthur O'Shaughnessy
  9. C++ Random number issue

    Just to be clear: a pseudorandom number generator (PRNG) is a mathematical operation that generates a series of numbers by applying a function to a state vector, replacing the state vector with new value each time. The state vector needs to be initialized to something at the start of the sequence (a process called seeding), and if you manually change the state on each iteration you're messing up the sequence and you're going to have problems. The size of the state vector for the classic std::minstd_rand0 is 32 bits. The size of the state vector for std::mt19937 is 19968 bits. The std::default_random_engine is likely one of those two PRNGs (I have not seen a standard library use anything else, but it's possible). If you seed std::mt19937 with an unsigned int (which is what you would be doing if you use time(0) and your library has implemented std::default_random_engine using std::mt19937), then it actually uses that seed value to initialize a std::minstd_rand0 engine to generate the seed vector. Fun facts. I don't recommend using time(0) as a seed. Use std::random_device instead, at least on desktop systems.
  10. I am not a lawyer, but I have spent a good deal of time dealing with similar license and distribution issues relating to software. My advice is not legal advice and you should not depend on it. I gave the FIPL a close reading. It offers terms similar to the LGPL2.1, with some additional conditions. Here's a brief summary of the license terms. (1) You can use the library with your closed-source application to produce a distributable work without having the library's license term extend to the entire work. The combined work can be distributed under any license you choose. (2) You can only redistribute the library source code under the FIPL, if you choose to (or are required to, see below) distribute it. (3) If you make any change at all to the library source code, you are required to make the sources available under the terms of the FIPL. That applies only to the library itself, not the combined work, although your application must provide a way to communicate that a modified version is available and how to obtain it (ie. some lines in a dialog box or something). (4) Mr. Floris van den Berg reserves the right to arbitrarily change the license terms at any time but not without changing the version number, so you should explicitly specify the version of the license you are using.
  11. C++ Win32 Clang c++98 vs c++11

    You need to go even deeper. You need every single practical combination of OS, compiler, standard library, and possibly thread model and exception model. If you're using clang on a Linux OS, for example, are you using libstdc++, libc++, or one of the more obscure third-party libraries? If you're using mingw on a Linux OS to cross-compile for Win32 to run on Win64, do you choose the posix thread model or the win32 thread model? It's a crazy crazy world out there and I can tell you from experience there are bizarre toolchain combinations that will never work 100% despite your manager a technical expert insisting they're the way things have to be done. If you really want to make your stuff portable across platforms, look at how boost does it. It's OK to leverage the work of others, and best of luck to you it can be a fun challenge.
  12. C++ Win32 Clang c++98 vs c++11

    <stdint.h> is a C99 header. I don't know what vendor's C standard library you;re using, but if it's the native Microsoft Windows one it doesn't support C99 yet. Clang uses a non-conformant method of indicating support for various features instead of the standards-sanctioned ways, which means you're going to need to use libc++ for the standard library because other vendor's standard C++ libraries are conformant. There was some discussion in the standards committee about whether to do something like clang does, but it was rejected outright as non-scalable. Is there any reason you can't just switch from an ancient primordial version of the language to an old out-of-date one? The differences between C++98 and C++11 are subtle and obscure for he most part, if you avoid the newer features (and do you really care that std::list::length() is guaranteed O(1) instead of having its complexity order implementation-defined?) You should be able to just compile C++98 code in C++11 mode without problem.
  13. General questions about Testing

    You need to get out of that abusive situation. Nothing tells management they're doing a bad job more than being unable to keep talent. Seriously, it's not worth it. Life's too short for that stuff.
  14. I'm not understanding what the problem is. You have an arbitrary collection of questions and associated answers, and you want to know whether you should index that collection using a string or an integer? Simple. Use a string, it's human-readable and can be assigned meaning, and is more useful during debugging. Have a struct storing the question and answers, and store it in a std::map keyed by the string index. Move on to the next problem.
  15. Rip internet 2017-12-14

    Sort of. It's more like the phone company charging you more if you discuss politics in a long-distance call with your mother. Or the post office making you put two stamps on your letters if you write them in cursive instead of typing them. Up until now, internet providers have been functioning as "common carriers" or to use the stale old analogy, they were just the pipes through which the information flowed. This was to their advantage, since various statutes and regulations provide protection for common carriers from the content they carry. The phone company can not be found liable for the content of your conversations, say or the post office can not be held accountable for the content of letters you write. The internet carriers (who in many cases devolved from phone companies in the first place) have insisted on this status so they would not be in court every day defending charges of child pornography of media copying. Nowadays, the internet carriers are a part of vertically integrated mega-enterprises who both provide content and the wires that convey it to your eyes and ears. They want to be able to leverage that to improve their bottom line, and as always resort to classic rent-seeking in collusion with willing political donation recipients. Look up the definition of rent seeking, you'll see what's going on with net neutrality makes for a classic example of such undesirable action. Perhaps the best analogy for what's going on right now would be to imagine if General Motors, Ford, and Chrysler were owned by Exxon Mobil, Chevron, and ConocoPhilips respectively, and charged different gas prices depending on the manufacturer of your car. Good luck if you drive a Toyota or a Volkswagen, although I understand Ford may have cut a deal with Volvo in which Volvo pays Ford extra behind the scenes so their drivers can fill up like a regular Ford drivers. GM has been lobbying for federal regulations to let them put up toll booths on the interstate highway system that only non-GM drivers have to pay, with a cut of revenues going to government programs that promote "green" technologies. I should probably stop now, It's just making me bitter(er).