# turch

Member

239

590 Good

• Rank
Member
1. ## use index buffer to draw a cube, how can each face be one color

You'll have to draw 12 triangles either way. Just instead of using 8 vertices and reusing them for each face, you have 3 unique verts per face with the color.  This also applies to normals, u/v, etc - if two adjacent faces share a vertex, but have different normals, you'll have to split it into two vertices.
2. ## How does tan work exactly?

ok, so tan(angle x) = opp / adj In the image below, tan(x) = 2/1   tan^-1 is the inverse of tan, so if you have the angle, tan(angle) gives you the ratio, and if you have the ratio, tan^-1(ratio) gives you the angle. In the image below, tan^-1(2/1) = ~1.107 rads (~63.5 deg)       So you have the setup in the image below. Subtracting the position of the image from the mouse gives you the length of the two sides. You then divide them to get the ratio, and pass that to tan^-1 to get the angle (in radians).     The sin and cos formulas work the same but are used when you have the hypotenuse and one of the shorter sides.   There's also sin^-1 and cos^-1, they are also known as arcsine, arccosine, and arctan (asin/acos/atan).
3. ## Terrain UV coordinate help

I'm not seeing the problem here. From the code, it looks like the texture using texCoord should stretch across each quad (repeat on every quad) and the texture using texCoord2 should stretch across 256 quads (repeat every 256 quads). Is that not what's happening or not what you want?
4. ## Client - non dedicated server architecture

Civilization 4 & 5 have a pretty robust master-server-less multiplayer, so it is definitely feasible - you can even have players join and leave during the middle of a game with no problems. You have to do more planning to handle data disparity, since none of the data is "canonical" and you can't just throw the conflicting data away (or you have to decide on which client's data is the master representation). If your simulation isn't deterministic, you'll need to figure out a way to reconcile floating point errors between different clients.
5. ## GitHub Forums

Github has their issue system which you can use as a sort of forum, as well as a wiki.
6. ## Resources with smart pointers?

As Chetanhl said, use ComPtr   http://legalizeadulthood.wordpress.com/2009/01/11/direct3d-programming-tip-3-use-smart-pointers/
7. ## Scripting language for some specific tasks

"ChaiScript is the first and only scripting language designed from the ground up with C++ compatibility" and is very lightweight ("a header-only library"). I've used it before and had excellent results. It does, however, require either Boost or C++11   I've heard great things about Falcon, which isn't quite as lightweight, but trades it in for (allegedly) excellent flexibility. I've never used it but have had several people recommend it.
8. ## Anyway to saving a game before game is killed?

Take a look at the iOS Application States.   applicationWillTerminate: looks like the obvious choice but it is not guaranteed to be sent to applications which run in the background. Your best bet would be applicationDidEnterBackground:   Basically, when your app is backgrounded, write out that it is in the background state. When it is foregrounded, write out that it is in the foreground state. When your app launches, check whether the background flag is set - if so, the app was killed while in the background - either by the os, the user, or lack of power. It's not ideal, but is the best you can do on an iOS device - since an application can go from "not running" to "terminated" without executing any code, you can only rely on background / foreground.   You should get applicationDidEnterBackground: called for every situation except for sudden power loss / destruction.
9. ## Gimp and GPL license with default fonts, brushes and patterns

1. GIMP does not come with any fonts (at least it didn't back in 2011). The default fonts are the fonts you have installed on your system. 2. Font licenses apply to the font file itself. You only need to license it if you are going to distribute the font file - if you are just distributing the rasterized result you don't need to do anything special. Same thing for brushes - the license applies to the "use" of the brush, not the result. and of course, IANAL
10. ## Passing file name to main with Windows "open with" option

When your application is launched by an "open with", the current working directory is %WINDIR%\system32, so if you use any relative file paths they will be broken. It will be the first argument passed in to the application.
11. ## Event System like RPG Maker?

So, you have an "event", which is just an id to distinguish between events. It can be an enum, #DEFINE'd ints, hashed strings, whatever. You also have a "delegate", which is the code that should be executed when the event happens. Delegates in C++ (which is what I assume you're using) are a pretty big topic, so I'll link you to the stackoverflow question What is a C++ delegate? Lets say you have a class that keeps track of the player's score, and whenever an enemy is killed, the score should increase by the enemy's point value. Pseudocode would look like this: class ScoreTracker { class EnemyKilledDelegate : Delegate { int totalPoints; virtual void operator()(void* data) { totalPoints = (int*)data; } } ScoreTracker() { //... EventManager* mgr; EnemyKilledDelegate* del; mgr.RegisterListener("EnemyKilled", del); //... } } The event manager would then keep some sort of dictionary to call the delegates when the event occurs: class EventManager { map<string, vector<Delegate*>*> eventMap; // map strings to (pointers to (vector of pointers to delegates)) RegisterListener(string event, Delegate* delegate) { // get the vector of delegates for the event (or create a new one) vector<Delegate>* eventListeners = eventMap.getOrCreate(event); eventListeners.add(delegate); // add the delegate } ProcessEvent(string event, void* data) { // get the vector of delegates for the event (or create a new one) vector<Delegate>* eventListeners = eventMap.getOrCreate(event); foreach(Delegate* del in eventListeners) // loop through and call each delegate { (*del)(data); } } } And finally, to fire an event: class Enemy { int pointValue; Die() { //... EventManager* mgr; mgr.ProcessEvent("EnemyKilled", &pointValue); //... } }
12. ## Scene design.

Don't think of it as a monolithic structure. Keep as many copies of the data as you need. Graphics system needs to cull geometry based on visibility? Keep a quadtree/bsp tree/whatever around. Need to quickly look up certain game objects based on string keys? Keep those in a dictionary. Need a data structure specialized for physics? Have one of those around (if you're going to be using a 3rd party physics api then it will keep it's own copies of the data it cares about). A general purpose scene probably doesn't need to support parent-child relationships. You only really need that for calculating world transforms (and you've got another class for that right?). If this is the "master list of all game objects" type of scene, then really all it needs to be is an array or some sort of dictionary if you have unique ids.
13. ## Auto-tile system - algorithm to auto-generate hash table

Its kind of hard to tell what's going on without more description.... What does the hash table store? Each tile's value? If so, I can only assume the tiles are in some sort of array to begin with, so you would be able to i = 0 j = 0 for each row for each column hash_table.Add( ((i * numCols) + j), tile_array[j]) j++ i++ And since your keys are 0-255 with no gaps, why do you need a hash table? A 1-d array would serve you just as well... Edit: from reading your previous question, I take it you are trying to generate one of 47 unique ids based on a 3x3 pattern?
14. ## How do I avoid hundreds of identical scene graph traversals?

You usually do a two step update, parent -> child to update transforms, and then child -> parent to update bounding volumes for culling.