# Question
Title: Converting 2D coordinates from multiple viewpoints into 3D coordinates
Here's the situation. I've got a set of 2D coordinates that specify a point on an image. These 2D coordinates relate to an event that happened in a 3D space (video game).

I have 5 images with the same event point on it, so I have 5 sets of 2D coordinates for a single 3D coordinate. I've tried everything I can think to translate these 2D coordinates into 3D coordinates, but the math just escapes me. I have a good estimate of the coordinates from which each image was taken, they're not perfect but they're close.

I tried simplifying this and opening up Cinema 4D, a 3D modeling application. I placed 5 cameras at the coordinates where the pictures were taken and lined up the pictures with the event points for each one and tried to find a link, but nothing was forthcoming. I know it's a math question, but like I said, I just can't get it. I took physics in high school 6 years ago, but we didn't deal with a whole lot of this sort of thing.

Any help will be very much appreciated, I've been thinking on it for quite a while and I just can't come up with anything.

# Answer
> 2 votes
You really only need two viewpoints to locate the point. From each viewpoint, you have a camera location and a direction; that is, you have everything you need to uniquely define a line in 3d Cartesian space. All this amounts to is finding the intersection of two lines.

# Answer
> 0 votes
It depends just how much freedom you have with this scenario. In the worst case you will need to set up some 3x3 matrices and do some coordinate transformations between different coordinate systems.

However if you have control over the layout, then the simplest situation would arise if three of those five projection angles happen to be mutually perpendicular. Then each just corresponds to different planes: x-y, y-z, x-z. So if the coordinates in the x-y plane are (a,b) and in the y-z plane are (b,c) then the coordinates should be (a,b,c). Of course this means that the coordinates in the x-z plane are (a,c), as we are assuming that they are perpendicular and there is no scale change between planes. You will also be choosing origins appropriately etc.

However if you have an independent coordinate system for the 3D space (X,Y,Z) then you will need to find the transformation matrix between the various coordinate systems: M(a,b,c) = (X,Y,Z).

In the general case you are looking for 3 (or 5) projection 3x3 matrices $P\_1$, $P\_2$, $P\_3$ which will have the property that $P\_{i}^2 = P\_i$ and they are of rank two. The 2 eigenvectors of P will correspond to the two axes of the projection plane. If you need to know more about this then a book on 3D geometry for computer modelling will be required. Some of the maths can be quite sophisticated - a subject called "Geometric Algebra" has recently become quite popular in this area, to assist with visualising and efficiently calculating the various formulae involved.

# Answer
> 0 votes
just looking at vision.middlebury.edu has a bunch of stuff. I used to have an old text with the stereo to 3d algorithm in BASIC ! long gone. There is quite a bit on the web.

# Answer
> 0 votes
If you have projection matrices of each image, you can use triangulation (for example here). It works for two cameras and generates one 3D point.

# Answer
> 0 votes
Hey thanks for all the answers. Unfortunately, I have no control over the scene. The images have been taken from fixed points and I had to do a lot of visual comparisons to get a decent approximation of where they were taken from.

Basically what happens is an event happens within the game (a kill or a death) and the event is sent to the server when the game ends. The software behind the server takes the 3D coordinates from that event and maps it to a 2D image that you can look at and see where that kill or death happened. Those coordinates are relative to the image, though, not the actual game space. All I know about the images is an estimate of the coordinates where it was taken at (in game space) and the field of view (78°). Here are the position and rotation coordinates for 3 of the images in (X, Z, Y) / (yaw, pitch):

```
1: (15.894, 152.263, 43.839) / (53.34, -14.61)
2: (27.205, 170.375, 72.500) / (0.00, -85.50)
3: (51.987, 184.236, 41.290) / (206.38, -14.07)

```

And here are the coordinates that the server is calculating for those 3 points of view, remember they're relative to the image, (X, Y):

```
1: (322, 205)
2: (389, 232)
3: (240, 109)

```

And finally, the actual in-game cordinates where this event happened, (X, Z, Y):

```
(25, 164, 039)

```

Hopefully someone here can lend me their brain for a bit, I'm completely at a loss.

Edit: Perhaps I should have used the same name I posted the original question with. My mistake, I am the original poster.

---
Tags: coordinates
---


# Question
Title: How should I manage my game objects and components?
By far, the biggest problem that has always dawned on my when programming games is how to structure my code. It just becomes an incredible mess, after a while. The reason for that is because I have no idea how different classes should interact with each other.

For example, say I have a `Player` class, a `PlayerInput class` and a `Map` class. The `Player` class contains information as to the location of the player, whereas the `PlayerInput` class handles changing that location, but by first making sure it is within a walkable area, using the `Map` class. How should I structure this?

My usual approach is to pass these components, as parameters, in the constructors of the parameters that need them, like so:

```
var map = new Map(); var player = new
Player(); var input = new
PlayerInput(player, map);

```

The problem with that is that it quickly gets messy; when you add new components, you have to go through your constructors and update them, and it doesn't work well if you have mirroring references:

```
var physics = new Physics(input); //Oops, doesn't work
var input = new Input(physics);

```

How should I manage my game objects and components?

# Answer
> 11 votes
No lie, architecting games (or any other simulation-style program) is harder than your average business app. When you have lots of different entities that all need to interact then in the code they'll need to, well, *interact*. Letting them do that in a maintainable way is tricky.

A component pattern can help, but even then figuring out how to wire the components up is non-trivial.

To your specific question:

> Say I have a class Player, a class PlayerInput and a class Map. The player class contains information as to the location of the player, whereas the player input class handles changing that location, but by first making sure it's within a walkable area from the map class. How to structure this?

In this case, I generally order the dependencies by how the information flows:

1. User input comes in. That defines how the player *wants* to move.
2. The player's behavior and animation modify that to determine how it *can* move (things like preventing a jump if you're already in the air).
3. The collision modifies that to determine how the player *does* move.

So collision refers to animation which refers to user input. Any of those dependencies can be decoupled by hiding them behind an interface. So, for example, the animation system just needs to know the direction the player wants to go. It doesn't care if that's coming from user input or from something else (like AI, a replay script, or demo mode) so all it needs is an instance of some `IPlayerMovement` interface.

> and it doesn't work well if you have mirroring references:

If you can't avoid a circular reference altogether, you can always break it by introducing an interface:

```
// Problematic:
class A {
  A(B b) { /* ... */ }
}

// Bad:
class B {
  B(A a) { /* ... */ }
}

// No more cycle:
interface I {
}

class A {
  A(I i) { /* ... */ }
}

// Bad:
class B implements I {
  B(A a) { /* ... */ }
}

```

# Answer
> 4 votes
In your particular example, typically one system is more "important" than the other, or somehow the relationship is not exactly symmetric (one relies on the other more), and that's the opportunity to do something like the following:

```
var physics = new Physics();
var input = new Input(physics);
physics.attachInput(input);

```

This is not uncommon; for example in Java's Swing GUI system, the BoxLayout LayoutManager requires knowing about the component that it is laying out; so you must first initialize a component (which assumes a default LayoutManager), and then initialize a BoxLayout passing it that component, and finally do a setLayout of the BoxLayout on the component. It looks like the following (taken from this Java documentation page):

```
JPanel listPane = new JPanel();
listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));

```

# Answer
> 1 votes
Good question. One away around these types of interdependency on subsystems, like input, physic, rendering, etc, is to use the services & singleton pattern together. Each subsystem could be modeled as a service, and the game only has one instance of that service at a time (sub system) that gets created when first called.

At some point though, your going to have a chicken and egg problem if the creation of your subsystems depends on the creation of another subsystem that depends on the creation of the other.

So, avoid the above circular creation problem, and also use static singletons. For example: Input.getInstance(), Physics.getInstance(). Both of those getInstance methods could create and return the subsystem on the first call, but then return the sub system on other calls (singleton pattern). So the first time Input needs the physics sub system it gets it via the singleton service call. Read up on the Gang Of Four Design patterns for more information on those patterns.

---
Tags: component-based
---


title: Facebook Game database design

text:
# Question
Title: Facebook Game database design
I'm currently develop a facebook mafia like PHP game(of course, a light weight version), here is a simplify database(MySQL) of the game

```
id-a           <int3>  <for index>
uid            <chr15> <facebook uid>
HP             <int3>  <health point>
exp            <int3>  <experience>
money          <int3>  <money>
list_inventory <chr5>  <the inventory user hold...some special here, talk next>
... and 20 other fields just like reputation, num of combat...

```

**the number next to the type is the size(byte) of the type*

For the list\_inventory, there have 40 inventorys in my game, (actually, I have 5 these kind of list in my database), and each user can only contain 1 qty of each inventory, therefore, I assign 5 char for this field and each bit of char as 1 item(5 char * 8 bit = 40 slot), and I will do some manipulation by PHP to extract the data from this 5 byte.

OK, I was thinking on this, if this game contains 100,000 user, and only 10% are active, therefore,

if use my method, for the space use,

5 byte * 100,000 = 500 KB

if I use another method, create a table user\_hold\_inventory, if the user have the inventory, then insert a record into this table, so, for 10,000 active user, I assume they got all item, but for other, I assume they got no item, here is the fields of the new table

```
id-b     <int3>  <for index>
id-a     <int3>  <id of the user table>
inv_no   <int1>  <inventory that user hold>

```

for the space use,

(\[id\] (3+3) byte + \[inv\_no\] 1 byte ) * \[active user\] 10,000 * \[all inventory\] * 40 = 2.8 MB

seems method 2 have use more space, but it consume less CPU power. Please comment these 2 method or please correct me if there have another better method rather than what I think.

Another question is, my database contain 26 fields, but I counted 5 of them are not change frquently, should I need to separate it on the other table or not?

So many words, thanks for reading :)

# Answer
> 8 votes
First of all, don't skimp so much on space. Even on shared hosting you'll get several GB of space and if you're not storing large binaries or entire books or something, CPU and memory are going to be bottlenecks before disk space is (usually).

I thinking keeping int columns as small as possible is pretty old advice when disk space was more expensive than it is now. Just use regular int, and if needed bigints (or whatever your DB's equivalent is)

You'll definitely want to have a separate table for inventory, because that'll give your more flexibility. If the items have any kind of special attributes you'll probably want the items in the DB as well (not sure from your question whether you were planning that already) that way you can do queries like, get all the items in player x's inventory that can be used while in combat, or something like that.

Edit:
As far as speed goes, with this simple structure, the database is likely not going to be the thing slowing you down. They are generally well optimized if you know how to use them properly, and it's not until you get really complex queries that performance even begins to be an issue. According to this accepted answer on Stack Overflow, 100,000 records is still considered a small database, and large isn't until around 10,000,000 to 1,000,000,000 records, so you should be good for some time.

# Answer
> 4 votes
What you're doing here is premature optimization. Modern RDBMS can handle much more records and are optimized for speed and efficiency.

There's no point in simplifying your DB-design like that, because:

* You'll loose flexibility.
* You will have to do the stuff in your code that was previously handled by the RDBMS (eg. get all inventory items as separate fields?)
* It will needlessly obfuscate your DB-design.

A lot of RDMBS can also do load balancing, so if you're really going to hit a DB performance bottleneck, you could scale up your DB servers.

# Answer
> 1 votes
You might want to look into a noSQL database like mongodb if you work with PHP because of the ready made drivers and because it looks like all you have to save are statistical and property data for which you wouldn't need joins or anything more "complex".

If you arent sure about the size of your app you might be better off starting with a cloud solution. I know many use EC2 but im very happy with rackspace cloud servers. They are decent fast and super easy to deploy. We had our own Facebook app running around two years ago and maxed out around 42 million users on FB. As database storage i used redis because it is very fast (all in memory) and spread the data (simple properties similar to your data) over 20 2GB nodes and hashed the data with the flexihash algo (redis cant shard/hash) with a redundancy of four. That way i was able to scale up and down pretty easy. (Looking back at it it wasn't the smartest solution...)

Just always work with intergers and use caching everwhere (memcached) and you're good. Don't worry too much about the disk space. If you have to handle a LOT of users you should be able to pay for a few more servers.

A little tip for the hosting: If you want a serious hoster, you might want to look into the Softlayer special deals and ask the support if they give you a raid or double disk storage for free. When i got my first Softlayer server around 5 years ago i asked them if they could turn the RAM deal into a Disk deal and got 2x250GB.

---
Tags: architecture, databases, php
---


# Question
Title: What economic books would you suggest for learning about economic valuation of goods and simulations thereof?
I'm looking to create an economic model for a game based on goods created procedurally.

Every natural resource and produced good would be procedurally generated, with certain goods being assigned certain uses.

> Fakesium might be used for the production of Weapon A and produced from Fakesium factories which use Dilithium and Widgets as reagents, where Widgets are also the product of Foo and Bar

The problem is not creating the resources and their various production utlities - but getting the game's AI empires and merchants to (Addendum: somewhat) correctly value the goods according to their scarcity, utility and production costs.

I need to create a simulation of goods which allows the various game factions to assign a common value denominator (credits) to each resource, depending on how much its worth to that empire.

I see the simulation being something like: "I have a high requirement for Weapon A. Since I don't have much of Fakesium, which is needed for Weapon A - I must have a high demand for Fakesium. If I can acquire Fakesium, devalue it. If not, increase its value - and also increase demand for Dilithium and Widgets too."

This is very naive - because it may be much much cheaper for the empire to simply purchase Dilithium and Widgets directly rather than purchasing Fakesium, for example. Another example is two resources might allow the creation of Weapon A (Fakesium and Lieron), so we'd need to consider that. I've been scratching my head over the problem and it keeps growing.

By the time the player joins the world, I'd expect enough iterations of this process to have occurred that prices would have largely normalised - and would then only trigger rarely to compensate for major changes (eg. if the player blows up the world's only Foo mine!)

Could anyone suggest resources (books, largely) which outline this style of modelling, preferably in the context of simulations? Since this problem would never occur outside fantasy worlds, I figured this is probably the most likely place to find people who have encountered similar problems and I'm sure there's people who know of good places for Games Developers to start looking at less specific economic theory too.

Additionally, does anyone know of any developers with blogs whose games or research applications perform similar modelling?

**EDIT**: I think I should underline that I'm not looking for optimal solutions. I'm looking to make the actors impulsive - making rudimentary decisions based on fuzzy inputs about what they care about or don't. I'm aiming to understand the problem area better not derive answers. All the textbooks I've found seem to be about real-world economics or how to solve complex theoretical problems, neither of which are terribly relevant to the actor's decision making.

# Answer
I would skim through any Applied Calculus for Business textbooks. The examples and exercises will be helpful. You will be surprised that the business case you described happens ALL the time outside of gaming. Then proceed to Numerical Sciences or Management Sciences textbooks. That is where your solution eventually lies.
> 3 votes

---
Tags: simulations, economy
---


# Question
Title: How important is a single-player mode in a 2-player game?
So say you have a 2 player game, taking Chess as an example (except it's an original game with no ready-to-go AI available).

Let's say there's also a social-aspect to the meta-game, so let's say it's a Chess game on Facebook where you can challenge your friends.

How important is it to have a single-player mode, knowing that an AI will need to be created (I've done minimax AI for tic tac toe, but nothing too sophisticated)?

Is it important enough that it should be in the initial launch of the game?

Can it wait for a future iteration (knowing that being hosted on the web means the game can be updated at any time)?

# Answer
It's going to depend on how your users are going to find opponents.

If they need to pick off a friends list (say) then you need to have mechanisms for players to invite friends etc. In this case, when there might not be a lot of players, having an AI opponent will at least allow someone to play the game.

However, if they can pick a player at random (or get assigned a player at random) then having AI is less important as (hopefully) there will be enough players on line so that someone will be able to find an opponent.

Having said all that, having a computer opponent will allow players to practice the game.
> 10 votes

# Answer
Your should be careful launching a game that will not be able to please the user right away. Your game idea and -play could be fantastic but if your initial user base cannot get the game started because they don't have a friend sitting next to them, or because not enough players is queuing the your match making system then the user be dissatisfied. Moreover there is little chance the user will recommend the game or come back to try your game once you improve the game or add the ability to actually get into a match.

So, if you're launching a MP game, then you have to make sure that it will have enough players available so that people always can get into a match. In case of a Facebook game this is not so much an issue since you have the ability to invite the users friends to the game.
> 6 votes

---
Tags: ai, multiplayer
---


title: Beginners' Guide to Development

text:
# Question
Title: Beginners' Guide to Development
So I have some experience programming in Java, and at the moment I am learning how to use Python. I have read on the process of game design and such. I also have media covered, got experience with graphics and audio. My question is geared more towards the actual tools to use for making games, developing. I am willing to commit to a long term development cycle, as I will be doing this as a hobby. I've heard of Flash, Gamemaker, etc. I don't intend to create my own Game Engine, so I was looking for a platform that is extensible and easy to program with an OOP mind frame. As a plus it would be great of said game could be played directly from a website. TIA!

# Answer
> 7 votes
Unity is the top game development tool in the industry right now. It has a free version and has a web player so you are able to deploy to a website as you said you want to do. The scripting is in C#, JavaScript or Boo, and it is cross-platform (Windows or Mac) so it should run on your computer, whichever you have.

If you want to go lower-level and take advantage of your Java skills, you could check out JMonkeyEngine. This is a Java graphics engine with some extra features that make it particularly tuned to games. It is scene-graph based, which means instead of worrying about drawing polygons on screen (or pushing them to the graphics card), you simply load meshes and manipulate the meshes in a tree structure, e.g. everything in the scene is a node in the scene graph, so child nodes inherit from their parents and so on. This might be the object-oriented aspect you're looking for.

These are my recommendations to you. If you want a drag-and-drop style interface and just want to do high-level scripting, go with Unity. If you want to write your game essentially from scratch, but not too low-level, go with JMonkeyEngine.

For any further information I suggest you search our site. Almost every day we get a question like this, asking how to start game development, so there are many search results. Please notice the search box in the top right corner.

# Answer
> 1 votes
Even if you're an experienced programmer (any level of experience), I might recommend using something like GameMaker to build a simple game, before you start building your own. Start with building a game whose rules are well defined, and on the more simple side, think TicTacToe, Pong, or something similar. This will help get you orentated to the process your going to need without getting you stuck in the actual development. This can help you get your art and asset creation workflow down pat. (For my own experience, it this has been my largest pitfall, I spent too much time programming the game and got disenchanted with the project because I hadn't formalized an art workflow for myself.)

If you are not set on building your own engine (which is a good thing, get a game out there thats fun, even the best engine wont make a fun game) AND you are willing to be language agnostic (even though you have Java, you mention GameMaker and Flash) and have thoughts of possibly going public with your game, Epic recently upped the total amount you need to make (from 5k to 50k) before the royalties kick in for using the UDK. Its big and complicated, but it has a good deal of head-room.

As Ricket said, Unity is hot right now, and has a pretty low bar to entry and might be worth looking in to.

If being cross-platform is not of high value to you and you would rather do some programming, I cannot recommend C# and XNA highly enough. C# has all of the good parts of Java, without all of the poor parts, like the Java implementation of Genrics, and all the goodness of DirectX in a very "managed" style API. TorqueX is an XNA engine, but if you see my question here: it is not highly recommended. There are other XNA based frameworks and engines that can help get you off the ground; depending on the complexity of your game, you may not need any of these engines.

If you are dedicated to Python, you might want to look into pygame -- I'm not much of a python guy, so I can't commont on its ease of use, but I've heard it mentioned a lot with respect to game development in Python.

# Answer
> 0 votes
I'm surprised no one suggested http://PyGame.org since you already now Python.

Flash/Unity will get your game on the web, though those are proprietary technologies and I would not recommend it for hobby game development - not a lot of hobbyists have the resources to learn non-free tools.

If you are adventurous you might want to try any of the new html5 game engines (those will become feasible to deploy in the coming years): https://github.com/bebraw/jswiki/wiki/Game-Engines

---
Tags: software-engineering, tools
---


# Question
Title: How to fix Ogre3d segfault with std::_Rb_tree_insert_and_rebalance?
I'm working on a 3d music visualizer using Ogre3d, basically it's a spectrum analizer, a lot like the old xmms plugin: http://www.youtube.com/watch?v=\_6NKBiwYN24

It works well, the bars are drawn and updated, there are no framerate issues, but it crashes randomly. Sometimes it can run without problems, finish the song, other times it crashes instantly, other times the music just stops, without a crash.

Here is the source code for the main class :

https://github.com/balazsbela/OgreVisualizer/blob/master/src/VisualizerApplication.cpp#L221

Also the crashes seem to happen less often when I display the framerate overlay from Ogre samples. Would limiting the framerate help ?

The crashes are seemingly random. Is it a performance issue ?

Please help me out, I'm quite lost on this one, I also posted on Ogre3d forums but I received no responses.

http://www.ogre3d.org/forums/viewtopic.php?f=2&t=63207

I also tried stackoverflow: https://stackoverflow.com/questions/5050147/how-to-fix-ogre3d-segfault-with-std-rb-tree-insert-and-rebalance

Backtrace:

```
balazsbela@darknet:~/workspace/OgreVisualizer/Release$ gdb OgreVisualizer core
GNU gdb (GDB) 7.2-debian
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/balazsbela/workspace/OgreVisualizer/Release/OgreVisualizer...done.
[New Thread 17705]
[New Thread 17702]
[New Thread 17703]
[New Thread 17700]
Reading symbols from /usr/lib/libv4l/v4l1compat.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libv4l/v4l1compat.so
Reading symbols from /usr/local/lib/libOgreMain.so.1.7.1...done.
Loaded symbols for /usr/local/lib/libOgreMain.so.1.7.1
Reading symbols from /usr/lib/libfftw3.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libfftw3.so.3
Reading symbols from /usr/lib/libSDL_sound-1.0.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libSDL_sound-1.0.so.1
Reading symbols from /usr/lib/libSDL-1.2.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libSDL-1.2.so.0
Reading symbols from /usr/lib/libSDL_mixer-1.2.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libSDL_mixer-1.2.so.0
Reading symbols from /usr/lib/libOIS-1.2.0.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libOIS-1.2.0.so
Reading symbols from /usr/lib/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libstdc++.so.6
Reading symbols from /lib/i686/cmov/libm.so.6...Reading symbols from /usr/lib/debug/lib/i686/cmov/libm-2.11.2.so...done.
done.
Loaded symbols for /lib/i686/cmov/libm.so.6
Reading symbols from /lib/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/i686/cmov/libc.so.6...Reading symbols from /usr/lib/debug/lib/i686/cmov/libc-2.11.2.so...done.
done.
Loaded symbols for /lib/i686/cmov/libc.so.6
Reading symbols from /lib/i686/cmov/libpthread.so.0...Reading symbols from /usr/lib/debug/lib/i686/cmov/libpthread-2.11.2.so...done.
done.
Loaded symbols for /lib/i686/cmov/libpthread.so.0
Reading symbols from /usr/local/lib/libv4l1.so.0...done.
Loaded symbols for /usr/local/lib/libv4l1.so.0
Reading symbols from /usr/lib/libfreetype.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libfreetype.so.6
Reading symbols from /usr/lib/libSM.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libSM.so.6
Reading symbols from /usr/lib/libICE.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libICE.so.6
Reading symbols from /usr/lib/libX11.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libX11.so.6
Reading symbols from /usr/lib/libXext.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXext.so.6
Reading symbols from /usr/lib/libXt.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXt.so.6
Reading symbols from /usr/lib/libXaw.so.7...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXaw.so.7
Reading symbols from /lib/i686/cmov/libdl.so.2...Reading symbols from /usr/lib/debug/lib/i686/cmov/libdl-2.11.2.so...done.
done.
Loaded symbols for /lib/i686/cmov/libdl.so.2
Reading symbols from /usr/lib/libboost_thread.so.1.42.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libboost_thread.so.1.42.0
Reading symbols from /usr/lib/libboost_date_time.so.1.42.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libboost_date_time.so.1.42.0
Reading symbols from /usr/lib/libfreeimage.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libfreeimage.so.3
Reading symbols from /usr/lib/libzzip-0.so.13...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libzzip-0.so.13
Reading symbols from /usr/lib/libz.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libz.so.1
Reading symbols from /usr/lib/libsmpeg-0.4.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libsmpeg-0.4.so.0
Reading symbols from /usr/lib/libmikmod.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libmikmod.so.2
Reading symbols from /usr/lib/libvorbis.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libvorbis.so.0
Reading symbols from /usr/lib/libvorbisfile.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libvorbisfile.so.3
Reading symbols from /usr/lib/libFLAC.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libFLAC.so.8
Reading symbols from /usr/lib/libogg.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libogg.so.0
Reading symbols from /usr/lib/sse2/libspeex.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/sse2/libspeex.so.1
Reading symbols from /usr/lib/libasound.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libasound.so.2
Reading symbols from /lib/i686/cmov/librt.so.1...Reading symbols from /usr/lib/debug/lib/i686/cmov/librt-2.11.2.so...done.
done.
Loaded symbols for /lib/i686/cmov/librt.so.1
Reading symbols from /usr/lib/libdirectfb-1.2.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libdirectfb-1.2.so.9
Reading symbols from /usr/lib/libfusion-1.2.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libfusion-1.2.so.9
Reading symbols from /usr/lib/libdirect-1.2.so.9...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libdirect-1.2.so.9
Reading symbols from /usr/lib/libvga.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libvga.so.1
Reading symbols from /lib/ld-linux.so.2...Reading symbols from /usr/lib/debug/lib/ld-2.11.2.so...done.
done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /usr/local/lib/libv4l2.so.0...done.
Loaded symbols for /usr/local/lib/libv4l2.so.0
Reading symbols from /lib/libuuid.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libuuid.so.1
Reading symbols from /usr/lib/libxcb.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libxcb.so.1
Reading symbols from /usr/lib/libXmu.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXmu.so.6
Reading symbols from /usr/lib/libXpm.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXpm.so.4
Reading symbols from /usr/lib/libjpeg.so.62...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libjpeg.so.62
Reading symbols from /usr/lib/libmng.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libmng.so.1
Reading symbols from /usr/lib/libopenjpeg.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libopenjpeg.so.2
Reading symbols from /lib/libpng12.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib/libpng12.so.0
Reading symbols from /usr/lib/libIlmImf.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libIlmImf.so.6
Reading symbols from /usr/lib/libImath.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libImath.so.6
Reading symbols from /usr/lib/libHalf.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libHalf.so.6
Reading symbols from /usr/lib/libIex.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libIex.so.6
Reading symbols from /usr/lib/libIlmThread.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libIlmThread.so.6
Reading symbols from /lib/libx86.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libx86.so.1
Reading symbols from /usr/local/lib/libv4lconvert.so.0...done.
Loaded symbols for /usr/local/lib/libv4lconvert.so.0
Reading symbols from /usr/lib/libXau.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXau.so.6
Reading symbols from /usr/lib/libXdmcp.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXdmcp.so.6
Reading symbols from /usr/lib/liblcms.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/liblcms.so.1
Reading symbols from /usr/local/lib/OGRE/RenderSystem_GL.so...done.
Loaded symbols for /usr/local/lib/OGRE/RenderSystem_GL.so
Reading symbols from /usr/lib/libGLU.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libGLU.so.1
Reading symbols from /usr/lib/libGL.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libGL.so.1
Reading symbols from /usr/lib/libXrandr.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXrandr.so.2
Reading symbols from /usr/lib/libGLcore.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libGLcore.so.1
Reading symbols from /usr/lib/tls/libnvidia-tls.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/tls/libnvidia-tls.so.1
Reading symbols from /usr/lib/libXrender.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXrender.so.1
Reading symbols from /usr/lib/libXcursor.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXcursor.so.1
Reading symbols from /usr/lib/libXfixes.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libXfixes.so.3
Reading symbols from /lib/i686/cmov/libnss_compat.so.2...Reading symbols from /usr/lib/debug/lib/i686/cmov/libnss_compat-2.11.2.so...done.
done.
Loaded symbols for /lib/i686/cmov/libnss_compat.so.2
Reading symbols from /lib/i686/cmov/libnsl.so.1...Reading symbols from /usr/lib/debug/lib/i686/cmov/libnsl-2.11.2.so...done.
done.
Loaded symbols for /lib/i686/cmov/libnsl.so.1
Reading symbols from /lib/i686/cmov/libnss_nis.so.2...Reading symbols from /usr/lib/debug/lib/i686/cmov/libnss_nis-2.11.2.so...done.
done.
Loaded symbols for /lib/i686/cmov/libnss_nis.so.2
Reading symbols from /lib/i686/cmov/libnss_files.so.2...Reading symbols from /usr/lib/debug/lib/i686/cmov/libnss_files-2.11.2.so...done.
done.
Loaded symbols for /lib/i686/cmov/libnss_files.so.2
Reading symbols from /usr/lib/alsa-lib/libasound_module_rate_speexrate.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/alsa-lib/libasound_module_rate_speexrate.so
Reading symbols from /usr/lib/sse2/libspeexdsp.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/sse2/libspeexdsp.so.1
Core was generated by `./OgreVisualizer'.
Program terminated with signal 11, Segmentation fault.
#0  0xb6dc563d in std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&) ()
   from /usr/lib/libstdc++.so.6
(gdb) bt
#0  0xb6dc563d in std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&) ()
   from /usr/lib/libstdc++.so.6
#1  0xb73bb3c2 in std::_Rb_tree<Ogre::Node*, Ogre::Node*, std::_Identity<Ogre::Node*>, std::less<Ogre::Node*>, Ogre::STLAllocator<Ogre::Node*, Ogre::CategorisedAllocPolicy<(Ogre::MemoryCategory)0> > >::_M_insert_(std::_Rb_tree_node_base const*, std::_Rb_tree_node_base const*, Ogre::Node* const&) ()
   from /usr/local/lib/libOgreMain.so.1.7.1
#2  0xb73b5a52 in _M_insert_unique (this=0xb6157ea0, child=0xb616aff8, forceParentUpdate=false) at /usr/include/c++/4.4/bits/stl_tree.h:1182
#3  insert (this=0xb6157ea0, child=0xb616aff8, forceParentUpdate=false) at /usr/include/c++/4.4/bits/stl_set.h:411
#4  Ogre::Node::requestUpdate (this=0xb6157ea0, child=0xb616aff8, forceParentUpdate=false)
    at /home/balazsbela/Downloads/ogre_src_v1-7-1/OgreMain/src/OgreNode.cpp:805
#5  0xb73b6a40 in Ogre::Node::needUpdate (this=0xb616aff8, forceParentUpdate=92)
    at /home/balazsbela/Downloads/ogre_src_v1-7-1/OgreMain/src/OgreNode.cpp:789
#6  0xb73b5038 in Ogre::Node::setScale (this=0x1825c, scale=...) at /home/balazsbela/Downloads/ogre_src_v1-7-1/OgreMain/src/OgreNode.cpp:638
#7  0x0805d306 in VisualizerApplication::adjustNodes (this=0x9cd4808) at ../src/VisualizerApplication.cpp:236
#8  0xb6e867f0 in ?? () from /usr/lib/libSDL_mixer-1.2.so.0
#9  0xb6e8719a in ?? () from /usr/lib/libSDL_mixer-1.2.so.0
#10 0xb6ed9b0d in ?? () from /usr/lib/libSDL-1.2.so.0
#11 0xb6ee185e in ?? () from /usr/lib/libSDL-1.2.so.0
#12 0xb6f2e0bd in ?? () from /usr/lib/libSDL-1.2.so.0
#13 0xb6bc7955 in start_thread (arg=0xb198ab70) at pthread_create.c:300
#14 0xb6ca6e7e in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130
(gdb)

```

Ogre.log: http://pastie.org/1581790

# Answer
> 3 votes
Standard C++ containers do not offer guarantees of threadsafety, and I don't think OgreNodes do either. You're probably adjusting the node at the same time Ogre is doing something with it in a different thread.

You also have a double delete and leave behind a stale pointer in ~VisualizerApplication. Fix it by not making it a singleton. Just... don't use singletons. Ever.

---
Tags: c++, ogre
---


title: Managing flash animations for a game

text:
# Question
Title: Managing flash animations for a game
Ok, I've been writing C# for a while, but I'm new to ActionScript, so this is a question about best practices.

We're developing a simple match game, where the user selects tiles and tries to match various numbers - sort of like memory - and when the match is made we want a series of animations to take place, and when they're done, remove the tile and add a new one.

So basically it's:

1. User clicks the MC
2. Animation 1 on the MC starts
3. Animation 1 ends
4. Remove the MC from the stage
5. Add a new MC
6. Start the animation on the new MC

The problem I run into is that I don't want to make the same timeline motion tween on each and every tile, when the animation is all the same. It's just the picture in the tile that's different.

The other method I've come up with is to just apply the tweens in code on the main stage. Then I attach an event handler for MOTION\_FINISH, and in that handler I trigger the next animation and listen for that to finish etc. This works too, but not only do I have to do all the tweening in code, I have a seperate event handler for each stage of the animation.

So is there a more structured way of chaining these animations together?

# Answer
Definitely have a look at the greensock Tweening library. Especially TweenLite and TimelineLite. It's a really great tweening library and will definitely make tasks like the one you're facing a lot easier.
> 2 votes

# Answer
So there seem like two good ways to solve this. The first is to take Bummzack's advice and use TweenLite to programmatically advance your movie clip. When the tween finishes you can then remove the clip and carry on. The second approach I've used is to add an event to the final frame in your movie clip. Usually I will fire an EVENT\_COMPLETE event in the final frame. The game would then add the movie clip, start playing it, and listen for the complete event.
> 1 votes

# Answer
Timeline animation is fun and quick to create. As you mentioned only the image(s) in the tile changes. I would create a tile (with animation) on a the timeline and load the image(s) into it. Use frame labels and base your logic on the current frame label.
> 1 votes

---
Tags: flash, actionscript-3, animation
---


title: Double sides face with two normals

text:
# Question
Title: Double sides face with two normals
I think this isn't possible, but I just want to check this:

Is it possible to create a face in opengl that has two normals?

So: I want the inside and outside of some cilinder to be drawn, but I want the lights to do as expected and not calculate it for the normal given. I was trying to do this with backface culling off, so I would have both faces, but the light was wrongly calculated of course. Is this possible, or do I have to draw an inside and an outside? So draw twice?

# Answer
Use gl\_FrontFacing in your fragment program and set your normal to -in\_normal if back facing.
> 3 votes

# Answer
Unless you will use custom shaders for triangle replication in geometry shader, there is no way to do this and you have to use twice more triangles.

There is also another way to do it in pixel shader (which is considered to be easier than gs), **but it is buggy**. You can use `abs(n dot l)` in phong, but it will cause that the side of the triangle which should be lighted just with ambient light is also lighted with diffuse light.
> 2 votes

---
Tags: c++, opengl, culling
---


# Question
Title: Internationalization (i18n) in Flash games? Is there an easy way?
I want to internationalize some texts in a flash (not flex) game I'm working on and I can not find an easy way to achieve that... I have found some libraries and other solutions, but I expected something a lot easier (it is really easy with other technologies).

Do you have experience in this? How do you do it?

# Answer
> 5 votes
I recently developed a Flash Game that I translated to German and English. You can have a look at it here: http://www.bioaschi.ch/?lang=en#/game. You can change the language on the fly in the *settings* menu.

To translate the game, I used the following approach: I have a custom written *Config* class that is basically just a registry of *key* =\> *value* pairs. The config class can read from an XML file and also dispatches events when a value changes.

For the game I created 2 different config files. One is the `main` config, and then one file containing the translations (called `lang`). Them `main` config contains a key that specifies the language, eg. *lang = en*. In game I listen for change events on that key. Whenever that happens, I read/apply the values from the appropriate language.

Here's a small snippet of code that shows how the language is switched in game:

*Somewhere in the "Settings" panel code:*

```
Config.getConfig('main').setValue('lang', 'de'); // or 'en'

```

*Then anywhere else where text needs to be localized:*

```
        // this is in the construtor or some init method
        ...
        var cfg:Config = Config.getConfig('main');
        cfg.addEventListener(ConfigEvent.CONFIG_CHANGE, onConfigChange);

        updateText(cfg.getValue('lang', 'en') + '.');
    }

    private function updateText(langns:String) : void {
        var langCfg:Config = Config.getConfig('lang');
        this.title.htmlText = langCfg.getValue(langns + "credits.TITLE", "<title>");
        this.text.htmlText = langCfg.getValue(langns + "credits.TEXT", "<text>");
        _btnClose.label = langCfg.getValue(langns + 'highscore.CLOSE', 'X');
    }

    private function onConfigChange(evt:ConfigEvent) : void {
        if(evt.key == 'lang'){
            updateText(evt.value + ".");
        }
    }

```

You can have a look at the file that is being loaded by the game here: http://www.bioaschi.ch/game/language.xml

To substitute parts of the text with variables (eg. `your score is %d` transforms to `your score is 10000`), I suggest you use the excellent *Polygonal Datastructures Library*. It contains a AS3 implementation of *Sprintf*.

Instead of having all translations in one file, you could also easily have one single file per language.

For the sake of completeness, here are some code listings:

Wow, this kinda turned out to be a long post, I'm sorry. The approach I took is rather simplistic and doesn't cover the more complicated topics of internationalization, like *date formats*, *number or currency formatting* etc. For simple translations it works just fine though.

# Answer
> 1 votes
Coming from the C++ world, the general idea for changing languages on the fly is to have all language text in memory in a table somewhere, with each string (or sprite that contains text) assigned a numeric ID. All IDs are the same in different languages, plus a language offset. For example:

const LANG\_EN:int = 0; const LANG\_DE:int = 1000;

const STRING\_HELLO\_WORLD:int = 0;

var StringTable:array /\* of string \*/; StringTable\[STRING\_HELLO\_WORLD+LANG\_EN\] = "Hello, World!" StringTable\[STRING\_HELLO\_WORLD+LANG\_DE\] = "Hallo, Veldt!"

This takes considerable setup time, granted, but it only has to be done once.

Then, in your code, you just reference the table using the string and current language offset: myObject.text = StringTable\[STRING\_HELLO\_WORLD+currentLanguage\];

# Answer
> 0 votes
Bind your components to a flash.utils.Dictionary object. A Dictionary is basically an associative array. If you swap one with another, and your bindings are in place, the views will change automatically. Use can place date formatting etc information there two. I also introduced an unpopular and unfriendly "numbered id" system. This was because when you truly explore internationalization/multilingual apps, you will find that some words English translate differently depending on context (in French or Spanish it is very common).

---
Tags: flash, actionscript-3
---


title: XBOX + Xna != DirectX?

text:
# Question
Title: XBOX + Xna != DirectX?
I'm a bit confused. The question is: when I'm developing a XNA game for Xbox (or Windows), is it possible to use DirectX (to make use of the GPU)? Or is everything getting calculated by the CPU?

A quick Google search didn't gave any results of combining those two...

# Answer
As far as i know, it's no different from PC + XNA: draw calls you make (anything using Spritebatch, any of the DrawIndexedPrimitives, rendering models, etc.) are done via the GPU (since XNA is a layer on DirectX). Anything else goes on the CPU(s).
> 8 votes

# Answer
XNA uses Direct3D 9, so you can do pretty much the same things you can do with D3D9 in XNA, without having to deal with some of the lower level plumbing. And, as said, you can use HLSL with XNA to compute stuff on the GPU.

As a rule, most (if not all) of the graphics rendering/computing is done on the GPU, and the rest is done on the CPU.
> 5 votes

---
Tags: xna, graphics, directx
---


# Question
Title: How do I leverage code and experience across alternate platforms?
I continually build complex engines and libraries within a single platform and technology, to allow me to build increasingly bigger and better games. How do I continue this when development crosses into different platforms? If I switch platforms, how do I leverage past code and experiences?

---

Games are hard to build. Big games are even harder to build. I've decided that to be able to make big games, I need to start building smaller games, and building up an asset base of code, assets such as graphics and sounds, tools, and most importantly, game engines. I can eventually get there, one game at a time.

Let me give an analogy. To build an MMO 3D RPG, I would approach this by building and releasing small games with increasingly more features. This could entail, for example:

* A simple 2D game
* A tile-based game
* A game with RPG elements (items, equipment, monsters, battle)
* A full-fledged RPG
* A 3D RPG

The problem now is if I have to change platforms or tools; I don't know how to leverage past code-bases and experience to start with a mature product.

---

Right now, I'm writing Silverlight (FlatRedBall) games. Let's say I stick with this for ten years, and then suddenly decide to write a PlayStation 6 game, which is in an entirely different programming language.

Granted, I have ten years of game-development experience, and ten years of professional software development experience from my day job, to back me up. I would still like some way to transplant that 2D RPG engine into the new programming language, or else leverage it, somehow.

Is this even possible? What are my options?

# Answer
> 6 votes
If you look at how you do business systems I don't think there's much difference in this regard.

Abstract and layer everything as cleanly as possible so you can reuse interfaces and libraries later on, making the games as modular as possible. Write your game code against an engine layer that isn't hardwired to run on a specific platform.

Use scripting languages as much as possible and just write or add the script interpreter to each new platform, reusing script logic.

Design your tools to be as generic as possible and with flexible content formats. Reuse the tools and content pipelines and only re-implement the platform specific parts.

# Answer
> 9 votes
You could try to use an interpreted language combined with some small native components for hardware specific bits. By using Python, for example, you only need to recode native language extensions that interact with the hardware directly, while sticking to the same API on the Python side. This allows you to code your game logic, asset loading and rendering once in Python and reuse them as long as you manage to get the Python interpreter and your extensions operational on the new system.

All-in-all, I think that a game engine should be very hardware and language specific so it can pull off cpu or gpu intensive feats. I would want to build or buy a new engine when migrating to another language or system, so you can benefit from the optimizations they offer.

You do have good options for your other systems, though:

* Game logic can be written in an interpreted language that is supported by or built into the new engine
* Assets are already pretty portable, again, as long as the engine supports them or you have converters for them
* Tools do not need to be written in the same language as the engine is written in as long as they communicate or export in way understandable by the engine (again converters can solve this problem)

The bottom line is that you will never be able to fully transplant an engine 'as-is' to a different platform or language. You always need some kind of layer or wrapper that translates the platform/language calls into engine calls and vice versa.

# Answer
> 6 votes
So, first, please stop saying 'leverage'. Say exactly what you want to do with it ("I want to run the bytecode across platforms.", "I want to use my old .cs files in ten years.", "I want to...", etc.). Buzzwords aren't helpful for us here.

First, let me try to see if I understand your underlying questions:

1. I wrote a game or engine to do X on Y platform. How do I use this (without modification) on platform Z?
2. I wrote a bunch of code in language X. How do I convert it to language Y?
3. I want to rerelease my game or engine X for platform Z 10 years later. How does this work?

All of which boils down to a better question; we'll get there in a bit.

**I wrote a game or engine to do X on Y platform. How do I use this (without modification) on platform Z?**

So, there are two parts to this: "doing X on Z", and "using on Z".

You want to make sure that you are bringing something worthwhile onto the platform ("doing X on Z"): why port a text adventure game onto a PS6? Is there an opportunity to update the technology and game to make better use of available resources (i.e., "I've got pixel shaders now, so I can move away from statically-calculated per-sector lighting in my Doom clone.", "I've got hardware T&L and rasterization now, so no reason to use an engine limited to raycasting wall segments")? If you are porting over code limited by old hardware, might as well ditch those limitations and start anew.

"But," you say,"Zork is still awesome, and would be great on the PS6!".

Okay, no worries, agreed. So, now the problem is how to make Zork run unchanged on a PS6 ("using on Z"). To run old programs, you either need to adapt the code to its new operating environment, or adapt its new operating environment to it. You made a decision writing your code, and this is what is going to be important: *did you write your code to be interpreted?*

*Why yes, all of my game logic is in a custom, well-specified bytecode format running on a custom virtual machine.*

Good for you, Mr. Fancypants. You saw this day coming, and you wisely wrote your language to run completely on a virtual machine (emulator). You are following in the footsteps of Carmack, Lucent/Bell Labs, or Berez and Blank. All you have to do to run a port is to rewrite/recompile your interpreting environment, and now you can rest assured that as long as people can write VMs for the new platform, you're tech will persist. Java or C# is a decent way of going about this as well.

*Er, that's rather silly... I just wrote everything in portable C/C++, complying to all the standards and abstracting away all of the platform-specific stuff.*

Alright, cool! Your diligence in proper systems engineering and abstraction is going to pay off. You just have to rewrite the platform-specific stuff, tweak the build process, and away you'll go! Sure, writing a Direct3D backend to replace your OpenGL renderer might take a month, but hey, at least it isn't the whole stack!

*Um... I... uh... well, it was a lot simpler to let objects make Direct3D calls directly. I mean, it wasn't supposed to turn into this big app.*

Congratulations! You're screwed!

...more seriously, this is something that can be unavoidable. If you wrote your text game in QBasic, and here we are on Windows 7, you probably can't do anything to salvage it. At this point, you can't possibly adapt your application to run correctly on the new architecture/machine/operating system.

So, you'll need to adapt the environment to your application (if Mohamed won't come to the mountain...). Consider: if you've got the binaries, and the assets, and you know the configuration of the machine they ran on successfully, then all you have to do is use some emulator for that environment. This has been done before. As long as you don't need to communicate with it, or reuse its routines, you'll be fine.

*But... but... but what about my A-star implementation in 68000 assembler? I don't want to rewrite that!*

Tough luck. That's the cost of *not thinking* about what you are going to do with your code later in life. This is why we call it software *engineering*, not software *kludging*--at least not in public.

**I wrote a bunch of code in language X. How do I convert it to language Y?**

One character at a time? Outsource it? sed and regex?

More productively, if you wrote it in C or something similar, you might have it compiled into a library you can link with. It's okay to have something written in Fortran that you can still call from other code whose build environment knows how to digest libraries. COM objects and .dlls and all that let Visual Basic apps interact with C# code.

If you have to rewrite it, and don't care about code quality, sometimes you can find a tool to do the work for you. This might not even work, but hey, you don't have to write the code yourself.

If you don't mind, rewriting it in another language is a great opportunity to learn the new language, remove dead code, and rethink old algorithms that might not be optimal anymore. And because you wrote good unit-tests (right?), testing that the new code is at most as buggy as the old should be easy.

**I want to rerelease my game or engine X for platform Z 10 years later. How does this work?**

After reading the above, it should be obvious: write modular, well-specified code for a virtual machine, and/or properly abstract away implementation-specific functionality. If that doesn't work, ship it with an emulator.

*

The real question you want to ask, though, is:

**How do I design software that I can keep using throughout my career?**

You've got to plan out, ahead of time, what it is going to do, and how it is going to do it. You've got to hide or isolate anything that doesn't directly deal with the logic of the algorithms being implemented (no direct API calls), or decide where you stop caring about portability. You've got to be willing to *remove and rewrite deficient code*. Mostly, though, it's the same as the way you get to Carnegie Hall:

Practice, man. Practice.

# Answer
> 2 votes
The idea that you won't be able to take libraries of code and use them again, or use them on multiple projects because the language doesn't match, or the design is partially within the implementation is consistently misjudged in games development.

While developing projects across different languages, the inability to reuse source code is significant, but also inappropriate when considering the true meaning of reusability.

Reusability is not concerned in reusing source files, not even in particular languages, but the ability to maintain an invenstment in information. A wealth of knowledge for the entity that owns the development IP.

Copyright law has made it hard to see what resources have value in reuse, as it maintains the source as the object of it's discussion rather than the intellectual property represented by the source. The reason for this is that ideas cannot be copyrighted, so by maintaining this stance, the copyrighter keeps hold of this tenuous link to a right to withold information. Reusability across the language gap comes from being aware of the information contained within the medium it is stored. In our case, it is normally stored as source code, but the information is not the source code.

With same-language ports, the source can be adapted to any project we wish to venture. However, the source is not the information. The information is the order and existence of tasks that can and will be performed on data. This view of information leads to an understanding that any reusability is an adaptation from one set of temporally coupled tasks into a new framework.

So, even though you want to move from one language to another, or one platform to another, and the code doesn't appear resuable on the outside, the fact is that it contains a wealth of information in a readable form. In fact, porting between languages can often show up bugs that have been present for years.

The method by which you port the code from one language to another varies with the languages involved, but a good starting point is to load the old code into the new language as comments then, treating the old code as pseudo code, begin writing in the new language. This way, all the old bug fixes are maintained while any new ones can be quickly ported back to the old codebase if wanted/necessary.

---
Tags: architecture
---


title: Oscillating Sprite Movement in XNA

text:
# Question
Title: Oscillating Sprite Movement in XNA
I'm working on a 2d game and am looking to make a sprite move horizontally across the screen in XNA while oscillating vertically (basically I want the movement to look like a sin wave). Currently for movement I'm using two vectors, one for speed and one for direction. My update function for sprites just contains this:

```
Position += direction * speed * (float)t.ElapsedGameTime.TotalSeconds;

```

How could I utilize this setup to create the desired movement? I'm assuming I'd call Math.Sin or Math.Cos, but I'm unsure of where to start to make this sort of thing happened. My attempt looked like this:

```
    public override void Update(GameTime t)
    {
        double msElapsed = t.TotalGameTime.Milliseconds;
        mDirection.Y = (float)Math.Sin(msElapsed);
        if (mDirection.Y >= 0)
            mSpeed.Y = moveSpeed;
        else
            mSpeed.Y = -moveSpeed;
        base.Update(t, mSpeed, mDirection);
    }

```

moveSpeed is just some constant positive integer. With this, the sprite simply just continuously moves downward until it's off screen. Can anyone give me some info on what I'm doing wrong here? I've never tried something like this so if I'm doing things completely wrong, let me know!

# Answer
> 5 votes
You need to move the sprite relative to a center point. To do this, create an offset and alter the position of Y with that offset.

If your Y doesn't move, you can just store your Y:

```
float center = Position.Y;
float offset = 0; //The offset to add to your Y
float radius = 5; //Whatever you want your radius to be

```

Then, in your update function, you can offset your Y by a specific amount:

```
double msElapsed = t.TotalGameTime.Milliseconds;
offset = (float)Math.Sin(msElapsed) * radius;
Position.Y = center + offset;

```

# Answer
> 2 votes
If this is the kind of motion you are trying to get, all you need to do is something like this:

```
[pseudo clode]
float center_y = position.y;
float raduis = 10.0f;
float angle = 0.0f;

void update( float elapsedTime )
{
    // you can use different speeds for the X and Y positions
    // to adjust the wave as you need.
    position.x += speed * elapsedTime;
    position.y = center_y + Math.Sin(angle) * radius;
    angle += speed * elapsedTime;
}

```

Essentially, what the sine function does is return a float point value in range \[-1,1\] based on the input angle (in radians). You can then scale that result by the radius, in the example, I scale the value by 5 given me a value in the range \[-5, 5\], and then all you need to do is add that value to the Y position you want the sprite to oscillate around.

You can also think of the "speed" variable as the frequency of the wave in this line:

```
angle += speed * elapsedTime;

```

The higher the speed the faster the oscillation will be. Note however that this isn't physically accurate, to make waves and have control of amplitude, frequency and other parameters is a little more "complicated".

Hope this helps.

---
Tags: xna, sprites, movement
---


title: How should I replan A*?

text:
# Question
Title: How should I replan A*?
I've got a pathfinding boss enemy that seeks the player using the A\* algorithm. It's a pretty complex environment, and I'm doing it in Flash, so the search can get a bit slow when it's searching over long distances. If the player was stationary, I could just search once, but at the moment I'm searching every frame. This takes long enough that my framerate is suffering.

What's the usual solution to this? Is there a way to "replan" A\* without redoing the entire search? Should I just search a little less often (every half-second or second) and accept that there will be a little inaccuracy in the path?

# Answer
> 13 votes
You don't have to search the entire path in one frame, I have done this by giving a limit on the search loop, the AI will then start to follow the little information it has, and the next frame I'll search some more, it might take 3 frames until the path is found. It can look quite convincing to, as it looks like the AI is actually searching.

# Answer
> 8 votes
You could use proximity detection to run the algorithm every few frames if the distance is very great (because in most cases if the distance is large, the target path wont change drastically from frame-to-frame). For example:

```
      Distance > 100, run A* every 2 seconds
100 > Distance >  50, run A* every 1 second
50  > Distance >  25, run A* every 10 frames
25  > Distance <  25, run A* every frame

```

This is assuming that there is a distance where running A\* every frame has performance that is still acceptable. In short, I'd go for your second option. Especially if what you have is working, I'd avoid reimplementing something else if I can just scale back what is working well. The bottom line is that you'll have to try it out to see if it works for your game.

# Answer
> 8 votes
Not really answering your exact question, but... if you're willing to "cheat", you can make the player leave "breadcrumbs" and have the boss follow them. If the breadcrumbs path crosses itself, follow the most recent one (this makes the boss avoid loops and other paths that may be too long, not to mention not following the exact path of the player)

This would work fine if the boss is some kind of animal with a good sense of smell. This would work a lot like following the scent of the player :)

# Answer
> 5 votes
Your case is pretty much what HPA\* was invented to address. If it seems like overkill, though, I would tend to think that pathfinding every half second or so should work out pretty well.

# Answer
> 4 votes
If it's a static environment then you can precalculate all-pairs shortest path.

# Answer
> 2 votes
I created a game for a 48 game competition where an A\* character follows the player around a level. Because my A\* implementation was slow (it couldn't run every frame) I put the interval on a three second delay. This had the unintended result of allowing the player to "trick" the AI for a few moments. It actually made the game more fun.

Later on, I improved the performance of the A\* implementation and tried running it on every frame. The game stopped being fun because the enemy would always perfectly seek the player.

That was unexpected and a good learning experience.

# Answer
> 0 votes
Unless you absolutely want (or need) to use A\*, you could also take a look into Steering Behaviours. As there is no complete path planning per frame involved, it should be a lot lighter on the processing.

---
Tags: ai, path-finding, planning
---


title: Adding 'swerve' to a direction

text:
# Question
Title: Adding 'swerve' to a direction
I'm not much of a maths expert, so this is probably quite straight forward. I was playing a soccer flash game where you take free kicks. You provide Power, Swerve and Direction. I'm reading up on vectors and such so I can use the direction and power information to shoot the ball with the correct velocity.

What I don't understand is how the 'Swerve' information is used. What formula connects the Swerve information with the Direction and Power? This is all assuming a 2D environment.

# Answer
> 5 votes
If, as AttackingHobo says, you're talking about spin, then the 'swerve' is known as the Magnus Effect. The ball is spinning, causing the air to travel faster on one side and slower on the other, producing a pressure difference.

Basically, the force exerted on the spinning ball (from the Magnus Effect alone) at a given time would be something like this

```
F = k * (w x v)

```

Where `F` is force, `w` should actually be an omega and is the rotation vector, `x` is just a cross-product operator, and `v` is the current velocity of the ball. `k` is some kind of constant factor depending on what kind of surface the ball has and so on, that one you basically have to try different values and see which fits.

The `v` vector is pretty straight forward, just the direction and speed of the ball. `w` (or omega) might seem unintuitive though, the magnitude is the rate of the spin (usually radians per second, but since we're multiplying with an arbitrary constant anyway, it might as well be RPM), and the direction is the axis around which the ball is rotating. To know which way is 'up', it's easiest to take your right hand and bend your fingers, the rotation is in the direction of your finger tips, and your thumb is basically the rotation vector.

In 2D, birds-eye perspective, a counter clockwise rotation would have the rotational axis pointing into your eye (away from the ground). You don't really need 3D stuff (like the cross product), buts it's easier to work the stuff out on paper and use zero all but one of the components (like z) to reduce the formula.

Also remember Newton, `F = m*a`, but again, the `k` is arbitrary, so we can just bake the mass into it, making `a = k * (w x v)`. Where `a` is the acceleration (vector).

Birds-eye again, z pointing away from the ground (into your eye), x to the right, and y up the screen.

```
w = s*ẑ, v = (vx, vy), a = (ax, ay)

```

here I've used `s` as the spin (rate of rotation, positive being counter clockwise,  denotes the unit vector in the z-direction).

```
ax = -k*s*vy
ay = k*s*vx

```

Long rant for a simple formula, hope it helps. :)

Note that back-spin will cause the ball to travel further, and top-spin will cause it to dive early, if that's something you want, you need to do the spin-vector in 3D.

# Answer
> 1 votes
Do you mean spin? Spin will cause the ball to swerve in the air.

In a true to life simulation, you would only apply a force to a spot on the ball from a certain angle, and the speed, spin, and direction would be determined from that.

In this soccer game, I am going to assume the graphics are 2d, but the view is facing the goal, and the ball graphic shrinks to provide depth.

So you need some sort of z depth at least.

The Swerve, or spin, causes the ball to change direction after it is hit. This allow for shots that look like they are going to end up to the right, but end up moving left.

So in the game make the swerve variable a float, and have it change the X direction on the ball, or what ever direction is left and right.

# Answer
> 0 votes
@roe above is probably the best answer. In real life it takes some amount of time for the fluid velocities to equilibrate to the motion of the ball through the air. So you could try to add some sort of time delay. My favorite is just exponential time damping. Swerve is just a some fraction of what it was the last time update, plus what you get from the current time update. So use roes: formulae for instantaneous swerve accelleration (or the current contribution), and combine say .05 times that to .95 times the previous result. Start the saved value at say 0, and you won't see much bending of the flight until several time steps have passed, which is kind of like a breaking ball in baseball, by the time the batter sees the balls trajectory deviate, it is too late to correct his swing.

---
Tags: mathematics, physics, vector, projectile-physics
---


title: How is console game development done?

text:
# Question
Title: How is console game development done?
I'm curious what the process is for development for a game console such as Wii, Playstation, or Xbox. Do I need to use some game engine and compile for each platform?

What IDE is used? Any C++ IDE? Are all console games built in C++?

# Answer
Pro development is almost unilaterally done in C++. If you're planning on targeting multiple platforms, this is a must since it's the only thing that's supported on every console and OS. Note: if you're new to this, I'd start with something much simpler like XNA - still very, very powerful, but it'll let you focus on your game instead of memory leaks and other neophyte C++ hurdles.

Also, developing for any of the three major consoles (if you include Wii in that category) will require a dev hardware, which is difficult/impossible to obtain unless you're working with a group that has an established presence in the game industry. (Read: Gearbox, Bungee, etc.)

To date, Microsoft is the only company to produce a free/very, very cheap option for independent developers to write and publish console games, and XNA is no slouch - many people are building very interesting things with XNA, and as far as I've been able to tell it's more than powerful enough to take full advantage of the current console hardware. Most of the work is done on the GPU these days, anyway, and the CPU code just coordinates things.

Oh, and your XNA code will run on Windows, as well. =)

**More thoughts**

I recently started working for a medium-sized game studio, and my development rig /pipeline consists of:

* PS4 dev kit.
* XBox One dev kit
* Windows machine - dual Xeon (20 cores, 40 with hyperthreading), 64GB of RAM, Titans.

It still takes 15 minutes to compile one of the larger games.

All actual coding is done in Visual Studio. The Sony and Microsoft tools allow connecting to your dev kit over the network, and provide remote debuggers that connect to Visual Studio. I haven't seen similar tools for other operating systems, but I haven't really looked.

The PS4 version is built through clang. XBox and Windows go through the Visual C++ compiler. (Some of our guys do their initial development on the PS4 because compilation is *significantly* faster.)

Most of the popular engines go a long way towards handling differences between the hardware, but when you get into shaders and real platform-specific optimizations (memory transfers are different beasts when comparing consoles to PCs), you're going to have to become something of an expert on consoles. On my team, we have one guy who is the PS4 expert, one who is the XBox expert, One super-badass who is the everything expert, but everyone works on everything.

**Update 2017**

* XNA has been dead for awhile now. Look into Unity if you're C#-inclined.
* You can now develop for XBOX using a retail console.
> 11 votes

# Answer
To make retail games for a console you need to become an officially licensed developer. Each console manufacturer has a slightly different process for this, but it involves showing them that your team is capable to building and completing projects. If you've never shipped anything don't expect to get past this hurdle.

Once you've got a license then you'll need to purchase development hardware. The cost of the hardware is ~$10k per machine.

In the course of building your game you will need to get at least a distribution deal with an officially licensed publisher. You will also need to pass your game concept through each console manufacturer for approval. They each can accept or decline your title for their system.

Once the game is finished you again have to submit to the console owner for final approval and then pay them to manufacture the product. Distribution to stores is then handled by your publisher.

Basically the retail console space is a controlled market for established teams only.

To short circuit this whole process, MS put together XNA and the Community/Indie part of XBLA. XNA requires C# and doesn't give you complete access to the hardware, but in exchange you can develop and test on retail systems, don't need a developer license, and only have to pay a small fee to distribute digitally.
> 4 votes

# Answer
You don't have to use an existing game engine, but creating one from scratch can be a daunting Task. Right now your easier option is XNA and C# for the Xbox. XNA is free but to be able to publish your game you have to pay $99 per year fee to join microsoft's developer club. Unity3d is a game engine which also has an export to Wii option but you still need to be a licensed developer through nintendo and I don't know the costs involved with that.

**resources:**

Microsoft app Hub(XNA and such)

Unity3d game engine
> 2 votes

---
Tags: tools, game-industry, console, process
---


# Question
Title: Blending animations for more character movements
I am making a hack n slash 3rd person game, and I want the character movements to be more dynamic not like fighting games where you have a moves list.

I want to animate tons of different animations and have them "Tween" between each other.

I do not want the to use the mouse for controls, I want it to be all keyboard, that way you have up to 10 inputs (All your fingers) to blend and morph animations to create more fluid movements. In the end this will almost be similar to characters typing a phrase or string of keys rather than move forward mouse look click to melee.

My questions are:

* Has anyone done this before?
* How would someone go about trying to tween?

lets say one for key on the keyboard excluding Tab, Caps, R+Shift, L+Shift, Enter, R+Ctrl, L+Ctrl, L+Alt, R+Alt, Windows Key, and Menu.

So thats all the numbers, letters and punctuation keys. Thats 46 keys gives me a combination of 46P1 = 5502622159812088949850305428800254892961651752960000000000L (used Python), and with a minimum entry value of 2 keypresses shortening to half. This is not humanly possible to create so many inique animations in one lifetime. But I'm guessing there is a reason this hasn't been done already.

Or if I just used 10 basic keys. Maybe ASDF SPACE (RIGHT HAND) 456+0 (LEFT HAND KEYPAD) it would give me 3,628,800 posible unique animations.

# Answer
> 4 votes
That type of control scheme is totally useless as you will overload the players with information and at least the reaction time will suffer considerably,that is why mouse is preferable since a lot of variation can be made

If you want variety in animation you don't need convoluted controls schemes, you can use either procedural animations and/or blend multiple animations togheter

# Answer
> 1 votes
Well... the reason there's a moves list is because each "attack" has to do SOMETHING. Limiting the options does limit the gameplay but it also limits players from being overwhelmed and it limits the chances of something obscenely overpowered sneaking in.

If the "something" for the attack is, for example, a slash attack but one varies one degree from another then you're likely better off with a different interface, maybe like an aiming icon that's mouse based but changes the angle of attack and one or two buttons for the slash. That gives you simplicity but also variety.

Anywho, as far as the animations go then **I would suggest having a discreet set of starting points or stances for the animations.** Each animation that you want to form for the attack would then only have to start from those discreet start points, and to tween between animations then you would just, at worst, have to tween between the start points. It's not quite the same pie-in-the-sky type of animation that you sound like you're describing, but it's vastly more feasible to do.

# Answer
> 0 votes
The closest thing I can think of to what you are talking about is Die by the Sword. It was a hack'n'slash that didn't have any fixed moves. Instead you used either the numberpad or the mouse to directly control the weapon arm. The end result was frankly a bit difficult to control, but did have the occasional moments of brilliance particularly in multiplayer.

The biggest problem here is in getting players to make the mental translation between input and what's occurring on screen. Things like the WiiMote, Move, and Kinect can shorten that mental gap between what the player and avatar are doing. Although any block attacks will continue to create a disconnect.

In the more experimental spaces, other games that play with direct control of limbs as opposed to pre-recorded movements include QWOP and Toribash

---
Tags: mathematics, animation, graphics-programming, tweening
---


title: How to design a leaderboard?

text:
# Question
Title: How to design a leaderboard?
This sounds like an easy thing but when I considering the following

* Many players
* Some have played many games and some just started
* Different type of statistics

On what information should the actual ranking be based on? I am planning to display the board in a UITableView so there is limited space available per player. However, I am not bound to the UITableView if there is a better solution.

This is a quiz game and the information I am currently capturing per player is:

* #games played totally
* #games played per game type (current version have only one game type)
* #questions answered
* #correct answers

Maybe I should include additional information.

I have been thinking about having a leaderboard property page where the player can decide on what basis the leaderboard should display information but would like to avoid the complexity in that. However, if that is needed I will do it.

Anyone that can give me some advice on how to design the presentation of this would be highly appreciated?

# Answer
> 0 votes
as far as leader board development you can get it from the gamekit

check out this video: http://www.youtube.com/watch?v=JjF82OYGBq4&feature=player\_embedded

as far as the artistic design that really depends on style of you game.

hope that helps

# Answer
> 1 votes
You could base the ranking on a "weighted" average. For instance, the number of games played would have a smaller weight in the average compared to the number of correct answers. That way you provide a general ranking based on different information. It's also a nice "feature" for the user to be able to look at rankings according to specific info.

---
Tags: iphone, objective-c, leaderboards
---


# Question
Title: Compatibility between DirectX 9 and DirectX 10 shaders
I am a beginner to game development and as I am used to programming in C# I decided to go for XNA. I've been playing around with it for a while and now I am learning the basics of HLSL shaders, I have noticed in the MSDN documentation that there have been some syntax changes in HLSL between DirectX 9 and DirectX 10, for example, the Sampler type

Since I am having some troubles with my desktop pc, I am using my laptop which video card only supports DirectX 9.0c. Then I'm gonna have to write my shaders using the DirectX 9 syntax, right? So I am wondering, **will my HLSL shaders written using the DirectX 9 syntax work on a system running DirectX 10 (or higher)?**

# Answer
> 0 votes
XNA uses Direct3D 9 under the hood, and D3D9 only supports up to shader model 3, so (I could be wrong though) you can only use shader model 1, 2 or 3 with XNA. D3D9 will work on all D3D9 or higher enabled GPUs, so you can safely write some shader model 3 HLSL code for XNA.

On the other hand I'm not sure about the xbox. I think the xbox supports shader model 3.0, but I'm not sure, and I think it has a few specific functionality. But in general when using XNA, if it compiles, it should run fine on PC + xbox.

# Answer
> 0 votes
You cannot use directx10 in xna.

If you wish to have DX10 and DX11 features in C#, i suggest using SlimDX, which is great framework over directx. It contains "sample framework", similar to XNA. If you don't mind losing the xbox and win 7 phone support, slimdx is giving you more freedom and better performance than XNA.

---
Tags: xna, c#, directx, shaders, hlsl
---