Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Warren Seymour committed Jun 16, 2014
2 parents ee79d9e + da9adb1 commit 25ad7a5
Show file tree
Hide file tree
Showing 30 changed files with 453 additions and 310 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,9 @@ $RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

# Ignore dependencies and builds
src/RemoteTech2/*.dll
*.zip
GameData/RemoteTech2/Plugins/RemoteTech2.dll
GameData/build.txt
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: objective-c # force osx machines

os:
- osx

env:
global:
- secure: Q4UfP54tnvoioOnoQElnkUQMd4qQ/2dLLkhnSz35MiwUrraxqrixdh22EWsTmcqD8ntjPI4tt3P9N6On9+qn8D+qYpt+zX5otikfgvXdKCxGJj+q1Nv0rWq6b0P5QGo61vXFV1cH4EOONBDyAq0IbmtjtEISBhQaefFdzaAAk/Y=
- secure: J/M1/WIRgP4GssMr9HS9k7Wr9XUqlo0S+olIVWvr8eY8jxxVbx+ONZbkkjKey2BvC1BRVtRXpbBe+YcPLYe7V1jG5mmm3Lc1B/x5WC54q4KKfoV53m+ARAtaHFYrJY2h4O+GLaysQoCwCG/tAt0GhJmgJgy9IojH4ojJjDOGHCE=
before_install:
- date -u
- uname -a
- export BUILDTAG=`git describe --abbrev=0 --tags`
- env | sort | grep -v ZIPPASSWORD | grep -v GITHUB_TOKEN

install:
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then echo "Should only be on OSX"; exit 1; fi
- ./CI/travis.osx.install.deps.sh # it appears TRAVIS_OS_NAME is unset often, assume we're OSX if not linux

script:
- ./build.remotetech2.sh

# Custom deploy
after_success:
- ./CI/github.build.deploy.sh
80 changes: 80 additions & 0 deletions CI/github.build.deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# These should be set by Travis
#TRAVIS_BUILD_NUMBER=1
#TRAVIS_BRANCH=master
#TRAVIS_REPO_SLUG="RemoteTechnologiesGroup/RemoteTech"
#TRAVIS_COMMIT=master
#GITHUB_TOKEN="Personal access token from https://github.com/settings/applications"
#TRAVIS_PULL_REQUEST=false

VERSION="build-${TRAVIS_BRANCH}-${TRAVIS_BUILD_NUMBER}"
FILENAME=$(echo "${VERSION}.zip" | tr '/' '_') # else it will fail on branches like chore/travis

python_parse_json() {
# python errors are surpressed for when the key doesn't exist
cat | python -c 'import sys,json;obj=json.load(sys.stdin);print obj[sys.argv[1]];' $1 2>/dev/null
}

if [ -z "$GITHUB_TOKEN" ] || [ -z "$TRAVIS_REPO_SLUG" ] \
|| [ -z "$TRAVIS_BUILD_NUMBER" ] || [ -z "$TRAVIS_BRANCH" ] \
|| [ -z "$TRAVIS_COMMIT" ]
then
echo "GITHUB_TOKEN, TRAVIS_REPO_SLUG, TRAVIS_BUILD_NUMBER and TRAVIS_COMMIT must be set in order to deploy";
echo "Skipping deploy for now";
exit 0; # prevent build failing if unset
fi

if [ "$TRAVIS_PULL_REQUEST" != "false" ]
then
echo "This is a pull request build, it doesn't need to be released."
exit 0; # prevent build fail
fi

if [[ "$TRAVIS_BRANCH" == build* ]]
then
echo "We're already on a 'build branch' (or tag), don't need to deploy again";
exit 0;
fi

echo "Build ${TRAVIS_BUILD_NUMBER} from branch ${TRAVIS_BRANCH} in ${TRAVIS_REPO_SLUG}" > GameData/build.txt
echo "Built from commit ${TRAVIS_COMMIT} with tag ${BUILDTAG}" >> GameData/build.txt
echo "Creating ${FILENAME}"
zip -r "${FILENAME}" GameData/

echo "Attempting to create tag ${VERSION} on ${TRAVIS_REPO_SLUG}"
API_JSON=$(printf '{"tag_name": "%s","target_commitish": "%s","name": "%s","body": "Automated pre-release of branch %s build %s","draft": false,"prerelease": true}' \
$VERSION $TRAVIS_COMMIT $VERSION $TRAVIS_BRANCH $TRAVIS_BUILD_NUMBER)
ADDRESS=$(printf 'https://api.github.com/repos/%s/releases?access_token=%s' $TRAVIS_REPO_SLUG $GITHUB_TOKEN)

REPLY=$(curl --data "$API_JSON" "$ADDRESS");
UPLOAD_ID=$(echo $REPLY | python_parse_json "id")
ERRORS=$(echo $REPLY | python_parse_json "errors");

if [ -n "$ERRORS" ] || [ -z "$REPLY" ] || [ -z "$UPLOAD_ID" ]
then
echo "ERROR: An error occured while setting the tag";
echo $REPLY;
exit 1;
fi

UPLOAD_URL="https://uploads.github.com/repos/${TRAVIS_REPO_SLUG}/releases/${UPLOAD_ID}/assets"

echo "Uploading ${FILENAME} to GitHub repo ${UPLOAD_ID} (tag ${VERSION} on ${TRAVIS_REPO_SLUG})"
REPLY=$(curl -H "Authorization: token ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.manifold-preview" \
-H "Content-Type: application/zip" \
--data-binary @${FILENAME} \
"${UPLOAD_URL}?name=${FILENAME}")

ERRORS=$(echo $REPLY | python_parse_json "errors")
ASSET_ID=$(echo $REPLY | python_parse_json "id" )

if [ -n "$ERRORS" ] || [ -z "$REPLY" ] || [ -z "$ASSET_ID" ]
then
echo "ERROR: An error occured while uploading the file to GitHub";
echo $REPLY;
exit 1;
fi

echo "Uploaded ${FILENAME} to ${TRAVIS_REPO_SLUG} as asset id ${ASSET_ID}"
8 changes: 8 additions & 0 deletions CI/travis.osx.install.deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -ev

MONO_VERSION="3.4.0"

echo "Installing Mono ${MONO_VERSION}"
wget "http://download.mono-project.com/archive/${MONO_VERSION}/macos-10-x86/MonoFramework-MDK-${MONO_VERSION}.macos10.xamarin.x86.pkg"
sudo installer -pkg "MonoFramework-MDK-${MONO_VERSION}.macos10.xamarin.x86.pkg" -target /
Binary file added GameData/ModuleManager.2.1.5.dll
Binary file not shown.
Binary file removed GameData/ModuleManager_1_5.dll
Binary file not shown.
16 changes: 16 additions & 0 deletions GameData/RemoteTech2/RemoteTech.version
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"NAME": "RemoteTech",
"URL": "https://raw.githubusercontent.com/RemoteTechnologiesGroup/RemoteTech/master/GameData/RemoteTech2/RemoteTech.version",
"DOWNLOAD": "https://github.com/RemoteTechnologiesGroup/RemoteTech/releases/latest",
"_comment": "Use old-style format to keep compatibility with KSP-AVC Utility 0.3.",
"VERSION": {
"MAJOR": 1,
"MINOR": 3,
"PATCH": 3
},
"KSP_VERSION": {
"MAJOR": 0,
"MINOR": 23,
"PATCH": 5
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GameData/RemoteTech2/Textures/texFlightGreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GameData/RemoteTech2/Textures/texFlightGreenDown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GameData/RemoteTech2/Textures/texFlightGreenOver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GameData/RemoteTech2/Textures/texFlightRed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GameData/RemoteTech2/Textures/texFlightYellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GameData/RemoteTech2/Textures/texFlightYellowDown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified GameData/RemoteTech2/Textures/texFlightYellowOver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.org/RemoteTechnologiesGroup/RemoteTech.svg?branch=master)](https://travis-ci.org/RemoteTechnologiesGroup/RemoteTech)

RemoteTech
==========

Expand Down
36 changes: 36 additions & 0 deletions build.remotetech2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

SRCDIR=src/RemoteTech2

if [ ! -f "$SRCDIR/Assembly-CSharp-firstpass.dll" ] \
|| [ ! -f "$SRCDIR/Assembly-CSharp.dll" ] \
|| [ ! -f "$SRCDIR/UnityEngine.dll" ];
then
if [ "$TRAVIS_SECURE_ENV_VARS" = "false" ]; then
# this should only happen for pull requests
echo "Unable to build as the env vars have not been set. Can't decrypt the zip."
exit 0; # can't decide if this should error
fi

if [[ ! -f dlls.zip ]]; then
echo "Need to get dependency .dll's"
wget -O dlls.zip "https://www.dropbox.com/s/kyv25p3qn166nzp/dlls.zip?dl=1"
fi

if [ -z "$ZIPPASSWORD" ]; then
if [ "$TRAVIS" = "true" ]; then
echo "Password not set, on travis and DLL's missing, can't build";
exit 1;
else
echo "Password required to decrypt the zip";
unzip dlls.zip -d src/RemoteTech2/ # this will prompt for a password
fi
else
unzip -P "$ZIPPASSWORD" dlls.zip -d src/RemoteTech2/
fi

rm -f dlls.zip
fi

cd src/RemoteTech2 && xbuild

37 changes: 24 additions & 13 deletions src/RemoteTech2/API/API.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RemoteTech;
using UnityEngine;

namespace RemoteTech
{
Expand All @@ -13,7 +10,9 @@ public static bool HasFlightComputer(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
if (satellite == null) return false;
return satellite.FlightComputer != null;
var hasFlightComputer = satellite.FlightComputer != null;
RTLog.Verbose("Flight: {0} HasFlightComputer: {1}", id, hasFlightComputer);
return hasFlightComputer;
}

public static void AddSanctionedPilot(Guid id, Action<FlightCtrlState> autopilot)
Expand All @@ -24,6 +23,7 @@ public static void AddSanctionedPilot(Guid id, Action<FlightCtrlState> autopilot
{
if (spu.FlightComputer == null) continue;
if (spu.FlightComputer.SanctionedPilots.Contains(autopilot)) continue;
RTLog.Verbose("Flight: {0} Adding Sanctioned Pilot", id);
spu.FlightComputer.SanctionedPilots.Add(autopilot);
}
}
Expand All @@ -35,48 +35,59 @@ public static void RemoveSanctionedPilot(Guid id, Action<FlightCtrlState> autopi
foreach (var spu in satellite.SignalProcessors)
{
if (spu.FlightComputer == null) continue;
RTLog.Verbose("Flight: {0} Removing Sanctioned Pilot", id);
spu.FlightComputer.SanctionedPilots.Remove(autopilot);
}
}

public static bool HasAnyConnection(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
return RTCore.Instance.Network[satellite].Any();
var hasConnection = RTCore.Instance.Network[satellite].Any();
RTLog.Verbose("Flight: {0} Has Connection: {1}", id, hasConnection);
return hasConnection;
}

public static bool HasConnectionToKSC(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
return RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid));
var connectedToKerbin = RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid));
RTLog.Verbose("Flight: {0} Has Connection to Kerbin: {1}", id, connectedToKerbin);
return connectedToKerbin;
}

public static double GetShortestSignalDelay(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
if (!RTCore.Instance.Network[satellite].Any()) return Double.PositiveInfinity;
return RTCore.Instance.Network[satellite].Min().Delay;
var shortestDelay = RTCore.Instance.Network[satellite].Min().Delay;
RTLog.Verbose("Flight: Shortest signal delay from {0} to {1}", id, shortestDelay);
return shortestDelay;
}

public static double GetSignalDelayToKSC(Guid id)
{
var satellite = RTCore.Instance.Satellites[id];
if (!RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid))) return Double.PositiveInfinity;
return RTCore.Instance.Network[satellite].Where(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid)).Min().Delay;
var signalDelaytoKerbin = RTCore.Instance.Network[satellite].Where(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid)).Min().Delay;
RTLog.Verbose("Connection from {0} to Kerbin Delay: {1}", id, signalDelaytoKerbin);
return signalDelaytoKerbin;
}

public static double GetSignalDelayToSatellite(Guid a, Guid b)
{
var sat_a = RTCore.Instance.Satellites[a];
var sat_b = RTCore.Instance.Satellites[b];
if (sat_a == null || sat_b == null) return Double.PositiveInfinity;
var satelliteA = RTCore.Instance.Satellites[a];
var satelliteB = RTCore.Instance.Satellites[b];
if (satelliteA == null || satelliteB == null) return Double.PositiveInfinity;

Func<ISatellite, IEnumerable<NetworkLink<ISatellite>>> neighbors = RTCore.Instance.Network.FindNeighbors;
Func<ISatellite, NetworkLink<ISatellite>, double> cost = RangeModelExtensions.DistanceTo;
Func<ISatellite, ISatellite, double> heuristic = RangeModelExtensions.DistanceTo;

var path = NetworkPathfinder.Solve(sat_a, sat_b, neighbors, cost, heuristic);
return path.Delay;
var path = NetworkPathfinder.Solve(satelliteA, satelliteB, neighbors, cost, heuristic);
var delayBetween = path.Delay;
RTLog.Verbose("Connection from {0} to {1} Delay: {2}", a, b, delayBetween);
return delayBetween;
}
}
}
52 changes: 43 additions & 9 deletions src/RemoteTech2/FlightComputer/Commands/ManeuverCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -12,15 +12,22 @@ public class ManeuverCommand : AbstractCommand
public double OriginalDelta { get; set; }
public double RemainingTime { get; set; }
public double RemainingDelta { get; set; }
public bool EngineActivated { get; set; }
public override int Priority { get { return 0; } }

public override string Description
{
get
{
if (RemainingTime > 0 || RemainingDelta > 0)
return "Executing maneuver: " + RemainingDelta.ToString("F2") + "m/s" + Environment.NewLine +
"Remaining duration: " + RTUtil.FormatDuration(RemainingTime) + Environment.NewLine + base.Description;
{
string flightInfo = "Executing maneuver: " + RemainingDelta.ToString("F2") +
"m/s" + Environment.NewLine + "Remaining duration: ";

flightInfo += EngineActivated ? RTUtil.FormatDuration(RemainingTime) : "-:-";

return flightInfo + Environment.NewLine + base.Description;
}
else
return "Execute planned maneuver" + Environment.NewLine + base.Description;
}
Expand All @@ -29,10 +36,22 @@ public override string Description
public override bool Pop(FlightComputer f)
{
var burn = f.ActiveCommands.FirstOrDefault(c => c is BurnCommand);
if (burn != null) f.Remove(burn);
if (burn != null) {
f.Remove (burn);
}

OriginalDelta = Node.DeltaV.magnitude;
RemainingDelta = Node.GetBurnVector(f.Vessel.orbit).magnitude;
RemainingTime = RemainingDelta / (FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass());
EngineActivated = true;

double thrustToMass = FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass();
if (thrustToMass == 0.0) {
EngineActivated = false;
RTUtil.ScreenMessage("[Flight Computer]: No engine to carry out the maneuver.");
} else {
RemainingTime = RemainingDelta / thrustToMass;
}

return true;
}

Expand All @@ -44,17 +63,32 @@ public override bool Execute(FlightComputer f, FlightCtrlState fcs)
var up = (f.SignalProcessor.Body.position - f.SignalProcessor.Position).normalized;
var orientation = Quaternion.LookRotation(forward, up);
FlightCore.HoldOrientation(fcs, f, orientation);

double thrustToMass = (FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass());
if (thrustToMass == 0.0) {
EngineActivated = false;
return false;
}

EngineActivated = true;
fcs.mainThrottle = 1.0f;
RemainingTime -= TimeWarp.deltaTime;
RemainingDelta -= (FlightCore.GetTotalThrust(f.Vessel) / f.Vessel.GetTotalMass()) * TimeWarp.deltaTime;
RemainingTime = RemainingDelta / thrustToMass;
RemainingDelta -= thrustToMass * TimeWarp.deltaTime;
return false;
}
f.Enqueue(AttitudeCommand.Off(), true, true, true);
return true;
}

public static ManeuverCommand WithNode(ManeuverNode node)
public static ManeuverCommand WithNode(ManeuverNode node, FlightComputer f)
{
double thrust = FlightCore.GetTotalThrust(f.Vessel);
double advance = f.Delay;

if (thrust > 0) {
advance += (node.DeltaV.magnitude / (thrust / f.Vessel.GetTotalMass())) / 2;
}

var newNode = new ManeuverCommand()
{
Node = new ManeuverNode()
Expand All @@ -67,7 +101,7 @@ public static ManeuverCommand WithNode(ManeuverNode node)
UT = node.UT,
nodeRotation = node.nodeRotation,
},
TimeStamp = node.UT,
TimeStamp = node.UT - advance,
};
return newNode;
}
Expand Down
3 changes: 2 additions & 1 deletion src/RemoteTech2/FlightComputer/EventCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public override String Description
{
get
{
return BaseEvent.listParent.part.partInfo.title + ": " + BaseEvent.GUIName;
return BaseEvent.listParent.part.partInfo.title + ": " +
BaseEvent.GUIName + Environment.NewLine + base.Description;
}
}

Expand Down
Loading

0 comments on commit 25ad7a5

Please sign in to comment.