-
Notifications
You must be signed in to change notification settings - Fork 7
Breaking Down Player Objects
Brian Erikson edited this page Jul 22, 2014
·
5 revisions
ws.send(message('playerObject', "{'cmd': 'pObjCreate', 'objectId': 'None', 'type': TYPE_AS_STRING, 'model': MODEL_AS_STRING, 'data': EPHEMERIS_AS_STRING +'}'));
- Ensure that the ephemeris that you send to the server DOES NOT have a
full_name
orname
assigned to it; the server will do so. - ensure the model in
MODEL_AS_STRING
is also located injs/objectDB.js
with associated paths and Blender.dae
files added to the/models
folder. - Sample ephemeris:
ephemeris = { ma: -2.47311027, epoch: 2451545.0, a:1.00000261, e: 0.01671123, i: 0.00001531, w_bar: 102.93768193, w: 102.93768193, L: 100.46457166, om: 0, P: 365.256 }
ws.send(message('playerObject',"{'data': {'cmd': 'destroy', 'uuid': '" + OBJECT_ID + "'}}"));
- The server WILL NOT remove an object that the player is not an owner of.
- Ensure that the OBJECT_ID is the ID you want to remove, because after you send this, it is out of your hands.
- Data format of request is
{cmd: 'playerObject', data: {cmd: 'pObjCreate', objectId: 'None', type: MODEL_TYPE_AS_STR, model: MODEL_AS_STR, data: EPHEMERIS}
- The EPHEMERIS consists of the following object:
{ma: 0, epoch: 0, a: 0, e: 0, i: 0, w_bar: 0, w: 0, L: 0, om: 0, P: 0}
- NOTE: Server will assign an ephemeris name according to
type
,model
, and logged inuser
- The first step in the parsing process is at the
parse function
, which hands off the parsing of the message to theplayerObjectResponder function
, located in the same module. - The
playerObjectResponder
figures out which game instance the player is a part of, parses the data, and checks to see what action it needs to take.
- Available actions right now are:
'create'
,'query'
, and'destroy'
, with query currently being unimplemented.
- The action we are concerned with right now is
'create'
. The create command carries a heavier payload than the other two, as it needs to parse an entire object, and the other two commands only need to carry aUUID
as data. - The
create
command parses and passes the type of the object, model, orbit, and the user's name to theaddPlayerObject function
.
- This function parses the requested object itself, and adds the full_name of the orbit.
- The parsing substitutes
whitespace
as an underline,_
, and apostrophes'
(to show possession), as a double-dash--
, and finally adds a unique identifier so multiples of the same object don't conflict. - example:
"TestUser--s_Magellan_Probe_5"
- The function then appends this new object to the playerObjects list for the game instance, and returns the object to the webSocketParser for submission. The websocket then sends the content contained in the following message:
{cmd: pObjCreate, data: OBJECT}
- the message from the server is received here, via the
'pObjCreate'
command, parses the object, and then gets the model path fromjs/objectDB.js
. this path is handed off toaddBlenderPlayerObjectMesh
atjs/main.js
.
- This function parses the
.DAE
blender file into something THREE.js can use and incorporate into therSimulate.scene
via aTHREE.ColladaLoader()
.
- The
ColladaLoader
takes a fraction of a second to parse, so we use a callback here to push the mesh to theaddPlayerObject function
and theplayerObjects
list once it's parsed. - You can also use this callback to scale, rotate, and introduce animations before loading to the scene.
- The
addPlayerObject function
adds the body to the scene viaaddBody function
with the'playerObject' indexLabel
, then parses the orbit name to show up as a clean button label, and finally adds a button listener with a callback to theorientToObject function
, which simply moves the camera to the object that was clicked.
- This action is initiated through the
Remove this object
button listener (which callsremovePlayerBody function
), which is added to the HTML doc through theinitUI function
. - The
removePlayerBody function
checks to see which body is selected, and then sends a message to the server:{cmd: 'playerObject', data: {cmd: 'destroy', uuid: OBJECT_UUID}
- Message is passed to the
playerObjectResponder function
via theplayerObject
command. - The
playerObjectResponder function
parses the message, passes it to the'destroy'
command, gets the UUID of the object and passes this information to theremovePlayerObject function
, which is located in theGame.py
module.
- The
removePlayerObject function
checks to see if the object exists in theplayerObject
list and if the requesting player owns the object, then removes it from the object and returnsTrue
. If the player doesn't own the object or the object doesn't match up with any existingUUIDs
, the function returnsFalse
. - The
webSocketParser.py
then passes this info onto the client an object:{cmd: 'playerObject', data: {cmd: 'pObjDestroyRequest', 'result': str(result), 'objectId': uuid, 'reason': str(result)}
- The reason is currently statically configured as
'unknown'
. This will later change to be more verbose. The server log is more verbose than the client's currently.
- The
wsMessageParser.js
module calls for removal of the body through theremoveBody function
, located inmain.js
. If the request to the server was denied, the error will log in the browser console. - The
removeBody function
removes the object from the following: mesh and ellipse from the scene, the orbits array, meshes array, ellipses array, indexes array, and the playerObjects array, then removes the button from the UI, and deselects the object if it is still selected.