aboutsummaryrefslogtreecommitdiff
ModeNameSize
-rw-r--r--couple.lua4723logplain
-rw-r--r--crafting.lua2526logplain
-rw-r--r--damage.lua859logplain
-rw-r--r--debugitems.lua980logplain
-rw-r--r--depends.txt7logplain
-rw-r--r--helpers.lua8259logplain
-rw-r--r--init.lua739logplain
-rw-r--r--license.txt23977logplain
-rw-r--r--license_media.txt19556logplain
-rw-r--r--manual.pdf1083147logplain
-rw-r--r--misc_nodes.lua1858logplain
d---------models2898logplain
-rw-r--r--pseudoload.lua6305logplain
-rw-r--r--readme.txt2278logplain
-rw-r--r--signals.lua2454logplain
d---------textures2608logplain
-rw-r--r--trackplacer.lua8983logplain
-rw-r--r--tracks.lua13763logplain
-rw-r--r--trainhud.lua1826logplain
-rw-r--r--trainlogic.lua28450logplain
-rw-r--r--wagons.lua15029logplain
>->handle; } ObjDef *ObjDefManager::get(ObjDefHandle handle) const { u32 index = validateHandle(handle); return (index != OBJDEF_INVALID_INDEX) ? getRaw(index) : NULL; } ObjDef *ObjDefManager::set(ObjDefHandle handle, ObjDef *obj) { u32 index = validateHandle(handle); if (index == OBJDEF_INVALID_INDEX) return NULL; ObjDef *oldobj = setRaw(index, obj); obj->uid = oldobj->uid; obj->index = oldobj->index; obj->handle = oldobj->handle; return oldobj; } u32 ObjDefManager::addRaw(ObjDef *obj) { size_t nobjects = m_objects.size(); if (nobjects >= OBJDEF_MAX_ITEMS) return -1; obj->index = nobjects; // Ensure UID is nonzero so that a valid handle == OBJDEF_INVALID_HANDLE // is not possible. The slight randomness bias isn't very significant. obj->uid = myrand() & OBJDEF_UID_MASK; if (obj->uid == 0) obj->uid = 1; m_objects.push_back(obj); infostream << "ObjDefManager: added " << getObjectTitle() << ": name=\"" << obj->name << "\" index=" << obj->index << " uid=" << obj->uid << std::endl; return nobjects; } ObjDef *ObjDefManager::getRaw(u32 index) const { return m_objects[index]; } ObjDef *ObjDefManager::setRaw(u32 index, ObjDef *obj) { ObjDef *old_obj = m_objects[index]; m_objects[index] = obj; return old_obj; } ObjDef *ObjDefManager::getByName(const std::string &name) const { for (size_t i = 0; i != m_objects.size(); i++) { ObjDef *obj = m_objects[i]; if (obj && !strcasecmp(name.c_str(), obj->name.c_str())) return obj; } return NULL; } void ObjDefManager::clear() { for (size_t i = 0; i != m_objects.size(); i++) delete m_objects[i]; m_objects.clear(); } u32 ObjDefManager::validateHandle(ObjDefHandle handle) const { ObjDefType type; u32 index; u32 uid; bool is_valid = (handle != OBJDEF_INVALID_HANDLE) && decodeHandle(handle, &index, &type, &uid) && (type == m_objtype) && (index < m_objects.size()) && (m_objects[index]->uid == uid); return is_valid ? index : -1; } ObjDefHandle ObjDefManager::createHandle(u32 index, ObjDefType type, u32 uid) { ObjDefHandle handle = 0; set_bits(&handle, 0, 18, index); set_bits(&handle, 18, 6, type); set_bits(&handle, 24, 7, uid); u32 parity = calc_parity(handle); set_bits(&handle, 31, 1, parity); return handle ^ OBJDEF_HANDLE_SALT; } bool ObjDefManager::decodeHandle(ObjDefHandle handle, u32 *index, ObjDefType *type, u32 *uid) { handle ^= OBJDEF_HANDLE_SALT; u32 parity = get_bits(handle, 31, 1); set_bits(&handle, 31, 1, 0); if (parity != calc_parity(handle)) return false; *index = get_bits(handle, 0, 18); *type = (ObjDefType)get_bits(handle, 18, 6); *uid = get_bits(handle, 24, 7); return true; }