Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 21 Feb 2008
Online Last Active Today, 05:27 PM

#5207113 Confused about XMFLOAT2 and D3DXVECTOR2

Posted by on 28 January 2015 - 03:22 AM

The reason behind this change is that the DirectMath, XM* stuff, supports SIMD instructions which allow you to add 2 vector4 together in one operation. SIMD liberaries are constructed in such a way that they keep all of the data in XMM registers on the CPU. This means that the operations like +, -, * and / are implemented as standalone functions that return a XMVector and takes two XMVector arguments.



#5206563 Is it a very bad idea for a class to pass (*this) into a function? Strange bu...

Posted by on 25 January 2015 - 11:16 AM

There is something else going on.  C++ programs use *this all the time.

Vector2d& Vector2d::operator= (const Vector2d& param)
  return *this;

There should be no problem pass a (this*) to a function.  



Also, I know that "this" is a pointer... and since * is used to dereference a pointer, does that mean passing (*this) is pass-by-value?


As far as this part goes, it can be confusing.  C++ function arguments are always "pass-by-value".  Everything that goes into a function is copied.  That's why you pass a pointer or reference instead of an object.  It can be a lot cheaper to copy a 32bit pointer than a huge object.  For instance, when you pass a pointer and then access the thing it points to, you are using a copy of the pointer that points to the same object.


As an example, what does this do?

void func( int* intPointer ) {
   intPointer = new int{2};

void test() {
   int x = 4;
   int* intPointer = &x;
   func( intPointer );
   std::count << *intPointer << std::endl;

If the int* was passed by reference, then we have changed it to point to a different value.  Is that what happens?

Just as a point but a pointer is not necessarily 32 bits and you should never ever write code that actually relies on the exact size of a pointer. This is what causes a lot of bugs in software when switching from 32-bit to 64-bit.


#5206558 alpha question

Posted by on 25 January 2015 - 10:51 AM

    uniform float alpha; //This needs to come from the main application
    in vec2 textuv;
    uniform sampler2D textsampler;
    out vec4  color; float a = 1.0;
    void main()
       color = vec4 ( texture2D(textsampler, textuv).rgb, alpha );

You need to not do any calculation in the shader at all as mentioned earlier, I just fixed up your shader so you can see what it would look like.
If you do want to do this in a shader you need to not send in the dt from frame to frame, you need to send in an actual elapsed time since the effect started which also gets updated on the CPU not the GPU. In the case of the elapsed time, you would actually do the minus.
To change the speed at which the fade effect works you need to take into account how fast your application is updating and maybe add a speed up/slow down factor to achieve what you want.

#5205328 A new beginning, some questions for pointers for a stranger to coding

Posted by on 19 January 2015 - 10:50 AM

I would advice you to pick the PC as your platform to start with, because for managed langauges it is still the best platform. On the mobile ones you will run into issues you might not yet be able to deal with, remember the phones have a whole lot of less power.

#5201413 Yet another global variable debate

Posted by on 02 January 2015 - 05:10 PM

This pattern is used a lot, whether its a global variable or a singleton, the idea for access is the same. Usually its done to make the components you need to access easier, however they always are hidden dependencies. I dont use this pattern in my own code, I only have one global variable called application, it spawns all the rest of the systems and uses dependency injection to pass a resource object around that has pointers to all the systems.

#5198015 Text rendering and low FPS in game.

Posted by on 13 December 2014 - 12:13 PM

To keep text rendering fast you will want to actually use bitmap font rendering, I have never heard of a tripple A game that actually uses something else to do text rendering with. Btw we also generate this maps and table lookups offline and and load the transformed data to render with.

To actually get fancy and nice rendering with this you might want to look at SDF bitmap rendering, which generates smooth edges at any magnification of the font.

#5197750 C++ | DirectX | Class system ?!

Posted by on 12 December 2014 - 04:39 AM

std::list might not be the most appropriate data structure to use in C++ depending on what you're doing. I don't know if Java's 'list' is a linked list or not either. Google says Java's List by itself is just an interface so you probably mean either ArrayList or LinkedList . std:list is most like LinkedList and std::vector is most like ArrayList. There are many other data structures to look into. std::deque never gets as much attention as it should since it can be a good compromise between std::list and std::vector.

I know you are trying to link std containers to how they work in C# or Java, but what you are saying is incorrect.

  • std::list is implemented as a double linked list, and thus is always a linked list, a list in C# or Java is only an access interface the container underneath can be anything.
  • std::vector is always an array, and it has more in common with a naked array in any language than any other container.
  • std::deque is implementation dependant on how it works, for small queues it usually is an std::vector, but it could also be a more complicated datastructure, where it conceptually resembles a linked list of arrays, but this is usually stored as an array of pointers to those memory blocks

std::deque should be used when you need to be able to add or remove elements from both ends of the queue with O(1) access time, usually these things are used for commandlists where you get from the front and add at the back.

#5197615 Efficiently when compressing char* to std::string

Posted by on 11 December 2014 - 11:13 AM

Or just link to the ZLib library yourself and avoid the overhead of boost completely. The ZLib library is not that hard to use and the documentation is clear.



#5196840 C++ | DirectX | Class system ?!

Posted by on 07 December 2014 - 02:39 PM


#5196769 C++ | DirectX | Class system ?!

Posted by on 07 December 2014 - 05:29 AM

In C++ you have header(.h) and implementation files(.cpp, .c, .cxx) you need to create these files yourself and add them to the project. In the header file you specify how the class looks, so which methods and variables it has, in the cpp file you actually implement the methods, this is split from how Java or C# does it. When you want to use a class thats defined in another file you include the header file , with a #include statement, into the file where you want to use the class name.


Be careful with including headers in other headers because you can create loops and the compiler can't deal with that. there are other ways to deal with that, forward declarations, but this is a more advanced topic.


PS you can use COM in other files as well they dont have to be in the main.cpp file, the main.cpp is usually just the file that defines and implements the main function so the application can start.

#5193759 C# .Net Open Source

Posted by on 20 November 2014 - 03:42 AM

I don't like Mono but might try C# when it will be integrated fully in Ubuntu. When speed is comparable to C++ and doesn't pose install fuss for users, I might use it or simply stick to C++. I'm curious if Unity3D will move to MS C# as they didn't update to the latest Mono.


C# is generally speaking only slower on first boot, because the runtime is compiling the application down to native instructions based on the environment setup.


Poor cache awereness in the application code however might hurt the performance more, but then again if you dont do this in C++ you will have the a similar slowdown.

#5193434 Disassembly and assembly links

Posted by on 18 November 2014 - 08:41 AM

As I was gathering info on how to learn to read disassembly today I figured I would place the results on here as well for anyone who is interested.


First Up is Alex Darby's series on C/C++ disassembly, he teaches you how to read disassembly by going from C/C++ source code to disassembly generated by the MSVC compiler:



If altdevblogaday ever comes back you can find the whole series there.

Another good series on x64 assmebly are these youtube videos:


He starts from the other direction and shows you how you can call asm code from C++, the reason why you need to do this in a different manner from x86 is because the 64 bit compiler doesnt allow inline asm anymore. There is 65 videos in that link with an average runtime of 15 minutes and covers stuff from simple instructions all the way up to MMX, SSE and AVX.


I hope this information is useful for someone.

#5191535 Rate the code of my game!

Posted by on 06 November 2014 - 10:37 AM

mah eyes they are bleeding!

#5190339 Why don't you use GCC on windows?

Posted by on 31 October 2014 - 06:34 AM

Why are you not using Clang on Linux?

#5187131 c++ segmentation fault

Posted by on 15 October 2014 - 05:58 AM

You could also modify the default stack size in your compile settings which will allow you to use larger stacks.


gcc: --stack=reserve, commit

MSVC: /STACK: reserve,commit


reserve is virtual memory size, commit is actual physical size


I couldnt find the clang version but it will be similar to gcc to be honest.


Be careful of messing with these settings because they are set to be small for a reason, large stack sizes will not detected endless recursion fast.