Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 Aug 2000
Offline Last Active Today, 12:52 AM

#5289201 Which alignment to use?

Posted by BitMaster on 29 April 2016 - 01:30 AM

[...] if your Component types are not strictly PODs (as in is_pod_v<Component> == true).

Correct me if I'm wrong, but isn't the check for PODs too strong? std::is_trivially_copyable_v should be enough.

#5287751 std::sort corrupts my memory

Posted by BitMaster on 20 April 2016 - 06:21 AM

Then you either use an extremely ancient version of the compiler or you can just write
without extra spaces between template closing brackets.

#5286849 Simple code for reading and writing file in UTF-16 mode

Posted by BitMaster on 14 April 2016 - 05:56 AM

I would just try to read/write the data using standard streams on char16_t instead of char while not trying to change the locale or anything else.

Well, actually I would avoid UTF-16 like the plague.

#5286635 I need a book (or somebody's project source code) which properly explains...

Posted by BitMaster on 13 April 2016 - 05:32 AM

As you can see I have no idea what I'm doing. I'm taking lines of code of random websites and pasting them into my program, then when it doesn't compile I move parts around so that stuff is (I hope) in the scope it's meant to be in. This is the technique I used to learn Blitz Max, and it works, because I can use Blitz today and instantly make a program which uses OOP, even though I haven't used Blitz since 2006  :lol:

This is not a method I would recommend to learn any language, least of all C++ where a lot of things can "appear to work" very easily while blowing up in your face later (sometimes much later, as in weeks or months).

Your problems are not really related to OOP though but essential bits of the language, like scoping.

This might be actually a disservice to you, but:
class Thing
Thing(int a, int b)
ThingRec.x = x;
ThingRec.y = y;
ThingRec.w = (x + 32);
ThingRec.h = (y + 32);

void drawMe(SDL_Surface* pic, SDL_Surface* vid) const
SDL_BlitSurface(pic, 0, vid, &ThingRec);
int x;
int y;
SDL_Rect ThingRec;

int main(int argc, char* argv[])
std::list<Thing> myList;
myList.push_back(Thing(10, 12));
myList.push_back(Thing(11, 13));

for (const Thing& thing : myList)
thing.drawMe(/* whatever */);

On a sidenote, when I see "using namespace std;" in a file I have the urgent need to punch the author.

Edit: Mhm. Apparently the darn forum editor does not even allow me to preserve spaces anymore. Apparently not a week can go by without it becoming ever slightly more broken...

#5286630 I need a book (or somebody's project source code) which properly explains...

Posted by BitMaster on 13 April 2016 - 05:04 AM

Yes, I suspect that "abstract class" is a term one uses when there is an abstract class, with inheritance used for sub-classes - hence, the original class (not actually used directly) is called the abstract class. I'll edit my file now and add the proper terms  :)

You suspect wrongly. An abstract class is a class which contains one or more pure virtual member functions. An abstract class cannot be instantiated because the compile prevents you from doing that. A lot of base classes are not abstract even when they are seldom or never intended to be instantiated.

#5285755 Should getters and setters be avoided?

Posted by BitMaster on 08 April 2016 - 03:36 AM

One of the reasons Yegor mentions is the dependency of clients connected to the object. Say, we suddenly want to know who withdrawn something from the object? I am not understanding why his "idea" would help us in any way. We still have to change the withdraw method and all clients using this withdraw method need to be changed. I guess I still have no clue what he is talking about.



If you can only withdraw money by calling 'withdraw' you can just add a new parameter to withdraw and your compiler will scream at you until all places where money is withdrawn supply that information. If you just manually decreased amount everywhere you have to find all uses of 'amount' manually in the code, identify which are actually withdraw operations and add the withdrawer information manually (help the compiler can be to you in that case: zero).



This eventually results in long constructors since all the final properties that are allowed to mutate (yes it sounds crazy) need to be set in the constructor.


If your constructor becomes so complicated you have to pass so many parameters you probably have a class which just tries to do far too much. Look into the Single Responsibility Principle (https://en.wikipedia.org/wiki/Single_responsibility_principle). Having immutable classes where reasonably possible certainly simplifies a lot of problems, but especially in the context of game programming it is not always doable. Spending a few moment to ponder "Do I actually need that to be mutable?" for a new class is not a bad idea though.


Edit: Stupid editor screwed up the link...

#5285398 glew does not initializes extensions

Posted by BitMaster on 06 April 2016 - 12:59 AM

Or you are linking GLEW statically which means executable and DLL both have their own distinct copy of GLEW and the copy you are initializing is not the copy used for further rendering.

#5285234 Project is missing SDL_mixer.h; I add it and the compiler gives 77 errors

Posted by BitMaster on 05 April 2016 - 05:19 AM

I'm not familiar with SDL but my guess would be these errors have nothing to do with SDL but originate in whatever framework your book supplies, probably because utility code it expects is not compiled/linked together.

#5285222 Is it bad to use macros such as __LINE__ or __DATE__?

Posted by BitMaster on 05 April 2016 - 03:38 AM

There is no library which could provide this information. You could only get that functionality with a custom preprocessing step before passing the source to the compiler (which would be just a hand-rolled kind preprocessor definition again).

#5285221 Project is missing SDL_mixer.h; I add it and the compiler gives 77 errors

Posted by BitMaster on 05 April 2016 - 03:26 AM

Well, SDL 2.0 has been out for a long while now and although I have never used it from what I have heard it's much better than its predecessor. You cannot really expect deprecated stuff to remain around indefinitely.


Also, I now have the strong suspicion your unresolved externals have a very different source than linking or not linking SDL mixer. Most likely it depends on some Windows multimedia functions which you have to link as well. Of course that would have been immediately obvious had you posted the actual error messages. Which you unfortunately did not.


On a personal note, this is the second time you go towards blaming the tool in this thread. A decent programmer does not blame the tool until he has understood the whole problem and exhausted all options. Placing the blame on the tool early and often is a good way to tick people off and receive less and less help in the future.

#5285006 Project is missing SDL_mixer.h; I add it and the compiler gives 77 errors

Posted by BitMaster on 04 April 2016 - 05:41 AM

I've had mixer.dll in the project folder the whole time. I added SDL_mixer.lib to sdl's LIB&amp;nbsp;directory and I&amp;nbsp;tell Visual Studio to include it as an additional dependency and it still gives 76 errors.

Are you telling MSVC to actually link it or have you just specified it as a dependency?

It tells me to use /nodefaultlib:library but what the heck is that? Do I replace the words "library" or do I input that parameter verbatim? I don't understand how the compiler complains about one thing, then I add what it wants, and it gives 77 warnings. It's so stupid! I have sympathy for people who try programming and give up. The errors make no sense. Before anybody asks, yes I can reproduce this problem over-and-over again. I want to know how to fix it.

I guess this error has something to do with Microsoft's stupidity in making Visual Studio. I think maybe I can kill off msvcrt.lib and there will be no conflict. Should I do it?

A library you are trying to link was compiled with a different MSVC runtime than the one the rest of your project is using. This could be a different version or a conflict between dynamic/static or debug/release runtimes. You need to download a version which matches your build system or build it yourself using the adequate compile time options.

#5284629 text file -> object file -> link ?

Posted by BitMaster on 01 April 2016 - 11:19 AM

Unless you absolutely know you will only ever be using MSVC I would not do something like that. Both at work and at home I'm using CMake for that. The tool which does these transformations is a simple command line application inside the project. CMake tracks the dependencies, builds the tool before anything needing the transformations and executes it as part of the build process. It's CMake's job to put that into a form your build environment understands, whether that is MSVC project files, a bunch of make files or soemthing else.

#5284626 SpriteFont render Umlaute

Posted by BitMaster on 01 April 2016 - 11:00 AM

In my opinion the console is irrelevant. Check the content of your strings with the debugger, not by printing them to the console. The console expects some encoding, perhaps Latin-1 (which works fine the range 1-127 but not beyond) or ANSI and whatever encoding your compiler generates is probably not the same.

For example when I print "Test 'ü'" to the console in a source written in stock QtCreator and compiled with MinGW I get "Test 'ü'" printed out. The debugger says the same and the values of the relevant bytes are a 195 followed by a 188. Now, I could take a look at how UTF-8 was encoded again and do the check myself. However, it's been a long day and I'd rather use this cheat sheet but it confirms I'm dealing with UTF-8.

Now, we are not even sure what the encoding of the string is in your source file. If you wrote it with MSVC it does something, but not the sensible. Open your source with a decent text editor (like Notepad++) and convert it to UTF-8 (with the BOM - the BOM is not recommended but MSVC does not recognize UTF-8 properly without it).

Now, dealing with UTF-8 is not the simplest thing since multiple bytes can be used for a single character. Still, I strongly recommend it for sanity, and I say that as someone who has written applications which translate freely between German, English and Italian (sometimes other languages).
For a simple game with extremely limited text output it might not be worth the battle but the battle is won and lost at string encodings no matter how exactly you solve the issue. You absolutely need to know in which way your input strings are encoded and which mapping the font uses.

#5284616 Actor object understanding

Posted by BitMaster on 01 April 2016 - 09:35 AM

Of course. Unfortunately you do not post anything that would allow anyone to help you. You know, simple things. Like the code you are having problems with together with the error message. Crystalball-based forum posts usually do not work out well.

#5284486 Actor object understanding

Posted by BitMaster on 31 March 2016 - 07:52 AM

Initializer list