Erste Gui Version. Es wird lediglich die Map gezeichnet. Das Backend ist angeschlossen
This commit is contained in:
@@ -1,35 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace WorldOfPeacecraft
|
||||
{
|
||||
public class Buffer
|
||||
{
|
||||
private Queue<string> RawBuffer = new Queue<string>();
|
||||
private AutoResetEvent BufferFilledEvent = new AutoResetEvent (false);
|
||||
int size;
|
||||
public class Buffer
|
||||
{
|
||||
private Queue<string> Lines = new Queue<string>();
|
||||
private int MaxSize;
|
||||
private AutoResetEvent QueueFullLock = new AutoResetEvent(false);
|
||||
private AutoResetEvent QueueEmptyLock = new AutoResetEvent(false);
|
||||
|
||||
public Buffer(int size)
|
||||
{
|
||||
this.size=size;
|
||||
}
|
||||
|
||||
|
||||
public void AddToBuffer (string s)
|
||||
public Buffer (int maxSize)
|
||||
{
|
||||
if (RawBuffer.Count >= size){
|
||||
this.MaxSize = maxSize;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
lock (RawBuffer) {
|
||||
RawBuffer.Enqueue (s);
|
||||
BufferFilledEvent.Set ();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public void AddLine (string line)
|
||||
{
|
||||
bool waitRequired = false;
|
||||
lock (Lines) {
|
||||
if (Lines.Count >= MaxSize) {
|
||||
waitRequired = true;
|
||||
QueueFullLock.Reset ();
|
||||
}
|
||||
}
|
||||
if (waitRequired) {
|
||||
QueueFullLock.WaitOne ();
|
||||
}
|
||||
lock (Lines) {
|
||||
Lines.Enqueue (line);
|
||||
QueueEmptyLock.Set();
|
||||
}
|
||||
}
|
||||
|
||||
public string NextLine ()
|
||||
{
|
||||
bool waitRequired = false;
|
||||
string line;
|
||||
lock (Lines) {
|
||||
if (Lines.Count == 0) {
|
||||
waitRequired = true;
|
||||
QueueEmptyLock.Reset ();
|
||||
}
|
||||
}
|
||||
if (waitRequired) {
|
||||
QueueEmptyLock.WaitOne ();
|
||||
}
|
||||
lock (Lines) {
|
||||
line = Lines.Dequeue();
|
||||
QueueFullLock.Set ();
|
||||
}
|
||||
return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user