Skip to content

Commit

Permalink
Render engine, closes #26 (#66)
Browse files Browse the repository at this point in the history
* add renderer sfml - prework

* add renderer sfml - prework 2

* add renderer sfml - prework 3

* rework sfml renderer and add gmock

* something is wrong...

* something is wrong... v2

* save it

* it works...partially

* add examples

* try fix window compilation

* add sfml lib dir for appveyor

* try fix linux compilation

* try fix linux compilation - add this

* add factory

* reorganize files

* Reorganize directories and replace math structures by own

* Reorganize directories part two

* cmake make global standard requirements

* fix std14 standard for linux

* ut

* update glm from 0.9.5.3 to 0.9.9-a1

* update GSL to master

* update range-v3 from 0.2.1 to 0.3.0

* update docs

* ut

* fix dependency

* fix dependency

* external up

* refactoring example

* refactoring

* fix warnings

* merge master fix

* not working yet, but commit need to be done

* still in progress

* add Window to graphics

* remove disabling warning

* update imgs

* fix sfml enum in test

* add boost operator

* update docs

* update ClassDiagram md

* appveyor show lib lis

* review fix

* fix appveyor

* merge with master part two

* fix window crash

* fix warnings

* fix test coverage linker

* make coverage global

* delete src directory and update docs

* add window test suites

* sneaking around

* sneaking around

* sneaking around

* sneaking around

* sneaking around

* sneaking around

* sneaking around

* sneaking around

* fix not overriden virtual function

* boost boost

* fix unused-template

* fix game ut compilation

* fix and restore game ut

* introduce math lib to physics interface

* fix physics cmake

* try to disable coverage for facade function

* try to disable coverage for facade function

* change SfmlRenderTarget to template class and create stub for testing purpose
  • Loading branch information
Abergard authored and kn65op committed Feb 1, 2018
1 parent 716f0db commit 706f848
Show file tree
Hide file tree
Showing 89 changed files with 1,653 additions and 291 deletions.
36 changes: 20 additions & 16 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
os: Visual Studio 2015
os: Visual Studio 2017

build:
verbosity: detailed
Expand All @@ -24,23 +24,29 @@ platform:
- x64

install:
- set NINJA_URL="https://github.com/ninja-build/ninja/releases/download/v1.6.0/ninja-win.zip"
- set NINJA_URL="https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-win.zip"
- set SFML_URL="https://www.sfml-dev.org/files/SFML-2.4.2-windows-vc14-64-bit.zip"
- set DEPS_DIR=C:\projects\deps

- if not exist C:\projects\deps (
mkdir C:\projects\deps &&
cd C:\projects\deps &&
- if not exist %DEPS_DIR% (
mkdir %DEPS_DIR% &&
cd %DEPS_DIR% &&
appveyor DownloadFile %NINJA_URL% -FileName ninja.zip &&
appveyor DownloadFile %SFML_URL% -FileName sfml.zip &&
7z x ninja.zip -oC:\projects\deps\ninja > nul &&
7z x sfml.zip -oC:\projects\deps\sfml > nul)

- set PATH=C:\projects\deps\ninja;%PATH%
- set PATH=C:\projects\deps\sfml\SFML-2.4.2\bin;%PATH%
- set PATH="C:\Program Files\LLVM\bin";%PATH%
- set INCLUDE=%INCLUDE%;C:\Libraries\boost_1_63_0
- set LIB=%LIB%;C:\Libraries\boost_1_63_0

7z x ninja.zip -o%DEPS_DIR%\ninja > nul &&
7z x sfml.zip -o%DEPS_DIR%\sfml > nul)

- set BOOST_LIB=C:\Libraries\boost_1_65_1
- set SFML_DIR=%DEPS_DIR%\sfml\SFML-2.4.2
- set SFML_LIB=%SFML_DIR%\lib
- set SFML_BIN=%SFML_DIR%\bin
- set NINJA_BIN=%DEPS_DIR%\ninja

- set PATH=%NINJA_BIN%;%PATH%
- set PATH=%SFML_BIN%;%PATH%
- set INCLUDE=%INCLUDE%;%BOOST_LIB%
- set LIB=%LIB%;%BOOST_LIB%;%SFML_LIB%

- ninja --version
- clang-cl -v

Expand All @@ -62,5 +68,3 @@ build_script:
test_script:
- ps: |
& ctest -V -j nproc
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ CMakeScripts
cmake_install.cmake
install_manifest.txt
CTestTestfile.cmake

TAGS

# Compiled Object files
*.slo
*.lo
Expand Down
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ matrix:
# Build steps
script:
- mkdir boost-dl; cd boost-dl
- wget https://sourceforge.net/projects/boost/files/boost/1.62.0/boost_1_62_0.tar.bz2
- tar --bzip2 -xf ./boost_1_62_0.tar.bz2
- sudo mv ./boost_1_62_0/boost /usr/include
- wget https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.bz2
- tar --bzip2 -xf ./boost_1_65_1.tar.bz2
- sudo mv ./boost_1_65_1/boost /usr/include
- cd ..
- mkdir build
- cd build
- env CC=${C_COMPILER} CXX=${CXX_COMPILER} cmake .. -DENABLE_COVERAGE:BOOL=TRUE
- echo "We have" `nproc` "cores here"
- make -j `nproc`
- ctest -j `nproc` -V

after_success:
- bash <(curl -s https://codecov.io/bash)
70 changes: 33 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
cmake_minimum_required (VERSION 2.8.11)
project("bomberman")
cmake_minimum_required (VERSION 3.2.2)
project("bomberman" CXX)

set(CMAKE_CXX_EXTENSIONS OFF)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})
set(EXTERNAL_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/external")
set(GLM_INCLUDE_DIR "${EXTERNAL_INCLUDE_DIR}/glm/")
set(RANGEV3_INCLUDE_DIR "${EXTERNAL_INCLUDE_DIR}/range-v3/include/")
set(FAKEIT_INCLUDE_DIR "${EXTERNAL_INCLUDE_DIR}/fakeit/single_header/gtest/")
set(GSL_INCLUDE_DIR "${EXTERNAL_INCLUDE_DIR}/GSL/include")
set(GMOCK_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/external/googletest/googlemock/include")
set(GTEST_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/external/googletest/googletest/include")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGSL_THROW_ON_CONTRACT_VIOLATION")

enable_testing()

add_subdirectory(external/googletest/)

if(${WIN32})
include(${CMAKE_SOURCE_DIR}/cmake/platforms/Windows.cmake)
else()
include(${CMAKE_SOURCE_DIR}/cmake/platforms/Linux.cmake)
endif()

find_package(SFML 2 COMPONENTS system window graphics network audio)

if(SFML_FOUND)
enable_testing()

set(GLM_INCLUDE_DIR "${EXTERNAL_INCLUDE_DIR}/glm/")
set(RANGEV3_INCLUDE_DIR "${EXTERNAL_INCLUDE_DIR}/range-v3/include/")
set(FAKEIT_INCLUDE_DIR "${EXTERNAL_INCLUDE_DIR}/fakeit/single_header/gtest/")
set(GSL_INCLUDE_DIR "${EXTERNAL_INCLUDE_DIR}/GSL/include")
set(GMOCK_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/external/googletest/googlemock/include")
set(GTEST_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/external/googletest/googletest/include")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGSL_THROW_ON_CONTRACT_VIOLATION")

add_subdirectory(external/googletest)

if(${WIN32})
include(${CMAKE_SOURCE_DIR}/cmake/platforms/Windows.cmake)
else()
include(${CMAKE_SOURCE_DIR}/cmake/platforms/Linux.cmake)
endif()

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
include(${CMAKE_SOURCE_DIR}/cmake/compilators/Clang.cmake)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
include(${CMAKE_SOURCE_DIR}/cmake/compilators/Msvc.cmake)
else()
include(${CMAKE_SOURCE_DIR}/cmake/compilators/Gcc.cmake)
endif()

include_directories(SYSTEM ${RANGEV3_INCLUDE_DIR})
include_directories(SYSTEM ${SFML_INCLUDE_DIR})
include_directories(SYSTEM ${GSL_INCLUDE_DIR})
include_directories(SYSTEM ${GLM_INCLUDE_DIR})

add_subdirectory(src)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
include(${CMAKE_SOURCE_DIR}/cmake/compilators/Clang.cmake)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
include(${CMAKE_SOURCE_DIR}/cmake/compilators/Msvc.cmake)
else()
include(${CMAKE_SOURCE_DIR}/cmake/compilators/Gcc.cmake)
endif()

include_directories(SYSTEM ${RANGEV3_INCLUDE_DIR})
include_directories(SYSTEM ${GSL_INCLUDE_DIR})
include_directories(SYSTEM ${GLM_INCLUDE_DIR})

add_subdirectory(src)
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# bomberman
Repo for bomberman

[![Build Status](https://travis-ci.org/NadzwyczajnaGrupaRobocza/bomberman.svg?branch=master)](https://travis-ci.org/NadzwyczajnaGrupaRobocza/bomberman)[![Build status](https://ci.appveyor.com/api/projects/status/60vqqan3qtj4eu35/branch/master?svg=true)](https://ci.appveyor.com/project/Abergard/bomberman/branch/master)[![codecov](https://codecov.io/gh/NadzwyczajnaGrupaRobocza/bomberman/branch/master/graph/badge.svg)](https://codecov.io/gh/NadzwyczajnaGrupaRobocza/bomberman)
3 changes: 2 additions & 1 deletion cmake/platforms/Linux.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
message(STATUS "Detected GNU CXX compiler.")
message(STATUS "Detected Linux kind system.")

option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" FALSE)

if(${ENABLE_COVERAGE})
add_compile_options(--coverage -O0)
link_libraries(--coverage)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
3 changes: 3 additions & 0 deletions docs/04-ClassDiagram.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Class diagram

## All
![ClassDiagramImage](./img/class_diagram.png)

## Graphics
![GraphicsClassDiagramImage](./img/class_diagram_graphics.png)
Binary file modified docs/img/Activity_2_1_BombLauncher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/Activity_2_2_Bomb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/Activity_2_2_BombLauncher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/Activity_2_2_Explosion.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/Activity_3_2_PhysicsEngine.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/Communication_UC_1_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/Communication_UC_1_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/Communication_UC_2_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/Communication_UC_2_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/Communication_UC_2_3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/UC_1_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/UC_1_3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/UC_1_4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/UC_2_1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/UC_2_2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/UC_2_3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/class_diagram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/class_diagram_graphics.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/domain_model.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/graphical_layer_domain_model.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/main_state_changes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/move_update_loop.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/player_seq.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 34 additions & 17 deletions docs/uml_src/class_diagram.uml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
@startuml

namespace graphics{
interface RendererPool{
+ RendererId acquire(const math::Size2f&, const math::Position2f&)
+ void release(const RendererId&)
+ void render_all()
+ void set_position(const RendererId&, const math::Position2f&)
+ Position get_position(const RendererId&)
}
interface Window{
+ bool is_open()
+ void display()
+ void update()
}
class RendererId
}

interface Entity {
+ update(delta_time)
+ bool areYouDead()
Expand All @@ -8,23 +24,26 @@ interface Entity {
class Bomberman {
- phys_id : PhysId
- physics_engine : PhysicsEngine&
- render_id : RenderId
- render_engine : RenderEngine&
- renderer_id : graphics::RendererId
- renderer_pool : graphics::RendererPool&
- human_player : HumanPlayer
- bomb_launcher : BombLauncher
}
Bomberman o-- graphics.RendererPool
Bomberman *-- graphics.RendererId

class GameWorld {
- bomberman : Entity
- map : Map
- physics_engine : std::unique_ptr<PhysicsEngine>
- render_engine : std::unique_ptr<RenderEngine>
- renderer_pool : std::unique_ptr<graphics::RendererPool>
- bombs : std::vector<Bomb>
- explosions : std::vector<Explosion>
+ bool is_bomb_at_pos(Vector2D position)
+ create_bomb(Vector2D position, int timeToExplode)
+ create_explosion(Vector2D povesition)
}
GameWorld o-down- graphics.RendererPool

class HumanPlayer {
+ Vector2D get_direction()
Expand All @@ -40,12 +59,14 @@ class BombLauncher {
}

class Map {
- background : RenderId
- background : graphics::RendererId
- static_element : std::vector<PhysId>
- render_engine : RenderEngine&
- renderer_pool : graphics::RendererPool&
- physics_engine : PhysicsEngine&
+ ExplosionRange : get_explosion_range(const std::pair<int, int>, int)
}
Map o-- graphics.RendererPool
Map *-- graphics.RendererId

class PhysicsEngine{
+ void set_position(PhysId id, Vector2D position)
Expand All @@ -54,25 +75,23 @@ class PhysicsEngine{
+ PhysicId register_colider(const math::vec2d&, const math::vec2d&)
}

class RenderEngine{
+ void set_position(RenderId id, Vector2D position)
+ void render()
+ RenderId register_rendarable(const math::vec2d&, const math:::vec2d&)
}

class Bomb {
- phys_id : PhysId
- render_id : RenderId
- render_engine : RenderEngine&
- renderer_id : graphics::RendererId
- physics_engine : PhysicsEngine&
- renderer_pool : RendererPool&
}
Bomb o-- graphics.RendererPool
Bomb *-- graphics.RendererId

class Explosion {
- renderer_ids : std::vector<graphics::RendererId>
- phys_ids : std::vector<PhysId>
- render_ids : std::vector<RenderId>
- render_engine : RenderEngine&
- physics_engine : PhysicsEngine&
- renderer_pool : graphics::RendererPool&
}
Explosion o-- graphics.RendererPool
Explosion *-- graphics.RendererId

Bomberman --|> Entity
Bomb --|> Entity
Expand All @@ -87,10 +106,8 @@ HumanPlayer --* Bomberman
BombLauncher --> GameWorld
BombLauncher --* Bomberman


Map --* GameWorld

RenderEngine --* GameWorld
PhysicsEngine --* GameWorld

@enduml
86 changes: 86 additions & 0 deletions docs/uml_src/class_diagram_graphics.uml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
@startuml

namespace sf{
class RectangleShape
class Window
abstract class RenderTarget
}

namespace graphics {
package public <<Rectangle>> {

interface RendererPool{
+ RendererId acquire(const math::Size2f&, const math::Position2f&)
+ void release(const RendererId&)
+ void render_all()
+ void set_position(const RendererId&, const math::Position2f&)
+ Position get_position(const RendererId&)
}
interface Window{
+ bool is_open()
+ void display()
+ void update()
}
class RendererId
}
package private <<Rectangle>> {

package types{
math.Position2f <|-- Position2f
math.Size2f <|-- Size2f
math.Size2u <|-- WindowSize
}

package sfml_adaptors <<Rectangle>> {

interface SfmlWindow{
+ bool is_open()
+ void display()
+ bool poll_event(sf::Event&)
+ void close()
+ void create(sf::VideoMode, const sf::String& title)
}

class SfmlWindowFacade
SfmlWindowFacade --|> SfmlWindow
SfmlWindowFacade *-down- sf.Window

class SfmlRenderTarget
SfmlRenderTarget -down-|> sf.RenderTarget


class SfmlRectangleShape{
+ Position2f getPosition()
+ Size2f getSize()
}
SfmlRectangleShape --|> sf.RectangleShape

}
class WindowSfml
WindowSfml --|> Window
WindowSfml *-- SfmlWindow

interface ContextRenderer{
+ initialize()
+ clear(const sf::Color&)
+ draw(const SfmlRectangleShape&)
}
ContextRenderer --> SfmlRectangleShape
ContextRenderer <|-- SfmlRenderTarget

class RendererPoolSfml{
}
RendererPoolSfml --|> RendererPool
RendererPoolSfml o-- RendererId
RendererPoolSfml o-- SfmlRectangleShape
RendererPoolSfml *-- RendererIdGenerator
RendererPoolSfml *-- ContextRenderer

class RendererIdGenerator
RendererIdGenerator --> RendererId
}


}

@enduml
2 changes: 1 addition & 1 deletion external/glm
Submodule glm updated 1052 files
2 changes: 1 addition & 1 deletion external/range-v3
Submodule range-v3 updated 211 files

0 comments on commit 706f848

Please sign in to comment.