aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornathansmith117 <nathansmith117@sdf.org>2025-02-04 11:29:07 +0000
committernathansmith117 <nathansmith117@sdf.org>2025-02-04 11:29:07 +0000
commitfe9b718f8978cfd792f7303214b2dd45172b8d4b (patch)
tree8efd867eae12ad5d55d29e964272974ee3d71b18 /src
parentfb7ccc0c046ed80fdac2e829b8c367841600e211 (diff)
downloadsldj-fe9b718f8978cfd792f7303214b2dd45172b8d4b.tar.gz
sldj-fe9b718f8978cfd792f7303214b2dd45172b8d4b.tar.bz2
sldj-fe9b718f8978cfd792f7303214b2dd45172b8d4b.zip
Working on script context
Diffstat (limited to 'src')
-rw-r--r--src/libsldj/util.c (renamed from src/util.c)0
-rw-r--r--src/main.c13
-rw-r--r--src/scripting.c1
-rw-r--r--src/scripting.h3
-rw-r--r--src/sldj.c22
-rw-r--r--src/sldj.h7
-rw-r--r--src/util.h13
7 files changed, 35 insertions, 24 deletions
diff --git a/src/util.c b/src/libsldj/util.c
index b7e445c..b7e445c 100644
--- a/src/util.c
+++ b/src/libsldj/util.c
diff --git a/src/main.c b/src/main.c
index a02b023..298c65b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,11 +1,20 @@
#include <raylib.h>
#include "sldj.h"
+#include "sldjConfig.h"
-int main()
+int main(int argc, char** argv)
{
Sldj sldj;
initSldj(&sldj);
-
+
+ // Add script from argument.
+ if (argc > 1)
+ {
+ strncpy(sldj.scriptFilepath, argv[1], SLDJ_NAMEMAX);
+ reloadScript(&sldj);
+ }
+
+ // Run update loop.
while (!WindowShouldClose())
{
updateSldj(&sldj);
diff --git a/src/scripting.c b/src/scripting.c
index f0a2582..e43f4b5 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -85,6 +85,7 @@ void compileScript(SldjScripting* scripting, const char filePath[SLDJ_NAMEMAX])
}
scripting->lineScanner = tcc_get_symbol(scripting->state, "lineScanner");
+ scripting->loadContext = tcc_get_symbol(scripting->state, "loadContext");
}
void closeScripting(SldjScripting* scripting)
diff --git a/src/scripting.h b/src/scripting.h
index fab64b2..2a7220a 100644
--- a/src/scripting.h
+++ b/src/scripting.h
@@ -11,16 +11,19 @@
#include <libtcc.h>
#include "sldjConfig.h"
+#include "libsldj/util.h"
#ifndef SCRIPTING_H
#define SCRIPTING_H
typedef Color (*LineScanner)(uint16_t x, uint16_t y, uint32_t frameNumber);
+typedef void (*LoadContext)(SldjContext context);
typedef struct SldjScripting {
TCCState* state;
LineScanner lineScanner;
+ LoadContext loadContext;
char* fileBuf;
size_t fileSize;
diff --git a/src/sldj.c b/src/sldj.c
index 349229b..a7483f2 100644
--- a/src/sldj.c
+++ b/src/sldj.c
@@ -14,13 +14,7 @@ void initSldj(Sldj* sldj)
// Scripting.
initScripting(&sldj->scripting);
-
- //compileScript(&sldj->scripting, "/home/nathan/Documents/dev/sldj/test/scanTest1.c");
-
- if (sldj->scripting.lineScanner != NULL)
- {
- printf("%d", sldj->scripting.lineScanner(0, 0, 0).b);
- }
+ sldj->scriptFilepath[0] = '\0';
}
void updateSldj(Sldj* sldj)
@@ -68,7 +62,7 @@ void updateSldj(Sldj* sldj)
if (IsKeyPressed(KEY_R))
{
- compileScript(&sldj->scripting, "/home/nathan/Documents/dev/sldj/test/scanTest1.c");
+ reloadScript(sldj);
}
EndDrawing();
@@ -92,3 +86,15 @@ void resetViewport(Sldj* sldj, int width, int height)
sldj->yCount = UINT16_MAX / height;
}
+void reloadScriptContext(Sldj* sldj)
+{
+}
+
+void reloadScript(Sldj* sldj)
+{
+ if (sldj->scriptFilepath[0] != '\0')
+ {
+ compileScript(&sldj->scripting, sldj->scriptFilepath);
+ }
+}
+
diff --git a/src/sldj.h b/src/sldj.h
index 1db4331..7788a86 100644
--- a/src/sldj.h
+++ b/src/sldj.h
@@ -6,8 +6,8 @@
#include <raylib.h>
#include "sldjConfig.h"
-#include "util.h"
#include "scripting.h"
+#include "libsldj/util.h"
#ifndef SLDJ_H
#define SLDJ_H
@@ -16,10 +16,13 @@ typedef struct Sldj {
RenderTexture viewport;
uint32_t frameCounter;
+
+ // Used for always using a 0 to 2**16 range when scanning.
uint16_t xCount;
uint16_t yCount;
SldjScripting scripting;
+ char scriptFilepath[SLDJ_NAMEMAX];
} Sldj;
void initSldj(Sldj* sldj);
@@ -27,5 +30,7 @@ void updateSldj(Sldj* sldj);
void closeSldj(Sldj* sldj);
void resetViewport(Sldj* sldj, int width, int height);
+void reloadScriptContext(Sldj* sldj);
+void reloadScript(Sldj* sldj);
#endif
diff --git a/src/util.h b/src/util.h
deleted file mode 100644
index 110aae7..0000000
--- a/src/util.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifndef UTIL_H
-#define UTIL_H
-
-#define SET_BIT(b, n) (b | (0x1 << n))
-#define CLEAR_BIT(b, n) (b & ~(0x1 << n))
-#define IS_BIT_SET(b, n) ((b >> n) & 0x1)
-#define TOGGLE_BIT(b, n) (b ^ (0x1 << n))
-#define HAS_FLAG(v, f) ((v & f) == f)
-
-#endif