Пример #1
0
        internal Scheduler(Context context)
        {
            Assert.NotNull(context, "context");

            this.context = context;
            this.heap = new Collections.BinaryHeap<float, Action>();
        }
Пример #2
0
        protected Server(ServerConfiguration configuration)
        {
            // Set configuration
            Assert.NotNull(configuration, "configuration");

            Configuration = configuration;

            // Set log level
            Log.SetLevel(configuration.LogLevel);

            // Log some generic data
            log.Info("Running server in {0} mode", configuration.ServerMode);
            log.Info("Using {0} ms of send buffering", configuration.SendBuffering);

            // Setup id pools
            actorIdPool = new Collections.UShortPool();
            playerIdPool = new Collections.UShortPool();

            //
            LoadAssemblies();

            // Setup context
            ContextPlugin = CreateContextPlugin(typeof(ServerContextPluginAttribute));
            Context = new Context(this);

            // Create server
            NetworkPeer = NetworkServer = new Network.LidgrenServer(this);
        }
Пример #3
0
        protected Client(ClientConfiguration configuration)
        {
            // Verify and set configuraiton
            Assert.NotNull(configuration, "configuration");

            Configuration = configuration;

            // Set log level
            Log.SetLevel(configuration.LogLevel);

            // Create context and plugin
            ContextPlugin = CreateContextPlugin(typeof(ClientContextPluginAttribute));
            Context = new Context(this);

            // Network
            NetworkPeer = networkClient = new Network.LidgrenClient(this);

            // Event handlers
            Context.PlayerEventHandler.RegisterReceiver<Events.Hello>(onHello);
            Context.PlayerEventHandler.RegisterReceiver<Events.Spawn>(onSpawn);
            Context.PlayerEventHandler.RegisterReceiver<Events.Despawn>(onDespawn);
            Context.ActorEventHandler.RegisterReceiver<Events.ChangeOwner>(onChangeOwner);
        }
Пример #4
0
 public Stats(Context context)
 {
     #if DEBUG || RECORD_STATS
     inBytes = new Counter(context.Time);
     outBytes = new Counter(context.Time);
     inEvents = new Counter(context.Time);
     outEvents = new Counter(context.Time);
     #endif
 }
Пример #5
0
        internal static void Init(Context context)
        {
            if (byId == null || byType == null)
            {
                IEnumerable<ActorDefinition> instances =
                    typeof(ActorDefinition)
                        .GetSubTypes()
                        .Where(x => !x.IsAbstract && !x.IsGenericType && x.HasDefaultConstructor())
                        .Select(x => Activator.CreateInstance(x))
                        .Cast<ActorDefinition>()
                        .Select(x => { x.Context = context; return x; });

                all = instances.ToArray();
                byId = all.ToDictionary(x => x.Id);
                byType = all.ToDictionary(x => x.GetType());

                log.Info("Found {0} Actor Definitions", all.Length);
            }
        }