mirror of
https://github.com/Relintai/sfw.git
synced 2024-11-08 07:52:09 +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 "core/memory.h"
|
||||
#include "core/thread.h"
|
||||
#include "render_core/3rd_glad.h"
|
||||
#include "render_core/app_window.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;
|
||||
}
|
||||
|
||||
@ -350,9 +357,36 @@ void GameScene::render_immediate_3d() {
|
||||
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() {
|
||||
render_type = 0;
|
||||
|
||||
_thread_running = false;
|
||||
_thread = NULL;
|
||||
|
||||
left = false;
|
||||
right = false;
|
||||
up = false;
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "render_objects/text_2d.h"
|
||||
#include "render_objects/tile_map.h"
|
||||
|
||||
class Thread;
|
||||
|
||||
class GameScene : public Scene {
|
||||
SFW_OBJECT(GameScene, Scene);
|
||||
|
||||
@ -34,6 +36,9 @@ public:
|
||||
virtual void render_obj();
|
||||
virtual void render_immediate_3d();
|
||||
|
||||
void toggle_thread();
|
||||
static void test_thread_func(void* d);
|
||||
|
||||
GameScene();
|
||||
~GameScene();
|
||||
|
||||
@ -44,6 +49,9 @@ public:
|
||||
bool up;
|
||||
bool down;
|
||||
|
||||
Thread *_thread;
|
||||
bool _thread_running;
|
||||
|
||||
Ref<Image> image;
|
||||
Ref<Texture> texture;
|
||||
Ref<TextureMaterial2D> material;
|
||||
|
Loading…
Reference in New Issue
Block a user