start on toxic game port

This commit is contained in:
Green Sky 2023-11-25 19:41:55 +01:00
commit 8f02e6b5ee
No known key found for this signature in database
7 changed files with 281 additions and 0 deletions

26
.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
.vs/
*.o
*.swp
~*
*~
.idea/
cmake-build-debug/
cmake-build-debugandtest/
cmake-build-release/
*.stackdump
*.coredump
compile_commands.json
/build*
/result*
.clangd
.cache
.DS_Store
.AppleDouble
.LSOverride
CMakeLists.txt.user*
CMakeCache.txt
*.tox
imgui.ini

73
CMakeLists.txt Normal file
View File

@ -0,0 +1,73 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
# cmake setup begin
project(solanaceae_toxic_games)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(SOLANACEAE_TOXIC_GAMES_STANDALONE ON)
# why the f do i need this >:(
set(NOT_SOLANACEAE_TOXIC_GAMES_STANDALONE OFF)
else()
set(SOLANACEAE_TOXIC_GAMES_STANDALONE OFF)
set(NOT_SOLANACEAE_TOXIC_GAMES_STANDALONE ON)
endif()
message("II SOLANACEAE_TOXIC_GAMES_STANDALONE " ${SOLANACEAE_TOXIC_GAMES_STANDALONE})
option(SOLANACEAE_TOXIC_GAMES_BUILD_PLUGINS "Build the toxic_games plugins" ${SOLANACEAE_TOXIC_GAMES_STANDALONE})
if (SOLANACEAE_TOXIC_GAMES_STANDALONE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# defaulting to debug mode, if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# setup my vim ycm :D
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# more paths
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()
# external libs
add_subdirectory(./external EXCLUDE_FROM_ALL) # before increasing warn levels, sad :(
if (SOLANACEAE_TOXIC_GAMES_STANDALONE)
set(CMAKE_CXX_EXTENSIONS OFF)
# bump up warning levels appropriately for clang, gcc & msvc
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
add_compile_options(
-Wall -Wextra # Reasonable and standard
-Wpedantic # Warn if non-standard C++ is used
-Wunused # Warn on anything being unused
#-Wconversion # Warn on type conversions that may lose data
#-Wsign-conversion # Warn on sign conversions
-Wshadow # Warn if a variable declaration shadows one from a parent context
)
if (NOT WIN32)
#link_libraries(-fsanitize=address,undefined)
#link_libraries(-fsanitize=undefined)
endif()
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
endif()
endif()
# cmake setup end
add_subdirectory(./src)
if (SOLANACEAE_TOXIC_GAMES_BUILD_PLUGINS)
add_subdirectory(./plugins)
endif()

82
external/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,82 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
include(FetchContent)
if (NOT TARGET imgui)
FetchContent_Declare(imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG d4ddc46e7
EXCLUDE_FROM_ALL
)
FetchContent_GetProperties(imgui)
if(NOT imgui_POPULATED)
FetchContent_Populate(imgui)
add_library(imgui STATIC
${imgui_SOURCE_DIR}/imgui.h
${imgui_SOURCE_DIR}/imgui_internal.h
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/imstb_rectpack.h
${imgui_SOURCE_DIR}/imstb_textedit.h
${imgui_SOURCE_DIR}/imstb_truetype.h
${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.h
${imgui_SOURCE_DIR}/misc/cpp/imgui_stdlib.cpp
)
target_include_directories(imgui PUBLIC ${imgui_SOURCE_DIR})
endif()
endif()
# TODO: move entt dep into solanaceae_contact
if (NOT TARGET EnTT::EnTT)
FetchContent_Declare(EnTT
GIT_REPOSITORY https://github.com/skypjack/entt.git
GIT_TAG v3.12.2
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(EnTT)
endif()
if (NOT TARGET solanaceae_contact)
FetchContent_Declare(solanaceae_contact
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_contact.git
GIT_TAG master
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(solanaceae_contact)
endif()
if (NOT TARGET solanaceae_plugin)
FetchContent_Declare(solanaceae_plugin
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_plugin.git
GIT_TAG master
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(solanaceae_plugin)
endif()
if (NOT TARGET solanaceae_toxcore)
# set option to interface only? or make default
FetchContent_Declare(solanaceae_toxcore
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_toxcore.git
GIT_TAG master
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(solanaceae_toxcore)
endif()
if (NOT TARGET solanaceae_tox_contacts AND NOT TARGET solanaceae_tox_messages)
FetchContent_Declare(solanaceae_tox
GIT_REPOSITORY https://github.com/Green-Sky/solanaceae_tox.git
GIT_TAG master
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(solanaceae_tox)
endif()

2
plugins/CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)

39
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
if (OFF)
add_library(toxic_games STATIC
#./toxic/windows_stripped.h
#./toxic/misc_tools.h
#./toxic/misc_tools.c
./toxic/fake_ncurses.h
./toxic/toxic_patched_utils.h
./toxic/game_base.h
#./toxic/game_base.c
./toxic/game_base_stripped.c
./toxic/game_util.h
./toxic/game_util.c
#./toxic/game_centipede.h
#./toxic/game_centipede.c
./toxic/game_chess.h
./toxic/game_chess.c
#./toxic/game_life.h
#./toxic/game_life.c
#./toxic/game_snake.h
#./toxic/game_snake.c
)
endif()
########################################
add_library(solanaceae_toxic_games
./solanaceae_toxic_games.hpp
./solanaceae_toxic_games.cpp
)
target_link_libraries(solanaceae_toxic_games PUBLIC
solanaceae_tox_contacts
)

View File

@ -0,0 +1,34 @@
#include "./solanaceae_toxic_games.hpp"
ToxicGames::ToxicGames(
Contact3Registry& cr,
ToxI& t,
ToxEventProviderI& tep,
ToxContactModel2& tcm
) :
_cr(cr),
_t(t),
_tep(tep),
_tcm(tcm)
{
// register custom packet handlers
_tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_LOSSLESS_PACKET);
_tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_CUSTOM_PACKET);
_tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_CUSTOM_PRIVATE_PACKET);
}
bool ToxicGames::onToxEvent(const Tox_Event_Friend_Lossless_Packet* e) {
//CUSTOM_PACKET_GAME_INVITE = 160,
//CUSTOM_PACKET_GAME_DATA = 161,
return false;
}
bool ToxicGames::onToxEvent(const Tox_Event_Group_Custom_Packet* e) {
return false;
}
bool ToxicGames::onToxEvent(const Tox_Event_Group_Custom_Private_Packet* e) {
return false;
}

View File

@ -0,0 +1,25 @@
#pragma once
#include <solanaceae/contact/contact_model3.hpp>
#include <solanaceae/tox_contacts/tox_contact_model2.hpp>
class ToxicGames : public ToxEventI {
Contact3Registry& _cr;
ToxI& _t;
ToxEventProviderI& _tep;
ToxContactModel2& _tcm;
public:
ToxicGames(
Contact3Registry& cr,
ToxI& t,
ToxEventProviderI& tep,
ToxContactModel2& tcm
);
private: // tox events
bool onToxEvent(const Tox_Event_Friend_Lossless_Packet* e) override;
bool onToxEvent(const Tox_Event_Group_Custom_Packet* e) override;
bool onToxEvent(const Tox_Event_Group_Custom_Private_Packet* e) override;
};