This commit is contained in:
rock88 2020-05-02 02:00:30 +03:00
parent 4022497798
commit 048fca0705
8 changed files with 267 additions and 51 deletions

View file

@ -44,12 +44,13 @@ else ifneq (,$(findstring osx,$(platform)))
GL_LIB := -framework OpenGL
CFLAGS += -DOSX
INCLUDES += -I/usr/local/include -I/usr/local/opt/openssl@1.1/include
LIBS += -L/usr/local/lib -L/usr/local/opt/openssl@1.1/lib
ifeq ($(arch),ppc)
CFLAGS += -D__ppc__ -DOSX_PPC
endif
OSXVER = `sw_vers -productVersion | cut -d. -f 2`
OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"`
fpic += -mmacosx-version-min=10.1
fpic += -mmacosx-version-min=10.12
else ifeq ($(platform), pi)
TARGET := $(TARGET_NAME)_libretro.so
fpic := -fPIC
@ -66,8 +67,8 @@ ifeq ($(IOSSDK),)
IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
endif
GL_LIB := -framework OpenGLES
DEFINES := -DIOS
CFLAGS += -DHAVE_OPENGLES $(DEFINES)
DEFINES += -DIOS
CFLAGS += -DHAVE_OPENGLES
CC = cc -arch armv7 -isysroot $(IOSSDK)
ifeq ($(platform),ios9)
CC += -miphoneos-version-min=8.0
@ -150,38 +151,25 @@ else
CFLAGS += -std=gnu99
endif
INCLUDES += \
-Isrc \
-Isrc/nanogui_resources \
-Isrc/ui \
-Ilibgamestream \
-Ithird_party/moonlight-common-c/reedsolomon \
-Ithird_party/moonlight-common-c/src \
-Ithird_party/moonlight-common-c/enet/include \
-Ithird_party/nanogui/include \
-Ithird_party/nanogui/ext/nanovg/src
LIBS += \
-lcrypto -lssl -lcurl -lz -lexpat \
-lavcodec -lavformat -lavutil -lavdevice
LIBGAMESTREAM_SOURCES = \
libgamestream/client.c \
libgamestream/http.c \
libgamestream/mkcert.c \
libgamestream/xml.c
MOONLIGHT_LIBRETRO_SOURCES = \
MOONLIGHT_LIBRETRO_C_SOURCES = \
src/glsym/rglgen.c \
src/nanogui_resources/nanogui_resources.c \
src/moonlight_libretro.c \
src/moonlight_libretro.c
MOONLIGHT_LIBRETRO_CXX_SOURCES = \
src/ui/AddHostWindow.cpp \
src/ui/Application.cpp \
src/ui/ContentWindow.cpp \
src/ui/LoadingOverlay.cpp \
src/ui/MainWindow.cpp \
src/moonlight_libretro.c \
src/Server.cpp
src/Server.cpp \
src/moonlight_libretro_wrapper.cpp
MOONLIGHT_COMMON_C_SOURCES = \
third_party/moonlight-common-c/enet/callbacks.c \
@ -213,11 +201,65 @@ MOONLIGHT_COMMON_C_SOURCES = \
third_party/moonlight-common-c/src/VideoDepacketizer.c \
third_party/moonlight-common-c/src/VideoStream.c
C_SOURCES = $(MOONLIGHT_COMMON_C_SOURCES) $(H264BITSTREAM_SOURCES) $(MOONLIGHT_LIBRETRO_SOURCES)
NANOGUI_C_SOURCES = \
third_party/nanogui/ext/nanovg/src/nanovg.c
OBJECTS := $(C_SOURCES:.c=.o)
CFLAGS += -Wall -pedantic $(fpic) -std=gnu11 -DNANOGUI_USE_OPENGL -DNVG_STB_IMAGE_IMPLEMENTATION -DNANOGUI_NO_GLFW
CXXFLAGS += $(CFLAGS) -std=gnu++17
NANOGUI_CXX_SOURCES = \
third_party/nanogui/src/widget.cpp \
third_party/nanogui/src/button.cpp \
third_party/nanogui/src/common.cpp \
third_party/nanogui/src/screen.cpp \
third_party/nanogui/src/checkbox.cpp \
third_party/nanogui/src/vscrollpanel.cpp \
third_party/nanogui/src/colorpicker.cpp \
third_party/nanogui/src/textarea.cpp \
third_party/nanogui/src/shader_gl.cpp \
third_party/nanogui/src/canvas.cpp \
third_party/nanogui/src/window.cpp \
third_party/nanogui/src/graph.cpp \
third_party/nanogui/src/popup.cpp \
third_party/nanogui/src/layout.cpp \
third_party/nanogui/src/texture.cpp \
third_party/nanogui/src/texture_gl.cpp \
third_party/nanogui/src/tabwidget.cpp \
third_party/nanogui/src/shader.cpp \
third_party/nanogui/src/imageview.cpp \
third_party/nanogui/src/progressbar.cpp \
third_party/nanogui/src/combobox.cpp \
third_party/nanogui/src/theme.cpp \
third_party/nanogui/src/traits.cpp \
third_party/nanogui/src/label.cpp \
third_party/nanogui/src/opengl.cpp \
third_party/nanogui/src/renderpass_gl.cpp \
third_party/nanogui/src/imagepanel.cpp \
third_party/nanogui/src/colorwheel.cpp \
third_party/nanogui/src/messagedialog.cpp \
third_party/nanogui/src/textbox.cpp \
third_party/nanogui/src/slider.cpp \
third_party/nanogui/src/popupbutton.cpp
INCLUDES += \
-Isrc \
-Isrc/nanogui_resources \
-Isrc/ui \
-Ilibgamestream \
-Ithird_party/moonlight-common-c/reedsolomon \
-Ithird_party/moonlight-common-c/src \
-Ithird_party/moonlight-common-c/enet/include \
-Ithird_party/nanogui/include \
-Ithird_party/nanogui/ext/nanovg/src
C_SOURCES = $(LIBGAMESTREAM_SOURCES) $(MOONLIGHT_LIBRETRO_C_SOURCES) $(MOONLIGHT_COMMON_C_SOURCES) $(NANOGUI_C_SOURCES)
CXX_SOURCES = $(MOONLIGHT_LIBRETRO_CXX_SOURCES) $(NANOGUI_CXX_SOURCES)
OBJECTS := $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o)
DEFINES += -DNANOGUI_USE_OPENGL -DNVG_STB_IMAGE_IMPLEMENTATION -DNANOGUI_NO_GLFW
CFLAGS += -Wall -pedantic $(fpic) -std=gnu11 $(DEFINES)
CXXFLAGS += -std=gnu++17 -stdlib=libc++ $(DEFINES)
LIBS += \
-lcrypto -lssl -lcurl -lz -lexpat \
-lavcodec -lavformat -lavutil -lavdevice -lstdc++
ifeq ($(GLES), 1)
CFLAGS += -DHAVE_OPENGLES -DHAVE_OPENGLES2
@ -246,7 +288,7 @@ $(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) $(fpic) $(INCLUDES) -c -o $@ $<
%.o: %.cpp
gcc $(CXXFLAGS) $(fpic) $(INCLUDES) -c -o $@ $<
$(CXX) $(CXXFLAGS) $(fpic) $(INCLUDES) -c -o $@ $<
clean:
rm -f $(OBJECTS) $(TARGET)

View file

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
361F8A3A245CB44E00A8D9C0 /* moonlight_libretro_wrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 361F8A38245CB44E00A8D9C0 /* moonlight_libretro_wrapper.cpp */; };
3652EFCD245B3B00001FABF3 /* widget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF0F245B3B00001FABF3 /* widget.cpp */; };
3652EFCE245B3B00001FABF3 /* common.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF10245B3B00001FABF3 /* common.cpp */; };
3652EFCF245B3B00001FABF3 /* checkbox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF11245B3B00001FABF3 /* checkbox.cpp */; };
@ -22,7 +23,6 @@
3652EFD9245B3B00001FABF3 /* popup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF1B245B3B00001FABF3 /* popup.cpp */; };
3652EFDA245B3B00001FABF3 /* layout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF1C245B3B00001FABF3 /* layout.cpp */; };
3652EFDB245B3B00001FABF3 /* texture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF1D245B3B00001FABF3 /* texture.cpp */; };
3652EFDC245B3B00001FABF3 /* darwin.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF1E245B3B00001FABF3 /* darwin.mm */; };
3652EFDD245B3B00001FABF3 /* texture_gl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF1F245B3B00001FABF3 /* texture_gl.cpp */; };
3652EFDE245B3B00001FABF3 /* tabwidget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF20245B3B00001FABF3 /* tabwidget.cpp */; };
3652EFDF245B3B00001FABF3 /* shader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3652EF21245B3B00001FABF3 /* shader.cpp */; };
@ -104,6 +104,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
361F8A38245CB44E00A8D9C0 /* moonlight_libretro_wrapper.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = moonlight_libretro_wrapper.cpp; sourceTree = "<group>"; };
361F8A39245CB44E00A8D9C0 /* moonlight_libretro_wrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = moonlight_libretro_wrapper.h; sourceTree = "<group>"; };
3652ECE8245B3AFF001FABF3 /* colorpicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = colorpicker.h; sourceTree = "<group>"; };
3652ECE9245B3AFF001FABF3 /* renderpass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = renderpass.h; sourceTree = "<group>"; };
3652ECEA245B3AFF001FABF3 /* theme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = theme.h; sourceTree = "<group>"; };
@ -550,6 +552,8 @@
3652F004245C28C6001FABF3 /* Server.hpp */,
3652F084245C6CFC001FABF3 /* libretro.h */,
3652F085245C6CFC001FABF3 /* moonlight_libretro.c */,
361F8A39245CB44E00A8D9C0 /* moonlight_libretro_wrapper.h */,
361F8A38245CB44E00A8D9C0 /* moonlight_libretro_wrapper.cpp */,
);
path = src;
sourceTree = "<group>";
@ -697,6 +701,7 @@
3652F075245C292B001FABF3 /* VideoStream.c in Sources */,
3652EFE0245B3B00001FABF3 /* imageview.cpp in Sources */,
3652EFDB245B3B00001FABF3 /* texture.cpp in Sources */,
361F8A3A245CB44E00A8D9C0 /* moonlight_libretro_wrapper.cpp in Sources */,
3652F079245C292B001FABF3 /* RtpReorderQueue.c in Sources */,
3652F065245C292B001FABF3 /* list.c in Sources */,
36DFE0CD2459FA3F00FC51CE /* nanogui_resources.cpp in Sources */,
@ -737,7 +742,6 @@
3652EFD4245B3B00001FABF3 /* shader_gl.cpp in Sources */,
3652EFE7245B3B00001FABF3 /* label.cpp in Sources */,
3652EFDA245B3B00001FABF3 /* layout.cpp in Sources */,
3652EFDC245B3B00001FABF3 /* darwin.mm in Sources */,
3652F080245C292B001FABF3 /* ByteBuffer.c in Sources */,
3652EFF3245B3B00001FABF3 /* slider.cpp in Sources */,
3652EFCE245B3B00001FABF3 /* common.cpp in Sources */,

View file

@ -43,8 +43,11 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<PathRunnable
runnableDebuggingMode = "0"
FilePath = "/Applications/RetroArch.app">
</PathRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "36DBDE8D2450BB7E0057C8D3"
@ -52,10 +55,10 @@
BlueprintName = "moonlight"
ReferencedContainer = "container:moonlight.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</MacroExpansion>
<CommandLineArguments>
<CommandLineArgument
argument = "-L /Users/rock88/Documents/Projects/RetroArch/moonlight_libretro/moonlight_libretro.dylib"
argument = "-L /Users/rock88/Documents/Projects/RetroArch/moonlight-libretro/moonlight_libretro.dylib"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>

View file

@ -6,6 +6,7 @@
#include "glsym/glsym.h"
#include "libretro.h"
#include "moonlight_libretro_wrapper.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
static struct retro_hw_render_callback hw_render;
@ -32,9 +33,16 @@ static struct retro_hw_render_callback hw_render;
static unsigned width = BASE_WIDTH;
static unsigned height = BASE_HEIGHT;
static retro_video_refresh_t video_cb;
static retro_audio_sample_t audio_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
static retro_log_printf_t log_cb;
void retro_init(void) {
//OpenSSL_add_all_algorithms();
//curl_global_init(CURL_GLOBAL_ALL);
//moonlight_libretro_wrapper_init();
}
void retro_deinit(void){
@ -73,18 +81,19 @@ void retro_get_system_av_info(struct retro_system_av_info *info) {
};
}
static retro_video_refresh_t video_cb;
static retro_audio_sample_t audio_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
void retro_set_environment(retro_environment_t cb) {
environ_cb = cb;
bool no_game = true;
cb(RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME, &no_game);
const char *dir = NULL;
cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir);
moonlight_libretro_wrapper_set_working_dir(dir);
static struct retro_log_callback logging;
if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
log_cb = logging.log;
}
void retro_set_audio_sample(retro_audio_sample_t cb) {
@ -108,23 +117,69 @@ void retro_set_video_refresh(retro_video_refresh_t cb) {
}
static void update_variables(void) {
bool updated = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) {
}
}
static unsigned frame_count;
double last_mouse_x = 0, last_mouse_y = 0;
void retro_run(void) {
bool updated = false;
moonlight_libretro_wrapper_init(width, height);
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) {
update_variables();
// Handle inputs
input_poll_cb();
double mouse_x = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X);
double mouse_y = input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y);
// if (mouse_x == 0 && mouse_y == 0) {
// int pointer_x = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X);
// int pointer_y = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y);
//
// if (pointer_x != 0 && pointer_y != 0) {
// mouse_x = (pointer_x / 32768.0f + 1) / 2 * width;
// mouse_y = (pointer_y / 32768.0f + 1) / 2 * height;
// }
// }
if (input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED)) {
int p_x = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X);
int p_y = input_state_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y);
//int px=(int)((float)retro.width/854.0*(float)p_x);
//int py=(int)((float)retro.height/480.0*(float)p_y);
mouse_x=(int)((p_x+0x7fff)*width/0xffff);
mouse_y=(int)((p_y+0x7fff)*height/0xffff);
}
input_poll_cb();
if (mouse_x != 0 && mouse_y != 0) {
moonlight_libretro_wrapper_handle_mouse_move(mouse_x, mouse_y);
}
last_mouse_x = mouse_x;
last_mouse_y = mouse_y;
static bool mouse_l_pressed = false;
if (input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT) && !mouse_l_pressed) {
mouse_l_pressed = true;
moonlight_libretro_wrapper_handle_mouse_button(0, 1, 0);
} else if (!input_state_cb(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT) && mouse_l_pressed) {
mouse_l_pressed = false;
moonlight_libretro_wrapper_handle_mouse_button(0, 0, 0);
}
// Draw
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, hw_render.get_current_framebuffer());
glViewport(0, 0, width, height);
moonlight_libretro_wrapper_draw();
video_cb(RETRO_HW_FRAME_BUFFER_VALID, width, height, 0);
}
@ -139,7 +194,7 @@ static void context_destroy(void) {
}
static bool retro_init_hw_context(void) {
#if 0
#if 1
hw_render.context_type = RETRO_HW_CONTEXT_OPENGL_CORE;
hw_render.version_major = 3;
hw_render.version_minor = 1;

View file

@ -0,0 +1,42 @@
#include "moonlight_libretro_wrapper.h"
#include "Application.hpp"
#include <openssl/ssl.h>
#include <curl/curl.h>
static bool moonlight_is_initialized = false;
static Application* app;
void moonlight_libretro_wrapper_init(int width, int height) {
if (moonlight_is_initialized) {
return;
}
moonlight_is_initialized = true;
OpenSSL_add_all_algorithms();
curl_global_init(CURL_GLOBAL_ALL);
nanogui::init();
app = new Application(Size(width, height), Size(width, height));
nanogui::setup(1.0 / 60.0);
}
void moonlight_libretro_wrapper_set_working_dir(char* dir) {
}
void moonlight_libretro_wrapper_handle_mouse_move(double x, double y) {
//printf("mouse_move: %fx%f\n", x, y);
nanogui::cursor_pos_callback_event(x, y);
}
void moonlight_libretro_wrapper_handle_mouse_button(int button, int action, int modifiers) {
//printf("mouse_button: %i x %i\n", button, action);
nanogui::mouse_button_callback_event(button, action, modifiers);
}
void moonlight_libretro_wrapper_draw() {
nanogui::draw();
}

View file

@ -0,0 +1,13 @@
#include <stdio.h>
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN
#endif
EXTERN void moonlight_libretro_wrapper_init(int width, int height);
EXTERN void moonlight_libretro_wrapper_set_working_dir(char* dir);
EXTERN void moonlight_libretro_wrapper_handle_mouse_move(double x, double y);
EXTERN void moonlight_libretro_wrapper_handle_mouse_button(int button, int action, int modifiers);
EXTERN void moonlight_libretro_wrapper_draw();

View file

@ -1,5 +1,6 @@
#include "AddHostWindow.hpp"
#include "Server.hpp"
#include "LoadingOverlay.hpp"
using namespace nanogui;
@ -47,12 +48,17 @@ AddHostWindow::AddHostWindow(Widget *parent): ContentWindow(parent, "Add Host")
auto connect = other_buttons_container->add<Button>("Connect");
connect->set_fixed_size(Size(100, 100));
connect->set_callback([text] {
connect->set_callback([text, this] {
if (text->value().size() > 0) {
Server::server().connect(text->value(), [](auto result) {
auto loader = add<LoadingOverlay>();
Server::server().connect(text->value(), [this, loader](auto result) {
loader->dispose();
if (result.isSuccess()) {
printf("Pair: %i\n", result.value()->paired);
} else {
screen()->add<MessageDialog>(MessageDialog::Type::Information, "Error", result.error());
printf("Error: %s\n", result.error().c_str());
}
});

View file

@ -1 +1,52 @@
#include "LoadingOverlay.hpp"
#include "nanovg.h"
using namespace nanogui;
LoadingOverlay::LoadingOverlay(Widget* parent): Widget(parent->screen()) {
set_fixed_size(parent->screen()->size());
m_icon = FA_SPINNER;
screen()->perform_layout();
}
void LoadingOverlay::draw(NVGcontext *ctx) {
nvgSave(ctx);
// Draw bg
nvgFillColor(ctx, Color(0, 0, 0, 100));
nvgBeginPath(ctx);
nvgRect(ctx, 0, 0, width(), height());
nvgFill(ctx);
// Draw spinner
static double r = 0;
r += 0.05;
nvgTranslate(ctx, width() / 2, height() / 2);
nvgRotate(ctx, r);
nvgFillColor(ctx, Color(255, 255, 255, 255));
nvgFontSize(ctx, 40);
nvgFontFace(ctx, "icons");
nvgTextAlign(ctx, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
nvgText(ctx, 0, 0, utf8(m_icon).data(), NULL);
nvgRestore(ctx);
}
bool LoadingOverlay::mouse_enter_event(const nanogui::Vector2i &p, bool enter) {
return true;
}
bool LoadingOverlay::mouse_button_event(const nanogui::Vector2i &p, int button, bool down, int modifiers) {
return true;
}
bool LoadingOverlay::scroll_event(const nanogui::Vector2i &p, const nanogui::Vector2f &rel) {
return true;
}
void LoadingOverlay::dispose() {
screen()->remove_child(this);
}