mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-19 13:29:54 +00:00
Starting replacing WIN32 specific code with crossplatform SDL!
This commit is contained in:
parent
2f14ad4715
commit
526330f3c8
5 changed files with 107 additions and 50 deletions
|
|
@ -46,6 +46,7 @@
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <SDL3/SDL_filesystem.h>
|
#include <SDL3/SDL_filesystem.h>
|
||||||
extern const char binding_mri_module_rpg1_rb[];
|
extern const char binding_mri_module_rpg1_rb[];
|
||||||
extern const int binding_mri_module_rpg1_rb_len;
|
extern const int binding_mri_module_rpg1_rb_len;
|
||||||
|
|
@ -421,7 +422,7 @@ static void runRMXPScripts(BacktraceData &btData){
|
||||||
rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str()));
|
rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute preloaded scripts */
|
//Execute preloaded scripts
|
||||||
for (std::set<std::string>::iterator i = preloadScripts.begin();
|
for (std::set<std::string>::iterator i = preloadScripts.begin();
|
||||||
i != preloadScripts.end(); ++i)
|
i != preloadScripts.end(); ++i)
|
||||||
runCustomScript(*i);
|
runCustomScript(*i);
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,12 @@ project(_______)
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
option(DEBUG "Debug mode" ON)
|
option(DEBUG "Debug mode" ON)
|
||||||
option(SANITIZERS "Enable sanitizers" OFF)
|
option(SANITIZERS "Enable sanitizers" OFF)
|
||||||
option(NATIVE "Use native instructions(for local use only)" OFF)
|
|
||||||
set(CMAKE_DISABLE_IN_SOURCE_BUILD TRUE)
|
set(CMAKE_DISABLE_IN_SOURCE_BUILD TRUE)
|
||||||
set(VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION "5.1.2600.0")
|
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
set(EMBEDDED_INPUT
|
set(EMBEDDED_INPUT
|
||||||
assets/icon.png
|
assets/icon.png
|
||||||
|
assets/default.png
|
||||||
)
|
)
|
||||||
|
|
||||||
## Process Embeddeds ##
|
## Process Embeddeds ##
|
||||||
|
|
@ -43,7 +42,8 @@ endforeach()
|
||||||
|
|
||||||
source_group("Embedded Source" FILES ${EMBEDDED_INPUT} ${EMBEDDED_SOURCE})
|
source_group("Embedded Source" FILES ${EMBEDDED_INPUT} ${EMBEDDED_SOURCE})
|
||||||
add_executable(${PROJECT_NAME} ${EMBEDDED_SOURCE} main.c)
|
add_executable(${PROJECT_NAME} ${EMBEDDED_SOURCE} main.c)
|
||||||
find_package(SDL3 CONFIG)
|
find_package(SDL3 CONFIG REQUIRED)
|
||||||
find_package(SDL3_image CONFIG)
|
find_package(SDL3_image CONFIG REQUIRED)
|
||||||
|
find_package(SDL3_net CONFIG REQUIRED)
|
||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE ${DEFINES})
|
target_compile_definitions(${PROJECT_NAME} PRIVATE ${DEFINES})
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 SDL3_image::SDL3_image)
|
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 SDL3_image::SDL3_image SDL3_net::SDL3_net)
|
||||||
|
|
|
||||||
BIN
journal/SDL/assets/default.png
Normal file
BIN
journal/SDL/assets/default.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 430 B |
|
|
@ -0,0 +1,75 @@
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <SDL3/SDL_log.h>
|
||||||
|
#include "icon.png.xxd"
|
||||||
|
#include "default.png.xxd"
|
||||||
|
|
||||||
|
char image[256] = "default"
|
||||||
|
|
||||||
|
int LoadImage(SDL_Renderer* ren){
|
||||||
|
if(image == "default"){
|
||||||
|
SDL_Surface* img = IMG_Load_IO(SDL_IOFromConstMem(assets_the_modded_machine_png, assets_the_modded_machine_png_len), true);
|
||||||
|
}else{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
|
SDL_Window* win = SDL_CreateWindow("SDL3 Image",640, 480, 0);
|
||||||
|
if (win == NULL) {
|
||||||
|
SDL_Log("SDL_CreateWindow Error: %s", SDL_GetError());
|
||||||
|
SDL_Quit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Renderer* ren = SDL_CreateRenderer(win, NULL);
|
||||||
|
if (ren == NULL) {
|
||||||
|
SDL_Log("SDL_CreateRenderer Error: %s", SDL_GetError());
|
||||||
|
SDL_DestroyWindow(win);
|
||||||
|
SDL_Quit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Surface* bmp = SDL_LoadBMP("lettuce.bmp");
|
||||||
|
if (bmp == NULL) {
|
||||||
|
SDL_Log("Image loading Error: %s", SDL_GetError());
|
||||||
|
SDL_DestroyRenderer(ren);
|
||||||
|
SDL_DestroyWindow(win);
|
||||||
|
SDL_Quit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Texture* tex = SDL_CreateTextureFromSurface(ren, bmp);
|
||||||
|
SDL_DestroySurface(bmp);
|
||||||
|
|
||||||
|
if (tex == NULL) {
|
||||||
|
std::cerr << "SDL_CreateTextureFromSurface Error: " << SDL_GetError() << std::endl;
|
||||||
|
SDL_DestroyRenderer(ren);
|
||||||
|
SDL_DestroyWindow(win);
|
||||||
|
SDL_Quit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Event e;
|
||||||
|
bool quit = false;
|
||||||
|
|
||||||
|
while (!quit) {
|
||||||
|
while (SDL_PollEvent(&e)) {
|
||||||
|
if (e.type == SDL_EVENT_QUIT) {
|
||||||
|
quit = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RenderClear(ren);
|
||||||
|
SDL_RenderTexture(ren, tex, NULL, NULL);
|
||||||
|
SDL_RenderPresent(ren);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_DestroyTexture(tex);
|
||||||
|
SDL_DestroyRenderer(ren);
|
||||||
|
SDL_DestroyWindow(win);
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
69
src/main.cpp
69
src/main.cpp
|
|
@ -23,7 +23,9 @@
|
||||||
#include <SDL3_image/SDL_image.h>
|
#include <SDL3_image/SDL_image.h>
|
||||||
#include <SDL3_ttf/SDL_ttf.h>
|
#include <SDL3_ttf/SDL_ttf.h>
|
||||||
#include <SDL3_mixer/SDL_mixer.h>
|
#include <SDL3_mixer/SDL_mixer.h>
|
||||||
|
#include <SDL3/SDL_stdinc.h>
|
||||||
#include <physfs.h>
|
#include <physfs.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
|
@ -31,7 +33,6 @@
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#include <SDL3/SDL_stdinc.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -166,41 +167,6 @@ static void setupWindowIcon(const Config &conf, SDL_Window *win){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mainly doing this so journal app knows where to load images from
|
|
||||||
static void setGamePathInRegistry() {
|
|
||||||
#if defined WIN32
|
|
||||||
// this logic is currently windows specific
|
|
||||||
const char* dataDir = SDL_GetBasePath();
|
|
||||||
if (dataDir){
|
|
||||||
HKEY key;
|
|
||||||
long keyOpenError = RegOpenKey(HKEY_CURRENT_USER, TEXT("Software\\OneShot\\"), &key);
|
|
||||||
|
|
||||||
if (keyOpenError != ERROR_SUCCESS) {
|
|
||||||
// try creating the key first
|
|
||||||
long keyCreateError = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\OneShot\\"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL);
|
|
||||||
|
|
||||||
if (keyCreateError != ERROR_SUCCESS){
|
|
||||||
WarnMsg("Unable to create key in registry");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
keyOpenError = ERROR_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyOpenError != ERROR_SUCCESS){
|
|
||||||
WarnMsg("Unable to open registry.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DWORD dataSize = (SDL_strlen(dataDir) + 1) * sizeof(char);
|
|
||||||
if (RegSetValueEx(key, TEXT("GameDirectory"), 0, REG_SZ, (LPBYTE)dataDir, dataSize) != ERROR_SUCCESS){
|
|
||||||
WarnMsg("Unable to set GameDirectory registry value");
|
|
||||||
}
|
|
||||||
RegCloseKey(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
//TODO handle this for Linux/Mac
|
|
||||||
}
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
startTime = boost::chrono::high_resolution_clock::now();
|
startTime = boost::chrono::high_resolution_clock::now();
|
||||||
loadLanguageMetadata(); //there will be a segfault on fclose if I don't move it here
|
loadLanguageMetadata(); //there will be a segfault on fclose if I don't move it here
|
||||||
|
|
@ -247,9 +213,6 @@ int main(int argc, char *argv[]){
|
||||||
(void)result;
|
(void)result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
setGamePathInRegistry();
|
|
||||||
|
|
||||||
/* Initialize physfs here so that config can call PHYSFS_getPrefDir */
|
/* Initialize physfs here so that config can call PHYSFS_getPrefDir */
|
||||||
PHYSFS_init(argv[0]);
|
PHYSFS_init(argv[0]);
|
||||||
|
|
||||||
|
|
@ -266,13 +229,33 @@ int main(int argc, char *argv[]){
|
||||||
freopen("CONOUT$", "w", stderr);
|
freopen("CONOUT$", "w", stderr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!conf.gameFolder.empty()){
|
if (!conf.gameFolder.empty()){
|
||||||
if (chdir(conf.gameFolder.c_str()) != 0){
|
if (chdir(conf.gameFolder.c_str()) != 0){
|
||||||
WarnMsg("Unable to switch into gameFolder %s", conf.gameFolder.c_str());
|
WarnMsg("Unable to switch into gameFolder %s", conf.gameFolder.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string path;
|
||||||
|
|
||||||
|
if (!conf.gameFolder.empty()) {
|
||||||
|
if (conf.gameFolder == ".") {
|
||||||
|
path = std::filesystem::current_path().string();
|
||||||
|
} else {
|
||||||
|
path = std::filesystem::absolute(conf.gameFolder).string();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
path = std::filesystem::current_path().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream out(std::filesystem::temp_directory_path() / "sunshine");
|
||||||
|
if (!out) {
|
||||||
|
WarnMsg("Failed to write game directory path to temp file, problems with journal app expected!");
|
||||||
|
} else {
|
||||||
|
out << path;
|
||||||
|
}
|
||||||
|
|
||||||
extern int screenMain(Config &conf);
|
extern int screenMain(Config &conf);
|
||||||
if (conf.screenMode)
|
if (conf.screenMode)
|
||||||
return screenMain(conf);
|
return screenMain(conf);
|
||||||
|
|
@ -283,13 +266,13 @@ int main(int argc, char *argv[]){
|
||||||
if (TTF_Init() == false){
|
if (TTF_Init() == false){
|
||||||
WarnMsg("Error initializing SDL_ttf: %s", SDL_GetError());
|
WarnMsg("Error initializing SDL_ttf: %s", SDL_GetError());
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MIX_Init() == false){
|
if (MIX_Init() == false){
|
||||||
WarnMsg("Error initializing SDL_mixer: %s", SDL_GetError());
|
WarnMsg("Error initializing SDL_mixer: %s", SDL_GetError());
|
||||||
TTF_Quit();
|
TTF_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,7 +288,6 @@ int main(int argc, char *argv[]){
|
||||||
MIX_Quit();
|
MIX_Quit();
|
||||||
TTF_Quit();
|
TTF_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -329,8 +311,7 @@ int main(int argc, char *argv[]){
|
||||||
WarnMsg("Error creating Mixer Device, check your system audio configuration");
|
WarnMsg("Error creating Mixer Device, check your system audio configuration");
|
||||||
MIX_Quit();
|
MIX_Quit();
|
||||||
TTF_Quit();
|
TTF_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue