first commit
This commit is contained in:
145
include/engine/project/project.h
Normal file
145
include/engine/project/project.h
Normal file
@ -0,0 +1,145 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NPROJECT__
|
||||
#define __NPROJECT__
|
||||
|
||||
|
||||
#include "project/project_factory_interface.h"
|
||||
#include "project/project_scene_instance.h"
|
||||
#include "project/project_script_unit.h"
|
||||
#include "project/project_layer.h"
|
||||
#include "core/resource_factories.h"
|
||||
#include "core/raster_font.h"
|
||||
#include "core/clock.h"
|
||||
#include "script/script_unit.h"
|
||||
#include "script/script_vm.h"
|
||||
#include "font/font_factory.h"
|
||||
#include "font/font_cache.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
|
||||
namespace Audio { struct IMixer; }
|
||||
namespace Render { class Renderer; }
|
||||
|
||||
namespace Core {
|
||||
using Audio::IMixer;
|
||||
using Render::Renderer;
|
||||
|
||||
//
|
||||
class Project
|
||||
{
|
||||
protected:
|
||||
|
||||
sResourceFactories factories;
|
||||
|
||||
AutoList <ProjectSceneInstance *> instance_list;
|
||||
|
||||
bool prohibit_project_action; ///< Disable all instance creation and layer stack modifications.
|
||||
|
||||
/// Check whether project action are allowed.
|
||||
bool IsProjectActionAllowed(const char *f);
|
||||
|
||||
public:
|
||||
|
||||
String file_path;
|
||||
String name, authors, description, company;
|
||||
|
||||
Script::sVM vm;
|
||||
|
||||
sClock clock;
|
||||
sFontCache font_cache;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
/// @short Render flags.
|
||||
enum RenderFlag
|
||||
{
|
||||
FlagNone = 0,
|
||||
FlagDisableScript = (1 << 0),
|
||||
|
||||
FlagDefault = FlagNone
|
||||
};
|
||||
|
||||
enum ProjectFlag
|
||||
{
|
||||
ProjectFlagNone = 0,
|
||||
ProjectFlagEnd = (1 << 0),
|
||||
ProjectFlagDebugPhysics = (1 << 1)
|
||||
};
|
||||
|
||||
BitField flags;
|
||||
|
||||
AutoList <ProjectLayer *> layer_list;
|
||||
|
||||
void Update(uint scene_update_flag);
|
||||
void Render(Renderer &, RenderFlag = FlagDefault);
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/// Draw profiler.
|
||||
void DrawProfilerText(Renderer &, Render::RasterFont *font[2], float &x, float &y);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
StringList root_script_list, search_path;
|
||||
|
||||
bool CompileRootScripts();
|
||||
|
||||
AutoPtr <ProjectScriptUnit> script_unit;
|
||||
|
||||
void UpdateScriptClock();
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
AutoPtr <IProjectFactory> iproject_factory;
|
||||
|
||||
ProjectSceneInstance *FindSceneInstance(const char *) const;
|
||||
ProjectSceneInstance *FindSceneInstance(const S3D::Scene *) const;
|
||||
ProjectSceneInstance *FindSceneInstance(const S2D::Scene *) const;
|
||||
|
||||
ProjectSceneInstance *Instantiate(const char *name);
|
||||
ProjectSceneInstance *Instantiate(S3D::Scene *);
|
||||
ProjectSceneInstance *Instantiate(S2D::Scene *);
|
||||
|
||||
void Delete(ProjectSceneInstance *scene);
|
||||
|
||||
/// Create a layer for a given project scene.
|
||||
ProjectLayer *AddLayer(ProjectSceneInstance *, float zorder = 0.5);
|
||||
|
||||
bool IsActive(const ProjectSceneInstance &inst) const { return inst.active; }
|
||||
void Activate(ProjectSceneInstance &, bool activate);
|
||||
|
||||
/// Return the number of instantiated layer in the display stack.
|
||||
uint GetInstanceCount() const { return instance_list.GetCount(); }
|
||||
/// Get scene instance list.
|
||||
const AutoList <ProjectSceneInstance *> &GetInstanceList() const { return instance_list; }
|
||||
/// Return the number of active layer in the display stack.
|
||||
uint GetActiveCount() const;
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void ResetStatistics();
|
||||
|
||||
void New();
|
||||
|
||||
bool Open(bool project_mode = true);
|
||||
bool Setup();
|
||||
void Close();
|
||||
|
||||
bool FromMetaTag(NML::Tag &);
|
||||
NML::Tag *AsMetaTag() const;
|
||||
|
||||
Project(ResourceFactories *, IFontFactory *, Script::IVM * = 0);
|
||||
virtual ~Project();
|
||||
};
|
||||
|
||||
} // Core
|
||||
} // GS
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#define __PROJECT_ACTION_SAFETY_CHECK(__RET__) { if (!IsProjectActionAllowed(__FUNCTION__)) return __RET__; }
|
||||
#define __PROJECT_ACTION_SAFETY_CHECK_RAW { if (!IsProjectActionAllowed(__FUNCTION__)) return; }
|
||||
|
||||
|
||||
#endif // __NPROJECT__
|
||||
28
include/engine/project/project_factory_interface.h
Normal file
28
include/engine/project/project_factory_interface.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NPROJECTFACTORYINTERFACE__
|
||||
#define __NPROJECTFACTORYINTERFACE__
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S3D { class PhysicWorld; }
|
||||
namespace Core {
|
||||
|
||||
/// Project factory abstract interface.
|
||||
struct IProjectFactory
|
||||
{
|
||||
/// Return a new physic world interface.
|
||||
virtual S3D::PhysicWorld *NewPhysicWorld() const { return 0; }
|
||||
|
||||
virtual ~IProjectFactory() {}
|
||||
};
|
||||
|
||||
} // Core
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NPROJECTFACTORYINTERFACE__
|
||||
29
include/engine/project/project_layer.h
Normal file
29
include/engine/project/project_layer.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NPROJECTLAYER__
|
||||
#define __NPROJECTLAYER__
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Core {
|
||||
class ProjectSceneInstance;
|
||||
|
||||
/// Project layer to display a scene instance.
|
||||
struct ProjectLayer
|
||||
{
|
||||
ProjectSceneInstance *inst;
|
||||
float zorder;
|
||||
|
||||
ProjectLayer(ProjectSceneInstance *i, float _zorder = 0.5) : inst(i)
|
||||
{ zorder = _zorder; }
|
||||
};
|
||||
|
||||
} // Core
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NPROJECTLAYER__
|
||||
75
include/engine/project/project_scene_instance.h
Normal file
75
include/engine/project/project_scene_instance.h
Normal file
@ -0,0 +1,75 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NPROJECTSCENEINSTANCE__
|
||||
#define __NPROJECTSCENEINSTANCE__
|
||||
|
||||
|
||||
#include "nstring/nstring.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace S2D { class Scene; }
|
||||
namespace S3D { class Scene; }
|
||||
namespace Core {
|
||||
|
||||
// Project scene instance.
|
||||
class ProjectSceneInstance
|
||||
{
|
||||
friend class Project;
|
||||
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
Type_Scene3d = 0,
|
||||
Type_Scene2d
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
bool active;
|
||||
Type type;
|
||||
|
||||
public:
|
||||
|
||||
union
|
||||
{
|
||||
void *instance;
|
||||
S2D::Scene *instance_2d;
|
||||
S3D::Scene *instance_3d;
|
||||
};
|
||||
|
||||
String GetPath() const;
|
||||
|
||||
Type GetType() const { return type; }
|
||||
bool IsActive() const { return active; }
|
||||
|
||||
void Free();
|
||||
|
||||
~ProjectSceneInstance();
|
||||
|
||||
protected:
|
||||
|
||||
ProjectSceneInstance(S3D::Scene *inst)
|
||||
{
|
||||
active = true;
|
||||
type = Type_Scene3d;
|
||||
instance_3d = inst;
|
||||
}
|
||||
ProjectSceneInstance(S2D::Scene *inst)
|
||||
{
|
||||
active = true;
|
||||
type = Type_Scene2d;
|
||||
instance_2d = inst;
|
||||
}
|
||||
};
|
||||
|
||||
} // Core
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NPROJECTSCENEINSTANCE__
|
||||
38
include/engine/project/project_script_unit.h
Normal file
38
include/engine/project/project_script_unit.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __PROJECTSCRIPTUNIT__
|
||||
#define __PROJECTSCRIPTUNIT__
|
||||
|
||||
|
||||
#include "script/script_unit.h"
|
||||
#include "script/script_object.h"
|
||||
#include "memory/nauto_ptr.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace Core {
|
||||
|
||||
/*!
|
||||
@short Project script unit.
|
||||
@author Emmanuel Julien (ejulien@gsworks.fr)
|
||||
*/
|
||||
struct ProjectScriptUnit : public GS::Script::Unit
|
||||
{
|
||||
AutoPtr <Script::Object> setup_callback, update_callback;
|
||||
|
||||
bool Open();
|
||||
void Close();
|
||||
|
||||
ProjectScriptUnit(Script::IVM *);
|
||||
~ProjectScriptUnit();
|
||||
};
|
||||
|
||||
} // Core
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __PROJECTSCRIPTUNIT__
|
||||
Reference in New Issue
Block a user