[nctetris] find the background everywhere #2042

This commit is contained in:
nick black 2021-12-02 03:06:39 -05:00
parent 744e1ce015
commit 238de45e96
5 changed files with 27 additions and 16 deletions

View File

@ -608,11 +608,12 @@ target_link_libraries(notcurses-input
############################################################################
# nctetris
file(GLOB TETRISSRC CONFIGURE_DEPENDS src/tetris/*.cpp)
file(GLOB TETRISSRC CONFIGURE_DEPENDS src/tetris/*.cpp src/compat/*.c)
add_executable(nctetris ${TETRISSRC})
target_include_directories(nctetris
BEFORE
PRIVATE
src
include
"${CMAKE_REQUIRED_INCLUDES}"
"${PROJECT_BINARY_DIR}/include"

View File

@ -116,6 +116,26 @@ int clock_nanosleep(clockid_t clockid, int flags,
const struct timespec *request,
struct timespec *remain);
static inline char*
notcurses_data_path(const char* f){
char* datadir = notcurses_data_dir();
if(datadir == NULL){
return NULL;
}
const size_t dlen = strlen(datadir);
// cast is for benefit of c++ callers, sigh
char* path = (char*)malloc(dlen + 1 + strlen(f) + 1);
if(path == NULL){
free(datadir);
return NULL;
}
strcpy(path, datadir);
free(datadir);
path[dlen] = path_separator();
strcpy(path + dlen + 1, f);
return path;
}
#ifdef __cplusplus
}
#else

View File

@ -44,12 +44,7 @@ const demoresult* demoresult_lookup(int idx){
}
char* find_data(const char* datum){
const size_t dlen = strlen(datadir);
char* path = malloc(dlen + 1 + strlen(datum) + 1);
strcpy(path, datadir);
path[dlen] = path_separator();
strcpy(path + dlen + 1, datum);
return path;
return notcurses_data_path(datum);
}
float delaymultiplier = 1;

View File

@ -2275,8 +2275,8 @@ internal_get(inputctx* ictx, const struct timespec* ts, ncinput* ni){
sendsignal = true;
}else{
logtrace("draining event readiness pipe %d\n", ictx->ivalid);
char c;
#ifndef __MINGW64__
char c;
while(read(ictx->readypipes[0], &c, sizeof(c)) == 1){
// FIXME accelerate?
}

View File

@ -11,19 +11,14 @@
#include <cinttypes>
#include <ncpp/NotCurses.hh>
#include <ncpp/Visual.hh>
#include "compat/compat.h"
#include "builddef.h"
#include "version.h"
std::mutex ncmtx;
#ifdef __MINGW64__
#define PATHSEP "\\"
#else
#define PATHSEP "/"
#endif
const std::string BackgroundFile = NOTCURSES_SHARE PATHSEP "tetris-background.jpg";
const std::string LogoFile = NOTCURSES_SHARE PATHSEP "notcurses.png";
#undef PATHSEP
const std::string BackgroundFile = notcurses_data_path("tetris-background.jpg");
const std::string LogoFile = notcurses_data_path("notcurses.png");
using namespace std::chrono_literals;