-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogrammableblock.h
More file actions
78 lines (68 loc) · 2.13 KB
/
programmableblock.h
File metadata and controls
78 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef PROGRAMMABLEBLOCK_H
#define PROGRAMMABLEBLOCK_H
#include <string>
#include <memory>
#include "pge/olcPixelGameEngine.h"
#include "lua/lua.hpp"
#include "block.h"
#include "pge/imgui.h"
class ProgrammableBlock : public Block
{
private:
void InitLua();
void SetupLuaPorts();
std::string PopString();
DataValueEx GetDataValue(int index);
void PushDataValue(DataValueEx data);
void DisplayError();
lua_State* L;
std::string lastError;
bool running;
// lua execution timing restrictions
std::chrono::time_point<std::chrono::steady_clock> prevTime;
std::chrono::duration<int64_t, std::nano> toYield;
const std::chrono::milliseconds yieldTime{50};
const std::chrono::milliseconds warmupTime{300};
const int hookInstrCount = 100000;
const std::vector<std::string> colors = {
"black",
"blue",
"light_blue",
"violet",
"pink",
"green",
"light_green",
"orange",
"yellow",
"red",
"light_red",
"brown",
"light_brown",
"gray",
"light_gray",
"white"
};
const std::string defaultCode = "-- write code that runs once here\n\nfunction update()\n-- write code that runs every simulation tick here\nend";
public:
std::string code;
ProgrammableBlock(SpriteManager* sm, olc::vi2d pos);
ProgrammableBlock(SpriteManager* sm, olc::vi2d pos, int inputPorts, int outputPorts);
ProgrammableBlock(SpriteManager* sm, olc::vi2d pos, std::vector<std::string> inputPorts, std::vector<std::string> outputPorts);
ProgrammableBlock(const ProgrammableBlock& other);
~ProgrammableBlock();
virtual bool IsProgrammable();
virtual std::string GetDescription();
virtual std::shared_ptr<olc::Sprite> GetDefaultSprite();
virtual ProgrammableBlock* Clone();
bool RunSetup();
bool RunUpdate();
bool VerifyCode();
bool UpdateYieldTimer();
void ResetYieldTimer(std::chrono::milliseconds t);
void SetRunning(bool val);
std::string GetError();
void Update(float timedelta);
void Start();
void Stop();
};
#endif // PROGRAMMABLEBLOCK_H