Skip to content
Snippets Groups Projects
Commit f6c022ad authored by Armin Co's avatar Armin Co
Browse files

Merge branch 'master' into feature_config

parents f4ff95e2 54680e76
No related branches found
No related tags found
No related merge requests found
Showing
with 93 additions and 47 deletions
[submodule "libs/googletest"]
path = libs/googletest
url = https://github.com/google/googletest.git
## CMake file for the Q-Pong game.
##
project(QuantumPong)
# CMake file for the QPong project.
project(QPong)
cmake_minimum_required(VERSION 3.2)
## Use modern C++!
# Options
option(create_test "Build all tests." OFF)
option(release_type "Set the type of the releas (Debug/Release)." Release)
# Use modern C++!
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_BUILD_TYPE Release)
## PkgConfig
find_package(PkgConfig REQUIRED)
message(" - Build type is set to ${CMAKE_BUILD_TYPE}")
add_subdirectory(
src
)
# @todo Check versions of glib etc. librarys.
# On Ubuntu 19.10 there are warnings which are not present in Ubuntu 18.04
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
# Add qpong lib for core qpong functionality
add_subdirectory(qpong_core)
include_directories(qpong_core)
# Add dir with gtk qpong app
add_subdirectory(gtk_qpong_app)
# Add some unit tests
# not many yet ^^
if (create_test)
add_subdirectory(libs/googletest)
add_subdirectory(tests)
endif()
......@@ -25,6 +25,12 @@ make
````
## TODOS
- ImageBuffer in die Klasse Particle ziehen,
- Methoden bereitstellen zum Abrufen der ImageBuffer
- ParticleImage muss das Particle Objekt kennen, um die ImageBuffer abrufen zu können.
- Umbauen der Klasse Particle zu einer Klasse Simulation Environemnt
## Erweiterungsideen
- Konfiguration über die GUI, evt. mit speichern
- Spalt & Interferenz
......
# library for the app should be GTK independent
add_library(qpong
Particle.cpp
ImageBuffer.cpp
QPlayer.cpp
Profiler.cpp
Config.cpp
)
# Specific settings for macOS
if(APPLE)
link_directories("/usr/local/lib")
message("ATTENTION: You probably have to export the PKG_CONFIG_PATH.")
message("For example: export PKG_CONFIG_PATH=\"/usr/local/lib:/usr/local/opt/zlib/lib/pkgconfig\"")
endif()
# Setup GTK configuration
pkg_check_modules(GTKMM gtkmm-3.0)
link_directories(${GTKMM_LIBRARY_DIRS})
# get all GTKMM dependencies and configuration
include_directories(${GTKMM_INCLUDE_DIRS})
if(APPLE)
include_directories(/usr/local/include)
endif()
# @todo Check versions of glib etc. librarys.
# On Ubuntu 19.10 there are warnings which are not present in Ubuntu 18.04
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
# create the application
add_executable( qpong.app
......@@ -23,15 +31,10 @@ add_executable(qpong.app
# we do need some threads
find_package(Threads)
# get all GTKMM dependencies and configuration
pkg_check_modules(GTKMM gtkmm-3.0)
link_directories(${GTKMM_LIBRARY_DIRS})
include_directories(${GTKMM_INCLUDE_DIRS})
# link all necessary libs to the target
target_link_libraries( qpong.app
qpong
qpong_core
${CMAKE_THREAD_LIBS_INIT}
${GTKMM_LIBRARIES}
fftw3
......
///
/// @brief
///
......
File moved
File moved
......@@ -4,9 +4,10 @@
///
#include "ParticleImage.hpp"
#include "Profiler.hpp"
#include "Common.hpp"
using namespace QPong;
constexpr int bytesPerPixel = 3;
constexpr int bitsPerSample = 8;
......
......@@ -13,10 +13,11 @@
#include "ImageBuffer.hpp"
/// @brief Wraps an one dimensional array.
/// Values can be accessed as in 2D.
///
class ParticleImage : public ImageBuffer
class ParticleImage : public QPong::ImageBuffer
{
public:
ParticleImage();
......
......@@ -5,21 +5,25 @@
#include "QDrawingArea.hpp"
QDrawingArea::QDrawingArea()
{
m_dispatcher.connect(sigc::mem_fun(*this, &QDrawingArea::queue_draw));
}
void QDrawingArea::redraw()
{
m_dispatcher.emit();
}
void QDrawingArea::setPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf)
{
m_image = pixbuf;
}
bool QDrawingArea::on_draw(const Cairo::RefPtr<Cairo::Context> &cr)
{
cr->save();
......
File moved
......@@ -4,8 +4,8 @@
#include "QWindow.hpp"
#include "Profiler.hpp"
#include "Config.hpp"
using namespace QPong;
bool propagating = true;
int propRate = 0;
......@@ -28,16 +28,16 @@ void QWindow::simulation()
propRate = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count();
if (qPressed)
m_players[Player::One]->move(Direction::Up);
m_players[Player::Id::One]->move(Player::Direction::Up);
if (aPressed)
m_players[Player::One]->move(Direction::Down);
m_players[Player::Id::One]->move(Player::Direction::Down);
if (upPressed)
m_players[Player::Two]->move(Direction::Up);
m_players[Player::Id::Two]->move(Player::Direction::Up);
if (downPressed)
m_players[Player::Two]->move(Direction::Down);
m_players[Player::Id::Two]->move(Player::Direction::Down);
// Limit the speed of the simulation.
auto dt = std::chrono::system_clock::now() - start;
......@@ -59,7 +59,7 @@ void render(QWindow *w)
{
using namespace std::chrono_literals;
auto start = std::chrono::system_clock::now();
std::this_thread::sleep_for(20ms);
std::this_thread::sleep_for(15ms);
w->updateView();
renderRate = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count();
} while (true);
......@@ -75,8 +75,8 @@ QWindow::QWindow()
constexpr double playerOneStartX = -0.7;
constexpr double playerTwoStartX = 0.7;
m_players.insert(std::make_pair<Player, std::shared_ptr<QPlayer>>(Player::One, std::make_shared<QPlayer>(Player::One, Position{-0.7, 0})));
m_players.insert(std::make_pair<Player, std::shared_ptr<QPlayer>>(Player::Two, std::make_shared<QPlayer>(Player::Two, Position{ 0.7, 0.4})));
m_players.insert(std::make_pair<Player::Id, std::shared_ptr<Player>>(Player::Id::One, std::make_shared<Player>(Player::Id::One, Player::Position{-0.7, 0})));
m_players.insert(std::make_pair<Player::Id, std::shared_ptr<Player>>(Player::Id::Two, std::make_shared<Player>(Player::Id::Two, Player::Position{ 0.7, 0.4})));
m_momentum = new ParticleImage;
m_position = new ParticleImage;
......@@ -147,7 +147,7 @@ void QWindow::updateGui()
ss = std::stringstream();
ss << "Score Player 1: ";
auto score = m_players[Player::One]->getScore();
auto score = m_players[Player::Id::One]->getScore();
ss << std::setprecision(2) << std::setw(7) << score << "%";
if (score > 50.0)
{
......@@ -158,7 +158,7 @@ void QWindow::updateGui()
ss = std::stringstream();
ss << "Score Player 2: ";
score = m_players[Player::Two]->getScore();
score = m_players[Player::Id::Two]->getScore();
ss << std::setprecision(2) << std::setw(7) << score << "%";
if (score > 50.0)
{
......
......@@ -72,13 +72,13 @@ private:
QDrawingArea m_positionArea;
QDrawingArea m_momentumArea;
Particle *m_particle;
QPong::Particle *m_particle;
std::thread m_propagatingThread;
ParticleImage *m_momentum;
ParticleImage *m_position;
ParticleImage *m_obstacle;
std::map<Player, std::shared_ptr<QPlayer>> m_players;
std::map<QPong::Player::Id, std::shared_ptr<QPong::Player>> m_players;
};
#endif
\ No newline at end of file
File moved
File moved
Subproject commit 8b4817e3df3746a20502a84580f661ac448821be
Subproject commit dcc92d0ab6c4ce022162a23566d44f673251eee4
# Add macOS specific include path.
if(APPLE)
include_directories(/usr/local/include)
endif()
# Core QPong library
add_library(qpong_core Particle.cpp ImageBuffer.cpp Player.cpp)
\ No newline at end of file
File moved
......@@ -5,6 +5,8 @@
#include "Common.hpp"
#include "ImageBuffer.hpp"
using namespace QPong;
ImageBuffer::ImageBuffer()
{
m_potbuf = new double[QPong::arraySize];
......@@ -28,11 +30,11 @@ const QColor ImageBuffer::getValue(unsigned index)
QColor c {
static_cast<float>(obs + r*r), //< red
static_cast<float>(r*r + i*i + obs/2), //< green
static_cast<float>(r*r + i*i + obs/1.5), //< green
static_cast<float>(i*i) //< blue
};
constexpr double max = 0.83;
constexpr double max = 0.81;
if (c.r > max)
{
c.r = max;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment