Editing KeyComm

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 4: Line 4:
  
 
We needed a way for a ship (or the Targetting MFD we made) to communicate with turret to tell it to pick up a target, start firing, stop firing, etc. The initial plan was to obtain the vessel pointer, cast it to a Turret, and call a method specifically. However, this has several undesired properties, such as requiring the calling MFD or ship code to include the turret header, etc, and thus isn't very extensible. Additionally, if we attached something other than a Turret (say for a fighter-type craft, where you have a missile directly attached to the ship), the object wouldn't cast nicely to a Turret.
 
We needed a way for a ship (or the Targetting MFD we made) to communicate with turret to tell it to pick up a target, start firing, stop firing, etc. The initial plan was to obtain the vessel pointer, cast it to a Turret, and call a method specifically. However, this has several undesired properties, such as requiring the calling MFD or ship code to include the turret header, etc, and thus isn't very extensible. Additionally, if we attached something other than a Turret (say for a fighter-type craft, where you have a missile directly attached to the ship), the object wouldn't cast nicely to a Turret.
Thus, we needed a function that's part of the normal [[VESSEL]] or [[VESSEL2]] class that we can overload to serve as our messaging function. clbkConsumeBufferedKey works very well for this purpose--it takes as parameters a DWORD, a boolean, and a char*, and returns an int. Normally, the DWORD parameter will not be greater than about 0xDF (the highest OAPI_KEY_xxx constant), and since there's 32 bits in a DWORD, that gives us only about 4.3 billion possible messages we can send to this function that won't be misinterpreted as keyboard input. More concretely:
+
Thus, we needed a function that's part of the normal VESSEL or VESSEL2 class that we can overload to serve as our messaging function. clbkConsumeBufferedKey works very well for this purpose--it takes as parameters a DWORD, a boolean, and a char*, and returns an int. Normally, the DWORD parameter will not be greater than about 0xDF (the highest OAPI_KEY_xxx constant), and since there's 32 bits in a DWORD, that gives us only about 4.3 billion possible messages we can send to this function that won't be misinterpreted as keyboard input. More concretely:
 
The MFD and the turret both define a constant COMM_SET_TARGET to be some number greater than 0xFF. The MFD asks the user to input the name of the ship to target, obtains the turret's VESSEL pointer, casts it to a VESSEL2*, then calls
 
The MFD and the turret both define a constant COMM_SET_TARGET to be some number greater than 0xFF. The MFD asks the user to input the name of the ship to target, obtains the turret's VESSEL pointer, casts it to a VESSEL2*, then calls
  
Line 92: Line 92:
  
 
Note that there is still no prefix handled here, but this demonstrates how the "payload" can be used to return a value other than an int to the sending ship.
 
Note that there is still no prefix handled here, but this demonstrates how the "payload" can be used to return a value other than an int to the sending ship.
 
[[Category: Articles]]
 
[[Category: Tutorials]]
 

Please note that all contributions to OrbiterWiki are considered to be released under the GNU Free Documentation License 1.2 (see OrbiterWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)