Example #1
0
    public BitmapCi ToBitmap(GamePlatform p)
    {
        BitmapCi bmp = p.BitmapCreate(width, height);

        p.BitmapSetPixelsArgb(bmp, argb);
        return(bmp);
    }
Example #2
0
 public void UpdateThumbnails()
 {
     for (int i = 0; i < serversOnListCount; i++)
     {
         ServerOnList server = serversOnList[i];
         if (server == null)
         {
             continue;
         }
         if (server.thumbnailFetched)
         {
             //Thumbnail already loaded
             continue;
         }
         if (!server.thumbnailDownloading)
         {
             //Not started downloading yet
             thumbResponses[i] = new ThumbnailResponseCi();
             menu.p.ThumbnailDownloadAsync(server.ip, server.port, thumbResponses[i]);
             server.thumbnailDownloading = true;
         }
         else
         {
             //Download in progress
             if (thumbResponses[i] != null)
             {
                 if (thumbResponses[i].done)
                 {
                     //Request completed. load received bitmap
                     BitmapCi bmp = menu.p.BitmapCreateFromPng(thumbResponses[i].data, thumbResponses[i].dataLength);
                     if (bmp != null)
                     {
                         int texture = menu.p.LoadTextureFromBitmap(bmp);
                         menu.textures.Set(menu.p.StringFormat("serverlist_entry_{0}.png", server.hash), texture);
                         menu.p.BitmapDelete(bmp);
                     }
                     server.thumbnailDownloading = false;
                     server.thumbnailFetched     = true;
                 }
                 if (thumbResponses[i].error)
                 {
                     //Error while trying to download thumbnail
                     server.thumbnailDownloading = false;
                     server.thumbnailError       = true;
                     server.thumbnailFetched     = true;
                 }
             }
             else
             {
                 //An error occured. stop trying
                 server.thumbnailDownloading = false;
                 server.thumbnailError       = true;
                 server.thumbnailFetched     = true;
             }
         }
     }
 }
Example #3
0
 public static BitmapData_ CreateFromBitmap(GamePlatform p, BitmapCi atlas2d_)
 {
     BitmapData_ b = new BitmapData_();
     b.width = p.FloatToInt(p.BitmapGetWidth(atlas2d_));
     b.height = p.FloatToInt(p.BitmapGetHeight(atlas2d_));
     b.argb = new int[b.width * b.height];
     p.BitmapGetPixelsArgb(atlas2d_, b.argb);
     return b;
 }
Example #4
0
    public static BitmapData_ CreateFromBitmap(GamePlatform p, BitmapCi atlas2d_)
    {
        BitmapData_ b = new BitmapData_();

        b.width  = p.FloatToInt(p.BitmapGetWidth(atlas2d_));
        b.height = p.FloatToInt(p.BitmapGetHeight(atlas2d_));
        b.argb   = new int[b.width * b.height];
        p.BitmapGetPixelsArgb(atlas2d_, b.argb);
        return(b);
    }
Example #5
0
 internal int GetTexture(string name)
 {
     if (!textures.Contains(name))
     {
         BoolRef  found   = new BoolRef();
         BitmapCi bmp     = p.BitmapCreateFromPng(GetFile(name), GetFileLength(name));
         int      texture = p.LoadTextureFromBitmap(bmp);
         textures.Set(name, texture);
         p.BitmapDelete(bmp);
     }
     return(textures.Get(name));
 }
Example #6
0
    TextTexture GetTextTexture(string text, FontCi font)
    {
        for (int i = 0; i < textTexturesCount; i++)
        {
            TextTexture t = textTextures[i];
            if (t == null)
            {
                continue;
            }
            if (t.text == text &&
                t.font.size == font.size &&
                t.font.family == font.family &&
                t.font.style == font.style)
            {
                return(t);
            }
        }
        TextTexture textTexture = new TextTexture();

        Text_ text_ = new Text_();

        text_.text  = text;
        text_.font  = font;
        text_.color = Game.ColorFromArgb(255, 255, 255, 255);
        BitmapCi textBitmap = textColorRenderer.CreateTextTexture(text_);

        int texture = p.LoadTextureFromBitmap(textBitmap);

        IntRef textWidth  = new IntRef();
        IntRef textHeight = new IntRef();

        p.TextSize(text, font, textWidth, textHeight);

        textTexture.texture       = texture;
        textTexture.texturewidth  = p.FloatToInt(p.BitmapGetWidth(textBitmap));
        textTexture.textureheight = p.FloatToInt(p.BitmapGetHeight(textBitmap));
        textTexture.text          = text;
        textTexture.font          = font;
        textTexture.textwidth     = textWidth.value;
        textTexture.textheight    = textHeight.value;

        p.BitmapDelete(textBitmap);

        textTextures[textTexturesCount++] = textTexture;
        return(textTexture);
    }
    internal void DrawSkySphere(Game game)
    {
        if (skyspheretexture == -1)
        {
            BitmapCi skysphereBmp      = game.platform.BitmapCreateFromPng(game.GetFile("skysphere.png"), game.GetFileLength("skysphere.png"));
            BitmapCi skysphereNightBmp = game.platform.BitmapCreateFromPng(game.GetFile("skyspherenight.png"), game.GetFileLength("skyspherenight.png"));
            skyspheretexture      = game.platform.LoadTextureFromBitmap(skysphereBmp);
            skyspherenighttexture = game.platform.LoadTextureFromBitmap(skysphereNightBmp);
            game.platform.BitmapDelete(skysphereBmp);
            game.platform.BitmapDelete(skysphereNightBmp);
        }
        int texture = game.SkySphereNight ? skyspherenighttexture : skyspheretexture;

        if (game.shadowssimple) //d_Shadows.GetType() == typeof(ShadowsSimple))
        {
            texture = skyspheretexture;
        }
        SkyTexture = texture;
        Draw(game, game.currentfov());
    }
Example #8
0
    internal void DrawSkySphere(Game game)
    {
        if (!started)
        {
            started = true;
            BitmapCi skyBmp  = game.platform.BitmapCreateFromPng(game.GetFile("sky.png"), game.GetFileLength("sky.png"));
            BitmapCi glowBmp = game.platform.BitmapCreateFromPng(game.GetFile("glow.png"), game.GetFileLength("glow.png"));
            skyPixels  = new int[textureSize * textureSize * 4];
            glowPixels = new int[textureSize * textureSize * 4];
            game.platform.BitmapGetPixelsArgb(skyBmp, skyPixels);
            game.platform.BitmapGetPixelsArgb(glowBmp, glowPixels);
            game.platform.BitmapDelete(skyBmp);
            game.platform.BitmapDelete(glowBmp);
        }

        game.platform.GLDisableAlphaTest();
        game.platform.GlDisableDepthTest();
        Draw(game, game.currentfov());
        game.platform.GLEnableAlphaTest();
        game.platform.GlEnableDepthTest();
    }
Example #9
0
    //tiles = 16 means 16 x 16 atlas
    public BitmapCi[] Atlas2dInto1d(GamePlatform p, BitmapCi atlas2d_, int tiles, int atlassizezlimit, IntRef retCount)
    {
        BitmapData_ orig = BitmapData_.CreateFromBitmap(p, atlas2d_);

        int tilesize = orig.width / tiles;

        int atlasescount = MathCi.MaxInt(1, (tiles * tiles * tilesize) / atlassizezlimit);

        BitmapCi[] atlases      = new BitmapCi[128];
        int        atlasesCount = 0;

        BitmapData_ atlas1d = null;

        for (int i = 0; i < tiles * tiles; i++)
        {
            int x            = i % tiles;
            int y            = i / tiles;
            int tilesinatlas = (tiles * tiles / atlasescount);
            if (i % tilesinatlas == 0)
            {
                if (atlas1d != null)
                {
                    atlases[atlasesCount++] = atlas1d.ToBitmap(p);
                }
                atlas1d = BitmapData_.Create(tilesize, atlassizezlimit);
            }
            for (int xx = 0; xx < tilesize; xx++)
            {
                for (int yy = 0; yy < tilesize; yy++)
                {
                    int c = orig.GetPixel(x * tilesize + xx, y * tilesize + yy);
                    atlas1d.SetPixel(xx, (i % tilesinatlas) * tilesize + yy, c);
                }
            }
        }
        atlases[atlasesCount++] = atlas1d.ToBitmap(p);
        retCount.value          = atlasescount;
        return(atlases);
    }
Example #10
0
 public override void OnNewFrameDraw3d(Game game, float deltaTime)
 {
     if (ShouldDrawHand(game))
     {
         string img = HandImage2d(game);
         if (img != null)
         {
             game.OrthoMode(game.Width(), game.Height());
             if (lasthandimage != img)
             {
                 lasthandimage = img;
                 byte[]   file = game.GetFile(img);
                 BitmapCi bmp  = game.platform.BitmapCreateFromPng(file, game.platform.ByteArrayLength(file));
                 if (bmp != null)
                 {
                     game.handTexture = game.platform.LoadTextureFromBitmap(bmp);
                     game.platform.BitmapDelete(bmp);
                 }
             }
             game.Draw2dTexture(game.handTexture, game.Width() / 2, game.Height() - 512, 512, 512, null, 0, Game.ColorFromArgb(255, 255, 255, 255), false);
             game.PerspectiveMode();
         }
     }
 }
Example #11
0
    void UpdateAvi(float dt)
    {
        if (avi == null)
        {
            return;
        }
        if (!firstFrameDone)
        {
            // skip first frame, because screen is not redrawn yet.
            firstFrameDone = true;
            return;
        }
        writeAccum += dt;
        float totalTime = playingSpeed * TotalDistance();

        if (writeAccum >= one / framerate * recspeed)
        {
            writeAccum -= one / framerate * recspeed;

            BitmapCi bmp = m.GrabScreenshot();
            avi.AddFrame(bmp);
            bmp.Dispose();
        }
    }
Example #12
0
    //tiles = 16 means 16 x 16 atlas
    public BitmapCi[] Atlas2dInto1d(GamePlatform p, BitmapCi atlas2d_, int tiles, int atlassizezlimit, IntRef retCount)
    {
        BitmapData_ orig = BitmapData_.CreateFromBitmap(p, atlas2d_);

        int tilesize = orig.width / tiles;

        int atlasescount = MathCi.MaxInt(1, (tiles * tiles * tilesize) / atlassizezlimit);
        BitmapCi[] atlases = new BitmapCi[128];
        int atlasesCount = 0;

        BitmapData_ atlas1d = null;

        for (int i = 0; i < tiles * tiles; i++)
        {
            int x = i % tiles;
            int y = i / tiles;
            int tilesinatlas = (tiles * tiles / atlasescount);
            if (i % tilesinatlas == 0)
            {
                if (atlas1d != null)
                {
                    atlases[atlasesCount++] = atlas1d.ToBitmap(p);
                }
                atlas1d = BitmapData_.Create(tilesize, atlassizezlimit);
            }
            for (int xx = 0; xx < tilesize; xx++)
            {
                for (int yy = 0; yy < tilesize; yy++)
                {
                    int c = orig.GetPixel(x * tilesize + xx, y * tilesize + yy);
                    atlas1d.SetPixel(xx, (i % tilesinatlas) * tilesize + yy, c);
                }
            }
        }
        atlases[atlasesCount++] = atlas1d.ToBitmap(p);
        retCount.value = atlasescount;
        return atlases;
    }
Example #13
0
 public abstract int LoadTextureFromBitmap(BitmapCi bmp);
Example #14
0
 public abstract int LoadTextureFromBitmap(BitmapCi bmp);
Example #15
0
 public override float BitmapGetHeight(BitmapCi bmp)
 {
     BitmapCiCs bmp_ = (BitmapCiCs)bmp;
     return bmp_.bmp.Height;
 }
Example #16
0
 public abstract void BitmapGetPixelsArgb(BitmapCi bitmap, int[] bmpPixels);
Example #17
0
 internal int GetTextureOrLoad(string name, BitmapCi bmp)
 {
     if (!textures.Contains(name))
     {
         BoolRef found = new BoolRef();
         textures.Set(name, platform.LoadTextureFromBitmap(bmp));
     }
     return textures.Get(name);
 }
Example #18
0
 public override void BitmapDelete(BitmapCi bmp)
 {
     BitmapCiCs bmp_ = (BitmapCiCs)bmp;
     bmp_.bmp.Dispose();
 }
Example #19
0
 public abstract float BitmapGetHeight(BitmapCi bmp);
Example #20
0
 public override float BitmapGetWidth(BitmapCi bmp)
 {
     BitmapCiCs bmp_ = (BitmapCiCs)bmp;
     return bmp_.bmp.Width;
 }
Example #21
0
 public override void BitmapGetPixelsArgb(BitmapCi bitmap, int[] bmpPixels)
 {
     BitmapCiCs bmp = (BitmapCiCs)bitmap;
     int width = bmp.bmp.Width;
     int height = bmp.bmp.Height;
     if (IsMono)
     {
         for (int x = 0; x < width; x++)
         {
             for (int y = 0; y < height; y++)
             {
                 bmpPixels[x + y * width] = bmp.bmp.GetPixel(x, y).ToArgb();
             }
         }
     }
     else
     {
         FastBitmap fastbmp = new FastBitmap();
         fastbmp.bmp = bmp.bmp;
         fastbmp.Lock();
         for (int x = 0; x < width; x++)
         {
             for (int y = 0; y < height; y++)
             {
                 bmpPixels[x + y * width] = fastbmp.GetPixel(x, y);
             }
         }
         fastbmp.Unlock();
     }
 }
Example #22
0
 public override void BitmapSetPixelsArgb(BitmapCi bmp, int[] pixels)
 {
     BitmapCiCs bmp_ = (BitmapCiCs)bmp;
     int width = bmp_.bmp.Width;
     int height = bmp_.bmp.Height;
     if (IsMono)
     {
         for (int y = 0; y < height; y++)
         {
             for (int x = 0; x < width; x++)
             {
                 int color = pixels[x + y * width];
                 bmp_.bmp.SetPixel(x, y, Color.FromArgb(color));
             }
         }
     }
     else
     {
         FastBitmap fastbmp = new FastBitmap();
         fastbmp.bmp = bmp_.bmp;
         fastbmp.Lock();
         for (int x = 0; x < width; x++)
         {
             for (int y = 0; y < height; y++)
             {
                 fastbmp.SetPixel(x, y, pixels[x + y * width]);
             }
         }
         fastbmp.Unlock();
     }
 }
Example #23
0
    internal void LoadPlayerTextures(Game game)
    {
        if (!game.issingleplayer)
        {
            if (skinserverResponse.done)
            {
                skinserver = game.platform.StringFromUtf8ByteArray(skinserverResponse.value, skinserverResponse.valueLength);
            }
            else if (skinserverResponse.error)
            {
                skinserver = null;
            }
            else
            {
                return;
            }
        }
        for (int i = 0; i < game.entitiesCount; i++)
        {
            Entity e = game.entities[i];
            if (e == null)
            {
                continue;
            }
            if (e.drawModel == null)
            {
                continue;
            }
            if (e.drawModel.CurrentTexture != -1)
            {
                continue;
            }
            // a) download skin
            if (!game.issingleplayer && e.drawModel.DownloadSkin && skinserver != null && e.drawModel.Texture_ == null)
            {
                if (e.drawModel.SkinDownloadResponse == null)
                {
                    e.drawModel.SkinDownloadResponse = new HttpResponseCi();
                    string url = StringTools.StringAppend(game.platform, skinserver, StringTools.StringSubstringToEnd(game.platform, e.drawName.Name, 2));
                    url = StringTools.StringAppend(game.platform, url, ".png");
                    game.platform.WebClientDownloadDataAsync(url, e.drawModel.SkinDownloadResponse);
                    continue;
                }
                if (!e.drawModel.SkinDownloadResponse.error)
                {
                    if (!e.drawModel.SkinDownloadResponse.done)
                    {
                        continue;
                    }
                    BitmapCi bmp_ = game.platform.BitmapCreateFromPng(e.drawModel.SkinDownloadResponse.value, e.drawModel.SkinDownloadResponse.valueLength);
                    if (bmp_ != null)
                    {
                        e.drawModel.CurrentTexture = game.GetTextureOrLoad(e.drawName.Name, bmp_);
                        game.platform.BitmapDelete(bmp_);
                        continue;
                    }
                }
            }
            // b) file skin
            if (e.drawModel.Texture_ == null)
            {
                e.drawModel.CurrentTexture = game.GetTexture("mineplayer.png");
                continue;
            }

            byte[] file = game.GetFile(e.drawModel.Texture_);
            if (file == null)
            {
                e.drawModel.CurrentTexture = 0;
                continue;
            }
            BitmapCi bmp = game.platform.BitmapCreateFromPng(file, game.platform.ByteArrayLength(file));
            if (bmp == null)
            {
                e.drawModel.CurrentTexture = 0;
                continue;
            }
            e.drawModel.CurrentTexture = game.GetTextureOrLoad(e.drawModel.Texture_, bmp);
            game.platform.BitmapDelete(bmp);
        }
    }
Example #24
0
 internal void UseTerrainTextureAtlas2d(BitmapCi atlas2d, int atlas2dWidth)
 {
     terrainTexture = platform.LoadTextureFromBitmap(atlas2d);
     int[] terrainTextures1d_;
     int terrainTextures1dCount = 0;
     {
         terrainTexturesPerAtlas = atlas1dheight() / (atlas2dWidth / atlas2dtiles());
         IntRef atlasesidCount = new IntRef();
         BitmapCi[] atlases1d = d_TextureAtlasConverter.Atlas2dInto1d(platform, atlas2d, atlas2dtiles(), atlas1dheight(), atlasesidCount);
         terrainTextures1d_ = new int[atlasesidCount.value];
         for (int i = 0; i < atlasesidCount.value; i++)
         {
             BitmapCi bmp = atlases1d[i];
             int texture = platform.LoadTextureFromBitmap(bmp);
             terrainTextures1d_[terrainTextures1dCount++] = texture;
             platform.BitmapDelete(bmp);
         }
     }
     this.terrainTextures1d = terrainTextures1d_;
 }
Example #25
0
 public abstract void BitmapSetPixelsArgb(BitmapCi bmp, int[] pixels);
Example #26
0
 public abstract void BitmapGetPixelsArgb(BitmapCi bitmap, int[] bmpPixels);
Example #27
0
 public abstract float BitmapGetWidth(BitmapCi bmp);
Example #28
0
 public abstract float BitmapGetWidth(BitmapCi bmp);
Example #29
0
 public abstract void BitmapDelete(BitmapCi bmp);
Example #30
0
 public abstract void BitmapSetPixelsArgb(BitmapCi bmp, int[] pixels);
Example #31
0
    public override void AddFrame(BitmapCi bitmap)
    {
        var bmp_ = (BitmapCiCs)bitmap;

        using (Graphics g = Graphics.FromImage(openbmp))
        {
            g.DrawImage(bmp_.bmp, 0, 0);
        }
        openbmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

        avi.AddFrame();
    }
Example #32
0
 public abstract void AddFrame(BitmapCi bitmap);
Example #33
0
 public abstract void BitmapDelete(BitmapCi bmp);
Example #34
0
 public override int LoadTextureFromBitmap(BitmapCi bmp)
 {
     BitmapCiCs bmp_ = (BitmapCiCs)bmp;
     return LoadTexture(bmp_.bmp, false);
 }
Example #35
0
 public abstract float BitmapGetHeight(BitmapCi bmp);
Example #36
0
    /// <summary>
    /// Creates a bitmap from a given string
    /// </summary>
    /// <param name="t">The <see cref="Text_"/> object to create an image from</param>
    /// <returns>A <see cref="BitmapCi"/> containing the rendered text</returns>
    internal BitmapCi CreateTextTexture(Text_ t)
    {
        IntRef partsCount = new IntRef();

        TextPart[] parts = DecodeColors(t.text, t.color, partsCount);

        float totalwidth  = 0;
        float totalheight = 0;

        int[] sizesX = new int[partsCount.value];
        int[] sizesY = new int[partsCount.value];

        for (int i = 0; i < partsCount.value; i++)
        {
            IntRef outWidth  = new IntRef();
            IntRef outHeight = new IntRef();
            platform.TextSize(parts[i].text, t.font, outWidth, outHeight);

            sizesX[i] = outWidth.value;
            sizesY[i] = outHeight.value;

            totalwidth += outWidth.value;
            totalheight = MathCi.MaxFloat(totalheight, outHeight.value);
        }

        int      size2X = NextPowerOfTwo(platform.FloatToInt(totalwidth) + 1);
        int      size2Y = NextPowerOfTwo(platform.FloatToInt(totalheight) + 1);
        BitmapCi bmp2   = platform.BitmapCreate(size2X, size2Y);

        int[] bmp2Pixels = new int[size2X * size2Y];

        float currentwidth = 0;

        for (int i = 0; i < partsCount.value; i++)
        {
            int sizeiX = sizesX[i];
            int sizeiY = sizesY[i];
            if (sizeiX == 0 || sizeiY == 0)
            {
                continue;
            }

            Text_ partText = new Text_();
            partText.text  = parts[i].text;
            partText.color = parts[i].color;
            partText.font  = t.font;

            BitmapCi partBmp       = platform.CreateTextTexture(partText);
            int      partWidth     = platform.FloatToInt(platform.BitmapGetWidth(partBmp));
            int      partHeight    = platform.FloatToInt(platform.BitmapGetHeight(partBmp));
            int[]    partBmpPixels = new int[partWidth * partHeight];
            platform.BitmapGetPixelsArgb(partBmp, partBmpPixels);
            for (int x = 0; x < partWidth; x++)
            {
                for (int y = 0; y < partHeight; y++)
                {
                    if (x + currentwidth >= size2X)
                    {
                        continue;
                    }
                    if (y >= size2Y)
                    {
                        continue;
                    }
                    int c = partBmpPixels[MapUtilCi.Index2d(x, y, partWidth)];
                    if (Game.ColorA(c) > 0)
                    {
                        bmp2Pixels[MapUtilCi.Index2d(platform.FloatToInt(currentwidth) + x, y, size2X)] = c;
                    }
                }
            }
            currentwidth += sizeiX;
        }
        platform.BitmapSetPixelsArgb(bmp2, bmp2Pixels);
        return(bmp2);
    }