pastebin

Paste #YuW -- näytä pelkkänä tekstinä -- uusi tämän pohjalta

Värjäys: Tyyli: ensimmäinen rivinumero: Tabin korvaus:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
diff --git a/src/environment.cpp b/src/environment.cpp
index 5bf127a..0a5bff1 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -331,7 +331,8 @@ void ActiveBlockList::update(core::list<v3s16> &active_positions,
        m_active_block_interval_overload_skip(0),
        m_game_time(0),
        m_game_time_fraction_counter(0),
-       m_recommended_send_interval(0.1)
+       m_recommended_send_interval(0.1),
+       m_next_active_object_id(1)
 {
 }
 
@@ -1238,20 +1239,21 @@ bool isFreeServerActiveObjectId(u16 id,
        return true;
 }
 
-u16 getFreeServerActiveObjectId(
+u16 ServerEnvironment::getFreeServerActiveObjectId(
                core::map<u16, ServerActiveObject*> &objects)
 {
-       u16 new_id = 1;
-       for(;;)
+       u16 new_id = m_next_active_object_id++;
+       // Try all of them if the wanted one is already allocated
+       for(u32 i=0; i<65535; i++)
        {
+               if(new_id == 0) // 0 is an invalid id
+                       new_id++;
                if(isFreeServerActiveObjectId(new_id, objects))
                        return new_id;
-               
-               if(new_id == 65535)
-                       return 0;
-
                new_id++;
        }
+       // Not found
+       return 0;
 }
 
 u16 ServerEnvironment::addActiveObject(ServerActiveObject *object)
diff --git a/src/environment.h b/src/environment.h
index 0cc53f9..8dafe80 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -300,6 +300,9 @@ class ServerEnvironment : public Environment
                -------------------------------------------
        */
 
+       u16 getFreeServerActiveObjectId(
+                       core::map<u16, ServerActiveObject*> &objects);
+
        /*
                Add an active object to the environment.
 
@@ -367,6 +370,8 @@ class ServerEnvironment : public Environment
        core::list<ABMWithState> m_abms;
        // An interval for generally sending object positions and stuff
        float m_recommended_send_interval;
+       // Preferred next active object id
+       u16 m_next_active_object_id;
 };
 
 #ifndef SERVER