From 190fd55f2da0f6bea46d73e02ab62d2f9d4d138c Mon Sep 17 00:00:00 2001 From: maneatingape <44142177+maneatingape@users.noreply.github.com> Date: Thu, 30 Jul 2020 11:39:00 +0100 Subject: [PATCH] Remove ".ks" extension from source filenames and add "compile_to" function Allow users to use the more compact compiled version of the source on craft that have limited volume space. By removing the extension kOS will first look for files with a ".ksm" extension, then for files with a ".ks" extension. Compiled files take about 20% of the space of the raw source, resulting in a significant space savings. Refactor the "import" method to use a list to support a "compileto" function that takes the same list of source files. This new convenience function compiles the source to a user-specified destination (e.g. a kOS processor hard drive). --- CHANGELOG.md | 10 ++++++++ README.md | 8 ++++++- src/main.ks | 68 ++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 942f11f..454d456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,17 @@ # Changelog +### v4 + +Support `.ksm` compiled files. + +### New Features +* Add ability to use more compact compiled version of the source on craft that have limited volume space. Compiled files take about 20% of the space of the raw source, resulting in a significant space savings. +* Add `compile_to` convenience function that compiles the source to a user-specified destination, for example a kOS processor hard drive. + ## v3 +Improve handling of objects on hyperbolic orbits. + ### Technical Improvements * Use different strategy when calculating default `search_duration`, `max_time_of_flight` and `search_interval` values for a destination with a hyperbolic orbit, for example an asteroid or comet. This change prevents a `Tried to push Infinity onto the stack` error that occurred because the approach used for planets assumes an elliptical orbit with a finite orbital period. diff --git a/README.md b/README.md index 624c4cf..8f03f7a 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ This short video shows these features in action: 3. Launch a craft into a stable orbit of Kerbin. 3. Run this script from the craft: ``` - runoncepath("0:/rsvp/main.ks"). + runoncepath("0:/rsvp/main"). // Default value is 250. Overclocking CPU speed to maximum is recommended // as finding transfers is computationally intensive. @@ -175,6 +175,12 @@ RSVP is designed with some quality of life features to make it as straightforwar [1] = "Option 'verbose' is 'qux', expected boolean" [303] = "Option 'foo_bar' not recognised" ``` +* To save space on the limited hard disks of kOS processors you can compile the source to `.ksm` files that are about 20% of the size of the raw source. A convenience `rsvp:compile_to` function exists for this purpose. For example, the following code will compile the source from the archive then copy the compiled files to the hard disk of the current processor. + ``` + runoncepath("0:/rsvp/main"). + createdir("1:/rsvp"). + rsvp:compile_to("1:/rsvp"). + ``` ## Technical Details diff --git a/src/main.ks b/src/main.ks index cd00db6..836c0fa 100644 --- a/src/main.ks +++ b/src/main.ks @@ -4,16 +4,23 @@ // in order to make them available to other scripts while preventing pollution // of the global namespace. global rsvp is lex(). -export("goto", goto@). -// Add functions from all other scripts into lexicon. -import("hill_climb.ks"). -import("lambert.ks"). -import("maneuver.ks"). -import("orbit.ks"). -import("search.ks"). -import("transfer.ks"). -import("validate.ks"). +// List of all source files. Omit extenstion so that users can use +// compiled version if desired. +local source_files is list( + "hill_climb", + "lambert", + "main", + "maneuver", + "orbit", + "search", + "transfer", + "validate" +). + +export("goto", goto@). +export("compile_to", compile_to@). +import(). local function goto { parameter destination, options is lex(). @@ -54,15 +61,52 @@ local function goto { return result. } +// Add delegate to the global "rsvp" lexicon. local function export { parameter key, value. rsvp:add(key, value). } +// Add functions from all other scripts into lexicon. User can use compiled +// versions of the source, trading off less storage space vs harder to debug +// error messages. local function import { - parameter filename. + local source_root is scriptpath():parent. + + for filename in source_files { + local source_path is source_root:combine(filename). + + runoncepath(source_path, export@). + } +} + +// Compiles source files and copies them to a new location. This is useful to +// save space on processor hard disks that have limited capacity. +// The trade-off is that error messages are less descriptive. +local function compile_to { + parameter destination. + + local source_root is scriptpath():parent. + local destination_root is path(destination). + + // Check that path exists and is a directory. + if not exists(destination_root) { + print destination_root + " does not exist". + return. + } + if open(destination_root):isfile { + print destination_root + " is a file. Should be a directory". + return. + } + + for filename in source_files { + local source_path is source_root:combine(filename + ".ks"). + local destination_path is destination_root:combine(filename + ".ksm"). + + print "Compiling " + source_path. + compile source_path to destination_path. + } - local full_path is scriptpath():parent:combine(filename). - runoncepath(full_path, export@). + print "Succesfully compiled " + source_files:length + " files to " + destination_root. } \ No newline at end of file