Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 06 Oct 2006
Offline Last Active Today, 03:15 AM

#5298417 Generate terrain once given the heightmap

Posted by phil_t on Yesterday, 11:27 AM

Regarding the jaggedness, there are two ways to triangulate each grid cell. If you choose the one that has the center "axis" parallel to the gentlest slope of the quad, your terrain will come out a little smoother (especially if you're using normals for lighting).


See "additional optimizations" here:



Since you're doing this on the CPU, it's easy enough to do as you can just re-order the triangle vertices as you create them. But if you end up doing it in a vertex shader at some point:


#5297915 what means these error?

Posted by phil_t on 24 June 2016 - 03:06 PM

You need to learn how to debug this yourself. It's unlikely anyone can help you by guessing what the problem is. You're in the best position to diagnose this, because you can inspect the state of your program when it crashes, and set breakpoints, etc...


BitMaster said it best:


Again, you need to break into the crash with your debugger and inspect the state of variables. This kind of problem is bread and butter to any programmer. If you are unwilling to learn debugging this, you should change career/hobby.

#5297758 Hundreds of timers...

Posted by phil_t on 23 June 2016 - 05:39 PM

You do not need a separate thread to check if one value is larger than another.


It's as simple as ApochPiQ says. Dealing with buff timers will be the least of your challenges if you're making an MMO.

#5297504 Game Object Update Order

Posted by phil_t on 21 June 2016 - 04:49 PM

If you're trying to update all components on one entity, then all on the next entity, etc..., you'll have a problem. 


Instead, update all components of a particular type on all entities. Then all components of another type on all entities, etc...



foreach entity with MovementComponent




foreach entity with SkinnedMeshComponent





Your dependencies can be expressed at a high level in your main game loop like this.


I assume when you say Unity says "screw dependencies", you mean that the update order of Scripts attached to the entities isn't predictable. That may be true, but I can assure you core components like physics, mesh renderers, etc... have very explicit update orders.

#5297493 what means these error?

Posted by phil_t on 21 June 2016 - 03:46 PM

From a quick glance, it looks like you're passing the address of an entry in a vector to another thread, and then reading from it. 

I see no attempt at any synchronization.


I'm not sure how you expect that to work? What's stopping the vector from being resized (and thus any addresses pointing into it now potentially pointing to invalid memory) while your other thread is reading from it?

#5297418 Free game analytics

Posted by phil_t on 21 June 2016 - 01:42 AM

Thanks for the links. Yeah, I want something simple like the guy at the first link did. Really, all I need is something on the server side than can accept uploads (with some key/password/whatever to validate it's coming from my app) and store them on my server. He's got some Django code snippet there that does that I guess, but I've never even heard of Django. Or boto.


I have Open Web Analytics as a one-click install on my webhost, maybe I can get something out of that....

#5297408 Should all gameobjects be stored in the same data structure?

Posted by phil_t on 20 June 2016 - 10:02 PM

There's nothing stopping you from keeping one object in multiple lists (except the complexity of keeping them in sync, of course :P).


So if all your game objects share the same collision functionality (defined by attributes on them like mass/shape, rather than by their concrete type), then you could dump (pointers to) them in a data structure that is used for handing collisions.  At the same time you can keep your strongly-typed lists for handling specific functionality.

#5297390 Free game analytics

Posted by phil_t on 20 June 2016 - 05:46 PM

I have text parser based game, and I want to collect analytics on phrases the player enters that don't get a proper response. Mainly for beta-testing (though it would be nice to have it in production code too, but I understand the volume of data could be prohibitive)


I'm using Unity. I've checked out the analytics support included with Unity, but it's not really suited to tracking arbitrary strings (you would use up your "analysis points" very quickly).


Does anyone know of any other quick and easy solutions I could use? Worse comes to worst, I can just have the game store the data in a file on the player's computer and then have them email it to me. This only works on PC/Mac of course - ideally I'd want it to send the data to a webserver so it would work for WebGL, etc... too. And then they can just play the game, and I can see the data online somewhere.


I lease space on a webserver for hosting downloads, etc..., but I'm not very fluent in web development, so I don't feel like writing my own service that would handle these submissions.

#5297377 what means these error?

Posted by phil_t on 20 June 2016 - 03:51 PM

Set your debugger to break into the program when the crash happens. Then look at your data to see what is happening.

#5297218 Breakout Animation for bricks.

Posted by phil_t on 19 June 2016 - 10:17 AM

In terms of understanding how the game loop works, this might be useful: http://gameprogrammingpatterns.com/update-method.html

#5297138 Help with UV mapping procedural game

Posted by phil_t on 18 June 2016 - 02:33 PM

If you need different texture coordinates for different faces of your cube, then the faces can't share vertices. Simple as that.


Assuming your cubes are axis aligned, you could use triplanar texturing, and only draw certain sides of the cubes in one draw call (so your cubes are only cubes conceptually - they wouldn't be organized like that in your index buffers). That way you only need one texture sample, instead of lerping between three in the pixel shader based on orientation (the thing Wyrframe is doing). And if you can determine the texture coordinates by x/y/z position, then you potentially wouldn't even need texture coordinates in your cube's vertices, which means you could re-use them between faces.

#5297065 Object created in one class, needs to use variables in the class it was creat...

Posted by phil_t on 17 June 2016 - 08:11 PM

What is the responsibility of your Input class?

#5297061 Problem on referencing a vector of derived class

Posted by phil_t on 17 June 2016 - 07:53 PM

I guess... be generic when you can and it promotes code re-use, and be specific if it feels like you're trying to cram something into a pattern that doesn't fit - or rethink your design.




Can you think of any other convincing cases that require genericity?


Nothing really requires it. But some other things it makes easier for this particular scenario:

    - An in-game level editor is easier to implement (in regards to adding components to entities), as it doesn't need to know anything specific about how the game has stored stuff internally, and doesn't even really need to know much about the types of components available.

    - Similarly, loading "prefabs" from a text file

    - Serialization. You're right that you may need custom behavior here (as with Cloning), but ideally it can be expressed by attributes on the components ("don't serialize me", etc...). If there are complex inter-dependencies that make that not possible, then sure, write some specific code for that (or re-evaluate your design?).


I looked some of the slides of the Uncharted 2 talk you linked to in that other thread. I'm fully cognizant of the fact that there are times when it doesn't make sense to treat everything in the same way. Although, for the particular example they gave - did they start out with that design intentionally from the start? Or did they have something more "generic", and then realize "oh crap, we can't do this thing we want to (or can't get the perf we want, or whatever), we're going to have to be more explicit about things and treat our various systems in a specific manner"?


I guess what I'm getting at, is that treating things in an abstract way clearly has benefits - so if you can do that with a little design foresight then great. But if you find yourself making your abstractions more complex and fragile and convoluted to try to fit your needs, well then maybe it wasn't a good idea. Or maybe you didn't understand your scenarios enough up front to do a proper design.


In the ECS I've worked on, I do have a generic list of Systems that have an Update method. But yes, I think I did have to give the main "world manager" (or whatever) some explicit knowledge of a couple of systems to accomplish my needs - so not everything fit nicely into the abstraction I had. One time it did come in handy though was when I needed to do some offline environment map baking in my world editor. Not wanting to muck with the editor world state, I just fired up a new instance of my world, but only added the handful of systems needed to render static objects and terrain. Then I moved the camera around in that other world and got the images I needed.

#5297033 Problem on referencing a vector of derived class

Posted by phil_t on 17 June 2016 - 03:51 PM




[Edit:] Ah, you're talking about separating the components out of the systems. That's an interesting idea. I still don't get the benefit of the component mapper rather than just "theWorld.transformComponents", or "world.components.transforms" though. How does it benefit me, as a programmer?




I would say having explicit variables for each kind of component array is fine (and certainly clear)... until it's not.


For instance, what if you need to clone an entity? I'm struggling to think of how you would write a Clone function that is agnostic of any particular component types or component array variable names in your case. That is, add a new component type, and you need to update your Clone function.


Whereas I can write a generic Clone function. Off the top of my head, suppose you have an entity is defined by a map of component type (i.e. std::type_index) to array index (index into the corresponding component array). Those are the collection of components that define a particular entity. There are probably more efficient ways to store this, but for the sake of argument:



class IComponentMapperBase
    // Now our useless baseclass actually has some functionality:
    virtual int Clone(int index) = 0;



template<class _T>
class ComponentMapper : public IComponentMapperBase
    // Which is implemented by the concrete subclass:
    int Clone(int index) override
        // Copy the component at index, add it to the end of the vector, return its index:
        return (int)(Components.size() - 1);
    std::vector<_T> Components;


Then in TheWorld we add this method, again assuming an Entity is defined by the type->index mapping:


std::unordered_map<std::type_index, int> CloneEntity(const std::unordered_map<std::type_index, int> &sourceEntityComponentMap)
    std::unordered_map<std::type_index, int> clonedEntityComponentMap;
    for (const auto &pair : sourceEntityComponentMap)
        clonedEntityComponentMap[pair.first] = _componentMaps[pair.first]->Clone(pair.second);
    return clonedEntityComponentMap;



There, now I can add all the different new types of components I want, and I'll never have to touch the Clone functionality again. And I'm sure you can think of other operations where it makes sense to treat component types in an agnostic manner.

#5297009 Problem on referencing a vector of derived class

Posted by phil_t on 17 June 2016 - 01:49 PM

It's not necessarily better. In your example, you combine storage with game-specific code, whereas I was showing how you could have a generic storage mechanism which game-specific code could leverage. Presumably "TheWorld" has a little more logic than just a basic storage mechanism - you'll want ways to add/remove components, group them together as a "entity". So it seems useful for "TheWorld" to be able to reason over components in a generic way without needed to know the game's specific types..