mirror of
https://github.com/Relintai/sfw.git
synced 2025-01-03 05:09:36 +01:00
Added a thread test to the GameScene.
This commit is contained in:
parent
83bec2b506
commit
d2089a0ccb
@ -3,6 +3,7 @@
|
|||||||
#include "render_core/application.h"
|
#include "render_core/application.h"
|
||||||
|
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
|
#include "core/thread.h"
|
||||||
#include "render_core/3rd_glad.h"
|
#include "render_core/3rd_glad.h"
|
||||||
#include "render_core/app_window.h"
|
#include "render_core/app_window.h"
|
||||||
#include "render_core/keyboard.h"
|
#include "render_core/keyboard.h"
|
||||||
@ -62,6 +63,12 @@ void GameScene::input_event(const Ref<InputEvent> &event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (k->get_physical_scancode() == KEY_T) {
|
||||||
|
if (pressed) {
|
||||||
|
toggle_thread();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,9 +357,36 @@ void GameScene::render_immediate_3d() {
|
|||||||
rotmi += 0.01;
|
rotmi += 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameScene::toggle_thread() {
|
||||||
|
if (_thread) {
|
||||||
|
_thread_running = false;
|
||||||
|
|
||||||
|
_thread->wait_to_finish();
|
||||||
|
|
||||||
|
memdelete(_thread);
|
||||||
|
_thread = NULL;
|
||||||
|
} else {
|
||||||
|
_thread_running = true;
|
||||||
|
|
||||||
|
_thread = memnew(Thread);
|
||||||
|
_thread->start(test_thread_func, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameScene::test_thread_func(void *data) {
|
||||||
|
GameScene *self = (GameScene *)data;
|
||||||
|
|
||||||
|
while (self->_thread_running) {
|
||||||
|
ERR_PRINT("Test Thread!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GameScene::GameScene() {
|
GameScene::GameScene() {
|
||||||
render_type = 0;
|
render_type = 0;
|
||||||
|
|
||||||
|
_thread_running = false;
|
||||||
|
_thread = NULL;
|
||||||
|
|
||||||
left = false;
|
left = false;
|
||||||
right = false;
|
right = false;
|
||||||
up = false;
|
up = false;
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#include "render_objects/text_2d.h"
|
#include "render_objects/text_2d.h"
|
||||||
#include "render_objects/tile_map.h"
|
#include "render_objects/tile_map.h"
|
||||||
|
|
||||||
|
class Thread;
|
||||||
|
|
||||||
class GameScene : public Scene {
|
class GameScene : public Scene {
|
||||||
SFW_OBJECT(GameScene, Scene);
|
SFW_OBJECT(GameScene, Scene);
|
||||||
|
|
||||||
@ -34,6 +36,9 @@ public:
|
|||||||
virtual void render_obj();
|
virtual void render_obj();
|
||||||
virtual void render_immediate_3d();
|
virtual void render_immediate_3d();
|
||||||
|
|
||||||
|
void toggle_thread();
|
||||||
|
static void test_thread_func(void* d);
|
||||||
|
|
||||||
GameScene();
|
GameScene();
|
||||||
~GameScene();
|
~GameScene();
|
||||||
|
|
||||||
@ -44,6 +49,9 @@ public:
|
|||||||
bool up;
|
bool up;
|
||||||
bool down;
|
bool down;
|
||||||
|
|
||||||
|
Thread *_thread;
|
||||||
|
bool _thread_running;
|
||||||
|
|
||||||
Ref<Image> image;
|
Ref<Image> image;
|
||||||
Ref<Texture> texture;
|
Ref<Texture> texture;
|
||||||
Ref<TextureMaterial2D> material;
|
Ref<TextureMaterial2D> material;
|
||||||
|
Loading…
Reference in New Issue
Block a user