Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 11 Jan 2013
Offline Last Active Feb 23 2016 08:45 AM

#5272562 WinAPI WNDPROC to Engine/Game MessageHandler

Posted by on 25 January 2016 - 06:04 AM

Another way is to capture messages in the main loop when returned from GetMessage/PeekMessage.


This is in general not an option, since Windows sometimes uses an internal message loop instead of the applications loop, e.g. when a menu is opened, the window is resized, when a modal dialog is shown...

#5166143 c++ function pointers

Posted by on 11 July 2014 - 01:46 AM

I second SiCrane, If you want to know what it would look like without typedefs, though:

int AddOne(int a)
    return a + 1;

int (*GiveMeFunctionPointer())(int)
    return &AddOne;
Function pointer types are weird. It sort of goes around the function declaration.


In the "new" standard (C++11), you can use a type alias instead of typedef:

using PF = int(*)(int);

Or, without typedef or alias, C++11 allows trailing return types; the syntax may be somewhat clearer:

auto GiveMeFunctionPointer() -> int (*)(int)
    return &AddOne;

#5157498 Why is infinite technically not a number.

Posted by on 02 June 2014 - 02:58 AM

There are ideas how to extend the field of real numbers to include infinity:


(The German article is more elaborate: http://de.wikipedia.org/wiki/Erweiterte_reelle_Zahl)

However, the usual arithmetic rules would no longer hold in such a field, because this set is no longer an ordered field:


So in practice it seem to be not very useful to work with such a definition.


Related question:

From a mathematical point of view: If you die young, are you longer dead?

#5143409 confuse with row major and column major matrix multiplication in hlsl

Posted by on 31 March 2014 - 01:46 AM

The HLSL compiler works with both column major and row major matrixes; command line switches Zpc and Zpr are used to declare the matrix ordering. IIRC Zpc (column major) is default. Maybe your shader was compiled using Zpr?


However, your last paragraph about matrix multiplication is wrong. The notations "row major" and "column major" only apply to storage. They say nothing about how the matrix elements are interpreted, and how the order of multiplication is. When writing "vec * matrix", vec is interpreted as row vector (a 4 * 1 matrix), and the multiplication works out as 4 dot products of vec with the columns of the matrix. With "matrix * vec", vec is assumed to be a column vector (a 1 * 4 matrix), and the multiplications are dot products of vec with the rows of the matrix. Again, this has nothing to do with the ordering of matrix elements in memory or registers.


"Column major" in terms of HLSL means the compiler assumes that each register contains a matrix column; "row major" means each register contains a row. When writing "vec * matrix", the compiler will create different assembly code with Zpr and Zpc; the code created with Zpc (column major) is slightly more efficient, but both is possible and correct.

#5139789 Exactly what's the point of 'int32_t', etc.

Posted by on 17 March 2014 - 02:19 PM

And the code runs on 32 bits machine the x memory will start at the 5th byte while in a 64 machine it would start at the 9th byte. In this example you would surely run into a bug and very likely into a seg_fault.

This ain't necessarily so. In MSVC all int types have the same size on 32 and 64 bit; i.e. long is also 32 bit.

#5135132 Using the same message processor but closing only 1 window

Posted by on 27 February 2014 - 01:10 PM

Wait - you have 2 dialog boxes displayed at the same time? So these are non modal dialogs? In that case, using EndDialog is wrong. EndDialog is for modal dialog boxes only.

#5134703 C++ Constructors vs. Init() Functions

Posted by on 26 February 2014 - 03:32 AM

If your base class is depending on a specific variable to be allocated by the inheriting class object, you're going to get a null reference error in the base class.

This seems to be a strange design. Can you give a more concrete example? Why would the base class know about variables of the derived class?

#5134430 Wondering how heap allocation works with classes[c++]

Posted by on 25 February 2014 - 09:04 AM

I think your confusion comes from the fact that there are "reference types" (class) and "value types" (struct) in C#. In C++, there is no such distinction. Everything is a value type; if you want to have references or pointers, this must be specified explicitly.

So if you add a member of type Bar to class Foo, and Bar needs 32 bytes, the size of Foo grows by 32 bytes (assuming no padding bytes). There is no pointer or reference in Foo that points to an instance of Bar.

#5132901 I don't get c++11.

Posted by on 20 February 2014 - 02:16 AM

Rant (slightly off topic):

And still, in 2014, Microsoft does not fully support the standard. The latest thing I came across: No defaulted move constructors or defaulted move assignment operators.

It's quite remarkable that the "convener" of the ISO C++ committee, Herb Sutter, is MS employee...

#5132582 I don't get c++11.

Posted by on 19 February 2014 - 04:28 AM

But imagine I wanted to use a local variable of 'main()' in my lambda...

int main()
    int localVar = 357;
    auto foo = []()
       return localVar;

    int x = foo();
...lambdas can "capture" the local variable, either by value or by reference, and access it later (assuming the reference is still valid).


 Two errors here:
1. Missing default capture mode, must specify either [&] or [=];
2. Missing ; behind lambda definition:

int main()
    int localVar = 357;
    auto foo = [=]()
       return localVar;

    int x = foo();

#5131224 C++ Primer - CodeBlocks

Posted by on 14 February 2014 - 04:04 AM

By default, Code::Blocks creates a subfolder for new projects, with the name of the project. Check where the project file is located (*.cbp). The *.cpp and *.h should be in the same folder; otherwise you have to add the include folders in the project settings, as explained in the link provided by molehill mountaineer. Do not follow the "workaround" shown there, this is bad practice.

#5130991 From C to ?

Posted by on 13 February 2014 - 02:43 AM

I wouldn't go on C++ right now. Main problem is that there's no such thing as "C++" to start with.

Oh, come on.

I'm so happy that C++ is evolving again, after so many years of standstill. Simply take a modern compiler like MSVC or GCC and take off. There are still some minor restrictions regarding C++11 support, but well, if it's not one thing, it's another.

And regarding different versions: What C# version are you going to learn: 3, 4, 5? And what .net framework: 3.5, 4.0, 4.5?

#5130766 How much planning do game programmer before writing a single line of code and...

Posted by on 12 February 2014 - 03:17 AM

Before a single code is worked on, the Technical Design Specification should be completed.

Honestly: Does it really work that way in your company?

In my 17 years as software developer this never happened.

Problem 1: You cannot write a meaningful spec without prototyping and testing, and this includes: Coding.

Problem 2: If you write a full spec, the relevant people will not read or understand it. And in the end, when you show your final product, these people will state that they wanted something completely different.

#5130544 Needing help on how to "re-begin" on C++

Posted by on 11 February 2014 - 09:05 AM

C++ books as a whole have done a really piss poor job of updating to C++11. Many of the ones I checked out simply bolted C++ 11 features on as additional chapters, which is a very wrong headed approach to it.

This is true, but there is one good reason for keeping the C++11 stuff separated: Compiler support. If the examples in the book require some feature your compiler does not support, you're lost. If it's optional, you can skip that part for now.

#5130541 Needing help on how to "re-begin" on C++

Posted by on 11 February 2014 - 08:57 AM

I found a Visual Studio 2010 Setup DVD...

Why not get Visual Studio 2013 Express, it's free (http://www.microsoft.com/en-us/download/details.aspx?id=40787). It supports much more of the new C++11 features, although support is still incomplete (shame on you, Microsoft!).

Or get the Code::Blocks IDE (http://www.codeblocks.org/). The included GNU compiler is even more free and more standard compliant.

And, yes: C++11 matters