The 3D World Demo shows how well the real-time positions of objects in a multiplayer 3D world can be delivered over WebSockets and HTTP via Lightstreamer Server. Particular attention is paid to aspects of real-time communication and opportunities to minimize the network bandwidth utilization.
This project shows the Data Adapter and Metadata Adapters for the 3D World Demo and how they can be plugged into Lightstreamer Server.
As example of a client using this adapter, you may refer to the 3D World Demo - HTML (Three.js) Client and view the corresponding Live Demo
To fully understand this demo, please read the article: Optimizing Multiplayer 3D Game Synchronization Over the Web
There are two ways the demo can work.
- First way: the physics engine runs on the client side, which periodically synchronizes with the authoritative server.
- Second way: the physics engine runs on the server side only and the positional and rotational data for all the players in a world are transmitted to all the clients. In other words, the clients are pure renderers.
This project includes the implementation of both the SmartDataProvider interface and the MetadataProviderAdapter interface to inject data into Lightstreamer server with real time information about the movement of every object in the world. Both translations and rotations in 3D space are calculated by the adapter and transmitted to the clients in a 7-value array: position for axis X, position for axis Y, position for axis Z, and a quaternion object for rotation information: x, y, z, Quat(X, Y, Z, W). Precision and format of data in output are configurable by each user among these choices:
- binary Base64 encoded float numbers in single precision;
- binary Base64 encoded float numbers in double precision;
- string with fixed decimal places (ranging from 1 to 15).
The adapter receives input commands from Lightstreamer server, which forwards messages arrived from clients to the adapter in relation to:
- changing nick name for the player;
- changing last message for the player;
- changing world scenario for the player;
- movement commands.
If you want to install a version of this demo in your local Lightstreamer server, follow these steps.
- Download Lightstreamer Server Vivace (make sure you use Vivace edition, otherwise you will see a limit on the event rate; Lightstreamer Server comes with a free non-expiring demo license for 20 connected users) from Lightstreamer Download page, and install it, as explained in the
GETTING_STARTED.TXTfile in the installation home directory. - Get the
deploy.zipfile of the latest release and unzip it. - Copy the just unzipped
3DWorldDemofolder into theadaptersfolder of your Lightstreamer Server installation. - Download croftsoft library and compile a
croftsoft-math.jarversion. Please make sure to include: applet, io, inlp, lang and math packages. - Copy the just compiled
croftsoft-math.jarfile in the3DWorldDemo/libfolder. - [Optional] Supply a specific "LS_3DWorldDemo_Logger" and "LS_demos_Logger" category in logback configuration
Lightstreamer/conf/lightstreamer_log_conf.xml. - Launch Lightstreamer Server.
- Launch a client like the 3D World Demo - HTML (Three.js) Client
To build your own version of LS_3DWorldDemo_Adapters.jar, instead of using the one provided in the deploy.zip file from the Install section above, follow these steps:
- Clone this project.
- Get the
ls-adapter-interface.jar,ls-generic-adapters.jar, andlog4j-1.2.15.jarfiles from the Lightstreamer distribution and copy them into thelibfolder. - Download croftsoft library and compile a
croftsoft-math.jarversion. Please make sure to include: applet, io, inlp, lang and math packages. - Put the just compiled
croftsoft-math.jarfile in thelibfolder. - Build the java source files in the
srcfolder into aLS_3DWorldDemo_Adapters.jarfile. Here is an example for that:
>javac -source 1.7 -target 1.7 -nowarn -g -classpath lib/croftsoft-math.jar;lib/ls-adapter-interface.jar;lib/ls-generic-adapters.jar;lib/log4j-1.2.15.jar -sourcepath src -d tmp_classes src/com/lightstreamer/adapters/DemoQuat3d/Move3dAdapter.java
>jar cvf LS_3DWorldDemo_Adapters.jar -C tmp_classes com- Copy the just compiled
LS_3DWorldDemo_Adapters.jarin theadapters/3DWorldDemo/libfolder of your Lightstreamer Server installation.
- Compatible with Lightstreamer SDK for Java Adapters since 5.1