Jump to content
  • Advertisement

rnlf_in_space

Member
  • Content Count

    246
  • Joined

  • Last visited

Everything posted by rnlf_in_space

  1. While I understand what you're aiming at, in the absolute way you state this, it's not right. There are circumstances where volatile is the right thing to use. It is unlikely for a game developer on modern hardware to ever be in such circumstances, but there are areas of software engineering, where it's the right thing to do (embedded/low level software, retro hardware games). Basically whenever dealing with memory that is not under the control of your program (hardware registers, memory mapped IO). If you see a volatile in high level code for modern hardware, you most likely have a bug 😝
  2. rnlf_in_space

    Temporary string literals

    @ryt, just to be clear, what @Bregma suggested is a joke. You see how they want you to "XOR with the original string"? That means you need to store that in your file.
  3. rnlf_in_space

    Temporary string literals

    Please don't!
  4. rnlf_in_space

    Temporary string literals

    @Alberth, I think what they're really trying to do is to have constant string data in a program without having it in any file they're shipping. I'm a bit lost as to how to explain that that's not possible.
  5. rnlf_in_space

    Temporary string literals

    So it's still stored inside the exe, just in this case as part of a movl instruction. That works for short strings (8 characters incl. terminator at most). This is the piece of code that copies the string onto the stack! Yes, 0x00636261 is a 32 bit value that is equal to the string "ABC\0". So yes, for short strings it's part of the code itself. But that doesn't work with longer strings. When you have a longer string, it will copy it from where it is stored (.rodata or .text doesn't really matter) onto the stack first. See it here: https://gcc.godbolt.org/z/KBHEBm The .LCn: are the labels where the compiler puts the string data, all those movdqa xmm0 ... movaps [rsp] are the unrolled memcpy, where the compiler added the code to move the string from the (in this case) .text section onto the stack. The first line, sub rsp, 104 is where the compiler makes space for the string on the stack. The stack is completely empty when the program starts running. The only way to get something onto the stack is during runtime using code! The same goes for the heap. You cannot store something on the stack or heap directly so that it's just there when your program starts running.
  6. rnlf_in_space

    Temporary string literals

    No, it's the same, really. Going back to the moving apartments analogy, if you want to sort the books into your shelves (the stack in your code) in the new apartment, you first have to get them there somehow. .text and .rodata both end up in the exe (and again, this would put the strings into the read only data section, not the code section). The only way you get something onto the stack or heap is to put it there using code (that the compiler generates for you, you don't see it directly in C++). And that generated code needs to copy it from somewhere. This "somewhere" is you exe file. I cannot ask you to hand me a certain book from your bookshelves if you didn't bring that book from your old apartment. And that means you need to have had that book in one of the boxes while moving. The exe file must contain all the data required to execute your program (unless you load the data from a different file, but then again you need to ship that file and it doesn't make a big difference in the overall size of things). If your program contains code that relies on a certain string being present, then that string must somehow get to the place where you execute the program.
  7. rnlf_in_space

    Temporary string literals

    If the strings get used (and not optimized out), of course they need to be stored somewhere. Where else would they be stored if not in the executable? You could store them in a data file, but then you have to load them at runtime. I don't know how to clarify that any better... if the strings are used OF COURSE they need to be stored somewhere, how else could you use them? Maybe an analogy: If you move to a different apartment and you want to take your books with you, you have to store them in a box. Are the boxes "bloated" just because you want to take your 10000 books with you? Your new apartment is the running process, the boxes are the executable file, the books are the strings. If you don't want the bloat, find a way to code your program without using the strings.
  8. rnlf_in_space

    Temporary string literals

    Of course the string has to be stored somewhere in your executable file, likely in a readonly data section, as you conjectured. The heap is a purely runtime thing and will only be populated during execution of your program. That being said, depending on what you're doing with the string and your optimization options, it's possible that the string doesn't actually end up on the heap (e.g. all functions you call on the string are getting inlined and you only do read-only accesses).
  9. rnlf_in_space

    Array arithmetic

    Could be a way to gauge how careful your coworkers do their reviews.
  10. rnlf_in_space

    How to organize constants? (c++)

    suliman, because it doesn't protect you from type errors. enum WeaponClass { Axe, Sword }; enum Action { Move, SkipTurn }; if(unit.action == Axe) // perfectly fine, but still not what you want And in the end you'll want to prefix the names, because now they are not scoped anymore, imagine this: enum WeaponClass { Axe, Sword, }; enum ImpactSound { Axe, // error, Axe already defined Sword // error, Sword already defined }; The classic way to fix that would be to prefix the enumerators: enum WeaponClass { WeaponAxe, WeaponSword, }; enum ImpactSound { ImpactSoundAxe, ImpactSoundSword }; And that's already almost the scoped/typed enum variant.
  11. rnlf_in_space

    How to organize constants? (c++)

    For one, it's called constexpr in a single word. Second, it the advantage of using a typed enum is type safety. Using integers for everything makes the code less easy to understand and easier to confuse different things: constexpr int WEAPON_AXE = 1; constexpr int WEAPON_SWORD = 2; constexpr int ACTION_MOVE = 3; if(unit.action == WEAPON_AXE) { // allowed by the compiler, but clearly not what you want. // something like this will happen sooner or later. Maybe not in an if statement, but // I've seen it happen dozens of times when passing method arguments. // And when it happens, it can be a pain to debug. } enum class WeaponClass { Axe, Sword }; enum class Action { Move, SkipTurn }; if(unit.action == WeaponClass:Axe) // compiler error If you really want to express a number (like mr_tawan's example in the beginning), then a constexpr is a good way to do it. You'll have to make it a static constexpr though, if you want to define it in a header file, or else you will get into trouble when linking.
  12. rnlf_in_space

    How to organize constants? (c++)

    In modern C++, the normal way to do that would be a strongly typed enum like so: enum class WeaponClass { Sword, Axe }; if(weapon.class == WeaponClass::Axe) { ... }
  13. rnlf_in_space

    loop only every 10th or so

    Of course you get flickering when you draw something only every 10th frame. What you probably want to do is store the last computed FPS into a variable and only do the computation every 10th frame, but still draw on every frame.
  14. rnlf_in_space

    How was lighting handled in early 3D games?

    Don't forget that Duke Nukem 3D was released 3 years after DOOM. Half a year before id released Quake. Of course Build engine games looked better at that time.
  15. rnlf_in_space

    Always align memory in array class ?

    Alignment is important for many things. Most CPUs cannot access unaligned memory. If you want to save on the padding, try rearranging stuff inside of your elements or consider going from Array of Structures to a Structure of Arrays, i.e. instead of having struct MyStruct { uint32_t foo; uint16_t bar; }; MyStruct array[100]; // 200 bytes wasted To something like struct MyData { uint32_t foo[100]; uint16_t bar[100]; }; MyData data; // Nothing wasted.
  16. rnlf_in_space

    STB Image

    I am using STBI and I never had a problem. Not sure what kind of trouble you had, but for it's been a smooth ride so far.
  17. rnlf_in_space

    Problem with sleep

    @Luhan M., it will probably take weeks before you notice any difference. A single night is not going to change anything. Continuity is the key to good sleep.
  18. rnlf_in_space

    Problem with sleep

    I had problems sleeping, too. In hindsight, they may have started when I got my first smart phone. I started watching YouTube and whatnot late in the evening while already in bed but recently I am forcing myself to not look at my phone at least an hour before I plan to sleep. Instead I'm reading books (those things made from paper) for an hour. I've only been doing that for three weeks, but I believe it already improved the situation. I tend to fall asleep faster and then wake up a few minutes before my alarm, just like it used to be in highschool.
  19. rnlf_in_space

    Too Many Roads With No Map

    When you're just starting to learn programming and want to do so while making games, why not give LÖVE a try. It's a very powerful but relatively basic and easy to learn 2D game engine. It just takes a few minutes to understand the basics and get an image on screen and a few more to make the image move. It used Lua as its user programming language, which is a very small language that will allow you to focus on the basic principles of programming. But don't think it's a beginner language, it is tremendously powerful when used skillfully.
  20. rnlf_in_space

    Leaving a company at a critical moment

    During the interview for the job I have now, I told the interviewer that I felt it was my obligation to help my previous (then current) company finish an important project and asked them to let me start 2 months later. I expected that to be a problem for them, but quite the contrary: After the interview, they told me they had talked about that and found it meant I was a loyal person and that they felt assured that if I ever left the new company, I'd give them enough time to find a replacement, too. Have you tried talking to the new company about the issue? Maybe they are more open to it than you think.
  21. rnlf_in_space

    Convert functions to linux (gcc)

    I think you may want to use CLOCK_MONOTONIC_RAW instead of CLOCK_MONOTONIC. It doesn't make a huge difference, and mostlikely never causes any notiveable problems, but CLOCK_MONOTONIC may run slower or faster than "real" time, when the clock gets adjusted. Basically, a correctly implemented tool to set system time on a UNIX system will not just set the new time, but rather slow down or speed up the system clock to gradually go to the new time. This is so that there are no jumps in the system time, which will throw off a bunch of things on a UNIX system. CLOCK_MONOTONIC is subject to these adjustments, so you might experience a time where your game does not actually measure one second of realtime as one second, but rather as 1.1s or something like that. CLOCK_MONOTONIC_RAW is never sped up or slowed down.
  22. rnlf_in_space

    Convert functions to linux (gcc)

    There's clock_gettime in Linux. It gives you the time with nano-second resolution (but lower precision, usually), but clock_getres can be used to find the actual precision. You may want to use the clock named CLOCK_MONOTONIC_RAW to get the actual real time that has passed.
  23. rnlf_in_space

    Bit manipulation returning wrong data

    I'm not sure why you even want to go through all the trouble of packing your data like this. Just return a struct { int mouse_x; int mouse_y; } and you're done.
  24. rnlf_in_space

    Video codecs: compressing delta values

    I don't know much about the topic, but you don't actually need one extra bit for the difference if you wrap the difference around at the 1-byte border: The difference from 255 to 0 is -255, but can be expressed as +1: (255 + 1) % 256 = 0. The difference from 0 to 255 is +255 and can be expressed as that: (0+255) % 256 = 255. PNG does that for some row filter methods if i'm not mistaken.
  25. rnlf_in_space

    std::string_view

    Yeah, this can all lead to an explosion of overloads very quickly. I think passing an std::string by value and then moving from that string to initialize your members has the best performance/effort ratio. This talk by Nicolai Josuttis illustrates the problem very nicely, even if for slightly more complex cases: In your case I'd probably just go with Str(std::string str) : m_str(std::move(str)) {}, that way you create one copy of your string at the call site and then just use the (comparatively) cheap move constructor to initialize your member. std::string only has an explicit constructor that takes a string_view though, so if you'll either have to create the string object at the call site, too, or overload with something like Std(std::string_view v) : Str(std::string(v)) {}. I'd prefer the first option (making the copy explicit at the call site) because it doesn't hide the extra allocations and memcpy.
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!