VERSIÓ 1.3.14
- [NEW] draw.pattern() sense paràmetres restableix el patró de relleno - [FIX] Llevat el std::vector que estava donant pel cul. No, si ja sabia jo... - [NEW] Gestió del cas en que es supere el nombre màxim de textures (en compte d'explotar, tira un error bonico)
This commit is contained in:
42
mini.cpp
42
mini.cpp
@@ -6,10 +6,10 @@
|
||||
#include "gifenc.h"
|
||||
#include "jail_audio.h"
|
||||
#include "jshader.h"
|
||||
#include <vector>
|
||||
//#include <vector>
|
||||
#include "log.h"
|
||||
|
||||
//#define MAX_TEXTURES 100
|
||||
#define MAX_SURFACES 100
|
||||
|
||||
#ifdef MACOS_BUNDLE
|
||||
#include <libgen.h>
|
||||
@@ -47,9 +47,9 @@ bool screen_cursor = true;
|
||||
int desktop_width = 0;
|
||||
int desktop_height = 0;
|
||||
|
||||
std::vector<surface_t> surfaces;
|
||||
surface_t *screen_surface = NULL; //&surfaces[0];
|
||||
surface_t *dest_surface = NULL; //screen_surface;
|
||||
surface_t surfaces[MAX_SURFACES];
|
||||
surface_t *screen_surface = &surfaces[0];
|
||||
surface_t *dest_surface = screen_surface;
|
||||
surface_t *source_surface = NULL;
|
||||
surface_t *map_surface = NULL;
|
||||
|
||||
@@ -136,8 +136,8 @@ void read_ini() {
|
||||
int size;
|
||||
FILE *f = file_getfilepointer("game.ini", size); // fopen("game.ini", "r");
|
||||
char line[1024];
|
||||
if (f == NULL) { log_msg(LOG_FAIL, "No s'ha pogut obrir 'game.ini'"); exit(-1); }
|
||||
log_msg(LOG_OK, "'game.ini' carregat");
|
||||
if (f == NULL) { log_msg(LOG_FAIL, "No s'ha pogut obrir 'game.ini'\n"); exit(-1); }
|
||||
log_msg(LOG_OK, "'game.ini' carregat\n");
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
char *value = get_value_from_line(line);
|
||||
if (value != NULL) {
|
||||
@@ -183,13 +183,14 @@ void reinit() {
|
||||
ds::trans=0;
|
||||
ds::fill_pattern = 0b1111111111111111;
|
||||
ds::fill_trans = false;
|
||||
for (unsigned int i=1; i<surfaces.size(); ++i) {
|
||||
for (unsigned int i=1; i<MAX_SURFACES; ++i) freesurf(i);
|
||||
/*{
|
||||
if (surfaces[i].p != NULL) free(surfaces[i].p);
|
||||
surfaces[i].p = NULL;
|
||||
if (surfaces[i].name != NULL) free(surfaces[i].name);
|
||||
surfaces[i].name = NULL;
|
||||
}
|
||||
surfaces.clear();
|
||||
surfaces.clear();*/
|
||||
dest_surface = screen_surface;
|
||||
|
||||
for (int i=0;i<256;++i) ds::draw_palette[i]=i;
|
||||
@@ -218,8 +219,8 @@ int scrh() {
|
||||
|
||||
uint8_t newsurf(int w, int h) {
|
||||
unsigned int i = 0;
|
||||
while (i<surfaces.size() && surfaces[i].p != NULL) ++i;
|
||||
if (i==surfaces.size()) surfaces.emplace_back();
|
||||
while (i<MAX_SURFACES && surfaces[i].p != NULL) ++i;
|
||||
if (i==MAX_SURFACES) return 255;
|
||||
surfaces[i].name = nullptr;
|
||||
surfaces[i].w = w;
|
||||
surfaces[i].h = h;
|
||||
@@ -231,12 +232,17 @@ uint8_t newsurf(int w, int h) {
|
||||
|
||||
uint8_t loadsurf(const char* filename, const bool external) {
|
||||
// Si el gif ja s'ha carregat en una textura, tornem eixa textura
|
||||
for (unsigned int i=0; i<surfaces.size(); ++i)
|
||||
for (unsigned int i=0; i<MAX_SURFACES; ++i)
|
||||
if (surfaces[i].name && strcmp(surfaces[i].name, filename)==0) {
|
||||
log_msg(LOG_INFO, "Carrega de '%s' abortada: Reusant: %i.\n", filename, i);
|
||||
return i;
|
||||
}
|
||||
|
||||
// Agafar la pròxima textura lliure
|
||||
unsigned int i = 0;
|
||||
while (i<MAX_SURFACES && surfaces[i].p != NULL) ++i;
|
||||
if (i==MAX_SURFACES) return 255;
|
||||
|
||||
// Carregar l'arxiu de disc
|
||||
int size;
|
||||
uint8_t *buffer;
|
||||
@@ -253,11 +259,6 @@ uint8_t loadsurf(const char* filename, const bool external) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
// Agafar la pròxima textura lliure
|
||||
unsigned int i = 0;
|
||||
while (i<surfaces.size() && surfaces[i].p != NULL) ++i;
|
||||
if (i==surfaces.size()) surfaces.emplace_back();
|
||||
|
||||
surfaces[i].p = LoadGif(buffer, &surfaces[i].w, &surfaces[i].h);
|
||||
surfaces[i].size = surfaces[i].w*surfaces[i].h;
|
||||
surfaces[i].name = (char*)malloc(strlen(filename)+1);
|
||||
@@ -318,7 +319,7 @@ void setmap(uint8_t surface) {
|
||||
|
||||
uint8_t getmap()
|
||||
{
|
||||
for (unsigned int i=0; i<surfaces.size(); ++i) if (map_surface == &surfaces[i]) return i;
|
||||
for (unsigned int i=0; i<MAX_SURFACES; ++i) if (map_surface == &surfaces[i]) return i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -418,7 +419,7 @@ int main(int argc,char*argv[]){
|
||||
}
|
||||
}
|
||||
|
||||
screen_surface = &surfaces.emplace_back();
|
||||
//screen_surface = &surfaces.emplace_back();
|
||||
while (!should_quit) {
|
||||
should_exit=false;
|
||||
|
||||
@@ -583,8 +584,7 @@ int main(int argc,char*argv[]){
|
||||
|
||||
//Mix_Quit();
|
||||
|
||||
for (unsigned int i=0;i<surfaces.size();++i) freesurf(i);
|
||||
surfaces.clear();
|
||||
for (unsigned int i=0;i<MAX_SURFACES;++i) freesurf(i);
|
||||
dest_surface = source_surface = map_surface = NULL;
|
||||
destroyDisplay();
|
||||
SDL_Quit();
|
||||
|
||||
Reference in New Issue
Block a user