Skip to content

Commit

Permalink
refactor: Merge New Subscreens (ZQuestClassic#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 authored Aug 20, 2023
2 parents 01a98d5 + 7aac40d commit 7441956
Show file tree
Hide file tree
Showing 150 changed files with 14,100 additions and 11,057 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
4a60fd30f78754db103f40d07983e64715b28258
9492513da453edf2ad2fb2ff4ea18d6128a248ab
4efd9e4c0200db4f253fe800ca6c86f0859f6084
6e9c3767ed30e84cc13df2674fd8a141d761b084

# Mass comment update
f3ae9af4b92021cbfcf14ced7714968532b96b78
Expand Down
1 change: 1 addition & 0 deletions modules/zelda/ZeldaCore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ src/user_object.cpp
src/ffc.cpp
src/slopes.cpp
src/zc/saves.cpp
src/zc/db_rng.cpp

## End of Zelda Core module
)
1 change: 1 addition & 0 deletions modules/zelda/ZeldaSubscreen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(ZELDA_SUBSCREEN_SOURCES
# Add or remove files here
################################
src/subscr.cpp
src/new_subscr.cpp
src/zc/zc_subscr.cpp
src/md5.cpp
src/midi.cpp
Expand Down
1 change: 1 addition & 0 deletions modules/zquest/ZQuestCore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ src/qst.cpp
src/sprite.cpp
src/solidobject.cpp
src/subscr.cpp
src/new_subscr.cpp
src/zc/zc_custom.cpp
src/init.cpp
src/zinfo.cpp
Expand Down
3 changes: 3 additions & 0 deletions modules/zquest/ZQuestGUI.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ src/dialog/info.cpp
src/dialog/info_lister.cpp
src/dialog/about.cpp
src/dialog/subscr_props.cpp
src/dialog/subscr_settings.cpp
src/dialog/subscr_transition.cpp
src/dialog/subscr_lists_edit.cpp
src/dialog/room.cpp
src/dialog/foodlg.cpp
src/dialog/quest_rules.cpp
Expand Down
11 changes: 11 additions & 0 deletions resources/docs/ZScript_Additions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3286,6 +3286,14 @@ int MiscSprites[MISCSPR_MAX];
int MiscSFX[MISCSFX_MAX];
* The quest's misc sfx. Use the 'MISCSFX_' constants to access this array.

int OverrideItems[IC_MAX];
* The override values for each itemclass.
* Default value is `-2`. If set to `-2`, no override occurs.
* If > -2, anything that checks for the "highest level item" of this class,
* uses this ID instead.
* A value of '-1' indicates forcing it to return "no item".
* If set to an item ID that is of the wrong itemclass, has no effect.

untyped EventData[?];
* Contains event data for use with 'WaitEvent()' in generic scripts.
* Use the appropriate set of 'GENEV_' constants based on the event.
Expand Down Expand Up @@ -6507,6 +6515,9 @@ int ActiveSubscreen;

int PassiveSubscreen;
* The passive subscreen ID.

int OverlaySubscreen;
* The overlay subscreen ID.

int Grid[8];
* The rooms displayed either when the player has the map item,
Expand Down
1 change: 1 addition & 0 deletions src/base/dmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct dmap
byte tmusictrack;
byte active_subscreen;
byte passive_subscreen;
byte overlay_subscreen;
// int32_t emusic;
//byte padding;
//204
Expand Down
48 changes: 48 additions & 0 deletions src/base/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,54 @@ int32_t do_zqdialog(DIALOG *dialog, int32_t focus_obj)
popup_zqdialog_end();
return ret;
}
int32_t do_zqdialog_custom(DIALOG *dialog, int32_t focus_obj, std::function<bool(int)> proc)
{
DIALOG_PLAYER *player2;
ASSERT(dialog);
int ret;

popup_zqdialog_start();

while(true)
{
player2 = init_dialog(dialog, focus_obj);

bool should_draw = true;
int num_idle_frames = 0;
while(update_dialog(player2))
{
if (player2->res & D_REDRAWME)
{
player2->res &= ~D_REDRAWME;
should_draw = true;
}
if (should_draw)
{
should_draw = false;
num_idle_frames = 0;
update_hw_screen(true);
al_rest(1. / 60);
continue;
}

// Not perfect, but beats using 100% of CPU.
// The above may miss things, so draw at least a few times a second.
if (num_idle_frames++ == 15)
{
should_draw = 1;
}
al_rest(1. / 60);
}

ret = shutdown_dialog(player2);

if(proc(ret))
break;
}

popup_zqdialog_end();
return ret;
}



Expand Down
4 changes: 4 additions & 0 deletions src/base/mapscr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "base/zsys.h"
#include "base/qrs.h"

std::vector<mapscr> TheMaps;
std::vector<word> map_autolayers;
word map_count = 0;

byte mapscr::ffEffectWidth(size_t ind) const
{
return (byte)ffcs[ind].hit_width;
Expand Down
5 changes: 5 additions & 0 deletions src/base/mapscr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "base/zdefs.h"
#include "ffc.h"
#include <vector>

struct mapscr
{
Expand Down Expand Up @@ -294,5 +295,9 @@ enum
rMAX
};

extern std::vector<mapscr> TheMaps;
extern std::vector<word> map_autolayers;
extern word map_count;

#endif

14 changes: 8 additions & 6 deletions src/base/qrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
byte quest_rules[QUESTRULES_NEW_SIZE];
byte extra_rules[EXTRARULES_SIZE];

bool get_qr(int index)
bool get_qr(int index,byte* qrptr)
{
return get_bit(quest_rules,index)!=0;
if(!qrptr) qrptr = quest_rules;
return get_bit(qrptr,index)!=0;
}
void set_qr(int index,bool state)
void set_qr(int index,bool state,byte* qrptr)
{
set_bit(quest_rules,index,state);
if(!qrptr) qrptr = quest_rules;
set_bit(qrptr,index,state);
}
bool get_er(int index)
{
return get_bit(extra_rules,index)!=0;
return get_qr(index,extra_rules);
}
void set_er(int index,bool state)
{
set_bit(extra_rules,index,state);
set_qr(index,state,extra_rules);
}

23 changes: 20 additions & 3 deletions src/base/qrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ enum
qr_SCROLLWARP_NO_RESET_FRAME, qr_BROKEN_RAFT_SCROLL, qr_BROKEN_INPUT_DOWN_STATE, qr_OLD_GUY_HANDLING,
//52
qr_FREEFORM_SUBSCREEN_CURSOR, qr_SUBSCR_PRESS_TO_EQUIP, qr_FAIRY_FLAG_COMPAT, qr_MIRROR_PRISM_LAYERS,
qr_OLD_LENS_LAYEREFFECT, qr_PUSHBLOCK_SPRITE_LAYER,
qr_OLD_LENS_LAYEREFFECT, qr_PUSHBLOCK_SPRITE_LAYER, qr_OLD_SUBSCR, qr_ITM_0_INVIS_ON_BTNS,
//53
qr_NO_BUTTON_VERIFY, qr_OLD_GAUGE_TILE_LAYOUT,
//EMILY SPOT
//60
//CONNOR SPOT qr_ = 60*8,
Expand Down Expand Up @@ -221,10 +223,25 @@ enum extraRules
er_MAX
};

bool get_qr(int index);
void set_qr(int index,bool state);
enum //Rulesets
{
rulesetNONE, rulesetNES, rulesetFixedNES, rulesetBSZ, rulesetZ3, rulesetModern, rulesetLast
};

enum //Rule Templates
{
ruletemplateFixCompat, ruletemplateFixZSCompat,
ruletemplateNewSubscreen, ruletemplateOldSubscreen,
sz_ruletemplate
};

bool get_qr(int index,byte* qrptr = nullptr);
void set_qr(int index,bool state,byte* qrptr = nullptr);
bool get_er(int index);
void set_er(int index,bool state);
//Want to move these here, but looks complicated...
// void applyRuleset(int32_t ruleset, byte* qrptr = nullptr);
// void applyRuleTemplate(int32_t ruleTemplate, byte* qrptr = nullptr);

#endif

17 changes: 9 additions & 8 deletions src/base/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ zc_randgen* zc_get_default_rand()
return &default_rng;
}

int32_t zc_oldrand(zc_randgen* rng)
{
// RAND_MAX can't be used because it is platform dependent, and we need
// reproducible randomness. 0x7fff is the value MSVC uses.
return zc_rand(0x7fff, 0, rng);
}

int32_t zc_rand(zc_randgen* rng)
{
if(!rng) rng = &default_rng;
Expand All @@ -38,4 +31,12 @@ void zc_srand(int32_t seedval, zc_randgen* rng)
{
if(!rng) rng = &default_rng;
rng->seed(seedval);
}
}

int32_t zc_oldrand(zc_randgen* rng)
{
// RAND_MAX can't be used because it is platform dependent, and we need
// reproducible randomness. 0x7fff is the value MSVC uses.
return zc_rand(0x7fff, 0, rng);
}

20 changes: 19 additions & 1 deletion src/base/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,31 @@
#include "base/zdefs.h"
#include <random>

typedef std::mt19937 zc_randgen;
#ifdef IS_PLAYER
#define DEBUG_RAND false
#else
#define DEBUG_RAND false //Can only work when IS_PLAYER
#endif

typedef std::mt19937 zc_randgen;
zc_randgen* zc_get_default_rand();

#if !DEBUG_RAND || defined(_ZC_DBRNG)
int32_t zc_oldrand(zc_randgen* rng=NULL);
int32_t zc_rand(zc_randgen* rng=NULL);
int32_t zc_rand(int32_t upper, int32_t lower=0, zc_randgen* rng=NULL);
void zc_srand(int32_t seedval, zc_randgen* rng=NULL);
#else

#define zc_oldrand(...) db_oldrand(__FILE__,__LINE__,__VA_ARGS__)
int32_t db_oldrand(char const* f, int l,zc_randgen* rng=NULL);
#define zc_rand(...) db_rand(__FILE__,__LINE__,__VA_ARGS__)
int32_t db_rand(char const* f, int l,zc_randgen* rng=NULL);
int32_t db_rand(char const* f, int l,int32_t upper,int32_t lower=0,zc_randgen* rng=NULL);
#define zc_srand(...) db_srand(__FILE__,__LINE__,__VA_ARGS__)
void db_srand(char const* f, int l, int32_t seedval, zc_randgen* rng=NULL);

#endif

#endif

20 changes: 14 additions & 6 deletions src/base/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,25 +1050,33 @@ void zc_trace_clear()
ASSERT(trace_file);
}

std::string QRHINT(std::vector<int> qrs)
static std::string HINT_TY(std::vector<int> vals, dword ty)
{
if(qrs.empty()) return "";
if(vals.empty()) return "";
std::ostringstream oss;
bool comma = false;
oss << "$";
for(int qr : qrs)
oss << "$#" << ty << "#";
for(int v : vals)
{
if(comma)
oss << "," << qr;
oss << "," << v;
else
{
comma = true;
oss << qr;
oss << v;
}
}
oss << "$";
return oss.str();
}
std::string QRHINT(std::vector<int> qrs)
{
return HINT_TY(qrs,INFOHINT_T_QR);
}
std::string RULETMPL_HINT(std::vector<int> tmpls)
{
return HINT_TY(tmpls,INFOHINT_T_RULETMPL);
}

int binary_search_int(int b1, int b2, std::function<int(int,int&)> proc, int defval)
{
Expand Down
7 changes: 7 additions & 0 deletions src/base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ int32_t zc_trace_handler(const char *);
void zc_trace_clear();

std::string QRHINT(std::vector<int> qrs);
std::string RULETMPL_HINT(std::vector<int> tmpls);
enum //special insert types
{
INFOHINT_T_QR,
INFOHINT_T_RULETMPL,
INFOHINT_T_MAX
};

enum
{
Expand Down
Loading

0 comments on commit 7441956

Please sign in to comment.