Jump to content

  • Log In with Google      Sign In   
  • Create Account

phil_t

Member Since 06 Oct 2006
Offline Last Active Today, 11:20 AM

#5293077 c++: sprintf but return chars. Possible?

Posted by phil_t on 23 May 2016 - 10:50 AM

If you're just looking for nice c++ string formatting, I recommend fmt.

 


fmt (formerly cppformat) is an open-source formatting library. It can be used as a safe alternative to printf or as a fast alternative to C++ IOStreams.




#5292974 Drawing Crosshair in perspective?

Posted by phil_t on 22 May 2016 - 09:17 PM

Is there some reason you need to use the same camera to draw the crosshair? Generally it's much simpler to use a separate camera to draw HUD elements.




#5292922 c++: sprintf but return chars. Possible?

Posted by phil_t on 22 May 2016 - 02:18 PM

void doStuff(const char*);

int main()
{
    int myInt = 555;
    std::ostringstream ss;
    ss << "Mytext: " << myInt;
    dostuff(ss.str().c_str());
}



#5291160 marking world objects as "currently being used" by players

Posted by phil_t on 11 May 2016 - 10:26 AM

If your code is flexible enough to support multiple notions of ownership for a game object (visual, inventory, tribe, etc...), then this should just be a matter of a player having a "temp crafting inventory". Those items are placed in the "temp crafting inventory" as needed - then when the player is done crafting, the "temp crafting inventory" is emptied. All along the items remain visible in the world, but any code that checks if someone can pick it up needs to check that it isn't owned by a "temp crafting inventory".




#5290833 Looking for game engine

Posted by phil_t on 09 May 2016 - 11:08 AM

I can't quite find it in unity even after browsing the entire asset store, or even going through unreal.

 

 

I'm sure either Unity or Unreal can handle your scenario, it's just you seem confused as to what is part of the engine and what's game-specific.

 

 

What is Unity missing that you need?




#5290684 Custom editor undo/redo system

Posted by phil_t on 08 May 2016 - 12:08 PM

If you already have support for serializing/deserializing (assuming you can read/write to a binary blob that can exist in memory), then #1 is the easiest (almost trivial to implement) - but it might come at an unacceptable performance cost once your scene gets large. 




#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






PARTNERS