Fix Linux and Windows build issues; texture looks in CDBs first
This commit is contained in:
@@ -553,16 +553,6 @@ int point2segindex(cpVect p, cpVect *segs, double slop) {
|
||||
return best;
|
||||
}
|
||||
|
||||
int file_exists(char *path) {
|
||||
FILE *o = fopen(path, "r");
|
||||
if (o) {
|
||||
fclose(o);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2int(argv[0]);
|
||||
const char *str = NULL;
|
||||
@@ -830,7 +820,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
|
||||
case 65:
|
||||
str = JS_ToCString(js, argv[1]);
|
||||
ret = JS_NewBool(js, file_exists(str));
|
||||
ret = JS_NewBool(js, fexists(str));
|
||||
break;
|
||||
|
||||
case 66:
|
||||
@@ -1107,6 +1097,12 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
case 137:
|
||||
ret = v22js(screen2world(js2hmmv2(argv[1])));
|
||||
break;
|
||||
|
||||
case 138:
|
||||
str = JS_ToCString(js, argv[1]);
|
||||
ret = JS_NewInt64(js, jso_file(str));
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (str)
|
||||
|
||||
@@ -94,7 +94,7 @@ char *seprint(char *fmt, ...)
|
||||
char test[128];
|
||||
int len = vsnprintf(test, 128, fmt, args);
|
||||
if (len > 128) {
|
||||
char test = malloc(len+1);
|
||||
char *test = malloc(len+1);
|
||||
vsnprintf(test, len+1, fmt, args);
|
||||
return strdup(test);
|
||||
}
|
||||
@@ -190,6 +190,18 @@ void *cdb_slurp(struct cdb *cdb, const char *file, size_t *size)
|
||||
return data;
|
||||
}
|
||||
|
||||
int fexists(char *path)
|
||||
{
|
||||
return !access(path,R_OK);
|
||||
|
||||
int len = strlen(path);
|
||||
if (cdb_find(&game_cdb, path,len)) return 1;
|
||||
else if (cdb_find(&core_cdb, path, len)) return 1;
|
||||
else if (!access(path, R_OK)) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char *slurp_file(const char *filename, size_t *size)
|
||||
{
|
||||
if (cdb_find(&game_cdb, filename, strlen(filename)))
|
||||
|
||||
@@ -14,6 +14,7 @@ FILE *res_open(char *path, const char *tag);
|
||||
FILE *path_open(const char *tag, const char *fmt, ...);
|
||||
char *make_path(const char *file);
|
||||
char **ls(char *path);
|
||||
int fexists(char *path);
|
||||
|
||||
unsigned char *slurp_file(const char *filename, size_t *size);
|
||||
char *slurp_text(const char *filename, size_t *size);
|
||||
|
||||
@@ -45,8 +45,8 @@ void script_startup() {
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
num_cache[i] = int2js(i);
|
||||
|
||||
script_dofile("scripts/engine.js");
|
||||
|
||||
script_dofile("scripts/engine.js");
|
||||
// jso_file("scripts/engine.js");
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ JSValue script_runjso(const uint8_t *buf, size_t len)
|
||||
time_t jso_file(const char *file)
|
||||
{
|
||||
size_t len;
|
||||
uint8_t *byte = compile_script(file, &len);
|
||||
uint8_t *byte = slurp_file(file, &len);
|
||||
JSValue obj = JS_ReadObject(js, byte, len, JS_READ_OBJ_BYTECODE);
|
||||
JSValue ret = JS_EvalFunction(js, obj);
|
||||
js_print_exception(ret);
|
||||
|
||||
@@ -25,7 +25,7 @@ static struct {
|
||||
struct Texture *tex_default;
|
||||
|
||||
struct Texture *texture_notex() {
|
||||
return texture_pullfromfile("./icons/no_tex.png");
|
||||
return texture_pullfromfile("icons/no_tex.png");
|
||||
}
|
||||
|
||||
unsigned int next_pow2(unsigned int v)
|
||||
@@ -86,19 +86,22 @@ struct Texture *texture_pullfromfile(const char *path) {
|
||||
|
||||
int n;
|
||||
|
||||
long rawlen;
|
||||
unsigned char *raw = slurp_file(path, &rawlen);
|
||||
unsigned char *data;
|
||||
|
||||
char *ext = strrchr(path, '.');
|
||||
|
||||
if (ext && !strcmp(ext, ".qoi")) {
|
||||
qoi_desc qoi;
|
||||
data = qoi_read(path, &qoi, 4);
|
||||
data = qoi_decode(raw, rawlen, &qoi, 4);
|
||||
tex->width = qoi.width;
|
||||
tex->height = qoi.height;
|
||||
n = qoi.channels;
|
||||
} else {
|
||||
data = stbi_load(path, &tex->width, &tex->height, &n, 4);
|
||||
data = stbi_load_from_memory(raw, rawlen, &tex->width, &tex->height, &n, 4);
|
||||
}
|
||||
free(raw);
|
||||
|
||||
if (data == NULL) {
|
||||
YughError("STBI failed to load file %s with message: %s\nOpening default instead.", path, stbi_failure_reason());
|
||||
|
||||
1
source/engine/thirdparty/sokol/sokol_gfx.h
vendored
1
source/engine/thirdparty/sokol/sokol_gfx.h
vendored
@@ -3897,6 +3897,7 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_
|
||||
#define GL_TEXTURE_COMPARE_MODE 0x884C
|
||||
#define GL_TEXTURE_COMPARE_FUNC 0x884D
|
||||
#define GL_COMPARE_REF_TO_TEXTURE 0x884E
|
||||
#define GL_VIEWPORT 0x0BA2
|
||||
#endif
|
||||
|
||||
#ifndef GL_UNSIGNED_INT_2_10_10_10_REV
|
||||
|
||||
7
source/engine/thirdparty/tinycdb/cdb_make.c
vendored
7
source/engine/thirdparty/tinycdb/cdb_make.c
vendored
@@ -147,7 +147,14 @@ cdb_make_finish_internal(struct cdb_make *cdbmp)
|
||||
_cdb_make_fullwrite(cdbmp->cdb_fd, p, 2048) != 0)
|
||||
return -1;
|
||||
|
||||
/* TODO: Windows doesn't support fsync; simple workaround is to not do it!
|
||||
It does not seem that the lower level open(), read(), write() require it anyway.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
return 0;
|
||||
#else
|
||||
return fsync(cdbmp->cdb_fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -34,10 +34,6 @@
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#include "nuklear.h"
|
||||
#include "sokol/sokol_gfx.h"
|
||||
#include "sokol/sokol_nuklear.h"
|
||||
|
||||
#define SOKOL_TRACE_HOOKS
|
||||
#define SOKOL_IMPL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user