Jump to content

  • Log In with Google      Sign In   
  • Create Account

Jason Z

Member Since 04 Feb 2004
Offline Last Active Yesterday, 08:33 AM

#5172438 I know a good amount of C++ but what do i need to know about game programming?

Posted by Jason Z on 09 August 2014 - 05:49 AM

First of all, you should know that it is normal for being overwhelmed when you get started in a new area of programming.  Even if you know a particular language, it can be quite difficult to sit down and read the designs for a particular industry.  So don't stress out about it - just take it one piece at a time and make progress.


I think the other advice that was already given about learning how the main loop works is a good place to start.  Once you know that, then you can move on to the update method and all of the things that are done there - rendering, then audio, etc...  But make a concerted effort to only concentrate on one topic at a time, and you will be able to digest the information more easily.

#5169289 C++ avoiding pointers

Posted by Jason Z on 26 July 2014 - 07:33 AM


EXACTLYYYYY finally one man on earth understands programming. damn. why is it so hard to make people forget about those damned rule of 3/5 ?

Not knowing the rule of 3/5 is like not knowing for loops. You have a giant gaping hole in your knowledge just waiting to come along and bite you on the ass.

There are a great many situations where the "rule of zero" will not work conveniently without you implementing the appropriate containers or proxies (which need to obey the rule of 3/5, by the way) in order to have your "rule of zero." Two examples where you need non-trivial handling of objects where the standard library is lacking convenient containers: handle duplication and COM with proper reference handling, unlike most DirectX code.


This, plus the rule of zero depends on your compiler being able to automatically generate appropriate default equivalents for move ctor/assignment operator.  That isn't available everywhere just yet (although the situation seems to be improving).  Many people will be using older compilers, so you can't blindly forget about the rule of 3/5.

#5168384 How dangerous is returning a initialized pointer in C++?

Posted by Jason Z on 22 July 2014 - 09:21 AM

Second, and more importantly, on some systems (notably one major desktop operating system), shared libraries have (or may have) their own heap.
All the more reason for stack allocation!

#5168341 [Depth buffer] From linear -> non-linear depth values

Posted by Jason Z on 22 July 2014 - 04:52 AM

Retrieving the result via the original projection matrix is an option yes, but for educational purposes I was interested in the equation.
This is obtained by using the original projection matrix, and just taking the z component.  As long as you know how your projection matrix is constructed, then you would have the symbolic equivalent of your equation quickly and easily!

#5168288 How dangerous is returning a initialized pointer in C++?

Posted by Jason Z on 21 July 2014 - 08:55 PM

Actually, I think I'm starting to fall in love with smart pointers! I always loved the smart ones. At first it was confusing because I wanted to get the functions I made within that class or struct - you know? I never knew how until I read the tutorial about C++ 11 smart tutorials. I was a bit naive about the std::shared_ptr. So, I tried it on the graphics device struct and there was no worries about ever freeing up the initialized class - just had to dispose the COM objects created by DIrectX. Pretty sweet!
Smart pointers are a great tool, but remember what they are implying - they implement ownership semantics for the object they are wrapping.  If you have a shared pointer to your engine API object, then you are essentially saying that any object that has a reference to it is also an owner of it.  That means that if you have one outstanding reference, the object will not be destroyed.


That can be what you want in many cases, but the usage you point out above is not really one of those (at least in my humble opinion!).

#5168285 Converting STL heavy static library to shared

Posted by Jason Z on 21 July 2014 - 08:51 PM

If the STL usage is kept to the library's implementation and is only used internally for implementation, then would it still introduce problems?
If you are 100% certain that the STL usage of the shared library is only internal, then you are ok in theory.  In reality, that is usually pretty hard to isolate and it takes some serious dedication to make sure non of your interface exposes STL types in any way.  In addition, the types of bugs that can be produced with this include memory corruption which can be notoriously difficult to track down.


My advice is that unless you are absolutely certain that you need a shared library, stick with a static library.  If you must use a shared library, make sure that your projects are always compiled in tandem with the same settings.  If you are using Visual Studio, this is pretty easy to do with the configuration management system, but easy to mess up if you manually introduce compilation flags in one project but not in the others.

#5168279 How dangerous is returning a initialized pointer in C++?

Posted by Jason Z on 21 July 2014 - 08:16 PM

What are you trying to accomplish with this design?  You could just as easily stack allocate the EngineAPI object in your main function, and then pass around a pointer to that object.  This would control the timing of the object creation, it would trivially ensure that the object is destroyed when it goes out of scope, and there is no question of ownership or shared ownership.  I usually default to the simplest solution with the fewest strings attached to it, and unless you have a good reason to hide the object creation behind a factory/singleton hybrid method, I think you are unnecessarily complicating this!

#5168272 Why Java games do not need installation

Posted by Jason Z on 21 July 2014 - 07:43 PM

That only tells me your games aren't complex enough to require an installation procedure.

That seems slightly misguided - I wouldn't count requiring registry settings or special installation locations as a measure of complexity...


To the OPs original question, it is clear that you need the java runtime environment for running your game - so as the others have mentioned, you have just been lucky so far that nobody tried to run your game without it already installed.  C++ has similar requirements in the form of the redistributable packages on Windows (not sure about Linux though...).  So the overall answer to your question is that you actually do require an installer, you just haven't run into a user that didn't have your pre-requisites already installed.

#5166563 Drawing levels and scanning them in 2D

Posted by Jason Z on 13 July 2014 - 06:34 AM

If you want it to be fully automated, that might be quite difficult to implement, as it would require computer vision algorithms to figure out where each object is and to pull them out.  However, if you do a partially automated system it might be pretty easy to get going.  You just scan the drawing in high res, then do a guided parsing of the file (i.e. you lasso an object, then use the image processing techniques to select all the details).

#5166496 [HLSL] Copy content of Consume Buffer to Structured Buffer

Posted by Jason Z on 12 July 2014 - 06:23 PM

If I'm correct I could solve this by copying the content of the consume buffer to an auxiliary structured buffer with CopyStructureCount. Will try and report results

That's right - and if you have the debug device activated, then you should also get warnings / errors about binding the same resource for input/output (UAV) and input (SRV) at the same time.

#5166329 Mipmaps not used with multiplied texture coordinates

Posted by Jason Z on 11 July 2014 - 06:33 PM

Beware that it's very slow, but will always produce correct results according to the D3D spec.

Off topic: The only caveat here being that multithreaded context behavior is not easily reproduced on the reference device, so if you have bug due to multithreading the reference device won't help you!

#5166081 Device or Context lost. Should I bother?

Posted by Jason Z on 10 July 2014 - 03:55 PM


Device and Context cannot be lost, but Swap Chain can be (though you have to reinstall driver or physically remove GPU). Read more here: http://msdn.microsoft.com/en-us/library/windows/apps/dn458383.aspx

If you read that, it's a lot more than the SwapChain being lost. You have to recreate the Device and all resources.

It's worthwhile IMO since drivers crash and the OS has to restart them sometimes, which is equivalent to reinstalling a driver or removing/replacing the GPU. Borderlands 2 did this for me a few months ago when my GPU started overheating (dust buildup in the heatsink) and it was nice that I didn't lose hours of play but rather just had a few moment of intermittent pauses/screen-blanks before I decided to find out what was wrong.



That's probably true for a production game like Borderlands, but for anything less than a commercial product it is most likely overkill.  If your graphics driver crashes, there are some serious issues, and most people wouldn't expect a game to continue running through that...

#5165925 Having a problem getting data from .obj file to render (index / Vertex buffer...

Posted by Jason Z on 09 July 2014 - 07:08 PM

Does your data look correct on the pre-VS tab for the vertices?  If so, then it may be an issue with your projection matrices, since your x values are squashed to zero.  I would guess that this is not the case though - I would bet that your data pre-VS is not correct, and that you have a data alignment issue in your vertex buffer.  Double check to make sure that the positions in your vertex buffer all match what is given in the OBJ file, and if they don't match then you probably have an alignment issue!

#5165541 How to use external variables in HLSL?

Posted by Jason Z on 08 July 2014 - 07:53 AM

@AvengerDR: That looks like an interesting approach (although you wrote much more C++ code than just writing the shader by hand :P ).  Do you have any further information about the system written up?

#5165027 Black smoke alpha settings

Posted by Jason Z on 06 July 2014 - 06:29 AM

I would use the same setup for any color of smoke - use billboards (which are just textured quads) and additively blend them together in a particle system that models the behavior of the smoke.  I normally use PNGs while developing, but you would likely want to switch to a processed format later on when you deploy your application.  That let's you load it faster into your application specific format.