Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tictactoe-sfml): add whole tictactoe game #79

Merged
merged 5 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/antara.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ macro(magic_game_app_image_generation from_dir desktop_file appdata_file app_ico
add_custom_command(TARGET ${target}
POST_BUILD COMMAND
bash -c
"VERSION=${PROJECT_VERSION} ${PROJECT_SOURCE_DIR}/tools/linux/linuxdeploy-x86_64.AppImage --appdir ${output_dir} --output appimage"
"ARCH=x86_64 VERSION=${PROJECT_VERSION} ${PROJECT_SOURCE_DIR}/tools/linux/linuxdeploy-x86_64.AppImage --appdir ${output_dir} --output appimage"
$<TARGET_FILE:${target}>
WORKING_DIRECTORY ${exe_runtime_directory})
endif ()
Expand Down
3 changes: 2 additions & 1 deletion examples/sfml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(basis-draft)
add_subdirectory(flappy-bird)
add_subdirectory(flappy-bird-scripted)
add_subdirectory(flappy-bird-scripted)
add_subdirectory(tic-tac-toe)
4 changes: 3 additions & 1 deletion examples/sfml/basis-draft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ if (WIN32)
COMMENT "copying dlls …"
$<TARGET_FILE_DIR:antara-sfml-example>
)
endif ()
endif ()

get_sfml_intro_assets(${CMAKE_CURRENT_SOURCE_DIR})
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions examples/sfml/basis-draft/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
#include "antara/gaming/scenes/base.scene.hpp"
#include "antara/gaming/sfml/audio.system.hpp"
#include "antara/gaming/sfml/resources.manager.hpp"
#include "../tic-tac-toe/game.scene.hpp"


class intro_scene;

class game_scene final : public antara::gaming::scenes::base_scene
{
public:

game_scene(entt::registry &entity_registry) noexcept : base_scene(entity_registry)
{
auto handle = resource_mgr.load_font("sansation.ttf");
Expand Down Expand Up @@ -68,6 +70,24 @@ class game_scene final : public antara::gaming::scenes::base_scene
entity_registry_.assign<entt::tag<"game_scene"_hs>>(triangle_entity);
this->entity_registry_.assign<antara::gaming::ecs::component::layer<0>>(triangle_entity);

auto cross_entity = entity_registry.create();
auto &cross_cmp = entity_registry.assign<antara::gaming::sfml::vertex_array>(cross_entity,
sf::VertexArray(sf::Lines, 16));
sf::VertexArray &lines = cross_cmp.drawable;

auto nb_cells = 3u;
auto cell_width = window_info.x / nb_cells;
auto cell_height = window_info.y / nb_cells;

for (std::size_t counter = 0, i = 0; i < nb_cells; ++i, counter += 4) {
lines[counter].position = sf::Vector2f(i * cell_width, 0);
lines[counter + 1].position = sf::Vector2f(i * cell_width, window_info.y);
lines[counter + 2].position = sf::Vector2f(0, i * cell_height);
lines[counter + 3].position = sf::Vector2f(window_info.x, i * cell_height);
}

entity_registry_.assign<entt::tag<"game_scene"_hs>>(cross_entity);
this->entity_registry_.assign<antara::gaming::ecs::component::layer<0>>(cross_entity);
}

void update() noexcept final
Expand Down
2 changes: 2 additions & 0 deletions examples/sfml/flappy-bird-scripted/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ endif ()
if (USE_LUA_ANTARA_WRAPPER)
get_lua_scenes_system(${CMAKE_CURRENT_SOURCE_DIR})
endif ()

get_sfml_intro_assets(${CMAKE_CURRENT_SOURCE_DIR})
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<id>org.antara.gaming.sfml.flappybird.desktop</id>
<metadata_license>MIT</metadata_license>
<project_license>MIT</project_license>
<name>antara-sfml-flappy-birds</name>
<name>antara-sfml-flappy-birds-scripted</name>
<summary>flappy birds example with antara gaming sdk and SFML</summary>
<description>
<p>Written in c++17</p>
Expand Down
19 changes: 10 additions & 9 deletions examples/sfml/flappy-bird-scripted/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* *
******************************************************************************/

#include <antara/gaming/sfml/graphic.system.hpp>
#include <antara/gaming/sfml/lua.system.hpp>
#include <antara/gaming/sfml/input.system.hpp>
#include <antara/gaming/sfml/komodo.intro.scene.hpp>
#include <antara/gaming/lua/lua.system.hpp>
#include <antara/gaming/scenes/scene.manager.hpp>
#include "world.hpp"
#include "antara/gaming/sfml/komodo.intro.scene.hpp"
#include "antara/gaming/lua/lua.system.hpp"
#include "antara/gaming/scenes/scene.manager.hpp"
#include "antara/gaming/sfml/graphic.system.hpp"
#include "antara/gaming/sfml/input.system.hpp"

flappy_world::flappy_world() noexcept
{
Expand All @@ -29,8 +29,9 @@ flappy_world::flappy_world() noexcept
auto &graphic_system = this->system_manager_.create_system<antara::gaming::sfml::graphic_system>();
this->system_manager_.create_system<antara::gaming::sfml::input_system>(graphic_system.get_window());
auto &scene_manager = this->system_manager_.create_system<antara::gaming::scenes::manager>();
scene_manager.change_scene(std::make_unique<antara::gaming::sfml::intro_scene>(entity_registry_, [&lua_scripting_system, this]() {
lua_scripting_system.load_scripted_system("scenes_system.lua");
this->system_manager_.mark_system<antara::gaming::scenes::manager>();
}), true);
scene_manager.change_scene(
std::make_unique<antara::gaming::sfml::intro_scene>(entity_registry_, [&lua_scripting_system, this]() {
lua_scripting_system.load_scripted_system("scenes_system.lua");
this->system_manager_.mark_system<antara::gaming::scenes::manager>();
}), true);
}
4 changes: 3 additions & 1 deletion examples/sfml/flappy-bird/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ if (WIN32)
COMMENT "copying dlls …"
$<TARGET_FILE_DIR:antara-sfml-flappy-birds>
)
endif ()
endif ()

get_sfml_intro_assets(${CMAKE_CURRENT_SOURCE_DIR})
Binary file removed examples/sfml/flappy-bird/assets/sounds/intro1.wav
Binary file not shown.
Binary file removed examples/sfml/flappy-bird/assets/sounds/intro2.wav
Binary file not shown.
Binary file not shown.
Binary file removed examples/sfml/flappy-bird/assets/textures/name.png
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/sfml/flappy-bird/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

int main()
{
flappy_world game_app;
game_world game_app;
return game_app.run();
}
2 changes: 1 addition & 1 deletion examples/sfml/flappy-bird/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "world.hpp"
#include "intro.scene.hpp"

flappy_world::flappy_world() noexcept
game_world::game_world() noexcept
{
auto &graphic_system = this->system_manager_.create_system<antara::gaming::sfml::graphic_system>();
this->system_manager_.create_system<antara::gaming::sfml::input_system>(graphic_system.get_window());
Expand Down
4 changes: 2 additions & 2 deletions examples/sfml/flappy-bird/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "antara/gaming/sfml/graphic.system.hpp"
#include "antara/gaming/sfml/input.system.hpp"

class flappy_world : public antara::gaming::world::app
class game_world : public antara::gaming::world::app
{
public:
flappy_world() noexcept;
game_world() noexcept;
};
38 changes: 38 additions & 0 deletions examples/sfml/tic-tac-toe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
set(ICON)
configure_icon_osx(data/osx/kmd_logo.icns ICON kmd_logo.icns)

add_executable(antara-sfml-tictactoe MACOSX_BUNDLE ${ICON} main.cpp)
target_sources(antara-sfml-tictactoe PRIVATE world.cpp game.scene.cpp tic.tac.toe.factory.cpp)
target_link_libraries(antara-sfml-tictactoe PUBLIC antara::world antara::scenes antara::sfml)

set_target_properties(antara-sfml-tictactoe
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
)

magic_game_app_image_generation("${CMAKE_CURRENT_SOURCE_DIR}/data/linux"
"org.antara.gaming.sfml.tictactoe.desktop"
"org.antara.gaming.sfml.tictactoe.appdata.xml"
"komodo_icon.png"
antara-sfml-tictactoe
AntaraTicTacToeAppDir
${CMAKE_CURRENT_SOURCE_DIR}/assets
)

target_enable_ubsan(antara-sfml-tictactoe)
if (APPLE)
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/bin/antara-sfml-tictactoe.app/Contents/Resources)
include(data/osx/sfml_tictactoe_install.cmake)
endif()


if (WIN32)
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/bin/)
ADD_CUSTOM_COMMAND(TARGET antara-sfml-tictactoe POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${SFML_BINARY_DIR}/lib" "${CMAKE_BINARY_DIR}/bin/"
COMMENT "copying dlls …"
$<TARGET_FILE_DIR:antara-sfml-tictactoe>
)
endif ()

get_sfml_intro_assets(${CMAKE_CURRENT_SOURCE_DIR})
10 changes: 10 additions & 0 deletions examples/sfml/tic-tac-toe/assets/config/game.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"window": {
"fullscreen": false,
"size": {
"width": 1920,
"height": 1080
},
"title": "my game window"
}
}
Empty file.
Binary file not shown.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component type="desktop-application">
<id>org.antara.gaming.sfml.tictactoe.desktop</id>
<metadata_license>MIT</metadata_license>
<project_license>MIT</project_license>
<name>antara-sfml-tictactoe</name>
<summary>tic tac toe example with antara gaming sdk and SFML</summary>
<description>
<p>Written in c++17</p>
</description>
<launchable type="desktop-id">org.antara.gaming.sfml.tictactoe.desktop</launchable>
<url type="homepage">https://github.com/KomodoPlatform/antara-gaming-sdk</url>
<screenshots>
<screenshot type="default">
<image>https://www.freedesktop.org/software/appstream/docs/images/scr-examples/geany-good.png</image>
</screenshot>
</screenshots>
<provides>
<id>org.antara.gaming.sfml.tictactoe.desktop</id>
</provides>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Desktop Entry]
Type=Application
Name=antara-sfml-tictactoe
Exec=antara-sfml-tictactoe
Icon=komodo_icon
Categories=Game;
Binary file not shown.
57 changes: 57 additions & 0 deletions examples/sfml/tic-tac-toe/data/osx/Packaging_CMakeDMGSetup.scpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
on run argv
set image_name to item 1 of argv

tell application "Finder"
tell disk image_name

-- wait for the image to finish mounting
set open_attempts to 0
repeat while open_attempts < 4
try
open
delay 1
set open_attempts to 5
close
on error errStr number errorNumber
set open_attempts to open_attempts + 1
delay 10
end try
end repeat
delay 5

-- open the image the first time and save a DS_Store with just
-- background and icon setup
open
set current view of container window to icon view
set theViewOptions to the icon view options of container window
set background picture of theViewOptions to file ".background:background.tif"
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 128
delay 5
close

-- next setup the position of the app and Applications symlink
-- plus hide all the window decorationPackaging_CMakeDMGBackground.tif
open
update without registering applications
tell container window
set sidebar width to 0
set statusbar visible to false
set toolbar visible to false
set the bounds to { 400, 100, 900, 465 }
set position of item "antara-sfml-tictactoe.app" to { 133, 200 }
set position of item "Applications" to { 378, 200 }
end tell
update without registering applications
delay 5
close

-- one last open and close so you can see everything looks correct
open
delay 5
close

end tell
delay 1
end tell
end run
Binary file added examples/sfml/tic-tac-toe/data/osx/kmd_logo.icns
Binary file not shown.
35 changes: 35 additions & 0 deletions examples/sfml/tic-tac-toe/data/osx/sfml_tictactoe_install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
if (APPLE)
set_target_properties(antara-sfml-tictactoe PROPERTIES
MACOSX_BUNDLE_BUNDLE_NAME "antara-sfml-tictactoe"
RESOURCE data/osx/antara-sfml-tictactoe.icns
MACOSX_BUNDLE_ICON_FILE antara-sfml-tictactoe
MACOSX_BUNDLE_SHORT_VERSION_STRING 0.0.1
MACOSX_BUNDLE_LONG_VERSION_STRING 0.0.1
MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/cmake/MacOSXBundleInfo.plist.in")
add_custom_command(TARGET antara-sfml-tictactoe
POST_BUILD COMMAND
${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../Frameworks/"
$<TARGET_FILE:antara-sfml-tictactoe>)
endif ()

if (APPLE)
install(TARGETS antara-sfml-tictactoe
BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION bin COMPONENT Runtime
)

# Note Mac specific extension .app
set(APPS "\${CMAKE_INSTALL_PREFIX}/antara-sfml-tictactoe.app")

# Directories to look for dependencies
set(DIRS ${CMAKE_BINARY_DIR})

install(CODE "include(BundleUtilities)
fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")")

set(CPACK_GENERATOR "DRAGNDROP")
set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/data/osx/Packaging_CMakeDMGSetup.scpt")
set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/data/osx/Packaging_CMakeDMGBackground.tif")
set(CPACK_PACKAGE_NAME "antara-sfml-tictactoe")
include(CPack)
endif ()
Loading