diff --git a/CMakeLists.txt b/CMakeLists.txt index b942135..9ae6ccd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,17 +30,16 @@ if(SANDBOX) endif() if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten") - target_link_libraries(${PROJECT_NAME} "--profiling") - target_link_libraries(${PROJECT_NAME} "-s RUNTIME_DEBUG") - target_link_libraries(${PROJECT_NAME} "-s ASSERTIONS=1") - target_link_libraries(${PROJECT_NAME} "-s NO_DISABLE_EXCEPTION_CATCHING") + # target_link_libraries(${PROJECT_NAME} "--profiling") + # target_link_libraries(${PROJECT_NAME} "-s RUNTIME_DEBUG") + # target_link_libraries(${PROJECT_NAME} "-s ASSERTIONS=1") + # target_link_libraries(${PROJECT_NAME} "-s NO_DISABLE_EXCEPTION_CATCHING") target_link_libraries(${PROJECT_NAME} "-s ALLOW_MEMORY_GROWTH=1") - # target_link_libraries(${PROJECT_NAME} "-s FORCE_FILESYSTEM=1") target_link_libraries(${PROJECT_NAME} "-s INITIAL_MEMORY=134217728") target_link_libraries(${PROJECT_NAME} "-s EXPORTED_RUNTIME_METHODS=['callMain']") - target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror -pedantic -Og -g) + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror -pedantic -O2 -flto) elseif(CMAKE_BUILD_TYPE MATCHES "Debug") if (MSVC) target_compile_options(${PROJECT_NAME} PRIVATE /W4 /Od /Zi) diff --git a/assets/sandbox/scripts/main.lua b/assets/sandbox/scripts/main.lua index 8b35d2b..700d040 100644 --- a/assets/sandbox/scripts/main.lua +++ b/assets/sandbox/scripts/main.lua @@ -18,48 +18,48 @@ me.x = (engine.width // 2) - (me.width // 2) me.y = (engine.height // 2) - (me.height // 2) me:on_update(function(self) - if engine:is_keydown(KeyEvent.w) then - self.y = self.y - 1 - end - - if engine:is_keydown(KeyEvent.a) then - self.x = self.x - 1 - end - - if engine:is_keydown(KeyEvent.s) then - self.y = self.y + 1 - end - - if engine:is_keydown(KeyEvent.d) then - self.x = self.x + 1 - end - - if engine:is_keydown(KeyEvent.space) then - me:play("blobs/deitzis.ogg") - end - - angle = angle + 1 - if angle > 360 then - angle = 0 - end - - self.angle = angle - - if direction == 0 then - alpha = alpha - 2 - if alpha <= 0 then - alpha = 0 - direction = 1 + if engine:is_keydown(KeyEvent.w) then + self.y = self.y - 1 end - else - alpha = alpha + 2 - if alpha >= 255 then - alpha = 255 - direction = 0 + + if engine:is_keydown(KeyEvent.a) then + self.x = self.x - 1 + end + + if engine:is_keydown(KeyEvent.s) then + self.y = self.y + 1 + end + + if engine:is_keydown(KeyEvent.d) then + self.x = self.x + 1 + end + + if engine:is_keydown(KeyEvent.space) then + me:play("blobs/deitzis.ogg") + end + + angle = angle + 1 + if angle > 360 then + angle = 0 end - end - self.alpha = alpha + self.angle = angle + + if direction == 0 then + alpha = alpha - 2 + if alpha <= 0 then + alpha = 0 + direction = 1 + end + else + alpha = alpha + 2 + if alpha >= 255 then + alpha = 255 + direction = 0 + end + end + + self.alpha = alpha end) local garbage = engine:spawn() @@ -69,11 +69,11 @@ garbage = nil local gc = engine:spawn() gc:on_update(function(self) - if collectgarbage("count") / 1024 > 8 then - collectgarbage("collect") - else - collectgarbage("step", 1) - end + if collectgarbage("count") / 1024 > 8 then + collectgarbage("collect") + else + collectgarbage("step", 1) + end end) engine:run() diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp index 7efcdc9..65a2bc5 100644 --- a/src/eventmanager.cpp +++ b/src/eventmanager.cpp @@ -9,22 +9,22 @@ void eventmanager::update() { SDL_Event event; while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_QUIT: - std::for_each(_receivers.begin(), _receivers.end(), - std::bind(&eventreceiver::on_quit, std::placeholders::_1)); - break; - - case SDL_KEYDOWN: - std::for_each(_receivers.begin(), _receivers.end(), - std::bind(&eventreceiver::on_keydown, std::placeholders::_1, keyevent(event.key.keysym.sym))); - break; - - case SDL_KEYUP: - std::for_each(_receivers.begin(), _receivers.end(), - std::bind(&eventreceiver::on_keyup, std::placeholders::_1, keyevent(event.key.keysym.sym))); - break; - } + // switch (event.type) { + // case SDL_QUIT: + // std::for_each(_receivers.begin(), _receivers.end(), + // std::bind(&eventreceiver::on_quit, std::placeholders::_1)); + // break; + + // case SDL_KEYDOWN: + // std::for_each(_receivers.begin(), _receivers.end(), + // std::bind(&eventreceiver::on_keydown, std::placeholders::_1, keyevent(event.key.keysym.sym))); + // break; + + // case SDL_KEYUP: + // std::for_each(_receivers.begin(), _receivers.end(), + // std::bind(&eventreceiver::on_keyup, std::placeholders::_1, keyevent(event.key.keysym.sym))); + // break; + // } } } diff --git a/src/scriptengine.cpp b/src/scriptengine.cpp index ea85dc2..55ba441 100644 --- a/src/scriptengine.cpp +++ b/src/scriptengine.cpp @@ -19,7 +19,8 @@ using namespace framework; void scriptengine::run() { sol::state lua; - lua.open_libraries(); + lua.open_libraries(sol::lib::base); + // lua.open_libraries(); lua.new_enum( "KeyEvent", @@ -80,4 +81,15 @@ void scriptengine::run() { const auto script = storage::io::read("scripts/main.lua"); lua.script(std::string_view(reinterpret_cast(script.data()), script.size())); + + // lua.script("print('Hello, world!')"); + + // const auto e = enginefactory() + // .set_title("Snake") + // .set_width(640) + // .set_height(480) + // .set_fullscreen(false) + // .create(); + + // e->run(); } \ No newline at end of file