Skip to content

Commit

Permalink
Merge pull request #5 from c4games/master
Browse files Browse the repository at this point in the history
Sync with primary
  • Loading branch information
rh101 authored Apr 24, 2021
2 parents 0886473 + 540c937 commit 6fbebe9
Show file tree
Hide file tree
Showing 47 changed files with 1,560 additions and 1,262 deletions.
186 changes: 186 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# This file is copy from https://github.com/microsoft/STL with some modifications
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# https://releases.llvm.org/12.0.0/tools/clang/docs/ClangFormatStyleOptions.html

---
Language: Cpp
Standard: Cpp11
BasedOnStyle: LLVM
# AccessModifierOffset: -2
AccessModifierOffset: -4
# AlignAfterOpenBracket: Align
AlignAfterOpenBracket: DontAlign
# AlignConsecutiveMacros: false
AlignConsecutiveMacros: true
# AlignConsecutiveAssignments: false
AlignConsecutiveAssignments: true
# AlignConsecutiveBitFields: false
# AlignConsecutiveDeclarations: false
# AlignEscapedNewlines: Right
AlignEscapedNewlines: Left
# AlignOperands: Align
AlignOperands: AlignAfterOperator
# AlignTrailingComments: true
AlignTrailingComments: false
# AllowAllArgumentsOnNextLine: true
# AllowAllConstructorInitializersOnNextLine: true
# AllowAllParametersOfDeclarationOnNextLine: true
# AllowShortEnumsOnASingleLine: true
# AllowShortBlocksOnASingleLine: Never
# AllowShortCaseLabelsOnASingleLine: false
# AllowShortFunctionsOnASingleLine: All
AllowShortFunctionsOnASingleLine: Empty
# AllowShortLambdasOnASingleLine: All
# AllowShortIfStatementsOnASingleLine: Never
# AllowShortLoopsOnASingleLine: false
# AlwaysBreakAfterDefinitionReturnType: None
# AlwaysBreakAfterReturnType: None
# AlwaysBreakBeforeMultilineStrings: false
# AlwaysBreakTemplateDeclarations: MultiLine
AlwaysBreakTemplateDeclarations: Yes
# BinPackArguments: true
# BinPackParameters: true
# BraceWrapping:
# AfterCaseLabel: false
# AfterClass: false
# AfterControlStatement: Never
# AfterEnum: false
# AfterFunction: false
# AfterNamespace: false
# AfterObjCDeclaration: false
# AfterStruct: false
# AfterUnion: false
# AfterExternBlock: false
# BeforeCatch: false
# BeforeElse: false
# BeforeLambdaBody: false
# BeforeWhile: false
# IndentBraces: false
# SplitEmptyFunction: true
# SplitEmptyRecord: true
# SplitEmptyNamespace: true
# BreakBeforeBinaryOperators: None
BreakBeforeBinaryOperators: NonAssignment
# BreakBeforeBraces: Attach
# BreakBeforeInheritanceComma: false
# BreakInheritanceList: BeforeColon
# BreakBeforeTernaryOperators: true
# BreakConstructorInitializersBeforeComma: false
# BreakConstructorInitializers: BeforeColon
# BreakAfterJavaFieldAnnotations: false
# BreakStringLiterals: true
# ColumnLimit: 80
ColumnLimit: 120
# CommentPragmas: '^ IWYU pragma:'
# CompactNamespaces: false
# ConstructorInitializerAllOnOneLineOrOnePerLine: false
# ConstructorInitializerIndentWidth: 4
# ContinuationIndentWidth: 4
# Cpp11BracedListStyle: true
# DeriveLineEnding: true
DeriveLineEnding: false
# DerivePointerAlignment: false
# DisableFormat: false
# ExperimentalAutoDetectBinPacking: false
# FixNamespaceComments: true
# ForEachMacros:
# - foreach
# - Q_FOREACH
# - BOOST_FOREACH
# IncludeBlocks: Preserve
IncludeBlocks: Regroup
# IncludeCategories:
# - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
# Priority: 2
# SortPriority: 0
# - Regex: '^(<|"(gtest|gmock|isl|json)/)'
# Priority: 3
# SortPriority: 0
# - Regex: '.*'
# Priority: 1
# SortPriority: 0
IncludeCategories:
- Regex: '^<yvals(_core)?\.h>$'
Priority: 1
- Regex: '^<(Windows|userenv)\.h>$'
Priority: 3
SortPriority: 3
- Regex: '^<WinIoCtl\.h>$'
Priority: 3
SortPriority: 4
- Regex: '^<__.*\.hpp>$'
Priority: 2
- Regex: '\.hpp[>"]$'
Priority: 5
- Regex: '.*'
Priority: 2
# IncludeIsMainRegex: '(Test)?$'
# IncludeIsMainSourceRegex: ''
# IndentCaseLabels: false
# IndentCaseBlocks: false
IndentCaseBlocks: true
# IndentGotoLabels: true
# IndentPPDirectives: None
# IndentExternBlock: AfterExternBlock
# IndentWidth: 2
IndentWidth: 4
# IndentWrappedFunctionNames: false
IndentWrappedFunctionNames: true
# InsertTrailingCommas: None
# JavaScriptQuotes: Leave
# JavaScriptWrapImports: true
# KeepEmptyLinesAtTheStartOfBlocks: true
# NOTE: MacroBlockBegin/MacroBlockEnd don't work with _CATCH_ALL.
# MacroBlockBegin: ''
# MacroBlockEnd: ''
# MaxEmptyLinesToKeep: 1
MaxEmptyLinesToKeep: 2
# NamespaceIndentation: None
NamespaceIndentation: None
# ObjCBinPackProtocolList: Auto
# ObjCBlockIndentWidth: 2
# ObjCBreakBeforeNestedBlockParam: true
# ObjCSpaceAfterProperty: false
# ObjCSpaceBeforeProtocolList: true
# PenaltyBreakAssignment: 2
# PenaltyBreakBeforeFirstCallParameter: 19
# PenaltyBreakComment: 300
# PenaltyBreakFirstLessLess: 120
# PenaltyBreakString: 1000
# PenaltyBreakTemplateDeclaration: 10
# PenaltyExcessCharacter: 1000000
# PenaltyReturnTypeOnItsOwnLine: 60
# PointerAlignment: Right
PointerAlignment: Left
# ReflowComments: true
SortIncludes: false
# SortUsingDeclarations: true
# SpaceAfterCStyleCast: false
SpaceAfterCStyleCast: true
# SpaceAfterLogicalNot: false
# SpaceAfterTemplateKeyword: true
# SpaceBeforeAssignmentOperators: true
# SpaceBeforeCpp11BracedList: false
# SpaceBeforeCtorInitializerColon: true
# SpaceBeforeInheritanceColon: true
# SpaceBeforeParens: ControlStatements
# SpaceBeforeRangeBasedForLoopColon: true
# SpaceInEmptyBlock: false
# SpaceInEmptyParentheses: false
# SpacesBeforeTrailingComments: 1
# SpacesInAngles: false
# SpacesInConditionalStatement: false
# SpacesInContainerLiterals: true
# SpacesInCStyleCastParentheses: false
# SpacesInParentheses: false
# SpacesInSquareBrackets: false
# SpaceBeforeSquareBrackets: false
# Standard: Latest
# StatementMacros:
# - Q_UNUSED
# - QT_REQUIRE_VERSION
# NOTE: _STD_BEGIN, _STD_END, etc. aren't macros for complete statements, but telling
# clang-format that they are produces the behavior that we want (with no block indentation).
UseTab: Never
18 changes: 10 additions & 8 deletions cocos/2d/CCFontFreeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ static unsigned long ft_stream_read_callback(FT_Stream stream, unsigned long off
}

static void ft_stream_close_callback(FT_Stream stream) {
auto fd = (FileStream*)stream->descriptor.pointer;
if (fd) delete fd;
const auto* fd = (FileStream*)stream->descriptor.pointer;
delete fd;
stream->size = 0;
stream->descriptor.pointer = nullptr;
}
Expand Down Expand Up @@ -174,21 +174,23 @@ bool FontFreeType::createFontObject(const std::string &fontName, float fontSize)
auto fullPath = FileUtils::getInstance()->fullPathForFilename(fontName);
if (fullPath.empty()) return false;

FileStream fs;
if (!fs.open(fullPath, FileStream::Mode::READ))
FileStream* fs = FileUtils::getInstance()->openFileStream(fullPath, FileStream::Mode::READ);
if (!fs)
{
return false;
}

std::unique_ptr<FT_StreamRec> fts(new FT_StreamRec());
fts->read = ft_stream_read_callback;
fts->close = ft_stream_close_callback;
fts->size = fs.seek(0, SEEK_END);
fs.seek(0, SEEK_SET);
fts->size = fs->seek(0, SEEK_END);
fs->seek(0, SEEK_SET);

fts->descriptor.pointer = new FileStream(std::move(fs));
fts->descriptor.pointer = fs;

FT_Open_Args args = { 0 };
args.flags = FT_OPEN_STREAM;
args.stream = fts.get();;
args.stream = fts.get();

if (FT_Open_Face(getFTLibrary(), &args, 0, &face))
return false;
Expand Down
2 changes: 1 addition & 1 deletion cocos/audio/include/AudioDecoderMp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AudioDecoderMp3 : public AudioDecoder
static bool lazyInit();
static void destroy();

FileStream _fileStream;
FileStream* _fileStream = nullptr;
mp3dec_handle_t _handle;

friend class AudioDecoderManager;
Expand Down
2 changes: 1 addition & 1 deletion cocos/audio/include/AudioDecoderOgg.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AudioDecoderOgg : public AudioDecoder
AudioDecoderOgg();
~AudioDecoderOgg();

FileStream _fileStream;
FileStream* _fileStream;
OggVorbis_File _vf;

friend class AudioDecoderManager;
Expand Down
2 changes: 1 addition & 1 deletion cocos/audio/include/AudioDecoderWav.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct WAV_FILE
WAV_FILE_HEADER FileHeader;
AUDIO_SOURCE_FORMAT SourceFormat;
uint32_t PcmDataOffset;
cocos2d::FileStream Stream;
cocos2d::FileStream* Stream = nullptr;
};


Expand Down
14 changes: 10 additions & 4 deletions cocos/audio/src/AudioDecoderMp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ namespace cocos2d {
#if !CC_USE_MPG123
do
{
if (!_fileStream.open(fullPath, FileStream::Mode::READ))
delete _fileStream;
_fileStream = FileUtils::getInstance()->openFileStream(fullPath, FileStream::Mode::READ);
if (!_fileStream)
{
ALOGE("Trouble with minimp3(1): %s\n", strerror(errno));
break;
Expand All @@ -138,7 +140,7 @@ namespace cocos2d {

handle->_decIO.read = minimp3_read_r;
handle->_decIO.seek = minimp3_seek_r;
handle->_decIO.read_data = handle->_decIO.seek_data = &_fileStream;
handle->_decIO.read_data = handle->_decIO.seek_data = _fileStream;

if (mp3dec_ex_open_cb(&handle->_dec, &handle->_decIO, MP3D_SEEK_TO_SAMPLE) != 0)
{
Expand Down Expand Up @@ -189,7 +191,7 @@ namespace cocos2d {

mpg123_replace_reader_handle(_handle, mpg123_read_r, mpg123_lseek_r, mpg123_close_r);

if (mpg123_open_handle(_handle, &_fileStream) != MPG123_OK
if (mpg123_open_handle(_handle, _fileStream) != MPG123_OK
|| mpg123_getformat(_handle, &rate, &channel, &mp3Encoding) != MPG123_OK)
{
ALOGE("Trouble with mpg123(2): %s\n", mpg123_strerror(_handle));
Expand Down Expand Up @@ -248,14 +250,18 @@ namespace cocos2d {
delete _handle;
_handle = nullptr;

_fileStream.close();
delete _fileStream;
_fileStream = nullptr;
}
#else
if (_handle != nullptr)
{
mpg123_close(_handle);
mpg123_delete(_handle);
_handle = nullptr;

delete _fileStream;
_fileStream = nullptr;
}
#endif
_isOpened = false;
Expand Down
3 changes: 2 additions & 1 deletion cocos/audio/src/AudioDecoderOgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ namespace cocos2d {

bool AudioDecoderOgg::open(const std::string& fullPath)
{
if (!_fileStream.open(fullPath, FileStream::Mode::READ))
_fileStream = FileUtils::getInstance()->openFileStream(fullPath, FileStream::Mode::READ);
if (!_fileStream)
{
ALOGE("Trouble with ogg(1): %s\n", strerror(errno));
return false;
Expand Down
Loading

0 comments on commit 6fbebe9

Please sign in to comment.