Jump to content

[WIP][1.7.3] Kift - Thrift plugin for KSP (v0.1.0-alpha.2, 2019-08-10)


Xavier513

Recommended Posts

JvLtUjC.png

What is Kift?

Kift is an add-on based on Thrift(v0.12.0) .

Kift is a bridge between your code and the game, it lets you control the game with your program running outside of the game.

Kift is inpired by kRPC -- a great Mod from @djungelorm -- but implemented in a different way.

 

Release Thread: https://forum.kerbalspaceprogram.com/index.php?/topic/187109-173-kift-thrift-plugin-for-ksp-v010-alpha2/

GitHub: https://github.com/vaporz/Kift 

Releases: https://github.com/vaporz/Kift/releases

Doc portal: https://vaporz.github.io/Kift/index.html

Licensed by LGPL-3.0 .

 

Architecture 
Py71Z3b.png

Kift starts a Thrift server inside of KSP process. The server receives requests, then send them to a Message Queue. A KSP addon will dequeue requests from the queue, and run the corresponding Executor. The server will wait until the response to a request is returned.

Supported languages
Theoritically, any programming language supported by Thrift v0.12.0 is supported by Kift.

Languages supported by Thrift v0.12.0:

C, C++, Go, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi, etc.

Getting Started
1, Install Kift
Download Kift.zip, copy the "Kift" folder in zip file into "Kerbal Space Programe/GameData" directory.

Now the server side is ready. When your game is loaded and the main menu shows up, the Thift server is started and listening for requests.


2, Connect to Thrift server, and call Kift APIs
To interact with the Thrift server within KSP process, you have to write your own client side codes.

Following lines of code show how to call a Kift API to get current vessel's info, in C#:
 

// The game is started, and MUST be in Flight scene.
 
 // Import "Kift.ThriftGen.dll"(built from "Kift/thrift-gen/gen-csharp"),
 // or generate stub codes by yourself, then build and import your DLL file.
 using Kift;

 // Import "Thrift.dll": https://cwiki.apache.org/confluence/display/thrift/ThriftUsageCSharp
 using Thrift.Protocol;
 using Thrift.Transport;

 ...

 // The port is configable in "Kerbal Space Program/GameData/Kift/server.cfg"
 TTransport transport = new TFramedTransport(new TSocket("localhost", 9090));
 TProtocol protocol = new TCompactProtocol(transport);
 KiftService.Client client = new KiftService.Client(protocol);
 transport.Open(); // Connect to server

 Vessel v = client.currentVessel(); // Call API "currentVessel"
 Console.WriteLine(v.Name);

 ...

 transport.Close(); // finally close the connection

Kift APIs
Kift provides two sets of APIs: "InfoSync APIs" and "Command APIs". 

"InfoSync APIs" pull infos from the game. "Command APIs" send commands to control vessels/parts/game.

Command APIs are devided into three categories according to the target.

  • InfoSync APIs
    • Real time snapshot  
      Read data at real time(approximately), useful when you want to monitor any data, such as height, speed, etc.
    • GetInfo APIs
      Get data from current game, such as current vessel, the part list of a vessel, etc.
  • Command APIs
    • Vessel Control APIs
      APIs to control a vessel, such as pitch/yaw/roll, enable/disable RCS, deploy/restract landing legs, etc.
    • Part Control APIs
      APIs to control a part, such as deploy/restract a solar panel, open/close a cargo bay, etc.
    • Game Control APIs
      APIs to control the game, such as time warp, change camera mode, set/remove maneuver nodes etc.

See more about Kift APIs at the doc portal: https://vaporz.github.io/Kift/api/index.html

Kift needs your help

1. Please pay more attention to APIs about position/direction/rotation and reference frames, I spent a lot of time investigaing and learning about them, but I still can not be sure about the correctness.
2. Please report an issue if you find a bug: https://github.com/vaporz/Kift/issues
3. Kift's codes are relatively simple, you're very appreciated to submit a PR and contribute to Kift.
4. English is not my native language, please help me to improve the wording of documentation, or add new articles to "Kift/server/articles". Docs are generated from the "md" files under "Kift/server" using Docfx.
5. I'm quite new to C# programming, in fact, this is my first C# program, so please create an issue if you have any suggestion against the code, for example, coding style, best practices, etc.
6. Star "Kift" on GitHub if you like it :)

Edited by Xavier513
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...