Jump to content

  • Log In with Google      Sign In   
  • Create Account

phil_t

Member Since 06 Oct 2006
Offline Last Active Apr 30 2016 05:51 AM

#5288799 Returning by value is inevitable?

Posted by phil_t on 26 April 2016 - 12:41 PM

It's not *just* a problem with multi-threading. It also broken if you call the function a second time and are still using the value from the first one (It's also not re-entrant).




#5288146 How to implement a Behavior tree(prefarably in Unity 3D)

Posted by phil_t on 22 April 2016 - 09:28 AM

 The thing now is I want to implement my own tree and a heads up on how I can do it will be appreciated.

 

Have you seen the talks/slides on this site? They might help.

 

A behavior tree core implementation is actually fairly simple. I mean, I wrote one a while back based on info I learned from the above reference site - I could dig that code up and give it to you - but looking at Behavior Machine in the Unity asset store, it does everything mine did and much more (and appears to plug nicely into Unity). What's wrong with it exactly? How is it limiting you?

 

The hard part is modelling the world and somehow distilling that into nodes in a BT. And you won't find any implementation that does that, because it will be specific to your game. So maybe you're looking for tutorials that help explain how to do that, or concrete examples of complex AI implemented using behavior trees? Let me know if you find any good info on that!




#5286806 'External Code' taking up most of my CPU?

Posted by phil_t on 13 April 2016 - 11:41 PM

Ok, it looks like (from my own tests) calling ElementAt on the Dictionary's Values collection is really slow. I'm guessing it is an order-n operation that needs to iterate through items one by one, since the larger the index the longer it takes.

 

You probably want to use foreach instead (and hopefully the ValueCollection's iterator is a value type, to avoid unnecessary heap allocation)

 

In the little test I did, for a Dictionary of 10,000 items, this:

 

            for (int i = 0; i < blobs.Values.Count; i++)
            {
                value += blobs.Values.ElementAt(i).a;
            }
 
was more than a 1000x slower than this:
 
            foreach (Blob blob in blobs.Values)
            {
                value += blob.a;
            }
 



#5286515 linestrip flickering

Posted by phil_t on 12 April 2016 - 01:17 PM

It looks like it could be z-fighting, even though you say it's not.

 

What are your near/far plane distances, and how far away is the mesh?

What value are you clearing the depth buffer to?

Does the problem go away if you disable the depth buffer when drawing the wireframe? (If not, that would definitely prove it's not a z-fighting issue).




#5284817 Why is my struct destructor not called?

Posted by phil_t on 02 April 2016 - 08:42 PM


What the!? Why am I not getting Destruct A [500]?! Memory leaks if I would have some pointers in A cuz its destructor is never called!? I want to see something like this:


Construct A [0]
Destruct A [500]
Construct A [0]
Destruct A [0]
Finally 0
Destruct A [300]

 

That wouldn't make sense, because then your constructors and destructors aren't matched.

 

The line 

a = A()

doesn't call the destructor on a (I'm guessing that's what you're expecting based on your desired output). It simply calls a's assignment operator (and the temporary's constructor and destructor, unless elided as ApochPiQ said).




#5284547 Texture Coord Generation in Shader

Posted by phil_t on 31 March 2016 - 04:29 PM

You might want to search for "projective texture mapping". You can assign UVs in the vertex shader based upon the local or world position values.

 

If you project along 3 axes (just by applying a scale/offset to xz, xy and yz positions), you can generate 3 sets of UVs, and then blend between three texture samples in the pixel shader, depending on the vertex normal. This is an easy way to handle arbitrary meshes - the downside being that it requires 3 texture samples in the pixel shader. I saw a talk at PAXDev where a team was using this a lot in their game though (I forget which company), and it was a big time-saver for them in terms of artist effort.

 

I use it in one of my own projects to texture things like rocks. The following rock uses projected textures:

 

https://mtnphil.files.wordpress.com/2016/03/projtexture.jpg

 

If you look closely, you can see the blurring caused by blending between different projections. That's another downside.

 

Of course, for simple objects like cubes or planes, it's pretty straightforward.




#5284343 Matrix Question - Handling translation in world space.

Posted by phil_t on 30 March 2016 - 03:41 PM

Generally, for each game object you can store translation (vector3), scale (vector3, or maybe just a single float), and rotation (quaternion) separately.

 

Then, each frame (or whenever the object moves/rotates/changes size) combine them (scale, rotation, then translation) to get the final world matrix. Whatever framework you're using presumably has functions to do this.




#5284280 fading effect

Posted by phil_t on 30 March 2016 - 10:19 AM

Something like that will work (though I'd assume you'd want a region close to you where they are all opaque throughout).

 

But if you're using alpha blending, you'll need to make sure that you're sorting all your objects by distance to the camera, and drawing back to front. This could become a performance issue on the GPU (overdraw, blending) or CPU (sorting) depending on how many objects you have and how big they are.




#5284140 fading effect

Posted by phil_t on 29 March 2016 - 05:40 PM

I seem to be confused about something, in some tests I've run using the code I provided, even when object is like 10 units from the camera, the Z value is something like 0.995, while near the far end of the frustum at nearly 1000 units away, it's like 0.99998...

 

 

Yeah, it will be non-linear. It has to do perspective-correct rasterization:

 

http://www.gamedev.net/topic/539378-why-non-linear-depth-buffer/#entry4483438




#5283904 Nothing displaying on screen.

Posted by phil_t on 28 March 2016 - 01:48 PM

How far is your mesh from the camera? Your near/far distances look like they are set to 0.1 and 1. So anything further than 1 unit away (or closer than 0.1) won't be visible.




#5283742 queue of unique_ptr issue

Posted by phil_t on 27 March 2016 - 12:28 PM


Not sure how you derived it being the copy-constructor from the error message (I have no access to xcode files).

 

Yay for obtuse C++ compile errors! The (deleted) copy constructor needs to be invoked to pass the parameter by value, and the error message references a missing constructor:

 No matching constructor for initialization of 'std::__1::unique_ptr<Action, std::__1::default_delete<Action> >'



#5283415 heightmap sample in vertex shader

Posted by phil_t on 25 March 2016 - 11:39 AM

They should be in the range [0, 1].

 

Be sure you're sampling from the center of the texel (especially important for unfiltered texture reads like in a vertex shader). If you're sampling from the border between pixels, you may get any of the 4 neighboring values (not exactly "random", but it might look like it).

 

What does your grayscale image look like?

What does your rendered grid look like?




#5283259 Meshes rendered with the aid of shaders corrupted in windows 64 bit

Posted by phil_t on 24 March 2016 - 03:49 PM

You're probably doing something undefined that just happened to work on a different setup. Mismatched vertex layouts, or who knows what.

 

Are you checking the return values from all your DirectX calls to ensure they succeed?

Have you tried enabling the directX debug runtime to see if any warnings are spewed?




#5283256 How can I locate a memory leak?

Posted by phil_t on 24 March 2016 - 03:43 PM


I have run into such cases in the past, and not at all in the situation you refer to. I was thinking of shared pointers in particular, you can just google to find people who have run into performance issues. In particular, the atomic guarantee for the reference counting can lead to some issues for poorly designed concurrent applications, and depending on the implementation and usage, a shared pointer might also allocate its reference count from heap - increasing the risk of cache misses (tip for C++11 implementations: use make_shared rather than the constructors).

 

You're talking about a possible performance issue with reference counting. That's really an orthogonal discussion to using RAII/smart pointers or not (reference counting can certainly be implemented without smart pointers, e.g. COM). Using reference counting is a decision based on your object ownership requirements, whereas RAII is a syntactic tool to help eliminate memory/resource leaks (and generally doesn't present performance issues).




#5281362 Game Optimization

Posted by phil_t on 15 March 2016 - 11:19 AM

As Krypt0n mentioned, it's not about the "optimizer being smart" in this case. It's about the language specification. Short-circuit evaluation is a specifically defined behavior (and I don't know any language that doesn't do it). 






PARTNERS