mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-21 06:19:56 +00:00
filesystem.cpp replacing strcpySafe with SDL_strlcpy
This commit is contained in:
parent
9bb25b57ee
commit
8526adff06
6 changed files with 17 additions and 55 deletions
|
|
@ -6,7 +6,8 @@ include(FindPackageHandleStandardArgs)
|
|||
option(STEAM "Build for Steam" OFF)
|
||||
option(DEBUG "Debug mode" OFF)
|
||||
option(FORCE32 "Force 32bit compile on 64bit OS" OFF) # from MKXP
|
||||
option(NATIVE "Use native instructions(for local use only)" ON) # from MKXP
|
||||
option(NATIVE "Use native instructions(for local use only)" ON)
|
||||
option(PROFILE "Extra optimization" ON)
|
||||
option(EXTRA_SECURITY "Extra security" OFF)
|
||||
|
||||
set(CMAKE_DISABLE_IN_SOURCE_BUILD TRUE)
|
||||
|
|
@ -47,23 +48,14 @@ else()
|
|||
add_compile_options(/O2 /fp:fast /GL /GF /GA)
|
||||
else()
|
||||
#bruh....
|
||||
add_compile_options(-Ofast -flto -funroll-loops -fipa-pta -ftree-vectorize -fstdarg-opt -fomit-frame-pointer)
|
||||
add_compile_options(-Ofast -flto -funroll-loops -fipa-pta -ftree-vectorize -fstdarg-opt -fomit-frame-pointer -frename-registers)
|
||||
add_link_options(-Wl,-O2)
|
||||
set_property(SOURCE src/tilequad.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/tilemap.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/tileatlas.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/texpool.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/table.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/sprite.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/shader.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/security.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/vorbissource.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/sdlsoundsource.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/screen.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/oneshot.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/meow.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/etc.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
set_property(SOURCE src/filesystem.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(PROFILE)
|
||||
if (!MSVC)
|
||||
add_compile_options(-fprofile-generate -fprofile-use)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
|
|
|||
|
|
@ -35,13 +35,7 @@
|
|||
#include <SDL3/SDL_timer.h>
|
||||
|
||||
ALStream::ALStream(LoopMode loopMode, const std::string &threadId)
|
||||
: looped(loopMode == Looped),
|
||||
state(Closed),
|
||||
source(0),
|
||||
thread(0),
|
||||
preemptPause(false),
|
||||
pitch(1.0f)
|
||||
{
|
||||
: looped(loopMode == Looped), state(Closed), source(0), thread(0), preemptPause(false), pitch(1.0f) {
|
||||
alSrc = AL::Source::gen();
|
||||
|
||||
AL::Source::setVolume(alSrc, 1.0f);
|
||||
|
|
|
|||
|
|
@ -30,10 +30,7 @@
|
|||
#include <SDL3/SDL_timer.h>
|
||||
|
||||
AudioStream::AudioStream(ALStream::LoopMode loopMode, const std::string &threadId)
|
||||
: extPaused(false),
|
||||
noResumeStop(false),
|
||||
stream(loopMode, threadId)
|
||||
{
|
||||
: extPaused(false), noResumeStop(false), stream(loopMode, threadId){
|
||||
current.volume = 1.0f;
|
||||
current.pitch = 1.0f;
|
||||
|
||||
|
|
@ -199,8 +196,7 @@ void AudioStream::fadeOut(int duration){
|
|||
fade.reqTerm.clear();
|
||||
fade.startTicks = SDL_GetTicks();
|
||||
|
||||
fade.thread = createSDLThread
|
||||
<AudioStream, &AudioStream::fadeOutThread>(this, fade.threadName);
|
||||
fade.thread = createSDLThread<AudioStream, &AudioStream::fadeOutThread>(this, fade.threadName);
|
||||
|
||||
unlockStream();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,10 +47,7 @@ struct SDLRWIoContext{
|
|||
SDL_IOStream *ops;
|
||||
std::string filename;
|
||||
|
||||
SDLRWIoContext(const char *filename)
|
||||
: ops(SDL_IOFromFile(filename, "r")),
|
||||
filename(filename)
|
||||
{
|
||||
SDLRWIoContext(const char *filename) : ops(SDL_IOFromFile(filename, "r")), filename(filename){
|
||||
if (!ops)
|
||||
throw Exception(Exception::SDLError, "Failed to open file: %s", SDL_GetError());
|
||||
}
|
||||
|
|
@ -67,7 +64,6 @@ static SDL_IOStream *getSDLRWops(PHYSFS_Io *io){
|
|||
}
|
||||
|
||||
static PHYSFS_sint64 SDLRWIoRead(struct PHYSFS_Io *io, void *buf, PHYSFS_uint64 len){
|
||||
// return SDL_ReadIO(getSDLRWops(io), buf, 1, len);
|
||||
return SDL_ReadIO(getSDLRWops(io), buf, len);
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +113,7 @@ static PHYSFS_Io *createSDLRWIo(const char *filename){
|
|||
try{
|
||||
ctx = new SDLRWIoContext(filename);
|
||||
}catch (const Exception &e){
|
||||
Debug() << "Failed mounting" << filename;
|
||||
Debug() << "Failed mounting: " << filename;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -225,22 +221,6 @@ static int SDL_RWopsCloseFree(void *userdata)
|
|||
return result;
|
||||
}*/
|
||||
|
||||
/* Copies the first srcN characters from src into dst,
|
||||
* or the full string if srcN == -1. Never writes more
|
||||
* than dstMax, and guarantees dst to be null terminated.
|
||||
* Returns copied bytes (minus terminating null) */
|
||||
static size_t strcpySafe(char *dst, const char *src, size_t dstMax, int srcN){
|
||||
if (srcN < 0)
|
||||
srcN = SDL_strlen(src);
|
||||
|
||||
size_t cpyMax = std::min<size_t>(dstMax-1, srcN);
|
||||
|
||||
SDL_memcpy(dst, src, cpyMax);
|
||||
dst[cpyMax] = '\0';
|
||||
|
||||
return cpyMax;
|
||||
}
|
||||
|
||||
/* Attempt to locate an extension string in a filename.
|
||||
* Either a pointer into the input string pointing at the
|
||||
* extension, or null is returned */
|
||||
|
|
@ -556,7 +536,7 @@ openReadEnumCB(void *d, const char *dirpath, const char *filename){
|
|||
|
||||
void FileSystem::openRead(OpenHandler &handler, const char *filename){
|
||||
char buffer[512];
|
||||
size_t len = strcpySafe(buffer, filename, sizeof(buffer), -1);
|
||||
size_t len = SDL_strlcpy(buffer, filename, sizeof(buffer));
|
||||
char *delim;
|
||||
|
||||
if (p->havePathCache)
|
||||
|
|
|
|||
|
|
@ -654,7 +654,7 @@ void Graphics::freeze(){
|
|||
p->compositeToBuffer(p->frozenScene);
|
||||
}
|
||||
|
||||
void Graphics::transition(unsigned short duration, const char *filename, int vague){
|
||||
void Graphics::transition(unsigned int duration, const char *filename, int vague){
|
||||
p->checkSyncLock();
|
||||
|
||||
if (!p->frozen)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Graphics{
|
|||
public:
|
||||
void update(bool limitFps = true);
|
||||
void freeze();
|
||||
void transition(unsigned short duration = 8, const char *filename = "", int vague = 40);
|
||||
void transition(unsigned int duration = 8, const char *filename = "", int vague = 40);
|
||||
void frameReset();
|
||||
|
||||
DECL_ATTR( FrameRate, int )
|
||||
|
|
|
|||
Loading…
Reference in a new issue