]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/utility.cpp
Fix key change menu a bit
[dragonfireclient.git] / src / utility.cpp
index 7ffbe716066cf467df04d392687494a1e3845313..4e9f307d8396c7d90be5ba699977cb99f2ba307d 100644 (file)
@@ -172,27 +172,6 @@ int myrand_range(int min, int max)
        return (myrand()%(max-min+1))+min;
 }
 
-#ifndef SERVER
-// Sets the color of all vertices in the mesh
-void setMeshVerticesColor(scene::IMesh* mesh, video::SColor& color)
-{
-       if(mesh == NULL)
-               return;
-       
-       u16 mc = mesh->getMeshBufferCount();
-       for(u16 j=0; j<mc; j++)
-       {
-               scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
-               video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
-               u16 vc = buf->getVertexCount();
-               for(u16 i=0; i<vc; i++)
-               {
-                       vertices[i].Color = color;
-               }
-       }
-}
-#endif
-
 /*
        blockpos: position of block in block coordinates
        camera_pos: position of camera in nodes
@@ -276,3 +255,103 @@ std::string translatePassword(std::string playername, std::wstring password)
 
 
 
+PointedThing::PointedThing():
+       type(POINTEDTHING_NOTHING),
+       node_undersurface(0,0,0),
+       node_abovesurface(0,0,0),
+       object_id(-1)
+{}
+
+std::string PointedThing::dump() const
+{
+       std::ostringstream os(std::ios::binary);
+       if(type == POINTEDTHING_NOTHING)
+       {
+               os<<"[nothing]";
+       }
+       else if(type == POINTEDTHING_NODE)
+       {
+               const v3s16 &u = node_undersurface;
+               const v3s16 &a = node_abovesurface;
+               os<<"[node under="<<u.X<<","<<u.Y<<","<<u.Z
+                       << " above="<<a.X<<","<<a.Y<<","<<a.Z<<"]";
+       }
+       else if(type == POINTEDTHING_OBJECT)
+       {
+               os<<"[object "<<object_id<<"]";
+       }
+       else
+       {
+               os<<"[unknown PointedThing]";
+       }
+       return os.str();
+}
+
+void PointedThing::serialize(std::ostream &os) const
+{
+       writeU8(os, 0); // version
+       writeU8(os, (u8)type);
+       if(type == POINTEDTHING_NOTHING)
+       {
+               // nothing
+       }
+       else if(type == POINTEDTHING_NODE)
+       {
+               writeV3S16(os, node_undersurface);
+               writeV3S16(os, node_abovesurface);
+       }
+       else if(type == POINTEDTHING_OBJECT)
+       {
+               writeS16(os, object_id);
+       }
+}
+
+void PointedThing::deSerialize(std::istream &is)
+{
+       int version = readU8(is);
+       if(version != 0) throw SerializationError(
+                       "unsupported PointedThing version");
+       type = (PointedThingType) readU8(is);
+       if(type == POINTEDTHING_NOTHING)
+       {
+               // nothing
+       }
+       else if(type == POINTEDTHING_NODE)
+       {
+               node_undersurface = readV3S16(is);
+               node_abovesurface = readV3S16(is);
+       }
+       else if(type == POINTEDTHING_OBJECT)
+       {
+               object_id = readS16(is);
+       }
+       else
+       {
+               throw SerializationError(
+                       "unsupported PointedThingType");
+       }
+}
+
+bool PointedThing::operator==(const PointedThing &pt2) const
+{
+       if(type != pt2.type)
+               return false;
+       if(type == POINTEDTHING_NODE)
+       {
+               if(node_undersurface != pt2.node_undersurface)
+                       return false;
+               if(node_abovesurface != pt2.node_abovesurface)
+                       return false;
+       }
+       else if(type == POINTEDTHING_OBJECT)
+       {
+               if(object_id != pt2.object_id)
+                       return false;
+       }
+       return true;
+}
+
+bool PointedThing::operator!=(const PointedThing &pt2) const
+{
+       return !(*this == pt2);
+}