Restructure

This commit is contained in:
Fierelier 2023-05-16 12:29:12 +02:00
parent 1f51cea02c
commit e5914a3f54
18 changed files with 81 additions and 215 deletions

View File

@ -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

Binary file not shown.

Binary file not shown.

View File

@ -83,6 +83,6 @@ for func in functions:
ofile.write('''\ ofile.write('''\
engine_lua_init_manual(); 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); lua_call(engine_lua_state,0,0);
}''') }''')

15
main.c
View File

@ -1,15 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#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();
}

61
mods/main/script/main.lua Normal file
View File

@ -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()

2
run
View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
./lua_translate ./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 exec ./engine

View File

@ -28,7 +28,7 @@
// INTEGER UPSCALING // INTEGER UPSCALING
// 2 makes the surface scaled 2x, 3 = 3x, etc. // 2 makes the surface scaled 2x, 3 = 3x, etc.
// TODO: Fix ENGINE_SDL_TRANSPARENCY 2 // TODO: Fix ENGINE_SDL_TRANSPARENCY 2
#define ENGINE_SDL_SCALE 5 #define ENGINE_SDL_SCALE 2
// SKIP: COLOR // SKIP: COLOR
// Skip setting colors every X requests. Set to 2 to skip every second request, 3 for every third, etc. // Skip setting colors every X requests. Set to 2 to skip every second request, 3 for every third, etc.

View File

@ -152,6 +152,6 @@ void engine_lua_init() {
lua_pushcfunction(engine_lua_state,engine_luaf_texture_from_file); lua_pushcfunction(engine_lua_state,engine_luaf_texture_from_file);
lua_setglobal (engine_lua_state,"engine_texture_from_file"); lua_setglobal (engine_lua_state,"engine_texture_from_file");
engine_lua_init_manual(); 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); lua_call(engine_lua_state,0,0);
} }

16
src/main.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#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;
}

145
test.c
View File

@ -1,145 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#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);
}
}