Skip to content

Commit 67b138c

Browse files
committed
add simple cli args
1 parent f43bd85 commit 67b138c

File tree

6 files changed

+62
-37
lines changed

6 files changed

+62
-37
lines changed

.editorconfig

Whitespace-only changes.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
.vscode
55
.zed
66
.DS_Store
7+
BUILD
8+
KEEP

Makefile

+12-12
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,46 @@ all: $(PROJECTS)
3737
mk_log:
3838
ifneq (,$(mk_log_config))
3939
@echo "==== Building mk_log ($(mk_log_config)) ===="
40-
@${MAKE} --no-print-directory -C .ignore -f mk_log.make config=$(mk_log_config)
40+
@${MAKE} --no-print-directory -C BUILD -f mk_log.make config=$(mk_log_config)
4141
endif
4242

4343
mk_ini:
4444
ifneq (,$(mk_ini_config))
4545
@echo "==== Building mk_ini ($(mk_ini_config)) ===="
46-
@${MAKE} --no-print-directory -C .ignore -f mk_ini.make config=$(mk_ini_config)
46+
@${MAKE} --no-print-directory -C BUILD -f mk_ini.make config=$(mk_ini_config)
4747
endif
4848

4949
mk_sokol:
5050
ifneq (,$(mk_sokol_config))
5151
@echo "==== Building mk_sokol ($(mk_sokol_config)) ===="
52-
@${MAKE} --no-print-directory -C .ignore -f mk_sokol.make config=$(mk_sokol_config)
52+
@${MAKE} --no-print-directory -C BUILD -f mk_sokol.make config=$(mk_sokol_config)
5353
endif
5454

5555
mk_hmm:
5656
ifneq (,$(mk_hmm_config))
5757
@echo "==== Building mk_hmm ($(mk_hmm_config)) ===="
58-
@${MAKE} --no-print-directory -C .ignore -f mk_hmm.make config=$(mk_hmm_config)
58+
@${MAKE} --no-print-directory -C BUILD -f mk_hmm.make config=$(mk_hmm_config)
5959
endif
6060

6161
mk_stb:
6262
ifneq (,$(mk_stb_config))
6363
@echo "==== Building mk_stb ($(mk_stb_config)) ===="
64-
@${MAKE} --no-print-directory -C .ignore -f mk_stb.make config=$(mk_stb_config)
64+
@${MAKE} --no-print-directory -C BUILD -f mk_stb.make config=$(mk_stb_config)
6565
endif
6666

6767
mk_sqv:
6868
ifneq (,$(mk_sqv_config))
6969
@echo "==== Building mk_sqv ($(mk_sqv_config)) ===="
70-
@${MAKE} --no-print-directory -C .ignore -f mk_sqv.make config=$(mk_sqv_config)
70+
@${MAKE} --no-print-directory -C BUILD -f mk_sqv.make config=$(mk_sqv_config)
7171
endif
7272

7373
clean:
74-
@${MAKE} --no-print-directory -C .ignore -f mk_log.make clean
75-
@${MAKE} --no-print-directory -C .ignore -f mk_ini.make clean
76-
@${MAKE} --no-print-directory -C .ignore -f mk_sokol.make clean
77-
@${MAKE} --no-print-directory -C .ignore -f mk_hmm.make clean
78-
@${MAKE} --no-print-directory -C .ignore -f mk_stb.make clean
79-
@${MAKE} --no-print-directory -C .ignore -f mk_sqv.make clean
74+
@${MAKE} --no-print-directory -C BUILD -f mk_log.make clean
75+
@${MAKE} --no-print-directory -C BUILD -f mk_ini.make clean
76+
@${MAKE} --no-print-directory -C BUILD -f mk_sokol.make clean
77+
@${MAKE} --no-print-directory -C BUILD -f mk_hmm.make clean
78+
@${MAKE} --no-print-directory -C BUILD -f mk_stb.make clean
79+
@${MAKE} --no-print-directory -C BUILD -f mk_sqv.make clean
8080

8181
help:
8282
@echo "Usage: make [config=name] [target]"

deps/sokol.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#define SOKOL_IMPL
22

33
#include "sokol_app.h"
4+
#include "sokol_args.h"
45
#include "sokol_gfx.h"
56
#include "sokol_glue.h"
67
#include "sokol_log.h"

premake5.lua

+25-20
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@ workspace "ProjectWorkspace"
1919
project "mk_log"
2020
kind "StaticLib"
2121
language "C"
22-
location ".ignore"
23-
targetdir ".ignore/build/"
24-
objdir ".ignore/build/obj"
22+
location "BUILD"
23+
targetdir "BUILD/build/"
24+
objdir "BUILD/build/obj"
2525
targetname "log"
2626
files {"deps/log.c"}
2727

2828
-- 🔹 Rxi INI Library
2929
project "mk_ini"
3030
kind "StaticLib"
3131
language "C"
32-
location ".ignore"
33-
targetdir ".ignore/build/"
34-
objdir ".ignore/build/obj"
32+
location "BUILD"
33+
targetdir "BUILD/build/"
34+
objdir "BUILD/build/obj"
3535
targetname "ini"
3636
files {"deps/ini.c"}
3737

3838
-- 🔹 Sokol Library
3939
project "mk_sokol"
4040
kind "StaticLib"
4141
language "C"
42-
location ".ignore"
43-
targetdir ".ignore/build/"
44-
objdir ".ignore/build/obj"
42+
location "BUILD"
43+
targetdir "BUILD/build/"
44+
objdir "BUILD/build/obj"
4545
targetname "sokol"
4646
files {"deps/sokol.c"}
4747

@@ -58,19 +58,19 @@ project "mk_sokol"
5858
project "mk_hmm"
5959
kind "StaticLib"
6060
language "C"
61-
location ".ignore"
62-
targetdir ".ignore/build/"
63-
objdir ".ignore/build/obj"
61+
location "BUILD"
62+
targetdir "BUILD/build/"
63+
objdir "BUILD/build/obj"
6464
targetname "hmm"
6565
files {"deps/hmm.c"}
6666

6767
-- 🔹 STB Library
6868
project "mk_stb"
6969
kind "StaticLib"
7070
language "C"
71-
location ".ignore"
72-
targetdir ".ignore/build/"
73-
objdir ".ignore/build/obj"
71+
location "BUILD"
72+
targetdir "BUILD/build/"
73+
objdir "BUILD/build/obj"
7474
targetname "stb"
7575
buildoptions { "-Wno-deprecated-declarations" }
7676
files {"deps/stb.c"}
@@ -79,9 +79,9 @@ project "mk_stb"
7979
project "mk_sqv"
8080
kind "ConsoleApp"
8181
language "C"
82-
location ".ignore"
83-
targetdir ".ignore/build/"
84-
objdir ".ignore/build/obj"
82+
location "BUILD"
83+
targetdir "BUILD/build/"
84+
objdir "BUILD/build/obj"
8585
targetname "sqv"
8686
files {"src/*.c", "src/qk/*.c"}
8787
includedirs {"src", "deps"}
@@ -108,8 +108,13 @@ newaction {
108108
-- 🔹 Run Action
109109
newaction {
110110
trigger = "run",
111-
description = "Execute the program",
111+
description = "Execute the program with optional arguments",
112112
execute = function()
113-
os.execute(".ignore/build/sqv")
113+
-- Capture additional command-line arguments
114+
local args = _ARGS
115+
local args_str = table.concat(args, " ")
116+
117+
-- Execute the program with arguments
118+
os.execute("BUILD/build/sqv " .. args_str)
114119
end
115120
}

src/sqv.c

+22-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../deps/hmm.h"
44
#include "../deps/log.h"
55
#include "../deps/sokol_app.h"
6+
#include "../deps/sokol_args.h"
67
#include "../deps/sokol_gfx.h"
78
#include "../deps/sokol_glue.h"
89
#include "../deps/sokol_log.h"
@@ -13,9 +14,8 @@
1314
#define QK_MDL_IMPLEMENTATION
1415

1516
#include "glsl/default.h"
16-
#include "quake/mdl.h"
17-
#include "errors.h"
1817
#include "utils/all.h"
18+
#include "quake/mdl.h"
1919

2020
static struct {
2121
sg_pipeline pip;
@@ -42,6 +42,8 @@ void load_mdl_file(const char* path) {
4242
void init(void) {
4343
log_info("initializing gpu ...");
4444

45+
const char* mdl_file_path = (const char*)sapp_userdata();
46+
4547
sg_setup(&(sg_desc){
4648
.environment = sglue_environment(),
4749
.logger.func = slog_func,
@@ -53,7 +55,7 @@ void init(void) {
5355
state.indices = NULL;
5456
size_t verticesz = 0;
5557

56-
load_mdl_file(".keep/player.mdl");
58+
load_mdl_file(mdl_file_path);
5759
arena_print(&state.qkmdl.mem);
5860

5961
memcpy(&state.scale, &state.qkmdl.header.scale, sizeof(state.scale));
@@ -172,15 +174,30 @@ void frame(void) {
172174
void cleanup(void) {
173175
log_info("shuting down");
174176
sg_shutdown();
177+
sargs_shutdown();
175178
}
176179

177180
sapp_desc sokol_main(int argc, char* argv[]) {
178181
log_info("starting");
179182

180-
(void)argc;
181-
(void)argv;
183+
sargs_setup(&(sargs_desc){
184+
.argc = argc,
185+
.argv = argv,
186+
});
187+
188+
const char* _mdl = NULL;
189+
if (sargs_exists("-m")) {
190+
_mdl = sargs_value("-m");
191+
} else if (sargs_exists("--model")) {
192+
_mdl = sargs_value("--model");
193+
} else {
194+
makesure(false,
195+
"you need to provide either '-m' or '--model' to define the path "
196+
"to the MDL model");
197+
}
182198

183199
return (sapp_desc){
200+
.user_data = (void*)_mdl,
184201
.init_cb = init,
185202
.frame_cb = frame,
186203
.cleanup_cb = cleanup,

0 commit comments

Comments
 (0)