Good day, dear sirs. I have seen some fresh topics about physics. And I decided it’s my turn to create another question. So can Bullet physics be used without connection to main thread/loop? I mean, I just want to create another node and perform physics action in this node. Yes, it sounds dumb and maybe there are better solutions. But when game works on server and clientside at the same time, I would prefer to isolate some physics actions to serverside.
PS. I didn’t find similar topics on the forum.
bullet physics is handled by an AppState and it doesn’t need to be rendered.
The only thing you will need to update bullet world is to call the BulletAppState’s update method.
And it should work. (And you will also need to take care of initialisation if you don’t use an AppStateManager).
Thanks! So I actually need to type something like:
BulletAppState state = new BulletAppState();
state.startPhysics();
state.update(myTpf); // Call it in Runnable with some interval
And it is going to work as a typical BulletAppState?
Actually you’d need to copy the code from the “AppStateManager” and then attach the BulletAppState to this as you would to the one from Application.
Or you could try to copy the code from Application which deals with the AppStateManager and then simply have two seperate StateManagers, but:
Your Method will/might fail hard. I didn’t entirely understand what or why you want to seperate but common answers are:
a) Use Bullets Parallel Threading Type. It allows Physics to run on a different thread
b) Having a Server App you can specify the FPS anyway so physics run at 20 FPS. But there also was some setting in the BulletAppState to make it only run on every n’th frame, iirc.
c) You can use multiple Physics Spaces. They will be treated indepently so they are essentially the same as new BulletAppStates.
Your Problem comes from Synchronization: Would you want to copy each Node? You must not use the same Node for both AppStates or they would freak out each other when placing the Spatial.
When it’s multiple threads, it gets even worse as opposed to calling them sequential…
Well i think it’s better if you first of all create a new StateManager then you add the BulletAppState to it.
And then you update the StateManager as you wish.
This will prevent you from doing all the initialization manually.
Plus AppState are intended to be used with a StateManager. (else you will have NPE)
You don’t have to use the AppState at all, you can use a PhysicsSpace “standalone” no problem, you’ll have to use the base PhysicsRigidBody etc. to do your physics, the Controls obviously won’t work without an update loop. And of course you’ll have to somehow call the PhysicsSpace update method continuously in your own loop.
Thanks, guys. It is become much clearer. The idea of using PhysicsSpace sounds very good. I’ll try to implement it.
Your Method will/might fail hard. I didn’t entirely understand what or why you want to seperate but common answers are:
I just want server process most of physics actions and sends result for all clients. And clients only operate physics of their characters. In other words: If somebody drop some item, server process it’s falling and sends only movement of this item to clients. While client’s BulletAppState cares only about movement/collision of client’s character.
Then it’s not really about having multiple app states
at all.
You simply have a different “game”/“jar”/“application” for the Server and you simply add those items and the clients don’t add the items at all (i.e. no RigidBodyControl) but you rather receive their position and set it then.
The only time you’d need multiple Physics Spaces would be Phasing: The Sever has the same map but every player has it’s own house with own furniture to collide with.
But then you’d have to overthink what the server should process and what not. The less it processes the more hacking is possible but the less it processes the less power you need and the more responsiveness the user will feel.
Another thing here is to use seperate colissions (i.e. only bounding boxes on the server, no need for precise colissions to check whether the player stepped through a wall)
Well, Server and client are already separated. They located in the same jar (with possibility to run client, server or both) but it made because it is much more comfortable for casual player to have everything in the one box. And that’s why I want to create for server it’s own loop with it’s own Physics Space and it’s own resources etc. So in case when player want to host server and join to it, actually there are two applications in single. This sounds messy but I hope you get the point .
Strictly seperate it and only have a “commons” jar for interfaces and such.
You can always bundle it and then make the User choose in your “main method” which to pick or even better: Have a Launcher Script and make them decide there instead of making it available during the game.
You save yourself from lots of trouble, because if you don’t you are tempted to access server data without using the network and such strange things.
I don’t know but it could even be possible to launch two Simple Applications.
Just look into the Main Method and try that out.
Only then you have complete seperation.
In my game, it always use network (even in “both server and client” (127.0.01)). And separate data folders.
And about complete separation, I think, it is really good idea to have separate server. You know, games like Counter Strike have embeded into client server and dedicated server. And it works great.
Anyway I see your concerns and will try not to make mistake!
You say you always send it through the Network but you could access them without when you dont separate them.
The most important thing that I learnt about programming is to first make a proper Design and restrict yourself even if it was easier without or even when you try not to make a mistake.
I’ve always wondered why you need OOP and especially fields like private.
They arent stopping any Hacker from accessing but they stop you from accessing. They say “Hey, this is class internal, redesign your Interface”.
But i am derailing way too much: murphys Law is your Problem so an improper Design will lead to hours of troubleshooting why it works when you connect to localhost and not on the net.
You wont ever have that Problem with separate projects. Trust me, it helps.
Back to cs: do you know wheter the games launches another executable in the Background?
You should separate them in Code but it doesnt matter how you package them for the User.
Plus: i wouldn’t want to download all the Textures just to launch the Server on my Server.
For a FPS you should consider doing all Physics on the Server though. Also See @pspeed valve links he often posts in this regard.
We have some misunderstanding. You didn’t understand my words correctly and/or I am just bad in english . I wanted to say that I can ONLY access via networking. Moreover, I agree that localhost is not real internet and I take it into account. After some updates I send copy of my game to my friend and we trying to do something on the server. And hoster’s client has the same rights and use the same parts of code as other clients.
Suprisingly, but I have read these valve links some times and my game based on this system. Also, doing all Physics on the server is good idea if it not very costly. Currently I am afraid that default server can’t compute all physics for 50+ players (If we are talking about big online).
After all, I understand your words and agree with OOP conception. Anyway, you think I use these type of design: “client” “clientserver common features” “server”. And server and client parts mixed with each other.
But actually it designed as: “main menu” (to launch client or/and server), “server library”, “client library”. And if I delete server part or move it to another project, the game will launch as it was launched before (but without ability to host, of course). As well as client part.
50 players isn’t that many, though. Especially if they are zoned properly. I wonder if you will spend more processing time trying to sort out paradoxes in more complicated approaches.
Note that I have a networking library that is supposed to solve these cases:
It’s not really documented at all yet except some source javadoc and there is on known bug for message splitting (that can easily be disabled without much issue). It’s a decent start for real-time high performance physics-based networking. Another game on here is using it already to good effect.
You can see the help I provided in getting it working here:
If nothing else maybe it provides some ideas.
Or I guess this is where I started my ‘tutorial’:
The funniest thing is that after looking through this library I understand that I am wheel reinventor .
I was forced to write my own ZoneManager (it has the same name. Actually it separate world into zone/cells) and kind of bit stream to send information about objects.
Anyway, I am very grateful. At least now I could “sharpen” my wheel and take ideas. Especially about physics!
PS. I have checked your website before and I couldn’t find any words about this library. It is very sad that sometimes it is hard to find such good information. Don’t you mind to post about it somewhere? I think it is very useful for community but people could just don’t know about it’s existance.
Everything takes time and my time is usually split a hundred different ways these days. For example, my wife just started chemo again recently. kids are home for the summer, etc…
I will get to it eventually.
Trust me … @pspeed 's network library saved my ass for my network layer and physics partitioning. The end result in production right now? over 1700 users, over 2000 ships in a solar system at one time … total bandwidth used per player 10Kbps … EVERYTHING is server controlled and properly zoned for free with his library. I also have over 100,000 missiles flying around at the same time as well. I basically created an etherial stack for each unique set of entities … planets/astroids, ships, weapons fire … all running in parallel against a single node tree on the server. It is amazing to watch 1700 players flying in space with full physics and the server idling at 5% CPU usage lol
Your results are amazing. Have already started researching Ethereal! By the way, your post sounds even more inspiring. Thanks for your words.
I had written my own network layer originally but then I spent a week with etherial and realized that I can use the built in zone manager for everything else in the game as well. For example, missiles are REALLY small in size so weapons run under a separate instance of etherial on a different port with a VERY SMALL zone size. Ships are much larger so they run in a larger zone size and planets and asteroids run on an even larger one. It not only helps with bandwidth but also helped with different physics partitioning. As @pspeed stated there is a bug in the message splitting code but I have posted the workaround in my original thread that he posted above.
I plan (and life has a way of making me eat that word these days) to spend some time on SimEthereal next weekend (13th/14th). We’ll see what I accomplish as I’ll have to make a test case that requires splitting before I can really make any progress on that bug.