[gunzemulator] r340 committed - Got rid fo the failure check-style and moved MUIDSanta.

0 views
Skip to first unread message

gunzem...@googlecode.com

unread,
Jun 27, 2010, 12:06:43 PM6/27/10
to gogo-dev...@googlegroups.com
Revision: 340
Author: cg.wowus.cg
Date: Sun Jun 27 09:06:30 2010
Log: Got rid fo the failure check-style and moved MUIDSanta.
http://code.google.com/p/gunzemulator/source/detail?r=340

Added:
/trunk/gunz/src/MUIDSanta.cpp
/trunk/include/gunz/MUIDSanta.h
Deleted:
/trunk/build/check-style.sh
Modified:
/trunk/gunz/src/CMakeLists.txt

=======================================
--- /dev/null
+++ /trunk/gunz/src/MUIDSanta.cpp Sun Jun 27 09:06:30 2010
@@ -0,0 +1,33 @@
+#include <gunz/MUIDSanta.h>
+
+#if defined(_MSC_VER)
+ #include <windows.h>
+#endif
+
+MUIDSanta::MUIDSanta()
+ : next(1) // Gunz doesn't like it when we give out MUIDs of 0.
+{
+}
+
+MUID MUIDSanta::get()
+{
+// TODO(Clark): Move this ugly #ifdef hell out into an "atomics" library
of sorts.
+#if defined(__GNUC__) || defined(__clang__)
+ return __sync_fetch_and_add(&next, 1);
+#elif defined(_MSC_VER)
+ return InterlockedIncrement(&next);
+#else
+ #error "Unsupported platform! Please write your own lock-free increment."
+#endif
+}
+
+void MUIDSanta::give_back(MUID /*id*/)
+{
+ // Unimplemented for now... we don't need it until the number of clients
+ // exceeds 2^64. In order for that to happen, the entire population of
+ // the world would need to connect 2.75 * 10^9 times EACH. And even then,
+ // this algorithm won't generate any collisions unless there's been
someone
+ // on from the very beginning. Suffice to say, there's no pressing need
+ // to make this algorithm "right", or any more complex until a bug report
+ // is filed.
+}
=======================================
--- /dev/null
+++ /trunk/include/gunz/MUIDSanta.h Sun Jun 27 09:06:30 2010
@@ -0,0 +1,14 @@
+#pragma once
+#include <gunz/simple_types.h>
+
+// This class controls the MUIDs of various in-game objects.
+class MUIDSanta
+{
+private:
+ volatile MUID next; // The "next" MUID to give out.
+
+public:
+ MUIDSanta();
+ MUID get();
+ void give_back(MUID id);
+};
=======================================
--- /trunk/build/check-style.sh Sat Jun 26 20:59:42 2010
+++ /dev/null
@@ -1,1 +0,0 @@
-cppcheck --enable=all --force -I /usr/include/mysql -I
/usr/include/mysql++ -I /home/clark/dev/cpp/GoGo/include -I /usr/include
-j3 .. 2> issues.txt
=======================================
--- /trunk/gunz/src/CMakeLists.txt Sat Jun 26 14:21:44 2010
+++ /trunk/gunz/src/CMakeLists.txt Sun Jun 27 09:06:30 2010
@@ -1,6 +1,7 @@
set(GUNZ_SRC
Channel.cpp
ChannelList.cpp
+ MUIDSanta.cpp
PlayerTraits.cpp
# More sources here!
)

Reply all
Reply to author
Forward
0 new messages