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 == ""){
@ -43,27 +42,26 @@ void LUAFileParser::save(Project* project,irr::core::stringc file){
"\t\ttype = \"fixed\",\n"
"\t\tfixed = {\n";
for (int i = 0;i<NODEB_MAX;i++){
NodeBox* box = node->GetNodeBox(i);
if (box){
std::vector<NodeBox*> boxes = node->GetBoxes();
for (std::vector<NodeBox*>::const_iterator it = boxes.begin();
it != boxes.end();
++it) {
myfile << "\t\t\t{";
myfile << box->one.X;
myfile << (*it)->one.X;
myfile << ",";
myfile << box->one.Y;
myfile << (*it)->one.Y;
myfile << ",";
myfile << box->one.Z;
myfile << (*it)->one.Z;
myfile << ",";
myfile << box->two.X;
myfile << (*it)->two.X;
myfile << ",";
myfile << box->two.Y;
myfile << (*it)->two.Y;
myfile << ",";
myfile << box->two.Z;
myfile << (*it)->two.Z;
myfile << "}, --";
myfile << box->name.c_str();
myfile << (*it)->name.c_str();
myfile << "\n";
}
}
myfile << "\t\t}\n\t}\n";
myfile << "})\n\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,10 +36,11 @@ 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){
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 << " ";
@ -56,7 +57,6 @@ void NBEFileParser::save(Project* project,irr::core::stringc file){
myfile << box->two.Z;
myfile << "\n";
}
}
myfile << "END NODE";
a++;
@ -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;
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,18 +1,20 @@
#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];
for (std::vector<NodeBox*>::iterator it = boxes.begin();
it != boxes.end();
++it) {
delete *it;
}
boxes.clear();
}
NodeBox* Node::GetCurrentNodeBox() {
@ -20,84 +22,47 @@ NodeBox* Node::GetCurrentNodeBox(){
}
NodeBox* Node::GetNodeBox(int id) {
if (id==-1)
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);
boxes.push_back(tmp);
select(boxes.size() - 1);
tmp->buildNode(getPosition(), _device);
// Increment and print message
number++;
printf("Nodebox added\n");
// Clean up list
defrag();
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);
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,6 +20,7 @@ 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;}
@ -29,13 +32,11 @@ public:
// 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,5 +1,6 @@
#ifndef _NODEBOX_H_INCLUDED_
#define _NODEBOX_H_INCLUDED_
#include "common.h"
#include "EditorState.h"
@ -9,8 +10,9 @@ class 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)
@ -18,7 +20,7 @@ class NodeBox
}
irr::core::vector3df one;
irr::core::vector3df two;
core::stringc name;
stringw name;
irr::scene::IMeshSceneNode* model;
irr::core::vector3df GetCenter(){

View File

@ -58,15 +58,11 @@ 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;
size_t origsize = (*it)->name.size() + 1;
static wchar_t wcstring[1024];
mbstowcs(wcstring, node->name.c_str(), origsize);
wcscat(wcstring, L"");
mbstowcs(wcstring, (*it)->name.c_str(), origsize);
lb->addItem(wcstring);
}
}
lb->setSelected(lb->getListItem(GetState()->project->GetSelectedNodeId()));
fillProperties();

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