Common stuff for shared classes.

pull/3/head
pirogronian 2019-09-03 20:32:09 +02:00 committed by Łukasz Buczyński
parent 3a56afb24f
commit c0cc66e77d
7 changed files with 38 additions and 19 deletions

View File

@ -98,6 +98,7 @@ set(CELENGINE_SOURCES
selection.h
shadermanager.cpp
shadermanager.h
shared.h
simulation.cpp
simulation.h
skygrid.cpp

View File

@ -11,12 +11,11 @@
#ifndef _CELENGINE_FRAME_H_
#define _CELENGINE_FRAME_H_
#include <memory>
#include <celengine/astro.h>
#include <celengine/selection.h>
#include <Eigen/Core>
#include <Eigen/Geometry>
#include "shared.h"
/*! A ReferenceFrame object has a center and set of orthogonal axes.
*
@ -27,8 +26,8 @@
class ReferenceFrame
{
public:
using SharedPtr = std::shared_ptr<ReferenceFrame>;
using SharedConstPtr = std::shared_ptr<const ReferenceFrame>;
SHARED_TYPES(ReferenceFrame)
ReferenceFrame(Selection center);
virtual ~ReferenceFrame() {};
@ -72,6 +71,8 @@ class CachingFrame : public ReferenceFrame
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
SHARED_TYPES(CachingFrame)
CachingFrame(Selection _center);
virtual ~CachingFrame() {};
@ -93,6 +94,8 @@ class CachingFrame : public ReferenceFrame
class J2000EclipticFrame : public ReferenceFrame
{
public:
SHARED_TYPES(J2000EclipticFrame)
J2000EclipticFrame(Selection center);
virtual ~J2000EclipticFrame() {};
@ -113,6 +116,8 @@ class J2000EclipticFrame : public ReferenceFrame
class J2000EquatorFrame : public ReferenceFrame
{
public:
SHARED_TYPES(J2000EquatorFrame)
J2000EquatorFrame(Selection center);
virtual ~J2000EquatorFrame() {};
Eigen::Quaterniond getOrientation(double tjd) const;
@ -132,8 +137,8 @@ class J2000EquatorFrame : public ReferenceFrame
class BodyFixedFrame : public ReferenceFrame
{
public:
using SharedPtr = std::shared_ptr<BodyFixedFrame>;
using SharedConstPtr = std::shared_ptr<const BodyFixedFrame>;
SHARED_TYPES(BodyFixedFrame)
BodyFixedFrame(Selection center, Selection obj);
virtual ~BodyFixedFrame() {};
Eigen::Quaterniond getOrientation(double tjd) const;
@ -151,8 +156,8 @@ class BodyFixedFrame : public ReferenceFrame
class BodyMeanEquatorFrame : public ReferenceFrame
{
public:
using SharedPtr = std::shared_ptr<BodyMeanEquatorFrame>;
using SharedConstPtr = std::shared_ptr<const BodyMeanEquatorFrame>;
SHARED_TYPES(BodyMeanEquatorFrame)
BodyMeanEquatorFrame(Selection center, Selection obj, double freeze);
BodyMeanEquatorFrame(Selection center, Selection obj);
virtual ~BodyMeanEquatorFrame() {};

View File

@ -1413,9 +1413,9 @@ ObserverFrame::ObserverFrame(CoordinateSystem _coordSys,
/*! Create a new ObserverFrame with the specified reference frame.
* The coordinate system of this frame will be marked as unknown.
*/
ObserverFrame::ObserverFrame(const ReferenceFrame &f) :
ObserverFrame::ObserverFrame(const ReferenceFrame::SharedConstPtr &f) :
coordSys(Unknown),
frame(&f)
frame(f)
{
}

View File

@ -18,18 +18,17 @@
#ifndef _CELENGINE_OBSERVER_H_
#define _CELENGINE_OBSERVER_H_
#include <memory>
#include <celmath/mathlib.h>
#include <celengine/frame.h>
#include <Eigen/Core>
#include <Eigen/Geometry>
#include "shared.h"
class ObserverFrame
{
public:
using SharedPtr = std::shared_ptr<ObserverFrame>;
using SharedConstPtr = std::shared_ptr<const ObserverFrame>;
SHARED_TYPES(ObserverFrame)
enum CoordinateSystem
{
Universal = 0,
@ -59,7 +58,7 @@ public:
const Selection &_refObject,
const Selection &_targetObj = Selection());
ObserverFrame(const ObserverFrame&);
ObserverFrame(const ReferenceFrame &f);
ObserverFrame(const ReferenceFrame::SharedConstPtr &f);
~ObserverFrame() = default;

View File

@ -0,0 +1,14 @@
#pragma once
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <set>
#define SHARED_TYPES(T) \
typedef typename std::shared_ptr<T> SharedPtr; \
typedef typename std::shared_ptr<const T> SharedConstPtr; \
typedef typename std::unordered_map<T*, SharedPtr> SelfPtrMap; \
typedef typename std::unordered_set<SharedPtr> UnorderedSet; \
typedef typename std::set<SharedPtr> Set;

View File

@ -1122,7 +1122,7 @@ static int object_orbitframe(lua_State* l)
else
{
auto f = sel->body()->getOrbitFrame(t);
celx.newFrame(ObserverFrame(*f));
celx.newFrame(ObserverFrame(f));
}
return 1;
@ -1163,7 +1163,7 @@ static int object_bodyframe(lua_State* l)
else
{
auto f = sel->body()->getBodyFrame(t);
celx.newFrame(ObserverFrame(*f));
celx.newFrame(ObserverFrame(f));
}
return 1;

View File

@ -96,7 +96,7 @@ static int phase_orbitframe(lua_State* l)
auto phase = this_phase(l);
auto f = phase->orbitFrame();
celx.newFrame(ObserverFrame(*f));
celx.newFrame(ObserverFrame(f));
return 1;
}
@ -114,7 +114,7 @@ static int phase_bodyframe(lua_State* l)
auto phase = this_phase(l);
auto f = phase->bodyFrame();
celx.newFrame(ObserverFrame(*f));
celx.newFrame(ObserverFrame(f));
return 1;
}