-
Notifications
You must be signed in to change notification settings - Fork 11
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_nameornameassigned to it; the server will do so. - ensure the model in
MODEL_AS_STRINGis also located injs/objectDB.jswith associated paths and Blender.daefiles added to the/modelsfolder. - 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
playerObjectResponderfigures 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 aUUIDas data. - The
createcommand 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
whitespaceas 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 toaddBlenderPlayerObjectMeshatjs/main.js.
- This function parses the
.DAEblender file into something THREE.js can use and incorporate into therSimulate.scenevia aTHREE.ColladaLoader().
- The
ColladaLoadertakes a fraction of a second to parse, so we use a callback here to push the mesh to theaddPlayerObject functionand theplayerObjectslist once it's parsed. - You can also use this callback to scale, rotate, and introduce animations before loading to the scene.
- The
addPlayerObject functionadds the body to the scene viaaddBody functionwith 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 objectbutton listener (which callsremovePlayerBody function), which is added to the HTML doc through theinitUI function. - The
removePlayerBody functionchecks 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 functionvia theplayerObjectcommand. - The
playerObjectResponder functionparses 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.pymodule.
- The
removePlayerObject functionchecks to see if the object exists in theplayerObjectlist 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.pythen 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.jsmodule 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 functionremoves 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.