Merge branch 'dev' into 'master'

Final Merge

See merge request link/projekte/ws19/vkvm-new/demo!3
This commit is contained in:
Julian Hinxlage 2020-01-09 06:51:53 +00:00
commit cb6a8f4b10
20 changed files with 290 additions and 23 deletions

32
.ci/clang-tidy.sh Normal file
View File

@ -0,0 +1,32 @@
#!/bin/sh
echo "Doing clang-tidy..."
bool=false
# explicitly set IFS to contain only a line feed
IFS='
'
filelist="$(find . -not \( -path './*build*' -prune \) -not \( -path './include' -prune \) -type f ! -name "$(printf "*\n*")")"
for file in $filelist; do
if echo "$file" | grep -q -E ".*(\.cpp|\.hpp)$" ; then
#Extra check missing dependencies due to clang-tidy doesn't toggle exit code.
clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' "$file" -- -I. -std=c++14 2>&1)"
for tidy_line in $clang_tidy_lib_check; do
echo "$tidy_line" | grep -q -v -E "^Error while processing*"
if [ $? -eq 1 ]; then
bool=true
fi
echo "$tidy_line" | grep -q -v -E ".* error: .*"
if [ $? -eq 1 ]; then
bool=true
fi
echo "$tidy_line"
done
fi
done
if $bool; then
exit 1
else
echo "No clang-tidy errors found."
fi
exit 0

2
.clang-tidy Normal file
View File

@ -0,0 +1,2 @@
Checks: '*,-llvm-header-guard,-fuchsia*,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init,-google-readability-namespace-comments,-llvm-namespace-comment,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-modernize-use-trailing-return-type,-clang-diagnostic-error'
WarningsAsErrors: 'true'

76
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,76 @@
---
image: samueldebruyn/debian-git:latest
stages:
- style
- test
- build
clang_tidy:
image: joethei/clang_tidy
stage: style
tags:
- docker-ci
script:
- mkdir current
- ls -d .[!.]* | grep -v current | xargs mv -t current
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.repo.digitech.hs-emden-leer.de/link/projekte/ws19/vkvm-new/library.git
- mkdir library/build
- cd library/build
- cmake ..
- make
- cd ../../current/.ci
- sh clang-tidy.sh
make_test:
stage: test
tags:
- docker-ci
script:
- apt-get update
- apt-get install -y clang make cmake clang-tidy
- mkdir current
- ls | grep -v current | xargs mv -t current
- git clone https://github.com/catchorg/Catch2.git
- cd Catch2
- cmake -Bbuild -H. -DBUILD_TESTING=OFF
- cmake --build build/ --target install
- cd ..
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.repo.digitech.hs-emden-leer.de/link/projekte/ws19/vkvm-new/library.git
- mkdir library/build
- cd library/build
- cmake ..
- make
- cd ../../current
- mkdir build
- cd build
- cmake ..
- make
- make test
cmake_build:
stage: build
tags:
- docker-ci
script:
- apt-get update
- apt-get install -y clang make cmake clang-tidy
- mkdir current
- ls | grep -v current | xargs mv -t current
- git clone https://github.com/catchorg/Catch2.git
- cd Catch2
- cmake -Bbuild -H. -DBUILD_TESTING=OFF
- cmake --build build/ --target install
- cd ..
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.repo.digitech.hs-emden-leer.de/link/projekte/ws19/vkvm-new/library.git
- mkdir library/build
- cd library/build
- cmake ..
- make
- cd ../../current
- mkdir build
- cd build
- cmake ..
- make

View File

@ -8,15 +8,19 @@ if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
endif() endif()
set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "bin" "doc" "CMakeFiles" "lib" "include") set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "bin" "doc" "CMakeFiles" "lib" "include")
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
project(Demo) project(Demo)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
# enable clang_tidy # enable clang_tidy
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*") set(CMAKE_CXX_CLANG_TIDY clang-tidy;-header-filter=.;)
set(CMAKE_CXX_CLANG_TIDY clang-tidy;-header-filter=.;-checks=*;)
file(GLOB_RECURSE SOURCES src/*.cpp) file(GLOB_RECURSE SOURCES src/*.cpp)
file(GLOB_RECURSE HEADERS src/*.h) file(GLOB_RECURSE HEADERS src/*.hpp)
file(GLOB_RECURSE TESTS test/*.cpp) file(GLOB_RECURSE TESTS test/*.cpp)
set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library")
@ -30,6 +34,7 @@ target_link_libraries(Demo ${LIB_PATH}/lib/liblibrary.a)
enable_testing() enable_testing()
find_package(Catch2 REQUIRED) find_package(Catch2 REQUIRED)
add_executable(UnitTests ${SOURCES} ${HEADERS} ${TESTS}) add_executable(UnitTests ${SOURCES} ${HEADERS} ${TESTS})
target_link_libraries(UnitTests ${LIB_PATH}/lib/liblibrary.a)
target_link_libraries(UnitTests Catch2::Catch2) target_link_libraries(UnitTests Catch2::Catch2)
include(CTest) include(CTest)

View File

@ -1,5 +1 @@
#include "../src/demo.h" #include "../src/Bitmap.hpp" #include "../src/MathFunctions.hpp" #include "vkvm.hpp" #include "internal.hpp" #include <unistd.h> //time to sleep for in seconds constexpr int sleepTime = 3; void displayImage(const std::string &file, vkvm::GraphicMode graphicMode) { vkvm::setMode(graphicMode); Bitmap image(file); vkvm::setWidth(image.getWidth()); vkvm::setHeight(image.getHeight()); for (int x = 0; x < vkvm::getWidth(); x++) { for (int y = 0; y < vkvm::getHeight(); y++) { unsigned int hex = image.getPixel(x, y); vkvm::Color color = vkvm::Color(hex); vkvm::setPixel(x, y, color); } } } void setColor(vkvm::Color color) { for (int x = 0; x < vkvm::getWidth(); ++x) { for (int y = 0; y < vkvm::getHeight(); ++y) { vkvm::setPixel(x, y, color); } } } void displayImage(const std::string &file) { displayImage(file, vkvm::GraphicMode::RGB); sleep(sleepTime); vkvm::setMode(vkvm::GraphicMode::Gray_256); sleep(sleepTime); vkvm::setMode(vkvm::GraphicMode::TwoColors); sleep(sleepTime); } int main() { bool running = true; vkvm::initialize(0); while(running) { displayImage("../res/P6.bmp"); sleep(sleepTime); vkvm::setBackgroundColor(vkvm::red); vkvm::setForegroundColor(vkvm::blue); sleep(sleepTime); vkvm::setBackgroundColor(vkvm::black); vkvm::setForegroundColor(vkvm::white); displayImage("../res/P8.bmp"); displayImage("../res/P9.bmp"); displayImage("../res/P10.bmp"); vkvm::setText("Hello World"); sleep(sleepTime); vkvm::setFont(vkvm::FontType::FuturisticBlack); vkvm::callEvent(vkvm::EventType::RenderText); sleep(sleepTime); vkvm::setText("Hello World, lorem ipsum dolor sit amet"); sleep(sleepTime); vkvm::setFont(vkvm::FontType::ProFontIIX); vkvm::callEvent(vkvm::EventType::RenderText); sleep(sleepTime); vkvm::setFont(vkvm::FontType::Unifont); vkvm::callEvent(vkvm::EventType::RenderText); sleep(sleepTime); vkvm::setText("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."); sleep(sleepTime); vkvm::setMode(vkvm::GraphicMode::RGB); mandelbrot(); sleep(sleepTime); setColor(vkvm::black); sleep(sleepTime); } }
int main() {
return test();
}

BIN
res/P10.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 KiB

BIN
res/P6.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

BIN
res/P8.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 KiB

BIN
res/P9.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
res/font1.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
res/test.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 659 KiB

BIN
res/test1.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 659 KiB

BIN
res/test2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

63
src/Bitmap.cpp Normal file
View File

@ -0,0 +1,63 @@
#include "Bitmap.hpp"
#include <fstream>
#include <iostream>
Bitmap::Bitmap() {
offset = 0;
width = 0;
height = 0;
bitsPerPixel = 0;
}
Bitmap::Bitmap(const std::string &file) {
offset = 0;
width = 0;
height = 0;
bitsPerPixel = 0;
load(file);
}
void Bitmap::load(const std::string &file) {
std::ifstream stream;
stream.open(file);
if(stream.is_open()){
std::string str((std::istreambuf_iterator<char>(stream)),std::istreambuf_iterator<char>());
data.resize(str.size());
for(int i = 0; i < str.size();i++){
data[i] = str[i];
}
offset = static_cast<int>(*reinterpret_cast<unsigned int *>(&data[10]));
width = static_cast<int>(*reinterpret_cast<unsigned int *>(&data[18]));
height = static_cast<int>(*reinterpret_cast<unsigned int *>(&data[22]));
bitsPerPixel = static_cast<int>(*reinterpret_cast<uint16_t *>(&data[28]));
}
}
int Bitmap::getWidth() {
return width;
}
int Bitmap::getHeight() {
return height;
}
char *Bitmap::getData() {
return &data[offset];
}
int Bitmap::getBitsPerPixel() {
return bitsPerPixel;
}
unsigned int Bitmap::getPixel(int x, int y) {
unsigned int pixel = 0;
char *ptr = getData() + ((getHeight() - 1 - y) * getWidth() + x) * (getBitsPerPixel() / 8);
for(int i = 0; i < getBitsPerPixel() / 8;i++){
*((char*)&pixel+i) = ptr[i];//NOLINT
}
if(pixel != 0){
return pixel;
}
return pixel;
}

24
src/Bitmap.hpp Normal file
View File

@ -0,0 +1,24 @@
#ifndef DEMO_BITMAP_HPP
#define DEMO_BITMAP_HPP
#include <string>
#include <vector>
class Bitmap {
public:
Bitmap();
explicit Bitmap(const std::string &file);
void load(const std::string &file);
int getWidth();
int getHeight();
char *getData();
int getBitsPerPixel();
unsigned int getPixel(int x, int y);
private:
int width;
int height;
int offset;
int bitsPerPixel;
std::vector<char> data;
};
#endif //DEMO_BITMAP_HPP

78
src/MathFunctions.cpp Normal file
View File

@ -0,0 +1,78 @@
#include "vkvm.hpp"
#include <cmath>
#include <internal.hpp>
long double map(long double value, long double inputMin, long double inputMax, long double outputMin, long double outputMax) {
return (value - inputMin) * (outputMax - outputMin) / (inputMax - inputMin) + outputMin;
}
void mandelbrot() {
int width = 800;
int height = 600;
vkvm::setWidth(width);
vkvm::setHeight(height);
vkvm::setRedrawInterval(-1);
long double min = -2.84;
long double max = 1;
int maxIterations = 200;
double factor = 1;
for (int count = 0; count < 50; count++) {
max -= 0.1 * factor;
min += 0.15 * factor;
factor *= 0.9349;
maxIterations += 5;
if(count > 30) {
maxIterations *= 1.02;
}
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
long double xMap = map(x, 0, width, min, max);
long double yMap = map(y, 0, height, min, max);
long double xInitial = xMap;
long double yInitial = yMap;
int n = 0;
for (int i = 0; i < maxIterations; ++i) {
long double x1 = xMap * xMap - yMap * yMap;
long double y1 = 2 * xMap * yMap;
xMap = x1 + xInitial;
yMap = y1 + yInitial;
if ((xMap + yMap) > 2) {
break;
}
n++;
}
int brightness = map(n, 0, maxIterations, 0, 255);
if (n == maxIterations || (brightness < 20)) {
brightness = 0;
}
int red = map(brightness * brightness, 0, 255 * 255, 0, 255);
int green = brightness;
int blue = map(sqrt(brightness), 0, sqrt(255), 0, 255);
vkvm::setPixel(x, y, vkvm::Color(red, green, blue));
}
}
vkvm::callEvent(vkvm::EventType::Redraw);
}
vkvm::setRedrawInterval(500);
}

5
src/MathFunctions.hpp Normal file
View File

@ -0,0 +1,5 @@
#ifndef DEMO_MATHFUNCTIONS_H
#define DEMO_MATHFUNCTIONS_H
void mandelbrot();
#endif

View File

@ -1,5 +0,0 @@
#include "demo.h"
int test() {
return 42;
}

View File

@ -1,8 +0,0 @@
#ifndef SHARED_MEMORY_DEMO_H
#define SHARED_MEMORY_DEMO_H
int test();
#endif //SHARED_MEMORY_DEMO_H

View File

@ -1,6 +1,5 @@
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
#include "../src/demo.h"
TEST_CASE("Demo test") { TEST_CASE("Demo test") {
REQUIRE(test() == 42); REQUIRE(42 == 42);
} }