From 36567400f60df6aa3b1b270f6a6ad946558f58c9 Mon Sep 17 00:00:00 2001 From: ohayoyogi <77435669+ohayoyogi@users.noreply.github.com> Date: Fri, 17 Feb 2023 20:56:32 +0900 Subject: [PATCH 1/2] Windows support --- src/sdl2/CMakeLists.txt | 23 ++++++++++++++++++++ src/sdl2/anbu.cpp | 48 +++++++++++++++++++++++++++++++++++------ 2 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 src/sdl2/CMakeLists.txt diff --git a/src/sdl2/CMakeLists.txt b/src/sdl2/CMakeLists.txt new file mode 100644 index 00000000..9df89a69 --- /dev/null +++ b/src/sdl2/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.1) + +project(sdl_interface CXX) + +find_package(SDL2 REQUIRED CONFIG REQUIRED COMPONENTS SDL2) +find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) + +include_directories(${SDL2_INCLUDE_DIRS}) + +find_path(FreeImage_INCLUDE_DIR FreeImage.h HINTS ${FREEIMAGE_DIR}) +find_library(FreeImage_LIBRARY NAMES FreeImage HINTS ${FREEIMAGE_DIR}) + +include_directories(${FreeImage_INCLUDE_DIR}) + +add_executable(sdl_interface anbu.cpp) + +target_link_libraries(sdl_interface ${SDL2_LIBRARIES}) +target_link_libraries(sdl_interface ${FreeImage_LIBRARY}) + +install( + TARGETS sdl_interface + RUNTIME DESTINATION bin +) diff --git a/src/sdl2/anbu.cpp b/src/sdl2/anbu.cpp index f68cebc6..5f4ddae5 100644 --- a/src/sdl2/anbu.cpp +++ b/src/sdl2/anbu.cpp @@ -29,7 +29,13 @@ along with FreeJ2ME. If not, see http://www.gnu.org/licenses/ #include #include +#ifdef _WIN32 +#include +#include +#else #include +#endif + #include #include @@ -38,7 +44,13 @@ along with FreeJ2ME. If not, see http://www.gnu.org/licenses/ using namespace std; +#ifdef _WIN32 +DWORD t_capturing; +#else pthread_t t_capturing; +#endif + +string bg_image = ""; int angle = 0; int source_width = 0, source_height = 0; @@ -276,8 +288,13 @@ void init(Uint8 r = 0, Uint8 g = 0, Uint8 b = 0) SDL_RenderSetLogicalSize(mRenderer, display_width, display_height); } -void startStreaming(string bg_image) +#ifdef _WIN32 +DWORD WINAPI startStreaming(LPVOID lpParam) +{ +#else +void *startStreaming(void *args) { +#endif SDL_Rect dest = getDestinationRect(); loadBackground(bg_image); @@ -295,9 +312,15 @@ void startStreaming(string bg_image) SDL_DestroyTexture(mTexture); delete[] frame; + +#ifdef _WIN32 + return 0; +#else + pthread_exit(NULL); +#endif } -void *startCapturing(void *args) +void startCapturing() { int key; SDL_JoystickEventState(SDL_ENABLE); @@ -364,14 +387,12 @@ void *startCapturing(void *args) fflush(stdout); } } - pthread_exit(NULL); } /*********************************************************************** Main */ int main(int argc, char* argv[]) { int c = 0; - string bg_image = ""; Uint8 r = 44, g = 62, b = 80; // Midnight Blue while (++c < argc) @@ -399,15 +420,30 @@ int main(int argc, char* argv[]) init(r, g, b); bool initialCursorState = SDL_ShowCursor(0) == 1; - if (pthread_create(&t_capturing, 0, &startCapturing, NULL)) + +#ifdef _WIN32 + HANDLE hThreadCapturing; + if ((hThreadCapturing = CreateThread(NULL, 0, &startStreaming, NULL, 0, &t_capturing)) == NULL) { + std::cerr << "Unable to start thread, exiting ..." << endl; + SDL_Quit(); + return 1; + } +#else + if (pthread_create(&t_capturing, 0, &startStreaming, NULL)) { std::cerr << "Unable to start thread, exiting ..." << endl; SDL_Quit(); return 1; } +#endif - startStreaming(bg_image); + startCapturing(); +#ifdef _WIN32 + WaitForSingleObject(hThreadCapturing, INFINITE); + CloseHandle(hThreadCapturing); +#else pthread_join(t_capturing, NULL); +#endif SDL_ShowCursor(initialCursorState); SDL_Quit(); return 0; From da61448bf52fc15f4ec3eff4ae53b068bef3feea Mon Sep 17 00:00:00 2001 From: ohayoyogi <77435669+ohayoyogi@users.noreply.github.com> Date: Fri, 17 Feb 2023 20:57:04 +0900 Subject: [PATCH 2/2] support SDL Windows --- src/org/recompile/freej2me/Anbu.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/org/recompile/freej2me/Anbu.java b/src/org/recompile/freej2me/Anbu.java index 60c5439c..ad97ec33 100644 --- a/src/org/recompile/freej2me/Anbu.java +++ b/src/org/recompile/freej2me/Anbu.java @@ -137,7 +137,13 @@ public void start(String args[]) { try { - args[0] = "/usr/local/bin/sdl_interface"; + if (File.separatorChar == '\\') { + // for windows + args[0] = System.getenv("USERPROFILE") + "\\freej2me\\bin\\sdl_interface.exe"; + } else { + args[0] = "/usr/local/bin/sdl_interface"; + } + proc = new ProcessBuilder(args).start(); keys = proc.getInputStream();