/// <summary> /// Draw /// </summary> /// <param name="sprite"></param> /// <param name="skeletonMeshRenderer"></param> /// <param name="gameTime"></param> /// <param name="mapShiftX"></param> /// <param name="mapShiftY"></param> /// <param name="centerX"></param> /// <param name="centerY"></param> /// <param name="renderWidth"></param> /// <param name="renderHeight"></param> /// <param name="RenderObjectScaling"></param> /// <param name="mapRenderResolution"></param> /// <param name="TickCount"></param> public override void Draw(SpriteBatch sprite, SkeletonMeshRenderer skeletonMeshRenderer, GameTime gameTime, int mapShiftX, int mapShiftY, int centerX, int centerY, ReflectionDrawableBoundary drawReflectionInfo, int renderWidth, int renderHeight, float RenderObjectScaling, RenderResolution mapRenderResolution, int TickCount) { Point MousePos = Mouse.GetState().Position; // relative to the window already if ((mouseCursorItemStates & (int)MouseCursorItemStates.LeftPress) != (int)MouseCursorItemStates.LeftPress && (mouseCursorItemStates & (int)MouseCursorItemStates.RightPress) != (int)MouseCursorItemStates.RightPress) // default { base.Draw(sprite, skeletonMeshRenderer, gameTime, -MousePos.X, -MousePos.Y, centerX, centerY, drawReflectionInfo, renderWidth, renderHeight, RenderObjectScaling, mapRenderResolution, TickCount); } else // if left or right press is active, draw pressed state { cursorItemPressedState.Draw(sprite, skeletonMeshRenderer, gameTime, -MousePos.X, -MousePos.Y, centerX, centerY, drawReflectionInfo, renderWidth, renderHeight, RenderObjectScaling, mapRenderResolution, TickCount); } }
public void DrawBackground(Microsoft.Xna.Framework.Graphics.SpriteBatch sprite, SkeletonMeshRenderer meshRenderer, GameTime gameTime, int x, int y, Color color, bool flip, ReflectionDrawableBoundary drawReflectionInfo) { sprite.Draw(texture, new Rectangle(x, y, texture.Width, texture.Height), null, color, 0f, new Vector2(0f, 0f), flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0f); }
public void DrawObject(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, SkeletonMeshRenderer meshRenderer, GameTime gameTime, int mapShiftX, int mapShiftY, bool flip, ReflectionDrawableBoundary drawReflectionInfo) { int drawX = X - mapShiftX; int drawY = Y - mapShiftY; spriteBatch.Draw(texture, new Rectangle(drawX, drawY, texture.Width, texture.Height), null, // src rectangle Color.White, // color 0f, // angle new Vector2(0f, 0f), // origin flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, // flip 0f // layer depth ); if (drawReflectionInfo != null && drawReflectionInfo.Reflection) { const float reflectionAngle = 0f; // using flip instead of angle // TODO gradient in an optimized way.. hm spriteBatch.Draw(texture, new Rectangle(drawX, drawY, texture.Width, texture.Height), null, // src rectangle _REFLECTION_OPACITY_COLOR, reflectionAngle, new Vector2(0, -texture.Height), // origin flip ? SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically : SpriteEffects.None | SpriteEffects.FlipVertically, 0f // layer depth ); } }
/// <summary> /// Draw as object /// </summary> /// <param name="sprite"></param> /// <param name="skeletonMeshRenderer"></param> /// <param name="mapShiftX"></param> /// <param name="mapShiftY"></param> /// <param name="centerX"></param> /// <param name="centerY"></param> /// <param name="drawReflectionInfo">The reflection info to draw for this object. Null if none.</param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="TickCount">Ticks since system startup</param> public virtual void Draw(SpriteBatch sprite, SkeletonMeshRenderer skeletonMeshRenderer, GameTime gameTime, int mapShiftX, int mapShiftY, int centerX, int centerY, ReflectionDrawableBoundary drawReflectionInfo, int width, int height, float RenderObjectScaling, RenderResolution mapRenderResolution, int TickCount) { int shiftCenteredX = mapShiftX - centerX; int shiftCenteredY = mapShiftY - centerY; IDXObject drawFrame; if (notAnimated) { drawFrame = frame0; } else { drawFrame = GetCurrentFrame(TickCount); } if (IsFrameWithinView(drawFrame, shiftCenteredX, shiftCenteredY, width, height)) { drawFrame.DrawObject(sprite, skeletonMeshRenderer, gameTime, shiftCenteredX - _Position.X, shiftCenteredY - _Position.Y, flip, drawReflectionInfo // for map objects that are able to cast a reflection on items that are reflectable ); this._LastFrameDrawn = drawFrame; // set the last frame drawn } else { this._LastFrameDrawn = null; } }
protected override void UnloadContent() { if (audio != null) { //audio.Pause(); audio.Dispose(); } skeletonMeshRenderer.End(); _DxDeviceManager.EndDraw(); _DxDeviceManager.Dispose(); mapObjects_NPCs.Clear(); mapObjects_Mobs.Clear(); mapObjects_Reactors.Clear(); mapObjects_Portal.Clear(); backgrounds_front.Clear(); backgrounds_back.Clear(); texturePool.Dispose(); // clear prior mirror bottom boundary rect_mirrorBottom = new Rectangle(); mirrorBottomReflection = null; }
public override void Draw(SpriteBatch sprite, SkeletonMeshRenderer skeletonMeshRenderer, GameTime gameTime, int mapShiftX, int mapShiftY, int centerX, int centerY, ReflectionDrawableBoundary drawReflectionInfo, int renderWidth, int renderHeight, float RenderObjectScaling, RenderResolution mapRenderResolution, int TickCount) { if (((int)mapRenderResolution & screenMode) != screenMode || disabledBackground) // dont draw if the screenMode isnt for this { return; } IDXObject drawFrame = GetCurrentFrame(TickCount); int X = CalculateBackgroundPosX(drawFrame, mapShiftX, centerX, renderWidth, RenderObjectScaling); int Y = CalculateBackgroundPosY(drawFrame, mapShiftY, centerY, renderHeight, RenderObjectScaling); int _cx = cx == 0 ? drawFrame.Width : cx; int _cy = cy == 0 ? drawFrame.Height : cy; switch (type) { case BackgroundType.Regular: Draw2D(sprite, skeletonMeshRenderer, gameTime, X, Y, drawFrame); break; case BackgroundType.HorizontalTiling: DrawHorizontalCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, X, Y, _cx, drawFrame); break; case BackgroundType.VerticalTiling: DrawVerticalCopies(sprite, skeletonMeshRenderer, gameTime, renderHeight, X, Y, _cy, drawFrame); break; case BackgroundType.HVTiling: DrawHVCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, renderHeight, X, Y, _cx, _cy, drawFrame); break; case BackgroundType.HorizontalMoving: DrawHorizontalCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, X + (int)bgMoveShiftX, Y, _cx, drawFrame); IncreaseShiftX(_cx, TickCount); break; case BackgroundType.VerticalMoving: DrawVerticalCopies(sprite, skeletonMeshRenderer, gameTime, renderHeight, X, Y + (int)bgMoveShiftY, _cy, drawFrame); IncreaseShiftY(_cy, TickCount); break; case BackgroundType.HorizontalMovingHVTiling: DrawHVCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, renderHeight, X + (int)bgMoveShiftX, Y, _cx, _cy, drawFrame); IncreaseShiftX(_cx, TickCount); break; case BackgroundType.VerticalMovingHVTiling: DrawHVCopies(sprite, skeletonMeshRenderer, gameTime, renderWidth, renderHeight, X, Y + (int)bgMoveShiftY, _cx, _cy, drawFrame); IncreaseShiftX(_cy, TickCount); break; default: break; } }
/// <summary> /// Constructor /// Load from data /// </summary> /// <param name="board"></param> /// <param name="rect"></param> public MirrorFieldData(Board board, XNA.Rectangle rect, Vector2 offset, ReflectionDrawableBoundary reflectionInfo, MirrorFieldDataType mirrorFieldDataType) : base(board, rect) { this.reflectionInfo = reflectionInfo; this.mirrorFieldDataType = mirrorFieldDataType; this.offset = offset; }
public override void Draw(SpriteBatch sprite, SkeletonMeshRenderer skeletonMeshRenderer, GameTime gameTime, int mapShiftX, int mapShiftY, int centerX, int centerY, ReflectionDrawableBoundary drawReflectionInfo, int renderWidth, int renderHeight, float RenderObjectScaling, RenderResolution mapRenderResolution, int TickCount) { base.Draw(sprite, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, centerX, centerY, drawReflectionInfo, renderWidth, renderHeight, RenderObjectScaling, mapRenderResolution, TickCount); }
/*public override string ToString() * { * return "X: " + x.val.ToString() + ", Y: " + y.val.ToString(); * }*/ #endregion #region Serialization /// <summary> /// Constructor /// Load from serialized form /// </summary> /// <param name="board"></param> /// <param name="json"></param> public MirrorFieldData(Board board, SerializationForm json) : base(board, json) { mirrorFieldDataType = json.mirrorFieldDataType; offset = json.offset; reflectionInfo = new ReflectionDrawableBoundary( json.reflectionInfo.Gradient, json.reflectionInfo.Alpha, json.reflectionInfo.ObjectForOverlay, json.reflectionInfo.Reflection, json.reflectionInfo.AlphaTest); }
public override void Draw(SpriteBatch sprite, SkeletonMeshRenderer skeletonMeshRenderer, GameTime gameTime, int mapShiftX, int mapShiftY, int centerX, int centerY, ReflectionDrawableBoundary drawReflectionInfo, int RenderWidth, int RenderHeight, float RenderObjectScaling, RenderResolution mapRenderResolution, int TickCount) { // control minimap render UI position via // Position.X, Position.Y // Draw the main drame base.Draw(sprite, skeletonMeshRenderer, gameTime, 0, 0, centerX, centerY, drawReflectionInfo, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); int minimapPosX = (mapShiftX + (RenderWidth / 2)) / 16; int minimapPosY = (mapShiftY + (RenderHeight / 2)) / 16; item_pixelDot.Draw(sprite, skeletonMeshRenderer, gameTime, -Position.X, -Position.Y, minimapPosX, minimapPosY, drawReflectionInfo, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); //IDXObject lastFrameDrawn = base.LastFrameDrawn; //int minimapMainFrameWidth = lastFrameDrawn.Width; //int minimapMainFrameHeight = lastFrameDrawn.Height; // draw minimap buttons foreach (MapObjects.UIObject.UIObject uiBtn in uiButtons) { BaseDXDrawableItem buttonToDraw = uiBtn.GetBaseDXDrawableItemByState(); // Position drawn is relative to the MinimapItem int drawRelativeX = -(this.Position.X) - uiBtn.X; // Left to right int drawRelativeY = -(this.Position.Y) - uiBtn.Y; // Top to bottom buttonToDraw.Draw(sprite, skeletonMeshRenderer, gameTime, drawRelativeX, drawRelativeY, centerX, centerY, null, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); } }
public void DrawObject(SpriteBatch sprite, SkeletonMeshRenderer skeletonMeshRenderer, GameTime gameTime, int mapShiftX, int mapShiftY, bool flip, ReflectionDrawableBoundary drawReflectionInfo) { spineObject.state.Update(gameTime.ElapsedGameTime.Milliseconds / 1000f); spineObject.state.Apply(spineObject.skeleton); spineObject.skeleton.FlipX = flip; spineObject.skeleton.X = X - mapShiftX; spineObject.skeleton.Y = Y - mapShiftY; spineObject.skeleton.UpdateWorldTransform(); skeletonMeshRenderer.PremultipliedAlpha = spineObject.spineAnimationItem.PremultipliedAlpha; skeletonMeshRenderer.Begin(); skeletonMeshRenderer.Draw(spineObject.skeleton); skeletonMeshRenderer.End(); }
public void DrawBackground(SpriteBatch sprite, SkeletonMeshRenderer skeletonMeshRenderer, GameTime gameTime, int x, int y, Color color, bool flip, ReflectionDrawableBoundary drawReflectionInfo) { spineObject.state.Update(gameTime.ElapsedGameTime.Milliseconds / 1000f); spineObject.state.Apply(spineObject.skeleton); //if (spineObject.skeleton.FlipX != flip || spineObject.skeleton.X != x || spineObject.skeleton.Y != y) // reduce the number of updates [removed, recent spine object includes the ones that does not move] //{ spineObject.skeleton.FlipX = flip; spineObject.skeleton.X = x; //x + (Width); spineObject.skeleton.Y = y; //y + (Height / 2); spineObject.skeleton.UpdateWorldTransform(); //} skeletonMeshRenderer.PremultipliedAlpha = spineObject.spineAnimationItem.PremultipliedAlpha; skeletonMeshRenderer.Begin(); skeletonMeshRenderer.Draw(spineObject.skeleton); skeletonMeshRenderer.End(); }
protected override void Draw(GameTime gameTime) { float frameRate = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds; int TickCount = currTickCount; //float delta = gameTime.ElapsedGameTime.Milliseconds / 1000f; MouseState mouseState = this.oldMouseState; int mouseXRelativeToMap = mouseState.X - mapShiftX; int mouseYRelativeToMap = mouseState.Y - mapShiftY; //System.Diagnostics.Debug.WriteLine("Mouse relative to map: X {0}, Y {1}", mouseXRelativeToMap, mouseYRelativeToMap); int mapCenterX = mapBoard.CenterPoint.X; int mapCenterY = mapBoard.CenterPoint.Y; int shiftCenteredX = mapShiftX - mapCenterX; int shiftCenteredY = mapShiftY - mapCenterY; //GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 1.0f, 0); // Clear the window to black GraphicsDevice.Clear(Color.Black); spriteBatch.Begin( SpriteSortMode.Immediate, // spine :( needs to be drawn immediately to maintain the layer orders //SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, null, null, null, this.matrixScale); //skeletonMeshRenderer.Begin(); // Back Backgrounds backgrounds_back.ForEach(bg => { bg.Draw(spriteBatch, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, mapCenterX, mapCenterY, null, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); }); // Map objects foreach (List <BaseDXDrawableItem> mapItem in mapObjects) { foreach (BaseDXDrawableItem item in mapItem) { item.Draw(spriteBatch, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, mapCenterX, mapCenterY, null, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); } } // Portals foreach (PortalItem portalItem in mapObjects_Portal) { portalItem.Draw(spriteBatch, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, mapCenterX, mapCenterY, null, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); } // Reactors foreach (ReactorItem reactorItem in mapObjects_Reactors) { reactorItem.Draw(spriteBatch, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, mapCenterX, mapCenterY, null, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); } // Life (NPC + Mobs) foreach (MobItem mapMob in mapObjects_Mobs) // Mobs { ReflectionDrawableBoundary mirrorFieldData = null; if (mirrorBottomReflection != null) { if (rect_mirrorBottom.Contains(new Point(mapMob.MobInstance.X, mapMob.MobInstance.Y))) { mirrorFieldData = mirrorBottomReflection; } } if (mirrorFieldData == null) // a field may contain both 'info/mirror_Bottom' and 'MirrorFieldData' { mirrorFieldData = mapBoard.BoardItems.CheckObjectWithinMirrorFieldDataBoundary(mapMob.MobInstance.X, mapMob.MobInstance.Y, MirrorFieldDataType.mob)?.ReflectionInfo; } mapMob.Draw(spriteBatch, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, mapCenterX, mapCenterY, mirrorFieldData, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); } foreach (NpcItem mapNpc in mapObjects_NPCs) // NPCs (always in front of mobs) { ReflectionDrawableBoundary mirrorFieldData = null; if (mirrorBottomReflection != null) { if (rect_mirrorBottom.Contains(new Point(mapNpc.NpcInstance.X, mapNpc.NpcInstance.Y))) { mirrorFieldData = mirrorBottomReflection; } } if (mirrorFieldData == null) // a field may contain both 'info/mirror_Bottom' and 'MirrorFieldData' { mirrorFieldData = mapBoard.BoardItems.CheckObjectWithinMirrorFieldDataBoundary(mapNpc.NpcInstance.X, mapNpc.NpcInstance.Y, MirrorFieldDataType.npc)?.ReflectionInfo; } mapNpc.Draw(spriteBatch, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, mapCenterX, mapCenterY, mirrorFieldData, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); } // Front Backgrounds backgrounds_front.ForEach(bg => { bg.Draw(spriteBatch, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, mapCenterX, mapCenterY, null, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); }); // Borders // Create any rectangle you want. Here we'll use the TitleSafeArea for fun. //Rectangle titleSafeRectangle = GraphicsDevice.Viewport.TitleSafeArea; //DrawBorder(spriteBatch, titleSafeRectangle, 1, Color.Black); DrawVRFieldBorder(spriteBatch); //////////////////// UI related here //////////////////// // Tooltips if (mapObjects_tooltips.Count > 0) { foreach (TooltipItem tooltip in mapObjects_tooltips) // NPCs (always in front of mobs) { if (tooltip.TooltipInstance.CharacterToolTip != null) { Rectangle tooltipRect = tooltip.TooltipInstance.CharacterToolTip.Rectangle; if (tooltipRect != null) // if this is null, show it at all times { Rectangle rect = new Rectangle( tooltipRect.X - shiftCenteredX, tooltipRect.Y - shiftCenteredY, tooltipRect.Width, tooltipRect.Height); if (bShowDebugMode) { DrawBorder(spriteBatch, rect, 1, Color.White); // test spriteBatch.DrawString(font_DebugValues, "X: " + rect.X + ", Y: " + rect.Y, new Vector2(rect.X, rect.Y), Color.White); } if (!rect.Contains(mouseState.X, mouseState.Y)) { continue; } } } tooltip.Draw(spriteBatch, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, mapBoard.CenterPoint.X, mapBoard.CenterPoint.Y, null, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); } } // Minimap if (miniMap != null) { miniMap.Draw(spriteBatch, skeletonMeshRenderer, gameTime, mapShiftX, mapShiftY, minimapPos.X, minimapPos.Y, null, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); miniMap.CheckMouseEvent(shiftCenteredX, shiftCenteredY, mouseState); } if (gameTime.TotalGameTime.TotalSeconds < 4) { spriteBatch.DrawString(font_navigationKeysHelper, string.Format("[Left] [Right] [Up] [Down] [Shift] for navigation.{0}[F5] for debug mode{1}[Alt+Enter] Full screen{2}[PrintSc] Screenshot", Environment.NewLine, Environment.NewLine, Environment.NewLine), new Vector2(20, Height - 140), Color.White); } if (!bSaveScreenshot && bShowDebugMode) { StringBuilder sb = new StringBuilder(); sb.Append("FPS: ").Append(frameRate).Append(Environment.NewLine); sb.Append("Mouse : X ").Append(mouseXRelativeToMap).Append(", Y ").Append(mouseYRelativeToMap).Append(Environment.NewLine); sb.Append("RMouse: X ").Append(mouseState.X).Append(", Y ").Append(mouseState.Y); spriteBatch.DrawString(font_DebugValues, sb.ToString(), new Vector2(Width - 170, 10), Color.White); // use the original width to render text } // Cursor [this is in front of everything else] mouseCursor.Draw(spriteBatch, skeletonMeshRenderer, gameTime, 0, 0, 0, 0, // pos determined in the class null, RenderWidth, RenderHeight, RenderObjectScaling, mapRenderResolution, TickCount); spriteBatch.End(); //skeletonMeshRenderer.End(); // Save screenshot if render is activated DoScreenshot(); base.Draw(gameTime); }
/// <summary> /// Load game assets /// </summary> protected override void LoadContent() { WzDirectory MapWzFile = Program.WzManager["map"]; // Map.wz WzDirectory UIWZFile = Program.WzManager["ui"]; WzDirectory SoundWZFile = Program.WzManager["sound"]; this.bBigBangUpdate = UIWZFile["UIWindow2.img"]?["BigBang!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"] != null; // different rendering for pre and post-bb, to support multiple vers this.bBigBang2Update = UIWZFile["UIWindow2.img"]?["BigBang2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"] != null; // BGM if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm)) { audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true); if (audio != null) { audio.Volume = 0.3f; audio.Play(); } } if (mapBoard.VRRectangle == null) { vr_fieldBoundary = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y); } else { vr_fieldBoundary = new Rectangle(mapBoard.VRRectangle.X + mapBoard.CenterPoint.X, mapBoard.VRRectangle.Y + mapBoard.CenterPoint.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height); } //SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); // test benchmark #if DEBUG var watch = new System.Diagnostics.Stopwatch(); watch.Start(); #endif /////// Background and objects List <WzObject> usedProps = new List <WzObject>(); // Objects Task t_tiles = Task.Run(() => { foreach (LayeredItem tileObj in mapBoard.BoardItems.TileObjs) { WzImageProperty tileParent = (WzImageProperty)tileObj.BaseInfo.ParentObject; mapObjects[tileObj.LayerNumber].Add( MapSimulatorLoader.CreateMapItemFromProperty(texturePool, tileParent, tileObj.X, tileObj.Y, mapBoard.CenterPoint, _DxDeviceManager.GraphicsDevice, ref usedProps, tileObj is IFlippable ? ((IFlippable)tileObj).Flip : false)); } }); // Background Task t_Background = Task.Run(() => { foreach (BackgroundInstance background in mapBoard.BoardItems.BackBackgrounds) { WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject; backgrounds_back.Add( MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip)); } foreach (BackgroundInstance background in mapBoard.BoardItems.FrontBackgrounds) { WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject; backgrounds_front.Add( MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip)); } }); // Reactors Task t_reactor = Task.Run(() => { foreach (ReactorInstance reactor in mapBoard.BoardItems.Reactors) { //WzImage imageProperty = (WzImage)NPCWZFile[reactorInfo.ID + ".img"]; ReactorItem reactorItem = MapSimulatorLoader.CreateReactorFromProperty(texturePool, reactor, _DxDeviceManager.GraphicsDevice, ref usedProps); mapObjects_Reactors.Add(reactorItem); } }); // NPCs Task t_npc = Task.Run(() => { foreach (NpcInstance npc in mapBoard.BoardItems.NPCs) { //WzImage imageProperty = (WzImage) NPCWZFile[npcInfo.ID + ".img"]; if (npc.Hide) { continue; } NpcItem npcItem = MapSimulatorLoader.CreateNpcFromProperty(texturePool, npc, _DxDeviceManager.GraphicsDevice, ref usedProps); mapObjects_NPCs.Add(npcItem); } }); // Mobs Task t_mobs = Task.Run(() => { foreach (MobInstance mob in mapBoard.BoardItems.Mobs) { //WzImage imageProperty = Program.WzManager.FindMobImage(mobInfo.ID); // Mob.wz Mob2.img Mob001.wz if (mob.Hide) { continue; } MobItem npcItem = MapSimulatorLoader.CreateMobFromProperty(texturePool, mob, _DxDeviceManager.GraphicsDevice, ref usedProps); mapObjects_Mobs.Add(npcItem); } }); // Portals Task t_portal = Task.Run(() => { WzSubProperty portalParent = (WzSubProperty)MapWzFile["MapHelper.img"]["portal"]; WzSubProperty gameParent = (WzSubProperty)portalParent["game"]; //WzSubProperty editorParent = (WzSubProperty) portalParent["editor"]; foreach (PortalInstance portal in mapBoard.BoardItems.Portals) { PortalItem portalItem = MapSimulatorLoader.CreatePortalFromProperty(texturePool, gameParent, portal, _DxDeviceManager.GraphicsDevice, ref usedProps); if (portalItem != null) { mapObjects_Portal.Add(portalItem); } } }); // Tooltips Task t_tooltips = Task.Run(() => { WzSubProperty farmFrameParent = (WzSubProperty)UIWZFile["UIToolTip.img"]?["Item"]?["FarmFrame"]; foreach (ToolTipInstance tooltip in mapBoard.BoardItems.ToolTips) { TooltipItem item = MapSimulatorLoader.CreateTooltipFromProperty(texturePool, UserScreenScaleFactor, farmFrameParent, tooltip, _DxDeviceManager.GraphicsDevice); mapObjects_tooltips.Add(item); } }); // Cursor Task t_cursor = Task.Run(() => { WzImageProperty cursorImageProperty = (WzImageProperty)UIWZFile["Basic.img"]?["Cursor"]; this.mouseCursor = MapSimulatorLoader.CreateMouseCursorFromProperty(texturePool, cursorImageProperty, 0, 0, _DxDeviceManager.GraphicsDevice, ref usedProps, false); }); // Spine object Task t_spine = Task.Run(() => { skeletonMeshRenderer = new SkeletonMeshRenderer(GraphicsDevice) { PremultipliedAlpha = false, }; skeletonMeshRenderer.Effect.World = this.matrixScale; }); // Minimap Task t_minimap = Task.Run(() => { if (!mapBoard.MapInfo.hideMinimap) { miniMap = MapSimulatorLoader.CreateMinimapFromProperty(UIWZFile, mapBoard, GraphicsDevice, UserScreenScaleFactor, mapBoard.MapInfo.strMapName, mapBoard.MapInfo.strStreetName, SoundWZFile, bBigBangUpdate); } }); while (!t_tiles.IsCompleted || !t_Background.IsCompleted || !t_reactor.IsCompleted || !t_npc.IsCompleted || !t_mobs.IsCompleted || !t_portal.IsCompleted || !t_tooltips.IsCompleted || !t_cursor.IsCompleted || !t_spine.IsCompleted || !t_minimap.IsCompleted) { Thread.Sleep(100); } #if DEBUG // test benchmark watch.Stop(); Debug.WriteLine($"Map WZ files loaded. Execution Time: {watch.ElapsedMilliseconds} ms"); #endif // spriteBatch = new SpriteBatch(GraphicsDevice); // default positioning for character SetCameraMoveX(true, true, 0); SetCameraMoveY(true, true, 0); ///////////// Border int leftRightVRDifference = (int)((vr_fieldBoundary.Right - vr_fieldBoundary.Left) * RenderObjectScaling); if (leftRightVRDifference < RenderWidth) // viewing range is smaller than the render width.. { this.bDrawVRBorderLeftRight = true; // flag this.texture_vrBoundaryRectLeft = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice); this.texture_vrBoundaryRectRight = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice); this.texture_vrBoundaryRectTop = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice); this.texture_vrBoundaryRectBottom = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice); } // mirror bottom boundaries //rect_mirrorBottom if (mapBoard.MapInfo.mirror_Bottom) { if (mapBoard.MapInfo.VRLeft != null && mapBoard.MapInfo.VRRight != null) { int vr_width = (int)mapBoard.MapInfo.VRRight - (int)mapBoard.MapInfo.VRLeft; const int obj_mirrorBottom_height = 200; rect_mirrorBottom = new Rectangle((int)mapBoard.MapInfo.VRLeft, (int)mapBoard.MapInfo.VRBottom - obj_mirrorBottom_height, vr_width, obj_mirrorBottom_height); mirrorBottomReflection = new ReflectionDrawableBoundary(128, 255, "mirror", true, false); } } /* * DXObject leftDXVRObject = new DXObject( * vr_fieldBoundary.Left - VR_BORDER_WIDTHHEIGHT, * vr_fieldBoundary.Top, * texture_vrBoundaryRectLeft); * this.leftVRBorderDrawableItem = new BaseDXDrawableItem(leftDXVRObject, false); * //new BackgroundItem(int cx, int cy, int rx, int ry, BackgroundType.Regular, 255, true, leftDXVRObject, false, (int) RenderResolution.Res_All); * * // Right VR * DXObject rightDXVRObject = new DXObject( * vr_fieldBoundary.Right, * vr_fieldBoundary.Top, * texture_vrBoundaryRectRight); * this.rightVRBorderDrawableItem = new BaseDXDrawableItem(rightDXVRObject, false); */ ///////////// End Border // Debug items System.Drawing.Bitmap bitmap_debug = new System.Drawing.Bitmap(1, 1); bitmap_debug.SetPixel(0, 0, System.Drawing.Color.White); texture_debugBoundaryRect = bitmap_debug.ToTexture2D(_DxDeviceManager.GraphicsDevice); // cleanup // clear used items foreach (WzObject obj in usedProps) { // Spine events WzSpineObject spineObj = (WzSpineObject)obj.MSTagSpine; if (spineObj != null) { spineObj.state.Start += Start; spineObj.state.End += End; spineObj.state.Complete += Complete; spineObj.state.Event += Event; } obj.MSTag = null; obj.MSTagSpine = null; // cleanup } usedProps.Clear(); }