filesystem.cpp replacing strcpySafe with SDL_strlcpy
This commit is contained in:
parent
9bb25b57ee
commit
8526adff06
|
|
@ -6,7 +6,8 @@ include(FindPackageHandleStandardArgs)
|
||||||
option(STEAM "Build for Steam" OFF)
|
option(STEAM "Build for Steam" OFF)
|
||||||
option(DEBUG "Debug mode" OFF)
|
option(DEBUG "Debug mode" OFF)
|
||||||
option(FORCE32 "Force 32bit compile on 64bit OS" OFF) # from MKXP
|
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)
|
option(EXTRA_SECURITY "Extra security" OFF)
|
||||||
|
|
||||||
set(CMAKE_DISABLE_IN_SOURCE_BUILD TRUE)
|
set(CMAKE_DISABLE_IN_SOURCE_BUILD TRUE)
|
||||||
|
|
@ -47,23 +48,14 @@ else()
|
||||||
add_compile_options(/O2 /fp:fast /GL /GF /GA)
|
add_compile_options(/O2 /fp:fast /GL /GF /GA)
|
||||||
else()
|
else()
|
||||||
#bruh....
|
#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)
|
add_link_options(-Wl,-O2)
|
||||||
set_property(SOURCE src/tilequad.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
endif()
|
||||||
set_property(SOURCE src/tilemap.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
endif()
|
||||||
set_property(SOURCE src/tileatlas.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
|
||||||
set_property(SOURCE src/texpool.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
if(PROFILE)
|
||||||
set_property(SOURCE src/table.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
if (!MSVC)
|
||||||
set_property(SOURCE src/sprite.cpp APPEND PROPERTY COMPILE_OPTIONS "-fgcse-las")
|
add_compile_options(-fprofile-generate -fprofile-use)
|
||||||
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()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,13 +35,7 @@
|
||||||
#include <SDL3/SDL_timer.h>
|
#include <SDL3/SDL_timer.h>
|
||||||
|
|
||||||
ALStream::ALStream(LoopMode loopMode, const std::string &threadId)
|
ALStream::ALStream(LoopMode loopMode, const std::string &threadId)
|
||||||
: looped(loopMode == Looped),
|
: looped(loopMode == Looped), state(Closed), source(0), thread(0), preemptPause(false), pitch(1.0f) {
|
||||||
state(Closed),
|
|
||||||
source(0),
|
|
||||||
thread(0),
|
|
||||||
preemptPause(false),
|
|
||||||
pitch(1.0f)
|
|
||||||
{
|
|
||||||
alSrc = AL::Source::gen();
|
alSrc = AL::Source::gen();
|
||||||
|
|
||||||
AL::Source::setVolume(alSrc, 1.0f);
|
AL::Source::setVolume(alSrc, 1.0f);
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,7 @@
|
||||||
#include <SDL3/SDL_timer.h>
|
#include <SDL3/SDL_timer.h>
|
||||||
|
|
||||||
AudioStream::AudioStream(ALStream::LoopMode loopMode, const std::string &threadId)
|
AudioStream::AudioStream(ALStream::LoopMode loopMode, const std::string &threadId)
|
||||||
: extPaused(false),
|
: extPaused(false), noResumeStop(false), stream(loopMode, threadId){
|
||||||
noResumeStop(false),
|
|
||||||
stream(loopMode, threadId)
|
|
||||||
{
|
|
||||||
current.volume = 1.0f;
|
current.volume = 1.0f;
|
||||||
current.pitch = 1.0f;
|
current.pitch = 1.0f;
|
||||||
|
|
||||||
|
|
@ -199,8 +196,7 @@ void AudioStream::fadeOut(int duration){
|
||||||
fade.reqTerm.clear();
|
fade.reqTerm.clear();
|
||||||
fade.startTicks = SDL_GetTicks();
|
fade.startTicks = SDL_GetTicks();
|
||||||
|
|
||||||
fade.thread = createSDLThread
|
fade.thread = createSDLThread<AudioStream, &AudioStream::fadeOutThread>(this, fade.threadName);
|
||||||
<AudioStream, &AudioStream::fadeOutThread>(this, fade.threadName);
|
|
||||||
|
|
||||||
unlockStream();
|
unlockStream();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,7 @@ struct SDLRWIoContext{
|
||||||
SDL_IOStream *ops;
|
SDL_IOStream *ops;
|
||||||
std::string filename;
|
std::string filename;
|
||||||
|
|
||||||
SDLRWIoContext(const char *filename)
|
SDLRWIoContext(const char *filename) : ops(SDL_IOFromFile(filename, "r")), filename(filename){
|
||||||
: ops(SDL_IOFromFile(filename, "r")),
|
|
||||||
filename(filename)
|
|
||||||
{
|
|
||||||
if (!ops)
|
if (!ops)
|
||||||
throw Exception(Exception::SDLError, "Failed to open file: %s", SDL_GetError());
|
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){
|
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);
|
return SDL_ReadIO(getSDLRWops(io), buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,7 +113,7 @@ static PHYSFS_Io *createSDLRWIo(const char *filename){
|
||||||
try{
|
try{
|
||||||
ctx = new SDLRWIoContext(filename);
|
ctx = new SDLRWIoContext(filename);
|
||||||
}catch (const Exception &e){
|
}catch (const Exception &e){
|
||||||
Debug() << "Failed mounting" << filename;
|
Debug() << "Failed mounting: " << filename;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,22 +221,6 @@ static int SDL_RWopsCloseFree(void *userdata)
|
||||||
return result;
|
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.
|
/* Attempt to locate an extension string in a filename.
|
||||||
* Either a pointer into the input string pointing at the
|
* Either a pointer into the input string pointing at the
|
||||||
* extension, or null is returned */
|
* 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){
|
void FileSystem::openRead(OpenHandler &handler, const char *filename){
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
size_t len = strcpySafe(buffer, filename, sizeof(buffer), -1);
|
size_t len = SDL_strlcpy(buffer, filename, sizeof(buffer));
|
||||||
char *delim;
|
char *delim;
|
||||||
|
|
||||||
if (p->havePathCache)
|
if (p->havePathCache)
|
||||||
|
|
|
||||||
|
|
@ -654,7 +654,7 @@ void Graphics::freeze(){
|
||||||
p->compositeToBuffer(p->frozenScene);
|
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();
|
p->checkSyncLock();
|
||||||
|
|
||||||
if (!p->frozen)
|
if (!p->frozen)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class Graphics{
|
||||||
public:
|
public:
|
||||||
void update(bool limitFps = true);
|
void update(bool limitFps = true);
|
||||||
void freeze();
|
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();
|
void frameReset();
|
||||||
|
|
||||||
DECL_ATTR( FrameRate, int )
|
DECL_ATTR( FrameRate, int )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue