Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code formatting with clang-format #16

Merged
merged 13 commits into from
Nov 19, 2023
Merged
  •  
  •  
  •  
24 changes: 24 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignArrayOfStructures: Left
AllowShortBlocksOnASingleLine: Empty
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Empty
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Allman
ColumnLimit: 160
IncludeBlocks: Regroup
IndentWidth: 4
IndentWrappedFunctionNames: true
InsertNewlineAtEOF: true
NamespaceIndentation: All
PackConstructorInitializers: Never
PointerAlignment: Left
SeparateDefinitionBlocks: Always
SortUsingDeclarations: Lexicographic
SpaceAfterTemplateKeyword: false
24 changes: 24 additions & 0 deletions .github/workflows/check-formatting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: check-formatting

on:
pull_request:

jobs:
check-formatting:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1
with:
version: "17.0"

- name: Test formatting for all files
working-directory: ${{ github.workspace }}
run: |
export CLANG_FORMAT_BIN="${LLVM_PATH}/bin/clang-format"
./scripts/check-format.sh
8 changes: 8 additions & 0 deletions scripts/check-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# Go to repository root
cd "$(dirname "$0")/.." || exit 2

CLANG_FORMAT_BIN="${CLANG_FORMAT_BIN:-clang-format}"

find ./src ./test -iname '*.h' -o -iname '*.cpp' | xargs $CLANG_FORMAT_BIN -Werror -ferror-limit=1 --dry-run
6 changes: 6 additions & 0 deletions scripts/reformat-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Go to repository root
cd "$(dirname "$0")/.." || exit 2

find ./src ./test -iname '*.h' -o -iname '*.cpp' | xargs clang-format --verbose -i
5 changes: 3 additions & 2 deletions src/Common/Game/IGame.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#include <vector>
#include "GameLanguage.h"

#include <vector>

class Zone;

class IGame
Expand All @@ -20,4 +21,4 @@ class IGame
virtual void RemoveZone(Zone* zone) = 0;
virtual std::vector<Zone*> GetZones() = 0;
virtual std::vector<GameLanguagePrefix> GetLanguagePrefixes() = 0;
};
};
4 changes: 2 additions & 2 deletions src/Common/Game/IW3/CommonIW3.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace IW3
static constexpr uint32_t R_HashString(const char* string, const uint32_t hash)
{
const char* v2 = string; // edx@1
char v3 = *string; // cl@1
char v3 = *string; // cl@1
uint32_t result = hash;

for (; *v2; v3 = *v2)
Expand All @@ -28,4 +28,4 @@ namespace IW3
static void Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out);
static void Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out);
};
}
} // namespace IW3
4 changes: 2 additions & 2 deletions src/Common/Game/IW3/GameIW3.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "GameIW3.h"

#include <algorithm>

#include "IW3.h"

#include <algorithm>

using namespace IW3;

GameIW3 g_GameIW3;
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Game/IW3/GameIW3.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class GameIW3 : public IGame
std::vector<GameLanguagePrefix> GetLanguagePrefixes() override;
};

extern GameIW3 g_GameIW3;
extern GameIW3 g_GameIW3;
8 changes: 6 additions & 2 deletions src/Common/Game/IW3/IW3.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#pragma once

//#include <d3d11.h>
// clang-format off: Order of includes matters here

// #include <d3d9.h>
#include "Image/Texture.h"

#include "IW3_Assets.h"

// clang-format on

namespace IW3
{
struct ScriptStringList
Expand Down Expand Up @@ -79,4 +83,4 @@ namespace IW3

WFT_NUM_FIELD_TYPES
};
}
} // namespace IW3
106 changes: 53 additions & 53 deletions src/Common/Game/IW3/IW3_Assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace IW3
ASSET_TYPE_RAWFILE = 0x1F,
ASSET_TYPE_STRINGTABLE = 0x20,
ASSET_TYPE_COUNT,

ASSET_TYPE_STRING = ASSET_TYPE_COUNT,
ASSET_TYPE_ASSETLIST,

Expand Down Expand Up @@ -100,35 +100,35 @@ namespace IW3
union XAssetHeader
{
// XModelPieces *xmodelPieces; // NOT AN ASSET
PhysPreset *physPreset;
XAnimParts *parts;
XModel *model;
Material *material;
MaterialPixelShader *pixelShader;
MaterialVertexShader *vertexShader;
MaterialTechniqueSet *techniqueSet;
GfxImage *image;
snd_alias_list_t *sound;
SndCurve *sndCurve;
LoadedSound *loadSnd;
clipMap_t *clipMap;
ComWorld *comWorld;
GameWorldSp *gameWorldSp;
GameWorldMp *gameWorldMp;
MapEnts *mapEnts;
GfxWorld *gfxWorld;
GfxLightDef *lightDef;
Font_s *font;
MenuList *menuList;
menuDef_t *menu;
LocalizeEntry *localize;
WeaponDef *weapon;
SndDriverGlobals *sndDriverGlobals;
FxEffectDef *fx;
FxImpactTable *impactFx;
RawFile *rawfile;
StringTable *stringTable;
void *data;
PhysPreset* physPreset;
XAnimParts* parts;
XModel* model;
Material* material;
MaterialPixelShader* pixelShader;
MaterialVertexShader* vertexShader;
MaterialTechniqueSet* techniqueSet;
GfxImage* image;
snd_alias_list_t* sound;
SndCurve* sndCurve;
LoadedSound* loadSnd;
clipMap_t* clipMap;
ComWorld* comWorld;
GameWorldSp* gameWorldSp;
GameWorldMp* gameWorldMp;
MapEnts* mapEnts;
GfxWorld* gfxWorld;
GfxLightDef* lightDef;
Font_s* font;
MenuList* menuList;
menuDef_t* menu;
LocalizeEntry* localize;
WeaponDef* weapon;
SndDriverGlobals* sndDriverGlobals;
FxEffectDef* fx;
FxImpactTable* impactFx;
RawFile* rawfile;
StringTable* stringTable;
void* data;
};

typedef char cbrushedge_t;
Expand All @@ -142,7 +142,7 @@ namespace IW3
XModel* model;
float offset[3];
};

struct XModelPieces
{
const char* name;
Expand All @@ -152,14 +152,14 @@ namespace IW3

struct PhysPreset
{
const char *name;
const char* name;
int type;
float mass;
float bounce;
float friction;
float bulletForceScale;
float explosiveForceScale;
const char *sndAliasPrefix;
const char* sndAliasPrefix;
float piecesSpreadFraction;
float piecesUpwardVelocity;
bool tempDefaultToCylinder;
Expand Down Expand Up @@ -224,7 +224,7 @@ namespace IW3

struct XAnimDeltaPartQuatDataFrames
{
XQuat *frames;
XQuat* frames;
XAnimDynamicIndicesQuat indices;
};

Expand Down Expand Up @@ -371,7 +371,7 @@ namespace IW3
char zoneHandle;
uint16_t baseTriIndex;
uint16_t baseVertIndex;
r_index16_t(*triIndices)[3];
r_index16_t (*triIndices)[3];
XSurfaceVertexInfo vertInfo;
GfxPackedVertex* verts0;
unsigned int vertListCount;
Expand Down Expand Up @@ -485,8 +485,8 @@ namespace IW3
char lodRampType;
uint16_t* boneNames;
char* parentList;
int16_t(*quats)[4];
float(*trans)[4];
int16_t (*quats)[4];
float (*trans)[4];
char* partClassification;
DObjAnimMat* baseMat;
XSurface* surfs;
Expand Down Expand Up @@ -705,7 +705,7 @@ namespace IW3
char nameStart;
char nameEnd;
unsigned char samplerState; // SamplerStateBits_e
unsigned char semantic; // TextureSemantic
unsigned char semantic; // TextureSemantic
MaterialTextureDefInfo u;
};

Expand Down Expand Up @@ -820,7 +820,7 @@ namespace IW3

union MaterialArgumentDef
{
const float(*literalConst)[4];
const float (*literalConst)[4];
MaterialArgumentCodeConst codeConst;
unsigned int codeSampler;
unsigned int nameHash;
Expand Down Expand Up @@ -1156,7 +1156,7 @@ namespace IW3
struct MaterialVertexStreamRouting
{
MaterialStreamRouting data[16];
void/*IDirect3DVertexDeclaration9*/* decl[16];
void /*IDirect3DVertexDeclaration9*/* decl[16];
};

struct MaterialVertexDeclaration
Expand All @@ -1176,7 +1176,7 @@ namespace IW3

struct MaterialVertexShaderProgram
{
void/*IDirect3DVertexShader9*/* vs;
void /*IDirect3DVertexShader9*/* vs;
GfxVertexShaderLoadDef loadDef;
};

Expand All @@ -1195,7 +1195,7 @@ namespace IW3

struct MaterialPixelShaderProgram
{
void/*IDirect3DPixelShader9*/* ps;
void /*IDirect3DPixelShader9*/* ps;
GfxPixelShaderLoadDef loadDef;
};

Expand Down Expand Up @@ -1304,10 +1304,10 @@ namespace IW3

union GfxTexture
{
//void/*IDirect3DBaseTexture9*/* basemap;
//void/*IDirect3DTexture9*/* map;
//void/*IDirect3DVolumeTexture9*/* volmap;
//void/*IDirect3DCubeTexture9*/* cubemap;
// void/*IDirect3DBaseTexture9*/* basemap;
// void/*IDirect3DTexture9*/* map;
// void/*IDirect3DVolumeTexture9*/* volmap;
// void/*IDirect3DCubeTexture9*/* cubemap;
Texture* texture;
GfxImageLoadDef* loadDef;
};
Expand Down Expand Up @@ -1681,7 +1681,7 @@ namespace IW3
unsigned int numLeafSurfaces;
unsigned int* leafsurfaces;
unsigned int vertCount;
vec3_t *verts;
vec3_t* verts;
int triCount;
uint16_t* triIndices;
char* triEdgeIsWalkable;
Expand Down Expand Up @@ -1898,13 +1898,13 @@ namespace IW3
struct GfxWorldVertexData
{
GfxWorldVertex* vertices;
void/*IDirect3DVertexBuffer9*/* worldVb;
void /*IDirect3DVertexBuffer9*/* worldVb;
};

struct GfxWorldVertexLayerData
{
char* data;
void/*IDirect3DVertexBuffer9*/* layerVb;
void /*IDirect3DVertexBuffer9*/* layerVb;
};

struct SunLightParseParams
Expand Down Expand Up @@ -1979,7 +1979,7 @@ namespace IW3
bool isAncestor;
char recursionDepth;
char hullPointCount;
float(*hullPoints)[2];
float (*hullPoints)[2];
GfxPortal* queuedParent;
};

Expand Down Expand Up @@ -3076,13 +3076,13 @@ namespace IW3
// TODO: Order is accuracyGraphName[0] -> originalAccuracyGraphKnots[0] -> accuracyGraphName[1] -> ...
// Which is currently not possible to do in code generation. Afaik this is the only place where this is the case.
// So might be something to fix but on the other hand it might be too much work for this little inconvenience.
//const char* accuracyGraphName[2];
// const char* accuracyGraphName[2];
const char* accuracyGraphName0;
const char* accuracyGraphName1;
//float(*accuracyGraphKnots[2])[2];
// float(*accuracyGraphKnots[2])[2];
vec2_t* accuracyGraphKnots0;
vec2_t* accuracyGraphKnots1;
//float(*originalAccuracyGraphKnots[2])[2];
// float(*originalAccuracyGraphKnots[2])[2];
vec2_t* originalAccuracyGraphKnots0;
vec2_t* originalAccuracyGraphKnots1;
int accuracyGraphKnotCount[2];
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Game/IW4/CommonIW4.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace IW4
static constexpr uint32_t R_HashString(const char* string, const uint32_t hash)
{
const char* v2 = string; // edx@1
char v3 = *string; // cl@1
char v3 = *string; // cl@1
uint32_t result = hash;

for (; *v2; v3 = *v2)
Expand All @@ -35,4 +35,4 @@ namespace IW4
static void Vec3UnpackUnitVec(const PackedUnitVec& in, vec3_t* out);
static void Vec4UnpackGfxColor(const GfxColor& in, vec4_t* out);
};
}
} // namespace IW4
Loading