Exemplo n.º 1
0
 public ObjectComponent(GameObject obj)
 {
     this.Obj = obj;
     renderInfo = new WorldObjectRenderInfo();
     if (obj.OBJ.BaseGraphicID > 0)
     {
         var gid = obj.OBJ.BaseGraphicID;
         this.DrawGroup = obj.Resource.Get<DGRP>(gid);
         dgrp = new DGRPRenderer(this.DrawGroup);
         dgrp.DynamicSpriteBaseID = obj.OBJ.DynamicSpriteBaseId;
         dgrp.NumDynamicSprites = obj.OBJ.NumDynamicSprites;
     }
 }
Exemplo n.º 2
0
        public override void PreDraw(GraphicsDevice gd, WorldState state)
        {
            //var oht = state.BaseHeight;
            //state.BaseHeight = 0;
            var pxOffset = -state.WorldSpace.GetScreenOffset();
            //state.BaseHeight = oht;
            var damage = Blueprint.Damage;
            var _2d    = state._2D;

            /**
             * Tasks:
             *  If zoom or rotation has changed, redraw all static layers
             *  If scroll has changed, redraw static layer if the scroll is outwith the buffered region
             *  If architecture has changed, redraw appropriate static layer
             *  If there is a new object in the static layer, redraw the static layer
             *  If an objects in the static layer has changed, redraw the static layer and move the object to the dynamic layer
             *  If wall visibility has changed, redraw wall layer (should think about how this works with breakthrough wall mode
             */

            var im = state.ThisFrameImmediate;

            var recacheWalls   = false;
            var recacheCutaway = false;
            var recacheFloors  = false;
            var recacheTerrain = false;
            var recacheObjects = false;
            var drawImmediate  = false;

            var lightChangeType = 0;

            if (Math.Abs(Blueprint.OutsideTime - LastTimeOfDay) > 0.001f)
            {
                damage.Add(new BlueprintDamage(BlueprintDamageType.OUTDOORS_LIGHTING_CHANGED));
                LastTimeOfDay = Blueprint.OutsideTime;
            }

            WorldObjectRenderInfo info = null;

            foreach (var item in damage)
            {
                switch (item.Type)
                {
                case BlueprintDamageType.ROTATE:
                case BlueprintDamageType.ZOOM:
                case BlueprintDamageType.LEVEL_CHANGED:
                    recacheObjects = true;
                    recacheWalls   = true;
                    recacheFloors  = true;
                    state.Light?.InvalidateOutdoors();
                    //recacheTerrain = true;
                    break;

                case BlueprintDamageType.SCROLL:
                    break;

                case BlueprintDamageType.PRECISE_ZOOM:
                    drawImmediate = true;
                    break;

                case BlueprintDamageType.LIGHTING_CHANGED:
                    if (lightChangeType >= 2)
                    {
                        break;
                    }
                    var room = (ushort)item.TileX;

                    state.Light?.InvalidateRoom(room);
                    Blueprint.GenerateRoomLights();
                    state.OutsideColor   = Blueprint.RoomColors[1];
                    state._3D.RoomLights = Blueprint.RoomColors;
                    state.OutsidePx.SetData(new Color[] { new Color(Blueprint.OutsideColor, (Blueprint.OutsideColor.R + Blueprint.OutsideColor.G + Blueprint.OutsideColor.B) / (255 * 3f)) });
                    if (state.AmbientLight != null)
                    {
                        state.AmbientLight.SetData(Blueprint.RoomColors);
                    }
                    TicksSinceLight = 0;
                    break;

                case BlueprintDamageType.OUTDOORS_LIGHTING_CHANGED:
                    if (lightChangeType >= 1)
                    {
                        break;
                    }
                    lightChangeType = 1;

                    Blueprint.GenerateRoomLights();
                    state.OutsideColor   = Blueprint.RoomColors[1];
                    state._3D.RoomLights = Blueprint.RoomColors;
                    state.OutsidePx.SetData(new Color[] { new Color(Blueprint.OutsideColor, (Blueprint.OutsideColor.R + Blueprint.OutsideColor.G + Blueprint.OutsideColor.B) / (255 * 3f)) });
                    if (state.AmbientLight != null)
                    {
                        state.AmbientLight.SetData(Blueprint.RoomColors);
                    }
                    state.Light?.InvalidateOutdoors();

                    TicksSinceLight = 0;
                    break;

                case BlueprintDamageType.OBJECT_MOVE:
                    /** Redraw if its in static layer **/

                    /*
                     * info = GetRenderInfo(item.Component);
                     * if (info.Layer == WorldObjectRenderLayer.STATIC)
                     * {
                     *  recacheObjects = true;
                     *  info.Layer = WorldObjectRenderLayer.DYNAMIC;
                     * }
                     * if (item.Component is ObjectComponent) ((ObjectComponent)item.Component).DynamicCounter = 0;*/
                    break;

                case BlueprintDamageType.OBJECT_GRAPHIC_CHANGE:
                    /** Redraw if its in static layer **/

                    /*
                     *  info = GetRenderInfo(item.Component);
                     *  if (info.Layer == WorldObjectRenderLayer.STATIC)
                     *  {
                     * recacheObjects = true;
                     * info.Layer = WorldObjectRenderLayer.DYNAMIC;
                     *  }
                     *  if (item.Component is ObjectComponent) ((ObjectComponent)item.Component).DynamicCounter = 0;*/
                    break;

                case BlueprintDamageType.OBJECT_RETURN_TO_STATIC:
                    /*
                     * info = GetRenderInfo(item.Component);
                     * if (info.Layer == WorldObjectRenderLayer.DYNAMIC)
                     * {
                     *  recacheObjects = true;
                     *  info.Layer = WorldObjectRenderLayer.STATIC;
                     * }*/
                    break;

                case BlueprintDamageType.WALL_CUT_CHANGED:
                    recacheCutaway = true;
                    break;

                case BlueprintDamageType.ROOF_STYLE_CHANGED:
                    Blueprint.RoofComp.StyleDirty = true;
                    break;

                case BlueprintDamageType.ROOM_CHANGED:
                    for (sbyte i = 0; i < Blueprint.RoomMap.Length; i++)
                    {
                        state.Rooms.SetRoomMap(i, Blueprint.RoomMap[i]);
                    }
                    if (state.Light != null)
                    {
                        if (lightChangeType < 2)
                        {
                            lightChangeType = 2;
                            state.Light.InvalidateAll();
                        }
                    }
                    Blueprint.Indoors             = null;
                    Blueprint.RoofComp.ShapeDirty = true;
                    break;

                case BlueprintDamageType.FLOOR_CHANGED:
                case BlueprintDamageType.WALL_CHANGED:
                    recacheFloors = true;
                    recacheWalls  = true;
                    Blueprint.RoofComp.ShapeDirty = true;
                    break;
                }
            }
            damage.Clear();

            if (recacheTerrain)
            {
                Blueprint.Terrain.RegenTerrain(gd, Blueprint);
            }

            if (recacheWalls)
            {
                Blueprint.WCRC?.Generate(gd, state, false);
            }
            else if (recacheCutaway)
            {
                Blueprint.WCRC?.Generate(gd, state, true);
            }

            if (recacheFloors)
            {
                Blueprint.FloorGeom.FullReset(gd, state.BuildMode > 1);
            }

            if (Drawn)
            {
                state.Light?.ParseInvalidated((sbyte)(state.Level + ((state.DrawRoofs) ? 1 : 0)), state);
            }

            if (recacheObjects)
            {
                /* objects no longer statically cached?
                 * _2d.Pause();
                 * _2d.Resume();
                 *
                 * foreach (var obj in Blueprint.Objects)
                 * {
                 *  if (obj.Level > state.Level) continue;
                 *  var renderInfo = GetRenderInfo(obj);
                 *  if (renderInfo.Layer == WorldObjectRenderLayer.STATIC)
                 *  {
                 *      var tilePosition = obj.Position;
                 *      _2d.OffsetPixel(state.WorldSpace.GetScreenFromTile(tilePosition));
                 *      _2d.OffsetTile(tilePosition);
                 *      _2d.SetObjID(obj.ObjectID);
                 *      obj.Draw(gd, state);
                 *  }
                 * }
                 * ClearDrawBuffer(StaticObjectsCache);
                 * _2d.End(StaticObjectsCache, true);
                 */
            }

            state.ThisFrameImmediate = drawImmediate;
        }