Browse Source

Migrate to STL containers/algorithms.

nephele-craftmethods
Ilya Zhuravlev 10 years ago committed by kwolekr
parent
commit
6a1670dbc3
  1. 20
      src/chat.cpp
  2. 14
      src/chat.h
  3. 102
      src/client.cpp
  4. 15
      src/client.h
  5. 55
      src/clientmap.cpp
  6. 8
      src/clientmap.h
  7. 12
      src/clientobject.cpp
  8. 5
      src/clientobject.h
  9. 254
      src/connection.cpp
  10. 23
      src/connection.h
  11. 21
      src/content_abm.cpp
  12. 2
      src/content_cao.cpp
  13. 12
      src/content_mapblock.cpp
  14. 2
      src/content_sao.cpp
  15. 29
      src/debug.cpp
  16. 29
      src/debug.h
  17. 12
      src/emerge.cpp
  18. 398
      src/environment.cpp
  19. 35
      src/environment.h
  20. 8
      src/farmesh.cpp
  21. 25
      src/game.h
  22. 2
      src/guiChatConsole.cpp
  23. 10
      src/guiFormSpecMenu.h
  24. 6
      src/itemdef.cpp
  25. 13
      src/keycode.cpp
  26. 2
      src/localplayer.cpp
  27. 3
      src/localplayer.h
  28. 104
      src/main.cpp
  29. 15
      src/mainmenumanager.h
  30. 314
      src/map.cpp
  31. 92
      src/map.h
  32. 4
      src/mapblock.cpp
  33. 3
      src/mapblock.h
  34. 12
      src/mapblock_mesh.cpp
  35. 6
      src/mapblock_mesh.h
  36. 4
      src/mapgen.cpp
  37. 4
      src/mapgen_v6.cpp
  38. 41
      src/mapsector.cpp
  39. 8
      src/mapsector.h
  40. 4
      src/mods.h
  41. 5
      src/object_properties.h
  42. 63
      src/profiler.h
  43. 16
      src/scriptapi.cpp
  44. 6
      src/scriptapi_env.cpp
  45. 394
      src/server.cpp
  46. 27
      src/server.h
  47. 12
      src/serverobject.cpp
  48. 2
      src/serverobject.h
  49. 113
      src/settings.h
  50. 36
      src/shader.cpp
  51. 12
      src/staticobject.cpp
  52. 14
      src/staticobject.h
  53. 43
      src/test.cpp
  54. 78
      src/tile.cpp
  55. 20
      src/treegen.cpp
  56. 88
      src/util/container.h
  57. 2
      src/util/numeric.cpp
  58. 3
      src/util/numeric.h
  59. 16
      src/util/thread.h
  60. 37
      src/voxel.cpp
  61. 12
      src/voxel.h
  62. 12
      src/voxelalgorithms.cpp
  63. 8
      src/voxelalgorithms.h

20
src/chat.cpp

@ -117,8 +117,8 @@ void ChatBuffer::deleteOldest(u32 count) @@ -117,8 +117,8 @@ void ChatBuffer::deleteOldest(u32 count)
--count;
}
m_unformatted.erase(0, del_unformatted);
m_formatted.erase(0, del_formatted);
m_unformatted.erase(m_unformatted.begin(), m_unformatted.begin() + del_unformatted);
m_formatted.erase(m_formatted.begin(), m_formatted.begin() + del_formatted);
}
void ChatBuffer::deleteByAge(f32 maxAge)
@ -232,10 +232,10 @@ void ChatBuffer::scrollTop() @@ -232,10 +232,10 @@ void ChatBuffer::scrollTop()
}
u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
core::array<ChatFormattedLine>& destination) const
std::vector<ChatFormattedLine>& destination) const
{
u32 num_added = 0;
core::array<ChatFormattedFragment> next_frags;
std::vector<ChatFormattedFragment> next_frags;
ChatFormattedLine next_line;
ChatFormattedFragment temp_frag;
u32 out_column = 0;
@ -292,7 +292,7 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols, @@ -292,7 +292,7 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
frag.column = out_column;
next_line.fragments.push_back(frag);
out_column += frag.text.size();
next_frags.erase(0, 1);
next_frags.erase(next_frags.begin());
}
else
{
@ -414,7 +414,7 @@ std::wstring ChatPrompt::submit() @@ -414,7 +414,7 @@ std::wstring ChatPrompt::submit()
if (!line.empty())
m_history.push_back(line);
if (m_history.size() > m_history_limit)
m_history.erase(0);
m_history.erase(m_history.begin());
m_history_index = m_history.size();
m_view = 0;
m_cursor = 0;
@ -464,7 +464,7 @@ void ChatPrompt::historyNext() @@ -464,7 +464,7 @@ void ChatPrompt::historyNext()
}
}
void ChatPrompt::nickCompletion(const core::list<std::wstring>& names, bool backwards)
void ChatPrompt::nickCompletion(const std::list<std::wstring>& names, bool backwards)
{
// Two cases:
// (a) m_nick_completion_start == m_nick_completion_end == 0
@ -492,10 +492,10 @@ void ChatPrompt::nickCompletion(const core::list<std::wstring>& names, bool back @@ -492,10 +492,10 @@ void ChatPrompt::nickCompletion(const core::list<std::wstring>& names, bool back
std::wstring prefix = m_line.substr(prefix_start, prefix_end - prefix_start);
// find all names that start with the selected prefix
core::array<std::wstring> completions;
for (core::list<std::wstring>::ConstIterator
std::vector<std::wstring> completions;
for (std::list<std::wstring>::const_iterator
i = names.begin();
i != names.end(); i++)
i != names.end(); ++i)
{
if (str_starts_with(*i, prefix, true))
{

14
src/chat.h

@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_bloated.h"
#include <string>
#include <vector>
#include <list>
// Chat console related classes, only used by the client
@ -55,7 +57,7 @@ struct ChatFormattedFragment @@ -55,7 +57,7 @@ struct ChatFormattedFragment
struct ChatFormattedLine
{
// Array of text fragments
core::array<ChatFormattedFragment> fragments;
std::vector<ChatFormattedFragment> fragments;
// true if first line of one formatted ChatLine
bool first;
};
@ -110,7 +112,7 @@ public: @@ -110,7 +112,7 @@ public:
// Appends the formatted lines to the destination array and
// returns the number of formatted lines.
u32 formatChatLine(const ChatLine& line, u32 cols,
core::array<ChatFormattedLine>& destination) const;
std::vector<ChatFormattedLine>& destination) const;
protected:
s32 getTopScrollPos() const;
@ -120,7 +122,7 @@ private: @@ -120,7 +122,7 @@ private:
// Scrollback size
u32 m_scrollback;
// Array of unformatted chat lines
core::array<ChatLine> m_unformatted;
std::vector<ChatLine> m_unformatted;
// Number of character columns in console
u32 m_cols;
@ -129,7 +131,7 @@ private: @@ -129,7 +131,7 @@ private:
// Scroll position (console's top line index into m_formatted)
s32 m_scroll;
// Array of formatted lines
core::array<ChatFormattedLine> m_formatted;
std::vector<ChatFormattedLine> m_formatted;
// Empty formatted line, for error returns
ChatFormattedLine m_empty_formatted_line;
};
@ -158,7 +160,7 @@ public: @@ -158,7 +160,7 @@ public:
void historyNext();
// Nick completion
void nickCompletion(const core::list<std::wstring>& names, bool backwards);
void nickCompletion(const std::list<std::wstring>& names, bool backwards);
// Update console size and reformat the visible portion of the prompt
void reformat(u32 cols);
@ -209,7 +211,7 @@ private: @@ -209,7 +211,7 @@ private:
// Currently edited line
std::wstring m_line;
// History buffer
core::array<std::wstring> m_history;
std::vector<std::wstring> m_history;
// History index (0 <= m_history_index <= m_history.size())
u32 m_history_index;
// Maximum number of history entries

102
src/client.cpp

@ -232,8 +232,8 @@ void * MediaFetchThread::Thread() @@ -232,8 +232,8 @@ void * MediaFetchThread::Thread()
#if USE_CURL
CURL *curl;
CURLcode res;
for (core::list<MediaRequest>::Iterator i = m_file_requests.begin();
i != m_file_requests.end(); i++) {
for (std::list<MediaRequest>::iterator i = m_file_requests.begin();
i != m_file_requests.end(); ++i) {
curl = curl_easy_init();
assert(curl);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
@ -360,8 +360,8 @@ Client::~Client() @@ -360,8 +360,8 @@ Client::~Client()
}
}
for (core::list<MediaFetchThread*>::Iterator i = m_media_fetch_threads.begin();
i != m_media_fetch_threads.end(); i++)
for (std::list<MediaFetchThread*>::iterator i = m_media_fetch_threads.begin();
i != m_media_fetch_threads.end(); ++i)
delete *i;
}
@ -585,7 +585,7 @@ void Client::step(float dtime) @@ -585,7 +585,7 @@ void Client::step(float dtime)
if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime))
{
ScopeProfiler sp(g_profiler, "Client: map timer and unload");
core::list<v3s16> deleted_blocks;
std::list<v3s16> deleted_blocks;
m_env.getMap().timerUpdate(map_timer_and_unload_dtime,
g_settings->getFloat("client_unload_unused_data_timeout"),
&deleted_blocks);
@ -599,8 +599,8 @@ void Client::step(float dtime) @@ -599,8 +599,8 @@ void Client::step(float dtime)
NOTE: This loop is intentionally iterated the way it is.
*/
core::list<v3s16>::Iterator i = deleted_blocks.begin();
core::list<v3s16> sendlist;
std::list<v3s16>::iterator i = deleted_blocks.begin();
std::list<v3s16> sendlist;
for(;;)
{
if(sendlist.size() == 255 || i == deleted_blocks.end())
@ -619,9 +619,9 @@ void Client::step(float dtime) @@ -619,9 +619,9 @@ void Client::step(float dtime)
writeU16(&reply[0], TOSERVER_DELETEDBLOCKS);
reply[2] = sendlist.size();
u32 k = 0;
for(core::list<v3s16>::Iterator
for(std::list<v3s16>::iterator
j = sendlist.begin();
j != sendlist.end(); j++)
j != sendlist.end(); ++j)
{
writeV3S16(&reply[2+1+6*k], *j);
k++;
@ -635,7 +635,7 @@ void Client::step(float dtime) @@ -635,7 +635,7 @@ void Client::step(float dtime)
}
sendlist.push_back(*i);
i++;
++i;
}
}
@ -727,7 +727,7 @@ void Client::step(float dtime) @@ -727,7 +727,7 @@ void Client::step(float dtime)
<<std::endl;*/
int num_processed_meshes = 0;
while(m_mesh_update_thread.m_queue_out.size() > 0)
while(!m_mesh_update_thread.m_queue_out.empty())
{
num_processed_meshes++;
MeshUpdateResult r = m_mesh_update_thread.m_queue_out.pop_front();
@ -779,10 +779,10 @@ void Client::step(float dtime) @@ -779,10 +779,10 @@ void Client::step(float dtime)
*/
if (m_media_receive_started) {
bool all_stopped = true;
for (core::list<MediaFetchThread*>::Iterator thread = m_media_fetch_threads.begin();
thread != m_media_fetch_threads.end(); thread++) {
for (std::list<MediaFetchThread*>::iterator thread = m_media_fetch_threads.begin();
thread != m_media_fetch_threads.end(); ++thread) {
all_stopped &= !(*thread)->IsRunning();
while ((*thread)->m_file_data.size() > 0) {
while (!(*thread)->m_file_data.empty()) {
std::pair <std::string, std::string> out = (*thread)->m_file_data.pop_front();
++m_media_received_count;
@ -803,9 +803,9 @@ void Client::step(float dtime) @@ -803,9 +803,9 @@ void Client::step(float dtime)
}
{
core::map<std::string, std::string>::Node *n;
std::map<std::string, std::string>::iterator n;
n = m_media_name_sha1_map.find(out.first);
if(n == NULL)
if(n == m_media_name_sha1_map.end())
errorstream<<"The server sent a file that has not "
<<"been announced."<<std::endl;
else
@ -814,11 +814,11 @@ void Client::step(float dtime) @@ -814,11 +814,11 @@ void Client::step(float dtime)
}
}
if (all_stopped) {
core::list<MediaRequest> fetch_failed;
for (core::list<MediaFetchThread*>::Iterator thread = m_media_fetch_threads.begin();
thread != m_media_fetch_threads.end(); thread++) {
for (core::list<MediaRequest>::Iterator request = (*thread)->m_failed.begin();
request != (*thread)->m_failed.end(); request++)
std::list<MediaRequest> fetch_failed;
for (std::list<MediaFetchThread*>::iterator thread = m_media_fetch_threads.begin();
thread != m_media_fetch_threads.end(); ++thread) {
for (std::list<MediaRequest>::iterator request = (*thread)->m_failed.begin();
request != (*thread)->m_failed.end(); ++request)
fetch_failed.push_back(*request);
(*thread)->m_failed.clear();
}
@ -1015,14 +1015,14 @@ void Client::deletingPeer(con::Peer *peer, bool timeout) @@ -1015,14 +1015,14 @@ void Client::deletingPeer(con::Peer *peer, bool timeout)
string name
}
*/
void Client::request_media(const core::list<MediaRequest> &file_requests)
void Client::request_media(const std::list<MediaRequest> &file_requests)
{
std::ostringstream os(std::ios_base::binary);
writeU16(os, TOSERVER_REQUEST_MEDIA);
writeU16(os, file_requests.size());
for(core::list<MediaRequest>::ConstIterator i = file_requests.begin();
i != file_requests.end(); i++) {
for(std::list<MediaRequest>::const_iterator i = file_requests.begin();
i != file_requests.end(); ++i) {
os<<serializeString(i->name);
}
@ -1622,7 +1622,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) @@ -1622,7 +1622,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
infostream<<"Client: Received media announcement: packet size: "
<<datasize<<std::endl;
core::list<MediaRequest> file_requests;
std::list<MediaRequest> file_requests;
for(int i=0; i<num_files; i++)
{
@ -1641,7 +1641,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) @@ -1641,7 +1641,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
std::string sha1_hex = hex_encode(sha1_raw);
std::ostringstream tmp_os(std::ios_base::binary);
bool found_in_cache = m_media_cache.load_sha1(sha1_raw, tmp_os);
m_media_name_sha1_map.set(name, sha1_raw);
m_media_name_sha1_map[name] = sha1_raw;
// If found in cache, try to load it from there
if(found_in_cache)
@ -1677,16 +1677,16 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) @@ -1677,16 +1677,16 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
request_media(file_requests);
} else {
#if USE_CURL
core::list<MediaFetchThread*>::Iterator cur = m_media_fetch_threads.begin();
for(core::list<MediaRequest>::Iterator i = file_requests.begin();
i != file_requests.end(); i++) {
std::list<MediaFetchThread*>::iterator cur = m_media_fetch_threads.begin();
for(std::list<MediaRequest>::iterator i = file_requests.begin();
i != file_requests.end(); ++i) {
(*cur)->m_file_requests.push_back(*i);
cur++;
if (cur == m_media_fetch_threads.end())
cur = m_media_fetch_threads.begin();
}
for (core::list<MediaFetchThread*>::Iterator i = m_media_fetch_threads.begin();
i != m_media_fetch_threads.end(); i++) {
for (std::list<MediaFetchThread*>::iterator i = m_media_fetch_threads.begin();
i != m_media_fetch_threads.end(); ++i) {
(*i)->m_remote_url = remote_media;
(*i)->Start();
}
@ -1762,9 +1762,9 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) @@ -1762,9 +1762,9 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
}
{
core::map<std::string, std::string>::Node *n;
std::map<std::string, std::string>::iterator n;
n = m_media_name_sha1_map.find(name);
if(n == NULL)
if(n == m_media_name_sha1_map.end())
errorstream<<"The server sent a file that has not "
<<"been announced."<<std::endl;
else
@ -2231,7 +2231,7 @@ void Client::sendPlayerItem(u16 item) @@ -2231,7 +2231,7 @@ void Client::sendPlayerItem(u16 item)
void Client::removeNode(v3s16 p)
{
core::map<v3s16, MapBlock*> modified_blocks;
std::map<v3s16, MapBlock*> modified_blocks;
try
{
@ -2245,12 +2245,11 @@ void Client::removeNode(v3s16 p) @@ -2245,12 +2245,11 @@ void Client::removeNode(v3s16 p)
// add urgent task to update the modified node
addUpdateMeshTaskForNode(p, false, true);
for(core::map<v3s16, MapBlock * >::Iterator
i = modified_blocks.getIterator();
i.atEnd() == false; i++)
for(std::map<v3s16, MapBlock * >::iterator
i = modified_blocks.begin();
i != modified_blocks.end(); ++i)
{
v3s16 p = i.getNode()->getKey();
addUpdateMeshTaskWithEdge(p);
addUpdateMeshTaskWithEdge(i->first);
}
}
@ -2258,7 +2257,7 @@ void Client::addNode(v3s16 p, MapNode n) @@ -2258,7 +2257,7 @@ void Client::addNode(v3s16 p, MapNode n)
{
TimeTaker timer1("Client::addNode()");
core::map<v3s16, MapBlock*> modified_blocks;
std::map<v3s16, MapBlock*> modified_blocks;
try
{
@ -2268,12 +2267,11 @@ void Client::addNode(v3s16 p, MapNode n) @@ -2268,12 +2267,11 @@ void Client::addNode(v3s16 p, MapNode n)
catch(InvalidPositionException &e)
{}
for(core::map<v3s16, MapBlock * >::Iterator
i = modified_blocks.getIterator();
i.atEnd() == false; i++)
for(std::map<v3s16, MapBlock * >::iterator
i = modified_blocks.begin();
i != modified_blocks.end(); ++i)
{
v3s16 p = i.getNode()->getKey();
addUpdateMeshTaskWithEdge(p);
addUpdateMeshTaskWithEdge(i->first);
}
}
@ -2373,7 +2371,7 @@ ClientActiveObject * Client::getSelectedActiveObject( @@ -2373,7 +2371,7 @@ ClientActiveObject * Client::getSelectedActiveObject(
core::line3d<f32> shootline_on_map
)
{
core::array<DistanceSortedActiveObject> objects;
std::vector<DistanceSortedActiveObject> objects;
m_env.getActiveObjects(from_pos_f_on_map, max_d, objects);
@ -2381,7 +2379,7 @@ ClientActiveObject * Client::getSelectedActiveObject( @@ -2381,7 +2379,7 @@ ClientActiveObject * Client::getSelectedActiveObject(
// Sort them.
// After this, the closest object is the first in the array.
objects.sort();
std::sort(objects.begin(), objects.end());
for(u32 i=0; i<objects.size(); i++)
{
@ -2420,13 +2418,13 @@ void Client::printDebugInfo(std::ostream &os) @@ -2420,13 +2418,13 @@ void Client::printDebugInfo(std::ostream &os)
<<std::endl;*/
}
core::list<std::wstring> Client::getConnectedPlayerNames()
std::list<std::wstring> Client::getConnectedPlayerNames()
{
core::list<Player*> players = m_env.getPlayers(true);
core::list<std::wstring> playerNames;
for(core::list<Player*>::Iterator
std::list<Player*> players = m_env.getPlayers(true);
std::list<std::wstring> playerNames;
for(std::list<Player*>::iterator
i = players.begin();
i != players.end(); i++)
i != players.end(); ++i)
{
Player *player = *i;
playerNames.push_back(narrow_to_wide(player->getName()));

15
src/client.h

@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include "particles.h"
#include "util/pointedthing.h"
#include <algorithm>
struct MeshMakeData;
class MapBlockMesh;
@ -142,9 +143,9 @@ public: @@ -142,9 +143,9 @@ public:
void * Thread();
core::list<MediaRequest> m_file_requests;
std::list<MediaRequest> m_file_requests;
MutexedQueue<std::pair<std::string, std::string> > m_file_data;
core::list<MediaRequest> m_failed;
std::list<MediaRequest> m_failed;
std::string m_remote_url;
IGameDef *m_gamedef;
};
@ -282,7 +283,7 @@ public: @@ -282,7 +283,7 @@ public:
// Prints a line or two of info
void printDebugInfo(std::ostream &os);
core::list<std::wstring> getConnectedPlayerNames();
std::list<std::wstring> getConnectedPlayerNames();
float getAnimationTime();
@ -347,7 +348,7 @@ private: @@ -347,7 +348,7 @@ private:
// Insert a media file appropriately into the appropriate manager
bool loadMedia(const std::string &data, const std::string &filename);
void request_media(const core::list<MediaRequest> &file_requests);
void request_media(const std::list<MediaRequest> &file_requests);
// Virtual methods from con::PeerHandler
void peerAdded(con::Peer *peer);
@ -377,7 +378,7 @@ private: @@ -377,7 +378,7 @@ private:
MtEventManager *m_event;
MeshUpdateThread m_mesh_update_thread;
core::list<MediaFetchThread*> m_media_fetch_threads;
std::list<MediaFetchThread*> m_media_fetch_threads;
ClientEnvironment m_env;
con::Connection m_con;
IrrlichtDevice *m_device;
@ -387,7 +388,7 @@ private: @@ -387,7 +388,7 @@ private:
bool m_inventory_updated;
Inventory *m_inventory_from_server;
float m_inventory_from_server_age;
core::map<v3s16, bool> m_active_blocks;
std::set<v3s16> m_active_blocks;
PacketCounter m_packetcounter;
// Block mesh animation parameters
float m_animation_time;
@ -405,7 +406,7 @@ private: @@ -405,7 +406,7 @@ private:
Queue<ClientEvent> m_client_event_queue;
FileCache m_media_cache;
// Mapping from media file name to SHA1 checksum
core::map<std::string, std::string> m_media_name_sha1_map;
std::map<std::string, std::string> m_media_name_sha1_map;
bool m_media_receive_started;
u32 m_media_count;
u32 m_media_received_count;

55
src/clientmap.cpp

@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "profiler.h"
#include "settings.h"
#include "util/mathconstants.h"
#include <algorithm>
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@ -83,7 +84,7 @@ MapSector * ClientMap::emergeSector(v2s16 p2d) @@ -83,7 +84,7 @@ MapSector * ClientMap::emergeSector(v2s16 p2d)
{
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
m_sectors.insert(p2d, sector);
m_sectors[p2d] = sector;
}
return sector;
@ -164,11 +165,11 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) @@ -164,11 +165,11 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
INodeDefManager *nodemgr = m_gamedef->ndef();
for(core::map<v3s16, MapBlock*>::Iterator
i = m_drawlist.getIterator();
i.atEnd() == false; i++)
for(std::map<v3s16, MapBlock*>::iterator
i = m_drawlist.begin();
i != m_drawlist.end(); ++i)
{
MapBlock *block = i.getNode()->getValue();
MapBlock *block = i->second;
block->refDrop();
}
m_drawlist.clear();
@ -215,11 +216,11 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) @@ -215,11 +216,11 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
// Blocks from which stuff was actually drawn
//u32 blocks_without_stuff = 0;
for(core::map<v2s16, MapSector*>::Iterator
si = m_sectors.getIterator();
si.atEnd() == false; si++)
for(std::map<v2s16, MapSector*>::iterator
si = m_sectors.begin();
si != m_sectors.end(); ++si)
{
MapSector *sector = si.getNode()->getValue();
MapSector *sector = si->second;
v2s16 sp = sector->getPos();
if(m_control.range_all == false)
@ -231,7 +232,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) @@ -231,7 +232,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
continue;
}
core::list< MapBlock * > sectorblocks;
std::list< MapBlock * > sectorblocks;
sector->getBlocks(sectorblocks);
/*
@ -240,7 +241,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) @@ -240,7 +241,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
u32 sector_blocks_drawn = 0;
core::list< MapBlock * >::Iterator i;
std::list< MapBlock * >::iterator i;
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
{
MapBlock *block = *i;
@ -350,7 +351,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) @@ -350,7 +351,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
} // foreach sectorblocks
if(sector_blocks_drawn != 0)
m_last_drawn_sectors[sp] = true;
m_last_drawn_sectors.insert(sp);
}
m_control.blocks_would_have_drawn = blocks_would_have_drawn;
@ -368,12 +369,12 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver) @@ -368,12 +369,12 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
struct MeshBufList
{
video::SMaterial m;
core::list<scene::IMeshBuffer*> bufs;
std::list<scene::IMeshBuffer*> bufs;
};
struct MeshBufListList
{
core::list<MeshBufList> lists;
std::list<MeshBufList> lists;
void clear()
{
@ -382,8 +383,8 @@ struct MeshBufListList @@ -382,8 +383,8 @@ struct MeshBufListList
void add(scene::IMeshBuffer *buf)
{
for(core::list<MeshBufList>::Iterator i = lists.begin();
i != lists.end(); i++){
for(std::list<MeshBufList>::iterator i = lists.begin();
i != lists.end(); ++i){
MeshBufList &l = *i;
if(l.m == buf->getMaterial()){
l.bufs.push_back(buf);
@ -487,11 +488,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) @@ -487,11 +488,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
MeshBufListList drawbufs;
for(core::map<v3s16, MapBlock*>::Iterator
i = m_drawlist.getIterator();
i.atEnd() == false; i++)
for(std::map<v3s16, MapBlock*>::iterator
i = m_drawlist.begin();
i != m_drawlist.end(); ++i)
{
MapBlock *block = i.getNode()->getValue();
MapBlock *block = i->second;
// If the mesh of the block happened to get deleted, ignore it
if(block->mesh == NULL)
@ -569,11 +570,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) @@ -569,11 +570,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
}
}
core::list<MeshBufList> &lists = drawbufs.lists;
std::list<MeshBufList> &lists = drawbufs.lists;
int timecheck_counter = 0;
for(core::list<MeshBufList>::Iterator i = lists.begin();
i != lists.end(); i++)
for(std::list<MeshBufList>::iterator i = lists.begin();
i != lists.end(); ++i)
{
{
timecheck_counter++;
@ -595,8 +596,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) @@ -595,8 +596,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
driver->setMaterial(list.m);
for(core::list<scene::IMeshBuffer*>::Iterator j = list.bufs.begin();
j != list.bufs.end(); j++)
for(std::list<scene::IMeshBuffer*>::iterator j = list.bufs.begin();
j != list.bufs.end(); ++j)
{
scene::IMeshBuffer *buf = *j;
driver->drawMeshBuffer(buf);
@ -769,7 +770,7 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor, @@ -769,7 +770,7 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
float sunlight_min_d = max_d*0.8;
if(sunlight_min_d > 35*BS)
sunlight_min_d = 35*BS;
core::array<int> values;
std::vector<int> values;
for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
v3f z_dir = z_directions[i];
z_dir.normalize();
@ -798,7 +799,7 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor, @@ -798,7 +799,7 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
}
int brightness_sum = 0;
int brightness_count = 0;
values.sort();
std::sort(values.begin(), values.end());
u32 num_values_to_use = values.size();
if(num_values_to_use >= 10)
num_values_to_use -= num_values_to_use/2;

8
src/clientmap.h

@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include "map.h"
#include <set>
#include <map>
struct MapDrawControl
{
@ -128,7 +130,7 @@ public: @@ -128,7 +130,7 @@ public:
// Check if sector was drawn on last render()
bool sectorWasDrawn(v2s16 p)
{
return (m_last_drawn_sectors.find(p) != NULL);
return (m_last_drawn_sectors.find(p) != m_last_drawn_sectors.end());
}
private:
@ -143,9 +145,9 @@ private: @@ -143,9 +145,9 @@ private:
f32 m_camera_fov;
JMutex m_camera_mutex;
core::map<v3s16, MapBlock*> m_drawlist;
std::map<v3s16, MapBlock*> m_drawlist;
core::map<v2s16, bool> m_last_drawn_sectors;
std::set<v2s16> m_last_drawn_sectors;
};
#endif

12
src/clientobject.cpp

@ -43,9 +43,9 @@ ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef, @@ -43,9 +43,9 @@ ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef,
ClientEnvironment *env)
{
// Find factory function
core::map<u16, Factory>::Node *n;
std::map<u16, Factory>::iterator n;
n = m_types.find(type);
if(n == NULL)
if(n == m_types.end())
{
// If factory is not found, just return.
dstream<<"WARNING: ClientActiveObject: No factory for type="
@ -53,18 +53,18 @@ ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef, @@ -53,18 +53,18 @@ ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef,
return NULL;
}
Factory f = n->getValue();
Factory f = n->second;
ClientActiveObject *object = (*f)(gamedef, env);
return object;
}
void ClientActiveObject::registerType(u16 type, Factory f)
{
core::map<u16, Factory>::Node *n;
std::map<u16, Factory>::iterator n;
n = m_types.find(type);
if(n)
if(n != m_types.end())
return;
m_types.insert(type, f);
m_types[type] = f;
}

5
src/clientobject.h

@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include "activeobject.h"
#include <map>
/*
@ -96,7 +97,7 @@ protected: @@ -96,7 +97,7 @@ protected:
ClientEnvironment *m_env;
private:
// Used for creating objects based on type
static core::map<u16, Factory> m_types;
static std::map<u16, Factory> m_types;
};
struct DistanceSortedActiveObject
@ -110,7 +111,7 @@ struct DistanceSortedActiveObject @@ -110,7 +111,7 @@ struct DistanceSortedActiveObject
d = a_d;
}
bool operator < (DistanceSortedActiveObject &other)
bool operator < (const DistanceSortedActiveObject &other) const
{
return d < other.d;
}

254
src/connection.cpp

@ -76,19 +76,20 @@ SharedBuffer<u8> makeOriginalPacket( @@ -76,19 +76,20 @@ SharedBuffer<u8> makeOriginalPacket(
return b;
}
core::list<SharedBuffer<u8> > makeSplitPacket(
std::list<SharedBuffer<u8> > makeSplitPacket(
SharedBuffer<u8> data,
u32 chunksize_max,
u16 seqnum)
{
// Chunk packets, containing the TYPE_SPLIT header
core::list<SharedBuffer<u8> > chunks;
std::list<SharedBuffer<u8> > chunks;
u32 chunk_header_size = 7;
u32 maximum_data_size = chunksize_max - chunk_header_size;
u32 start = 0;
u32 end = 0;
u32 chunk_num = 0;
u16 chunk_count = 0;
do{
end = start + maximum_data_size - 1;
if(end > data.getSize() - 1)
@ -106,16 +107,15 @@ core::list<SharedBuffer<u8> > makeSplitPacket( @@ -106,16 +107,15 @@ core::list<SharedBuffer<u8> > makeSplitPacket(
memcpy(&chunk[chunk_header_size], &data[start], payload_size);
chunks.push_back(chunk);
chunk_count++;
start = end + 1;
chunk_num++;
}
while(end != data.getSize() - 1);
u16 chunk_count = chunks.getSize();
core::list<SharedBuffer<u8> >::Iterator i = chunks.begin();
for(; i != chunks.end(); i++)
for(std::list<SharedBuffer<u8> >::iterator i = chunks.begin();
i != chunks.end(); ++i)
{
// Write chunk_count
writeU16(&((*i)[3]), chunk_count);
@ -124,13 +124,13 @@ core::list<SharedBuffer<u8> > makeSplitPacket( @@ -124,13 +124,13 @@ core::list<SharedBuffer<u8> > makeSplitPacket(
return chunks;
}
core::list<SharedBuffer<u8> > makeAutoSplitPacket(
std::list<SharedBuffer<u8> > makeAutoSplitPacket(
SharedBuffer<u8> data,
u32 chunksize_max,
u16 &split_seqnum)
{
u32 original_header_size = 1;
core::list<SharedBuffer<u8> > list;
std::list<SharedBuffer<u8> > list;
if(data.getSize() + original_header_size > chunksize_max)
{
list = makeSplitPacket(data, chunksize_max, split_seqnum);
@ -170,11 +170,13 @@ SharedBuffer<u8> makeReliablePacket( @@ -170,11 +170,13 @@ SharedBuffer<u8> makeReliablePacket(
ReliablePacketBuffer
*/
ReliablePacketBuffer::ReliablePacketBuffer(): m_list_size(0) {}
void ReliablePacketBuffer::print()
{
core::list<BufferedPacket>::Iterator i;
i = m_list.begin();
for(; i != m_list.end(); i++)
for(std::list<BufferedPacket>::iterator i = m_list.begin();
i != m_list.end();
++i)
{
u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
dout_con<<s<<" ";
@ -186,13 +188,12 @@ bool ReliablePacketBuffer::empty() @@ -186,13 +188,12 @@ bool ReliablePacketBuffer::empty()
}
u32 ReliablePacketBuffer::size()
{
return m_list.getSize();
return m_list_size;
}
RPBSearchResult ReliablePacketBuffer::findPacket(u16 seqnum)
{
core::list<BufferedPacket>::Iterator i;
i = m_list.begin();
for(; i != m_list.end(); i++)
std::list<BufferedPacket>::iterator i = m_list.begin();
for(; i != m_list.end(); ++i)
{
u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
/*dout_con<<"findPacket(): finding seqnum="<<seqnum
@ -218,8 +219,8 @@ BufferedPacket ReliablePacketBuffer::popFirst() @@ -218,8 +219,8 @@ BufferedPacket ReliablePacketBuffer::popFirst()
if(empty())
throw NotFoundException("Buffer is empty");
BufferedPacket p = *m_list.begin();
core::list<BufferedPacket>::Iterator i = m_list.begin();
m_list.erase(i);
m_list.erase(m_list.begin());
--m_list_size;
return p;
}
BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum)
@ -231,6 +232,7 @@ BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum) @@ -231,6 +232,7 @@ BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum)
}
BufferedPacket p = *r;
m_list.erase(r);
--m_list_size;
return p;
}
void ReliablePacketBuffer::insert(BufferedPacket &p)
@ -240,6 +242,7 @@ void ReliablePacketBuffer::insert(BufferedPacket &p) @@ -240,6 +242,7 @@ void ReliablePacketBuffer::insert(BufferedPacket &p)
assert(type == TYPE_RELIABLE);
u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]);
++m_list_size;
// Find the right place for the packet and insert it there
// If list is empty, just add it
@ -250,12 +253,12 @@ void ReliablePacketBuffer::insert(BufferedPacket &p) @@ -250,12 +253,12 @@ void ReliablePacketBuffer::insert(BufferedPacket &p)
return;
}
// Otherwise find the right place
core::list<BufferedPacket>::Iterator i;
i = m_list.begin();
std::list<BufferedPacket>::iterator i = m_list.begin();
// Find the first packet in the list which has a higher seqnum
for(; i != m_list.end(); i++){
for(; i != m_list.end(); ++i){
u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
if(s == seqnum){
--m_list_size;
throw AlreadyExistsException("Same seqnum in list");
}
if(seqnum_higher(s, seqnum)){
@ -271,14 +274,14 @@ void ReliablePacketBuffer::insert(BufferedPacket &p) @@ -271,14 +274,14 @@ void ReliablePacketBuffer::insert(BufferedPacket &p)
return;
}
// Insert before i
m_list.insert_before(i, p);
m_list.insert(i, p);
}
void ReliablePacketBuffer::incrementTimeouts(float dtime)
{
core::list<BufferedPacket>::Iterator i;
i = m_list.begin();
for(; i != m_list.end(); i++){
for(std::list<BufferedPacket>::iterator i = m_list.begin();
i != m_list.end(); ++i)
{
i->time += dtime;
i->totaltime += dtime;
}
@ -286,9 +289,9 @@ void ReliablePacketBuffer::incrementTimeouts(float dtime) @@ -286,9 +289,9 @@ void ReliablePacketBuffer::incrementTimeouts(float dtime)
void ReliablePacketBuffer::resetTimedOuts(float timeout)
{
core::list<BufferedPacket>::Iterator i;
i = m_list.begin();
for(; i != m_list.end(); i++){
for(std::list<BufferedPacket>::iterator i = m_list.begin();
i != m_list.end(); ++i)
{
if(i->time >= timeout)
i->time = 0.0;
}
@ -296,21 +299,20 @@ void ReliablePacketBuffer::resetTimedOuts(float timeout) @@ -296,21 +299,20 @@ void ReliablePacketBuffer::resetTimedOuts(float timeout)
bool ReliablePacketBuffer::anyTotaltimeReached(float timeout)
{
core::list<BufferedPacket>::Iterator i;
i = m_list.begin();
for(; i != m_list.end(); i++){
for(std::list<BufferedPacket>::iterator i = m_list.begin();
i != m_list.end(); ++i)
{
if(i->totaltime >= timeout)
return true;
}
return false;
}
core::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout)
std::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout)
{
core::list<BufferedPacket> timed_outs;
core::list<BufferedPacket>::Iterator i;
i = m_list.begin();
for(; i != m_list.end(); i++)
std::list<BufferedPacket> timed_outs;
for(std::list<BufferedPacket>::iterator i = m_list.begin();
i != m_list.end(); ++i)
{
if(i->time >= timeout)
timed_outs.push_back(*i);
@ -324,11 +326,10 @@ core::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout) @@ -324,11 +326,10 @@ core::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout)
IncomingSplitBuffer::~IncomingSplitBuffer()
{
core::map<u16, IncomingSplitPacket*>::Iterator i;
i = m_buf.getIterator();
for(; i.atEnd() == false; i++)
for(std::map<u16, IncomingSplitPacket*>::iterator i = m_buf.begin();
i != m_buf.end(); ++i)
{
delete i.getNode()->getValue();
delete i->second;
}
}
/*
@ -346,7 +347,7 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) @@ -346,7 +347,7 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
u16 chunk_num = readU16(&p.data[BASE_HEADER_SIZE+5]);
// Add if doesn't exist
if(m_buf.find(seqnum) == NULL)
if(m_buf.find(seqnum) == m_buf.end())
{
IncomingSplitPacket *sp = new IncomingSplitPacket();
sp->chunk_count = chunk_count;
@ -369,7 +370,7 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) @@ -369,7 +370,7 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
// If chunk already exists, ignore it.
// Sometimes two identical packets may arrive when there is network
// lag and the server re-sends stuff.
if(sp->chunks.find(chunk_num) != NULL)
if(sp->chunks.find(chunk_num) != sp->chunks.end())
return SharedBuffer<u8>();
// Cut chunk data out of packet
@ -386,11 +387,10 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) @@ -386,11 +387,10 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
// Calculate total size
u32 totalsize = 0;
core::map<u16, SharedBuffer<u8> >::Iterator i;
i = sp->chunks.getIterator();
for(; i.atEnd() == false; i++)
for(std::map<u16, SharedBuffer<u8> >::iterator i = sp->chunks.begin();
i != sp->chunks.end(); ++i)
{
totalsize += i.getNode()->getValue().getSize();
totalsize += i->second.getSize();
}
SharedBuffer<u8> fulldata(totalsize);
@ -407,34 +407,32 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) @@ -407,34 +407,32 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
}
// Remove sp from buffer
m_buf.remove(seqnum);
m_buf.erase(seqnum);
delete sp;
return fulldata;
}
void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout)
{
core::list<u16> remove_queue;
core::map<u16, IncomingSplitPacket*>::Iterator i;
i = m_buf.getIterator();
for(; i.atEnd() == false; i++)
std::list<u16> remove_queue;
for(std::map<u16, IncomingSplitPacket*>::iterator i = m_buf.begin();
i != m_buf.end(); ++i)
{
IncomingSplitPacket *p = i.getNode()->getValue();
IncomingSplitPacket *p = i->second;
// Reliable ones are not removed by timeout
if(p->reliable == true)
continue;
p->time += dtime;
if(p->time >= timeout)
remove_queue.push_back(i.getNode()->getKey());
remove_queue.push_back(i->first);
}
core::list<u16>::Iterator j;
j = remove_queue.begin();
for(; j != remove_queue.end(); j++)
for(std::list<u16>::iterator j = remove_queue.begin();
j != remove_queue.end(); ++j)
{
dout_con<<"NOTE: Removing timed out unreliable split packet"
<<std::endl;
delete m_buf[*j];
m_buf.remove(*j);
m_buf.erase(*j);
}
}
@ -556,12 +554,11 @@ Connection::~Connection() @@ -556,12 +554,11 @@ Connection::~Connection()
{
stop();
// Delete peers
for(core::map<u16, Peer*>::Iterator
j = m_peers.getIterator();
j.atEnd() == false; j++)
for(std::map<u16, Peer*>::iterator
j = m_peers.begin();
j != m_peers.end(); ++j)
{
Peer *peer = j.getNode()->getValue();
delete peer;
delete j->second;
}
}
@ -591,7 +588,7 @@ void * Connection::Thread() @@ -591,7 +588,7 @@ void * Connection::Thread()
runTimeouts(dtime);
while(m_command_queue.size() != 0){
while(!m_command_queue.empty()){
ConnectionCommand c = m_command_queue.pop_front();
processCommand(c);
}
@ -648,18 +645,18 @@ void Connection::processCommand(ConnectionCommand &c) @@ -648,18 +645,18 @@ void Connection::processCommand(ConnectionCommand &c)
void Connection::send(float dtime)
{
for(core::map<u16, Peer*>::Iterator
j = m_peers.getIterator();
j.atEnd() == false; j++)
for(std::map<u16, Peer*>::iterator
j = m_peers.begin();
j != m_peers.end(); ++j)
{
Peer *peer = j.getNode()->getValue();
Peer *peer = j->second;
peer->m_sendtime_accu += dtime;
peer->m_num_sent = 0;
peer->m_max_num_sent = peer->m_sendtime_accu *
peer->m_max_packets_per_second;
}
Queue<OutgoingPacket> postponed_packets;
while(m_outgoing_queue.size() != 0){
while(!m_outgoing_queue.empty()){
OutgoingPacket packet = m_outgoing_queue.pop_front();
Peer *peer = getPeerNoEx(packet.peer_id);
if(!peer)
@ -674,14 +671,14 @@ void Connection::send(float dtime) @@ -674,14 +671,14 @@ void Connection::send(float dtime)
postponed_packets.push_back(packet);
}
}
while(postponed_packets.size() != 0){
while(!postponed_packets.empty()){
m_outgoing_queue.push_back(postponed_packets.pop_front());
}
for(core::map<u16, Peer*>::Iterator
j = m_peers.getIterator();
j.atEnd() == false; j++)
for(std::map<u16, Peer*>::iterator
j = m_peers.begin();
j != m_peers.end(); ++j)
{
Peer *peer = j.getNode()->getValue();
Peer *peer = j->second;
peer->m_sendtime_accu -= (float)peer->m_num_sent /
peer->m_max_packets_per_second;
if(peer->m_sendtime_accu > 10. / peer->m_max_packets_per_second)
@ -751,11 +748,11 @@ void Connection::receive() @@ -751,11 +748,11 @@ void Connection::receive()
Allow only entries that have has_sent_with_id==false.
*/
core::map<u16, Peer*>::Iterator j;
j = m_peers.getIterator();
for(; j.atEnd() == false; j++)
std::map<u16, Peer*>::iterator j;
j = m_peers.begin();
for(; j != m_peers.end(); ++j)
{