Skip to content

Commit

Permalink
keyboard, audio work
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed Apr 9, 2024
1 parent 043e037 commit 521a793
Show file tree
Hide file tree
Showing 67 changed files with 4,207 additions and 145 deletions.
52 changes: 51 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
include(FetchContent)

set(LOVE_VERSION "12.0")
set(APP_VERSION "3.1.0")
Expand Down Expand Up @@ -161,6 +162,48 @@ add_library(lua53
)
target_link_libraries(lua53 PRIVATE PkgConfig::lua51)

FetchContent_Declare(lua-https
GIT_REPOSITORY https://github.com/bartbes/lua-https
GIT_TAG selectable_library_loaders
)

FetchContent_GetProperties(lua-https)
if(NOT lua-https_POPULATED)
FetchContent_Populate(lua-https)
endif()

add_library(lua-https STATIC
${lua-https_SOURCE_DIR}/src/common/config.h
${lua-https_SOURCE_DIR}/src/common/LibraryLoader.h
${lua-https_SOURCE_DIR}/src/common/Connection.h
${lua-https_SOURCE_DIR}/src/common/ConnectionClient.h
${lua-https_SOURCE_DIR}/src/common/HTTPRequest.cpp
${lua-https_SOURCE_DIR}/src/common/HTTPRequest.h
${lua-https_SOURCE_DIR}/src/common/HTTPS.cpp
${lua-https_SOURCE_DIR}/src/common/HTTPS.h
${lua-https_SOURCE_DIR}/src/common/HTTPSClient.cpp
${lua-https_SOURCE_DIR}/src/common/HTTPSClient.h
${lua-https_SOURCE_DIR}/src/common/PlaintextConnection.cpp
${lua-https_SOURCE_DIR}/src/common/PlaintextConnection.h
${lua-https_SOURCE_DIR}/src/generic/LinktimeLibraryLoader.cpp
${lua-https_SOURCE_DIR}/src/generic/CurlClient.cpp
${lua-https_SOURCE_DIR}/src/generic/CurlClient.h
${lua-https_SOURCE_DIR}/src/generic/OpenSSLConnection.cpp
${lua-https_SOURCE_DIR}/src/generic/OpenSSLConnection.h
${lua-https_SOURCE_DIR}/src/lua/main.cpp
)

set(LIBRARY_LOADER "linktime")
target_compile_definitions(lua-https PRIVATE
HTTPS_LIBRARY_LOADER_LINKTIME
HTTPS_BACKEND_CURL
)

# link curl
pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl)
target_link_libraries(lua-https PRIVATE PkgConfig::lua51 PkgConfig::libcurl)


add_library(love_physfs
libraries/physfs/physfs.c
libraries/physfs/physfs.h
Expand Down Expand Up @@ -215,7 +258,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE wuff)

# link everything else
target_link_libraries(${PROJECT_NAME} PRIVATE
${APP_LIBS} z luabit lua53 vorbisidec ogg modplug
${APP_LIBS} z luabit lua53 vorbisidec ogg modplug lua-https
)

include_directories(
Expand All @@ -225,6 +268,7 @@ include_directories(
libraries/noise1234
libraries/physfs
libraries/wuff
libraries/utf8
)

# find source -type f -name \*.cpp | clip
Expand All @@ -239,6 +283,11 @@ source/common/Stream.cpp
source/common/types.cpp
source/common/Variant.cpp
source/main.cpp
source/modules/audio/Audio.cpp
source/modules/audio/Pool.cpp
source/modules/audio/Source.cpp
source/modules/audio/wrap_Audio.cpp
source/modules/audio/wrap_Source.cpp
source/modules/data/ByteData.cpp
source/modules/data/CompressedData.cpp
source/modules/data/DataModule.cpp
Expand All @@ -262,6 +311,7 @@ source/modules/filesystem/wrap_Filesystem.cpp
source/modules/joystick/JoystickModule.cpp
source/modules/joystick/wrap_Joystick.cpp
source/modules/joystick/wrap_JoystickModule.cpp
source/modules/keyboard/wrap_Keyboard.cpp
source/modules/love/love.cpp
source/modules/sensor/Sensor.cpp
source/modules/sensor/wrap_Sensor.cpp
Expand Down
7 changes: 0 additions & 7 deletions debug/Cargo.lock

This file was deleted.

6 changes: 0 additions & 6 deletions debug/Cargo.toml

This file was deleted.

75 changes: 75 additions & 0 deletions debug/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import sys
import argparse
import time
import os

from io import TextIOWrapper
from socket import gaierror, socket, AF_INET, SOCK_STREAM
from pathlib import Path


def clear_console() -> None:
match os.name:
case "nt":
os.system("cls")
case _:
os.system("clear")


def main() -> None:
parser = argparse.ArgumentParser()

parser.add_argument("host", help="the host to connect to")
parser.add_argument(
"-l", "--log", action="store_true", help="write data to log file"
)

args = parser.parse_args()

clear_console()

tcp_socket = socket(AF_INET, SOCK_STREAM, 0)

try:
tcp_socket.connect((args.host, 8000))
except (ConnectionRefusedError, TimeoutError):
print(f"Failed to connect to {args.host}:8000")
sys.exit(1)
except gaierror:
print(f"Invalid host: {args.host}")
sys.exit(1)

log_file: TextIOWrapper = None

if args.log:
Path("logs").mkdir(exist_ok=True)
timestamp = str(int(time.time()))
log_file = open(f"logs/{timestamp}.txt", "w")

while True:
try:
raw_data = tcp_socket.recv(0x400)

if not len(raw_data):
break

data = raw_data.decode("utf-8")

if args.log:
log_file.write(data)

print(data, end="")
except ConnectionResetError:
print("Connection reset by peer")
break
except KeyboardInterrupt:
break

tcp_socket.close()

if args.log:
log_file.close()


if __name__ == "__main__":
main()
56 changes: 56 additions & 0 deletions debug/meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import argparse
import re

from pathlib import Path


def read_file(file_path) -> Path | None:
try:
return Path(file_path).read_text(encoding="utf-8")
except FileNotFoundError:
print(f"File '{file_path}' not found.")

return None


MATCH_STRING = r"(love\.\w+\.\w+)\(\)\s+==>\s+\w+\s+-\s+(\d+\.\d+)"
TIME_REGEX = re.compile(MATCH_STRING, re.MULTILINE)


def main() -> None:
parser = argparse.ArgumentParser(description="Read a file.")
parser.add_argument("file", type=str, help="Path to the file")
parser.add_argument(
"--top", "-t", action="store_true", help="Get top 3 slowest methods"
)

args = parser.parse_args()

content = read_file(args.file)

if not content:
print("No content found in the file.")
return

times = re.findall(TIME_REGEX, content)

if not times:
print("No times found in the file.")
return

sorted_times = sorted(times, key=lambda x: float(x[1][:-1]), reverse=True)

if args.top:
for time in sorted_times[:3]:
method, total_time = time
print(f"- {method}: {total_time}s")

return

for time in sorted_times:
method, total_time = time
print(f"- {method}: {total_time}s")


if __name__ == "__main__":
main()
55 changes: 0 additions & 55 deletions debug/src/main.rs

This file was deleted.

8 changes: 6 additions & 2 deletions include/common/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ using StringMap = MapT<std::string_view, V, N>;
static inline bool getConstant(type in, std::string_view& out) \
{ \
return name.getKey(in, out); \
}
// clang-format on
} \
static inline const char* getConstant(type in) \
{ \
std::string_view out {}; \
return name.getKey(in, out) ? out.data() : nullptr; \
} // clang-format on

template<typename T>
concept MapTIsEnumType = std::is_enum_v<T>;
Expand Down
Loading

0 comments on commit 521a793

Please sign in to comment.