Expose the shared pointer instead of the raw pointer in the resource manager and rewrite the custom sheets list to use a vector instead of manual memory management
In particular, this should fix a segmentation fault in the sound system caused by the resource manager pulling a resource that's in use.
This commit is contained in:
@@ -632,7 +632,7 @@ void cPict::recalcRect() {
|
||||
setBounds(bounds);
|
||||
}
|
||||
|
||||
const sf::Texture* cPict::getSheet(eSheetType type, size_t n) {
|
||||
std::shared_ptr<const sf::Texture> cPict::getSheet(eSheetType type, size_t n) {
|
||||
std::ostringstream sout;
|
||||
switch(type) {
|
||||
case NUM_SHEET_TYPES:
|
||||
@@ -734,7 +734,7 @@ void cPict::draw(){
|
||||
}
|
||||
|
||||
void cPict::drawPresetTer(short num, rectangle to_rect){
|
||||
const sf::Texture* from_gw = getSheet(SHEET_TER, num / 50);
|
||||
auto from_gw = getSheet(SHEET_TER, num / 50);
|
||||
if(!from_gw) return;
|
||||
num = num % 50;
|
||||
rectangle from_rect = calc_rect(num % 10, num / 10);
|
||||
@@ -745,7 +745,7 @@ void cPict::drawPresetTer(short num, rectangle to_rect){
|
||||
|
||||
void cPict::drawPresetTerAnim(short num, rectangle to_rect){
|
||||
rectangle from_rect = calc_rect(4 * (num / 5) + animFrame % 4, num % 5);
|
||||
const sf::Texture* from_gw = getSheet(SHEET_TER_ANIM);
|
||||
auto from_gw = getSheet(SHEET_TER_ANIM);
|
||||
if(to_rect.right - to_rect.left > 28) {
|
||||
to_rect.inset(4,0);
|
||||
to_rect.right = to_rect.left + 28;
|
||||
@@ -771,7 +771,7 @@ static rectangle calcDefMonstRect(short i, short animFrame){
|
||||
|
||||
void cPict::drawPresetMonstSm(short num, rectangle to_rect){
|
||||
short m_start_pic = m_pic_index[num].i;
|
||||
const sf::Texture* from_gw = getSheet(SHEET_MONST, m_start_pic / 20);
|
||||
auto from_gw = getSheet(SHEET_MONST, m_start_pic / 20);
|
||||
if(!from_gw) return;
|
||||
m_start_pic = m_start_pic % 20;
|
||||
rectangle from_rect = calcDefMonstRect(m_start_pic, animFrame);
|
||||
@@ -787,7 +787,7 @@ void cPict::drawPresetMonstWide(short num, rectangle to_rect){
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
|
||||
short m_start_pic = m_pic_index[num].i;
|
||||
const sf::Texture* from_gw = getSheet(SHEET_MONST, m_start_pic / 20);
|
||||
auto from_gw = getSheet(SHEET_MONST, m_start_pic / 20);
|
||||
if(!from_gw) return;
|
||||
rectangle from_rect = calcDefMonstRect(m_start_pic % 20, animFrame);
|
||||
small_monst_rect.offset(to_rect.left,to_rect.top + 7);
|
||||
@@ -808,7 +808,7 @@ void cPict::drawPresetMonstTall(short num, rectangle to_rect){
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
|
||||
short m_start_pic = m_pic_index[num].i;
|
||||
const sf::Texture* from_gw = getSheet(SHEET_MONST, m_start_pic / 20);
|
||||
auto from_gw = getSheet(SHEET_MONST, m_start_pic / 20);
|
||||
if(!from_gw) return;
|
||||
rectangle from_rect = calcDefMonstRect(m_start_pic % 20, animFrame);
|
||||
small_monst_rect.offset(to_rect.left + 7,to_rect.top);
|
||||
@@ -829,7 +829,7 @@ void cPict::drawPresetMonstLg(short num, rectangle to_rect){
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
|
||||
short m_start_pic = m_pic_index[num].i;
|
||||
const sf::Texture* from_gw = getSheet(SHEET_MONST, m_start_pic / 20);
|
||||
auto from_gw = getSheet(SHEET_MONST, m_start_pic / 20);
|
||||
if(!from_gw) return;
|
||||
rectangle from_rect = calcDefMonstRect(m_start_pic % 20, animFrame);
|
||||
small_monst_rect.offset(to_rect.left,to_rect.top);
|
||||
@@ -860,7 +860,7 @@ void cPict::drawPresetMonstLg(short num, rectangle to_rect){
|
||||
void cPict::drawPresetDlog(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 36;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
const sf::Texture* from_gw = getSheet(SHEET_DLOG);
|
||||
auto from_gw = getSheet(SHEET_DLOG);
|
||||
rectangle from_rect = {0,0,36,36};
|
||||
from_rect.offset(36 * (num % 4),36 * (num / 4));
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect);
|
||||
@@ -869,7 +869,7 @@ void cPict::drawPresetDlog(short num, rectangle to_rect){
|
||||
void cPict::drawPresetDlogLg(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + (drawScaled ? getBounds().width() : 72);
|
||||
to_rect.bottom = to_rect.top + (drawScaled ? getBounds().height() : 72);
|
||||
const sf::Texture* from_gw = getSheet(SHEET_DLOG);
|
||||
auto from_gw = getSheet(SHEET_DLOG);
|
||||
rectangle from_rect = {0,0,72,72};
|
||||
from_rect.offset(36 * (num % 4),36 * (num / 4));
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect);
|
||||
@@ -878,14 +878,14 @@ void cPict::drawPresetDlogLg(short num, rectangle to_rect){
|
||||
void cPict::drawPresetTalk(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 32;
|
||||
to_rect.bottom = to_rect.top + 32;
|
||||
const sf::Texture* from_gw = getSheet(SHEET_TALK);
|
||||
auto from_gw = getSheet(SHEET_TALK);
|
||||
rectangle from_rect = {0,0,32,32};
|
||||
from_rect.offset(32 * (num % 10),32 * (num / 10));
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect);
|
||||
}
|
||||
|
||||
void cPict::drawPresetScen(short num, rectangle to_rect){
|
||||
const sf::Texture* from_gw = getSheet(SHEET_SCEN);
|
||||
auto from_gw = getSheet(SHEET_SCEN);
|
||||
rectangle from_rect = {0,0,32,32};
|
||||
from_rect.offset(32 * (num % 5),32 * (num / 5));
|
||||
to_rect.right = to_rect.left + 32;
|
||||
@@ -894,7 +894,7 @@ void cPict::drawPresetScen(short num, rectangle to_rect){
|
||||
}
|
||||
|
||||
void cPict::drawPresetScenLg(short num, rectangle to_rect){
|
||||
const sf::Texture* from_gw = getSheet(SHEET_SCEN_LG);
|
||||
auto from_gw = getSheet(SHEET_SCEN_LG);
|
||||
to_rect.right = to_rect.left + (drawScaled ? getBounds().width() : 64);
|
||||
to_rect.bottom = to_rect.top + (drawScaled ? getBounds().height() : 64);
|
||||
rectangle from_rect = {0,0,64,64};
|
||||
@@ -906,7 +906,7 @@ void cPict::drawPresetItem(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
rectangle from_rect = {0,0,18,18};
|
||||
if(num < 55) {
|
||||
from_gw = getSheet(SHEET_ITEM);
|
||||
@@ -923,15 +923,14 @@ void cPict::drawPresetTinyItem(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 18;
|
||||
to_rect.bottom = to_rect.top + 18;
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
const sf::Texture* from_gw;
|
||||
rectangle from_rect = {0,0,18,18};
|
||||
from_gw = getSheet(SHEET_TINY_ITEM);
|
||||
auto from_gw = getSheet(SHEET_TINY_ITEM);
|
||||
from_rect.offset(18 * (num % 10), 18 * (num / 10));
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
}
|
||||
|
||||
void cPict::drawPresetPc(short num, rectangle to_rect){
|
||||
const sf::Texture* from_gw = getSheet(SHEET_PC);
|
||||
auto from_gw = getSheet(SHEET_PC);
|
||||
rectangle from_rect = calc_rect(2 * (num / 8), num % 8);
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
@@ -940,7 +939,7 @@ void cPict::drawPresetPc(short num, rectangle to_rect){
|
||||
}
|
||||
|
||||
void cPict::drawPresetField(short num, rectangle to_rect){
|
||||
const sf::Texture* from_gw = getSheet(SHEET_FIELD);
|
||||
auto from_gw = getSheet(SHEET_FIELD);
|
||||
rectangle from_rect = calc_rect(num % 8, num / 8);
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
@@ -949,7 +948,7 @@ void cPict::drawPresetField(short num, rectangle to_rect){
|
||||
}
|
||||
|
||||
void cPict::drawPresetBoom(short num, rectangle to_rect){
|
||||
const sf::Texture* from_gw = getSheet(SHEET_BOOM);
|
||||
auto from_gw = getSheet(SHEET_BOOM);
|
||||
if(num >= 8)
|
||||
num = 8 * (num - 7) + animFrame % 8;
|
||||
rectangle from_rect = calc_rect(num % 8, num / 8);
|
||||
@@ -962,7 +961,7 @@ void cPict::drawPresetBoom(short num, rectangle to_rect){
|
||||
|
||||
void cPict::drawFullSheet(short num, rectangle to_rect){
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw = getSheet(SHEET_FULL, num);
|
||||
auto from_gw = getSheet(SHEET_FULL, num);
|
||||
from_rect = rectangle(*from_gw);
|
||||
if(!drawScaled) {
|
||||
to_rect.right = to_rect.left + (from_rect.right - from_rect.left);
|
||||
@@ -973,7 +972,7 @@ void cPict::drawFullSheet(short num, rectangle to_rect){
|
||||
|
||||
void cPict::drawPresetMissile(short num, rectangle to_rect){
|
||||
rectangle from_rect = {0,0,18,18};
|
||||
const sf::Texture* from_gw = getSheet(SHEET_MISSILE);
|
||||
auto from_gw = getSheet(SHEET_MISSILE);
|
||||
to_rect.right = to_rect.left + 18;
|
||||
to_rect.bottom = to_rect.top + 18;
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
@@ -984,7 +983,7 @@ void cPict::drawPresetMissile(short num, rectangle to_rect){
|
||||
|
||||
void cPict::drawPresetTerMap(short num, rectangle to_rect){
|
||||
rectangle from_rect = {0,0,12,12};
|
||||
const sf::Texture* from_gw = getSheet(SHEET_TER_MAP);
|
||||
auto from_gw = getSheet(SHEET_TER_MAP);
|
||||
// TODO: Should probably fill black somewhere in here...?
|
||||
to_rect.right = to_rect.left + 24;
|
||||
to_rect.bottom = to_rect.top + 24;
|
||||
@@ -996,7 +995,7 @@ void cPict::drawPresetTerMap(short num, rectangle to_rect){
|
||||
|
||||
void cPict::drawStatusIcon(short num, rectangle to_rect){
|
||||
rectangle from_rect = {0,0,12,12};
|
||||
const sf::Texture* from_gw = getSheet(SHEET_STATUS);
|
||||
auto from_gw = getSheet(SHEET_STATUS);
|
||||
to_rect.right = to_rect.left + 12;
|
||||
to_rect.bottom = to_rect.top + 12;
|
||||
from_rect.offset(12 * (num % 3), 12 * (num / 3));
|
||||
@@ -1012,7 +1011,7 @@ void cPict::drawCustomTer(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect);
|
||||
}
|
||||
@@ -1022,7 +1021,7 @@ void cPict::drawCustomTerAnim(short num, rectangle to_rect){
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
num += animFrame % 4;
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect);
|
||||
}
|
||||
@@ -1035,7 +1034,7 @@ void cPict::drawCustomMonstSm(short num, rectangle to_rect){
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
}
|
||||
@@ -1049,7 +1048,7 @@ void cPict::drawCustomMonstWide(short num, rectangle to_rect){
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
small_monst_rect.offset(to_rect.left,to_rect.top + 7);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, small_monst_rect, sf::BlendAlpha);
|
||||
@@ -1068,7 +1067,7 @@ void cPict::drawCustomMonstTall(short num, rectangle to_rect){
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
small_monst_rect.offset(to_rect.left + 7,to_rect.top);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, small_monst_rect, sf::BlendAlpha);
|
||||
@@ -1087,7 +1086,7 @@ void cPict::drawCustomMonstLg(short num, rectangle to_rect){
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
small_monst_rect.offset(to_rect.left,to_rect.top);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, small_monst_rect, sf::BlendAlpha);
|
||||
@@ -1110,7 +1109,7 @@ static int dlog_to_w = 18, dlog_to_h = 36;
|
||||
|
||||
void cPict::drawCustomDlog(short num, rectangle to_rect){
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
to_rect.right = to_rect.left + dlog_to_w;
|
||||
to_rect.bottom = to_rect.top + dlog_to_h;
|
||||
@@ -1145,7 +1144,7 @@ void cPict::drawCustomDlogLg(short num, rectangle to_rect){
|
||||
|
||||
void cPict::drawCustomTalk(short num, rectangle to_rect){
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
to_rect.right = to_rect.left + 16;
|
||||
to_rect.bottom = to_rect.top + 32;
|
||||
@@ -1164,7 +1163,7 @@ void cPict::drawCustomItem(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
@@ -1174,7 +1173,7 @@ void cPict::drawCustomTinyItem(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 18;
|
||||
to_rect.bottom = to_rect.top + 18;
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
@@ -1184,7 +1183,7 @@ void cPict::drawCustomBoom(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num + animFrame % 8);
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
rect_draw_some_item(*from_gw, from_rect, *inWindow, to_rect, sf::BlendAlpha);
|
||||
@@ -1193,7 +1192,7 @@ void cPict::drawCustomBoom(short num, rectangle to_rect){
|
||||
void cPict::drawCustomMissile(short num, rectangle to_rect){
|
||||
num += animFrame % 8;
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num);
|
||||
from_rect.right = from_rect.left + 18;
|
||||
from_rect.bottom = from_rect.top + 18;
|
||||
@@ -1205,7 +1204,7 @@ void cPict::drawCustomMissile(short num, rectangle to_rect){
|
||||
|
||||
void cPict::drawCustomTerMap(short num, rectangle to_rect){
|
||||
rectangle from_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num % 1000);
|
||||
from_rect.right = from_rect.left + 12;
|
||||
from_rect.bottom = from_rect.top + 12;
|
||||
@@ -1219,7 +1218,7 @@ void cPict::drawCustomTerMap(short num, rectangle to_rect){
|
||||
void cPict::drawPartyMonstSm(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
rectangle from_rect;
|
||||
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num, true);
|
||||
@@ -1232,7 +1231,7 @@ void cPict::drawPartyMonstWide(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
rectangle from_rect;
|
||||
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num, true);
|
||||
@@ -1249,7 +1248,7 @@ void cPict::drawPartyMonstTall(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
rectangle from_rect;
|
||||
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num, true);
|
||||
@@ -1266,7 +1265,7 @@ void cPict::drawPartyMonstLg(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
fill_rect(*inWindow, to_rect, sf::Color::Black);
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
rectangle from_rect;
|
||||
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num, true);
|
||||
@@ -1287,7 +1286,7 @@ void cPict::drawPartyMonstLg(short num, rectangle to_rect){
|
||||
}
|
||||
|
||||
void cPict::drawPartyScen(short num, rectangle to_rect){
|
||||
const sf::Texture* from_gw = getSheet(SHEET_HEADER);
|
||||
auto from_gw = getSheet(SHEET_HEADER);
|
||||
rectangle from_rect = {0,0,32,32};
|
||||
from_rect.offset(32 * (num % 5),32 * (num / 5));
|
||||
to_rect.right = to_rect.left + 32;
|
||||
@@ -1298,7 +1297,7 @@ void cPict::drawPartyScen(short num, rectangle to_rect){
|
||||
void cPict::drawPartyItem(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
rectangle from_rect;
|
||||
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num, true);
|
||||
@@ -1309,7 +1308,7 @@ void cPict::drawPartyItem(short num, rectangle to_rect){
|
||||
void cPict::drawPartyPc(short num, rectangle to_rect){
|
||||
to_rect.right = to_rect.left + 28;
|
||||
to_rect.bottom = to_rect.top + 36;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
rectangle from_rect;
|
||||
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(num, true);
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
cPict& operator=(cPict& other) = delete;
|
||||
cPict(cPict& other) = delete;
|
||||
private:
|
||||
static const sf::Texture* getSheet(eSheetType type, size_t n = 0);
|
||||
static std::shared_ptr<const sf::Texture> getSheet(eSheetType type, size_t n = 0);
|
||||
static short animFrame;
|
||||
pic_num_t picNum;
|
||||
ePicType picType;
|
||||
|
||||
@@ -391,9 +391,10 @@ bool load_party_v2(fs::path file_to_load, cUniverse& real_univ){
|
||||
sf::Image party_sheet;
|
||||
StdInputStream stream(fin);
|
||||
if(party_sheet.loadFromStream(stream)) {
|
||||
spec_scen_g.party_sheet.reset(new sf::Texture);
|
||||
spec_scen_g.party_sheet->create(party_sheet.getSize().x, party_sheet.getSize().y);
|
||||
spec_scen_g.party_sheet->update(party_sheet);
|
||||
sf::Texture sheet;
|
||||
sheet.create(party_sheet.getSize().x, party_sheet.getSize().y);
|
||||
sheet.update(party_sheet);
|
||||
spec_scen_g.party_sheet.reset(new sf::Texture(sheet));
|
||||
} else showWarning("There was an error loading the party custom graphics.");
|
||||
}
|
||||
|
||||
|
||||
@@ -2449,13 +2449,16 @@ void load_spec_graphics_v1(fs::path scen_file) {
|
||||
// This means they need an alpha channel
|
||||
graphics_store.createMaskFromColor(sf::Color::White);
|
||||
spec_scen_g.is_old = true;
|
||||
spec_scen_g.sheets = new sf::Texture[1];
|
||||
spec_scen_g.sheets.resize(1);
|
||||
spec_scen_g.numSheets = 1;
|
||||
if(!spec_scen_g.sheets[0].loadFromImage(graphics_store)) {
|
||||
sf::Texture sheet;
|
||||
if(sheet.loadFromImage(graphics_store)) {
|
||||
spec_scen_g.sheets[0].reset(new sf::Texture(sheet));
|
||||
} else {
|
||||
showWarning("An error occurred while converting old-style graphics into the new format.",noGraphics);
|
||||
spec_scen_g.is_old = false;
|
||||
spec_scen_g.numSheets = 0;
|
||||
delete[] spec_scen_g.sheets;
|
||||
spec_scen_g.sheets.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2464,12 +2467,12 @@ void load_spec_graphics_v1(fs::path scen_file) {
|
||||
void load_spec_graphics_v2(int num_sheets) {
|
||||
spec_scen_g.clear();
|
||||
if(num_sheets > 0) {
|
||||
spec_scen_g.sheets = new sf::Texture[num_sheets];
|
||||
spec_scen_g.sheets.resize(num_sheets);
|
||||
spec_scen_g.numSheets = num_sheets;
|
||||
}
|
||||
while(num_sheets-- > 0) {
|
||||
std::string name = "sheet" + std::to_string(num_sheets);
|
||||
ResMgr::graphics.free(name);
|
||||
spec_scen_g.sheets[num_sheets] = *ResMgr::graphics.get(name);
|
||||
spec_scen_g.sheets[num_sheets] = &ResMgr::graphics.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ namespace ResMgr {
|
||||
return **res_ptr;
|
||||
}
|
||||
// Overloading the address operator...
|
||||
const T*const operator&() const {
|
||||
return res_ptr.get()->get();
|
||||
std::shared_ptr<const T> operator&() const {
|
||||
return *res_ptr.get();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -317,7 +317,7 @@ void draw_startup_stats() {
|
||||
to_rect.offset(pc_rect.left,pc_rect.top);
|
||||
pic_num_t pic = univ.party[i].which_graphic;
|
||||
if(pic >= 1000) {
|
||||
const sf::Texture* gw;
|
||||
std::shared_ptr<const sf::Texture> gw;
|
||||
graf_pos_ref(gw, from_rect) = spec_scen_g.find_graphic(pic % 1000, pic >= 10000);
|
||||
rect_draw_some_item(*gw,from_rect,mainPtr,to_rect,sf::BlendAlpha);
|
||||
} else if(pic >= 100) {
|
||||
@@ -1191,7 +1191,7 @@ void draw_trim(short q,short r,short which_trim,ter_num_t ground_ter) {
|
||||
};
|
||||
static std::unique_ptr<sf::Texture> trim_masks[12], walkway_masks[9];
|
||||
rectangle from_rect = {0,0,36,28},to_rect;
|
||||
const sf::Texture* from_gworld;
|
||||
std::shared_ptr<const sf::Texture> from_gworld;
|
||||
sf::Texture* mask;
|
||||
static bool inited = false;
|
||||
if(!inited){
|
||||
|
||||
@@ -62,7 +62,7 @@ bool gave_no_g_error = false;
|
||||
void draw_one_terrain_spot (short i,short j,short terrain_to_draw) {
|
||||
rectangle where_draw;
|
||||
rectangle source_rect;
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
short anim_type = 0;
|
||||
location l;
|
||||
|
||||
@@ -146,7 +146,7 @@ void draw_monsters() {
|
||||
if(picture_wanted >= 0) {
|
||||
if(picture_wanted >= 1000) {
|
||||
for(short k = 0; k < width * height; k++) {
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
graf_pos_ref(src_gw, source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000 +
|
||||
((enc.direction < 4) ? 0 : (width * height)) + k);
|
||||
to_rect = monst_rects[(width - 1) * 2 + height - 1][k];
|
||||
@@ -189,7 +189,7 @@ void draw_monsters() {
|
||||
draw_one_terrain_spot((short) where_draw.x,(short) where_draw.y,10000 + univ.scenario.ter_types[ter].flag1);
|
||||
else if(monst.picture_num >= 1000) {
|
||||
bool isParty = monst.picture_num >= 10000;
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
pic_num_t need_pic = (monst.picture_num % 1000) + k;
|
||||
if(monst.direction >= 4) need_pic += width * height;
|
||||
if(combat_posing_monster == i + 100) need_pic += (2 * width * height);
|
||||
@@ -228,7 +228,7 @@ void draw_combat_pc(cPlayer& who, location center, bool attacking) {
|
||||
if(point_onscreen(center, who.combat_pos) && (cartoon_happening || party_can_see(who.combat_pos) < 6)) {
|
||||
location where_draw(who.combat_pos.x - center.x + 4, who.combat_pos.y - center.y + 4);
|
||||
rectangle source_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
pic_num_t pic = who.which_graphic;
|
||||
if(pic >= 1000) {
|
||||
bool isParty = pic >= 10000;
|
||||
@@ -303,7 +303,7 @@ void draw_items(location where){
|
||||
if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].item_loc == where) {
|
||||
if(univ.town.items[i].contained) continue;
|
||||
if(party_can_see(where) >= 6) continue;
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
to_rect = coord_to_rect(where_draw.x,where_draw.y);
|
||||
if(univ.town.items[i].graphic_num >= 10000){
|
||||
graf_pos_ref(src_gw, from_rect) = spec_scen_g.find_graphic(univ.town.items[i].graphic_num - 10000, true);
|
||||
@@ -451,7 +451,7 @@ void draw_party_symbol(location center) {
|
||||
|
||||
if((univ.party.in_boat < 0) && (univ.party.in_horse < 0)) {
|
||||
i = first_active_pc();
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
pic_num_t pic = univ.party[i].which_graphic;
|
||||
if(pic >= 1000) {
|
||||
bool isParty = pic >= 10000;
|
||||
|
||||
@@ -424,7 +424,7 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) {
|
||||
base -= 10000;
|
||||
} else base -= 1000;
|
||||
base += step % 4;
|
||||
const sf::Texture* from_gw = nullptr;
|
||||
std::shared_ptr<const sf::Texture> from_gw = nullptr;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(base, isParty);
|
||||
if(from_gw == nullptr) continue;
|
||||
from_rect.width() = 18;
|
||||
@@ -557,7 +557,7 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) {
|
||||
if(store_booms[i].boom_type >= 0) {
|
||||
if((t + store_booms[i].offset >= 0) && (t + store_booms[i].offset <= 7)) {
|
||||
if(cur_boom_type >= 1000) {
|
||||
const sf::Texture* src_gworld;
|
||||
std::shared_ptr<const sf::Texture> src_gworld;
|
||||
graf_pos_ref(src_gworld, from_rect) = spec_scen_g.find_graphic(cur_boom_type - 1000 + t);
|
||||
rect_draw_some_item(*src_gworld, from_rect, mainPtr, explode_place_rect[i], sf::BlendAlpha);
|
||||
} else {
|
||||
@@ -606,7 +606,7 @@ void click_shop_rect(rectangle area_rect) {
|
||||
graf_pos calc_item_rect(int num,rectangle& to_rect) {
|
||||
if(num >= 1000) return spec_scen_g.find_graphic(num - 1000);
|
||||
rectangle from_rect = {0,0,18,18};
|
||||
const sf::Texture *from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
if(num < 55) {
|
||||
from_gw = &ResMgr::graphics.get("objects");
|
||||
from_rect = calc_rect(num % 5, num / 5);
|
||||
@@ -666,7 +666,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
|
||||
// Place store icon
|
||||
if(!pressed) {
|
||||
rectangle from_rect = {0,0,32,32};
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
int i = std::max<int>(0, active_shop.getFace());
|
||||
if(i >= 1000) {
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(i - 1000);
|
||||
@@ -734,7 +734,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
|
||||
base_item = item.item;
|
||||
std::string cur_name = base_item.full_name, cur_info_str;
|
||||
rectangle from_rect, to_rect = shopping_rects[i][SHOPRECT_GRAPHIC];
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
switch(item.type) {
|
||||
case eShopItemType::ITEM:
|
||||
base_item.ident = true;
|
||||
|
||||
@@ -435,7 +435,7 @@ void place_item_graphic(short which_slot,short graphic) {
|
||||
to_rect.inset(-1,-1);
|
||||
to_rect.offset(20,1);
|
||||
from_rect.inset(2,2);
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
if(graphic >= 10000) {
|
||||
graf_pos_ref(src_gw, from_rect) = spec_scen_g.find_graphic(graphic - 10000, true);
|
||||
rect_draw_some_item(*src_gw, from_rect, item_stats_gworld, to_rect,sf::BlendAlpha);
|
||||
@@ -496,7 +496,7 @@ void place_item_bottom_buttons() {
|
||||
to_rect = item_screen_button_rects[i];
|
||||
rect_draw_some_item(invenbtn_gworld, but_from_rect, item_stats_gworld, to_rect, sf::BlendAlpha);
|
||||
pic_num_t pic = univ.party[i].which_graphic;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
if(pic >= 1000) {
|
||||
bool isParty = pic >= 10000;
|
||||
pic_num_t need_pic = pic % 1000;
|
||||
|
||||
@@ -1428,7 +1428,7 @@ void draw_map(bool need_refresh) {
|
||||
if(pic >= 1000) {
|
||||
if(spec_scen_g) {
|
||||
//print_nums(0,99,pic);
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
if(drawLargeIcon) {
|
||||
pic = pic % 1000;
|
||||
graf_pos_ref(src_gw, custom_from) = spec_scen_g.find_graphic(pic);
|
||||
@@ -1448,7 +1448,7 @@ void draw_map(bool need_refresh) {
|
||||
rect_draw_some_item(*ResMgr::graphics.get("teranim"), custom_from, map_gworld, draw_rect);
|
||||
} else {
|
||||
int which_sheet = pic / 50;
|
||||
const sf::Texture* src_gw = &ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));
|
||||
auto src_gw = &ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));
|
||||
pic %= 50;
|
||||
custom_from = calc_rect(pic % 10, pic / 10);
|
||||
rect_draw_some_item(*src_gw, custom_from, map_gworld, draw_rect);
|
||||
|
||||
@@ -29,7 +29,7 @@ graf_pos cCustomGraphics::find_graphic(pic_num_t which_rect, bool party) {
|
||||
else if(numSheets == 0) valid = false;
|
||||
if(!valid) {
|
||||
INVALID:
|
||||
const sf::Texture* blank = &ResMgr::graphics.get("blank");
|
||||
std::shared_ptr<const sf::Texture> blank = &ResMgr::graphics.get("blank");
|
||||
return {blank, {0,0,36,28}};
|
||||
}
|
||||
short sheet = which_rect / 100;
|
||||
@@ -38,22 +38,22 @@ graf_pos cCustomGraphics::find_graphic(pic_num_t which_rect, bool party) {
|
||||
rectangle store_rect = {0,0,36,28};
|
||||
|
||||
store_rect.offset(28 * (which_rect % 10),36 * (which_rect / 10));
|
||||
sf::Texture* the_sheet = party ? party_sheet.get() : &sheets[sheet];
|
||||
std::shared_ptr<const sf::Texture> the_sheet = party ? party_sheet : sheets[sheet];
|
||||
rectangle test(*the_sheet);
|
||||
if((store_rect & test) != store_rect) goto INVALID; // FIXME: HACK
|
||||
return std::make_pair(the_sheet,store_rect);
|
||||
}
|
||||
|
||||
size_t cCustomGraphics::count(bool party) {
|
||||
if(!party && sheets == nullptr) return 0;
|
||||
if(!party && !sheets.empty()) return 0;
|
||||
else if(party && party_sheet == nullptr) return 0;
|
||||
else if(is_old || party) {
|
||||
rectangle bounds(party ? *party_sheet : sheets[0]);
|
||||
rectangle bounds(party ? *party_sheet : *sheets[0]);
|
||||
if(bounds.width() < 280) return bounds.width() / 28;
|
||||
return 10 * bounds.height() / 36;
|
||||
} else {
|
||||
size_t count = 100 * (numSheets - 1);
|
||||
rectangle bounds(sheets[numSheets - 1]);
|
||||
rectangle bounds(*sheets[numSheets - 1]);
|
||||
if(bounds.width() < 280) count += bounds.width() / 28;
|
||||
else count += 10 * bounds.height() / 36;
|
||||
return count;
|
||||
@@ -65,9 +65,10 @@ void cCustomGraphics::copy_graphic(pic_num_t dest, pic_num_t src, size_t numSlot
|
||||
if(!party_sheet) {
|
||||
sf::Image empty;
|
||||
empty.create(280, 180, sf::Color::Transparent);
|
||||
party_sheet.reset(new sf::Texture);
|
||||
party_sheet->create(280, 180);
|
||||
party_sheet->update(empty);
|
||||
sf::Texture sheet;
|
||||
sheet.create(280, 180);
|
||||
sheet.update(empty);
|
||||
party_sheet.reset(new sf::Texture(sheet));
|
||||
numSheets = 1;
|
||||
}
|
||||
size_t havePics = count();
|
||||
@@ -79,25 +80,25 @@ void cCustomGraphics::copy_graphic(pic_num_t dest, pic_num_t src, size_t numSlot
|
||||
temp.create(280, party_sheet->getSize().y + 36 * addRows);
|
||||
temp.clear(sf::Color::Transparent);
|
||||
rect_draw_some_item(*party_sheet, rectangle(*party_sheet), temp, rectangle(*party_sheet));
|
||||
*party_sheet = temp.getTexture();
|
||||
party_sheet.reset(new sf::Texture(temp.getTexture()));
|
||||
}
|
||||
const sf::Texture* from_sheet;
|
||||
const sf::Texture* to_sheet;
|
||||
sf::Texture* last_src = nullptr;
|
||||
std::shared_ptr<const sf::Texture> from_sheet;
|
||||
std::shared_ptr<const sf::Texture> to_sheet;
|
||||
std::shared_ptr<const sf::Texture> last_src = nullptr;
|
||||
sf::RenderTexture temp;
|
||||
rectangle from_rect, to_rect;
|
||||
for(size_t i = 0; i < numSlots; i++) {
|
||||
graf_pos_ref(from_sheet, from_rect) = find_graphic(src + i);
|
||||
graf_pos_ref(to_sheet, to_rect) = find_graphic(dest + i, true);
|
||||
if(to_sheet != last_src) {
|
||||
if(last_src) *last_src = temp.getTexture();
|
||||
last_src = const_cast<sf::Texture*>(to_sheet);
|
||||
if(last_src) last_src.reset(new sf::Texture(temp.getTexture()));
|
||||
last_src = to_sheet;
|
||||
temp.create(to_sheet->getSize().x, to_sheet->getSize().y);
|
||||
rect_draw_some_item(*to_sheet, rectangle(*to_sheet), temp, rectangle(*to_sheet));
|
||||
}
|
||||
rect_draw_some_item(*from_sheet, from_rect, temp, to_rect);
|
||||
}
|
||||
*last_src = temp.getTexture();
|
||||
last_src.reset(new sf::Texture(temp.getTexture()));
|
||||
}
|
||||
|
||||
extern std::string scenario_temp_dir_name;
|
||||
@@ -105,11 +106,11 @@ void cCustomGraphics::convert_sheets() {
|
||||
if(!is_old) return;
|
||||
int num_graphics = count();
|
||||
is_old = false;
|
||||
sf::Image old_graph = sheets[0].copyToImage();
|
||||
delete[] sheets;
|
||||
sf::Image old_graph = sheets[0]->copyToImage();
|
||||
sheets.clear();
|
||||
numSheets = num_graphics / 100;
|
||||
if(num_graphics % 100) numSheets++;
|
||||
sheets = new sf::Texture[numSheets];
|
||||
sheets.resize(numSheets);
|
||||
extern fs::path tempDir;
|
||||
fs::path pic_dir = tempDir/scenario_temp_dir_name/"graphics";
|
||||
for(size_t i = 0; i < numSheets; i++) {
|
||||
@@ -122,18 +123,22 @@ void cCustomGraphics::convert_sheets() {
|
||||
sheet.create(280, 360);
|
||||
sheet.copy(old_graph, 0, 0, subrect);
|
||||
|
||||
sheets[i].create(280, 360);
|
||||
sheets[i].update(sheet);
|
||||
sf::Texture sheet_tex;
|
||||
sheet_tex.create(280, 360);
|
||||
sheet_tex.update(sheet);
|
||||
sheets[i].reset(new sf::Texture(sheet_tex));
|
||||
|
||||
fs::path sheetPath = pic_dir/("sheet" + std::to_string(i) + ".png");
|
||||
sheets[i].copyToImage().saveToFile(sheetPath.string().c_str());
|
||||
sheets[i]->copyToImage().saveToFile(sheetPath.string().c_str());
|
||||
}
|
||||
ResMgr::graphics.pushPath(pic_dir);
|
||||
}
|
||||
|
||||
void cCustomGraphics::replace_sheet(size_t num, sf::Image& newSheet) {
|
||||
if(num >= numSheets) return; // TODO: Fail silently? Is that a good idea?
|
||||
sheets[num].loadFromImage(newSheet);
|
||||
sf::Texture replacement;
|
||||
replacement.loadFromImage(newSheet);
|
||||
sheets[num].reset(new sf::Texture(replacement));
|
||||
// Then we need to do some extra stuff to ensure the dialog engine also sees the change
|
||||
extern fs::path tempDir;
|
||||
std::string sheetname = "sheet" + std::to_string(num);
|
||||
@@ -143,19 +148,21 @@ void cCustomGraphics::replace_sheet(size_t num, sf::Image& newSheet) {
|
||||
}
|
||||
|
||||
void cCustomGraphics::init_sheet(size_t num) {
|
||||
sheets[num].create(280,360);
|
||||
sf::Texture placeholder;
|
||||
placeholder.create(280,360);
|
||||
sf::Image fill1, fill2;
|
||||
fill1.create(28,36,{0xff,0xff,0xc0});
|
||||
fill2.create(28,36,{0xc0,0xff,0xc0});
|
||||
for(int y = 0; y < 10; y++) {
|
||||
for(int x = 0; x < 10; x++) {
|
||||
if(x % 2 == y % 2) {
|
||||
sheets[num].update(fill1.getPixelsPtr(), 28, 36, x * 28, y * 36);
|
||||
placeholder.update(fill1.getPixelsPtr(), 28, 36, x * 28, y * 36);
|
||||
} else {
|
||||
sheets[num].update(fill2.getPixelsPtr(), 28, 36, x * 28, y * 36);
|
||||
placeholder.update(fill2.getPixelsPtr(), 28, 36, x * 28, y * 36);
|
||||
}
|
||||
}
|
||||
}
|
||||
sheets[num].reset(new sf::Texture(placeholder));
|
||||
}
|
||||
|
||||
extern const std::vector<m_pic_index_t> m_pic_index = {
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
#include "location.hpp"
|
||||
|
||||
static const pic_num_t NO_PIC = -1;
|
||||
using graf_pos = std::pair<const sf::Texture*,rectangle>;
|
||||
using graf_pos_ref = std::pair<const sf::Texture*&,rectangle&>;
|
||||
using graf_pos = std::pair<std::shared_ptr<const sf::Texture>,rectangle>;
|
||||
using graf_pos_ref = std::pair<std::shared_ptr<const sf::Texture>&,rectangle&>;
|
||||
|
||||
struct m_pic_index_t {
|
||||
unsigned char i, x, y;
|
||||
@@ -25,18 +25,18 @@ struct m_pic_index_t {
|
||||
|
||||
struct cCustomGraphics {
|
||||
size_t numSheets;
|
||||
sf::Texture* sheets = nullptr;
|
||||
std::shared_ptr<sf::Texture> party_sheet;
|
||||
std::vector<std::shared_ptr<const sf::Texture>> sheets;
|
||||
std::shared_ptr<const sf::Texture> party_sheet;
|
||||
bool is_old = false;
|
||||
void clear() {
|
||||
if(sheets != nullptr) delete[] sheets;
|
||||
sheets = nullptr;
|
||||
}
|
||||
~cCustomGraphics() {
|
||||
clear();
|
||||
sheets.clear();
|
||||
party_sheet.reset();
|
||||
}
|
||||
explicit operator bool() {
|
||||
return sheets;
|
||||
return !sheets.empty() && bool(sheets[0]);
|
||||
}
|
||||
bool operator!() {
|
||||
return !bool(*this);
|
||||
}
|
||||
void convert_sheets();
|
||||
void copy_graphic(pic_num_t dest, pic_num_t src, size_t numSlots);
|
||||
|
||||
@@ -392,7 +392,7 @@ void display_party() {
|
||||
if(univ.party[i].main_status != eMainStatus::ABSENT) { // PC exists?
|
||||
// draw PC graphic
|
||||
pic_num_t pic = univ.party[i].which_graphic;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
if(pic >= 1000) {
|
||||
bool isParty = pic >= 10000;
|
||||
pic_num_t need_pic = pic % 1000;
|
||||
|
||||
@@ -3348,10 +3348,10 @@ void edit_custom_sheets() {
|
||||
|
||||
if(must_init_spec_g) {
|
||||
spec_scen_g.clear();
|
||||
spec_scen_g.sheets = new sf::Texture[1];
|
||||
spec_scen_g.sheets.resize(1);
|
||||
spec_scen_g.numSheets = 1;
|
||||
spec_scen_g.init_sheet(0);
|
||||
spec_scen_g.sheets[0].copyToImage().saveToFile((pic_dir/"sheet0.png").string().c_str());
|
||||
spec_scen_g.sheets[0]->copyToImage().saveToFile((pic_dir/"sheet0.png").string().c_str());
|
||||
all_pics.insert(all_pics.begin(), 0);
|
||||
ResMgr::graphics.pushPath(pic_dir);
|
||||
}
|
||||
@@ -3362,7 +3362,7 @@ void edit_custom_sheets() {
|
||||
size_t cur = 0;
|
||||
std::unordered_map<size_t, sf::Image> sheets;
|
||||
for(size_t i = 0; i < spec_scen_g.numSheets; i++) {
|
||||
sheets[i] = spec_scen_g.sheets[i].copyToImage();
|
||||
sheets[i] = spec_scen_g.sheets[i]->copyToImage();
|
||||
}
|
||||
auto sheetsSave = sheets;
|
||||
|
||||
@@ -3438,11 +3438,9 @@ void edit_custom_sheets() {
|
||||
int newSheet = pickNum->getControl("num").getTextAsNum();
|
||||
fs::path sheetPath = pic_dir/("sheet" + std::to_string(newSheet) + ".png");
|
||||
if(newSheet == spec_scen_g.numSheets) {
|
||||
sf::Texture* wasSheets = spec_scen_g.sheets;
|
||||
spec_scen_g.sheets = new sf::Texture[spec_scen_g.numSheets + 1];
|
||||
std::copy_n(wasSheets, spec_scen_g.numSheets, spec_scen_g.sheets);
|
||||
spec_scen_g.sheets.emplace_back();
|
||||
spec_scen_g.init_sheet(newSheet);
|
||||
spec_scen_g.sheets[newSheet].copyToImage().saveToFile(sheetPath.string().c_str());
|
||||
spec_scen_g.sheets[newSheet]->copyToImage().saveToFile(sheetPath.string().c_str());
|
||||
spec_scen_g.numSheets++;
|
||||
auto iter = all_pics.insert(std::upper_bound(all_pics.begin(), all_pics.end(), newSheet), newSheet);
|
||||
cur = iter - all_pics.begin();
|
||||
@@ -3470,11 +3468,8 @@ void edit_custom_sheets() {
|
||||
if(which_pic < spec_scen_g.numSheets - 1)
|
||||
choice = cChoiceDlog("must-delete-in-order", {"cancel", "del", "move"}, &me).show();
|
||||
if(choice == "cancel") return true;
|
||||
sf::Texture* wasSheets = spec_scen_g.sheets;
|
||||
if(choice == "move") {
|
||||
spec_scen_g.sheets = new sf::Texture[spec_scen_g.numSheets-1];
|
||||
std::copy_n(wasSheets, which_pic, spec_scen_g.sheets);
|
||||
std::copy(wasSheets + which_pic + 1, wasSheets + spec_scen_g.numSheets, spec_scen_g.sheets + which_pic);
|
||||
spec_scen_g.sheets.erase(spec_scen_g.sheets.begin() + which_pic);
|
||||
spec_scen_g.numSheets--;
|
||||
for(; which_pic < spec_scen_g.numSheets; which_pic++) {
|
||||
fs::path from = pic_dir/("sheet" + std::to_string(which_pic + 1) + ".png");
|
||||
@@ -3494,11 +3489,9 @@ void edit_custom_sheets() {
|
||||
} else if(choice == "del") {
|
||||
all_pics.erase(all_pics.begin() + cur);
|
||||
spec_scen_g.numSheets = which_pic;
|
||||
spec_scen_g.sheets = new sf::Texture[which_pic];
|
||||
std::copy_n(wasSheets, which_pic, spec_scen_g.sheets);
|
||||
spec_scen_g.sheets.resize(which_pic);
|
||||
ResMgr::graphics.free("sheet" + std::to_string(which_pic));
|
||||
}
|
||||
delete[] wasSheets;
|
||||
}
|
||||
fs::path fpath = pic_dir/("sheet" + std::to_string(which_pic) + ".png");
|
||||
if(fs::exists(fpath)) fs::remove(fpath);
|
||||
|
||||
@@ -1089,7 +1089,7 @@ void save_scenario(bool rename) {
|
||||
if(spec_scen_g.is_old) {
|
||||
spec_scen_g.convert_sheets();
|
||||
for(size_t i = 0; i < spec_scen_g.numSheets; i++) {
|
||||
sf::Image sheet = spec_scen_g.sheets[i].copyToImage();
|
||||
sf::Image sheet = spec_scen_g.sheets[i]->copyToImage();
|
||||
fs::path tempPath = tempDir/"temp.png";
|
||||
sheet.saveToFile(tempPath.string());
|
||||
std::ostream& pic_out = scen_file.newFile("scenario/graphics/sheet" + std::to_string(i) + ".png");
|
||||
|
||||
@@ -518,7 +518,7 @@ void set_up_terrain_buttons(bool reset) {
|
||||
ter_from = ter_from_base;
|
||||
pic = scenario.ter_types[i].picture;
|
||||
if(pic >= 1000) {
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic % 1000);
|
||||
rect_draw_some_item(*source_gworld, ter_from, mainPtr, draw_rect);
|
||||
}
|
||||
@@ -555,7 +555,7 @@ void set_up_terrain_buttons(bool reset) {
|
||||
pic %= 1000;
|
||||
tiny_to.width() = tiny_to.width() / 2;
|
||||
tiny_to.height() = tiny_to.height() / 2;
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
|
||||
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
|
||||
pic++;
|
||||
@@ -575,7 +575,7 @@ void set_up_terrain_buttons(bool reset) {
|
||||
tiny_to.width() = tiny_to.width() / 2;
|
||||
tiny_to.height() = tiny_to.height() / 2;
|
||||
tiny_to.offset(tiny_to.width() / 2, 0);
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
|
||||
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
|
||||
pic++;
|
||||
@@ -587,7 +587,7 @@ void set_up_terrain_buttons(bool reset) {
|
||||
tiny_to.width() = tiny_to.width() / 2;
|
||||
tiny_to.height() = tiny_to.height() / 2;
|
||||
tiny_to.offset(0, tiny_to.height() / 2);
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
|
||||
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
|
||||
pic++;
|
||||
@@ -596,7 +596,7 @@ void set_up_terrain_buttons(bool reset) {
|
||||
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
|
||||
} else if(pic >= 1000) {
|
||||
pic %= 1000;
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic);
|
||||
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
|
||||
} else {
|
||||
@@ -653,7 +653,7 @@ void set_up_terrain_buttons(bool reset) {
|
||||
tiny_to = draw_rect;
|
||||
frame_rect(mainPtr, tiny_to, sf::Color::Black);
|
||||
if(pic >= 1000) {
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, ter_from) = spec_scen_g.find_graphic(pic % 1000);
|
||||
rect_draw_some_item(*source_gworld, ter_from, mainPtr, tiny_to, sf::BlendAlpha);
|
||||
} else {
|
||||
@@ -976,7 +976,7 @@ void draw_terrain(){
|
||||
|
||||
void draw_monsts() {
|
||||
short width,height,m_start_pic;
|
||||
const sf::Texture* from_gworld = nullptr;
|
||||
std::shared_ptr<const sf::Texture> from_gworld = nullptr;
|
||||
rectangle source_rect;
|
||||
location where_draw,store_loc;
|
||||
|
||||
@@ -1059,7 +1059,7 @@ void draw_items() {
|
||||
(where_draw.y >= 0) && (where_draw.y <= 8)) {
|
||||
|
||||
if(pic_num >= 1000) {
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(pic_num - 1000);
|
||||
dest_rect = calc_rect(where_draw.x,where_draw.y);
|
||||
dest_rect.offset(8+TER_RECT_UL_X,8+TER_RECT_UL_Y);
|
||||
@@ -1095,7 +1095,7 @@ void draw_one_terrain_spot (short i,short j,ter_num_t terrain_to_draw) {
|
||||
location where_draw;
|
||||
rectangle source_rect;
|
||||
short picture_wanted;
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
|
||||
if(i < 0 || i > 8 || j < 0 || j > 8)
|
||||
return;
|
||||
@@ -1136,7 +1136,7 @@ void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short
|
||||
rectangle dest_rect = {0,0,size,size},from_rect = {0,0,12,12};
|
||||
short picture_wanted;
|
||||
bool drawLargeIcon = false;
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
|
||||
picture_wanted = scenario.ter_types[terrain_to_draw].map_pic;
|
||||
if(picture_wanted == NO_PIC) {
|
||||
@@ -1160,7 +1160,7 @@ void draw_one_tiny_terrain_spot (short i,short j,ter_num_t terrain_to_draw,short
|
||||
rect_draw_some_item(*source_gworld, from_rect, mainPtr, dest_rect);
|
||||
} else {
|
||||
if(picture_wanted >= 1000) {
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
|
||||
from_rect.right = from_rect.left + 12;
|
||||
from_rect.bottom = from_rect.top + 12;
|
||||
@@ -1261,7 +1261,7 @@ static void place_selected_terrain(ter_num_t ter, rectangle draw_rect) {
|
||||
pic_num_t picture_wanted = scenario.ter_types[ter].picture;
|
||||
rectangle source_rect;
|
||||
if(picture_wanted >= 1000) {
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
|
||||
rect_draw_some_item(*source_gworld, source_rect,mainPtr,draw_rect);
|
||||
}
|
||||
@@ -1377,7 +1377,7 @@ void place_location() {
|
||||
picture_wanted %= 1000;
|
||||
to_rect.width() = to_rect.width() / 2;
|
||||
to_rect.height() = to_rect.height() / 2;
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
|
||||
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
|
||||
picture_wanted++;
|
||||
@@ -1397,7 +1397,7 @@ void place_location() {
|
||||
to_rect.width() = to_rect.width() / 2;
|
||||
to_rect.height() = to_rect.height() / 2;
|
||||
to_rect.offset(to_rect.width() / 2, 0);
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
|
||||
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
|
||||
picture_wanted++;
|
||||
@@ -1409,7 +1409,7 @@ void place_location() {
|
||||
to_rect.width() = to_rect.width() / 2;
|
||||
to_rect.height() = to_rect.height() / 2;
|
||||
to_rect.offset(0, to_rect.height() / 2);
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
|
||||
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
|
||||
picture_wanted++;
|
||||
@@ -1418,7 +1418,7 @@ void place_location() {
|
||||
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
|
||||
} else if(picture_wanted >= 1000) {
|
||||
picture_wanted %= 1000;
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted);
|
||||
rect_draw_some_item(*source_gworld, source_rect, mainPtr, to_rect, sf::BlendAlpha);
|
||||
} else {
|
||||
@@ -1472,7 +1472,7 @@ void place_location() {
|
||||
} else if(overall_mode == MODE_PLACE_ITEM || overall_mode == MODE_PLACE_SAME_ITEM) {
|
||||
picture_wanted = scenario.scen_items[mode_count].graphic_num;
|
||||
if(picture_wanted >= 1000) {
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
graf_pos_ref(source_gworld, source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000);
|
||||
rect_draw_some_item(*source_gworld,source_rect,mainPtr,draw_rect,sf::BlendAlpha);
|
||||
} else if(picture_wanted < 55) {
|
||||
|
||||
@@ -62,7 +62,7 @@ void init_snd_tool(){
|
||||
}
|
||||
|
||||
void play_sound(snd_num_t which, sf::Time delay) { // if < 0, play asynch
|
||||
const sf::SoundBuffer* sndhandle;
|
||||
std::shared_ptr<const sf::SoundBuffer> sndhandle;
|
||||
if(!get_bool_pref("PlaySounds", true)) {
|
||||
if(which >= 0)
|
||||
sf::sleep(delay);
|
||||
|
||||
Reference in New Issue
Block a user