• Advertisement


GDNet+ Basic
  • Content count

  • Joined

  • Last visited

Everything posted by Bregma

  1. Is there a doctor in the house?

    Just a point of order, but "obsession" refers to repetitive thoughts. The term "compulsion" refers to repetitive actions. So, it would be Button Pressing Compulsion Disorder (BPCD) if anything. Doesn't play as nicely as an acronym but could still get you sympathy at parties ("My wife was diagnosed with BPCD and she keeps pushing for a cure...").
  2. initialize std::thread

    Unless of course the compiler decides to reorder the instructions in your code, or the CPU is superscalar and performs out-of-order and/or speculative execution, and you end up using the results of your interlocked add before actually calling that instruction: a locked processor instruction does not affect that but a fence does. Then again, you're using this in a multi-threaded application, so you're going to get pre-empted right after your InterlockAdd and the value gets changed by the other thread after you've obtained it, and you're left scratching your head why things don't work, sometimes, maybe.
  3. sys/socket.h and std::thread (C__)

    listen() is a system call: it will block the thread briefly while it switches to the kernel and performs some setup operations. It gets called once (per server socket, so generally once per application) during startup, and is fairly resource-lean and fast. You call accept() to wait for connection attempts on a socket that you have previously called listen() on. The accept() call is also a system call (requires a switch to kernel mode to perform its operations, which means it steps out of the ready-thread queue and go on the IO-wait queue), and whether it performs a blocking wait on the socket or not depends on if the socket is in blocking mode or not.
  4. sys/socket.h and std::thread (C__)

    Well, yes, you could use blocking sockets and have a thread listen on the socket, accepting client connections as they come, and go back to blocking on the accept call. That's all it would do. It's a very sensible way to program sockets and easy to reason about. You could also use non-blocking sockets and use a multiplexor like select/poll/epoll/kqueue to combine all of your socket waits onto a single thread, and dispatch them via callbacks to a worker thread pool. Again, not too difficult to reason about, but targeted towards a POSIX I/O model rather than a Windows I/O model. If you're using an Windows-based system, you could use IOCP and overlapped I/O to handle everything, including dispatching commands to a thread queue if you really want.
  5. Python Interest in Python

    Yes. Python is one of the main languages that runs the internet. It is widely support. It is worthwhile to be familiar with and a joy to use to program in. The Python standard library has support for RDBMs and key-value databases. I can't recommend an IDE (because I don't recommend using an IDE) but the one that ships with Python itself is IDLE.
  6. The mechanism they introducd into C++11 to do exactly this was the template parameter pack (AKA variadic templates). Prior to that, you could use Alexandrescu's typelists or something similar. It's pretty much an academic exercise: processing a regex at compile time gives you the benefit of incredible and error-time complexity at the cost of massive code bloat. But it's nevertheless an interesting academic exercise, so carry on.
  7. Pretty much, yeah.
  8. You might consider shipping your assets using a virtual file system. There are readily available ones out there. There is nothing unprofessional about shipping your assets with your game. I've played a number of AAA games that do that.
  9. 4K is 3840 × 2160 pixels. A 24 inch monitor running at 4K is great. Two is even better. You might want to consider the most common aspect ratio of displays these days is 16:9 because that's what most TV broadcasts are, so your display media (TVs, computers, tablets, phones) tend to be made to fit that. That means 1080p and now at twice the dot-pitch, 2160p AKA 4K. Gone are the days when you'd have an old bottle monitor showing 1024x768 with 96 PPI standing in for 72.27 points over a smaller value of an inch. I think it's been over a decade since I've used one of those.
  10. I saw nothing in the original question or the OP's follow-ups saying they were looking for some kind of type ID or RTTI functionality, so all these responses saying "don't do RTTI" are a little off the mark. My understanding was they were asking for a good way to do strong ID typing because just using an int is a good way to avoid using the languages built-in mechanisms to distinguish between values of unrelated types. As I understood it, the question was not about class type IDs, but about object ID types. Not "number 3 is a door" but "door number three". The original problem was that door number 3 and goat number 3 are unrelated even though they're both number 3, and OP wanted the code to reflect that concept to prevent him from accidentally opening a goat to see if he won a car. Or something.
  11. C++ comparing 2 floats

    Is your logic backwards? You have a "boolean" you set to "true" (in C++ we actually have types and constants for that, using them can make it easier to reason about logic). You iterate through a list of values comparing them to your input value, and if at least one of the values matches, you set the "boolean" to "false" to indicate f is in the list. If that "boolean" named fexists is still "true" by the end of the loop, it indicates f does not exist. I realize it doesn't answer you question, but...
  12. 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 }
  13. 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?
  14. 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>;
  15. 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); }
  16. 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.
  17. 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.
  18. 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.
  19. 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
  20. 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.
  21. 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.
  22. 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.
  23. 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.
  24. 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.
  25. 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.
  • Advertisement