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

WIP Plugins common code, initial implementation #469

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[skip ci] wip
  • Loading branch information
375gnu committed Oct 24, 2019
commit cd9e49c94938b8264df5f51c0e17c7aa086abd82
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ add_subdirectory(celscript)
# These compiled objects are merged with the celengine library
add_subdirectory(celephem)
add_subdirectory(celcompat)
add_subdirectory(celplugin)

if (ENABLE_TOOLS)
add_subdirectory(tools)
2 changes: 0 additions & 2 deletions src/celengine/parseobject.cpp
Original file line number Diff line number Diff line change
@@ -22,8 +22,6 @@
#include <celephem/spiceorbit.h>
#include <celephem/spicerotation.h>
#endif
#include <celephem/scriptorbit.h>
#include <celephem/scriptrotation.h>
#include <celmath/geomutil.h>
#include <celutil/debug.h>
#include <cassert>
12 changes: 0 additions & 12 deletions src/celephem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -32,18 +32,6 @@ if(ENABLE_SPICE)
)
endif()


if(ENABLE_CELX)
list(APPEND CELEPHEM_SOURCES
scriptobject.cpp
scriptobject.h
scriptorbit.cpp
scriptorbit.h
scriptrotation.cpp
scriptrotation.h
)
endif()

# These object files are merged in the celegine library
add_library(celephem OBJECT ${CELEPHEM_SOURCES})

2 changes: 1 addition & 1 deletion src/celestia/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ endif()
add_library(celestia STATIC ${CELESTIA_SOURCES}
$<TARGET_OBJECTS:celcommonscript>
$<TARGET_OBJECTS:cellegacyscript>
$<TARGET_OBJECTS:celluascript>)
$<TARGET_OBJECTS:celplugin>)

#[[
add_library(celestia SHARED ${CELESTIA_SOURCES})
5 changes: 0 additions & 5 deletions src/celestia/celestiacore.cpp
Original file line number Diff line number Diff line change
@@ -54,11 +54,6 @@
#include <celutil/color.h>
#include <celengine/vecgl.h>
#include <celengine/rectangle.h>

#ifdef CELX
#include <celephem/scriptobject.h>
#endif

#include "imagecapture.h"

// TODO: proper gettext
30 changes: 10 additions & 20 deletions src/celplugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
cmake_minimum_required(VERSION 3.7)
if (NOT WIN32)
add_compile_options(-fPIC)
add_compile_options(-g)
else()
add_definitions(
-D_CRT_SECURE_NO_WARNINGS
-D_SCL_SECURE_NO_WARNINGS
-DNOMINMAX
-DWIN32_LEAN_AND_MEAN
)
endif()
find_package(fmt 4.0.0 CONFIG REQUIRED)
if (WIN32)
set(WINUTIL ../celutil/winutil.cpp)
endif()
add_executable(plugintest host.cpp plugin.cpp pluginmanager.cpp ../celcompat/fs.cpp ../celutil/util.cpp ${WINUTIL})
include_directories(. ..)
target_link_libraries(plugintest fmt::fmt ${CMAKE_DL_LIBS})
add_library(myplug SHARED myplug.cpp)
# These object files are merged in the celegine library
set(CELPLUGIN_SOURCES
plugin-common.h
plugin.cpp
plugin.h
pluginmanager.cpp
pluginmanager.h
)
add_library(celplugin OBJECT ${CELPLUGIN_SOURCES})

Empty file removed src/celplugin/config.h
Empty file.
9 changes: 5 additions & 4 deletions src/celplugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

#include <iostream>
#include <fmt/printf.h>
#include "plugin.h"
#ifndef _WIN32
@@ -133,15 +134,15 @@ IScript* Plugin::createScript(CelestiaCore *appCore) const
return fn == nullptr ? nullptr : (*fn)(appCore);
}

RotationModel* Plugin::createScritedRotation(const std::string& moduleName, const std::string& funcName, Hash* parameters) const
RotationModel* Plugin::createScriptedRotation(const std::string& moduleName, const std::string& funcName, Hash* parameters) const
{
auto fn = m_func.createScritedRotation;
auto fn = m_func.createScriptedRotation;
return fn == nullptr ? nullptr : (*fn)(moduleName, funcName, parameters);
}

CachingOrbit* Plugin::createScritedOrbit(const std::string& moduleName, const std::string& funcName, Hash* parameters) const
CachingOrbit* Plugin::createScriptedOrbit(const std::string& moduleName, const std::string& funcName, Hash* parameters) const
{
auto fn = m_func.createScritedOrbit;
auto fn = m_func.createScriptedOrbit;
return fn == nullptr ? nullptr : (*fn)(moduleName, funcName, parameters);
}

12 changes: 6 additions & 6 deletions src/celplugin/plugin.h
Original file line number Diff line number Diff line change
@@ -61,16 +61,16 @@ class Plugin
/// scripting support
typedef bool(CreateScriptEnvironmentFunc)(CelestiaCore*, const CelestiaConfig*, ProgressNotifier*);
typedef IScript*(CreateScriptFunc)(CelestiaCore*);
typedef RotationModel*(CreateScritedRotationFunc)(const std::string&, const std::string&, Hash*);
typedef CachingOrbit*(CreateScritedOrbitFunc)(const std::string&, const std::string&, Hash*);
typedef RotationModel*(CreateScriptedRotationFunc)(const std::string&, const std::string&, Hash*);
typedef CachingOrbit*(CreateScriptedOrbitFunc)(const std::string&, const std::string&, Hash*);

/// renderer support
typedef Renderer*(CreateRendererFunc)();

bool createScriptEnvironment(CelestiaCore *appCore, const CelestiaConfig *config, ProgressNotifier *progressNotifier) const;
IScript* createScript(CelestiaCore *appCore) const;
RotationModel* createScritedRotation(const std::string& moduleName, const std::string& funcName, Hash* parameters) const;
CachingOrbit* createScritedOrbit(const std::string& moduleName, const std::string& funcName, Hash* parameters) const;
RotationModel* createScriptedRotation(const std::string& moduleName, const std::string& funcName, Hash* parameters) const;
CachingOrbit* createScriptedOrbit(const std::string& moduleName, const std::string& funcName, Hash* parameters) const;
Renderer* createRenderer() const;

private:
@@ -96,8 +96,8 @@ class Plugin
{
CreateScriptEnvironmentFunc *createScriptEnvironment;
CreateScriptFunc *createScript;
CreateScritedRotationFunc *createScritedRotation;
CreateScritedOrbitFunc *createScritedOrbit;
CreateScriptedRotationFunc *createScriptedRotation;
CreateScriptedOrbitFunc *createScriptedOrbit;
};
struct
{
8 changes: 7 additions & 1 deletion src/celscript/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -26,6 +26,12 @@ set(CELX_SOURCES
celx_vector.h
luascript.cpp
luascript.h
scriptobject.cpp
scriptobject.h
scriptorbit.cpp
scriptorbit.h
scriptrotation.cpp
scriptrotation.h
)

add_library(celluascript OBJECT ${CELX_SOURCES})
add_library(celluascript SHARED ${CELX_SOURCES})
2 changes: 1 addition & 1 deletion src/celscript/lua/luascript.cpp
Original file line number Diff line number Diff line change
@@ -13,12 +13,12 @@
#include <fmt/printf.h>
#include <celcompat/filesystem.h>
#include <celcompat/memory.h>
#include <celephem/scriptobject.h>
#include <celestia/configfile.h>
#include <celestia/celestiacore.h>
#include <celutil/util.h>
#include "celx_internal.h"
#include "luascript.h"
#include "scriptobject.h"

using namespace std;

File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions src/celephem/scriptorbit.cpp → src/celscript/lua/scriptorbit.cpp
Original file line number Diff line number Diff line change
@@ -17,6 +17,40 @@
using namespace Eigen;
using namespace std;

static ScriptedOrbit*
CreateScriptedOrbit(Hash* orbitData,
const fs::path& path)
{
#if !defined(CELX)
clog << "ScriptedOrbit not usable without scripting support.\n";
return nullptr;
#else

// Function name is required
string funcName;
if (!orbitData->getString("Function", funcName))
{
clog << "Function name missing from script orbit definition.\n";
return nullptr;
}

// Module name is optional
string moduleName;
orbitData->getString("Module", moduleName);

Value* pathValue = new Value(path.string());
orbitData->addValue("AddonPath", *pathValue);

ScriptedOrbit* scriptedOrbit = new ScriptedOrbit();
if (!scriptedOrbit->initialize(moduleName, funcName, orbitData))
{
delete scriptedOrbit;
scriptedOrbit = nullptr;
}

return scriptedOrbit;



/*! Initialize the script orbit.
* moduleName is the name of a module that contains the orbit factory
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
#define _CELENGINE_SCRIPTORBIT_H_

#include <celengine/parser.h>
#include "orbit.h"
#include <celephem/orbit.h>

struct lua_State;

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
#define _CELENGINE_SCRIPTROTATION_H_

#include <celengine/parser.h>
#include "rotation.h"
#include <celephem/rotation.h>

struct lua_State;