VERSIÓ 1.3.13

- [NEW]  Executant la versió de debug amb el paràmeter "--new" crea un projecte nou en eixe directori.
- [NEW] Nou sistema de log
- [FIX] Amb el tema de usar std::vector no s'estava inicialitzant la surface de pantalla correctament.
- [FIX] Proteccions per a que no pete quan s'intenta usar funcions que els fa falta una surface de oritge, pero no hi ha ninguna seleccionada.
- [NEW] file_createFolder() (ATENCIÓ: No funcionarà en Windows encara)
This commit is contained in:
2025-12-03 14:05:52 +01:00
parent ace4a0f9f0
commit 3e524fd32d
9 changed files with 133 additions and 69 deletions

View File

@@ -3,6 +3,7 @@
#include "stb_vorbis.h" #include "stb_vorbis.h"
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <stdio.h> #include <stdio.h>
#include "log.h"
#define JA_MAX_SIMULTANEOUS_CHANNELS 5 #define JA_MAX_SIMULTANEOUS_CHANNELS 5
@@ -146,14 +147,13 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels)
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
#endif #endif
SDL_Log("Iniciant JailAudio...");
JA_audioSpec = {format, channels, freq }; JA_audioSpec = {format, channels, freq };
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice); if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec); sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
if (!sdlAudioDevice) { if (!sdlAudioDevice) {
SDL_Log("Failed to initialize SDL audio: %s\n", SDL_GetError()); log_msg(LOG_FAIL, "Failed to initialize SDL audio: %s\n", SDL_GetError());
} else { } else {
SDL_Log( "JailAudio OK!\n"); log_msg(LOG_OK, "Audio subsytem initialized\n");
} }
//SDL_PauseAudioDevice(sdlAudioDevice); //SDL_PauseAudioDevice(sdlAudioDevice);
JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr); JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
@@ -217,9 +217,9 @@ void JA_PlayMusic(JA_Music_t *music, const int loop)
current_music->times = loop; current_music->times = loop;
current_music->stream = SDL_CreateAudioStream(&current_music->spec, &JA_audioSpec); current_music->stream = SDL_CreateAudioStream(&current_music->spec, &JA_audioSpec);
if (!SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length)) printf("[ERROR] SDL_PutAudioStreamData failed!\n"); if (!SDL_PutAudioStreamData(current_music->stream, current_music->buffer, current_music->length)) log_msg(LOG_FAIL, "SDL_PutAudioStreamData failed!\n");
SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume); SDL_SetAudioStreamGain(current_music->stream, JA_musicVolume);
if (!SDL_BindAudioStream(sdlAudioDevice, current_music->stream)) printf("[ERROR] SDL_BindAudioStream failed!\n"); if (!SDL_BindAudioStream(sdlAudioDevice, current_music->stream)) log_msg(LOG_FAIL, "SDL_BindAudioStream failed!\n");
//SDL_ResumeAudioStreamDevice(current_music->stream); //SDL_ResumeAudioStreamDevice(current_music->stream);
} }

View File

@@ -271,3 +271,10 @@ void file_setconfigvalue(const char* key, const char* value) {
file_saveconfigvalues(); file_saveconfigvalues();
return; return;
} }
bool file_createFolder(const char* name) {
char tmp[256];
strcpy(tmp, "./");
strcat(tmp, name);
return mkdir(tmp, 0755)==0;
}

View File

@@ -19,3 +19,5 @@ char *file_getfilebufferex(const char *filename, int& filesize, const bool zero_
const char* file_getconfigvalue(const char *key); const char* file_getconfigvalue(const char *key);
void file_setconfigvalue(const char* key, const char* value); void file_setconfigvalue(const char* key, const char* value);
bool file_createFolder(const char* name);

View File

@@ -150,13 +150,13 @@ namespace shader
shader::backBuffer = backBuffer; shader::backBuffer = backBuffer;
SDL_GetWindowSize(win, &win_size.x, &win_size.y); SDL_GetWindowSize(win, &win_size.x, &win_size.y);
SDL_GetTextureSize(backBuffer, &tex_size.x, &tex_size.y); SDL_GetTextureSize(backBuffer, &tex_size.x, &tex_size.y);
printf("tex size: %fx%f\n", tex_size.x, tex_size.y); //printf("tex size: %fx%f\n", tex_size.x, tex_size.y);
SDL_PropertiesID props = SDL_GetTextureProperties(backBuffer); SDL_PropertiesID props = SDL_GetTextureProperties(backBuffer);
texture_number = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER, -1); texture_number = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER, -1);
printf("texture number: %i\n", texture_number); //printf("texture number: %i\n", texture_number);
int access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, -1); int access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, -1);
nose = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER, -1); nose = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET_NUMBER, -1);
printf("texture target number: %i\n", nose); //printf("texture target number: %i\n", nose);
if (access != SDL_TEXTUREACCESS_TARGET) if (access != SDL_TEXTUREACCESS_TARGET)
{ {
@@ -165,7 +165,7 @@ namespace shader
} }
const char * renderer_name = SDL_GetRendererName(renderer); const char * renderer_name = SDL_GetRendererName(renderer);
printf("rendererInfo.name: %s\n", renderer_name); //printf("rendererInfo.name: %s\n", renderer_name);
if(!strncmp(renderer_name, "opengl", 6)) { if(!strncmp(renderer_name, "opengl", 6)) {
#ifndef __APPLE__ #ifndef __APPLE__

27
log.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
#include <stdio.h>
#include <stdarg.h>
#ifdef DEBUG
enum LogLevel { LOG_OK, LOG_FAIL, LOG_WARN, LOG_INFO, LOG_LUART, LOG_LUALD, LOG_VERBOSE, LOG_UNSALTED };
static inline void log_msg(enum LogLevel level, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
switch (level) {
case LOG_OK: printf("[\033[1;32m OK \033[0m] "); break;
case LOG_FAIL: printf("[\033[1;31mFAIL\033[0m] "); break;
case LOG_WARN: printf("[\033[1;33mWARN\033[0m] "); break;
case LOG_INFO: printf("[\033[1;34mINFO\033[0m] "); break;
case LOG_LUART: printf("[\033[1;35mLUA RUNTIME ERROR\033[0m] "); break;
case LOG_LUALD: printf("[\033[1;35mLUA LOADING ERROR\033[0m] "); break;
case LOG_VERBOSE: printf(" - "); break;
case LOG_UNSALTED: break;
}
vprintf(fmt, args);
va_end(args);
}
#else
#define log_msg(...) ((void)0)
#endif

28
lua.cpp
View File

@@ -2,7 +2,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#include "mini.h" #include "mini.h"
#include "jfile.h" #include "jfile.h"
#include "log.h"
#include <filesystem> #include <filesystem>
namespace fs = std::filesystem; namespace fs = std::filesystem;
@@ -1181,8 +1181,7 @@ int MiniLoader(lua_State *L) {
int size; int size;
char* buffer = file_getfilebuffer(filename, size); char* buffer = file_getfilebuffer(filename, size);
if (luaL_loadbuffer(L, buffer, size, filename)) { if (luaL_loadbuffer(L, buffer, size, filename)) {
debug("REQUIRE LOADING ERROR: "); log_msg(LOG_LUALD, "%s\n",lua_tostring(L, -1));
debug("%s\n",lua_tostring(L, -1));
lua_pop(L,1); lua_pop(L,1);
//return ; //return ;
} }
@@ -1200,19 +1199,14 @@ void lua_init(const char *main_lua_file) {
int size; int size;
char* buffer = file_getfilebuffer(main_lua_file, size); char* buffer = file_getfilebuffer(main_lua_file, size);
if (luaL_loadbuffer(L, buffer, size, "main")) { if (luaL_loadbuffer(L, buffer, size, "main")) {
debug("LOADING ERROR: "); log_msg(LOG_LUALD, "%s\n", lua_tostring(L, -1));
debug("%s\n",lua_tostring(L, -1));
lua_pop(L,1); lua_pop(L,1);
return; return;
} }
free(buffer); free(buffer);
if (lua_pcall(L,0, LUA_MULTRET, 0)) { if (lua_pcall(L,0, LUA_MULTRET, 0)) {
debug("RUNTIME ERROR [BOOT]: "); //luaL_traceback(L, L, NULL, 1);
//debug("%s\n",lua_tostring(L, -1)); log_msg(LOG_LUART, "%s\n", lua_tostring(L, -1));
//lua_pop(L,1);
luaL_traceback(L, L, NULL, 1);
debug("%s\n", lua_tostring(L, -1));
lua_pop(L,1); lua_pop(L,1);
return; return;
} }
@@ -1238,11 +1232,7 @@ void lua_call_init() {
lua_getglobal(L, "mini"); lua_getglobal(L, "mini");
lua_getfield(L, -1, "init"); lua_getfield(L, -1, "init");
if (lua_pcall(L, 0, 0, 0)) { if (lua_pcall(L, 0, 0, 0)) {
debug("RUNTIME ERROR [INIT]: "); log_msg(LOG_LUART, "%s\n", lua_tostring(L, -1));
debug("%s\n",lua_tostring(L, -1));
lua_pop(L,1);
luaL_traceback(L, L, NULL, 1);
debug("%s\n", lua_tostring(L, -1));
lua_pop(L,1); lua_pop(L,1);
is_playing = false; is_playing = false;
} }
@@ -1255,11 +1245,7 @@ void lua_call_update() {
lua_getglobal(L, "mini"); lua_getglobal(L, "mini");
lua_getfield(L, -1, "update"); lua_getfield(L, -1, "update");
if (lua_pcall(L, 0, 0, 0)) { if (lua_pcall(L, 0, 0, 0)) {
debug("RUNTIME ERROR [UPDATE]: "); log_msg(LOG_LUART, "%s\n", lua_tostring(L, -1));
debug("%s\n",lua_tostring(L, -1));
lua_pop(L,1);
luaL_traceback(L, L, NULL, 1);
debug("%s\n", lua_tostring(L, -1));
lua_pop(L,1); lua_pop(L,1);
is_playing = false; is_playing = false;
} }

116
mini.cpp
View File

@@ -7,6 +7,7 @@
#include "jail_audio.h" #include "jail_audio.h"
#include "jshader.h" #include "jshader.h"
#include <vector> #include <vector>
#include "log.h"
//#define MAX_TEXTURES 100 //#define MAX_TEXTURES 100
@@ -47,8 +48,8 @@ int desktop_width = 0;
int desktop_height = 0; int desktop_height = 0;
std::vector<surface_t> surfaces; std::vector<surface_t> surfaces;
surface_t *screen_surface = &surfaces[0]; surface_t *screen_surface = NULL; //&surfaces[0];
surface_t *dest_surface = screen_surface; surface_t *dest_surface = NULL; //screen_surface;
surface_t *source_surface = NULL; surface_t *source_surface = NULL;
surface_t *map_surface = NULL; surface_t *map_surface = NULL;
@@ -122,6 +123,8 @@ JA_Sound_t *sounds[MAX_SOUNDS];
int16_t beats, num_beats = 0; int16_t beats, num_beats = 0;
void createNewProject();
char* get_value_from_line(char* line) { char* get_value_from_line(char* line) {
char* equal_character = strchr(line, '='); char* equal_character = strchr(line, '=');
if (equal_character == NULL) return NULL; if (equal_character == NULL) return NULL;
@@ -131,21 +134,20 @@ char* get_value_from_line(char* line) {
void read_ini() { void read_ini() {
int size; int size;
SDL_Log("Carregant 'game.ini'...");
FILE *f = file_getfilepointer("game.ini", size); // fopen("game.ini", "r"); FILE *f = file_getfilepointer("game.ini", size); // fopen("game.ini", "r");
char line[1024]; char line[1024];
if (f == NULL) { SDL_Log("FAIL!\n"); return; } if (f == NULL) { log_msg(LOG_FAIL, "No s'ha pogut obrir 'game.ini'"); exit(-1); }
SDL_Log("OK!\n"); log_msg(LOG_OK, "'game.ini' carregat");
while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) {
char *value = get_value_from_line(line); char *value = get_value_from_line(line);
if (value != NULL) { if (value != NULL) {
value[strlen(value)-1] = '\0'; value[strlen(value)-1] = '\0';
if (strcmp(line, "title") == 0) { strcpy(window_title, value); SDL_Log("-title=%s\n", window_title); } if (strcmp(line, "title") == 0) { strcpy(window_title, value); log_msg(LOG_VERBOSE, "title = %s\n", window_title); }
else if (strcmp(line, "config") == 0) { strcpy(config_folder, value); SDL_Log("-config=%s\n", config_folder); } else if (strcmp(line, "config") == 0) { strcpy(config_folder, value); log_msg(LOG_VERBOSE, "config = %s\n", config_folder); }
else if (strcmp(line, "width") == 0) { screen_width = atoi(value); SDL_Log("-screen width=%i\n", screen_width); } else if (strcmp(line, "width") == 0) { screen_width = atoi(value); log_msg(LOG_VERBOSE, "screen width = %i\n", screen_width); }
else if (strcmp(line, "height") == 0) { screen_height = atoi(value); SDL_Log("-screen height=%i\n", screen_height); } else if (strcmp(line, "height") == 0) { screen_height = atoi(value); log_msg(LOG_VERBOSE, "screen height = %i\n", screen_height); }
else if (strcmp(line, "zoom") == 0) { screen_zoom = atoi(value); SDL_Log("-screen zoom=%i\n", screen_zoom); } else if (strcmp(line, "zoom") == 0) { screen_zoom = atoi(value); log_msg(LOG_VERBOSE, "screen zoom = %i\n", screen_zoom); }
else if (strcmp(line, "fullscreen") == 0) { screen_fullscreen = atoi(value); SDL_Log("-screen sullscreen=%i\n", screen_fullscreen); } else if (strcmp(line, "fullscreen") == 0) { screen_fullscreen = atoi(value); log_msg(LOG_VERBOSE, "screen sullscreen = %i\n", screen_fullscreen); }
//else if (strcmp(line, "files") == 0) { //else if (strcmp(line, "files") == 0) {
//lua_files = (char*)malloc(strlen(value)); //lua_files = (char*)malloc(strlen(value));
// strcpy(lua_files, value); // strcpy(lua_files, value);
@@ -153,7 +155,7 @@ void read_ini() {
} }
} }
fclose(f); fclose(f);
SDL_Log("'game.ini' carregat!\n"); //SDL_Log("'game.ini' carregat!\n");
} }
void pset_fast(int x, int y) { void pset_fast(int x, int y) {
@@ -171,7 +173,7 @@ void pset_pattern(int x, int y) {
} }
void reinit() { void reinit() {
SDL_Log("REINIT\n"); log_msg(LOG_INFO, "STARTING A SYSTEM REINITIALIZATION\n");
do_pset = pset_fast; do_pset = pset_fast;
ds::pen_color = 6; ds::pen_color = 6;
ds::back_color = 0; ds::back_color = 0;
@@ -181,13 +183,14 @@ void reinit() {
ds::trans=0; ds::trans=0;
ds::fill_pattern = 0b1111111111111111; ds::fill_pattern = 0b1111111111111111;
ds::fill_trans = false; ds::fill_trans = false;
for (int i=1; i<surfaces.size(); ++i) { for (unsigned int i=1; i<surfaces.size(); ++i) {
if (surfaces[i].p != NULL) free(surfaces[i].p); if (surfaces[i].p != NULL) free(surfaces[i].p);
surfaces[i].p = NULL; surfaces[i].p = NULL;
if (surfaces[i].name != NULL) free(surfaces[i].name); if (surfaces[i].name != NULL) free(surfaces[i].name);
surfaces[i].name = NULL; surfaces[i].name = NULL;
} }
surfaces.clear(); surfaces.clear();
dest_surface = screen_surface;
for (int i=0;i<256;++i) ds::draw_palette[i]=i; for (int i=0;i<256;++i) ds::draw_palette[i]=i;
if (file!=NULL) fclose(file); if (file!=NULL) fclose(file);
@@ -214,23 +217,23 @@ int scrh() {
} }
uint8_t newsurf(int w, int h) { uint8_t newsurf(int w, int h) {
int i = 0; unsigned int i = 0;
while (i<surfaces.size() && surfaces[i].p != NULL) ++i; while (i<surfaces.size() && surfaces[i].p != NULL) ++i;
if (i==i<surfaces.size()) surfaces.emplace_back(); if (i==surfaces.size()) surfaces.emplace_back();
surfaces[i].name = nullptr; surfaces[i].name = nullptr;
surfaces[i].w = w; surfaces[i].w = w;
surfaces[i].h = h; surfaces[i].h = h;
surfaces[i].size = w*h; surfaces[i].size = w*h;
surfaces[i].p = (uint8_t*)calloc(surfaces[i].size,1); surfaces[i].p = (uint8_t*)calloc(surfaces[i].size,1);
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Surface %i creada.\n", i); log_msg(LOG_INFO, "Surface %i creada.\n", i);
return i; return i;
} }
uint8_t loadsurf(const char* filename, const bool external) { uint8_t loadsurf(const char* filename, const bool external) {
// Si el gif ja s'ha carregat en una textura, tornem eixa textura // Si el gif ja s'ha carregat en una textura, tornem eixa textura
for (int i=0; i<surfaces.size(); ++i) for (unsigned int i=0; i<surfaces.size(); ++i)
if (surfaces[i].name && strcmp(surfaces[i].name, filename)==0) { if (surfaces[i].name && strcmp(surfaces[i].name, filename)==0) {
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Carrega de '%s' abortada: Reusant: %i.\n", filename, i); log_msg(LOG_INFO, "Carrega de '%s' abortada: Reusant: %i.\n", filename, i);
return i; return i;
} }
@@ -245,14 +248,15 @@ uint8_t loadsurf(const char* filename, const bool external) {
// Si no s'ha pogut, petar // Si no s'ha pogut, petar
if (!buffer) { if (!buffer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al intentar obrir l'arxiu '%s'\n", filename); log_msg(LOG_FAIL, "Error al intentar obrir l'arxiu '%s'\n", filename);
exit(-1);
return 255; return 255;
} }
// Agafar la pròxima textura lliure // Agafar la pròxima textura lliure
int i = 0; unsigned int i = 0;
while (i<surfaces.size() && surfaces[i].p != NULL) ++i; while (i<surfaces.size() && surfaces[i].p != NULL) ++i;
if (i==i<surfaces.size()) surfaces.emplace_back(); if (i==surfaces.size()) surfaces.emplace_back();
surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h); surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h);
surfaces[i].size = surfaces[i].w*surfaces[i].h; surfaces[i].size = surfaces[i].w*surfaces[i].h;
@@ -260,7 +264,7 @@ uint8_t loadsurf(const char* filename, const bool external) {
strcpy(surfaces[i].name, filename); strcpy(surfaces[i].name, filename);
free(buffer); free(buffer);
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Carregat '%s': Surface: %i.\n", filename, i); log_msg(LOG_INFO, "Arxiu '%s' carregat en surface: %i.\n", filename, i);
return i; return i;
} }
@@ -274,7 +278,7 @@ void freesurf(uint8_t surface) {
surfaces[surface].name = NULL; surfaces[surface].name = NULL;
if (surfaces[surface].p != NULL) { if (surfaces[surface].p != NULL) {
free(surfaces[surface].p); free(surfaces[surface].p);
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Surface %i alliberada.\n", surface); log_msg(LOG_INFO, "Surface %i alliberada.\n", surface);
} }
surfaces[surface].p = NULL; surfaces[surface].p = NULL;
} }
@@ -314,7 +318,7 @@ void setmap(uint8_t surface) {
uint8_t getmap() uint8_t getmap()
{ {
for (int i=0; i<surfaces.size(); ++i) if (map_surface == &surfaces[i]) return i; for (unsigned int i=0; i<surfaces.size(); ++i) if (map_surface == &surfaces[i]) return i;
return 0; return 0;
} }
@@ -347,7 +351,7 @@ void createDisplay() {
SDL_PropertiesID props = SDL_GetTextureProperties(mini_bak); SDL_PropertiesID props = SDL_GetTextureProperties(mini_bak);
int real_pixelformat = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, -1); int real_pixelformat = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, -1);
if (real_pixelformat != SDL_PIXELFORMAT_ARGB8888) { if (real_pixelformat != SDL_PIXELFORMAT_ARGB8888) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Pixelformat incorrecte: %i\n", real_pixelformat); log_msg(LOG_FAIL, "Pixelformat incorrecte: %i\n", real_pixelformat);
exit(1); exit(1);
} }
mini_shadertex = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, screen_width*screen_zoom, screen_height*screen_zoom); mini_shadertex = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, screen_width*screen_zoom, screen_height*screen_zoom);
@@ -357,6 +361,7 @@ void createDisplay() {
//char *shaderfile = file_getfilebuffer("lynx.glsl", filesize); //char *shaderfile = file_getfilebuffer("lynx.glsl", filesize);
shader::init(mini_win, mini_shadertex, nullptr); shader::init(mini_win, mini_shadertex, nullptr);
//SDL_GetWindowPosition(mini_win, &windowpos_x, &windowpos_y); //SDL_GetWindowPosition(mini_win, &windowpos_x, &windowpos_y);
log_msg(LOG_OK, "Graphics subsystem initialized\n");
} }
void destroyDisplay() { void destroyDisplay() {
@@ -374,6 +379,7 @@ void initGamePad() {
gamepad = SDL_OpenGamepad(joysticks[i]); gamepad = SDL_OpenGamepad(joysticks[i]);
if (SDL_GamepadConnected(gamepad)) { if (SDL_GamepadConnected(gamepad)) {
SDL_SetGamepadEventsEnabled(true); SDL_SetGamepadEventsEnabled(true);
log_msg(LOG_OK, "Gamepad found and initialized");
return; return;
} }
} }
@@ -387,9 +393,19 @@ int main(int argc,char*argv[]){
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG); SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
#endif #endif
#ifdef DEBUG
log_msg(LOG_UNSALTED, "MINI v%s\n",MINI_VERSION);
#endif
if (argc>1) if (argc>1)
{ {
if (strstr(argv[1], ".lua")!=nullptr) { if (argv[1][0]=='-' && argv[1][1]=='-') {
const char *command = &argv[1][2];
if (strcmp(command, "new")==0) {
createNewProject();
exit(0);
}
} else if (strstr(argv[1], ".lua")!=nullptr) {
file_setresourcefolder("./"); file_setresourcefolder("./");
file_setsource(SOURCE_FOLDER); file_setsource(SOURCE_FOLDER);
strcpy(main_lua_file, argv[1]); strcpy(main_lua_file, argv[1]);
@@ -402,6 +418,7 @@ int main(int argc,char*argv[]){
} }
} }
screen_surface = &surfaces.emplace_back();
while (!should_quit) { while (!should_quit) {
should_exit=false; should_exit=false;
@@ -440,11 +457,6 @@ int main(int argc,char*argv[]){
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD);
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay()); const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
if (!dm)
{
SDL_Log("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError());
return 1;
}
desktop_width = dm->w; desktop_width = dm->w;
desktop_height = dm->h; desktop_height = dm->h;
@@ -458,9 +470,7 @@ int main(int argc,char*argv[]){
reinit(); reinit();
initaudio(); initaudio();
#ifdef DEBUG
debug("MINI v%s\n",MINI_VERSION);
#endif
lua_init(main_lua_file); lua_init(main_lua_file);
lua_call_init(); lua_call_init();
@@ -573,7 +583,7 @@ int main(int argc,char*argv[]){
//Mix_Quit(); //Mix_Quit();
for (int i=0;i<surfaces.size();++i) freesurf(i); for (unsigned int i=0;i<surfaces.size();++i) freesurf(i);
surfaces.clear(); surfaces.clear();
dest_surface = source_surface = map_surface = NULL; dest_surface = source_surface = map_surface = NULL;
destroyDisplay(); destroyDisplay();
@@ -1052,11 +1062,13 @@ void ovalfill(int x0, int y0, int x1, int y1, uint8_t color) {
} }
uint8_t sget(int x, int y) { uint8_t sget(int x, int y) {
if (!source_surface) return 0;
if (x < 0 || x > (source_surface->w-1) || y < 0 || y > (source_surface->h-1)) return 0; if (x < 0 || x > (source_surface->w-1) || y < 0 || y > (source_surface->h-1)) return 0;
return SOURCE(x, y); return SOURCE(x, y);
} }
void sset(int x, int y) { void sset(int x, int y) {
if (!source_surface) return;
if (x < 0 || x > (source_surface->w-1) || y < 0 || y > (source_surface->h-1)) return; if (x < 0 || x > (source_surface->w-1) || y < 0 || y > (source_surface->h-1)) return;
SOURCE(x, y) = ds::pen_color; SOURCE(x, y) = ds::pen_color;
} }
@@ -1067,6 +1079,7 @@ void sset(int x, int y, uint8_t color) {
} }
void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) { void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) {
if (!source_surface) return;
int tx = (n%(source_surface->w >> 3))<<3; int tx = (n%(source_surface->w >> 3))<<3;
int ty = (n/(source_surface->w >> 3))<<3; int ty = (n/(source_surface->w >> 3))<<3;
int tw = w*8 - 1; int tw = w*8 - 1;
@@ -1469,3 +1482,34 @@ void exit() {
should_exit = true; should_exit = true;
should_quit = true; should_quit = true;
} }
void createNewProject() {
if (file_createFolder("data")) {
log_msg(LOG_OK, "Directori 'data' creat\n");
} else {
log_msg(LOG_FAIL, "No s'ha pogut crear la carpeta 'data'\n");
exit(-1);
}
FILE *f = fopen("./data/game.ini", "w");
if (f) {
log_msg(LOG_OK, "Arxiu 'data/game.ini' creat\n");
} else {
log_msg(LOG_FAIL, "No s'ha pogut crear l'arxiu 'data/game.ini'\n");
exit(-1);
}
fprintf(f, "title=NEW MINI PROJECT\nconfig=newminiproject\nwidth=320\nheight=240\nzoom=2\n");
fclose(f);
f = fopen("./data/main.lua", "w");
if (f) {
log_msg(LOG_OK, "Arxiu 'data/main.lua' creat\n");
} else {
log_msg(LOG_FAIL, "No s'ha pogut crear l'arxiu 'data/main.lua'\n");
exit(-1);
}
fprintf(f, "function mini.init()\n\nend\n\nfunction mini.update()\n surf.cls(0)\nend\n");
fclose(f);
log_msg(LOG_OK, "Projecte nou creat. Ja està fet lo més dificil del jailgame!\n");
}

2
mini.h
View File

@@ -233,8 +233,6 @@ bool beat(int16_t i);
int rnd(int x); int rnd(int x);
int getfps(); int getfps();
#define debug printf
void playmusic(const char *filename, const int loop=-1); void playmusic(const char *filename, const int loop=-1);
void pausemusic(); void pausemusic();
void resumemusic(); void resumemusic();

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define MINI_VERSION "1.3.12" #define MINI_VERSION "1.3.13"