Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

216 Neutral

About sundersoft

  • Rank
  1. sundersoft

    Is using a debugger lazy?

    I almost never use a debugger because: -I usually have a good idea of where the bug is; it's usually in the last code you wrote (assuming you're testing properly). The code's errorneous behavior is also usually enough to determine roughly where the bug is. Having to look at stack traces and whatnot takes a good amount of time and it's usually not necessary to know exactly where the bug is. -My approach to fixing bugs is to look at the relevant code and try to improve it. I may find other bugs that I didn't know about or I may find that the code or variable names are confusing. I may also decide that the method I'm using is naturally error prone (has many special cases, etc) and that I should rewrite the code to be simpler. With a debugger, I normally find the bug, fix it, and leave, so the code quality is not improved much. I'd rather spend time looking at the code than using a debugger. When I do use a debugger, it's usually to generate a stack trace for an uncaught exception or segmentation fault. Although well written C++ code shouldn't throw many exceptions or have many opportunities to segfault, so I very rarely use the debugger. I normally do printf-style debugging since it's faster than using a debugger to generate the same information if you're lucky, and since I prefer reading log files over suspending the program every time I want data. I also hate Visual Studio because it gets in my way so much. You should just be able to write text without having a box suddenly pop up on the screen, eat your keyboard input, and block out the rest of the code. Why can't the autocomplete stuff be on a seperate panel on the side of the screen instead of blocking the code? I use Dev-C++ (a beta version of it and with the most recent version of GCC) to do all development because the IDE is simple and doesn't get in my way. Also, autocomplete encourages lazy variable naming because the penalty for not naming your variables properly is reduced which makes it harder to detect badly-named variables. Many of the other IDE's features are stupidly implemented and it would waste more space (specifically vertical space) than Dev-C++ even if you disabled all of its features. With that being said, most people are reliant on debuggers and prefer complicated IDEs such as Visual Studio.
  2. sundersoft

    std::enable_if, template specialization

    This is what the standard says about it (this is from a 2005 draft but I doubt the C++11 standard changed this significantly): "It is unde?ned for a C++ program to add declarations or de?nitions to namespace std or namespaces within names- pace std unless otherwise speci?ed. A program may add template specializations for any standard library template to namespace std. Such a specialization (complete or partial) of a standard library template results in unde?ned behavior unless the declaration depends on a user-de?ned type of external linkage and unless the specialization meets the standard library requirements for the original template. 171) A program may explicitly instantiate any templates in the standard library only if the declaration depends on the name of a user-de?ned type of external linkage and the instantiation meets the standard library requirements for the original template." Footnote 171: "Any library code that instantiates other library templates must be prepared to work adequately with any user-supplied specialization that meets the minimum requirements of the Standard." You might want to wait for concepts to be standardized (or killed) before trying to add information about when a template would work to its interface. You're going to have to change your code if the standards comittee actually implements concepts and you want to use that feature (which would basically do what you're trying to do right now). http://en.wikipedia.org/wiki/Concepts_%28C%2B%2B%29 However, this probably isn't going to be standardized for another 5 years at least (if it does become standard).
  3. sundersoft

    std::enable_if, template specialization

    I could try this but it would involve specializing is_arithmetic for mytype which is something I don't really want to do. Even still it would only evaluate to true and produce the same problems. [/quote] I really doubt you're going to be able to specialize the function if your type doesn't have is_arithmetic<mytype>::value==true . You are allowed to specialize templates in the standard library (under certain conditions). The following code compiles even though the mytype specialization of func doesn't use is_arithmetic: #include <iostream> #include <type_traits> // firstsomething.hpp template <typename T> typename std::enable_if<std::is_arithmetic<T>::value, T>::type func(const T& x) noexcept { return x; } // something.hpp class mytype { }; namespace std { template<> class is_arithmetic<mytype> { static const bool value=1; }; } template <> mytype func(const mytype& x) noexcept { return mytype(); } int main() { func(0.0); func(0); } If the is_arithmetic specialization was removed, the code would fail to compile on GCC 4.6. If your type is not an arithmetic type then I think you're going to have to use function overloading. I think I was concerned that creating an overload would break func for integer types because mytype does not have an explicit constructor and it still takes a single argument integer value. However this is not the case apparently.[/quote] Yes; the compiler will prefer to instantiate a template over having a cast and using a non-template (although you can force it to use the non-template version by generating a function pointer to it and calling it, or you can force it to use a template by specifying the template arguments explicitly).
  4. sundersoft

    std::enable_if, template specialization

    This code compiles in GCC 4.6. I don't have 4.7 to test with. #include <type_traits> // firstsomething.hpp template <typename T> typename std::enable_if<std::is_arithmetic<T>::value, T>::type func(const T& x) noexcept { return x; } // something.hpp typedef int mytype; template <> typename std::enable_if<true, mytype>::type func(const mytype& x) noexcept { return 0; } int main() { func(0.0); func(0); } You could try changing the specialization to: template <> typename std::enable_if<std::is_arithmetic<mytype>::value, mytype>::type func(const mytype& x) noexcept; If that doesn't work, you might not need a function specialization in the first place (I'm not sure what exactly you're trying to do), so you ought to be able to use function overloading: mytype func(const mytype& x) noexcept; I did add 'template <typename T>' to the specializations instead of 'template <>' but doesn't this then mean the functions are no longer specializations of the original? [/quote] Yes. You can't have a partial function specialization in C++ so all function specializations must start with "template<>" (as far as I know).
  5. I accidentally downvoted your post, sorry.
  6. sundersoft

    Floating Point Constants

    IMO you should be using templates if you need to write code that works with any type. This allows you to use multiple types and change them later without affecting existing code. Besides float and double, it's also possible that you may use one of the integer types, complex, a quaternion type, a vector or matrix type, etc. For example, if you have a generic vector type then you can use vec<unsigned char, 4> or vec_4<unsigned char> to store image data and manipulate it in a convenient manner (although you may also have to implement casts).
  7. Intel's drivers are famous for not supporting OpenGL properly. You could try using DirectX if you want to support Intel cards, which is supposed to work somewhat better.
  8. Most commercial games use a fixed time step, meaning that they only advance the physics engine by a fixed interval. If the game is running at a low frame rate, then the physics engine will be advanced multiple times per frame instead of being advanced only once. It is possible that the user's PC is not capable of running the physics in real time in which case you have to use a larger time step, but this should never happen for PCs which surpass the minimum requirements that you intend to support. I believe that most physics engines run discrete collision detection multiple times per physics frame to get more accurate results and handle fast-moving objects better. Using either of those along with careful design of the levels should avoid problems caused by the use of discrete collision detection. The alternative is to make your physics engine do all of the collision detection continuously and to not use approximations that become worse with larger time steps. However, this is more difficult to implement and commercial physics engines do not do this so you are not likely to be able to implement it properly.
  9. sundersoft

    AUTO_PTR issue.

    If you have access to a modern compiler with unique_ptr then you could basically replace each usage of auto_ptr with unique_ptr and make some simple alterations to the code based on error messages and it ought to work (is there a good reason for why are you porting to VS 2005?). If you're changing auto_ptr to unique_ptr then you have to add a call to std::move in some cases. For example, if a and b are auto_ptrs, then this code is valid: a=b But, the unique_ptr version must be written like this: a=move(b) You can just use the error messages to find all of the places where you need a call to move.
  10. sundersoft

    Best Minigame Ever?

    My favorite minigame is Overworld Zero from System Shock 2. System Shock 2 is an FPS/RPG so the player has an inventory, and one of the items you can pick up is the GamePig, which lets you play minigames while you're playing the main game (it's not paused or anything; you might get ambushed by enemies while you're playing the minigame). You also had to find game cartridges throughout the game after you found the GamePig. It actually served a purpose in the game because there are many actions in System Shock 2 that take lots of time to complete such as research (the player has to research some items before using them, and they can research parts of dead enemies to do more damage to them in the future) or waiting for the red alien goo to heal you. Instead of just waiting, you might want to read some of your unread audio logs (you can find audio logs around the ship which tell you about what happened and sometimes where items are) or play the minigames. All of the minigames were controlled only with the mouse and Overworld Zero was a turn-based RPG where the player had to kill enemies, find coins, pay for healing, transfer items from one house to another for coins, and go to a shrine to level up. You could only move in 8 directions and it was tile-based. I think there were also some items you could find that boosted your health. If you beat the game I think you got nanites (money) for the main game, but only a small amount. There was only one map but it was randomly generated and the player had to kill some boss enemies after getting to a certain level to complete the game. Someone actually made a clone of it in Java: http://mac.softpedia.com/progDownload/OverWorld-Zero-Download-60710.html Basically System Shock 2's minigames were effective because there were occasions where a player would need to kill time, the player wasn't incentivized to play them (actually it wasted one inventory slot), and the games themselves were fun.
  11. sundersoft

    Math fail: Adding frames per second

    This means that, if you ran one game for 100 frames, stopped it, ran the second one for 100 frames, stopped it, etc, then your overall average frame rate would be given by the harmonic mean. This is not very useful. That was an example to prove that the data is plausible. If you agree that the data is plausible, then you need some way to measure each GPU's overall performance taking into account only the data. You can use either the harmonic or arithmetic means for this purpose, or some other measure of center. In my example, a game that was not significantly affected by the choice of graphics card caused the percent increase in performance of the second card based on arithmetic mean to change from 161% (if the 3rd game is removed from the data) to 127%, whereas the percent increase associated with the harmonic mean would change from 161% to 40%. Most people would consider the harmonic mean to perform worse in this case, but this is subjective. You also need to decide how likely it is to have a slow game that is not affected by choice of graphics card, and whether the harmonic mean has any other differences with respect to the arithmetic mean that would redeem it if you consider its behavior in this case bad. Both of these considerations are pretty subjective.
  12. sundersoft

    Math fail: Adding frames per second

    The definition of the arithmetic mean is the same whether you're using FPS or seconds per frame. You would still just add all of the numbers. You're proposing using the harmonic mean to describe the center of FPS rates. First of all, neither one is mathematically correct and there are other measures of center such as the median and geometric mean. However, each measure of center has different behavior when it comes to values that deviate far from the rest of the values. If you're trying find the average performance of a graphics card, then each game should be given equal weight. Also, if the card has exceptionally low performance on one game, that sample should be given less weight because this would indicate that the game has an optimization problem with that card or in general. To compare the harmonic and arithmetic means, assume that two different cards had these FPS rates for a sample of 3 games: 60, 55, 30 150, 150, 28 The 3rd game can be assumed to be badly optimized and the second card is obviously much faster than the first one. Harmonic means: 44.0 61.2 (40% more than the first card) Arithmetic means: 48.3 109.3 (127% more than the first card) If the harmonic mean was used to compare the two cards, then slow games would have more weight than fast ones. This isn't what we want since slow games are generally poorly optimized. In this example (where the 3rd game was bottlenecked by something other than the graphics card), most people would consider 127% to be more representative of the 2nd card's speed relative to the 1st one, rather than 40%, so the arithmetic mean would be preferred over the harmonic one.
  13. Anything starting with two underscores or one underscore and a capital letter is reserved for the compiler. So, anything starting with three underscores is reserved (since it also starts with two underscores) and any capitalized macro that starts with any underscores is reserved. Also, there can't be any sequence of two underscores in the identifier, even if it's not at the start. The compiler is not likely to define a macro that starts with three underscores but it is still allowed to do so.
  14. sundersoft

    Overusing smart pointers?

    If you're going to have register and unregister functions in one of your classes, you should consider providing a helper RAII class which registers its argument in its constructor and unregisters it in the destructor. Anyway, if you're going to be using reference counting you might as well just use shared_ptr since the efficiency improvement of implementing it yourself is going to be negligable. Anyway, the implementation you should use is going to depend on what kind of efficiency constraints you want and what exactly you're trying to do. For example, if you're making a game and you want to cache textures and models that were loaded from the disk, I'd recommend the following in your caching class: -Have it return shared_ptrs on an object lookup. This allows you to not have to worry about whether the cached objects are in use or not when you flush the cache. I would also recommend storing shared_ptrs in the cache because, if you use weak_ptrs, then the object would become flushed from the cache as soon as the last shared_ptr reference to it was destroyed. This would be bad if part of your game involved loading a model (e.g. of a rocket), instancing it, and then destroying it later. Every time the model would be requested from the cache, it would have to be loaded from disk again. -Have a "flush" function which goes through the cache and removes any object that only has one shared_ptr referring to it (i.e. the one stored by the cache). This removes all currently unused objects from the cache. It is not desireable to remove every object from the cache because this may cause two different instances of the same object to exist. When you're performing an operation where most of the cache would be redundant (e.g. loading a new level), you would flush the cache. For loading a level, you would first delete the existing one, load and initialize the new one, and then flush the cache. This order would cause any resources that exist in both levels to not need to be loaded from disk twice.
  15. sundersoft

    Overusing smart pointers?

    Raw pointer. If the object is deleted and then accessed by the currently selected pointer, that would usually indicate an error in your code and both weak_ptr and raw pointers will cause a runtime error here (assuming you don't check for a null shared_ptr from the weak_ptr's lock function). It's possible that a memory access to deleted memory will not cause a runtime error but this is rare and usually yields garbage data. Using shared_ptr generally implies that there is shared ownership of the pointed-to object, so having only one shared_ptr to an object means that there is exclusive ownership, which makes the code less clear in addition to having more overhead. It's also possible that a second shared_ptr could be created by mistake which points to the same object, which is generally not desired (removing the object from the container should delete it) and not possible with the unique_ptr implementation. Using shared_ptr for both the currently selected pointer and the container of objects would cause the object to remain in memory when the object is removed from the container while being referenced by the currently selected pointer, but this condition is usually errorneous (the selected pointer should generally only point to objects in the container), so this will mask the error and make it hard to detect. The object may require shared ownership without considering the existance of the currently selected pointer (for example, if the object is immutable then you might want to copy a pointer to it instead of doing a full copy, in which case shared_ptr is appropriate). In this case, weak_ptr should be preferred since the overhead of having another weak_ptr instead of a raw pointer when the shared_ptr already exists is neglegible and the weak_ptr is more likely to detect errors. However, checking if the shared_ptr returned by weak_ptr's lock function is null should usually be omitted since it is usually a non-recoverable error to have the weak_ptr return a null shared_ptr.
  • 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!