Skip to content

Commit

Permalink
Changes for MC 1.21
Browse files Browse the repository at this point in the history
* added 1.21.2 to versions, as well as an experimental 1.21.3 for the pale_garden biome
* added trial chamber finder
* added inner linked gateways
* fixed inaccurate End generation at large distances from 0,0
* fixed copying seeds from matching seed list (#302)
* fixed non-persistent search progress and results list in headless mode (#310)
  • Loading branch information
Cubitect committed Oct 7, 2024
1 parent abcbfbd commit a5376bf
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 51 deletions.
2 changes: 1 addition & 1 deletion cubiomes
Submodule cubiomes updated 15 files
+54 −55 biomenoise.c
+7 −3 biomenoise.h
+455 −0 biomes.c
+33 −4 biomes.h
+9 −5 biometree.c
+405 −14 finders.c
+33 −3 finders.h
+4 −2 generator.c
+0 −452 layers.c
+0 −17 layers.h
+4 −1 makefile
+1 −1 tables/btree20.h
+2,342 −0 tables/btree213.h
+69 −7 tests.c
+30 −2 util.c
1 change: 1 addition & 0 deletions cubiomes-viewer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ HEADERS += \
$$CUPATH/finders.h \
$$CUPATH/generator.h \
$$CUPATH/layers.h \
$$CUPATH/biomes.h \
$$CUPATH/quadbase.h \
$$CUPATH/util.h \
$$LUAPATH/lapi.h \
Expand Down
Binary file modified rc/icons/chambers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rc/icons/chambers_d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool WorldInfo::equals(const WorldInfo& wi) const

void WorldInfo::reset()
{
mc = MC_NEWEST;
mc = MC_DEFAULT;
large = false;
seed = 0;
y = 255;
Expand Down Expand Up @@ -92,7 +92,7 @@ bool WorldInfo::read(const QString& line)
{
mc = str2mc(buf);
if (mc < 0)
mc = MC_NEWEST;
mc = MC_DEFAULT;
return true;
}
if (sscanf(p, "#Large: %d", &tmp) == 1)
Expand Down
3 changes: 2 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#define PRECOMPUTE48_BUFSIZ ((int64_t)1 << 30)

enum { MC_DEFAULT = MC_1_21_2 };

struct ExtGenConfig
{
Expand Down Expand Up @@ -77,7 +78,7 @@ enum {
LOPT_NOOCEAN_1,
LOPT_BETA_T_1,
LOPT_BETA_H_1,
LOPT_HEIGHT_4,
LOPT_HEIGHT,
LOPT_STRUCTS,
LOPT_MAX,
};
Expand Down
31 changes: 18 additions & 13 deletions src/formsearchcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,17 @@ void FormSearchControl::setSearchRange(uint64_t smin, uint64_t smax)
searchProgressReset();
}

bool FormSearchControl::getSeed(int row, uint64_t *seed)
{
QAbstractItemModel *model = ui->results->model();
if (row < 0 || row >= model->rowCount())
return false;
QModelIndex idx = model->index(row, SeedTableModel::COL_SEED);
*seed = model->data(idx, Qt::UserRole).toULongLong();
return true;
}


void FormSearchControl::on_buttonClear_clicked()
{
model->reset();
Expand Down Expand Up @@ -444,13 +455,9 @@ void FormSearchControl::on_buttonMore_clicked()

void FormSearchControl::onSeedSelectionChanged()
{
int row = ui->results->currentIndex().row();
if (row >= 0 && row < ui->results->model()->rowCount())
{
QModelIndex idx = ui->results->model()->index(row, SeedTableModel::COL_SEED);
uint64_t s = ui->results->model()->data(idx, Qt::UserRole).toULongLong();
uint64_t s;
if (getSeed(ui->results->currentIndex().row(), &s))
emit selectedSeedChanged(s);
}
}

void FormSearchControl::on_results_clicked(const QModelIndex &)
Expand Down Expand Up @@ -809,10 +816,9 @@ void FormSearchControl::removeCurrent()

void FormSearchControl::copySeed()
{
QModelIndex index = ui->results->currentIndex();
if (index.isValid())
uint64_t seed;
if (getSeed(ui->results->currentIndex().row(), &seed))
{
uint64_t seed = ui->results->model()->data(index, Qt::UserRole).toULongLong();
QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(QString::asprintf("%" PRId64, seed));
}
Expand All @@ -824,11 +830,10 @@ void FormSearchControl::copyResults()
int n = ui->results->model()->rowCount();
for (int i = 0; i < n; i++)
{
QModelIndex idx = ui->results->model()->index(i, SeedTableModel::COL_SEED);
uint64_t seed = ui->results->model()->data(idx, Qt::UserRole).toULongLong();
text += QString::asprintf("%" PRId64 "\n", seed);
uint64_t seed;
if (getSeed(i, &seed))
text += QString::asprintf("%" PRId64 "\n", seed);
}

QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(text);
}
Expand Down
2 changes: 2 additions & 0 deletions src/formsearchcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class FormSearchControl : public QWidget

void setSearchMode(int mode);

bool getSeed(int row, uint64_t *seed);

signals:
void selectedSeedChanged(uint64_t seed);
void searchStatusChanged(bool running);
Expand Down
50 changes: 44 additions & 6 deletions src/headless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

#include <QApplication>
#include <QDateTime>
#include <QFileInfo>
#include <QStandardPaths>

#include <stdio.h>

#if defined(_WIN32)
#include <windows.h>
short get_term_width()
Expand Down Expand Up @@ -34,19 +37,20 @@ static QTextStream& qOut()
return out;
}

Headless::Headless(QString sessionpath, QString resultspath, QObject *parent)
Headless::Headless(QString sessionpath, QString resultspath, bool reset, QObject *parent)
: QThread(parent)
, sthread(nullptr)
, sessionpath(sessionpath)
, resultfile(resultspath)
, resultstream(stdout)
, progressfp()
{
sthread.isdone = true;

QSettings settings(APP_STRING, APP_STRING);
g_extgen.load(settings);

if (!loadSession(sessionpath))
if (!loadSession(sessionpath, reset))
return;

if (!sthread.set(nullptr, session))
Expand Down Expand Up @@ -82,7 +86,7 @@ static bool load_seeds(std::vector<uint64_t>& seeds, QString path)
return false;
}

bool Headless::loadSession(QString sessionpath)
bool Headless::loadSession(QString sessionpath, bool reset)
{
qOut() << "Loading session: \"" << sessionpath << "\"\n";
qOut().flush();
Expand All @@ -100,6 +104,11 @@ bool Headless::loadSession(QString sessionpath)
return false;
}

if (reset)
session.sc.startseed = 0;
else
results = session.slist;

if (session.cv.empty())
{
warn(nullptr, "Session defines no search constraints.");
Expand Down Expand Up @@ -149,15 +158,32 @@ void Headless::run()
session.writeHeader(resultstream);
resultstream.flush();

sthread.startSearch();
elapsed.start();

if (resultfile.isOpen())
{
// open a separate write channel to the same result file and
// reserve space for a progress field after the header
QByteArray path = QFileInfo(resultfile).absoluteFilePath().toLocal8Bit();
progressfp = fopen(path.data(), "rb+");
if (progressfp)
{
fseek(progressfp, resultfile.size(), SEEK_SET);
resultstream << QString::asprintf("#Progress: %20" PRId64 "\n", session.sc.startseed);
resultstream.flush();
}

for (uint64_t s : results)
{
resultstream << (int64_t) s << "\n";
resultstream.flush();
}

qOut() << "\n\n\n\n\n\n\n";
qOut().flush();
timer.start(250);
}

sthread.startSearch();
elapsed.start();
}

void Headless::searchResult(uint64_t seed)
Expand All @@ -174,6 +200,11 @@ void Headless::searchFinish(bool done)
timer.stop();
progressTimeout();
}
if (progressfp)
{
fclose(progressfp);
progressfp = NULL;
}
if (done)
qOut() << "Search done!\n";
qOut() << "Stopping event loop.\n";
Expand All @@ -188,6 +219,13 @@ void Headless::progressTimeout()
qreal min, avg, max;
sthread.getProgress(&status, &prog, &end, &seed, &min, &avg, &max);

if (progressfp)
{
long pos = ftell(progressfp);
fprintf(progressfp, "#Progress: %20" PRId64 "\n", seed);
fseek(progressfp, pos, SEEK_SET);
}

short width = get_term_width();
if (width <= 24)
return;
Expand Down
5 changes: 3 additions & 2 deletions src/headless.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class Headless : public QThread
Q_OBJECT

public:
Headless(QString sessionpath, QString resultspath, QObject *parent = 0);
Headless(QString sessionpath, QString resultspath, bool reset, QObject *parent = 0);
virtual ~Headless();

bool loadSession(QString sessionpath);
bool loadSession(QString sessionpath, bool reset);

public slots:
void run();
Expand All @@ -33,6 +33,7 @@ public slots:
std::vector<uint64_t> results;
QFile resultfile;
QTextStream resultstream;
FILE *progressfp;
QTimer timer;
QElapsedTimer elapsed;
};
Expand Down
6 changes: 3 additions & 3 deletions src/layerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool getLayerOptionInfo(LayerOptInfo *info, int mode, int disp, WorldInfo wi)
if (disp == 3) txt = "1:64";
if (disp == 4) txt = "1:256";
break;
case LOPT_HEIGHT_4:
case LOPT_HEIGHT:
if (disp == 0) txt = QApplication::translate("LayerDialog", "Grayscale");
if (disp == 1) txt = QApplication::translate("LayerDialog", "Shaded biome map");
if (disp == 2) txt = QApplication::translate("LayerDialog", "Contours on biomes");
Expand Down Expand Up @@ -113,7 +113,7 @@ LayerDialog::LayerDialog(QWidget *parent, WorldInfo wi)
radio[LOPT_NOOCEAN_1] = ui->radioNoOcean;
radio[LOPT_BETA_T_1] = ui->radioBetaT;
radio[LOPT_BETA_H_1] = ui->radioBetaH;
radio[LOPT_HEIGHT_4] = ui->radioHeight;
radio[LOPT_HEIGHT] = ui->radioHeight;
radio[LOPT_STRUCTS] = ui->radioStruct;

combo[LOPT_BIOMES] = ui->comboBiomes;
Expand All @@ -122,7 +122,7 @@ LayerDialog::LayerDialog(QWidget *parent, WorldInfo wi)
combo[LOPT_NOISE_C_4] = ui->comboNoiseC;
combo[LOPT_NOISE_E_4] = ui->comboNoiseE;
combo[LOPT_NOISE_W_4] = ui->comboNoiseW;
combo[LOPT_HEIGHT_4] = ui->comboHeight;
combo[LOPT_HEIGHT] = ui->comboHeight;

for (int i = 0; i < LOPT_MAX; i++)
{
Expand Down
6 changes: 5 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ int main(int argc, char *argv[])

bool version = false;
bool nogui = false;
bool clear = false;
bool reset = false;
bool usage = false;
QString sessionpath;
Expand All @@ -45,6 +46,8 @@ int main(int argc, char *argv[])
version = true;
else if (strcmp(argv[i], "--nogui") == 0)
nogui = true;
else if (strcmp(argv[i], "--reset") == 0)
clear = true;
else if (strcmp(argv[i], "--reset-all") == 0)
reset = true;
else if (strncmp(argv[i], "--session=", 10) == 0)
Expand All @@ -67,6 +70,7 @@ int main(int argc, char *argv[])
" --help Display this help and exit.\n"
" --version Output version information and exit.\n"
" --nogui Run in headless search mode.\n"
" --reset Discard results and reset starting seed.\n"
" --reset-all Clear settings and remove all session data.\n"
" --session=file Open this session file.\n"
" --out=file Write matching seeds to this file while searching.\n"
Expand Down Expand Up @@ -105,7 +109,7 @@ int main(int argc, char *argv[])
if (nogui)
{
QCoreApplication app(argc, argv);
Headless headless(sessionpath, resultspath, &app);
Headless headless(sessionpath, resultspath, clear, &app);

QObject::connect(&headless, SIGNAL(finished()), &app, SLOT(quit()));
QTimer::singleShot(0, &headless, SLOT(run()));
Expand Down
8 changes: 4 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ MainWindow::MainWindow(QString sessionpath, QString resultspath, QWidget *parent
laction[LOPT_NOOCEAN_1] = ui->actionNoOceans;
laction[LOPT_BETA_T_1] = ui->actionBetaTemperature;
laction[LOPT_BETA_H_1] = ui->actionBetaHumidity;
laction[LOPT_HEIGHT_4] = ui->actionHeight;
laction[LOPT_HEIGHT] = ui->actionHeight;
laction[LOPT_STRUCTS] = ui->actionStructures;

QActionGroup *grp = new QActionGroup(this);
Expand Down Expand Up @@ -365,7 +365,7 @@ bool MainWindow::getSeed(WorldInfo *wi, bool applyrand)
{
if (applyrand)
qDebug() << "Unknown MC version: " << mcs.c_str();
wi->mc = MC_NEWEST;
wi->mc = MC_DEFAULT;
ok = false;
}

Expand Down Expand Up @@ -697,13 +697,13 @@ void MainWindow::setMCList(bool experimental)
if (ui->comboBoxMC->count())
getSeed(&wi, false);
else
wi.mc = MC_NEWEST;
wi.mc = MC_DEFAULT;
QStringList mclist;
for (int mc = MC_NEWEST; mc > MC_UNDEF; mc--)
{
if (!experimental && mc != wi.mc)
{
if (mc <= MC_1_0 || mc == MC_1_16_1 || mc == MC_1_19_2)
if (mc <= MC_1_0 || mc == MC_1_16_1 || mc == MC_1_19_2 || mc == MC_1_21_3)
continue;
}
const char *mcs = mc2str(mc);
Expand Down
2 changes: 1 addition & 1 deletion src/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void MapView::paintEvent(QPaintEvent *)
QPoint cur = mapFromGlobal(QCursor::pos());
qreal bx = (cur.x() - width()/2.0) / blocks2pix + fx;
qreal bz = (cur.y() - height()/2.0) / blocks2pix + fz;
Pos p = {(int)clampimax(bx), (int)clampimax(bz)};
Pos p = {(int)clampimax(floor(bx)), (int)clampimax(floor(bz))};
overlay->pos = p;
overlay->bname = world->getBiomeName(p);

Expand Down
1 change: 1 addition & 0 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,7 @@ testCondAt(
case F_PORTALN:
case F_ANCIENT_CITY:
case F_TRAILS:
case F_CHAMBERS:

case F_FORTRESS:
case F_BASTION:
Expand Down
8 changes: 8 additions & 0 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ enum
F_TRAILS,
F_BIOME_SAMPLE,
F_NOISE_SAMPLE,
F_CHAMBERS,
// new filters should be added here at the end to keep some downwards compatibility
FILTER_MAX,
};
Expand Down Expand Up @@ -504,6 +505,13 @@ static const struct FilterList : private FilterInfo
""
};

list[F_CHAMBERS] = FilterInfo{
CAT_STRUCT, 1, LOC_RAD, Trial_Chambers, 1, BR_CLUST, MC_1_21, MC_NEWEST, 0, 0, disp++,
"chambers",
QT_TRANSLATE_NOOP("Filter", "Trial chambers"),
""
};

list[F_PORTAL] = FilterInfo{
CAT_STRUCT, 0, LOC_RAD, Ruined_Portal, 1, BR_CLUST, MC_1_16_1, MC_NEWEST, 0, 0, disp++,
"portal",
Expand Down
2 changes: 2 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ QString getBiomeDisplay(int mc, int id)
case mangrove_swamp: return QApplication::translate("Biome", "Mangrove Swamp");
// 1.20
case cherry_grove: return QApplication::translate("Biome", "Cherry Grove");
// 1.21.3 (Winter Drop Version TBA)
case pale_garden: return QApplication::translate("Biome", "Pale Garden");
}
const char *name = biome2str(mc, id);
return name ? name : "";
Expand Down
Loading

0 comments on commit a5376bf

Please sign in to comment.