Skip to content

Commit

Permalink
[275] ReadyState für ActorHosts eingeführt, ChunkRenderer Priorisierung
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwendel committed Nov 13, 2015
1 parent 19c67e2 commit baf3df1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 39 deletions.
2 changes: 1 addition & 1 deletion OctoAwesome/OctoAwesome.Client/Controls/SceneControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ private bool FillChunkRenderer()
}
}

Index3 comparationIndex = new Index3(destinationChunk, 0);
Index3 comparationIndex = player.ActorHost.Position.ChunkIndex;
orderedChunkRenderer.Sort((x, y) =>
{
if (!x.ChunkPosition.HasValue) return 1;
Expand Down
20 changes: 15 additions & 5 deletions OctoAwesome/OctoAwesome.Runtime/ActorHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ActorHost : IPlayerController

public InventorySlot ActiveTool { get; set; }

public bool ReadyState { get; private set; }

public ActorHost(Player player)
{
Player = player;
Expand All @@ -35,11 +37,15 @@ public ActorHost(Player player)
_oldIndex = Player.Position.ChunkIndex;

ActiveTool = null;
ReadyState = false;
}

public void Initialize()
{
localChunkCache.SetCenter(planet, Player.Position.ChunkIndex, (success) => { });
localChunkCache.SetCenter(planet, Player.Position.ChunkIndex, (success) =>
{
ReadyState = success;
});
}

public void Update(GameTime frameTime)
Expand Down Expand Up @@ -92,7 +98,7 @@ public void Update(GameTime frameTime)
powerdirection += jumpDirection * Player.JUMPPOWER;
}



Vector3 VelocityChange = (2.0f / Player.Mass * (powerdirection - Friction * Player.Velocity)) *
(float)frameTime.ElapsedGameTime.TotalSeconds;
Expand Down Expand Up @@ -201,7 +207,7 @@ public void Update(GameTime frameTime)
// Koordinate normalisieren (Rundwelt)
Coordinate position = Player.Position;
position.NormalizeChunkIndexXY(planet.Size);

//Beam me up
KeyboardState ks = Keyboard.GetState();
if (ks.IsKeyDown(Keys.P))
Expand All @@ -215,13 +221,17 @@ public void Update(GameTime frameTime)
}
while (collision && loop < 3);



if (Player.Position.ChunkIndex != _oldIndex)
{
//TODO: Planeten rundung beachten :)
_oldIndex = Player.Position.ChunkIndex;
localChunkCache.SetCenter(planet, Player.Position.ChunkIndex);
localChunkCache.SetCenter(planet, Player.Position.ChunkIndex, (success) =>
{
ReadyState = success;
});
ReadyState = false;
}

#endregion
Expand Down
1 change: 0 additions & 1 deletion OctoAwesome/OctoAwesome.Runtime/OctoAwesome.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<Compile Include="ResourceManager.cs" />
<Compile Include="UpdateDomain.cs" />
<Compile Include="World.cs" />
<Compile Include="WorldState.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OctoAwesome\OctoAwesome.csproj">
Expand Down
9 changes: 5 additions & 4 deletions OctoAwesome/OctoAwesome.Runtime/UpdateDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ private void updateLoop()
watch.Elapsed, frameTime);
lastCall = watch.Elapsed;

// TODO: Chunk Updates

foreach (var actorHost in ActorHosts)
actorHost.Update(gameTime);
if (!world.Paused)
{
foreach (var actorHost in ActorHosts.Where(h => h.ReadyState))
actorHost.Update(gameTime);
}

TimeSpan diff = frameTime - (watch.Elapsed - lastCall);
if (diff > TimeSpan.Zero)
Expand Down
12 changes: 2 additions & 10 deletions OctoAwesome/OctoAwesome.Runtime/World.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace OctoAwesome.Runtime
{
Expand All @@ -15,11 +8,10 @@ public sealed class World

private UpdateDomain[] updateDomains;

public WorldState State { get; private set; }
public bool Paused { get; set; }

public World()
{
State = WorldState.Loading;
watch.Start();
updateDomains = new UpdateDomain[1];
updateDomains[0] = new UpdateDomain(this, watch);
Expand Down
15 changes: 0 additions & 15 deletions OctoAwesome/OctoAwesome.Runtime/WorldState.cs

This file was deleted.

6 changes: 3 additions & 3 deletions OctoAwesome/OctoAwesome/LocalChunkCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public void SetCenter(IPlanet planet, Index3 index, Action<bool> successCallback
{
_cancellationToken.Cancel();
_cancellationToken = new CancellationTokenSource();
_loadingTask = _loadingTask.ContinueWith(_ => InternalSetCenter(_cancellationToken.Token, planet, index));
_loadingTask = _loadingTask.ContinueWith(_ => InternalSetCenter(_cancellationToken.Token, planet, index, successCallback));
}
else
{
_cancellationToken = new CancellationTokenSource();
_loadingTask = Task.Factory.StartNew(() => InternalSetCenter(_cancellationToken.Token, planet, index));
_loadingTask = Task.Factory.StartNew(() => InternalSetCenter(_cancellationToken.Token, planet, index, successCallback));
}
}

private void InternalSetCenter(CancellationToken token, IPlanet planet, Index3 index, Action<bool> successCallback = null)
private void InternalSetCenter(CancellationToken token, IPlanet planet, Index3 index, Action<bool> successCallback)
{
// Planet resetten falls notwendig
if (this.planet != planet)
Expand Down

0 comments on commit baf3df1

Please sign in to comment.