diff --git a/spine-xna/example/spine-xna-example.csproj b/spine-xna/example/spine-xna-example.csproj index b68f4539d..70102e75f 100644 --- a/spine-xna/example/spine-xna-example.csproj +++ b/spine-xna/example/spine-xna-example.csproj @@ -1,227 +1,227 @@ - - - - {29CC4385-294A-4885-A3E8-FD4825E0CFDD} - {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Debug - x86 - WinExe - Properties - Spine - spine-xna-example - v4.0 - Client - v4.0 - Windows - HiDef - bf3b738e-f348-48d3-b35b-94bc118edb90 - Game - Game.ico - GameThumbnail.png - false - - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - true - - - true - full - false - bin\x86\Debug - DEBUG;TRACE;WINDOWS - prompt - 4 - true - false - x86 - True - - - pdbonly - true - bin\x86\Release - TRACE;WINDOWS - prompt - 4 - true - false - x86 - True - - - Spine.ExampleProgram - - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - False - - - - - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - {94144e22-2431-4a8f-ac04-dec22f7edd8f} - spine-csharp - - - {D0632D20-BC92-4A73-896B-30BB687732B8} - spine-xna-example-content - Content - - - {7F8F2327-C016-49C8-BB4D-F3F77971961E} - spine-xna - - - - - False - Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - false - - - False - Windows Installer 3.1 - true - - - False - Microsoft XNA Framework Redistributable 4.0 - true - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - - + + + + {29CC4385-294A-4885-A3E8-FD4825E0CFDD} + {6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Debug + x86 + WinExe + Properties + Spine + spine-xna-example + v4.0 + Client + v4.0 + Windows + HiDef + bf3b738e-f348-48d3-b35b-94bc118edb90 + Game + Game.ico + GameThumbnail.png + false + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + true + + + true + full + false + bin\x86\Debug + DEBUG;TRACE;WINDOWS + prompt + 4 + true + false + x86 + True + + + pdbonly + true + bin\x86\Release + TRACE;WINDOWS + prompt + 4 + true + false + x86 + True + + + Spine.ExampleProgram + + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + False + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + {94144e22-2431-4a8f-ac04-dec22f7edd8f} + spine-csharp + + + {D0632D20-BC92-4A73-896B-30BB687732B8} + spine-xna-example-content + Content + + + {7F8F2327-C016-49C8-BB4D-F3F77971961E} + spine-xna + + + + + False + Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + + + False + Microsoft XNA Framework Redistributable 4.0 + true + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + \ No newline at end of file diff --git a/spine-xna/example/src/ExampleGame.cs b/spine-xna/example/src/ExampleGame.cs index 7ef9f4c05..1f1480f55 100644 --- a/spine-xna/example/src/ExampleGame.cs +++ b/spine-xna/example/src/ExampleGame.cs @@ -1,253 +1,253 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -using System; -using System.IO; -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Audio; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using Microsoft.Xna.Framework.Media; -using Spine; - -namespace Spine { - public class Example : Microsoft.Xna.Framework.Game { - GraphicsDeviceManager graphics; - SkeletonRenderer skeletonRenderer; - SkeletonDebugRenderer skeletonDebugRenderer; - Skeleton skeleton; - Slot headSlot; - AnimationState state; - SkeletonBounds bounds = new SkeletonBounds(); - -#if WINDOWS_STOREAPP - private string assetsFolder = @"Assets\"; -#else - private string assetsFolder = "data/"; -#endif - - public Example () { - IsMouseVisible = true; - - graphics = new GraphicsDeviceManager(this); - graphics.IsFullScreen = false; - graphics.PreferredBackBufferWidth = 800; - graphics.PreferredBackBufferHeight = 600; - } - - protected override void Initialize () { - // TODO: Add your initialization logic here - - base.Initialize(); - } - - protected override void LoadContent () { - - bool useNormalmapShader = false; - Effect spineEffect; - if (!useNormalmapShader) { - // Two color tint effect. Note that you can also use the default BasicEffect instead. - spineEffect = Content.Load("spine-xna-example-content\\SpineEffect"); - } - else { - spineEffect = Content.Load("spine-xna-example-content\\SpineEffectNormalmap"); - spineEffect.Parameters["Light0_Direction"].SetValue(new Vector3(-0.5265408f, 0.5735765f, -0.6275069f)); - spineEffect.Parameters["Light0_Diffuse"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f)); - spineEffect.Parameters["Light0_Specular"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f)); - spineEffect.Parameters["Light0_SpecularExponent"].SetValue(2.0f); - } - spineEffect.Parameters["World"].SetValue(Matrix.Identity); - spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up)); - - skeletonRenderer = new SkeletonRenderer(GraphicsDevice); - skeletonRenderer.PremultipliedAlpha = false; - skeletonRenderer.Effect = spineEffect; - - skeletonDebugRenderer = new SkeletonDebugRenderer(GraphicsDevice); - skeletonDebugRenderer.DisableAll(); - skeletonDebugRenderer.DrawClipping = true; - - // String name = "spineboy-ess"; - // String name = "goblins-pro"; - String name = "raptor-pro"; - // String name = "tank-pro"; - //String name = "coin-pro"; - if (useNormalmapShader) - name = "raptor-pro"; // we only have normalmaps for raptor - String atlasName = name.Replace("-pro", "").Replace("-ess", ""); - if (name == "goblins-pro") atlasName = "goblins-mesh"; - bool binaryData = false; - - Atlas atlas; - if (!useNormalmapShader) { - atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice)); - } - else { - atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice, - loadMultipleTextureLayers: true, textureSuffixes: new string[] { "", "_normals" })); - } - float scale = 1; - if (name == "spineboy-ess") scale = 0.6f; - if (name == "raptor-pro") scale = 0.5f; - if (name == "tank-pro") scale = 0.3f; - if (name == "coin-pro") scale = 1; - - SkeletonData skeletonData; - if (binaryData) { - SkeletonBinary binary = new SkeletonBinary(atlas); - binary.Scale = scale; - skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel"); - } else { - SkeletonJson json = new SkeletonJson(atlas); - json.Scale = scale; - skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json"); - } - skeleton = new Skeleton(skeletonData); - if (name == "goblins-pro") skeleton.SetSkin("goblin"); - - // Define mixing between animations. - AnimationStateData stateData = new AnimationStateData(skeleton.Data); - state = new AnimationState(stateData); - - if (name == "spineboy-ess") { - skeleton.SetAttachment("head-bb", "head"); - - stateData.SetMix("run", "jump", 0.2f); - stateData.SetMix("jump", "run", 0.4f); - - // Event handling for all animations. - state.Start += Start; - state.End += End; - state.Complete += Complete; - state.Event += Event; - - state.SetAnimation(0, "run", true); - TrackEntry entry = state.AddAnimation(0, "jump", false, 0); - entry.End += End; // Event handling for queued animations. - state.AddAnimation(0, "run", true, 0); - } - else if (name == "raptor-pro") { - state.SetAnimation(0, "walk", true); - state.AddAnimation(1, "gun-grab", false, 2); - } - else if (name == "coin-pro") { - state.SetAnimation(0, "animation", true); - } - else if (name == "tank-pro") { - skeleton.X += 300; - state.SetAnimation(0, "drive", true); - } - else { - state.SetAnimation(0, "walk", true); - } - - skeleton.X += 400; - skeleton.Y += GraphicsDevice.Viewport.Height; - skeleton.UpdateWorldTransform(); - - headSlot = skeleton.FindSlot("head"); - } - - protected override void UnloadContent () { - // TODO: Unload any non ContentManager content here - } - - protected override void Update (GameTime gameTime) { - // TODO: Add your update logic here -#if (!WINDOWS_STOREAPP || WINDOWS_PHONE81) && !IOS - if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) - this.Exit(); -#endif - base.Update(gameTime); - } - - protected override void Draw (GameTime gameTime) { - GraphicsDevice.Clear(Color.Black); - - state.Update(gameTime.ElapsedGameTime.Milliseconds / 1000f); - state.Apply(skeleton); - skeleton.UpdateWorldTransform(); - if (skeletonRenderer.Effect is BasicEffect) { - ((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1, 0); - } else { - skeletonRenderer.Effect.Parameters["Projection"].SetValue(Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1, 0)); - } - skeletonRenderer.Begin(); - skeletonRenderer.Draw(skeleton); - skeletonRenderer.End(); - - skeletonDebugRenderer.Effect.Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1, 0); - skeletonDebugRenderer.Begin(); - skeletonDebugRenderer.Draw(skeleton); - skeletonDebugRenderer.End(); - - bounds.Update(skeleton, true); - MouseState mouse = Mouse.GetState(); - if (headSlot != null) { - headSlot.G = 1; - headSlot.B = 1; - if (bounds.AabbContainsPoint(mouse.X, mouse.Y)) { - BoundingBoxAttachment hit = bounds.ContainsPoint(mouse.X, mouse.Y); - if (hit != null) { - headSlot.G = 0; - headSlot.B = 0; - } - } - } - - base.Draw(gameTime); - } - - public void Start (TrackEntry entry) { -#if !WINDOWS_STOREAPP - Console.WriteLine(entry + ": start"); -#endif - } - - public void End (TrackEntry entry) { -#if !WINDOWS_STOREAPP - Console.WriteLine(entry + ": end"); -#endif - } - - public void Complete (TrackEntry entry) { -#if !WINDOWS_STOREAPP - Console.WriteLine(entry + ": complete "); -#endif - } - - public void Event (TrackEntry entry, Event e) { -#if !WINDOWS_STOREAPP - Console.WriteLine(entry + ": event " + e); -#endif - } - } -} +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated January 1, 2020. Replaces all prior versions. + * + * Copyright (c) 2013-2020, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, + * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +using System; +using System.IO; +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Media; +using Spine; + +namespace Spine { + public class Example : Microsoft.Xna.Framework.Game { + GraphicsDeviceManager graphics; + SkeletonRenderer skeletonRenderer; + SkeletonDebugRenderer skeletonDebugRenderer; + Skeleton skeleton; + Slot headSlot; + AnimationState state; + SkeletonBounds bounds = new SkeletonBounds(); + +#if WINDOWS_STOREAPP + private string assetsFolder = @"Assets\"; +#else + private string assetsFolder = "data/"; +#endif + + public Example () { + IsMouseVisible = true; + + graphics = new GraphicsDeviceManager(this); + graphics.IsFullScreen = false; + graphics.PreferredBackBufferWidth = 800; + graphics.PreferredBackBufferHeight = 600; + } + + protected override void Initialize () { + // TODO: Add your initialization logic here + + base.Initialize(); + } + + protected override void LoadContent () { + + bool useNormalmapShader = false; + Effect spineEffect; + if (!useNormalmapShader) { + // Two color tint effect. Note that you can also use the default BasicEffect instead. + spineEffect = Content.Load("spine-xna-example-content\\SpineEffect"); + } + else { + spineEffect = Content.Load("spine-xna-example-content\\SpineEffectNormalmap"); + spineEffect.Parameters["Light0_Direction"].SetValue(new Vector3(-0.5265408f, 0.5735765f, -0.6275069f)); + spineEffect.Parameters["Light0_Diffuse"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f)); + spineEffect.Parameters["Light0_Specular"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f)); + spineEffect.Parameters["Light0_SpecularExponent"].SetValue(2.0f); + } + spineEffect.Parameters["World"].SetValue(Matrix.Identity); + spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up)); + + skeletonRenderer = new SkeletonRenderer(GraphicsDevice); + skeletonRenderer.PremultipliedAlpha = false; + skeletonRenderer.Effect = spineEffect; + + skeletonDebugRenderer = new SkeletonDebugRenderer(GraphicsDevice); + skeletonDebugRenderer.DisableAll(); + skeletonDebugRenderer.DrawClipping = true; + + // String name = "spineboy-ess"; + // String name = "goblins-pro"; + String name = "raptor-pro"; + // String name = "tank-pro"; + //String name = "coin-pro"; + if (useNormalmapShader) + name = "raptor-pro"; // we only have normalmaps for raptor + String atlasName = name.Replace("-pro", "").Replace("-ess", ""); + if (name == "goblins-pro") atlasName = "goblins-mesh"; + bool binaryData = false; + + Atlas atlas; + if (!useNormalmapShader) { + atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice)); + } + else { + atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice, + loadMultipleTextureLayers: true, textureSuffixes: new string[] { "", "_normals" })); + } + float scale = 1; + if (name == "spineboy-ess") scale = 0.6f; + if (name == "raptor-pro") scale = 0.5f; + if (name == "tank-pro") scale = 0.3f; + if (name == "coin-pro") scale = 1; + + SkeletonData skeletonData; + if (binaryData) { + SkeletonBinary binary = new SkeletonBinary(atlas); + binary.Scale = scale; + skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel"); + } else { + SkeletonJson json = new SkeletonJson(atlas); + json.Scale = scale; + skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json"); + } + skeleton = new Skeleton(skeletonData); + if (name == "goblins-pro") skeleton.SetSkin("goblin"); + + // Define mixing between animations. + AnimationStateData stateData = new AnimationStateData(skeleton.Data); + state = new AnimationState(stateData); + + if (name == "spineboy-ess") { + skeleton.SetAttachment("head-bb", "head"); + + stateData.SetMix("run", "jump", 0.2f); + stateData.SetMix("jump", "run", 0.4f); + + // Event handling for all animations. + state.Start += Start; + state.End += End; + state.Complete += Complete; + state.Event += Event; + + state.SetAnimation(0, "run", true); + TrackEntry entry = state.AddAnimation(0, "jump", false, 0); + entry.End += End; // Event handling for queued animations. + state.AddAnimation(0, "run", true, 0); + } + else if (name == "raptor-pro") { + state.SetAnimation(0, "walk", true); + state.AddAnimation(1, "gun-grab", false, 2); + } + else if (name == "coin-pro") { + state.SetAnimation(0, "animation", true); + } + else if (name == "tank-pro") { + skeleton.X += 300; + state.SetAnimation(0, "drive", true); + } + else { + state.SetAnimation(0, "walk", true); + } + + skeleton.X += 400; + skeleton.Y += GraphicsDevice.Viewport.Height; + skeleton.UpdateWorldTransform(); + + headSlot = skeleton.FindSlot("head"); + } + + protected override void UnloadContent () { + // TODO: Unload any non ContentManager content here + } + + protected override void Update (GameTime gameTime) { + // TODO: Add your update logic here +#if (!WINDOWS_STOREAPP || WINDOWS_PHONE81) && !IOS + if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) + this.Exit(); +#endif + base.Update(gameTime); + } + + protected override void Draw (GameTime gameTime) { + GraphicsDevice.Clear(Color.Black); + + state.Update(gameTime.ElapsedGameTime.Milliseconds / 1000f); + state.Apply(skeleton); + skeleton.UpdateWorldTransform(); + if (skeletonRenderer.Effect is BasicEffect) { + ((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1, 0); + } else { + skeletonRenderer.Effect.Parameters["Projection"].SetValue(Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1, 0)); + } + skeletonRenderer.Begin(); + skeletonRenderer.Draw(skeleton); + skeletonRenderer.End(); + + skeletonDebugRenderer.Effect.Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1, 0); + skeletonDebugRenderer.Begin(); + skeletonDebugRenderer.Draw(skeleton); + skeletonDebugRenderer.End(); + + bounds.Update(skeleton, true); + MouseState mouse = Mouse.GetState(); + if (headSlot != null) { + headSlot.G = 1; + headSlot.B = 1; + if (bounds.AabbContainsPoint(mouse.X, mouse.Y)) { + BoundingBoxAttachment hit = bounds.ContainsPoint(mouse.X, mouse.Y); + if (hit != null) { + headSlot.G = 0; + headSlot.B = 0; + } + } + } + + base.Draw(gameTime); + } + + public void Start (TrackEntry entry) { +#if !WINDOWS_STOREAPP + Console.WriteLine(entry + ": start"); +#endif + } + + public void End (TrackEntry entry) { +#if !WINDOWS_STOREAPP + Console.WriteLine(entry + ": end"); +#endif + } + + public void Complete (TrackEntry entry) { +#if !WINDOWS_STOREAPP + Console.WriteLine(entry + ": complete "); +#endif + } + + public void Event (TrackEntry entry, Event e) { +#if !WINDOWS_STOREAPP + Console.WriteLine(entry + ": event " + e); +#endif + } + } +} diff --git a/spine-xna/src/MeshBatcher.cs b/spine-xna/src/MeshBatcher.cs index 5a81d2575..bcca36aeb 100644 --- a/spine-xna/src/MeshBatcher.cs +++ b/spine-xna/src/MeshBatcher.cs @@ -1,195 +1,195 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework; - -namespace Spine { - public struct VertexPositionColorTextureColor : IVertexType { - public Vector3 Position; - public Color Color; - public Vector2 TextureCoordinate; - public Color Color2; - - public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration - ( - new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), - new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0), - new VertexElement(16, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0), - new VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 1) - ); - - VertexDeclaration IVertexType.VertexDeclaration { - get { return VertexDeclaration; } - } - } - - // #region License - // /* - // Microsoft Public License (Ms-PL) - // MonoGame - Copyright � 2009 The MonoGame Team - // - // All rights reserved. - // - // This license governs use of the accompanying software. If you use the software, you accept this license. If you do not - // accept the license, do not use the software. - // - // 1. Definitions - // The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under - // U.S. copyright law. - // - // A "contribution" is the original software, or any additions or changes to the software. - // A "contributor" is any person that distributes its contribution under this license. - // "Licensed patents" are a contributor's patent claims that read directly on its contribution. - // - // 2. Grant of Rights - // (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, - // each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. - // (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, - // each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. - // - // 3. Conditions and Limitations - // (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. - // (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, - // your patent license from such contributor to the software ends automatically. - // (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution - // notices that are present in the software. - // (D) If you distribute any portion of the software in source code form, you may do so only under this license by including - // a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object - // code form, you may only do so under a license that complies with this license. - // (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees - // or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent - // permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular - // purpose and non-infringement. - // */ - // #endregion License - // - - /// Draws batched meshes. - public class MeshBatcher { - private readonly List items; - private readonly Queue freeItems; - private VertexPositionColorTextureColor[] vertexArray = { }; - private short[] triangles = { }; - - public MeshBatcher () { - items = new List(256); - freeItems = new Queue(256); - EnsureCapacity(256, 512); - } - - /// Returns a pooled MeshItem. - public MeshItem NextItem (int vertexCount, int triangleCount) { - MeshItem item = freeItems.Count > 0 ? freeItems.Dequeue() : new MeshItem(); - if (item.vertices.Length < vertexCount) item.vertices = new VertexPositionColorTextureColor[vertexCount]; - if (item.triangles.Length < triangleCount) item.triangles = new int[triangleCount]; - item.vertexCount = vertexCount; - item.triangleCount = triangleCount; - items.Add(item); - return item; - } - - private void EnsureCapacity (int vertexCount, int triangleCount) { - if (vertexArray.Length < vertexCount) vertexArray = new VertexPositionColorTextureColor[vertexCount]; - if (triangles.Length < triangleCount) triangles = new short[triangleCount]; - } - - public void Draw (GraphicsDevice device) { - if (items.Count == 0) return; - - int itemCount = items.Count; - int vertexCount = 0, triangleCount = 0; - for (int i = 0; i < itemCount; i++) { - MeshItem item = items[i]; - vertexCount += item.vertexCount; - triangleCount += item.triangleCount; - } - EnsureCapacity(vertexCount, triangleCount); - - vertexCount = 0; - triangleCount = 0; - Texture2D lastTexture = null; - for (int i = 0; i < itemCount; i++) { - MeshItem item = items[i]; - int itemVertexCount = item.vertexCount; - - if (item.texture != lastTexture || vertexCount + itemVertexCount > short.MaxValue) { - FlushVertexArray(device, vertexCount, triangleCount); - vertexCount = 0; - triangleCount = 0; - lastTexture = item.texture; - device.Textures[0] = lastTexture; - if (item.textureLayers != null) { - for (int layer = 1; layer < item.textureLayers.Length; ++layer) - device.Textures[layer] = item.textureLayers[layer]; - } - } - - int[] itemTriangles = item.triangles; - int itemTriangleCount = item.triangleCount; - for (int ii = 0, t = triangleCount; ii < itemTriangleCount; ii++, t++) - triangles[t] = (short)(itemTriangles[ii] + vertexCount); - triangleCount += itemTriangleCount; - - Array.Copy(item.vertices, 0, vertexArray, vertexCount, itemVertexCount); - vertexCount += itemVertexCount; - } - FlushVertexArray(device, vertexCount, triangleCount); - } - - public void AfterLastDrawPass () { - int itemCount = items.Count; - for (int i = 0; i < itemCount; i++) { - var item = items[i]; - item.texture = null; - freeItems.Enqueue(item); - } - items.Clear(); - } - - private void FlushVertexArray (GraphicsDevice device, int vertexCount, int triangleCount) { - if (vertexCount == 0) return; - device.DrawUserIndexedPrimitives( - PrimitiveType.TriangleList, - vertexArray, 0, vertexCount, - triangles, 0, triangleCount / 3, - VertexPositionColorTextureColor.VertexDeclaration); - } - } - - public class MeshItem { - public Texture2D texture = null; - public Texture2D[] textureLayers = null; - public int vertexCount, triangleCount; - public VertexPositionColorTextureColor[] vertices = { }; - public int[] triangles = { }; - } -} +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated January 1, 2020. Replaces all prior versions. + * + * Copyright (c) 2013-2020, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, + * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; + +namespace Spine { + public struct VertexPositionColorTextureColor : IVertexType { + public Vector3 Position; + public Color Color; + public Vector2 TextureCoordinate; + public Color Color2; + + public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration + ( + new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), + new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0), + new VertexElement(16, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0), + new VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 1) + ); + + VertexDeclaration IVertexType.VertexDeclaration { + get { return VertexDeclaration; } + } + } + + // #region License + // /* + // Microsoft Public License (Ms-PL) + // MonoGame - Copyright � 2009 The MonoGame Team + // + // All rights reserved. + // + // This license governs use of the accompanying software. If you use the software, you accept this license. If you do not + // accept the license, do not use the software. + // + // 1. Definitions + // The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under + // U.S. copyright law. + // + // A "contribution" is the original software, or any additions or changes to the software. + // A "contributor" is any person that distributes its contribution under this license. + // "Licensed patents" are a contributor's patent claims that read directly on its contribution. + // + // 2. Grant of Rights + // (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, + // each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. + // (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, + // each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. + // + // 3. Conditions and Limitations + // (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. + // (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, + // your patent license from such contributor to the software ends automatically. + // (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution + // notices that are present in the software. + // (D) If you distribute any portion of the software in source code form, you may do so only under this license by including + // a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object + // code form, you may only do so under a license that complies with this license. + // (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees + // or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent + // permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular + // purpose and non-infringement. + // */ + // #endregion License + // + + /// Draws batched meshes. + public class MeshBatcher { + private readonly List items; + private readonly Queue freeItems; + private VertexPositionColorTextureColor[] vertexArray = { }; + private short[] triangles = { }; + + public MeshBatcher () { + items = new List(256); + freeItems = new Queue(256); + EnsureCapacity(256, 512); + } + + /// Returns a pooled MeshItem. + public MeshItem NextItem (int vertexCount, int triangleCount) { + MeshItem item = freeItems.Count > 0 ? freeItems.Dequeue() : new MeshItem(); + if (item.vertices.Length < vertexCount) item.vertices = new VertexPositionColorTextureColor[vertexCount]; + if (item.triangles.Length < triangleCount) item.triangles = new int[triangleCount]; + item.vertexCount = vertexCount; + item.triangleCount = triangleCount; + items.Add(item); + return item; + } + + private void EnsureCapacity (int vertexCount, int triangleCount) { + if (vertexArray.Length < vertexCount) vertexArray = new VertexPositionColorTextureColor[vertexCount]; + if (triangles.Length < triangleCount) triangles = new short[triangleCount]; + } + + public void Draw (GraphicsDevice device) { + if (items.Count == 0) return; + + int itemCount = items.Count; + int vertexCount = 0, triangleCount = 0; + for (int i = 0; i < itemCount; i++) { + MeshItem item = items[i]; + vertexCount += item.vertexCount; + triangleCount += item.triangleCount; + } + EnsureCapacity(vertexCount, triangleCount); + + vertexCount = 0; + triangleCount = 0; + Texture2D lastTexture = null; + for (int i = 0; i < itemCount; i++) { + MeshItem item = items[i]; + int itemVertexCount = item.vertexCount; + + if (item.texture != lastTexture || vertexCount + itemVertexCount > short.MaxValue) { + FlushVertexArray(device, vertexCount, triangleCount); + vertexCount = 0; + triangleCount = 0; + lastTexture = item.texture; + device.Textures[0] = lastTexture; + if (item.textureLayers != null) { + for (int layer = 1; layer < item.textureLayers.Length; ++layer) + device.Textures[layer] = item.textureLayers[layer]; + } + } + + int[] itemTriangles = item.triangles; + int itemTriangleCount = item.triangleCount; + for (int ii = 0, t = triangleCount; ii < itemTriangleCount; ii++, t++) + triangles[t] = (short)(itemTriangles[ii] + vertexCount); + triangleCount += itemTriangleCount; + + Array.Copy(item.vertices, 0, vertexArray, vertexCount, itemVertexCount); + vertexCount += itemVertexCount; + } + FlushVertexArray(device, vertexCount, triangleCount); + } + + public void AfterLastDrawPass () { + int itemCount = items.Count; + for (int i = 0; i < itemCount; i++) { + var item = items[i]; + item.texture = null; + freeItems.Enqueue(item); + } + items.Clear(); + } + + private void FlushVertexArray (GraphicsDevice device, int vertexCount, int triangleCount) { + if (vertexCount == 0) return; + device.DrawUserIndexedPrimitives( + PrimitiveType.TriangleList, + vertexArray, 0, vertexCount, + triangles, 0, triangleCount / 3, + VertexPositionColorTextureColor.VertexDeclaration); + } + } + + public class MeshItem { + public Texture2D texture = null; + public Texture2D[] textureLayers = null; + public int vertexCount, triangleCount; + public VertexPositionColorTextureColor[] vertices = { }; + public int[] triangles = { }; + } +} diff --git a/spine-xna/src/Util.cs b/spine-xna/src/Util.cs index 54d495ac5..5c6479ad8 100644 --- a/spine-xna/src/Util.cs +++ b/spine-xna/src/Util.cs @@ -1,79 +1,79 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -using System; -using System.IO; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -#if WINDOWS_STOREAPP -using System.Threading.Tasks; -using Windows.Storage; -#endif - -namespace Spine { - - static public class Util { -#if WINDOWS_STOREAPP - private static async Task LoadFile(GraphicsDevice device, String path) { - var folder = Windows.ApplicationModel.Package.Current.InstalledLocation; - var file = await folder.GetFileAsync(path).AsTask().ConfigureAwait(false); - try { - return Util.LoadTexture(device, await file.OpenStreamForReadAsync().ConfigureAwait(false)); - } catch (Exception ex) { - throw new Exception("Error reading texture file: " + path, ex); - } - } - - static public Texture2D LoadTexture (GraphicsDevice device, String path) { - return LoadFile(device, path).Result; - } -#else - static public Texture2D LoadTexture (GraphicsDevice device, String path) { - -#if WINDOWS_PHONE - Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(path); - using (Stream input = stream) { -#else - using (Stream input = new FileStream(path, FileMode.Open, FileAccess.Read)) { -#endif - try { - return Util.LoadTexture(device, input); - } catch (Exception ex) { - throw new Exception("Error reading texture file: " + path, ex); - } - } - } -#endif - - static public Texture2D LoadTexture (GraphicsDevice device, Stream input) { - return Texture2D.FromStream(device, input); - } - } -} +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated January 1, 2020. Replaces all prior versions. + * + * Copyright (c) 2013-2020, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, + * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +using System; +using System.IO; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +#if WINDOWS_STOREAPP +using System.Threading.Tasks; +using Windows.Storage; +#endif + +namespace Spine { + + static public class Util { +#if WINDOWS_STOREAPP + private static async Task LoadFile(GraphicsDevice device, String path) { + var folder = Windows.ApplicationModel.Package.Current.InstalledLocation; + var file = await folder.GetFileAsync(path).AsTask().ConfigureAwait(false); + try { + return Util.LoadTexture(device, await file.OpenStreamForReadAsync().ConfigureAwait(false)); + } catch (Exception ex) { + throw new Exception("Error reading texture file: " + path, ex); + } + } + + static public Texture2D LoadTexture (GraphicsDevice device, String path) { + return LoadFile(device, path).Result; + } +#else + static public Texture2D LoadTexture (GraphicsDevice device, String path) { + +#if WINDOWS_PHONE + Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(path); + using (Stream input = stream) { +#else + using (Stream input = new FileStream(path, FileMode.Open, FileAccess.Read)) { +#endif + try { + return Util.LoadTexture(device, input); + } catch (Exception ex) { + throw new Exception("Error reading texture file: " + path, ex); + } + } + } +#endif + + static public Texture2D LoadTexture (GraphicsDevice device, Stream input) { + return Texture2D.FromStream(device, input); + } + } +} diff --git a/spine-xna/src/XnaTextureLoader.cs b/spine-xna/src/XnaTextureLoader.cs index f31921cba..3aa77e5c1 100644 --- a/spine-xna/src/XnaTextureLoader.cs +++ b/spine-xna/src/XnaTextureLoader.cs @@ -1,94 +1,94 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -using System; -using System.IO; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace Spine { - public class XnaTextureLoader : TextureLoader { - GraphicsDevice device; - string[] textureLayerSuffixes = null; - - /// - /// Constructor. - /// - /// The graphics device to be used. - /// If true multiple textures layers - /// (e.g. a diffuse/albedo texture and a normal map) are loaded instead of a single texture. - /// Names are constructed based on suffixes added according to the textureSuffixes parameter. - /// If loadMultipleTextureLayers is true, the strings of this array - /// define the path name suffix of each layer to be loaded. Array size must be equal to the number of layers to be loaded. - /// The first array entry is the suffix to be replaced (e.g. "_albedo", or "" for a first layer without a suffix), - /// subsequent array entries contain the suffix to replace the first entry with (e.g. "_normals"). - /// - /// An example would be: - /// new string[] { "", "_normals" } for loading a base diffuse texture named "skeletonname.png" and - /// a normalmap named "skeletonname_normals.png". - public XnaTextureLoader (GraphicsDevice device, bool loadMultipleTextureLayers = false, string[] textureSuffixes = null) { - this.device = device; - if (loadMultipleTextureLayers) - this.textureLayerSuffixes = textureSuffixes; - } - - public void Load (AtlasPage page, String path) { - Texture2D texture = Util.LoadTexture(device, path); - page.width = texture.Width; - page.height = texture.Height; - - if (textureLayerSuffixes == null) { - page.rendererObject = texture; - } - else { - Texture2D[] textureLayersArray = new Texture2D[textureLayerSuffixes.Length]; - textureLayersArray[0] = texture; - for (int layer = 1; layer < textureLayersArray.Length; ++layer) { - string layerPath = GetLayerName(path, textureLayerSuffixes[0], textureLayerSuffixes[layer]); - textureLayersArray[layer] = Util.LoadTexture(device, layerPath); - } - page.rendererObject = textureLayersArray; - } - } - - public void Unload (Object texture) { - ((Texture2D)texture).Dispose(); - } - - private string GetLayerName (string firstLayerPath, string firstLayerSuffix, string replacementSuffix) { - - int suffixLocation = firstLayerPath.LastIndexOf(firstLayerSuffix + "."); - if (suffixLocation == -1) { - throw new Exception(string.Concat("Error composing texture layer name: first texture layer name '", firstLayerPath, - "' does not contain suffix to be replaced: '", firstLayerSuffix, "'")); - } - return firstLayerPath.Remove(suffixLocation, firstLayerSuffix.Length).Insert(suffixLocation, replacementSuffix); - } - } -} +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated January 1, 2020. Replaces all prior versions. + * + * Copyright (c) 2013-2020, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, + * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +using System; +using System.IO; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Spine { + public class XnaTextureLoader : TextureLoader { + GraphicsDevice device; + string[] textureLayerSuffixes = null; + + /// + /// Constructor. + /// + /// The graphics device to be used. + /// If true multiple textures layers + /// (e.g. a diffuse/albedo texture and a normal map) are loaded instead of a single texture. + /// Names are constructed based on suffixes added according to the textureSuffixes parameter. + /// If loadMultipleTextureLayers is true, the strings of this array + /// define the path name suffix of each layer to be loaded. Array size must be equal to the number of layers to be loaded. + /// The first array entry is the suffix to be replaced (e.g. "_albedo", or "" for a first layer without a suffix), + /// subsequent array entries contain the suffix to replace the first entry with (e.g. "_normals"). + /// + /// An example would be: + /// new string[] { "", "_normals" } for loading a base diffuse texture named "skeletonname.png" and + /// a normalmap named "skeletonname_normals.png". + public XnaTextureLoader (GraphicsDevice device, bool loadMultipleTextureLayers = false, string[] textureSuffixes = null) { + this.device = device; + if (loadMultipleTextureLayers) + this.textureLayerSuffixes = textureSuffixes; + } + + public void Load (AtlasPage page, String path) { + Texture2D texture = Util.LoadTexture(device, path); + page.width = texture.Width; + page.height = texture.Height; + + if (textureLayerSuffixes == null) { + page.rendererObject = texture; + } + else { + Texture2D[] textureLayersArray = new Texture2D[textureLayerSuffixes.Length]; + textureLayersArray[0] = texture; + for (int layer = 1; layer < textureLayersArray.Length; ++layer) { + string layerPath = GetLayerName(path, textureLayerSuffixes[0], textureLayerSuffixes[layer]); + textureLayersArray[layer] = Util.LoadTexture(device, layerPath); + } + page.rendererObject = textureLayersArray; + } + } + + public void Unload (Object texture) { + ((Texture2D)texture).Dispose(); + } + + private string GetLayerName (string firstLayerPath, string firstLayerSuffix, string replacementSuffix) { + + int suffixLocation = firstLayerPath.LastIndexOf(firstLayerSuffix + "."); + if (suffixLocation == -1) { + throw new Exception(string.Concat("Error composing texture layer name: first texture layer name '", firstLayerPath, + "' does not contain suffix to be replaced: '", firstLayerSuffix, "'")); + } + return firstLayerPath.Remove(suffixLocation, firstLayerSuffix.Length).Insert(suffixLocation, replacementSuffix); + } + } +}