windows release build, fix book crash, fix lock, fix finale

This commit is contained in:
Ondrej Novak 2025-02-08 20:08:01 +01:00
parent 3d8ee275e4
commit d13297e4f4
24 changed files with 158 additions and 63 deletions

View file

@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#include <string.h> #include <string.h>

View file

@ -764,7 +764,7 @@ void draw_medium_map(void)
{ {
int xr, yr; int xr, yr;
int xp, yp; int xp, yp;
int xc,yc,x,y; int xc=0,yc=0,x=0,y=0;
int j,i,k,layer; int j,i,k,layer;
//char c=" "; //char c=" ";

View file

@ -1363,7 +1363,7 @@ extern char att_player;
void mob_hit(TMOB *mm,int dostal) void mob_hit(TMOB *mm,int dostal)
{ {
int ch; int ch;
int mob_dostal,mob_dostal_pocet; int mob_dostal=0,mob_dostal_pocet=0;
if (mm->vlajky & MOB_PASSABLE) return; if (mm->vlajky & MOB_PASSABLE) return;
if (dostal>mm->vlastnosti[VLS_MAXHIT]) dostal=mm->vlastnosti[VLS_MAXHIT]; if (dostal>mm->vlastnosti[VLS_MAXHIT]) dostal=mm->vlastnosti[VLS_MAXHIT];

View file

@ -592,7 +592,7 @@ void global_map_point(EVENT_MSG *msg,void **_)
} }
} }
void unwire_global_map() void unwire_global_map(void)
{ {
purge_index_tab(); purge_index_tab();
send_message(E_DONE,E_MOUSE,global_map_point); send_message(E_DONE,E_MOUSE,global_map_point);
@ -601,7 +601,7 @@ void unwire_global_map()
} }
void wire_global_map() void wire_global_map(void)
{ {
unwire_proc(); unwire_proc();
schovej_mysku(); schovej_mysku();
@ -614,14 +614,14 @@ void wire_global_map()
change_click_map(NULL,0); change_click_map(NULL,0);
} }
static void *old_wire_save; static void (*old_wire_save)(void);
static int old_viewsector; static int old_viewsector;
static void empty_unwire() static void empty_unwire(void)
{ {
} }
static void unwire_automap_file() static void unwire_automap_file(void)
{ {
load_map_automap(level_fname); load_map_automap(level_fname);
wire_proc=old_wire_save; wire_proc=old_wire_save;

View file

@ -1207,7 +1207,7 @@ static void play_wav(int wav,int sector)
static void play_random_sound(int sector,int dir,int pos) static void play_random_sound(int sector,int dir,int pos)
{ {
int seed; int seed;
int v; int v=0;
seed=rand(); seed=rand();
srand(sector+dir); srand(sector+dir);
@ -1264,7 +1264,7 @@ void fletna_glob_add_note(uint8_t note)
if (strlen(globFletnaStr)<250) strcat(globFletnaStr,globNotes[note]); if (strlen(globFletnaStr)<250) strcat(globFletnaStr,globNotes[note]);
} }
static char compareMelody(const char *m1,const char *m2) static int compareMelody(const char *m1,const char *m2)
{ {
while (*m1 && *m2) while (*m1 && *m2)
{ {

View file

@ -803,7 +803,7 @@ char uloz_sip(int id,int xa,int ya,int xr,int yr);
char info_box_drawed=0; char info_box_drawed=0;
void *info_box_below=NULL; void *info_box_below=NULL;
void *inv_keyboard(EVENT_MSG *msg,void **usr); void inv_keyboard(EVENT_MSG *msg,void **usr);
T_CLK_MAP clk_inv_view[]= T_CLK_MAP clk_inv_view[]=
{ {
@ -1742,7 +1742,7 @@ void inv_item_info_box(EVENT_MSG *msg,void **data)
} }
} }
void unwire_inv_mode() void unwire_inv_mode(void)
{ {
send_message(E_DONE,E_KEYBOARD,inv_keyboard); send_message(E_DONE,E_KEYBOARD,inv_keyboard);
send_message(E_DONE,E_MOUSE,inv_item_info_box); send_message(E_DONE,E_MOUSE,inv_item_info_box);
@ -2189,7 +2189,7 @@ char human_click(int id,int xa,int ya,int xr,int yr)
} }
void *inv_keyboard(EVENT_MSG *msg,void **usr) void inv_keyboard(EVENT_MSG *msg,void **usr)
{ {
char c; char c;
@ -2215,7 +2215,6 @@ void *inv_keyboard(EVENT_MSG *msg,void **usr)
break; break;
} }
} }
return &inv_keyboard;
} }
@ -2241,9 +2240,9 @@ static int fly_count; //vyuziti mapy
void draw_fly_items(int celx,int cely,int sector,int side) void draw_fly_items(int celx,int cely,int sector,int side)
{ {
LETICI_VEC *p; LETICI_VEC *p;
int xpos,ypos; int xpos=0,ypos=0;
const short *pic; const short *pic;
short picnum;char turn,smr; short picnum;char turn=0,smr=0;
TITEM *it; TITEM *it;
int i; int i;
@ -2385,8 +2384,8 @@ char shop_keeper_click(int id, int xa, int ya,int xr,int yr);
char shop_block_click(int id, int xa, int ya,int xr,int yr); char shop_block_click(int id, int xa, int ya,int xr,int yr);
char shop_change_player(int id, int xa, int ya,int xr,int yr); char shop_change_player(int id, int xa, int ya,int xr,int yr);
char _exit_shop(int id, int xa, int ya,int xr,int yr); char _exit_shop(int id, int xa, int ya,int xr,int yr);
void unwire_shop(); void unwire_shop(void);
void wire_shop(); void wire_shop(void);
@ -2960,7 +2959,7 @@ static void shop_keyboard_proc(EVENT_MSG *msg, void **_) {
static int old_inv_view_mode; static int old_inv_view_mode;
void unwire_shop() void unwire_shop(void)
{ {
send_message(E_DONE,E_MOUSE,shop_mouse_event); send_message(E_DONE,E_MOUSE,shop_mouse_event);
send_message(E_DONE,E_KEYBOARD, shop_keyboard_proc); send_message(E_DONE,E_KEYBOARD, shop_keyboard_proc);
@ -2969,7 +2968,7 @@ void unwire_shop()
inv_view_mode=old_inv_view_mode; inv_view_mode=old_inv_view_mode;
} }
void wire_shop() void wire_shop(void)
{ {
int32_t size; int32_t size;
static TSHOP *last_shop=NULL; static TSHOP *last_shop=NULL;

View file

@ -283,12 +283,12 @@ static char read_set(TMPFILE_RD *txt,char *var,char *set)
do do
c=temp_storage_getc(txt); c=temp_storage_getc(txt);
while (c<33); while (c<33);
if (c=='"') temp_storage_scanf(txt,"%[^\"]%c%c",set,&d,&d); if (c=='"') temp_storage_scanf(txt,"%[^\"]%c%c",set,&d,&c);
else if (c=='\'') temp_storage_scanf(txt,"%[^']%c%c",set,&d,&d); else if (c=='\'') temp_storage_scanf(txt,"%[^']%c%c",set,&d,&c);
else else
{ {
temp_storage_ungetc(txt); temp_storage_ungetc(txt);
temp_storage_scanf(txt,"%[^> ]%c",set,&d); temp_storage_scanf(txt,"%[^> ]%c",set,&c);
} }
while(c<33 && c!=EOF) c=temp_storage_getc(txt); while(c<33 && c!=EOF) c=temp_storage_getc(txt);
if (c!='>') temp_storage_ungetc(txt); if (c!='>') temp_storage_ungetc(txt);
@ -308,7 +308,7 @@ static char read_set(TMPFILE_RD *txt,char *var,char *set)
return c; return c;
} }
static int get_data_handle(char *filename,void *dec) static int get_data_handle(char *filename,ABLOCK_DECODEPROC dec)
{ {
int i; int i;
@ -492,7 +492,7 @@ static void read_text(TMPFILE_RD *txt)
static void seek_section(TMPFILE_RD *txt,int sect_number) static void seek_section(TMPFILE_RD *txt,int sect_number)
{ {
int c=0,i; int c=0,i=0;
winconv=0; winconv=0;
do do

View file

@ -739,7 +739,7 @@ void call_macro_ex(int side, int flags, int runatside) {
z = mrec.action_list; z = mrec.action_list;
if (z->general.flags & flags) { if (z->general.flags & flags) {
int jmp_to = -1; int jmp_to = -1;
char force_cancel = 0; char cancel_enabled = 1;
int stindex = z - first_macro; int stindex = z - first_macro;
if (!z->general.once || !macro_state_block.states[stindex]) { if (!z->general.once || !macro_state_block.states[stindex]) {
macro_state_block.states[stindex] = 1; macro_state_block.states[stindex] = 1;
@ -789,14 +789,14 @@ void call_macro_ex(int side, int flags, int runatside) {
enter_shop(z->text.textindex); enter_shop(z->text.textindex);
break; break;
case MA_CLOCK: case MA_CLOCK:
force_cancel = decode_lock(z->clock.znak, z->clock.string, cancel_enabled = decode_lock(z->clock.znak, z->clock.string,
z->clock.codenum); z->clock.codenum);
break; break;
case MA_CACTN: case MA_CACTN:
cancel_action(z->cactn.sector, z->cactn.dir); cancel_action(z->cactn.sector, z->cactn.dir);
break; break;
case MA_LOCK: case MA_LOCK:
force_cancel = if_lock(side, z->lock.key_id, cancel_enabled = if_lock(side, z->lock.key_id,
z->lock.thieflevel, &z->lock); z->lock.thieflevel, &z->lock);
break; break;
case MA_SWAPS: case MA_SWAPS:
@ -879,7 +879,7 @@ void call_macro_ex(int side, int flags, int runatside) {
if (jmp_to != -1) { if (jmp_to != -1) {
mrec = go_macro(runatside, jmp_to); mrec = go_macro(runatside, jmp_to);
program_counter = jmp_to; program_counter = jmp_to;
} else if (z->general.cancel || force_cancel) { } else if (z->general.cancel && cancel_enabled) {
break; break;
} else { } else {
program_counter++; program_counter++;

View file

@ -672,7 +672,7 @@ static void kill_timer(void)
timer_tree.next=NULL; timer_tree.next=NULL;
} }
void *user_timer(EVENT_MSG *msg,void **usr) void user_timer(EVENT_MSG *msg,void **usr)
{ {
int x; int x;
static int lastvalue=0; static int lastvalue=0;
@ -685,7 +685,6 @@ void *user_timer(EVENT_MSG *msg,void **usr)
lastvalue+=x; lastvalue+=x;
if (x) send_message(E_TIMER,x); if (x) send_message(E_TIMER,x);
} }
return &user_timer;
} }
void do_timer(void) void do_timer(void)
@ -1305,7 +1304,7 @@ static void game_big_circle(char enforced)
char s[13]; char s[13];
purge_playlist(); purge_playlist();
s[12]=0;strcopy_n(s,loadlevel.name,12); strcopy_n(s,loadlevel.name,sizeof(s));
err=load_map(s); err=load_map(s);
if (!enforced) if (!enforced)
{ {
@ -1363,7 +1362,7 @@ static void game_big_circle(char enforced)
enter_game(); enter_game();
leave_current_map(); leave_current_map();
s[12]=0;strcopy_n(s,loadlevel.name,12); strcopy_n(s,loadlevel.name,sizeof(s));
if (s[0]!=0)err=load_map(s); if (s[0]!=0)err=load_map(s);
memset(GlobEventList,0,sizeof(GlobEventList)); memset(GlobEventList,0,sizeof(GlobEventList));
@ -1384,9 +1383,9 @@ static void new_game(int argc, char *argv[])
load_shops(); load_shops();
open_story_file(); open_story_file();
if (argc<2) if (argc<2)
strcopy_n(loadlevel.name,default_map,12); strcopy_n(loadlevel.name,default_map,sizeof(loadlevel.name));
else else
strcopy_n(loadlevel.name,argv[1],12); strcopy_n(loadlevel.name,argv[1],sizeof(loadlevel.name));
if (argc>2) if (argc>2)
{ {
sscanf(argv[2],"%d",&sect); sscanf(argv[2],"%d",&sect);

View file

@ -733,7 +733,7 @@ void wire_end_game()
if (mname != NULL) { if (mname != NULL) {
cur_group = postavy[i].groupnum; cur_group = postavy[i].groupnum;
TMA_LOADLEV lv; TMA_LOADLEV lv;
strcopy_n(lv.name,mname, sizeof(lv.name)-1); strcopy_n(lv.name,mname, sizeof(lv.name));
lv.start_pos = -postavy[i].sektor; lv.start_pos = -postavy[i].sektor;
lv.dir = postavy[i].direction; lv.dir = postavy[i].direction;
macro_load_another_map(&lv); macro_load_another_map(&lv);
@ -1968,7 +1968,7 @@ void fix_group_direction()
if (postavy[i].used && postavy[i].groupnum==g && !postavy[i].programovano) postavy[i].direction=viewdir; if (postavy[i].used && postavy[i].groupnum==g && !postavy[i].programovano) postavy[i].direction=viewdir;
} }
void souboje_turn(char smer) void souboje_turn(int smer)
{ {
if (pass_zavora) return; if (pass_zavora) return;
norefresh=1; norefresh=1;

View file

@ -49,15 +49,15 @@ void temp_storage_store(const char *name, const void *data, int32_t size) {
int32_t temp_storage_find(const char *name) { int32_t temp_storage_find(const char *name) {
auto iter = temp_fsystem.find(std::string_view(name)); auto iter = temp_fsystem.find(std::string_view(name));
if (iter == temp_fsystem.end()) return -1; if (iter == temp_fsystem.end()) return -1;
return iter->second.size(); return static_cast<int32_t>(iter->second.size());
} }
int32_t temp_storage_retrieve(const char *name, void *data, int32_t size) { int32_t temp_storage_retrieve(const char *name, void *data, int32_t size) {
auto iter = temp_fsystem.find(std::string_view(name)); auto iter = temp_fsystem.find(std::string_view(name));
if (iter == temp_fsystem.end()) return -1; if (iter == temp_fsystem.end()) return -1;
size = std::min<int32_t>(size, iter->second.size()); size = std::min<int32_t>(size, static_cast<int32_t>(iter->second.size()));
std::copy(iter->second.begin(), iter->second.end(), reinterpret_cast<uint8_t *>(data)); std::copy(iter->second.begin(), iter->second.end(), reinterpret_cast<uint8_t *>(data));
return iter->second.size(); return static_cast<int32_t>(iter->second.size());
} }
@ -109,7 +109,7 @@ uint32_t temp_storage_read(void *data, uint32_t size, TMPFILE_RD *f) {
d = d.substr(p.size()); d = d.substr(p.size());
auto b = reinterpret_cast<uint8_t *>(data); auto b = reinterpret_cast<uint8_t *>(data);
std::copy(p.begin(), p.end(), b); std::copy(p.begin(), p.end(), b);
return p.size(); return static_cast<uint32_t>(p.size());
} }
void temp_storage_skip(TMPFILE_RD *f, int bytes) { void temp_storage_skip(TMPFILE_RD *f, int bytes) {
@ -136,7 +136,7 @@ char *temp_storage_gets(char *buff, size_t sz, TMPFILE_RD *f) {
if (pos > d.size()) pos = d.size(); else ++pos; if (pos > d.size()) pos = d.size(); else ++pos;
if (pos == 0) return NULL; if (pos == 0) return NULL;
if (pos > sz - 1) pos = sz - 1; if (pos > sz - 1) pos = sz - 1;
temp_storage_read(buff, pos, f); temp_storage_read(buff, static_cast<int32_t>(pos), f);
buff[pos] = 0; buff[pos] = 0;
return buff; return buff;
} }

View file

@ -359,7 +359,7 @@ static reload_mobs()
{ {
extern char reset_mobiles; extern char reset_mobiles;
reset_mobiles=1; reset_mobiles=1;
strcopy_n(loadlevel.name,level_fname,12); strcopy_n(loadlevel.name,level_fname,sizeof(loadlevel.name));
loadlevel.start_pos=viewsector; loadlevel.start_pos=viewsector;
loadlevel.name[12]=0; loadlevel.name[12]=0;
loadlevel.dir=viewdir; loadlevel.dir=viewdir;

View file

@ -78,7 +78,7 @@ int build_tables()
case 128:while (fgetc(source)!='\n'); case 128:while (fgetc(source)!='\n');
fgetc(source); fgetc(source);
i=fscanf(source,"%[^\n]",global_name); i=fscanf(source,"%[^\n]",global_name);
strcopy_n(kouzla_tab[cur_spell].spellname,global_name,29); strcopy_n(kouzla_tab[cur_spell].spellname,global_name,sizeof(kouzla_tab[cur_spell].spellname));
printf("(%3d, 0x%05X) %s\n",cur_spell, kouzla_tab[cur_spell].start,global_name); printf("(%3d, 0x%05X) %s\n",cur_spell, kouzla_tab[cur_spell].start,global_name);
break; break;
case 129:add_prog_command(0xff); case 129:add_prog_command(0xff);

View file

@ -352,7 +352,7 @@ inline bool CSVReader<Source>::readRow(const CSVFieldIndexMapping<T> &mapping,T
} else { } else {
static_assert(std::is_same_v<TVal, bool>); static_assert(std::is_same_v<TVal, bool>);
CSVState st = read(buff); CSVState st = read(buff);
std::transform(buff.begin(), buff.end(), buff.begin(), [](char c) -> char { return std::tolower(c); }); std::transform(buff.begin(), buff.end(), buff.begin(), [](char c) -> char { return static_cast<char>(std::tolower(c)); });
if (buff == "y" || buff == "t" || buff =="true" || buff == "yes" || buff == "on") { if (buff == "y" || buff == "t" || buff =="true" || buff == "yes" || buff == "on") {
target.*ptr = true; target.*ptr = true;
} else if (buff == "n" || buff == "f" || buff =="false" || buff == "no" || buff == "off") { } else if (buff == "n" || buff == "f" || buff =="false" || buff == "no" || buff == "off") {

View file

@ -40,10 +40,9 @@ TSTR_LIST merge_configs(TSTR_LIST target, TSTR_LIST source)
int i; int i;
char *c; char *c;
buff[255]=0;
for (i=0;i<str_count(source);i++) if (source[i]) for (i=0;i<str_count(source);i++) if (source[i])
{ {
strcopy_n(buff,source[i],255); strcopy_n(buff,source[i],sizeof(buff));
c=strchr(buff,' '); c=strchr(buff,' ');
if (c!=NULL) if (c!=NULL)
{ {

View file

@ -666,7 +666,7 @@ void display_status()
int k; int k;
for(k=0;k<5;k++) copys[k]=h->flags & (1<<k)?flags[k]:'.'; for(k=0;k<5;k++) copys[k]=h->flags & (1<<k)?flags[k]:'.';
if (h->src_file[0]) strcopy_n(nname,h->src_file,12);else strcpy(nname,"<local>"); if (h->src_file[0]) strcopy_n(nname,h->src_file,sizeof(nname));else strcpy(nname,"<local>");
printf("%04Xh ... %12s %s %s %08lXh %6d %10d %6d \n",i*BK_MINOR_HANDLES+j, printf("%04Xh ... %12s %s %s %08lXh %6d %10d %6d \n",i*BK_MINOR_HANDLES+j,
nname,names[h->status-1], nname,names[h->status-1],
copys,(unsigned long)(uintptr_t)h->blockdata,h->size,h->counter,h->lockcount); copys,(unsigned long)(uintptr_t)h->blockdata,h->size,h->counter,h->lockcount);

View file

@ -363,7 +363,7 @@ char mgif_play(const void *mgif) //dekoduje a zobrazi frame
const char *pc; const char *pc;
char *ff; char *ff;
// int acts,size,act,csize; // int acts,size,act,csize;
const void *scr_sav; const void *scr_sav = 0;
int scr_act=-1; int scr_act=-1;

View file

@ -17,10 +17,10 @@ class MUSStreamParser: public IMusicStream {
public: public:
MUSStreamParser(const char *name) { MUSStreamParser(const char *name) {
data = map_file_to_memory(file_icase_find(name), &sz); _data = map_file_to_memory(file_icase_find(name), &sz);
if (data) { if (_data) {
_loaded = true; _loaded = true;
iter = reinterpret_cast<const uint8_t *>(data); iter = reinterpret_cast<const uint8_t *>(_data);
chans = read_short(); chans = read_short();
freq = read_int(); freq = read_int();
iter += 4; iter += 4;
@ -32,7 +32,7 @@ public:
} }
~MUSStreamParser() { ~MUSStreamParser() {
if (data) unmap_file(data, sz); if (_data) unmap_file(_data, sz);
} }
MUSStreamParser(const MUSStreamParser &) = delete; MUSStreamParser(const MUSStreamParser &) = delete;
MUSStreamParser& operator=(const MUSStreamParser &) = delete; MUSStreamParser& operator=(const MUSStreamParser &) = delete;
@ -60,7 +60,7 @@ public:
protected: protected:
bool _loaded = false; bool _loaded = false;
void *data; void *_data;
std::size_t sz; std::size_t sz;
std::int16_t chans; std::int16_t chans;

View file

@ -30,7 +30,7 @@ TSTRINGTABLE *stringtable_load(const char *filename) {
CSVRecord rec; CSVRecord rec;
std::unique_ptr<TSTRINGTABLE> tbl = std::make_unique<TSTRINGTABLE>(); std::unique_ptr<TSTRINGTABLE> tbl = std::make_unique<TSTRINGTABLE>();
while (reader.readRow(mapping, rec)) { while (reader.readRow(mapping, rec)) {
windows2kamenik(rec.string.data(), rec.string.size(), rec.string.data()); windows2kamenik(rec.string.data(), (int)rec.string.size(), rec.string.data());
tbl->_strings[rec.index] = rec.string; tbl->_strings[rec.index] = rec.string;
} }
return tbl.release(); return tbl.release();

View file

@ -173,7 +173,7 @@ EVENT_MSG *task_wait_event(int32_t event_number) {
return cur_message; return cur_message;
} }
int q_any_task() { int q_any_task() {
return task_list.size(); return (int)task_list.size();
} }
char task_quitmsg() { char task_quitmsg() {
if (current_task_inst == NULL) return 0; if (current_task_inst == NULL) return 0;

View file

@ -16,6 +16,7 @@
#pragma warning(disable: 4456) #pragma warning(disable: 4456)
#pragma warning(disable: 4457) #pragma warning(disable: 4457)
#pragma warning(disable: 4702) #pragma warning(disable: 4702)
#pragma warning(disable: 4100)
#define CASE_FALLTHROUGH #define CASE_FALLTHROUGH
#else #else
#define CASE_FALLTHROUGH [[fallthrough]] #define CASE_FALLTHROUGH [[fallthrough]]

View file

@ -26,9 +26,8 @@ void SDLContext::SDL_Deleter::operator ()(SDL_Texture* texture) {
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
} }
void SDLContext::SDL_Audio_Deleter::operator()(void *x) { void SDLContext::SDL_Audio_Deleter::operator()(SDL_AudioDeviceID x) {
SDL_AudioDeviceID id = reinterpret_cast<std::uintptr_t>(x); SDL_CloseAudioDevice(x);
SDL_CloseAudioDevice(id);
} }
struct SDL_INIT_Context { struct SDL_INIT_Context {
@ -602,12 +601,12 @@ SDLContext::AudioInfo SDLContext::init_audio(const AudioConfig &config, SDL_Audi
} }
throw std::runtime_error(err.str()); throw std::runtime_error(err.str());
} }
_audio.reset(reinterpret_cast<void *>(id)); _audio.reset(id);
return {obtaied.freq}; return {obtaied.freq};
} }
void SDLContext::pause_audio(bool pause) { void SDLContext::pause_audio(bool pause) {
SDL_AudioDeviceID id = reinterpret_cast<std::intptr_t>(_audio.get()); SDL_AudioDeviceID id = _audio.get();
SDL_PauseAudioDevice(id, pause?1:0); SDL_PauseAudioDevice(id, pause?1:0);
} }

View file

@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include <libs/mouse.h> #include <libs/mouse.h>
#include <functional> #include <functional>
#include "unique_value.h"
#include <queue> #include <queue>
@ -124,7 +125,7 @@ protected:
}; };
struct SDL_Audio_Deleter { struct SDL_Audio_Deleter {
void operator()(void *x); void operator()(SDL_AudioDeviceID x);
}; };
@ -142,7 +143,7 @@ protected:
std::unique_ptr<SDL_Texture, SDL_Deleter> _texture; std::unique_ptr<SDL_Texture, SDL_Deleter> _texture;
std::unique_ptr<SDL_Texture, SDL_Deleter> _texture2; std::unique_ptr<SDL_Texture, SDL_Deleter> _texture2;
std::unique_ptr<SDL_Texture, SDL_Deleter> _crt_effect; std::unique_ptr<SDL_Texture, SDL_Deleter> _crt_effect;
std::unique_ptr<void, SDL_Audio_Deleter> _audio; unique_value<SDL_AudioDeviceID, SDL_Audio_Deleter> _audio;
SDL_Texture *_visible_texture; SDL_Texture *_visible_texture;
SDL_Texture *_hidden_texture; SDL_Texture *_hidden_texture;

View file

@ -0,0 +1,96 @@
#include <optional>
#include <utility>
#include <type_traits>
template<typename T, typename Deleter>
class unique_value {
public:
using value_type = T;
using deleter_type = Deleter;
private:
std::optional<T> value;
deleter_type deleter;
public:
unique_value() noexcept(std::is_nothrow_default_constructible_v<Deleter>)
: value(std::nullopt), deleter{} { }
explicit unique_value(T v, Deleter d = Deleter{}) noexcept
: value(std::move(v)), deleter(std::move(d)) { }
// Zakázání kopírování
unique_value(const unique_value&) = delete;
unique_value& operator=(const unique_value&) = delete;
unique_value(unique_value&& other) noexcept
: value(std::move(other.value)), deleter(std::move(other.deleter))
{
other.value.reset();
}
unique_value& operator=(unique_value&& other) noexcept {
if (this != &other) {
reset(); // Uvolní aktuální hodnotu (volá deleter)
value = std::move(other.value);
deleter = std::move(other.deleter);
other.value.reset();
}
return *this;
}
~unique_value() {
reset();
}
T* operator->() {
return &(*value);
}
const T* operator->() const {
return &(*value);
}
T& operator*() {
return *value;
}
const T& operator*() const {
return *value;
}
T& get() {
return *value;
}
const T& get() const {
return *value;
}
bool has_value() const noexcept {
return value.has_value();
}
explicit operator bool() const noexcept {
return value.has_value();
}
std::optional<T> release() noexcept {
auto temp = std::move(value);
value.reset();
return temp;
}
void reset() noexcept {
if (value.has_value()) {
deleter(*value);
value.reset();
}
}
void reset(T &&v) noexcept {
reset();
value = std::move(v);
}
void reset(const T &v) noexcept {
reset();
value = v;
}
};