added basic scripting to the SceneNode
This commit is contained in:
parent
0015acb84c
commit
8d5b5f7ac9
@ -33,7 +33,8 @@ TextInputNode::TextInputNode(glm::vec2 dimension):
|
||||
mesh->setMaterial(mat);
|
||||
mesh->setDepth(30);
|
||||
mesh->initGL();
|
||||
m_cursor_mesh = new SceneNode(false);
|
||||
m_cursor_mesh = new SceneNode();
|
||||
m_cursor_mesh->setVisible(false);
|
||||
m_cursor_mesh->setMesh(mesh);
|
||||
addChild(m_cursor_mesh);
|
||||
}
|
||||
@ -147,12 +148,11 @@ void TextInputNode::updateTextMesh(){
|
||||
this->removeChild(m_text_mesh);
|
||||
m_text_mesh->destroyWhenOrphan();
|
||||
}
|
||||
m_text_mesh = shellfont->getTextNode(m_text,m_text_color,m_font_size,false);
|
||||
m_text_mesh = shellfont->getTextNode(m_text, m_text_color, m_font_size);
|
||||
if(m_text_mesh){
|
||||
m_text_mesh->setTransform(glm::mat4());
|
||||
m_text_mesh->setDepth(15);
|
||||
this->addChild(m_text_mesh);
|
||||
m_text_mesh->setVisible(true);
|
||||
}
|
||||
m_text_updated = false;
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ void SceneNode::setParent(SceneNode* parent)
|
||||
m_parent = parent;
|
||||
}
|
||||
|
||||
SceneNode::SceneNode(bool visible) :
|
||||
SceneNode::SceneNode(Script* script) :
|
||||
m_toDestroy(false),
|
||||
m_parentVisible(true),
|
||||
m_visible(visible),
|
||||
m_visible(true),
|
||||
m_enabled(true),
|
||||
m_transformChanged(true),
|
||||
m_parent(nullptr),
|
||||
@ -31,12 +31,18 @@ SceneNode::SceneNode(bool visible) :
|
||||
m_geometry(nullptr, glm::mat4()),
|
||||
m_light(nullptr),
|
||||
m_transform(glm::mat4()),
|
||||
m_script(script),
|
||||
m_rigidBody(nullptr),
|
||||
m_motionState(this)
|
||||
{}
|
||||
{
|
||||
if(m_script != nullptr)
|
||||
m_script->begin(this);
|
||||
}
|
||||
|
||||
SceneNode::~SceneNode()
|
||||
{
|
||||
if(m_script != nullptr)
|
||||
m_script->end(this);
|
||||
setVisible(false);
|
||||
setSceneTree(nullptr);
|
||||
for(SceneNode* child : m_children)
|
||||
@ -110,7 +116,8 @@ void SceneNode::update()
|
||||
if(m_light != nullptr)
|
||||
updateLightSource();
|
||||
}
|
||||
// TODO : add script execution here
|
||||
if(m_script != nullptr)
|
||||
m_script->update(this);
|
||||
for(SceneNode* child : m_children)
|
||||
{
|
||||
if(m_transformChanged)
|
||||
|
@ -29,6 +29,14 @@ public:
|
||||
virtual void setWorldTransform(const btTransform& worldTrans);
|
||||
};
|
||||
|
||||
class Script
|
||||
{
|
||||
public:
|
||||
virtual void begin(SceneNode* node) {}
|
||||
virtual void update(SceneNode* node) = 0;
|
||||
virtual void end(SceneNode* node) {}
|
||||
};
|
||||
|
||||
private:
|
||||
bool m_toDestroy;
|
||||
|
||||
@ -56,6 +64,9 @@ private:
|
||||
// m_parentTransform is the base transform for this element
|
||||
glm::mat4 m_parentTransform;
|
||||
|
||||
// m_script allows to add some game logic in a generic way
|
||||
Script* m_script;
|
||||
|
||||
// bullet physics rigidbody
|
||||
btRigidBody *m_rigidBody;
|
||||
|
||||
@ -71,7 +82,7 @@ private:
|
||||
|
||||
public:
|
||||
// constructor/destructor
|
||||
SceneNode(bool visible = true);
|
||||
SceneNode(Script *script = nullptr);
|
||||
virtual ~SceneNode();
|
||||
|
||||
// game logic methods
|
||||
@ -81,6 +92,8 @@ public:
|
||||
bool isEnabled() { return m_enabled; }
|
||||
void setEnabled(bool isEnabled) { m_enabled = isEnabled; }
|
||||
|
||||
Script* getScript();
|
||||
|
||||
// methods called to access the graphic propeties of the node
|
||||
void setMesh(Mesh* mesh) { m_geometry.mesh = mesh; }
|
||||
Mesh* getMesh() { return m_geometry.mesh; }
|
||||
|
@ -17,8 +17,8 @@ private:
|
||||
|
||||
friend class LabelNode;
|
||||
public:
|
||||
TextNode(Mesh* mesh,std::wstring s,float fontSize,bool visible = true) : SceneNode(visible),m_string(s),m_fontSize(fontSize) { setMesh(mesh); }
|
||||
TextNode(Mesh* mesh,std::string s,float fontSize,bool visible = true) : SceneNode(visible),m_fontSize(fontSize) {
|
||||
TextNode(Mesh* mesh,std::wstring s,float fontSize) : SceneNode(),m_string(s),m_fontSize(fontSize) { setMesh(mesh); }
|
||||
TextNode(Mesh* mesh,std::string s,float fontSize) : SceneNode(),m_fontSize(fontSize) {
|
||||
setMesh(mesh);
|
||||
m_string.assign(s.begin(),s.end());
|
||||
}
|
||||
|
@ -117,11 +117,12 @@ void SparrowShell::out(std::string str,glm::vec3 color)
|
||||
{
|
||||
if(!str.empty()){
|
||||
Font *shellfont = RESOURCE_GET(Font,"shellfont");
|
||||
TextNode* tnode = shellfont->getTextNode(str,color,m_buffer->getFontSize(),false);
|
||||
TextNode* tnode = shellfont->getTextNode(str,color,m_buffer->getFontSize());
|
||||
std::string name = "shellTextLine";
|
||||
name += m_buffer->size();
|
||||
tnode->getMesh()->setName(name);
|
||||
tnode->setDepth(SHELL_DEPTH+1);
|
||||
tnode->setVisible(false);
|
||||
m_buffer->push(tnode);
|
||||
scrollDown();
|
||||
if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_LINES)
|
||||
|
@ -8,7 +8,7 @@ Font::Font()
|
||||
|
||||
}
|
||||
|
||||
TextNode* Font::getTextNode(std::string s, glm::vec3 color, float font_size,bool visible)
|
||||
TextNode* Font::getTextNode(std::string s, glm::vec3 color, float font_size)
|
||||
{
|
||||
if(s.empty()) return nullptr;
|
||||
|
||||
@ -44,7 +44,7 @@ TextNode* Font::getTextNode(std::string s, glm::vec3 color, float font_size,bool
|
||||
mat->albedo = color;
|
||||
textmesh->setMaterial((Material*)mat);
|
||||
textmesh->initGL();
|
||||
TextNode *text = new TextNode(textmesh,ws,font_size,visible);
|
||||
TextNode *text = new TextNode(textmesh, ws, font_size);
|
||||
if (dimension.x < current_pos.x)
|
||||
dimension.x = current_pos.x;
|
||||
text->setDimension(dimension * sizeRatio);
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
void setScale(glm::vec2 scale){m_scale = scale;}
|
||||
void setTexture(Texture *tex){m_tex = tex;}
|
||||
|
||||
TextNode* getTextNode(std::string s, glm::vec3 color = glm::vec3(1), float font_size = 64.f, bool visible = true);
|
||||
TextNode* getTextNode(std::string s, glm::vec3 color = glm::vec3(1), float font_size = 64.f);
|
||||
private:
|
||||
std::string m_name;
|
||||
Texture *m_tex;
|
||||
|
Loading…
x
Reference in New Issue
Block a user