Wrapping runtime compiled code as a module manager
parent
8095b4aef2
commit
523c9996a8
|
@ -65,8 +65,8 @@ SET ( protot_SRCS
|
||||||
src/shaderc_glsl.cpp
|
src/shaderc_glsl.cpp
|
||||||
src/shaderc_hlsl.cpp
|
src/shaderc_hlsl.cpp
|
||||||
|
|
||||||
src/Scene.cc
|
src/ModuleManager.cc
|
||||||
src/SceneObject.cpp
|
src/TestModule.cpp
|
||||||
|
|
||||||
3rdparty/glfw/deps/glad.c
|
3rdparty/glfw/deps/glad.c
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "Scene.h"
|
#include "ModuleManager.h"
|
||||||
|
|
||||||
// Runtime Compiled Cpp
|
// Runtime Compiled Cpp
|
||||||
#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObjectFactorySystem.h"
|
#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObjectFactorySystem.h"
|
||||||
|
@ -26,13 +26,13 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Scene::Scene() :
|
ModuleManager::ModuleManager() :
|
||||||
mCompilerLogger(nullptr),
|
mCompilerLogger(nullptr),
|
||||||
mRuntimeObjectSystem(nullptr),
|
mRuntimeObjectSystem(nullptr)
|
||||||
mUpdateable(nullptr) {
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Scene::~Scene() {
|
ModuleManager::~ModuleManager() {
|
||||||
if (mRuntimeObjectSystem != nullptr) {
|
if (mRuntimeObjectSystem != nullptr) {
|
||||||
mRuntimeObjectSystem->CleanObjectFiles();
|
mRuntimeObjectSystem->CleanObjectFiles();
|
||||||
}
|
}
|
||||||
|
@ -40,16 +40,18 @@ Scene::~Scene() {
|
||||||
if (mRuntimeObjectSystem && mRuntimeObjectSystem->GetObjectFactorySystem()) {
|
if (mRuntimeObjectSystem && mRuntimeObjectSystem->GetObjectFactorySystem()) {
|
||||||
mRuntimeObjectSystem->GetObjectFactorySystem()->RemoveListener(this);
|
mRuntimeObjectSystem->GetObjectFactorySystem()->RemoveListener(this);
|
||||||
|
|
||||||
// delete object via correct interface
|
for (unsigned int i = 0; i < mModuleIds.size(); i++) {
|
||||||
IObject* obj = mRuntimeObjectSystem->GetObjectFactorySystem()->GetObject( mObjectId );
|
// delete object via correct interface
|
||||||
delete obj;
|
IObject* obj = mRuntimeObjectSystem->GetObjectFactorySystem()->GetObject( mModuleIds[i] );
|
||||||
|
delete obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete mRuntimeObjectSystem;
|
delete mRuntimeObjectSystem;
|
||||||
delete mCompilerLogger;
|
delete mCompilerLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Scene::init() {
|
bool ModuleManager::init() {
|
||||||
mRuntimeObjectSystem = new RuntimeObjectSystem;
|
mRuntimeObjectSystem = new RuntimeObjectSystem;
|
||||||
mCompilerLogger = new StdioLogSystem();
|
mCompilerLogger = new StdioLogSystem();
|
||||||
|
|
||||||
|
@ -60,48 +62,66 @@ bool Scene::init() {
|
||||||
|
|
||||||
mRuntimeObjectSystem->GetObjectFactorySystem()->AddListener(this);
|
mRuntimeObjectSystem->GetObjectFactorySystem()->AddListener(this);
|
||||||
|
|
||||||
// construct an object
|
|
||||||
IObjectConstructor* constructor = mRuntimeObjectSystem->GetObjectFactorySystem()->GetConstructor("SceneObject");
|
|
||||||
if (constructor) {
|
|
||||||
IObject* obj = constructor->Construct();
|
|
||||||
obj->GetInterface(&mUpdateable);
|
|
||||||
|
|
||||||
if (nullptr == mUpdateable) {
|
|
||||||
delete obj;
|
|
||||||
mCompilerLogger->LogError("Error - no updateable interface found!\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mObjectId = obj->GetObjectId();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::OnConstructorsAdded() {
|
void ModuleManager::OnConstructorsAdded() {
|
||||||
if (mUpdateable) {
|
for (unsigned int i = 0; i < mModules.size(); i++) {
|
||||||
IObject* obj = mRuntimeObjectSystem->GetObjectFactorySystem()->GetObject(mObjectId);
|
IUpdateable* module = mModules[i];
|
||||||
obj->GetInterface(&mUpdateable);
|
|
||||||
|
if (!module)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
IObject* obj = mRuntimeObjectSystem->GetObjectFactorySystem()->GetObject(mModuleIds[i]);
|
||||||
|
obj->GetInterface(&mModules[i]);
|
||||||
|
|
||||||
if (nullptr == mUpdateable) {
|
if (nullptr == module) {
|
||||||
delete obj;
|
delete obj;
|
||||||
mCompilerLogger->LogError("Error - no updateable interface found!\n");
|
mCompilerLogger->LogError("Error - no updateable interface found!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::update() {
|
void ModuleManager::update() {
|
||||||
if (mRuntimeObjectSystem->GetIsCompiledComplete()) {
|
if (mRuntimeObjectSystem->GetIsCompiledComplete()) {
|
||||||
mRuntimeObjectSystem->LoadCompiledModule();
|
mRuntimeObjectSystem->LoadCompiledModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mRuntimeObjectSystem->GetIsCompiling()) {
|
if (!mRuntimeObjectSystem->GetIsCompiling()) {
|
||||||
static int num_updates = 0;
|
static int num_updates = 0;
|
||||||
|
num_updates ++;
|
||||||
std::cout << "Main loop. num_updates = " << num_updates << "\n";
|
std::cout << "Main loop. num_updates = " << num_updates << "\n";
|
||||||
|
|
||||||
const float delta_time = 1.0f;
|
const float delta_time = 1.0f;
|
||||||
mRuntimeObjectSystem->GetFileChangeNotifier()->Update(delta_time);
|
mRuntimeObjectSystem->GetFileChangeNotifier()->Update(delta_time);
|
||||||
mUpdateable->Update(delta_time);
|
|
||||||
usleep(1000 * 1000);
|
for (unsigned int i = 0; i < mModules.size(); i++) {
|
||||||
|
mModules[i]->Update(delta_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(1000 * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ModuleManager::RegisterModule(const char* name) {
|
||||||
|
cout << "Registering Module: " << name << endl;
|
||||||
|
|
||||||
|
// construct an object
|
||||||
|
IObjectConstructor* constructor = mRuntimeObjectSystem->GetObjectFactorySystem()->GetConstructor(name);
|
||||||
|
if (constructor) {
|
||||||
|
IObject* obj = constructor->Construct();
|
||||||
|
IUpdateable** module = new IUpdateable*[1];
|
||||||
|
obj->GetInterface(module);
|
||||||
|
|
||||||
|
if (nullptr == module) {
|
||||||
|
delete obj;
|
||||||
|
mCompilerLogger->LogError("Error - no updateable interface found!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mModules.push_back(*module);
|
||||||
|
mModuleIds.push_back(obj->GetObjectId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -6,17 +6,20 @@
|
||||||
struct IUpdateable;
|
struct IUpdateable;
|
||||||
struct IRuntimeObjectSystem;
|
struct IRuntimeObjectSystem;
|
||||||
|
|
||||||
struct Scene : IObjectFactoryListener {
|
struct ModuleManager : IObjectFactoryListener {
|
||||||
ICompilerLogger* mCompilerLogger;
|
ICompilerLogger* mCompilerLogger;
|
||||||
IRuntimeObjectSystem* mRuntimeObjectSystem;
|
IRuntimeObjectSystem* mRuntimeObjectSystem;
|
||||||
|
|
||||||
IUpdateable* mUpdateable;
|
std::vector<IUpdateable*> mModules;
|
||||||
ObjectId mObjectId;
|
std::vector<ObjectId> mModuleIds;
|
||||||
|
|
||||||
Scene();
|
ModuleManager();
|
||||||
virtual ~Scene();
|
virtual ~ModuleManager();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
void OnConstructorsAdded();
|
|
||||||
void update ();
|
void update ();
|
||||||
|
|
||||||
|
void OnConstructorsAdded();
|
||||||
|
bool RegisterModule(const char* name);
|
||||||
|
|
||||||
};
|
};
|
|
@ -20,8 +20,6 @@
|
||||||
|
|
||||||
#include "math_types.h"
|
#include "math_types.h"
|
||||||
|
|
||||||
#include "Scene.h"
|
|
||||||
|
|
||||||
// BGFX globals
|
// BGFX globals
|
||||||
|
|
||||||
bgfx::VertexBufferHandle cube_vbh;
|
bgfx::VertexBufferHandle cube_vbh;
|
||||||
|
@ -465,8 +463,6 @@ class BGFXCallbacks: public bgfx::CallbackI {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Scene scene;
|
|
||||||
|
|
||||||
void Renderer::initialize(int width, int height) {
|
void Renderer::initialize(int width, int height) {
|
||||||
this->width = width;
|
this->width = width;
|
||||||
this->height = height;
|
this->height = height;
|
||||||
|
@ -534,8 +530,6 @@ void Renderer::initialize(int width, int height) {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
resize (width, height);
|
resize (width, height);
|
||||||
bgfx::frame();
|
bgfx::frame();
|
||||||
|
|
||||||
scene.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::shutdown() {
|
void Renderer::shutdown() {
|
||||||
|
@ -600,16 +594,15 @@ void Renderer::paintGLSimple() {
|
||||||
const double toMs = 1000.0/freq;
|
const double toMs = 1000.0/freq;
|
||||||
|
|
||||||
// Use debug font to print information about this example.
|
// Use debug font to print information about this example.
|
||||||
bgfx::dbgTextClear();
|
|
||||||
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/00-helloworld");
|
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/00-helloworld");
|
||||||
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Initialization and debug text.");
|
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Initialization and debug text.");
|
||||||
bgfx::dbgTextPrintf(0, 3, 0x8f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
|
bgfx::dbgTextPrintf(0, 3, 0x8f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
|
||||||
|
|
||||||
scene.update();
|
|
||||||
|
|
||||||
// Advance to next frame. Rendering thread will be kicked to
|
// Advance to next frame. Rendering thread will be kicked to
|
||||||
// process submitted rendering primitives.
|
// process submitted rendering primitives.
|
||||||
bgfx::frame();
|
bgfx::frame();
|
||||||
|
bgfx::dbgTextClear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::paintGL() {
|
void Renderer::paintGL() {
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
#include "RuntimeCompiledCpp/RuntimeObjectSystem/ObjectInterfacePerModule.h"
|
|
||||||
#include "RuntimeCompiledCpp/RuntimeObjectSystem/IObject.h"
|
|
||||||
|
|
||||||
#include "IUpdateable.h"
|
|
||||||
#include "InterfaceIds.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
|
||||||
class SceneObject : public TInterface<IID_IUPDATEABLE,IUpdateable>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void Update( float deltaTime )
|
|
||||||
{
|
|
||||||
std::cout << "Runtime Object 01231 update called!\n";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
REGISTERCLASS(SceneObject);
|
|
|
@ -5,14 +5,13 @@
|
||||||
#include "rcpp/InterfaceIds.h"
|
#include "rcpp/InterfaceIds.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
class TestModule : public TInterface<IID_IUPDATEABLE,IUpdateable>
|
||||||
class SceneObject : public TInterface<IID_IUPDATEABLE,IUpdateable>
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void Update( float deltaTime )
|
virtual void Update( float deltaTime )
|
||||||
{
|
{
|
||||||
std::cout << "Runtime Object 23 update called!\n";
|
std::cout << "TestModule: 1 Runtime Object 214 update called!\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTERCLASS(SceneObject);
|
REGISTERCLASS(TestModule);
|
|
@ -48,6 +48,7 @@
|
||||||
#include "bgfx/bgfxplatform.h"
|
#include "bgfx/bgfxplatform.h"
|
||||||
#include "bx/timer.h"
|
#include "bx/timer.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
#include "ModuleManager.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -153,6 +154,11 @@ int main(void)
|
||||||
// Set view 0 clear state.
|
// Set view 0 clear state.
|
||||||
// bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x3070F0FF);
|
// bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x3070F0FF);
|
||||||
|
|
||||||
|
printf("Initializing ModuleManager...\n");
|
||||||
|
ModuleManager module_manager;
|
||||||
|
module_manager.init();
|
||||||
|
module_manager.RegisterModule("TestModule");
|
||||||
|
|
||||||
printf("Starting main loop...\n");
|
printf("Starting main loop...\n");
|
||||||
glfwSetKeyCallback(win, key_callback);
|
glfwSetKeyCallback(win, key_callback);
|
||||||
int64_t time_offset = bx::getHPCounter();
|
int64_t time_offset = bx::getHPCounter();
|
||||||
|
@ -173,7 +179,10 @@ int main(void)
|
||||||
renderer.resize(width, height);
|
renderer.resize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module_manager.update();
|
||||||
|
|
||||||
renderer.paintGLSimple();
|
renderer.paintGLSimple();
|
||||||
|
|
||||||
// bgfx::setViewRect(0, 0, 0, width, height);
|
// bgfx::setViewRect(0, 0, 0, width, height);
|
||||||
|
|
||||||
// Dummy submit call to make sure view 0 is cleared
|
// Dummy submit call to make sure view 0 is cleared
|
||||||
|
|
Loading…
Reference in New Issue