Ejemplo n.º 1
0
        public bool merge_CHR(sprite_data _spr, SPReD.CHR_data_group.ECHRPackingType _packing_type, bool _mode8x16)
        {
            // check if data were already packed
            if (_spr.is_packed(_mode8x16))
            {
                return(false);
            }

            int last_CHR_cnt = get_CHR_data().get_data().Count;

            CHR_data_group spr_chr_data = _spr.get_CHR_data();

            get_CHR_data().add_data_range(spr_chr_data);

            int i;
            int size = _spr.get_CHR_attr().Count;

            for (i = 0; i < size; i++)
            {
                _spr.get_CHR_attr()[i].CHR_ind += last_CHR_cnt;
            }

            _spr.set_CHR_data(this.get_CHR_data());

            return(true);
        }
Ejemplo n.º 2
0
        private void update()
        {
            clear_background(CONST_BACKGROUND_COLOR);

            // sprite data drawing
            if (m_spr_data != null)
            {
                disable(false);

                draw_chars();

                if (m_selected_CHR >= 0 && m_mode == EMode.m_build)
                {
                    // draw a frame of the selected CHR
                    CHR_data_attr chr_attr = m_spr_data.get_CHR_attr()[m_selected_CHR];
                    CHR_data      chr_data = m_spr_data.get_CHR_data().get_data()[chr_attr.CHR_ind];

                    float chr_scr_pos_x = transform_to_scr_pos(chr_attr.x + m_offset_x + m_spr_data.offset_x, m_scr_half_width);
                    float chr_scr_pos_y = transform_to_scr_pos(chr_attr.y + m_offset_y + m_spr_data.offset_y, m_scr_half_height);

                    float CHR_height = get_CHR_height();

                    m_pen.Color = Color.Red;
                    m_gfx.DrawRectangle(m_pen, chr_scr_pos_x, chr_scr_pos_y, m_CHR_size, CHR_height);

                    m_pen.Color = Color.White;
                    m_gfx.DrawRectangle(m_pen, chr_scr_pos_x - 1, chr_scr_pos_y - 1, m_CHR_size + 2, CHR_height + 2);

#if DEF_NES
                    m_label.Text = "Pos: " + chr_attr.x + ";" + chr_attr.y + " / Palette: " + (chr_attr.palette_ind + 1) + " / Id: " + chr_attr.CHR_ind + " / Tiles: " + m_spr_data.get_CHR_attr().Count;
#elif DEF_SMS || DEF_PCE
                    m_label.Text = "Pos: " + chr_attr.x + ";" + chr_attr.y + " / Id: " + chr_attr.CHR_ind + " / Tiles: " + m_spr_data.get_CHR_attr().Count;
        public static void export_CHR_data(sprite_data _spr, string _filename)
        {
            int i;

            List <CHR_data_attr> attrs = _spr.get_CHR_attr();

            int[] exp_attrs     = new int[attrs.Count];
            int   exp_attrs_pos = 0;

            bool[] attr_usage = new bool[attrs.Count];                                          // used attributes

            Array.Clear(attr_usage, 0, attr_usage.Length);

            // collect sprite patterns
            {
                // 32x64
                for (i = 0; i < attrs.Count; i++)
                {
                    search_pattern(_spr, attrs[i], exp_attrs, ref exp_attrs_pos, attr_usage, 8);
                }

                // 32x32
                for (i = 0; i < attrs.Count; i++)
                {
                    search_pattern(_spr, attrs[i], exp_attrs, ref exp_attrs_pos, attr_usage, 4);
                }

                // 32x16
                for (i = 0; i < attrs.Count; i++)
                {
                    search_pattern(_spr, attrs[i], exp_attrs, ref exp_attrs_pos, attr_usage, 2);
                }

                // 16x16
                for (i = 0; i < attrs.Count; i++)
                {
                    search_pattern(_spr, attrs[i], exp_attrs, ref exp_attrs_pos, attr_usage, 1);
                }
            }

            // save collected patterns
            {
                BinaryWriter bw = new BinaryWriter(File.Open(_filename, FileMode.Create));

                for (i = 0; i < exp_attrs.Length; i++)
                {
                    save_CHR(bw, _spr.get_CHR_data().get_data()[attrs[exp_attrs[i]].CHR_ind]);
                }

                bw.Dispose();
            }
        }
        public static void export_sprite(StreamWriter _sw, sprite_data _spr, int _CHRs_offset, int _palette_slot, string _data_prefix)
        {
            int i;
            int num_sprites = 0;

            List <CHR_data_attr> attrs = _spr.get_CHR_attr();

            int[] exp_attrs     = new int[attrs.Count];
            int   exp_attrs_pos = 0;

            bool[] attr_usage = new bool[attrs.Count];                                          // used attributes

            int offset_x = _spr.offset_x;
            int offset_y = _spr.offset_y;

            CHR_data_attr chr_attr;

            Array.Clear(attr_usage, 0, attr_usage.Length);

            _sw.WriteLine(_data_prefix + _spr.name + ":");

            _sw.WriteLine("\t.word " + _data_prefix + _spr.name + "_end - " + _data_prefix + _spr.name + " - 3\t; data size");
            _sw.WriteLine("\t.byte " + _spr.get_CHR_data().id + "\t\t; GFX bank index (" + _spr.get_CHR_data().name + ")\n");

            // collect sprite patterns
            {
                // 32x64
                for (i = 0; i < attrs.Count; i++)
                {
                    chr_attr = attrs[i];

                    if (search_pattern(_spr, chr_attr, exp_attrs, ref exp_attrs_pos, attr_usage, 8))
                    {
                        chr_attr         = chr_attr.copy();
                        chr_attr.CHR_ind = exp_attrs_pos - 8;

                        if ((chr_attr.flip_flag & CHR_data_attr.CONST_CHR_ATTR_FLAG_HFLIP) != 0)
                        {
                            chr_attr.x -= utils.CONST_CHR_SIDE_PIXELS_CNT;
                        }

                        if ((chr_attr.flip_flag & CHR_data_attr.CONST_CHR_ATTR_FLAG_VFLIP) != 0)
                        {
                            chr_attr.y -= utils.CONST_CHR_SIDE_PIXELS_CNT * 3;
                        }

                        save_attribute(_sw, _spr, chr_attr, 0x31 << 8, _CHRs_offset, 0, _palette_slot);

                        ++num_sprites;
                    }
                }

                // 32x32
                for (i = 0; i < attrs.Count; i++)
                {
                    chr_attr = attrs[i];

                    if (search_pattern(_spr, chr_attr, exp_attrs, ref exp_attrs_pos, attr_usage, 4))
                    {
                        chr_attr         = chr_attr.copy();
                        chr_attr.CHR_ind = exp_attrs_pos - 4;

                        if ((chr_attr.flip_flag & CHR_data_attr.CONST_CHR_ATTR_FLAG_HFLIP) != 0)
                        {
                            chr_attr.x -= utils.CONST_CHR_SIDE_PIXELS_CNT;
                        }

                        if ((chr_attr.flip_flag & CHR_data_attr.CONST_CHR_ATTR_FLAG_VFLIP) != 0)
                        {
                            chr_attr.y -= utils.CONST_CHR_SIDE_PIXELS_CNT;
                        }

                        save_attribute(_sw, _spr, chr_attr, 0x11 << 8, _CHRs_offset, 0, _palette_slot);

                        ++num_sprites;
                    }
                }

                // 32x16
                for (i = 0; i < attrs.Count; i++)
                {
                    chr_attr = attrs[i];

                    if (search_pattern(_spr, chr_attr, exp_attrs, ref exp_attrs_pos, attr_usage, 2))
                    {
                        chr_attr         = chr_attr.copy();
                        chr_attr.CHR_ind = exp_attrs_pos - 2;

                        if ((chr_attr.flip_flag & CHR_data_attr.CONST_CHR_ATTR_FLAG_HFLIP) != 0)
                        {
                            chr_attr.x -= utils.CONST_CHR_SIDE_PIXELS_CNT;
                        }

                        save_attribute(_sw, _spr, chr_attr, 0x01 << 8, _CHRs_offset, 0, _palette_slot);

                        ++num_sprites;
                    }
                }

                // 16x16
                for (i = 0; i < attrs.Count; i++)
                {
                    chr_attr = attrs[i];

                    if (search_pattern(_spr, chr_attr, exp_attrs, ref exp_attrs_pos, attr_usage, 1))
                    {
                        chr_attr         = chr_attr.copy();
                        chr_attr.CHR_ind = exp_attrs_pos - 1;

                        save_attribute(_sw, _spr, chr_attr, 0, _CHRs_offset, 0, _palette_slot);

                        ++num_sprites;
                    }
                }
            }

            _sw.WriteLine(_data_prefix + _spr.name + "_end:\n");

            if (num_sprites > utils.CONST_SPRITE_MAX_NUM_ATTRS)
            {
                throw new Exception("The sprite - " + _spr.name + " - has more than " + utils.CONST_SPRITE_MAX_NUM_ATTRS.ToString() + " tiles that exceed the hardware limit!\n Please, fix it to avoid the sprite drawing error in your project!");
            }
        }