Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 21 Feb 2008
Offline Last Active Today, 07:05 AM

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

Posted by NightCreature83 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 NightCreature83 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 NightCreature83 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 NightCreature83 on 06 November 2014 - 10:37 AM

mah eyes they are bleeding!

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

Posted by NightCreature83 on 31 October 2014 - 06:34 AM

Why are you not using Clang on Linux?

#5187131 c++ segmentation fault

Posted by NightCreature83 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.

#5185257 D3DCompileFromFile

Posted by NightCreature83 on 06 October 2014 - 05:59 AM

its the function that the HLSL shader will use to set as the function to execute when you call this shader. Its the same as the main function in a C/C++ application and you need to provide this so that the HLSL compiler and runtime know where to start from.

#5184267 Updated from VC 8 To VC 10 and My App Has a Error in VC10 xstring Help

Posted by NightCreature83 on 01 October 2014 - 03:39 AM

Expect even more fun if you use custom allocators with STL, the allocator interface for STL changed with VC10.

#5181263 Multiples of 16B constant buffer or Microsoft gone mad.

Posted by NightCreature83 on 18 September 2014 - 07:37 AM



Also, alignment.


a-har a-har a-har... not.


seriously, one thing is to read documentation the other is reading hundreds of pages just to prevent something you have no idea of what. most functions and other programming instruments offer functionality that isn't needed most of the time. that's like reading about rocket science just because you are interested in a fuel tank that is also used in rockets by coincidence.


RTFM, when reading msdn documentation always, ALWAYS, read the remarks section! In this case the allignment of 16 bytes is done because you can nicely stuff 4 floats in there, or a vector4. Coincidentally CPUs like this allignement because the can now write a nice block to another nice block without having to do address computations.


By allowing you to specify your own buffers you can enforce the allignment by using __declspec( align( 16 ) ) before struct in MSVC.

__declspec( align( 16 ) ) struct MyStruct

This will pad your structure so it always lands on a 16 byte boundary.

And even in D3D9 times MS actually always wrote on a 16Byte boundary to the shaders in the effect code everything was sent as a float4 to the shader even if you called a setFloatParam on the effect or shader. MS has just made it easier for you to construct your buffers, without lifting this restriction.

#5178484 GOTO, why are you adverse to using it

Posted by NightCreature83 on 06 September 2014 - 04:45 AM




Let's not forget that goto fail; happened.

Braceless conditionals are eeeeevuuuuul!


This is true. Though with the goto fail example, shouldn't the compiler have produced an "unreachable code detected" warning? (Or do they still not have that kind of static analysis there?)

Maybe I'm just spoiled by C# compilers...


Who's to say the project doesn't compile with a bajillion warnings, or that particular warning is disabled?


That's the reason for always compiling with /w4 and treat warnings as errors.

#5166401 Fallout 3 Terminal in C++

Posted by NightCreature83 on 12 July 2014 - 06:59 AM

The other option is to use a mask that animates per line on the rendering. You can then just set the text of all lines and the mask animation will reveal text as goes a long untill it is finished.


Ignore this I missed the console app, my solution will only work if you are doing some fancy rendering

#5162965 Direct3D 11 Swap-Chain Madness

Posted by NightCreature83 on 26 June 2014 - 02:34 AM

I can’t use D3D11_CREATE_DEVICE_DEBUG without the Windows SDK 8 installed, something I fear doing considering apparently some things have to be done through Visual Studio 2012 (which I do not have).

L. Spiro


VS 2012 makes it easier to launch these applications, you can still just manually go into the SDK directory and launch the tool you need from there.

#5162492 Direct3D 11 Swap-Chain Madness

Posted by NightCreature83 on 24 June 2014 - 02:39 AM

Have you turned the Debug runtime on, because as of WIN8 SDK this has to be done through the VS2012 and up window or through executing the settings window from the WinSDK directory. It will not turn your debug runtime on other wise even though you did set it on in the D3D june SDK. http://blogs.msdn.com/b/chuckw/archive/2012/11/30/direct3d-sdk-debug-layer-tricks.aspx

#5160808 Untransformed vertices coordinates.

Posted by NightCreature83 on 16 June 2014 - 03:51 AM

In D3D9 you control the culling mode with D3DRS_CULLMODE and set it to CCW, CW or No culling. You sometimes might want to change this value because of how you are rendering things.

#5155183 Templates causing linker errors.

Posted by NightCreature83 on 22 May 2014 - 02:44 AM

template <class T>
void list_add_end( node_t<T>** list, T data );

If all you do is modify what the list pointer needs to point at please write this in the C++ way, which looks like this:

template <class T>
void list_add_end( node_t<T>*& list, T data );

Also means you don't have to write your pointer modification code like this anymore:

node_t<t>* newNode = new node_t<T>();
*list = &newNode;
//instead you can just write this
node_t<t>* newNode = new node_t<T>();
list = newNode;