Reduced server CPU usage on NodeMetadata step()s. Also furnace now cooks while no...
authorPerttu Ahola <celeron55@gmail.com>
Tue, 31 May 2011 17:02:55 +0000 (20:02 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 31 May 2011 17:02:55 +0000 (20:02 +0300)
src/environment.cpp
src/environment.h
src/main.cpp
src/map.h
src/nodemetadata.cpp
src/server.cpp
src/server.h

index 36c754d5717b5a153279ffc868196e5d769671c0..f5f20d0e5e0b7832889e9c60f0013bb92058735c 100644 (file)
@@ -729,6 +729,16 @@ void ServerEnvironment::step(float dtime)
                        // Activate stored objects
                        activateObjects(block);
 
+                       // Run node metadata
+                       bool changed = block->m_node_metadata.step((float)dtime_s);
+                       if(changed)
+                       {
+                               MapEditEvent event;
+                               event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
+                               event.p = p;
+                               m_map->dispatchEvent(&event);
+                       }
+
                        // TODO: Do something
                        // TODO: Implement usage of ActiveBlockModifier
                        
@@ -762,8 +772,10 @@ void ServerEnvironment::step(float dtime)
        /*
                Mess around in active blocks
        */
-       if(m_active_blocks_test_interval.step(dtime, 10.0))
+       if(m_active_blocks_nodemetadata_interval.step(dtime, 1.0))
        {
+               float dtime = 1.0;
+
                for(core::map<v3s16, bool>::Iterator
                                i = m_active_blocks.m_list.getIterator();
                                i.atEnd()==false; i++)
@@ -779,7 +791,38 @@ void ServerEnvironment::step(float dtime)
                        
                        // Set current time as timestamp
                        block->setTimestamp(m_game_time);
+
+                       // Run node metadata
+                       bool changed = block->m_node_metadata.step(dtime);
+                       if(changed)
+                       {
+                               MapEditEvent event;
+                               event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
+                               event.p = p;
+                               m_map->dispatchEvent(&event);
+                       }
+               }
+       }
+       if(m_active_blocks_test_interval.step(dtime, 10.0))
+       {
+               //float dtime = 10.0;
+
+               for(core::map<v3s16, bool>::Iterator
+                               i = m_active_blocks.m_list.getIterator();
+                               i.atEnd()==false; i++)
+               {
+                       v3s16 p = i.getNode()->getKey();
                        
+                       /*dstream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
+                                       <<") being handled"<<std::endl;*/
+
+                       MapBlock *block = m_map->getBlockNoCreateNoEx(p);
+                       if(block==NULL)
+                               continue;
+                       
+                       // Set current time as timestamp
+                       block->setTimestamp(m_game_time);
+
                        /*
                                Do stuff!
 
@@ -801,8 +844,11 @@ void ServerEnvironment::step(float dtime)
                        {
                                v3s16 p = p0 + block->getPosRelative();
                                MapNode n = block->getNodeNoEx(p0);
-                               // Test something:
-                               // Convert mud under proper lighting to grass
+
+                               /*
+                                       Test something:
+                                       Convert mud under proper lighting to grass
+                               */
                                if(n.d == CONTENT_MUD)
                                {
                                        if(myrand()%20 == 0)
index f5cce59339ab01451f8655edf85aeb652f1d19ce..b4f2a64caeb465ee5614b5a89452b44f17a3fe26 100644 (file)
@@ -246,6 +246,7 @@ private:
        ActiveBlockList m_active_blocks;
        IntervalLimiter m_active_blocks_management_interval;
        IntervalLimiter m_active_blocks_test_interval;
+       IntervalLimiter m_active_blocks_nodemetadata_interval;
        // Time from the beginning of the game in seconds.
        // Incremented in step().
        u32 m_game_time;
index a739d71bffb9301f09122bcc4e662d3ae6dfb1c9..e582569c521548dcc3431d10e91036eaf49c3d37 100644 (file)
@@ -312,7 +312,8 @@ Stuff to do before release:
 \r
 Fixes to the current release:\r
 -----------------------------\r
-- Make AuthManager to save only when data has changed\r
+- Fix client password crash\r
+- Remember to release the fixes (some are already done)\r
 \r
 Stuff to do after release:\r
 ---------------------------\r
index 09154547cf6240bf5bd44ea2aff0a9c39df8b2db..6f7ac0d3bfc5a591f6ac5d2dc99ea47ed5642261 100644 (file)
--- a/src/map.h
+++ b/src/map.h
@@ -46,8 +46,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define MAPTYPE_CLIENT 2
 
 enum MapEditEventType{
+       // Node added (changed from air or something else to something)
        MEET_ADDNODE,
+       // Node removed (changed to air)
        MEET_REMOVENODE,
+       // Node metadata of block changed (not knowing which node exactly)
+       // p stores block coordinate
+       MEET_BLOCK_NODE_METADATA_CHANGED,
+       // Anything else
        MEET_OTHER
 };
 
index 308a3385432a5126ee6e4010158e24dbd4f6bdda..f9468e4fa14f2a3dcc21f08788fdb734b2d24712 100644 (file)
@@ -268,91 +268,100 @@ void FurnaceNodeMetadata::inventoryModified()
 }
 bool FurnaceNodeMetadata::step(float dtime)
 {
+       if(dtime > 60.0)
+               dstream<<"Furnace stepping a long time ("<<dtime<<")"<<std::endl;
        // Update at a fixed frequency
-       const float interval = 0.5;
+       const float interval = 2.0;
        m_step_accumulator += dtime;
-       if(m_step_accumulator < interval)
-               return false;
-       m_step_accumulator -= interval;
-       dtime = interval;
-
-       //dstream<<"Furnace step dtime="<<dtime<<std::endl;
-       
-       InventoryList *dst_list = m_inventory->getList("dst");
-       assert(dst_list);
-
-       InventoryList *src_list = m_inventory->getList("src");
-       assert(src_list);
-       InventoryItem *src_item = src_list->getItem(0);
-       
-       // Start only if there are free slots in dst, so that it can
-       // accomodate any result item
-       if(dst_list->getFreeSlots() > 0 && src_item && src_item->isCookable())
-       {
-               m_src_totaltime = 3;
-       }
-       else
+       bool changed = false;
+       while(m_step_accumulator > interval)
        {
-               m_src_time = 0;
-               m_src_totaltime = 0;
-       }
+               m_step_accumulator -= interval;
+               dtime = interval;
 
-       if(m_fuel_time < m_fuel_totaltime)
-       {
-               //dstream<<"Furnace is active"<<std::endl;
-               m_fuel_time += dtime;
-               m_src_time += dtime;
-               if(m_src_time >= m_src_totaltime && m_src_totaltime > 0.001
-                               && src_item)
+               //dstream<<"Furnace step dtime="<<dtime<<std::endl;
+               
+               InventoryList *dst_list = m_inventory->getList("dst");
+               assert(dst_list);
+
+               InventoryList *src_list = m_inventory->getList("src");
+               assert(src_list);
+               InventoryItem *src_item = src_list->getItem(0);
+               
+               // Start only if there are free slots in dst, so that it can
+               // accomodate any result item
+               if(dst_list->getFreeSlots() > 0 && src_item && src_item->isCookable())
+               {
+                       m_src_totaltime = 3;
+               }
+               else
                {
-                       InventoryItem *cookresult = src_item->createCookResult();
-                       dst_list->addItem(cookresult);
-                       src_list->decrementMaterials(1);
                        m_src_time = 0;
                        m_src_totaltime = 0;
                }
-               return true;
-       }
-       
-       if(src_item == NULL || m_src_totaltime < 0.001)
-       {
-               return false;
-       }
-       
-       bool changed = false;
 
-       //dstream<<"Furnace is out of fuel"<<std::endl;
+               if(m_fuel_time < m_fuel_totaltime)
+               {
+                       //dstream<<"Furnace is active"<<std::endl;
+                       m_fuel_time += dtime;
+                       m_src_time += dtime;
+                       if(m_src_time >= m_src_totaltime && m_src_totaltime > 0.001
+                                       && src_item)
+                       {
+                               InventoryItem *cookresult = src_item->createCookResult();
+                               dst_list->addItem(cookresult);
+                               src_list->decrementMaterials(1);
+                               m_src_time = 0;
+                               m_src_totaltime = 0;
+                       }
+                       changed = true;
+                       continue;
+               }
+               
+               if(src_item == NULL || m_src_totaltime < 0.001)
+               {
+                       continue;
+               }
+               
+               //dstream<<"Furnace is out of fuel"<<std::endl;
 
-       InventoryList *fuel_list = m_inventory->getList("fuel");
-       assert(fuel_list);
-       InventoryItem *fuel_item = fuel_list->getItem(0);
+               InventoryList *fuel_list = m_inventory->getList("fuel");
+               assert(fuel_list);
+               InventoryItem *fuel_item = fuel_list->getItem(0);
 
-       if(ItemSpec(ITEM_MATERIAL, CONTENT_TREE).checkItem(fuel_item))
-       {
-               m_fuel_totaltime = 10;
-               m_fuel_time = 0;
-               fuel_list->decrementMaterials(1);
-               changed = true;
-       }
-       else if(ItemSpec(ITEM_MATERIAL, CONTENT_WOOD).checkItem(fuel_item))
-       {
-               m_fuel_totaltime = 5;
-               m_fuel_time = 0;
-               fuel_list->decrementMaterials(1);
-               changed = true;
-       }
-       else if(ItemSpec(ITEM_CRAFT, "lump_of_coal").checkItem(fuel_item))
-       {
-               m_fuel_totaltime = 10;
-               m_fuel_time = 0;
-               fuel_list->decrementMaterials(1);
-               changed = true;
-       }
-       else
-       {
-               //dstream<<"No fuel found"<<std::endl;
+               if(ItemSpec(ITEM_MATERIAL, CONTENT_TREE).checkItem(fuel_item))
+               {
+                       m_fuel_totaltime = 30;
+                       m_fuel_time = 0;
+                       fuel_list->decrementMaterials(1);
+                       changed = true;
+               }
+               else if(ItemSpec(ITEM_MATERIAL, CONTENT_WOOD).checkItem(fuel_item))
+               {
+                       m_fuel_totaltime = 30/4;
+                       m_fuel_time = 0;
+                       fuel_list->decrementMaterials(1);
+                       changed = true;
+               }
+               else if(ItemSpec(ITEM_CRAFT, "Stick").checkItem(fuel_item))
+               {
+                       m_fuel_totaltime = 30/4/4;
+                       m_fuel_time = 0;
+                       fuel_list->decrementMaterials(1);
+                       changed = true;
+               }
+               else if(ItemSpec(ITEM_CRAFT, "lump_of_coal").checkItem(fuel_item))
+               {
+                       m_fuel_totaltime = 40;
+                       m_fuel_time = 0;
+                       fuel_list->decrementMaterials(1);
+                       changed = true;
+               }
+               else
+               {
+                       //dstream<<"No fuel found"<<std::endl;
+               }
        }
-
        return changed;
 }
 
index 1b471fd09d3e23290b80549592719e9dcb205354..acfc7446f18fa6f12f59d8f14920c8086f6e3760 100644 (file)
@@ -1637,6 +1637,11 @@ void Server::AsyncRunStep()
                                dstream<<"Server: MEET_REMOVENODE"<<std::endl;
                                sendRemoveNode(event->p, event->already_known_by_peer);
                        }
+                       else if(event->type == MEET_BLOCK_NODE_METADATA_CHANGED)
+                       {
+                               dstream<<"Server: MEET_BLOCK_NODE_METADATA_CHANGED"<<std::endl;
+                               setBlockNotSent(event->p);
+                       }
                        else if(event->type == MEET_OTHER)
                        {
                                dstream<<"WARNING: Server: MEET_OTHER not implemented"
@@ -1676,7 +1681,7 @@ void Server::AsyncRunStep()
                Step node metadata
                TODO: Move to ServerEnvironment and utilize active block stuff
        */
-       {
+       /*{
                //TimeTaker timer("Step node metadata");
 
                JMutexAutoLock envlock(m_env_mutex);
@@ -1686,6 +1691,8 @@ void Server::AsyncRunStep()
 
                core::map<v3s16, MapBlock*> changed_blocks;
                m_env.getMap().nodeMetadataStep(dtime, changed_blocks);
+               
+               // Use setBlockNotSent
 
                for(core::map<v3s16, MapBlock*>::Iterator
                                i = changed_blocks.getIterator();
@@ -1701,7 +1708,7 @@ void Server::AsyncRunStep()
                                client->SetBlockNotSent(block->getPos());
                        }
                }
-       }
+       }*/
                
        /*
                Trigger emergethread (it somehow gets to a non-triggered but
@@ -3655,6 +3662,17 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
        }
 }
 
+void Server::setBlockNotSent(v3s16 p)
+{
+       for(core::map<u16, RemoteClient*>::Iterator
+               i = m_clients.getIterator();
+               i.atEnd()==false; i++)
+       {
+               RemoteClient *client = i.getNode()->getValue();
+               client->SetBlockNotSent(p);
+       }
+}
+
 void Server::SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver)
 {
        DSTACK(__FUNCTION_NAME);
index 6bee106855b98efb6c527c01df2a6a4479a9ebc3..791ecdec770009dcd9ead6b2347709efdd284399 100644 (file)
@@ -480,15 +480,17 @@ private:
                Additionally, if far_players!=NULL, players further away than
                far_d_nodes are ignored and their peer_ids are added to far_players
        */
+       // Envlock and conlock should be locked when calling these
        void sendRemoveNode(v3s16 p, u16 ignore_id=0,
                        core::list<u16> *far_players=NULL, float far_d_nodes=100);
        void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
                        core::list<u16> *far_players=NULL, float far_d_nodes=100);
+       void setBlockNotSent(v3s16 p);
        
        // Environment and Connection must be locked when called
        void SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver);
        
-       // Sends blocks to clients
+       // Sends blocks to clients (locks env and con on its own)
        void SendBlocks(float dtime);
 
        /*