void Circuit::removeElement(v3s16 pos) { JMutexAutoLock lock(m_elements_mutex); std::vector <std::list <CircuitElementVirtual>::iterator> virtual_elements_for_update; std::list <CircuitElement>::iterator current_element = m_pos_to_iterator[pos]; m_database->del(itos(current_element->getId())); current_element->getNeighbors(virtual_elements_for_update); m_elements.erase(current_element); for(std::vector <std::list <CircuitElementVirtual>::iterator>::iterator i = virtual_elements_for_update.begin(); i != virtual_elements_for_update.end(); ++i) { if((*i)->size() > 1) { std::ostringstream out(std::ios_base::binary); (*i)->serialize(out); m_virtual_database->put(itos((*i)->getId()), out.str()); } else { m_virtual_database->del(itos((*i)->getId())); std::list <CircuitElement>::iterator element_to_save; for(std::list <CircuitElementVirtualContainer>::iterator j = (*i)->begin(); j != (*i)->end(); ++j) { element_to_save = j->element_pointer; } m_virtual_elements.erase(*i); saveElement(element_to_save, false); } } m_pos_to_iterator.erase(pos); }
void QGUISkin::saveDamage() { pfGUISkin* skin = pfGUISkin::Convert(fCreatable); skin->setItemMargin(fItemMargin->value()); skin->setBorderMargin(fBorderMargin->value()); saveElement(); }
void QGUISkin::setElement(int which) { pfGUISkin* skin = pfGUISkin::Convert(fCreatable); saveElement(); fCurElement = which; fX->setValue(skin->getElement(fCurElement).fX); fY->setValue(skin->getElement(fCurElement).fY); fWidth->setValue(skin->getElement(fCurElement).fWidth); fHeight->setValue(skin->getElement(fCurElement).fHeight); }
void Circuit::updateElement(MapNode& node, v3s16 pos, INodeDefManager* ndef, const unsigned char* func) { if(!m_updating_process) { m_elements_mutex.Lock(); } std::list <CircuitElement>::iterator current_element = m_pos_to_iterator[pos]; std::pair<const unsigned char*, unsigned long> node_func; if(ndef->get(node).param_type_2 == CPT2_FACEDIR) { node_func = m_circuit_elements_states.addState(func, node.param2); } else { node_func = m_circuit_elements_states.addState(func); } current_element->setFunc(node_func.first, node_func.second); current_element->setDelay(ndef->get(node).circuit_element_delay); saveCircuitElementsStates(); saveElement(current_element, false); if(!m_updating_process) { m_elements_mutex.Unlock(); } }
void Circuit::addElement(Map& map, INodeDefManager* ndef, v3s16 pos, const unsigned char* func) { JMutexAutoLock lock(m_elements_mutex); bool already_existed[6]; bool connected_faces[6] = {0}; std::vector <std::pair <std::list <CircuitElement>::iterator, int > > connected; MapNode node = map.getNode(pos); std::pair <const unsigned char*, unsigned long> node_func; if(ndef->get(node).param_type_2 == CPT2_FACEDIR) { // If block is rotatable, then rotate it's function. node_func = m_circuit_elements_states.addState(func, node.param2); } else { node_func = m_circuit_elements_states.addState(func); } saveCircuitElementsStates(); std::list <CircuitElement>::iterator current_element_iterator = m_elements.insert(m_elements.begin(), CircuitElement(pos, node_func.first, node_func.second, m_max_id++, ndef->get(node).circuit_element_delay)); m_pos_to_iterator[pos] = current_element_iterator; // For each face add all other connected faces. for(int i = 0; i < 6; ++i) { if(!connected_faces[i]) { connected.clear(); CircuitElement::findConnectedWithFace(connected, map, ndef, pos, SHIFT_TO_FACE(i), m_pos_to_iterator, connected_faces); if(connected.size() > 0) { std::list <CircuitElementVirtual>::iterator virtual_element_it; bool found = false; for(std::vector <std::pair <std::list <CircuitElement>::iterator, int> >::iterator j = connected.begin(); j != connected.end(); ++j) { if(j->first->getFace(j->second).is_connected) { virtual_element_it = j->first->getFace(j->second).list_pointer; found = true; break; } } // If virtual element already exist if(found) { already_existed[i] = true; } else { already_existed[i] = false; virtual_element_it = m_virtual_elements.insert(m_virtual_elements.begin(), CircuitElementVirtual(m_max_virtual_id++)); } std::list <CircuitElementVirtualContainer>::iterator it; for(std::vector <std::pair <std::list <CircuitElement>::iterator, int> >::iterator j = connected.begin(); j != connected.end(); ++j) { if(!j->first->getFace(j->second).is_connected) { it = virtual_element_it->insert(virtual_element_it->begin(), CircuitElementVirtualContainer()); it->shift = j->second; it->element_pointer = j->first; j->first->connectFace(j->second, it, virtual_element_it); } } it = virtual_element_it->insert(virtual_element_it->begin(), CircuitElementVirtualContainer()); it->shift = i; it->element_pointer = current_element_iterator; current_element_iterator->connectFace(i, it, virtual_element_it); } } } for(int i = 0; i < 6; ++i) { if(current_element_iterator->getFace(i).is_connected && !already_existed[i]) { saveVirtualElement(current_element_iterator->getFace(i).list_pointer, true); } } saveElement(current_element_iterator, true); }
void Circuit::processElementsQueue(Map& map, INodeDefManager* ndef) { if(m_elements_queue.size() > 0) { JMutexAutoLock lock(m_elements_mutex); std::vector <std::pair <std::list <CircuitElement>::iterator, int> > connected; std::vector <std::list <CircuitElementVirtual>::iterator> created_virtual_elements; MapNode node; bool connected_faces[6]; // Filling with empty elements for(unsigned int i = 0; i < m_elements_queue.size(); ++i) { node = map.getNode(m_elements_queue[i]); std::pair <const unsigned char*, unsigned long> node_func; if(ndef->get(node).param_type_2 == CPT2_FACEDIR) { node_func = m_circuit_elements_states.addState(ndef->get(node).circuit_element_states, node.param2); } else { node_func = m_circuit_elements_states.addState(ndef->get(node).circuit_element_states); } m_pos_to_iterator[m_elements_queue[i]] = m_elements.insert(m_elements.begin(), CircuitElement(m_elements_queue[i], node_func.first, node_func.second, m_max_id++, ndef->get(node).circuit_element_delay)); } for(unsigned int i = 0; i < m_elements_queue.size(); ++i) { v3s16 pos = m_elements_queue[i]; std::list <CircuitElement>::iterator current_element_it = m_pos_to_iterator[pos]; for(int j = 0; j < 6; ++j) { connected_faces[j] = false; } for(int j = 0; j < 6; ++j) { if(!current_element_it->getFace(j).is_connected && !connected_faces[j]) { connected.clear(); CircuitElement::findConnectedWithFace(connected, map, ndef, pos, SHIFT_TO_FACE(j), m_pos_to_iterator, connected_faces); if(!connected.empty()) { std::list <CircuitElementVirtual>::iterator virtual_element_it; bool found = false; for(std::vector <std::pair <std::list <CircuitElement>::iterator, int> >::iterator k = connected.begin(); k != connected.end(); ++k) { if(k->first->getFace(k->second).is_connected) { virtual_element_it = k->first->getFace(k->second).list_pointer; found = true; break; } } if(!found) { virtual_element_it = m_virtual_elements.insert(m_virtual_elements.begin(), CircuitElementVirtual(m_max_virtual_id++)); } std::list <CircuitElementVirtualContainer>::iterator it; for(std::vector <std::pair <std::list <CircuitElement>::iterator, int> >::iterator k = connected.begin(); k != connected.end(); ++k) { if(!k->first->getFace(k->second).is_connected) { it = virtual_element_it->insert(virtual_element_it->begin(), CircuitElementVirtualContainer()); it->shift = k->second; it->element_pointer = k->first; k->first->connectFace(k->second, it, virtual_element_it); } } it = virtual_element_it->insert(virtual_element_it->begin(), CircuitElementVirtualContainer()); it->shift = j; it->element_pointer = current_element_it; current_element_it->connectFace(j, it, virtual_element_it); } } } } for(unsigned int i = 0; i < created_virtual_elements.size(); ++i) { saveVirtualElement(created_virtual_elements[i], true); } for(unsigned int i = 0; i < m_elements_queue.size(); ++i) { saveElement(m_pos_to_iterator[m_elements_queue[i]], false); } m_elements_queue.clear(); saveCircuitElementsStates(); } }
void Circuit::removeWire(Map& map, INodeDefManager* ndef, v3s16 pos, MapNode& node) { JMutexAutoLock lock(m_elements_mutex); std::vector <std::pair <std::list <CircuitElement>::iterator, int> > current_face_connected; bool connected_faces[6]; for(int i = 0; i < 6; ++i) { connected_faces[i] = false; } // Find and remove virtual elements bool found_virtual_elements = false; for(int i = 0; i < 6; ++i) { if(!connected_faces[i]) { current_face_connected.clear(); CircuitElement::findConnectedWithFace(current_face_connected, map, ndef, pos, SHIFT_TO_FACE(i), m_pos_to_iterator, connected_faces); for(unsigned int j = 0; j < current_face_connected.size(); ++j) { CircuitElementContainer current_edge = current_face_connected[j].first->getFace(current_face_connected[j].second); if(current_edge.is_connected) { found_virtual_elements = true; m_virtual_database->del(itos(current_edge.list_pointer->getId())); m_virtual_elements.erase(current_edge.list_pointer); break; } } for(unsigned int j = 0; j < current_face_connected.size(); ++j) { saveElement(current_face_connected[j].first, false); } } } for(int i = 0; i < 6; ++i) { connected_faces[i] = false; } if(found_virtual_elements) { // Restore some previously deleted connections. for(int i = 0; i < 6; ++i) { if(!connected_faces[i]) { current_face_connected.clear(); CircuitElement::findConnectedWithFace(current_face_connected, map, ndef, pos, SHIFT_TO_FACE(i), m_pos_to_iterator, connected_faces); if(current_face_connected.size() > 1) { std::list <CircuitElementVirtual>::iterator new_virtual_element = m_virtual_elements.insert( m_virtual_elements.begin(), CircuitElementVirtual(m_max_virtual_id++)); for(unsigned int j = 0; j < current_face_connected.size(); ++j) { std::list <CircuitElementVirtualContainer>::iterator new_container = new_virtual_element->insert( new_virtual_element->begin(), CircuitElementVirtualContainer()); new_container->element_pointer = current_face_connected[j].first; new_container->shift = current_face_connected[j].second; current_face_connected[j].first->connectFace(current_face_connected[j].second, new_container, new_virtual_element); saveElement(current_face_connected[j].first, false); } saveVirtualElement(new_virtual_element, false); } } } } }