Remove nodebox count limit

master
ShadowNinja 2014-04-25 02:56:13 -04:00
parent 6a95d1f982
commit 685c072aab
8 changed files with 130 additions and 192 deletions

View File

@ -24,7 +24,6 @@ void LUAFileParser::save(Project* project,irr::core::stringc file){
int a = 1;
list<Node*>* nodes = project->GetList();
for (irr::core::list<Node*>::Iterator it=nodes->begin();it!=nodes->end();it++){
printf("Looping...\n");
Node* node = *it;
myfile << "minetest.register_node(\"";
if (node->name == ""){
@ -40,29 +39,28 @@ void LUAFileParser::save(Project* project,irr::core::stringc file){
myfile << "\tdrawtype=\"nodebox\",\n"
"\tparamtype = \"light\",\n"
"\tnode_box = {\n"
"\t\ttype = \"fixed\",\n"
"\t\tfixed = {\n";
"\t\ttype = \"fixed\",\n"
"\t\tfixed = {\n";
for (int i = 0;i<NODEB_MAX;i++){
NodeBox* box = node->GetNodeBox(i);
if (box){
myfile << "\t\t\t{";
myfile << box->one.X;
myfile << ",";
myfile << box->one.Y;
myfile << ",";
myfile << box->one.Z;
myfile << ",";
myfile << box->two.X;
myfile << ",";
myfile << box->two.Y;
myfile << ",";
myfile << box->two.Z;
myfile << "}, --";
myfile << box->name.c_str();
myfile << "\n";
}
std::vector<NodeBox*> boxes = node->GetBoxes();
for (std::vector<NodeBox*>::const_iterator it = boxes.begin();
it != boxes.end();
++it) {
myfile << "\t\t\t{";
myfile << (*it)->one.X;
myfile << ",";
myfile << (*it)->one.Y;
myfile << ",";
myfile << (*it)->one.Z;
myfile << ",";
myfile << (*it)->two.X;
myfile << ",";
myfile << (*it)->two.Y;
myfile << ",";
myfile << (*it)->two.Z;
myfile << "}, --";
myfile << (*it)->name.c_str();
myfile << "\n";
}
myfile << "\t\t}\n\t}\n";
@ -71,6 +69,7 @@ void LUAFileParser::save(Project* project,irr::core::stringc file){
}
myfile.close();
}else
} else {
printf("Unable to write to file\n");
}
}

View File

@ -36,26 +36,26 @@ void NBEFileParser::save(Project* project,irr::core::stringc file){
myfile << node->getPosition().Z;
myfile << "\n";
for (int i = 0;i<NODEB_MAX;i++){
NodeBox* box = node->GetNodeBox(i);
if (box){
myfile << "NODEBOX ";
myfile << box->name.c_str();
myfile << " ";
myfile << box->one.X;
myfile << " ";
myfile << box->one.Y;
myfile << " ";
myfile << box->one.Z;
myfile << " ";
myfile << box->two.X;
myfile << " ";
myfile << box->two.Y;
myfile << " ";
myfile << box->two.Z;
myfile << "\n";
}
std::vector<NodeBox*> boxes = node->GetBoxes();
for (std::vector<NodeBox*>::const_iterator it = boxes.begin();
it != boxes.end();
++it) {
NodeBox* box = *it;
myfile << "NODEBOX ";
myfile << box->name.c_str();
myfile << " ";
myfile << box->one.X;
myfile << " ";
myfile << box->one.Y;
myfile << " ";
myfile << box->one.Z;
myfile << " ";
myfile << box->two.X;
myfile << " ";
myfile << box->two.Y;
myfile << " ";
myfile << box->two.Z;
myfile << "\n";
}
myfile << "END NODE";
@ -72,7 +72,7 @@ Project* NBEFileParser::open(irr::core::stringc file){
std::ifstream myfile(file.c_str());
if (myfile.is_open()){
// Read parser header
if (!std::getline (myfile,line) || !std::getline (myfile,line))
if (!std::getline (myfile,line) || !std::getline (myfile,line))
return NULL;
if (line!="PARSER 1"){
printf("Not parser 1!\n");
@ -84,7 +84,7 @@ Project* NBEFileParser::open(irr::core::stringc file){
// Parse file
proj = new Project();
stage = ERS_ROOT;
while (std::getline (myfile,line) )
while (std::getline(myfile, line))
{
parseLine(irr::core::stringc(line.c_str()));
}
@ -102,9 +102,6 @@ void NBEFileParser::parseLine(stringc line){
if (l == "")
return;
printf("Parsing line: %s\n",l.c_str());
#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8
stringc lw = irr::core::stringc(l);
lw.make_lower();
@ -115,32 +112,20 @@ void NBEFileParser::parseLine(stringc line){
if (stage == ERS_ROOT){
if (lw.find("name ") == 0){
printf("-- is project name\n");
stringc name = l.subString(4,l.size());
name = name.trim();
printf("-- Name: '%s'\n",name.c_str());
proj->name = name;
stringc name = l.subString(4, l.size());
proj->name = name.trim();
}else if (lw.find("node ") == 0){
printf("-- is node\n");
stage = ERS_NODE;
node = new Node(state->GetDevice(),state,proj->GetNodeCount());
stringc name = l.subString(4,l.size());
name = name.trim();
printf("-- Name: '%s'\n",name.c_str());
node->name = name;
node->name = name.trim();
}
}else if (stage == ERS_NODE){
if (!node){
printf("In node stage, but no node active\n");
}
if (lw.find("position ") == 0){
printf("-- position parser not complete!\n");
}else if (lw.find("nodebox ") == 0){
printf("-- reading nodebox data!\n");
stringc n = l.subString(7,l.size());
n = n.trim();
printf("-- read name\n");
stringc ls[7];
int i = 0;
while (n!=""){
@ -164,16 +149,11 @@ void NBEFileParser::parseLine(stringc line){
node->GetCurrentNodeBox()->one = vector3df(atof(ls[1].c_str()),atof(ls[2].c_str()),atof(ls[3].c_str()));
node->GetCurrentNodeBox()->two = vector3df(atof(ls[4].c_str()),atof(ls[5].c_str()),atof(ls[6].c_str()));
node->remesh();
printf("-- added nodebox\n");
}else if (lw.find("end node") == 0){
printf("-- is exit, saving and returning...\n");
proj->AddNode(node);
node = NULL;
stage = ERS_ROOT;
}
}
}

View File

@ -116,15 +116,11 @@ void NBEditor::load_ui(){
if (lb){
lb->clear();
lb->setVisible(true);
for (int i = 0;i<NODEB_MAX;i++){
NodeBox* box = node->GetNodeBox(i);
if (box){
size_t origsize = strlen(box->name.c_str()) + 1;
static wchar_t wcstring[1024];
mbstowcs(wcstring, box->name.c_str(), origsize);
wcscat(wcstring, L"");
lb->addItem(wcstring);
}
std::vector<NodeBox*> boxes = node->GetBoxes();
for (std::vector<NodeBox*>::const_iterator it = boxes.begin();
it != boxes.end();
++it) {
lb->addItem((*it)->name.c_str());
}
lb->setSelected(lb->getListItem(node->GetId()));
}

View File

@ -1,103 +1,68 @@
#include "Node.h"
Node::Node(IrrlichtDevice* mdevice,EditorState* state, unsigned int id)
:_device(mdevice), _state(state), number(0), _selected(-1), _nid(id)
Node::Node(IrrlichtDevice* mdevice, EditorState* state, unsigned int id) :
_device(mdevice),
_state(state),
_selected(-1),
_nid(id)
{
for (int i=0;i<NODEB_MAX;i++){
boxes[i] = NULL;
}
}
Node::~Node(){
for (int i=0;i<NODEB_MAX;i++){
if (boxes[i])
delete boxes[i];
Node::~Node() {
for (std::vector<NodeBox*>::iterator it = boxes.begin();
it != boxes.end();
++it) {
delete *it;
}
boxes.clear();
}
NodeBox* Node::GetCurrentNodeBox(){
NodeBox* Node::GetCurrentNodeBox() {
return GetNodeBox(GetId());
}
NodeBox* Node::GetNodeBox(int id){
if (id==-1)
NodeBox* Node::GetNodeBox(int id) {
if (id < 0 || id > boxes.size()) {
return NULL;
}
return boxes[id];
}
// Operation functions
NodeBox* Node::addNodeBox(){
if (!number)
number = 0;
// Name it
core::stringc nb="NodeBox";
nb+=(number+1);
core::stringc name = "NodeBox";
// Append number
name += boxes.size() + 1;
// Set up structure
NodeBox* tmp =new NodeBox(nb,vector3df(0,-0.5,-0.5),vector3df(0.5,0.5,0.5));
NodeBox* tmp = new NodeBox(name,
vector3df(0, -0.5, -0.5),
vector3df(0.5, 0.5, 0.5));
if (!tmp)
return NULL;
boxes[number] = tmp;
select(number);
tmp->buildNode(getPosition(),_device);
// Increment and print message
number++;
printf("Nodebox added\n");
// Clean up list
defrag();
boxes.push_back(tmp);
select(boxes.size() - 1);
tmp->buildNode(getPosition(), _device);
return tmp;
}
void Node::deleteNodebox(int id){
if (!GetNodeBox(id))
if (!GetNodeBox(id)) {
return;
}
delete boxes[id];
boxes[id] = NULL;
defrag();
boxes.erase(boxes.begin() + id);
}
// Build node models
void Node::remesh(){
for (int i=0;i<NODEB_MAX;i++){
NodeBox* box = GetNodeBox(i);
if (box)
box->buildNode(getPosition(),_device);
void Node::remesh() {
for (std::vector<NodeBox*>::iterator it = boxes.begin();
it != boxes.end();
++it) {
(*it)->buildNode(getPosition(), _device);
}
}
// Private functions
void Node::defrag(){
int a=0;
for (int i=0;i<NODEB_MAX;i++){
if (boxes[i]!=NULL){
boxes[a]=boxes[i];
if (GetId()==i)
_selected=a;
a++;
}else{
boxes[a]=NULL;
}
}
number = a;
#ifdef _DEBUG
for (int i=0;i<NODEB_MAX;i++){
if (boxes[i]!=NULL && boxes[i]->model->getName()){
printf("%i> ",i);
printf("%s \n",boxes[i]->model->getName());
}
}
printf("There are %i boxes\n",a);
#endif
}

View File

@ -1,5 +1,7 @@
#ifndef _NODE_H_INCLUDED_
#define _NODE_H_INCLUDED_
#include <vector>
#include "common.h"
#include "EditorState.h"
#include "NodeBox.h"
@ -18,24 +20,23 @@ public:
unsigned int NodeId()const{ return _nid; }
NodeBox* GetCurrentNodeBox();
NodeBox* GetNodeBox(int id);
const std::vector<NodeBox*> & GetBoxes() { return boxes; }
NodeBox* addNodeBox();
void deleteNodebox(int id);
void select(int id){_selected = id;}
// Node properties
vector3di getPosition() const{return nd_position;}
void setPosition(vector3di in){nd_position = in;}
stringc name;
// Node bulk updaters
void remesh(); // creates the node mesh
void defrag(); // Defragments node array
private:
// Data
NodeBox* boxes[NODEB_MAX];
std::vector<NodeBox*> boxes;
int _selected;
unsigned int _nid; // the node's id.
int number;
vector3di nd_position;
// Irrlicht

View File

@ -1,43 +1,45 @@
#ifndef _NODEBOX_H_INCLUDED_
#define _NODEBOX_H_INCLUDED_
#include "common.h"
#include "EditorState.h"
class EditorState;
class NodeBox
{
public:
NodeBox(){};
{
public:
NodeBox() {};
NodeBox(core::stringc _name, vector3df _one, vector3df _two)
:name(_name),one(_one),two(_two),model(NULL){};
NodeBox(stringw name, vector3df one, vector3df two) :
name(name), one(one), two(two), model(NULL)
{};
~NodeBox(){
if (model)
model->remove();
}
irr::core::vector3df one;
irr::core::vector3df two;
core::stringc name;
irr::scene::IMeshSceneNode* model;
~NodeBox(){
if (model)
model->remove();
}
irr::core::vector3df one;
irr::core::vector3df two;
stringw name;
irr::scene::IMeshSceneNode* model;
irr::core::vector3df GetCenter(){
return vector3df(
one.X + ((two.X - one.X)/2),
one.Y + ((two.Y - one.Y)/2),
one.Z + ((two.Z - one.Z)/2)
);
}
irr::core::vector3df GetScale(){
return vector3df(
(two.X - one.X)/2,
(two.Y - one.Y)/2,
(two.Z - one.Z)/2
);
}
void resizeNodeBoxFace(EditorState* editor,CDR_TYPE type,vector3df position,bool both);
void moveNodeBox(EditorState* editor,CDR_TYPE type,vector3df position);
void buildNode(vector3di nd_position,IrrlichtDevice* device);
};
irr::core::vector3df GetCenter(){
return vector3df(
one.X + ((two.X - one.X)/2),
one.Y + ((two.Y - one.Y)/2),
one.Z + ((two.Z - one.Z)/2)
);
}
irr::core::vector3df GetScale(){
return vector3df(
(two.X - one.X)/2,
(two.Y - one.Y)/2,
(two.Z - one.Z)/2
);
}
void resizeNodeBoxFace(EditorState* editor,CDR_TYPE type,vector3df position,bool both);
void moveNodeBox(EditorState* editor,CDR_TYPE type,vector3df position);
void buildNode(vector3di nd_position,IrrlichtDevice* device);
};
#endif

View File

@ -58,14 +58,10 @@ void NodeEditor::load_ui(){
list<Node*>* nodes = GetState()->project->GetList();
for (irr::core::list<Node*>::Iterator it=nodes->begin();it!=nodes->end();it++){
Node* node = *it;
if (node){
size_t origsize = strlen(node->name.c_str()) + 1;
static wchar_t wcstring[1024];
mbstowcs(wcstring, node->name.c_str(), origsize);
wcscat(wcstring, L"");
lb->addItem(wcstring);
}
size_t origsize = (*it)->name.size() + 1;
static wchar_t wcstring[1024];
mbstowcs(wcstring, (*it)->name.c_str(), origsize);
lb->addItem(wcstring);
}
lb->setSelected(lb->getListItem(GetState()->project->GetSelectedNodeId()));
@ -188,4 +184,4 @@ bool NodeEditor::OnEvent(const irr::SEvent &event){
}
}
return false;
}
}

View File

@ -52,7 +52,6 @@ enum FileParserType
#define EDITOR_PARSER 1
#define NODE_RES 16 // The resolution of the snapping (16) - doesn't work
#define NODE_THIN 1/NODE_RES // The smallest a box can be (1/NODE_RES) - don't think this works
#define NODEB_MAX 50 // Maximum amount of nodeboxes (50)
#define NODEB_MENU_START 250 // No idea what this does