Skip to content

Commit

Permalink
the update
Browse files Browse the repository at this point in the history
  • Loading branch information
LDAsuku committed Nov 22, 2022
1 parent 3fc5dac commit 529c491
Show file tree
Hide file tree
Showing 92 changed files with 24,144 additions and 171 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
extern/** -text -eol linguist-vendored=true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# builds
/build*
/out*
.cache/
.vs*

# user data
.soggy_history
Expand Down
47 changes: 20 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,31 @@ cmake_minimum_required(VERSION 3.13)

project(soggy)

option(SOGGY_PROTO_SHARED "Use a shared library for protos. Decreases build time but doesn't work on some systems." OFF)

# debug build by default
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

find_package(PkgConfig REQUIRED)
find_package(Protobuf REQUIRED)
find_package(Lua REQUIRED)

add_subdirectory("extern/enet-1.3.17")
add_subdirectory("extern/replxx-0.0.4")

# libenet
pkg_check_modules(libenet IMPORTED_TARGET libenet REQUIRED)
add_library(libenet INTERFACE)
target_compile_options(libenet INTERFACE ${libenet_CFLAGS})
target_link_libraries(libenet INTERFACE ${libenet_LDFLAGS})

# readline
pkg_check_modules(readline IMPORTED_TARGET readline REQUIRED)
add_library(readline INTERFACE)
target_compile_options(readline INTERFACE ${readline_CFLAGS})
target_link_libraries(readline INTERFACE ${readline_LDFLAGS})

# lua53
#pkg_check_modules(lua53 IMPORTED_TARGET lua53 REQUIRED)
#add_library(lua53 INTERFACE)
#target_compile_options(lua53 INTERFACE ${lua53_CFLAGS})
#target_link_libraries(lua53 INTERFACE ${lua53_LDFLAGS})
set(CMAKE_CXX_STANDARD "17")

# protos
# use a shared library because linking a 100mb+ static library takes extremely long
# maybe use a static library for release builds?
add_library(soggy_proto SHARED)
if(SOGGY_PROTO_SHARED)
add_library(soggy_proto SHARED)
else()
add_library(soggy_proto STATIC)
endif()
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/proto/proto")
file(GLOB proto_srcs "${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto")
target_include_directories(soggy_proto PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/proto")
# target_compile_definitions(soggy_proto PUBLIC "PROTOBUF_NAMESPACE_ID=proto")
target_include_directories(soggy_proto PUBLIC "${Protobuf_INCLUDE_DIRS}")
foreach(f ${proto_srcs})
protobuf_generate_cpp(proto_src proto_header ${f} PROTOC_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/proto/proto")
target_sources(soggy_proto PRIVATE ${proto_src})
Expand All @@ -47,7 +37,6 @@ target_link_libraries(soggy_proto PUBLIC ${Protobuf_LIBRARY})

# cmdids processor
add_executable(soggy_cmdids_processor "tool/cmdids_processor.cpp")
set_target_properties(soggy_cmdids_processor PROPERTIES CXX_STANDARD "17")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/proto/proto/cmdids.cpp" "${CMAKE_CURRENT_BINARY_DIR}/proto/proto/cmdids.hpp"
DEPENDS soggy_cmdids_processor "${CMAKE_CURRENT_SOURCE_DIR}/proto/cmdids.csv"
Expand All @@ -65,8 +54,12 @@ add_executable(soggy
)
target_include_directories(soggy PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_include_directories(soggy PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/extern")
set_target_properties(soggy PROPERTIES CXX_STANDARD "17")
target_include_directories(soggy PRIVATE "${LUA_INCLUDE_DIR}")
target_include_directories(soggy PRIVATE "extern/enet/1.3.17/include")
if(WIN32)
target_link_libraries(soggy PRIVATE winmm ws2_32)
endif()
target_link_libraries(soggy PRIVATE soggy_proto)
target_link_libraries(soggy PRIVATE libenet)
target_link_libraries(soggy PRIVATE readline)
#target_link_libraries(soggy PRIVATE lua)
target_link_libraries(soggy PRIVATE enet)
target_link_libraries(soggy PRIVATE replxx)
target_link_libraries(soggy PRIVATE ${LUA_LIBRARIES})
27 changes: 23 additions & 4 deletions dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import traceback
import urllib.parse

DISPATCH_LISTEN = "localhost"
DISPATCH_LISTEN = "0.0.0.0"
DISPATCH_PORT = 8099
DISPATCH_ROUTE_URL = "http://localhost:8099"

Expand Down Expand Up @@ -55,13 +55,30 @@ def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(DESIGN_DATA_CUR_VERSION_BYTES)
elif url.path == "/":
self.send_response(200)
self.end_headers()
self.wfile.write(b"<head><style>@keyframes soggy{from{background-position:0 234px}to{background-position:375px 0}}body{background:url(\"/soggy_cat.png\") repeat;animation:soggy 2s linear 0s infinite}</style></head>\n")
elif url.path == "/soggy_cat.png":
self.send_response(200)
self.send_header("Content-Type", "image/png")
self.send_header("Content-Disposition", "inline")
self.end_headers()
with open("soggy_cat.png", "rb") as f:
self.wfile.write(f.read())
elif url.path == "/favicon.ico":
self.send_response(404)
self.wfile.write(b"404 Not Found\n")
self.end_headers()
else:
self.send_response(501)
self.send_response(400)
self.end_headers()
self.wfile.write(b"400 Bad Request\n")
except Exception as ex:
traceback.print_exception(ex)
self.send_response(500)
self.end_headers()
self.wfile.write(b"500 Internal Server Error\n")

def do_HEAD(self):
url = urllib.parse.urlparse(self.path)
Expand All @@ -83,12 +100,14 @@ def do_HEAD(self):
self.send_header("Content-Length", str(len(DESIGN_DATA_CUR_VERSION_BYTES)))
self.end_headers()
else:
self.send_response(501)
self.send_response(400)
self.wfile.write(b"400 Bad Request\n")
self.end_headers()
except Exception as ex:
traceback.print_exc(ex)
self.send_response(500)
self.end_headers()
self.wfile.write(b"500 Internal Server Error\n")

def do_POST(self):
self.send_response(501)
Expand Down Expand Up @@ -172,7 +191,7 @@ def do_query_cur_region(self, url: urllib.parse.ParseResult, query: dict):
httpd = None
try:
socketserver.TCPServer.allow_reuse_address = True
httpd = socketserver.TCPServer(("localhost", DISPATCH_PORT), DispatchHandler)
httpd = socketserver.TCPServer((DISPATCH_LISTEN, DISPATCH_PORT), DispatchHandler)
print(f"dispatch listening on port {DISPATCH_PORT:d}")
httpd.serve_forever()
except KeyboardInterrupt:
Expand Down
94 changes: 94 additions & 0 deletions extern/enet-1.3.17/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#cmake_minimum_required(VERSION 2.6)

project(enet)

# The "configure" step.
include(CheckFunctionExists)
include(CheckStructHasMember)
include(CheckTypeSize)
check_function_exists("fcntl" HAS_FCNTL)
check_function_exists("poll" HAS_POLL)
check_function_exists("getaddrinfo" HAS_GETADDRINFO)
check_function_exists("getnameinfo" HAS_GETNAMEINFO)
check_function_exists("gethostbyname_r" HAS_GETHOSTBYNAME_R)
check_function_exists("gethostbyaddr_r" HAS_GETHOSTBYADDR_R)
check_function_exists("inet_pton" HAS_INET_PTON)
check_function_exists("inet_ntop" HAS_INET_NTOP)
check_struct_has_member("struct msghdr" "msg_flags" "sys/types.h;sys/socket.h" HAS_MSGHDR_FLAGS)
set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h" "sys/socket.h")
check_type_size("socklen_t" HAS_SOCKLEN_T BUILTIN_TYPES_ONLY)
unset(CMAKE_EXTRA_INCLUDE_FILES)
if(MSVC)
add_definitions(-W3)
else()
add_definitions(-Wno-error)
endif()

if(HAS_FCNTL)
add_definitions(-DHAS_FCNTL=1)
endif()
if(HAS_POLL)
add_definitions(-DHAS_POLL=1)
endif()
if(HAS_GETNAMEINFO)
add_definitions(-DHAS_GETNAMEINFO=1)
endif()
if(HAS_GETADDRINFO)
add_definitions(-DHAS_GETADDRINFO=1)
endif()
if(HAS_GETHOSTBYNAME_R)
add_definitions(-DHAS_GETHOSTBYNAME_R=1)
endif()
if(HAS_GETHOSTBYADDR_R)
add_definitions(-DHAS_GETHOSTBYADDR_R=1)
endif()
if(HAS_INET_PTON)
add_definitions(-DHAS_INET_PTON=1)
endif()
if(HAS_INET_NTOP)
add_definitions(-DHAS_INET_NTOP=1)
endif()
if(HAS_MSGHDR_FLAGS)
add_definitions(-DHAS_MSGHDR_FLAGS=1)
endif()
if(HAS_SOCKLEN_T)
add_definitions(-DHAS_SOCKLEN_T=1)
endif()

include_directories(${PROJECT_SOURCE_DIR}/include)

set(INCLUDE_FILES_PREFIX include/enet)
set(INCLUDE_FILES
${INCLUDE_FILES_PREFIX}/callbacks.h
${INCLUDE_FILES_PREFIX}/enet.h
${INCLUDE_FILES_PREFIX}/list.h
${INCLUDE_FILES_PREFIX}/protocol.h
${INCLUDE_FILES_PREFIX}/time.h
${INCLUDE_FILES_PREFIX}/types.h
${INCLUDE_FILES_PREFIX}/unix.h
${INCLUDE_FILES_PREFIX}/utility.h
${INCLUDE_FILES_PREFIX}/win32.h
)

set(SOURCE_FILES
callbacks.c
compress.c
host.c
list.c
packet.c
peer.c
protocol.c
unix.c
win32.c)

source_group(include FILES ${INCLUDE_FILES})
source_group(source FILES ${SOURCE_FILES})

add_library(enet STATIC
${INCLUDE_FILES}
${SOURCE_FILES}
)

if (MINGW)
target_link_libraries(enet winmm ws2_32)
endif()
Loading

0 comments on commit 529c491

Please sign in to comment.