mirror of https://git.sr.ht/~kikoodx/sle
Fix very bad casting mistake & dummy verbose mode
This commit is contained in:
parent
dcd4afc520
commit
0dc7fb3914
10
README
10
README
|
@ -55,8 +55,10 @@ All these options take a path to a file as argument.
|
|||
|
||||
Optionnal flags
|
||||
---------------
|
||||
All these options take integers as argument.
|
||||
These flags are boolean toggles. They take no option.
|
||||
-verbose
|
||||
|
||||
All these flags take integers as argument.
|
||||
-tile-width
|
||||
-tile-height
|
||||
-editor-width
|
||||
|
@ -72,6 +74,12 @@ DEFAULT CONFIGURATION
|
|||
Edit include/conf.h to change default configuration. Read the comments!
|
||||
Don't forget to recompile after you made your modifications.
|
||||
|
||||
DEBUG FEATURES
|
||||
==============
|
||||
The following features are enabled with the -verbose flag.
|
||||
Pressing middle mouse button in the editor will print the value of the
|
||||
tile pointed to STDIN.
|
||||
|
||||
LICENSE
|
||||
=======
|
||||
Copyright (C) 2021 KikooDX <kikoodx@paranoici.org>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Copyright (C) 2021 KikooDX */
|
||||
#pragma once
|
||||
|
||||
#define INFO(message) \
|
||||
{ \
|
||||
extern int verbose; \
|
||||
if (verbose) \
|
||||
printf("[%s:%d] " message "\n", __FILE__, \
|
||||
__LINE__); \
|
||||
}
|
||||
#define INFO_VAR(format, var) \
|
||||
{ \
|
||||
extern int verbose; \
|
||||
if (verbose) \
|
||||
printf("[%s:%d] " format "\n", __FILE__, \
|
||||
__LINE__, var); \
|
||||
}
|
|
@ -16,13 +16,13 @@ void level_draw(struct Level level, struct Options options,
|
|||
for (y = 0; y < level.height; y += 1) {
|
||||
const int tile_index = x + y * level.width;
|
||||
/* if tile index is out of bound, skip */
|
||||
if (tile_index >= level.width *
|
||||
level.height)
|
||||
if (tile_index >= level.width * level.height)
|
||||
continue;
|
||||
const Tile tile =
|
||||
level.data[x + y * level.width];
|
||||
/* if tile is not in tileset, skip */
|
||||
if (!tile || tile >= options.tileset_width * options.tileset_height)
|
||||
if (!tile || tile >= options.tileset_width *
|
||||
options.tileset_height)
|
||||
continue;
|
||||
|
||||
const Rectangle tile_rect = {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/* Copyright (C) 2021 KikooDX */
|
||||
|
||||
#include "editing_area/level.h"
|
||||
#include "info.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -91,10 +92,11 @@ void level_free(struct Level *level) { free(level->data); }
|
|||
|
||||
int level_write(struct Level level, char *path)
|
||||
{
|
||||
INFO("write begin");
|
||||
FILE *file = NULL;
|
||||
int tile = 0;
|
||||
int tile_size = 0;
|
||||
int max_tile_size = 1;
|
||||
unsigned int tile_size = 0;
|
||||
unsigned int max_tile_size = 1;
|
||||
int i = 0;
|
||||
const int level_size = level.width * level.height;
|
||||
|
||||
|
@ -105,16 +107,23 @@ int level_write(struct Level level, char *path)
|
|||
path);
|
||||
return -1;
|
||||
}
|
||||
INFO("file opened");
|
||||
|
||||
INFO("look for longest value in data");
|
||||
/* find longest value in data (in bytes) */
|
||||
for (i = 0; i < level_size; i += 1) {
|
||||
tile = level.data[i];
|
||||
tile_size = 1;
|
||||
while (tile >>= 8)
|
||||
while (tile >>= 8) {
|
||||
tile_size += 1;
|
||||
if (tile_size > max_tile_size)
|
||||
INFO_VAR("%d", tile);
|
||||
}
|
||||
if (tile_size > max_tile_size) {
|
||||
max_tile_size = tile_size;
|
||||
}
|
||||
}
|
||||
INFO("max tile size is");
|
||||
INFO_VAR("%d", max_tile_size);
|
||||
|
||||
/* write KBLE format version */
|
||||
write_byte(file, kble_fmt_version);
|
||||
|
@ -133,6 +142,7 @@ int level_write(struct Level level, char *path)
|
|||
/* close file */
|
||||
fclose(file);
|
||||
|
||||
INFO("write end");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -144,7 +154,7 @@ static int read_byte(FILE *file)
|
|||
fprintf(stderr, "ERROR: unexpected EOF\n");
|
||||
return -1;
|
||||
}
|
||||
return (char)byte;
|
||||
return (unsigned char)byte;
|
||||
}
|
||||
|
||||
/* Read multiple bytes and "merge" them into one integer. Return -1 if
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "editing_area/draw.h"
|
||||
#include "editing_area/level.h"
|
||||
#include "info.h"
|
||||
#include "mouse.h"
|
||||
#include "options.h"
|
||||
#include "shared_data.h"
|
||||
|
@ -97,6 +98,7 @@ static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
|
|||
{
|
||||
const bool left_click = IsMouseButtonDown(0);
|
||||
const bool right_click = IsMouseButtonDown(1);
|
||||
const bool middle_click = IsMouseButtonPressed(2);
|
||||
|
||||
update_mouse_position(mouse_x, mouse_y, level.width - 1,
|
||||
level.height - 1);
|
||||
|
@ -110,4 +112,9 @@ static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
|
|||
if (right_click) {
|
||||
level.data[*mouse_x + *mouse_y * level.width] = 0;
|
||||
}
|
||||
/* get info about tile */
|
||||
if (middle_click) {
|
||||
INFO_VAR("%d",
|
||||
level.data[*mouse_x + *mouse_y * level.width]);
|
||||
}
|
||||
}
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -16,6 +16,8 @@
|
|||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int verbose = 0;
|
||||
|
||||
static void *create_shared_memory(size_t size);
|
||||
static void overflow_prevention(void); /* work on optarg */
|
||||
static void process_arguments(int argc, char **argv,
|
||||
|
@ -89,6 +91,7 @@ static void process_arguments(int argc, char **argv,
|
|||
int opt;
|
||||
while (1) {
|
||||
static struct option long_options[] = {
|
||||
{"verbose", no_argument, &verbose, 1},
|
||||
{"level", required_argument, 0, 'l'},
|
||||
{"tileset", required_argument, 0, 't'},
|
||||
{"tile-width", required_argument, 0, 'w'},
|
||||
|
@ -157,11 +160,7 @@ static void process_arguments(int argc, char **argv,
|
|||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"ERROR: option -%c non handled "
|
||||
"(open an issue!)\n",
|
||||
opt);
|
||||
exit(EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* missing arguments? */
|
||||
|
@ -193,6 +192,7 @@ static int int_arg_min(int opt, int min)
|
|||
opt, min, value);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static void set_tileset_dimensions(struct Options *options)
|
||||
|
|
Loading…
Reference in New Issue