Address review comments

This commit is contained in:
ISSOtm
2024-06-29 22:26:49 +02:00
parent 0b6a73f380
commit c6103d23fa
5 changed files with 36 additions and 46 deletions

View File

@@ -205,19 +205,23 @@ SDL_LDFLAGS += -lopenal
endif endif
SDL_AUDIO_DRIVERS += openal SDL_AUDIO_DRIVERS += openal
endif endif
else else # ifneq ($(PKG_CONFIG),)
SDL_CFLAGS := $(shell $(PKG_CONFIG) --cflags sdl2) SDL_CFLAGS := $(shell $(PKG_CONFIG) --cflags sdl2)
SDL_LDFLAGS := $(shell $(PKG_CONFIG) --libs sdl2) -lpthread SDL_LDFLAGS := $(shell $(PKG_CONFIG) --libs sdl2) -lpthread
# Allow OpenAL to be disabled even if the development libraries are available # Allow OpenAL to be disabled even if the development libraries are available
ifneq ($(ENABLE_OPENAL),0) ifneq ($(ENABLE_OPENAL),0)
ifeq ($(shell $(PKG_CONFIG) --exists openal && echo 0),0) ifneq ($(shell $(PKG_CONFIG) --exists openal && echo 0),)
SDL_CFLAGS += $(shell $(PKG_CONFIG) --cflags openal) -DENABLE_OPENAL SDL_CFLAGS += $(shell $(PKG_CONFIG) --cflags openal) -DENABLE_OPENAL
SDL_LDFLAGS += $(shell $(PKG_CONFIG) --libs openal) SDL_LDFLAGS += $(shell $(PKG_CONFIG) --libs openal)
SDL_AUDIO_DRIVERS += openal SDL_AUDIO_DRIVERS += openal
endif endif
endif endif
ifneq ($(shell pkg-config --exists gio-2.0 || echo 0),)
GIO_CFLAGS = $(error The Gio library could not be found)
GIO_LDFLAGS = $(error The Gio library could not be found)
else
GIO_CFLAGS := $(shell $(PKG_CONFIG) --cflags gio-2.0) -DG_LOG_USE_STRUCTURED GIO_CFLAGS := $(shell $(PKG_CONFIG) --cflags gio-2.0) -DG_LOG_USE_STRUCTURED
GIO_LDFLAGS := $(shell $(PKG_CONFIG) --libs gio-2.0) GIO_LDFLAGS := $(shell $(PKG_CONFIG) --libs gio-2.0)
ifeq ($(CONF),debug) ifeq ($(CONF),debug)
@@ -225,10 +229,16 @@ GIO_CFLAGS += -DG_ENABLE_DEBUG
else else
GIO_CFLAGS += -DG_DISABLE_ASSERT GIO_CFLAGS += -DG_DISABLE_ASSERT
endif endif
endif
ifneq ($(shell pkg-config --exists gdk-pixbuf-2.0 || echo 0),)
GDK_PIXBUF_CFLAGS = $(error The Gdk-Pixbuf library could not be found)
GDK_PIXBUF_LDFLAGS = $(error The Gdk-Pixbuf library could not be found)
else
GDK_PIXBUF_CFLAGS := $(shell $(PKG_CONFIG) --cflags gdk-pixbuf-2.0) GDK_PIXBUF_CFLAGS := $(shell $(PKG_CONFIG) --cflags gdk-pixbuf-2.0)
GDK_PIXBUF_LDFLAGS := $(shell $(PKG_CONFIG) --libs gdk-pixbuf-2.0) GDK_PIXBUF_LDFLAGS := $(shell $(PKG_CONFIG) --libs gdk-pixbuf-2.0)
endif endif
endif
ifeq (,$(PKG_CONFIG)) ifeq (,$(PKG_CONFIG))
GL_LDFLAGS := -lGL GL_LDFLAGS := -lGL
@@ -656,12 +666,12 @@ $(BIN)/SDL/background.bmp: SDL/background.bmp
$(BIN)/SDL/Shaders: Shaders $(BIN)/SDL/Shaders: Shaders
-@$(MKDIR) -p $@ -@$(MKDIR) -p $@
cp -rf $< $@ cp -rfT $< $@
touch $@ touch $@
$(BIN)/SDL/Palettes: Misc/Palettes $(BIN)/SDL/Palettes: Misc/Palettes
-@$(MKDIR) -p $@ -@$(MKDIR) -p $@
cp -rf $< $@ cp -rfT $< $@
touch $@ touch $@
# Boot ROMs # Boot ROMs
@@ -698,6 +708,8 @@ libretro:
# If you somehow find a reasonable way to make associate an icon with an extension in this dumpster # If you somehow find a reasonable way to make associate an icon with an extension in this dumpster
# fire of a desktop environment, open an issue or a pull request # fire of a desktop environment, open an issue or a pull request
ifneq ($(FREEDESKTOP),) ifneq ($(FREEDESKTOP),)
all: xdg-thumbnailer
ICON_NAMES := apps/sameboy mimetypes/x-gameboy-rom mimetypes/x-gameboy-color-rom ICON_NAMES := apps/sameboy mimetypes/x-gameboy-rom mimetypes/x-gameboy-color-rom
ICON_SIZES := 16x16 32x32 64x64 128x128 256x256 512x512 ICON_SIZES := 16x16 32x32 64x64 128x128 256x256 512x512
ICONS := $(foreach name,$(ICON_NAMES), $(foreach size,$(ICON_SIZES),$(DESTDIR)$(PREFIX)/share/icons/hicolor/$(size)/$(name).png)) ICONS := $(foreach name,$(ICON_NAMES), $(foreach size,$(ICON_SIZES),$(DESTDIR)$(PREFIX)/share/icons/hicolor/$(size)/$(name).png))

View File

@@ -12,28 +12,6 @@
#define NB_FRAMES_TO_EMULATE (60 * 10) #define NB_FRAMES_TO_EMULATE (60 * 10)
#define BOOT_ROM_SIZE (0x100 + 0x800) // The two "parts" of it, which are stored contiguously. #define BOOT_ROM_SIZE (0x100 + 0x800) // The two "parts" of it, which are stored contiguously.
static char *boot_rom;
void load_boot_rom(void)
{
static char const *boot_rom_path = DATA_DIR "/cgb_boot_fast.bin";
size_t length;
GError *error = NULL;
g_file_get_contents(boot_rom_path, &boot_rom, &length, &error);
if (error) {
g_error("Error loading boot ROM from \"%s\": %s", boot_rom_path, error->message);
// NOTREACHED
}
else if (length != BOOT_ROM_SIZE) {
g_error("Error loading boot ROM from \"%s\": expected to read %d bytes, got %zu", boot_rom_path, BOOT_ROM_SIZE,
length);
// NOTREACHED
}
}
void unload_boot_rom(void) { g_free(boot_rom); }
/* --- */ /* --- */

View File

@@ -9,7 +9,4 @@ enum FileKind {
KIND_ISX, KIND_ISX,
}; };
void load_boot_rom(void);
void unload_boot_rom(void);
unsigned emulate(enum FileKind kind, unsigned char const *rom, size_t rom_size, uint32_t screen[static 160 * 144]); unsigned emulate(enum FileKind kind, unsigned char const *rom, size_t rom_size, uint32_t screen[static 160 * 144]);

View File

@@ -16,8 +16,8 @@
// Auto-generated via `gdbus-codegen` from `interface.xml`. // Auto-generated via `gdbus-codegen` from `interface.xml`.
#include "build/obj/XdgThumbnailer/interface.h" #include "build/obj/XdgThumbnailer/interface.h"
static char const *const name_on_bus = "com.github.liji32.sameboy.XdgThumbnailer"; static char const name_on_bus[] = "com.github.liji32.sameboy.XdgThumbnailer";
static char const *const object_path = "/com/github/liji32/sameboy/XdgThumbnailer"; static char const object_path[] = "/com/github/liji32/sameboy/XdgThumbnailer";
ThumbnailerSpecializedThumbnailer1 *thumbnailer_interface = NULL; ThumbnailerSpecializedThumbnailer1 *thumbnailer_interface = NULL;
static unsigned max_nb_worker_threads; static unsigned max_nb_worker_threads;
@@ -127,7 +127,6 @@ int main(int argc, char const *argv[])
g_info("Waiting for outstanding tasks..."); g_info("Waiting for outstanding tasks...");
cleanup_tasks(); // Also waits for any remaining tasks. cleanup_tasks(); // Also waits for any remaining tasks.
// "Pedantic" cleanup for Valgrind et al. // "Pedantic" cleanup for Valgrind et al.
unload_boot_rom();
g_main_loop_unref(main_loop); g_main_loop_unref(main_loop);
g_bus_unown_name(owner_id); g_bus_unown_name(owner_id);
if (thumbnailer_interface) { if (thumbnailer_interface) {

View File

@@ -12,12 +12,16 @@
#include "main.h" #include "main.h"
#include "tasks.h" #include "tasks.h"
#define DMG_ONLY_RESOURCE_PATH "/thumbnailer/CartridgeTemplate.png"
#define DUAL_RESOURCE_PATH "/thumbnailer/UniversalCartridgeTemplate.png"
#define CGB_ONLY_RESOURCE_PATH "/thumbnailer/ColorCartridgeTemplate.png"
#define THUMBNAILING_ERROR_DOMAIN (g_quark_from_static_string("thumbnailing")) #define THUMBNAILING_ERROR_DOMAIN (g_quark_from_static_string("thumbnailing"))
static char const dmg_only_resource_path[] = "/thumbnailer/CartridgeTemplate.png";
static char const dual_resource_path[] = "/thumbnailer/UniversalCartridgeTemplate.png";
static char const cgb_only_resource_path[] = "/thumbnailer/ColorCartridgeTemplate.png";
static char const gb_mime_type[] = "application/x-gameboy-rom";
static char const gbc_mime_type[] = "application/x-gameboy-color-rom";
static char const isx_mime_type[] = "application/x-gameboy-isx";
/* --- */ /* --- */
struct TaskData { struct TaskData {
@@ -38,11 +42,11 @@ char const *mime_type(enum FileKind kind)
{ {
switch (kind) { switch (kind) {
case KIND_GB: case KIND_GB:
return "application/x-gameboy-rom"; return gb_mime_type;
case KIND_GBC: case KIND_GBC:
return "application/x-gameboy-color-rom"; return gbc_mime_type;
case KIND_ISX: case KIND_ISX:
return "application/x-gameboy-isx"; return isx_mime_type;
} }
} }
@@ -82,13 +86,13 @@ static void generate_thumbnail(GTask *task, void *source_object, void *data, GCa
GdkPixbuf *template; GdkPixbuf *template;
switch (cgb_flag) { switch (cgb_flag) {
case 0xC0: case 0xC0:
template = gdk_pixbuf_new_from_resource(CGB_ONLY_RESOURCE_PATH, &error); template = gdk_pixbuf_new_from_resource(cgb_only_resource_path, &error);
break; break;
case 0x80: case 0x80:
template = gdk_pixbuf_new_from_resource(DUAL_RESOURCE_PATH, &error); template = gdk_pixbuf_new_from_resource(dual_resource_path, &error);
break; break;
default: default:
template = gdk_pixbuf_new_from_resource(DMG_ONLY_RESOURCE_PATH, &error); template = gdk_pixbuf_new_from_resource(dmg_only_resource_path, &error);
break; break;
} }
g_assert_no_error(error); g_assert_no_error(error);
@@ -109,7 +113,7 @@ static void generate_thumbnail(GTask *task, void *source_object, void *data, GCa
// TODO: proper file name // TODO: proper file name
gdk_pixbuf_save(scaled_screen, "/tmp/output.png", "png", &error, // "Base" parameters. gdk_pixbuf_save(scaled_screen, "/tmp/output.png", "png", &error, // "Base" parameters.
"tEXt::Thumb::URI", g_task_get_name(task), // URI of the file being thumbnailed. "tEXt::Thumb::URI", g_task_get_name(task), // URI of the file being thumbnailed.
"tEXt::Thumb::MTime", "", // TODO // "tEXt::Thumb::MTime", "", // TODO
"tEXt::Thumb::Size", file_size, // Size (in bytes) of the file being thumbnailed. "tEXt::Thumb::Size", file_size, // Size (in bytes) of the file being thumbnailed.
"tEXt::Thumb::Mimetype", mime_type(task_data->kind), // MIME type of the file being thumbnailed. "tEXt::Thumb::Mimetype", mime_type(task_data->kind), // MIME type of the file being thumbnailed.
NULL); NULL);
@@ -183,13 +187,13 @@ void start_thumbnailing(unsigned handle, GCancellable *cancellable, gboolean is_
g_task_set_name(task, uri); g_task_set_name(task, uri);
enum FileKind kind; enum FileKind kind;
if (g_strcmp0(mime_type, "application/x-gameboy-color-rom") == 0) { if (g_strcmp0(mime_type, gbc_mime_type) == 0) {
kind = KIND_GBC; kind = KIND_GBC;
} }
else if (g_strcmp0(mime_type, "application/x-gameboy-rom") == 0) { else if (g_strcmp0(mime_type, gb_mime_type) == 0) {
kind = KIND_GB; kind = KIND_GB;
} }
else if (g_strcmp0(mime_type, "application/x-gameboy-isx") == 0) { else if (g_strcmp0(mime_type, isx_mime_type) == 0) {
kind = KIND_ISX; kind = KIND_ISX;
} }
else { else {