Esempio n. 1
0
        /// <summary>
        /// Verifies that all of created templates in the template context have an associated
        /// definition in the list of template definitions.
        /// </summary>
        private void VerifyReferenceDefinitions(GameEngineContext engineContext, TemplateConversionContext templateContext, List <ContentTemplateSerializationFormat> templateDefinitions)
        {
            // We only verify template definitions if we're restoring an for an engine; it does not
            // matter if the templates are not fully instantiated if we're only in content editing
            // mode, as no game code will be executed.
            // TODO: do we really want to do this?
            if (engineContext.GameEngine.IsEmpty)
            {
                return;
            }

            // Get all of the ids for templates that we can restore
            HashSet <int> restoredTemplates = new HashSet <int>();

            foreach (var restoredTemplate in templateDefinitions)
            {
                restoredTemplates.Add(restoredTemplate.TemplateId);
            }

            // For every template that we have already created a reference for, verify that we have
            // an associated definition
            foreach (var pair in templateContext.CreatedTemplates)
            {
                ITemplate template = pair.Value;

                if (restoredTemplates.Contains(template.TemplateId) == false)
                {
                    throw new InvalidOperationException("Found template reference with id=" +
                                                        template.TemplateId + ", but the ITemplateGroup had no corresponding " +
                                                        "template definition");
                }
            }
        }
Esempio n. 2
0
        protected override void OnSystemAdd()
        {
            _sceneSystem = Services.GetSafeServiceAs <SceneSystem>();

            _gameClockManager  = Services.GetSafeServiceAs <GameClockManager>();
            _gameEngineContext = Services.GetService <GameEngineContext>();
            _networkService    = Services.GetService <IGameNetworkService>();
        }
Esempio n. 3
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                EntitySerializationContainer container =
                    (EntitySerializationContainer)existingValue ?? new EntitySerializationContainer();

                var serializedEntities = serializer.Deserialize <List <ContentEntitySerializationFormat> >(reader);

                // We need to get our conversion context
                GeneralStreamingContext generalContext    = (GeneralStreamingContext)serializer.Context.Context;
                EntityConversionContext conversionContext = generalContext.Get <EntityConversionContext>();
                GameEngineContext       engineContext     = generalContext.Get <GameEngineContext>();

                // There is only an EventDispatcherContext when we have a GameEngineContext
                IEventDispatcher eventDispatcher = null;

                if (engineContext.GameEngine.Exists)
                {
                    EventDispatcherContext eventContext = generalContext.Get <EventDispatcherContext>();
                    eventDispatcher = eventContext.Dispatcher;
                }

                // Restore our created entity instances
                List <IEntity> restored = new List <IEntity>();

                foreach (ContentEntitySerializationFormat format in serializedEntities)
                {
                    int     entityId = format.UniqueId;
                    IEntity entity   = conversionContext.GetEntityInstance(entityId, engineContext);
                    restored.Add(entity);

                    if (entity is ContentEntity)
                    {
                        ((ContentEntity)entity).Initialize(format);
                    }
                    else
                    {
                        ((RuntimeEntity)entity).Initialize(format, eventDispatcher);
                    }
                }

                container.Entities = restored;
                return(container);
            }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, GameEngineContext context)
        {
            context.Database.Migrate();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(MyAllowSpecificOrigins);


            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseEndpoints(x => x.MapControllers());

            app.UseSwagger(c =>
            {
                c.SerializeAsV2 = true;
            });

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "game-engine");
                // Serve the swagger UI at the app's root
                c.RoutePrefix = string.Empty;
            });
        }
Esempio n. 5
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            TemplateSerializationContainer container =
                (TemplateSerializationContainer)existingValue ?? new TemplateSerializationContainer();

            List <ContentTemplateSerializationFormat> serializedTemplates = serializer.Deserialize <List <ContentTemplateSerializationFormat> >(reader);

            // We need to get our conversion context
            GeneralStreamingContext   generalContext    = (GeneralStreamingContext)serializer.Context.Context;
            TemplateConversionContext conversionContext = generalContext.Get <TemplateConversionContext>();
            GameEngineContext         engineContext     = generalContext.Get <GameEngineContext>();

            // TODO: if this method is really slow, then we can combine VerifyReferenceDefinitions
            //       and the
            // actual restoration process

            // Verify that we have restored all of our referenced templates
            VerifyReferenceDefinitions(engineContext, conversionContext, serializedTemplates);

            // Restore our created template instances
            foreach (ContentTemplateSerializationFormat format in serializedTemplates)
            {
                int       templateId = format.TemplateId;
                ITemplate template   = conversionContext.GetTemplateInstance(templateId, engineContext);

                if (template is ContentTemplate)
                {
                    ((ContentTemplate)template).Initialize(format);
                }
                else
                {
                    ((RuntimeTemplate)template).Initialize(format);
                }
            }

            container.Templates = conversionContext.CreatedTemplates.Select(p => p.Value).ToList();
            return(container);
        }
Esempio n. 6
0
 protected override void OnSystemAdd()
 {
     _gameClockManager  = Services.GetService <GameClockManager>();
     _gameEngineContext = Services.GetService <GameEngineContext>();
 }
Esempio n. 7
0
 public CharacterRepository(GameEngineContext context)
 {
     _context = context;
 }