mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
Set up core basic framework that calls the main code
This commit is contained in:
parent
cf8fb234b4
commit
33f3c44d6e
10 changed files with 191 additions and 87 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
"use strict";
|
||||||
|
|
15
Nibriboard/Env.cs
Normal file
15
Nibriboard/Env.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
using System;
|
||||||
|
namespace Nibriboard
|
||||||
|
{
|
||||||
|
public static class Env
|
||||||
|
{
|
||||||
|
public static readonly DateTime ServerStartTime = DateTime.Now;
|
||||||
|
|
||||||
|
public static double SecondsSinceStart {
|
||||||
|
get {
|
||||||
|
TimeSpan timeSinceStart = DateTime.Now - ServerStartTime;
|
||||||
|
return timeSinceStart.TotalSeconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,9 +3,10 @@ namespace Nibriboard
|
||||||
{
|
{
|
||||||
public static class Log
|
public static class Log
|
||||||
{
|
{
|
||||||
|
|
||||||
public static int WriteLine(string text, params object[] args)
|
public static int WriteLine(string text, params object[] args)
|
||||||
{
|
{
|
||||||
string outputText = $"[{DateTime.Now}] " + string.Format(text, args);
|
string outputText = $"[{Env.SecondsSinceStart}] " + string.Format(text, args);
|
||||||
Console.WriteLine(outputText);
|
Console.WriteLine(outputText);
|
||||||
return outputText.Length;
|
return outputText.Length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace Nibriboard
|
||||||
|
|
||||||
//Task.Run(async () => await onMessage(frame)).Wait();
|
//Task.Run(async () => await onMessage(frame)).Wait();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task onMessage(string frame)
|
private async Task onMessage(string frame)
|
||||||
|
|
|
@ -1,79 +1,81 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<PropertyGroup>
|
||||||
<PropertyGroup>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
<ProjectGuid>{B7F806D9-9C50-4BA8-A803-0FC2EC5F5932}</ProjectGuid>
|
||||||
<ProjectGuid>{B7F806D9-9C50-4BA8-A803-0FC2EC5F5932}</ProjectGuid>
|
<OutputType>Exe</OutputType>
|
||||||
<OutputType>Exe</OutputType>
|
<RootNamespace>Nibriboard</RootNamespace>
|
||||||
<RootNamespace>Nibriboard</RootNamespace>
|
<AssemblyName>Nibriboard</AssemblyName>
|
||||||
<AssemblyName>Nibriboard</AssemblyName>
|
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
</PropertyGroup>
|
||||||
</PropertyGroup>
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugType>full</DebugType>
|
||||||
<DebugType>full</DebugType>
|
<Optimize>false</Optimize>
|
||||||
<Optimize>false</Optimize>
|
<OutputPath>bin\Debug</OutputPath>
|
||||||
<OutputPath>bin\Debug</OutputPath>
|
<DefineConstants>DEBUG;</DefineConstants>
|
||||||
<DefineConstants>DEBUG;</DefineConstants>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<WarningLevel>4</WarningLevel>
|
||||||
<WarningLevel>4</WarningLevel>
|
<ExternalConsole>true</ExternalConsole>
|
||||||
<ExternalConsole>true</ExternalConsole>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<CustomCommands>
|
||||||
<CustomCommands>
|
<CustomCommands>
|
||||||
<CustomCommands>
|
<Command>
|
||||||
<Command>
|
<type>BeforeBuild</type>
|
||||||
<type>BeforeBuild</type>
|
<command>npm run build</command>
|
||||||
<command>npm run build</command>
|
<workingdir>${ProjectDir}/Client</workingdir>
|
||||||
<workingdir>${ProjectDir}/Client</workingdir>
|
</Command>
|
||||||
</Command>
|
</CustomCommands>
|
||||||
</CustomCommands>
|
</CustomCommands>
|
||||||
</CustomCommands>
|
</PropertyGroup>
|
||||||
</PropertyGroup>
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
<Optimize>true</Optimize>
|
||||||
<Optimize>true</Optimize>
|
<OutputPath>bin\Release</OutputPath>
|
||||||
<OutputPath>bin\Release</OutputPath>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<WarningLevel>4</WarningLevel>
|
||||||
<WarningLevel>4</WarningLevel>
|
<ExternalConsole>true</ExternalConsole>
|
||||||
<ExternalConsole>true</ExternalConsole>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
</PropertyGroup>
|
||||||
</PropertyGroup>
|
<ItemGroup>
|
||||||
<ItemGroup>
|
<Reference Include="System" />
|
||||||
<Reference Include="System" />
|
<Reference Include="IotWeb.Common">
|
||||||
<Reference Include="IotWeb.Common">
|
<HintPath>..\packages\IotWeb.0.8.6\lib\net45\IotWeb.Common.dll</HintPath>
|
||||||
<HintPath>..\packages\IotWeb.0.8.6\lib\net45\IotWeb.Common.dll</HintPath>
|
</Reference>
|
||||||
</Reference>
|
<Reference Include="IotWeb.Server">
|
||||||
<Reference Include="IotWeb.Server">
|
<HintPath>..\packages\IotWeb.0.8.6\lib\net45\IotWeb.Server.dll</HintPath>
|
||||||
<HintPath>..\packages\IotWeb.0.8.6\lib\net45\IotWeb.Server.dll</HintPath>
|
</Reference>
|
||||||
</Reference>
|
</ItemGroup>
|
||||||
</ItemGroup>
|
<ItemGroup>
|
||||||
<ItemGroup>
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="RippleSpace\Plane.cs" />
|
||||||
<Compile Include="RippleSpace\Plane.cs" />
|
<Compile Include="RippleSpace\Chunk.cs" />
|
||||||
<Compile Include="RippleSpace\Chunk.cs" />
|
<Compile Include="RippleSpace\LocationReference.cs" />
|
||||||
<Compile Include="RippleSpace\LocationReference.cs" />
|
<Compile Include="RippleSpace\ChunkReference.cs" />
|
||||||
<Compile Include="RippleSpace\ChunkReference.cs" />
|
<Compile Include="RippleSpace\DrawnLine.cs" />
|
||||||
<Compile Include="RippleSpace\DrawnLine.cs" />
|
<Compile Include="RippleSpace\Reference.cs" />
|
||||||
<Compile Include="RippleSpace\Reference.cs" />
|
<Compile Include="Utilities.cs" />
|
||||||
<Compile Include="Utilities.cs" />
|
<Compile Include="NibriboardServer.cs" />
|
||||||
<Compile Include="NibriboardServer.cs" />
|
<Compile Include="NibriClient.cs" />
|
||||||
<Compile Include="NibriClientManager.cs" />
|
<Compile Include="NibriClientManager.cs" />
|
||||||
<Compile Include="Log.cs" />
|
<Compile Include="Log.cs" />
|
||||||
<Compile Include="Utilities\EmbeddedFiles.cs" />
|
<Compile Include="Utilities\EmbeddedFiles.cs" />
|
||||||
<Compile Include="NibriClient.cs" />
|
<Compile Include="Env.cs" />
|
||||||
</ItemGroup>
|
<Compile Include="RippleSpace\RippleSpaceManager.cs" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<EmbeddedResource Include="Client\index.html" />
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Client\NibriClient.js" />
|
<EmbeddedResource Include="Client\index.html" />
|
||||||
<EmbeddedResource Include="Client\Nibri.css" />
|
<EmbeddedResource Include="Client\NibriClient.js" />
|
||||||
</ItemGroup>
|
<EmbeddedResource Include="Client\Nibri.css" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<Folder Include="RippleSpace\" />
|
<ItemGroup>
|
||||||
<Folder Include="Client\" />
|
<Folder Include="RippleSpace\" />
|
||||||
<Folder Include="Utilities\" />
|
<Folder Include="Client\" />
|
||||||
</ItemGroup>
|
<Folder Include="Utilities\" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<None Include="packages.config" />
|
<ItemGroup>
|
||||||
</ItemGroup>
|
<None Include="packages.config" />
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<None Include="Client\index.js" />
|
||||||
</Project>
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
|
@ -1,22 +1,26 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using IotWeb.Server;
|
using IotWeb.Server;
|
||||||
using IotWeb.Common.Http;
|
using IotWeb.Common.Http;
|
||||||
using System.Net;
|
|
||||||
|
using Nibriboard.RippleSpace;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Nibriboard
|
namespace Nibriboard
|
||||||
{
|
{
|
||||||
public class NibriboardServer
|
public class NibriboardServer
|
||||||
{
|
{
|
||||||
private HttpServer httpServer;
|
private HttpServer httpServer;
|
||||||
|
|
||||||
|
private RippleSpaceManager planeManager = new RippleSpaceManager();
|
||||||
|
|
||||||
public readonly int Port = 31586;
|
public readonly int Port = 31586;
|
||||||
|
|
||||||
public NibriboardServer()
|
public NibriboardServer(int inPort = 31586)
|
||||||
{
|
{
|
||||||
}
|
Port = inPort;
|
||||||
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
httpServer = new HttpServer(Port);
|
httpServer = new HttpServer(Port);
|
||||||
httpServer.AddHttpRequestHandler(
|
httpServer.AddHttpRequestHandler(
|
||||||
"/",
|
"/",
|
||||||
|
@ -30,8 +34,14 @@ namespace Nibriboard
|
||||||
"/RipplespaceConnection",
|
"/RipplespaceConnection",
|
||||||
new NibriClientManager()
|
new NibriClientManager()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Start()
|
||||||
|
{
|
||||||
httpServer.Start();
|
httpServer.Start();
|
||||||
Log.WriteLine("[NibriboardServer] Started on port {0}", Port);
|
Log.WriteLine("[NibriboardServer] Started on port {0}", Port);
|
||||||
|
|
||||||
|
await planeManager.StartMaintenanceMonkey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using SBRLUtilities;
|
using SBRLUtilities;
|
||||||
|
|
||||||
namespace Nibriboard
|
namespace Nibriboard
|
||||||
|
@ -8,8 +9,15 @@ namespace Nibriboard
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Hello World!");
|
Log.WriteLine("[core] Starting Nibriboard.");
|
||||||
|
|
||||||
|
Log.WriteLine("[core] Detected embedded files: ");
|
||||||
EmbeddedFiles.WriteResourceList();
|
EmbeddedFiles.WriteResourceList();
|
||||||
|
|
||||||
|
NibriboardServer server = new NibriboardServer();
|
||||||
|
Task.WaitAll(
|
||||||
|
server.Start()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,5 +82,10 @@ namespace Nibriboard.RippleSpace
|
||||||
containingChunk.Add(newLineSegment);
|
containingChunk.Add(newLineSegment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task PerformMaintenance()
|
||||||
|
{
|
||||||
|
// TODO: Perform maintenance here
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
59
Nibriboard/RippleSpace/RippleSpaceManager.cs
Normal file
59
Nibriboard/RippleSpace/RippleSpaceManager.cs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Nibriboard.RippleSpace
|
||||||
|
{
|
||||||
|
public class RippleSpaceManager
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The master list of planes that this PlaneManager is in charge of.
|
||||||
|
/// </summary>
|
||||||
|
public List<Plane> Planes = new List<Plane>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of milliseconds between each maintenance run.
|
||||||
|
/// </summary>
|
||||||
|
public readonly int MaintenanceInternal = 5000;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of milliseconds the last maintenance run took.
|
||||||
|
/// </summary>
|
||||||
|
public long LastMaintenanceDuration = 0;
|
||||||
|
|
||||||
|
public RippleSpaceManager()
|
||||||
|
{
|
||||||
|
Log.WriteLine("[RippleSpace] New blank ripplespace initialised.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plane GetById(string targetName)
|
||||||
|
{
|
||||||
|
foreach (Plane plane in Planes)
|
||||||
|
{
|
||||||
|
if (plane.Name == targetName)
|
||||||
|
return plane;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task StartMaintenanceMonkey()
|
||||||
|
{
|
||||||
|
Log.WriteLine("[RippleSpace/Maintenance] Automated maintenance monkey created.");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Stopwatch maintenanceStopwatch = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
foreach (Plane plane in Planes)
|
||||||
|
await plane.PerformMaintenance();
|
||||||
|
|
||||||
|
LastMaintenanceDuration = maintenanceStopwatch.ElapsedMilliseconds;
|
||||||
|
|
||||||
|
await Task.Delay(MaintenanceInternal);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,4 +5,4 @@ An infinite whiteboard for recording those big ideas.
|
||||||
## Credits
|
## Credits
|
||||||
- Main code - [Starbeamrainbowlabs](https://starbeamrainbowlabs.com/)
|
- Main code - [Starbeamrainbowlabs](https://starbeamrainbowlabs.com/)
|
||||||
- [Paper.js](http://paperjs.org/) - Client-side rendering
|
- [Paper.js](http://paperjs.org/) - Client-side rendering
|
||||||
- [IotWeb](http://sensaura.org/pages/tools/iotweb/) - Underlying HTTP / WebSocket server
|
- [IotWeb](http://sensaura.org/pages/tools/iotweb/) - Underlying HTTP / WebSocket server
|
||||||
|
|
Loading…
Reference in a new issue