mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2024-11-16 11:27:33 -08:00
Slightly refactor some C tools
This commit is contained in:
parent
e068f9cf69
commit
1a6b051119
2
Makefile
2
Makefile
@ -60,7 +60,7 @@ clean: tidy
|
|||||||
find gfx/pokemon -mindepth 1 ! -path "gfx/pokemon/unown/*" \( -name "bitmask.asm" -o -name "frames.asm" -o -name "front.animated.tilemap" -o -name "front.dimensions" \) -delete
|
find gfx/pokemon -mindepth 1 ! -path "gfx/pokemon/unown/*" \( -name "bitmask.asm" -o -name "frames.asm" -o -name "front.animated.tilemap" -o -name "front.dimensions" \) -delete
|
||||||
|
|
||||||
tidy:
|
tidy:
|
||||||
rm -f $(roms) $(pokecrystal_obj) $(pokecrystal11_obj) $(pokecrystal_au_obj) $(pokecrystal_debug_obj) $(pokecrystal11_debug_obj) $(roms:.gbc=.map) $(roms:.gbc=.sym) rgbdscheck.o
|
$(RM) $(roms) $(pokecrystal_obj) $(pokecrystal11_obj) $(pokecrystal_au_obj) $(pokecrystal_debug_obj) $(pokecrystal11_debug_obj) $(roms:.gbc=.map) $(roms:.gbc=.sym) rgbdscheck.o
|
||||||
$(MAKE) clean -C tools/
|
$(MAKE) clean -C tools/
|
||||||
|
|
||||||
compare: $(roms)
|
compare: $(roms)
|
||||||
|
@ -11,11 +11,12 @@ tools := \
|
|||||||
pokemon_animation_graphics \
|
pokemon_animation_graphics \
|
||||||
scan_includes \
|
scan_includes \
|
||||||
stadium
|
stadium
|
||||||
|
|
||||||
all: $(tools)
|
all: $(tools)
|
||||||
@:
|
@:
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(tools)
|
$(RM) $(tools)
|
||||||
|
|
||||||
gfx: common.h
|
gfx: common.h
|
||||||
png_dimensions: common.h
|
png_dimensions: common.h
|
||||||
|
15
tools/gfx.c
15
tools/gfx.c
@ -134,15 +134,12 @@ void remove_whitespace(struct Graphic *graphic) {
|
|||||||
graphic->size &= ~(tile_size - 1);
|
graphic->size &= ~(tile_size - 1);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (int j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
|
for (int j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
|
||||||
while (j < graphic->size && is_whitespace(&graphic->data[j], tile_size) && !is_preserved(j / tile_size - d)) {
|
for (; j < graphic->size && is_whitespace(&graphic->data[j], tile_size) && !is_preserved(j / tile_size - d); j += tile_size, d++) {
|
||||||
shift_preserved(j / tile_size - d);
|
shift_preserved(j / tile_size - d);
|
||||||
d++;
|
|
||||||
j += tile_size;
|
|
||||||
}
|
}
|
||||||
if (j >= graphic->size) {
|
if (j >= graphic->size) {
|
||||||
break;
|
break;
|
||||||
}
|
} else if (j > i) {
|
||||||
if (j > i) {
|
|
||||||
memcpy(&graphic->data[i], &graphic->data[j], tile_size);
|
memcpy(&graphic->data[i], &graphic->data[j], tile_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,13 +167,11 @@ void remove_duplicates(struct Graphic *graphic) {
|
|||||||
graphic->size &= ~(tile_size - 1);
|
graphic->size &= ~(tile_size - 1);
|
||||||
int num_tiles = 0;
|
int num_tiles = 0;
|
||||||
for (int i = 0, j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
|
for (int i = 0, j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
|
||||||
while (j < graphic->size && tile_exists(&graphic->data[j], graphic->data, tile_size, num_tiles)) {
|
for (; j < graphic->size && tile_exists(&graphic->data[j], graphic->data, tile_size, num_tiles); j += tile_size, d++) {
|
||||||
if ((options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) || is_preserved(j / tile_size - d)) {
|
if ((options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) || is_preserved(j / tile_size - d)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
shift_preserved(j / tile_size - d);
|
shift_preserved(j / tile_size - d);
|
||||||
d++;
|
|
||||||
j += tile_size;
|
|
||||||
}
|
}
|
||||||
if (j >= graphic->size) {
|
if (j >= graphic->size) {
|
||||||
break;
|
break;
|
||||||
@ -227,13 +222,11 @@ void remove_flip(struct Graphic *graphic, bool xflip, bool yflip) {
|
|||||||
graphic->size &= ~(tile_size - 1);
|
graphic->size &= ~(tile_size - 1);
|
||||||
int num_tiles = 0;
|
int num_tiles = 0;
|
||||||
for (int i = 0, j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
|
for (int i = 0, j = 0, d = 0; i < graphic->size && j < graphic->size; i += tile_size, j += tile_size) {
|
||||||
while (j < graphic->size && flip_exists(&graphic->data[j], graphic->data, tile_size, num_tiles, xflip, yflip)) {
|
for (; j < graphic->size && flip_exists(&graphic->data[j], graphic->data, tile_size, num_tiles, xflip, yflip); j += tile_size, d++) {
|
||||||
if ((options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) || is_preserved(j / tile_size - d)) {
|
if ((options.keep_whitespace && is_whitespace(&graphic->data[j], tile_size)) || is_preserved(j / tile_size - d)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
shift_preserved(j / tile_size - d);
|
shift_preserved(j / tile_size - d);
|
||||||
d++;
|
|
||||||
j += tile_size;
|
|
||||||
}
|
}
|
||||||
if (j >= graphic->size) {
|
if (j >= graphic->size) {
|
||||||
break;
|
break;
|
||||||
|
@ -47,17 +47,16 @@ void scan_file(const char *filename, bool strict) {
|
|||||||
ptr = strchr(ptr, '\n');
|
ptr = strchr(ptr, '\n');
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
fprintf(stderr, "%s: no newline at end of file\n", filename);
|
fprintf(stderr, "%s: no newline at end of file\n", filename);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
ptr++;
|
ptr++;
|
||||||
ptr = strchr(ptr, '"');
|
ptr = strchr(ptr, '"');
|
||||||
if (!ptr) {
|
if (ptr) {
|
||||||
fprintf(stderr, "%s: unterminated string\n", filename);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ptr++;
|
ptr++;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "%s: unterminated string\n", filename);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'I':
|
case 'I':
|
||||||
case 'i':
|
case 'i':
|
||||||
@ -65,9 +64,7 @@ void scan_file(const char *filename, bool strict) {
|
|||||||
is_include = !strncmp(ptr, "INCLUDE", 7) || !strncmp(ptr, "include", 7);
|
is_include = !strncmp(ptr, "INCLUDE", 7) || !strncmp(ptr, "include", 7);
|
||||||
if (is_incbin || is_include) {
|
if (is_incbin || is_include) {
|
||||||
ptr = strchr(ptr, '"');
|
ptr = strchr(ptr, '"');
|
||||||
if (!ptr) {
|
if (ptr) {
|
||||||
break;
|
|
||||||
}
|
|
||||||
ptr++;
|
ptr++;
|
||||||
char *include_path = ptr;
|
char *include_path = ptr;
|
||||||
size_t length = strcspn(ptr, "\"");
|
size_t length = strcspn(ptr, "\"");
|
||||||
@ -78,6 +75,7 @@ void scan_file(const char *filename, bool strict) {
|
|||||||
scan_file(include_path, strict);
|
scan_file(include_path, strict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user