public void LoadMap(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException();
            }
            _tileEngineMap?.Dispose();

            //_tileEngineMap = new ZipMapContainer(filePath);
            CreateMapContainer(filePath);

            _typeManager         = new TypeManager();
            TypeManager.Instance = _typeManager;

            ScriptingManager.Instance = new ScriptingManager();

            if (_tileEngineMap != null)
            {
                GameResources.Instance.LoadResourcesFromMap(_tileEngineMap);
                ScriptingManager.Instance.LoadTypesFromMap(_tileEngineMap, "Scripts");
            }

            _scene = Scene.CreateFromMap(_tileEngineMap, "main.scene");
            InitializeFields();
        }
Exemple #2
0
        /// <summary>
        /// The main function in the sample.
        /// </summary>
        /// <param name="args"></param>
        public override void SampleCall(string[] args)
        {
            #region Parse Arguments
            ArgParser cmdLineParser = new ArgParser();
            if (!cmdLineParser.Parse(args))
            {
                // parse failed
                PrintUsage(INVALID_ARGUMENTS_ERROR);
                return;
            }
            #endregion

            #region Initialize properties from command line
            // Initialize the properties.
            ContextProperties contextProps = new ContextProperties();
            SessionProperties sessionProps = SampleUtils.NewSessionPropertiesFromConfig(cmdLineParser.Config);
            #endregion

            // Define IContext and ISession and ITopic.
            IContext context = null;
            ISession session = null;
            ITopic   topic   = null;
            try
            {
                InitContext(cmdLineParser.LogLevel);
                Console.WriteLine("About to create the Context ...");
                context = ContextFactory.Instance.CreateContext(contextProps, null);
                Console.WriteLine("Context successfully created. ");

                Console.WriteLine("About to create the Session ...");
                session = context.CreateSession(sessionProps,
                                                PrintReceivedMessage,
                                                SampleUtils.HandleSessionEvent);
                Console.WriteLine("Session successfully created.");

                Console.WriteLine("About to connect the Session ...");
                if (session.Connect() == ReturnCode.SOLCLIENT_OK)
                {
                    Console.WriteLine("Session successfully connected");
                    Console.WriteLine(GetRouterInfo(session));
                }

                topic = ContextFactory.Instance.CreateTopic(SampleUtils.SAMPLE_TOPIC);

                Console.WriteLine("About to subscribe to topic " + SampleUtils.SAMPLE_TOPIC);
                if (session.Subscribe(topic, true) == ReturnCode.SOLCLIENT_OK)
                {
                    Console.WriteLine("Successfully added topic subscription");
                }

                // Create the message independent stream.
                IStreamContainer stream = SDTUtils.CreateStream(1024);

                // Populate the stream.
                stream.AddDouble(3.141592654);
                stream.AddString("message");

                // Create the message-independent map.
                IMapContainer map = SDTUtils.CreateMap(1024);

                // Add a well known integer to the map.
                map.AddInt32("mersenne", 43112609);

                // Create the message.
                IMessage message = ContextFactory.Instance.CreateMessage();

                // Set the message delivery options.
                message.DeliveryMode = MessageDeliveryMode.Direct;
                message.Destination  = topic;

                int numMsgsToSend = 10;
                Console.WriteLine(string.Format("About to send {0} messages ...", numMsgsToSend));
                for (int i = 0; i < numMsgsToSend; i++)
                {
                    // Overwrite the "message" field, set the container, and send.
                    map.DeleteField("message");
                    map.AddString("message", "message" + (i + 1));
                    // Set the user property map to the map.
                    message.UserPropertyMap = map;
                    SDTUtils.SetSDTContainer(message, stream);
                    session.Send(message);
                }

                // Dispose of the map, stream, and message.
                map.Dispose();
                stream.Dispose();
                message.Dispose();

                Thread.Sleep(500); // wait for 0.5 seconds
                Console.WriteLine("\nDone");
            }
            catch (Exception ex)
            {
                PrintException(ex);
            }
            finally
            {
                if (session != null)
                {
                    if (topic != null)
                    {
                        session.Unsubscribe(topic, true);
                    }
                    session.Dispose();
                }
                if (context != null)
                {
                    context.Dispose();
                }
                // Must cleanup after.
                CleanupContext();
            }
        }