WIP (transfération d'un ordi à un autre)

This commit is contained in:
attilavs2 2025-04-15 16:14:21 +02:00
parent efd52dae7d
commit 081ceeb70e
8 changed files with 36 additions and 3 deletions

View file

@ -3,7 +3,7 @@
OUTNAME = mtycoon OUTNAME = mtycoon
CFLAGS = -O0 -Wall -Wextra -g -I./raylib/include -I./lua/include -pipe CFLAGS = -O2 -Wall -Wextra -g -I./raylib/include -I./lua/include -pipe
CC = gcc CC = gcc

Binary file not shown.

View file

@ -22,3 +22,8 @@ end
function on_frame(game) function on_frame(game)
end end
function on_load(game, map)
mtprint("loaded map :")
mtprint(map)
end

View file

@ -58,8 +58,6 @@ int init_game(Game *game){
return 1; return 1;
} }
load_map(game, 0);
int c_worker = 0; int c_worker = 0;
for(int k = 0; k < 16; k++){ for(int k = 0; k < 16; k++){

View file

@ -258,6 +258,29 @@ void lua_onframe(Game *game){
lua_callloop(game, "on_frame"); lua_callloop(game, "on_frame");
} }
void lua_onmapload(Game *game, int map){
gl_game = game;
for(int i = 0; i < lstate_n; i++){
lua_State *L = lstates[i];
lua_mkgame(L, game);
if(lua_getglobal(L, "on_load") == LUA_TNIL){
lua_pop(L, 2);
continue;
}
lua_pushvalue(L, -2);
lua_pushinteger(L, map);
int ret = lua_pcall(L, 2, 0, 0);
if(ret)
puts(lua_tostring(L, -1));
else{
lua_pushliteral(L, "cash");
lua_gettable(L, -2);
if(lua_isinteger(L, -1))
game->cash = lua_tointeger(L, -1);
}
}
}
void lua_mt_init(lua_State *L){ void lua_mt_init(lua_State *L){
for(int i = 0; i < sizeof(exported_funcs)/sizeof(*exported_funcs); i++) for(int i = 0; i < sizeof(exported_funcs)/sizeof(*exported_funcs); i++)
lua_register(L, exported_funcs[i].name, exported_funcs[i].fn); lua_register(L, exported_funcs[i].name, exported_funcs[i].fn);

View file

@ -7,6 +7,8 @@ void lua_ontick(Game *game);
void lua_onframe(Game *game); void lua_onframe(Game *game);
void lua_onmapload(Game *game, int map);
void script_init(); void script_init();
void script_clean(); void script_clean();

View file

@ -30,6 +30,7 @@ int init(Game *game){
err |= init_game(game); err |= init_game(game);
init_ui(); init_ui();
script_init(game); script_init(game);
load_map(game, 0);
return err; return err;
} }

View file

@ -10,6 +10,7 @@
#include "types.h" #include "types.h"
#include "draw.h" #include "draw.h"
#include "lua_inter.h"
extern MapCollec mapcollec; extern MapCollec mapcollec;
@ -39,6 +40,9 @@ int load_map(Game *game, int mapn){
return 1; return 1;
if(generate_coll(game, mapn)) if(generate_coll(game, mapn))
return 1; return 1;
lua_onmapload(game, mapn);
return 0; return 0;
} }