Fix cmake files and add input file
This commit is contained in:
parent
2de172775d
commit
077b2759ad
8 changed files with 65 additions and 26 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -30,7 +30,7 @@
|
|||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
"environment": [],
|
||||
"externalConsole": true,
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "/usr/bin/gdb",
|
||||
"setupCommands": [
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
cmake_minimum_required (VERSION 3.8)
|
||||
cmake_minimum_required(VERSION 4.0)
|
||||
|
||||
if (POLICY CMP0141)
|
||||
cmake_policy(SET CMP0141 NEW)
|
||||
|
|
|
@ -9,6 +9,8 @@ set(CMAKE_CXX_STANDARD 20)
|
|||
set(SOURCES
|
||||
main.cpp
|
||||
main.h
|
||||
input.cpp
|
||||
input.h
|
||||
${CMAKE_SOURCE_DIR}/include/glad.c
|
||||
)
|
||||
|
||||
|
@ -26,15 +28,15 @@ if(WIN32)
|
|||
${CMAKE_SOURCE_DIR}/lib/luajit.lib
|
||||
)
|
||||
elseif(UNIX)
|
||||
include_directories(${SDL2_INCLUDE_DIRS} ${LUAJIT_INCLUDE_DIRS})
|
||||
link_directories(${SDL2_LIBRARY_DIRS} ${LUAJIT_LIBRARY_DIRS})
|
||||
find_package(SDL2 REQUIRED)
|
||||
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(engine
|
||||
${SDL2_LIBRARIES}
|
||||
${LUAJIT_LIBRARIES}
|
||||
SDL2::SDL2
|
||||
luajit
|
||||
dl # just in case LuaJIT needs dynamic linking
|
||||
m # math lib, commonly needed
|
||||
dl
|
||||
m
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
35
engine/input.cpp
Normal file
35
engine/input.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
#include "input.h"
|
||||
|
||||
void process_input(SDL_Keysym keysym) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Call engine.keypressed(key)
|
||||
lua_getglobal(luaState, "engine");
|
||||
if (lua_istable(luaState, -1)) {
|
||||
lua_getfield(luaState, -1, "KeyPressed");
|
||||
if (lua_isfunction(luaState, -1)) {
|
||||
lua_pushinteger(luaState, keysym.scancode);
|
||||
|
||||
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||
const char* error = lua_tostring(luaState, -1);
|
||||
std::cerr << "Lua error in engine.keypressed: " << error << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (keysym.scancode) {
|
||||
case SDL_SCANCODE_ESCAPE:
|
||||
isRunning = false;
|
||||
|
||||
std::cout << "Closing game\n";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
4
engine/input.h
Normal file
4
engine/input.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
void process_input();
|
|
@ -9,6 +9,8 @@ extern "C" {
|
|||
#include <lauxlib.h>
|
||||
}
|
||||
|
||||
#include "input.h"
|
||||
|
||||
|
||||
bool isRunning = false;
|
||||
lua_State* luaState;
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
// Game-Engine.h : Include file for standard system include files,
|
||||
// or project specific include files.
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// TODO: Reference additional headers your program requires here.
|
||||
|
|
2
test.lua
2
test.lua
|
@ -1,4 +1,4 @@
|
|||
|
||||
function engine.KeyPressed(key)
|
||||
print("Pressed key:" .. key)
|
||||
print("Pressed key: " .. key)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue