Commit 58641594 authored by wind2009's avatar wind2009

Merge remote-tracking branch 'upstream/server' into 2pick

parents 963081b6 00b06fea
Pipeline #37013 failed with stages
in 6 minutes and 22 seconds
export ASSET_BRANCH_NAME="master"
# if $CI_COMMIT_REF_NAME includes develop or pre, then we use the develop branch
if [[ "$CI_COMMIT_REF_NAME" == *"develop"* || "$CI_COMMIT_REF_NAME" == *".pre"* ]]; then
export ASSET_BRANCH_NAME="develop"
fi
#!/bin/bash
set -x
set -o errexit
source .ci/asset-branch
# ygopro-database
apt update && apt -y install wget git libarchive-tools
git clone --depth=1 https://code.mycard.moe/nanahira/ygopro-database
cp -rf ./ygopro-database/locales/$TARGET_LOCALE/* .
apt update && apt -y install wget git libarchive-tools sqlite3
git clone --depth=1 -b "$ASSET_BRANCH_NAME" https://code.moenext.com/mycard/ygopro-database
cp -rf ./ygopro-database/locales/$TARGET_LOCALE/strings.conf .
rm -f cards.cdb
sqlite3 ./ygopro-database/locales/$TARGET_LOCALE/cards.cdb .dump | sqlite3 cards.cdb
# ygopro-images
mkdir pics
wget -O - https://cdn01.moecube.com/images/ygopro-images-${TARGET_LOCALE}.zip | bsdtar -C pics -xf -
if [[ "$ASSET_BRANCH_NAME" == "develop" ]]; then
echo "This is a pre-release, skipping download."
else
wget -O - https://cdn02.moecube.com:444/images/ygopro-images-${TARGET_LOCALE}.zip | bsdtar -C pics -xf -
fi
#!/bin/sh
set -x
set -o errexit
if [ -n "$NO_AUDIO" ]; then
echo "Skipping opus build because NO_AUDIO is set"
exit 0
fi
cd miniaudio
external_built_dir="$PWD/external-built"
is_macos=false
if [ "$(uname)" = "Darwin" ]; then
is_macos=true
fi
maybe_patch_configure() {
if $is_macos; then
sed -i.bak 's/-force_cpusubtype_ALL//g' configure*
fi
}
build_single_thing() {
lib_name="$1"
cd "external/$lib_name"
shift
maybe_patch_configure
PKG_CONFIG_PATH="$external_built_dir/lib/pkgconfig" CFLAGS="$OPUS_FLAGS" CXXFLAGS="$OPUS_FLAGS" ./configure --prefix="$external_built_dir" --enable-static=yes --enable-shared=no "$@"
make -j$(nproc)
make install
cd ../..
}
build_single_thing ogg
build_single_thing opus
build_single_thing opusfile --disable-examples --disable-http
build_single_thing vorbis --with-ogg="$external_built_dir"
cd ..
......@@ -6,15 +6,24 @@ TARGET_PLATFORM=$(arch)
TARGET_YGOPRO_BINARY_PATH=./ygopro-platforms/ygopro-platform-$TARGET_PLATFORM
export EVENT_INCLUDE_DIR=$PWD/libevent-stable/include
export EVENT_LIB_DIR=$PWD/libevent-stable/lib
export IRRLICHT_INCLUDE_DIR=$PWD/irrlicht/include
export IRRLICHT_LIB_DIR=$PWD/irrlicht/lib/$(arch)
export OPUS_INCLUDE_DIR=$PWD/miniaudio/external-built/include/opus
export OPUS_LIB_DIR=$PWD/miniaudio/external-built/lib
export OPUSFILE_INCLUDE_DIR=$PWD/miniaudio/external-built/include/opus
export OPUSFILE_LIB_DIR=$PWD/miniaudio/external-built/lib
export VORBIS_INCLUDE_DIR=$PWD/miniaudio/external-built/include
export VORBIS_LIB_DIR=$PWD/miniaudio/external-built/lib
export OGG_INCLUDE_DIR=$PWD/miniaudio/external-built/include
export OGG_LIB_DIR=$PWD/miniaudio/external-built/lib
export ACLOCAL=aclocal
export AUTOMAKE=automake
./.ci/libevent-prebuild.sh
./.ci/build-opus.sh
./premake5 gmake --cc=clang --build-freetype --build-sqlite --no-use-irrklang
./premake5 gmake --cc=clang --build-freetype --build-sqlite
cd build
make config=release -j4
make config=release -j$(sysctl -n hw.ncpu)
cd ..
mkdir ygopro-platforms
......
#!/bin/bash
#!/bin/sh
set -x
set -o errexit
# PROCESSOR_COUNT=4
wget -O - https://cdn01.moecube.com/ygopro-build-materials/libevent-2.0.22-stable.tar.gz | tar zfx -
if [ -d "libevent-stable" ]; then
rm -rf libevent-stable
fi
if [ ! -d "libevent-2.0.22-stable" ]; then
wget -O - https://cdn02.moecube.com:444/ygopro-build-materials/libevent-2.0.22-stable.tar.gz | tar zfx -
fi
install_path="$PWD/libevent-stable"
cd libevent-2.0.22-stable
./configure --prefix=$PWD/libevent-stable --disable-openssl --enable-static=yes --enable-shared=no
make -j$PROCESSOR_COUNT
./configure "--prefix=$install_path" --disable-openssl --enable-static=yes --enable-shared=no "$@"
make -j$(nproc)
make install
cd ..
mv libevent-2.0.22-stable/libevent-stable .
rm -rf libevent-2.0.22-stable
......@@ -2,9 +2,15 @@
set -x
set -o errexit
ARCHIVE_FILES=(ygopro lib cards.cdb locales fonts sound textures strings.conf system.conf pack)
ARCHIVE_FILES=(ygopro cards.cdb locales fonts sound textures strings.conf system.conf pack)
TARGET_PLATFORM=linux
if [[ -z "$TARGET_PLATFORM" ]]; then
TARGET_PLATFORM=linux
fi
#if [[ "$TARGET_PLATFORM" != "linuxarm" ]]; then
ARCHIVE_FILES+=(sound)
#fi
apt update && apt -y install tar zstd
mkdir dist replay
......
......@@ -2,11 +2,17 @@
set -x
set -o errexit
ARCHIVE_FILES=(ygopro LICENSE README.md lib lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay sound windbot bot bot.conf locales fonts pack)
ARCHIVE_FILES=(ygopro LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay windbot bot bot.conf locales fonts pack)
# TARGET_LOCALE
# ARCHIVE_SUFFIX
TARGET_PLATFORM=linux
if [[ -z "$TARGET_PLATFORM" ]]; then
TARGET_PLATFORM=linux
fi
if [[ "$TARGET_PLATFORM" != "linuxarm" ]]; then
ARCHIVE_FILES+=(sound)
fi
apt update && apt -y install tar git zstd
mkdir dist replay
......
......@@ -2,9 +2,11 @@
set -x
set -o errexit
ARCHIVE_FILES=(ygopro.app cards.cdb locales fonts textures strings.conf system.conf pack)
ARCHIVE_FILES=(ygopro.app cards.cdb locales fonts sound textures strings.conf system.conf pack)
TARGET_PLATFORM=darwin
if [[ -z "$TARGET_PLATFORM" ]]; then
TARGET_PLATFORM=darwin
fi
apt update && apt -y install tar zstd
mkdir dist replay
......
......@@ -2,11 +2,13 @@
set -x
set -o errexit
ARCHIVE_FILES=(ygopro.app LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay windbot bot bot.conf locales fonts pack)
ARCHIVE_FILES=(ygopro.app LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay sound windbot bot bot.conf locales fonts pack)
# TARGET_LOCALE
# ARCHIVE_SUFFIX
TARGET_PLATFORM=darwin
if [[ -z "$TARGET_PLATFORM" ]]; then
TARGET_PLATFORM=darwin
fi
apt update && apt -y install tar git zstd
mkdir dist replay
......
......@@ -9,7 +9,9 @@ if [[ "$TARGET_LOCALE" == "zh-CN" ]]; then
fi
# TARGET_LOCALE
TARGET_PLATFORM=win32
if [[ -z "$TARGET_PLATFORM" ]]; then
TARGET_PLATFORM=win32
fi
apt update && apt -y install p7zip-full git
mkdir dist replay
......
......@@ -4,7 +4,9 @@ set -o errexit
ARCHIVE_FILES=(ygopro.exe cards.cdb locales fonts sound textures strings.conf system.conf skin pack)
TARGET_PLATFORM=win32
if [[ -z "$TARGET_PLATFORM" ]]; then
TARGET_PLATFORM=win32
fi
apt update && apt -y install tar zstd
mkdir dist replay
......
......@@ -10,7 +10,9 @@ fi
# TARGET_LOCALE
# ARCHIVE_SUFFIX
TARGET_PLATFORM=win32
if [[ -z "$TARGET_PLATFORM" ]]; then
TARGET_PLATFORM=win32
fi
apt update && apt -y install tar git zstd
mkdir dist replay
......
#!/bin/bash
set -x
set -o errexit
source .ci/asset-branch
IRRLICHT_REPO_URL="https://code.moenext.com/mycard/irrlicht-new.git"
IRRLICHT_BRANCH_NAME="$ASSET_BRANCH_NAME"
if [ ! -d "irrlicht" ]; then
git clone --depth=1 --branch "$IRRLICHT_BRANCH_NAME" "$IRRLICHT_REPO_URL" irrlicht
else
cd irrlicht
git fetch origin "$IRRLICHT_BRANCH_NAME"
git checkout "$IRRLICHT_BRANCH_NAME"
git reset --hard origin/"$IRRLICHT_BRANCH_NAME"
cd ..
fi
#!/bin/sh
set -x
set -o errexit
if [ ! -d "miniaudio" ]; then
git clone --depth=1 --branch 0.11.22 https://github.com/mackron/miniaudio
fi
cp -rf miniaudio/extras/miniaudio_split/miniaudio.* miniaudio/
mkdir -p miniaudio/external
install_external() {
dir="$1"
url="$2"
if [ ! -d "miniaudio/external/$dir" ]; then
mkdir -p "miniaudio/external/$dir"
# Download the external library and strip one level of directories from the archive
wget -O - "$url" | tar --strip-components=1 -C "miniaudio/external/$dir" -zxf -
fi
}
install_external "ogg" "https://github.com/xiph/ogg/releases/download/v1.3.5/libogg-1.3.5.tar.gz"
install_external "opus" "https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz"
install_external "opusfile" "https://github.com/xiph/opusfile/releases/download/v0.12/opusfile-0.12.tar.gz"
install_external "vorbis" "https://github.com/xiph/vorbis/releases/download/v1.3.7/libvorbis-1.3.7.tar.gz"
......@@ -33,9 +33,15 @@ runForDepot() {
echo "$result" | jq .
}
runForDepot win32 zh-CN
runForDepot linux zh-CN
runForDepot darwin zh-CN
runForDepot win32 en-US
runForDepot linux en-US
runForDepot darwin en-US
source .ci/asset-branch
if [[ "$ASSET_BRANCH_NAME" == "develop" ]]; then
echo "This is a pre-release, skipping upload."
else
runForDepot win32 zh-CN
runForDepot linux zh-CN
runForDepot darwin zh-CN
runForDepot win32 en-US
runForDepot linux en-US
runForDepot darwin en-US
fi
This diff is collapsed.
......@@ -15,6 +15,7 @@ build
/irrklang
/irrlicht*
/lua
/miniaudio
# gframe additionals
/gframe/ygopro.ico
......@@ -75,7 +76,7 @@ build
/ygopro_*.app
/premake4
/premake4.exe
/premake5
/premake5*
/premake5.exe
# others
......
......@@ -14,14 +14,18 @@ mat_common:
- linux
script:
# lua
- wget -O - https://cdn01.moecube.com/ygopro-build-materials/lua-5.4.4.tar.gz | tar zfx -
- wget -O - https://cdn02.moecube.com:444/ygopro-build-materials/lua-5.4.4.tar.gz | tar zfx -
- mv lua-5.4.4 lua
# sqlite3
- wget -O - https://cdn01.moecube.com/ygopro-build-materials/sqlite-autoconf-3390300.tar.gz | tar zfx -
- wget -O - https://cdn02.moecube.com:444/ygopro-build-materials/sqlite-autoconf-3390300.tar.gz | tar zfx -
- mv sqlite-autoconf-3390300 sqlite3
# freetype
#- wget -O - https://cdn01.moecube.com/ygopro-build-materials/freetype-2.11.1.tar.gz | tar zfx -
#- wget -O - https://cdn02.moecube.com:444/ygopro-build-materials/freetype-2.11.1.tar.gz | tar zfx -
#- mv freetype-2.11.1 freetype
# irrlicht
- ./.ci/prepare-irrlicht.sh
# miniaudio
#- ./.ci/prepare-miniaudio.sh
# premake
- cp -rf premake/* .;
artifacts:
......@@ -29,6 +33,8 @@ mat_common:
- lua
#- freetype
- sqlite3
- irrlicht
#- miniaudio
mat_submodules:
stage: prepare
......@@ -37,26 +43,36 @@ mat_submodules:
script:
- rm -rf ocgcore script
- mkdir ocgcore script
- git config --global --add safe.directory $CI_PROJECT_DIR
- git submodule update --init
artifacts:
paths:
- ocgcore
- script
mat_linux:
#mat_linux:
# stage: prepare
# tags:
# - linux
# image: git-registry.mycard.moe/mycard/docker-runner-base:debian11
# script:
# - apt update; apt -y install git wget tar
# - ./.ci/prepare-irrlicht.sh
# artifacts:
# paths:
# - irrlicht
mat_macos:
stage: prepare
tags:
- linux
script:
- apt update; apt -y install git wget tar
- git clone --depth=1 https://code.mycard.moe/mycard/irrlicht-new irrlicht
- wget -O - https://cdn01.moecube.com/ygopro-build-materials/premake-5.0.0-beta2-linux.tar.gz | tar zfx -
- env PROCESSOR_COUNT=$(nproc) ./.ci/libevent-prebuild.sh
- apt update; apt -y install wget tar
- wget -O - https://cdn02.moecube.com:444/ygopro-build-materials/premake-5.0.0-beta5-macosx.tar.gz | tar zfx -
- chmod +x premake5
artifacts:
paths:
- premake5
- irrlicht
- libevent-stable
mat_windows:
stage: prepare
......@@ -65,18 +81,15 @@ mat_windows:
script:
- apt update; apt -y install wget tar patch p7zip-full
# premake5.exe
- wget https://cdn01.moecube.com/ygopro-build-materials/premake-5.0.0-beta2-windows.zip
- 7z x -y premake-5.0.0-beta2-windows.zip
- wget https://cdn02.moecube.com:444/ygopro-build-materials/premake-5.0.0-beta5-windows.zip
- 7z x -y premake-5.0.0-beta5-windows.zip
# event
- wget -O - https://cdn01.moecube.com/ygopro-build-materials/libevent-2.0.22-stable.tar.gz | tar zfx -
- wget -O - https://cdn02.moecube.com:444/ygopro-build-materials/libevent-2.0.22-stable.tar.gz | tar zfx -
- mv libevent-2.0.22-stable event
# irrlicht
# - git clone --depth=1 https://code.mycard.moe/mycard/irrlicht-new irrlicht
artifacts:
paths:
- premake5.exe
- event
# - irrlicht
._exec_build:
stage: build
......@@ -88,7 +101,7 @@ mat_windows:
- bin/
- obj/
exec_windows:
.exec_windows:
extends: ._exec_build
tags:
- vs
......@@ -96,54 +109,195 @@ exec_windows:
- mat_common
- mat_windows
- mat_submodules
script:
- bash -c 'cp -rf premake/* .'
- '.\premake5.exe vs2019'
- cmd /c '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" build\YGOPro.sln /m /p:Configuration=Release'
- copy bin\release\ygopro.exe .
before_script:
- bash -c 'cp -rf premake/* . ; cp -rf resource/* .'
artifacts:
paths:
- ygopro.exe
- dist
exec_linux:
exec_windows:
extends: .exec_windows
script:
- '.\premake5.exe vs2019 --server-zip-support'
- cmd /c '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" build\YGOPro.sln /m /p:Configuration=Release'
- mkdir dist
- mkdir dist\windows
- copy bin\release\ygopro.exe dist\windows\ygopro.exe
exec_windows_pro3:
extends: .exec_windows
script:
- '.\premake5.exe vs2019 --server-pro3-support --log-in-chat'
- cmd /c '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" build\YGOPro.sln /m /p:Configuration=Release'
- mkdir dist
- mkdir dist\windows
- copy bin\release\ygoserver.dll dist\windows\ygoserver.dll
.exec_unix_common:
extends: ._exec_build
tags:
- linux
dependencies:
- mat_common
- mat_linux
- mat_submodules
variables:
RELEASE_DIR: ''
TARGET_FILE: ygopro
PREMAKE5_BIN: premake5
script:
- apt update; apt -y install git build-essential
- ./premake5 gmake --build-sqlite --server-zip-support
- $PREMAKE5_BIN gmake
- cd build
- make config=release -j$(nproc)
- cd ..
- mv bin/release/ygopro ./ygopro
- strip ygopro
- mkdir -p dist/$RELEASE_DIR
- mv bin/release/$TARGET_FILE dist/$RELEASE_DIR/$TARGET_FILE
- |
if [ "$TARGET_FILE" = "ygopro" ]; then
strip dist/$RELEASE_DIR/$TARGET_FILE
fi
artifacts:
paths:
- ygopro
- dist
exec_debian:
extends: ._exec_build
.exec_linux_common:
extends: .exec_unix_common
tags:
- linux
image: git-registry.moenext.com/mycard/docker-ygopro-builder
dependencies:
- mat_common
#- mat_linux
- mat_submodules
.exec_linux:
extends: .exec_linux_common
variables:
BUILD_SQLITE: '1'
SERVER_ZIP_SUPPORT: '1'
EVENT_INCLUDE_DIR: /usr/share/libevent-stable/include
EVENT_LIB_DIR: /usr/share/libevent-stable/lib
RELEASE_DIR: linux-x64
.exec_debian:
extends: .exec_linux_common
variables:
LUA_DEB: '1'
RELEASE_DIR: debian-x64
before_script:
- apt update; apt -y install git build-essential liblua5.4-dev libsqlite3-dev libevent-dev
.use_arm:
image: git-registry.moenext.com/mycard/docker-ygopro-builder:fpic
tags:
- arm
.use_pro3:
image: git-registry.moenext.com/mycard/docker-ygopro-builder:fpic
variables:
SERVER_PRO3_SUPPORT: '1'
LOG_IN_CHAT: '1'
TARGET_FILE: libygoserver.so
.use_pro3_macos:
variables:
SERVER_PRO3_SUPPORT: '1'
LOG_IN_CHAT: '1'
TARGET_FILE: libygoserver.dylib
LIBEVENT_PREBUILD_FLAGS: '-fPIC'
exec_linux:
extends: .exec_linux
exec_linux_pro3:
extends:
- .exec_linux
- .use_pro3
exec_debian:
extends: .exec_debian
exec_linuxarm:
extends:
- .exec_linux
- .use_arm
variables:
RELEASE_DIR: linux-arm64
exec_linuxarm_pro3:
extends:
- .exec_linux
- .use_arm
- .use_pro3
variables:
RELEASE_DIR: linux-arm64
exec_debianarm:
extends:
- .exec_debian
- .use_arm
variables:
RELEASE_DIR: debian-arm
.exec_macos_platform:
extends: .exec_unix_common
dependencies:
- mat_common
- mat_linux
- mat_macos
- mat_submodules
before_script:
- env CFLAGS=$LIBEVENT_PREBUILD_FLAGS CXXFLAGS=$LIBEVENT_PREBUILD_FLAGS ./.ci/libevent-prebuild.sh
variables:
PREMAKE5_BIN: ./premake5
BUILD_SQLITE: '1'
SERVER_ZIP_SUPPORT: '1'
EVENT_INCLUDE_DIR: ../libevent-stable/include
EVENT_LIB_DIR: ../libevent-stable/lib
exec_macos_x64:
extends: .exec_macos_platform
tags:
- macos
variables:
RELEASE_DIR: macos-x64
exec_macos_arm64:
extends: .exec_macos_platform
tags:
- macos-m1
variables:
RELEASE_DIR: macos-arm64
exec_macos_x64_pro3:
extends:
- .exec_macos_platform
- .use_pro3_macos
tags:
- macos
variables:
RELEASE_DIR: macos-x64
exec_macos_arm64_pro3:
extends:
- .exec_macos_platform
- .use_pro3_macos
tags:
- macos-m1
variables:
RELEASE_DIR: macos-arm64
exec_macos:
stage: combine
tags:
- macos
dependencies:
- exec_macos_x64
- exec_macos_arm64
- exec_macos_x64_pro3
- exec_macos_arm64_pro3
script:
- apt update; apt -y install git build-essential liblua5.3-dev libsqlite3-dev libevent-dev
- ./premake5 gmake --lua-deb
- cd build
- make config=release -j$(nproc)
- cd ..
- mv bin/release/ygopro ./ygopro
- strip ygopro
- mkdir -p dist/macos
- lipo -create -output dist/macos/ygopro dist/macos-x64/ygopro dist/macos-arm64/ygopro
- lipo -create -output dist/macos/libygoserver.dylib dist/macos-x64/libygoserver.dylib dist/macos-arm64/libygoserver.dylib
- rm -rf dist/macos-x64 dist/macos-arm64
artifacts:
paths:
- ygopro
- dist
#win_server_pack:
# stage: pack
......@@ -155,14 +309,22 @@ exec_debian:
# - apt update; apt -y install p7zip-full wget
# - wget https://nodejs.org/dist/v14.17.0/node-v14.17.0-win-x64.7z
upload_to_minio:
stage: deploy
dependencies:
- exec_windows
- exec_linux
- exec_linuxarm
- exec_windows_pro3
- exec_linux_pro3
- exec_linuxarm_pro3
- exec_debian
- exec_debianarm
- exec_macos
tags:
- linux
script:
- aws s3 --endpoint=https://minio.mycard.moe:9000 cp ygopro.exe s3://mycard/koishipro/server/ygopro.exe
- aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/ s3://mycard/koishipro/server
only:
- server
- tags
......@@ -7,8 +7,8 @@ install:
- git submodule update --init --recursive
# environment and system dependency
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/premake/premake-core/releases/download/v5.0.0-beta2/premake-5.0.0-beta2-windows.zip ; exit 0"
- 7z x premake-5.0.0-beta2-windows.zip
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/premake/premake-core/releases/download/v5.0.0-beta5/premake-5.0.0-beta5-windows.zip ; exit 0"
- 7z x premake-5.0.0-beta5-windows.zip
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz ; exit 0"
- tar xf libevent-2.0.22-stable.tar.gz
......@@ -19,13 +19,16 @@ install:
- tar xf lua-5.4.4.tar.gz
- move lua-5.4.4 lua
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.sqlite.org/2022/sqlite-amalgamation-3390300.zip ; exit 0"
- 7z x -y sqlite-amalgamation-3390300.zip
- move sqlite-amalgamation-3390300 sqlite3
- bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.sqlite.org/2024/sqlite-amalgamation-3470000.zip ; exit 0"
- 7z x sqlite-amalgamation-3470000.zip
- move sqlite-amalgamation-3470000 sqlite3
- git clone --depth=1 https://github.com/mercury233/irrlicht irrlicht
before_build:
- xcopy /E premake\* .
- premake5 vs2019
- xcopy /E resource\* .
- premake5 vs2019 --server-zip-support
configuration: Release
......
No preview for this file type
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_GUI_BUTTON_H_INCLUDED__
#define __C_GUI_BUTTON_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUIButton.h"
#include "IGUISpriteBank.h"
#include "SColor.h"
namespace irr
{
namespace gui
{
class CGUIButton : public IGUIButton
{
public:
//! constructor
CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip=false);
//! destructor
virtual ~CGUIButton();
//! called if an event happened.
virtual bool OnEvent(const SEvent& event);
//! draws the element and its children
virtual void draw();
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
virtual void setOverrideFont(IGUIFont* font=0);
//! Gets the override font (if any)
virtual IGUIFont* getOverrideFont() const;
//! Get the font which is used right now for drawing
virtual IGUIFont* getActiveFont() const;
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets the sprite bank used by the button
virtual void setSpriteBank(IGUISpriteBank* bank=0);
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color=video::SColor(255,255,255,255), bool loop=false);
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
virtual void setIsPushButton(bool isPushButton=true);
//! Checks whether the button is a push button
virtual bool isPushButton() const;
//! Sets the pressed state of the button if this is a pushbutton
virtual void setPressed(bool pressed=true);
//! Returns if the button is currently pressed
virtual bool isPressed() const;
//! Sets if the button should use the skin to draw its border
virtual void setDrawBorder(bool border=true);
//! Checks if the button face and border are being drawn
virtual bool isDrawingBorder() const;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
virtual void setUseAlphaChannel(bool useAlphaChannel=true);
//! Checks if the alpha channel should be used for drawing images on the button
virtual bool isAlphaChannelUsed() const;
//! Sets if the button should scale the button images to fit
virtual void setScaleImage(bool scaleImage=true);
//! Checks whether the button scales the used images
virtual bool isScalingImage() const;
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
//! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
protected:
struct ButtonSprite
{
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
u32 ClickTime, HoverTime, FocusTime;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
};
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
#endif // __C_GUI_BUTTON_H_INCLUDED__
This diff is collapsed.
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_GUI_IMAGE_BUTTON_H_
#define _C_GUI_IMAGE_BUTTON_H_
#include <irrlicht.h>
#include "CGUIButton.h"
#include <IrrCompileConfig.h>
#ifdef _IRR_COMPILE_WITH_GUI_
#include <IGUIButton.h>
#include <SColor.h>
namespace irr {
namespace video {
class IVideoDriver;
class ITexture;
}
namespace gui {
class IGUISpriteBank;
void Draw2DImageRotation(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> position, core::position2d<s32> rotationPoint, f32 rotation = 0.0f,
core::vector2d<s32> position, core::vector2d<s32> rotationPoint, f32 rotation = 0.0f,
core::vector2df scale = core::vector2df(1.0, 1.0), bool useAlphaChannel = true, video::SColor color = 0xffffffff);
void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> corner[4], bool useAlphaChannel = true, video::SColor color = 0xffffffff);
class CGUIImageButton : public CGUIButton {
core::vector2d<s32> corner[4], bool useAlphaChannel = true, video::SColor color = 0xffffffff);
class CGUIImageButton : public IGUIButton {
public:
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle);
static CGUIImageButton* addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
virtual void draw();
virtual void setImage(video::ITexture* image = 0);
virtual void setDrawImage(bool b);
virtual void setImageRotation(f32 r);
virtual void setImageScale(core::vector2df s);
virtual void setImageSize(core::dimension2di s);
virtual IGUIFont* getOverrideFont(void) const;
virtual IGUIFont* getActiveFont() const;
private:
static CGUIImageButton* addImageButton(IGUIEnvironment* env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
//! constructor
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip = false);
//! destructor
~CGUIImageButton() override;
//! called if an event happened.
bool OnEvent(const SEvent& event) override;
//! draws the element and its children
void draw() override;
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
void setOverrideFont(IGUIFont* font = 0) override;
//! Gets the override font (if any)
IGUIFont* getOverrideFont() const override;
//! Get the font which is used right now for drawing
IGUIFont* getActiveFont() const override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets the sprite bank used by the button
void setSpriteBank(IGUISpriteBank* bank = 0) override;
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color = video::SColor(255, 255, 255, 255), bool loop = false) override;
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
void setIsPushButton(bool isPushButton = true) override;
//! Checks whether the button is a push button
bool isPushButton() const override;
//! Sets the pressed state of the button if this is a pushbutton
void setPressed(bool pressed = true) override;
//! Returns if the button is currently pressed
bool isPressed() const override;
//! Sets if the button should use the skin to draw its border
void setDrawBorder(bool border = true) override;
//! Checks if the button face and border are being drawn
bool isDrawingBorder() const override;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
void setUseAlphaChannel(bool useAlphaChannel = true) override;
//! Checks if the alpha channel should be used for drawing images on the button
bool isAlphaChannelUsed() const override;
//! Sets if the button should scale the button images to fit
void setScaleImage(bool scaleImage = true) override;
//! Checks whether the button scales the used images
bool isScalingImage() const override;
//! Writes attributes of the element.
void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const override;
//! Reads attributes of the element
void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) override;
// from ygopro
void setDrawImage(bool b);
void setImageRotation(f32 r);
void setImageScale(core::vector2df s);
void setImageSize(core::dimension2di s);
protected:
struct ButtonSprite
{
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
// from ygopro
bool isDrawImage;
bool isFixedSize;
f32 imageRotation;
......@@ -36,4 +155,6 @@ private:
}
}
#endif // _IRR_COMPILE_WITH_GUI_
#endif //_C_GUI_IMAGE_BUTTON_H_
This diff is collapsed.
......@@ -54,7 +54,7 @@ public:
//! Structure representing a single TrueType glyph.
struct SGUITTGlyph {
//! Constructor.
SGUITTGlyph() : isLoaded(false), glyph_page(0), surface(0), parent(0) {}
SGUITTGlyph() : isLoaded(false), glyph_page(0), advance({}), surface(0), parent(0) {}
//! Destructor.
~SGUITTGlyph() {
......@@ -207,93 +207,95 @@ public:
static CGUITTFont* create(IrrlichtDevice *device, const io::path& filename, const u32 size, const bool antialias = true, const bool transparency = true);
//! Destructor
virtual ~CGUITTFont();
~CGUITTFont() override;
//! Sets the amount of glyphs to batch load.
virtual void setBatchLoadSize(u32 batch_size) {
void setBatchLoadSize(u32 batch_size) {
batch_load_size = batch_size;
}
//! Sets the maximum texture size for a page of glyphs.
virtual void setMaxPageTextureSize(const core::dimension2du& texture_size) {
void setMaxPageTextureSize(const core::dimension2du& texture_size) {
max_page_texture_size = texture_size;
}
//! Get the font size.
virtual u32 getFontSize() const {
u32 getFontSize() const {
return size;
}
//! Check the font's transparency.
virtual bool isTransparent() const {
bool isTransparent() const {
return use_transparency;
}
//! Check if the font auto-hinting is enabled.
//! Auto-hinting is FreeType's built-in font hinting engine.
virtual bool useAutoHinting() const {
bool useAutoHinting() const {
return use_auto_hinting;
}
//! Check if the font hinting is enabled.
virtual bool useHinting() const {
bool useHinting() const {
return use_hinting;
}
//! Check if the font is being loaded as a monochrome font.
//! The font can either be a 256 color grayscale font, or a 2 color monochrome font.
virtual bool useMonochrome() const {
bool useMonochrome() const {
return use_monochrome;
}
//! Tells the font to allow transparency when rendering.
//! Default: true.
//! \param flag If true, the font draws using transparency.
virtual void setTransparency(const bool flag);
void setTransparency(const bool flag);
//! Tells the font to use monochrome rendering.
//! Default: false.
//! \param flag If true, the font draws using a monochrome image. If false, the font uses a grayscale image.
virtual void setMonochrome(const bool flag);
void setMonochrome(const bool flag);
//! Enables or disables font hinting.
//! Default: Hinting and auto-hinting true.
//! \param enable If false, font hinting is turned off. If true, font hinting is turned on.
//! \param enable_auto_hinting If true, FreeType uses its own auto-hinting algorithm. If false, it tries to use the algorithm specified by the font.
virtual void setFontHinting(const bool enable, const bool enable_auto_hinting = true);
void setFontHinting(const bool enable, const bool enable_auto_hinting = true);
//! Draws some text and clips it to the specified rectangle if wanted.
virtual void draw(const core::stringw& text, const core::rect<s32>& position,
void draw(const core::stringw& text, const core::rect<s32>& position,
video::SColor color, bool hcenter = false, bool vcenter = false,
const core::rect<s32>* clip = 0);
const core::rect<s32>* clip = 0) override;
void drawUstring(const core::ustring& text, const core::rect<s32>& position,
video::SColor color, bool hcenter = false, bool vcenter = false,
const core::rect<s32>* clip = 0);
//! Returns the dimension of a character produced by this font.
virtual core::dimension2d<u32> getCharDimension(const wchar_t ch) const;
core::dimension2d<u32> getCharDimension(const wchar_t ch) const;
//! Returns the dimension of a text string.
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const;
virtual core::dimension2d<u32> getDimension(const core::ustring& text) const;
core::dimension2d<u32> getDimension(const wchar_t* text) const override;
core::dimension2d<u32> getDimension(const core::ustring& text) const;
//! Calculates the index of the character in the text which is on a specific position.
virtual s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const;
virtual s32 getCharacterFromPos(const core::ustring& text, s32 pixel_x) const;
s32 getCharacterFromPos(const wchar_t* text, s32 pixel_x) const override;
s32 getCharacterFromPos(const core::ustring& text, s32 pixel_x) const;
//! Sets global kerning width for the font.
virtual void setKerningWidth(s32 kerning);
void setKerningWidth(s32 kerning) override;
//! Sets global kerning height for the font.
virtual void setKerningHeight(s32 kerning);
void setKerningHeight(s32 kerning) override;
//! Gets kerning values (distance between letters) for the font. If no parameters are provided,
virtual s32 getKerningWidth(const wchar_t* thisLetter = 0, const wchar_t* previousLetter = 0) const;
virtual s32 getKerningWidth(const uchar32_t thisLetter = 0, const uchar32_t previousLetter = 0) const;
s32 getKerningWidth(const wchar_t* thisLetter = 0, const wchar_t* previousLetter = 0) const override;
s32 getKerningWidth(const uchar32_t thisLetter = 0, const uchar32_t previousLetter = 0) const;
//! Returns the distance between letters
virtual s32 getKerningHeight() const;
s32 getKerningHeight() const override;
//! Define which characters should not be drawn by the font.
virtual void setInvisibleCharacters(const wchar_t *s);
virtual void setInvisibleCharacters(const core::ustring& s);
void setInvisibleCharacters(const wchar_t *s) final;
//! Get the last glyph page if there's still available slots.
//! If not, it will return zero.
......@@ -312,14 +314,14 @@ public:
//! Create corresponding character's software image copy from the font,
//! so you can use this data just like any ordinary video::IImage.
//! \param ch The character you need
virtual video::IImage* createTextureFromChar(const uchar32_t& ch);
video::IImage* createTextureFromChar(const uchar32_t& ch);
//! This function is for debugging mostly. If the page doesn't exist it returns zero.
//! \param page_index Simply return the texture handle of a given page index.
virtual video::ITexture* getPageTextureByIndex(const u32& page_index) const;
video::ITexture* getPageTextureByIndex(const u32& page_index) const;
//! Add a list of scene nodes generated by putting font textures on the 3D planes.
virtual core::array<scene::ISceneNode*> addTextSceneNode
core::array<scene::ISceneNode*> addTextSceneNode
(const wchar_t* text, scene::ISceneManager* smgr, scene::ISceneNode* parent = 0,
const video::SColor& color = video::SColor(255, 0, 0, 0), bool center = false );
......@@ -340,7 +342,7 @@ private:
static scene::IMesh* shared_plane_ptr_;
static scene::SMesh shared_plane_;
CGUITTFont(IGUIEnvironment *env);
explicit CGUITTFont(IGUIEnvironment *env);
bool load(const io::path& filename, const u32 size, const bool antialias, const bool transparency);
void reset_images();
void update_glyph_pages() const;
......
......@@ -2,44 +2,47 @@
#define BUFFERIO_H
#include <cstdint>
#include <cwchar>
#include "../ocgcore/buffer.h"
class BufferIO {
public:
inline static int ReadInt32(unsigned char*& p) {
static int ReadInt32(unsigned char*& p) {
return buffer_read<int32_t>(p);
}
inline static unsigned int ReadUInt32(unsigned char*& p) {
unsigned int ret = *(unsigned int*)p;
p += 4;
return ret;
static unsigned int ReadUInt32(unsigned char*& p) {
return buffer_read<uint32_t>(p);
}
inline static short ReadInt16(unsigned char*& p) {
static short ReadInt16(unsigned char*& p) {
return buffer_read<int16_t>(p);
}
inline static unsigned short ReadUInt16(unsigned char*& p) {
unsigned short ret = *(unsigned short*)p;
p += 2;
return ret;
static unsigned short ReadUInt16(unsigned char*& p) {
return buffer_read<uint16_t>(p);
}
inline static char ReadInt8(unsigned char*& p) {
static char ReadInt8(unsigned char*& p) {
return buffer_read<char>(p);
}
inline static unsigned char ReadUInt8(unsigned char*& p) {
static unsigned char ReadUInt8(unsigned char*& p) {
return buffer_read<unsigned char>(p);
}
inline static void WriteInt32(unsigned char*& p, int val) {
static void WriteInt32(unsigned char*& p, int val) {
buffer_write<int32_t>(p, val);
}
inline static void WriteInt16(unsigned char*& p, short val) {
static void WriteInt16(unsigned char*& p, short val) {
buffer_write<int16_t>(p, val);
}
inline static void WriteInt8(unsigned char*& p, char val) {
static void WriteInt8(unsigned char*& p, char val) {
buffer_write<char>(p, val);
}
// return: string length
/**
* @brief Copy a C-style string to another C-style string.
* @param src The source wide string
* @param pstr The destination char string
* @param bufsize The length of the destination buffer
* @return The length of the copied string
*/
template<typename T1, typename T2>
inline static int CopyWStr(const T1* src, T2* pstr, int bufsize) {
static int CopyWStr(const T1* src, T2* pstr, int bufsize) {
int l = 0;
while(src[l] && l < bufsize - 1) {
pstr[l] = (T2)src[l];
......@@ -49,7 +52,7 @@ public:
return l;
}
template<typename T1, typename T2>
inline static int CopyWStrRef(const T1* src, T2*& pstr, int bufsize) {
static int CopyWStrRef(const T1* src, T2*& pstr, int bufsize) {
int l = 0;
while(src[l] && l < bufsize - 1) {
pstr[l] = (T2)src[l];
......@@ -59,22 +62,131 @@ public:
*pstr = 0;
return l;
}
template<typename T1, typename T2, size_t N>
static int CopyCharArray(const T1* src, T2(&dst)[N]) {
return CopyWStr(src, dst, N);
}
template<size_t N>
static void CopyString(const char* src, char(&dst)[N]) {
std::strncpy(dst, src, N - 1);
dst[N - 1] = 0;
}
template<size_t N>
static void CopyWideString(const wchar_t* src, wchar_t(&dst)[N]) {
std::wcsncpy(dst, src, N - 1);
dst[N - 1] = 0;
}
template<typename T>
static bool CheckUTF8Byte(const T* str, int len) {
for (int i = 1; i < len; ++i) {
if ((str[i] & 0xc0U) != 0x80U)
return false;
}
return true;
}
static unsigned int ConvertUTF8(const char*& p) {
unsigned int cur = 0;
if ((p[0] & 0x80U) == 0) {
cur = p[0] & 0xffU;
p++;
}
else if ((p[0] & 0xe0U) == 0xc0U) {
if (!CheckUTF8Byte(p, 2)) {
p++;
return UINT32_MAX;
}
cur = ((p[0] & 0x1fU) << 6) | (p[1] & 0x3fU);
p += 2;
if(cur < 0x80U)
return UINT32_MAX;
}
else if ((p[0] & 0xf0U) == 0xe0U) {
if (!CheckUTF8Byte(p, 3)) {
p++;
return UINT32_MAX;
}
cur = ((p[0] & 0xfU) << 12) | ((p[1] & 0x3fU) << 6) | (p[2] & 0x3fU);
p += 3;
if (cur < 0x800U)
return UINT32_MAX;
}
else if ((p[0] & 0xf8U) == 0xf0U) {
if (!CheckUTF8Byte(p, 4)) {
p++;
return UINT32_MAX;
}
cur = ((p[0] & 0x7U) << 18) | ((p[1] & 0x3fU) << 12) | ((p[2] & 0x3fU) << 6) | (p[3] & 0x3fU);
p += 4;
if (cur < 0x10000U)
return UINT32_MAX;
}
else {
p++;
return UINT32_MAX;
}
return cur;
}
static bool IsHighSurrogate(unsigned int c) {
return (c >= 0xd800U && c <= 0xdbffU);
}
static bool IsLowSurrogate(unsigned int c) {
return (c >= 0xdc00U && c <= 0xdfffU);
}
static bool IsUnicodeChar(unsigned int c) {
if(IsHighSurrogate(c))
return false;
if (IsLowSurrogate(c))
return false;
if (c > 0x10ffffU)
return false;
return true;
}
// UTF-16/UTF-32 to UTF-8
// return: string length
static int EncodeUTF8String(const wchar_t* wsrc, char* str, int size) {
char* pstr = str;
while (*wsrc != 0) {
unsigned cur = *wsrc;
auto pw = wsrc;
auto pstr = str;
while (*pw != 0) {
unsigned cur = 0;
int codepoint_size = 0;
if (sizeof(wchar_t) == 2) {
if (IsHighSurrogate(pw[0])) {
if (pw[1] == 0)
break;
if (IsLowSurrogate(pw[1])) {
cur = ((pw[0] & 0x3ffU) << 10) | (pw[1] & 0x3ffU);
cur += 0x10000;
pw += 2;
}
else {
pw++;
continue;
}
}
else if (IsLowSurrogate(pw[0])) {
pw++;
continue;
}
else {
cur = *pw;
pw++;
}
}
else {
cur = *pw;
pw++;
}
if (!IsUnicodeChar(cur))
continue;
if (cur < 0x80U)
codepoint_size = 1;
else if (cur < 0x800U)
codepoint_size = 2;
else if (cur < 0x10000U && (cur < 0xd800U || cur > 0xdfffU))
else if (cur < 0x10000U)
codepoint_size = 3;
else
codepoint_size = 4;
if (pstr - str + codepoint_size > size - 1)
if ((int)(pstr - str) + codepoint_size > size - 1)
break;
switch (codepoint_size) {
case 1:
......@@ -90,13 +202,6 @@ public:
pstr[2] = (cur & 0x3f) | 0x80;
break;
case 4:
if (sizeof(wchar_t) == 2) {
cur = 0;
cur |= ((unsigned)*wsrc & 0x3ff) << 10;
++wsrc;
cur |= (unsigned)*wsrc & 0x3ff;
cur += 0x10000;
}
pstr[0] = ((cur >> 18) & 0x7) | 0xf0;
pstr[1] = ((cur >> 12) & 0x3f) | 0x80;
pstr[2] = ((cur >> 6) & 0x3f) | 0x80;
......@@ -106,10 +211,9 @@ public:
break;
}
pstr += codepoint_size;
wsrc++;
}
*pstr = 0;
return pstr - str;
return (int)(pstr - str);
}
// UTF-8 to UTF-16/UTF-32
// return: string length
......@@ -117,9 +221,11 @@ public:
const char* p = src;
wchar_t* wp = wstr;
while(*p != 0) {
const unsigned cur = (unsigned)*p & 0xff;
unsigned int cur = ConvertUTF8(p);
int codepoint_size = 0;
if ((cur & 0xf8) == 0xf0) {
if (!IsUnicodeChar(cur))
continue;
if (cur >= 0x10000) {
if (sizeof(wchar_t) == 2)
codepoint_size = 2;
else
......@@ -127,30 +233,18 @@ public:
}
else
codepoint_size = 1;
if (wp - wstr + codepoint_size > size - 1)
if ((int)(wp - wstr) + codepoint_size > size - 1)
break;
if((cur & 0x80) == 0) {
*wp = *p;
p++;
} else if((cur & 0xe0) == 0xc0) {
*wp = (((unsigned)p[0] & 0x1f) << 6) | ((unsigned)p[1] & 0x3f);
p += 2;
} else if((cur & 0xf0) == 0xe0) {
*wp = (((unsigned)p[0] & 0xf) << 12) | (((unsigned)p[1] & 0x3f) << 6) | ((unsigned)p[2] & 0x3f);
p += 3;
} else if((cur & 0xf8) == 0xf0) {
if (sizeof(wchar_t) == 2) {
unsigned unicode = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
unicode -= 0x10000;
*wp++ = (unicode >> 10) | 0xd800;
*wp = (unicode & 0x3ff) | 0xdc00;
} else {
*wp = (((unsigned)p[0] & 0x7) << 18) | (((unsigned)p[1] & 0x3f) << 12) | (((unsigned)p[2] & 0x3f) << 6) | ((unsigned)p[3] & 0x3f);
}
p += 4;
} else
p++;
wp++;
if (codepoint_size == 1) {
wp[0] = cur;
wp++;
}
else {
cur -= 0x10000U;
wp[0] = (cur >> 10) | 0xd800;
wp[1] = (cur & 0x3ff) | 0xdc00;
wp += 2;
}
}
*wp = 0;
return wp - wstr;
......@@ -163,15 +257,23 @@ public:
static int DecodeUTF8(const char* src, wchar_t(&dst)[N]) {
return DecodeUTF8String(src, dst, N);
}
template<size_t N, typename T>
static void NullTerminate(T(&str)[N]) {
str[N - 1] = 0;
}
static int GetVal(const wchar_t* pstr) {
unsigned int ret = 0;
while(*pstr >= L'0' && *pstr <= L'9') {
ret = ret * 10 + (*pstr - L'0');
pstr++;
if (*pstr >= L'0' && *pstr <= L'9') {
int ret{};
wchar_t* str_end{};
ret = std::wcstol(pstr, &str_end, 10);
if (*str_end == 0)
return ret;
else
return 0;
}
if (*pstr == 0)
return (int)ret;
return 0;
else
return 0;
}
};
......
#include "client_card.h"
#include "client_field.h"
#include "data_manager.h"
#include "game.h"
namespace ygo {
......@@ -32,12 +31,12 @@ ClientCard::~ClientCard() {
}
overlayed.clear();
}
void ClientCard::SetCode(int code) {
if((location == LOCATION_HAND) && (this->code != (unsigned int)code)) {
this->code = code;
void ClientCard::SetCode(unsigned int x) {
if((location == LOCATION_HAND) && (code != x)) {
code = x;
mainGame->dField.MoveCard(this, 5);
} else
this->code = code;
code = x;
}
void ClientCard::UpdateInfo(unsigned char* buf) {
int flag = BufferIO::ReadInt32(buf);
......@@ -57,7 +56,7 @@ void ClientCard::UpdateInfo(unsigned char* buf) {
}
if(flag & QUERY_POSITION) {
int pdata = (BufferIO::ReadInt32(buf) >> 24) & 0xff;
if((location & (LOCATION_EXTRA | LOCATION_REMOVED)) && (u8)pdata != position) {
if((location & (LOCATION_EXTRA | LOCATION_REMOVED)) && pdata != position) {
position = pdata;
mainGame->dField.MoveCard(this, 1);
} else
......@@ -176,13 +175,13 @@ void ClientCard::UpdateInfo(unsigned char* buf) {
}
}
void ClientCard::ClearTarget() {
for(auto cit = cardTarget.begin(); cit != cardTarget.end(); ++cit) {
(*cit)->is_showtarget = false;
(*cit)->ownerTarget.erase(this);
for (auto& pcard : cardTarget) {
pcard->is_showtarget = false;
pcard->ownerTarget.erase(this);
}
for(auto cit = ownerTarget.begin(); cit != ownerTarget.end(); ++cit) {
(*cit)->is_showtarget = false;
(*cit)->cardTarget.erase(this);
for (auto& pcard : ownerTarget) {
pcard->is_showtarget = false;
pcard->cardTarget.erase(this);
}
cardTarget.clear();
ownerTarget.clear();
......@@ -215,101 +214,35 @@ void ClientCard::ClearData() {
bool ClientCard::client_card_sort(ClientCard* c1, ClientCard* c2) {
if(c1->is_selected != c2->is_selected)
return c1->is_selected < c2->is_selected;
int32 cp1 = c1->overlayTarget ? c1->overlayTarget->controler : c1->controler;
int32 cp2 = c2->overlayTarget ? c2->overlayTarget->controler : c2->controler;
int cp1 = c1->overlayTarget ? c1->overlayTarget->controler : c1->controler;
int cp2 = c2->overlayTarget ? c2->overlayTarget->controler : c2->controler;
if(cp1 != cp2)
return cp1 < cp2;
if(c1->location != c2->location)
return c1->location < c2->location;
if (c1->location & LOCATION_OVERLAY) {
if (c1->location == LOCATION_OVERLAY) {
if (c1->overlayTarget != c2->overlayTarget)
return c1->overlayTarget->sequence < c2->overlayTarget->sequence;
else
return c1->sequence < c2->sequence;
}
else {
if(c1->location & (LOCATION_DECK | LOCATION_GRAVE | LOCATION_REMOVED | LOCATION_EXTRA)) {
auto it1 = std::find_if(mainGame->dField.chains.rbegin(), mainGame->dField.chains.rend(), [c1](const ChainInfo& ch) {
return c1 == ch.chain_card || ch.target.find(c1) != ch.target.end();
});
auto it2 = std::find_if(mainGame->dField.chains.rbegin(), mainGame->dField.chains.rend(), [c2](const ChainInfo& ch) {
return c2 == ch.chain_card || ch.target.find(c2) != ch.target.end();
});
if(it1 != mainGame->dField.chains.rend() || it2 != mainGame->dField.chains.rend()) {
return it1 < it2;
}
return c1->sequence > c2->sequence;
else if (c1->location == LOCATION_DECK) {
return c1->sequence > c2->sequence;
}
else if (c1->location & (LOCATION_GRAVE | LOCATION_REMOVED | LOCATION_EXTRA)) {
auto it1 = std::find_if(mainGame->dField.chains.rbegin(), mainGame->dField.chains.rend(), [c1](const ChainInfo& ch) {
return c1 == ch.chain_card || ch.target.find(c1) != ch.target.end();
});
auto it2 = std::find_if(mainGame->dField.chains.rbegin(), mainGame->dField.chains.rend(), [c2](const ChainInfo& ch) {
return c2 == ch.chain_card || ch.target.find(c2) != ch.target.end();
});
if (it1 != mainGame->dField.chains.rend() || it2 != mainGame->dField.chains.rend()) {
return it1 < it2;
}
else
return c1->sequence < c2->sequence;
}
}
bool ClientCard::deck_sort_lv(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
int type1 = (p1->second.type & 0x48020c0) ? (p1->second.type & 0x48020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x48020c0) ? (p2->second.type & 0x48020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if(p1->second.defense != p2->second.defense)
return p1->second.defense > p2->second.defense;
return p1->first < p2->first;
return c1->sequence > c2->sequence;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_atk(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if(p1->second.defense != p2->second.defense)
return p1->second.defense > p2->second.defense;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
int type1 = (p1->second.type & 0x48020c0) ? (p1->second.type & 0x48020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x48020c0) ? (p2->second.type & 0x48020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_def(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
if(p1->second.defense != p2->second.defense)
return p1->second.defense > p2->second.defense;
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
int type1 = (p1->second.type & 0x48020c0) ? (p1->second.type & 0x48020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x48020c0) ? (p2->second.type & 0x48020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
return p1->first < p2->first;
else {
return c1->sequence < c2->sequence;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_name(code_pointer p1, code_pointer p2) {
const wchar_t* name1 = dataManager.GetName(p1->first);
const wchar_t* name2 = dataManager.GetName(p2->first);
int res = wcscmp(name1, name2);
if(res != 0)
return res < 0;
return p1->first < p2->first;
}
}
......@@ -2,35 +2,12 @@
#define CLIENT_CARD_H
#include "config.h"
#include "../ocgcore/card_data.h"
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
namespace ygo {
using CardData = card_data;
struct CardDataC : card_data {
unsigned int ot{};
unsigned int category{};
bool is_setcodes(std::vector <uint32> values) const {
for (auto& value : values) {
if (is_setcode(value))
return true;
}
return false;
}
};
struct CardString {
std::wstring name;
std::wstring text;
std::wstring desc[16];
};
typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer;
typedef std::unordered_map<unsigned int, CardString>::const_iterator string_pointer;
class ClientCard {
public:
#ifndef YGOPRO_SERVER_MODE
......@@ -39,9 +16,9 @@ public:
irr::core::vector3df curRot;
irr::core::vector3df dPos;
irr::core::vector3df dRot;
u32 curAlpha{ 255 };
u32 dAlpha{ 0 };
u32 aniFrame{ 0 };
irr::u32 curAlpha{ 255 };
irr::u32 dAlpha{ 0 };
irr::u32 aniFrame{ 0 };
bool is_moving{ false };
bool is_fading{ false };
bool is_hovered{ false };
......@@ -99,15 +76,11 @@ public:
ClientCard() = default;
~ClientCard();
void SetCode(int code);
void SetCode(unsigned int x);
void UpdateInfo(unsigned char* buf);
void ClearTarget();
void ClearData();
static bool client_card_sort(ClientCard* c1, ClientCard* c2);
static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2);
static bool deck_sort_def(code_pointer l1, code_pointer l2);
static bool deck_sort_name(code_pointer l1, code_pointer l2);
#endif //YGOPRO_SERVER_MODE
};
......
This diff is collapsed.
......@@ -58,9 +58,12 @@ public:
int select_min{ 0 };
int select_max{ 0 };
int must_select_count{ 0 };
int select_curval_l{ 0 };
int select_curval_h{ 0 };
int select_sumval{ 0 };
int select_mode{ 0 };
bool select_cancelable{ false };
int select_hint{0};
bool select_cancelable{false};
bool select_panalmode{ false };
bool select_ready{ false };
int announce_count{ 0 };
......@@ -71,15 +74,15 @@ public:
std::vector<ClientCard*> selected_cards;
std::set<ClientCard*> selectsum_cards;
std::vector<ClientCard*> selectsum_all;
std::vector<int> declare_opcodes;
std::vector<unsigned int> declare_opcodes;
std::vector<ClientCard*> display_cards;
std::vector<int> sort_list;
std::map<int, int> player_desc_hints[2];
bool grave_act{ false };
bool remove_act{ false };
bool deck_act{ false };
bool extra_act{ false };
bool pzone_act[2]{};
bool grave_act[2]{ false };
bool remove_act[2]{ false };
bool deck_act[2]{ false };
bool extra_act[2]{ false };
bool pzone_act[2]{ false };
bool conti_act{ false };
bool chain_forced{ false };
ChainInfo current_chain;
......@@ -94,7 +97,8 @@ public:
ClientField();
~ClientField();
void Clear();
void Initial(int player, int deckc, int extrac);
void Initial(int player, int deckc, int extrac, int sidec = 0);
void ResetSequence(std::vector<ClientCard*>& list, bool reset_height);
ClientCard* GetCard(int controler, int location, int sequence, int sub_seq = 0);
void AddCard(ClientCard* pcard, int controler, int location, int sequence);
ClientCard* RemoveCard(int controler, int location, int sequence);
......@@ -129,9 +133,6 @@ public:
void RefreshCardCountDisplay();
irr::gui::IGUIElement* panel{ nullptr };
bool is_dragging_cardtext{ false };
int dragging_cardtext_start_pos{ 0 };
int dragging_cardtext_start_y{ 0 };
std::vector<int> ancard;
int hovered_controler{ 0 };
int hovered_location{ 0 };
......@@ -147,8 +148,8 @@ public:
ClientCard* menu_card{ nullptr };
int list_command{ 0 };
virtual bool OnEvent(const irr::SEvent& event);
virtual bool OnCommonEvent(const irr::SEvent& event);
bool OnEvent(const irr::SEvent& event) override;
bool OnCommonEvent(const irr::SEvent& event);
void GetHoverField(int x, int y);
void ShowMenu(int flag, int x, int y);
void HideMenu();
......@@ -164,8 +165,6 @@ public:
}
//special cards
#define CARD_MARINE_DOLPHIN 78734254
#define CARD_TWINKLE_MOSS 13857930
#define CARD_QUESTION 38723936
#endif //CLIENT_FIELD_H
#ifndef __CONFIG_H
#define __CONFIG_H
#pragma once
#ifndef YGOPRO_CONFIG_H
#define YGOPRO_CONFIG_H
#define _IRR_STATIC_LIB_
#define IRR_COMPILE_WITH_DX9_DEV_PACK
#include <cerrno>
#ifdef _WIN32
#define NOMINMAX
......@@ -24,14 +25,12 @@
#else //_WIN32
#include <errno.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <locale.h>
#define SD_BOTH 2
#define SOCKET int
......@@ -42,58 +41,61 @@
#define SOCKADDR sockaddr
#define SOCKET_ERRNO() (errno)
#include <wchar.h>
#define mywcsncasecmp wcsncasecmp
#define mystrncasecmp strncasecmp
inline int _wtoi(const wchar_t * s) {
wchar_t * endptr;
return (int)wcstol(s, &endptr, 10);
}
#endif
template<size_t N, typename... TR>
inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
return swprintf(buf, N, fmt, args...);
#ifndef _WIN32
#include <wchar.h>
inline int _wtoi(const wchar_t * str){
return (int)wcstol(str, 0, 10);
}
#endif
#ifndef YGOPRO_SERVER_MODE
#include <irrlicht.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else //__APPLE__
#include <GL/gl.h>
#include <GL/glu.h>
#endif //__APPLE__
#include "CGUITTFont.h"
#include "CGUIImageButton.h"
#endif //YGOPRO_SERVER_MODE
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <thread>
#include <mutex>
#include <algorithm>
#include <string>
#include "bufferio.h"
#include "myfilesystem.h"
#include "mysignal.h"
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/common.h"
#ifndef YGOPRO_SERVER_MODE
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#endif //YGOPRO_SERVER_MODE
#ifdef SERVER_ZIP_SUPPORT
template<size_t N, typename... TR>
inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
return std::swprintf(buf, N, fmt, args...);
}
inline FILE* mywfopen(const wchar_t* filename, const char* mode) {
FILE* fp{};
#ifdef _WIN32
wchar_t wmode[20]{};
BufferIO::CopyCharArray(mode, wmode);
fp = _wfopen(filename, wmode);
#else
char fname[1024]{};
BufferIO::EncodeUTF8(filename, fname);
fp = std::fopen(fname, mode);
#endif
return fp;
}
#if !defined(_WIN32)
#define myfopen std::fopen
#elif defined(WDK_NTDDI_VERSION) && (WDK_NTDDI_VERSION >= 0x0A000005) // Redstone 4, Version 1803, Build 17134.
#define FOPEN_WINDOWS_SUPPORT_UTF8
#define myfopen std::fopen
#else
inline FILE* myfopen(const char* filename, const char* mode) {
wchar_t wfilename[256]{};
BufferIO::DecodeUTF8(filename, wfilename);
wchar_t wmode[20]{};
BufferIO::CopyCharArray(mode, wmode);
return _wfopen(wfilename, wmode);
}
#endif
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
#include <irrlicht.h>
using namespace irr;
using namespace io;
#endif
extern unsigned short PRO_VERSION;
......
This diff is collapsed.
#ifndef DATAMANAGER_H
#define DATAMANAGER_H
#include "config.h"
#include "sqlite3.h"
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
#include "spmemvfs/spmemvfs.h"
#endif
#include "client_card.h"
#include <unordered_map>
#include <vector>
#include <string>
#include <sqlite3.h>
#include "../ocgcore/card_data.h"
namespace irr {
namespace io {
class IReadFile;
class IFileSystem;
}
}
namespace ygo {
constexpr int MAX_STRING_ID = 0x7ff;
constexpr unsigned int MIN_CARD_ID = (unsigned int)(MAX_STRING_ID + 1) >> 4;
constexpr int MAX_STRING_ID = 0x7ff;
constexpr unsigned int MIN_CARD_ID = (unsigned int)(MAX_STRING_ID + 1) >> 4;
constexpr unsigned int MAX_CARD_ID = 0x0fffffffU;
using CardData = card_data;
struct CardDataC : card_data {
uint32_t ot{};
uint32_t category{};
bool is_setcodes(const std::vector<unsigned int>& values) const {
for (auto& value : values) {
if (is_setcode(value))
return true;
}
return false;
}
};
struct CardString {
std::wstring name;
std::wstring text;
std::wstring desc[16];
};
using code_pointer = std::unordered_map<unsigned int, CardDataC>::const_iterator;
using string_pointer = std::unordered_map<unsigned int, CardString>::const_iterator;
class DataManager {
public:
DataManager();
bool ReadDB(sqlite3* pDB);
bool LoadDB(const wchar_t* wfile);
bool LoadStrings(const char* file);
#ifndef YGOPRO_SERVER_MODE
bool LoadStrings(IReadFile* reader);
#endif
bool LoadStrings(const char* file);
bool LoadStrings(irr::io::IReadFile* reader);
void ReadStringConfLine(const char* linebuf);
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
bool Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt = 0);
#else
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = 0);
#endif //YGOPRO_SERVER_MODE
bool GetData(unsigned int code, CardData* pData);
#endif
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = nullptr);
code_pointer GetCodePointer(unsigned int code) const;
#ifndef YGOPRO_SERVER_MODE
string_pointer GetStringPointer(unsigned int code) const;
bool GetString(unsigned int code, CardString* pStr);
const wchar_t* GetName(unsigned int code);
const wchar_t* GetText(unsigned int code);
const wchar_t* GetDesc(unsigned int strCode);
const wchar_t* GetSysString(int code);
const wchar_t* GetVictoryString(int code);
const wchar_t* GetCounterName(int code);
const wchar_t* GetSetName(int code);
std::vector<unsigned int> GetSetCodes(std::wstring setname);
const wchar_t* GetNumString(int num, bool bracket = false);
const wchar_t* FormatLocation(int location, int sequence);
const wchar_t* FormatAttribute(int attribute);
const wchar_t* FormatRace(int race);
const wchar_t* FormatType(int type);
const wchar_t* FormatSetName(const uint16_t setcode[]);
const wchar_t* FormatLinkMarker(int link_marker);
code_pointer datas_begin() const;
code_pointer datas_end() const;
string_pointer strings_begin() const;
string_pointer strings_end() const;
#endif
bool GetData(unsigned int code, CardData* pData) const;
#ifndef YGOPRO_SERVER_MODE
bool GetString(unsigned int code, CardString* pStr) const;
const wchar_t* GetName(unsigned int code) const;
const wchar_t* GetText(unsigned int code) const;
const wchar_t* GetDesc(unsigned int strCode) const;
const wchar_t* GetSysString(int code) const;
const wchar_t* GetVictoryString(int code) const;
const wchar_t* GetCounterName(int code) const;
const wchar_t* GetSetName(int code) const;
std::vector<unsigned int> GetSetCodes(std::wstring setname) const;
std::wstring GetNumString(int num, bool bracket = false) const;
const wchar_t* FormatLocation(int location, int sequence) const;
std::wstring FormatAttribute(unsigned int attribute) const;
std::wstring FormatRace(unsigned int race) const;
std::wstring FormatType(unsigned int type) const;
std::wstring FormatSetName(const uint16_t setcode[]) const;
std::wstring FormatLinkMarker(unsigned int link_marker) const;
std::unordered_map<unsigned int, std::wstring> _counterStrings;
std::unordered_map<unsigned int, std::wstring> _victoryStrings;
std::unordered_map<unsigned int, std::wstring> _setnameStrings;
std::unordered_map<unsigned int, std::wstring> _sysStrings;
code_pointer datas_begin;
code_pointer datas_end;
string_pointer strings_begin;
string_pointer strings_end;
wchar_t numStrings[301][4]{};
wchar_t numBuffer[6]{};
wchar_t attBuffer[128]{};
wchar_t racBuffer[128]{};
wchar_t tpBuffer[128]{};
wchar_t scBuffer[128]{};
wchar_t lmBuffer[32]{};
#endif
char errmsg[512]{};
static byte scriptBuffer[0x20000];
static unsigned char scriptBuffer[0x100000];
static const wchar_t* unknown_string;
static uint32 CardReader(uint32, card_data*);
static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len = 2);
static byte* ScriptReader(const char* script_name, int* slen);
static uint32_t CardReader(uint32_t, card_data*);
static unsigned char* ScriptReaderEx(const char* script_name, int* slen);
static unsigned char* ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len = 2, unsigned int use_irr = FALSE);
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
static IFileSystem* FileSystem;
//read by IFileSystem
static unsigned char* ReadScriptFromIrrFS(const char* script_name, int* slen);
#endif
//read by fread
static unsigned char* ReadScriptFromFile(const char* script_name, int* slen);
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
static irr::io::IFileSystem* FileSystem;
#endif
#ifndef YGOPRO_SERVER_MODE
static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2);
static bool deck_sort_def(code_pointer l1, code_pointer l2);
static bool deck_sort_name(code_pointer l1, code_pointer l2);
#endif
static bool deck_sort_lv(code_pointer l1, code_pointer l2);
static bool deck_sort_atk(code_pointer l1, code_pointer l2);
static bool deck_sort_def(code_pointer l1, code_pointer l2);
static bool deck_sort_name(code_pointer l1, code_pointer l2);
private:
std::unordered_map<unsigned int, CardDataC> _datas;
......
This diff is collapsed.
#ifndef DECK_CON_H
#define DECK_CON_H
#include "config.h"
#include <unordered_map>
#include <vector>
#include "client_card.h"
#include <irrlicht.h>
#include "data_manager.h"
#include "deck_manager.h"
#include "../ocgcore/mtrandom.h"
namespace ygo {
class DeckBuilder: public irr::IEventReceiver {
public:
virtual bool OnEvent(const irr::SEvent& event);
bool OnEvent(const irr::SEvent& event) override;
void Initialize();
void Terminate();
void GetHoveredCard();
......@@ -28,7 +29,7 @@ public:
void ChangeCategory(int catesel);
void ShowDeckManage();
void ShowBigCard(int code, float zoom);
void ZoomBigCard(s32 centerx = -1, s32 centery = -1);
void ZoomBigCard(irr::s32 centerx = -1, irr::s32 centery = -1);
void CloseBigCard();
bool CardNameContains(const wchar_t *haystack, const wchar_t *needle);
......@@ -41,7 +42,7 @@ public:
void pop_side(int seq);
bool check_limit(code_pointer pointer);
long long filter_effect{};
unsigned long long filter_effect{};
unsigned int filter_type{};
unsigned int filter_type2{};
unsigned int filter_attrib{};
......@@ -56,7 +57,7 @@ public:
unsigned int filter_scl{};
unsigned int filter_marks{};
int filter_lm{};
position2di mouse_pos;
irr::core::vector2di mouse_pos;
int hovered_code{};
int hovered_pos{};
int hovered_seq{ -1 };
......@@ -74,14 +75,14 @@ public:
code_pointer draging_pointer;
int prev_category{};
int prev_deck{};
s32 prev_operation{};
irr::s32 prev_operation{};
int prev_sel{ -1 };
bool is_modified{};
bool readonly{};
bool showing_pack{};
mt19937 rnd;
const std::unordered_map<int, int>* filterList;
const LFList* filterList{};
std::vector<code_pointer> results;
wchar_t result_string[8]{};
std::vector<std::wstring> expansionPacks;
......
This diff is collapsed.
#ifndef DECKMANAGER_H
#define DECKMANAGER_H
#include "config.h"
#include "client_card.h"
#include <unordered_map>
#include <vector>
#ifndef YGOPRO_SERVER_MODE
#include <sstream>
#endif
#include "data_manager.h"
#ifndef YGOPRO_MAX_DECK
#define YGOPRO_MAX_DECK 60
......@@ -30,17 +27,18 @@ namespace ygo {
constexpr int DECK_MIN_SIZE = YGOPRO_MIN_DECK;
constexpr int EXTRA_MAX_SIZE = YGOPRO_MAX_EXTRA;
constexpr int SIDE_MAX_SIZE = YGOPRO_MAX_SIDE;
constexpr int PACK_MAX_SIZE = 1000;
struct LFList {
unsigned int hash{};
std::wstring listName;
std::unordered_map<int, int> content;
std::unordered_map<unsigned int, int> content;
};
struct Deck {
std::vector<code_pointer> main;
std::vector<code_pointer> extra;
std::vector<code_pointer> side;
Deck() {}
Deck() = default;
Deck(const Deck& ndeck) {
main = ndeck.main;
extra = ndeck.extra;
......@@ -53,6 +51,12 @@ struct Deck {
}
};
struct DeckArray {
std::vector<uint32_t> main;
std::vector<uint32_t> extra;
std::vector<uint32_t> side;
};
class DeckManager {
public:
Deck current_deck;
......@@ -64,29 +68,33 @@ public:
void LoadLFListSingle(const char* path);
void LoadLFList();
const wchar_t* GetLFListName(int lfhash);
const std::unordered_map<int, int>* GetLFListContent(int lfhash);
int CheckDeck(Deck& deck, int lfhash, int rule);
int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_packlist = false);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
const wchar_t* GetLFListName(unsigned int lfhash);
const LFList* GetLFList(unsigned int lfhash);
unsigned int CheckDeck(const Deck& deck, unsigned int lfhash, int rule);
#ifndef YGOPRO_SERVER_MODE
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool LoadDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
FILE* OpenDeckFile(const wchar_t* file, const char* mode);
IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadDeck(const wchar_t* file, bool is_packlist = false);
bool LoadDeck(std::istringstream* deckStream, bool is_packlist = false);
bool SaveDeck(Deck& deck, const wchar_t* file);
bool DeleteDeck(const wchar_t* file);
bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false);
bool LoadCurrentDeck(int category_index, const wchar_t* category_name, const wchar_t* deckname);
wchar_t DeckFormatBuffer[128];
int TypeCount(std::vector<code_pointer> list, unsigned int ctype);
bool LoadDeckFromCode(Deck& deck, const unsigned char *code, int len);
int SaveDeckToCode(Deck &deck, unsigned char *code);
bool CreateCategory(const wchar_t* name);
bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
bool DeleteCategory(const wchar_t* name);
#endif //YGOPRO_SERVER_MODE
#endif // YGOPRO_SERVER_MODE
static uint32_t LoadDeck(Deck& deck, uint32_t dbuf[], int mainc, int sidec, bool is_packlist = false);
static bool LoadSide(Deck& deck, uint32_t dbuf[], int mainc, int sidec);
#ifndef YGOPRO_SERVER_MODE
static uint32_t LoadDeckFromStream(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
static void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
static void GetDeckFile(wchar_t* ret, int category_index, const wchar_t* category_name, const wchar_t* deckname);
static FILE* OpenDeckFile(const wchar_t* file, const char* mode);
static irr::io::IReadFile* OpenDeckReader(const wchar_t* file);
static bool SaveDeck(const Deck& deck, const wchar_t* file);
static bool DeleteDeck(const wchar_t* file);
static bool CreateCategory(const wchar_t* name);
static bool RenameCategory(const wchar_t* oldname, const wchar_t* newname);
static bool DeleteCategory(const wchar_t* name);
static bool SaveDeckArray(const DeckArray& deck, const wchar_t* name);
#endif // YGOPRO_SERVER_MODE
};
extern DeckManager deckManager;
......
This diff is collapsed.
This diff is collapsed.
#ifndef DUELCLIENT_H
#define DUELCLIENT_H
#include "config.h"
#include <vector>
#include <set>
#include <utility>
#include "network.h"
#include "data_manager.h"
#include "deck_manager.h"
#include "../ocgcore/mtrandom.h"
namespace ygo {
......@@ -55,23 +51,26 @@ class DuelClient {
private:
static unsigned int connect_state;
static unsigned char response_buf[SIZE_RETURN_VALUE];
static unsigned int response_len;
static size_t response_len;
static unsigned int watching;
static bool is_host;
static event_base* client_base;
static bufferevent* client_bev;
static unsigned char duel_client_read[SIZE_NETWORK_BUFFER];
static int read_len;
static unsigned char duel_client_write[SIZE_NETWORK_BUFFER];
static bool is_closing;
static bool is_swapping;
static int select_hint;
static int select_unselect_hint;
static int last_select_hint;
static unsigned char last_successful_msg[0x2000];
static unsigned int last_successful_msg_length;
static unsigned char last_successful_msg[SIZE_NETWORK_BUFFER];
static size_t last_successful_msg_length;
static wchar_t event_string[256];
static mt19937 rnd;
static bool is_refreshing;
static int match_kill;
static event* resp_event;
static std::set<std::pair<unsigned int, unsigned short>> remotes;
public:
static unsigned int temp_ip;
static unsigned short temp_port;
......@@ -82,13 +81,13 @@ public:
static void ConnectTimeout(evutil_socket_t fd, short events, void* arg);
static void StopClient(bool is_exiting = false);
static void ClientRead(bufferevent* bev, void* ctx);
static void ClientEvent(bufferevent *bev, short events, void *ctx);
static void ClientEvent(bufferevent* bev, short events, void* ctx);
static int ClientThread();
static void HandleSTOCPacketLan(unsigned char* data, int len);
static int ClientAnalyze(unsigned char* msg, unsigned int len);
static bool ClientAnalyze(unsigned char* msg, int len);
static void SwapField();
static void SetResponseI(int respI);
static void SetResponseB(void* respB, unsigned int len);
static void SetResponseI(int32_t respI);
static void SetResponseB(void* respB, size_t len);
static void SendResponse();
static unsigned int LookupHost(char *host);
static bool LookupSRV(char *hostname, HostResult* result);
......@@ -96,49 +95,39 @@ public:
static HostResult ParseHost(char *hostname, unsigned short port);
static void SendPacketToServer(unsigned char proto) {
auto p = duel_client_write;
BufferIO::WriteInt16(p, 1);
BufferIO::WriteInt8(p, proto);
buffer_write<uint16_t>(p, 1);
buffer_write<uint8_t>(p, proto);
#ifdef YGOPRO_MESSAGE_DEBUG
printf("CTOS: %d\n", proto);
#endif
bufferevent_write(client_bev, duel_client_write, 3);
}
template<typename ST>
static void SendPacketToServer(unsigned char proto, ST& st) {
static void SendPacketToServer(unsigned char proto, const ST& st) {
auto p = duel_client_write;
int blen = sizeof(ST);
if (blen > MAX_DATA_SIZE)
if (sizeof(ST) > MAX_DATA_SIZE)
return;
BufferIO::WriteInt16(p, (short)(1 + blen));
BufferIO::WriteInt8(p, proto);
std::memcpy(p, &st, blen);
buffer_write<uint16_t>(p, (uint16_t)(1 + sizeof(ST)));
buffer_write<uint8_t>(p, proto);
std::memcpy(p, &st, sizeof(ST));
#ifdef YGOPRO_MESSAGE_DEBUG
printf("CTOS: %d Length: %ld\n", proto, sizeof(ST));
#endif
bufferevent_write(client_bev, duel_client_write, blen + 3);
bufferevent_write(client_bev, duel_client_write, sizeof(ST) + 3);
}
static void SendBufferToServer(unsigned char proto, void* buffer, size_t len) {
auto p = duel_client_write;
int blen = len;
if (blen < 0)
return;
if (blen > MAX_DATA_SIZE)
blen = MAX_DATA_SIZE;
BufferIO::WriteInt16(p, (short)(1 + blen));
BufferIO::WriteInt8(p, proto);
std::memcpy(p, buffer, blen);
if (len > MAX_DATA_SIZE)
len = MAX_DATA_SIZE;
buffer_write<uint16_t>(p, (uint16_t)(1 + len));
buffer_write<uint8_t>(p, proto);
std::memcpy(p, buffer, len);
#ifdef YGOPRO_MESSAGE_DEBUG
printf("CTOS: %d Length: %ld\n", proto, len);
#endif
bufferevent_write(client_bev, duel_client_write, blen + 3);
bufferevent_write(client_bev, duel_client_write, len + 3);
}
protected:
static bool is_refreshing;
static int match_kill;
static event* resp_event;
static std::set<std::pair<unsigned int, unsigned short>> remotes;
public:
static std::vector<HostPacket> hosts;
static std::vector<std::wstring> hosts_srvpro;
static bool is_srvpro;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "config.h"
#include "game.h"
#include "data_manager.h"
#include <event2/thread.h>
#include <memory>
#ifdef __APPLE__
#import <CoreFoundation/CoreFoundation.h>
#endif
int main(int argc, char* argv[]);
This diff is collapsed.
#ifndef IMAGEMANAGER_H
#define IMAGEMANAGER_H
#ifndef _OPENMP
#define YGOPRO_USE_THUMB_LOAD_THREAD
#endif
#include "config.h"
#include "data_manager.h"
#include <unordered_map>
#ifdef YGOPRO_USE_THUMB_LOAD_THREAD
#include <queue>
#include <mutex>
#endif
namespace ygo {
......@@ -15,27 +22,31 @@ public:
bool Initial();
//random image
irr::video::ITexture* GetRandomImage(int image_type);
irr::video::ITexture* GetRandomImage(int image_type, s32 width, s32 height);
irr::video::ITexture* GetRandomImage(int image_type, irr::s32 width, irr::s32 height);
void RefreshRandomImageList();
void RefreshImageDir(std::wstring path, int image_type);
void SetDevice(irr::IrrlichtDevice* dev);
void ClearTexture();
void RemoveTexture(int code);
void ResizeTexture();
irr::video::ITexture* GetTextureFromFile(const char* file, s32 width, s32 height);
irr::video::ITexture* GetTextureFromFile(const char* file, irr::s32 width, irr::s32 height);
irr::video::ITexture* GetTexture(int code, bool fit = false);
irr::video::ITexture* GetBigPicture(int code, float zoom);
irr::video::ITexture* GetTextureThumb(int code);
irr::video::ITexture* GetTextureField(int code);
#ifdef YGOPRO_USE_THUMB_LOAD_THREAD
static int LoadThumbThread();
#endif
std::unordered_map<int, irr::video::ITexture*> tMap[2];
std::unordered_map<int, irr::video::ITexture*> tThumb;
std::unordered_map<int, irr::video::ITexture*> tFields;
#ifdef YGOPRO_USE_THUMB_LOAD_THREAD
std::unordered_map<int, irr::video::IImage*> tThumbLoading;
std::queue<int> tThumbLoadingCodes;
std::mutex tThumbLoadingMutex;
bool tThumbLoadingThreadRunning;
#endif
irr::IrrlichtDevice* device;
irr::video::IVideoDriver* driver;
irr::video::ITexture* tCover[4];
......@@ -43,7 +54,9 @@ public:
irr::video::ITexture* tUnknownFit;
irr::video::ITexture* tUnknownThumb;
irr::video::ITexture* tBigPicture;
#ifdef YGOPRO_USE_THUMB_LOAD_THREAD
irr::video::ITexture* tLoading;
#endif
irr::video::ITexture* tAct;
irr::video::ITexture* tAttack;
irr::video::ITexture* tNegated;
......
This diff is collapsed.
project "clzma"
kind "StaticLib"
cdialect "C11"
files { "*.c", "*.h" }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef MENU_HANDLER_H
#define MENU_HANDLER_H
#include "config.h"
#include <irrlicht.h>
#include "replay.h"
namespace ygo {
class MenuHandler: public irr::IEventReceiver {
public:
virtual bool OnEvent(const irr::SEvent& event);
s32 prev_operation;
int prev_sel;
bool OnEvent(const irr::SEvent& event) override;
irr::s32 prev_operation{ 0 };
int prev_sel{ -1 };
Replay temp_replay;
};
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef SINGLE_MODE_H
#define SINGLE_MODE_H
#include <stdint.h>
#include <cstdint>
#include <vector>
#include "replay.h"
......@@ -30,7 +30,7 @@ public:
static void SinglePlayRefreshSingle(int player, int location, int sequence, int flag = 0xf81fff);
static void SinglePlayReload();
static uint32 MessageHandler(intptr_t fduel, uint32 type);
static uint32_t MessageHandler(intptr_t fduel, uint32_t type);
protected:
static Replay last_replay;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Subproject commit b69f68fc424281977c6e8e2d4aa2f381c91ec399
Subproject commit 972751787a8f1c8fb2aad9df1a9f292003539bb3
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment