Esempio n. 1
0
        public bool Start(int port = 9051)
        {
            _node = new NetworkNode();
            var started = _node.Start(port, 128, true);

            if (!started)
            {
                return(false);
            }
            _sessionId = _node.Create <SessionEntity>();
            _node.Create <VisibilityEntity>();
            _node.NewConnectionEstablished += NewConnection;
            _physicsWorld    = new VoltWorld();
            _node.CustomData = _physicsWorld;
            var map = DefsHolder.Instance.LoadDef <MapDef>("/TestMapDef");

            _debugCreator = new LocationCreator(map.Locations[0].CreatorDef, 0);
            _debugCreator.Setup(map.Locations[0].RootSite, map.Locations[0].Pos, map.Locations[0].Rot);
            while (_debugCreator.Tick())
            {
                ;
            }
            return(true);
        }
Esempio n. 2
0
 public void Update()
 {
     try
     {
         if (firstTime)
         {
             var r = new Random(0);
             firstTime = false;
             foreach (var site in _debugCreator.Sites)
             {
                 if (site.Def.Type.Def != null && site.Def.Type.Def.EntitiesToSpawnOn.Count > 0)
                 {
                     var randomEntity = site.Def.Type.Def.EntitiesToSpawnOn[r.Next(site.Def.Type.Def.EntitiesToSpawnOn.Count)].Def;
                     var objId        = _node.Create(EntityObjectsMap.GetTypeFromDef(randomEntity), e =>
                     {
                         ((IEntityObject)e).Def          = randomEntity;
                         ((IPositionedEntity)e).Position = site.GlobalPos;
                         ((IPositionedEntity)e).Rotation = site.GlobalRot;
                     });
                     if (site.Def.AttachedScene != null)
                     {
                         _node.Create <SceneEntity>(se =>
                         {
                             se.Position = site.GlobalPos;
                             se.Rotation = site.GlobalRot;
                             se.SceneDef = site.Def.AttachedScene;
                         });
                     }
                 }
             }
             if (_debugCreator._rootInstance.Def.AttachedScene != null)
             {
                 _node.Create <SceneEntity>(se =>
                 {
                     se.Position = _debugCreator._rootInstance.GlobalPos;
                     se.Rotation = _debugCreator._rootInstance.GlobalRot;
                     se.SceneDef = _debugCreator._rootInstance.Def.AttachedScene;
                 });
             }
         }
         var deltaTime = EnvironmentAPI.Time.DeltaTime;
         foreach (var ghost in _node.AllGhosts())
         {
             if (ghost is ICharacterLikeMovement charLikeMovement)
             {
                 if (charLikeMovement.PhysicsBody == null)
                 {
                     var pos = ((IPositionedEntity)ghost).Position;
                     lock (_physicsWorld)
                     {
                         var circleShape = _physicsWorld.CreateCircleWorldSpace(new Vector2(pos.X, pos.Y), 1f, 1);
                         var body        = _physicsWorld.CreateDynamicBody(new Vector2(pos.X, pos.Y), 1, circleShape);
                         body.UserData = ghost.Id;
                         charLikeMovement.PhysicsBody = body;
                     }
                 }
                 charLikeMovement.InterpolationUpdate(deltaTime);
             }
         }
         var tick = _node.Tick();
         lock (_physicsWorld)
         {
             _physicsWorld.DeltaTime = EnvironmentAPI.Time.DeltaTime;
             _physicsWorld.Update();
         }
         tick.Wait();
     }
     catch (Exception e)
     {
         Logger.LogError?.Invoke(e.ToString());
     }
 }