Better .clang-format (maybe I added some useless things: I don't know what the LLVM style sets the settings to)

This commit is contained in:
mibi88 2024-07-29 21:04:23 +02:00
parent 84d83d85c0
commit 2ca939430d
13 changed files with 114 additions and 104 deletions

View file

@ -1,7 +1,12 @@
BasedOnStyle: LLVM BasedOnStyle: LLVM
IndentWidth: 4 IndentWidth: 4
PointerAlignment: Right PointerAlignment: Right
SpaceBeforeParens: Custom SpaceBeforeAssignmentOperators: true
SpaceBeforeParensOptions: BreakBeforeBinaryOperators: true
AfterControlStatements: false SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpaceBeforeParens: Never
IndentCaseBlocks: true
IncludeBlocks: Regroup
AllowShortBlocksOnASingleLine: Empty

View file

@ -1,15 +1,14 @@
#include "dialogs.h" #include "dialogs.h"
#include <gint/cpu.h>
#include <gint/keyboard.h>
#include <string.h>
#include "config.h" #include "config.h"
#include "events.h" #include "events.h"
#include "game.h" #include "game.h"
#include "npc.h" #include "npc.h"
#include <gint/cpu.h>
#include <gint/keyboard.h>
#include <string.h>
#define BOX_HEIGHT (F_HEIGHT / PXSIZE + 8) #define BOX_HEIGHT (F_HEIGHT / PXSIZE + 8)
#define CHOICE_BOX_HEIGHT 10 #define CHOICE_BOX_HEIGHT 10
@ -46,8 +45,8 @@ int dialogs_text_opt(Game *game, bopti_image_t *face, char *text,
dfont(&FONT_USED); dfont(&FONT_USED);
unsigned int i, n, y = PXSIZE, l = 0; unsigned int i, n, y = PXSIZE, l = 0;
int line_max_chars, return_int = 0; int line_max_chars, return_int = 0;
unsigned int max_lines_amount = unsigned int max_lines_amount
(BOX_HEIGHT - 2) * PXSIZE / (FONT_USED.line_height + PXSIZE); = (BOX_HEIGHT - 2) * PXSIZE / (FONT_USED.line_height + PXSIZE);
const char *c; const char *c;
if(start_anim) { if(start_anim) {
/* Run a little fancy animation. */ /* Run a little fancy animation. */
@ -146,10 +145,11 @@ int dialogs_text_opt(Game *game, bopti_image_t *face, char *text,
/* If we drew one entire screen. */ /* If we drew one entire screen. */
/* Wait that the SHIFT key is pressed if we should. */ /* Wait that the SHIFT key is pressed if we should. */
if(wait_continue) { if(wait_continue) {
while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT
~GETKEY_MOD_ALPHA, & ~GETKEY_MOD_ALPHA,
NULL) NULL)
.key != KEY_SHIFT) { .key
!= KEY_SHIFT) {
sleep(); sleep();
} }
} }
@ -180,10 +180,11 @@ int dialogs_text_opt(Game *game, bopti_image_t *face, char *text,
if(update_screen) if(update_screen)
blit(); blit();
if(wait_continue) { if(wait_continue) {
while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & while(getkey_opt(GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT
~GETKEY_MOD_ALPHA, & ~GETKEY_MOD_ALPHA,
NULL) NULL)
.key != KEY_SHIFT) { .key
!= KEY_SHIFT) {
sleep(); sleep();
} }
} }

View file

@ -4,6 +4,7 @@
#include "config.h" #include "config.h"
#include "game.h" #include "game.h"
#include "map.h" #include "map.h"
#include <gint/display.h> #include <gint/display.h>
#include <string.h> #include <string.h>

View file

@ -1,4 +1,5 @@
#include "events.h" #include "events.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -38,8 +39,8 @@ int _op_mod(int a, int b) {
return a % b; return a % b;
} }
int (*_operations[OP_AMOUNT])(int, int) = {_op_null, _op_set, _op_add, _op_sub, int (*_operations[OP_AMOUNT])(int, int)
_op_div, _op_mul, _op_mod}; = {_op_null, _op_set, _op_add, _op_sub, _op_div, _op_mul, _op_mod};
#define MIN(a, b) a < b ? a : b #define MIN(a, b) a < b ? a : b

View file

@ -1,8 +1,8 @@
#include "game.h" #include "game.h"
#include "map.h"
#include "config.h" #include "config.h"
#include "map.h"
#include "npc.h"
#include <gint/cpu.h> #include <gint/cpu.h>
#include <gint/display.h> #include <gint/display.h>
@ -10,8 +10,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "npc.h"
extern bopti_image_t SignAction_img; extern bopti_image_t SignAction_img;
extern Dialog *dialogRPG; extern Dialog *dialogRPG;
@ -28,13 +26,13 @@ void game_logic(Game *game) {
for(uint32_t i = 0; i < game->map_level->nbextradata; i++) { for(uint32_t i = 0; i < game->map_level->nbextradata; i++) {
/* simple distance check along X and Y axis */ /* simple distance check along X and Y axis */
/* Be careful to use world coordinates, not local (i.e.map) ones */ /* Be careful to use world coordinates, not local (i.e.map) ones */
if((abs((int)game->player.wx - if((abs((int)game->player.wx
(int)game->map_level->extradata[i].x * PXSIZE) < - (int)game->map_level->extradata[i].x * PXSIZE)
MAX_INTERACTION_DISTANCE * PXSIZE) && < MAX_INTERACTION_DISTANCE * PXSIZE)
(abs((int)game->player.wy - && (abs((int)game->player.wy
(int)game->map_level->extradata[i].y * PXSIZE) < - (int)game->map_level->extradata[i].y * PXSIZE)
MAX_INTERACTION_DISTANCE * PXSIZE) && < MAX_INTERACTION_DISTANCE * PXSIZE)
strcmp(game->map_level->extradata[i].type, "NPC") != 0) { && strcmp(game->map_level->extradata[i].type, "NPC") != 0) {
/* the player can do something */ /* the player can do something */
game->player.canDoSomething = true; game->player.canDoSomething = true;
/* we mark the action for futur treatment in player_action() */ /* we mark the action for futur treatment in player_action() */
@ -48,11 +46,11 @@ void game_logic(Game *game) {
for(uint32_t i = 0; i < nbNPC; i++) { for(uint32_t i = 0; i < nbNPC; i++) {
/* simple distance check along X and Y axis */ /* simple distance check along X and Y axis */
/* Be careful to use world coordinates, not local (i.e.map) ones */ /* Be careful to use world coordinates, not local (i.e.map) ones */
if((abs((int)game->player.wx - (int)npcRPG[i].curx * PXSIZE) < if((abs((int)game->player.wx - (int)npcRPG[i].curx * PXSIZE)
MAX_INTERACTION_DISTANCE * PXSIZE) && < MAX_INTERACTION_DISTANCE * PXSIZE)
(abs((int)game->player.wy - (int)npcRPG[i].cury * PXSIZE) < && (abs((int)game->player.wy - (int)npcRPG[i].cury * PXSIZE)
MAX_INTERACTION_DISTANCE * PXSIZE) && < MAX_INTERACTION_DISTANCE * PXSIZE)
strcmp(game->map_level->extradata[i].type, "NPC") != 0) { && strcmp(game->map_level->extradata[i].type, "NPC") != 0) {
/* the player can do something */ /* the player can do something */
game->player.canDoSomething = true; game->player.canDoSomething = true;
/* we mark the action for futur treatment in player_action() */ /* we mark the action for futur treatment in player_action() */

View file

@ -1,11 +1,11 @@
#ifndef GAME_H #ifndef GAME_H
#define GAME_H #define GAME_H
#include "events.h"
#include <gint/display.h> #include <gint/display.h>
#include <stdint.h> #include <stdint.h>
#include "events.h"
/* The direction where the player is going to. */ /* The direction where the player is going to. */
typedef enum { D_UP, D_DOWN, D_LEFT, D_RIGHT } Direction; typedef enum { D_UP, D_DOWN, D_LEFT, D_RIGHT } Direction;

View file

@ -1,15 +1,14 @@
#include <gint/cpu.h>
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/timer.h>
#include <fxlibc/printf.h>
#include "config.h" #include "config.h"
#include "events.h" #include "events.h"
#include "npc.h" #include "npc.h"
#include <fxlibc/printf.h>
#include <gint/cpu.h>
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/timer.h>
#if USB_FEATURE #if USB_FEATURE
#include <gint/usb-ff-bulk.h> #include <gint/usb-ff-bulk.h>
#include <gint/usb.h> #include <gint/usb.h>
@ -19,13 +18,12 @@
#include <gint/gray.h> #include <gint/gray.h>
#endif // GRAYMODEOK #endif // GRAYMODEOK
#include <stdbool.h> #include "dialogs.h"
#include <stdint.h>
#include "game.h" #include "game.h"
#include "mapdata.h" #include "mapdata.h"
#include "dialogs.h" #include <stdbool.h>
#include <stdint.h>
extern bopti_image_t player_face_img; extern bopti_image_t player_face_img;

View file

@ -1,4 +1,5 @@
#include "map.h" #include "map.h"
#include "config.h" #include "config.h"
#include "game.h" #include "game.h"
@ -80,8 +81,8 @@ void map_render(Game *game) {
for(x = 0; x < dw; x++) { for(x = 0; x < dw; x++) {
/* I get the tile number if his position is inside the map. Then /* I get the tile number if his position is inside the map. Then
* I draw it. */ * I draw it. */
if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0 && if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0
ty + y < map_level->h) { && ty + y < map_level->h) {
/* index of the current tile */ /* index of the current tile */
current_index = (y + ty) * map_level->w + tx + x; current_index = (y + ty) * map_level->w + tx + x;
/* we get the ID of the tile in the current drawable layers /* we get the ID of the tile in the current drawable layers
@ -172,8 +173,8 @@ void map_render_by_layer(Game *game, int layer) {
for(x = 0; x < dw; x++) { for(x = 0; x < dw; x++) {
/* I get the tile number if his position is inside the map. Then /* I get the tile number if his position is inside the map. Then
* I draw it. */ * I draw it. */
if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0 && if(tx + x >= 0 && tx + x < map_level->w && ty + y >= 0
ty + y < map_level->h) { && ty + y < map_level->h) {
/* index of the current tile */ /* index of the current tile */
int currentIndex = (y + ty) * map_level->w + tx + x; int currentIndex = (y + ty) * map_level->w + tx + x;
/* we get the ID of the tile in the current drawable layers /* we get the ID of the tile in the current drawable layers
@ -219,8 +220,8 @@ short int map_get_walkable(Game *game, int x, int y) {
/* return the pointer to the map containing the given position */ /* return the pointer to the map containing the given position */
Map *map_get_for_coordinates(Game *game, int x, int y) { Map *map_get_for_coordinates(Game *game, int x, int y) {
/* check if the current map contains the point */ /* check if the current map contains the point */
if(x >= (int)game->map_level->xmin && x < (int)game->map_level->xmax && if(x >= (int)game->map_level->xmin && x < (int)game->map_level->xmax
y >= (int)game->map_level->ymin && y < (int)game->map_level->ymax) { && y >= (int)game->map_level->ymin && y < (int)game->map_level->ymax) {
return game->map_level; return game->map_level;
} }
@ -228,8 +229,8 @@ Map *map_get_for_coordinates(Game *game, int x, int y) {
int i = 0; int i = 0;
Map *current = worldRPG[i]; Map *current = worldRPG[i];
do { do {
if(x >= (int)current->xmin && x < (int)current->xmax && if(x >= (int)current->xmin && x < (int)current->xmax
y >= (int)current->ymin && y < (int)current->ymax) && y >= (int)current->ymin && y < (int)current->ymax)
return current; return current;
i++; i++;
current = worldRPG[i]; current = worldRPG[i];

View file

@ -2,6 +2,7 @@
#define MAPDATA_H #define MAPDATA_H
#include "game.h" #include "game.h"
#include <stdint.h> #include <stdint.h>
extern Map *worldRPG[]; extern Map *worldRPG[];

View file

@ -1,11 +1,12 @@
#include "npc.h" #include "npc.h"
#include "config.h" #include "config.h"
#include "dialogs.h" #include "dialogs.h"
#include "game.h" #include "game.h"
#include "map.h" #include "map.h"
#include <gint/display.h> #include <gint/display.h>
#include <gint/keyboard.h> /*debug*/ #include <gint/keyboard.h> /*debug*/
#include <math.h> #include <math.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -185,8 +186,8 @@ int npc_pathfind(int32_t dest_x, int32_t dest_y, Map *full_map, NPC *npc) {
if(att_score < gscore[j * w + i]) { if(att_score < gscore[j * w + i]) {
came_from[j * w + i] = by * w + bx; came_from[j * w + i] = by * w + bx;
gscore[j * w + i] = att_score; gscore[j * w + i] = att_score;
fscore[j * w + i] = fscore[j * w + i]
att_score + round(length(dest_x - i, dest_y - j)); = att_score + round(length(dest_x - i, dest_y - j));
if(visited[j * w + i]) if(visited[j * w + i])
visited[j * w + i] = 0; visited[j * w + i] = 0;
} }
@ -314,20 +315,20 @@ void npc_draw(Game *game) {
int NbPoints = Data->path_length + 1; int NbPoints = Data->path_length + 1;
for(int v = 0; v < NbPoints; v++) { for(int v = 0; v < NbPoints; v++) {
int16_t deltaX1 = int16_t deltaX1
((int16_t)(Data->x + Data->xpath[v % NbPoints]) * PXSIZE) - = ((int16_t)(Data->x + Data->xpath[v % NbPoints]) * PXSIZE)
(int16_t)pl->wx; - (int16_t)pl->wx;
int16_t deltaY1 = int16_t deltaY1
((int16_t)(Data->y + Data->ypath[v % NbPoints]) * PXSIZE) - = ((int16_t)(Data->y + Data->ypath[v % NbPoints]) * PXSIZE)
(int16_t)pl->wy; - (int16_t)pl->wy;
int16_t deltaX2 = int16_t deltaX2
((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints]) * = ((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints])
PXSIZE) - * PXSIZE)
(int16_t)pl->wx; - (int16_t)pl->wx;
int16_t deltaY2 = int16_t deltaY2
((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints]) * = ((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints])
PXSIZE) - * PXSIZE)
(int16_t)pl->wy; - (int16_t)pl->wy;
dline(pl->px + deltaX1, pl->py + deltaY1, pl->px + deltaX2, dline(pl->px + deltaX1, pl->py + deltaY1, pl->px + deltaX2,
pl->py + deltaY2, PATH_COLOR); pl->py + deltaY2, PATH_COLOR);
@ -368,23 +369,23 @@ void OLD_npc_draw(Game *game) {
int NbPoints = Data->path_length + 1; int NbPoints = Data->path_length + 1;
for(int v = 0; v < NbPoints; v++) { for(int v = 0; v < NbPoints; v++) {
int16_t deltaX1 = int16_t deltaX1
((int16_t)(Data->x + Data->xpath[v % NbPoints]) * = ((int16_t)(Data->x + Data->xpath[v % NbPoints])
PXSIZE) - * PXSIZE)
(int16_t)player->wx; - (int16_t)player->wx;
int16_t deltaY1 = int16_t deltaY1
((int16_t)(Data->y + Data->ypath[v % NbPoints]) * = ((int16_t)(Data->y + Data->ypath[v % NbPoints])
PXSIZE) - * PXSIZE)
(int16_t)player->wy; - (int16_t)player->wy;
int16_t deltaX2 = int16_t deltaX2
((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints]) * = ((int16_t)(Data->x + Data->xpath[(v + 1) % NbPoints])
PXSIZE) - * PXSIZE)
(int16_t)player->wx; - (int16_t)player->wx;
int16_t deltaY2 = int16_t deltaY2
((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints]) * = ((int16_t)(Data->y + Data->ypath[(v + 1) % NbPoints])
PXSIZE) - * PXSIZE)
(int16_t)player->wy; - (int16_t)player->wy;
dline(player->px + deltaX1, player->py + deltaY1, dline(player->px + deltaX1, player->py + deltaY1,
player->px + deltaX2, player->py + deltaY2, player->px + deltaX2, player->py + deltaY2,
@ -394,10 +395,10 @@ void OLD_npc_draw(Game *game) {
#endif // DEBUGMODE #endif // DEBUGMODE
int16_t deltaX = int16_t deltaX
((int16_t)(Data->x * PXSIZE)) - (int16_t)player->wx; = ((int16_t)(Data->x * PXSIZE)) - (int16_t)player->wx;
int16_t deltaY = int16_t deltaY
((int16_t)(Data->y * PXSIZE)) - (int16_t)player->wy; = ((int16_t)(Data->y * PXSIZE)) - (int16_t)player->wy;
dimage(player->px - P_WIDTH / 2 + deltaX, dimage(player->px - P_WIDTH / 2 + deltaX,
player->py - P_HEIGHT / 2 + deltaY, &tiny_npc_male); player->py - P_HEIGHT / 2 + deltaY, &tiny_npc_male);
} }

View file

@ -1,12 +1,12 @@
#ifndef NPC_H #ifndef NPC_H
#define NPC_H #define NPC_H
#include <stdbool.h>
#include <stdint.h>
#include "game.h" #include "game.h"
#include "memory.h" #include "memory.h"
#include <stdbool.h>
#include <stdint.h>
enum { enum {
NPC_NONE = 0, NPC_NONE = 0,

View file

@ -1,9 +1,11 @@
#include "player.h" #include "player.h"
#include "config.h" #include "config.h"
#include "dialogs.h" #include "dialogs.h"
#include "game.h" #include "game.h"
#include "map.h" #include "map.h"
#include "npc.h" #include "npc.h"
#include <gint/display.h> #include <gint/display.h>
extern bopti_image_t player_male_img; extern bopti_image_t player_male_img;
@ -65,8 +67,8 @@ void player_move(Game *game, Direction direction) {
player_fix_position(game, dx, dy); player_fix_position(game, dx, dy);
} else { } else {
if(player_collision(game, direction, P_RIGHTDOWN) || if(player_collision(game, direction, P_RIGHTDOWN)
player_collision(game, direction, P_LEFTUP)) { || player_collision(game, direction, P_LEFTUP)) {
/* If the will collide with the edges of the player. */ /* If the will collide with the edges of the player. */
/* I fix his position so he won't be partially in the tile. */ /* I fix his position so he won't be partially in the tile. */
@ -102,8 +104,8 @@ void player_action(Game *game) {
/* we indicate that the player is occupied */ /* we indicate that the player is occupied */
game->player.isDoingAction = true; game->player.isDoingAction = true;
ExtraData *currentData = ExtraData *currentData
&game->map_level->extradata[game->player.whichAction]; = &game->map_level->extradata[game->player.whichAction];
/* we use the correct image as per the class of the item */ /* we use the correct image as per the class of the item */
@ -135,8 +137,8 @@ void player_action(Game *game) {
/* when done we release the occupied status of the player */ /* when done we release the occupied status of the player */
game->player.isDoingAction = false; game->player.isDoingAction = false;
} else if(game->player.canDoSomething && } else if(game->player.canDoSomething
game->player.isInteractingWithNPC) { && game->player.isInteractingWithNPC) {
/* we can do something (action IS with an NPC) */ /* we can do something (action IS with an NPC) */
/* we indicate that the player is occupied */ /* we indicate that the player is occupied */
game->player.isDoingAction = true; game->player.isDoingAction = true;
@ -145,8 +147,8 @@ void player_action(Game *game) {
/* we use the correct image as per the class of the item */ /* we use the correct image as per the class of the item */
ExtraData *currentData = ExtraData *currentData
&game->map_level->extradata[game->player.whichAction]; = &game->map_level->extradata[game->player.whichAction];
bopti_image_t *face = &npc_male; bopti_image_t *face = &npc_male;
/* It's a NPC */ /* It's a NPC */
/* (Mibi88) TODO: Use string hash + strcmp if the hashes match for /* (Mibi88) TODO: Use string hash + strcmp if the hashes match for

View file

@ -4,6 +4,7 @@
#include "config.h" #include "config.h"
#include "game.h" #include "game.h"
#include "memory.h" #include "memory.h"
#include <stdbool.h> #include <stdbool.h>
typedef struct { typedef struct {