29 Commits

Author SHA1 Message Date
TheSumm
a1a993282b Fix vcpkg compiling 2021-06-12 12:37:32 +02:00
diath
6cd5eb3e22 Add clickable NPC keywords (#1148) 2021-04-29 18:06:48 +02:00
Ranieri Althoff
5cc9319a94 Optimize XTEA encryption (#1143)
https://dev.to/rsa/making-an-algorithm-15x-faster-without-parallelism-38k5
2021-04-02 21:48:58 +02:00
vfjpl
3600a9b40b Fix Lua errors when the client is built without the sound framework (#1142) 2021-04-02 21:35:34 +02:00
diath
b37623cd86 Fix the use of deprecated C++ functions (#1138) 2021-04-01 00:38:36 +02:00
vfjpl
67b7dbfcfe Keep log messages in a deque instead of a list and remove unnecessary copy
Co-authored-by: Kacper Piwiński <kacper.piwinski@arex.pl>
2021-04-01 00:38:02 +02:00
vfjpl
7752add8aa Use float literals where applicable (#1140)
Use float literals to perform more calculation in float instead of performing implicit conversion to double and back to float.

Co-authored-by: Kacper Piwiński <kacper.piwinski@arex.pl>
2021-04-01 00:06:50 +02:00
diath
7c528be73e Cleanup CMake project (#1137)
* Updated the minimum required standard from C++11 to C++14 (https://en.wikipedia.org/wiki/C%2B%2B14).
* Fixed -g0 and -Os flags being passed to luafunctions.cpp when building with MSVC.
* Fixed case mismatch in FIND_PACKAGE_HANDLE_STANDARD_ARGS argument in a number of CMake files.
2021-03-31 07:30:09 +02:00
vfjpl
4d055913dc Clean up BitmapFont code (#1129) 2021-03-30 17:03:02 +02:00
Marcin Michalski
4edb1eb3ad Fix adding executable icon on windows with non-msvc compiler (#1136) 2021-03-30 08:58:32 +02:00
Marcin Michalski
69e44a3722 Fix & enable by default static linking on macOS (#1133) 2021-03-29 17:22:04 +02:00
Marcin Michalski
ba706fc5c3 Remove travis (#1135)
Replaced by GitHub workflows.
2021-03-29 16:58:38 +02:00
Marcin Michalski
975d138a57 Run windows workflow with luajit only (#1134) 2021-03-29 16:54:02 +02:00
Marcin Michalski
c4530a6d17 Bump minimum required CMake version to 3.1 (#1131)
* Removed Ubuntu Clang workflow
* Removed FindCXX.cmake (in favor of native feature)
* Added support for building Windows binaries with CMake when using MSVC
* Cleaned up a number of Find*.cmake modules
2021-03-27 01:04:59 +01:00
Marcin Michalski
b6399a8ad9 Update workflow (#1130) 2021-03-26 14:37:02 +01:00
Kamil Chojnowski
9c9b85ac5e Fix UITextEdit::setTextHidden ignoring the hidden param and always setting the member variable to true 2021-03-14 21:12:59 +01:00
Martin Nylind
872abf05f4 Add Missile:setPath to Lua interface (#1125)
Add Missile:setPath(fromPos, toPos) method to Lua interface.
2021-02-10 05:40:39 +01:00
peonso
d07e7fcce7 Correct messageModsMap for version 10.41 (#1119) 2021-01-04 17:33:04 +01:00
vfjpl
f521737b26 Return Tile walking creatures and things by const ref instead of copy (#1117) 2020-11-23 17:26:15 +01:00
reyhammer
18dd9c2d2d Fix TPoint::distanceFrom() calling TPoint::getLength() instead of TPoint::length() (#1116) 2020-11-23 15:59:50 +01:00
vfjpl
72cc4b2fb0 Fix out-of-bounds access in Platform::getCPUName (#1115) 2020-11-22 22:08:37 +01:00
vfjpl
c6d0fc0f71 Fix laggy diagonal movement (#1108) 2020-10-07 03:14:00 +02:00
vfjpl
b3d947d4c3 Use std::deque for queues (#1112) 2020-10-07 03:12:04 +02:00
bakasuradbl
83959e5e23 Fix window position when entering fullscreen mode on Windows platform (#1099) 2020-10-05 19:59:36 +02:00
Source61
70400bc83e Add optional format string for stdext::date_time_string() (#1110) 2020-09-15 18:58:47 +02:00
vfjpl
9c1f519f8a resourcemanager:[bug fix] directoryExists method should resolvePath before checking (#1102) 2020-08-29 17:35:42 +02:00
diath
88d0ea34bf Fix UITabBar and UIMoveableTabBar bricking when removing first tabs in (#1101) collapsed view
Co-authored-by: Xagul <eixim@hotmail.com>
2020-08-26 09:54:56 +02:00
diath
b3aaa10646 Remove stdext::packed_vector (#1106)
Co-authored-by: Kacper Piwiński <cosiekvfj@o2.pl>
2020-08-26 09:54:05 +02:00
diath
59059321a6 Fix an issue with pathfinding not respecting the PathFindAllowCreatures flag properly (#1090) 2020-06-13 09:00:01 +02:00
59 changed files with 439 additions and 569 deletions

View File

@@ -28,7 +28,7 @@ jobs:
fail-fast: false fail-fast: false
max-parallel: 8 max-parallel: 8
matrix: matrix:
name: [ubuntu-gcc, ubuntu-clang, macos-clang, windows-msvc] name: [ubuntu-gcc, macos-clang, windows-msvc]
buildtype: [Debug, Release] buildtype: [Debug, Release]
luajit: [on, off] luajit: [on, off]
include: include:
@@ -38,23 +38,15 @@ jobs:
cc: cl.exe cc: cl.exe
triplet: x64-windows triplet: x64-windows
packages: > packages: >
boost-iostreams boost-asio boost-system boost-variant boost-lockfree luajit glew boost-iostreams boost-asio boost-system boost-variant boost-lockfree boost-filesystem boost-uuid
boost-filesystem boost-uuid physfs openal-soft libogg libvorbis zlib opengl glew luajit libogg libvorbis openal-soft opengl openssl physfs zlib
- name: ubuntu-gcc - name: ubuntu-gcc
os: ubuntu os: ubuntu
cxx: g++ cxx: g++
cc: gcc cc: gcc
triplet: x64-linux triplet: x64-linux
packages: > packages: >
boost-iostreams boost-asio boost-system boost-variant boost-lockfree luajit glew boost-iostreams boost-asio boost-system boost-variant boost-lockfree glew
boost-filesystem boost-uuid physfs openal-soft libogg libvorbis zlib opengl
- name: ubuntu-clang
os: ubuntu
cxx: clang++
cc: clang
triplet: x64-linux
packages: >
boost-iostreams boost-asio boost-system boost-variant boost-lockfree luajit glew
boost-filesystem boost-uuid physfs openal-soft libogg libvorbis zlib opengl boost-filesystem boost-uuid physfs openal-soft libogg libvorbis zlib opengl
- name: macos-clang - name: macos-clang
os: macos os: macos
@@ -62,8 +54,11 @@ jobs:
cc: clang cc: clang
triplet: x64-osx triplet: x64-osx
packages: > packages: >
boost-iostreams boost-asio boost-system boost-variant boost-lockfree luajit glew boost-iostreams boost-asio boost-system boost-variant boost-lockfree glew
boost-filesystem boost-uuid physfs openal-soft libogg libvorbis zlib opengl boost-filesystem boost-uuid libogg libvorbis zlib opengl
exclude:
- name: windows-msvc
luajit: off
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@@ -77,35 +72,35 @@ jobs:
# Using 'latest' branch, the latest CMake is installed. # Using 'latest' branch, the latest CMake is installed.
uses: lukka/get-cmake@latest uses: lukka/get-cmake@latest
- name: Ubuntu - install luajit - name: Ubuntu - install opengl lua5.1 luajit
run: | # vcpkg has lua 5.3+
sudo apt-get install libluajit-5.1-dev run: sudo apt-get install libglew-dev liblua5.1-0-dev libluajit-5.1-dev
if: contains( matrix.os, 'ubuntu') if: contains( matrix.os, 'ubuntu')
- name: MacOS - install luajit pkgconfig - name: MacOS - install physfs pkgconfig lua5.1 luajit xquartz
run: brew install luajit pkgconfig run: brew install physfs pkgconfig lua@5.1 luajit xquartz
if: contains( matrix.os, 'macos') if: contains( matrix.os, 'macos')
- uses: lukka/set-shell-env@v1 - name: Set Environment vars
with: run: |
CXX: ${{ matrix.cxx }} echo "CXX=${{ matrix.cxx }}" >> $GITHUB_ENV
CC: ${{ matrix.cc }} echo "CC=${{ matrix.cc }}" >> $GITHUB_ENV
- name: Run vcpkg - name: Run vcpkg
uses: lukka/run-vcpkg@v2 uses: lukka/run-vcpkg@v7.1
with: with:
vcpkgArguments: ${{ matrix.packages }} vcpkgArguments: ${{ matrix.packages }}
vcpkgDirectory: ${{ runner.workspace }}/vcpkg/ vcpkgDirectory: ${{ runner.workspace }}/vcpkg/
vcpkgTriplet: ${{ matrix.triplet }} vcpkgTriplet: ${{ matrix.triplet }}
vcpkgGitCommitId: 7db401cb1ef1fc559ec9f9ce814d064c328fd767 vcpkgGitCommitId: 9a49e3df7f729655318c59b9985c9c18ad0c99d6
- name: Build with CMake - name: Build with CMake
uses: lukka/run-cmake@v2 uses: lukka/run-cmake@v3
with: with:
useVcpkgToolchainFile: true
buildDirectory: ${{ runner.workspace }}/build buildDirectory: ${{ runner.workspace }}/build
cmakeBuildType: ${{ matrix.buildtype }} cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeAppendedArgs: -DUSE_LUAJIT=${{ matrix.luajit }} cmakeAppendedArgs: '-G Ninja -DCMAKE_BUILD_TYPE="${{ matrix.buildtype }}" -DLUAJIT="${{ matrix.luajit }}"'
useVcpkgToolchainFile: true
- name: dir - name: dir
run: find $RUNNER_WORKSPACE run: find $RUNNER_WORKSPACE

View File

@@ -1,38 +0,0 @@
language: cpp
compiler:
- gcc
before_script:
- |-
set -o errexit
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
git-core \
libboost-all-dev \
libglew-dev \
liblua5.1-0-dev \
libncurses5-dev \
libopenal-dev \
libssl-dev \
libvorbis-dev \
mercurial \
zlib1g-dev
hg clone -r stable-3.0 http://hg.icculus.org/icculus/physfs/
mkdir -p physfs/build
pushd physfs/build
cmake ..
make -j$(nproc)
sudo make install
popd
script: |
cmake . -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
notifications:
irc:
channels:
- "irc.freenode.org#otclient"
on_success: change
skip_join: true

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 3.1)
project(otclient) project(otclient)
set(VERSION "1.0.0") set(VERSION "1.0.0")
@@ -23,13 +23,24 @@ set(executable_SOURCES
src/main.cpp src/main.cpp
) )
# add executable icon for win32 platforms
if(WIN32) if(WIN32)
if(MSVC)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o
COMMAND ${CMAKE_RC_COMPILER}
-I${CMAKE_CURRENT_SOURCE_DIR}/src
-fo${CMAKE_CURRENT_BINARY_DIR}/otcicon.o
${CMAKE_CURRENT_SOURCE_DIR}/src/otcicon.rc
)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
else()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o
COMMAND ${CMAKE_RC_COMPILER} COMMAND ${CMAKE_RC_COMPILER}
-I${CMAKE_CURRENT_SOURCE_DIR}/src -I${CMAKE_CURRENT_SOURCE_DIR}/src
-i${CMAKE_CURRENT_SOURCE_DIR}/src/otcicon.rc -i${CMAKE_CURRENT_SOURCE_DIR}/src/otcicon.rc
-o ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o) -o ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o
)
endif()
set(executable_SOURCES ${executable_SOURCES} otcicon.o) set(executable_SOURCES ${executable_SOURCES} otcicon.o)
endif() endif()
@@ -37,8 +48,16 @@ add_definitions(-D"VERSION=\\"${VERSION}\\"")
# add client executable # add client executable
add_executable(${PROJECT_NAME} ${framework_SOURCES} ${client_SOURCES} ${executable_SOURCES}) add_executable(${PROJECT_NAME} ${framework_SOURCES} ${client_SOURCES} ${executable_SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON)
target_link_libraries(${PROJECT_NAME} ${framework_LIBRARIES}) target_link_libraries(${PROJECT_NAME} ${framework_LIBRARIES})
if(APPLE AND USE_STATIC_LIBS)
target_link_libraries(${PROJECT_NAME} "-framework Foundation" "-framework IOKit")
endif()
if(USE_PCH) if(USE_PCH)
include(cotire) include(cotire)
cotire(${PROJECT_NAME}) cotire(${PROJECT_NAME})

View File

@@ -1,4 +1,4 @@
[![Build Status](https://secure.travis-ci.org/edubart/otclient.svg?branch=master)](http://travis-ci.org/edubart/otclient) [![Join the chat at https://gitter.im/edubart/otclient](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/edubart/otclient?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Open Source Helpers](https://www.codetriage.com/edubart/otclient/badges/users.svg)](https://www.codetriage.com/edubart/otclient) [![Build Status](https://github.com/edubart/otclient/actions/workflows/build-vcpkg.yml/badge.svg)](https://github.com/edubart/otclient/actions/workflows/build-vcpkg.yml) [![Join the chat at https://gitter.im/edubart/otclient](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/edubart/otclient?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Open Source Helpers](https://www.codetriage.com/edubart/otclient/badges/users.svg)](https://www.codetriage.com/edubart/otclient)
### What is otclient? ### What is otclient?

View File

@@ -1,5 +1,8 @@
local musicFilename = "/sounds/startup" local musicFilename = "/sounds/startup"
local musicChannel = g_sounds.getChannel(1) local musicChannel = nil
if g_sounds then
musicChannel = g_sounds.getChannel(SoundChannels.Music)
end
function setMusic(filename) function setMusic(filename)
musicFilename = filename musicFilename = filename
@@ -27,12 +30,14 @@ end
function startup() function startup()
-- Play startup music (The Silver Tree, by Mattias Westlund) -- Play startup music (The Silver Tree, by Mattias Westlund)
if musicChannel then
musicChannel:enqueue(musicFilename, 3) musicChannel:enqueue(musicFilename, 3)
connect(g_game, { onGameStart = function() musicChannel:stop(3) end }) connect(g_game, { onGameStart = function() musicChannel:stop(3) end })
connect(g_game, { onGameEnd = function() connect(g_game, { onGameEnd = function()
g_sounds.stopAll() g_sounds.stopAll()
musicChannel:enqueue(musicFilename, 3) musicChannel:enqueue(musicFilename, 3)
end }) end })
end
-- Check for startup errors -- Check for startup errors
local errtitle = nil local errtitle = nil
@@ -57,7 +62,9 @@ function init()
onExit = exit }) onExit = exit })
g_window.setMinimumSize({ width = 600, height = 480 }) g_window.setMinimumSize({ width = 600, height = 480 })
if musicChannel then
g_sounds.preload(musicFilename) g_sounds.preload(musicFilename)
end
-- initialize in fullscreen mode on mobile devices -- initialize in fullscreen mode on mobile devices
if g_window.getPlatformType() == "X11-EGL" then if g_window.getPlatformType() == "X11-EGL" then

View File

@@ -109,8 +109,8 @@ function init()
graphicsPanel = g_ui.loadUI('graphics') graphicsPanel = g_ui.loadUI('graphics')
optionsTabBar:addTab(tr('Graphics'), graphicsPanel, '/images/optionstab/graphics') optionsTabBar:addTab(tr('Graphics'), graphicsPanel, '/images/optionstab/graphics')
audioPanel = g_ui.loadUI('audio') soundPanel = g_ui.loadUI('audio')
optionsTabBar:addTab(tr('Audio'), audioPanel, '/images/optionstab/audio') optionsTabBar:addTab(tr('Audio'), soundPanel, '/images/optionstab/audio')
optionsButton = modules.client_topmenu.addLeftButton('optionsButton', tr('Options'), '/images/topbuttons/options', toggle) optionsButton = modules.client_topmenu.addLeftButton('optionsButton', tr('Options'), '/images/topbuttons/options', toggle)
audioButton = modules.client_topmenu.addLeftButton('audioButton', tr('Audio'), '/images/topbuttons/audio', function() toggleOption('enableAudio') end) audioButton = modules.client_topmenu.addLeftButton('audioButton', tr('Audio'), '/images/topbuttons/audio', function() toggleOption('enableAudio') end)
@@ -190,17 +190,23 @@ function setOption(key, value, force)
elseif key == 'fullscreen' then elseif key == 'fullscreen' then
g_window.setFullscreen(value) g_window.setFullscreen(value)
elseif key == 'enableAudio' then elseif key == 'enableAudio' then
if g_sounds then
g_sounds.setAudioEnabled(value) g_sounds.setAudioEnabled(value)
end
if value then if value then
audioButton:setIcon('/images/topbuttons/audio') audioButton:setIcon('/images/topbuttons/audio')
else else
audioButton:setIcon('/images/topbuttons/audio_mute') audioButton:setIcon('/images/topbuttons/audio_mute')
end end
elseif key == 'enableMusicSound' then elseif key == 'enableMusicSound' then
if g_sounds then
g_sounds.getChannel(SoundChannels.Music):setEnabled(value) g_sounds.getChannel(SoundChannels.Music):setEnabled(value)
end
elseif key == 'musicSoundVolume' then elseif key == 'musicSoundVolume' then
if g_sounds then
g_sounds.getChannel(SoundChannels.Music):setGain(value/100) g_sounds.getChannel(SoundChannels.Music):setGain(value/100)
audioPanel:getChildById('musicSoundVolumeLabel'):setText(tr('Music volume: %d', value)) end
soundPanel:getChildById('musicSoundVolumeLabel'):setText(tr('Music volume: %d', value))
elseif key == 'showLeftPanel' then elseif key == 'showLeftPanel' then
modules.game_interface.getLeftPanel():setOn(value) modules.game_interface.getLeftPanel():setOn(value)
elseif key == 'backgroundFrameRate' then elseif key == 'backgroundFrameRate' then

View File

@@ -334,9 +334,12 @@ function UIMoveableTabBar:removeTab(tab)
end end
if self.currentTab == tab then if self.currentTab == tab then
self:selectPrevTab()
if #self.tabs == 1 then if #self.tabs == 1 then
self.currentTab = nil self.currentTab = nil
elseif index == #self.tabs then
self:selectPrevTab()
else
self:selectNextTab()
end end
end end
table.remove(tabTable, index) table.remove(tabTable, index)

View File

@@ -77,7 +77,13 @@ function UITabBar:removeTab(tab)
local index = table.find(self.tabs, tab) local index = table.find(self.tabs, tab)
if index == nil then return end if index == nil then return end
if self.currentTab == tab then if self.currentTab == tab then
if #self.tabs == 1 then
self.currentTab = nil
elseif index == #self.tabs then
self:selectPrevTab() self:selectPrevTab()
else
self:selectNextTab()
end
end end
table.remove(self.tabs, index) table.remove(self.tabs, index)
tab:destroy() tab:destroy()

View File

@@ -553,6 +553,8 @@ function addTabText(text, speaktype, tab, creatureName)
label:setColor(speaktype.color) label:setColor(speaktype.color)
consoleTabBar:blinkTab(tab) consoleTabBar:blinkTab(tab)
label.highlightInfo = {}
-- Overlay for consoleBuffer which shows highlighted words only -- Overlay for consoleBuffer which shows highlighted words only
if speaktype.npcChat and (g_game.getCharacterName() ~= creatureName or g_game.getCharacterName() == 'Account Manager') then if speaktype.npcChat and (g_game.getCharacterName() ~= creatureName or g_game.getCharacterName() == 'Account Manager') then
@@ -582,6 +584,10 @@ function addTabText(text, speaktype, tab, creatureName)
local dataBlock = { _start = highlightData[(i-1)*3+1], _end = highlightData[(i-1)*3+2], words = highlightData[(i-1)*3+3] } local dataBlock = { _start = highlightData[(i-1)*3+1], _end = highlightData[(i-1)*3+2], words = highlightData[(i-1)*3+3] }
local lastBlockEnd = (highlightData[(i-2)*3+2] or 1) local lastBlockEnd = (highlightData[(i-2)*3+2] or 1)
for i = dataBlock._start, dataBlock._end do
label.highlightInfo[i] = dataBlock.words
end
for letter = lastBlockEnd, dataBlock._start-1 do for letter = lastBlockEnd, dataBlock._start-1 do
local tmpChar = string.byte(drawText:sub(letter, letter)) local tmpChar = string.byte(drawText:sub(letter, letter))
local fillChar = (tmpChar == 10 or tmpChar == 32) and string.char(tmpChar) or string.char(127) local fillChar = (tmpChar == 10 or tmpChar == 32) and string.char(tmpChar) or string.char(127)
@@ -609,8 +615,15 @@ function addTabText(text, speaktype, tab, creatureName)
processMessageMenu(mousePos, mouseButton, nil, nil, nil, tab) processMessageMenu(mousePos, mouseButton, nil, nil, nil, tab)
end end
label.onMouseRelease = function(self, mousePos, mouseButton) label.onMouseRelease = function(self, mousePos, mouseButton)
if mouseButton == MouseLeftButton then
local position = label:getTextPos(mousePos)
if position and label.highlightInfo[position] then
sendMessage(label.highlightInfo[position], npcTab)
end
elseif mouseButton == MouseRightButton then
processMessageMenu(mousePos, mouseButton, creatureName, text, self, tab) processMessageMenu(mousePos, mouseButton, creatureName, text, self, tab)
end end
end
label.onMousePress = function(self, mousePos, button) label.onMousePress = function(self, mousePos, button)
if button == MouseLeftButton then clearSelection(consoleBuffer) end if button == MouseLeftButton then clearSelection(consoleBuffer) end
end end

View File

@@ -1,8 +1,3 @@
# CMAKE_CURRENT_LIST_DIR cmake 2.6 compatibility
if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
endif(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
# client options # client options
add_definitions(-DCLIENT) add_definitions(-DCLIENT)
option(BOT_PROTECTION "Enable bot protection" ON) option(BOT_PROTECTION "Enable bot protection" ON)
@@ -109,5 +104,7 @@ set(client_SOURCES ${client_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/position.h ${CMAKE_CURRENT_LIST_DIR}/position.h
) )
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp if(NOT MSVC)
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp
PROPERTIES LANGUAGE CXX COMPILE_FLAGS "-g0 -Os") PROPERTIES LANGUAGE CXX COMPILE_FLAGS "-g0 -Os")
endif()

View File

@@ -78,7 +78,7 @@ void Container::onAddItem(const ItemPtr& item, int slot)
ItemPtr Container::findItemById(uint itemId, int subType) ItemPtr Container::findItemById(uint itemId, int subType)
{ {
for(const ItemPtr item : m_items) for(const ItemPtr& item : m_items)
if(item->getId() == itemId && (subType == -1 || item->getSubType() == subType)) if(item->getId() == itemId && (subType == -1 || item->getSubType() == subType))
return item; return item;
return nullptr; return nullptr;

View File

@@ -483,14 +483,14 @@ void Creature::onDeath()
callLuaField("onDeath"); callLuaField("onDeath");
} }
void Creature::updateWalkAnimation(int totalPixelsWalked) void Creature::updateWalkAnimation(int totalPixelsWalked, int stepDuration)
{ {
// update outfit animation // update outfit animation
if(m_outfit.getCategory() != ThingCategoryCreature) if(m_outfit.getCategory() != ThingCategoryCreature)
return; return;
int footAnimPhases = getAnimationPhases() - 1; int footAnimPhases = getAnimationPhases() - 1;
int footDelay = getStepDuration(true) / 3; int footDelay = stepDuration / 3;
// Since mount is a different outfit we need to get the mount animation phases // Since mount is a different outfit we need to get the mount animation phases
if(m_outfit.getMount() != 0) { if(m_outfit.getMount() != 0) {
ThingType *type = g_things.rawGetThingType(m_outfit.getMount(), m_outfit.getCategory()); ThingType *type = g_things.rawGetThingType(m_outfit.getMount(), m_outfit.getCategory());
@@ -579,20 +579,20 @@ void Creature::nextWalkUpdate()
m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] { m_walkUpdateEvent = g_dispatcher.scheduleEvent([self] {
self->m_walkUpdateEvent = nullptr; self->m_walkUpdateEvent = nullptr;
self->nextWalkUpdate(); self->nextWalkUpdate();
}, getStepDuration() / 32); }, getStepDuration(true) / Otc::TILE_PIXELS);
} }
} }
void Creature::updateWalk() void Creature::updateWalk()
{ {
float walkTicksPerPixel = getStepDuration(true) / 32; int stepDuration = getStepDuration(true);
int totalPixelsWalked = std::min<int>(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f); int totalPixelsWalked = stepDuration ? std::min<int>((m_walkTimer.ticksElapsed() * Otc::TILE_PIXELS) / stepDuration, Otc::TILE_PIXELS) : 0;
// needed for paralyze effect // needed for paralyze effect
m_walkedPixels = std::max<int>(m_walkedPixels, totalPixelsWalked); m_walkedPixels = std::max<int>(m_walkedPixels, totalPixelsWalked);
// update walk animation and offsets // update walk animation and offsets
updateWalkAnimation(totalPixelsWalked); updateWalkAnimation(totalPixelsWalked, stepDuration);
updateWalkOffset(m_walkedPixels); updateWalkOffset(m_walkedPixels);
updateWalkingTile(); updateWalkingTile();

View File

@@ -135,7 +135,7 @@ public:
virtual void onDeath(); virtual void onDeath();
protected: protected:
virtual void updateWalkAnimation(int totalPixelsWalked); virtual void updateWalkAnimation(int totalPixelsWalked, int stepDuration);
virtual void updateWalkOffset(int totalPixelsWalked); virtual void updateWalkOffset(int totalPixelsWalked);
void updateWalkingTile(); void updateWalkingTile();
virtual void nextWalkUpdate(); virtual void nextWalkUpdate();

View File

@@ -72,7 +72,7 @@ protected:
private: private:
stdext::dynamic_storage<uint8> m_attribs; stdext::dynamic_storage<uint8> m_attribs;
std::unordered_map<Position, CreatureTypePtr, PositionHasher> m_creatures; std::unordered_map<Position, CreatureTypePtr, Position::Hasher> m_creatures;
friend class CreatureManager; friend class CreatureManager;
}; };
@@ -137,7 +137,7 @@ protected:
private: private:
std::vector<CreatureTypePtr> m_creatures; std::vector<CreatureTypePtr> m_creatures;
std::unordered_map<Position, SpawnPtr, PositionHasher> m_spawns; std::unordered_map<Position, SpawnPtr, Position::Hasher> m_spawns;
stdext::boolean<false> m_loaded, m_spawnLoaded; stdext::boolean<false> m_loaded, m_spawnLoaded;
CreatureTypePtr m_nullCreature; CreatureTypePtr m_nullCreature;
}; };

View File

@@ -85,9 +85,9 @@ typedef std::list<TownPtr> TownList;
typedef std::list<ItemPtr> ItemList; typedef std::list<ItemPtr> ItemList;
typedef std::list<TilePtr> TileList; typedef std::list<TilePtr> TileList;
typedef std::vector<ItemPtr> ItemVector; typedef std::vector<ItemPtr> ItemVector;
typedef std::unordered_map<Position, TilePtr, PositionHasher> TileMap; typedef std::unordered_map<Position, TilePtr, Position::Hasher> TileMap;
typedef std::unordered_map<Position, CreatureTypePtr, PositionHasher> CreatureMap; typedef std::unordered_map<Position, CreatureTypePtr, Position::Hasher> CreatureMap;
typedef std::unordered_map<Position, SpawnPtr, PositionHasher> SpawnMap; typedef std::unordered_map<Position, SpawnPtr, Position::Hasher> SpawnMap;
// net // net
class ProtocolLogin; class ProtocolLogin;

View File

@@ -265,17 +265,16 @@ void LocalPlayer::updateWalkOffset(int totalPixelsWalked)
void LocalPlayer::updateWalk() void LocalPlayer::updateWalk()
{ {
int stepDuration = getStepDuration(); int stepDuration = getStepDuration(true);
float walkTicksPerPixel = getStepDuration(true) / 32.0f; int totalPixelsWalked = stepDuration ? std::min<int>((m_walkTimer.ticksElapsed() * Otc::TILE_PIXELS) / stepDuration, Otc::TILE_PIXELS) : 0;
int totalPixelsWalked = std::min<int>(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f);
// update walk animation and offsets // update walk animation and offsets
updateWalkAnimation(totalPixelsWalked); updateWalkAnimation(totalPixelsWalked, stepDuration);
updateWalkOffset(totalPixelsWalked); updateWalkOffset(totalPixelsWalked);
updateWalkingTile(); updateWalkingTile();
// terminate walk only when client and server side walk are completed // terminate walk only when client and server side walk are completed
if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= stepDuration) if(m_walking && !m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration())
terminateWalk(); terminateWalk();
} }

View File

@@ -596,6 +596,7 @@ void Client::registerLuaFunctions()
g_lua.registerClass<Missile, Thing>(); g_lua.registerClass<Missile, Thing>();
g_lua.bindClassStaticFunction<Missile>("create", []{ return MissilePtr(new Missile); }); g_lua.bindClassStaticFunction<Missile>("create", []{ return MissilePtr(new Missile); });
g_lua.bindClassMemberFunction<Missile>("setId", &Missile::setId); g_lua.bindClassMemberFunction<Missile>("setId", &Missile::setId);
g_lua.bindClassMemberFunction<Missile>("setPath", &Missile::setPath);
g_lua.registerClass<StaticText, Thing>(); g_lua.registerClass<StaticText, Thing>();
g_lua.bindClassStaticFunction<StaticText>("create", []{ return StaticTextPtr(new StaticText); }); g_lua.bindClassStaticFunction<StaticText>("create", []{ return StaticTextPtr(new StaticText); });

View File

@@ -718,19 +718,21 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
// as described in http://en.wikipedia.org/wiki/A*_search_algorithm // as described in http://en.wikipedia.org/wiki/A*_search_algorithm
struct Node { struct Node {
using Pair = std::pair<Node *, float>;
Node(const Position& pos) : cost(0), totalCost(0), pos(pos), prev(nullptr), dir(Otc::InvalidDirection) { } Node(const Position& pos) : cost(0), totalCost(0), pos(pos), prev(nullptr), dir(Otc::InvalidDirection) { }
float cost; float cost;
float totalCost; float totalCost;
Position pos; Position pos;
Node *prev; Node *prev;
Otc::Direction dir; Otc::Direction dir;
};
struct LessNode : std::binary_function<std::pair<Node*, float>, std::pair<Node*, float>, bool> { struct Compare {
bool operator()(std::pair<Node*, float> a, std::pair<Node*, float> b) const { bool operator() (const Pair &a, const Pair &b) const {
return b.second < a.second; return b.second < a.second;
} }
}; };
};
std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> ret; std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> ret;
std::vector<Otc::Direction>& dirs = std::get<0>(ret); std::vector<Otc::Direction>& dirs = std::get<0>(ret);
@@ -751,7 +753,7 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
// check the goal pos is walkable // check the goal pos is walkable
if(g_map.isAwareOfPosition(goalPos)) { if(g_map.isAwareOfPosition(goalPos)) {
const TilePtr goalTile = getTile(goalPos); const TilePtr goalTile = getTile(goalPos);
if(!goalTile || !goalTile->isWalkable()) { if(!goalTile || !goalTile->isWalkable((flags & Otc::PathFindAllowCreatures))) {
return ret; return ret;
} }
} }
@@ -762,8 +764,8 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
} }
} }
std::unordered_map<Position, Node*, PositionHasher> nodes; std::unordered_map<Position, Node*, Position::Hasher> nodes;
std::priority_queue<std::pair<Node*, float>, std::vector<std::pair<Node*, float>>, LessNode> searchList; std::priority_queue<Node::Pair, std::deque<Node::Pair>, Node::Compare> searchList;
Node *currentNode = new Node(startPos); Node *currentNode = new Node(startPos);
currentNode->pos = startPos; currentNode->pos = startPos;
@@ -799,7 +801,7 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
wasSeen = true; wasSeen = true;
if(const TilePtr& tile = getTile(neighborPos)) { if(const TilePtr& tile = getTile(neighborPos)) {
hasCreature = tile->hasCreature(); hasCreature = tile->hasCreature();
isNotWalkable = !tile->isWalkable(); isNotWalkable = !tile->isWalkable((flags & Otc::PathFindAllowCreatures));
isNotPathable = !tile->isPathable(); isNotPathable = !tile->isPathable();
speed = tile->getGroundSpeed(); speed = tile->getGroundSpeed();
} }
@@ -856,7 +858,7 @@ std::tuple<std::vector<Otc::Direction>, Otc::PathFindResult> Map::findPath(const
neighborNode->cost = cost; neighborNode->cost = cost;
neighborNode->totalCost = neighborNode->cost + neighborPos.distance(goalPos); neighborNode->totalCost = neighborNode->cost + neighborPos.distance(goalPos);
neighborNode->dir = walkDir; neighborNode->dir = walkDir;
searchList.push(std::make_pair(neighborNode, neighborNode->totalCost)); searchList.emplace(neighborNode, neighborNode->totalCost);
} }
} }

View File

@@ -253,7 +253,7 @@ private:
std::vector<AnimatedTextPtr> m_animatedTexts; std::vector<AnimatedTextPtr> m_animatedTexts;
std::vector<StaticTextPtr> m_staticTexts; std::vector<StaticTextPtr> m_staticTexts;
std::vector<MapViewPtr> m_mapViews; std::vector<MapViewPtr> m_mapViews;
std::unordered_map<Position, std::string, PositionHasher> m_waypoints; std::unordered_map<Position, std::string, Position::Hasher> m_waypoints;
uint8 m_animationFlags; uint8 m_animationFlags;
uint32 m_zoneFlags; uint32 m_zoneFlags;

View File

@@ -154,21 +154,21 @@ public:
{ {
float angle = getAngleFromPositions(fromPos, toPos) * RAD_TO_DEC; float angle = getAngleFromPositions(fromPos, toPos) * RAD_TO_DEC;
if(angle >= 360 - 22.5 || angle < 0 + 22.5) if(angle >= 360 - 22.5f || angle < 0 + 22.5f)
return Otc::East; return Otc::East;
else if(angle >= 45 - 22.5 && angle < 45 + 22.5) else if(angle >= 45 - 22.5f && angle < 45 + 22.5f)
return Otc::NorthEast; return Otc::NorthEast;
else if(angle >= 90 - 22.5 && angle < 90 + 22.5) else if(angle >= 90 - 22.5f && angle < 90 + 22.5f)
return Otc::North; return Otc::North;
else if(angle >= 135 - 22.5 && angle < 135 + 22.5) else if(angle >= 135 - 22.5f && angle < 135 + 22.5f)
return Otc::NorthWest; return Otc::NorthWest;
else if(angle >= 180 - 22.5 && angle < 180 + 22.5) else if(angle >= 180 - 22.5f && angle < 180 + 22.5f)
return Otc::West; return Otc::West;
else if(angle >= 225 - 22.5 && angle < 225 + 22.5) else if(angle >= 225 - 22.5f && angle < 225 + 22.5f)
return Otc::SouthWest; return Otc::SouthWest;
else if(angle >= 270 - 22.5 && angle < 270 + 22.5) else if(angle >= 270 - 22.5f && angle < 270 + 22.5f)
return Otc::South; return Otc::South;
else if(angle >= 315 - 22.5 && angle < 315 + 22.5) else if(angle >= 315 - 22.5f && angle < 315 + 22.5f)
return Otc::SouthEast; return Otc::SouthEast;
else else
return Otc::InvalidDirection; return Otc::InvalidDirection;
@@ -243,12 +243,14 @@ public:
int x; int x;
int y; int y;
short z; short z;
};
struct PositionHasher : std::unary_function<Position, std::size_t> { // NOTE: This does not increase the size of the struct.
std::size_t operator()(const Position& pos) const { struct Hasher
{
std::size_t operator() (const Position& pos) const {
return (((pos.x * 8192) + pos.y) * 16) + pos.z; return (((pos.x * 8192) + pos.y) * 16) + pos.z;
} }
};
}; };
inline std::ostream& operator<<(std::ostream& out, const Position& pos) inline std::ostream& operator<<(std::ostream& out, const Position& pos)

View File

@@ -77,6 +77,49 @@ void buildMessageModesMap(int version) {
messageModesMap[Otc::MessageTutorialHint] = 40; messageModesMap[Otc::MessageTutorialHint] = 40;
messageModesMap[Otc::MessageThankyou] = 41; messageModesMap[Otc::MessageThankyou] = 41;
messageModesMap[Otc::MessageMarket] = 42; messageModesMap[Otc::MessageMarket] = 42;
} else if(version >= 1041) {
messageModesMap[Otc::MessageNone] = 0;
messageModesMap[Otc::MessageSay] = 1;
messageModesMap[Otc::MessageWhisper] = 2;
messageModesMap[Otc::MessageYell] = 3;
messageModesMap[Otc::MessagePrivateFrom] = 4;
messageModesMap[Otc::MessagePrivateTo] = 5;
messageModesMap[Otc::MessageChannelManagement] = 6;
messageModesMap[Otc::MessageChannel] = 7;
messageModesMap[Otc::MessageChannelHighlight] = 8;
messageModesMap[Otc::MessageSpell] = 9;
messageModesMap[Otc::MessageNpcFromStartBlock] = 10;
messageModesMap[Otc::MessageNpcFrom] = 11;
messageModesMap[Otc::MessageNpcTo] = 12;
messageModesMap[Otc::MessageGamemasterBroadcast] = 13;
messageModesMap[Otc::MessageGamemasterChannel] = 14;
messageModesMap[Otc::MessageGamemasterPrivateFrom] = 15;
messageModesMap[Otc::MessageGamemasterPrivateTo] = 16;
messageModesMap[Otc::MessageLogin] = 17;
messageModesMap[Otc::MessageWarning] = 18; // Admin
messageModesMap[Otc::MessageGame] = 19;
messageModesMap[Otc::MessageFailure] = 20;
messageModesMap[Otc::MessageLook] = 21;
messageModesMap[Otc::MessageDamageDealed] = 22;
messageModesMap[Otc::MessageDamageReceived] = 23;
messageModesMap[Otc::MessageHeal] = 24;
messageModesMap[Otc::MessageExp] = 25;
messageModesMap[Otc::MessageDamageOthers] = 26;
messageModesMap[Otc::MessageHealOthers] = 27;
messageModesMap[Otc::MessageExpOthers] = 28;
messageModesMap[Otc::MessageStatus] = 29;
messageModesMap[Otc::MessageLoot] = 30;
messageModesMap[Otc::MessageTradeNpc] = 31;
messageModesMap[Otc::MessageGuild] = 32;
messageModesMap[Otc::MessagePartyManagement] = 33;
messageModesMap[Otc::MessageParty] = 34;
messageModesMap[Otc::MessageBarkLow] = 35;
messageModesMap[Otc::MessageBarkLoud] = 36;
messageModesMap[Otc::MessageReport] = 37;
messageModesMap[Otc::MessageHotkeyUse] = 38;
messageModesMap[Otc::MessageTutorialHint] = 49;
messageModesMap[Otc::MessageThankyou] = 40;
messageModesMap[Otc::MessageMarket] = 41;
} else if(version >= 1036) { } else if(version >= 1036) {
for(int i = Otc::MessageNone; i <= Otc::MessageBeyondLast; ++i) { for(int i = Otc::MessageNone; i <= Otc::MessageBeyondLast; ++i) {
if(i >= Otc::MessageNpcTo) if(i >= Otc::MessageNpcTo)

View File

@@ -88,8 +88,8 @@ public:
int getDrawElevation() { return m_drawElevation; } int getDrawElevation() { return m_drawElevation; }
std::vector<ItemPtr> getItems(); std::vector<ItemPtr> getItems();
std::vector<CreaturePtr> getCreatures(); std::vector<CreaturePtr> getCreatures();
std::vector<CreaturePtr> getWalkingCreatures() { return m_walkingCreatures; } const std::vector<CreaturePtr>& getWalkingCreatures() { return m_walkingCreatures; }
std::vector<ThingPtr> getThings() { return m_things; } const std::vector<ThingPtr>& getThings() { return m_things; }
ItemPtr getGround(); ItemPtr getGround();
int getGroundSpeed(); int getGroundSpeed();
uint8 getMinimapColorByte(); uint8 getMinimapColorByte();
@@ -132,9 +132,9 @@ public:
private: private:
void checkTranslucentLight(); void checkTranslucentLight();
stdext::packed_vector<CreaturePtr> m_walkingCreatures; std::vector<CreaturePtr> m_walkingCreatures;
stdext::packed_vector<EffectPtr> m_effects; // leave this outside m_things because it has no stackpos. std::vector<EffectPtr> m_effects; // leave this outside m_things because it has no stackpos.
stdext::packed_vector<ThingPtr> m_things; std::vector<ThingPtr> m_things;
Position m_position; Position m_position;
uint8 m_drawElevation; uint8 m_drawElevation;
uint8 m_minimapColor; uint8 m_minimapColor;

View File

@@ -5,11 +5,6 @@
# FRAMEWORK_XML # FRAMEWORK_XML
# FRAMEWORK_SQL # FRAMEWORK_SQL
# CMAKE_CURRENT_LIST_DIR cmake 2.6 compatibility
if(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
endif(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
# add framework cmake modules # add framework cmake modules
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake;${CMAKE_MODULE_PATH}") set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake;${CMAKE_MODULE_PATH}")
@@ -49,7 +44,6 @@ set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/stdext/net.h ${CMAKE_CURRENT_LIST_DIR}/stdext/net.h
${CMAKE_CURRENT_LIST_DIR}/stdext/packed_any.h ${CMAKE_CURRENT_LIST_DIR}/stdext/packed_any.h
${CMAKE_CURRENT_LIST_DIR}/stdext/packed_storage.h ${CMAKE_CURRENT_LIST_DIR}/stdext/packed_storage.h
${CMAKE_CURRENT_LIST_DIR}/stdext/packed_vector.h
${CMAKE_CURRENT_LIST_DIR}/stdext/shared_object.h ${CMAKE_CURRENT_LIST_DIR}/stdext/shared_object.h
${CMAKE_CURRENT_LIST_DIR}/stdext/shared_ptr.h ${CMAKE_CURRENT_LIST_DIR}/stdext/shared_ptr.h
${CMAKE_CURRENT_LIST_DIR}/stdext/stdext.h ${CMAKE_CURRENT_LIST_DIR}/stdext/stdext.h
@@ -134,41 +128,44 @@ set(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/platform/platform.h ${CMAKE_CURRENT_LIST_DIR}/platform/platform.h
) )
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp if(NOT MSVC)
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/luafunctions.cpp
PROPERTIES LANGUAGE CXX COMPILE_FLAGS "-g0 -Os") PROPERTIES LANGUAGE CXX COMPILE_FLAGS "-g0 -Os")
endif()
# some build options # some build options
option(LUAJIT "Use lua jit" OFF) option(LUAJIT "Use lua jit" OFF)
option(USE_STATIC_LIBS "Don't use shared libraries (dlls)" ON)
if(NOT APPLE) if(NOT APPLE)
option(CRASH_HANDLER "Generate crash reports" ON) option(CRASH_HANDLER "Generate crash reports" ON)
option(USE_STATIC_LIBS "Don't use shared libraries (dlls)" ON)
option(USE_LIBCPP "Use the new libc++ library instead of stdc++" OFF) option(USE_LIBCPP "Use the new libc++ library instead of stdc++" OFF)
option(USE_LTO "Use link time optimizations" OFF) option(USE_LTO "Use link time optimizations" OFF)
else() else()
set(CRASH_HANDLER OFF) set(CRASH_HANDLER OFF)
set(USE_STATIC_LIBS OFF)
set(USE_LIBCPP ON) set(USE_LIBCPP ON)
endif() endif()
set(BUILD_COMMIT "devel" CACHE "Git commit string (intended for releases)" STRING) set(BUILD_COMMIT "devel" CACHE STRING "Git commit string (intended for releases)")
set(BUILD_REVISION "0" CACHE "Git revision string (intended for releases)" STRING) set(BUILD_REVISION "0" CACHE STRING "Git revision string (intended for releases)")
# default build type # default build type
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo") set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif() endif()
include(FindCXX11) set(COMPILER_CXX_EXTRA_FLAGS "-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wno-unused-result -pipe")
# gcc compile flags
set(WARNS_FLAGS "-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wno-unused-result")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNS_FLAGS} ${ARCH_FLAGS} ${CPP2011_FLAGS} -pipe")
set(CMAKE_CXX_FLAGS_COMPILESPEED "-O0")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_RELEASE "-O2") set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS_PERFORMANCE "-Ofast -march=native") if (WIN32 AND MSVC)
set(COMPILER_CXX_EXTRA_FLAGS "/bigobj")
set(CMAKE_CXX_FLAGS_DEBUG "/Od /DEBUG:FULL")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O12 /DEBUG:FASTLINK")
set(CMAKE_CXX_FLAGS_RELEASE "/Ot")
endif()
if(USE_LTO) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_CXX_EXTRA_FLAGS} ${ARCH_FLAGS} ${CPP2011_FLAGS}")
if(USE_LTO AND NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fwhole-program -flto") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fwhole-program -flto")
if(WIN32) if(WIN32)
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-O1,--gc-sections,--sort-common,--relax") set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-O1,--gc-sections,--sort-common,--relax")
@@ -275,7 +272,10 @@ if(USE_LIBCPP)
endif() endif()
if(WIN32) if(WIN32)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthreads") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthreads")
endif()
set(framework_DEFINITIONS ${framework_DEFINITIONS} -D_WIN32_WINNT=0x0501 -DWIN32) set(framework_DEFINITIONS ${framework_DEFINITIONS} -D_WIN32_WINNT=0x0501 -DWIN32)
#set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,--large-address-aware") # strip all debug information #set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,--large-address-aware") # strip all debug information
set(SYSTEM_LIBRARIES "") set(SYSTEM_LIBRARIES "")
@@ -295,15 +295,16 @@ if(FRAMEWORK_THREAD_SAFE)
set(framework_DEFINITIONS ${framework_DEFINITIONS} -DTHREAD_SAFE) set(framework_DEFINITIONS ${framework_DEFINITIONS} -DTHREAD_SAFE)
endif() endif()
set(OpenGL_GL_PREFERENCE "GLVND")
if(FRAMEWORK_GRAPHICS) if(FRAMEWORK_GRAPHICS)
set(OPENGLES "OFF" CACHE "Use OpenGL ES 1.0 or 2.0 (for mobiles devices)" STRING) set(OPENGLES "OFF" CACHE STRING "Use OpenGL ES 1.0 or 2.0 (for mobiles devices)")
if(OPENGLES STREQUAL "2.0") if(OPENGLES STREQUAL "2.0")
find_package(OpenGLES2 REQUIRED) find_package(OpenGLES2 REQUIRED)
find_package(EGL REQUIRED) find_package(EGL REQUIRED)
set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=2) set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=2)
set(framework_INCLUDE_DIRS ${framework_INCLUDE_DIRS} ${EGL_INCLUDE_DIR} ${OPENGLES2_INCLUDE_DIR}) set(framework_INCLUDE_DIRS ${framework_INCLUDE_DIRS} ${EGL_INCLUDE_DIR} ${OPENGLES2_INCLUDE_DIR})
set(framework_LIBRARIES ${framework_LIBRARIES} ${EGL_LIBRARY} ${OPENGLES2_LIBRARY}) set(framework_LIBRARIES ${framework_LIBRARIES} ${EGL_LIBRARY} ${OPENGLES2_LIBRARY})
ELSEif(OPENGLES STREQUAL "1.0") elseif(OPENGLES STREQUAL "1.0")
find_package(OpenGLES1 REQUIRED) find_package(OpenGLES1 REQUIRED)
find_package(EGL REQUIRED) find_package(EGL REQUIRED)
set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=1) set(framework_DEFINITIONS ${framework_DEFINITIONS} -DOPENGL_ES=1)

View File

@@ -1,26 +0,0 @@
if(__FIND_CXX11_CMAKE__)
return()
endif()
set(__FIND_CXX11_CMAKE__ TRUE)
include(CheckCXXCompilerFlag)
enable_language(CXX)
check_cxx_compiler_flag("-std=c++11" COMPILER_KNOWS_CXX11)
if(COMPILER_KNOWS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Tested on Mac OS X 10.8.2 with XCode 4.6 Command Line Tools
# Clang requires this to find the correct c++11 headers
check_cxx_compiler_flag("-stdlib=libc++" COMPILER_KNOWS_STDLIB)
if(APPLE AND COMPILER_KNOWS_STDLIB)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
else()
check_cxx_compiler_flag("-std=c++0x" COMPILER_KNOWS_CXX0X)
if(COMPILER_KNOWS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif()
endif()

View File

@@ -4,10 +4,10 @@
# LUA_LIBRARY - the lua library # LUA_LIBRARY - the lua library
# LUA_LIBRARIES - the lua library and it's dependencies # LUA_LIBRARIES - the lua library and it's dependencies
FIND_PATH(LUA_INCLUDE_DIR NAMES lua.h PATH_SUFFIXES lua51 lua5.1 lua) FIND_PATH(LUA_INCLUDE_DIR NAMES lua.h PATH_SUFFIXES lua51 lua5-1 lua5.1 lua)
FIND_LIBRARY(LUA_LIBRARY NAMES) FIND_LIBRARY(LUA_LIBRARY NAMES)
SET(_LUA_STATIC_LIBS liblua51.a liblua5.1.a liblua-5.1.a liblua.a ) SET(_LUA_STATIC_LIBS liblua51.a liblua5.1.a liblua-5.1.a liblua.a)
SET(_LUA_SHARED_LIBS liblua51.dll.a liblua5.1.dll.a liblua-5.1.dll.a liblua.dll.a lua51.dll lua5.1 lua-5.1 lua) SET(_LUA_SHARED_LIBS lua51 lua5.1 lua-5.1 lua)
IF(USE_STATIC_LIBS) IF(USE_STATIC_LIBS)
FIND_LIBRARY(LUA_LIBRARY NAMES ${_LUA_STATIC_LIBS} ${_LUA_SHARED_LIBS}) FIND_LIBRARY(LUA_LIBRARY NAMES ${_LUA_STATIC_LIBS} ${_LUA_SHARED_LIBS})
ELSE() ELSE()

View File

@@ -2,11 +2,10 @@
# LUAJIT_FOUND - system has lua # LUAJIT_FOUND - system has lua
# LUAJIT_INCLUDE_DIR - the lua include directory # LUAJIT_INCLUDE_DIR - the lua include directory
# LUAJIT_LIBRARY - the lua library # LUAJIT_LIBRARY - the lua library
# LUAJIT_LIBRARIES - the lua library and it's dependencies
FIND_PATH(LUAJIT_INCLUDE_DIR NAMES lua.h PATH_SUFFIXES luajit-2.0) FIND_PATH(LUAJIT_INCLUDE_DIR NAMES luajit.h PATH_SUFFIXES luajit luajit-2.0 luajit-2.1)
SET(_LUAJIT_STATIC_LIBS libluajit51.a libluajit5.1.a libluajit-5.1.a libluajit.a) SET(_LUAJIT_STATIC_LIBS libluajit-5.1.a libluajit.a liblua51.a)
SET(_LUAJIT_SHARED_LIBS libluajit51.dll.a libluajit5.1.dll.a libluajit-5.1.dll.a libluajit.dll.a luajit51 luajit5.1 luajit-5.1 luajit) SET(_LUAJIT_SHARED_LIBS luajit-5.1 luajit lua51)
IF(USE_STATIC_LIBS) IF(USE_STATIC_LIBS)
FIND_LIBRARY(LUAJIT_LIBRARY NAMES ${_LUAJIT_STATIC_LIBS} ${_LUAJIT_SHARED_LIBS}) FIND_LIBRARY(LUAJIT_LIBRARY NAMES ${_LUAJIT_STATIC_LIBS} ${_LUAJIT_SHARED_LIBS})
ELSE() ELSE()

View File

@@ -12,5 +12,5 @@ ELSE()
FIND_LIBRARY(OGG_LIBRARY NAMES ${_OGG_SHARED_LIBS} ${_OGG_STATIC_LIBS}) FIND_LIBRARY(OGG_LIBRARY NAMES ${_OGG_SHARED_LIBS} ${_OGG_STATIC_LIBS})
ENDIF() ENDIF()
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OGG DEFAULT_MSG OGG_LIBRARY OGG_INCLUDE_DIR) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ogg DEFAULT_MSG OGG_LIBRARY OGG_INCLUDE_DIR)
MARK_AS_ADVANCED(OGG_LIBRARY OGG_INCLUDE_DIR) MARK_AS_ADVANCED(OGG_LIBRARY OGG_INCLUDE_DIR)

View File

@@ -13,5 +13,5 @@ ELSE()
FIND_LIBRARY(OPENAL_LIBRARY NAMES ${_OPENAL_SHARED_LIBS} ${_OPENAL_STATIC_LIBS} PATHS ${OPENAL_APPLE_PATHS}) FIND_LIBRARY(OPENAL_LIBRARY NAMES ${_OPENAL_SHARED_LIBS} ${_OPENAL_STATIC_LIBS} PATHS ${OPENAL_APPLE_PATHS})
ENDIF() ENDIF()
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENAL DEFAULT_MSG OPENAL_LIBRARY OPENAL_INCLUDE_DIR) FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenAL DEFAULT_MSG OPENAL_LIBRARY OPENAL_INCLUDE_DIR)
MARK_AS_ADVANCED(OPENAL_LIBRARY OPENAL_INCLUDE_DIR) MARK_AS_ADVANCED(OPENAL_LIBRARY OPENAL_INCLUDE_DIR)

View File

@@ -3,11 +3,11 @@
# OPENSSL_INCLUDE_DIR - the OpenSSL include directory # OPENSSL_INCLUDE_DIR - the OpenSSL include directory
# OPENSSL_LIBRARY - the OpenSSL library # OPENSSL_LIBRARY - the OpenSSL library
FIND_PATH(OPENSSL_INCLUDE_DIR NAMES openssl/ssl.h PATH_SUFFIXES openssl-1.0) FIND_PATH(OPENSSL_INCLUDE_DIR NAMES openssl/ssl.h PATH_SUFFIXES include openssl-1.0)
SET(_OPENSSL_STATIC_LIBS libssl.a) SET(_OPENSSL_STATIC_LIBS libssl.a ssl.a)
SET(_OPENSSL_SHARED_LIBS libssl.dll.a ssl) SET(_OPENSSL_SHARED_LIBS libssl ssl)
SET(_OPENSSL_CRYPTO_STATIC_LIBS libcrypto.a) SET(_OPENSSL_CRYPTO_STATIC_LIBS libcrypto.a crypto.a)
SET(_OPENSSL_CRYPTO_SHARED_LIBS libcrypto.dll.a crypto) SET(_OPENSSL_CRYPTO_SHARED_LIBS libcrypto crypto)
IF(USE_STATIC_LIBS) IF(USE_STATIC_LIBS)
FIND_LIBRARY(OPENSSL_LIBRARY NAMES ${_OPENSSL_STATIC_LIBS} ${_OPENSSL_SHARED_LIBS} PATH_SUFFIXES openssl-1.0) FIND_LIBRARY(OPENSSL_LIBRARY NAMES ${_OPENSSL_STATIC_LIBS} ${_OPENSSL_SHARED_LIBS} PATH_SUFFIXES openssl-1.0)
FIND_LIBRARY(OPENSSL_CRYPTO_LIBRARY NAMES ${_OPENSSL_CRYPTO_STATIC_LIBS} ${_OPENSSL_CRYPTO_SHARED_LIBS} PATH_SUFFIXES openssl-1.0) FIND_LIBRARY(OPENSSL_CRYPTO_LIBRARY NAMES ${_OPENSSL_CRYPTO_STATIC_LIBS} ${_OPENSSL_CRYPTO_SHARED_LIBS} PATH_SUFFIXES openssl-1.0)
@@ -17,5 +17,5 @@ ELSE()
ENDIF() ENDIF()
SET(OPENSSL_LIBRARIES ${OPENSSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}) SET(OPENSSL_LIBRARIES ${OPENSSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENSSL DEFAULT_MSG OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR) FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenSSL DEFAULT_MSG OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR)
MARK_AS_ADVANCED(OPENSSL_LIBRARIES OPENSSL_LIBRARY OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) MARK_AS_ADVANCED(OPENSSL_LIBRARIES OPENSSL_LIBRARY OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR)

View File

@@ -12,5 +12,5 @@ ELSE()
FIND_LIBRARY(PHYSFS_LIBRARY NAMES ${_PHYSFS_SHARED_LIBS} ${_PHYSFS_STATIC_LIBS}) FIND_LIBRARY(PHYSFS_LIBRARY NAMES ${_PHYSFS_SHARED_LIBS} ${_PHYSFS_STATIC_LIBS})
ENDIF() ENDIF()
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PHYSFS DEFAULT_MSG PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR) FIND_PACKAGE_HANDLE_STANDARD_ARGS(PhysFS DEFAULT_MSG PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR)
MARK_AS_ADVANCED(PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR) MARK_AS_ADVANCED(PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR)

View File

@@ -12,5 +12,5 @@ ELSE()
FIND_LIBRARY(VORBIS_LIBRARY NAMES ${_VORBIS_SHARED_LIBS} ${_VORBIS_STATIC_LIBS}) FIND_LIBRARY(VORBIS_LIBRARY NAMES ${_VORBIS_SHARED_LIBS} ${_VORBIS_STATIC_LIBS})
ENDIF() ENDIF()
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(VORBIS DEFAULT_MSG VORBIS_LIBRARY VORBIS_INCLUDE_DIR) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Vorbis DEFAULT_MSG VORBIS_LIBRARY VORBIS_INCLUDE_DIR)
MARK_AS_ADVANCED(VORBIS_LIBRARY VORBIS_INCLUDE_DIR) MARK_AS_ADVANCED(VORBIS_LIBRARY VORBIS_INCLUDE_DIR)

View File

@@ -12,5 +12,5 @@ ELSE()
FIND_LIBRARY(VORBISFILE_LIBRARY NAMES ${_VORBISFILE_SHARED_LIBS} ${_VORBISFILE_STATIC_LIBS}) FIND_LIBRARY(VORBISFILE_LIBRARY NAMES ${_VORBISFILE_SHARED_LIBS} ${_VORBISFILE_STATIC_LIBS})
ENDIF() ENDIF()
INCLUDE(FindPackageHandleStandardArgs) INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(VORBISFILE DEFAULT_MSG VORBISFILE_LIBRARY VORBISFILE_INCLUDE_DIR) FIND_PACKAGE_HANDLE_STANDARD_ARGS(VorbisFile DEFAULT_MSG VORBISFILE_LIBRARY VORBISFILE_INCLUDE_DIR)
MARK_AS_ADVANCED(VORBISFILE_LIBRARY VORBISFILE_INCLUDE_DIR) MARK_AS_ADVANCED(VORBISFILE_LIBRARY VORBISFILE_INCLUDE_DIR)

View File

@@ -25,8 +25,8 @@
#include "stdext/compiler.h" #include "stdext/compiler.h"
#define DEG_TO_RAD (acos(-1)/180.0) #define DEG_TO_RAD (std::acos(-1.f)/180.f)
#define RAD_TO_DEC (180.0/acos(-1)) #define RAD_TO_DEC (180.f/std::acos(-1.f))
#ifndef BUILD_COMMIT #ifndef BUILD_COMMIT
#define BUILD_COMMIT "devel" #define BUILD_COMMIT "devel"
@@ -52,7 +52,7 @@
namespace Fw namespace Fw
{ {
static const float pi = 3.14159265; static const float pi = 3.14159265f;
static const float MIN_ALPHA = 0.003f; static const float MIN_ALPHA = 0.003f;
enum Key : unsigned char { enum Key : unsigned char {
KeyUnknown = 0, KeyUnknown = 0,

View File

@@ -54,7 +54,7 @@ ConfigPtr ConfigManager::getSettings()
ConfigPtr ConfigManager::get(const std::string& file) ConfigPtr ConfigManager::get(const std::string& file)
{ {
for(const ConfigPtr config : m_configs) { for(const ConfigPtr& config : m_configs) {
if(config->getFileName() == file) { if(config->getFileName() == file) {
return config; return config;
} }

View File

@@ -116,4 +116,3 @@ EventPtr EventDispatcher::addEvent(const std::function<void()>& callback, bool p
m_eventList.push_back(event); m_eventList.push_back(event);
return event; return event;
} }

View File

@@ -40,10 +40,10 @@ public:
ScheduledEventPtr cycleEvent(const std::function<void()>& callback, int delay); ScheduledEventPtr cycleEvent(const std::function<void()>& callback, int delay);
private: private:
std::list<EventPtr> m_eventList; std::deque<EventPtr> m_eventList;
int m_pollEventsSize; int m_pollEventsSize;
stdext::boolean<false> m_disabled; stdext::boolean<false> m_disabled;
std::priority_queue<ScheduledEventPtr, std::vector<ScheduledEventPtr>, lessScheduledEvent> m_scheduledEventList; std::priority_queue<ScheduledEventPtr, std::deque<ScheduledEventPtr>, ScheduledEvent::Compare> m_scheduledEventList;
}; };
extern EventDispatcher g_dispatcher; extern EventDispatcher g_dispatcher;

View File

@@ -34,6 +34,12 @@
Logger g_logger; Logger g_logger;
namespace
{
const std::string s_logPrefixes[] = { "", "", "WARNING: ", "ERROR: ", "FATAL ERROR: " };
bool s_ignoreLogs = false;
}
void Logger::log(Fw::LogLevel level, const std::string& message) void Logger::log(Fw::LogLevel level, const std::string& message)
{ {
std::lock_guard<std::recursive_mutex> lock(m_mutex); std::lock_guard<std::recursive_mutex> lock(m_mutex);
@@ -43,13 +49,10 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
return; return;
#endif #endif
static bool ignoreLogs = false; if(s_ignoreLogs)
if(ignoreLogs)
return; return;
const static std::string logPrefixes[] = { "", "", "WARNING: ", "ERROR: ", "FATAL ERROR: " }; std::string outmsg = s_logPrefixes[level] + message;
std::string outmsg = logPrefixes[level] + message;
/* /*
#if !defined(NDEBUG) && !defined(WIN32) #if !defined(NDEBUG) && !defined(WIN32)
@@ -91,7 +94,7 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
#ifdef FW_GRAPHICS #ifdef FW_GRAPHICS
g_window.displayFatalError(message); g_window.displayFatalError(message);
#endif #endif
ignoreLogs = true; s_ignoreLogs = true;
exit(-1); exit(-1);
} }
} }
@@ -122,8 +125,7 @@ void Logger::fireOldMessages()
std::lock_guard<std::recursive_mutex> lock(m_mutex); std::lock_guard<std::recursive_mutex> lock(m_mutex);
if(m_onLog) { if(m_onLog) {
auto backup = m_logMessages; for(const LogMessage& logMessage : m_logMessages) {
for(const LogMessage& logMessage : backup) {
m_onLog(logMessage.level, logMessage.message, logMessage.when); m_onLog(logMessage.level, logMessage.message, logMessage.when);
} }
} }

View File

@@ -59,7 +59,7 @@ public:
void setOnLog(const OnLogCallback& onLog) { m_onLog = onLog; } void setOnLog(const OnLogCallback& onLog) { m_onLog = onLog; }
private: private:
std::list<LogMessage> m_logMessages; std::deque<LogMessage> m_logMessages;
OnLogCallback m_onLog; OnLogCallback m_onLog;
std::ofstream m_outFile; std::ofstream m_outFile;
std::recursive_mutex m_mutex; std::recursive_mutex m_mutex;

View File

@@ -156,14 +156,13 @@ void ResourceManager::searchAndAddPackages(const std::string& packagesDir, const
bool ResourceManager::fileExists(const std::string& fileName) bool ResourceManager::fileExists(const std::string& fileName)
{ {
const std::string path = resolvePath(fileName); return (PHYSFS_exists(resolvePath(fileName).c_str()) && !directoryExists(fileName));
return (PHYSFS_exists(path.c_str()) && !directoryExists(path));
} }
bool ResourceManager::directoryExists(const std::string& directoryName) bool ResourceManager::directoryExists(const std::string& directoryName)
{ {
PHYSFS_Stat stat = {}; PHYSFS_Stat stat = {};
if (!PHYSFS_stat(directoryName.c_str(), &stat)) { if (!PHYSFS_stat(resolvePath(directoryName).c_str(), &stat)) {
return false; return false;
} }

View File

@@ -40,6 +40,12 @@ public:
int cyclesExecuted() { return m_cyclesExecuted; } int cyclesExecuted() { return m_cyclesExecuted; }
int maxCycles() { return m_maxCycles; } int maxCycles() { return m_maxCycles; }
struct Compare {
bool operator() (const ScheduledEventPtr &a, const ScheduledEventPtr &b) const {
return b->ticks() < a->ticks();
}
};
private: private:
ticks_t m_ticks; ticks_t m_ticks;
int m_delay; int m_delay;
@@ -47,10 +53,4 @@ private:
int m_cyclesExecuted; int m_cyclesExecuted;
}; };
struct lessScheduledEvent : std::binary_function<ScheduledEventPtr, ScheduledEventPtr&, bool> {
bool operator()(const ScheduledEventPtr& a, const ScheduledEventPtr& b) {
return b->ticks() < a->ticks();
}
};
#endif #endif

View File

@@ -27,6 +27,14 @@
#include <framework/otml/otml.h> #include <framework/otml/otml.h>
namespace
{
// for performance reasons we use statics vectors that are allocated on demand
CoordsBuffer s_coordsBuffer;
std::vector<Point> s_glyphsPositions(1);
std::vector<int> s_lineWidths(1);
}
void BitmapFont::load(const OTMLNodePtr& fontNode) void BitmapFont::load(const OTMLNodePtr& fontNode)
{ {
OTMLNodePtr textureNode = fontNode->at("texture"); OTMLNodePtr textureNode = fontNode->at("texture");
@@ -35,11 +43,12 @@ void BitmapFont::load(const OTMLNodePtr& fontNode)
m_glyphHeight = fontNode->valueAt<int>("height"); m_glyphHeight = fontNode->valueAt<int>("height");
m_yOffset = fontNode->valueAt("y-offset", 0); m_yOffset = fontNode->valueAt("y-offset", 0);
m_firstGlyph = fontNode->valueAt("first-glyph", 32); m_firstGlyph = fontNode->valueAt("first-glyph", 32);
m_glyphSpacing = fontNode->valueAt("spacing", Size(0,0)); m_glyphSpacing = fontNode->valueAt("spacing", Size(0, 0));
int spaceWidth = fontNode->valueAt("space-width", glyphSize.width()); int spaceWidth = fontNode->valueAt("space-width", glyphSize.width());
// load font texture // load font texture
m_texture = g_textures.getTexture(textureFile); m_texture = g_textures.getTexture(textureFile);
Size textureSize = m_texture->getSize();
if(OTMLNodePtr node = fontNode->get("fixed-glyph-width")) { if(OTMLNodePtr node = fontNode->get("fixed-glyph-width")) {
for(int glyph = m_firstGlyph; glyph < 256; ++glyph) for(int glyph = m_firstGlyph; glyph < 256; ++glyph)
@@ -68,7 +77,7 @@ void BitmapFont::load(const OTMLNodePtr& fontNode)
// calculate glyphs texture coords // calculate glyphs texture coords
int numHorizontalGlyphs = m_texture->getSize().width() / glyphSize.width(); int numHorizontalGlyphs = textureSize.width() / glyphSize.width();
for(int glyph = m_firstGlyph; glyph < 256; ++glyph) { for(int glyph = m_firstGlyph; glyph < 256; ++glyph) {
m_glyphsTextureCoords[glyph].setRect(((glyph - m_firstGlyph) % numHorizontalGlyphs) * glyphSize.width(), m_glyphsTextureCoords[glyph].setRect(((glyph - m_firstGlyph) % numHorizontalGlyphs) * glyphSize.width(),
((glyph - m_firstGlyph) / numHorizontalGlyphs) * glyphSize.height(), ((glyph - m_firstGlyph) / numHorizontalGlyphs) * glyphSize.height(),
@@ -86,11 +95,9 @@ void BitmapFont::drawText(const std::string& text, const Point& startPos)
void BitmapFont::drawText(const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align) void BitmapFont::drawText(const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
{ {
static CoordsBuffer coordsBuffer; s_coordsBuffer.clear();
coordsBuffer.clear(); calculateDrawTextCoords(s_coordsBuffer, text, screenCoords, align);
g_painter->drawTextureCoords(s_coordsBuffer, m_texture);
calculateDrawTextCoords(coordsBuffer, text, screenCoords, align);
g_painter->drawTextureCoords(coordsBuffer, m_texture);
} }
void BitmapFont::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align) void BitmapFont::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
@@ -103,7 +110,7 @@ void BitmapFont::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::
// map glyphs positions // map glyphs positions
Size textBoxSize; Size textBoxSize;
const std::vector<Point>& glyphsPositions = calculateGlyphsPositions(text, align, &textBoxSize); const auto& glyphsPositions = calculateGlyphsPositions(text, align, &textBoxSize);
for(int i = 0; i < textLenght; ++i) { for(int i = 0; i < textLenght; ++i) {
int glyph = (uchar)text[i]; int glyph = (uchar)text[i];
@@ -171,52 +178,49 @@ void BitmapFont::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::
const std::vector<Point>& BitmapFont::calculateGlyphsPositions(const std::string& text, const std::vector<Point>& BitmapFont::calculateGlyphsPositions(const std::string& text,
Fw::AlignmentFlag align, Fw::AlignmentFlag align,
Size *textBoxSize) Size* textBoxSize)
{ {
// for performance reasons we use statics vectors that are allocated on demand
static std::vector<Point> glyphsPositions(1);
static std::vector<int> lineWidths(1);
int textLength = text.length(); int textLength = text.length();
int maxLineWidth = 0; int maxLineWidth = 0;
int lines = 0; int lines = 0;
int glyph; int glyph;
int i;
// return if there is no text // return if there is no text
if(textLength == 0) { if(textLength == 0) {
if(textBoxSize) if(textBoxSize)
textBoxSize->resize(0,m_glyphHeight); textBoxSize->resize(0, m_glyphHeight);
return glyphsPositions; return s_glyphsPositions;
} }
// resize glyphsPositions vector when needed // resize s_glyphsPositions vector when needed
if(textLength > (int)glyphsPositions.size()) if(textLength > (int)s_glyphsPositions.size())
glyphsPositions.resize(textLength); s_glyphsPositions.resize(textLength);
// calculate lines width // calculate lines width
if((align & Fw::AlignRight || align & Fw::AlignHorizontalCenter) || textBoxSize) { if((align & Fw::AlignRight || align & Fw::AlignHorizontalCenter) || textBoxSize) {
lineWidths[0] = 0; s_lineWidths[0] = 0;
for(i = 0; i< textLength; ++i) { for(int i = 0; i < textLength; ++i) {
glyph = (uchar)text[i]; glyph = (uchar)text[i];
if(glyph == (uchar)'\n') { if(glyph == (uchar)'\n') {
lines++; lines++;
if(lines+1 > (int)lineWidths.size()) // resize s_lineWidths vector when needed
lineWidths.resize(lines+1); if(lines+1 > (int)s_lineWidths.size())
lineWidths[lines] = 0; s_lineWidths.resize(lines+1);
s_lineWidths[lines] = 0;
} else if(glyph >= 32) { } else if(glyph >= 32) {
lineWidths[lines] += m_glyphsSize[glyph].width() ; s_lineWidths[lines] += m_glyphsSize[glyph].width();
if((i+1 != textLength && text[i+1] != '\n')) // only add space if letter is not the last or before a \n. // only add space if letter is not the last or before a \n
lineWidths[lines] += m_glyphSpacing.width(); if((i+1 != textLength && text[i+1] != '\n'))
maxLineWidth = std::max<int>(maxLineWidth, lineWidths[lines]); s_lineWidths[lines] += m_glyphSpacing.width();
maxLineWidth = std::max<int>(maxLineWidth, s_lineWidths[lines]);
} }
} }
} }
Point virtualPos(0, m_yOffset); Point virtualPos(0, m_yOffset);
lines = 0; lines = 0;
for(i = 0; i < textLength; ++i) { for(int i = 0; i < textLength; ++i) {
glyph = (uchar)text[i]; glyph = (uchar)text[i];
// new line or first glyph // new line or first glyph
@@ -228,16 +232,16 @@ const std::vector<Point>& BitmapFont::calculateGlyphsPositions(const std::string
// calculate start x pos // calculate start x pos
if(align & Fw::AlignRight) { if(align & Fw::AlignRight) {
virtualPos.x = (maxLineWidth - lineWidths[lines]); virtualPos.x = (maxLineWidth - s_lineWidths[lines]);
} else if(align & Fw::AlignHorizontalCenter) { } else if(align & Fw::AlignHorizontalCenter) {
virtualPos.x = (maxLineWidth - lineWidths[lines]) / 2; virtualPos.x = (maxLineWidth - s_lineWidths[lines]) / 2;
} else { // AlignLeft } else { // AlignLeft
virtualPos.x = 0; virtualPos.x = 0;
} }
} }
// store current glyph topLeft // store current glyph topLeft
glyphsPositions[i] = virtualPos; s_glyphsPositions[i] = virtualPos;
// render only if the glyph is valid // render only if the glyph is valid
if(glyph >= 32 && glyph != (uchar)'\n') { if(glyph >= 32 && glyph != (uchar)'\n') {
@@ -250,7 +254,7 @@ const std::vector<Point>& BitmapFont::calculateGlyphsPositions(const std::string
textBoxSize->setHeight(virtualPos.y + m_glyphHeight); textBoxSize->setHeight(virtualPos.y + m_glyphHeight);
} }
return glyphsPositions; return s_glyphsPositions;
} }
Size BitmapFont::calculateTextRectSize(const std::string& text) Size BitmapFont::calculateTextRectSize(const std::string& text)
@@ -265,11 +269,12 @@ void BitmapFont::calculateGlyphsWidthsAutomatically(const ImagePtr& image, const
if(!image) if(!image)
return; return;
int numHorizontalGlyphs = image->getSize().width() / glyphSize.width(); Size imageSize = image->getSize();
auto texturePixels = image->getPixels(); int numHorizontalGlyphs = imageSize.width() / glyphSize.width();
const auto& texturePixels = image->getPixels();
// small AI to auto calculate pixels widths // small AI to auto calculate pixels widths
for(int glyph = m_firstGlyph; glyph< 256; ++glyph) { for(int glyph = m_firstGlyph; glyph < 256; ++glyph) {
Rect glyphCoords(((glyph - m_firstGlyph) % numHorizontalGlyphs) * glyphSize.width(), Rect glyphCoords(((glyph - m_firstGlyph) % numHorizontalGlyphs) * glyphSize.width(),
((glyph - m_firstGlyph) / numHorizontalGlyphs) * glyphSize.height(), ((glyph - m_firstGlyph) / numHorizontalGlyphs) * glyphSize.height(),
glyphSize.width(), glyphSize.width(),
@@ -279,7 +284,7 @@ void BitmapFont::calculateGlyphsWidthsAutomatically(const ImagePtr& image, const
int filledPixels = 0; int filledPixels = 0;
// check if all vertical pixels are alpha // check if all vertical pixels are alpha
for(int y = glyphCoords.top(); y <= glyphCoords.bottom(); ++y) { for(int y = glyphCoords.top(); y <= glyphCoords.bottom(); ++y) {
if(texturePixels[(y * image->getSize().width() * 4) + (x*4) + 3] != 0) if(texturePixels[(y * imageSize.width() * 4) + (x*4) + 3] != 0)
filledPixels++; filledPixels++;
} }
if(filledPixels > 0) if(filledPixels > 0)
@@ -293,51 +298,54 @@ void BitmapFont::calculateGlyphsWidthsAutomatically(const ImagePtr& image, const
std::string BitmapFont::wrapText(const std::string& text, int maxWidth) std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
{ {
std::string outText; std::string outText;
std::string line;
std::vector<std::string> words; std::vector<std::string> words;
std::vector<std::string> wordsSplit = stdext::split(text); std::vector<std::string> wordsSplit = stdext::split(text);
// break huge words into small ones // break huge words into small ones
for(const auto &word: wordsSplit) { for(const auto& word: wordsSplit) {
int wordWidth = calculateTextRectSize(word).width(); int wordWidth = calculateTextRectSize(word).width();
if(wordWidth > maxWidth) { if(wordWidth > maxWidth) {
std::string newWord; std::string newWord;
for(uint j=0;j<word.length();++j) { for(uint j = 0; j < word.length(); ++j) {
std::string candidate = newWord + word[j]; std::string candidate = newWord + word[j];
if(j != word.length() - 1) if(j != word.length() - 1)
candidate += "-"; candidate += '-';
int candidateWidth = calculateTextRectSize(candidate).width(); int candidateWidth = calculateTextRectSize(candidate).width();
if(candidateWidth > maxWidth) { if(candidateWidth > maxWidth) {
newWord += "-"; newWord += '-';
words.push_back(newWord); words.push_back(newWord);
newWord = ""; newWord.clear();
} }
newWord += word[j]; newWord += word[j];
} }
words.push_back(newWord); words.push_back(newWord);
} else } else {
words.push_back(word); words.push_back(word);
} }
}
// compose lines // compose lines
for(const auto &word: words) { std::string line(words[0]);
std::string candidate = line + word; for(ulong i = 1; i < words.size(); ++i)
int candidateWidth = calculateTextRectSize(candidate).width(); {
const auto& word = words[i];
if(candidateWidth > maxWidth) { line.push_back(' ');
if(!line.empty()) ulong lineSize = line.size();
outText += line.substr(0, line.length()-1) + "\n"; line.append(word);
line = "";
if(calculateTextRectSize(line).width() > maxWidth)
{
line.resize(lineSize);
line.back() = '\n';
outText.append(line);
line.assign(word);
} }
line += word + " ";
} }
outText.append(line);
outText += line;
outText = outText.substr(0, outText.length()-1);
return outText; return outText;
} }

View File

@@ -55,7 +55,7 @@ public:
std::string wrapText(const std::string& text, int maxWidth); std::string wrapText(const std::string& text, int maxWidth);
std::string getName() { return m_name; } const std::string& getName() { return m_name; }
int getGlyphHeight() { return m_glyphHeight; } int getGlyphHeight() { return m_glyphHeight; }
const Rect* getGlyphsTextureCoords() { return m_glyphsTextureCoords; } const Rect* getGlyphsTextureCoords() { return m_glyphsTextureCoords; }
const Size* getGlyphsSize() { return m_glyphsSize; } const Size* getGlyphsSize() { return m_glyphsSize; }
@@ -79,4 +79,3 @@ private:
#endif #endif

View File

@@ -77,7 +77,7 @@ void GravityAffector::load(const OTMLNodePtr& node)
ParticleAffector::load(node); ParticleAffector::load(node);
m_angle = 270 * DEG_TO_RAD; m_angle = 270 * DEG_TO_RAD;
m_gravity = 9.8; m_gravity = 9.8f;
for(const OTMLNodePtr& childNode : node->children()) { for(const OTMLNodePtr& childNode : node->children()) {
if(childNode->tag() == "angle") if(childNode->tag() == "angle")
@@ -132,5 +132,5 @@ void AttractionAffector::updateParticle(const ParticlePtr& particle, float elaps
direction = PointF(-1, -1); direction = PointF(-1, -1);
PointF pVelocity = particle->getVelocity() + (d / d.length() * m_acceleration * elapsedTime) * direction; PointF pVelocity = particle->getVelocity() + (d / d.length() * m_acceleration * elapsedTime) * direction;
particle->setVelocity(pVelocity - pVelocity * m_reduction/100.0 * elapsedTime); particle->setVelocity(pVelocity - pVelocity * m_reduction/100.f * elapsedTime);
} }

View File

@@ -144,29 +144,35 @@ void Protocol::internalRecvData(uint8* buffer, uint16 size)
void Protocol::generateXteaKey() void Protocol::generateXteaKey()
{ {
std::mt19937 eng(std::time(nullptr)); std::random_device rd;
std::uniform_int_distribution<uint32> unif(0, 0xFFFFFFFF); std::uniform_int_distribution<uint32> unif;
m_xteaKey[0] = unif(eng); std::generate(m_xteaKey.begin(), m_xteaKey.end(), [&]() { return unif(rd); });
m_xteaKey[1] = unif(eng);
m_xteaKey[2] = unif(eng);
m_xteaKey[3] = unif(eng);
} }
void Protocol::setXteaKey(uint32 a, uint32 b, uint32 c, uint32 d) namespace {
constexpr uint32_t delta = 0x9E3779B9;
template<typename Round>
void apply_rounds(uint8_t* data, size_t length, Round round)
{ {
m_xteaKey[0] = a; for (auto j = 0u; j < length; j += 8) {
m_xteaKey[1] = b; uint32_t left = data[j+0] | data[j+1] << 8u | data[j+2] << 16u | data[j+3] << 24u,
m_xteaKey[2] = c; right = data[j+4] | data[j+5] << 8u | data[j+6] << 16u | data[j+7] << 24u;
m_xteaKey[3] = d;
round(left, right);
data[j] = static_cast<uint8_t>(left);
data[j+1] = static_cast<uint8_t>(left >> 8u);
data[j+2] = static_cast<uint8_t>(left >> 16u);
data[j+3] = static_cast<uint8_t>(left >> 24u);
data[j+4] = static_cast<uint8_t>(right);
data[j+5] = static_cast<uint8_t>(right >> 8u);
data[j+6] = static_cast<uint8_t>(right >> 16u);
data[j+7] = static_cast<uint8_t>(right >> 24u);
}
} }
std::vector<uint32> Protocol::getXteaKey()
{
std::vector<uint32> xteaKey;
xteaKey.resize(4);
for(int i = 0; i < 4; ++i)
xteaKey[i] = m_xteaKey[i];
return xteaKey;
} }
bool Protocol::xteaDecrypt(const InputMessagePtr& inputMessage) bool Protocol::xteaDecrypt(const InputMessagePtr& inputMessage)
@@ -177,22 +183,12 @@ bool Protocol::xteaDecrypt(const InputMessagePtr& inputMessage)
return false; return false;
} }
uint32 *buffer = (uint32*)(inputMessage->getReadBuffer()); for (uint32_t i = 0, sum = delta << 5, next_sum = sum - delta; i < 32; ++i, sum = next_sum, next_sum -= delta) {
int readPos = 0; apply_rounds(inputMessage->getReadBuffer(), encryptedSize, [&](uint32_t& left, uint32_t& right) {
right -= ((left << 4 ^ left >> 5) + left) ^ (sum + m_xteaKey[(sum >> 11) & 3]);
while(readPos < encryptedSize/4) { left -= ((right << 4 ^ right >> 5) + right) ^ (next_sum + m_xteaKey[next_sum & 3]);
uint32 v0 = buffer[readPos], v1 = buffer[readPos + 1]; });
uint32 delta = 0x61C88647; };
uint32 sum = 0xC6EF3720;
for(int32 i = 0; i < 32; i++) {
v1 -= ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + m_xteaKey[sum>>11 & 3]);
sum += delta;
v0 -= ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + m_xteaKey[sum & 3]);
}
buffer[readPos] = v0; buffer[readPos + 1] = v1;
readPos = readPos + 2;
}
uint16 decryptedSize = inputMessage->getU16() + 2; uint16 decryptedSize = inputMessage->getU16() + 2;
int sizeDelta = decryptedSize - encryptedSize; int sizeDelta = decryptedSize - encryptedSize;
@@ -217,21 +213,12 @@ void Protocol::xteaEncrypt(const OutputMessagePtr& outputMessage)
encryptedSize += n; encryptedSize += n;
} }
int readPos = 0; for (uint32_t i = 0, sum = 0, next_sum = sum + delta; i < 32; ++i, sum = next_sum, next_sum += delta) {
uint32 *buffer = (uint32*)(outputMessage->getDataBuffer() - 2); apply_rounds(outputMessage->getDataBuffer() - 2, encryptedSize, [&](uint32_t& left, uint32_t& right) {
while(readPos < encryptedSize / 4) { left += ((right << 4 ^ right >> 5) + right) ^ (sum + m_xteaKey[sum & 3]);
uint32 v0 = buffer[readPos], v1 = buffer[readPos + 1]; right += ((left << 4 ^ left >> 5) + left) ^ (next_sum + m_xteaKey[(next_sum >> 11) & 3]);
uint32 delta = 0x61C88647; });
uint32 sum = 0; };
for(int32 i = 0; i < 32; i++) {
v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + m_xteaKey[sum & 3]);
sum -= delta;
v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + m_xteaKey[sum>>11 & 3]);
}
buffer[readPos] = v0; buffer[readPos + 1] = v1;
readPos = readPos + 2;
}
} }
void Protocol::onConnect() void Protocol::onConnect()

View File

@@ -48,8 +48,8 @@ public:
void setConnection(const ConnectionPtr& connection) { m_connection = connection; } void setConnection(const ConnectionPtr& connection) { m_connection = connection; }
void generateXteaKey(); void generateXteaKey();
void setXteaKey(uint32 a, uint32 b, uint32 c, uint32 d); void setXteaKey(uint32 a, uint32 b, uint32 c, uint32 d) { m_xteaKey = {a, b, c, d}; }
std::vector<uint32> getXteaKey(); std::vector<uint32> getXteaKey() { return {m_xteaKey.begin(), m_xteaKey.end()}; }
void enableXteaEncryption() { m_xteaEncryptionEnabled = true; } void enableXteaEncryption() { m_xteaEncryptionEnabled = true; }
void enableChecksum() { m_checksumEnabled = true; } void enableChecksum() { m_checksumEnabled = true; }
@@ -64,7 +64,7 @@ protected:
virtual void onRecv(const InputMessagePtr& inputMessage); virtual void onRecv(const InputMessagePtr& inputMessage);
virtual void onError(const boost::system::error_code& err); virtual void onError(const boost::system::error_code& err);
uint32 m_xteaKey[4]; std::array<uint32, 4> m_xteaKey;
private: private:
void internalRecvHeader(uint8* buffer, uint16 size); void internalRecvHeader(uint8* buffer, uint16 size);

View File

@@ -130,12 +130,13 @@ std::string Platform::getCPUName()
std::ifstream in("/proc/cpuinfo"); std::ifstream in("/proc/cpuinfo");
while(getline(in, line)) { while(getline(in, line)) {
auto strs = stdext::split(line, ":"); auto strs = stdext::split(line, ":");
std::string first = strs[0]; if(strs.size() == 2) {
std::string second = strs[1]; stdext::trim(strs[0]);
stdext::trim(first); if(strs[0] == "model name") {
stdext::trim(second); stdext::trim(strs[1]);
if(strs.size() == 2 && first == "model name") return strs[1];
return second; }
}
} }
return std::string(); return std::string();
} }
@@ -146,12 +147,13 @@ double Platform::getTotalSystemMemory()
std::ifstream in("/proc/meminfo"); std::ifstream in("/proc/meminfo");
while(getline(in, line)) { while(getline(in, line)) {
auto strs = stdext::split(line, ":"); auto strs = stdext::split(line, ":");
std::string first = strs[0]; if(strs.size() == 2) {
std::string second = strs[1]; stdext::trim(strs[0]);
stdext::trim(first); if(strs[0] == "MemTotal") {
stdext::trim(second); stdext::trim(strs[1]);
if(strs.size() == 2 && first == "MemTotal") return stdext::unsafe_cast<double>(strs[1].substr(0, strs[1].length() - 3)) * 1000;
return stdext::unsafe_cast<double>(second.substr(0, second.length() - 3)) * 1000.0; }
}
} }
return 0; return 0;
} }
@@ -161,8 +163,7 @@ std::string Platform::getOSName()
std::string line; std::string line;
std::ifstream in("/etc/issue"); std::ifstream in("/etc/issue");
if(getline(in, line)) { if(getline(in, line)) {
std::size_t end = line.find('\\'); auto res = line.substr(0, line.find('\\'));
std::string res = line.substr(0, end);
stdext::trim(res); stdext::trim(res);
return res; return res;
} }

View File

@@ -852,10 +852,19 @@ void WIN32Window::setFullscreen(bool fullscreen)
wpPrev.length = sizeof(wpPrev); wpPrev.length = sizeof(wpPrev);
if(fullscreen) { if(fullscreen) {
Size size = getDisplaySize(); MONITORINFO mi;
HMONITOR m = MonitorFromWindow(m_window, MONITOR_DEFAULTTONEAREST);
mi.cbSize = sizeof(mi);
GetMonitorInfoW(m, &mi);
uint x = mi.rcMonitor.left;
uint y = mi.rcMonitor.top;
uint width = mi.rcMonitor.right - mi.rcMonitor.left;
uint height = mi.rcMonitor.bottom - mi.rcMonitor.top;
GetWindowPlacement(m_window, &wpPrev); GetWindowPlacement(m_window, &wpPrev);
SetWindowLong(m_window, GWL_STYLE, (dwStyle & ~WS_OVERLAPPEDWINDOW) | WS_POPUP | WS_EX_TOPMOST); SetWindowLong(m_window, GWL_STYLE, (dwStyle & ~WS_OVERLAPPEDWINDOW) | WS_POPUP | WS_EX_TOPMOST);
SetWindowPos(m_window, HWND_TOPMOST, 0, 0, size.width(), size.height(), SWP_FRAMECHANGED); SetWindowPos(m_window, HWND_TOPMOST, x, y, width, height, SWP_FRAMECHANGED);
} else { } else {
SetWindowLong(m_window, GWL_STYLE, (dwStyle & ~(WS_POPUP | WS_EX_TOPMOST)) | WS_OVERLAPPEDWINDOW); SetWindowLong(m_window, GWL_STYLE, (dwStyle & ~(WS_POPUP | WS_EX_TOPMOST)) | WS_OVERLAPPEDWINDOW);
SetWindowPlacement(m_window, &wpPrev); SetWindowPlacement(m_window, &wpPrev);

View File

@@ -27,8 +27,13 @@
#define AL_LIBTYPE_STATIC #define AL_LIBTYPE_STATIC
#if defined(__APPLE__)
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#else
#include <AL/al.h> #include <AL/al.h>
#include <AL/alc.h> #include <AL/alc.h>
#endif
class SoundManager; class SoundManager;
class SoundSource; class SoundSource;

View File

@@ -1,161 +0,0 @@
/*
* Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef STDEXT_PACKEDVECTOR_H
#define STDEXT_PACKEDVECTOR_H
#include <algorithm>
namespace stdext {
// disable memory alignment
#pragma pack(push,1)
template<class T, class U = uint8_t>
class packed_vector
{
public:
typedef U size_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
packed_vector() : m_size(0), m_data(nullptr) { }
packed_vector(size_type size) : m_size(size), m_data(new T[size]) { }
packed_vector(size_type size, const T& value) : m_size(size), m_data(new T[size]) { std::fill(begin(), end(), value); }
template <class InputIterator>
packed_vector(InputIterator first, InputIterator last) : m_size(last - first), m_data(new T[m_size]) { std::copy(first, last, m_data); }
packed_vector(const packed_vector<T>& other) : m_size(other.m_size), m_data(new T[other.m_size]) { std::copy(other.begin(), other.end(), m_data); }
~packed_vector() { delete[] m_data; }
packed_vector<T,U>& operator=(packed_vector<T,U> other) { other.swap(*this); return *this; }
iterator begin() { return m_data; }
const_iterator begin() const { return m_data; }
const_iterator cbegin() const { return m_data; }
iterator end() { return m_data + m_size; }
const_iterator end() const { return m_data + m_size; }
const_iterator cend() const { return m_data + m_size; }
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); }
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
const_reverse_iterator crend() const { return const_reverse_iterator(begin()); }
size_type size() const { return m_size; }
bool empty() const { return m_size == 0; }
T& operator[](size_type i) { return m_data[i]; }
const T& operator[](size_type i) const { return m_data[i]; }
T& at(size_type i) { return m_data[i]; }
const T& at(size_type i) const { return m_data[i]; }
T& front() { return m_data[0]; }
const T& front() const { return m_data[0]; }
T& back() { return m_data[m_size-1]; }
const T& back() const { return m_data[m_size-1]; }
T *data() { return m_data; }
const T *data() const { return m_data; }
void clear() {
if(m_data) {
delete[] m_data;
m_data = nullptr;
}
m_size = 0;
}
void resize(size_type size) {
clear();
if(size > 0) {
m_data = new T[size];
m_size = size;
}
}
void push_back(const T& x) {
T *tmp = new T[m_size+1];
std::copy(m_data, m_data + m_size, tmp);
tmp[m_size] = x;
delete[] m_data;
m_data = tmp;
m_size++;
}
void pop_back() {
if(m_size == 1) {
clear();
return;
}
T *tmp = new T[m_size-1];
std::copy(m_data, m_data + m_size - 1, tmp);
delete[] m_data;
m_data = tmp;
m_size--;
}
iterator insert(const_iterator position, const T& x) {
T *tmp = new T[m_size+1];
size_type i = position - m_data;
std::copy(m_data, m_data + i, tmp);
tmp[i] = x;
std::copy(m_data + i, m_data + m_size, tmp + i + 1);
delete[] m_data;
m_data = tmp;
m_size++;
return tmp + i;
}
iterator erase(const_iterator position) {
T *tmp = new T[m_size-1];
size_type i = position - m_data;
std::copy(m_data, m_data + i, tmp);
std::copy(m_data + i + 1, m_data + m_size, tmp + i);
delete[] m_data;
m_data = tmp;
m_size--;
return tmp + i;
}
void swap(packed_vector<T,U>& other) { std::swap(m_size, other.m_size); std::swap(m_data, other.m_data); }
operator std::vector<T>() const { return std::vector<T>(begin(), end()); }
private:
size_type m_size;
T* m_data;
};
// restore memory alignment
#pragma pack(pop)
}
namespace std {
template<class T, class U> void swap(stdext::packed_vector<T,U>& lhs, stdext::packed_vector<T,U>& rhs) { lhs.swap(rhs); }
}
#endif

View File

@@ -35,7 +35,6 @@
#include "math.h" #include "math.h"
#include "packed_any.h" #include "packed_any.h"
#include "packed_storage.h" #include "packed_storage.h"
#include "packed_vector.h"
#include "shared_object.h" #include "shared_object.h"
#include "string.h" #include "string.h"
#include "time.h" #include "time.h"

View File

@@ -45,23 +45,21 @@ std::string resolve_path(const std::string& filePath, std::string sourcePath)
return sourcePath + filePath; return sourcePath + filePath;
} }
std::string date_time_string() std::string date_time_string(const char* format/* = "%b %d %Y %H:%M:%S"*/)
{ {
char date[32]; char date[100];
std::time_t tnow; std::time_t tnow;
std::time(&tnow); std::time(&tnow);
std::tm *ts = std::localtime(&tnow); std::tm* ts = std::localtime(&tnow);
std::strftime(date, 32, "%b %d %Y %H:%M:%S", ts); std::strftime(date, 100, format, ts);
return std::string(date); return std::string(date);
} }
std::string dec_to_hex(uint64_t num) std::string dec_to_hex(uint64_t num)
{ {
std::string str;
std::ostringstream o; std::ostringstream o;
o << std::hex << num; o << std::hex << num;
str = o.str(); return o.str();
return str;
} }
uint64_t hex_to_dec(const std::string& str) uint64_t hex_to_dec(const std::string& str)
@@ -74,7 +72,7 @@ uint64_t hex_to_dec(const std::string& str)
bool is_valid_utf8(const std::string& src) bool is_valid_utf8(const std::string& src)
{ {
const unsigned char *bytes = (const unsigned char *)src.c_str(); const unsigned char* bytes = (const unsigned char*)src.c_str();
while(*bytes) { while(*bytes) {
if( (// ASCII if( (// ASCII
// use bytes[0] <= 0x7F to allow ASCII control characters // use bytes[0] <= 0x7F to allow ASCII control characters
@@ -146,7 +144,7 @@ bool is_valid_utf8(const std::string& src)
std::string utf8_to_latin1(const std::string& src) std::string utf8_to_latin1(const std::string& src)
{ {
std::string out; std::string out;
for(uint i=0;i<src.length();) { for(uint i = 0; i < src.length();) {
uchar c = src[i++]; uchar c = src[i++];
if((c >= 32 && c < 128) || c == 0x0d || c == 0x0a || c == 0x09) if((c >= 32 && c < 128) || c == 0x0d || c == 0x0a || c == 0x09)
out += c; out += c;
@@ -273,7 +271,7 @@ void replace_all(std::string& str, const std::string& search, const std::string&
std::vector<std::string> split(const std::string& str, const std::string& separators) std::vector<std::string> split(const std::string& str, const std::string& separators)
{ {
std::vector<std::string> splitted; std::vector<std::string> splitted;
boost::split(splitted, str, boost::is_any_of(std::string(separators))); boost::split(splitted, str, boost::is_any_of(separators));
return splitted; return splitted;
} }

View File

@@ -38,7 +38,7 @@ template<typename T> T from_string(const std::string& str, T def = T()) { return
/// Resolve a file path by combining sourcePath with filePath /// Resolve a file path by combining sourcePath with filePath
std::string resolve_path(const std::string& filePath, std::string sourcePath); std::string resolve_path(const std::string& filePath, std::string sourcePath);
/// Get current date and time in a std::string /// Get current date and time in a std::string
std::string date_time_string(); std::string date_time_string(const char* format = "%b %d %Y %H:%M:%S");
std::string dec_to_hex(uint64_t num); std::string dec_to_hex(uint64_t num);
uint64_t hex_to_dec(const std::string& str); uint64_t hex_to_dec(const std::string& str);
@@ -63,11 +63,12 @@ std::string utf16_to_latin1(const std::wstring& src);
std::wstring latin1_to_utf16(const std::string& src); std::wstring latin1_to_utf16(const std::string& src);
#endif #endif
// always returns at least one element in vector
std::vector<std::string> split(const std::string& str, const std::string& separators = " "); std::vector<std::string> split(const std::string& str, const std::string& separators = " ");
template<typename T> std::vector<T> split(const std::string& str, const std::string& separators = " ") { template<typename T> std::vector<T> split(const std::string& str, const std::string& separators = " ") {
std::vector<std::string> splitted = split(str, separators); std::vector<std::string> splitted = split(str, separators);
std::vector<T> results(splitted.size()); std::vector<T> results(splitted.size());
for(uint i=0;i<splitted.size();++i) for(uint i = 0; i < splitted.size(); ++i)
results[i] = safe_cast<T>(splitted[i]); results[i] = safe_cast<T>(splitted[i]);
return results; return results;
} }

View File

@@ -36,8 +36,8 @@ void microsleep(size_t us);
struct timer { struct timer {
public: public:
timer() { restart(); } timer() { restart(); }
float elapsed_seconds() { return (float)((stdext::micros() - m_start)/1000000.0); } float elapsed_seconds() { return (stdext::micros() - m_start) / 1000000.f; }
ticks_t elapsed_millis() { return (stdext::micros() - m_start)/1000; } ticks_t elapsed_millis() { return (stdext::micros() - m_start) / 1000; }
ticks_t elapsed_micros() { return stdext::micros() - m_start; } ticks_t elapsed_micros() { return stdext::micros() - m_start; }
void restart() { m_start = stdext::micros(); } void restart() { m_start = stdext::micros(); }
private: private:
@@ -47,4 +47,3 @@ private:
} }
#endif #endif

View File

@@ -142,9 +142,9 @@ void UITextEdit::update(bool focusCursor)
// map glyphs positions // map glyphs positions
Size textBoxSize; Size textBoxSize;
const std::vector<Point>& glyphsPositions = m_font->calculateGlyphsPositions(text, m_textAlign, &textBoxSize); const auto& glyphsPositions = m_font->calculateGlyphsPositions(text, m_textAlign, &textBoxSize);
const Rect *glyphsTextureCoords = m_font->getGlyphsTextureCoords(); const Rect* glyphsTextureCoords = m_font->getGlyphsTextureCoords();
const Size *glyphsSize = m_font->getGlyphsSize(); const Size* glyphsSize = m_font->getGlyphsSize();
int glyph; int glyph;
// update rect size // update rect size
@@ -369,7 +369,7 @@ void UITextEdit::setSelection(int start, int end)
void UITextEdit::setTextHidden(bool hidden) void UITextEdit::setTextHidden(bool hidden)
{ {
m_textHidden = true; m_textHidden = hidden;
update(true); update(true);
} }

View File

@@ -42,7 +42,7 @@ public:
void setCursorVisible(bool enable) { m_cursorVisible = enable; } void setCursorVisible(bool enable) { m_cursorVisible = enable; }
void setChangeCursorImage(bool enable) { m_changeCursorImage = enable; } void setChangeCursorImage(bool enable) { m_changeCursorImage = enable; }
void setTextHidden(bool hidden); void setTextHidden(bool hidden);
void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; } void setValidCharacters(const std::string& validCharacters) { m_validCharacters = validCharacters; }
void setShiftNavigation(bool enable) { m_shiftNavigation = enable; } void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }
void setMultiline(bool enable) { m_multiline = enable; } void setMultiline(bool enable) { m_multiline = enable; }
void setMaxLength(uint maxLength) { m_maxLength = maxLength; } void setMaxLength(uint maxLength) { m_maxLength = maxLength; }

View File

@@ -77,7 +77,7 @@ public:
T manhattanLength() const { return std::abs(x) + std::abs(y); } T manhattanLength() const { return std::abs(x) + std::abs(y); }
float distanceFrom(const TPoint<T>& other) const { float distanceFrom(const TPoint<T>& other) const {
return TPoint<T>(x - other.x, y - other.y).getLength(); return TPoint<T>(x - other.x, y - other.y).length();
} }
T x, y; T x, y;

View File

@@ -89,7 +89,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet> <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<AdditionalIncludeDirectories>$(VcpkgRoot)include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(VcpkgInstalledDir)$(VcpkgTriplet)\include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<TargetMachine>MachineX86</TargetMachine> <TargetMachine>MachineX86</TargetMachine>
@@ -101,7 +101,7 @@
<PreprocessorDefinitions>$(PREPROCESSOR_DEFS);_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>$(PREPROCESSOR_DEFS);_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet> <EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
<AdditionalIncludeDirectories>$(VcpkgRoot)include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(VcpkgInstalledDir)$(VcpkgTriplet)\include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@@ -115,7 +115,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations> <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<AdditionalIncludeDirectories>$(VcpkgRoot)include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(VcpkgInstalledDir)$(VcpkgTriplet)\include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<TargetMachine>MachineX86</TargetMachine> <TargetMachine>MachineX86</TargetMachine>
@@ -134,7 +134,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations> <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<AdditionalIncludeDirectories>$(VcpkgRoot)include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(VcpkgInstalledDir)$(VcpkgTriplet)\include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@@ -436,7 +436,6 @@
<ClInclude Include="..\src\framework\stdext\net.h" /> <ClInclude Include="..\src\framework\stdext\net.h" />
<ClInclude Include="..\src\framework\stdext\packed_any.h" /> <ClInclude Include="..\src\framework\stdext\packed_any.h" />
<ClInclude Include="..\src\framework\stdext\packed_storage.h" /> <ClInclude Include="..\src\framework\stdext\packed_storage.h" />
<ClInclude Include="..\src\framework\stdext\packed_vector.h" />
<ClInclude Include="..\src\framework\stdext\shared_object.h" /> <ClInclude Include="..\src\framework\stdext\shared_object.h" />
<ClInclude Include="..\src\framework\stdext\shared_ptr.h" /> <ClInclude Include="..\src\framework\stdext\shared_ptr.h" />
<ClInclude Include="..\src\framework\stdext\stdext.h" /> <ClInclude Include="..\src\framework\stdext\stdext.h" />

View File

@@ -833,9 +833,6 @@
<ClInclude Include="..\src\framework\stdext\packed_storage.h"> <ClInclude Include="..\src\framework\stdext\packed_storage.h">
<Filter>Header Files\framework\stdext</Filter> <Filter>Header Files\framework\stdext</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\framework\stdext\packed_vector.h">
<Filter>Header Files\framework\stdext</Filter>
</ClInclude>
<ClInclude Include="..\src\framework\stdext\shared_object.h"> <ClInclude Include="..\src\framework\stdext\shared_object.h">
<Filter>Header Files\framework\stdext</Filter> <Filter>Header Files\framework\stdext</Filter>
</ClInclude> </ClInclude>