コード例 #1
0
ファイル: Def.cs プロジェクト: sjschaff/rimlite
 public BldgMineableDef(
     string defName, string name,
     Tool tool, ItemInfo resource,
     SpriteDef sprite)
     : this(defName, name, tool, new ItemInfo[] { resource }, sprite)
 {
 }
コード例 #2
0
ファイル: MapTiler.cs プロジェクト: sjschaff/rimlite
        // TODO: this needs to handle sprite anchor
        // TODO: this is kinda jank
        // shouldnt be new'ing defs, and we'll end up with duplicate sprites
        public static bool SplitSprite(SpriteDef sprite, int height, out SpriteDef lower, out SpriteDef upper)
        {
            var atlas       = sprite.atlas;
            var heightTiles = height * atlas.tilesPerUnit;
            var rect        = sprite.rect;

            if (sprite.rect.size.y > heightTiles)
            {
                lower = new SpriteDef(null, atlas, new Atlas.Rect(
                                          rect.origin,
                                          new Vec2I(rect.size.x, heightTiles),
                                          rect.anchor));

                var upperOfs = new Vec2I(0, heightTiles);
                upper = new SpriteDef(null, atlas, new Atlas.Rect(
                                          rect.origin + upperOfs,
                                          new Vec2I(rect.size.x, rect.size.y - heightTiles),
                                          rect.anchor - upperOfs));

                return(true);
            }

            lower = upper = null;
            return(false);
        }
コード例 #3
0
        public Renderer(int screenWidth, int screenHeight)
        {
            camera       = new Camera(GRID_X, GRID_Y, screenWidth, screenHeight, (float)Math.PI / 2.8f);
            frame_buffer = new PixelBuffer(screenWidth, screenHeight);

            // Generate placeholder texture
            textures         = new Dictionary <int, TextureDef>();
            sprites          = new Dictionary <int, SpriteDef>();
            missing_sprites  = new Dictionary <int, bool>();
            missing_textures = new Dictionary <int, bool>();

            PixelBuffer tex = new PixelBuffer(16, 16);

            Render.clear(tex, new Rgba(0, 0, 0));
            for (int y = 0; y < 16; y++)
            {
                for (int x = 0; x < 16; x++)
                {
                    byte b = (byte)(x * 16);
                    byte c = (byte)(y * 16);
                    Render.point(tex, x, y, new Rgba(0, b, c));
                }
            }
            default_sprite  = new SpriteDef(0, tex);
            default_texture = new TextureDef(0, tex);
            // Ray buffer used for storing ray cast results.
            ray_buffer = new RayData[camera.view_cols];
            for (int index = 0; index < ray_buffer.Length; index++)
            {
                ray_buffer[index] = new RayData();
            }
        }
コード例 #4
0
 private void SplitSprite(AssetSrc assets, SpriteDef def,
                          int size, out Sprite sprite, out Sprite spriteOver)
 {
     if (Tiling.SplitSprite(def, size, out var defLower, out var defUpper))
     {
         sprite     = assets.sprites.Get(defLower);
         spriteOver = assets.sprites.Get(defUpper);
     }
コード例 #5
0
ファイル: AssetSrc.cs プロジェクト: sjschaff/rimlite
 // TODO: maybe this goes somewhere else
 public SpriteRenderer CreateJobOverlay(Transform parent, Vec2I pos, SpriteDef sprite)
 => CreateSpriteObject(
     parent,
     pos + new Vec2(.5f, .5f),
     "JobOverlay",
     sprite,
     new Color(.6f, .6f, 1, .5f),
     RenderLayer.Highlight);
コード例 #6
0
ファイル: Def.cs プロジェクト: sjschaff/rimlite
 public ItemDef(
     string defName, string name, SpriteDef icon,
     int maxStack)
     : base("BB:Item", defName, name)
 {
     this.sprite   = icon;
     this.maxStack = maxStack;
 }
コード例 #7
0
        public T Get(SpriteDef def)
        {
            if (disposedValue)
            {
                throw new ObjectDisposedException(nameof(SimpleSpriteCache <T>));
            }

            return(_sprites.GetOrAdd(def, _resolver));
        }
コード例 #8
0
        public GameSprite Get(SpriteDef def)
        {
            if (disposedValue)
            {
                throw new ObjectDisposedException(nameof(GameSpriteCache));
            }

            return(_sprites.GetOrAdd(def, LoadSprite));
        }
コード例 #9
0
ファイル: Def.cs プロジェクト: sjschaff/rimlite
 public BldgMineableDef(
     string defName, string name,
     Tool tool, ItemInfo[] resources,
     SpriteDef sprite)
     : base("BB:BldgResource", defName, name)
 {
     this.tool      = tool;
     this.resources = resources;
     this.sprite    = sprite;
 }
コード例 #10
0
ファイル: Projectile.cs プロジェクト: sjschaff/rimlite
        private SpriteRenderer MakeProjSprite(
            Game game, Vec2 start, Quaternion rot, SpriteDef def, Color color, int layer)
        {
            var sprite = game.assets.CreateSpriteObject(
                game.effectsContainer, start, "Projectile",
                def, color, RenderLayer.OverMap.Layer(layer));

            sprite.transform.localRotation = rot;
            return(sprite);
        }
コード例 #11
0
 protected BuildingProtoSpriteRender(
     Game game,
     BuildingBounds rect,
     SpriteDef spriteDefDown,
     SpriteDef spriteDefRight)
 {
     this.bounds = rect;
     SplitSprite(game.assets, spriteDefDown, rect.size.y, out spriteDown, out spriteDownOver);
     if (spriteDefRight != null)
     {
         SplitSprite(game.assets, spriteDefRight, rect.size.x, out spriteRight, out spriteRightOver);
     }
 }
コード例 #12
0
ファイル: Projectile.cs プロジェクト: sjschaff/rimlite
        public Projectile(Game game, Vec2 start, Vec2 target, float speed,
                          SpriteDef def, Vec2 spriteForward)
            : base(game)
        {
            this.target = target;
            this.speed  = speed;

            Vec2  dir   = target - start;
            float angle = Vec2.SignedAngle(spriteForward, dir);
            var   rot   = Quaternion.Euler(0, 0, angle);

            sprite       = MakeProjSprite(game, start, rot, def, Color.white, 3);
            spriteTrailA = MakeProjSprite(game, start, rot, def, new Color(1, 1, 1, .25f), 2);
            spriteTrailB = MakeProjSprite(game, start, rot, def, new Color(1, 1, 1, .0625f), 1);
        }
コード例 #13
0
ファイル: PlayerHub.cs プロジェクト: anjackthemage/dfe-blazor
        public async Task getSpritePixels(int id)
        {
            SpriteDef spr = null;

            if (GameServer.server.sprite_assets.TryGetValue(id, out spr) == false)
            {
                Console.WriteLine("Unable to fetch requested sprite : " + id);
                return;
            }
            else
            {
                PixelBuffer buffer = spr.pixelBuffer;
                await Clients.Client(Context.ConnectionId).SendAsync("receiveSpritePixels", id, buffer.width, buffer.height, buffer.pixels);
            }
        }
コード例 #14
0
ファイル: Def.cs プロジェクト: sjschaff/rimlite
 public BldgWorkbenchDef(
     string defName, string name,
     BuildingBounds bounds, Vec2I workSpot,
     SpriteDef spriteDown, SpriteDef spriteRight,
     ItemInfo[] materials,
     RecipeDef[] recipes)
     : base("BB:Workbench", defName, name)
 {
     BB.Assert(bounds.IsAdjacent(workSpot));
     this.bounds      = bounds;
     this.workSpot    = workSpot;
     this.spriteDown  = spriteDown;
     this.spriteRight = spriteRight;
     this.materials   = materials;
     this.recipes     = recipes;
 }
コード例 #15
0
        private SpriteDef ParseSpriteType(ASTNode node)
        {
            bool eq(string a, string b) => StringComparer.OrdinalIgnoreCase.Equals(a, b);

            var tokens = node.Children
                         .Where(child => child.Symbol.Name == "Option")
                         .Select(child => child.Children.First())
                         .Where(token => token.Children.Count > 1)
                         .Select <ASTNode, (string id, string value, string name)>(token => (token.Children[0].Value, token.Children[1].Value, token.Symbol.Name));

            var sprite = new SpriteDef();

            foreach (var(id, value, name) in tokens)
            {
                switch (name)
                {
                case "stringOption":
                case "idOption":     // Case of unquoted key/value
                    if (eq(id, "name"))
                    {
                        sprite.Name = value.Trim('"');
                    }
                    else if (eq(id, "textureFile"))
                    {
                        sprite.TextureFilePath = value.Trim('"').Replace(@"\\", "/");
                    }
                    break;

                case "boolOption" when eq(id, "norefcount"):
                    sprite.NoRefCount = value == "yes";

                    break;

                case "numberOption" when eq(id, "noOfFrames"):
                    sprite.FrameCount = int.Parse(value);

                    break;
                }
            }

            logger.LogDebug("SpriteDef Parsed: " + sprite);
            return(sprite);
        }
コード例 #16
0
        private GameSprite?LoadSprite(SpriteDef def)
        {
            bool found = false;

            // Paths in vanilla files are Windows-style
            string filePath = def.TextureFilePath;//.Replace('\\', Path.DirectorySeparatorChar);

            // Also try alternative extension (.tga <=> .dds)
            string extension           = Path.GetExtension(filePath);
            string alternative         = string.Equals(extension, ".dds", StringComparison.OrdinalIgnoreCase) ? ".tga" : ".dds";
            string alternativeFilePath = Path.ChangeExtension(filePath, alternative);

            string path = null;

            // Loop on reverse order - last occurence wins if asset is overriden !
            for (int i = ActiveContent.Count - 1; i >= 0; i--)
            {
                var content = ActiveContent[i];
                path = Path.Combine(content.AbsolutePath, filePath);

                if (!File.Exists(path))
                {
                    path = Path.Combine(content.AbsolutePath, alternativeFilePath);
                }

                if (File.Exists(path))
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                logger.LogWarning("Unable to find file: {0} under active content {1}", filePath, ActiveContent);
                return(null);
            }

            logger.LogDebug("Loading sprite from: {0}", path);
            return(new GameSprite(path, def.FrameCount));
        }
コード例 #17
0
        private PackSprite LoadSprite(SpriteDef def)
        {
            DirectoryInfo dir = null;

            // Loop on reverse order - last occurence wins if asset is overriden !
            for (int i = ActiveContent.Count - 1; i >= 0; i--)
            {
                var content = ActiveContent[i];
                dir = new DirectoryInfo(Path.Combine(content.AbsolutePath, def.Name));

                if (dir.Exists && dir.EnumerateFiles().Any())
                {
                    break;
                }
            }

            if (dir == null || !dir.Exists)
            {
                throw new FileNotFoundException(string.Format("Unable to find sprite: {0} under active content {1}", def.Name, ActiveContent));
            }

            logger.LogDebug("Loading pack sprite from: {0}", dir.FullName);
            return(new PackSprite(dir.FullName, def.FrameCount));
        }
コード例 #18
0
        public void renderSprites(Camera cam)
        {
            if (sprite_vis == null)
            {
                sprite_vis = new List <SpriteVis>();
            }
            sprite_vis.Clear();

            // Setup culling space.


            Coord   origin = new Coord(cam.x, cam.y);
            float   angle  = cam.view_angle - (cam.fov / 2);
            Vector2 left   = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));

            angle = cam.view_angle + (cam.fov / 2);
            Vector2 right = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));

            int spritecount = 0;
            int cullcount   = 0;
            // Cull all sprites out of the space.
            ClientState state = GameClient.game_state;

            foreach (Entity ent in state.local_props.Values)
            {
                spritecount++;
                if (((left.X * (ent.position.Y - origin.Y)) - (left.Y * (ent.position.X - origin.X))) > 0 &&
                    ((right.X * (ent.position.Y - origin.Y)) - (right.Y * (ent.position.X - origin.X))) < 0)
                {
                    sprite_vis.Add(new SpriteVis(ent));
                }
                else
                {
                    cullcount++;
                }
            }

            foreach (Entity ent in state.local_mobs.Values)
            {
                spritecount++;
                if (((left.X * (ent.position.Y - origin.Y)) - (left.Y * (ent.position.X - origin.X))) > 0 &&
                    ((right.X * (ent.position.Y - origin.Y)) - (right.Y * (ent.position.X - origin.X))) < 0)
                {
                    sprite_vis.Add(new SpriteVis(ent));
                }
                else
                {
                    cullcount++;
                }
            }

            foreach (Entity ent in state.local_players.Values)
            {
                spritecount++;
                if (((left.X * (ent.position.Y - origin.Y)) - (left.Y * (ent.position.X - origin.X))) > 0 &&
                    ((right.X * (ent.position.Y - origin.Y)) - (right.Y * (ent.position.X - origin.X))) < 0)
                {
                    sprite_vis.Add(new SpriteVis(ent));
                }
                else
                {
                    cullcount++;
                }
            }

            // Perform translation calculations on the resulting list.
            //OPTI: This code section could benefit from using some fixed point integers instead of floats.
            float nx = (float)Math.Cos(-camera.view_angle);
            float ny = (float)Math.Sin(-camera.view_angle);
            //OPTI: Math.Tan(fov / 2) is a constant that only needs to be calculated once.
            float viewAdjacent = (float)(frame_buffer.width / 2) / (float)Math.Tan(camera.fov / 2);

            foreach (SpriteVis spr_vis in sprite_vis)
            {
                float tx       = (spr_vis.x - camera.x) / 16;
                float ty       = (spr_vis.y - camera.y) / 16;
                float sx       = ((tx * nx) - (ty * ny));
                float sy       = ((tx * ny) + (ty * nx));
                int   screen_x = (int)((sy / sx) * viewAdjacent);
                spr_vis.screen_x = screen_x;
                spr_vis.distance = sx;
            }

            // Sort rendering order from back to front.
            sprite_vis.Sort(delegate(SpriteVis a, SpriteVis b)
            {
                if (a.distance == b.distance)
                {
                    return(0);
                }
                else if (a.distance > b.distance)
                {
                    return(-1);
                }
                else
                {
                    return(1);
                }
            });
            // Render the list.
            foreach (SpriteVis spr_vis in sprite_vis)
            {
                SpriteDef sprite = sprites[0];
                //PixelBuffer buffer = textures[0].pixelBuffer;
                if (sprites.TryGetValue(spr_vis.sprite_id, out sprite) == true && sprite.pixelBuffer != null)
                {
                    Render.sprite(frame_buffer, (int)spr_vis.screen_x + (frame_buffer.width / 2), spr_vis.distance, ray_buffer, sprite);
                }
                else
                {
                    Render.sprite(frame_buffer, (int)spr_vis.screen_x + (frame_buffer.width / 2), spr_vis.distance, ray_buffer, default_sprite);
                    // If the sprite is to be requested, or being downloaded, dont request it.
                    if (missing_sprites.ContainsKey(sprite.id) == false)
                    {
                        missing_sprites.Add(sprite.id, false);
                    }
                }
            }
        }
コード例 #19
0
 protected CommandBase(SpriteDef sprite, string text)
 {
     this.guiSprite = sprite;
     this.guiText   = text;
 }
コード例 #20
0
ファイル: AssetSrc.cs プロジェクト: sjschaff/rimlite
        public SpriteRenderer CreateSpriteObject(Transform parent, Vec2 pos, string name, SpriteDef sprite, Color color, RenderLayer layer)
        {
            var renderer = CreateObjectWithRenderer <SpriteRenderer>(parent, pos, name, layer);

            renderer.material = spriteMaterial;
            renderer.sprite   = sprites.Get(sprite);
            renderer.color    = color;
            return(renderer);
        }
コード例 #21
0
ファイル: GameSystemBase.cs プロジェクト: sjschaff/rimlite
 protected GameSystemAsOrders(Game game, SpriteDef guiSprite, string guiText)
     : base(game)
 {
     this.guiSprite = guiSprite;
     this.guiText   = guiText;
 }
コード例 #22
0
 ISprite ISpriteCache.Get(SpriteDef def) => Get(def);
コード例 #23
0
ファイル: Portrait.cs プロジェクト: scorpdx/PortraitBuilder
 static string GetBlobPath(SpriteDef def)
 => def.TextureFilePath.StartsWith("packs/") ? def.TextureFilePath.Substring("packs/".Length) : def.TextureFilePath;
コード例 #24
0
 public PackSprite Get(SpriteDef def) => _sprites?.GetOrAdd(def, LoadSprite) ?? throw new ObjectDisposedException(nameof(PackSpriteCache));