diff --git a/assets/scripts/main.lua b/assets/scripts/main.lua deleted file mode 100644 index 033c83d..0000000 --- a/assets/scripts/main.lua +++ /dev/null @@ -1,51 +0,0 @@ -engine_window_init(96,64,"Game") -texture = engine_texture_create(8,8) -engine_texture_from_file(texture,"assets/textures/fier0.rgba") - ---[[ -void handleEvent(struct ENGINE_EVENT * event) { - if (event->type == ENGINE_EVENT_TYPE_EXIT) { - exit(0); - } -} -]]-- - -frame = 0 -frameSec = 0 -lastSec = 0 -function tick() - frame = frame + 1 - frameSec = frameSec + 1 - t = engine_time_get() - if t - lastSec >= 1000 then - print("FPS: " ..tostring(frameSec)) - lastSec = t - frameSec = 0 - end - engine_window_present() -end - -function handleEvent(event,eventData) - if eventData[1] == ENGINE_EVENT_TYPE_EXIT then - os.exit() - end - - if eventData[1] == ENGINE_EVENT_TYPE_INPUT_KB then - for _,val in pairs(eventData) do - print(tostring(val)) - end - end -end - -while true do - event = engine_event_get() - eventData = {engine_lua_event_get_data(event)} - if eventData[1] ~= ENGINE_EVENT_TYPE_NONE then - handleEvent(event,eventData) - else - tick() - end - - engine_event_free(event) - engine_texture_render_2d(texture,math.random(-8,102),math.random(-8,72)) -end diff --git a/assets/textures/fier1.rgba b/assets/textures/fier1.rgba deleted file mode 100644 index daf854c..0000000 Binary files a/assets/textures/fier1.rgba and /dev/null differ diff --git a/assets/textures/fier2.rgba b/assets/textures/fier2.rgba deleted file mode 100644 index d7a5138..0000000 Binary files a/assets/textures/fier2.rgba and /dev/null differ diff --git a/lua_translate b/lua_translate index bf9cd89..1f66a51 100755 --- a/lua_translate +++ b/lua_translate @@ -83,6 +83,6 @@ for func in functions: ofile.write('''\ engine_lua_init_manual(); - luaL_loadfile(engine_lua_state,"assets/scripts/main.lua"); + luaL_loadfile(engine_lua_state,"mods/main/script/main.lua"); lua_call(engine_lua_state,0,0); }''') diff --git a/main.c b/main.c deleted file mode 100644 index 218725d..0000000 --- a/main.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include "modules/engine/main.c" -#include "modules/engine/textures.c" -#include "modules/engine/frontend/sdl/main.c" -#include "modules/engine/frontend/generic/textures.c" -#include "modules/engine/lua.c" - -int main(int argc, char **argv) { - for (int i = 0; i < argc; ++i) { - printf("argv[%d]: %s\n", i, argv[i]); - } - - engine_lua_init(); -} diff --git a/mods/main/script/main.lua b/mods/main/script/main.lua new file mode 100644 index 0000000..4428de7 --- /dev/null +++ b/mods/main/script/main.lua @@ -0,0 +1,61 @@ +function main() + math.randomseed(os.time()) + engine_window_init(96,64,"Game") + texture = engine_texture_create(8,8) + engine_texture_from_file(texture,bp("texture/fier.rgba")) + + while true do + event = engine_event_get() + eventData = {engine_lua_event_get_data(event)} + if eventData[1] ~= ENGINE_EVENT_TYPE_NONE then + handleEvent(event,eventData) + else + tick() + end + + engine_event_free(event) + end +end + +lastFrame = 0 +function tick() + engine_texture_render_2d(texture,math.random(0,88),math.random(0,56)) + engine_window_present() + trackFps() + local curFrame = engine_time_get() + local wait = 16 - (curFrame - lastFrame) + if wait > 0 then engine_time_sleep(wait) end + lastFrame = engine_time_get() +end + +function handleEvent(event,eventData) + if eventData[1] == ENGINE_EVENT_TYPE_EXIT then + os.exit() + end + + if eventData[1] == ENGINE_EVENT_TYPE_INPUT_KB then + for _,val in pairs(eventData) do + print(tostring(val)) + end + end +end + +local frameSec = 0 +local lastSec = 0 +function trackFps() + frameSec = frameSec + 1 + t = engine_time_get() + if t - lastSec >= 1000 then + print("FPS: " ..tostring(frameSec)) + lastSec = t + frameSec = 0 + end +end + +function bp(pth) + return basepath .. "/mods/main/" ..pth +end + +basepath = (debug.getinfo(1, "S").source:sub(2):match("(.*[/\\])") or "./"):sub(1,-2) .. "/../../.." -- Lazy, fix +package.path = basepath.. "/mods/main/script/?.lua;" ..basepath.. "/mods/main/script/?/main.lua;" ..package.path +main() diff --git a/assets/textures/fier0.rgba b/mods/main/texture/fier.rgba similarity index 100% rename from assets/textures/fier0.rgba rename to mods/main/texture/fier.rgba diff --git a/run b/run index e848ed9..03605cc 100755 --- a/run +++ b/run @@ -1,5 +1,5 @@ #!/usr/bin/env bash set -e ./lua_translate -gcc main.c -g -lSDL2 -llua5.3 -o engine -O3 -Werror -Wall +gcc src/main.c -g -lSDL2 -llua5.3 -o engine -O3 -Werror -Wall exec ./engine diff --git a/modules/engine/FUNCTIONS.toml b/src/engine/FUNCTIONS.toml similarity index 100% rename from modules/engine/FUNCTIONS.toml rename to src/engine/FUNCTIONS.toml diff --git a/modules/engine/STATICS.toml b/src/engine/STATICS.toml similarity index 100% rename from modules/engine/STATICS.toml rename to src/engine/STATICS.toml diff --git a/modules/engine/frontend/generic/textures.c b/src/engine/frontend/generic/textures.c similarity index 100% rename from modules/engine/frontend/generic/textures.c rename to src/engine/frontend/generic/textures.c diff --git a/modules/engine/frontend/sdl/main.c b/src/engine/frontend/sdl/main.c similarity index 99% rename from modules/engine/frontend/sdl/main.c rename to src/engine/frontend/sdl/main.c index c49d8fc..9f93548 100644 --- a/modules/engine/frontend/sdl/main.c +++ b/src/engine/frontend/sdl/main.c @@ -28,7 +28,7 @@ // INTEGER UPSCALING // 2 makes the surface scaled 2x, 3 = 3x, etc. // TODO: Fix ENGINE_SDL_TRANSPARENCY 2 -#define ENGINE_SDL_SCALE 5 +#define ENGINE_SDL_SCALE 2 // SKIP: COLOR // Skip setting colors every X requests. Set to 2 to skip every second request, 3 for every third, etc. diff --git a/modules/engine/lua.c b/src/engine/lua.c similarity index 98% rename from modules/engine/lua.c rename to src/engine/lua.c index 9497c41..59bdd32 100644 --- a/modules/engine/lua.c +++ b/src/engine/lua.c @@ -152,6 +152,6 @@ void engine_lua_init() { lua_pushcfunction(engine_lua_state,engine_luaf_texture_from_file); lua_setglobal (engine_lua_state,"engine_texture_from_file"); engine_lua_init_manual(); - luaL_loadfile(engine_lua_state,"assets/scripts/main.lua"); + luaL_loadfile(engine_lua_state,"mods/main/script/main.lua"); lua_call(engine_lua_state,0,0); } \ No newline at end of file diff --git a/modules/engine/lua_manual.c b/src/engine/lua_manual.c similarity index 100% rename from modules/engine/lua_manual.c rename to src/engine/lua_manual.c diff --git a/modules/engine/main.c b/src/engine/main.c similarity index 100% rename from modules/engine/main.c rename to src/engine/main.c diff --git a/modules/engine/textures.c b/src/engine/textures.c similarity index 100% rename from modules/engine/textures.c rename to src/engine/textures.c diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..ed318ef --- /dev/null +++ b/src/main.c @@ -0,0 +1,16 @@ +#include +#include +#include "engine/main.c" +#include "engine/textures.c" +#include "engine/frontend/sdl/main.c" +#include "engine/frontend/generic/textures.c" +#include "engine/lua.c" + +int main(int argc, char **argv) { + for (int i = 0; i < argc; ++i) { + printf("argv[%d]: %s\n", i, argv[i]); + } + + engine_lua_init(); + return 0; +} diff --git a/test.c b/test.c deleted file mode 100644 index dcc0066..0000000 --- a/test.c +++ /dev/null @@ -1,145 +0,0 @@ -#include -#include -#include "modules/engine/main.c" -#include "modules/engine/frontend/sdl/main.c" -#include "modules/engine/frontend/generic/textures.c" -//#include "modules/engine/frontend/sdl/textures.c" // TODO - -void handleEvent(struct ENGINE_EVENT * event) { - if (event->type == ENGINE_EVENT_TYPE_EXIT) { - exit(0); - } -} - -int frame = 0; -int frameSec = 0; -Uint32 lastSec = 0; -char tr, tg, tb; - -struct ENGINE_TEXTURE * texture; -void tick() { - int y = 0; - while (y < engine_height) { - int x = 0; - while (x < engine_width) { - /*tr = (char)(x + y) + ((char)frame * 1); - tg = (char)(x + y) + ((char)frame * 3); - tb = (char)(x + y) + ((char)frame * 5);*/ - - /*tr = (char)(x + y) * (char)frame * 1; - tg = (char)(x + y) * (char)frame * 3; - tb = (char)(x + y) * (char)frame * 5;*/ - - tr = (char)((x * y) + 64) + frame; - tg = (char)((x * y) + 128) + frame; - tb = (char)((x * y) + 192) + frame; - - /*int part = engine_width / 3; - if (x < part * 1) { - tr = 255; - tg = 0; - tb = 0; - } else if (x < part * 2) { - tr = 0; - tg = 255; - tb = 0; - } else { - tr = 0; - tg = 0; - tb = 255; - }*/ - - /*tr = 0; - tg = 255 - ((char)((x * y) + 128) + frame); - tb = 0;*/ - - /*tr = (char)(((float)x / (float)engine_width) * 255); - tg = 255 - tr; - tb = (char)(((float)y / (float)engine_height) * 255);*/ - engine_surface_color_set(tr,tg,tb,255); - engine_surface_draw_pixel(x,y); - ++x; - } - ++y; - } - - //y = 0; - //while (y < engine_height) { - // int x = 0; - // while (x < engine_width) { - // tr = (char)(x + y) + ((char)frame * 1); - // tg = (char)(x + y) + ((char)frame * 3); - // tb = (char)(x + y) + ((char)frame * 5); - - /*tr = (char)(x + y) * (char)frame * 1; - tg = (char)(x + y) * (char)frame * 3; - tb = (char)(x + y) * (char)frame * 5;*/ - - /*tr = (char)((x * y) + 64) + frame; - tg = (char)((x * y) + 128) + frame; - tb = (char)((x * y) + 192) + frame;*/ - - /*int part = engine_width / 3; - if (x < part * 1) { - tr = 255; - tg = 0; - tb = 0; - } else if (x < part * 2) { - tr = 0; - tg = 255; - tb = 0; - } else { - tr = 0; - tg = 0; - tb = 255; - }*/ - - /*tr = 0; - tg = 255 - ((char)((x * y) + 128) + frame); - tb = 0;*/ - - /*tr = (char)(((float)x / (float)engine_width) * 255); - tg = 255 - tr; - tb = (char)(((float)y / (float)engine_height) * 255);*/ - // engine_surface_color_set(tr,tg,tb,128); - // engine_surface_draw_pixel(x,y); - // ++x; - // } - // ++y; - //} - - - engine_texture_render_2d(texture,5,5); - - frame += 1; - frameSec += 1; - Uint32 tick = SDL_GetTicks(); - if (tick - lastSec >= 1000) { - printf("FPS: %d\n",frameSec); - lastSec = tick; - frameSec = 0; - } - engine_window_present(); - //engine_time_sleep(33); -} - -int main(int argc, char **argv) { - texture = engine_texture_create(8,8); - engine_texture_from_file(texture,"assets/textures/fier.rgba"); - - for (int i = 0; i < argc; ++i) { - printf("argv[%d]: %s\n", i, argv[i]); - } - - engine_window_init(256,256,"Game"); - - while (1) { - struct ENGINE_EVENT * event = engine_event_get(); - if (event->type != ENGINE_EVENT_TYPE_NONE) { - handleEvent(event); - } else { - tick(); - } - engine_free(event); - } -}