Jump to content

  • Log In with Google      Sign In   
  • Create Account


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

#5294277 Do you usually prefix your classes with the letter 'C' or something e...

Posted by BitMaster on Today, 02:14 AM

It sounds to me using "CppClass" instead of "Class" as such the suffix would solve the whole situation in a far more elegant way. It opens the way to whole new classes of vomit in your brain (BrainVomitClassCppClass in this case).

#5294138 Animated Cursor: how get frame delay?

Posted by BitMaster on Yesterday, 06:27 AM

The link ApochPiQ posted appears to describe tagANIHeader already, including where to find it in the .ani files. Either you will have to implement what is described there yourself or you need to find a library which does it for you. Considering the format looks rather simple to implement I would not spend a lot of time looking for a 3rd party library.

#5294120 Creating Cross-Platform Code

Posted by BitMaster on Yesterday, 01:31 AM

There are common tools like make, cmake that were used for over 20 years but in the case of make have the problem to be build arround the unix shell so most features are worthless on windows.

CMake does not need any special command line features. It can just generate a classic MSVC project structure when you work with it anyway and even the make files it generates are extremely tame. That said, having a *nix shell on Windows nowadays is hardly a big deal. Git for Windows comes with one out of the box. For the more arcane corners these is msys (comes with a lot of gcc distributions out of the box, can also be added with little work by hand) or Cygwin.

#5294065 Creating Cross-Platform Code

Posted by BitMaster on 29 May 2016 - 12:44 PM

You might want to take a look at build system generators like CMake or Premake. Dealing with file adds/removes/renames and compile option changes across multiple build systems is one annoying chore. I had to deal with that at work for a while and CMake really chopped off a lot of problems there.

If you want to keep using MSVC, keep doing it. Just make sure you do some test runs with gcc or clang regularly (build system generators like CMake should make that extremely trivial). MSVC compilers accept some code (especially when templates are involved) which are very much non-standard. Expect to spend quite a lot of time here at first, especially if you never worked on non-MSVC compilers. That becomes much less time-consuming once you get a hang for it.

Most of the platform dependency comes from window creation and context management. If you don't need any extra bells and whistles any of the usual suspects (SDL, SFML, GLFW, possible others) probably are all you need. With C++11 and C++14 Boost has become more of an option for me, but it still contains some useful abstractions (for example memory mapped files, although I have not tried them myself so far).

#5293181 I doubt I understand RAII just yet

Posted by BitMaster on 24 May 2016 - 04:17 AM

While I did not downvote you nor do I know the mind of the person who did, I kinda agree with the vote.

Your advise feels like bad advise. RAII is so fundamental to working in C++, if you do not have a solid grasp on it you should strive to remedy that situation as soon as possible. The reason for not using RAII should be <well-reasoned rationale> not 'nah, never had to use it before'.

#5293010 How to round 2 Straight lines

Posted by BitMaster on 23 May 2016 - 02:59 AM

The concept you are looking for is subdivision (on lines). Have a look at this slide and the following for example.

#5293002 c++: sprintf but return chars. Possible?

Posted by BitMaster on 23 May 2016 - 01:57 AM

The iostream classes are often very annoying to work with when you have to deal with more complex substitutions. It can become very hard to read, very fast.

Something like boost::format is often a better idea because it combines a familiar, easier to read syntax with all the type safety C++ can offer you.

#5292998 Wrapper Function for lua_register?

Posted by BitMaster on 23 May 2016 - 01:28 AM

This has nothing to do with the Lua registry. Or even Lua.

A member function (that is, a non-static function in a class or struct) is fundamentally different from a free function. A free function (often called a C function) can interact very simply with C code. A member function cannot.

Lua is written in C and thus cannot interact interact with C++ (there is no well-defined C++ ABI and as such 'calling a member function' is an unsolvable problem because different C++ compilers have very different idea what exactly that means and how to do that).

The link ApochPiQ posted will certainly help with part of your problem ('how do I write glue code to deal with that'). It does not seem to go into much detail beyond that and it opens a whole can of worms about 'why do I have to do that at all?' (for a few basic keywords to start your search, see above) as well as where to store the this-pointer as well as questions about the lifetime and ownership of this between C++ and Lua from then on.

It would have been a better idea to post this in For Beginners since that would have obligated people to be a bit more verbose in their answers (I don't have the time now, though). I would also advise you to take a step back from Lua for the moment and deal with the issues raised here in a pure C++ world for now. It's not horribly difficult but you will need to spend some time there to get a feeling for the area and Lua just adds additional complications on top of that.

#5291083 Operating System Questions in Assembly

Posted by BitMaster on 11 May 2016 - 01:27 AM

Based on your question, I think you should step back and evaluate your ability to complete this project.

Honestly, you are building a space shuttle and you've just asked about spray painting the NASA logo on the side.

The OP is (according to their profile) thirteen. Personally, for that age group I find it advisable to just give them the information desired and let the empirical values of something deceptively simple-sounding become a huge problem be a first-hand experience. We get a lot of older people who really should have learned that lesson earlier.

It's not even wasted time (especially at that age). You will be gaining skill points all over the place while working on it even with the originally intended goal not achievable.

#5290804 Operating System Questions in Assembly

Posted by BitMaster on 09 May 2016 - 08:42 AM

Executables on Windows follow the PE Format. Note that to run Windows executables you not only have to interpret the data format correctly you will also have to emulate a considerable part of the Windows runtime environment. Wine might be a good starting point for that.

Also note that it is generally an extremely horrible idea to put two completely different questions into the same thread.

#5290768 Manually loading OpenGL functions on Windows

Posted by BitMaster on 09 May 2016 - 03:05 AM

I have never dealt with working with loading GL functions by hand but that does not surprise me. The documentation of wglGetProcAddress says

The wglGetProcAddress function returns the address of an OpenGL extension function [...]

. glClear is to my knowledge as core as you can get in any version of OpenGL so should never be retrievable via wglGetProcAddress.

#5290520 How to implement Lua scripting into my game?

Posted by BitMaster on 07 May 2016 - 02:12 AM

There are plenty of solutions. I had a look at both lua-intf and integral in the past and they seemed to offer a lot of convenience and ease of use. Note you might also want to look at less general and more domain-specific solutions for your scripting. That will almost certainly require some work of your own but you can squeeze out a few drops more of performance and support scripting semantics which will be more difficult with a general solution. You will also learn a lot of the nitty gritty details of interaction with Lua.

#5289216 Data alignment on ARM processors

Posted by BitMaster on 29 April 2016 - 05:23 AM

*((unsigned char*)(&result)) = *offset;

Watch out for compiler optimisations breaking code like this (called type punning). It breaks the language aliasing rules. See this link:


Except this is irrelevant since the char-types are explicitly allowed to do this.

#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.