Skip to content

Commit

Permalink
threaded work slots to the controller
Browse files Browse the repository at this point in the history
  • Loading branch information
noisecode3 committed Aug 12, 2024
1 parent eacdd6c commit 0c5b1ca
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 128 deletions.
36 changes: 13 additions & 23 deletions fixes/8/IntoTheRealmOfEternalDarkness.patch
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ index f15a010a..468aeb21 100644
"title": "Current Position",
"file": "data/current.phd",
diff --git a/src/config_map.def b/src/config_map.def
index c2e9c683..d2c92c43 100644
index f449a25f..fe964da7 100644
--- a/src/config_map.def
+++ b/src/config_map.def
@@ -9,39 +9,39 @@ CFG_BOOL(enable_enhanced_look, true)
Expand Down Expand Up @@ -734,7 +734,7 @@ index c2e9c683..d2c92c43 100644
CFG_FLOAT(rendering.anisotropy_filter, 16.0f)
CFG_INT32(rendering.turbo_speed, 0)
CFG_BOOL(walk_to_items, false)
@@ -52,29 +52,29 @@ CFG_ENUM(airbar_show_mode, BSM_DEFAULT, BAR_SHOW_MODE)
@@ -52,30 +52,30 @@ CFG_ENUM(airbar_show_mode, BSM_DEFAULT, BAR_SHOW_MODE)
CFG_ENUM(enemy_healthbar_show_mode, BSM_ALWAYS, BAR_SHOW_MODE)
CFG_ENUM(healthbar_location, BL_TOP_LEFT, BAR_LOCATION)
CFG_ENUM(airbar_location, BL_TOP_RIGHT, BAR_LOCATION)
Expand Down Expand Up @@ -774,7 +774,7 @@ index c2e9c683..d2c92c43 100644
CFG_BOOL(enable_save_crystals, false)
CFG_BOOL(enable_uw_roll, true)
CFG_BOOL(enable_buffering, false)
@@ -88,15 +88,15 @@ CFG_INT32(rendering.window_x, -1)
@@ -88,7 +88,7 @@ CFG_INT32(rendering.window_x, -1)
CFG_INT32(rendering.window_y, -1)
CFG_INT32(rendering.window_width, -1)
CFG_INT32(rendering.window_height, -1)
Expand All @@ -783,18 +783,8 @@ index c2e9c683..d2c92c43 100644
CFG_INT32(rendering.texture_filter, GFX_TF_BILINEAR)
CFG_INT32(rendering.fbo_filter, GFX_TF_NN)
CFG_BOOL(rendering.enable_wireframe, false)
CFG_DOUBLE(rendering.wireframe_width, 2.5)
CFG_BOOL(rendering.enable_perspective_filter, true)
CFG_BOOL(rendering.enable_vsync, true)
-CFG_INT32(music_volume, 8)
-CFG_INT32(sound_volume, 8)
+CFG_INT32(music_volume, 10)
+CFG_INT32(sound_volume, 7)
CFG_INT32(input.layout, 0)
CFG_INT32(input.cntlr_layout, 0)
CFG_FLOAT(brightness, DEFAULT_BRIGHTNESS)
diff --git a/src/game/gameflow.c b/src/game/gameflow.c
index 026e846c..5bc83eec 100644
index 4d537771..6e2ea7fc 100644
--- a/src/game/gameflow.c
+++ b/src/game/gameflow.c
@@ -9,6 +9,8 @@
Expand Down Expand Up @@ -853,7 +843,7 @@ index 026e846c..5bc83eec 100644
Music_Play((int32_t)(intptr_t)seq->data);
break;
diff --git a/src/game/objects/general/trapdoor.c b/src/game/objects/general/trapdoor.c
index 0021839f..148bcb34 100644
index 46f6cc11..3e9d0a1c 100644
--- a/src/game/objects/general/trapdoor.c
+++ b/src/game/objects/general/trapdoor.c
@@ -5,6 +5,8 @@
Expand All @@ -862,10 +852,10 @@ index 0021839f..148bcb34 100644

+int g_TrapDoorFix = 0;
+
static bool TrapDoor_StandingOn(ITEM_INFO *item, int32_t x, int32_t z);
static bool TrapDoor_StandingOn(const ITEM_INFO *item, int32_t x, int32_t z);

static bool TrapDoor_StandingOn(ITEM_INFO *item, int32_t x, int32_t z)
@@ -34,12 +36,28 @@ void TrapDoor_Setup(OBJECT_INFO *obj)
static bool TrapDoor_StandingOn(const ITEM_INFO *item, int32_t x, int32_t z)
@@ -35,12 +37,28 @@ void TrapDoor_Setup(OBJECT_INFO *obj)
obj->save_flags = 1;
}

Expand Down Expand Up @@ -896,7 +886,7 @@ index 0021839f..148bcb34 100644
} else if (item->current_anim_state == DOOR_OPEN) {
item->goal_anim_state = DOOR_CLOSED;
diff --git a/src/game/objects/general/trapdoor.h b/src/game/objects/general/trapdoor.h
index ac38b3dc..531290b3 100644
index 54e0ea09..81df4dd4 100644
--- a/src/game/objects/general/trapdoor.h
+++ b/src/game/objects/general/trapdoor.h
@@ -4,6 +4,8 @@
Expand All @@ -907,9 +897,9 @@ index ac38b3dc..531290b3 100644
+
void TrapDoor_Setup(OBJECT_INFO *obj);
void TrapDoor_Control(int16_t item_num);
void TrapDoor_Floor(
int16_t TrapDoor_GetFloorHeight(
diff --git a/src/game/objects/traps/rolling_ball.c b/src/game/objects/traps/rolling_ball.c
index 7b42b8e1..1308c10b 100644
index 97c448d0..7942e9d5 100644
--- a/src/game/objects/traps/rolling_ball.c
+++ b/src/game/objects/traps/rolling_ball.c
@@ -18,6 +18,8 @@
Expand Down Expand Up @@ -973,7 +963,7 @@ index fb3f8619..320eeafb 100644
req->line_offset = 0;
req->requested = 0;
diff --git a/src/global/const.h b/src/global/const.h
index b77761bd..02409f5e 100644
index d3c03e5c..6fc74a5b 100644
--- a/src/global/const.h
+++ b/src/global/const.h
@@ -17,10 +17,10 @@
Expand All @@ -990,7 +980,7 @@ index b77761bd..02409f5e 100644
#define MAX_MATRICES 40
#define MAX_NESTED_MATRICES 32
diff --git a/src/global/types.h b/src/global/types.h
index 7586ef7e..9d9d975d 100644
index 0093d802..869de585 100644
--- a/src/global/types.h
+++ b/src/global/types.h
@@ -998,6 +998,7 @@ typedef enum GAMEFLOW_SEQUENCE_TYPE {
Expand Down
118 changes: 52 additions & 66 deletions src/Controller.cpp
Original file line number Diff line number Diff line change
@@ -1,70 +1,76 @@
#include "Controller.h"
#include <QDebug>

Controller::Controller(QObject *parent) : QObject(parent), workerRunning(false)
{
/*
Im not sure I need the thread for something else but found that
it was working by just using signals/slots to update the gui
workerThread = new QThread();
// Move the Controller to a separate thread
this->moveToThread(workerThread);
// Connect signals and slots for thread management
connect(workerThread, SIGNAL(started()), this, SLOT(doSetupOgWork()));
connect(workerThread, SIGNAL(started()), this, SLOT(doSetupLevelWork()));
connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater);
*/
Controller::Controller(QObject *parent) : QObject(parent), ControllerThread(nullptr)
{
ControllerThread = new QThread();
this->moveToThread(ControllerThread);
connect(ControllerThread, &QThread::finished, ControllerThread, &QThread::deleteLater);
ControllerThread->start();
/* this should make emits to signals from the controller and to the controller happen
* on another thread event loop so TombRaiderLinuxLauncher (view object) should have a slot for
* getting the results, update the GUI state, if the controller returns something it's just the
* state of some logic right before it calls the thread signal.
* Every method here should emit a signal to this object here again and use only quick logic
* in order to get back out again and never hold up the GUI thread, never. Even if someone have like
* the slowest hard drives in the world, so the game couldn't even run probably it will not wait for
* it and keep updating the GUI. This is the most safe and correct way to do this I think.
*/

// Those start threaded work a signal hub
connect(this, SIGNAL(setupCampThreadSignal(const QString&, const QString&)),
this, SLOT(setupCampThread(const QString&, const QString&)));
connect(this, SIGNAL(setupLevelThreadSignal(int)), this, SLOT(setupLevelThread(int)));


// Those work like a signal hub for threaded work, like in between callback
connect(&Model::getInstance(), SIGNAL(modelTickSignal()), this, SLOT(passTickSignal()));
connect(&FileManager::getInstance(), SIGNAL(fileWorkTickSignal()), this, SLOT(passTickSignal()));
connect(&Downloader::getInstance(), SIGNAL(networkWorkTickSignal()), this, SLOT(passTickSignal()));

// The TombRaiderLinuxLauncher object have the connect and slot for last signal emit that displays
// the result, we pass back what was return before like this
// connect(&Controller::getInstance(), SIGNAL(setupCampDone(bool)), this, SLOT(checkCommonFiles(bool)));
}

Controller::~Controller()
{
// Cleanup: Ensure the worker thread is stopped and cleaned up
// stopWorkerThread();
}
/*
void Controller::startWorkerThread()
{
if (!workerRunning)
{
workerThread->start();
workerRunning = true;
}
ControllerThread->quit();
ControllerThread->wait();
delete ControllerThread;
ControllerThread = nullptr;
}

void Controller::stopWorkerThread()
{
if (workerRunning)
{
workerThread->quit();
workerThread->wait();
workerRunning = false;
}
}
*/
int Controller::checkGameDirectory(int id)
{
return model.checkGameDirectory(id);
}

bool Controller::setupCamp(const QString& level, const QString& game)

void Controller::setupCamp(const QString& level, const QString& game)
{
return model.setDirectory(level,game);
emit setupCampThreadSignal(level,game);
}

void Controller::setupCampThread(const QString& level, const QString& game)
{
bool status = model.setDirectory(level,game);
emit setupCampDone(status);
}

bool Controller::setupOg(int id)
{
return model.setUpOg(id);
}

bool Controller::setupLevel(int id)
void Controller::setupLevel(int id)
{
id_m = id;
//startWorkerThread();
doSetupLevelWork();
//stopWorkerThread();
return true;
emit setupLevelThreadSignal(id);
}

void Controller::setupLevelThread(int id)
{
bool staus = model.getGame(id);
}

void Controller::getList(QVector<ListItemData>& list)
Expand All @@ -87,33 +93,13 @@ bool Controller::link(int id)
return model.setLink(id);
}

bool Controller::link(const QString& levelDir)
{
return false;
}

int Controller::getItemState(int id)
{
return model.getItemState(id);
}

void Controller::doSetupOgWork()
{
model.getGame(id_m);
}

void Controller::doSetupLevelWork()
void Controller::passTickSignal()
{
// Your worker functionality goes here
qDebug() << "Worker is doing some work...";
model.getGame(id_m);

// Emit a signal to indicate the work is finished
//emit workFinished();
emit controllerTickSignal();
}

void Controller::WorkerThreadFinished()
{
qDebug() << "Worker thread finished.";
// Handle worker thread finished event
}
31 changes: 14 additions & 17 deletions src/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,34 @@ class Controller : public QObject
static Controller instance;
return instance;
}
void startWorkerThread();
void stopWorkerThread();
bool setupCamp(const QString& level, const QString& game);
void setupCamp(const QString& level, const QString& game);
bool setupOg(int id);
bool setupLevel(int id);
void setupLevel(int id);
void getList(QVector<ListItemData>& list);
bool link(int id);
bool link(const QString& levelDir);
const InfoData getInfo(int id);
const QString getWalkthrough(int id);
int getItemState(int id);
int checkGameDirectory(int id);

signals:
void workFinished();

public slots:
void doSetupOgWork();
void doSetupLevelWork();
void WorkerThreadFinished();

private:
QThread* workerThread;
bool workerRunning;
int id_m;

Model& model = Model::getInstance();

Controller(QObject *parent = nullptr);
~Controller();
QThread* ControllerThread;
Q_DISABLE_COPY(Controller)

public slots:
void passTickSignal();
void setupCampThread(const QString& level, const QString& game);
void setupLevelThread(int id);
signals:
void controllerTickSignal();
void setupCampThreadSignal(const QString& level, const QString& game);
void setupCampDone(bool status);
void setupLevelThreadSignal(int id);
//void setupLevelDone(bool status);
};

#endif // CONTROLLER_H
9 changes: 7 additions & 2 deletions src/Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ class Data : public QObject
ZipData getDownload(int id);

private:
Data(QObject *parent = nullptr) : QObject(parent) { }
~Data() { db.close(); }
Data(QObject *parent = nullptr) : QObject(parent)
{
}
~Data()
{
db.close();
}

Q_DISABLE_COPY(Data)
QSqlDatabase db;
Expand Down
2 changes: 0 additions & 2 deletions src/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,5 +487,3 @@ bool FileManager::moveFilesToParentDirectory(const QString& levelDirectory)

return true;
}

void fileWorkTickSignal(){};
11 changes: 7 additions & 4 deletions src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ Model::Model(QObject *parent) : QObject(parent)
const QString s = QString::number(id) + ".TRLE/Titak-MistsOfAvalon-final";
fileManager.moveFilesToParentDirectory(s);
});
*/
*/

}

Model::~Model()
{

}

bool Model::setDirectory(const QString& level, const QString& game)
{
Expand Down Expand Up @@ -68,7 +73,6 @@ void Model::getList(QVector<ListItemData>& list)
list = data.getListItems();
}


int Model::getItemState(int id)
{
if(id < 0)
Expand All @@ -84,7 +88,6 @@ int Model::getItemState(int id)
return -1;
}


bool Model::setLink(int id)
{
if (id < 0)
Expand Down Expand Up @@ -176,6 +179,7 @@ bool Model::getGame(int id)
//fileManager.createDirectory(QString::number(id)+".TRLE", false);
fileManager.extractZip(zipData.name, QString::number(id)+".TRLE");
instructionManager.executeInstruction(id);
return true;
}
return false;
}
Expand All @@ -190,4 +194,3 @@ const QString Model::getWalkthrough(int id)
return data.getWalkthrough(id);
}

void modelTickSignal(){};
2 changes: 1 addition & 1 deletion src/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Model : public QObject
InstructionManager instructionManager;

Model(QObject *parent = nullptr);
~Model() {};
~Model();

Q_DISABLE_COPY(Model)
};
Expand Down
1 change: 0 additions & 1 deletion src/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,3 @@ void Downloader::run()
fclose(file);
}

void networkWorkTickSignal(){};
Loading

0 comments on commit 0c5b1ca

Please sign in to comment.