Skip to content

Commit

Permalink
Merge pull request #40 from Unix4ever/feature/improved-luarocks-opera…
Browse files Browse the repository at this point in the history
…tions-#154493924

[#154493924] improved Luarocks operations
  • Loading branch information
Unix4ever authored Jun 15, 2019
2 parents 86b72d1 + 3fa28ca commit a07b386
Show file tree
Hide file tree
Showing 145 changed files with 1,609 additions and 401 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ endif(CONAN_PACKAGE_NAME)

process_templates()

add_subdirectory(GsageCore)
add_subdirectory(GsageExe)
add_subdirectory(Core)
add_subdirectory(PlugIns)
add_subdirectory(Tests)
add_subdirectory(Vendor)
Expand Down
29 changes: 27 additions & 2 deletions GsageCore/CMakeLists.txt → Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ if(APPLE)
endif(APPLE)

include_directories(
include/
${gsage_SOURCE_DIR}/Vendor/Sol2/include
PRIVATE include/
SYSTEM PUBLIC ${gsage_SOURCE_DIR}/Vendor/Sol2/include
${gsage_SOURCE_DIR}/Vendor/jsoncpp/include
${gsage_SOURCE_DIR}/Vendor/easylogging/include
${gsage_SOURCE_DIR}/Vendor/gmath/src
Expand Down Expand Up @@ -74,3 +74,28 @@ install(TARGETS ${LIB_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
install(TARGETS ${LIB_NAME} DESTINATION "${CMAKE_INSTALL_PATH}/lib")

set(APP_NAME "game")
set(PACKAGER_NAME "packager")

gsage_executable(${APP_NAME} cmd/app.cpp)
console_executable(${PACKAGER_NAME} cmd/packager.cpp)

set(LIBS
GsageCore
easyloggingpp
cpp-channel
)

if(APPLE)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++")
set(LIBS ${LIBS}
${COREFOUNDATION_LIBRARY}
${CARBON}
${IOKIT}
${COCOA_LIBRARY}
)
endif(APPLE)

target_link_libraries(${APP_NAME} ${LIBS})
target_link_libraries(${PACKAGER_NAME} ${LIBS})
File renamed without changes.
83 changes: 83 additions & 0 deletions Core/cmd/packager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
-----------------------------------------------------------------------------
This file is a part of Gsage engine
Copyright (c) 2014-2016 Artem Chernyshev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#define POCO_NO_UNWINDOWS
#include "GsageFacade.h"

#include <stdio.h>
#include <thread>

#include "Logger.h"

#ifndef RESOURCES_FOLDER
#define RESOURCES_FOLDER "./resources"
#endif

#include "sol.hpp"

#ifdef __cplusplus
extern "C" {
#endif

int main(int argc, char *argv[])
{
Gsage::GsageFacade facade;
if(argc == 1) {
LOG(ERROR) << "Usage: executable config.json";
return 1;
}

std::string coreConfig(argv[1]);
Gsage::DataProxy env;
env.put("workdir", RESOURCES_FOLDER);
Gsage::FileLoader::init(Gsage::FileLoader::Json, env);
Gsage::DataProxy config;
if(!Gsage::FileLoader::getSingletonPtr()->load(coreConfig, Gsage::DataProxy(), config))
{
LOG(ERROR) << "Failed to load file " << coreConfig;
return 1;
}

config.put("startupScript", "");
config.put("startLuaInterface", false);

if(!facade.initialize(config, RESOURCES_FOLDER, 0))
{
LOG(ERROR) << "Failed to initialize game engine";
return 1;
}

Gsage::DataProxy deps = facade.getConfig().get("packager.deps", Gsage::DataProxy::create(Gsage::DataWrapper::JSON_OBJECT));
if(!facade.installLuaPackages(deps)) {
LOG(ERROR) << "Failed to install packages";
return 1;
}

return facade.getExitCode();
}
#ifdef __cplusplus
}
#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace Gsage {
class GSAGE_API Event
{
public:
typedef char* const Type;
typedef char const* Type;
typedef const char* ConstType;

Event() {}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ THE SOFTWARE.
#include <channel>
#include <map>

static inline std::string& ltrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
{
str.erase(0, str.find_first_not_of(chars));
return str;
}

static inline std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
{
str.erase(str.find_last_not_of(chars) + 1);
return str;
}

static inline std::string& trim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
{
return ltrim(rtrim(str, chars), chars);
}

static inline std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
Expand Down
76 changes: 68 additions & 8 deletions GsageCore/include/GsageFacade.h → Core/include/GsageFacade.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ namespace Gsage
class GsageFacade : public EventSubscriber<GsageFacade>
{
public:
enum ConfigureFlags {
Plugins = 0x01,
Systems = 0x03, // system configuration should include plugins config as well
Managers = 0x05, // managers configuration should also include plugins config

RestartSystems = 0x1000, // restart systems during reconfigure

All = Plugins | Systems | Managers
};

typedef bool(*INSTALL_PLUGIN)(GsageFacade*);
typedef bool(*UNINSTALL_PLUGIN)(GsageFacade*);

Expand All @@ -85,20 +95,53 @@ namespace Gsage

GsageFacade();
virtual ~GsageFacade();

/**
* Initializes engine, configures systems
*
* @param gsageConfigPath Path to the file with facade settings
*/
virtual bool initialize(const std::string& gsageConfigPath, const std::string& resourcePath, DataProxy* configOverride = 0, FileLoader::Encoding configEncoding = FileLoader::Json);
bool initialize(const DataProxy& config,
const std::string& resourcePath,
unsigned short configureFlags = ConfigureFlags::All
);

/**
* Initializes engine, configures systems
*
* @param gsageConfigPath Path to the file with facade settings
* @param resourcePath Main resource path
* @param configEncoding Config encoding to use for file loading
* @param configureFlags Allows setting what kind of configs run during startup
*/
virtual bool initialize(const std::string& gsageConfigPath, const std::string& resourcePath, FileLoader::Encoding configEncoding = FileLoader::Json, unsigned short configureFlags = ConfigureFlags::All);

/**
* Set new config and run configuration functions
*
* @param config New configuration
* @param configureFlags Configuration flags
* @return true if succeed
*/
virtual bool configure(const DataProxy& config, unsigned short configureFlags = ConfigureFlags::All);

/**
* Configure the engine and systems
*/
virtual bool configurePlugins();

/**
* Configure the engine and systems
*
* @param configuration Config data
* @param restart Forces restart of all systems
*/
virtual bool configure(const DataProxy& configuration, bool restart = false);
virtual bool configureSystems(bool restart = false);

/**
* Configures managers
*/
virtual bool configureManagers();

/**
* Add new system in the engine
*/
Expand Down Expand Up @@ -326,10 +369,10 @@ namespace Gsage
* Register new window manager factory
* @param id factory name
*/
template<class C>
void registerWindowManager(const std::string& id)
template<class C, class ... Types>
void registerWindowManager(const std::string& id, Types ... args)
{
mWindowManagerFactory.registerWindowManager<C>(id);
mWindowManagerFactory.registerWindowManager<C>(id, args...);
}

/**
Expand Down Expand Up @@ -362,13 +405,29 @@ namespace Gsage
* Get installed plugins
*/
const PluginOrder& getInstalledPlugins() const;

/**
* Installs lua dependencies using luarocks
* @param deps Dependency list
*/
bool installLuaPackages(const DataProxy& deps);

/**
* @return true if all passed subsystems were initialized at least one
*/
bool isReady(unsigned short flags) const;

inline DataProxy& getConfig() { return mConfig; }

inline const std::string& getResourcePath() const { return mResourcePath; }
protected:
bool onEngineShutdown(EventDispatcher* sender, const Event& event);
bool onLuaStateChange(EventDispatcher* sender, const Event& event);

bool mStarted;
bool mStartupScriptRun;
std::string mStartupScript;
std::string mResourcePath;
std::atomic<bool> mStopped;
std::vector<std::string> mPluginsFolders;

Expand All @@ -392,8 +451,8 @@ namespace Gsage

PluginOrder mPluginOrder;

typedef std::map<std::string, IPlugin*> Plugins;
Plugins mInstalledPlugins;
typedef std::map<std::string, IPlugin*> InstalledPlugins;
InstalledPlugins mInstalledPlugins;

typedef std::vector<UpdateListener*> UpdateListeners;
UpdateListeners mUpdateListeners;
Expand All @@ -402,6 +461,7 @@ namespace Gsage
UIManagers mUIManagers;

int mExitCode;
unsigned short mReady;
};
}
#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#include "GsageDefinitions.h"

namespace Gsage {

class ScopedCLocale
Expand All @@ -39,7 +41,11 @@ namespace Gsage {
if( mChangeLocaleTemporarily )
{
const char *currentLocale = setlocale( LC_NUMERIC, 0 );
#if GSAGE_PLATFORM == GSAGE_WIN32
strncpy_s( mSavedLocale, currentLocale, 64u );
#else
strncpy( mSavedLocale, currentLocale, 64u );
#endif
mSavedLocale[63] = '\0';
setlocale( LC_NUMERIC, "C" );
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
66 changes: 66 additions & 0 deletions Core/include/WIN32/CommandLine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
-----------------------------------------------------------------------------
This file is part of Gsage engine
Copyright (c) 2014-2019 Gsage Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#include "GsageDefinitions.h"

#if GSAGE_PLATFORM == GSAGE_WIN32
#ifndef __COMMAND_LINE_TOOLS_H__
#define __COMMAND_LINE_TOOLS_H__

#include <memory>
#include "sol_forward.hpp"

namespace Gsage {
// this package is here to fix built-in Lua behaviour of using standard shell
// on Windows, which leads to opening countless cmd windows

/**
* Represents command line run pipe object
*/
struct CommandPipe {
void close();
sol::object next(sol::this_state s);
CommandPipe* lines();
void execute(const std::string& command);
sol::object read(sol::object arg, sol::this_state s);
std::string readLine();

unsigned long exitCode;
std::stringstream data;
};

typedef std::shared_ptr<CommandPipe> CommandPipePtr;

/**
* Run shell command and returns status
*/
int luaCmd(const std::string& command);

CommandPipePtr luaPopen(const std::string& command);
}

#endif
#endif
File renamed without changes.
Loading

0 comments on commit a07b386

Please sign in to comment.