Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 05 May 2007
Offline Last Active Aug 12 2016 09:50 PM

#5291493 Should i learn Win32 or UWP?(C++, Directx)

Posted by on 14 May 2016 - 12:00 AM

People forget that before UWP, there was the Metro/Modern application platform for Windows 8 and now it's dead. What's telling us that Microsoft is not going to come out with some new API next year and kill off UWP? I mean, it's not like the platform has been without criticism; some big name game developers are already calling for the death of the platform, and tying the platform to the Windows Store when nobody actually uses the Windows Store or knows it exists doesn't exactly capture my heart as a developer. (Not even Apple can do that on the Mac.) As much as I dread using Qt, GTK, wxWidgets or MFC, I would pinch my nose and use those for now, and then cross my fingers that Microsoft gets things right for the UWP sooner than later. I would love to use the UWP for my project but as it is right now it's a no-go.


On a side note, I don't get why people dislike the CX language extensions so much. The objects of the UWP class library are glorified COM objects, and the CX extensions simplifies their manipulation as well as the creation of new ones, so why not make it easy on you and use those when you deal with Microsoft APIs? It still feels very much like C++ and is so much easier and convenient than the nameless mess that you have to deal with on competing platforms to get C++ to play well with the OSs. (Namely, JNI on Android and Objective-C on Apple.)

#5286486 Should getters and setters be avoided?

Posted by on 12 April 2016 - 10:14 AM

You need to take what you read with a grain of salt and evaluate whether it makes sense or applies to your project. ESPECIALLY when someone starts calling something always evil like in one of the linked URLs in the original post. At this point, I don't think there is anything that is always evil. I think I actually even have a good case for a goto in my rendering engine's code, which is the pinnacle of the NO-NOes in programming. (And I'm still looking to get rid of it.) So if you tell me that something as ubiquitous and proven as getters/setters are always evil, no, just no. Misused? Yeah, I think people often write a lot more getters and setters than they actually need to. But always evil? No. (And only a Sith deals in absolutes. :P)


The truth is that there are a lot of people in the programming circles that would like to make themselves a name by calling well accepted practices "evil" just because it's bad by some completely unpragmatic point of view, or because once upon a time someone misused the pattern or principle. Now it's get/set, last week singletons were evil. Next week if someone calls having a main() function an antipattern... well, remember I called it first here. :P


Don't ignore what you read, just have critical thinking. If you're a seasoned programmer, you know more about how to go with your project than some blogger with a book so listening advices and new method can never hurt, but in the end you're the one who can judge how to go with your project. A lot of those people writing about programming practices are academic Java programmers looking to sell their books or conferences. Probably the same type of people that state completely obvious things, wrap them in silly catchy acronyms like KISS, GRASP and SOLID and write PhD thesis around those, but I disgress...


I do think though that if you're going to write a data object with full read and write access and know it's going to remain that way, just write an old-fashioned plain-old-data struct. It's not "prettier" to have to write my_object.GetXXX() instead of my_object.XXX and for setters it's actually annoying if you like to do chain assignments or swaps. Qt is guilty of that a lot: you need to pass through methods to set the values of a vector or a matrix. It's just annoying. Don't do that.


This is kind of why I would like to see properties in C++: you can expose naked properties if you don't need to control reading and writing, and if you change your mind later and need a getter or setter, you can write them without breaking any code. But again, I disgress.

#5285708 My app cannot write files anywhere on Windows 10

Posted by on 07 April 2016 - 09:38 PM

The locations you listed have in common that they're either read-only or in a folder created in NSIS.


Look at the access rights of the folders created by NSIS in your User folder. Is it restricted in reading or writing? There may be an error in your NSIS script that makes it create folders that require admin rights, and therefore your app can't write in them.


Program Files and Program Data should be read-only so even the NSIS created folders should be read-only. (They're the equivalent of /usr on Mac/Linux.)

#5282801 (split thread) c-style casts

Posted by on 22 March 2016 - 11:09 PM

The point of C++ style casts is to specify your intent, so that the compiler can ensure that you're actually asking it to do what you meant to do. If you use C-style casts the compiler won't help you unless what you're writing is actually illegal code.


The way my C++ teacher taught us over a decade ago:

  • static_cast<T> = "I know that type is naturally convertible to T."
  • reinterpret_cast<T*> = "Yeah, I REALLY meant it."
  • (T) = "Convert and shut the f... up!"

Personally, I don't use C++ casts in my code, but I don't have a strong opinion for or against using them: I just don't use them today, and perhaps I will start using them if it bites me in the face tomorrow. I don't really care.


EDIT: But I think having long and annoying to type keywords like reinterpret_cast<T>(...) hinders the use of C++ casts. I know it's supposed to encourage you to write code that does not need casting in the first place but I wonder if it's really working the way the C++ people saw it. If you could do a static cast by writing something like (static int) and I dunno maybe (mutable int) for a const cast I think there would be less lazy C++ programmers out there.

#5282756 Naming conventions, software documentation and version control

Posted by on 22 March 2016 - 04:32 PM


It might be informative to look at the naming conventions used in the standard library (defined through an ISO standards document)


This. A thousand times this.


Why is it that so many C++ programmers choose a Java style and (often) also throw out any and all uses of the standard library... 



I would not use the C++ standard library coding style as the definite coding style for C++. It's not that simple.


Stroustroup, for example, recommends to capitalize the first letter of your class names to distinguish them from the standard library names, which is not what the C++ standard library does. He also recommends using UPPER_CASE for macro names (if you can't avoid them in the first place) to emphasize on the fact that they are alien in C++ and do not respect language's grammar, even though standard macros like assert(...) are in lower.


So no I don't think the C++ standard library standard is meant to be a hint of how you should name your things. (Unlike Java which tries to impose the JFC naming on your own code to the point where Eclipse generates compiler warnings if you don't use the prescribed style!) Boost uses lower_case everywhere because its libraries aspire to be part of the C++ standard library so it's different from your game engine.


But by all means, if you like the all_in_lower_case style go ahead and use it! My point is just that the C++ standard library coding style is not necessarily meant to be imported in your code, the way the JFC coding style is meant to be used by all Java programmers.

#5282483 Naming conventions, software documentation and version control

Posted by on 21 March 2016 - 06:56 PM

1) What naming conventions to follow? Is this all opinion based? Is there a/an common/industry standard style


Yeah it's mostly opinion-based because neither C nor C++ recommends one, so people usually import the naming convension of whatever language they used before. If you learned from Java you are probably going to import it's naming convention (Yuck! I hate lowerCamelCase! tongue.png) as did a lot of C++ library writers because Java was the hot new thing from the mid 90s to the mid 2000s. (Qt and Ogre3D are examples of C++ libraries that imported Java style.)


Personally, it was VB6, COM and MFC that were the hot new thing when I started programming, and I mostly skipped Java, jumping straight to C#, so my style is very Microsoft-influenced.


The Linux/GNU guys will probably use all_in_lower_case because that's how the standards look over there.


Really, style issues like naming are more like a programmer's signature so use whatever you want in your own projects. (Obviously, use your organization's standards at work.) As long as whatever style you're using is readable and understandable, and you stay consistent, your coding style is fine. smile.png



EDIT: I forgot to mention that the big names of the C++ community came up with a guide in late 2015 that recommends a style, but that's the "Stroustroup" style, which is a style that pretty much nobody uses, so I wouldn't recommend that one as the definite style for C++. (The rest of the guide is pretty good though.)





3) How to provide a documentation for my software?


In most of the case, it's Doxygen, although if you ever do .NET, SandCastle (or whatever the new one is called) is a bit better because it will generate docs that looks consistent with the one on MSDN.

#5282255 Too good to be true?

Posted by on 20 March 2016 - 07:56 PM


Hypothetically speaking, I could:
1. Buy RPG Maker MV for $80
2. Craft a storyline better than your typical mobile game, taking 3 whole seconds
3. Make a RPG using premade assets
4. Throw in a couple of songs not in the kit for flavor
5. Release it on the App Store, because you can legally release games made with the kit even using the kit's assets AFAIK - just read the terms
6. Probably make a thousand dollars or more, since the premade assets would be up-to-snuff quality, and since you're really not competing with much, even among other people who used RPG Maker
What are the flaws in this idea? It sounds downright evil and diabolical, because most of us or at least me have it embedded in our brains to actually try harder than a kit like RPG Maker, even if we fail badly.....



A few points.


It takes time to make an RPG. When I dabbled with RPG Maker 2000, me and my brother both had our own RPG Maker games that lasted about 50 to 70 hours (which is about where it's acceptable for selling IMHO), but they took us years to make. I remember spending an entire summer just for a chapter of my game. Making interesting dungeons takes a bit of planning, writing good dialogues takes some time to reread yourself and ideally a few other pairs of eyes, making bosses that aren't either damage sponges or cheap shot spammers needs a good balancing eye, etc, etc, etc.


Considering the abysmal return on investment of the crushing majority of paid-for iOS games, spending that time flipping burgers at McDonalds will likely be a lot more profitable. If you're doing this to get super rich, the flaws in your idea is right there. You also forgot to add $100 per year for your Apple dev license, so your production costs are minimum $180, plus whatever licensing fees that your extra songs will cost you.


Yeah, you can bundle it with the premade assets, but if you actually take the time to make a good game, other people will have already flooded the App Store with cheap ass 2-minute games and people will be used to those assets. When I was in the RPG Maker community, whenever I saw games with RPG Maker "Alex" (or sprite rips from Squaresoft games for that matter) as the main character I hit ALT-Left and browse the next game. Although this is personal opinion, I also think that the current RPG Maker assets are fugly. You can use RPG Maker XP's graphics instead, but they are more work to use because the auto-tile function doesn't work very well with them.


Also, just in general I don't see the appeal of epic RPGs on iOS; I think it's silly to expect me to "game" seriously on my phone with a 6 inches screen and touch controls, and when you look at it, a lot of big companies (lol Sega) broke their neck on mobile platforms, thinking it had place for "true" games. Personally, I have owned Final Fantasy Dimensions on my Android phone for two years, and I am a huge fan of the classic Final Fantasy games, and I consider FFD this to be the best game titled "Final Fantasy" since FFX-1... and yet I still prefer playing Solitaire than Final Fantasy on my phone. (In fact I wish I could just play FFD on my PC.) I just don't care about "serious" gaming on my mobile phone, I want to play quick games on that platform. Things like Three!, Solitaire, Angry Birds, etc. So I'm not going to buy your RPG Maker game knowing that I didn't even finish Final Fantasy Dimensions... And I don't care about your epic storyline on my tiny mobile phone screen, I don't have the attention span for it when I'm playing on my phone. You could have the next Lord of the Ring or a story about a distant future where bionic toilets have overrun humans after a zombie invasion and it would be the same to me. Perhaps other gamers have more tolerance for tiny screens than I do, but to me gaming on iOS is a joke. Maybe I would on an iPad Pro but at that price I would put a Titan X in my PC instead.

#5276019 Best C# library for implementing graphic editor's functions

Posted by on 16 February 2016 - 03:57 PM

Microsoft has already done the hard job of adapting their Direct3D 11 API for use in apps that require high performance 2D graphics for which GDI+ is insufficent, and it is fully-featured because it's the rendering technology of WPF. The result is what we call Direct2D and DirectWrite.


If you don't mind C++/CLI interop code, I would recommend that you write a C++/CLI wrapper around the D2D features that you need and use that. That is what I did for my game editor in Windows Forms and it's order of magnitudes faster than GDI.


If you don't want to write C++/CLI you can access Direct2D via SlimDX or SharpDX but I had issues with those libraries.

#5276012 Pointers: "type* var" versus "type *var"

Posted by on 16 February 2016 - 03:04 PM

These days all I see in other people's code is var * type? Apparently some programmers are fed up with being told where to put the space and put it on both sides of the asterisk. laugh.png


As for my opinion, I think all has been said: var* type unless you are declaring multiple variables on one line.

#5270483 Handling string literals

Posted by on 10 January 2016 - 10:23 PM

I don't believe you can tell whether a string was given as a literal or as a variable, but it would be trivial if the following were legal C++.

constexpr bool is_literal_string(const char* p)
    return p[0] == p[0];

bool is_literal_string(const char*)
    return false;

If you have a string literal, the compiler is able to use the constexpr version, would pick it, and the function returns true. If you pass in a variable then it's unable to run the constexpr version, so it generates a call to the non-constexpr version, which always returns false. (And would likely be optimized away.)


The problem with the code above is that you can't overload function with an identical (but constexpr) version. I figure that would make function overload resolution even more complex than it already is.

#5270481 Criticism of C++

Posted by on 10 January 2016 - 09:43 PM

I wish C++ generated more default operators (like I don't get why I need to define both += and +, < and > and >= and <= and so on). I wish I could just go operator+=(const SameClass&) = default; if I write the related classes.

Yeah, I agree that you should be able to =default operator += if you have both operator+ and operator= defined. That being said, the += variant can very often be optimized by removing the temporary object, so most of the time you should reimplement += yourself anyway. When it's simple code, the optimizer can probably figure out how to optimize it on its own so I guess it would be safe to =default it, but when the code of operators + and = is complex, it's a lot less certain.
But I think you should always be able to write a default ++ and -- operator (both variants). It would require an implementation of operator+= and an implicit constructor that takes a single integer (of any type) for it's parameter.


operator!= should be default-able if operator== is defined, and vice versa, make sense. And as you said, operator>= could also be defaulted if you have operator<, etc.


The C# programming language went through a lot of changes that were all aimed at killing boilerplate code, and the changes of version 6 of the language is almost all about removing boilerplate. I would like C++ to go through similar changes to reduce the boilerplate to a minimum, and that would include adding more default-able methods. Not that no effort have been made, we have the new auto as well as lambdas, but I think it could be even better.

#5269142 Java, still being a good option for game dev in 2016 or there are other optio...

Posted by on 04 January 2016 - 12:50 AM



Between Java being out of date every 2 days, Oracle trying to stealth install the Ask toolbar every time people update their JRE, and Oracle going back on Sun's previous open-sourcing of Java just to copyright troll other companies, I rid all my systems of Java many years ago and I am not looking back.


People that insist on using Java in 2016 should embed the JRE and the product in a single executable so people don't need to babysit Java. I personally wouldn't play a game or use any product that requires the Java runtime to be installed on my computer.

#5269138 c# / c++ /cli wrappers

Posted by on 04 January 2016 - 12:23 AM

Note that you can also use unsafe and fixed to use pointers in C#, including pointers to arrays. By doing that, you can bypass the whole marshalling step. The limitation is that you can only use pointers to pure value types (as in may not have any reference type members). Using unsafe and pointers in C# is generally not recommended, but it's probably not worse than using C++/CLI.


Fixed pointers and unsafe methods are for interacting with P/Invoke, and P/Invoke and C++/CLI are complementary technologies, not competing technologies. To my knowledge, P/Invoke does not work with C++ libraries so C++/CLI is the only way to go. (Considering the absolute mess that is C++ name mangling, making an automated tool such as P/Invoke support linking to C++ library would be a total PITA to maintain anyway.)


To wrap a C++ library, you typically use C++/CLI and leave your C# code free of the unsafe stuff like pointers. If you have any unsafe stuff to do, you do it in your C++/CLI wrapper where pointers are first-class citizens and you can access both the managed heap (via references) and the unmanaged heap, and you do the marshaling yourself.


I don't find marshaling to be slow. I am using two (previously 3) C++/CLI wrapper libraries for my game editor in C# and it works incredibly well, although I am not using it to keep graphics animated at 60 FPS in the level editor. Marshaling obviously has a cost since there is processing to be done for any managed input on top of the forwarded method call, but I designed the API of my C++/CLI wrapper classes with no real care for mashaling efficiency and it still works well. I think you shouldn't suffer too much from slowdowns unless you are passing very long lists of managed objects that have to be copied. Strings can also be an issue because of encoding, but even then that should not be a huge issue unless your string contains the Lord of the Rings trilogy or something.

#5267927 Advice on coding style

Posted by on 25 December 2015 - 03:22 PM

The C++ core guidelines are not even close to what I would call an language's official style. The guide even says that this is only a suggestion if you have no better idea and that otherwise you should keep using whatever style you are comfortable with or whatever style your organization has chosen. I agree that the suggested coding style is questionable at best (since almost nobody uses it) but I think recommending a working coding style for beginners to start with is the right thing to do, otherwise they will just import whatever style they used in another programming language, which may or may not work with the C++ programming language.


A language's official coding style is something like a compiler or IDE enforced coding style that will get you looked down upon by the community if you don't respect. Use PascalStyle or iso_cpp to name a method in a Java program and see how Eclipse likes that. And in Ruby the capitalization of the first letter is very meaningful to the interpreter. That kind of thing doesn't exist in C++. (Which, I would add, is a good thing.)

#5267893 Advice on coding style

Posted by on 25 December 2015 - 03:59 AM

Seems like you're asking more for coding guidelines than coding style advices.


I think it's important to make the difference between guidelines (ie: good practice) and coding style. Guidelines can be objectively argued for or against and make your code better and usually make your code better. Coding style is more like a programmer's signature. Arguments on coding styles are basically made of fools arguing with other fools, sometimes very vigorously, which can be kind of funny.


Putting declarations on multiple lines is good practice because it can be error prone, especially in C and C++ because of the pointer and reference shenanigans. Systematically declaring a 1-parameter "explicit" unless you really mean to allow implicit construction is another example of a guideline.


Coding style is something like opening brace placement or naming conventions and in languages like C and C++ where no "official" style is suggested, you just pick one that suits your taste for your personal projects, and whatever your organization has decided on for work. No point in arguing on that. Personally, I hate it with the raging passion of a thousands supernovae exploding in unission when people use lowerCamelCasing to name public methods (use either snake_casing or UpperCamelCasing for your public symbols, IMHO) but I'm not going to tell you that it's better for humanity that you don't use that style. (Ok, maybe it's better for MY humanity, but that's a different thing. tongue.png )


And by the way don't ever think about using the Google coding guidelines for your C++ code, unless you have a parrot and are out of newspapers to put in the cage. It basically bans everything C++ brings on the table in the name of incompetent C++ developers that will use those wrong. I have no words for how much I hate the Google C++ coding guidelines. Look here for guidelines and coding style for modern C++: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md. This was written by the big names in the C++ community. I have a bit of reserves for their suggestions on actual coding style since they recommend a naming style that pretty much nobody uses, but again, arguments on coding style... lol, personally not gonna get started.