public Server(ADispatchServer server) { Id = Interlocked.Increment(ref idCounter); _players.Add(Player.ServerPlayer); _server = server; _server.Server = this; }
public void AddTest() { var add = new object(); for (int i = 0; i < 10; i++) { _target.Add(add); } int expected = 10; int actual; actual = _target.Add(add); Assert.AreEqual(expected, actual); }
public virtual void AddBufferEntityParser(int gmuId, int appId, IFFParser parser, FFTgtParseBufferHandler action) { using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "AddBufferEntityParser")) { try { FF_FlowInitiation flowDirection = this.FlowInitiation; if (_subParsers == null) { _subParsers = new FFParserDictionary(); } if (_parserMappings == null) { _parserMappings = new IntDictionary <int>(); } if (parser != null && parser.FlowInitiation != FF_FlowInitiation.Any) { flowDirection = parser.FlowInitiation; } _subParsers.AddParserItem(flowDirection, gmuId, appId, parser, action); if (appId != -1 && !_parserMappings.ContainsKey(appId)) { _parserMappings.Add(appId, gmuId); } } catch (Exception ex) { method.Exception(ex); } } }
/// <summary> /// Set up the server, bind to a socket. Use Start to fully start the server after running this /// </summary> /// <param name="configuration"></param> public static void InitializeServer(ServerConfiguration configuration) { Configuration = configuration; if (peer != null && peer.Status != NetPeerStatus.NotRunning) { Debug.LogError("cannot start server while already running"); return; } _netPeerConfiguration = new NetPeerConfiguration(Configuration.AppIdentifier); _netPeerConfiguration.Port = Configuration.ListenPort; _netPeerConfiguration.MaximumConnections = Configuration.MaximumConnections; connections = new IntDictionary <NetConnection>(Configuration.MaximumConnections); _netPeerConfiguration.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true); peer = new NetServer(_netPeerConfiguration); peer.Start(); var serverId = connections.Add(null); var serverPlayer = new Player(); serverPlayer.Id = (ushort)serverId; Player.Server = serverPlayer; GameState.update += Update; }
internal void Add(GameObject gobj) { var id = _gameObjects.Add(gobj); gobj.ReferenceData = new ReferenceData { InstanceID = id }; }
internal NetworkView GetNew(Player owner) { lock (_networkViews) { var nid = (ushort)_networkViews.Add(null); var view = new NetworkView(this, nid, owner); _networkViews[nid] = view; return(view); } }
/////////////////////////////////////////////////////////////////////////////////////////////// public static bool SetDuplicateCount( /* O(N) */ IComparer <string> comparer, IntDictionary duplicates, string value, int count ) { // // HACK: Since the ContainsKey method of the Dictionary object // insists on using both the Equals and GetHashCode methods // of the custom IEqualityComparer interface we provide // to find the key, we must resort to a linear search // because we cannot reasonably implement the GetHashCode // method in terms of the Compare method in a semantically // compatible way. // if ((comparer != null) && (duplicates != null) && (value != null)) { foreach (string element in duplicates.Keys) { if (comparer.Compare(element, value) == 0 /* EQUAL */) { // // NOTE: Found the key value, set the count. // duplicates[element] = count; return(true); } } // // NOTE: The value was not found in the dictionary, // add it now. // duplicates.Add(value, count); return(true); } return(false); }
internal static void RegisterView(NetworkView view, ushort viewId) { lock (ViewsLock) { Views.Add(viewId, view); } }
/// <summary> /// Set up the server, bind to a socket. Use Start to fully start the server after running this /// </summary> /// <param name="configuration"></param> public static void InitializeServer(ServerConfiguration configuration) { Configuration = configuration; if (peer != null && peer.Status != NetPeerStatus.NotRunning) { Debug.LogError("cannot start server while already running"); return; } _netPeerConfiguration = new NetPeerConfiguration(Configuration.AppIdentifier); _netPeerConfiguration.Port = Configuration.ListenPort; _netPeerConfiguration.MaximumConnections = Configuration.MaximumConnections; connections = new IntDictionary<NetConnection>(Configuration.MaximumConnections); _netPeerConfiguration.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true); peer = new NetServer(_netPeerConfiguration); peer.Start(); var serverId = connections.Add(null); var serverPlayer = new Player(); serverPlayer.Id = (ushort)serverId; Player.Server = serverPlayer; GameState.update += Update; }
internal static int AddGameObject(GameObject newObject) { var newId = GameObjects.Add(newObject); return(newId); }
public void IntDictionaryComparisonTest() { const int TestSize = 10000000; var intDic = new IntDictionary<MockObject>(32); var dic = new Dictionary<int, MockObject>(32); //jit shit. var add = new MockObject(); add.Id = intDic.Add(add); foreach (var kvp in intDic) { kvp.DoNothing(); } intDic.Remove(add.Id); add.Id = 0; dic.Add(add.Id, add); foreach (var kvp in dic) { kvp.Value.DoNothing(); } dic.Remove(add.Id); Stopwatch watch = new Stopwatch(); watch.Reset(); //the real tests watch.Start(); for (int i = 0; i < TestSize; i++) { var foo = new MockObject(); foo.Id = intDic.Add(foo); } watch.Stop(); Debug.WriteLine("IntDic add: {0}", watch.Elapsed); watch.Reset(); watch.Start(); for (int i = 0; i < TestSize; i++) { var foo = new MockObject(); foo.Id = i; dic.Add(i, foo); } watch.Stop(); Debug.WriteLine("Dic add: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var kvp in intDic) { if (kvp != null) kvp.DoNothing(); } watch.Stop(); Debug.WriteLine("Intdic foreach: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var kvp in dic) { kvp.Value.DoNothing(); } watch.Stop(); Debug.WriteLine("Dic foreach: {0}", watch.Elapsed); watch.Reset(); watch.Start(); for (int i = 0; i < intDic.Capacity; i++) { MockObject value; if (intDic.TryGetValue(i, out value)) value.DoNothing(); } watch.Stop(); Debug.WriteLine("Intdic for: {0}", watch.Elapsed); watch.Reset(); const int halfSize = TestSize / 2; watch.Start(); for (int i = 0; i < halfSize; i++) { intDic.Remove(i); } watch.Stop(); Debug.WriteLine("Intdic remove: {0}", watch.Elapsed); watch.Reset(); watch.Start(); for (int i = 0; i < halfSize; i++) { dic.Remove(i); } watch.Stop(); Debug.WriteLine("dic remove: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var kvp in intDic) { if (kvp != null) kvp.DoNothing(); } watch.Stop(); Debug.WriteLine("intdic foreach after remove: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var kvp in dic) { kvp.Value.DoNothing(); } watch.Stop(); Debug.WriteLine("dic foreach after remove: {0}", watch.Elapsed); watch.Reset(); }
internal void Add(int value, int docId) { _ReplaceFieldValueIntToDocId.Add(value, docId); }
/// <summary> /// this function is called in first time loading. /// </summary> /// <param name="fs">file stream that position is already set to end of the header</param> /// <param name="storeLength">record length that stored in file</param> unsafe internal int LoadFromFile(System.IO.FileStream fs, int storeLength, int rankTab) { Clear(); _RankTab = rankTab; _Count = (int)((fs.Length - fs.Position) / storeLength); byte[] block = new byte[storeLength * BufSize]; int realPayloadSize = storeLength + 4; //add fileindex 4 bytes _PayloadSize = storeLength / 4 - 1; //subtract docid length (4 bytes); _PayloadSize is count of int int readCount = block.Length; Hubble.Framework.IO.Stream.ReadToBuf(fs, block, 0, ref readCount); int firstFileIndex = 0; int recordsInBlock = readCount / storeLength; int docId = -1; int lastDocId = -1; while (readCount > 0) { int fstDocid = BitConverter.ToInt32(block, 0); IndexElement indexElement = new IndexElement(fstDocid, realPayloadSize); IndexBuf[_IndexCount++] = indexElement; indexElement.MB.UsedCount = recordsInBlock; int *head = (int *)(IntPtr)indexElement.MB; int payloadIntLength = storeLength / 4 - 1; //how may int of payload data fixed(byte *pHead = &block[0]) { byte *pb = pHead; for (int i = 0; i < recordsInBlock; i++) { int *pInt = (int *)pb; *head = *pInt; //docid docId = *head; if (docId < lastDocId) { throw new Data.DataException(string.Format("docid = {0} < last docid ={1}", docId, lastDocId)); } lastDocId = docId; head++; //fileindex address pInt++; if (_DocIdReplaceField != null) { if (_DocIdReplaceField.DataType == DataType.BigInt) { long value = (((long)pInt[_DocIdReplaceField.TabIndex]) << 32) + (uint)pInt[_DocIdReplaceField.TabIndex + 1]; if (!_ReplaceFieldValueToDocId.ContainsKey(value)) { _ReplaceFieldValueToDocId.Add(value, docId); } else { _ReplaceFieldValueToDocId[value] = docId; } } else { int value = pInt[_DocIdReplaceField.TabIndex]; _ReplaceFieldValueToDocId.AddOrUpdate(value, docId); //if (!_ReplaceFieldValueToDocId.ContainsKey(value)) //{ // _ReplaceFieldValueToDocId.Add(value, docId); //} //else //{ // _ReplaceFieldValueToDocId[value] = docId; //} } } *head = firstFileIndex + i; head++; //Payload Data first byte address if (_RankTab > 0) { int rank = *(pInt + _RankTab); if (rank < 0) { rank = 0; } else if (rank > 65535) { rank = 65535; } _DocIdToRank.Add(docId, (UInt16)rank); } for (int j = 0; j < payloadIntLength; j++) { *head = *pInt; head++; pInt++; } pb += storeLength; } } firstFileIndex += recordsInBlock; readCount = block.Length; Hubble.Framework.IO.Stream.ReadToBuf(fs, block, 0, ref readCount); recordsInBlock = readCount / storeLength; } return(docId); }
public void IntDictionaryComparisonTest() { const int TestSize = 10000000; var intDic = new IntDictionary <MockObject>(32); var dic = new Dictionary <int, MockObject>(32); //jit shit. var add = new MockObject(); add.Id = intDic.Add(add); foreach (var kvp in intDic) { kvp.DoNothing(); } intDic.Remove(add.Id); add.Id = 0; dic.Add(add.Id, add); foreach (var kvp in dic) { kvp.Value.DoNothing(); } dic.Remove(add.Id); Stopwatch watch = new Stopwatch(); watch.Reset(); //the real tests watch.Start(); for (int i = 0; i < TestSize; i++) { var foo = new MockObject(); foo.Id = intDic.Add(foo); } watch.Stop(); Debug.WriteLine("IntDic add: {0}", watch.Elapsed); watch.Reset(); watch.Start(); for (int i = 0; i < TestSize; i++) { var foo = new MockObject(); foo.Id = i; dic.Add(i, foo); } watch.Stop(); Debug.WriteLine("Dic add: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var kvp in intDic) { if (kvp != null) { kvp.DoNothing(); } } watch.Stop(); Debug.WriteLine("Intdic foreach: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var kvp in dic) { kvp.Value.DoNothing(); } watch.Stop(); Debug.WriteLine("Dic foreach: {0}", watch.Elapsed); watch.Reset(); watch.Start(); for (int i = 0; i < intDic.Capacity; i++) { MockObject value; if (intDic.TryGetValue(i, out value)) { value.DoNothing(); } } watch.Stop(); Debug.WriteLine("Intdic for: {0}", watch.Elapsed); watch.Reset(); const int halfSize = TestSize / 2; watch.Start(); for (int i = 0; i < halfSize; i++) { intDic.Remove(i); } watch.Stop(); Debug.WriteLine("Intdic remove: {0}", watch.Elapsed); watch.Reset(); watch.Start(); for (int i = 0; i < halfSize; i++) { dic.Remove(i); } watch.Stop(); Debug.WriteLine("dic remove: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var kvp in intDic) { if (kvp != null) { kvp.DoNothing(); } } watch.Stop(); Debug.WriteLine("intdic foreach after remove: {0}", watch.Elapsed); watch.Reset(); watch.Start(); foreach (var kvp in dic) { kvp.Value.DoNothing(); } watch.Stop(); Debug.WriteLine("dic foreach after remove: {0}", watch.Elapsed); watch.Reset(); }
private void RegisterView(NetworkView view, NetworkViewId viewId) { _allViews.Add(viewId.guid, view); }
internal void SubscribeToSynchronizedField <T>(SynchronizedField <T> field) { int fieldId = FieldProcessors.Add(field.OnReceiveValue); field.FieldId = (byte)fieldId; }
internal static void RegisterView(NetworkView view, ushort viewId) { allViews.Add(viewId, view); }
public Server() { Id = Interlocked.Increment(ref idCounter); _players.Add(Player.ServerPlayer); }