Skip to content

Commit

Permalink
Use FileStream to write JPG images to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
rh101 committed Apr 22, 2021
1 parent 6effb16 commit 7540c06
Show file tree
Hide file tree
Showing 173 changed files with 3,724 additions and 5,646 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# build engine library and all tests

cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.6)

project(engine-x)

Expand Down
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software
Copyright (c) 2019-2020 HALX99
Copyright (c) 2020 C4games Ltd.
Copyright (c) 2021 Bytedance Inc.
Copyright (c) 2020 c4games.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
### [Roadmap](issues/1)

### Quick Start
Open [Wiki](https://github.com/c4games/engine-x-wiki) for additional information too.
Open [Wiki](https://github.com/c4games/engine-x/wiki) for additional information too.

#### Common Requirement [Python](https://www.python.org/downloads/)
* Python-2.7.17+, Python-3.7+
Expand Down Expand Up @@ -76,18 +76,21 @@ Open [Wiki](https://github.com/c4games/engine-x-wiki) for additional information
1. Ensure xcode11+ & [cmake3.14+](https://github.com/Kitware/CMake/releases) installed, install cmake command line support: ```sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install```
2. Execute follow command
```sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer```
3. Generate xcode project
- for any device
```cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake```
- for arm64:
```cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake -DCMAKE_OSX_ARCHITECTURES=arm64```
- for simulator x86_64:
```cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64```
3. Generate xcode project
```sh
# for any device
cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake

# for device combined armv7,arm64
# cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake "-DCMAKE_OSX_ARCHITECTURES=armv7;arm64"

# for simulator x86_64
# cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64
```
4. After cmake generate finish, you can open xcode project at ```build``` folder and run cpp-tests or other test targets.
5. Notes
- **The code sign required to run ios app on device, just change bundle identifier until the auto manage signing solved**
- **engine-x only provide armv7, arm64, x86_64 prebuilt libraries for ios**
- **The code sign required to run ios app on device, just change bundle identifier until the auto manage signing solved**
- **engine-x only provide armv7, arm64, x86_64 prebuilt libraries for ios**

### Notes
* ThreadLocalStorage (TLS)
Expand Down
19 changes: 11 additions & 8 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#### Windows
1. 安装CMake,要求3.14以上
2. 确保 Visual Studio 2019 已正确安装
2. 确保Visual Studio 2019以正确安装
3. 执行下面的命令
```bat
cd engine-x
Expand All @@ -79,14 +79,17 @@
1. 确保已安装xcode11+和[cmake3.14+](https://github.com/Kitware/CMake/releases), 安装CMake命令行支持: ```sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install```
2. 执行如下命令确保cmake能成功生成xcode工程:
```sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer```
3. 生成xcode工程, 进入engine-x根目录执行如下命令之一:
- for any device:
```cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake```
- for arm64:
```cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake -DCMAKE_OSX_ARCHITECTURES=arm64```
- for simulator x86_64:
```cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64```
3. 生成xcode工程, 进入engine-x根目录执行如下命令:
```sh
# for device arm64
cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake

# for device combined armv7,arm64
# cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake "-DCMAKE_OSX_ARCHITECTURES=armv7;arm64"

# for simulator x86_64
# cmake -S . -B build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64
```
4. 之后就可以用xcode打开, 选择cpp-tests编译运行

### 注意
Expand Down
12 changes: 4 additions & 8 deletions cmake/Modules/CocosConfigDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,18 @@ function(use_cocos2dx_compile_define target)
if(APPLE)
target_compile_definitions(${target} PUBLIC __APPLE__)
target_compile_definitions(${target} PUBLIC USE_FILE32API)
if(CC_COMPAT_GL)
target_compile_definitions(${target}
PUBLIC CC_COMPAT_GL=1
PUBLIC GL_SILENCE_DEPRECATION=1
)
if(IOS AND CC_FORCE_USE_GLES)
target_compile_definitions(${target} PUBLIC CC_FORCE_USE_GLES=1)
endif()

elseif(LINUX)
target_compile_definitions(${target} PUBLIC LINUX)
target_compile_definitions(${target} PUBLIC _GNU_SOURCE)
elseif(ANDROID)
target_compile_definitions(${target} PUBLIC ANDROID)
target_compile_definitions(${target} PUBLIC USE_FILE32API)
elseif(WINDOWS)
if(CC_COMPAT_GL)
target_compile_definitions(${target} PUBLIC CC_COMPAT_GL=1)
if(CC_FORCE_USE_GLES)
target_compile_definitions(${target} PUBLIC CC_FORCE_USE_GLES=1)
endif()
target_compile_definitions(${target}
PUBLIC WIN32
Expand Down
6 changes: 2 additions & 4 deletions cmake/Modules/CocosConfigDepend.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ macro(cocos2dx_depend)
find_library(CORE_GRAPHICS_LIBRARY CoreGraphics)
find_library(AV_FOUNDATION_LIBRARY AVFoundation)
find_library(WEBKIT_LIBRARY WebKit)
find_library(ZLIB z)
find_library(ICONVLIB iconv)
list(APPEND PLATFORM_SPECIFIC_LIBS
${UIKIT_LIBRARY}
${OPENGLES_LIBRARY}
Expand All @@ -95,8 +93,8 @@ macro(cocos2dx_depend)
${AV_FOUNDATION_LIBRARY}
${WEBKIT_LIBRARY}
${COCOS_APPLE_LIBS}
${ZLIB}
${ICONVLIB}
"/usr/lib/libz.dylib"
"/usr/lib/libiconv.dylib"
)
endif()
endif()
Expand Down
30 changes: 17 additions & 13 deletions cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ CMake is an open-source, cross-platform family of tools designed to build, test
```sh
cmake --version
```
if the CMake version is lower than 3.14, please upgrade.
if the CMake version is lower than 3.6, please upgrade.

2. You should use **out-of-source** builds, this means you need to create a different directory than **engine-x** to execute the `cmake` command.
2. You should use __out-of-source__ builds, this means you need to create a different directory than __cocos-re__ to execute the `cmake` command.

## Step by Step

Expand All @@ -29,29 +29,33 @@ Execute `make help` to see all build targets, `make <target>` build specified ta

```sh
cd engine-x
mkdir win32-build
cmake -B win32-build -G"Visual Studio 16 2019"
# build
cmake --build win32-build --config Debug
mkdir win32-build && cd win32-build
cmake .. -G"Visual Studio 16 2019"
```
or open **engine-x.sln** in Explorer to use the generated project.

Execute `cmake --build .` to compile,
```
cmake --build . --config Debug
cmake --build . --config Release
```
or open __cocos-re.sln__ in Explorer to use the generated project.

### Generate macOS Project

```sh
cd engine-x
mkdir mac-build
cmake -B mac-build -GXcode
open mac-build/engine-x.xcodeproj
mkdir mac-build && cd mac-build
cmake .. -GXcode
open engine-x.xcodeproj
```

### Generate iOS Project

```sh
cd engine-x
mkdir ios-build
cmake -B ios-build -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake
open ios-build/engine-x.xcodeproj
mkdir ios-build && cd ios-build
cmake .. -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/ios.mini.cmake
open engine-x.xcodeproj
```

#### How do I customize the generated Xcode project?
Expand Down
8 changes: 4 additions & 4 deletions cmake/scripts/sync_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def sync_folder(src_dir, dst_dir, luajit, compile):
parser.add_argument("-m", dest="mode", default=None)
(args, unkonw) = parser.parse_known_args(sys.argv)

need_compile = False
need_compile = True
# if args.luajit:
# print(" luajit mode '%s'" % (args.mode))

# if args.mode == "Debug" and args.luajit:
# need_compile = False
# print(" -Skip luacompile in debug mode!")
if args.mode == "Debug" and args.luajit:
need_compile = False
print(" -Skip luacompile in debug mode!")


create_files = 0
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/CCAtlasNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ AtlasNode * AtlasNode::create(const std::string& tile, int tileWidth, int tileHe
bool AtlasNode::initWithTileFile(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender)
{
CCASSERT(!tile.empty(), "file size should not be empty");
Texture2D *texture = _director->getTextureCache()->addImage(tile);
Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(tile);
return initWithTexture(texture, tileWidth, tileHeight, itemsToRender);
}

Expand Down Expand Up @@ -162,7 +162,7 @@ void AtlasNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)

auto programState = _quadCommand.getPipelineDescriptor().programState;

const auto& projectionMat = _director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
const auto& projectionMat = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
programState->setUniform(_mvpMatrixLocation, projectionMat.m, sizeof(projectionMat.m));

_quadCommand.init(_globalZOrder, _textureAtlas->getTexture(), _blendFunc, _textureAtlas->getQuads(), _quadsToDraw, transform, flags);
Expand Down
16 changes: 8 additions & 8 deletions cocos/2d/CCCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ void Camera::setAdditionalProjection(const Mat4& mat)

bool Camera::initDefault()
{
auto size = _director->getWinSize();
auto size = Director::getInstance()->getWinSize();
//create default camera
auto projection = _director->getProjection();
auto projection = Director::getInstance()->getProjection();
switch (projection)
{
case Director::Projection::_2D:
Expand All @@ -201,7 +201,7 @@ bool Camera::initDefault()
}
case Director::Projection::_3D:
{
float zeye = _director->getZEye();
float zeye = Director::getInstance()->getZEye();
initPerspective(60, (float)size.width / size.height, 10, zeye + size.height / 2.0f);
Vec3 eye(size.width/2, size.height/2.0f, zeye), center(size.width/2, size.height/2, 0.0f), up(0.0f, 1.0f, 0.0f);
setPosition3D(eye);
Expand Down Expand Up @@ -247,7 +247,7 @@ Vec2 Camera::project(const Vec3& src) const
{
Vec2 screenPos;

auto viewport = _director->getWinSize();
auto viewport = Director::getInstance()->getWinSize();
Vec4 clipPos;
getViewProjectionMatrix().transformVector(Vec4(src.x, src.y, src.z, 1.0f), &clipPos);

Expand All @@ -264,7 +264,7 @@ Vec2 Camera::projectGL(const Vec3& src) const
{
Vec2 screenPos;

auto viewport = _director->getWinSize();
auto viewport = Director::getInstance()->getWinSize();
Vec4 clipPos;
getViewProjectionMatrix().transformVector(Vec4(src.x, src.y, src.z, 1.0f), &clipPos);

Expand All @@ -280,14 +280,14 @@ Vec2 Camera::projectGL(const Vec3& src) const
Vec3 Camera::unproject(const Vec3& src) const
{
Vec3 dst;
unproject(_director->getWinSize(), &src, &dst);
unproject(Director::getInstance()->getWinSize(), &src, &dst);
return dst;
}

Vec3 Camera::unprojectGL(const Vec3& src) const
{
Vec3 dst;
unprojectGL(_director->getWinSize(), &src, &dst);
unprojectGL(Director::getInstance()->getWinSize(), &src, &dst);
return dst;
}

Expand Down Expand Up @@ -427,7 +427,7 @@ void Camera::apply()

void Camera::applyViewport()
{
_director->getRenderer()->setViewPort(_defaultViewport.x, _defaultViewport.y, _defaultViewport.w, _defaultViewport.h);
Director::getInstance()->getRenderer()->setViewPort(_defaultViewport.x, _defaultViewport.y, _defaultViewport.w, _defaultViewport.h);
}

int Camera::getRenderOrder() const
Expand Down
9 changes: 5 additions & 4 deletions cocos/2d/CCClippingNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32
// IMPORTANT:
// To ease the migration to v3.0, we still support the Mat4 stack,
// but it is deprecated and your code should not rely on it
CCASSERT(nullptr != _director, "Director is null when setting matrix stack");
_director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when setting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);

//Add group command

Expand Down Expand Up @@ -224,7 +225,7 @@ void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32

renderer->popGroup();

_director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}

void ClippingNode::setCameraMask(unsigned short mask, bool applyChildren)
Expand Down
6 changes: 3 additions & 3 deletions cocos/2d/CCClippingRectangleNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void ClippingRectangleNode::onBeforeVisitScissor()
{
if (_clippingEnabled)
{
auto renderer = _director->getRenderer();
auto renderer = Director::getInstance()->getRenderer();
_oldScissorTest = renderer->getScissorTest();
renderer->setScissorTest(true);

Expand All @@ -76,7 +76,7 @@ void ClippingRectangleNode::onBeforeVisitScissor()
}

const Point pos = convertToWorldSpace(Point(_clippingRegion.origin.x, _clippingRegion.origin.y));
GLView* glView = _director->getOpenGLView();
GLView* glView = Director::getInstance()->getOpenGLView();
glView->setScissorInPoints(pos.x,
pos.y,
_clippingRegion.size.width * scaleX,
Expand All @@ -87,7 +87,7 @@ void ClippingRectangleNode::onBeforeVisitScissor()
void ClippingRectangleNode::onAfterVisitScissor()
{
if (_clippingEnabled)
_director->getRenderer()->setScissorTest(_oldScissorTest);
Director::getInstance()->getRenderer()->setScissorTest(_oldScissorTest);
}

void ClippingRectangleNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
Expand Down
10 changes: 5 additions & 5 deletions cocos/2d/CCFastTMXLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool FastTMXLayer::initWithTilesetInfo(TMXTilesetInfo *tilesetInfo, TMXLayerInfo

if( tilesetInfo )
{
_texture = _director->getTextureCache()->addImage(tilesetInfo->_sourceImage);
_texture = Director::getInstance()->getTextureCache()->addImage(tilesetInfo->_sourceImage);
_texture->retain();
}

Expand Down Expand Up @@ -135,7 +135,7 @@ void FastTMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flag

if( flags != 0 || _dirty || _quadsDirty)
{
Size s = _director->getVisibleSize();
Size s = Director::getInstance()->getVisibleSize();
const Vec2 &anchor = getAnchorPoint();
auto rect = Rect(Camera::getVisitingCamera()->getPositionX() - s.width * (anchor.x == 0.0f ? 0.5f : anchor.x),
Camera::getVisitingCamera()->getPositionY() - s.height * (anchor.y == 0.0f ? 0.5f : anchor.y),
Expand All @@ -153,7 +153,7 @@ void FastTMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flag
_dirty = false;
}

const auto& projectionMat = _director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
const auto& projectionMat = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Mat4 finalMat = projectionMat * _modelViewTransform;
for (const auto& e : _customCommands)
{
Expand All @@ -168,7 +168,7 @@ void FastTMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flag

void FastTMXLayer::updateTiles(const Rect& culledRect)
{
Rect visibleTiles = Rect(culledRect.origin, culledRect.size * _director->getContentScaleFactor());
Rect visibleTiles = Rect(culledRect.origin, culledRect.size * Director::getInstance()->getContentScaleFactor());
Size mapTileSize = CC_SIZE_PIXELS_TO_POINTS(_mapTileSize);
Size tileSize = CC_SIZE_PIXELS_TO_POINTS(_tileSet->_tileSize);
Mat4 nodeToTileTransform = _tileToNodeTransform.getInversed();
Expand Down Expand Up @@ -300,7 +300,7 @@ void FastTMXLayer::setupTiles()
// Parse cocos2d properties
this->parseInternalProperties();

auto& screenSize = _director->getWinSize();
Size screenSize = Director::getInstance()->getWinSize();

switch (_layerOrientation)
{
Expand Down
Loading

0 comments on commit 7540c06

Please sign in to comment.