Skip to content

Commit

Permalink
Clang: Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Iswenzz committed May 26, 2024
1 parent 5b8b64a commit c8906ab
Show file tree
Hide file tree
Showing 26 changed files with 1,063 additions and 884 deletions.
32 changes: 32 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
BasedOnStyle: Google
ColumnLimit: 120
IndentWidth: 4
TabWidth: 4
UseTab: Always
ReflowComments: false
AccessModifierOffset: -4
IncludeBlocks: Preserve
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakBeforeBinaryOperators: NonAssignment
SpaceInEmptyBlock: true
SpacesBeforeTrailingComments: 1
SpaceAfterTemplateKeyword: true
IndentAccessModifiers: false
IndentRequiresClause: false
IndentCaseLabels: false
IndentPPDirectives: BeforeHash
InsertNewlineAtEOF: true
BinPackArguments: true
BinPackParameters: true
PackConstructorInitializers: BinPack
NamespaceIndentation: All
Cpp11BracedListStyle: false
FixNamespaceComments: false
AlignAfterOpenBracket: DontAlign
AlignOperands: false
AllowShortLoopsOnASingleLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowAllArgumentsOnNextLine: false
6 changes: 6 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Checks: >
-*
clang-analyzer-*
WarningsAsErrors: "*"
FormatStyle: file
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ else()
endif()
enable_language(ASM_NASM)

# CMake
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(ClangTools)

# CPack
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
Expand Down
25 changes: 25 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": 7,
"cmakeMinimumRequired": {
"major": 3,
"minor": 27,
"patch": 0
},
"configurePresets": [
{
"name": "windows",
"generator": "MinGW Makefiles",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": ".vcpkg/windows.cmake",
"COD4X": true
}
},
{
"name": "linux",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": ".vcpkg/linux.cmake",
"COD4X": true
}
}
]
}
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# CGSC

[![Checks](https://img.shields.io/github/checks-status/Iswenzz/CGSC/master?logo=github)](https://github.com/Iswenzz/CGSC/actions)
Expand All @@ -7,20 +6,23 @@

This Call of Duty 4X source extension adds new utilities to extend the server and the creation of new plugins. Such things include new functions to get data types that the original source doesn't offer, the ability to call functions defined in GSC from the C files and async workers for expensive operations on the server. To use this extension you must add the CGSC files included in the release section to the `/src/CGSC` folder, and then compile the CoD4X server source. More detailed instructions can be found towards the bottom of this document.

``Note: Depending on the version of Call of Duty 4X that you're running, some features of CGSC may not be available.``
`Note: Depending on the version of Call of Duty 4X that you're running, some features of CGSC may not be available.`

## Documentation
* [API](https://github.com/Iswenzz/CGSC/blob/master/docs/api.md)
* [Async](https://github.com/Iswenzz/CGSC/blob/master/docs/async.md)
* [Extensions](https://github.com/Iswenzz/CGSC/blob/master/docs/extensions.md)

- [API](https://github.com/Iswenzz/CGSC/blob/master/docs/api.md)
- [Async](https://github.com/Iswenzz/CGSC/blob/master/docs/async.md)
- [Extensions](https://github.com/Iswenzz/CGSC/blob/master/docs/extensions.md)

## Instructions
In order to use this extension, just download the archived file down below, and extract it to the cod4x server's ``src/CGSC`` directory, then copy the makefile snippet below and paste it before the default rule.
Then simply build the library with the build instructions and recompile the cod4x source with ``make``.

In order to use this extension, just download the archived file down below, and extract it to the cod4x server's `src/CGSC` directory, then copy the makefile snippet below and paste it before the default rule.
Then simply build the library with the build instructions and recompile the cod4x source with `make`.

### **[Download](https://github.com/Iswenzz/CGSC/releases)**

### **Snippet to add to the cod4x source's makefile before the first target:**

```makefile
##################################
# CGSC
Expand All @@ -41,32 +43,37 @@ $(OBJ_DIR)/%.o: $(CGSC_DIR)/asm/%.asm
```

## Building (Linux)

_Pre-Requisites:_

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install nasm:i386 build-essential gcc-multilib g++-multilib
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install nasm:i386 build-essential gcc-multilib g++-multilib

_Build Command:_

mkdir build && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=.vcpkg/linux.cmake -DCOD4X=True
cmake .. --preset linux
cmake --build .

## Building (Windows)

_Pre-Requisites:_

1. Windows [MinGW i686-8.1.0-win32-dwarf-msvcrt](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/8.1.0/threads-win32/dwarf/i686-8.1.0-release-win32-dwarf-rt_v6-rev0.7z)
2. [NASM](https://www.nasm.us/)
3. [CMake](https://cmake.org/) and [vcpkg](https://vcpkg.io/en/).

_Build Command:_

mkdir build && cd build
cmake .. -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=.vcpkg/windows.cmake -DCOD4X=True
cmake .. --preset windows
cmake --build .

## Package

This package is available for use via [vcpkg-registry](https://github.com/Iswenzz/vcpkg-registry).

## Contributors:
***Note:*** If you would like to contribute to this repository, feel free to send a pull request, and I will review your code. Also feel free to post about any problems that may arise in the issues section of the repository.

**_Note:_** If you would like to contribute to this repository, feel free to send a pull request, and I will review your code. Also feel free to post about any problems that may arise in the issues section of the repository.
23 changes: 13 additions & 10 deletions cgsc.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif

#ifdef _WIN32
Expand Down Expand Up @@ -42,8 +43,8 @@ extern "C" {

/// @brief Adds the definition for cod4x server and plugin export.
#define EXPORT(type, definition) \
type definition; \
type Plugin_##definition
type definition; \
type Plugin_##definition

#define CLASS_NUM_COUNT sizeof(gScrClassMap) / sizeof(gScrClassMap[0])
#define DEBUG_REFCOUNT_SIZE 65536
Expand Down Expand Up @@ -73,6 +74,7 @@ type Plugin_##definition
#define IsObject(var) ((var->w.type & VAR_MASK) >= VAR_THREAD)
#define IsObjectVal(var) ((var->type & VAR_MASK) >= VAR_THREAD)

// clang-format off
enum GSCTypeFlag
{
FLAG_UNDEFINED = 1,
Expand Down Expand Up @@ -107,26 +109,27 @@ enum GSCTypeFlag

struct scrStringDebugGlob_t
{
volatile int refCount[DEBUG_REFCOUNT_SIZE];
volatile int totalRefCount;
int ignoreLeaks;
volatile int refCount[DEBUG_REFCOUNT_SIZE];
volatile int totalRefCount;
int ignoreLeaks;
};

struct __attribute__((aligned (64))) scrVarGlob_t
struct __attribute__((aligned(64))) scrVarGlob_t
{
VariableValueInternal* variableList;
};

typedef struct
{
uint32_t length;
VariableValue *items;
VariableValue* items;
} VariableValueArray;
// clang-format on

#include "sys/compatibility.h"
#include "sys/async.h"
#include "extensions/functions.h"
#include "extensions/variables.h"
#include "sys/async.h"
#include "sys/compatibility.h"
#include "utils/utils.h"

#ifdef __cplusplus
Expand Down
12 changes: 12 additions & 0 deletions cmake/ClangTools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_custom_target(clang-tidy
COMMAND find . -type f \( -name '*.c' -o -name '*.h' \) -not -path './build/*' -exec clang-tidy --config-file=.clang-tidy {} +
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

add_custom_target(clang-format
COMMAND find . -type f \( -name '*.c' -o -name '*.h' \) -not -path './build/*' -exec clang-format -style=file -i --verbose {} +
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

set_target_properties(clang-tidy PROPERTIES FOLDER Clang)
set_target_properties(clang-format PROPERTIES FOLDER Clang)
40 changes: 20 additions & 20 deletions cod4x.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#pragma once
#define COD4X

#ifndef PLUGIN_HANDLER_VERSION_MAJOR
#include <plugin_declarations.h>
#endif

#define CHECK_UNSUPPORTED(condition) \
if (CGSC_UnsupportedMessage(condition, "CGSC: This feature is unsupported in this version.")) \
{ \
Scr_AddUndefined(); \
return; \
}

#include <version.h>
#include <scr_vm.h>
#include <scr_vm_functions.h>
#include <q_shared.h>

#undef ASSERT
#pragma once
#define COD4X

#ifndef PLUGIN_HANDLER_VERSION_MAJOR
#include <plugin_declarations.h>
#endif

#define CHECK_UNSUPPORTED(condition) \
if (CGSC_UnsupportedMessage(condition, "CGSC: This feature is unsupported in this version.")) \
{ \
Scr_AddUndefined(); \
return; \
}

#include <q_shared.h>
#include <scr_vm.h>
#include <scr_vm_functions.h>
#include <version.h>

#undef ASSERT
27 changes: 14 additions & 13 deletions extensions/__test__/main.test.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <greatest.h>
GREATEST_MAIN_DEFS();

extern SUITE(Suite_utils);

int main(int argc, char** argv)
{
GREATEST_MAIN_BEGIN();

RUN_SUITE(Suite_utils);

GREATEST_MAIN_END();
}
#include <greatest.h>

GREATEST_MAIN_DEFS();

extern SUITE(Suite_utils);

int main(int argc, char** argv)
{
GREATEST_MAIN_BEGIN();

RUN_SUITE(Suite_utils);

GREATEST_MAIN_END();
}
Loading

0 comments on commit c8906ab

Please sign in to comment.