compiling and running, just need to fix front end and logo bug

This commit is contained in:
DevL0rd 2022-03-04 21:49:25 +07:00
parent c25452aa7d
commit fac3f69160
9 changed files with 167 additions and 112 deletions

56
.vscode/settings.json vendored
View file

@ -16,6 +16,58 @@
"xutility": "c",
"string_view": "c",
"type_traits": "c",
"thread.h": "c"
}
"thread.h": "c",
"renderer.h": "c",
"switch.h": "c",
"xmemory0": "c"
},
"Lua.diagnostics.disable": [
"lowercase-global",
"undefined-doc-name"
],
"Lua.diagnostics.globals": [
"__simulator",
"print",
"simulator"
],
"Lua.runtime.version": "Lua 5.3",
"Lua.runtime.builtin": {
"coroutine": "enable",
"bit32": "enable",
"bit": "enable",
"builtin": "enable",
"utf8": "enable",
"package": "enable",
"os": "enable",
"jit": "enable",
"io": "enable",
"ffi": "enable",
"debug": "enable",
"basic": "enable"
},
"Lua.workspace.ignoreDir": [
".vscode",
"/out/",
"/_build/",
"/_examples_and_tutorials/"
],
"lua.debug.settings.cpath": [
"c:/Users/dmhzm/.vscode/extensions/nameouschangey.lifeboatapi-0.0.13//assets/luasocket/dll/socket/core.dll",
"c:/Users/dmhzm/.vscode/extensions/nameouschangey.lifeboatapi-0.0.13//assets/luasocket/dll/mime/core.dll"
],
"lua.debug.settings.path": [
"c:/Users/dmhzm/.vscode/extensions/nameouschangey.lifeboatapi-0.0.13//assets/luasocket/?.lua",
"c:/Users/dmhzm/.vscode/extensions/nameouschangey.lifeboatapi-0.0.13//assets/LifeBoatAPI/Microcontroller/?.lua",
"c:/Users/dmhzm/.vscode/extensions/nameouschangey.lifeboatapi-0.0.13//assets/LifeBoatAPI/Tools/?.lua"
],
"Lua.workspace.library": [
"c:/Users/dmhzm/.vscode/extensions/nameouschangey.lifeboatapi-0.0.13//assets/LifeBoatAPI/Microcontroller/",
"c:/Users/dmhzm/.vscode/extensions/nameouschangey.lifeboatapi-0.0.13//assets/LifeBoatAPI/Tools/"
],
"lua.debug.settings.luaVersion": "5.3",
"lua.debug.settings.luaArch": "x86",
"Lua.IntelliSense.traceBeSetted": true,
"Lua.IntelliSense.traceFieldInject": true,
"Lua.IntelliSense.traceLocalSet": true,
"Lua.IntelliSense.traceReturn": true
}

View file

@ -1,26 +0,0 @@
{
"Lua.diagnostics.disable": [
"lowercase-global",
"undefined-doc-name"
],
"Lua.diagnostics.globals": [
"__simulator",
"print",
"simulator"
],
"Lua.runtime.version": "Lua 5.3",
"Lua.runtime.builtin": {
"coroutine": "enable",
"bit32": "enable",
"bit": "enable",
"builtin": "enable",
"utf8": "enable",
"package": "enable",
"os": "enable",
"jit": "enable",
"io": "enable",
"ffi": "enable",
"debug": "enable",
"basic": "enable"
}
}

View file

@ -6,22 +6,21 @@
#include "renderer.h"
PadState pad;
HiddbgAbstractedPadHandle pads[4]={0};
HiddbgAbstractedPadState states[4]={0};
HiddbgAbstractedPadHandle pads[4] = {0};
HiddbgAbstractedPadState states[4] = {0};
HidSixAxisSensorHandle handles[4];
s32 tmpout=0;
Result rc=0;
s32 tmpout = 0;
Result rc = 0;
void gamePadSend(JoyConSocket *connection)
{
JoyPkg pkg;
pkg.streamStart = (uint64_t)UINT64_MAX; //easy identifiers for the start and stop of tcp stream
pkg.streamStart = (uint64_t)UINT64_MAX; // easy identifiers for the start and stop of tcp stream
pkg.streamEnd = (uint64_t)UINT64_MAX / 2;
pkg.controllerCount = (uint32_t)1;
tmpout = 0;
rc = hiddbgGetAbstractedPadsState(pads, states, sizeof(pads)/sizeof(u64), &tmpout);
rc = hiddbgGetAbstractedPadsState(pads, states, sizeof(pads) / sizeof(u64), &tmpout);
// if (tmpout>=1) {
// s8 AbstractedVirtualPadId=0;
@ -40,8 +39,6 @@ void gamePadSend(JoyConSocket *connection)
// printf("hiddbgSetAutoPilotVirtualPadState(): 0x%x\n", rc);
// }
pkg.heldKeys1 = (uint32_t)states[0].state.buttons;
pkg.lJoyX1 = (int32_t)states[0].state.analog_stick_l.x;
pkg.lJoyY1 = (int32_t)states[0].state.analog_stick_l.y;
@ -66,8 +63,9 @@ void gamePadSend(JoyConSocket *connection)
pkg.rJoyX4 = (int32_t)states[3].state.analog_stick_r.x;
pkg.rJoyY4 = (int32_t)states[3].state.analog_stick_r.y;
HidTouchScreenState touchState={0};
if (hidGetTouchScreenStates(&touchState, 1)) {
HidTouchScreenState touchState = {0};
if (hidGetTouchScreenStates(&touchState, 1))
{
pkg.touchX1 = (uint32_t)touchState.touches[0].x;
pkg.touchY1 = (uint32_t)touchState.touches[0].y;
pkg.touchX2 = (uint32_t)touchState.touches[1].x;
@ -80,7 +78,8 @@ void gamePadSend(JoyConSocket *connection)
hidGetSixAxisSensorStates(handles[0], &sixaxis, 1);
else if (style_set & HidNpadStyleTag_NpadFullKey)
hidGetSixAxisSensorStates(handles[1], &sixaxis, 1);
else if (style_set & HidNpadStyleTag_NpadJoyDual) {
else if (style_set & HidNpadStyleTag_NpadJoyDual)
{
// For JoyDual, read from either the Left or Right Joy-Con depending on which is/are connected
u64 attrib = padGetAttributes(&pad);
if (attrib & HidNpadAttribute_IsLeftConnected)
@ -102,9 +101,9 @@ void handleInput(JoyConSocket *connection)
if (connectJoyConSocket(connection, 2223))
gamePadSend(connection);
}
void inputHandlerLoop(void *dummy)
void input_init()
{
JoyConSocket *connection = createJoyConSocket();
padConfigureInput(4, HidNpadStyleSet_NpadStandard);
padInitializeAny(&pad);
rc = hiddbgInitialize();
@ -112,22 +111,30 @@ void inputHandlerLoop(void *dummy)
// It's necessary to initialize these separately as they all have different handle values
HidSixAxisSensorHandle handles[4];
hidGetSixAxisSensorHandles(&handles[0], 1, HidNpadIdType_Handheld, HidNpadStyleTag_NpadHandheld);
hidGetSixAxisSensorHandles(&handles[1], 1, HidNpadIdType_No1, HidNpadStyleTag_NpadFullKey);
hidGetSixAxisSensorHandles(&handles[2], 2, HidNpadIdType_No1, HidNpadStyleTag_NpadJoyDual);
hidGetSixAxisSensorHandles(&handles[1], 1, HidNpadIdType_No1, HidNpadStyleTag_NpadFullKey);
hidGetSixAxisSensorHandles(&handles[2], 2, HidNpadIdType_No1, HidNpadStyleTag_NpadJoyDual);
hidStartSixAxisSensor(handles[0]);
hidStartSixAxisSensor(handles[1]);
hidStartSixAxisSensor(handles[2]);
hidStartSixAxisSensor(handles[3]);
while (appletMainLoop())
{
handleInput(connection);
svcSleepThread(23333333ULL);
}
freeJoyConSocket(connection);
}
void input_unInit()
{
hiddbgUnsetAllAutoPilotVirtualPadState();
hiddbgExit();
hidStopSixAxisSensor(handles[0]);
hidStopSixAxisSensor(handles[1]);
hidStopSixAxisSensor(handles[2]);
hidStopSixAxisSensor(handles[3]);
}
void inputHandlerLoop(void *dummy)
{
JoyConSocket *connection = createJoyConSocket();
while (appletMainLoop())
{
handleInput(connection);
svcSleepThread(23333333ULL);
}
freeJoyConSocket(connection);
}

View file

@ -2,6 +2,7 @@
#define INPUT_H
/* Loop to handle joycon inputs and send theme to the server */
void inputHandlerLoop(void* dummy);
void inputHandlerLoop(void *dummy);
void input_init();
void input_unInit();
#endif

View file

@ -1,37 +1,3 @@
// The following ffmpeg code is inspired by an official ffmpeg example, so here is its Copyright notice:
/*
* Copyright (c) 2012 Stefano Sabatini
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @file
* Demuxing and decoding example.
*
* Show how to use the libavformat and libavcodec API to demux and
* decode audio and video data.
* @example demuxing_decoding.c
*/
#include <libavutil/samplefmt.h>
#include <switch.h>
@ -57,12 +23,12 @@ static const SocketInitConfig socketInitConf = {
.sb_efficiency = 2,
};
static Thread renderThread;
static Thread inputHandlerThread;
static Thread audioHandlerThread;
void startInput()
{
input_init();
threadCreate(&inputHandlerThread, inputHandlerLoop, NULL, NULL, 0x1000, 0x2b, 0);
threadStart(&inputHandlerThread);
}
@ -85,41 +51,59 @@ VideoContext *videoContext = NULL;
ClkrstSession cpuSession;
void init()
{
// consoleInit(NULL);
/* Init all switch required systems */
printf("romfsInit\n");
romfsInit();
networkInit(&socketInitConf);
printf("networkInit\n");
network_init(&socketInitConf);
printf("audoutInitialize\n");
audoutInitialize();
printf("audoutStartAudioOut\n");
audoutStartAudioOut();
padConfigureInput(8, HidNpadStyleSet_NpadStandard);
printf("clkrstInitialize\n");
clkrstInitialize();
clkrstOpenSession(&cpuSession, PcvModuleId_CpuBus, 3);
clkrstSetClockRate(&cpuSession, 1785000000);
renderContext = createRenderer();
printf("startAudio\n");
startAudio();
printf("startInput\n");
startInput();
printf("makeRenderer\n");
renderContext = makeRenderer();
printf("createVideoContext\n");
videoContext = createVideoContext();
videoContext->renderContext = renderContext;
startAudio();
startInput();
printf("startRender\n");
startRender(videoContext);
appletSetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension_ExtendedUnsafe);
printf("appletSetIdleTimeDetectionExtension\n");
appletSetIdleTimeDetectionExtension(AppletIdleTimeDetectionExtension_None);
printf("Complete INIT!\n");
}
void unInit()
{
freeRenderer(renderContext);
freeVideoContext(videoContext);
clkrstCloseSession(&cpuSession); //end OC
clkrstCloseSession(&cpuSession); // end OC
clkrstExit();
input_unInit();
audoutStopAudioOut();
audoutExit();
networkDestroy();
network_unInit();
plExit();
}
bool threadsSleeping = false;
int main(int argc, char **argv)
{
init();
static Thread renderThread;
static Thread inputHandlerThread;
static Thread audioHandlerThread;
while (appletMainLoop())
{
if (appletGetFocusState() == AppletFocusState_InFocus)
@ -139,10 +123,11 @@ int main(int argc, char **argv)
{
drawSplash(renderContext);
}
svcSleepThread(14285714ULL); //Nano sleep to keep at 70fps to handle drop frames without stutter
svcSleepThread(14285714ULL); // Nano sleep to keep at 70fps to handle drop frames without stutter
}
else
{
printf("sleeping\n");
if (!threadsSleeping)
{
threadPause(&renderThread);
@ -155,4 +140,5 @@ int main(int argc, char **argv)
}
/* Deinitialize all used systems */
unInit();
return 0;
}

View file

@ -9,14 +9,18 @@
#include <errno.h>
#include <arpa/inet.h>
void networkInit(const SocketInitConfig *conf)
void network_init(const SocketInitConfig *conf)
{
printf("socketInitialize\n");
socketInitialize(conf);
nxlinkStdio();
printf("avformat_network_init\n");
avformat_network_init();
}
void networkDestroy()
void network_unInit()
{
avformat_network_deinit();
socketExit();

View file

@ -46,10 +46,10 @@ typedef struct
} JoyPkg;
/* Init nx network and av network */
void networkInit(const SocketInitConfig *conf);
void network_init(const SocketInitConfig *conf);
/* Deinitialize nx network and av network*/
void networkDestroy();
void network_unInit();
/* Creates the context for sending joycon inputs */
JoyConSocket *createJoyConSocket();
@ -60,7 +60,7 @@ void freeJoyConSocket(JoyConSocket *connection);
/* Send joycon input over the network */
void sendJoyConInput(JoyConSocket *connection, const JoyPkg *pkg);
/*
/*
* Binds, listens and accepts connection with the server
* If the connection was previously opened reuses it
*/

View file

@ -196,10 +196,16 @@ void initBubbles()
}
}
SDL_Texture *logoTexture = NULL;
RenderContext *createRenderer()
RenderContext *makeRenderer()
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
SDL_Log("TTF_Init");
TTF_Init();
SDL_Log("plInitialize");
plInitialize(PlServiceType_User);
SDL_Log("malloc RenderContext\n");
RenderContext *context = malloc(sizeof(RenderContext));
SDL_Log("SDL_CreateWindow\n");
context->window = SDL_CreateWindow("sdl2_gles2", 0, 0, RESX, RESY, SDL_WINDOW_FULLSCREEN);
if (context->window == NULL)
{
@ -209,6 +215,7 @@ RenderContext *createRenderer()
;
}
SDL_Log("SDL_CreateRenderer\n");
context->renderer = SDL_CreateRenderer(context->window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (context->renderer == NULL)
{
@ -217,11 +224,20 @@ RenderContext *createRenderer()
while (1)
;
}
SDL_Log("SDL_SetRenderDrawBlendMode");
SDL_SetRenderDrawBlendMode(context->renderer, SDL_BLENDMODE_BLEND); // enable transparency
SDL_Log("IMG_LoadTexture ICON");
IMG_Init(IMG_INIT_PNG);
logoTexture = IMG_LoadTexture(context->renderer, "iconTransparent.png");
// SDL_Surface *logo = IMG_Load("iconTransparent.png");
// if (logo)
// {
// logoTexture = SDL_CreateTextureFromSurface(context->renderer, logo);
// SDL_FreeSurface(logo);
// }
// Create font cache
SDL_Log("SDL_CreateTexture");
context->yuv_text = SDL_CreateTexture(context->renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, RESX, RESY);
context->rect.x = 0;
@ -229,18 +245,27 @@ RenderContext *createRenderer()
context->rect.w = RESX;
context->rect.h = RESY;
SDL_Log("mutexInit texture_mut");
mutexInit(&context->texture_mut);
SDL_Log("mutexInit frame_avail_mut");
mutexInit(&context->frame_avail_mut);
SDL_Log("mutexInit video_active_mut");
mutexInit(&context->video_active_mut);
context->frame_avail = false;
context->video_active = false;
PlFontData fontData, fontExtData;
SDL_Log("plGetSharedFontByType");
plGetSharedFontByType(&fontData, PlSharedFontType_Standard);
plGetSharedFontByType(&fontExtData, PlSharedFontType_NintendoExt);
SDL_Log((char *)fontData.address);
SDL_Log("FC_CreateFont");
context->font = FC_CreateFont();
SDL_Log("FC_LoadFont_RW");
FC_LoadFont_RW(context->font, context->renderer, SDL_RWFromMem((void *)fontData.address, fontData.size), SDL_RWFromMem((void *)fontExtData.address, fontExtData.size), 1, 40, FC_MakeColor(0, 0, 0, 255), TTF_STYLE_NORMAL);
SDL_Log("initDelta");
initDelta();
SDL_Log("initBubbles");
initBubbles();
return context;
@ -452,15 +477,17 @@ void drawSplash(RenderContext *context)
drawGradient(context, 0, 0, 1280, 180, gf, gt, 1);
drawGradient(context, 0, 720 - 100, 1280, 180, gf, gt, 2);
int imgW = 0;
int imgH = 0;
SDL_QueryTexture(logoTexture, NULL, NULL, &imgW, &imgH);
int imgW = 256;
int imgH = 256;
// printf("SDL_QueryTexture\n");
// SDL_QueryTexture(logoTexture, NULL, NULL, &imgW, &imgH);
SDL_Rect imgDest;
imgDest.x = (1280 / 2) - (imgW / 2);
imgDest.y = (720 / 2) - (imgH / 2);
imgDest.w = imgW;
imgDest.h = imgH;
SDL_RenderCopy(context->renderer, logoTexture, NULL, &imgDest);
// printf("SDL_RenderCopy\n");
// SDL_RenderCopy(context->renderer, logoTexture, NULL, &imgDest);
SDL_Color white = {230, 230, 230, 255};
u32 ip = gethostid();
@ -506,4 +533,8 @@ void displayFrame(RenderContext *renderContext)
void freeRenderer(RenderContext *context)
{
free(context);
plExit();
IMG_Quit();
TTF_Quit();
SDL_Quit();
}

View file

@ -6,7 +6,7 @@
#include "context.h"
/* Allocates a render context */
RenderContext *createRenderer(void);
RenderContext *makeRenderer(void);
/* Draws an image filling all screen */
void drawSplash(RenderContext *context);