Skip to content

Commit

Permalink
KSP 1.8 update. No changes to Laserdist except API use.
Browse files Browse the repository at this point in the history
KSP 1.8 deprecated some API calls, replacing them with alternate
versions.  The shader used to draw the laser lines needed to be
construced with a new kind of constructor.
  • Loading branch information
Dunbaratu committed Dec 31, 2019
1 parent 2fcce2d commit b48b6e7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 17 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changes per version for LaserDist (in reverse order)
======================================================

v1.3.0 Just version updates
---------------------------

Between v0.9.2 and now, all changes have merely been for KSP version
updates that altered parts of the API and required LaserDist to adjust
to the new API alls.

v0.9.2 Just Small Visual Bug Fixes
-----------------------------------

Expand Down
27 changes: 18 additions & 9 deletions src/LaserDist/LaserDist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,17 @@ private void startDrawing()
isOnMap = MapView.MapIsEnabled;
ChooseLayerBasedOnScene();

Shader vecShader = Shader.Find("Particles/Alpha Blended"); // for when KSP version is < 1.8
if (vecShader == null)
vecShader = Shader.Find("Legacy Shaders/Particles/Alpha Blended"); // for when KSP version is >= 1.8

line = lineObj.AddComponent<LineRenderer>();

line.material = new Material(Shader.Find("Particles/Additive") );
line.material = new Material(vecShader);
Color c1 = laserColor;
Color c2 = laserColor;
line.SetColors( c1, c2 );
line.startColor = c1;
line.endColor = c2;
line.enabled = true;

laserAnimationRandomizer = new System.Random();
Expand Down Expand Up @@ -577,8 +582,8 @@ private void drainPower()
{
if( Activated )
{
float drainThisUpdate = (float) (ElectricPerSecond * deltaTime);
float actuallyUsed = part.RequestResource( "ElectricCharge", drainThisUpdate );
double drainThisUpdate = ElectricPerSecond * deltaTime;
double actuallyUsed = part.RequestResource( "ElectricCharge", (double)drainThisUpdate );
if( actuallyUsed < drainThisUpdate/2.0 )
{
hasPower = false;
Expand Down Expand Up @@ -671,9 +676,11 @@ public void PhysicsRaycaster()
debugline.material = new Material(Shader.Find("Particles/Additive") );
Color c1 = new Color(1.0f,0.0f,1.0f);
Color c2 = c1;
debugline.SetColors( c1, c2 );
debugline.startColor = c1;
debugline.endColor = c2;
debugline.enabled = true;
debugline.SetWidth(0.01f,0.01f);
debugline.startWidth = 0.01f;
debugline.endWidth = 0.01f;
debugline.SetPosition( 0, origin );
debugline.SetPosition( 1, origin + pointing*thisLateUpdateBestHit.distance );
}
Expand Down Expand Up @@ -840,7 +847,7 @@ private void drawUpdate()

float width = 0.02f;

line.SetVertexCount(2);
line.positionCount = 2;
line.SetPosition( 0, useOrigin );
line.SetPosition( 1, useOrigin + usePointing*( (Distance>0)?Distance:MaxDistance ) );

Expand All @@ -849,9 +856,11 @@ private void drawUpdate()
Color c2 = laserColor;
c1.a = laserOpacityAverage + laserOpacityVariance * (laserAnimationRandomizer.Next(0,100) / 100f);
c2.a = laserOpacityFadeMin;
line.SetColors(c1,c2);
line.startColor = c1;
line.endColor = c2;
float tempWidth = width * laserWidthTimeFunction(thicknessWatch.ElapsedMilliseconds, laserAnimationRandomizer.Next(0,100));
line.SetWidth( tempWidth, tempWidth );
line.startWidth = tempWidth;
line.endWidth = tempWidth;
}
}

Expand Down
35 changes: 31 additions & 4 deletions src/LaserDist/LaserDist.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<OutputType>Library</OutputType>
<RootNamespace>LaserDist</RootNamespace>
<AssemblyName>LaserDist</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<NoWin32Manifest>False</NoWin32Manifest>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
Expand All @@ -30,6 +31,12 @@
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\References\Assembly-CSharp.dll</HintPath>
Expand All @@ -48,6 +55,27 @@
<Reference Include="UnityEngine">
<HintPath>..\References\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule">
<HintPath>..\..\..\KOS-1\Resources\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AudioModule">
<HintPath>..\..\..\KOS-1\Resources\UnityEngine.AudioModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\KOS-1\Resources\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>..\..\..\KOS-1\Resources\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\..\..\KOS-1\Resources\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\..\..\KOS-1\Resources\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>..\..\..\KOS-1\Resources\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\References\UnityEngine.UI.dll</HintPath>
</Reference>
Expand All @@ -58,8 +86,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties" />
<Folder Include="obj" />
<Folder Include="obj\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
8 changes: 4 additions & 4 deletions src/LaserDist/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LaserDist")]
[assembly: AssemblyCopyright("Copyright ©2016,©2017,@2018 Steven Mading")]
[assembly: AssemblyCopyright("Copyright ©2016,©2017,@2018,@2019 Steven Mading")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyFileVersion("1.2.0")]
[assembly: AssemblyVersion("1.2.0")]
[assembly: KSPAssembly("LaserDist", 1, 2)]
[assembly: AssemblyFileVersion("1.3.0")]
[assembly: AssemblyVersion("1.3.0")]
[assembly: KSPAssembly("LaserDist", 1, 3)]

0 comments on commit b48b6e7

Please sign in to comment.