TazGraph Project v0.1.0
Loading...
Searching...
No Matches
PollingComponent.h
1#pragma once
2#include "../../../Components.h"
3
5public:
6 void StartPolling(const std::string& file, float delayInSeconds) {
7 pollingFile = file;
8 timer = delayInSeconds;
9 pollingActive = true;
10 }
11
12 void update(float deltaTime) override {
13 if (!pollingActive) return;
14
15 timer -= deltaTime / 10.0f;
16 if (timer <= 0.0f) {
17 SendMessageToOtherNodes(pollingFile);
18 pollingActive = false; // Stop polling after sending the message
19 }
20 }
21
22 std::string GetComponentName() override {
23 return "PollingComponent";
24 }
25
26private:
27 void SendMessageToOtherNodes(const std::string& file) {
28 std::cout << "Polling complete. Sending message from file: " << file << std::endl;
29
30 // get outLinks of Node, fine the node with the id, and send a message saying "Hello World"
31 // keep log in the nodes where it shows the messages received
32 if (!entity->getOutLinks().empty()) {
33 for (auto& link : entity->getOutLinks()) {
34 link->getToNode()->addMessage("Hello World");
35
36
37 link->GetComponent<LineFlashAnimatorComponent>().Play("LineTransfer");
38 }
39 }
40 // entity->makeAnimation(0.01f)
41
42 }
43
44 std::string pollingFile;
45 float timer = 0.0f;
46 bool pollingActive = false;
47};
Definition LineFlashAnimatorComponent.h:14
Definition GECS.h:128
Definition PollingComponent.h:4