Skip to content

Instantly share code, notes, and snippets.

@sofar
Created January 12, 2016 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sofar/50c040e78a8f2b691fe1 to your computer and use it in GitHub Desktop.
Save sofar/50c040e78a8f2b691fe1 to your computer and use it in GitHub Desktop.
diff --git a/src/nodedef.h b/src/nodedef.h
index 9e14c73..7322e18 100644
--- a/src/nodedef.h
+++ b/src/nodedef.h
@@ -277,6 +277,9 @@ struct ContentFeatures
SimpleSoundSpec sound_dig;
SimpleSoundSpec sound_dug;
+ std::vector<std::string> connects_to;
+ std::set<content_t> connects_to_ids;
+
/*
Methods
*/
diff --git a/src/nodedef.cpp b/src/nodedef.cpp
index fb90320..9af8b77 100644
--- a/src/nodedef.cpp
+++ b/src/nodedef.cpp
@@ -389,6 +389,8 @@ void ContentFeatures::reset()
sound_footstep = SimpleSoundSpec();
sound_dig = SimpleSoundSpec("__group");
sound_dug = SimpleSoundSpec();
+ connects_to.clear();
+ connects_to_ids.clear();
}
void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
@@ -455,6 +457,21 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
os<<serializeString(mesh);
collision_box.serialize(os, protocol_version);
writeU8(os, floodable);
+ // We don't send the strings over, instead we map names to strings first here.
+ // FIXME: this should move to some game initialization point in the server.
+ for (std::vector<std::string>::const_iterator i = connects_to.begin();
+ i != connects_to.end(); ++i) {
+ std::set<content_t> ids;
+ // FIXME ndef is unknown here but you get the idea...
+ ndef->getIds(*i, ids);
+ for (std::set<content_t>::const_iterator it = ids.begin();
+ it != ids.end(); it++)
+ connects_to_ids.insert(*it);
+ }
+ writeU8(os, connects_to_ids.size());
+ for(std::set<content_t>::const_iterator i = connects_to_ids.begin();
+ i != connects_to_ids.end(); i++)
+ writeU16(os, *i);
}
void ContentFeatures::deSerialize(std::istream &is)
@@ -526,6 +543,9 @@ void ContentFeatures::deSerialize(std::istream &is)
mesh = deSerializeString(is);
collision_box.deSerialize(is);
floodable = readU8(is);
+ u32 connects_to_size = readU8(is);
+ for (u32 i = 0; i < connects_to_size; i++)
+ connects_to_ids.insert(readU16(is));
}catch(SerializationError &e) {};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment