iv4xr-project / iv4xr-se-plugin

Integration of Space Engineers to the iv4XR framework.
GNU Lesser General Public License v3.0
6 stars 4 forks source link

Controlling multiple vehicles at once #174

Open gallorob opened 2 years ago

gallorob commented 2 years ago

To my understanding, the current API's Input replay functionalities emulate a virtual keyboard+mouse, essentially simulating a single user. Is it possible to issue commands in parallel, as in a multiplayer game? It would be helpful to control multiple vehicles at once instead of one after the other. @hovi is this feature implementable? Something like having multiple inputs applied to multiple (virtual) players?

Alternatively, do you know if it's possible to have multiple instances of Space Engineers open? If so, how does the API behave? Can it correctly deliver the JSON-RPC requests to the correct game instance?

hovi commented 2 years ago

It is possible to create multiple characters and control them to some extent (check out Admin.Character API), but the implementation is hard and buggy. Also the vehicle movement there doesn't work.

However what we are doing and works well is actually having multiple instances of game each running plugin and then communicating to all of them at once since each plugin has separate IP and port (sometimes we run 2 plugins at single computer - one for game and one for dedicated server). That is our current focus. There is all necessary API to load multiplayer game, connect to it, etc. if you have multiple computers to use.

gallorob commented 2 years ago

I'm not sure I follow: do I need to have more than one computer to have multiple instances of the game running?

hovi commented 2 years ago

Yes, unless there's some way to run multiple games on a single computer (maybe using virtualization and running another instance inside VM). We haven't really looked into that and just used multiple computers to make things easier for us (we also need fast performance for our tests). If you do that, make sure you change the port in the plugin config to different port so that you can communicate with both plugins. Also you probably want to change hostname from "127.0.0.1" to "0.0.0.0" to allow connections from network, rather than just localhost.

gallorob commented 2 years ago

I see. How difficult would it be instead to add multiple character control (especially input emulation) in a single game instance? Perhaps adding a reference to which character the inputs should refer to?

hovi commented 2 years ago

You can create new character using admin.character.create API. Then you can switch between characters using admin.character.switch. To show all characters use admin.observer.observeCharacters.

Once you switch to a character, all character.x API commants are related to the selected character. It has a lot of downsides and we are considering removing (or at least the current implementation):

There is similar functionality built into the game for singleplayer only, which we may use later and connect it with this API, but that is definitely not the priority at the moment. Now we are heavily focused on adding new functionality related to controlling the character, blocks and multiplayer gameplay.