graphics: continue to change code to store some images as Texture...

This commit is contained in:
ALONSO Laurent
2020-10-16 12:20:49 +02:00
committed by Celtic Minstrel
parent c31bb2d0ff
commit fcc2db7a5e
12 changed files with 63 additions and 46 deletions

View File

@@ -70,7 +70,7 @@ void cButton::draw(){
to_rect.right = to_rect.left + 14;
to_rect.bottom = to_rect.top + 10;
}
rect_draw_some_item(*ResMgr::graphics.get(buttons[btnGW[type]]),from_rect,*inWindow,to_rect,sf::BlendAlpha);
rect_draw_some_item(*ResMgr::textures.get(buttons[btnGW[type]]),from_rect,*inWindow,to_rect,sf::BlendAlpha);
style.colour = sf::Color::Black;
style.lineHeight = 8;
eTextMode textMode = eTextMode::CENTRE;
@@ -335,7 +335,7 @@ void cLed::draw(){
to_rect = frame;
to_rect.right = to_rect.left + 14;
to_rect.bottom = to_rect.top + 10;
rect_draw_some_item(*ResMgr::graphics.get(buttons[btnGW[BTN_LED]]),from_rect,*inWindow,to_rect);
rect_draw_some_item(*ResMgr::textures.get(buttons[btnGW[BTN_LED]]),from_rect,*inWindow,to_rect);
style.colour = textClr;
to_rect.right = frame.right;
to_rect.left = frame.left + 18; // Possibly could be 20

View File

@@ -171,7 +171,7 @@ void adjust_window_mode() {
mainView.setViewport(mainPort);
#ifndef __APPLE__ // This overrides Dock icon on OSX, which isn't what we want at all
const ImageRsrc& icon = ResMgr::graphics.get("icon", true);
auto const & icon = *ResMgr::textures.get("icon", true);
mainPtr.setIcon(icon->getSize().x, icon->getSize().y, icon->copyToImage().getPixelsPtr());
#endif
@@ -332,7 +332,7 @@ void draw_startup_stats() {
rect_draw_some_item(monst_gworld,from_rect,mainPtr,to_rect,sf::BlendAlpha);
} else {
from_rect = calc_rect(2 * (pic / 8), pic % 8);
sf::Texture& pc_gworld = *ResMgr::graphics.get("pcs");
auto const & pc_gworld = *ResMgr::textures.get("pcs");
rect_draw_some_item(pc_gworld,from_rect,mainPtr,to_rect,sf::BlendAlpha);
}
@@ -1242,7 +1242,7 @@ void place_road(short q,short r,location where,bool here) {
{16,12,20,16}, // central spot
};
sf::Texture& roads_gworld = *ResMgr::graphics.get("fields");
auto const & roads_gworld = *ResMgr::textures.get("fields");
if(here){
to_rect = road_dest_rects[6];
@@ -1419,7 +1419,7 @@ void boom_space(location where,short mode,short type,short damage,short sound) {
dest_rect.offset(win_to_rects[WINRECT_TERVIEW].topLeft());
source_rect.offset(-store_rect.left + 28 * type,-store_rect.top);
rect_draw_some_item(*ResMgr::graphics.get("booms"),source_rect,mainPtr,dest_rect,sf::BlendAlpha);
rect_draw_some_item(*ResMgr::textures.get("booms"),source_rect,mainPtr,dest_rect,sf::BlendAlpha);
if(damage > 0 && dest_rect.right - dest_rect.left >= 28 && dest_rect.bottom - dest_rect.top >= 36) {
TextStyle style;
@@ -1524,7 +1524,7 @@ void draw_targets(location center) {
return;
const rectangle src_rect{0,46,12,58};
sf::Texture& src_gworld = *ResMgr::graphics.get("invenbtns");
auto const & src_gworld = *ResMgr::textures.get("invenbtns");
for(short i = 0; i < 8; i++)
if((spell_targets[i].x != -1) && (point_onscreen(center,spell_targets[i]))) {
rectangle dest_rect = coord_to_rect(spell_targets[i].x - center.x + 4,spell_targets[i].y - center.y + 4);

View File

@@ -58,6 +58,7 @@ extern short which_combat_type;
extern eGameMode overall_mode;
extern bool boom_anim_active;
extern sf::RenderTexture terrain_screen_gworld;
extern rectangle terrain_screen_rect;
extern rectangle sbar_rect,item_sbar_rect,shop_sbar_rect;
extern std::shared_ptr<cScrollbar> text_sbar,item_sbar,shop_sbar;
extern std::shared_ptr<cButton> done_btn, help_btn;
@@ -194,14 +195,14 @@ void apply_light_mask(bool onWindow) {
if(same_mask) {
return;
}
#if 0
std::cout << "Current light mask:\n";
for(short i = 0; i < 13; i++) {
for(short j = 0; j < 13; j++)
std::cout << int(light_area[j][i]) << ' ';
std::cout << '\n';
}
#endif
dark_mask_region.clear();
dark_mask_region.addRect(big_to);
for(short i = 0; i < 13; i++)
@@ -348,7 +349,7 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) {
// make terrain_template contain current terrain all nicely
draw_terrain(1);
to_rect = rectangle(terrain_screen_gworld);
to_rect = terrain_screen_rect;
to_rect.bottom -= 10; // Adjust for pointing buttons
rectangle oldBounds = to_rect;
to_rect.offset(current_terrain_ul);
@@ -391,7 +392,7 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) {
play_sound(-1 * sound_num);
sf::Texture& missiles_gworld = *ResMgr::graphics.get("missiles");
auto const & missiles_gworld = *ResMgr::textures.get("missiles");
// Now, at last, launch missile
for(short t = 0; t < num_steps; t++) {
draw_terrain();
@@ -445,7 +446,7 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) {
for(short i = 0; i < 30; i++)
store_missiles[i].missile_type = -1;
to_rect = rectangle(terrain_screen_gworld);
to_rect = terrain_screen_rect;
to_rect.bottom -= 10; // Adjust for pointing buttons
rectangle oldRect = to_rect;
to_rect.offset(current_terrain_ul);
@@ -509,7 +510,7 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) {
// make terrain_template contain current terrain all nicely
draw_terrain(1);
if(special_draw != 2) {
to_rect = rectangle(terrain_screen_gworld);
to_rect = terrain_screen_rect;
to_rect.bottom -= 10; // Adjust for pointing buttons
rectangle oldRect = to_rect;
to_rect.offset(current_terrain_ul);
@@ -548,7 +549,7 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) {
play_sound(-1 * snd_num);
}
sf::Texture& boom_gworld = *ResMgr::graphics.get("booms");
auto const & boom_gworld = *ResMgr::textures.get("booms");
// Now, at last, do explosion
for(short t = (special_draw == 2) ? 6 : 0; t < ((special_draw == 1) ? 6 : 11); t++) { // t goes up to 10 to make sure screen gets cleaned up
draw_terrain();
@@ -716,7 +717,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
else
style.colour = Colours::BLACK;
sf::Texture& invenbtn_gworld = *ResMgr::graphics.get("invenbtns");
auto const & invenbtn_gworld = *ResMgr::textures.get("invenbtns");
// Place all the items
for(short i = 0; i < 8; i++) {
current_pos = i + shop_sbar->getPosition();

View File

@@ -122,7 +122,7 @@ void put_pc_screen() {
win_draw_string(pc_stats_gworld,day_rect[0],std::to_string(univ.party.calc_day()),eTextMode::WRAP,style);
style.colour = Colours::BLACK;
sf::Texture& invenbtn_gworld = *ResMgr::graphics.get("invenbtns");
auto const & invenbtn_gworld = *ResMgr::textures.get("invenbtns");
for(short i = 0; i < 6; i++) {
if(univ.party[i].main_status != eMainStatus::ABSENT) {
for(auto& flag : pc_area_button_active[i])
@@ -425,7 +425,7 @@ void place_buy_button(short position,short pc_num,short item_num) {
return;
}
if(item_area_button_active[position][ITEMBTN_SPEC]) {
sf::Texture& invenbtn_gworld = *ResMgr::graphics.get("invenbtns");
auto const & invenbtn_gworld = *ResMgr::textures.get("invenbtns");
store_selling_values[position] = val_to_place;
dest_rect = item_buttons[position][ITEMBTN_SPEC];
dest_rect.right = dest_rect.left + 30;
@@ -453,7 +453,7 @@ void place_item_graphic(short which_slot,short graphic) {
graf_pos_ref(src_gw, from_rect) = spec_scen_g.find_graphic(graphic - 1000);
rect_draw_some_item(*src_gw, from_rect, item_stats_gworld, to_rect,sf::BlendAlpha);
}
else rect_draw_some_item(*ResMgr::graphics.get("tinyobj"), from_rect, item_stats_gworld, to_rect, sf::BlendAlpha);
else rect_draw_some_item(*ResMgr::textures.get("tinyobj"), from_rect, item_stats_gworld, to_rect, sf::BlendAlpha);
}
// name, use, give, drop, info, sell/id
@@ -462,7 +462,7 @@ void place_item_graphic(short which_slot,short graphic) {
void place_item_button(short button_position,short which_slot,eItemButton button_type) {
rectangle from_rect = {0,0,18,18},to_rect;
sf::Texture& invenbtn_gworld = *ResMgr::graphics.get("invenbtns");
auto const & invenbtn_gworld = *ResMgr::textures.get("invenbtns");
switch(button_position) {
default: // this means put a regular item button
item_area_button_active[which_slot][button_type] = true;
@@ -502,7 +502,7 @@ void place_item_bottom_buttons() {
style.font = FONT_BOLD;
style.colour = Colours::YELLOW;
sf::Texture& invenbtn_gworld = *ResMgr::graphics.get("invenbtns");
auto const & invenbtn_gworld = *ResMgr::textures.get("invenbtns");
for(short i = 0; i < 6; i++) {
if(univ.party[i].main_status == eMainStatus::ALIVE) {
item_bottom_button_active[i] = true;
@@ -640,7 +640,7 @@ void draw_pc_effects(short pc) {
return;
univ.party[pc].status[eStatus::HASTE_SLOW]; // This just makes sure it exists in the map, without changing its value if it does
sf::Texture& status_gworld = *ResMgr::graphics.get("staticons");
auto const & status_gworld = *ResMgr::textures.get("staticons");
for(auto next : univ.party[pc].status) {
short placedIcon = -1;
if(next.first == eStatus::POISON && next.second > 4) placedIcon = 1;

View File

@@ -1405,7 +1405,7 @@ void draw_map(bool need_refresh) {
else out_mode = false;
// TODO: It could be possible to draw the entire map here and then only refresh if a spot actually changes terrain type
sf::Texture& small_ter_gworld = *ResMgr::graphics.get("termap");
auto const & small_ter_gworld = *ResMgr::textures.get("termap");
for(where.x = redraw_rect.left; where.x < redraw_rect.right; where.x++)
for(where.y = redraw_rect.top; where.y < redraw_rect.bottom; where.y++) {
draw_rect = orig_draw_rect;
@@ -1448,7 +1448,7 @@ void draw_map(bool need_refresh) {
} else if(drawLargeIcon) {
if(pic >= 960) {
custom_from = calc_rect(4 * ((pic - 960) / 5),(pic - 960) % 5);
rect_draw_some_item(*ResMgr::graphics.get("teranim"), custom_from, map_gworld, draw_rect);
rect_draw_some_item(*ResMgr::textures.get("teranim"), custom_from, map_gworld, draw_rect);
} else {
int which_sheet = pic / 50;
auto src_gw = &ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));

View File

@@ -39,16 +39,31 @@ struct Texture {
{ "bigscenpics", {256,64} },
{ "booms", {224,252} },
{ "buttons", {192,115} },
{ "dlgbtnred", {60,30} },
{ "dlogbtnhelp", {32,13} },
{ "dlogbtnled", {56,26} },
{ "dlogbtnlg", {204,23} },
{ "dlogbtnmed", {126,138} },
{ "dlogbtnsm", {46,23} },
{ "dlogbtntall", {126,80} },
{ "dlogpics", {144,360} },
{ "dlogscrollled", {56,48} },
{ "dlogscrollwh", {64,64} },
{ "edbuttons", {251,164} },
{ "edsplash", {640,480} },
{ "fields", {224,144} },
{ "fighthelp", {320,125} },
{ "icon", {38,38} },
{ "invenbtns", {130,80} },
{ "invenhelp", {138,112} },
{ "inventory", {271,144} },
{ "missiles", {144,288} },
{ "objects", {140,396} },
{ "outhelp", {320,125} },
{ "pcedbuttons", {114,57} },
{ "pcedtitle", {310,70} },
{ "pcs", {280,576} },
{ "pixpats", {320, 256} },
{ "scenpics", {160,224} },
{ "spidlogo", {350,350} },
{ "startanim", {280,590} },
@@ -66,6 +81,7 @@ struct Texture {
{ "tinyobj", {180,252} },
{ "townhelp", {320,125} },
{ "transcript", {256,138} },
{ "vehicle", {112,108} },
};
auto const &it=nameToDimensions.find(base);
if (it!=nameToDimensions.end())

View File

@@ -40,9 +40,9 @@ template<> struct hash<tessel_ref_t> {
std::unordered_map<tessel_ref_t, tessel_t> tiling_reservoir;
static int tessel_index = 0;
tessel_ref_t prepareForTiling(sf::Texture& srcImg, rectangle srcRect) {
tessel_ref_t prepareForTiling(Texture const & srcImg, rectangle srcRect) {
tessel_ref_t ref = {tessel_index++};
tiling_reservoir[ref].img = &srcImg;
tiling_reservoir[ref].img = &const_cast<sf::Texture &>(*srcImg);
tiling_reservoir[ref].srcRect = srcRect;
tiling_reservoir[ref].tessel = new sf::RenderTexture;
tiling_reservoir[ref].tessel->create(srcRect.width(), srcRect.height());
@@ -102,8 +102,8 @@ void init_tiling() {
bg_rects[7].top += 32;
rectangle bw_rect = {0,0,8,8};
sf::Texture& bg_gworld = *ResMgr::graphics.get("pixpats");
sf::Texture& bw_gworld = *ResMgr::graphics.get("bwpats");
auto const & bg_gworld = *ResMgr::textures.get("pixpats");
auto const & bw_gworld = *ResMgr::textures.get("bwpats");
for(int i = 0; i < 21; i++) {
if(i < 6) {
bw_pats[i] = prepareForTiling(bw_gworld, bw_rect);

View File

@@ -342,7 +342,7 @@ void draw_items() {
frame_dlog_rect(mainPtr,name_rect); // draw the frame
return; // If PC is dead, it has no items
}
sf::Texture& invenbtn_gworld = *ResMgr::graphics.get("invenbtns");
auto const & invenbtn_gworld = *ResMgr::textures.get("invenbtns");
for(short i = 0; i < univ.party[current_active_pc].items.size(); i++) // Loop through items and draw each
if(univ.party[current_active_pc].items[i].variety != eItemType::NO_ITEM) { // i.e. does item exist
std::string to_draw = std::to_string(i + 1) + ". ";

View File

@@ -169,7 +169,7 @@ void adjust_window (sf::RenderWindow& mainPtr, sf::View& mainView) {
mainPtr.setView(mainView);
#ifndef SFML_SYSTEM_MAC // This overrides Dock icon on OSX, which isn't what we want at all
const ImageRsrc& icon = ResMgr::graphics.get("icon", true);
auto const & icon = *ResMgr::textures.get("icon", true);
mainPtr.setIcon(icon->getSize().x, icon->getSize().y, icon->copyToImage().getPixelsPtr());
#endif

View File

@@ -3394,7 +3394,7 @@ void edit_custom_sheets() {
std::string resName = "sheet" + std::to_string(all_pics[cur]);
fs::path toPath = pic_dir/(resName + ".png");
img->saveToFile(toPath.string().c_str());
ResMgr::graphics.free(resName);
ResMgr::textures.free(resName);
return true;
}
sheets[cur] = *img;
@@ -3413,7 +3413,7 @@ void edit_custom_sheets() {
std::string resName = "sheet" + std::to_string(all_pics[cur]);
fs::path toPath = pic_dir/(resName + ".png");
img.saveToFile(toPath.string().c_str());
ResMgr::graphics.free(resName);
ResMgr::textures.free(resName);
return true;
}
sheets[cur] = img;
@@ -3479,7 +3479,7 @@ void edit_custom_sheets() {
if(!fs::exists(from)) continue; // Just in case
fs::remove(to);
fs::rename(from, to);
ResMgr::graphics.free("sheet" + std::to_string(which_pic));
ResMgr::textures.free("sheet" + std::to_string(which_pic));
}
auto end = std::find(all_pics.begin() + cur, all_pics.end(), which_pic - 1);
if(end != all_pics.end())
@@ -3492,7 +3492,7 @@ void edit_custom_sheets() {
all_pics.erase(all_pics.begin() + cur);
spec_scen_g.numSheets = which_pic;
spec_scen_g.sheets.resize(which_pic);
ResMgr::graphics.free("sheet" + std::to_string(which_pic));
ResMgr::textures.free("sheet" + std::to_string(which_pic));
}
}
fs::path fpath = pic_dir/("sheet" + std::to_string(which_pic) + ".png");

View File

@@ -381,10 +381,10 @@ void load_graphics(){
// Preload the main editor interface graphics
ResMgr::textures.get("edbuttons");
ResMgr::textures.get("teranim");
ResMgr::graphics.get("fields");
ResMgr::textures.get("fields");
ResMgr::textures.get("objects");
ResMgr::textures.get("tinyobj");
ResMgr::graphics.get("termap");
ResMgr::textures.get("termap");
}
void redraw_screen() {
@@ -542,7 +542,7 @@ void set_up_terrain_buttons(bool reset) {
pic = pic % 50;
ter_from.offset(28 * (pic % 10), 36 * (pic / 10));
int which_sheet = scenario.ter_types[i].picture / 50;
rect_draw_some_item(*ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet)),
rect_draw_some_item(*ResMgr::textures.get("ter" + std::to_string(1 + which_sheet)),
ter_from, mainPtr, draw_rect);
}
else {
@@ -754,8 +754,8 @@ void draw_terrain(){
destrec.bottom = destrec.top + BITMAP_HEIGHT;
destrec.offset(TER_RECT_UL_X,TER_RECT_UL_Y);
sf::Texture& fields_gworld = *ResMgr::graphics.get("fields");
sf::Texture& vehicle_gworld = *ResMgr::graphics.get("vehicle");
auto const & fields_gworld = *ResMgr::textures.get("fields");
auto const & vehicle_gworld = *ResMgr::textures.get("vehicle");
if(is_road(cen_x + q - 4,cen_y + r - 4))
rect_draw_some_item(fields_gworld, calc_rect(0, 2), mainPtr, destrec, sf::BlendAlpha);
@@ -1184,7 +1184,7 @@ void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short
from_rect.offset((picture_wanted / 3) * 12, (picture_wanted % 3) * 12);
rect_draw_some_item(*from_gw, from_rect, mainPtr, dest_rect);
} else {
sf::Texture& small_ter_gworld = *ResMgr::graphics.get("termap");
auto const & small_ter_gworld = *ResMgr::textures.get("termap");
if(picture_wanted >= 960) {
picture_wanted -= 960;
from_rect.offset(12 * 20, (picture_wanted - 960) * 12);
@@ -1294,7 +1294,7 @@ static void place_selected_terrain(ter_num_t ter, rectangle draw_rect) {
else {
source_rect = get_template_rect(ter);
int which_sheet = picture_wanted / 50;
sf::Texture& terrain_gworld = *ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));
auto const & terrain_gworld = *ResMgr::textures.get("ter" + std::to_string(1 + which_sheet));
rect_draw_some_item(terrain_gworld,source_rect,
mainPtr,draw_rect);
}
@@ -1495,12 +1495,12 @@ void place_location() {
rect_draw_some_item(*source_gworld,source_rect,mainPtr,draw_rect,sf::BlendAlpha);
} else if(picture_wanted < 55) {
source_rect = calc_rect(picture_wanted % 5,picture_wanted / 5);
rect_draw_some_item(*ResMgr::graphics.get("objects"),source_rect,mainPtr,draw_rect,sf::BlendAlpha);
rect_draw_some_item(*ResMgr::textures.get("objects"),source_rect,mainPtr,draw_rect,sf::BlendAlpha);
} else {
draw_rect.inset(5, 9);
rectangle tiny_from = {0,0,18,18};
tiny_from.offset((picture_wanted % 10) * 18,(picture_wanted / 10) * 18);
rect_draw_some_item(*ResMgr::graphics.get("tinyobj"),tiny_from,mainPtr,draw_rect,sf::BlendAlpha);
rect_draw_some_item(*ResMgr::textures.get("tinyobj"),tiny_from,mainPtr,draw_rect,sf::BlendAlpha);
}
} else if(overall_mode == MODE_TOGGLE_SPECIAL_DOT) {
draw_field = true;
@@ -1519,7 +1519,7 @@ void place_location() {
source_rect = calc_rect(7, 0);
} else if(overall_mode == MODE_PLACE_FIRE_BARRIER) {
source_rect = calc_rect(8, 4);
rect_draw_some_item(*ResMgr::graphics.get("teranim"),source_rect,mainPtr,draw_rect,sf::BlendAlpha);
rect_draw_some_item(*ResMgr::textures.get("teranim"),source_rect,mainPtr,draw_rect,sf::BlendAlpha);
} else if(overall_mode == MODE_PLACE_FORCE_BARRIER) {
source_rect = calc_rect(8, 4);
rect_draw_some_item(*ResMgr::textures.get("teranim"),source_rect,mainPtr,draw_rect,sf::BlendAlpha);
@@ -1534,7 +1534,7 @@ void place_location() {
source_rect = calc_rect(mode_count, 3);
}
if(draw_field) {
const sf::Texture& fields_gworld = *ResMgr::graphics.get("fields");
auto const & fields_gworld = *ResMgr::textures.get("fields");
rect_draw_some_item(fields_gworld,source_rect,mainPtr,draw_rect,sf::BlendAlpha);
}
draw_rect.offset(0,40);

View File

@@ -188,7 +188,7 @@ void adjust_windows (sf::RenderWindow & mainPtr, sf::View & mainView) {
mainPtr.setView(mainView);
#ifndef SFML_SYSTEM_MAC // This overrides Dock icon on OSX, which isn't what we want at all
const ImageRsrc& icon = ResMgr::graphics.get("icon", true);
auto const & icon = *ResMgr::textures.get("icon", true);
mainPtr.setIcon(icon->getSize().x, icon->getSize().y, icon->copyToImage().getPixelsPtr());
#endif
init_menubar();