diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-09-20 00:29:45 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-09-20 00:29:45 +0100 |
commit | 39ca43ca3b24dcae76e1283ec8af4a16c845e2b7 (patch) | |
tree | d3aa095fa982695ffc3e621f62797a041ac36cb3 | |
parent | 34396f0483d94229e3a315e5eeb90c77c1425273 (diff) | |
download | YAGE-39ca43ca3b24dcae76e1283ec8af4a16c845e2b7.tar.gz YAGE-39ca43ca3b24dcae76e1283ec8af4a16c845e2b7.zip |
More tests and adding spritesheet support
-rw-r--r-- | .dir-locals.el | 6 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rwxr-xr-x | cmake/sdl.cfg | 78 | ||||
-rw-r--r-- | tests/matrixtest.cpp | 49 | ||||
-rw-r--r-- | tests/matrixtest.h | 0 | ||||
-rw-r--r-- | tests/particlebodytest.h | 0 | ||||
-rw-r--r-- | tests/rendertest.cpp | 17 | ||||
-rw-r--r-- | tests/rendertest.h | 19 | ||||
-rw-r--r-- | tests/resources/floor_atlas.json | 1026 | ||||
-rw-r--r-- | tests/resources/floor_atlas.png | bin | 0 -> 234876 bytes | |||
-rw-r--r-- | tests/spritesheettest.cpp | 7 | ||||
-rw-r--r-- | tests/windowtest.h | 0 | ||||
-rw-r--r-- | tests/yagetest.h | 0 | ||||
-rw-r--r-- | yage/CMakeLists.txt | 17 | ||||
-rw-r--r-- | yage/base/spritesheet.h | 26 | ||||
-rw-r--r-- | yage/base/texture.h | 5 | ||||
-rw-r--r-- | yage/physics/particlebody.h | 2 | ||||
-rw-r--r-- | yage/yage.cpp | 24 | ||||
-rw-r--r-- | yage/yage.h | 10 |
19 files changed, 1237 insertions, 51 deletions
diff --git a/.dir-locals.el b/.dir-locals.el index f39d59fe..e0f76bc1 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -5,6 +5,9 @@ (list (concat "-I" (projectile-project-root) "yage"))))) (setq company-clang-arguments (delete-dups (append company-clang-arguments + (list (concat "-I" (projectile-project-root)))))) + (setq company-clang-arguments (delete-dups (append + company-clang-arguments (list (concat "-I" (projectile-project-root) "lib/googletest/googletest/include"))))) (setq company-clang-arguments (delete-dups (append company-clang-arguments @@ -14,6 +17,9 @@ (list (concat (projectile-project-root) "yage"))))) (setq flycheck-clang-include-path (delete-dups (append flycheck-clang-include-path + (list (concat (projectile-project-root)))))) + (setq flycheck-clang-include-path (delete-dups (append + flycheck-clang-include-path (list (concat (projectile-project-root) "lib/googletest/googletest/include"))))) (setq flycheck-clang-include-path (delete-dups (append flycheck-clang-include-path diff --git a/CMakeLists.txt b/CMakeLists.txt index c56bd2f3..808bfc0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ pkg_search_module(SDL2 REQUIRED sdl2) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/yage) +include(cmake/cppcheck.cmake) + if(${ENABLE_TESTING}) # enable tests enable_testing() diff --git a/cmake/sdl.cfg b/cmake/sdl.cfg new file mode 100755 index 00000000..aa1d0d55 --- /dev/null +++ b/cmake/sdl.cfg @@ -0,0 +1,78 @@ +<?xml version="1.0"?> +<def format="2"> + <function name="SDL_mutexP"> + <noreturn>false</noreturn> + <arg nr="1"> + <not-bool/> + <not-null/> + </arg> + </function> + <function name="SDL_mutexV"> + <noreturn>false</noreturn> + <arg nr="1"> + <not-bool/> + <not-null/> + </arg> + </function> + <function name="SDL_RWsize"> + <noreturn>false</noreturn> + <arg nr="1"> + <not-bool/> + <not-null/> + </arg> + </function> + <function name="SDL_RWread"> + <noreturn>false</noreturn> + <arg nr="1"> + <not-bool/> + <not-null/> + </arg> + <arg nr="2"> + <not-bool/> + <not-null/> + </arg> + </function> + <function name="IMG_isPNG"> + <noreturn>false</noreturn> + <arg nr="1"> + <not-bool/> + <not-null/> + </arg> + </function> + <function name="IMG_isJPG"> + <noreturn>false</noreturn> + <arg nr="1"> + <not-bool/> + <not-null/> + </arg> + </function> + <resource> + <dealloc>SDL_FreeSurface</dealloc> + <alloc init="true">SDL_CreateRGBSurface</alloc> + <alloc init="true">SDL_ConvertSurface</alloc> + <alloc init="true">TTF_RenderUTF8_Blended</alloc> + <alloc init="true">IMG_LoadPNG_RW</alloc> + <alloc init="true">IMG_LoadJPG_RW</alloc> + <alloc init="true">IMG_Load</alloc> + </resource> + <resource> + <dealloc>SDL_DestroyMutex</dealloc> + <alloc init="true">SDL_CreateMutex</alloc> + </resource> + <resource> + <dealloc>SDL_WaitThread</dealloc> + <alloc init="true">SDL_CreateThread</alloc> + </resource> + <resource> + <dealloc>SDL_RWclose</dealloc> + <alloc init="true">SDL_RWFromFile</alloc> + </resource> + <resource> + <dealloc>SDL_FreeRW</dealloc> + <alloc init="true">SDL_AllocRW</alloc> + </resource> + <resource> + <dealloc>Mix_FreeMusic</dealloc> + <alloc init="true">Mix_LoadMUSType_RW</alloc> + </resource> +</def> diff --git a/tests/matrixtest.cpp b/tests/matrixtest.cpp index 9cc8bccc..58786bae 100644 --- a/tests/matrixtest.cpp +++ b/tests/matrixtest.cpp @@ -6,51 +6,27 @@ * ---------------------------------------------------------------------------- */ -#include <yage/yage.h> #include <gtest/gtest.h> +#include <yage/yage.h> #include <algorithm> #include <cstdlib> #include <ctime> #include <vector> -template <int Size> -int matrixAddition(int num1, int num2) -{ - yage::Matrix<Size, Size, int> m1, m2; - m1[1][1] = num1; - m2[1][1] = num2; - - yage::Matrix<Size, Size, int> m3 = m1 + m2; - - return m3[1][1]; -} - -int vectorDotProduct(const std::vector<int> &vec_contents_f, - const std::vector<int> &vec_contents_s) -{ - yage::Vector<3, int> v1(vec_contents_f); - yage::Vector<3, int> v2(vec_contents_s); - - int x = yage::matrix::dot(v1, v2); - - return x; -} - -bool matrixMultiplication() -{ - return false; -} - // TESTS TEST(Matrix, Assign) { double rand_num = rand(); yage::Matrix<5, 5, double> mat1; + mat1[3][2] = rand_num; + ASSERT_EQ(rand_num, mat1[3][2]); - yage::Matrix<2, 2, double> mat2 {{rand_num, rand_num, rand_num, rand_num}}; + + yage::Matrix<2, 2, double> mat2{{rand_num, rand_num, rand_num, rand_num}}; + ASSERT_EQ(rand_num, mat2[1][0]); } @@ -58,18 +34,27 @@ TEST(Matrix, Addition) { int rand_x = rand(); int rand_y = rand(); - ASSERT_EQ(rand_x + rand_y, matrixAddition<10>(rand_x, rand_y)); + yage::Matrix<5, 5, int> m1, m2; + + m1[2][4] = rand_x; + m2[2][4] = rand_y; + + ASSERT_EQ(rand_x + rand_y, (m1 + m2)[2][4]); } TEST(Vector, DotProduct) { std::vector<int> contents_i = {rand() % 100, rand() % 100, rand() % 100}; std::vector<int> contents_j = {rand() % 100, rand() % 100, rand() % 100}; + yage::Vector<3, int> v1{contents_i}; + yage::Vector<3, int> v2{contents_j}; + int sum = 0; for (std::size_t i = 0; i < contents_i.size(); ++i) { sum += contents_i[i] * contents_j[i]; } - ASSERT_EQ(sum, vectorDotProduct(contents_i, contents_j)); + + ASSERT_EQ(sum, yage::matrix::dot(v1, v2)); } int main(int argc, char **argv) diff --git a/tests/matrixtest.h b/tests/matrixtest.h deleted file mode 100644 index e69de29b..00000000 --- a/tests/matrixtest.h +++ /dev/null diff --git a/tests/particlebodytest.h b/tests/particlebodytest.h deleted file mode 100644 index e69de29b..00000000 --- a/tests/particlebodytest.h +++ /dev/null diff --git a/tests/rendertest.cpp b/tests/rendertest.cpp new file mode 100644 index 00000000..5f35b1fc --- /dev/null +++ b/tests/rendertest.cpp @@ -0,0 +1,17 @@ +/* ---------------------------------------------------------------------------- + * renderingtest.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#include "rendertest.h" + +RenderTest::RenderTest(std::string sprite) : sprite_(sprite) +{ +} + +void RenderTest::render() +{ +} diff --git a/tests/rendertest.h b/tests/rendertest.h new file mode 100644 index 00000000..c239338f --- /dev/null +++ b/tests/rendertest.h @@ -0,0 +1,19 @@ +/* ---------------------------------------------------------------------------- + * renderingtest.h + * + * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#include <string> + +class RenderTest +{ +public: + RenderTest(std::string sprite); + void render(); + +private: + std::string sprite_; +}; diff --git a/tests/resources/floor_atlas.json b/tests/resources/floor_atlas.json new file mode 100644 index 00000000..a4c30f3d --- /dev/null +++ b/tests/resources/floor_atlas.json @@ -0,0 +1,1026 @@ +{ + "width": 512, + "height": 352, + "sprites": { + "sandstone_floor6.png": { + "x": 0, + "y": 0, + "width": 32, + "height": 32 + }, + "pedestal_ne.png": { + "x": 32, + "y": 0, + "width": 32, + "height": 32 + }, + "marble_floor4.png": { + "x": 64, + "y": 0, + "width": 32, + "height": 32 + }, + "pebble_brown2.png": { + "x": 96, + "y": 0, + "width": 32, + "height": 32 + }, + "sandstone_floor4.png": { + "x": 128, + "y": 0, + "width": 32, + "height": 32 + }, + "hive2.png": { + "x": 160, + "y": 0, + "width": 32, + "height": 32 + }, + "lair1.png": { + "x": 192, + "y": 0, + "width": 32, + "height": 32 + }, + "crystal_floor3.png": { + "x": 224, + "y": 0, + "width": 32, + "height": 32 + }, + "volcanic_floor1.png": { + "x": 256, + "y": 0, + "width": 32, + "height": 32 + }, + "snake2.png": { + "x": 288, + "y": 0, + "width": 32, + "height": 32 + }, + "lava2.png": { + "x": 320, + "y": 0, + "width": 32, + "height": 32 + }, + "cobble_blood5.png": { + "x": 352, + "y": 0, + "width": 32, + "height": 32 + }, + "dirt_ne.png": { + "x": 384, + "y": 0, + "width": 32, + "height": 32 + }, + "mesh2.png": { + "x": 416, + "y": 0, + "width": 32, + "height": 32 + }, + "cobble_blood7.png": { + "x": 448, + "y": 0, + "width": 32, + "height": 32 + }, + "sandstone_floor2.png": { + "x": 480, + "y": 0, + "width": 32, + "height": 32 + }, + "dirt_e.png": { + "x": 0, + "y": 32, + "width": 32, + "height": 32 + }, + "pedestal_se.png": { + "x": 32, + "y": 32, + "width": 32, + "height": 32 + }, + "rough_red0.png": { + "x": 64, + "y": 32, + "width": 32, + "height": 32 + }, + "grey_dirt2.png": { + "x": 96, + "y": 32, + "width": 32, + "height": 32 + }, + "bog_green2.png": { + "x": 128, + "y": 32, + "width": 32, + "height": 32 + }, + "floor_sand_stone3.png": { + "x": 160, + "y": 32, + "width": 32, + "height": 32 + }, + "tomb0.png": { + "x": 192, + "y": 32, + "width": 32, + "height": 32 + }, + "pedestal_sw.png": { + "x": 224, + "y": 32, + "width": 32, + "height": 32 + }, + "pebble_brown3.png": { + "x": 256, + "y": 32, + "width": 32, + "height": 32 + }, + "floor_vines3.png": { + "x": 288, + "y": 32, + "width": 32, + "height": 32 + }, + "pebble_brown1.png": { + "x": 320, + "y": 32, + "width": 32, + "height": 32 + }, + "crystal_floor0.png": { + "x": 352, + "y": 32, + "width": 32, + "height": 32 + }, + "rect_gray3.png": { + "x": 384, + "y": 32, + "width": 32, + "height": 32 + }, + "floor_sand_stone4.png": { + "x": 416, + "y": 32, + "width": 32, + "height": 32 + }, + "floor_sand_stone0.png": { + "x": 448, + "y": 32, + "width": 32, + "height": 32 + }, + "cobble_blood6.png": { + "x": 480, + "y": 32, + "width": 32, + "height": 32 + }, + "floor_nerves2.png": { + "x": 0, + "y": 64, + "width": 32, + "height": 32 + }, + "ice2.png": { + "x": 32, + "y": 64, + "width": 32, + "height": 32 + }, + "lair0.png": { + "x": 64, + "y": 64, + "width": 32, + "height": 32 + }, + "rough_red1.png": { + "x": 96, + "y": 64, + "width": 32, + "height": 32 + }, + "pebble_brown0.png": { + "x": 128, + "y": 64, + "width": 32, + "height": 32 + }, + "snake3.png": { + "x": 160, + "y": 64, + "width": 32, + "height": 32 + }, + "volcanic_floor2.png": { + "x": 192, + "y": 64, + "width": 32, + "height": 32 + }, + "pebble_brown7.png": { + "x": 224, + "y": 64, + "width": 32, + "height": 32 + }, + "floor_sand_stone1.png": { + "x": 256, + "y": 64, + "width": 32, + "height": 32 + }, + "floor_nerves6.png": { + "x": 288, + "y": 64, + "width": 32, + "height": 32 + }, + "cobble_blood10.png": { + "x": 320, + "y": 64, + "width": 32, + "height": 32 + }, + "dirt_n.png": { + "x": 352, + "y": 64, + "width": 32, + "height": 32 + }, + "mesh0.png": { + "x": 384, + "y": 64, + "width": 32, + "height": 32 + }, + "sandstone_floor7.png": { + "x": 416, + "y": 64, + "width": 32, + "height": 32 + }, + "volcanic_floor6.png": { + "x": 448, + "y": 64, + "width": 32, + "height": 32 + }, + "sandstone_floor0.png": { + "x": 480, + "y": 64, + "width": 32, + "height": 32 + }, + "rough_red3.png": { + "x": 0, + "y": 96, + "width": 32, + "height": 32 + }, + "pedestal_e.png": { + "x": 32, + "y": 96, + "width": 32, + "height": 32 + }, + "ice1.png": { + "x": 64, + "y": 96, + "width": 32, + "height": 32 + }, + "floor_nerves0.png": { + "x": 96, + "y": 96, + "width": 32, + "height": 32 + }, + "swamp0.png": { + "x": 128, + "y": 96, + "width": 32, + "height": 32 + }, + "dirt2.png": { + "x": 160, + "y": 96, + "width": 32, + "height": 32 + }, + "floor_sand_stone6.png": { + "x": 192, + "y": 96, + "width": 32, + "height": 32 + }, + "pedestal_s.png": { + "x": 224, + "y": 96, + "width": 32, + "height": 32 + }, + "pedestal_full.png": { + "x": 256, + "y": 96, + "width": 32, + "height": 32 + }, + "volcanic_floor4.png": { + "x": 288, + "y": 96, + "width": 32, + "height": 32 + }, + "pebble_brown4.png": { + "x": 320, + "y": 96, + "width": 32, + "height": 32 + }, + "dirt1.png": { + "x": 352, + "y": 96, + "width": 32, + "height": 32 + }, + "sandstone_floor5.png": { + "x": 384, + "y": 96, + "width": 32, + "height": 32 + }, + "rough_red2.png": { + "x": 416, + "y": 96, + "width": 32, + "height": 32 + }, + "rect_gray0.png": { + "x": 448, + "y": 96, + "width": 32, + "height": 32 + }, + "rect_gray2.png": { + "x": 480, + "y": 96, + "width": 32, + "height": 32 + }, + "floor_nerves5.png": { + "x": 0, + "y": 128, + "width": 32, + "height": 32 + }, + "swamp2.png": { + "x": 32, + "y": 128, + "width": 32, + "height": 32 + }, + "grey_dirt7.png": { + "x": 64, + "y": 128, + "width": 32, + "height": 32 + }, + "cobble_blood8.png": { + "x": 96, + "y": 128, + "width": 32, + "height": 32 + }, + "grey_dirt0.png": { + "x": 128, + "y": 128, + "width": 32, + "height": 32 + }, + "cobble_blood1.png": { + "x": 160, + "y": 128, + "width": 32, + "height": 32 + }, + "volcanic_floor3.png": { + "x": 192, + "y": 128, + "width": 32, + "height": 32 + }, + "lair2.png": { + "x": 224, + "y": 128, + "width": 32, + "height": 32 + }, + "lava0.png": { + "x": 256, + "y": 128, + "width": 32, + "height": 32 + }, + "cobble_blood4.png": { + "x": 288, + "y": 128, + "width": 32, + "height": 32 + }, + "grey_dirt1.png": { + "x": 320, + "y": 128, + "width": 32, + "height": 32 + }, + "pedestal_nw.png": { + "x": 352, + "y": 128, + "width": 32, + "height": 32 + }, + "crystal_floor5.png": { + "x": 384, + "y": 128, + "width": 32, + "height": 32 + }, + "bog_green3.png": { + "x": 416, + "y": 128, + "width": 32, + "height": 32 + }, + "marble_floor2.png": { + "x": 448, + "y": 128, + "width": 32, + "height": 32 + }, + "mesh3.png": { + "x": 480, + "y": 128, + "width": 32, + "height": 32 + }, + "pedestal_w.png": { + "x": 0, + "y": 160, + "width": 32, + "height": 32 + }, + "swamp1.png": { + "x": 32, + "y": 160, + "width": 32, + "height": 32 + }, + "snake0.png": { + "x": 64, + "y": 160, + "width": 32, + "height": 32 + }, + "crystal_floor4.png": { + "x": 96, + "y": 160, + "width": 32, + "height": 32 + }, + "cobble_blood12.png": { + "x": 128, + "y": 160, + "width": 32, + "height": 32 + }, + "floor_vines4.png": { + "x": 160, + "y": 160, + "width": 32, + "height": 32 + }, + "floor_vines2.png": { + "x": 192, + "y": 160, + "width": 32, + "height": 32 + }, + "floor_nerves1.png": { + "x": 224, + "y": 160, + "width": 32, + "height": 32 + }, + "snake1.png": { + "x": 256, + "y": 160, + "width": 32, + "height": 32 + }, + "dirt_sw.png": { + "x": 288, + "y": 160, + "width": 32, + "height": 32 + }, + "dirt0.png": { + "x": 320, + "y": 160, + "width": 32, + "height": 32 + }, + "hive0.png": { + "x": 352, + "y": 160, + "width": 32, + "height": 32 + }, + "grey_dirt3.png": { + "x": 384, + "y": 160, + "width": 32, + "height": 32 + }, + "floor_nerves3.png": { + "x": 416, + "y": 160, + "width": 32, + "height": 32 + }, + "marble_floor5.png": { + "x": 448, + "y": 160, + "width": 32, + "height": 32 + }, + "bog_green1.png": { + "x": 480, + "y": 160, + "width": 32, + "height": 32 + }, + "sandstone_floor3.png": { + "x": 0, + "y": 192, + "width": 32, + "height": 32 + }, + "bog_green0.png": { + "x": 32, + "y": 192, + "width": 32, + "height": 32 + }, + "pedestal_n.png": { + "x": 64, + "y": 192, + "width": 32, + "height": 32 + }, + "hive1.png": { + "x": 96, + "y": 192, + "width": 32, + "height": 32 + }, + "pebble_brown6.png": { + "x": 128, + "y": 192, + "width": 32, + "height": 32 + }, + "floor_sand_stone2.png": { + "x": 160, + "y": 192, + "width": 32, + "height": 32 + }, + "cobble_blood3.png": { + "x": 192, + "y": 192, + "width": 32, + "height": 32 + }, + "sandstone_floor9.png": { + "x": 224, + "y": 192, + "width": 32, + "height": 32 + }, + "swamp3.png": { + "x": 256, + "y": 192, + "width": 32, + "height": 32 + }, + "ice0.png": { + "x": 288, + "y": 192, + "width": 32, + "height": 32 + }, + "marble_floor3.png": { + "x": 320, + "y": 192, + "width": 32, + "height": 32 + }, + "volcanic_floor5.png": { + "x": 352, + "y": 192, + "width": 32, + "height": 32 + }, + "floor_vines6.png": { + "x": 384, + "y": 192, + "width": 32, + "height": 32 + }, + "tutorial_pad.png": { + "x": 416, + "y": 192, + "width": 32, + "height": 32 + }, + "dirt_nw.png": { + "x": 448, + "y": 192, + "width": 32, + "height": 32 + }, + "floor_vines0.png": { + "x": 480, + "y": 192, + "width": 32, + "height": 32 + }, + "grey_dirt4.png": { + "x": 0, + "y": 224, + "width": 32, + "height": 32 + }, + "marble_floor6.png": { + "x": 32, + "y": 224, + "width": 32, + "height": 32 + }, + "grey_dirt6.png": { + "x": 64, + "y": 224, + "width": 32, + "height": 32 + }, + "crystal_floor1.png": { + "x": 96, + "y": 224, + "width": 32, + "height": 32 + }, + "cobble_blood9.png": { + "x": 128, + "y": 224, + "width": 32, + "height": 32 + }, + "ice3.png": { + "x": 160, + "y": 224, + "width": 32, + "height": 32 + }, + "floor_nerves4.png": { + "x": 192, + "y": 224, + "width": 32, + "height": 32 + }, + "dirt_w.png": { + "x": 224, + "y": 224, + "width": 32, + "height": 32 + }, + "pebble_brown5.png": { + "x": 256, + "y": 224, + "width": 32, + "height": 32 + }, + "lair3.png": { + "x": 288, + "y": 224, + "width": 32, + "height": 32 + }, + "rect_gray1.png": { + "x": 320, + "y": 224, + "width": 32, + "height": 32 + }, + "tomb3.png": { + "x": 352, + "y": 224, + "width": 32, + "height": 32 + }, + "floor_vines1.png": { + "x": 384, + "y": 224, + "width": 32, + "height": 32 + }, + "grey_dirt5.png": { + "x": 416, + "y": 224, + "width": 32, + "height": 32 + }, + "floor_vines5.png": { + "x": 448, + "y": 224, + "width": 32, + "height": 32 + }, + "sandstone_floor1.png": { + "x": 480, + "y": 224, + "width": 32, + "height": 32 + }, + "floor_sand_stone5.png": { + "x": 0, + "y": 256, + "width": 32, + "height": 32 + }, + "dirt_se.png": { + "x": 32, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_full.png": { + "x": 64, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass1.png": { + "x": 96, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_flowers_yellow2.png": { + "x": 128, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_s.png": { + "x": 160, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_se.png": { + "x": 192, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_flowers_red2.png": { + "x": 224, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass2.png": { + "x": 256, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass0-dirt-mix2.png": { + "x": 288, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_flowers_blue3.png": { + "x": 320, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_flowers_blue2.png": { + "x": 352, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_flowers_blue1.png": { + "x": 384, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass0-dirt-mix1.png": { + "x": 416, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_flowers_red1.png": { + "x": 448, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_flowers_yellow3.png": { + "x": 480, + "y": 256, + "width": 32, + "height": 32 + }, + "grass/grass_sw.png": { + "x": 0, + "y": 288, + "width": 32, + "height": 32 + }, + "grass/grass_flowers_yellow1.png": { + "x": 32, + "y": 288, + "width": 32, + "height": 32 + }, + "grass/grass_nw.png": { + "x": 64, + "y": 288, + "width": 32, + "height": 32 + }, + "grass/grass_w.png": { + "x": 96, + "y": 288, + "width": 32, + "height": 32 + }, + "grass/grass_n.png": { + "x": 128, + "y": 288, + "width": 32, + "height": 32 + }, + "grass/grass_e.png": { + "x": 160, + "y": 288, + "width": 32, + "height": 32 + }, + "grass/grass_ne.png": { + "x": 192, + "y": 288, + "width": 32, + "height": 32 + }, + "grass/grass0-dirt-mix3.png": { + "x": 224, + "y": 288, + "width": 32, + "height": 32 + }, + "grass/grass0.png": { + "x": 256, + "y": 288, + "width": 32, + "height": 32 + }, + "grass/grass_flowers_red3.png": { + "x": 288, + "y": 288, + "width": 32, + "height": 32 + }, + "crystal_floor2.png": { + "x": 320, + "y": 288, + "width": 32, + "height": 32 + }, + "tomb2.png": { + "x": 352, + "y": 288, + "width": 32, + "height": 32 + }, + "cobble_blood11.png": { + "x": 384, + "y": 288, + "width": 32, + "height": 32 + }, + "cobble_blood2.png": { + "x": 416, + "y": 288, + "width": 32, + "height": 32 + }, + "lava3.png": { + "x": 448, + "y": 288, + "width": 32, + "height": 32 + }, + "volcanic_floor0.png": { + "x": 480, + "y": 288, + "width": 32, + "height": 32 + }, + "mesh1.png": { + "x": 0, + "y": 320, + "width": 32, + "height": 32 + }, + "dirt_full.png": { + "x": 32, + "y": 320, + "width": 32, + "height": 32 + }, + "lava1.png": { + "x": 64, + "y": 320, + "width": 32, + "height": 32 + }, + "tomb1.png": { + "x": 96, + "y": 320, + "width": 32, + "height": 32 + }, + "dirt_s.png": { + "x": 128, + "y": 320, + "width": 32, + "height": 32 + }, + "marble_floor1.png": { + "x": 160, + "y": 320, + "width": 32, + "height": 32 + }, + "floor_sand_stone7.png": { + "x": 192, + "y": 320, + "width": 32, + "height": 32 + }, + "hive3.png": { + "x": 224, + "y": 320, + "width": 32, + "height": 32 + }, + "pebble_brown8.png": { + "x": 256, + "y": 320, + "width": 32, + "height": 32 + }, + "sandstone_floor8.png": { + "x": 288, + "y": 320, + "width": 32, + "height": 32 + } + } +}
\ No newline at end of file diff --git a/tests/resources/floor_atlas.png b/tests/resources/floor_atlas.png Binary files differnew file mode 100644 index 00000000..61a5e90a --- /dev/null +++ b/tests/resources/floor_atlas.png diff --git a/tests/spritesheettest.cpp b/tests/spritesheettest.cpp new file mode 100644 index 00000000..675a3762 --- /dev/null +++ b/tests/spritesheettest.cpp @@ -0,0 +1,7 @@ +#include <yage/yage.h> +#include <gtest/gtest.h> + +TEST(SpriteSheet, Load) +{ + +} diff --git a/tests/windowtest.h b/tests/windowtest.h deleted file mode 100644 index e69de29b..00000000 --- a/tests/windowtest.h +++ /dev/null diff --git a/tests/yagetest.h b/tests/yagetest.h deleted file mode 100644 index e69de29b..00000000 --- a/tests/yagetest.h +++ /dev/null diff --git a/yage/CMakeLists.txt b/yage/CMakeLists.txt index d45ffa90..1de87757 100644 --- a/yage/CMakeLists.txt +++ b/yage/CMakeLists.txt @@ -2,32 +2,31 @@ cmake_policy(SET CMP0048 NEW) project(yage VERSION 0.1.1.0 - LANGUAGES CXX - ) + LANGUAGES CXX) include(base/CMakeLists.txt) include(physics/CMakeLists.txt) include(math/CMakeLists.txt) set(YAGE_SOURCES + yage.cpp ${YAGE_BASE_SOURCES} ${YAGE_PHYSICS_SOURCES} - ${YAGE_MATH_SOURCES} - ) + ${YAGE_MATH_SOURCES}) set(${PROJECT_NAME}_DIR ${PROJECT_SOURCE_DIR}) add_library(${PROJECT_NAME} - ${YAGE_SOURCES} - ) + ${YAGE_SOURCES}) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - ) + ${OPENGL_INCLUDE_DIR} + ${GLEW_INCLUDE_DIR} + ${SDL2_INCLUDE_DIR}) target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} - ${SDL2_LIBRARIES} - ) + ${SDL2_LIBRARIES}) diff --git a/yage/base/spritesheet.h b/yage/base/spritesheet.h index 2b70ad8b..dbde07c0 100644 --- a/yage/base/spritesheet.h +++ b/yage/base/spritesheet.h @@ -11,13 +11,37 @@ #include "texture.h" +#include <map> +#include <string> + namespace yage { +namespace +{ + +struct Coordinate { + int x; + int y; + int width; + int height; + + Coordinate(int x_i, int y_i, int width_i, int height_i) + : x(x_i), y(y_i), width(width_i), height(height_i) + { + } +}; + +} // namespace + class SpriteSheet { +public: + SpriteSheet(std::string pngFileName, std::string jsonFileName); + private: - Texture texture_; + Texture texture_; + std::map<std::string, Coordinate> fileLocations_; }; } // namespace yage diff --git a/yage/base/texture.h b/yage/base/texture.h index d1fdcbf2..3688bf04 100644 --- a/yage/base/texture.h +++ b/yage/base/texture.h @@ -18,6 +18,11 @@ struct Texture { GLuint id; int width; int height; + + Texture(GLuint id_i, int width_i, int height_i) + : id(id_i), width(width_i), height(height_i) + { + } }; } // namespace yage diff --git a/yage/physics/particlebody.h b/yage/physics/particlebody.h index 18cfff0b..c750c1a4 100644 --- a/yage/physics/particlebody.h +++ b/yage/physics/particlebody.h @@ -11,7 +11,7 @@ #include "body.h" -#include <yage/math/matrix.h> +#include <math/matrix.h> namespace yage { diff --git a/yage/yage.cpp b/yage/yage.cpp new file mode 100644 index 00000000..fa1e5c36 --- /dev/null +++ b/yage/yage.cpp @@ -0,0 +1,24 @@ +/* ---------------------------------------------------------------------------- + * yage.h + * + * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License + * See file LICENSE for more details + * ---------------------------------------------------------------------------- + */ + +#include "yage.h" + +namespace yage +{ + +bool init() +{ + return SDL_Init(SDL_INIT_VIDEO); +} + +void quit() +{ + SDL_Quit(); +} + +} // namespace yage diff --git a/yage/yage.h b/yage/yage.h index 286d4784..f20aff06 100644 --- a/yage/yage.h +++ b/yage/yage.h @@ -50,19 +50,13 @@ namespace yage * * @return Returns true if the initialization was successful. */ -bool init() -{ - return SDL_Init(SDL_INIT_VIDEO); -} +extern bool init(); /** Quit and cleanup yage * * SDL2 needs to clean itself up. */ -void quit() -{ - SDL_Quit(); -} +extern void quit(); } // namespace yage |