Skip to content

Commit

Permalink
ready to deploy appimage
Browse files Browse the repository at this point in the history
  • Loading branch information
theoden8 committed Dec 21, 2019
1 parent 432be77 commit 1270c8a
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 22 deletions.
10 changes: 7 additions & 3 deletions AutomatonApp.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#pragma once

#include <string>

#include <Window.hpp>
#include <Renderer.hpp>


class AutomatonApp {
Window w;
const std::string dir;
public:
AutomatonApp(Window &w):
w(w)
AutomatonApp(Window &w, std::string &dir):
w(w),
dir(dir)
{}

template <typename AUT>
Expand All @@ -19,7 +23,7 @@ class AutomatonApp {
gl::ShaderProgram<
gl::VertexShader,
gl::FragmentShader
> prog({"shaders/aut4.vert"s, "shaders/aut4.frag"s});
> prog({dir+"shaders/aut4.vert"s, dir+"shaders/aut4.frag"s});

using ShaderAttrib = decltype(attrVertex);
using ShaderProgram = decltype(prog);
Expand Down
27 changes: 25 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ else()
message(WARNING "You are using unsupported compiler, and will probably have to change the source code.")
endif()

# set(CMAKE_CXX_FLAGS "-std=c++17 -fopenmp -Wall")
set(CMAKE_CXX_FLAGS "-std=c++17 -Wall")
if(UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS "-std=c++17 -fopenmp -Wall")
else()
set(CMAKE_CXX_FLAGS "-std=c++17 -Wall")
endif()

set(exec automaton)
add_executable(${exec} ./main.cpp)
include_directories($(CMAKE_CURRENT_SOURCE_DIR))

file(COPY shaders DESTINATION ${CMAKE_BINARY_DIR})
file(COPY resources DESTINATION ${CMAKE_BINARY_DIR})

find_package(PkgConfig REQUIRED)

find_package(Threads REQUIRED)
Expand All @@ -41,6 +47,23 @@ target_link_libraries(${exec}
PkgConfig::GLM
)

include(ExternalProject)
ExternalProject_Add(Nuklear
GIT_REPOSITORY https://github.com/Immediate-Mode-UI/Nuklear
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
include_directories(${CMAKE_BINARY_DIR}/Nuklear-prefix/src)
add_dependencies(${exec} Nuklear)

if(UNIX)
install(DIRECTORY resources DESTINATION "${CMAKE_INSTALL_PREFIX}/..")
install(TARGETS ${exec} DESTINATION "${CMAKE_INSTALL_PREFIX}")
install(DIRECTORY shaders DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
install(DIRECTORY resources DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
endif(UNIX)

# find_package(EPOXY REQUIRED)
# pkg_search_module(EPOXY REQUIRED epoxy)
# pkg_check_modules(EPOXY epoxy REQUIRED)
Expand Down
52 changes: 39 additions & 13 deletions File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,53 @@
#include "Debug.hpp"
#include "Logger.hpp"

#include <string>
#include <cstdio>
#include <cassert>
#include <string>
#include <vector>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/file.h>

namespace sys {
namespace HACK {
void rename_file(const char *a, const char *b) {
int err = rename(a, b);
if(err)perror( "Error renaming file");
}

static void swap_files(std::string a, std::string b) {
ASSERT(a != b);
const char *TMP = "dahfsjkgdhjsfgshjkgfdhjgfwfghjfhdgjsvfh";
rename_file(a.c_str(), TMP);
rename_file(b.c_str(), a.c_str());
rename_file(TMP, b.c_str());
/* namespace HACK { */
/* void rename_file(const char *a, const char *b) { */
/* int err = rename(a, b); */
/* if(err)perror( "Error renaming file"); */
/* } */

/* static void swap_files(std::string a, std::string b) { */
/* ASSERT(a != b); */
/* const char *TMP = "dahfsjkgdhjsfgshjkgfdhjgfwfghjfhdgjsvfh"; */
/* rename_file(a.c_str(), TMP); */
/* rename_file(b.c_str(), a.c_str()); */
/* rename_file(TMP, b.c_str()); */
/* } */
/* } */


#ifdef __linux__
static std::string get_executable_path() {
std::vector<char> buf(1000);
readlink("/proc/self/exe", buf.data(), 1000);
return std::string(buf.begin(), buf.end());
}
#endif

std::string get_executable_directory(int argc, char *argv[]) {
#ifdef __linux__
const std::string exec = get_executable_path();
#else
const std::string exec = argv[0];
#endif
std::string::size_type n = exec.rfind('/');
std::string folder;
if(n == std::string::npos) {
folder = "./";
} else {
folder = exec.substr(0, n + 1);
}
return folder;
}

class File {
Expand Down
8 changes: 5 additions & 3 deletions InterfaceApp.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once


#include <cstring>
#include <vector>

#include <Window.hpp>
Expand Down Expand Up @@ -116,21 +117,22 @@ struct InterfaceApp {
if (nk_option_label(ctx, "Rule 110" , autOption == Linear::RULE110)) autOption = Linear::RULE110;
if (nk_option_label(ctx, "Rule 184" , autOption == Linear::RULE184)) autOption = Linear::RULE184;
} else if(autType == CELLULAR) {
nk_layout_row_dynamic(ctx, 30, 6);
nk_layout_row_dynamic(ctx, 30, 4);
if (nk_option_label(ctx, "Replicator" , autOption == Cellular::REPLICATOR )) autOption = Cellular::REPLICATOR;
if (nk_option_label(ctx, "Fredkin" , autOption == Cellular::FREDKIN )) autOption = Cellular::FREDKIN;
if (nk_option_label(ctx, "Seeds" , autOption == Cellular::SEEDS )) autOption = Cellular::SEEDS;
if (nk_option_label(ctx, "Live Or Die" , autOption == Cellular::LIVEORDIE )) autOption = Cellular::LIVEORDIE;
nk_layout_row_dynamic(ctx, 30, 4);
if (nk_option_label(ctx, "Flock" , autOption == Cellular::FLOCK )) autOption = Cellular::FLOCK;
if (nk_option_label(ctx, "Mazectric" , autOption == Cellular::MAZECTRIC )) autOption = Cellular::MAZECTRIC;
nk_layout_row_dynamic(ctx, 30, 6);
if (nk_option_label(ctx, "Maze" , autOption == Cellular::MAZE )) autOption = Cellular::MAZE;
if (nk_option_label(ctx, "Game Of Life", autOption == Cellular::GAMEOFLIFE )) autOption = Cellular::GAMEOFLIFE;
nk_layout_row_dynamic(ctx, 30, 4);
if (nk_option_label(ctx, "Eight Life" , autOption == Cellular::EIGHTLIFE )) autOption = Cellular::EIGHTLIFE;
if (nk_option_label(ctx, "Long Life" , autOption == Cellular::LONGLIFE )) autOption = Cellular::LONGLIFE;
if (nk_option_label(ctx, "TxT" , autOption == Cellular::TXT )) autOption = Cellular::TXT;
if (nk_option_label(ctx, "High Life" , autOption == Cellular::HIGHLIFE )) autOption = Cellular::HIGHLIFE;
nk_layout_row_dynamic(ctx, 30, 5);
nk_layout_row_dynamic(ctx, 30, 4);
if (nk_option_label(ctx, "Move" , autOption == Cellular::MOVE )) autOption = Cellular::MOVE;
if (nk_option_label(ctx, "Stains" , autOption == Cellular::STAINS )) autOption = Cellular::STAINS;
if (nk_option_label(ctx, "Day And Night",autOption == Cellular::DAYANDNIGHT)) autOption = Cellular::DAYANDNIGHT;
Expand Down
7 changes: 6 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <cstdint>
#include <cctype>

#include <string>

#include <Logger.hpp>
#include <Debug.hpp>
#include <File.hpp>

#include <Window.hpp>
#include <InterfaceApp.hpp>
Expand All @@ -19,6 +22,8 @@ int main(int argc, char *argv[]) {
Window w;
w.init();

std::string dir = sys::get_executable_directory(argc, argv);

bool shouldQuit = false;
while(!shouldQuit) {
InterfaceApp iface(w);
Expand All @@ -29,7 +34,7 @@ int main(int argc, char *argv[]) {
}
const int factor = iface.factor;

AutomatonApp app(w);
AutomatonApp app(w, dir);
if(iface.autType == InterfaceApp::LINEAR) {
switch(iface.autOption) {
case InterfaceApp::Linear::RULE30 : app.run<linear::Rule30 >(factor); break;
Expand Down
28 changes: 28 additions & 0 deletions resources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xl version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>automaton</string>
<key>CFBundleIdentifier</key>
<string>com.github.theoden8.emu-automaton</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>LifeEmulator</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<key>CFBundleVersion</key>
<string>0.1.0</string>
<key>CFBundleIconFile</key>
<string>automaton</string>
<key>LSMinimumSystemVersion</key>
<string>10.9</string>
<key>LSUIElement</key>
<true/>
<key>LSBackgroundOnly</key>
<true/>
</dict>
</plist>
7 changes: 7 additions & 0 deletions resources/automaton.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Desktop Entry]
Name=Life Emulator
Type=Application
Terminal=false
Exec=automaton
Icon=automaton
Categories=Game;
Binary file added resources/automaton.icns
Binary file not shown.
Binary file added resources/automaton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions tools/build_appimage
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

[ -z "$LINUXDEPLOY_APPIMAGE" ] && {
>&2 echo "error: LINUXDEPLOY_APPIMAGE is not defined"
exit 1
}

mkdir build_appimage
cd build_appimage || {
>&2 echo "error: failed to change directory"
exit 1
}
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_CXX_COMPILER=$(which clang++) || {
>&2 echo "error running cmake"
}
make install -j4 DESTDIR=AppDir
$LINUXDEPLOY_APPIMAGE --appdir AppDir -i AppDir/resources/automaton.png -d AppDir/resources/automaton.desktop -e AppDir/usr/automaton --output appimage

0 comments on commit 1270c8a

Please sign in to comment.