Skip to content

Commit

Permalink
Remove ".ks" extension from source filenames and add "compile_to" fun…
Browse files Browse the repository at this point in the history
…ction

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).
  • Loading branch information
maneatingape committed Jul 31, 2020
1 parent fa0c19a commit 190fd55
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 13 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
68 changes: 56 additions & 12 deletions src/main.ks
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down Expand Up @@ -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.
}

0 comments on commit 190fd55

Please sign in to comment.