Example #1
0
        public static void CreateFont(DrawEngine2d drawEngine2d)
        {
            //These two should be in sync all the time.
            //They should be unified by combining the upper and lower data
            // into a single UInt and kept as a single dict.
            var upper = new Dictionary<Char, UInt32>();
            var lower = new Dictionary<Char, UInt32>();

            PopulateDicts(ref upper, ref lower);

            Int32 textureWidth = MaxTextureCharCapacity * FontWidth;
            Int32 textureHeight = FontHeight;

            Byte[] texturePixels = new Byte[textureWidth * textureHeight];

            //This loop references only one of the two glyph dicts but
            // that is just a convenience. The data from both will be
            // used during the loop.
            foreach(Char c in upper.Keys)
                DecodePixelData(ref upper, ref lower, ref texturePixels, c, textureWidth);

            Texture2dPlus texture = new Texture2dPlus(drawEngine2d,TextureCachePolicy.KeepAlways, TextureKey, textureWidth, textureHeight, PixelFormat.Luminance);
            texture.SetPixels(0, texturePixels, PixelFormat.Luminance);
            texture.SetFilter(TextureFilterMode.Nearest, TextureFilterMode.Nearest, TextureFilterMode.Nearest);

            TiledTexture tiledTexture = new TiledTexture(drawEngine2d,TextureCachePolicy.KeepAlways, DebugFont.TextureKey, texture);
            tiledTexture.CreateColumnIndex(MaxTextureCharCapacity);
        }
        protected override void Initialize()
        {
            //TODO: Remove this after testing!
            DrawEngine2d.ClearColor = Colors.Blue;
            //EnableDebugInfo();

            String shipSprite = "/Application/TwinStickShooter/Images/Ship64.png";
            Texture2dPlus t2d = new Texture2dPlus(DrawEngine2d, TextureCachePolicy.DisposeAfterLastUse, shipSprite);
            TiledTexture tt = new TiledTexture(DrawEngine2d, TextureCachePolicy.DisposeAfterLastUse, shipSprite, t2d);
            tt.CreateColumnIndex(1);

            LayerBase l2 = DrawEngine2d.GetOrCreateWorldLayer(1);

            SpriteGroup sssg = new SpriteGroup(l2, tt);
            SpriteGroupItem sss1 = new SpriteGroupItem(sssg, new TiledTextureIndex(0));
            sss1.SetPositionFromCenter(new Coordinate2(32f, 32f));
            SpriteGroupItem sss2 = new SpriteGroupItem(sssg, new TiledTextureIndex(0));
            sss2.SetPositionFromCenter(new Coordinate2(96f, 32f));
            //sss2.Rotation = 45.0f;

            Texture2dPlus testT2d = DrawEngine2d.GetTexture(DebugFont.TextureKey);
            TiledTexture ttTest = new TiledTexture(DrawEngine2d, TextureCachePolicy.DisposeAfterLastUse, "test", testT2d);
            ttTest.CreateColumnIndex(1);
            SpriteGroup testSG = new SpriteGroup(l2, ttTest);
            SpriteGroupItem testSS = new SpriteGroupItem(testSG, new TiledTextureIndex(0));
            testSS.Position = new Coordinate2(32f, 200f);

            LayerBase debugOverlay = DrawEngine2d.GetOrCreateScreenLayer(2);
            _DebugTextLabel = new DebugLabel(debugOverlay);
            _DebugTextLabel.Text = "I";
            _DebugTextLabel.Position = new Coordinate2(100.0f, 100.0f);
        }
        internal void RegisterTexture(String key, Texture2dPlus texture, TextureCachePolicy cachePolicy)
        {
            if(String.IsNullOrWhiteSpace(key))
                throw new ArgumentNullException();

            if(texture == null)
                throw new ArgumentNullException();

            if(Textures.ContainsKey(key))
                throw new ArgumentException("Attempt to register duplicate key.");

            Textures.Add(key, texture);
            CachePolicies.Add(key, cachePolicy);
            Users.Add(key, new List<TiledTexture>());
        }
Example #4
0
        private void CleanupTexture2dManager()
        {
            //Textures
            Texture2dPlus[] cleanup = new Texture2dPlus[Textures.Values.Count];
            Textures.Values.CopyTo(cleanup, 0);
            foreach(Texture2dPlus t in cleanup)
                t.Dispose();
            Textures.Clear();
            Textures = null;

            //Cache
            Texture2dPlusCachePolicies.Clear();
            Texture2dPlusCachePolicies = null;

            //Users
            foreach(List<TiledTexture> list in Texture2dPlusUsers.Values)
                list.Clear();
            Texture2dPlusUsers.Clear();
            Texture2dPlusUsers = null;
        }
Example #5
0
 public TiledTexture(DrawEngine2d drawEngine2d, TextureCachePolicy cachePolicy, String key, Texture2dPlus texture)
 {
     Initialize(drawEngine2d, cachePolicy, key, texture);
 }
Example #6
0
        private void InitializeTexture2d(Texture2dPlus texture)
        {
            if(Texture != null)
                throw new NotSupportedException("Cannot initialize object more than once.");

            if(texture == null)
                throw new ArgumentNullException();

            Path = null;
            Texture = texture;

            RegisterAsUserOfTexture2d();
        }
Example #7
0
        private void InitializeTexture2d(String path)
        {
            if(Texture != null)
                throw new NotSupportedException("Cannot initialize object more than once.");

            if(String.IsNullOrWhiteSpace(path))
                throw new ArgumentException();

            Path = path;
            Texture = new Texture2dPlus(DrawEngine2d, TextureCachePolicy.DisposeAfterLastUse, path);

            RegisterAsUserOfTexture2d();
        }
Example #8
0
        private void Initialize(DrawEngine2d drawEngine2d, TextureCachePolicy cachePolicy, String key, Texture2dPlus texture)
        {
            InitializeDrawEngine2d(drawEngine2d, cachePolicy, key);
            InitializeTexture2d(texture);

            InitializeColumnIndex();
            InitializeGridIndex();
            InitializeNamedIndex();
        }
Example #9
0
        private void CleanupTexture2d()
        {
            UnregisterAsUserOfTexture2d();

            Texture = null;
            Path = null;
        }
Example #10
0
 internal TiledTexture(TiledTextureManager tileMgr, String key, Texture2dPlus texture, TextureCachePolicy cachePolicy = TextureCachePolicy.DisposeAfterLastUse)
 {
     Initialize(tileMgr, key, texture, cachePolicy);
 }
Example #11
0
        private void InitializeTexture2d(String path)
        {
            if(Texture != null)
                throw new InvalidOperationException("Cannot initialize object more than once.");

            if(String.IsNullOrWhiteSpace(path))
                throw new ArgumentException();

            Path = path;
            Texture = TiledTextureManager.DrawEngine2d.Textures.CreateTexture(path, CachePolicy);

            RegisterAsUserOfTexture2d();
        }
Example #12
0
 private void Initialize(TiledTextureManager tileMgr, String key, Texture2dPlus texture, TextureCachePolicy cachePolicy)
 {
     InitializeTiledTextureManager(tileMgr);
     InitializeKey(key, cachePolicy);
     InitializeTexture2d(texture);
     InitializeIndexes();
 }
 public TiledTexture CreateTiledTexture(String key, Texture2dPlus texture, TextureCachePolicy cachePolicy = TextureCachePolicy.DisposeAfterLastUse)
 {
     return new TiledTexture(this, key, texture, cachePolicy);
 }
Example #14
0
 private void CleanupTextures()
 {
     Texture2dPlus[] cleanup = new Texture2dPlus[Textures.Values.Count];
     Textures.Values.CopyTo(cleanup, 0);
     foreach(Texture2dPlus t in cleanup)
         t.Dispose();
     Textures.Clear();
     Textures = null;
 }