1
0
Fork 0
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:
Starbeamrainbowlabs 2017-01-19 13:13:35 +00:00
parent cf8fb234b4
commit 33f3c44d6e
10 changed files with 191 additions and 87 deletions

View file

@ -0,0 +1,2 @@
"use strict";

15
Nibriboard/Env.cs Normal file
View 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;
}
}
}
}

View file

@ -3,9 +3,10 @@ namespace Nibriboard
{
public static class Log
{
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);
return outputText.Length;
}

View file

@ -26,6 +26,8 @@ namespace Nibriboard
//Task.Run(async () => await onMessage(frame)).Wait();
};
}
private async Task onMessage(string frame)

View file

@ -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">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{B7F806D9-9C50-4BA8-A803-0FC2EC5F5932}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Nibriboard</RootNamespace>
<AssemblyName>Nibriboard</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
<CustomCommands>
<CustomCommands>
<Command>
<type>BeforeBuild</type>
<command>npm run build</command>
<workingdir>${ProjectDir}/Client</workingdir>
</Command>
</CustomCommands>
</CustomCommands>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="IotWeb.Common">
<HintPath>..\packages\IotWeb.0.8.6\lib\net45\IotWeb.Common.dll</HintPath>
</Reference>
<Reference Include="IotWeb.Server">
<HintPath>..\packages\IotWeb.0.8.6\lib\net45\IotWeb.Server.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RippleSpace\Plane.cs" />
<Compile Include="RippleSpace\Chunk.cs" />
<Compile Include="RippleSpace\LocationReference.cs" />
<Compile Include="RippleSpace\ChunkReference.cs" />
<Compile Include="RippleSpace\DrawnLine.cs" />
<Compile Include="RippleSpace\Reference.cs" />
<Compile Include="Utilities.cs" />
<Compile Include="NibriboardServer.cs" />
<Compile Include="NibriClientManager.cs" />
<Compile Include="Log.cs" />
<Compile Include="Utilities\EmbeddedFiles.cs" />
<Compile Include="NibriClient.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Client\index.html" />
<EmbeddedResource Include="Client\NibriClient.js" />
<EmbeddedResource Include="Client\Nibri.css" />
</ItemGroup>
<ItemGroup>
<Folder Include="RippleSpace\" />
<Folder Include="Client\" />
<Folder Include="Utilities\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{B7F806D9-9C50-4BA8-A803-0FC2EC5F5932}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Nibriboard</RootNamespace>
<AssemblyName>Nibriboard</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
<CustomCommands>
<CustomCommands>
<Command>
<type>BeforeBuild</type>
<command>npm run build</command>
<workingdir>${ProjectDir}/Client</workingdir>
</Command>
</CustomCommands>
</CustomCommands>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ExternalConsole>true</ExternalConsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="IotWeb.Common">
<HintPath>..\packages\IotWeb.0.8.6\lib\net45\IotWeb.Common.dll</HintPath>
</Reference>
<Reference Include="IotWeb.Server">
<HintPath>..\packages\IotWeb.0.8.6\lib\net45\IotWeb.Server.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RippleSpace\Plane.cs" />
<Compile Include="RippleSpace\Chunk.cs" />
<Compile Include="RippleSpace\LocationReference.cs" />
<Compile Include="RippleSpace\ChunkReference.cs" />
<Compile Include="RippleSpace\DrawnLine.cs" />
<Compile Include="RippleSpace\Reference.cs" />
<Compile Include="Utilities.cs" />
<Compile Include="NibriboardServer.cs" />
<Compile Include="NibriClient.cs" />
<Compile Include="NibriClientManager.cs" />
<Compile Include="Log.cs" />
<Compile Include="Utilities\EmbeddedFiles.cs" />
<Compile Include="Env.cs" />
<Compile Include="RippleSpace\RippleSpaceManager.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Client\index.html" />
<EmbeddedResource Include="Client\NibriClient.js" />
<EmbeddedResource Include="Client\Nibri.css" />
</ItemGroup>
<ItemGroup>
<Folder Include="RippleSpace\" />
<Folder Include="Client\" />
<Folder Include="Utilities\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Client\index.js" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -1,22 +1,26 @@
using System;
using System.Reflection;
using IotWeb.Server;
using IotWeb.Common.Http;
using System.Net;
using Nibriboard.RippleSpace;
using System.Threading.Tasks;
namespace Nibriboard
{
public class NibriboardServer
{
private HttpServer httpServer;
private RippleSpaceManager planeManager = new RippleSpaceManager();
public readonly int Port = 31586;
public NibriboardServer()
public NibriboardServer(int inPort = 31586)
{
}
Port = inPort;
public void Setup()
{
httpServer = new HttpServer(Port);
httpServer.AddHttpRequestHandler(
"/",
@ -30,8 +34,14 @@ namespace Nibriboard
"/RipplespaceConnection",
new NibriClientManager()
);
}
public async Task Start()
{
httpServer.Start();
Log.WriteLine("[NibriboardServer] Started on port {0}", Port);
await planeManager.StartMaintenanceMonkey();
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using SBRLUtilities;
namespace Nibriboard
@ -8,8 +9,15 @@ namespace Nibriboard
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Log.WriteLine("[core] Starting Nibriboard.");
Log.WriteLine("[core] Detected embedded files: ");
EmbeddedFiles.WriteResourceList();
NibriboardServer server = new NibriboardServer();
Task.WaitAll(
server.Start()
);
}
}
}

View file

@ -82,5 +82,10 @@ namespace Nibriboard.RippleSpace
containingChunk.Add(newLineSegment);
}
}
public async Task PerformMaintenance()
{
// TODO: Perform maintenance here
}
}
}

View 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);
}
}
}
}

View file

@ -5,4 +5,4 @@ An infinite whiteboard for recording those big ideas.
## Credits
- Main code - [Starbeamrainbowlabs](https://starbeamrainbowlabs.com/)
- [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