Use boost::chrono instead of std::chrono

This commit is contained in:
Eduardo Bart 2013-01-23 19:31:14 -02:00
parent d5d5e507af
commit 50c2db100e
3 changed files with 72 additions and 47 deletions

View File

@ -173,11 +173,10 @@ message(STATUS "Build revision: ${BUILD_REVISION}")
add_definitions(-D"BUILD_REVISION=\\\"${BUILD_REVISION}\\\"") add_definitions(-D"BUILD_REVISION=\\\"${BUILD_REVISION}\\\"")
# find boost # find boost
set(REQUIRED_BOOST_COMPONENTS locale system filesystem regex thread) set(REQUIRED_BOOST_COMPONENTS locale system filesystem regex thread chrono)
if(WIN32) if(WIN32)
set(Boost_THREADAPI win32) set(Boost_THREADAPI win32)
set(framework_DEFINITIONS ${framework_DEFINITIONS} -DBOOST_THREAD_USE_LIB) # fix boost thread linkage set(framework_DEFINITIONS ${framework_DEFINITIONS} -DBOOST_THREAD_USE_LIB) # fix boost thread linkage
set(REQUIRED_BOOST_COMPONENTS ${REQUIRED_BOOST_COMPONENTS} chrono) # mingw32 does not have std::thread
endif() endif()
set(Boost_USE_MULTITHREADED ON) set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ${USE_STATIC_LIBS}) set(Boost_USE_STATIC_LIBS ${USE_STATIC_LIBS})

View File

@ -21,19 +21,19 @@
*/ */
#include "time.h" #include "time.h"
#include <chrono> #include <boost/chrono.hpp>
#include <unistd.h> #include <unistd.h>
namespace stdext { namespace stdext {
const static auto startup_time = std::chrono::high_resolution_clock::now(); const static auto startup_time = boost::chrono::high_resolution_clock::now();
ticks_t millis() ticks_t millis()
{ {
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - startup_time).count(); return boost::chrono::duration_cast<boost::chrono::milliseconds>(boost::chrono::high_resolution_clock::now() - startup_time).count();
} }
ticks_t micros() { ticks_t micros() {
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - startup_time).count(); return boost::chrono::duration_cast<boost::chrono::microseconds>(boost::chrono::high_resolution_clock::now() - startup_time).count();
} }
void millisleep(size_t ms) void millisleep(size_t ms)

View File

@ -9,7 +9,22 @@ mingwplatform="i486-mingw32"
mingwbin="/usr/$mingwplatform/bin" mingwbin="/usr/$mingwplatform/bin"
makejobs=4 makejobs=4
[ "$1" == "--replace" ] && replace=true || replace=false replace=false
rebuild=true
for arg in "$@"; do
case "$arg" in
--no-rebuild)
rebuild=false
;;
--replace)
replace=true
;;
*)
echo "usage: $0 [--replace] [--no-rebuild]"
exit
;;
esac
done
# setup work directory # setup work directory
mkdir -p $workdir mkdir -p $workdir
@ -25,58 +40,71 @@ fi
cd $workdir/otclient cd $workdir/otclient
revision=`git rev-list --all | wc -l` revision=`git rev-list --all | wc -l`
commit=`git describe --dirty --always` commit=`git describe --always`
version=`cat CMakeLists.txt | grep "set(VERSION" | sed 's/.*"\([^"]*\)".*/\1/'` version=`cat CMakeLists.txt | grep "set(VERSION" | sed 's/.*"\([^"]*\)".*/\1/'`
# set flags # build for i686
export CFLAGS="-march=i686 -m32" export CFLAGS="-march=i686 -m32"
export CXXFLAGS="-march=i686 -m32" export CXXFLAGS="-march=i686 -m32"
export LDFLAGS="-march=i686 -m32" export LDFLAGS="-march=i686 -m32"
LIBPATH=/usr/lib
if [ -d /usr/lib32 ]; then
LIBPATH=/usr/lib32
fi
if $rebuild; then
rm -rf build.win32
rm -rf build.win32dx9
rm -rf build.linux32
fi
# compile for win32 # compile for win32
rm -rf build.win32 mkdir -p build.win32
mkdir build.win32
cd build.win32 cd build.win32
cmake -DCMAKE_TOOLCHAIN_FILE=$workdir/otclient/src/framework/cmake/${mingwplatform}_toolchain.cmake \ if $rebuild; then
cmake -DCMAKE_TOOLCHAIN_FILE=$workdir/otclient/src/framework/cmake/${mingwplatform}_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DBOT_PROTECTION=OFF \ -DBOT_PROTECTION=OFF \
-DBUILD_REVISION=$revision \ -DBUILD_REVISION=$revision \
-DBUILD_COMMIT=$commit \ -DBUILD_COMMIT=$commit \
.. || exit .. || exit
fi
make -j$makejobs || exit make -j$makejobs || exit
cd .. cd ..
# compile for win32 # compile for win32
rm -rf build.win32dx9 mkdir -p build.win32dx9
mkdir build.win32dx9
cd build.win32dx9 cd build.win32dx9
cmake -DCMAKE_TOOLCHAIN_FILE=$workdir/otclient/src/framework/cmake/${mingwplatform}_toolchain.cmake \ if $rebuild; then
cmake -DCMAKE_TOOLCHAIN_FILE=$workdir/otclient/src/framework/cmake/${mingwplatform}_toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DBOT_PROTECTION=OFF \ -DBOT_PROTECTION=OFF \
-DOPENGLES=2.0 \ -DOPENGLES=2.0 \
-DBUILD_REVISION=$revision \ -DBUILD_REVISION=$revision \
-DBUILD_COMMIT=$commit \ -DBUILD_COMMIT=$commit \
.. || exit .. || exit
fi
make -j$makejobs || exit make -j$makejobs || exit
cd .. cd ..
# compile for linux 64 # compile for linux32
rm -rf build.linux32 mkdir -p build.linux32
mkdir build.linux32
cd build.linux32 cd build.linux32
export CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2" if $rebuild; then
export LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro" cmake -DCMAKE_BUILD_TYPE=Release \
cmake -DCMAKE_BUILD_TYPE=Release \
-DBOT_PROTECTION=OFF \ -DBOT_PROTECTION=OFF \
-DBUILD_REVISION=$revision \ -DBUILD_REVISION=$revision \
-DBUILD_COMMIT=$commit \ -DBUILD_COMMIT=$commit \
-DCMAKE_LIBRARY_PATH=$LIBPATH \
.. || exit .. || exit
fi
make -j$makejobs || exit make -j$makejobs || exit
cd .. cd ..
################################################## ##################################################
# create win32 package # create win32 package
pkg_suffix="-linux64-$version" pkg_suffix="-linux32-$version"
pkgname="$name$pkg_suffix" pkgname="$name$pkg_suffix"
pkgzip="$pkgname.tgz" pkgzip="$pkgname.tgz"
cd $workdir cd $workdir
@ -85,10 +113,12 @@ mkdir $pkgname
cd $pkgname cd $pkgname
# copy otclient files # copy otclient files
cp -R $workdir/otclient/mods . mkdir mods
cp $workdir/otclient/mods/README.txt mods/
cp -R $workdir/otclient/modules . cp -R $workdir/otclient/modules .
cp $workdir/otclient/build.linux64/otclient . cp -R $workdir/otclient/data .
cp $workdir/otclient/build.linux64/otclient.map . cp $workdir/otclient/build.linux32/otclient .
cp $workdir/otclient/build.linux32/otclient.map .
cp $workdir/otclient/init.lua . cp $workdir/otclient/init.lua .
cp $workdir/otclient/otclientrc.lua . cp $workdir/otclient/otclientrc.lua .
cp $workdir/otclient/BUGS . cp $workdir/otclient/BUGS .
@ -129,7 +159,8 @@ mkdir $pkgname
cd $pkgname cd $pkgname
# copy otclient files # copy otclient files
cp -R $workdir/otclient/mods . mkdir mods
cp $workdir/otclient/mods/README.txt mods/
cp -R $workdir/otclient/modules . cp -R $workdir/otclient/modules .
cp -R $workdir/otclient/data . cp -R $workdir/otclient/data .
cp $mingwbin/libEGL.dll . cp $mingwbin/libEGL.dll .
@ -146,7 +177,7 @@ cp $workdir/otclient/AUTHORS AUTHORS.txt
cp $workdir/otclient/BUGS BUGS.txt cp $workdir/otclient/BUGS BUGS.txt
cp $workdir/otclient/LICENSE LICENSE.txt cp $workdir/otclient/LICENSE LICENSE.txt
cp $workdir/otclient/README.md README.txt cp $workdir/otclient/README.md README.txt
unix2dos LICENSE.txt README.txt BUGS.txt AUTHORS.txt unix2dos LICENSE.txt README.txt BUGS.txt AUTHORS.txt mods/README.txt
# remove git files # remove git files
find -name '.git*' -exec rm -rf {} \; find -name '.git*' -exec rm -rf {} \;
@ -171,11 +202,6 @@ zip -9 -qr $pkgzip $pkgname
echo "Package generated to $pkgzip" echo "Package generated to $pkgzip"
# test win32 otclient # test win32 otclient
mkdir otclient/modules/game_tibiafiles/860/
cp $workdir/Tibia/*.spr otclient/modules/game_tibiafiles/860/
cp $workdir/Tibia/*.dat otclient/modules/game_tibiafiles/860/
cd otclient cd otclient
wine build.win32/otclient.exe wine build.win32/otclient.exe
rm -f *.log rm -f *.log