|
|
|
@ -8,13 +8,14 @@
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <ranges>
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
#include <entt/entt.hpp>
|
|
|
|
|
#include <sol/sol.hpp>
|
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
|
|
|
|
|
constexpr std::chrono::microseconds FRAME_TIME (1'000'000 / 60);
|
|
|
|
|
constexpr std::chrono::duration<double> FRAME_TIME (1.0 / 60.0);
|
|
|
|
|
|
|
|
|
|
static bool handleInputs(entt::registry& registry);
|
|
|
|
|
|
|
|
|
@ -26,43 +27,28 @@ int main(int argc, const char *argv[])
|
|
|
|
|
if (auto err = sdl2Initialize(); err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i)
|
|
|
|
|
lua.script_file(argv[i]);
|
|
|
|
|
for (auto file : std::views::counted(argv + 1, argc - 1))
|
|
|
|
|
lua.script_file(file);
|
|
|
|
|
|
|
|
|
|
sol::optional<sol::table> entities = lua["entities"];
|
|
|
|
|
if (entities) {
|
|
|
|
|
if (auto entities = lua.get<sol::optional<sol::table>>("entities"); entities) {
|
|
|
|
|
entities->for_each([®istry](sol::object _, sol::object val) {
|
|
|
|
|
const auto ent = registry.create();
|
|
|
|
|
auto tbl = val.as<sol::table>();
|
|
|
|
|
|
|
|
|
|
sol::optional<std::string> solid = tbl["solid"];
|
|
|
|
|
if (solid) {
|
|
|
|
|
registry.emplace<Solid>(ent, solid->c_str());
|
|
|
|
|
}
|
|
|
|
|
if (auto solid = tbl.get<sol::optional<std::string>>("solid"); solid)
|
|
|
|
|
registry.emplace<Solid>(ent, *solid);
|
|
|
|
|
|
|
|
|
|
sol::optional<std::string> texture = tbl["texture"];
|
|
|
|
|
if (texture) {
|
|
|
|
|
registry.emplace<Texture>(ent, texture->c_str());
|
|
|
|
|
}
|
|
|
|
|
if (auto tex = tbl.get<sol::optional<std::string>>("texture"); tex)
|
|
|
|
|
registry.emplace<Texture>(ent, *tex);
|
|
|
|
|
|
|
|
|
|
sol::optional<sol::table> point = tbl["point"];
|
|
|
|
|
if (point) {
|
|
|
|
|
registry.emplace<Point>(ent,
|
|
|
|
|
static_cast<float>((*point)["x"]),
|
|
|
|
|
static_cast<float>((*point)["y"]));
|
|
|
|
|
}
|
|
|
|
|
if (auto point = tbl.get<sol::optional<sol::table>>("point"); point)
|
|
|
|
|
registry.emplace<Point>(ent, point->get<float, float>("x", "y"));
|
|
|
|
|
|
|
|
|
|
sol::optional<sol::table> velocity = tbl["velocity"];
|
|
|
|
|
if (velocity) {
|
|
|
|
|
registry.emplace<Velocity>(ent,
|
|
|
|
|
static_cast<float>((*velocity)["x"]),
|
|
|
|
|
static_cast<float>((*velocity)["y"]));
|
|
|
|
|
}
|
|
|
|
|
if (auto vel = tbl.get<sol::optional<sol::table>>("velocity"); vel)
|
|
|
|
|
registry.emplace<Velocity>(ent, vel->get<float, float>("x", "y"));
|
|
|
|
|
|
|
|
|
|
sol::optional<sol::table> player = tbl["player"];
|
|
|
|
|
if (player) {
|
|
|
|
|
if (auto player = tbl.get<sol::optional<sol::table>>("player"); player)
|
|
|
|
|
registry.emplace<Player>(ent);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "No entities defined..." << std::endl;
|
|
|
|
|