fix InstanceFactory for World::load

This commit is contained in:
floralrainfall 2023-07-18 20:54:41 -04:00
parent 0861cfbc6e
commit e48ac7f435
21 changed files with 174 additions and 48 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 770 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 912 B

View File

@ -20,6 +20,10 @@ if(COMPILE_PLAYER OR COMPILE_STUDIO)
if(COMPILE_STUDIO)
add_subdirectory(Studio)
endif()
if(NOT CI)
file(COPY ${CMAKE_SOURCE_DIR}/Content/RNR/ DESTINATION ${CMAKE_BINARY_DIR}/content)
endif()
endif()
if(COMPILE_SERVER)

View File

@ -37,6 +37,8 @@ class MainWindow : public QMainWindow
public slots:
void loadDatamodel();
void selectInstance(QTreeWidgetItem *item, int column);
void run();
void pause();
protected:
void widgetItemPrepare(QTreeWidgetItem* item, RNR::Instance* instance);
void recurseTreeAddInstance(QTreeWidgetItem* parent, RNR::Instance* instance);

View File

@ -108,6 +108,19 @@ void MainWindow::createToolbar()
QAction* load_action = file_menu->addAction("Load", this, SLOT(loadDatamodel()));
QMenu* help_menu = menubar->addMenu("Help");
help_menu->addAction("About...");
QAction* run_action = toolbar->addAction(QIcon("content/textures/studio/icons/run.png"), "", this, SLOT(run()));
QAction* pause_action = toolbar->addAction(QIcon("content/textures/studio/icons/pause.png"), "", this, SLOT(pause()));
}
void MainWindow::run()
{
this->ogreWidget->world->getRunService()->run();
}
void MainWindow::pause()
{
this->ogreWidget->world->getRunService()->pause();
}
void MainWindow::closeEvent(QCloseEvent* event)

View File

@ -45,6 +45,15 @@ void PropertyViewer::view(RNR::Instance* instance)
QTableWidgetItem* new_property_itemval = new QTableWidgetItem(tr("%1").arg(property.toString().c_str()));
new_property_itemval->setToolTip(QString(property.description().c_str()));
if(property.op() == RNR::OPERATION_READ)
{
cell_flags = new_property_itemval->flags();
cell_flags.setFlag(Qt::ItemFlag::ItemIsEditable, false);
cell_flags.setFlag(Qt::ItemFlag::ItemIsEnabled, false);
new_property_itemval->setFlags(cell_flags);
new_property_item->setFlags(cell_flags);
}
switch(property.type())
{
case RNR::PROPERTY_BOOL:
@ -52,7 +61,7 @@ void PropertyViewer::view(RNR::Instance* instance)
bool check_state = *(bool*)property.rawGetter();
new_property_itemval->setCheckState(check_state ? Qt::Checked : Qt::Unchecked);
new_property_itemval->setText("");
cell_flags = new_property_itemval->flags();
cell_flags.setFlag(Qt::ItemFlag::ItemIsEditable, false);
new_property_itemval->setFlags(cell_flags);

View File

@ -14,6 +14,7 @@ add_library(Engine STATIC
Header/App/V8/DataModel/ForceField.hpp
Header/App/V8/DataModel/PartInstance.hpp
Header/App/V8/DataModel/FaceInstance.hpp
Header/App/V8/DataModel/RunService.hpp
Header/App/V8/DataModel/Workspace.hpp
Header/App/V8/Tree/Instance.hpp
Header/App/V8/Tree/InstanceFactory.hpp
@ -40,6 +41,7 @@ add_library(Engine STATIC
Source/App/V8/DataModel/ForceField.cpp
Source/App/V8/DataModel/PartInstance.cpp
Source/App/V8/DataModel/FaceInstance.cpp
Source/App/V8/DataModel/RunService.cpp
Source/App/V8/DataModel/Workspace.cpp
Source/App/V8/Tree/Instance.cpp
Source/App/V8/Tree/InstanceFactory.cpp

View File

@ -71,6 +71,8 @@ namespace RNR
std::string name() { return m_name; }
std::string description() { return m_description; }
ReflectionPropertyType type() { return m_type; }
ReflectionPropertyAccess accessLevel() { return m_access; }
ReflectionPropertyOperation op() { return m_op; }
const void* rawGetter() { return m_getter(m_object); }
void rawSetter(const void* value) { return m_setter((void*)m_object, value); }

View File

@ -13,7 +13,7 @@ namespace RNR
private:
CoordinateFrame m_cframe;
virtual void deserializeProperty(char* prop_name, pugi::xml_node prop);
virtual void addProperties(std::vector<ReflectionProperty>& properties);
virtual void addProperties(std::vector<ReflectionProperty>& properties);
public:
Camera();
~Camera();

View File

@ -8,6 +8,7 @@ namespace RNR
public:
DataModel();
Instance* getService(std::string service_name);
private:
};

View File

@ -0,0 +1,29 @@
#pragma once
#include <App/V8/Tree/Instance.hpp>
namespace RNR
{
class RunService : public Instance
{
private:
float m_time;
bool m_running;
bool m_paused;
virtual void addProperties(std::vector<ReflectionProperty>& properties);
public:
RunService();
virtual std::string getClassName() { return "RunService"; }
bool getRunning() { return m_running; }
bool getPaused() { return m_paused; }
void step(float delta);
void run();
void pause();
void reset();
};
}

View File

@ -36,7 +36,7 @@ namespace RNR
~Instance();
virtual std::vector<ReflectionProperty> getProperties();
void deserializeXmlProperty(pugi::xml_node prop);
void deserializeXmlProperty(pugi::xml_node prop); // TODO: eventually replace this with a method that uses getProperties
bool contains(RNR::Instance* child);
bool isAncestorOf(RNR::Instance* instance);

View File

@ -1,8 +1,11 @@
#pragma once
#include <App/V8/Tree/Instance.hpp>
#include <App/V8/Tree/InstanceFactory.hpp>
#include <App/V8/DataModel/Workspace.hpp>
#include <App/V8/DataModel/Camera.hpp>
#include <App/V8/DataModel/RunService.hpp>
#include <App/V8/DataModel/DataModel.hpp>
#include <App/GUI/TopMenuBar.hpp>
#include <OGRE/Ogre.h>
#include <pugixml.hpp>
@ -21,11 +24,13 @@ namespace RNR
private:
std::map<std::string, Instance*> m_refs;
std::stack<WorldUndeserialized> m_undeserialized;
Instance* m_datamodel;
DataModel* m_datamodel;
Workspace* m_workspace;
RunService* m_runService;
Ogre::Root* m_ogreRoot;
Ogre::SceneManager* m_ogreSceneManager;
TopMenuBar* m_tmb;
InstanceFactory* m_instanceFactory;
void xmlAddItem(pugi::xml_node node, Instance* parent);
public:
@ -42,10 +47,12 @@ namespace RNR
Instance* getDatamodel() { return m_datamodel; }
void setDatamodel(Instance* instance) { m_datamodel = instance; }
DataModel* getDatamodel() { return m_datamodel; }
void setDatamodel(DataModel* instance) { m_datamodel = instance; }
Workspace* getWorkspace() { return m_workspace; }
void setWorkspace(Workspace* workspace) { m_workspace = workspace; }
RunService* getRunService() { return m_runService; }
void setRunService(RunService* runService) { m_runService = runService; }
Ogre::Root* getOgreRoot() { return m_ogreRoot; }
Ogre::SceneManager* getOgreSceneManager() { return m_ogreSceneManager; }
};

View File

@ -1,9 +1,24 @@
#include <App/V8/DataModel/DataModel.hpp>
#include <App/V8/Tree/InstanceFactory.hpp>
namespace RNR
{
DataModel::DataModel()
{
}
Instance* DataModel::getService(std::string service_name)
{
Instance* service = findFirstChildOfType(service_name);
if(!service)
{
service = InstanceFactory::singleton()->build(service_name);
if(service)
{
service->setParent(this);
}
}
return service;
}
}

View File

@ -8,8 +8,9 @@ namespace RNR
{
setName("Part");
updateMatrix();
m_color = Ogre::Vector4(0.63, 0.64, 0.63, 1.0);
updateMatrix();
}
void PartInstance::updateMatrix()

View File

@ -0,0 +1,52 @@
#include <App/V8/DataModel/RunService.hpp>
namespace RNR
{
RunService::RunService()
{
setName("RunService");
m_time = 0;
m_running = false;
m_paused = false;
}
void RunService::step(float time)
{
if(m_running && !m_paused)
{
m_time += time;
}
}
void RunService::run()
{
m_running = true;
m_paused = false;
}
void RunService::reset()
{
}
void RunService::pause()
{
m_paused = true;
}
void RunService::addProperties(std::vector<ReflectionProperty>& properties)
{
ReflectionProperty _properties[] = {
{ this, std::string("Running"), std::string(""),
ACCESS_NONE, OPERATION_READ, PROPERTY_BOOL,
REFLECTION_GETTER(RunService* instance = (RunService*)object; return &instance->m_running; ),
REFLECTION_SETTER( ) }, // do nothing
{ this, std::string("Paused"), std::string(""),
ACCESS_NONE, OPERATION_READ, PROPERTY_BOOL,
REFLECTION_GETTER(RunService* instance = (RunService*)object; return &instance->m_paused; ),
REFLECTION_SETTER( ) }, // do nothing
};
properties.insert(properties.end(), _properties, _properties+(sizeof(_properties)/sizeof(ReflectionProperty)));
}
}

View File

@ -18,6 +18,8 @@ namespace RNR
{
Ogre::SubEntity* surface = m_partEntity->getSubEntity(i);
Ogre::TextureUnitState* texture = surface->getMaterial()->getTechnique(0)->getPass(0)->createTextureUnitState("textures/stud_top.png");
surface->getMaterial()->setShininess(1.0);
}
}

View File

@ -162,7 +162,9 @@ namespace RNR
bool Instance::isA(std::string type)
{
if (type == getClassName()); // TODO: check if type is any of parent types
if (type == getClassName())
return true; // TODO: check if type is any of parent types
return false;
}
Instance* Instance::findFirstChild(std::string name)

View File

@ -12,23 +12,26 @@ namespace RNR
{
Instance::setWorld(this);
m_instanceFactory = new InstanceFactory();
m_instanceFactory->registerInstance("Camera", InstanceFactory::instanceBuilder<Camera>);
m_instanceFactory->registerInstance("Model", InstanceFactory::instanceBuilder<ModelInstance>);
m_instanceFactory->registerInstance("SelectionBox", InstanceFactory::instanceBuilder<SelectionBox>);
m_instanceFactory->registerInstance("Part", InstanceFactory::instanceBuilder<PartInstance>);
m_instanceFactory->registerInstance("Workspace", InstanceFactory::instanceBuilder<Workspace>);
m_instanceFactory->registerInstance("Humanoid", InstanceFactory::instanceBuilder<Humanoid>);
m_instanceFactory->registerInstance("RunService", InstanceFactory::instanceBuilder<RunService>);
m_ogreRoot = ogre;
m_ogreSceneManager = ogreSceneManager;
m_datamodel = new Instance();
m_datamodel = new DataModel();
m_datamodel->setName("DataModel");
m_workspace = new Workspace();
m_workspace->setParent(m_datamodel);
InstanceFactory();
InstanceFactory::singleton()->registerInstance("Camera", InstanceFactory::instanceBuilder<Camera>);
InstanceFactory::singleton()->registerInstance("Model", InstanceFactory::instanceBuilder<ModelInstance>);
InstanceFactory::singleton()->registerInstance("SelectionBox", InstanceFactory::instanceBuilder<SelectionBox>);
InstanceFactory::singleton()->registerInstance("Part", InstanceFactory::instanceBuilder<PartInstance>);
InstanceFactory::singleton()->registerInstance("Workspace", InstanceFactory::instanceBuilder<Workspace>);
InstanceFactory::singleton()->registerInstance("Humanoid", InstanceFactory::instanceBuilder<Humanoid>);
m_workspace = (Workspace*)m_datamodel->getService("Workspace");
m_runService = (RunService*)m_datamodel->getService("RunService");
m_tmb = new TopMenuBar();
}
World::~World()
@ -42,39 +45,19 @@ namespace RNR
Instance* instance;
/*
try{
instance = InstanceFactory::singleton()->build(class_attr.as_string());
if(parent == m_datamodel && m_datamodel->findFirstChildOfType(class_attr.as_string()))
instance = m_datamodel->findFirstChildOfType(class_attr.as_string());
else
{
std::string class_name = class_attr.value();
instance = m_instanceFactory->build(class_name);
}
}
catch(std::runtime_error e)
{
printf("World::xmlAddItem: InstanceFactory::build failed '%s'\n", e.what());
return;
}*/
if(class_attr.as_string() == std::string("Part"))
{
instance = new PartInstance();
}
else if(class_attr.as_string() == std::string("Workspace"))
{
instance = m_workspace;
}
else if(class_attr.as_string() == std::string("Camera"))
{
instance = new Camera();
}
else if(class_attr.as_string() == std::string("Model"))
{
instance = new ModelInstance();
}
else if(class_attr.as_string() == std::string("Humanoid"))
{
instance = new Humanoid();
}
else
{
instance = new Instance();
}
pugi::xml_attribute referent = node.attribute("referent");
@ -137,6 +120,8 @@ namespace RNR
double World::step(float timestep)
{
if(m_runService && m_runService->getRunning())
m_runService->step(timestep);
return 0.0;
}