Is Box2D perfectly deterministic? - android

I'm writing an Android game using LibGDX and Box2D. I'm planning on adding a turn-based multiplayer feature to it.
Now, if on both clients I step the Box2D world at the same rate with the same time steps and I start a simulation on both clients with the exact same initial parameters, when the simulations are over, will the final state of both simulations be exactly the same? In other words, is a Box2D simulation perfectly deterministic?
If it's not, then that means every time a simulation is over, one client acting as a host will have to tell the other to throw away its final simulation's results and use its instead.

Official FAQ quote
The official FAQ had a quote that confirms what you deduced http://web.archive.org/web/20160131050402/https://github.com/erincatto/Box2D/wiki/FAQ#is-box2d-deterministic:
Is Box2D deterministic?
For the same input, and same binary, Box2D will reproduce any simulation. Box2D does not use any random numbers nor base any computation on random events (such as timers, etc).
However, people often want more stringent determinism. People often want to know if Box2D can produce identical results on different binaries and on different platforms. The answer is no. The reason for this answer has to do with how floating point math is implemented in many compilers and processors. I recommend reading this article if you are curious: http://www.yosefk.com/blog/consistency-how-to-defeat-the-purpose-of-ieee-floating-point.html
Or in other words: Fixed-size floating point types
Why the wiki was deleted, I do not know. Humans. I'm glad he lowercased the project name though.

After looking around, the answer is "No", even if the same time steps are used! The reason for this answer has to do with how floating point math is implemented in many compilers and processors. Small discrepancies on each cycle add up resulting in significantly different simulations.

I managed to make Box2D deterministic for an experiment but it was not pretty. The way b2Body::GetTransform()/SetTransform() works does not allow reading the transform and then setting it back to the exact same values. I also had to delete and re-create the contact list for each body every frame. It would be possible to fix these cleanly and more efficiently but it would add enough overhead it would be hard to get the change merged.

Related

Unity how to improve your 3dDgame preformance for mobile devices?

I have build a pinball game in unity 3d for android and for some low mobile devices it is running slowly. I was thinking about hiring a unity expert to lighten up the code so it would run better on all devices.
But I wonder if this is possible. Can you make a game preform better by changing the code? I have to add this was my first unity project and it's very messy.
Thanks for helping
Absolutely, there are plenty of ways that changes to code could yield significant increases in performance, depending on how you're currently doing things.
One of them is object pooling when dealing with frequent creation/destruction of objects, another is caching component references when they are used often every frame. And if you're still using OnGui for your interface, probably avoid it in favour of the new (as of 4.6) GUI system. But you haven't included your code in your question, so I can't give a definite solution for optimizing your code.
Chances are though, not all of your code is problematic, just key scripts. My suggestion is to take a look at the Unity Profiler to determine which areas in your code are slowing down your game the most, then take steps to try reducing the execution time. You should also take into consideration non-code problems (eg. With lighting, geometry, materials, textures). Take a look at the guide Unity provides for ideas on how to address those
If you're still having problems, then you can bring that specific code to StackOverflow and see if it can be further improved. Hope this helps! Let me know if you have any questions.

Android application for reading money

I would like to make an Android Application that captures an image and searches it for coins and paper notes and then determines the value of the money in the image.
Additionally, the output of the system will be such that it can be understood by a blind person.
What functions and techniques in openCV would suit these tasks?
What limitations and development hurdles can I expect?
Assuming you already know how to program android apps,you need to do the following:-
Download the OpenCV SDK and set it up with the IDE.
Recognising shapes will be a huge part of your project, see the contour detection example that is present with the SDK examples. Your primary goal will be detecting a circle. Later you need to adapt your algorithm according to the currency. This will be of particular interest to you.
Learn the different image processing techniques like thresholding for better accurate results. Understanding what a Mat object is and how it can be manipulated is important.
Finally improve the accuracy of your algorithm, as sometimes lighting conditions make the difference between a good review and a dissatisfied user.

Image classification with opencv

We're currently working on an android ocr app using opencv.pre-processing ,segmentation ,Feature extraction steps are done. Classification is the remaining step and we're stuck ..We're using a DB table which is filled with each letter features ..Firstly we had only 1 feature per letter and we used euclidean distance ,but results wasn't accurate and more features needed to be obtained and so we did.The problem now is we have 7 features per letter and absolutely no idea of how to classify i/p based on them..some have recommended using knn ,but we can't figure out how and the opencv documentation in that part ain't clear ..so if anybody can help it wud be great.
Thanks in advance
Briefly and without discussing the details. Vector space comes in handy here. You need to build a feature vector
<feature1, feature2, feature3.. featureN> for each of the instances in your training set.
From each of these images you extract features that you think or you read in the research articles are important for image classification. For example you can do centroid, Gaussian blur, histograms, etc.
Once you have these values linear algebra comes into play with some classification algorithm: knn, svm, naive bayes etc that you run on your training set, that is you build your model.
If the model is ready you run it on your test set.
Use cross validation for more comprehensive results.
For more details check the course notes:
http://www.inf.ed.ac.uk/teaching/courses/iaml/slides/knn-2x2.pdf
or
http://www.inf.ed.ac.uk/teaching/courses/inf2b/lectureSchedule.html
would like to add that OpenCV may not have the sort of classifiers you might prefer.
There are several libraries out there, though you may have to see which works best when on a mobile platform. Could you give some details on the features you are using?
The simplest KNN (k-nearest neighbors) measure would be to find the Euclidean distance in n dimensions (for an n-dimensional feature vector) between the input sample's features and each of the vectors in your DB table. Also explore Mahalanobis distance (used to measure distance between a point and a dataset/class) if you have multiple classes and the input image is to be classified as one such 'type' or 'class' of image.
As #matcheek mentioned, more sophistication can be possible using machine learning techniques such as SVM, Neural Nets, etc. However first you might consider a simpler thing like kNN, considering its a mobile platform which may limit the computational complexity.

Search algorithm on Android: stack or preallocated buffer?

I am developing a pathfinding algorithm for an Android game, and I can write a recursive version (which is nice, but needs a big stack, so I might need to create a dedicated Thread for this with bigger stacksize), and a "loop" version which uses a buffer (instead of recursion). It is also a big problem that I don't know the size of the buffer in advance, so currently only the stack-based solution looks feasible.
I know this may be an algorithm theory or general computer science question, but perhaps it's Android specific because the stack size is a system-specific feature after all.
Generally, which should be more efficient (speed) on Android? The stack one, or the one which relies on buffer (heap)? Note that the question approaches the problem architecture-wise (assuming that the algorithmic complexity doesn't depend whether the algorithm is recursive or loop-based).
I know you asked for a Android specific answer, but I don't think it's really relevant to your problem. Two remarks
You don't necessarily need a stack based solution to implement a
recursive algorithm, you can emulate the stack on the heap with a
stack based data structure. Some times you don't even need this, though. This takes a bit more work, but don't base your algorithm on artifical architectural constraints.
There are plenty of non-recursive pathfinding, shortest path algorithms, ie Bellman-Ford
I can't comment on whether the most optimal recursive solution to a problem is going to be better than the most optimal iterative solution on Android. Usually, all other things being equal, the iterative solution is going to be faster, but when you get to more complex algorithms than say, Fibonacci numbers, implementing an iterative algorithm recursively or vice-versa might make a difference.
My gut feeling is you're about to commit the sin of early optimization. Do you have any calculations or measurements that indicate you'll run out of RAM?
I recommend that you use the simplest algorithm you can. You may however want to use AsyncTask so as not to freeze the UI, even for a second.

How to start game programming without a graphic artist?

Having a hard time phrasing the question, my situation actually is on the release phase of the game development cycle.
I have this game that falls under the casual category with little to no-complex-logic involved at all, running on a 2D side scrolling (semi) single character. In short it really is simple, so I am already done with the code and just need to replace sprites with my own to avoid any copyright issues once I decide to release it on the market (truth is I used sprites from various forums of another side scrolling MMORPG).
So my actual problem is, being an independent developer, with no talent in graphic arts and little budget to outsource a graphic artist, How would I (a plain programmer) create a modern looking graphical game?
Note:
The game is non-profit, I made it just to learn what the android platform has to offer.
But seeing it can actually be fun for others to play with, I'd like to release it.
I wanted to make this a community wiki as I see other game programming beginners would also face the same question. Although I am not that sure if that reason alone qualifies. But it seems with my reputation now, I'd leave that to the admin / mods decisions.
Keep the resources seperate and replace them before releasing with free versions or your own art.
There is no cheap source of high quality (graphics) unless you find someone willing to work for you cheap or for free.
Be very careful with copying sprites from other games. Some publishers have (and keep) very strict policies.
Another forum/site that might give you more information is http://www.Gamedev.net
Especially interesting might be the resources found here
I don't know how it is on Android but whenever I've tried games for fun, I've always relied on free sprite sheets which are all over the net. I've also clipped off a few from old DOS games which I run via. dosbox.
My favorite tactic is to put ugly placeholder graphics inside the game, and brag with it to my fellow pixel-movers. Next, someone from the pool will be disgusted with my lack of taste and ability to do good graphics, and put himself into the game.
If it doesn't work, you can always go headhunting, having your game ready and with just graphics to replace.
I stayed on the same problem, like you did.
Me as programmer also wanted to start coding a little android game, because i never did before.
And my garphic/artist skill is like 3-year-old-child...
So i tried to think of a designconcept with very easy geometrical Forms, if you are not so skilled.
And with the open source Software gimp you can do alot.
I dont know which engine you use, but i decided for unity3d, cause you are very flexible and you also can cross compile your project. I dont had experience with c#, but its very easy if you came from other oop languages, like java, so maybe have look for it. :)
Maybe also look what i made of it, it were just some circles and lines!
https://play.google.com/store/apps/details?id=de.duckdev.anbr
greets

Categories

Resources