Skip to content

Commit

Permalink
补加以format
Browse files Browse the repository at this point in the history
  • Loading branch information
ytfh44 committed Dec 10, 2024
1 parent 45f421e commit a278531
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 33 deletions.
64 changes: 64 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 4
ColumnLimit: 100
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Regroup
IndentCaseLabels: true
IndentPPDirectives: None
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++11
TabWidth: 4
UseTab: Never
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,7 @@ env/
.ruby-version
.node-version
.tool-versions
.vagrant/
.vagrant/

# Local configuration
config.env
8 changes: 6 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ doom_pp_CPPFLAGS = \

EXTRA_DIST = \
README.md \
autogen.sh
autogen.sh \
.clang-format \
format_code.sh \
config.env.template

dist-hook:
chmod +x $(distdir)/autogen.sh
chmod +x $(distdir)/autogen.sh \
chmod +x $(distdir)/format_code.sh
5 changes: 5 additions & 0 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/bash
set -e

# Load proxy settings if config exists
if [ -f "./config.env" ]; then
source ./config.env
fi

# Check for required tools
for tool in autoconf automake libtool pkg-config wget tar; do
if ! command -v $tool >/dev/null 2>&1; then
Expand Down
20 changes: 14 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Permission to use, copy, modify, and/or distribute this software for any purpose
AC_CONFIG_SRCDIR([src/main.cpp])

# 设置宏目录
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_MACRO_DIRS([m4])
AC_CONFIG_AUX_DIR([build-aux])

# 初始化automake
Expand Down Expand Up @@ -46,10 +46,6 @@ AC_PATH_PROG([TAR], [tar])
# 检查C++11支持
AX_CXX_COMPILE_STDCXX_11([mandatory], [noext])

# 初始化下载标志
need_download_sdl2=no
need_download_vulkan=no

# SDL2检查和自动下载
SDL2_VERSION="2.26.5"
AC_ARG_WITH([sdl2],
Expand All @@ -58,7 +54,7 @@ AC_ARG_WITH([sdl2],
[SDL2_PATH=""])

AS_IF([test "x$SDL2_PATH" != "x"],
[SDL2_CFLAGS="-I$SDL2_PATH/include/SDL2"
[SDL2_CFLAGS="-I$SDL2_PATH/include"
if test "x$windows" = "xyes"; then
SDL2_LIBS="-L$SDL2_PATH/lib -lSDL2main -lSDL2"
else
Expand All @@ -76,6 +72,18 @@ AC_ARG_WITH([vulkan-sdk],
[VULKAN_SDK="$withval"],
[VULKAN_SDK=""])

# 检查Vulkan头文件
AC_CHECK_HEADERS([vulkan/vulkan.h], [],
[if test "x$VULKAN_SDK" != "x"; then
VULKAN_CFLAGS="-I$VULKAN_SDK/include"
export CPPFLAGS="$CPPFLAGS $VULKAN_CFLAGS"
unset ac_cv_header_vulkan_vulkan_h
AC_CHECK_HEADERS([vulkan/vulkan.h], [],
[AC_MSG_ERROR([Vulkan headers not found even with specified SDK])])
else
AC_MSG_ERROR([Vulkan headers not found. Please install Vulkan SDK or specify its location])
fi])

AS_IF([test "x$VULKAN_SDK" != "x"],
[VULKAN_CFLAGS="-I$VULKAN_SDK/include"
if test "x$windows" = "xyes"; then
Expand Down
37 changes: 31 additions & 6 deletions deps/download_deps.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
#!/bin/bash
set -e

# Load proxy settings if config exists
if [ -f "../config.env" ]; then
source ../config.env
fi

DEPS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="$DEPS_DIR/build"
INSTALL_DIR="$DEPS_DIR/install"

mkdir -p "$BUILD_DIR"
mkdir -p "$INSTALL_DIR"

# 下载函数,支持代理
download_file() {
local url=$1
local output_file=$2
echo "Downloading $url to $output_file..."
wget --no-check-certificate \
--proxy=on \
--proxy-user= \
--proxy-password= \
-O "$output_file" \
"$url"
}

download_sdl2() {
local version=$1
echo "Downloading SDL2 version $version..."

cd "$BUILD_DIR"
wget "https://github.com/libsdl-org/SDL/releases/download/release-$version/SDL2-$version.tar.gz"
tar xzf "SDL2-$version.tar.gz"
local sdl2_url="https://github.com/libsdl-org/SDL/releases/download/release-$version/SDL2-$version.tar.gz"
local sdl2_archive="SDL2-$version.tar.gz"

download_file "$sdl2_url" "$sdl2_archive"
tar xzf "$sdl2_archive"
cd "SDL2-$version"

./configure --prefix="$INSTALL_DIR" \
Expand All @@ -35,12 +56,16 @@ download_vulkan() {
cd "$BUILD_DIR"
if [[ "$OSTYPE" == "msys"* ]] || [[ "$OSTYPE" == "win32" ]]; then
# Windows version
wget "https://sdk.lunarg.com/sdk/download/$version/windows/VulkanSDK-$version-Installer.exe"
./VulkanSDK-$version-Installer.exe --root "$INSTALL_DIR" --accept-licenses --default-answer --confirm-command
local vulkan_url="https://sdk.lunarg.com/sdk/download/$version/windows/VulkanSDK-$version-Installer.exe"
local vulkan_installer="VulkanSDK-$version-Installer.exe"
download_file "$vulkan_url" "$vulkan_installer"
./"$vulkan_installer" --root "$INSTALL_DIR" --accept-licenses --default-answer --confirm-command
else
# Linux version
wget "https://sdk.lunarg.com/sdk/download/$version/linux/vulkansdk-linux-x86_64-$version.tar.gz"
tar xzf "vulkansdk-linux-x86_64-$version.tar.gz"
local vulkan_url="https://sdk.lunarg.com/sdk/download/$version/linux/vulkansdk-linux-x86_64-$version.tar.gz"
local vulkan_archive="vulkansdk-linux-x86_64-$version.tar.gz"
download_file "$vulkan_url" "$vulkan_archive"
tar xzf "$vulkan_archive"
cp -r "$version"/* "$INSTALL_DIR/"
fi

Expand Down
13 changes: 13 additions & 0 deletions format_code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -e

# Check if clang-format is installed
if ! command -v clang-format &> /dev/null; then
echo "Error: clang-format is not installed"
exit 1
fi

# Format all C++ source files
find src tests \( -name "*.cpp" -o -name "*.h" \) -exec clang-format -i {} +

echo "Code formatting complete!"
6 changes: 5 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ libdoom_a_SOURCES = \

libdoom_a_CPPFLAGS = \
$(SDL2_CFLAGS) \
$(VULKAN_CFLAGS)
$(VULKAN_CFLAGS) \
-I$(top_srcdir)/src \
-std=c++11 \
-D_USE_MATH_DEFINES \
-DVK_USE_PLATFORM_WIN32_KHR

pkginclude_HEADERS = \
renderer/vulkan_renderer.h \
Expand Down
2 changes: 1 addition & 1 deletion src/game/game_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ void GameLogic::update() {

GameLogic::~GameLogic() {
// Cleanup game resources
}
}
2 changes: 1 addition & 1 deletion src/game/game_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class GameLogic {
~GameLogic();
};

#endif // GAME_LOGIC_H
#endif // GAME_LOGIC_H
9 changes: 5 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "game/game_logic.h"
#include "renderer/vulkan_renderer.h"

#include <SDL.h>
#include <vulkan/vulkan.h>
#include "renderer/vulkan_renderer.h"
#include "game/game_logic.h"

int main(int argc, char* argv[]) {
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
// Handle initialization error
return -1;
}

VulkanRenderer renderer;
GameLogic game;

Expand All @@ -30,4 +31,4 @@ int main(int argc, char* argv[]) {
// Cleanup
SDL_Quit();
return 0;
}
}
Loading

0 comments on commit a278531

Please sign in to comment.