int CHRs_optimization(tiles_data _data, bool _check) { int deleted_CHRs_cnt = 0; int CHR_data_sum; byte[] img_buff = new byte[utils.CONST_SPR8x8_TOTAL_PIXELS_CNT]; int size_offs; int size = _data.get_first_free_spr8x8_id(false); for (int CHR_n = 0; CHR_n < size; CHR_n++) { if (check_blocks_CHR(CHR_n, _data) == false) { CHR_data_sum = _data.spr8x8_sum(CHR_n); if (CHR_data_sum != 0) { ++deleted_CHRs_cnt; } if (_check == true) { continue; } // delete useless CHR { size_offs = platform_data.get_CHR_bank_max_sprites_cnt() - 1; for (int i = CHR_n; i < size_offs; i++) { _data.from_CHR_bank_to_spr8x8(i + 1, img_buff, 0); _data.from_spr8x8_to_CHR_bank(i, img_buff); } } // the last CHR is an empty space { #if DEF_ZX for (int i = 0; i < img_buff.Length; i++) { img_buff[i] = utils.CONST_ZX_DEFAULT_PAPER_COLOR; } #else Array.Clear(img_buff, 0, utils.CONST_SPR8x8_TOTAL_PIXELS_CNT); #endif _data.from_spr8x8_to_CHR_bank(platform_data.get_CHR_bank_max_sprites_cnt() - 1, img_buff); } shift_CHRs_data(CHR_n, _data); --CHR_n; --size; } } return(deleted_CHRs_cnt); }
private void update_bank_GFX() { tiles_data data = m_data_manager.get_tiles_data(ListBoxCHRBanks.SelectedIndex); int img_size = utils.CONST_BLOCKS_IMG_SIZE; int half_img_size = img_size >> 1; int side = 5; int size = side * side; Bitmap bmp = new Bitmap(img_size, img_size); Graphics gfx = Graphics.FromImage(bmp); gfx.SmoothingMode = SmoothingMode.HighSpeed; gfx.InterpolationMode = InterpolationMode.NearestNeighbor; // gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; for (int i = 0; i < size; i++) { utils.update_block_gfx(i, data, gfx, half_img_size, half_img_size, 0, 0, 0); m_blocks_preview.update(bmp, img_size, img_size, (i % side) * img_size, (i / side) * img_size, i == (size - 1), i == 0); } gfx.Dispose(); bmp.Dispose(); // update info { LabelCHRs.Text = data.get_first_free_spr8x8_id(false).ToString(); LabelBlocks2x2.Text = data.get_first_free_block_id(false).ToString(); LabelTiles4x4.Text = data.get_first_free_tile_id(false).ToString(); LabelScreens.Text = data.screen_data_cnt().ToString(); LabelPalettes.Text = data.palettes_arr.Count.ToString(); } }
public int get_CHRs_cnt(int _bank_ind) { tiles_data data = m_data_mngr.get_tiles_data(_bank_ind); if (data != null) { return(data.get_first_free_spr8x8_id(false)); } return(-1); }
public int merge_CHR_bin(BinaryReader _br, tiles_data _data) { byte[] tmp_arr = new byte[utils.CONST_SPR8x8_TOTAL_PIXELS_CNT]; int y; int added_CHRs = 0; int chr_id = _data.get_first_free_spr8x8_id(true); if (chr_id >= 0) { do { tmp_arr = _br.ReadBytes(platform_data.get_native_CHR_size_bytes()); for (y = 0; y < utils.CONST_SPR8x8_SIDE_PIXELS_CNT; y++) { convert_CHR(y, ref tmp_arr, ref utils.tmp_spr8x8_buff); } _data.from_spr8x8_to_CHR_bank(chr_id++, utils.tmp_spr8x8_buff); ++added_CHRs; if (chr_id == platform_data.get_CHR_bank_max_sprites_cnt()) { break; } }while(_br.BaseStream.Position + platform_data.get_native_CHR_size_bytes() <= _br.BaseStream.Length); } else { throw new Exception("There is no free space in the active CHR bank!"); } return(added_CHRs); }
public int merge_CHR_spred(BinaryReader _br) { int CHR_cnt = _br.ReadInt32(); int spr8x8_cnt; bool res = true; int copied_CHRs = 0; tiles_data data = get_tiles_data(tiles_data_pos); int chr_id; // get a first free spr8x8 position { chr_id = data.get_first_free_spr8x8_id(true); if (chr_id < 0) { throw new Exception("There is no free space in the active CHR bank!"); } } for (int i = 0; i < CHR_cnt; i++) { _br.ReadInt32(); // skip id _br.ReadInt32(); // skip link_cnt spr8x8_cnt = _br.ReadInt32(); if (chr_id + spr8x8_cnt > platform_data.get_CHR_bank_max_sprites_cnt()) { MainForm.set_status_msg(String.Format("Merged: {0} of {1} CHR banks", i, CHR_cnt)); res = false; if (copied_CHRs == 0) { return(-1); } } for (int j = 0; j < spr8x8_cnt; j++) { _br.Read(utils.tmp_spr8x8_buff, 0, utils.CONST_SPR8x8_TOTAL_PIXELS_CNT); if (res) { data.from_spr8x8_to_CHR_bank(chr_id++, utils.tmp_spr8x8_buff); ++copied_CHRs; } } } if (copied_CHRs != 0) { if (MainForm.message_box("Import palette ?", "SPReD Data Import", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { for (int plt_n = 0; plt_n < utils.CONST_PALETTE_SMALL_NUM_COLORS * utils.CONST_NUM_SMALL_PALETTES; plt_n++) { data.subpalettes[plt_n >> 2][plt_n & 0x03] = (byte)_br.ReadInt32(); } } } return(res ? CHR_cnt:-1); }