Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
skhaz committed Nov 22, 2023
1 parent eefcc03 commit 5b782e2
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 67 deletions.
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
88 changes: 44 additions & 44 deletions assets/sandbox/scripts/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
32 changes: 16 additions & 16 deletions src/eventmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ void eventmanager::update() {
SDL_Event event;

Check warning on line 9 in src/eventmanager.cpp

View workflow job for this annotation

GitHub Actions / lint

/src/eventmanager.cpp:9:13 [cppcoreguidelines-init-variables]

variable 'event' is not initialized

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;
// }
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/scriptengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ using namespace framework;
void scriptengine::run() {

Check warning on line 19 in src/scriptengine.cpp

View workflow job for this annotation

GitHub Actions / lint

/src/scriptengine.cpp:19:20 [readability-convert-member-functions-to-static]

method 'run' can be made static
sol::state lua;

Check warning on line 20 in src/scriptengine.cpp

View workflow job for this annotation

GitHub Actions / lint

/src/scriptengine.cpp:20:14 [cppcoreguidelines-init-variables]

variable 'lua' is not initialized

lua.open_libraries();
lua.open_libraries(sol::lib::base);
// lua.open_libraries();

lua.new_enum(
"KeyEvent",
Expand Down Expand Up @@ -80,4 +81,15 @@ void scriptengine::run() {

const auto script = storage::io::read("scripts/main.lua");
lua.script(std::string_view(reinterpret_cast<const char *>(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();
}

0 comments on commit 5b782e2

Please sign in to comment.