lua: pack.get_folder(pack_name) + shader fix
This commit is contained in:
parent
7d35356f9d
commit
d7f2771da4
@ -16,7 +16,7 @@ void main(){
|
||||
float depth = (a_distance/256.0);
|
||||
float alpha = a_color.a * tex_color.a;
|
||||
// anyway it's any alpha-test alternative required
|
||||
if (alpha < 0.1f)
|
||||
if (alpha < 0.5f)
|
||||
discard;
|
||||
f_color = mix(a_color * tex_color, vec4(fogColor,1.0), min(1.0, pow(depth*u_fogFactor, u_fogCurve)));
|
||||
f_color.a = alpha;
|
||||
|
||||
@ -46,7 +46,7 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
||||
}
|
||||
|
||||
auto resdir = paths->getResources();
|
||||
scripting::initialize(paths);
|
||||
scripting::initialize(this);
|
||||
|
||||
std::cout << "-- loading assets" << std::endl;
|
||||
std::vector<fs::path> roots {resdir};
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include "../../voxels/voxel.h"
|
||||
#include "../../lighting/Lighting.h"
|
||||
#include "../../logic/BlocksController.h"
|
||||
#include "../../engine.h"
|
||||
|
||||
inline int lua_pushivec3(lua_State* L, int x, int y, int z) {
|
||||
lua_pushinteger(L, x);
|
||||
@ -27,7 +28,25 @@ inline void luaL_openlib(lua_State* L, const char* name, const luaL_Reg* libfunc
|
||||
lua_setglobal(L, name);
|
||||
}
|
||||
|
||||
/* == world library ==*/
|
||||
/* == pack library == */
|
||||
static int l_pack_get_folder(lua_State* L) {
|
||||
std::string packName = lua_tostring(L, 1);
|
||||
for (auto& pack : scripting::engine->getContentPacks()) {
|
||||
if (pack.id == packName) {
|
||||
lua_pushstring(L, (pack.folder.u8string()+"/").c_str());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
lua_pushstring(L, "");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg packlib [] = {
|
||||
{"get_folder", l_pack_get_folder},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
/* == world library == */
|
||||
static int l_world_get_day_time(lua_State* L) {
|
||||
lua_pushnumber(L, scripting::level->world->daytime);
|
||||
return 1;
|
||||
@ -266,6 +285,7 @@ static int l_is_replaceable_at(lua_State* L) {
|
||||
lua_setglobal(L, NAME))
|
||||
|
||||
void apilua::create_funcs(lua_State* L) {
|
||||
luaL_openlib(L, "pack", packlib, 0);
|
||||
luaL_openlib(L, "world", worldlib, 0);
|
||||
luaL_openlib(L, "player", playerlib, 0);
|
||||
|
||||
|
||||
@ -11,19 +11,19 @@
|
||||
#include "../../voxels/Block.h"
|
||||
#include "../../items/ItemDef.h"
|
||||
#include "../../logic/BlocksController.h"
|
||||
#include "../../engine.h"
|
||||
#include "api_lua.h"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
namespace scripting {
|
||||
extern lua_State* L;
|
||||
extern EnginePaths* paths;
|
||||
}
|
||||
|
||||
Engine* scripting::engine = nullptr;
|
||||
lua_State* scripting::L = nullptr;
|
||||
Level* scripting::level = nullptr;
|
||||
const Content* scripting::content = nullptr;
|
||||
EnginePaths* scripting::paths = nullptr;
|
||||
BlocksController* scripting::blocks = nullptr;
|
||||
|
||||
inline int lua_pushivec3(lua_State* L, int x, int y, int z) {
|
||||
@ -58,8 +58,8 @@ int call_func(lua_State* L, int argc, const std::string& name) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void scripting::initialize(EnginePaths* paths) {
|
||||
scripting::paths = paths;
|
||||
void scripting::initialize(Engine* engine) {
|
||||
scripting::engine = engine;
|
||||
|
||||
L = luaL_newstate();
|
||||
if (L == nullptr) {
|
||||
@ -87,7 +87,7 @@ void scripting::on_world_load(Level* level, BlocksController* blocks) {
|
||||
scripting::level = level;
|
||||
scripting::content = level->content;
|
||||
scripting::blocks = blocks;
|
||||
|
||||
auto paths = scripting::engine->getPaths();
|
||||
fs::path file = paths->getResources()/fs::path("scripts/world.lua");
|
||||
std::string src = files::read_string(file);
|
||||
luaL_loadbuffer(L, src.c_str(), src.length(), file.string().c_str());
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
class EnginePaths;
|
||||
class Engine;
|
||||
class Content;
|
||||
class Level;
|
||||
class Block;
|
||||
@ -14,11 +14,12 @@ struct item_funcs_set;
|
||||
class BlocksController;
|
||||
|
||||
namespace scripting {
|
||||
extern Engine* engine;
|
||||
extern const Content* content;
|
||||
extern Level* level;
|
||||
extern BlocksController* blocks;
|
||||
|
||||
void initialize(EnginePaths* paths);
|
||||
void initialize(Engine* engine);
|
||||
void on_world_load(Level* level, BlocksController* blocks);
|
||||
void on_world_quit();
|
||||
void update_block(const Block* block, int x, int y, int z);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user