diff --git a/.dockerignore b/.dockerignore index 0c28964e..d33f6723 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,6 @@ -third_party/gfootball_engine/build +third_party/gfootball_engine/build*/ build/ gfootball.egg-info +football-env* +.vs +.idea diff --git a/.github/workflows/publish-wheels.yml b/.github/workflows/publish-wheels.yml new file mode 100644 index 00000000..1ed4d8d0 --- /dev/null +++ b/.github/workflows/publish-wheels.yml @@ -0,0 +1,111 @@ +name: Build and Publish Python Wheels + +on: + release: + types: [published] + +jobs: + build-windows: + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + python-version: [ 3.6, 3.7, 3.8, 3.9 ] + architecture: ['x86', 'x64'] + + env: + VCPKG_ROOT: "${{ github.workspace }}/vcpkg" + + steps: + - name: Check out football repository + uses: actions/checkout@v2 + with: + path: football + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + architecture: ${{ matrix.architecture }} + + - name: Upgrade pip and essential dependencies + run: | + python -m pip install --upgrade pip + pip install -U build setuptools psutil wheel + pip install -r requirements.txt + working-directory: football + + - name: Checkout vcpkg + uses: actions/checkout@v2 + with: + repository: microsoft/vcpkg + ref: 025e564979cc01d0fbc5c920aa8a36635efb01bb + path: vcpkg + fetch-depth: 0 + + # Uncomment to speed up building by caching C++ dependencies. Requires `python -m build --wheel` in the next step. +# - name: Restore vcpkg_installed cache +# uses: actions/cache@v2 +# with: +# path: ${{ github.workspace }}/football/third_party/gfootball_engine/build_win/vcpkg_installed +# key: vcpkg-${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.architecture }}-${{ hashFiles('football/third_party/gfootball_engine/vcpkg_manifests/py3*/vcpkg.json') }} + + - name: Build package + # `python -m build` without any arguments is used to check if the wheel can be built from source (sdist): + # the tool copies source code to the random temp directory, and proceeds with building. + # Doing so insures that MANIFEST.in contains all the required files to build engine from source. + # The downside is that we can't cache vcpkg_installed packages, since they'll be located in the random temp directory. + # It increases workflow running time from ~15 minutes to ~40 minutes. On the other hand, cache is valid only for 7 days, + # and releases are coming not so often anyway. + # To build in-place and take advantage of vcpkg_installed cache use `python -m build --wheel` instead. + run: python -m build + working-directory: football + + - name: Install the package using the wheel + run: python -m pip install temp-gfootball --no-index --find-links=dist + working-directory: football + + - name: Run the tests + run: FOR %%f IN (gfootball\env\*test.py) DO ( call python %%f & if errorlevel 1 exit /B 1 ) + env: + UNITTEST_IN_DOCKER: 1 + shell: cmd + working-directory: football + + - uses: actions/upload-artifact@v2 + with: + name: windows-wheel-py-${{ matrix.python-version }}-${{ matrix.architecture }} + path: ${{ github.workspace }}/football/dist/*.whl + retention-days: 7 + + upload-wheels: + needs: [build-windows] + runs-on: ubuntu-latest + steps: + - name: Check out football repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: python -m pip install --upgrade pip setuptools wheel psutil build + + - name: Build sdist + run: python -m build --sdist + + - name: Download artifacts + uses: actions/download-artifact@v2 + with: + path: ${{ github.workspace }}/artifacts + + - name: Move wheels to dist directory + run: mv artifacts/**/*.whl dist + + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.gitignore b/.gitignore index af16cc8d..00d6f83f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,18 @@ -third_party/gfootball_engine/build +third_party/gfootball_engine/build* build/ gfootball.egg-info __pycache__ *.a *.so *.dylib -CmakeCache.txt +C[M,m]akeCache.txt third_party/gfootball_engine/CMakeFiles/ third_party/gfootball_engine/Makefile third_party/gfootball_engine/cmake_install.cmake third_party/gfootball_engine/gameplayfootball footballenv/ -football-env/ +football-env*/ cmake-build-debug/ .idea .vs +vcpkg_installed/ diff --git a/CHANGELOG b/CHANGELOG index 9979f452..cebeb6b5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,10 @@ should not change, as modifications made to the environment are either new features or backward compatible bug fixes. We will maintain vX branches pointing at the most recent vX.Y. +v2.10 +- Windows support. +- Development mode (pip install -e .) + v2.9 - Drop hard dependency on Tensorflow. - Make installation easier, support for Ubuntu 20.04. diff --git a/Dockerfile b/Dockerfile index 1053d80d..65cbc043 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,10 @@ RUN apt-get update && apt-get --no-install-recommends install -yq git cmake buil libgl1-mesa-dev libsdl2-dev \ libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev libboost-all-dev \ libdirectfb-dev libst-dev mesa-utils xvfb x11vnc \ - libsdl-sge-dev python3-pip + python3-pip -RUN python3 -m pip install --upgrade pip setuptools psutil +RUN python3 -m pip install --upgrade pip setuptools wheel +RUN python3 -m pip install psutil COPY . /gfootball RUN cd /gfootball && python3 -m pip install . diff --git a/Dockerfile_examples b/Dockerfile_examples index faf7a2f9..06cc831d 100644 --- a/Dockerfile_examples +++ b/Dockerfile_examples @@ -7,9 +7,9 @@ RUN apt-get update && apt-get --no-install-recommends install -yq git cmake buil libgl1-mesa-dev libsdl2-dev \ libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev libboost-all-dev \ libdirectfb-dev libst-dev mesa-utils xvfb x11vnc \ - libsdl-sge-dev python3-pip + python3-pip -RUN python3 -m pip install --upgrade pip setuptools +RUN python3 -m pip install --upgrade pip setuptools wheel RUN pip3 install --no-cache-dir psutil dm-sonnet==1.* RUN pip list | grep 'tensorflow ' || pip3 install --no-cache-dir tensorflow==1.15.* diff --git a/MANIFEST.in b/MANIFEST.in index b897b2cf..f066a1bf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,16 @@ -include gfootball/build_game_engine.sh -recursive-include third_party/gfootball_engine/ * -recursive-include third_party/fonts/ * +include gfootball/build_game_engine.* +recursive-include gfootball/colabs * +recursive-include gfootball/doc * +recursive-include gfootball/eval_server/proto * +recursive-include gfootball/examples * + +include Dockerfile .dockerignore CHANGELOG CONTRIBUTING.md run_docker_test.sh + +recursive-include third_party/fonts * +recursive-include third_party/gfootball_engine * +recursive-exclude third_party/gfootball_engine *.a libgame.so cmake_install.cmake Makefile +prune third_party/gfootball_engine/CMakeFiles +prune third_party/gfootball_engine/cmake-build-debug +prune third_party/gfootball_engine/build* +prune third_party/gfootball_engine/.vs +prune third_party/gfootball_engine/.idea diff --git a/README.md b/README.md index 7072ae23..dde6060e 100644 --- a/README.md +++ b/README.md @@ -36,50 +36,63 @@ Instructions are available [here](gfootball/doc/docker.md). #### 1. Install required packages #### Linux -``` +```shell sudo apt-get install git cmake build-essential libgl1-mesa-dev libsdl2-dev \ libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev libboost-all-dev \ -libdirectfb-dev libst-dev mesa-utils xvfb x11vnc libsdl-sge-dev python3-pip +libdirectfb-dev libst-dev mesa-utils xvfb x11vnc python3-pip -python3 -m pip install --upgrade pip setuptools psutil +python3 -m pip install --upgrade pip setuptools psutil wheel ``` -#### Mac OS X +#### macOS First install [brew](https://brew.sh/). It should automatically install Command Line Tools. Next install required packages: -``` +```shell brew install git python3 cmake sdl2 sdl2_image sdl2_ttf sdl2_gfx boost boost-python3 + +python3 -m pip install --upgrade pip setuptools psutil wheel ``` -#### 2a. From PyPi package +#### Windows +Install [Git](https://git-scm.com/download/win) and [Python 3](https://www.python.org/downloads/). +Update pip in the Command Line (here and for the **next steps** type `python` instead of `python3`) +```commandline +python -m pip install --upgrade pip setuptools psutil wheel ``` + +#### 2. Install GFootball +#### 2a. From PyPi package +```shell python3 -m pip install gfootball ``` #### 2b. Installing from sources using GitHub repository -``` +```shell git clone https://github.com/google-research/football.git cd football ``` Optionally you can use [virtual environment](https://docs.python.org/3/tutorial/venv.html): -``` +```shell python3 -m venv football-env source football-env/bin/activate ``` -The last step is to build the environment: +Next, build the game engine and install dependencies: -``` +```shell python3 -m pip install . ``` This command can run for a couple of minutes, as it compiles the C++ environment in the background. +To compile the engine on Windows you have to install additional tools and set environment variables. See +[Compiling Engine](gfootball/doc/compile_engine.md#windows) for detailed instructions. + #### 3. Time to play! -``` +```shell python3 -m gfootball.play_game --action_set=full ``` Make sure to check out the [keyboard mappings](#keyboard-mappings). @@ -106,11 +119,11 @@ To quit the game press Ctrl+C in the terminal. ### Run training In order to run TF training, you need to install additional dependencies -- Update PIP, so that tensorflow 1.15 is available: `python3 -m pip install --upgrade pip setuptools` +- Update PIP, so that tensorflow 1.15 is available: `python3 -m pip install --upgrade pip setuptools wheel` - TensorFlow: `python3 -m pip install tensorflow==1.15.*` or `python3 -m pip install tensorflow-gpu==1.15.*`, depending on whether you want CPU or GPU version; -- Sonnet: `python3 -m pip install dm-sonnet==1.*`; +- Sonnet and psutil: `python3 -m pip install dm-sonnet==1.* psutil`; - OpenAI Baselines: `python3 -m pip install git+https://github.com/openai/baselines.git@master`. @@ -131,7 +144,8 @@ In order to reproduce PPO results from the paper, please refer to: ## Playing the game -Please note that playing the game is implemented through an environment, so human-controlled players use the same interface as the agents. One important implication is that there is a single action per 100 ms reported to the environment, which might cause a lag effect when playing. +Please note that playing the game is implemented through an environment, so human-controlled players use the same interface as the agents. +One important implication is that there is a single action per 100 ms reported to the environment, which might cause a lag effect when playing. ### Keyboard mappings @@ -143,8 +157,8 @@ The game defines following keyboard mapping (for the `keyboard` player type): * `ARROW RIGHT` - run to the right. * `S` - short pass in the attack mode, pressure in the defense mode. * `A` - high pass in the attack mode, sliding in the defense mode. -* `D` - shot in the the attack mode, team pressure in the defense mode. -* `W` - long pass in the the attack mode, goalkeeper pressure in the defense mode. +* `D` - shot in the attack mode, team pressure in the defense mode. +* `W` - long pass in the attack mode, goalkeeper pressure in the defense mode. * `Q` - switch the active player in the defense mode. * `C` - dribble in the attack mode. * `E` - sprint. diff --git a/gfootball/build_game_engine.bat b/gfootball/build_game_engine.bat new file mode 100644 index 00000000..da5ab809 --- /dev/null +++ b/gfootball/build_game_engine.bat @@ -0,0 +1,29 @@ +@echo off +rem This batch file compiles gfootball engine on Windows + +if "%VCPKG_ROOT%"=="" ( + echo VCPKG_ROOT environment variable is missing + echo Execute: SET "VCPKG_ROOT=PATH_TO_VCPKG" e.g., SET "VCPKG_ROOT=C:\src\vcpkg\" + exit /b 1 +) +if "%GENERATOR_PLATFORM%"=="" ( + echo GENERATOR_PLATFORM environment variable is missing + echo Execute: SET GENERATOR_PLATFORM={x64 or Win32}, depending on the Python Interpreter + exit /b 1 +) +if "%BUILD_CONFIGURATION%"=="" set BUILD_CONFIGURATION=Release + +pushd third_party\gfootball_engine + +if not exist build_win mkdir build_win +if exist build_win\CMakeCache.txt del build_win\CMakeCache.txt +if exist build_win\%BUILD_CONFIGURATION% rmdir /s /q build_win\%BUILD_CONFIGURATION% + +pushd build_win +cmake .. -A%GENERATOR_PLATFORM% +if errorlevel 1 exit /B 1 + +cmake --build . --parallel --config %BUILD_CONFIGURATION% +if errorlevel 1 exit /B 1 + +popd && popd \ No newline at end of file diff --git a/gfootball/doc/compile_engine.md b/gfootball/doc/compile_engine.md new file mode 100644 index 00000000..948c16e4 --- /dev/null +++ b/gfootball/doc/compile_engine.md @@ -0,0 +1,165 @@ +# Compiling Google Research Football Engine # + +This guide is intended to contain detailed information on building the environment +on different platforms and architectures. So far, it covers: +* [Windows](#windows), +* [macOS](#macos), +* [Linux](#linux). + +Additionally, [Development mode](#development-mode) section explains how to install the game +in the development (aka, editable) mode. + +## Windows +Install prerequisites: +- [Git](https://git-scm.com/download/win), +- [CMake](https://cmake.org/download/), +- [Visual Studio 2019 Community Edition](https://visualstudio.microsoft.com/downloads/) (make sure to + select "Desktop development with C++" component), +- [Python 3](https://www.python.org/downloads/). + +Finally, install [vcpkg](https://github.com/microsoft/vcpkg) by following a + [Quick Start Guide](https://github.com/microsoft/vcpkg#quick-start-windows) or simply by creating a directory, + e.g., `C:\dev`, opening Command Prompt and running the following commands: +```commandline +:: Navigate to the created directory +cd C:\dev +:: Clone vckpg +git clone https://github.com/microsoft/vcpkg.git +cd vckpg +:: Run installation script +.\bootstrap-vcpkg.bat +:: Return to previous directory +cd .. +``` + +If you have `vcpkg` already installed, consider updating it to the latest commit and running `.\bootstrap-vcpkg.bat`. + +As for the C++ engine dependencies (`boost`, `SDL`, etc.), you don't have to install them manually, `vcpkg's` +[manifest mode](https://github.com/microsoft/vcpkg/blob/master/docs/users/manifests.md) will handle it. + +Next, run the following lines in the command prompt to install Google Research Football environment: +```commandline +:: Clone the repository +git clone https://github.com/google-research/football.git +cd football +:: Set VCPKG_ROOT environment variable that points to vcpkg installation +set VCPKG_ROOT=C:\dev\vcpkg\ + +:: Create and activate virtual environment +python -m venv football-env +football-env\Scripts\activate.bat +:: For PowerShell users: football-env\Scripts\activate.ps1 + +:: Upgrade pip and install additional packages +python -m pip install --upgrade pip setuptools wheel +python -m pip install psutil + +:: Run the installation. It installs vcpkg dependencies and compiles the engine +pip install . --use-feature=in-tree-build +``` + + +## macOS + +First, install [brew](https://brew.sh/). It should automatically download Command Line Tools. +Next, install the required packages: +```shell +brew install git python3 cmake sdl2 sdl2_image sdl2_ttf sdl2_gfx boost boost-python3 + +python3 -m pip install --upgrade pip setuptools wheel +python3 -m pip install psutil +``` +Clone the repository and navigate to the directory: +```shell +git clone https://github.com/google-research/football.git +cd football +``` + +### Intel processor +#### Installation with brew version of Python +It is recommended to use Python shipped with `brew`, because `boost-python3` is compiled against the same version. +To check which Python 3 is used by default on your setup, execute `which python3`. +For Intel-based Macs it should be `/usr/local/bin/python3`. +If you have a different path, and you don't want to change symlinks, create a virtual environment with +`/usr/local/bin/python3 -m venv football-env` or `$(brew --prefix python3)/bin/python3.9 -m venv football-env`. + +Use [virtual environment](https://docs.python.org/3/tutorial/venv.html) to avoid messing up with global dependencies: + +```shell +python3 -m venv football-env +source football-env/bin/activate +# update pip and setuptools +python3 -m pip install --upgrade pip setuptools wheel +python3 -m pip install psutil +``` + +Finally, build the game environment: + +```shell +python3 -m pip install . --use-feature=in-tree-build +``` + +#### Installation with conda + +If you installed the engine using `conda`, you might encounter the following error: +`TypeError: __init__() should return None, not 'NoneType'` when trying to run the game. +It may happen because the `boost-python3` installed with `brew` is compiled against a different +version of Python (see the [discussion](https://github.com/google-research/football/issues/156)). +If you successfully installed and ran Google Research Football using `conda` please update this guide. +For now, the easiest way is to deactivate `conda` environment and install GRF with `brew` version of Python: +```shell +conda deactivate +$(brew --prefix python3)/bin/python3.9 -m venv football-env +source football-env/bin/activate +python3 -m pip install --upgrade pip setuptools psutil wheel +python3 -m pip install . --use-feature=in-tree-build +``` + +### Apple Silicon +The environment can be compiled and run on Apple Silicon. Until some dependencies (`opencv-python`, `numpy`, etc.) +fully support new architecture, the required components should be installed manually beforehand, +and Google Research Football should be installed without dependencies (`--no-deps`). + +#### Installation with conda +Python dependencies can be installed via `conda's` fork [miniforge](https://github.com/conda-forge/miniforge). +But you may encounter a `TypeError` when running the game if you use `boost-python3` from `brew`. + +## Linux +Install required packages: + +```shell +sudo apt-get install git cmake build-essential libgl1-mesa-dev libsdl2-dev \ +libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev libboost-all-dev \ +libdirectfb-dev libst-dev mesa-utils xvfb x11vnc python3-pip + +python3 -m pip install --upgrade pip setuptools wheel +python3 -m pip install psutil +``` +Use [virtual environment](https://docs.python.org/3/tutorial/venv.html) to avoid messing up with global dependencies: + +```shell +python3 -m venv football-env +source football-env/bin/activate +# update pip and setuptools +python3 -m pip install --upgrade pip setuptools wheel +python3 -m pip install psutil +``` + +Finally, build the game environment: + +```shell +python3 -m pip install . --use-feature=in-tree-build +``` + +## Development mode + +You can install Google Research Football +in the [development](https://packaging.python.org/guides/distributing-packages-using-setuptools/#id66) +(aka editable) mode by running: + +```shell +python3 -m pip install -e . --use-feature=in-tree-build +``` + +In such case, Python source files in projects can be edited in-place without reinstallation, +the changes will be reflected the next time an interpreter process is started. diff --git a/gfootball/env/config.py b/gfootball/env/config.py index 431b5705..5c0d53f4 100644 --- a/gfootball/env/config.py +++ b/gfootball/env/config.py @@ -18,6 +18,9 @@ from __future__ import print_function import copy +import tempfile +import os +import platform from absl import flags @@ -40,7 +43,12 @@ def parse_player_definition(definition): d = {'left_players': 0, 'right_players': 0} if ':' in definition: - (name, params) = definition.split(':') + # Windows requires special handling of replays, because path may contain ':' + if platform.system() == 'Windows' and definition.startswith('replay:') \ + and len(definition.split(':')) > 2: + (name, params) = 'replay', definition.split('replay:')[-1] + else: + (name, params) = definition.split(':') for param in params.split(','): (key, value) = param.split('=') d[key] = value @@ -86,7 +94,7 @@ def __init__(self, values=None): 'physics_steps_per_frame': 10, 'render_resolution_x': 1280, 'real_time': False, - 'tracesdir': '/tmp/dumps', + 'tracesdir': os.path.join(tempfile.gettempdir(), 'dumps'), 'video_format': 'avi', 'video_quality_level': 0, # 0 - low, 1 - medium, 2 - high 'write_video': False diff --git a/gfootball/env/football_env_test.py b/gfootball/env/football_env_test.py index 98b006d2..f385e177 100644 --- a/gfootball/env/football_env_test.py +++ b/gfootball/env/football_env_test.py @@ -19,13 +19,15 @@ from __future__ import division from __future__ import print_function from absl.testing import parameterized -from collections import Iterable +from collections.abc import Iterable from multiprocessing import pool from multiprocessing import Queue import gfootball import os +import platform import random import threading +import atexit import zlib from absl.testing import absltest @@ -80,10 +82,16 @@ def run_scenario(cfg, queue, actions, render=False, validation=True): obs = env.reset() queue.put(obs) if validation: - env.tracker_setup(0, 999999999999999) + # Otherwise the following error is generated on Windows: + # OverflowError: Python int too large to convert to C long + # The number can be also derived by + # import struct + # end = 2 ** (struct.Struct('l').size * 8 - 1) - 1 + end = 999999999999999 if platform.system() != 'Windows' else 2147483647 + env.tracker_setup(0, end) done = False step = 0 - while True: + while not done: if isinstance(actions, Iterable): if step >= len(actions): break @@ -98,8 +106,6 @@ def run_scenario(cfg, queue, actions, render=False, validation=True): else: obs, _, done, _ = env.step([action, action]) queue.put(obs) - if done: - break queue.put(None) env.close() @@ -141,17 +147,32 @@ def check_determinism(self, extensive=False): for episode in range(1 if extensive else 2): hash_value = compute_hash(env, actions, extensive) if extensive: - if hash_value != 1174966789: - self.assertEqual(hash_value, 2674313618) + # Linux + expected_hash_value = 1374617688 + if platform.system() == 'Windows': + expected_hash_value = 1828377453 + elif platform.system() == 'Darwin': + expected_hash_value = 2070005886 + self.assertEqual(hash_value, expected_hash_value) elif episode % 2 == 0: - if hash_value != 2275067030: - self.assertEqual(hash_value, 1402284732) + # Linux + expected_hash_value = 2457763948 + if platform.system() == 'Windows': + expected_hash_value = 2766829577 + elif platform.system() == 'Darwin': + expected_hash_value = 876758366 + self.assertEqual(hash_value, expected_hash_value) else: - if hash_value != 2045063811: - self.assertEqual(hash_value, 51517772) + # Linux + expected_hash_value = 867340920 + if platform.system() == 'Windows': + expected_hash_value = 2630021865 + elif platform.system() == 'Darwin': + expected_hash_value = 991389279 + self.assertEqual(hash_value, expected_hash_value) env.close() def test___control_all_players(self): @@ -285,7 +306,13 @@ def test___render(self): for _ in range(10): o, _, _, _ = env.step(football_action_set.action_right) hash_value = observation_hash(o, hash_value) - self.assertEqual(hash_value, 2591249504) + # Linux + expected_hash_value = 3642886809 + if platform.system() == 'Windows': + expected_hash_value = 683941870 + elif platform.system() == 'Darwin': + expected_hash_value = 1865563121 + self.assertEqual(hash_value, expected_hash_value) env.close() def test_dynamic_render(self): @@ -330,6 +357,7 @@ def test_determinism(self): def test_multi_instance(self): """Validates that two instances of the env can run in the same thread.""" tpool = pool.ThreadPool(processes=2) + atexit.register(tpool.close) run1 = tpool.apply_async(self.check_determinism) run2 = tpool.apply_async(self.check_determinism) run1.get() diff --git a/gfootball/env/observation_processor.py b/gfootball/env/observation_processor.py index 15d8de29..2ac60cdd 100644 --- a/gfootball/env/observation_processor.py +++ b/gfootball/env/observation_processor.py @@ -489,9 +489,9 @@ def write_dump(self, name): if WRITE_FILES: if not os.path.exists(self._dump_directory): os.makedirs(self._dump_directory) - dump_name = '{2}/{0}_{1}'.format(name, + dump_name = '{2}{3}{0}_{1}'.format(name, datetime.datetime.now().strftime('%Y%m%d-%H%M%S%f'), - self._dump_directory) + self._dump_directory, os.sep) config._active_dump = ActiveDump(dump_name, self._frame + config._steps_after, self._config) for step in list(self._trace)[-config._steps_before:]: diff --git a/gfootball/env/script_helpers_test.py b/gfootball/env/script_helpers_test.py index 0115e10c..97b81343 100644 --- a/gfootball/env/script_helpers_test.py +++ b/gfootball/env/script_helpers_test.py @@ -22,6 +22,7 @@ import glob import os import zlib +import tempfile from absl.testing import absltest from gfootball.env import config @@ -29,7 +30,7 @@ from gfootball.env import football_env from gfootball.env import script_helpers -test_tmpdir = '/tmp/gfootball_test' +test_tmpdir = os.path.join(tempfile.gettempdir(), 'gfootball_test') class ScriptHelpersTest(absltest.TestCase): diff --git a/gfootball/examples/run_multiagent_rllib.py b/gfootball/examples/run_multiagent_rllib.py index f73e0292..c7a6672a 100644 --- a/gfootball/examples/run_multiagent_rllib.py +++ b/gfootball/examples/run_multiagent_rllib.py @@ -19,6 +19,8 @@ from __future__ import division from __future__ import print_function +import os +import tempfile import argparse import gfootball.env as football_env @@ -42,7 +44,7 @@ class RllibGFootball(MultiAgentEnv): def __init__(self, num_agents): self.env = football_env.create_environment( env_name='test_example_multiagent', stacked=False, - logdir='/tmp/rllib_test', + logdir=os.path.join(tempfile.gettempdir(), 'rllib_test'), write_goal_dumps=False, write_full_episode_dumps=False, render=True, dump_frequency=0, number_of_left_players_agent_controls=num_agents, diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..116600e3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +pygame>=1.9.6 +opencv-python +psutil +scipy +gym>=0.11.0 +absl-py +wheel diff --git a/setup.py b/setup.py index 5ce05b25..9f569696 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,9 @@ import os import sys +import glob +import platform +import shutil from setuptools import find_packages from setuptools import setup, Extension from setuptools.command.install import install @@ -26,29 +29,38 @@ class CMakeExtension(Extension): def __init__(self, name): # don't invoke the original build_ext for this special extension - super().__init__(name, sources=[]) + sources = ['third_party/gfootball_engine/src/misc/empty.cpp'] + super().__init__(name, sources=sources, optional=True) class CustomBuild(build_ext): """Custom installation script to build the C++ environment.""" def run(self): + if platform.system() == 'Windows': + self.run_windows() + else: + self.run_unix() + super(CustomBuild, self).run() + + def run_unix(self): # https://stackoverflow.com/questions/32419594/how-to-create-a-dylib-c-extension-on-mac-os-x-with-distutils-and-or-setuptools if sys.platform == 'darwin': from distutils import sysconfig vars = sysconfig.get_config_vars() vars['LDSHARED'] = vars['LDSHARED'].replace('-bundle', '-dynamiclib -Wl,-F.') - if (os.path.exists(self.build_lib)): + if os.path.exists(self.build_lib): dest_dir = os.path.join(self.build_lib, 'gfootball_engine') else: + # Development install (pip install -e .) dest_dir = "gfootball_engine" if os.system('cp -r third_party/gfootball_engine/ ' + dest_dir): raise OSError("Google Research Football: Could not copy " - "engine to %s." % (dest_dir)) + "engine to %s." % dest_dir) if os.system('cp -r third_party/fonts ' + dest_dir): raise OSError('Google Research Football: Could not copy ' - 'fonts to %s.' % (dest_dir)) + 'fonts to %s.' % dest_dir) try: use_prebuilt_library = int( @@ -59,8 +71,8 @@ def run(self): if use_prebuilt_library: if os.system( - 'cp third_party/gfootball_engine/lib/prebuilt_gameplayfootball.so ' + - dest_dir + '/_gameplayfootball.so'): + 'cp third_party/gfootball_engine/lib/prebuilt_gameplayfootball.so ' + + dest_dir + '/_gameplayfootball.so'): raise OSError( 'Failed to copy pre-built library to a final destination %s.' % dest_dir) @@ -69,16 +81,57 @@ def run(self): os.system('cp third_party/gfootball_engine/_gameplayfootball.so ' + dest_dir)): raise OSError('Google Research Football compilation failed') - super(CustomBuild, self).run() + def run_windows(self): + if os.path.exists(self.build_lib): + dest_dir = os.path.join(self.build_lib, 'gfootball_engine') + else: # Development install + dest_dir = "gfootball_engine" + if not os.path.exists(dest_dir): + os.mkdir(dest_dir) + # For development mode (pip install -e .) gfootball_engine module has to be located + # in the project root directory. So we copy only __init__.py and `data` directory + shutil.copy2('third_party/gfootball_engine/__init__.py', dest_dir) + data_dir = os.path.join(dest_dir, 'data') + if not os.path.exists(data_dir): + shutil.copytree('third_party/gfootball_engine/data', data_dir) + + # Copy fonts + dst_fonts = os.path.join(dest_dir, "fonts") + if not os.path.exists(dst_fonts): + shutil.copytree("third_party/fonts", dst_fonts) + + py_major, py_minor, _ = platform.python_version_tuple() + guide_message = 'Please follow the guide on how to install prerequisites: ' \ + 'https://github.com/google-research/football/blob/master/gfootball/doc/compile_engine.md#windows' + if not os.environ.get('VCPKG_ROOT'): + raise OSError('VCPKG_ROOT environment variable is not defined.\n' + guide_message) + os.environ['GENERATOR_PLATFORM'] = 'x64' if sys.maxsize > 2 ** 32 else 'Win32' + os.environ['PY_VERSION'] = f'{py_major}.{py_minor}' + if os.system('gfootball\\build_game_engine.bat'): + raise OSError('Google Research Football compilation failed.\n' + guide_message) + # Copy compiled library and its dependencies + lib_path = 'third_party/gfootball_engine/build_win/Release/' + libs = glob.glob(f'{lib_path}*.pyd') + glob.glob(f'{lib_path}*.dll') + for file in libs: + shutil.copy2(file, dest_dir) + + +# To support development (a.k.a. editable) install (`pip install -e .` or `python3 setup.py develop`), +# we remove `build` directory created by a regular setup +if 'develop' in sys.argv and os.path.exists('build'): + shutil.rmtree('build') packages = find_packages() + find_packages('third_party') setup( name='gfootball', - version='2.9', + version='2.10', description=('Google Research Football - RL environment based on ' 'open-source game Gameplay Football'), + long_description=('Please see [our GitHub page](https://github.com/google-research/football) ' + 'for details.'), + long_description_content_type='text/markdown', author='Google LLC', author_email='no-reply@google.com', url='https://github.com/google-research/football', @@ -99,4 +152,3 @@ def run(self): ext_modules=[CMakeExtension('brainball_cpp_engine')], cmdclass={'build_ext': CustomBuild}, ) - diff --git a/third_party/gfootball_engine/CMakeLists.txt b/third_party/gfootball_engine/CMakeLists.txt index e1f8bdc4..0d847cb0 100644 --- a/third_party/gfootball_engine/CMakeLists.txt +++ b/third_party/gfootball_engine/CMakeLists.txt @@ -1,24 +1,39 @@ -cmake_minimum_required(VERSION 3.1) - -set(PACKAGE gameplayfootball) +cmake_minimum_required(VERSION 3.4) + +if(WIN32) + # Check for required Environment variables + if(NOT DEFINED CMAKE_GENERATOR_PLATFORM) + message(FATAL_ERROR "CMAKE_GENERATOR_PLATFORM is not defined. Add -Ax64 or -AWin32 to cmake command") + elseif(NOT DEFINED ENV{VCPKG_ROOT}) + message(FATAL_ERROR "VCPKG_ROOT is not defined. Set the location of vcpkg") + elseif(NOT DEFINED ENV{PY_VERSION}) # PY_VERSION has to be X.Y, e.g. 3.9 + message(FATAL_ERROR "PY_VERSION is not defined. Define Python version that will be used, e.g. 3.9") + endif() -set(VERSION_MAJOR 0) -set(VERSION_MINOR 2) -set(VERSION_PATCH 0) -if(${VERSION_PATCH}) - set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) -else(${VERSION_PATCH}) - set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}) -endif(${VERSION_PATCH}) + if(${CMAKE_GENERATOR_PLATFORM} STREQUAL Win32) + set(VCPKG_TARGET_TRIPLET x86-windows) + elseif(${CMAKE_GENERATOR_PLATFORM} STREQUAL x64) + set(VCPKG_TARGET_TRIPLET x64-windows) + else() + message(FATAL_ERROR "Unsupported Generator Platform, only Win32 or x64 are supported") + endif() -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules") + set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") + set(VCPKG_MANIFEST_DIR "${CMAKE_SOURCE_DIR}/vcpkg_manifests/py$ENV{PY_VERSION}") + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) +else() # UNIX + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules") +endif() project(gameplayfootball) +set(PACKAGE gameplayfootball) set (CMAKE_CXX_STANDARD 14) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} -fPIC -g -O3") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O3 -g") +if(UNIX) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} -fPIC -g -O3") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O3 -g") +endif(UNIX) # Find needed libraries FIND_PACKAGE(OpenGL REQUIRED) @@ -28,53 +43,66 @@ FIND_PACKAGE(SDL2 REQUIRED) include_directories(${SDL2_INCLUDE_DIR}) if(UNIX AND NOT APPLE) -FIND_PACKAGE(EGL REQUIRED) -include_directories(${EGL_INCLUDE_DIR}) + FIND_PACKAGE(EGL REQUIRED) + include_directories(${EGL_INCLUDE_DIR}) endif() -FIND_PACKAGE(SDL2_image REQUIRED) -include_directories(${SDL2_IMAGE_DIRS}) +if(WIN32) + FIND_PACKAGE(SDL2-image REQUIRED) + FIND_PACKAGE(SDL2-ttf REQUIRED) + FIND_PACKAGE(SDL2-gfx REQUIRED) +else() # Unix + FIND_PACKAGE(SDL2_image REQUIRED) + FIND_PACKAGE(SDL2_ttf REQUIRED) + FIND_PACKAGE(SDL2_gfx REQUIRED) +endif() -FIND_PACKAGE(SDL2_ttf REQUIRED) +include_directories(${SDL2_IMAGE_DIRS}) include_directories(${SDL2_TTF_DIRS}) - -FIND_PACKAGE(SDL2_gfx REQUIRED) include_directories(${SDL2_GFX_DIRS}) +if(UNIX) + find_package(PythonLibs 3 REQUIRED) +else() + set(PYTHONLIBS_VERSION_STRING $ENV{PY_VERSION}) +endif() -find_package(PythonLibs 3 REQUIRED) message("Using Python: ${PYTHONLIBS_VERSION_STRING}") string(REPLACE "." ";" VERSION_LIST ${PYTHONLIBS_VERSION_STRING}) list(GET VERSION_LIST 0 PYTHON_MAJOR) list(GET VERSION_LIST 1 PYTHON_MINOR) -# Include the python boost. -# Unfortunately different linux distributions are using different naming. +if(WIN32) + # find_package (Python COMPONENTS Development) + # FindPython package searches for system-wide python installations first. + # It was improved only recently (Jan 2021), so we can't use it for earlier py versions: + # (see https://github.com/microsoft/vcpkg/pull/15221 ) + # To avoid version mismatch we point to vcpkg's libs directly + set(PYTHON_LIBRARIES "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/lib/python${PYTHON_MAJOR}${PYTHON_MINOR}.lib") + set(PYTHON_INCLUDE_DIR "${CMAKE_BINARY_DIR}/vcpkg_installed/${VCPKG_TARGET_TRIPLET}/include/python${PYTHON_MAJOR}.${PYTHON_MINOR}") +endif() -# Ubuntu -FIND_PACKAGE(Boost COMPONENTS python3-py${PYTHON_MAJOR}${PYTHON_MINOR}) -if (Boost_PYTHON3-PY${PYTHON_MAJOR}${PYTHON_MINOR}_FOUND) - set(BOOST_PYTHON_VERSION python3-py${PYTHON_MAJOR}${PYTHON_MINOR}) +# Include Boost Python. +if(WIN32 OR APPLE) + set(BOOST_PYTHON_VERSION python${PYTHON_MAJOR}${PYTHON_MINOR}) else() - message("python3-py${PYTHON_MAJOR}${PYTHON_MINOR} not found. Trying other names.") - # Debian - FIND_PACKAGE(Boost COMPONENTS python-py${PYTHON_MAJOR}${PYTHON_MINOR}) - if (Boost_PYTHON-PY${PYTHON_MAJOR}${PYTHON_MINOR}_FOUND) - set(BOOST_PYTHON_VERSION python-py${PYTHON_MAJOR}${PYTHON_MINOR}) - else() - message("python-py${PYTHON_MAJOR}${PYTHON_MINOR} not found. Trying other names.") - - # Some other distributions. - FIND_PACKAGE(Boost COMPONENTS python${PYTHON_MAJOR}${PYTHON_MINOR}) - if (Boost_PYTHON${PYTHON_MAJOR}${PYTHON_MINOR}_FOUND) - set(BOOST_PYTHON_VERSION python${PYTHON_MAJOR}${PYTHON_MINOR}) - else() - message(FATAL_ERROR "Python boost not found") + # Unfortunately different linux distributions are using different naming for boost-python + # list of prefixes: Ubuntu, Debian, Some other distributions + set(BOOST_PYTHON_PREFIXES python3-py python-py python) + foreach(BP_PREFIX ${BOOST_PYTHON_PREFIXES}) + set(BOOST_PYTHON_NAME ${BP_PREFIX}${PYTHON_MAJOR}${PYTHON_MINOR}) + string(TOUPPER ${BOOST_PYTHON_NAME} BOOST_PYTHON_NAME_UPPER) + FIND_PACKAGE(Boost COMPONENTS ${BOOST_PYTHON_NAME}) + if(Boost_${BOOST_PYTHON_NAME_UPPER}_FOUND) + set(BOOST_PYTHON_VERSION ${BOOST_PYTHON_NAME}) + break() endif() + message("${BOOST_PYTHON_NAME} not found. Trying other names.") + endforeach() + if(NOT DEFINED BOOST_PYTHON_VERSION) + message(FATAL_ERROR "Boost Python not found") endif() - endif() - message("Using python_boost: ${BOOST_PYTHON_VERSION}") FIND_PACKAGE(Boost REQUIRED COMPONENTS thread system filesystem ${BOOST_PYTHON_VERSION}) @@ -88,65 +116,53 @@ include_directories(${PROJECT_SOURCE_DIR}/src/cmake) # Include the sources include(sources.cmake) - -set(OWN_LIBRARIES $ $ - $ $ - $ $ - $ $ - $) - -# Join all created static libraries into the single static or share one. - -# For shared library, uncomment bellow: - -#set_property(TARGET baselib PROPERTY POSITION_INDEPENDENT_CODE 1) -#set_property(TARGET systemscommonlib PROPERTY POSITION_INDEPENDENT_CODE 1) -#set_property(TARGET systemsgraphicslib PROPERTY POSITION_INDEPENDENT_CODE 1) -#set_property(TARGET loaderslib PROPERTY POSITION_INDEPENDENT_CODE 1) -#set_property(TARGET typeslib PROPERTY POSITION_INDEPENDENT_CODE 1) -#set_property(TARGET scenelib PROPERTY POSITION_INDEPENDENT_CODE 1) -#set_property(TARGET managerslib PROPERTY POSITION_INDEPENDENT_CODE 1) -#set_property(TARGET utilslib PROPERTY POSITION_INDEPENDENT_CODE 1) -#set_property(TARGET gui2lib PROPERTY POSITION_INDEPENDENT_CODE 1) -#add_library(blunted2 SHARED ${CORE_SOURCES} ${CORE_HEADERS} ${OWN_LIBRARIES}) - -#set_target_properties(blunted2 PROPERTIES VERSION ${VERSION} -# SOVERSION ${VERSION_MAJOR} ) -#add_library(blunted2 SHARED ${CORE_SOURCES} ${LIBS_SOURCES} ${CORE_HEADERS} -# ${ALL_LIBS_HEADERS} ${OWN_LIBRARIES}) - -# For static library. -add_library(blunted2 ${BLUNTED_CORE_SOURCES} ${LIBS_SOURCES} ${BLUNTED_CORE_HEADERS} - ${ALL_LIBS_HEADERS} ${OWN_LIBRARIES}) - - -# Compile it as multiple static libraries (note: not compiling physics, -# as not used by gameplayfootball) -add_library(gamelib ${GAME_SOURCES} ${GAME_HEADERS}) -add_library(menulib ${MENU_SOURCES} ${MENU_HEADERS}) -add_library(datalib ${DATA_SOURCES} ${DATA_HEADERS}) - -set(LIBRARIES gamelib menulib datalib blunted2 - Boost::filesystem Boost::system Boost::thread Boost::${BOOST_PYTHON_VERSION} ${PYTHON_LIBRARY} - ${SDL2_IMAGE_LIBRARIES} ${SDL2_TTF_LIBRARIES} ${SDL2_GFX_LIBRARIES} - ${SDL2_LIBRARIES} ${EGL_LIBRARIES} ${OPENGL_LIBRARIES}) add_library(baselib OBJECT ${BASE_SOURCES} ${BASE_HEADERS} ${BASE_GEOMETRY_HEADERS} ${BASE_MATH_HEADERS}) -add_library(systemscommonlib OBJECT ${SYSTEMS_COMMON_SOURCES} - ${SYSTEMS_COMMON_HEADERS}) -add_library(systemsgraphicslib OBJECT ${SYSTEMS_GRAPHICS_SOURCES} +add_library(systemsgraphicslib OBJECT ${SYSTEMS_GRAPHICS_SOURCES} ${SYSTEMS_COMMON_HEADERS} ${SYSTEMS_GRAPHICS_HEADERS} ${SYSTEMS_GRAPHICS_OBJECTS_HEADERS} ${SYSTEMS_GRAPHICS_RESOURCES_HEADERS} ${SYSTEMS_GRAPHICS_RENDERING_HEADERS}) -add_library(loaderslib OBJECT ${LOADERS_SOURCES} ${LOADERS_HEADERS}) +add_library(loaderslib OBJECT ${LOADERS_SOURCES} ${LOADERS_HEADERS} ${MANAGERS_HEADERS}) add_library(typeslib OBJECT ${TYPES_SOURCES} ${TYPES_HEADERS}) add_library(scenelib OBJECT ${SCENE_SOURCES} ${SCENE_HEADERS} ${SCENE2D_HEADERS} ${SCENE3D_HEADERS} ${SCENE_OBJECTS_HEADERS} ${SCENE_RESOURCES_HEADERS}) -add_library(managerslib OBJECT ${MANAGERS_SOURCES} ${MANAGERS_HEADERS}) add_library(utilslib OBJECT ${UTILS_SOURCES} ${UTILS_HEADERS} ${UTILS_EXT_HEADERS}) add_library(gui2lib OBJECT ${UTILS_GUI2_SOURCES} ${UTILS_GUI2_HEADERS} ${UTILS_GUI2_WIDGETS_HEADERS}) -add_library(game SHARED ${CORE_SOURCES} ${CORE_HEADERS} ${AI_HEADERS} ${AI_SOURCES}) -target_link_libraries(game ${LIBRARIES}) +# Join all created static libraries into a single static or shared one. +set(OWN_LIBRARIES $ # $ + $ $ + $ $ + $ $) + +# Compile it as multiple static libraries +add_library(blunted2 ${BLUNTED_CORE_SOURCES} ${BLUNTED_CORE_HEADERS} ${OWN_LIBRARIES}) +add_library(gamelib ${GAME_SOURCES} ${GAME_HEADERS}) +add_library(menulib ${MENU_SOURCES} ${MENU_HEADERS}) +add_library(datalib ${DATA_SOURCES} ${DATA_HEADERS}) + +if(UNIX) + set(SDL2_LIBS_ALL ${SDL2_IMAGE_LIBRARIES} ${SDL2_TTF_LIBRARIES} ${SDL2_GFX_LIBRARIES} ${SDL2_LIBRARIES}) +elseif(WIN32) + set(SDL2_LIBS_ALL SDL2::SDL2 SDL2::SDL2_image SDL2::SDL2_ttf SDL2::SDL2_gfx SDL2::SDL2main) +endif() + +set(LIBRARIES gamelib menulib datalib blunted2 + Boost::filesystem Boost::system Boost::thread Boost::${BOOST_PYTHON_VERSION} + ${PYTHON_LIBRARIES} ${SDL2_LIBS_ALL} ${EGL_LIBRARIES} ${OPENGL_LIBRARY}) + +if(UNIX) + set(LIB_NAME game) +else() # WIN32 + # Windows requires the library to have the same name as the module + set(LIB_NAME _gameplayfootball) +endif() + +add_library(${LIB_NAME} SHARED ${CORE_SOURCES} ${CORE_HEADERS} ${AI_HEADERS} ${AI_SOURCES}) +target_link_libraries(${LIB_NAME} ${LIBRARIES}) + +if(WIN32) + set_target_properties(${LIB_NAME} PROPERTIES SUFFIX ".pyd") +endif() diff --git a/third_party/gfootball_engine/CMakeModules/FindBlunted2.cmake b/third_party/gfootball_engine/CMakeModules/FindBlunted2.cmake deleted file mode 100644 index a38ba039..00000000 --- a/third_party/gfootball_engine/CMakeModules/FindBlunted2.cmake +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright 2019 Google LLC -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Locate Blunted library -# This module defines -# BLUNTED2_LIBRARY, the name of the library to link against -# BLUNTED2_FOUND, if false, do not try to link to BLUNTED2 -# -# BLUNTED2_INCLUDE_DIR, where to find blunted2config.h -# -# $BLUNTED2DIR - enviroment variable -# -# Created by Farrer. This was influenced by the FindSDL_image.cmake module. - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= - -FIND_PATH(BLUNTED2_INCLUDE_DIR NAMES blunted.hpp - HINTS - $ENV{BLUNTED2DIR} - PATH_SUFFIXES include - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/include/blunted2 - /usr/include/blunted2 - /usr/local/include - /usr/include - /sw/include/blunted2 # Fink - /sw/include - /opt/local/include/blunted2 # DarwinPorts - /opt/local/include - /opt/csw/include/kodold # Blastwave - /opt/csw/include - /opt/include/blunted2 - /opt/include -) - -FIND_LIBRARY(BLUNTED2_LIBRARY - NAMES blunted2 - HINTS - $ENV{BLUNTED2DIR} - PATH_SUFFIXES lib64 lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw - /opt/local - /opt/csw - /opt -) - -INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(BLUNTED2 - REQUIRED_VARS BLUNTED2_LIBRARY BLUNTED2_INCLUDE_DIR) diff --git a/third_party/gfootball_engine/CMakeModules/FindSDL_gfx.cmake b/third_party/gfootball_engine/CMakeModules/FindSDL_gfx.cmake deleted file mode 100644 index 2fb53e4d..00000000 --- a/third_party/gfootball_engine/CMakeModules/FindSDL_gfx.cmake +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright 2019 Google LLC -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Locate SDL_gfx library -# This module defines -# SDL_GFX_LIBRARIES, the name of the library to link against -# SDL_GFX_FOUND, if false, do not try to link to SDL_GFX -# -# SDL_GFX_INCLUDE_DIRS, where to find sgeconfig.h -# -# $SDL_GFXDIR - enviroment variable -# -# Created by Farrer. This was influenced by the FindSDL_image.cmake module. - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= - -FIND_PATH(SDL_GFX_INCLUDE_DIRS NAMES SDL_gfxPrimitives.h - HINTS - $ENV{SDL_GFXDIR} - PATH_SUFFIXES include - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/include/sge - /usr/local/include/SDL - /usr/include/sge - /usr/include/SDL - /usr/local/include - /usr/include - /sw/include/sge # Fink - /sw/include/SDL - /sw/include - /opt/local/include/sge # DarwinPorts - /opt/local/include/SDL - /opt/local/include - /opt/csw/include/sge # Blastwave - /opt/csw/include/SDL # Blastwave - /opt/csw/include - /opt/include/sge - /opt/include -) - -FIND_LIBRARY(SDL_GFX_LIBRARIES - NAMES SDL_gfx - HINTS - $ENV{SDL_GFXDIR} - PATH_SUFFIXES lib64 lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw - /opt/local - /opt/csw - /opt -) - -INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_gfx - REQUIRED_VARS SDL_GFX_LIBRARIES SDL_GFX_INCLUDE_DIRS) diff --git a/third_party/gfootball_engine/CMakeModules/FindSGE.cmake b/third_party/gfootball_engine/CMakeModules/FindSGE.cmake deleted file mode 100644 index 334f3ecc..00000000 --- a/third_party/gfootball_engine/CMakeModules/FindSGE.cmake +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright 2019 Google LLC -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Locate SGE library -# This module defines -# SGE_LIBRARY, the name of the library to link against -# SGE_FOUND, if false, do not try to link to SGE -# -# SGE_INCLUDE_DIR, where to find sgeconfig.h -# -# $SGEDIR - enviroment variable -# -# Created by Farrer. This was influenced by the FindSDL_image.cmake module. - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= - -FIND_PATH(SGE_INCLUDE_DIR NAMES sge.h - HINTS - $ENV{SGEDIR} - PATH_SUFFIXES include - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/include/sge - /usr/local/include/SDL - /usr/include/sge - /usr/include/SDL - /usr/local/include - /usr/include - /sw/include/sge # Fink - /sw/include/SDL - /sw/include - /opt/local/include/sge # DarwinPorts - /opt/local/include/SDL - /opt/local/include - /opt/csw/include/sge # Blastwave - /opt/csw/include/SDL # Blastwave - /opt/csw/include - /opt/include/sge - /opt/include -) - -FIND_LIBRARY(SGE_LIBRARY - NAMES SGE - HINTS - $ENV{SGEDIR} - PATH_SUFFIXES lib64 lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw - /opt/local - /opt/csw - /opt -) - -INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SGE - REQUIRED_VARS SGE_LIBRARY SGE_INCLUDE_DIR) diff --git a/third_party/gfootball_engine/ai.cpp b/third_party/gfootball_engine/ai.cpp index 55ff7275..dfd73e0d 100644 --- a/third_party/gfootball_engine/ai.cpp +++ b/third_party/gfootball_engine/ai.cpp @@ -16,6 +16,9 @@ #include "src/game_env.hpp" #include +#ifdef WIN32 +#define BOOST_USE_WINDOWS_H +#endif #include #include #include diff --git a/third_party/gfootball_engine/sources.cmake b/third_party/gfootball_engine/sources.cmake index e91120f9..e1fb4f4f 100644 --- a/third_party/gfootball_engine/sources.cmake +++ b/third_party/gfootball_engine/sources.cmake @@ -56,9 +56,6 @@ set(SYSTEMS_COMMON_HEADERS src/systems/isystemobject.hpp ) -set(SYSTEMS_COMMON_SOURCES -) - set(SYSTEMS_GRAPHICS_HEADERS src/systems/graphics/graphics_task.hpp src/systems/graphics/graphics_scene.hpp @@ -97,29 +94,6 @@ set(SYSTEMS_GRAPHICS_SOURCES src/systems/graphics/graphics_system.cpp ) -set(SYSTEMS_PHYSICS_HEADERS - src/systems/physics/physics_scene.hpp - src/systems/physics/physics_object.hpp - src/systems/physics/objects/physics_geometry.hpp - src/systems/physics/objects/physics_joint.hpp - src/systems/physics/wrappers/ode_physics.hpp - src/systems/physics/wrappers/interface_physics.hpp - src/systems/physics/resources/vertexbuffer.hpp - src/systems/physics/physics_system.hpp - src/systems/physics/physics_task.hpp -) - -set(SYSTEMS_PHYSICS_SOURCES - src/systems/physics/physics_scene.cpp - src/systems/physics/physics_task.cpp - src/systems/physics/physics_system.cpp - src/systems/physics/physics_object.cpp - src/systems/physics/objects/physics_joint.cpp - src/systems/physics/objects/physics_geometry.cpp - src/systems/physics/wrappers/ode_physics.cpp - src/systems/physics/resources/vertexbuffer.cpp -) - set(LOADERS_HEADERS src/loaders/aseloader.hpp src/loaders/imageloader.hpp @@ -199,9 +173,6 @@ set(MANAGERS_HEADERS src/managers/resourcemanager.hpp ) -set(MANAGERS_SOURCES -) - set(UTILS_HEADERS src/utils/animation.hpp src/utils/objectloader.hpp @@ -251,8 +222,6 @@ set(UTILS_GUI2_SOURCES src/utils/gui2/page.cpp ) -set(ALL_LIBS_HEADERS ${LIBS_HEADERS}) - set(BLUNTED_CORE_HEADERS src/defines.hpp src/blunted.hpp @@ -393,6 +362,3 @@ set(DATA_SOURCES src/data/playerdata.cpp src/data/teamdata.cpp ) - - - diff --git a/third_party/gfootball_engine/src/base/utils.cpp b/third_party/gfootball_engine/src/base/utils.cpp index 24da6d5a..587e22f6 100644 --- a/third_party/gfootball_engine/src/base/utils.cpp +++ b/third_party/gfootball_engine/src/base/utils.cpp @@ -197,9 +197,14 @@ void file_to_vector(std::string filename, std::string get_file_name(const std::string &filename) { DO_VALIDATION; +#ifdef WIN32 + std::string chompedFilename = + boost::filesystem::path(filename).filename().string(); +#else std::string chompedFilename = filename.substr(filename.find_last_of('\\') + 1); chompedFilename = chompedFilename.substr(filename.find_last_of('/') + 1); +#endif return chompedFilename; } diff --git a/third_party/gfootball_engine/src/cmake/backtrace.cpp b/third_party/gfootball_engine/src/cmake/backtrace.cpp index 5a37bea0..edf6d633 100644 --- a/third_party/gfootball_engine/src/cmake/backtrace.cpp +++ b/third_party/gfootball_engine/src/cmake/backtrace.cpp @@ -12,17 +12,21 @@ // limitations under the License. #include +#ifndef WIN32 #include +#include +#endif #include #include "backtrace.h" #include -#include void print_stacktrace() { void *array[20]; size_t size; +#ifndef WIN32 size = backtrace(array, 20); backtrace_symbols_fd(array, size, STDERR_FILENO); +#endif } diff --git a/third_party/gfootball_engine/src/cmake/file.cpp b/third_party/gfootball_engine/src/cmake/file.cpp index 5632310d..d61e2f81 100644 --- a/third_party/gfootball_engine/src/cmake/file.cpp +++ b/third_party/gfootball_engine/src/cmake/file.cpp @@ -51,7 +51,7 @@ void GetFilesRec(boost::filesystem::path path, const std::string &extension, if (thePath.extension() == "." + extension) { DO_VALIDATION; - files.push_back(path.string() + "/" + thePath.filename().string()); + files.push_back(thePath.string()); } } diff --git a/third_party/gfootball_engine/src/data/teamdata.cpp b/third_party/gfootball_engine/src/data/teamdata.cpp index f1d7eaa5..d2e86171 100755 --- a/third_party/gfootball_engine/src/data/teamdata.cpp +++ b/third_party/gfootball_engine/src/data/teamdata.cpp @@ -198,7 +198,11 @@ TeamData::TeamData(int teamDatabaseID, const std::vector &f) { while (changed && iterations < maxIterations) { DO_VALIDATION; +#ifdef WIN32 + std::vector offset(player_count); +#else Vector3 offset[player_count]; +#endif changed = false; for (int p1 = 0; p1 < player_count - 1; p1++) { diff --git a/third_party/gfootball_engine/src/defines.hpp b/third_party/gfootball_engine/src/defines.hpp index 54a72eee..cf856e8b 100644 --- a/third_party/gfootball_engine/src/defines.hpp +++ b/third_party/gfootball_engine/src/defines.hpp @@ -19,7 +19,9 @@ #define _HPP_DEFINES #ifdef WIN32 +#define NOMINMAX #include +#undef NOMINMAX #endif #include @@ -59,7 +61,7 @@ typedef std::string screenshoot; namespace blunted { class Animation; - using namespace boost; + //using namespace boost; } class Player; diff --git a/third_party/gfootball_engine/src/loaders/aseloader.cpp b/third_party/gfootball_engine/src/loaders/aseloader.cpp index 02ea9ee3..7dcac1dd 100644 --- a/third_party/gfootball_engine/src/loaders/aseloader.cpp +++ b/third_party/gfootball_engine/src/loaders/aseloader.cpp @@ -222,8 +222,11 @@ void ASELoader::BuildTriangleMesh( MESH_VERTEX 0 0.000 500.000 0.000 .. */ - +#ifdef WIN32 + std::vector vertex_cache(numvertex); +#else Vector3 vertex_cache[numvertex]; +#endif if (tree_mesh_vertex_list->entries.size() != (unsigned int)numvertex) Log(e_FatalError, "ASELoader", "BuildTriangleMesh", @@ -395,7 +398,11 @@ void ASELoader::BuildTriangleMesh( if (numtvertex > 0) { DO_VALIDATION; +#ifdef WIN32 + std::vector tvertex_cache(numtvertex); +#else Vector3 tvertex_cache[numtvertex]; +#endif if (tree_mesh_tvertex_list->entries.size() != (unsigned int)numtvertex) Log(e_FatalError, "ASELoader", "BuildTriangleMesh", diff --git a/third_party/gfootball_engine/src/main.cpp b/third_party/gfootball_engine/src/main.cpp index 5bc1698b..98cd8d03 100755 --- a/third_party/gfootball_engine/src/main.cpp +++ b/third_party/gfootball_engine/src/main.cpp @@ -16,7 +16,9 @@ // i do not offer support, so don't ask. to be used for inspiration :) #ifdef WIN32 +#define NOMINMAX #include +#undef NOMINMAX #endif #include @@ -136,18 +138,23 @@ void run_game(Properties* input_config, bool render) { game->context->gameTask = boost::shared_ptr(new GameTask()); std::string fontfilename = game->context->config->Get( "font_filename", "media/fonts/alegreya/AlegreyaSansSC-ExtraBold.ttf"); +#ifdef WIN32 + game->context->defaultFont = TTF_OpenFont(fontfilename.c_str(), 32); + game->context->defaultOutlineFont = TTF_OpenFont(fontfilename.c_str(), 32); +#else game->context->font = GetFile(fontfilename); game->context->defaultFont = TTF_OpenFontIndexRW(SDL_RWFromConstMem(game->context->font.data(), game->context->font.size()), 0, 32, 0); - if (!game->context->defaultFont) - Log(e_FatalError, "football", "main", - "Could not load font " + fontfilename); game->context->defaultOutlineFont = TTF_OpenFontIndexRW(SDL_RWFromConstMem(game->context->font.data(), game->context->font.size()), 0, 32, 0); +#endif + if (!game->context->defaultFont) + Log(e_FatalError, "football", "main", + "Could not load font " + fontfilename); TTF_SetFontOutline(game->context->defaultOutlineFont, 2); game->context->menuTask = boost::shared_ptr( new MenuTask(5.0f / 4.0f, 0, game->context->defaultFont, diff --git a/third_party/gfootball_engine/src/main.hpp b/third_party/gfootball_engine/src/main.hpp index 95630049..ebc951fb 100755 --- a/third_party/gfootball_engine/src/main.hpp +++ b/third_party/gfootball_engine/src/main.hpp @@ -74,10 +74,20 @@ class GameConfig { int render_resolution_x = 1280; int render_resolution_y = 720; std::string updatePath(const std::string& path) { +#ifdef WIN32 + boost::filesystem::path boost_path(path); + if (boost_path.is_absolute()) { + return path; + } + boost::filesystem::path data_dir_boost(data_dir); + data_dir_boost /= boost_path; + return data_dir_boost.string(); +#else if (path[0] == '/') { return path; } return data_dir + '/' + path; +#endif } void ProcessState(EnvState* state) { state->process(data_dir); @@ -111,7 +121,7 @@ struct ScenarioConfig { float leftDistance = 1000000; float rightDistance = 1000000; for (auto& player : left_team) { DO_VALIDATION; - leftDistance =std::min(leftDistance, + leftDistance = std::min(leftDistance, (player.start_position - ball_position).GetLength()); } for (auto& player : right_team) { DO_VALIDATION; @@ -295,7 +305,9 @@ const std::vector &GetControllers(); void run_game(Properties* input_config, bool render); void randomize(unsigned int seed); void quit_game(); +#ifndef WIN32 int main(int argc, char** argv); +#endif class Tracker { public: diff --git a/third_party/gfootball_engine/src/misc/empty.cpp b/third_party/gfootball_engine/src/misc/empty.cpp new file mode 100644 index 00000000..99f0d68e --- /dev/null +++ b/third_party/gfootball_engine/src/misc/empty.cpp @@ -0,0 +1 @@ +// This file is needed for installing gfootball_engine in development mode (`pip install -e .`). diff --git a/third_party/gfootball_engine/src/onthepitch/match.cpp b/third_party/gfootball_engine/src/onthepitch/match.cpp index d4c229db..8c419010 100755 --- a/third_party/gfootball_engine/src/onthepitch/match.cpp +++ b/third_party/gfootball_engine/src/onthepitch/match.cpp @@ -330,7 +330,7 @@ void Match::SetRandomSunParams() { float defaultRadius = 1000000.0f; float sunRadius = defaultRadius; - static_pointer_cast(sunNode->GetObject("sun"))->SetRadius(sunRadius); + boost::static_pointer_cast(sunNode->GetObject("sun"))->SetRadius(sunRadius); Vector3 sunColorNoon(0.9, 0.8, 1.0); sunColorNoon *= 1.4f; Vector3 sunColorDusk(1.4, 0.9, 0.7); sunColorDusk *= 1.2f; @@ -344,7 +344,7 @@ void Match::SetRandomSunParams() { randomAddition *= 1.2f; sunColor += randomAddition; - static_pointer_cast(sunNode->GetObject("sun"))->SetColor(sunColor * brightness); + boost::static_pointer_cast(sunNode->GetObject("sun"))->SetColor(sunColor * brightness); } void Match::RandomizeAdboards(boost::intrusive_ptr stadiumNode) { diff --git a/third_party/gfootball_engine/src/onthepitch/player/humanoid/humanoid.cpp b/third_party/gfootball_engine/src/onthepitch/player/humanoid/humanoid.cpp index c3d826d7..28b3ffbb 100755 --- a/third_party/gfootball_engine/src/onthepitch/player/humanoid/humanoid.cpp +++ b/third_party/gfootball_engine/src/onthepitch/player/humanoid/humanoid.cpp @@ -1847,7 +1847,11 @@ signed int Humanoid::GetBestCheatableAnimID(const DataSet &sortedDataSet, bool u boost::shared_ptr footballExtension = boost::static_pointer_cast(anim->GetExtension("football")); int totalTouches = footballExtension->GetTouchCount(); +#ifdef WIN32 + std::vector touchIDs(totalTouches); +#else int touchIDs[totalTouches]; +#endif int count = 0; int defaultTouchFrame = atoi(anim->GetVariable("touchframe").c_str()); diff --git a/third_party/gfootball_engine/src/onthepitch/teamAIcontroller.cpp b/third_party/gfootball_engine/src/onthepitch/teamAIcontroller.cpp index d8340d24..c97095fb 100755 --- a/third_party/gfootball_engine/src/onthepitch/teamAIcontroller.cpp +++ b/third_party/gfootball_engine/src/onthepitch/teamAIcontroller.cpp @@ -522,7 +522,11 @@ void TeamAIController::CalculateDynamicRoles() { hungarian_problem_t p; +#ifdef WIN32 + std::vector r(playerNum * playerNum); +#else int r[playerNum * playerNum]; +#endif for (unsigned int x = 0; x < playerNum; x++) { DO_VALIDATION; @@ -537,7 +541,11 @@ void TeamAIController::CalculateDynamicRoles() { } } +#ifdef WIN32 + int** m = array_to_matrix(&r[0], playerNum, playerNum); +#else int** m = array_to_matrix(r, playerNum, playerNum); +#endif /* initialize the hungarian_problem using the cost matrix*/ int matrix_size = hungarian_init(&p, m, playerNum, playerNum, HUNGARIAN_MODE_MINIMIZE_COST); diff --git a/third_party/gfootball_engine/src/scene/object.cpp b/third_party/gfootball_engine/src/scene/object.cpp index 49ab6ac7..7b286ad8 100644 --- a/third_party/gfootball_engine/src/scene/object.cpp +++ b/third_party/gfootball_engine/src/scene/object.cpp @@ -119,7 +119,7 @@ inline e_ObjectType Object::GetObjectType() { int observersSize = observers.size(); for (int i = 0; i < observersSize; i++) { DO_VALIDATION; - boost::intrusive_ptr interpreter = static_pointer_cast(observers[i]); + boost::intrusive_ptr interpreter = boost::static_pointer_cast(observers[i]); interpreter->OnSynchronize(); } } @@ -138,7 +138,7 @@ inline e_ObjectType Object::GetObjectType() { int observersSize = observers.size(); for (int i = 0; i < observersSize; i++) { DO_VALIDATION; - boost::intrusive_ptr interpreter = static_pointer_cast(observers[i]); + boost::intrusive_ptr interpreter = boost::static_pointer_cast(observers[i]); if (interpreter->GetSystemType() == targetSystemType) result = interpreter; } return result; diff --git a/third_party/gfootball_engine/src/scene/scene3d/node.hpp b/third_party/gfootball_engine/src/scene/scene3d/node.hpp index 9374959e..39c18483 100644 --- a/third_party/gfootball_engine/src/scene/scene3d/node.hpp +++ b/third_party/gfootball_engine/src/scene/scene3d/node.hpp @@ -59,7 +59,7 @@ namespace blunted { int objectsSize = objects.size(); for (int i = 0; i < objectsSize; i++) { DO_VALIDATION; if (objects[i]->GetObjectType() == targetObjectType) { DO_VALIDATION; - gatherObjects.push_back(static_pointer_cast(objects[i])); + gatherObjects.push_back(boost::static_pointer_cast(objects[i])); } } @@ -76,7 +76,7 @@ namespace blunted { int objectsSize = objects.size(); for (int i = 0; i < objectsSize; i++) { DO_VALIDATION; if (objects[i]->GetObjectType() == targetObjectType) { DO_VALIDATION; - if (objects[i]->GetAABB().Intersects(bounding)) gatherObjects.push_back(static_pointer_cast(objects[i])); + if (objects[i]->GetAABB().Intersects(bounding)) gatherObjects.push_back(boost::static_pointer_cast(objects[i])); } } diff --git a/third_party/gfootball_engine/src/systems/graphics/objects/graphics_camera.cpp b/third_party/gfootball_engine/src/systems/graphics/objects/graphics_camera.cpp index 49af2382..995734a4 100644 --- a/third_party/gfootball_engine/src/systems/graphics/objects/graphics_camera.cpp +++ b/third_party/gfootball_engine/src/systems/graphics/objects/graphics_camera.cpp @@ -133,7 +133,7 @@ void GraphicsCamera::SetPosition(const Vector3 &newPosition) { std::deque < boost::intrusive_ptr >::iterator visibleGeometryIter = visibleGeometry.begin(); while (visibleGeometryIter != visibleGeometry.end()) { DO_VALIDATION; - boost::intrusive_ptr interpreter = static_pointer_cast((*visibleGeometryIter)->GetInterpreter(e_SystemType_Graphics)); + boost::intrusive_ptr interpreter = boost::static_pointer_cast((*visibleGeometryIter)->GetInterpreter(e_SystemType_Graphics)); // add buffers to visible geometry queue interpreter->GetVertexBufferQueue(buffer->visibleGeometry); @@ -151,7 +151,7 @@ void GraphicsCamera::SetPosition(const Vector3 &newPosition) { DO_VALIDATION; LightQueueEntry entry; - boost::intrusive_ptr interpreter = static_pointer_cast((*visibleLightIter)->GetInterpreter(e_SystemType_Graphics)); + boost::intrusive_ptr interpreter = boost::static_pointer_cast((*visibleLightIter)->GetInterpreter(e_SystemType_Graphics)); if (interpreter->GetShadow()) { DO_VALIDATION; @@ -186,7 +186,7 @@ void GraphicsCamera::SetPosition(const Vector3 &newPosition) { std::deque < boost::intrusive_ptr >::iterator skyboxIter = skyboxes.begin(); while (skyboxIter != skyboxes.end()) { DO_VALIDATION; - boost::intrusive_ptr interpreter = static_pointer_cast((*skyboxIter)->GetInterpreter(e_SystemType_Graphics)); + boost::intrusive_ptr interpreter = boost::static_pointer_cast((*skyboxIter)->GetInterpreter(e_SystemType_Graphics)); // add buffers to skybox queue interpreter->GetVertexBufferQueue(buffer->skyboxes); skyboxIter++; diff --git a/third_party/gfootball_engine/src/systems/graphics/objects/graphics_light.cpp b/third_party/gfootball_engine/src/systems/graphics/objects/graphics_light.cpp index 70709c08..aefb0225 100644 --- a/third_party/gfootball_engine/src/systems/graphics/objects/graphics_light.cpp +++ b/third_party/gfootball_engine/src/systems/graphics/objects/graphics_light.cpp @@ -211,7 +211,7 @@ void GraphicsLight::SetPosition(const Vector3 &newPosition) { std::deque < boost::intrusive_ptr >::iterator visibleGeometryIter = visibleGeometry.begin(); while (visibleGeometryIter != visibleGeometry.end()) { DO_VALIDATION; - boost::intrusive_ptr interpreter = static_pointer_cast((*visibleGeometryIter)->GetInterpreter(e_SystemType_Graphics)); + boost::intrusive_ptr interpreter = boost::static_pointer_cast((*visibleGeometryIter)->GetInterpreter(e_SystemType_Graphics)); // add buffers to visible geometry queue interpreter->GetVertexBufferQueue(caller->shadowMaps.at(index).visibleGeometry); diff --git a/third_party/gfootball_engine/src/systems/graphics/rendering/opengl_renderer3d.cpp b/third_party/gfootball_engine/src/systems/graphics/rendering/opengl_renderer3d.cpp index 91cd9b61..b3707750 100644 --- a/third_party/gfootball_engine/src/systems/graphics/rendering/opengl_renderer3d.cpp +++ b/third_party/gfootball_engine/src/systems/graphics/rendering/opengl_renderer3d.cpp @@ -75,10 +75,6 @@ OpenGLRenderer3D::OpenGLRenderer3D() { OpenGLRenderer3D::~OpenGLRenderer3D() { DO_VALIDATION; - DeleteSimpleVertexBuffer(overlayBuffer); - DeleteSimpleVertexBuffer(quadBuffer); - // Shut down all SDL subsystems - SDL_Quit(); }; void OpenGLRenderer3D::SwapBuffers() { @@ -600,6 +596,8 @@ void OpenGLRenderer3D::Exit() { } currentShader = shaders.end(); + DeleteSimpleVertexBuffer(overlayBuffer); + DeleteSimpleVertexBuffer(quadBuffer); // assert(views.size() == 0); } @@ -1946,12 +1944,20 @@ bool OpenGLRenderer3D::CheckFrameBufferStatus() { void OpenGLRenderer3D::SetRenderTargets( std::vector targetAttachments) { DO_VALIDATION; +#ifdef WIN32 + std::vector targets(targetAttachments.size()); +#else GLenum targets[targetAttachments.size()]; +#endif for (int i = 0; i < (signed int)targetAttachments.size(); i++) { DO_VALIDATION; targets[i] = GetGLTargetAttachment(targetAttachments[i]); } +#ifdef WIN32 + mapping.glDrawBuffers(targetAttachments.size(), &targets[0]); +#else mapping.glDrawBuffers(targetAttachments.size(), targets); +#endif } // utility @@ -2034,8 +2040,13 @@ void GeneratePoissonKernel(float *kernel, unsigned int kernelSize) { DO_VALIDATION; unsigned int candidateSize = 32; +#ifdef WIN32 + std::vector samples(kernelSize); + std::vector candidates(candidateSize); +#else Vector3 samples[kernelSize]; Vector3 candidates[candidateSize]; +#endif for (unsigned int i = 0; i < kernelSize; i++) { DO_VALIDATION; @@ -2103,8 +2114,11 @@ void GeneratePoissonKernel(float *kernel, unsigned int kernelSize) { } } else { // PRECALCULATED SET - +#ifdef WIN32 + std::vector samples(kernelSize); +#else Vector3 samples[kernelSize]; +#endif // these samples seem relatively close to z = 0 (much 'ground effect' on // flat surface) @@ -2258,7 +2272,11 @@ void OpenGLRenderer3D::LoadShader(const std::string &name, unsigned int kernelSize = 32; // SetUniformInt("ambient", "SSAO_kernelSize", kernelSize); +#ifdef WIN32 + std::vector SSAO_kernel(kernelSize * 3); +#else float SSAO_kernel[kernelSize * 3]; +#endif GeneratePoissonKernel(&SSAO_kernel[0], kernelSize); SetUniformFloat3Array("ambient", "SSAO_kernel", kernelSize, &SSAO_kernel[0]); diff --git a/third_party/gfootball_engine/src/utils/gui2/widgets/image.cpp b/third_party/gfootball_engine/src/utils/gui2/widgets/image.cpp index 61d6ad04..86f0ccc1 100644 --- a/third_party/gfootball_engine/src/utils/gui2/widgets/image.cpp +++ b/third_party/gfootball_engine/src/utils/gui2/widgets/image.cpp @@ -23,15 +23,23 @@ #include "../windowmanager.hpp" #include "file.h" +#ifdef WIN32 +#include +#endif + namespace blunted { SDL_Surface *IMG_LoadBmp(const std::string &file) { DO_VALIDATION; std::string name = GetGameConfig().updatePath(file); name = name.substr(0, name.length() - 4) + ".bmp"; +#ifdef WIN32 + auto image = IMG_Load(name.c_str()); +#else std::string file_data = GetFile(name); SDL_RWops *rw = SDL_RWFromConstMem(file_data.data(), file_data.size()); auto image = SDL_LoadBMP_RW(rw, 1); +#endif if (image->format->format == SDL_PIXELFORMAT_ARGB8888) { DO_VALIDATION; diff --git a/third_party/gfootball_engine/vcpkg_manifests/py3.6/vcpkg.json b/third_party/gfootball_engine/vcpkg_manifests/py3.6/vcpkg.json new file mode 100644 index 00000000..ef6b8caa --- /dev/null +++ b/third_party/gfootball_engine/vcpkg_manifests/py3.6/vcpkg.json @@ -0,0 +1,22 @@ +{ + "name": "gfootball-engine", + "version-string": "2.10", + "builtin-baseline": "025e564979cc01d0fbc5c920aa8a36635efb01bb", + "dependencies": [ + "python3", + "boost-thread", + "boost-filesystem", + "boost-signals2", + "boost-circular-buffer", + "boost-interprocess", + "boost-python", + "sdl2", + "sdl2-image", + "sdl2-ttf", + "sdl2-gfx", + "opengl" + ], + "overrides": [ + { "name": "python3", "version-string": "3.6.4-5" } + ] +} diff --git a/third_party/gfootball_engine/vcpkg_manifests/py3.7/vcpkg.json b/third_party/gfootball_engine/vcpkg_manifests/py3.7/vcpkg.json new file mode 100644 index 00000000..433f712b --- /dev/null +++ b/third_party/gfootball_engine/vcpkg_manifests/py3.7/vcpkg.json @@ -0,0 +1,22 @@ +{ + "name": "gfootball-engine", + "version-string": "2.10", + "builtin-baseline": "025e564979cc01d0fbc5c920aa8a36635efb01bb", + "dependencies": [ + "python3", + "boost-thread", + "boost-filesystem", + "boost-signals2", + "boost-circular-buffer", + "boost-interprocess", + "boost-python", + "sdl2", + "sdl2-image", + "sdl2-ttf", + "sdl2-gfx", + "opengl" + ], + "overrides": [ + { "name": "python3", "version-string": "3.7.3-3" } + ] +} diff --git a/third_party/gfootball_engine/vcpkg_manifests/py3.8/vcpkg.json b/third_party/gfootball_engine/vcpkg_manifests/py3.8/vcpkg.json new file mode 100644 index 00000000..6ea3fc8f --- /dev/null +++ b/third_party/gfootball_engine/vcpkg_manifests/py3.8/vcpkg.json @@ -0,0 +1,22 @@ +{ + "name": "gfootball-engine", + "version-string": "2.10", + "builtin-baseline": "025e564979cc01d0fbc5c920aa8a36635efb01bb", + "dependencies": [ + "python3", + "boost-thread", + "boost-filesystem", + "boost-signals2", + "boost-circular-buffer", + "boost-interprocess", + "boost-python", + "sdl2", + "sdl2-image", + "sdl2-ttf", + "sdl2-gfx", + "opengl" + ], + "overrides": [ + { "name": "python3", "version-string": "3.8.3", "port-version": 2 } + ] +} diff --git a/third_party/gfootball_engine/vcpkg_manifests/py3.9/vcpkg.json b/third_party/gfootball_engine/vcpkg_manifests/py3.9/vcpkg.json new file mode 100644 index 00000000..e4b9d2bd --- /dev/null +++ b/third_party/gfootball_engine/vcpkg_manifests/py3.9/vcpkg.json @@ -0,0 +1,22 @@ +{ + "name": "gfootball-engine", + "version-string": "2.10", + "builtin-baseline": "025e564979cc01d0fbc5c920aa8a36635efb01bb", + "dependencies": [ + "python3", + "boost-thread", + "boost-filesystem", + "boost-signals2", + "boost-circular-buffer", + "boost-interprocess", + "boost-python", + "sdl2", + "sdl2-image", + "sdl2-ttf", + "sdl2-gfx", + "opengl" + ], + "overrides": [ + { "name": "python3", "version-string": "3.9.6" } + ] +}