Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


NightCreature83

Member Since 21 Feb 2008
Online Last Active Today, 02:41 AM

#5209598 Calling virtual abstract class function

Posted by NightCreature83 on 09 February 2015 - 08:41 AM

If you are on a C++11 compliant function its a good idea to add the "override" key word to any virtual function in a derived class, this will make the compiler check whether you are actually overriding a base class function and not just be accident adding another virtual function to the chain.

 

Can you actually post the exception message you get in the output. I am suspecrting that the pointer you are trying to call this function on is a null pointer, and that is the cause of the crash.




#5208362 Render To Texture

Posted by NightCreature83 on 03 February 2015 - 04:07 AM

The backbuffer is nothing special its just a texture as long as one is bound the present call will present the content of it to the front buffer and display.




#5207570 Profiling tools

Posted by NightCreature83 on 29 January 2015 - 06:08 PM

Well, Visual Studio comes with one built in that you could start with.

This one sadly does only whole timeline sampling and I would like to get those samples ordered a bit different, specially on a per frame basis not sure the VS filters allow this sort of profiling. The documentation for the VS profiler seems geared towards managed application profiling, I am more interested in native profiling, if you have better documentation for the VS Profilier that info is more than welcome.

 

Ok finally found this stuff in VS its a bit hidden but the info can be found here: https://msdn.microsoft.com/en-us/library/windows/desktop/jj585574%28v=vs.85%29.aspx

The trick is to tell VS to do a CPU and GPU sample based profile at the same time, and then setting the time frame to the time it took to render one frame. Sadly this is not ideal, specially since you have no control over how many samples the profiler will do per second.




#5207113 Confused about XMFLOAT2 and D3DXVECTOR2

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

 

https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.arithmetic.xmvectoradd%28v=vs.85%29.aspx




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

Posted by NightCreature83 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)
{
  x=param.x;
  y=param.y;
  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 NightCreature83 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 NightCreature83 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 NightCreature83 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 NightCreature83 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 NightCreature83 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 NightCreature83 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.

 

http://www.zlib.net/




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

Posted by NightCreature83 on 07 December 2014 - 02:39 PM

http://www.cplusplus.com/doc/tutorial/program_structure/




#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:
http://www.gamasutra.com/view/news/128161/A_Low_Level_Curriculum_for_C_and_C.php
http://www.gamasutra.com/view/news/128857/CC_Low_Level_Curriculum_Part_2_Data_Types.php
http://www.gamedevelopment.com/view/news/129645/CC_low_level_curriculum_Even_more_stack.php
http://www.gamedevelopment.com/view/news/165036/CC_low_level_curriculum_Conditionals.php
http://gamedeveloper.com/view/news/169946/CC_low_level_curriculum_Looking_at_optimized_assembly.php
http://www.gamasutra.com/view/news/177155/CC_low_level_curriculum_Loops.php

http://www.gamasutra.com/view/news/184430/InDepth_CC_Low_Level_Curriculum_Part_10_User_Defined_Types.php

 

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

Another good series on x64 assmebly are these youtube videos:
https://www.youtube.com/playlist?list=PL0C5C980A28FEE68D

 

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.






PARTNERS