mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
Migrate to STL containers/algorithms.
This commit is contained in:
parent
e204bedf1d
commit
6a1670dbc3
20
src/chat.cpp
20
src/chat.cpp
@ -117,8 +117,8 @@ void ChatBuffer::deleteOldest(u32 count)
|
|||||||
--count;
|
--count;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_unformatted.erase(0, del_unformatted);
|
m_unformatted.erase(m_unformatted.begin(), m_unformatted.begin() + del_unformatted);
|
||||||
m_formatted.erase(0, del_formatted);
|
m_formatted.erase(m_formatted.begin(), m_formatted.begin() + del_formatted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatBuffer::deleteByAge(f32 maxAge)
|
void ChatBuffer::deleteByAge(f32 maxAge)
|
||||||
@ -232,10 +232,10 @@ void ChatBuffer::scrollTop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
||||||
core::array<ChatFormattedLine>& destination) const
|
std::vector<ChatFormattedLine>& destination) const
|
||||||
{
|
{
|
||||||
u32 num_added = 0;
|
u32 num_added = 0;
|
||||||
core::array<ChatFormattedFragment> next_frags;
|
std::vector<ChatFormattedFragment> next_frags;
|
||||||
ChatFormattedLine next_line;
|
ChatFormattedLine next_line;
|
||||||
ChatFormattedFragment temp_frag;
|
ChatFormattedFragment temp_frag;
|
||||||
u32 out_column = 0;
|
u32 out_column = 0;
|
||||||
@ -292,7 +292,7 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
|
|||||||
frag.column = out_column;
|
frag.column = out_column;
|
||||||
next_line.fragments.push_back(frag);
|
next_line.fragments.push_back(frag);
|
||||||
out_column += frag.text.size();
|
out_column += frag.text.size();
|
||||||
next_frags.erase(0, 1);
|
next_frags.erase(next_frags.begin());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -414,7 +414,7 @@ std::wstring ChatPrompt::submit()
|
|||||||
if (!line.empty())
|
if (!line.empty())
|
||||||
m_history.push_back(line);
|
m_history.push_back(line);
|
||||||
if (m_history.size() > m_history_limit)
|
if (m_history.size() > m_history_limit)
|
||||||
m_history.erase(0);
|
m_history.erase(m_history.begin());
|
||||||
m_history_index = m_history.size();
|
m_history_index = m_history.size();
|
||||||
m_view = 0;
|
m_view = 0;
|
||||||
m_cursor = 0;
|
m_cursor = 0;
|
||||||
@ -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:
|
// Two cases:
|
||||||
// (a) m_nick_completion_start == m_nick_completion_end == 0
|
// (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
|
|||||||
std::wstring prefix = m_line.substr(prefix_start, prefix_end - prefix_start);
|
std::wstring prefix = m_line.substr(prefix_start, prefix_end - prefix_start);
|
||||||
|
|
||||||
// find all names that start with the selected prefix
|
// find all names that start with the selected prefix
|
||||||
core::array<std::wstring> completions;
|
std::vector<std::wstring> completions;
|
||||||
for (core::list<std::wstring>::ConstIterator
|
for (std::list<std::wstring>::const_iterator
|
||||||
i = names.begin();
|
i = names.begin();
|
||||||
i != names.end(); i++)
|
i != names.end(); ++i)
|
||||||
{
|
{
|
||||||
if (str_starts_with(*i, prefix, true))
|
if (str_starts_with(*i, prefix, true))
|
||||||
{
|
{
|
||||||
|
14
src/chat.h
14
src/chat.h
@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "irrlichttypes_bloated.h"
|
#include "irrlichttypes_bloated.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
// Chat console related classes, only used by the client
|
// Chat console related classes, only used by the client
|
||||||
|
|
||||||
@ -55,7 +57,7 @@ struct ChatFormattedFragment
|
|||||||
struct ChatFormattedLine
|
struct ChatFormattedLine
|
||||||
{
|
{
|
||||||
// Array of text fragments
|
// Array of text fragments
|
||||||
core::array<ChatFormattedFragment> fragments;
|
std::vector<ChatFormattedFragment> fragments;
|
||||||
// true if first line of one formatted ChatLine
|
// true if first line of one formatted ChatLine
|
||||||
bool first;
|
bool first;
|
||||||
};
|
};
|
||||||
@ -110,7 +112,7 @@ public:
|
|||||||
// Appends the formatted lines to the destination array and
|
// Appends the formatted lines to the destination array and
|
||||||
// returns the number of formatted lines.
|
// returns the number of formatted lines.
|
||||||
u32 formatChatLine(const ChatLine& line, u32 cols,
|
u32 formatChatLine(const ChatLine& line, u32 cols,
|
||||||
core::array<ChatFormattedLine>& destination) const;
|
std::vector<ChatFormattedLine>& destination) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
s32 getTopScrollPos() const;
|
s32 getTopScrollPos() const;
|
||||||
@ -120,7 +122,7 @@ private:
|
|||||||
// Scrollback size
|
// Scrollback size
|
||||||
u32 m_scrollback;
|
u32 m_scrollback;
|
||||||
// Array of unformatted chat lines
|
// Array of unformatted chat lines
|
||||||
core::array<ChatLine> m_unformatted;
|
std::vector<ChatLine> m_unformatted;
|
||||||
|
|
||||||
// Number of character columns in console
|
// Number of character columns in console
|
||||||
u32 m_cols;
|
u32 m_cols;
|
||||||
@ -129,7 +131,7 @@ private:
|
|||||||
// Scroll position (console's top line index into m_formatted)
|
// Scroll position (console's top line index into m_formatted)
|
||||||
s32 m_scroll;
|
s32 m_scroll;
|
||||||
// Array of formatted lines
|
// Array of formatted lines
|
||||||
core::array<ChatFormattedLine> m_formatted;
|
std::vector<ChatFormattedLine> m_formatted;
|
||||||
// Empty formatted line, for error returns
|
// Empty formatted line, for error returns
|
||||||
ChatFormattedLine m_empty_formatted_line;
|
ChatFormattedLine m_empty_formatted_line;
|
||||||
};
|
};
|
||||||
@ -158,7 +160,7 @@ public:
|
|||||||
void historyNext();
|
void historyNext();
|
||||||
|
|
||||||
// Nick completion
|
// 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
|
// Update console size and reformat the visible portion of the prompt
|
||||||
void reformat(u32 cols);
|
void reformat(u32 cols);
|
||||||
@ -209,7 +211,7 @@ private:
|
|||||||
// Currently edited line
|
// Currently edited line
|
||||||
std::wstring m_line;
|
std::wstring m_line;
|
||||||
// History buffer
|
// History buffer
|
||||||
core::array<std::wstring> m_history;
|
std::vector<std::wstring> m_history;
|
||||||
// History index (0 <= m_history_index <= m_history.size())
|
// History index (0 <= m_history_index <= m_history.size())
|
||||||
u32 m_history_index;
|
u32 m_history_index;
|
||||||
// Maximum number of history entries
|
// Maximum number of history entries
|
||||||
|
102
src/client.cpp
102
src/client.cpp
@ -232,8 +232,8 @@ void * MediaFetchThread::Thread()
|
|||||||
#if USE_CURL
|
#if USE_CURL
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
for (core::list<MediaRequest>::Iterator i = m_file_requests.begin();
|
for (std::list<MediaRequest>::iterator i = m_file_requests.begin();
|
||||||
i != m_file_requests.end(); i++) {
|
i != m_file_requests.end(); ++i) {
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
assert(curl);
|
assert(curl);
|
||||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||||
@ -360,8 +360,8 @@ Client::~Client()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (core::list<MediaFetchThread*>::Iterator i = m_media_fetch_threads.begin();
|
for (std::list<MediaFetchThread*>::iterator i = m_media_fetch_threads.begin();
|
||||||
i != m_media_fetch_threads.end(); i++)
|
i != m_media_fetch_threads.end(); ++i)
|
||||||
delete *i;
|
delete *i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,7 +585,7 @@ void Client::step(float dtime)
|
|||||||
if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime))
|
if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime))
|
||||||
{
|
{
|
||||||
ScopeProfiler sp(g_profiler, "Client: map timer and unload");
|
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,
|
m_env.getMap().timerUpdate(map_timer_and_unload_dtime,
|
||||||
g_settings->getFloat("client_unload_unused_data_timeout"),
|
g_settings->getFloat("client_unload_unused_data_timeout"),
|
||||||
&deleted_blocks);
|
&deleted_blocks);
|
||||||
@ -599,8 +599,8 @@ void Client::step(float dtime)
|
|||||||
NOTE: This loop is intentionally iterated the way it is.
|
NOTE: This loop is intentionally iterated the way it is.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
core::list<v3s16>::Iterator i = deleted_blocks.begin();
|
std::list<v3s16>::iterator i = deleted_blocks.begin();
|
||||||
core::list<v3s16> sendlist;
|
std::list<v3s16> sendlist;
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
if(sendlist.size() == 255 || i == deleted_blocks.end())
|
if(sendlist.size() == 255 || i == deleted_blocks.end())
|
||||||
@ -619,9 +619,9 @@ void Client::step(float dtime)
|
|||||||
writeU16(&reply[0], TOSERVER_DELETEDBLOCKS);
|
writeU16(&reply[0], TOSERVER_DELETEDBLOCKS);
|
||||||
reply[2] = sendlist.size();
|
reply[2] = sendlist.size();
|
||||||
u32 k = 0;
|
u32 k = 0;
|
||||||
for(core::list<v3s16>::Iterator
|
for(std::list<v3s16>::iterator
|
||||||
j = sendlist.begin();
|
j = sendlist.begin();
|
||||||
j != sendlist.end(); j++)
|
j != sendlist.end(); ++j)
|
||||||
{
|
{
|
||||||
writeV3S16(&reply[2+1+6*k], *j);
|
writeV3S16(&reply[2+1+6*k], *j);
|
||||||
k++;
|
k++;
|
||||||
@ -635,7 +635,7 @@ void Client::step(float dtime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendlist.push_back(*i);
|
sendlist.push_back(*i);
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,7 +727,7 @@ void Client::step(float dtime)
|
|||||||
<<std::endl;*/
|
<<std::endl;*/
|
||||||
|
|
||||||
int num_processed_meshes = 0;
|
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++;
|
num_processed_meshes++;
|
||||||
MeshUpdateResult r = m_mesh_update_thread.m_queue_out.pop_front();
|
MeshUpdateResult r = m_mesh_update_thread.m_queue_out.pop_front();
|
||||||
@ -779,10 +779,10 @@ void Client::step(float dtime)
|
|||||||
*/
|
*/
|
||||||
if (m_media_receive_started) {
|
if (m_media_receive_started) {
|
||||||
bool all_stopped = true;
|
bool all_stopped = true;
|
||||||
for (core::list<MediaFetchThread*>::Iterator thread = m_media_fetch_threads.begin();
|
for (std::list<MediaFetchThread*>::iterator thread = m_media_fetch_threads.begin();
|
||||||
thread != m_media_fetch_threads.end(); thread++) {
|
thread != m_media_fetch_threads.end(); ++thread) {
|
||||||
all_stopped &= !(*thread)->IsRunning();
|
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();
|
std::pair <std::string, std::string> out = (*thread)->m_file_data.pop_front();
|
||||||
++m_media_received_count;
|
++m_media_received_count;
|
||||||
|
|
||||||
@ -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);
|
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 "
|
errorstream<<"The server sent a file that has not "
|
||||||
<<"been announced."<<std::endl;
|
<<"been announced."<<std::endl;
|
||||||
else
|
else
|
||||||
@ -814,11 +814,11 @@ void Client::step(float dtime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (all_stopped) {
|
if (all_stopped) {
|
||||||
core::list<MediaRequest> fetch_failed;
|
std::list<MediaRequest> fetch_failed;
|
||||||
for (core::list<MediaFetchThread*>::Iterator thread = m_media_fetch_threads.begin();
|
for (std::list<MediaFetchThread*>::iterator thread = m_media_fetch_threads.begin();
|
||||||
thread != m_media_fetch_threads.end(); thread++) {
|
thread != m_media_fetch_threads.end(); ++thread) {
|
||||||
for (core::list<MediaRequest>::Iterator request = (*thread)->m_failed.begin();
|
for (std::list<MediaRequest>::iterator request = (*thread)->m_failed.begin();
|
||||||
request != (*thread)->m_failed.end(); request++)
|
request != (*thread)->m_failed.end(); ++request)
|
||||||
fetch_failed.push_back(*request);
|
fetch_failed.push_back(*request);
|
||||||
(*thread)->m_failed.clear();
|
(*thread)->m_failed.clear();
|
||||||
}
|
}
|
||||||
@ -1015,14 +1015,14 @@ void Client::deletingPeer(con::Peer *peer, bool timeout)
|
|||||||
string name
|
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);
|
std::ostringstream os(std::ios_base::binary);
|
||||||
writeU16(os, TOSERVER_REQUEST_MEDIA);
|
writeU16(os, TOSERVER_REQUEST_MEDIA);
|
||||||
writeU16(os, file_requests.size());
|
writeU16(os, file_requests.size());
|
||||||
|
|
||||||
for(core::list<MediaRequest>::ConstIterator i = file_requests.begin();
|
for(std::list<MediaRequest>::const_iterator i = file_requests.begin();
|
||||||
i != file_requests.end(); i++) {
|
i != file_requests.end(); ++i) {
|
||||||
os<<serializeString(i->name);
|
os<<serializeString(i->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1622,7 +1622,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||||||
infostream<<"Client: Received media announcement: packet size: "
|
infostream<<"Client: Received media announcement: packet size: "
|
||||||
<<datasize<<std::endl;
|
<<datasize<<std::endl;
|
||||||
|
|
||||||
core::list<MediaRequest> file_requests;
|
std::list<MediaRequest> file_requests;
|
||||||
|
|
||||||
for(int i=0; i<num_files; i++)
|
for(int i=0; i<num_files; i++)
|
||||||
{
|
{
|
||||||
@ -1641,7 +1641,7 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||||||
std::string sha1_hex = hex_encode(sha1_raw);
|
std::string sha1_hex = hex_encode(sha1_raw);
|
||||||
std::ostringstream tmp_os(std::ios_base::binary);
|
std::ostringstream tmp_os(std::ios_base::binary);
|
||||||
bool found_in_cache = m_media_cache.load_sha1(sha1_raw, tmp_os);
|
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, try to load it from there
|
||||||
if(found_in_cache)
|
if(found_in_cache)
|
||||||
@ -1677,16 +1677,16 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
|
|||||||
request_media(file_requests);
|
request_media(file_requests);
|
||||||
} else {
|
} else {
|
||||||
#if USE_CURL
|
#if USE_CURL
|
||||||
core::list<MediaFetchThread*>::Iterator cur = m_media_fetch_threads.begin();
|
std::list<MediaFetchThread*>::iterator cur = m_media_fetch_threads.begin();
|
||||||
for(core::list<MediaRequest>::Iterator i = file_requests.begin();
|
for(std::list<MediaRequest>::iterator i = file_requests.begin();
|
||||||
i != file_requests.end(); i++) {
|
i != file_requests.end(); ++i) {
|
||||||
(*cur)->m_file_requests.push_back(*i);
|
(*cur)->m_file_requests.push_back(*i);
|
||||||
cur++;
|
cur++;
|
||||||
if (cur == m_media_fetch_threads.end())
|
if (cur == m_media_fetch_threads.end())
|
||||||
cur = m_media_fetch_threads.begin();
|
cur = m_media_fetch_threads.begin();
|
||||||
}
|
}
|
||||||
for (core::list<MediaFetchThread*>::Iterator i = m_media_fetch_threads.begin();
|
for (std::list<MediaFetchThread*>::iterator i = m_media_fetch_threads.begin();
|
||||||
i != m_media_fetch_threads.end(); i++) {
|
i != m_media_fetch_threads.end(); ++i) {
|
||||||
(*i)->m_remote_url = remote_media;
|
(*i)->m_remote_url = remote_media;
|
||||||
(*i)->Start();
|
(*i)->Start();
|
||||||
}
|
}
|
||||||
@ -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);
|
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 "
|
errorstream<<"The server sent a file that has not "
|
||||||
<<"been announced."<<std::endl;
|
<<"been announced."<<std::endl;
|
||||||
else
|
else
|
||||||
@ -2231,7 +2231,7 @@ void Client::sendPlayerItem(u16 item)
|
|||||||
|
|
||||||
void Client::removeNode(v3s16 p)
|
void Client::removeNode(v3s16 p)
|
||||||
{
|
{
|
||||||
core::map<v3s16, MapBlock*> modified_blocks;
|
std::map<v3s16, MapBlock*> modified_blocks;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -2245,12 +2245,11 @@ void Client::removeNode(v3s16 p)
|
|||||||
// add urgent task to update the modified node
|
// add urgent task to update the modified node
|
||||||
addUpdateMeshTaskForNode(p, false, true);
|
addUpdateMeshTaskForNode(p, false, true);
|
||||||
|
|
||||||
for(core::map<v3s16, MapBlock * >::Iterator
|
for(std::map<v3s16, MapBlock * >::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
addUpdateMeshTaskWithEdge(i->first);
|
||||||
addUpdateMeshTaskWithEdge(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2258,7 +2257,7 @@ void Client::addNode(v3s16 p, MapNode n)
|
|||||||
{
|
{
|
||||||
TimeTaker timer1("Client::addNode()");
|
TimeTaker timer1("Client::addNode()");
|
||||||
|
|
||||||
core::map<v3s16, MapBlock*> modified_blocks;
|
std::map<v3s16, MapBlock*> modified_blocks;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -2268,12 +2267,11 @@ void Client::addNode(v3s16 p, MapNode n)
|
|||||||
catch(InvalidPositionException &e)
|
catch(InvalidPositionException &e)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
for(core::map<v3s16, MapBlock * >::Iterator
|
for(std::map<v3s16, MapBlock * >::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
addUpdateMeshTaskWithEdge(i->first);
|
||||||
addUpdateMeshTaskWithEdge(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2373,7 +2371,7 @@ ClientActiveObject * Client::getSelectedActiveObject(
|
|||||||
core::line3d<f32> shootline_on_map
|
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);
|
m_env.getActiveObjects(from_pos_f_on_map, max_d, objects);
|
||||||
|
|
||||||
@ -2381,7 +2379,7 @@ ClientActiveObject * Client::getSelectedActiveObject(
|
|||||||
|
|
||||||
// Sort them.
|
// Sort them.
|
||||||
// After this, the closest object is the first in the array.
|
// 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++)
|
for(u32 i=0; i<objects.size(); i++)
|
||||||
{
|
{
|
||||||
@ -2420,13 +2418,13 @@ void Client::printDebugInfo(std::ostream &os)
|
|||||||
<<std::endl;*/
|
<<std::endl;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<std::wstring> Client::getConnectedPlayerNames()
|
std::list<std::wstring> Client::getConnectedPlayerNames()
|
||||||
{
|
{
|
||||||
core::list<Player*> players = m_env.getPlayers(true);
|
std::list<Player*> players = m_env.getPlayers(true);
|
||||||
core::list<std::wstring> playerNames;
|
std::list<std::wstring> playerNames;
|
||||||
for(core::list<Player*>::Iterator
|
for(std::list<Player*>::iterator
|
||||||
i = players.begin();
|
i = players.begin();
|
||||||
i != players.end(); i++)
|
i != players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
playerNames.push_back(narrow_to_wide(player->getName()));
|
playerNames.push_back(narrow_to_wide(player->getName()));
|
||||||
|
15
src/client.h
15
src/client.h
@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "particles.h"
|
#include "particles.h"
|
||||||
#include "util/pointedthing.h"
|
#include "util/pointedthing.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
struct MeshMakeData;
|
struct MeshMakeData;
|
||||||
class MapBlockMesh;
|
class MapBlockMesh;
|
||||||
@ -142,9 +143,9 @@ public:
|
|||||||
|
|
||||||
void * Thread();
|
void * Thread();
|
||||||
|
|
||||||
core::list<MediaRequest> m_file_requests;
|
std::list<MediaRequest> m_file_requests;
|
||||||
MutexedQueue<std::pair<std::string, std::string> > m_file_data;
|
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;
|
std::string m_remote_url;
|
||||||
IGameDef *m_gamedef;
|
IGameDef *m_gamedef;
|
||||||
};
|
};
|
||||||
@ -282,7 +283,7 @@ public:
|
|||||||
// Prints a line or two of info
|
// Prints a line or two of info
|
||||||
void printDebugInfo(std::ostream &os);
|
void printDebugInfo(std::ostream &os);
|
||||||
|
|
||||||
core::list<std::wstring> getConnectedPlayerNames();
|
std::list<std::wstring> getConnectedPlayerNames();
|
||||||
|
|
||||||
float getAnimationTime();
|
float getAnimationTime();
|
||||||
|
|
||||||
@ -347,7 +348,7 @@ private:
|
|||||||
// Insert a media file appropriately into the appropriate manager
|
// Insert a media file appropriately into the appropriate manager
|
||||||
bool loadMedia(const std::string &data, const std::string &filename);
|
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
|
// Virtual methods from con::PeerHandler
|
||||||
void peerAdded(con::Peer *peer);
|
void peerAdded(con::Peer *peer);
|
||||||
@ -377,7 +378,7 @@ private:
|
|||||||
MtEventManager *m_event;
|
MtEventManager *m_event;
|
||||||
|
|
||||||
MeshUpdateThread m_mesh_update_thread;
|
MeshUpdateThread m_mesh_update_thread;
|
||||||
core::list<MediaFetchThread*> m_media_fetch_threads;
|
std::list<MediaFetchThread*> m_media_fetch_threads;
|
||||||
ClientEnvironment m_env;
|
ClientEnvironment m_env;
|
||||||
con::Connection m_con;
|
con::Connection m_con;
|
||||||
IrrlichtDevice *m_device;
|
IrrlichtDevice *m_device;
|
||||||
@ -387,7 +388,7 @@ private:
|
|||||||
bool m_inventory_updated;
|
bool m_inventory_updated;
|
||||||
Inventory *m_inventory_from_server;
|
Inventory *m_inventory_from_server;
|
||||||
float m_inventory_from_server_age;
|
float m_inventory_from_server_age;
|
||||||
core::map<v3s16, bool> m_active_blocks;
|
std::set<v3s16> m_active_blocks;
|
||||||
PacketCounter m_packetcounter;
|
PacketCounter m_packetcounter;
|
||||||
// Block mesh animation parameters
|
// Block mesh animation parameters
|
||||||
float m_animation_time;
|
float m_animation_time;
|
||||||
@ -405,7 +406,7 @@ private:
|
|||||||
Queue<ClientEvent> m_client_event_queue;
|
Queue<ClientEvent> m_client_event_queue;
|
||||||
FileCache m_media_cache;
|
FileCache m_media_cache;
|
||||||
// Mapping from media file name to SHA1 checksum
|
// 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;
|
bool m_media_receive_started;
|
||||||
u32 m_media_count;
|
u32 m_media_count;
|
||||||
u32 m_media_received_count;
|
u32 m_media_received_count;
|
||||||
|
@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "profiler.h"
|
#include "profiler.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "util/mathconstants.h"
|
#include "util/mathconstants.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ MapSector * ClientMap::emergeSector(v2s16 p2d)
|
|||||||
|
|
||||||
{
|
{
|
||||||
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
|
//JMutexAutoLock lock(m_sector_mutex); // Bulk comment-out
|
||||||
m_sectors.insert(p2d, sector);
|
m_sectors[p2d] = sector;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sector;
|
return sector;
|
||||||
@ -164,11 +165,11 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
|
|||||||
|
|
||||||
INodeDefManager *nodemgr = m_gamedef->ndef();
|
INodeDefManager *nodemgr = m_gamedef->ndef();
|
||||||
|
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = m_drawlist.getIterator();
|
i = m_drawlist.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_drawlist.end(); ++i)
|
||||||
{
|
{
|
||||||
MapBlock *block = i.getNode()->getValue();
|
MapBlock *block = i->second;
|
||||||
block->refDrop();
|
block->refDrop();
|
||||||
}
|
}
|
||||||
m_drawlist.clear();
|
m_drawlist.clear();
|
||||||
@ -215,11 +216,11 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
|
|||||||
// Blocks from which stuff was actually drawn
|
// Blocks from which stuff was actually drawn
|
||||||
//u32 blocks_without_stuff = 0;
|
//u32 blocks_without_stuff = 0;
|
||||||
|
|
||||||
for(core::map<v2s16, MapSector*>::Iterator
|
for(std::map<v2s16, MapSector*>::iterator
|
||||||
si = m_sectors.getIterator();
|
si = m_sectors.begin();
|
||||||
si.atEnd() == false; si++)
|
si != m_sectors.end(); ++si)
|
||||||
{
|
{
|
||||||
MapSector *sector = si.getNode()->getValue();
|
MapSector *sector = si->second;
|
||||||
v2s16 sp = sector->getPos();
|
v2s16 sp = sector->getPos();
|
||||||
|
|
||||||
if(m_control.range_all == false)
|
if(m_control.range_all == false)
|
||||||
@ -231,7 +232,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list< MapBlock * > sectorblocks;
|
std::list< MapBlock * > sectorblocks;
|
||||||
sector->getBlocks(sectorblocks);
|
sector->getBlocks(sectorblocks);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -240,7 +241,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
|
|||||||
|
|
||||||
u32 sector_blocks_drawn = 0;
|
u32 sector_blocks_drawn = 0;
|
||||||
|
|
||||||
core::list< MapBlock * >::Iterator i;
|
std::list< MapBlock * >::iterator i;
|
||||||
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
|
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
|
||||||
{
|
{
|
||||||
MapBlock *block = *i;
|
MapBlock *block = *i;
|
||||||
@ -350,7 +351,7 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
|
|||||||
} // foreach sectorblocks
|
} // foreach sectorblocks
|
||||||
|
|
||||||
if(sector_blocks_drawn != 0)
|
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;
|
m_control.blocks_would_have_drawn = blocks_would_have_drawn;
|
||||||
@ -368,12 +369,12 @@ void ClientMap::updateDrawList(video::IVideoDriver* driver)
|
|||||||
struct MeshBufList
|
struct MeshBufList
|
||||||
{
|
{
|
||||||
video::SMaterial m;
|
video::SMaterial m;
|
||||||
core::list<scene::IMeshBuffer*> bufs;
|
std::list<scene::IMeshBuffer*> bufs;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MeshBufListList
|
struct MeshBufListList
|
||||||
{
|
{
|
||||||
core::list<MeshBufList> lists;
|
std::list<MeshBufList> lists;
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
@ -382,8 +383,8 @@ struct MeshBufListList
|
|||||||
|
|
||||||
void add(scene::IMeshBuffer *buf)
|
void add(scene::IMeshBuffer *buf)
|
||||||
{
|
{
|
||||||
for(core::list<MeshBufList>::Iterator i = lists.begin();
|
for(std::list<MeshBufList>::iterator i = lists.begin();
|
||||||
i != lists.end(); i++){
|
i != lists.end(); ++i){
|
||||||
MeshBufList &l = *i;
|
MeshBufList &l = *i;
|
||||||
if(l.m == buf->getMaterial()){
|
if(l.m == buf->getMaterial()){
|
||||||
l.bufs.push_back(buf);
|
l.bufs.push_back(buf);
|
||||||
@ -487,11 +488,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||||||
|
|
||||||
MeshBufListList drawbufs;
|
MeshBufListList drawbufs;
|
||||||
|
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = m_drawlist.getIterator();
|
i = m_drawlist.begin();
|
||||||
i.atEnd() == false; i++)
|
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 the mesh of the block happened to get deleted, ignore it
|
||||||
if(block->mesh == NULL)
|
if(block->mesh == NULL)
|
||||||
@ -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;
|
int timecheck_counter = 0;
|
||||||
for(core::list<MeshBufList>::Iterator i = lists.begin();
|
for(std::list<MeshBufList>::iterator i = lists.begin();
|
||||||
i != lists.end(); i++)
|
i != lists.end(); ++i)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
timecheck_counter++;
|
timecheck_counter++;
|
||||||
@ -595,8 +596,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
|||||||
|
|
||||||
driver->setMaterial(list.m);
|
driver->setMaterial(list.m);
|
||||||
|
|
||||||
for(core::list<scene::IMeshBuffer*>::Iterator j = list.bufs.begin();
|
for(std::list<scene::IMeshBuffer*>::iterator j = list.bufs.begin();
|
||||||
j != list.bufs.end(); j++)
|
j != list.bufs.end(); ++j)
|
||||||
{
|
{
|
||||||
scene::IMeshBuffer *buf = *j;
|
scene::IMeshBuffer *buf = *j;
|
||||||
driver->drawMeshBuffer(buf);
|
driver->drawMeshBuffer(buf);
|
||||||
@ -769,7 +770,7 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
|
|||||||
float sunlight_min_d = max_d*0.8;
|
float sunlight_min_d = max_d*0.8;
|
||||||
if(sunlight_min_d > 35*BS)
|
if(sunlight_min_d > 35*BS)
|
||||||
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++){
|
for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
|
||||||
v3f z_dir = z_directions[i];
|
v3f z_dir = z_directions[i];
|
||||||
z_dir.normalize();
|
z_dir.normalize();
|
||||||
@ -798,7 +799,7 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
|
|||||||
}
|
}
|
||||||
int brightness_sum = 0;
|
int brightness_sum = 0;
|
||||||
int brightness_count = 0;
|
int brightness_count = 0;
|
||||||
values.sort();
|
std::sort(values.begin(), values.end());
|
||||||
u32 num_values_to_use = values.size();
|
u32 num_values_to_use = values.size();
|
||||||
if(num_values_to_use >= 10)
|
if(num_values_to_use >= 10)
|
||||||
num_values_to_use -= num_values_to_use/2;
|
num_values_to_use -= num_values_to_use/2;
|
||||||
|
@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "irrlichttypes_extrabloated.h"
|
#include "irrlichttypes_extrabloated.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
struct MapDrawControl
|
struct MapDrawControl
|
||||||
{
|
{
|
||||||
@ -128,7 +130,7 @@ public:
|
|||||||
// Check if sector was drawn on last render()
|
// Check if sector was drawn on last render()
|
||||||
bool sectorWasDrawn(v2s16 p)
|
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:
|
private:
|
||||||
@ -143,9 +145,9 @@ private:
|
|||||||
f32 m_camera_fov;
|
f32 m_camera_fov;
|
||||||
JMutex m_camera_mutex;
|
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
|
#endif
|
||||||
|
@ -43,9 +43,9 @@ ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef,
|
|||||||
ClientEnvironment *env)
|
ClientEnvironment *env)
|
||||||
{
|
{
|
||||||
// Find factory function
|
// Find factory function
|
||||||
core::map<u16, Factory>::Node *n;
|
std::map<u16, Factory>::iterator n;
|
||||||
n = m_types.find(type);
|
n = m_types.find(type);
|
||||||
if(n == NULL)
|
if(n == m_types.end())
|
||||||
{
|
{
|
||||||
// If factory is not found, just return.
|
// If factory is not found, just return.
|
||||||
dstream<<"WARNING: ClientActiveObject: No factory for type="
|
dstream<<"WARNING: ClientActiveObject: No factory for type="
|
||||||
@ -53,18 +53,18 @@ ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Factory f = n->getValue();
|
Factory f = n->second;
|
||||||
ClientActiveObject *object = (*f)(gamedef, env);
|
ClientActiveObject *object = (*f)(gamedef, env);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientActiveObject::registerType(u16 type, Factory f)
|
void ClientActiveObject::registerType(u16 type, Factory f)
|
||||||
{
|
{
|
||||||
core::map<u16, Factory>::Node *n;
|
std::map<u16, Factory>::iterator n;
|
||||||
n = m_types.find(type);
|
n = m_types.find(type);
|
||||||
if(n)
|
if(n != m_types.end())
|
||||||
return;
|
return;
|
||||||
m_types.insert(type, f);
|
m_types[type] = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "irrlichttypes_extrabloated.h"
|
#include "irrlichttypes_extrabloated.h"
|
||||||
#include "activeobject.h"
|
#include "activeobject.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ protected:
|
|||||||
ClientEnvironment *m_env;
|
ClientEnvironment *m_env;
|
||||||
private:
|
private:
|
||||||
// Used for creating objects based on type
|
// Used for creating objects based on type
|
||||||
static core::map<u16, Factory> m_types;
|
static std::map<u16, Factory> m_types;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DistanceSortedActiveObject
|
struct DistanceSortedActiveObject
|
||||||
@ -110,7 +111,7 @@ struct DistanceSortedActiveObject
|
|||||||
d = a_d;
|
d = a_d;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator < (DistanceSortedActiveObject &other)
|
bool operator < (const DistanceSortedActiveObject &other) const
|
||||||
{
|
{
|
||||||
return d < other.d;
|
return d < other.d;
|
||||||
}
|
}
|
||||||
|
@ -76,19 +76,20 @@ SharedBuffer<u8> makeOriginalPacket(
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<SharedBuffer<u8> > makeSplitPacket(
|
std::list<SharedBuffer<u8> > makeSplitPacket(
|
||||||
SharedBuffer<u8> data,
|
SharedBuffer<u8> data,
|
||||||
u32 chunksize_max,
|
u32 chunksize_max,
|
||||||
u16 seqnum)
|
u16 seqnum)
|
||||||
{
|
{
|
||||||
// Chunk packets, containing the TYPE_SPLIT header
|
// Chunk packets, containing the TYPE_SPLIT header
|
||||||
core::list<SharedBuffer<u8> > chunks;
|
std::list<SharedBuffer<u8> > chunks;
|
||||||
|
|
||||||
u32 chunk_header_size = 7;
|
u32 chunk_header_size = 7;
|
||||||
u32 maximum_data_size = chunksize_max - chunk_header_size;
|
u32 maximum_data_size = chunksize_max - chunk_header_size;
|
||||||
u32 start = 0;
|
u32 start = 0;
|
||||||
u32 end = 0;
|
u32 end = 0;
|
||||||
u32 chunk_num = 0;
|
u32 chunk_num = 0;
|
||||||
|
u16 chunk_count = 0;
|
||||||
do{
|
do{
|
||||||
end = start + maximum_data_size - 1;
|
end = start + maximum_data_size - 1;
|
||||||
if(end > data.getSize() - 1)
|
if(end > data.getSize() - 1)
|
||||||
@ -106,16 +107,15 @@ core::list<SharedBuffer<u8> > makeSplitPacket(
|
|||||||
memcpy(&chunk[chunk_header_size], &data[start], payload_size);
|
memcpy(&chunk[chunk_header_size], &data[start], payload_size);
|
||||||
|
|
||||||
chunks.push_back(chunk);
|
chunks.push_back(chunk);
|
||||||
|
chunk_count++;
|
||||||
|
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
chunk_num++;
|
chunk_num++;
|
||||||
}
|
}
|
||||||
while(end != data.getSize() - 1);
|
while(end != data.getSize() - 1);
|
||||||
|
|
||||||
u16 chunk_count = chunks.getSize();
|
for(std::list<SharedBuffer<u8> >::iterator i = chunks.begin();
|
||||||
|
i != chunks.end(); ++i)
|
||||||
core::list<SharedBuffer<u8> >::Iterator i = chunks.begin();
|
|
||||||
for(; i != chunks.end(); i++)
|
|
||||||
{
|
{
|
||||||
// Write chunk_count
|
// Write chunk_count
|
||||||
writeU16(&((*i)[3]), chunk_count);
|
writeU16(&((*i)[3]), chunk_count);
|
||||||
@ -124,13 +124,13 @@ core::list<SharedBuffer<u8> > makeSplitPacket(
|
|||||||
return chunks;
|
return chunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<SharedBuffer<u8> > makeAutoSplitPacket(
|
std::list<SharedBuffer<u8> > makeAutoSplitPacket(
|
||||||
SharedBuffer<u8> data,
|
SharedBuffer<u8> data,
|
||||||
u32 chunksize_max,
|
u32 chunksize_max,
|
||||||
u16 &split_seqnum)
|
u16 &split_seqnum)
|
||||||
{
|
{
|
||||||
u32 original_header_size = 1;
|
u32 original_header_size = 1;
|
||||||
core::list<SharedBuffer<u8> > list;
|
std::list<SharedBuffer<u8> > list;
|
||||||
if(data.getSize() + original_header_size > chunksize_max)
|
if(data.getSize() + original_header_size > chunksize_max)
|
||||||
{
|
{
|
||||||
list = makeSplitPacket(data, chunksize_max, split_seqnum);
|
list = makeSplitPacket(data, chunksize_max, split_seqnum);
|
||||||
@ -170,11 +170,13 @@ SharedBuffer<u8> makeReliablePacket(
|
|||||||
ReliablePacketBuffer
|
ReliablePacketBuffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
ReliablePacketBuffer::ReliablePacketBuffer(): m_list_size(0) {}
|
||||||
|
|
||||||
void ReliablePacketBuffer::print()
|
void ReliablePacketBuffer::print()
|
||||||
{
|
{
|
||||||
core::list<BufferedPacket>::Iterator i;
|
for(std::list<BufferedPacket>::iterator i = m_list.begin();
|
||||||
i = m_list.begin();
|
i != m_list.end();
|
||||||
for(; i != m_list.end(); i++)
|
++i)
|
||||||
{
|
{
|
||||||
u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
|
u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
|
||||||
dout_con<<s<<" ";
|
dout_con<<s<<" ";
|
||||||
@ -186,13 +188,12 @@ bool ReliablePacketBuffer::empty()
|
|||||||
}
|
}
|
||||||
u32 ReliablePacketBuffer::size()
|
u32 ReliablePacketBuffer::size()
|
||||||
{
|
{
|
||||||
return m_list.getSize();
|
return m_list_size;
|
||||||
}
|
}
|
||||||
RPBSearchResult ReliablePacketBuffer::findPacket(u16 seqnum)
|
RPBSearchResult ReliablePacketBuffer::findPacket(u16 seqnum)
|
||||||
{
|
{
|
||||||
core::list<BufferedPacket>::Iterator i;
|
std::list<BufferedPacket>::iterator i = m_list.begin();
|
||||||
i = m_list.begin();
|
for(; i != m_list.end(); ++i)
|
||||||
for(; i != m_list.end(); i++)
|
|
||||||
{
|
{
|
||||||
u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
|
u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
|
||||||
/*dout_con<<"findPacket(): finding seqnum="<<seqnum
|
/*dout_con<<"findPacket(): finding seqnum="<<seqnum
|
||||||
@ -218,8 +219,8 @@ BufferedPacket ReliablePacketBuffer::popFirst()
|
|||||||
if(empty())
|
if(empty())
|
||||||
throw NotFoundException("Buffer is empty");
|
throw NotFoundException("Buffer is empty");
|
||||||
BufferedPacket p = *m_list.begin();
|
BufferedPacket p = *m_list.begin();
|
||||||
core::list<BufferedPacket>::Iterator i = m_list.begin();
|
m_list.erase(m_list.begin());
|
||||||
m_list.erase(i);
|
--m_list_size;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum)
|
BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum)
|
||||||
@ -231,6 +232,7 @@ BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum)
|
|||||||
}
|
}
|
||||||
BufferedPacket p = *r;
|
BufferedPacket p = *r;
|
||||||
m_list.erase(r);
|
m_list.erase(r);
|
||||||
|
--m_list_size;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
void ReliablePacketBuffer::insert(BufferedPacket &p)
|
void ReliablePacketBuffer::insert(BufferedPacket &p)
|
||||||
@ -240,6 +242,7 @@ void ReliablePacketBuffer::insert(BufferedPacket &p)
|
|||||||
assert(type == TYPE_RELIABLE);
|
assert(type == TYPE_RELIABLE);
|
||||||
u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]);
|
u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]);
|
||||||
|
|
||||||
|
++m_list_size;
|
||||||
// Find the right place for the packet and insert it there
|
// Find the right place for the packet and insert it there
|
||||||
|
|
||||||
// If list is empty, just add it
|
// If list is empty, just add it
|
||||||
@ -250,12 +253,12 @@ void ReliablePacketBuffer::insert(BufferedPacket &p)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Otherwise find the right place
|
// Otherwise find the right place
|
||||||
core::list<BufferedPacket>::Iterator i;
|
std::list<BufferedPacket>::iterator i = m_list.begin();
|
||||||
i = m_list.begin();
|
|
||||||
// Find the first packet in the list which has a higher seqnum
|
// 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]));
|
u16 s = readU16(&(i->data[BASE_HEADER_SIZE+1]));
|
||||||
if(s == seqnum){
|
if(s == seqnum){
|
||||||
|
--m_list_size;
|
||||||
throw AlreadyExistsException("Same seqnum in list");
|
throw AlreadyExistsException("Same seqnum in list");
|
||||||
}
|
}
|
||||||
if(seqnum_higher(s, seqnum)){
|
if(seqnum_higher(s, seqnum)){
|
||||||
@ -271,14 +274,14 @@ void ReliablePacketBuffer::insert(BufferedPacket &p)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Insert before i
|
// Insert before i
|
||||||
m_list.insert_before(i, p);
|
m_list.insert(i, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReliablePacketBuffer::incrementTimeouts(float dtime)
|
void ReliablePacketBuffer::incrementTimeouts(float dtime)
|
||||||
{
|
{
|
||||||
core::list<BufferedPacket>::Iterator i;
|
for(std::list<BufferedPacket>::iterator i = m_list.begin();
|
||||||
i = m_list.begin();
|
i != m_list.end(); ++i)
|
||||||
for(; i != m_list.end(); i++){
|
{
|
||||||
i->time += dtime;
|
i->time += dtime;
|
||||||
i->totaltime += dtime;
|
i->totaltime += dtime;
|
||||||
}
|
}
|
||||||
@ -286,9 +289,9 @@ void ReliablePacketBuffer::incrementTimeouts(float dtime)
|
|||||||
|
|
||||||
void ReliablePacketBuffer::resetTimedOuts(float timeout)
|
void ReliablePacketBuffer::resetTimedOuts(float timeout)
|
||||||
{
|
{
|
||||||
core::list<BufferedPacket>::Iterator i;
|
for(std::list<BufferedPacket>::iterator i = m_list.begin();
|
||||||
i = m_list.begin();
|
i != m_list.end(); ++i)
|
||||||
for(; i != m_list.end(); i++){
|
{
|
||||||
if(i->time >= timeout)
|
if(i->time >= timeout)
|
||||||
i->time = 0.0;
|
i->time = 0.0;
|
||||||
}
|
}
|
||||||
@ -296,21 +299,20 @@ void ReliablePacketBuffer::resetTimedOuts(float timeout)
|
|||||||
|
|
||||||
bool ReliablePacketBuffer::anyTotaltimeReached(float timeout)
|
bool ReliablePacketBuffer::anyTotaltimeReached(float timeout)
|
||||||
{
|
{
|
||||||
core::list<BufferedPacket>::Iterator i;
|
for(std::list<BufferedPacket>::iterator i = m_list.begin();
|
||||||
i = m_list.begin();
|
i != m_list.end(); ++i)
|
||||||
for(; i != m_list.end(); i++){
|
{
|
||||||
if(i->totaltime >= timeout)
|
if(i->totaltime >= timeout)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout)
|
std::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout)
|
||||||
{
|
{
|
||||||
core::list<BufferedPacket> timed_outs;
|
std::list<BufferedPacket> timed_outs;
|
||||||
core::list<BufferedPacket>::Iterator i;
|
for(std::list<BufferedPacket>::iterator i = m_list.begin();
|
||||||
i = m_list.begin();
|
i != m_list.end(); ++i)
|
||||||
for(; i != m_list.end(); i++)
|
|
||||||
{
|
{
|
||||||
if(i->time >= timeout)
|
if(i->time >= timeout)
|
||||||
timed_outs.push_back(*i);
|
timed_outs.push_back(*i);
|
||||||
@ -324,11 +326,10 @@ core::list<BufferedPacket> ReliablePacketBuffer::getTimedOuts(float timeout)
|
|||||||
|
|
||||||
IncomingSplitBuffer::~IncomingSplitBuffer()
|
IncomingSplitBuffer::~IncomingSplitBuffer()
|
||||||
{
|
{
|
||||||
core::map<u16, IncomingSplitPacket*>::Iterator i;
|
for(std::map<u16, IncomingSplitPacket*>::iterator i = m_buf.begin();
|
||||||
i = m_buf.getIterator();
|
i != m_buf.end(); ++i)
|
||||||
for(; i.atEnd() == false; i++)
|
|
||||||
{
|
{
|
||||||
delete i.getNode()->getValue();
|
delete i->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -346,7 +347,7 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
|
|||||||
u16 chunk_num = readU16(&p.data[BASE_HEADER_SIZE+5]);
|
u16 chunk_num = readU16(&p.data[BASE_HEADER_SIZE+5]);
|
||||||
|
|
||||||
// Add if doesn't exist
|
// Add if doesn't exist
|
||||||
if(m_buf.find(seqnum) == NULL)
|
if(m_buf.find(seqnum) == m_buf.end())
|
||||||
{
|
{
|
||||||
IncomingSplitPacket *sp = new IncomingSplitPacket();
|
IncomingSplitPacket *sp = new IncomingSplitPacket();
|
||||||
sp->chunk_count = chunk_count;
|
sp->chunk_count = chunk_count;
|
||||||
@ -369,7 +370,7 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
|
|||||||
// If chunk already exists, ignore it.
|
// If chunk already exists, ignore it.
|
||||||
// Sometimes two identical packets may arrive when there is network
|
// Sometimes two identical packets may arrive when there is network
|
||||||
// lag and the server re-sends stuff.
|
// 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>();
|
return SharedBuffer<u8>();
|
||||||
|
|
||||||
// Cut chunk data out of packet
|
// Cut chunk data out of packet
|
||||||
@ -386,11 +387,10 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
|
|||||||
|
|
||||||
// Calculate total size
|
// Calculate total size
|
||||||
u32 totalsize = 0;
|
u32 totalsize = 0;
|
||||||
core::map<u16, SharedBuffer<u8> >::Iterator i;
|
for(std::map<u16, SharedBuffer<u8> >::iterator i = sp->chunks.begin();
|
||||||
i = sp->chunks.getIterator();
|
i != sp->chunks.end(); ++i)
|
||||||
for(; i.atEnd() == false; i++)
|
|
||||||
{
|
{
|
||||||
totalsize += i.getNode()->getValue().getSize();
|
totalsize += i->second.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedBuffer<u8> fulldata(totalsize);
|
SharedBuffer<u8> fulldata(totalsize);
|
||||||
@ -407,34 +407,32 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove sp from buffer
|
// Remove sp from buffer
|
||||||
m_buf.remove(seqnum);
|
m_buf.erase(seqnum);
|
||||||
delete sp;
|
delete sp;
|
||||||
|
|
||||||
return fulldata;
|
return fulldata;
|
||||||
}
|
}
|
||||||
void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout)
|
void IncomingSplitBuffer::removeUnreliableTimedOuts(float dtime, float timeout)
|
||||||
{
|
{
|
||||||
core::list<u16> remove_queue;
|
std::list<u16> remove_queue;
|
||||||
core::map<u16, IncomingSplitPacket*>::Iterator i;
|
for(std::map<u16, IncomingSplitPacket*>::iterator i = m_buf.begin();
|
||||||
i = m_buf.getIterator();
|
i != m_buf.end(); ++i)
|
||||||
for(; i.atEnd() == false; i++)
|
|
||||||
{
|
{
|
||||||
IncomingSplitPacket *p = i.getNode()->getValue();
|
IncomingSplitPacket *p = i->second;
|
||||||
// Reliable ones are not removed by timeout
|
// Reliable ones are not removed by timeout
|
||||||
if(p->reliable == true)
|
if(p->reliable == true)
|
||||||
continue;
|
continue;
|
||||||
p->time += dtime;
|
p->time += dtime;
|
||||||
if(p->time >= timeout)
|
if(p->time >= timeout)
|
||||||
remove_queue.push_back(i.getNode()->getKey());
|
remove_queue.push_back(i->first);
|
||||||
}
|
}
|
||||||
core::list<u16>::Iterator j;
|
for(std::list<u16>::iterator j = remove_queue.begin();
|
||||||
j = remove_queue.begin();
|
j != remove_queue.end(); ++j)
|
||||||
for(; j != remove_queue.end(); j++)
|
|
||||||
{
|
{
|
||||||
dout_con<<"NOTE: Removing timed out unreliable split packet"
|
dout_con<<"NOTE: Removing timed out unreliable split packet"
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
delete m_buf[*j];
|
delete m_buf[*j];
|
||||||
m_buf.remove(*j);
|
m_buf.erase(*j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,12 +554,11 @@ Connection::~Connection()
|
|||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
// Delete peers
|
// Delete peers
|
||||||
for(core::map<u16, Peer*>::Iterator
|
for(std::map<u16, Peer*>::iterator
|
||||||
j = m_peers.getIterator();
|
j = m_peers.begin();
|
||||||
j.atEnd() == false; j++)
|
j != m_peers.end(); ++j)
|
||||||
{
|
{
|
||||||
Peer *peer = j.getNode()->getValue();
|
delete j->second;
|
||||||
delete peer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,7 +588,7 @@ void * Connection::Thread()
|
|||||||
|
|
||||||
runTimeouts(dtime);
|
runTimeouts(dtime);
|
||||||
|
|
||||||
while(m_command_queue.size() != 0){
|
while(!m_command_queue.empty()){
|
||||||
ConnectionCommand c = m_command_queue.pop_front();
|
ConnectionCommand c = m_command_queue.pop_front();
|
||||||
processCommand(c);
|
processCommand(c);
|
||||||
}
|
}
|
||||||
@ -648,18 +645,18 @@ void Connection::processCommand(ConnectionCommand &c)
|
|||||||
|
|
||||||
void Connection::send(float dtime)
|
void Connection::send(float dtime)
|
||||||
{
|
{
|
||||||
for(core::map<u16, Peer*>::Iterator
|
for(std::map<u16, Peer*>::iterator
|
||||||
j = m_peers.getIterator();
|
j = m_peers.begin();
|
||||||
j.atEnd() == false; j++)
|
j != m_peers.end(); ++j)
|
||||||
{
|
{
|
||||||
Peer *peer = j.getNode()->getValue();
|
Peer *peer = j->second;
|
||||||
peer->m_sendtime_accu += dtime;
|
peer->m_sendtime_accu += dtime;
|
||||||
peer->m_num_sent = 0;
|
peer->m_num_sent = 0;
|
||||||
peer->m_max_num_sent = peer->m_sendtime_accu *
|
peer->m_max_num_sent = peer->m_sendtime_accu *
|
||||||
peer->m_max_packets_per_second;
|
peer->m_max_packets_per_second;
|
||||||
}
|
}
|
||||||
Queue<OutgoingPacket> postponed_packets;
|
Queue<OutgoingPacket> postponed_packets;
|
||||||
while(m_outgoing_queue.size() != 0){
|
while(!m_outgoing_queue.empty()){
|
||||||
OutgoingPacket packet = m_outgoing_queue.pop_front();
|
OutgoingPacket packet = m_outgoing_queue.pop_front();
|
||||||
Peer *peer = getPeerNoEx(packet.peer_id);
|
Peer *peer = getPeerNoEx(packet.peer_id);
|
||||||
if(!peer)
|
if(!peer)
|
||||||
@ -674,14 +671,14 @@ void Connection::send(float dtime)
|
|||||||
postponed_packets.push_back(packet);
|
postponed_packets.push_back(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while(postponed_packets.size() != 0){
|
while(!postponed_packets.empty()){
|
||||||
m_outgoing_queue.push_back(postponed_packets.pop_front());
|
m_outgoing_queue.push_back(postponed_packets.pop_front());
|
||||||
}
|
}
|
||||||
for(core::map<u16, Peer*>::Iterator
|
for(std::map<u16, Peer*>::iterator
|
||||||
j = m_peers.getIterator();
|
j = m_peers.begin();
|
||||||
j.atEnd() == false; j++)
|
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_sendtime_accu -= (float)peer->m_num_sent /
|
||||||
peer->m_max_packets_per_second;
|
peer->m_max_packets_per_second;
|
||||||
if(peer->m_sendtime_accu > 10. / 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()
|
|||||||
Allow only entries that have has_sent_with_id==false.
|
Allow only entries that have has_sent_with_id==false.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
core::map<u16, Peer*>::Iterator j;
|
std::map<u16, Peer*>::iterator j;
|
||||||
j = m_peers.getIterator();
|
j = m_peers.begin();
|
||||||
for(; j.atEnd() == false; j++)
|
for(; j != m_peers.end(); ++j)
|
||||||
{
|
{
|
||||||
Peer *peer = j.getNode()->getValue();
|
Peer *peer = j->second;
|
||||||
if(peer->has_sent_with_id)
|
if(peer->has_sent_with_id)
|
||||||
continue;
|
continue;
|
||||||
if(peer->address == sender)
|
if(peer->address == sender)
|
||||||
@ -766,14 +763,14 @@ void Connection::receive()
|
|||||||
If no peer was found with the same address and port,
|
If no peer was found with the same address and port,
|
||||||
we shall assume it is a new peer and create an entry.
|
we shall assume it is a new peer and create an entry.
|
||||||
*/
|
*/
|
||||||
if(j.atEnd())
|
if(j == m_peers.end())
|
||||||
{
|
{
|
||||||
// Pass on to adding the peer
|
// Pass on to adding the peer
|
||||||
}
|
}
|
||||||
// Else: A peer was found.
|
// Else: A peer was found.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Peer *peer = j.getNode()->getValue();
|
Peer *peer = j->second;
|
||||||
peer_id = peer->id;
|
peer_id = peer->id;
|
||||||
PrintInfo(derr_con);
|
PrintInfo(derr_con);
|
||||||
derr_con<<"WARNING: Assuming unknown peer to be "
|
derr_con<<"WARNING: Assuming unknown peer to be "
|
||||||
@ -797,7 +794,7 @@ void Connection::receive()
|
|||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
// Check if exists
|
// Check if exists
|
||||||
if(m_peers.find(peer_id_new) == NULL)
|
if(m_peers.find(peer_id_new) == m_peers.end())
|
||||||
break;
|
break;
|
||||||
// Check for overflow
|
// Check for overflow
|
||||||
if(peer_id_new == 65535){
|
if(peer_id_new == 65535){
|
||||||
@ -817,7 +814,7 @@ void Connection::receive()
|
|||||||
|
|
||||||
// Create a peer
|
// Create a peer
|
||||||
Peer *peer = new Peer(peer_id_new, sender);
|
Peer *peer = new Peer(peer_id_new, sender);
|
||||||
m_peers.insert(peer->id, peer);
|
m_peers[peer->id] = peer;
|
||||||
|
|
||||||
// Create peer addition event
|
// Create peer addition event
|
||||||
ConnectionEvent e;
|
ConnectionEvent e;
|
||||||
@ -837,9 +834,9 @@ void Connection::receive()
|
|||||||
// Go on and process whatever it sent
|
// Go on and process whatever it sent
|
||||||
}
|
}
|
||||||
|
|
||||||
core::map<u16, Peer*>::Node *node = m_peers.find(peer_id);
|
std::map<u16, Peer*>::iterator node = m_peers.find(peer_id);
|
||||||
|
|
||||||
if(node == NULL)
|
if(node == m_peers.end())
|
||||||
{
|
{
|
||||||
// Peer not found
|
// Peer not found
|
||||||
// This means that the peer id of the sender is not PEER_ID_INEXISTENT
|
// This means that the peer id of the sender is not PEER_ID_INEXISTENT
|
||||||
@ -849,7 +846,7 @@ void Connection::receive()
|
|||||||
throw InvalidIncomingDataException("Peer not found (possible timeout)");
|
throw InvalidIncomingDataException("Peer not found (possible timeout)");
|
||||||
}
|
}
|
||||||
|
|
||||||
Peer *peer = node->getValue();
|
Peer *peer = node->second;
|
||||||
|
|
||||||
// Validate peer address
|
// Validate peer address
|
||||||
if(peer->address != sender)
|
if(peer->address != sender)
|
||||||
@ -902,12 +899,11 @@ void Connection::runTimeouts(float dtime)
|
|||||||
float congestion_control_min_rate
|
float congestion_control_min_rate
|
||||||
= g_settings->getFloat("congestion_control_min_rate");
|
= g_settings->getFloat("congestion_control_min_rate");
|
||||||
|
|
||||||
core::list<u16> timeouted_peers;
|
std::list<u16> timeouted_peers;
|
||||||
core::map<u16, Peer*>::Iterator j;
|
for(std::map<u16, Peer*>::iterator j = m_peers.begin();
|
||||||
j = m_peers.getIterator();
|
j != m_peers.end(); ++j)
|
||||||
for(; j.atEnd() == false; j++)
|
|
||||||
{
|
{
|
||||||
Peer *peer = j.getNode()->getValue();
|
Peer *peer = j->second;
|
||||||
|
|
||||||
// Update congestion control values
|
// Update congestion control values
|
||||||
peer->congestion_control_aim_rtt = congestion_control_aim_rtt;
|
peer->congestion_control_aim_rtt = congestion_control_aim_rtt;
|
||||||
@ -934,8 +930,7 @@ void Connection::runTimeouts(float dtime)
|
|||||||
float resend_timeout = peer->resend_timeout;
|
float resend_timeout = peer->resend_timeout;
|
||||||
for(u16 i=0; i<CHANNEL_COUNT; i++)
|
for(u16 i=0; i<CHANNEL_COUNT; i++)
|
||||||
{
|
{
|
||||||
core::list<BufferedPacket> timed_outs;
|
std::list<BufferedPacket> timed_outs;
|
||||||
core::list<BufferedPacket>::Iterator j;
|
|
||||||
|
|
||||||
Channel *channel = &peer->channels[i];
|
Channel *channel = &peer->channels[i];
|
||||||
|
|
||||||
@ -966,8 +961,8 @@ void Connection::runTimeouts(float dtime)
|
|||||||
|
|
||||||
channel->outgoing_reliables.resetTimedOuts(resend_timeout);
|
channel->outgoing_reliables.resetTimedOuts(resend_timeout);
|
||||||
|
|
||||||
j = timed_outs.begin();
|
for(std::list<BufferedPacket>::iterator j = timed_outs.begin();
|
||||||
for(; j != timed_outs.end(); j++)
|
j != timed_outs.end(); ++j)
|
||||||
{
|
{
|
||||||
u16 peer_id = readPeerId(*(j->data));
|
u16 peer_id = readPeerId(*(j->data));
|
||||||
u8 channel = readChannel(*(j->data));
|
u8 channel = readChannel(*(j->data));
|
||||||
@ -1012,8 +1007,8 @@ nextpeer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove timed out peers
|
// Remove timed out peers
|
||||||
core::list<u16>::Iterator i = timeouted_peers.begin();
|
for(std::list<u16>::iterator i = timeouted_peers.begin();
|
||||||
for(; i != timeouted_peers.end(); i++)
|
i != timeouted_peers.end(); ++i)
|
||||||
{
|
{
|
||||||
PrintInfo(derr_con);
|
PrintInfo(derr_con);
|
||||||
derr_con<<"RunTimeouts(): Removing peer "<<(*i)<<std::endl;
|
derr_con<<"RunTimeouts(): Removing peer "<<(*i)<<std::endl;
|
||||||
@ -1041,13 +1036,13 @@ void Connection::connect(Address address)
|
|||||||
dout_con<<getDesc()<<" connecting to "<<address.serializeString()
|
dout_con<<getDesc()<<" connecting to "<<address.serializeString()
|
||||||
<<":"<<address.getPort()<<std::endl;
|
<<":"<<address.getPort()<<std::endl;
|
||||||
|
|
||||||
core::map<u16, Peer*>::Node *node = m_peers.find(PEER_ID_SERVER);
|
std::map<u16, Peer*>::iterator node = m_peers.find(PEER_ID_SERVER);
|
||||||
if(node != NULL){
|
if(node != m_peers.end()){
|
||||||
throw ConnectionException("Already connected to a server");
|
throw ConnectionException("Already connected to a server");
|
||||||
}
|
}
|
||||||
|
|
||||||
Peer *peer = new Peer(PEER_ID_SERVER, address);
|
Peer *peer = new Peer(PEER_ID_SERVER, address);
|
||||||
m_peers.insert(peer->id, peer);
|
m_peers[peer->id] = peer;
|
||||||
|
|
||||||
// Create event
|
// Create event
|
||||||
ConnectionEvent e;
|
ConnectionEvent e;
|
||||||
@ -1072,22 +1067,20 @@ void Connection::disconnect()
|
|||||||
writeU8(&data[1], CONTROLTYPE_DISCO);
|
writeU8(&data[1], CONTROLTYPE_DISCO);
|
||||||
|
|
||||||
// Send to all
|
// Send to all
|
||||||
core::map<u16, Peer*>::Iterator j;
|
for(std::map<u16, Peer*>::iterator j = m_peers.begin();
|
||||||
j = m_peers.getIterator();
|
j != m_peers.end(); ++j)
|
||||||
for(; j.atEnd() == false; j++)
|
|
||||||
{
|
{
|
||||||
Peer *peer = j.getNode()->getValue();
|
Peer *peer = j->second;
|
||||||
rawSendAsPacket(peer->id, 0, data, false);
|
rawSendAsPacket(peer->id, 0, data, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::sendToAll(u8 channelnum, SharedBuffer<u8> data, bool reliable)
|
void Connection::sendToAll(u8 channelnum, SharedBuffer<u8> data, bool reliable)
|
||||||
{
|
{
|
||||||
core::map<u16, Peer*>::Iterator j;
|
for(std::map<u16, Peer*>::iterator j = m_peers.begin();
|
||||||
j = m_peers.getIterator();
|
j != m_peers.end(); ++j)
|
||||||
for(; j.atEnd() == false; j++)
|
|
||||||
{
|
{
|
||||||
Peer *peer = j.getNode()->getValue();
|
Peer *peer = j->second;
|
||||||
send(peer->id, channelnum, data, reliable);
|
send(peer->id, channelnum, data, reliable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1108,13 +1101,12 @@ void Connection::send(u16 peer_id, u8 channelnum,
|
|||||||
if(reliable)
|
if(reliable)
|
||||||
chunksize_max -= RELIABLE_HEADER_SIZE;
|
chunksize_max -= RELIABLE_HEADER_SIZE;
|
||||||
|
|
||||||
core::list<SharedBuffer<u8> > originals;
|
std::list<SharedBuffer<u8> > originals;
|
||||||
originals = makeAutoSplitPacket(data, chunksize_max,
|
originals = makeAutoSplitPacket(data, chunksize_max,
|
||||||
channel->next_outgoing_split_seqnum);
|
channel->next_outgoing_split_seqnum);
|
||||||
|
|
||||||
core::list<SharedBuffer<u8> >::Iterator i;
|
for(std::list<SharedBuffer<u8> >::iterator i = originals.begin();
|
||||||
i = originals.begin();
|
i != originals.end(); ++i)
|
||||||
for(; i != originals.end(); i++)
|
|
||||||
{
|
{
|
||||||
SharedBuffer<u8> original = *i;
|
SharedBuffer<u8> original = *i;
|
||||||
|
|
||||||
@ -1187,40 +1179,39 @@ void Connection::rawSend(const BufferedPacket &packet)
|
|||||||
|
|
||||||
Peer* Connection::getPeer(u16 peer_id)
|
Peer* Connection::getPeer(u16 peer_id)
|
||||||
{
|
{
|
||||||
core::map<u16, Peer*>::Node *node = m_peers.find(peer_id);
|
std::map<u16, Peer*>::iterator node = m_peers.find(peer_id);
|
||||||
|
|
||||||
if(node == NULL){
|
if(node == m_peers.end()){
|
||||||
throw PeerNotFoundException("GetPeer: Peer not found (possible timeout)");
|
throw PeerNotFoundException("GetPeer: Peer not found (possible timeout)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error checking
|
// Error checking
|
||||||
assert(node->getValue()->id == peer_id);
|
assert(node->second->id == peer_id);
|
||||||
|
|
||||||
return node->getValue();
|
return node->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Peer* Connection::getPeerNoEx(u16 peer_id)
|
Peer* Connection::getPeerNoEx(u16 peer_id)
|
||||||
{
|
{
|
||||||
core::map<u16, Peer*>::Node *node = m_peers.find(peer_id);
|
std::map<u16, Peer*>::iterator node = m_peers.find(peer_id);
|
||||||
|
|
||||||
if(node == NULL){
|
if(node == m_peers.end()){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error checking
|
// Error checking
|
||||||
assert(node->getValue()->id == peer_id);
|
assert(node->second->id == peer_id);
|
||||||
|
|
||||||
return node->getValue();
|
return node->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<Peer*> Connection::getPeers()
|
std::list<Peer*> Connection::getPeers()
|
||||||
{
|
{
|
||||||
core::list<Peer*> list;
|
std::list<Peer*> list;
|
||||||
core::map<u16, Peer*>::Iterator j;
|
for(std::map<u16, Peer*>::iterator j = m_peers.begin();
|
||||||
j = m_peers.getIterator();
|
j != m_peers.end(); ++j)
|
||||||
for(; j.atEnd() == false; j++)
|
|
||||||
{
|
{
|
||||||
Peer *peer = j.getNode()->getValue();
|
Peer *peer = j->second;
|
||||||
list.push_back(peer);
|
list.push_back(peer);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
@ -1228,11 +1219,10 @@ core::list<Peer*> Connection::getPeers()
|
|||||||
|
|
||||||
bool Connection::getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst)
|
bool Connection::getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst)
|
||||||
{
|
{
|
||||||
core::map<u16, Peer*>::Iterator j;
|
for(std::map<u16, Peer*>::iterator j = m_peers.begin();
|
||||||
j = m_peers.getIterator();
|
j != m_peers.end(); ++j)
|
||||||
for(; j.atEnd() == false; j++)
|
|
||||||
{
|
{
|
||||||
Peer *peer = j.getNode()->getValue();
|
Peer *peer = j->second;
|
||||||
for(u16 i=0; i<CHANNEL_COUNT; i++)
|
for(u16 i=0; i<CHANNEL_COUNT; i++)
|
||||||
{
|
{
|
||||||
Channel *channel = &peer->channels[i];
|
Channel *channel = &peer->channels[i];
|
||||||
@ -1538,7 +1528,7 @@ SharedBuffer<u8> Connection::processPacket(Channel *channel,
|
|||||||
|
|
||||||
bool Connection::deletePeer(u16 peer_id, bool timeout)
|
bool Connection::deletePeer(u16 peer_id, bool timeout)
|
||||||
{
|
{
|
||||||
if(m_peers.find(peer_id) == NULL)
|
if(m_peers.find(peer_id) == m_peers.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Peer *peer = m_peers[peer_id];
|
Peer *peer = m_peers[peer_id];
|
||||||
@ -1549,7 +1539,7 @@ bool Connection::deletePeer(u16 peer_id, bool timeout)
|
|||||||
putEvent(e);
|
putEvent(e);
|
||||||
|
|
||||||
delete m_peers[peer_id];
|
delete m_peers[peer_id];
|
||||||
m_peers.remove(peer_id);
|
m_peers.erase(peer_id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1557,7 +1547,7 @@ bool Connection::deletePeer(u16 peer_id, bool timeout)
|
|||||||
|
|
||||||
ConnectionEvent Connection::getEvent()
|
ConnectionEvent Connection::getEvent()
|
||||||
{
|
{
|
||||||
if(m_event_queue.size() == 0){
|
if(m_event_queue.empty()){
|
||||||
ConnectionEvent e;
|
ConnectionEvent e;
|
||||||
e.type = CONNEVENT_NONE;
|
e.type = CONNEVENT_NONE;
|
||||||
return e;
|
return e;
|
||||||
@ -1602,8 +1592,8 @@ bool Connection::Connected()
|
|||||||
if(m_peers.size() != 1)
|
if(m_peers.size() != 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
core::map<u16, Peer*>::Node *node = m_peers.find(PEER_ID_SERVER);
|
std::map<u16, Peer*>::iterator node = m_peers.find(PEER_ID_SERVER);
|
||||||
if(node == NULL)
|
if(node == m_peers.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(m_peer_id == PEER_ID_INEXISTENT)
|
if(m_peer_id == PEER_ID_INEXISTENT)
|
||||||
|
@ -29,6 +29,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "util/thread.h"
|
#include "util/thread.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace con
|
namespace con
|
||||||
{
|
{
|
||||||
@ -142,14 +144,14 @@ SharedBuffer<u8> makeOriginalPacket(
|
|||||||
SharedBuffer<u8> data);
|
SharedBuffer<u8> data);
|
||||||
|
|
||||||
// Split data in chunks and add TYPE_SPLIT headers to them
|
// Split data in chunks and add TYPE_SPLIT headers to them
|
||||||
core::list<SharedBuffer<u8> > makeSplitPacket(
|
std::list<SharedBuffer<u8> > makeSplitPacket(
|
||||||
SharedBuffer<u8> data,
|
SharedBuffer<u8> data,
|
||||||
u32 chunksize_max,
|
u32 chunksize_max,
|
||||||
u16 seqnum);
|
u16 seqnum);
|
||||||
|
|
||||||
// Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet
|
// Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet
|
||||||
// Increments split_seqnum if a split packet is made
|
// Increments split_seqnum if a split packet is made
|
||||||
core::list<SharedBuffer<u8> > makeAutoSplitPacket(
|
std::list<SharedBuffer<u8> > makeAutoSplitPacket(
|
||||||
SharedBuffer<u8> data,
|
SharedBuffer<u8> data,
|
||||||
u32 chunksize_max,
|
u32 chunksize_max,
|
||||||
u16 &split_seqnum);
|
u16 &split_seqnum);
|
||||||
@ -167,7 +169,7 @@ struct IncomingSplitPacket
|
|||||||
reliable = false;
|
reliable = false;
|
||||||
}
|
}
|
||||||
// Key is chunk number, value is data without headers
|
// Key is chunk number, value is data without headers
|
||||||
core::map<u16, SharedBuffer<u8> > chunks;
|
std::map<u16, SharedBuffer<u8> > chunks;
|
||||||
u32 chunk_count;
|
u32 chunk_count;
|
||||||
float time; // Seconds from adding
|
float time; // Seconds from adding
|
||||||
bool reliable; // If true, isn't deleted on timeout
|
bool reliable; // If true, isn't deleted on timeout
|
||||||
@ -268,12 +270,12 @@ with a buffer in the receiving and transmitting end.
|
|||||||
for fast access to the smallest one.
|
for fast access to the smallest one.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef core::list<BufferedPacket>::Iterator RPBSearchResult;
|
typedef std::list<BufferedPacket>::iterator RPBSearchResult;
|
||||||
|
|
||||||
class ReliablePacketBuffer
|
class ReliablePacketBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
ReliablePacketBuffer();
|
||||||
void print();
|
void print();
|
||||||
bool empty();
|
bool empty();
|
||||||
u32 size();
|
u32 size();
|
||||||
@ -286,10 +288,11 @@ public:
|
|||||||
void incrementTimeouts(float dtime);
|
void incrementTimeouts(float dtime);
|
||||||
void resetTimedOuts(float timeout);
|
void resetTimedOuts(float timeout);
|
||||||
bool anyTotaltimeReached(float timeout);
|
bool anyTotaltimeReached(float timeout);
|
||||||
core::list<BufferedPacket> getTimedOuts(float timeout);
|
std::list<BufferedPacket> getTimedOuts(float timeout);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
core::list<BufferedPacket> m_list;
|
std::list<BufferedPacket> m_list;
|
||||||
|
u16 m_list_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -310,7 +313,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Key is seqnum
|
// Key is seqnum
|
||||||
core::map<u16, IncomingSplitPacket*> m_buf;
|
std::map<u16, IncomingSplitPacket*> m_buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Connection;
|
class Connection;
|
||||||
@ -589,7 +592,7 @@ private:
|
|||||||
void rawSend(const BufferedPacket &packet);
|
void rawSend(const BufferedPacket &packet);
|
||||||
Peer* getPeer(u16 peer_id);
|
Peer* getPeer(u16 peer_id);
|
||||||
Peer* getPeerNoEx(u16 peer_id);
|
Peer* getPeerNoEx(u16 peer_id);
|
||||||
core::list<Peer*> getPeers();
|
std::list<Peer*> getPeers();
|
||||||
bool getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst);
|
bool getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst);
|
||||||
// Returns next data from a buffer if possible
|
// Returns next data from a buffer if possible
|
||||||
// If found, returns true; if not, false.
|
// If found, returns true; if not, false.
|
||||||
@ -619,7 +622,7 @@ private:
|
|||||||
UDPSocket m_socket;
|
UDPSocket m_socket;
|
||||||
u16 m_peer_id;
|
u16 m_peer_id;
|
||||||
|
|
||||||
core::map<u16, Peer*> m_peers;
|
std::map<u16, Peer*> m_peers;
|
||||||
JMutex m_peers_mutex;
|
JMutex m_peers_mutex;
|
||||||
|
|
||||||
// Backwards compatibility
|
// Backwards compatibility
|
||||||
|
@ -114,7 +114,7 @@ public:
|
|||||||
actionstream<<"A sapling grows into a tree at "
|
actionstream<<"A sapling grows into a tree at "
|
||||||
<<PP(p)<<std::endl;
|
<<PP(p)<<std::endl;
|
||||||
|
|
||||||
core::map<v3s16, MapBlock*> modified_blocks;
|
std::map<v3s16, MapBlock*> modified_blocks;
|
||||||
v3s16 tree_p = p;
|
v3s16 tree_p = p;
|
||||||
ManualMapVoxelManipulator vmanip(map);
|
ManualMapVoxelManipulator vmanip(map);
|
||||||
v3s16 tree_blockp = getNodeBlockPos(tree_p);
|
v3s16 tree_blockp = getNodeBlockPos(tree_p);
|
||||||
@ -124,24 +124,19 @@ public:
|
|||||||
vmanip.blitBackAll(&modified_blocks);
|
vmanip.blitBackAll(&modified_blocks);
|
||||||
|
|
||||||
// update lighting
|
// update lighting
|
||||||
core::map<v3s16, MapBlock*> lighting_modified_blocks;
|
std::map<v3s16, MapBlock*> lighting_modified_blocks;
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
|
||||||
i = modified_blocks.getIterator();
|
|
||||||
i.atEnd() == false; i++)
|
|
||||||
{
|
|
||||||
lighting_modified_blocks.insert(i.getNode()->getKey(), i.getNode()->getValue());
|
|
||||||
}
|
|
||||||
map->updateLighting(lighting_modified_blocks, modified_blocks);
|
map->updateLighting(lighting_modified_blocks, modified_blocks);
|
||||||
|
|
||||||
// Send a MEET_OTHER event
|
// Send a MEET_OTHER event
|
||||||
MapEditEvent event;
|
MapEditEvent event;
|
||||||
event.type = MEET_OTHER;
|
event.type = MEET_OTHER;
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
// event.modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
|
||||||
i = modified_blocks.getIterator();
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i.atEnd() == false; i++)
|
i = modified_blocks.begin();
|
||||||
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
event.modified_blocks.insert(i->first);
|
||||||
event.modified_blocks.insert(p, true);
|
|
||||||
}
|
}
|
||||||
map->dispatchEvent(&event);
|
map->dispatchEvent(&event);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ struct ToolCapabilities;
|
|||||||
|
|
||||||
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
||||||
|
|
||||||
core::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
|
std::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
SmoothTranslator
|
SmoothTranslator
|
||||||
|
@ -230,9 +230,9 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
|
|||||||
|
|
||||||
// Neighbor liquid levels (key = relative position)
|
// Neighbor liquid levels (key = relative position)
|
||||||
// Includes current node
|
// Includes current node
|
||||||
core::map<v3s16, f32> neighbor_levels;
|
std::map<v3s16, f32> neighbor_levels;
|
||||||
core::map<v3s16, content_t> neighbor_contents;
|
std::map<v3s16, content_t> neighbor_contents;
|
||||||
core::map<v3s16, u8> neighbor_flags;
|
std::map<v3s16, u8> neighbor_flags;
|
||||||
const u8 neighborflag_top_is_same_liquid = 0x01;
|
const u8 neighborflag_top_is_same_liquid = 0x01;
|
||||||
v3s16 neighbor_dirs[9] = {
|
v3s16 neighbor_dirs[9] = {
|
||||||
v3s16(0,0,0),
|
v3s16(0,0,0),
|
||||||
@ -273,9 +273,9 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
|
|||||||
flags |= neighborflag_top_is_same_liquid;
|
flags |= neighborflag_top_is_same_liquid;
|
||||||
}
|
}
|
||||||
|
|
||||||
neighbor_levels.insert(neighbor_dirs[i], level);
|
neighbor_levels[neighbor_dirs[i]] = level;
|
||||||
neighbor_contents.insert(neighbor_dirs[i], content);
|
neighbor_contents[neighbor_dirs[i]] = content;
|
||||||
neighbor_flags.insert(neighbor_dirs[i], flags);
|
neighbor_flags[neighbor_dirs[i]] = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Corner heights (average between four liquids)
|
// Corner heights (average between four liquids)
|
||||||
|
@ -31,7 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "genericobject.h"
|
#include "genericobject.h"
|
||||||
#include "util/serialize.h"
|
#include "util/serialize.h"
|
||||||
|
|
||||||
core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
|
std::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
DummyLoadSAO
|
DummyLoadSAO
|
||||||
|
@ -130,7 +130,7 @@ void DebugStack::print(std::ostream &os, bool everything)
|
|||||||
os<<"Probably overflown."<<std::endl;
|
os<<"Probably overflown."<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::map<threadid_t, DebugStack*> g_debug_stacks;
|
std::map<threadid_t, DebugStack*> g_debug_stacks;
|
||||||
JMutex g_debug_stacks_mutex;
|
JMutex g_debug_stacks_mutex;
|
||||||
|
|
||||||
void debug_stacks_init()
|
void debug_stacks_init()
|
||||||
@ -144,12 +144,11 @@ void debug_stacks_print_to(std::ostream &os)
|
|||||||
|
|
||||||
os<<"Debug stacks:"<<std::endl;
|
os<<"Debug stacks:"<<std::endl;
|
||||||
|
|
||||||
for(core::map<threadid_t, DebugStack*>::Iterator
|
for(std::map<threadid_t, DebugStack*>::iterator
|
||||||
i = g_debug_stacks.getIterator();
|
i = g_debug_stacks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != g_debug_stacks.end(); ++i)
|
||||||
{
|
{
|
||||||
DebugStack *stack = i.getNode()->getValue();
|
i->second->print(os, false);
|
||||||
stack->print(os, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,11 +158,11 @@ void debug_stacks_print()
|
|||||||
|
|
||||||
DEBUGPRINT("Debug stacks:\n");
|
DEBUGPRINT("Debug stacks:\n");
|
||||||
|
|
||||||
for(core::map<threadid_t, DebugStack*>::Iterator
|
for(std::map<threadid_t, DebugStack*>::iterator
|
||||||
i = g_debug_stacks.getIterator();
|
i = g_debug_stacks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != g_debug_stacks.end(); ++i)
|
||||||
{
|
{
|
||||||
DebugStack *stack = i.getNode()->getValue();
|
DebugStack *stack = i->second;
|
||||||
|
|
||||||
for(int i=0; i<DEBUGSTREAM_COUNT; i++)
|
for(int i=0; i<DEBUGSTREAM_COUNT; i++)
|
||||||
{
|
{
|
||||||
@ -179,18 +178,18 @@ DebugStacker::DebugStacker(const char *text)
|
|||||||
|
|
||||||
JMutexAutoLock lock(g_debug_stacks_mutex);
|
JMutexAutoLock lock(g_debug_stacks_mutex);
|
||||||
|
|
||||||
core::map<threadid_t, DebugStack*>::Node *n;
|
std::map<threadid_t, DebugStack*>::iterator n;
|
||||||
n = g_debug_stacks.find(threadid);
|
n = g_debug_stacks.find(threadid);
|
||||||
if(n != NULL)
|
if(n != g_debug_stacks.end())
|
||||||
{
|
{
|
||||||
m_stack = n->getValue();
|
m_stack = n->second;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*DEBUGPRINT("Creating new debug stack for thread %x\n",
|
/*DEBUGPRINT("Creating new debug stack for thread %x\n",
|
||||||
(unsigned int)threadid);*/
|
(unsigned int)threadid);*/
|
||||||
m_stack = new DebugStack(threadid);
|
m_stack = new DebugStack(threadid);
|
||||||
g_debug_stacks.insert(threadid, m_stack);
|
g_debug_stacks[threadid] = m_stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_stack->stack_i >= DEBUG_STACK_SIZE)
|
if(m_stack->stack_i >= DEBUG_STACK_SIZE)
|
||||||
@ -224,7 +223,7 @@ DebugStacker::~DebugStacker()
|
|||||||
/*DEBUGPRINT("Deleting debug stack for thread %x\n",
|
/*DEBUGPRINT("Deleting debug stack for thread %x\n",
|
||||||
(unsigned int)threadid);*/
|
(unsigned int)threadid);*/
|
||||||
delete m_stack;
|
delete m_stack;
|
||||||
g_debug_stacks.remove(threadid);
|
g_debug_stacks.erase(threadid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
src/debug.h
29
src/debug.h
@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "threads.h"
|
#include "threads.h"
|
||||||
#include "gettime.h"
|
#include "gettime.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
@ -165,7 +166,7 @@ struct DebugStack
|
|||||||
int stack_max_i; // Highest i that was seen
|
int stack_max_i; // Highest i that was seen
|
||||||
};
|
};
|
||||||
|
|
||||||
extern core::map<threadid_t, DebugStack*> g_debug_stacks;
|
extern std::map<threadid_t, DebugStack*> g_debug_stacks;
|
||||||
extern JMutex g_debug_stacks_mutex;
|
extern JMutex g_debug_stacks_mutex;
|
||||||
|
|
||||||
extern void debug_stacks_init();
|
extern void debug_stacks_init();
|
||||||
@ -205,42 +206,42 @@ public:
|
|||||||
|
|
||||||
void add(u16 command)
|
void add(u16 command)
|
||||||
{
|
{
|
||||||
core::map<u16, u16>::Node *n = m_packets.find(command);
|
std::map<u16, u16>::iterator n = m_packets.find(command);
|
||||||
if(n == NULL)
|
if(n == m_packets.end())
|
||||||
{
|
{
|
||||||
m_packets[command] = 1;
|
m_packets[command] = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
n->setValue(n->getValue()+1);
|
n->second++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
for(core::map<u16, u16>::Iterator
|
for(std::map<u16, u16>::iterator
|
||||||
i = m_packets.getIterator();
|
i = m_packets.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_packets.end(); ++i)
|
||||||
{
|
{
|
||||||
i.getNode()->setValue(0);
|
i->second = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(std::ostream &o)
|
void print(std::ostream &o)
|
||||||
{
|
{
|
||||||
for(core::map<u16, u16>::Iterator
|
for(std::map<u16, u16>::iterator
|
||||||
i = m_packets.getIterator();
|
i = m_packets.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_packets.end(); ++i)
|
||||||
{
|
{
|
||||||
o<<"cmd "<<i.getNode()->getKey()
|
o<<"cmd "<<i->first
|
||||||
<<" count "<<i.getNode()->getValue()
|
<<" count "<<i->second
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// command, count
|
// command, count
|
||||||
core::map<u16, u16> m_packets;
|
std::map<u16, u16> m_packets;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -359,7 +359,7 @@ void *EmergeThread::Thread() {
|
|||||||
*/
|
*/
|
||||||
BlockMakeData data;
|
BlockMakeData data;
|
||||||
MapBlock *block = NULL;
|
MapBlock *block = NULL;
|
||||||
core::map<v3s16, MapBlock *> modified_blocks;
|
std::map<v3s16, MapBlock *> modified_blocks;
|
||||||
|
|
||||||
if (getBlockOrStartGen(p, &block, &data, allow_generate)) {
|
if (getBlockOrStartGen(p, &block, &data, allow_generate)) {
|
||||||
{
|
{
|
||||||
@ -415,13 +415,13 @@ void *EmergeThread::Thread() {
|
|||||||
JMutexAutoLock lock(m_server->m_con_mutex);
|
JMutexAutoLock lock(m_server->m_con_mutex);
|
||||||
// Add the originally fetched block to the modified list
|
// Add the originally fetched block to the modified list
|
||||||
if (block)
|
if (block)
|
||||||
modified_blocks.insert(p, block);
|
modified_blocks[p] = block;
|
||||||
|
|
||||||
// Set the modified blocks unsent for all the clients
|
// Set the modified blocks unsent for all the clients
|
||||||
for (core::map<u16, RemoteClient*>::Iterator
|
for (std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_server->m_clients.getIterator();
|
i = m_server->m_clients.begin();
|
||||||
i.atEnd() == false; i++) {
|
i != m_server->m_clients.end(); ++i) {
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
if (modified_blocks.size() > 0) {
|
if (modified_blocks.size() > 0) {
|
||||||
// Remove block from sent history
|
// Remove block from sent history
|
||||||
client->SetBlocksNotSent(modified_blocks);
|
client->SetBlocksNotSent(modified_blocks);
|
||||||
|
@ -58,8 +58,8 @@ Environment::Environment():
|
|||||||
Environment::~Environment()
|
Environment::~Environment()
|
||||||
{
|
{
|
||||||
// Deallocate players
|
// Deallocate players
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for(std::list<Player*>::iterator i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
delete (*i);
|
delete (*i);
|
||||||
}
|
}
|
||||||
@ -86,8 +86,8 @@ void Environment::removePlayer(u16 peer_id)
|
|||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
re_search:
|
re_search:
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for(std::list<Player*>::iterator i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
if(player->peer_id != peer_id)
|
if(player->peer_id != peer_id)
|
||||||
@ -103,8 +103,8 @@ re_search:
|
|||||||
|
|
||||||
Player * Environment::getPlayer(u16 peer_id)
|
Player * Environment::getPlayer(u16 peer_id)
|
||||||
{
|
{
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for(std::list<Player*>::iterator i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
if(player->peer_id == peer_id)
|
if(player->peer_id == peer_id)
|
||||||
@ -115,8 +115,8 @@ Player * Environment::getPlayer(u16 peer_id)
|
|||||||
|
|
||||||
Player * Environment::getPlayer(const char *name)
|
Player * Environment::getPlayer(const char *name)
|
||||||
{
|
{
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for(std::list<Player*>::iterator i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
if(strcmp(player->getName(), name) == 0)
|
if(strcmp(player->getName(), name) == 0)
|
||||||
@ -127,12 +127,12 @@ Player * Environment::getPlayer(const char *name)
|
|||||||
|
|
||||||
Player * Environment::getRandomConnectedPlayer()
|
Player * Environment::getRandomConnectedPlayer()
|
||||||
{
|
{
|
||||||
core::list<Player*> connected_players = getPlayers(true);
|
std::list<Player*> connected_players = getPlayers(true);
|
||||||
u32 chosen_one = myrand() % connected_players.size();
|
u32 chosen_one = myrand() % connected_players.size();
|
||||||
u32 j = 0;
|
u32 j = 0;
|
||||||
for(core::list<Player*>::Iterator
|
for(std::list<Player*>::iterator
|
||||||
i = connected_players.begin();
|
i = connected_players.begin();
|
||||||
i != connected_players.end(); i++)
|
i != connected_players.end(); ++i)
|
||||||
{
|
{
|
||||||
if(j == chosen_one)
|
if(j == chosen_one)
|
||||||
{
|
{
|
||||||
@ -146,12 +146,12 @@ Player * Environment::getRandomConnectedPlayer()
|
|||||||
|
|
||||||
Player * Environment::getNearestConnectedPlayer(v3f pos)
|
Player * Environment::getNearestConnectedPlayer(v3f pos)
|
||||||
{
|
{
|
||||||
core::list<Player*> connected_players = getPlayers(true);
|
std::list<Player*> connected_players = getPlayers(true);
|
||||||
f32 nearest_d = 0;
|
f32 nearest_d = 0;
|
||||||
Player *nearest_player = NULL;
|
Player *nearest_player = NULL;
|
||||||
for(core::list<Player*>::Iterator
|
for(std::list<Player*>::iterator
|
||||||
i = connected_players.begin();
|
i = connected_players.begin();
|
||||||
i != connected_players.end(); i++)
|
i != connected_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
f32 d = player->getPosition().getDistanceFrom(pos);
|
f32 d = player->getPosition().getDistanceFrom(pos);
|
||||||
@ -164,17 +164,17 @@ Player * Environment::getNearestConnectedPlayer(v3f pos)
|
|||||||
return nearest_player;
|
return nearest_player;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<Player*> Environment::getPlayers()
|
std::list<Player*> Environment::getPlayers()
|
||||||
{
|
{
|
||||||
return m_players;
|
return m_players;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<Player*> Environment::getPlayers(bool ignore_disconnected)
|
std::list<Player*> Environment::getPlayers(bool ignore_disconnected)
|
||||||
{
|
{
|
||||||
core::list<Player*> newlist;
|
std::list<Player*> newlist;
|
||||||
for(core::list<Player*>::Iterator
|
for(std::list<Player*>::iterator
|
||||||
i = m_players.begin();
|
i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ core::list<Player*> Environment::getPlayers(bool ignore_disconnected)
|
|||||||
void Environment::printPlayers(std::ostream &o)
|
void Environment::printPlayers(std::ostream &o)
|
||||||
{
|
{
|
||||||
o<<"Players in environment:"<<std::endl;
|
o<<"Players in environment:"<<std::endl;
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for(std::list<Player*>::iterator i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); i++)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
@ -251,7 +251,7 @@ ABMWithState::ABMWithState(ActiveBlockModifier *abm_):
|
|||||||
ActiveBlockList
|
ActiveBlockList
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void fillRadiusBlock(v3s16 p0, s16 r, core::map<v3s16, bool> &list)
|
void fillRadiusBlock(v3s16 p0, s16 r, std::set<v3s16> &list)
|
||||||
{
|
{
|
||||||
v3s16 p;
|
v3s16 p;
|
||||||
for(p.X=p0.X-r; p.X<=p0.X+r; p.X++)
|
for(p.X=p0.X-r; p.X<=p0.X+r; p.X++)
|
||||||
@ -259,21 +259,21 @@ void fillRadiusBlock(v3s16 p0, s16 r, core::map<v3s16, bool> &list)
|
|||||||
for(p.Z=p0.Z-r; p.Z<=p0.Z+r; p.Z++)
|
for(p.Z=p0.Z-r; p.Z<=p0.Z+r; p.Z++)
|
||||||
{
|
{
|
||||||
// Set in list
|
// Set in list
|
||||||
list[p] = true;
|
list.insert(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActiveBlockList::update(core::list<v3s16> &active_positions,
|
void ActiveBlockList::update(std::list<v3s16> &active_positions,
|
||||||
s16 radius,
|
s16 radius,
|
||||||
core::map<v3s16, bool> &blocks_removed,
|
std::set<v3s16> &blocks_removed,
|
||||||
core::map<v3s16, bool> &blocks_added)
|
std::set<v3s16> &blocks_added)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Create the new list
|
Create the new list
|
||||||
*/
|
*/
|
||||||
core::map<v3s16, bool> newlist;
|
std::set<v3s16> newlist;
|
||||||
for(core::list<v3s16>::Iterator i = active_positions.begin();
|
for(std::list<v3s16>::iterator i = active_positions.begin();
|
||||||
i != active_positions.end(); i++)
|
i != active_positions.end(); ++i)
|
||||||
{
|
{
|
||||||
fillRadiusBlock(*i, radius, newlist);
|
fillRadiusBlock(*i, radius, newlist);
|
||||||
}
|
}
|
||||||
@ -282,37 +282,37 @@ void ActiveBlockList::update(core::list<v3s16> &active_positions,
|
|||||||
Find out which blocks on the old list are not on the new list
|
Find out which blocks on the old list are not on the new list
|
||||||
*/
|
*/
|
||||||
// Go through old list
|
// Go through old list
|
||||||
for(core::map<v3s16, bool>::Iterator i = m_list.getIterator();
|
for(std::set<v3s16>::iterator i = m_list.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_list.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = *i;
|
||||||
// If not on new list, it's been removed
|
// If not on new list, it's been removed
|
||||||
if(newlist.find(p) == NULL)
|
if(newlist.find(p) == newlist.end())
|
||||||
blocks_removed.insert(p, true);
|
blocks_removed.insert(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Find out which blocks on the new list are not on the old list
|
Find out which blocks on the new list are not on the old list
|
||||||
*/
|
*/
|
||||||
// Go through new list
|
// Go through new list
|
||||||
for(core::map<v3s16, bool>::Iterator i = newlist.getIterator();
|
for(std::set<v3s16>::iterator i = newlist.begin();
|
||||||
i.atEnd()==false; i++)
|
i != newlist.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = *i;
|
||||||
// If not on old list, it's been added
|
// If not on old list, it's been added
|
||||||
if(m_list.find(p) == NULL)
|
if(m_list.find(p) == m_list.end())
|
||||||
blocks_added.insert(p, true);
|
blocks_added.insert(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Update m_list
|
Update m_list
|
||||||
*/
|
*/
|
||||||
m_list.clear();
|
m_list.clear();
|
||||||
for(core::map<v3s16, bool>::Iterator i = newlist.getIterator();
|
for(std::set<v3s16>::iterator i = newlist.begin();
|
||||||
i.atEnd()==false; i++)
|
i != newlist.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = *i;
|
||||||
m_list.insert(p, true);
|
m_list.insert(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,8 +348,8 @@ ServerEnvironment::~ServerEnvironment()
|
|||||||
m_map->drop();
|
m_map->drop();
|
||||||
|
|
||||||
// Delete ActiveBlockModifiers
|
// Delete ActiveBlockModifiers
|
||||||
for(core::list<ABMWithState>::Iterator
|
for(std::list<ABMWithState>::iterator
|
||||||
i = m_abms.begin(); i != m_abms.end(); i++){
|
i = m_abms.begin(); i != m_abms.end(); ++i){
|
||||||
delete i->abm;
|
delete i->abm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -370,7 +370,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
|
|||||||
std::string players_path = savedir + "/players";
|
std::string players_path = savedir + "/players";
|
||||||
fs::CreateDir(players_path);
|
fs::CreateDir(players_path);
|
||||||
|
|
||||||
core::map<Player*, bool> saved_players;
|
std::set<Player*> saved_players;
|
||||||
|
|
||||||
std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
|
std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
|
||||||
for(u32 i=0; i<player_files.size(); i++)
|
for(u32 i=0; i<player_files.size(); i++)
|
||||||
@ -419,15 +419,15 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
player->serialize(os);
|
player->serialize(os);
|
||||||
saved_players.insert(player, true);
|
saved_players.insert(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for(std::list<Player*>::iterator i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
if(saved_players.find(player) != NULL)
|
if(saved_players.find(player) != saved_players.end())
|
||||||
{
|
{
|
||||||
/*infostream<<"Player "<<player->getName()
|
/*infostream<<"Player "<<player->getName()
|
||||||
<<" was already saved."<<std::endl;*/
|
<<" was already saved."<<std::endl;*/
|
||||||
@ -473,7 +473,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
player->serialize(os);
|
player->serialize(os);
|
||||||
saved_players.insert(player, true);
|
saved_players.insert(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,8 +484,6 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
|
|||||||
{
|
{
|
||||||
std::string players_path = savedir + "/players";
|
std::string players_path = savedir + "/players";
|
||||||
|
|
||||||
core::map<Player*, bool> saved_players;
|
|
||||||
|
|
||||||
std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
|
std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
|
||||||
for(u32 i=0; i<player_files.size(); i++)
|
for(u32 i=0; i<player_files.size(); i++)
|
||||||
{
|
{
|
||||||
@ -627,7 +625,7 @@ private:
|
|||||||
ServerEnvironment *m_env;
|
ServerEnvironment *m_env;
|
||||||
std::map<content_t, std::list<ActiveABM> > m_aabms;
|
std::map<content_t, std::list<ActiveABM> > m_aabms;
|
||||||
public:
|
public:
|
||||||
ABMHandler(core::list<ABMWithState> &abms,
|
ABMHandler(std::list<ABMWithState> &abms,
|
||||||
float dtime_s, ServerEnvironment *env,
|
float dtime_s, ServerEnvironment *env,
|
||||||
bool use_timers):
|
bool use_timers):
|
||||||
m_env(env)
|
m_env(env)
|
||||||
@ -635,8 +633,8 @@ public:
|
|||||||
if(dtime_s < 0.001)
|
if(dtime_s < 0.001)
|
||||||
return;
|
return;
|
||||||
INodeDefManager *ndef = env->getGameDef()->ndef();
|
INodeDefManager *ndef = env->getGameDef()->ndef();
|
||||||
for(core::list<ABMWithState>::Iterator
|
for(std::list<ABMWithState>::iterator
|
||||||
i = abms.begin(); i != abms.end(); i++){
|
i = abms.begin(); i != abms.end(); ++i){
|
||||||
ActiveBlockModifier *abm = i->abm;
|
ActiveBlockModifier *abm = i->abm;
|
||||||
float trigger_interval = abm->getTriggerInterval();
|
float trigger_interval = abm->getTriggerInterval();
|
||||||
if(trigger_interval < 0.001)
|
if(trigger_interval < 0.001)
|
||||||
@ -862,12 +860,12 @@ bool ServerEnvironment::removeNode(v3s16 p)
|
|||||||
std::set<u16> ServerEnvironment::getObjectsInsideRadius(v3f pos, float radius)
|
std::set<u16> ServerEnvironment::getObjectsInsideRadius(v3f pos, float radius)
|
||||||
{
|
{
|
||||||
std::set<u16> objects;
|
std::set<u16> objects;
|
||||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
for(std::map<u16, ServerActiveObject*>::iterator
|
||||||
i = m_active_objects.getIterator();
|
i = m_active_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
ServerActiveObject* obj = i.getNode()->getValue();
|
ServerActiveObject* obj = i->second;
|
||||||
u16 id = i.getNode()->getKey();
|
u16 id = i->first;
|
||||||
v3f objectpos = obj->getBasePosition();
|
v3f objectpos = obj->getBasePosition();
|
||||||
if(objectpos.getDistanceFrom(pos) > radius)
|
if(objectpos.getDistanceFrom(pos) > radius)
|
||||||
continue;
|
continue;
|
||||||
@ -880,15 +878,15 @@ void ServerEnvironment::clearAllObjects()
|
|||||||
{
|
{
|
||||||
infostream<<"ServerEnvironment::clearAllObjects(): "
|
infostream<<"ServerEnvironment::clearAllObjects(): "
|
||||||
<<"Removing all active objects"<<std::endl;
|
<<"Removing all active objects"<<std::endl;
|
||||||
core::list<u16> objects_to_remove;
|
std::list<u16> objects_to_remove;
|
||||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
for(std::map<u16, ServerActiveObject*>::iterator
|
||||||
i = m_active_objects.getIterator();
|
i = m_active_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
ServerActiveObject* obj = i.getNode()->getValue();
|
ServerActiveObject* obj = i->second;
|
||||||
if(obj->getType() == ACTIVEOBJECT_TYPE_PLAYER)
|
if(obj->getType() == ACTIVEOBJECT_TYPE_PLAYER)
|
||||||
continue;
|
continue;
|
||||||
u16 id = i.getNode()->getKey();
|
u16 id = i->first;
|
||||||
v3f objectpos = obj->getBasePosition();
|
v3f objectpos = obj->getBasePosition();
|
||||||
// Delete static object if block is loaded
|
// Delete static object if block is loaded
|
||||||
if(obj->m_static_exists){
|
if(obj->m_static_exists){
|
||||||
@ -919,13 +917,13 @@ void ServerEnvironment::clearAllObjects()
|
|||||||
objects_to_remove.push_back(id);
|
objects_to_remove.push_back(id);
|
||||||
}
|
}
|
||||||
// Remove references from m_active_objects
|
// Remove references from m_active_objects
|
||||||
for(core::list<u16>::Iterator i = objects_to_remove.begin();
|
for(std::list<u16>::iterator i = objects_to_remove.begin();
|
||||||
i != objects_to_remove.end(); i++)
|
i != objects_to_remove.end(); ++i)
|
||||||
{
|
{
|
||||||
m_active_objects.remove(*i);
|
m_active_objects.erase(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<v3s16> loadable_blocks;
|
std::list<v3s16> loadable_blocks;
|
||||||
infostream<<"ServerEnvironment::clearAllObjects(): "
|
infostream<<"ServerEnvironment::clearAllObjects(): "
|
||||||
<<"Listing all loadable blocks"<<std::endl;
|
<<"Listing all loadable blocks"<<std::endl;
|
||||||
m_map->listAllLoadableBlocks(loadable_blocks);
|
m_map->listAllLoadableBlocks(loadable_blocks);
|
||||||
@ -937,8 +935,8 @@ void ServerEnvironment::clearAllObjects()
|
|||||||
u32 num_blocks_checked = 0;
|
u32 num_blocks_checked = 0;
|
||||||
u32 num_blocks_cleared = 0;
|
u32 num_blocks_cleared = 0;
|
||||||
u32 num_objs_cleared = 0;
|
u32 num_objs_cleared = 0;
|
||||||
for(core::list<v3s16>::Iterator i = loadable_blocks.begin();
|
for(std::list<v3s16>::iterator i = loadable_blocks.begin();
|
||||||
i != loadable_blocks.end(); i++)
|
i != loadable_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = *i;
|
v3s16 p = *i;
|
||||||
MapBlock *block = m_map->emergeBlock(p, false);
|
MapBlock *block = m_map->emergeBlock(p, false);
|
||||||
@ -1002,8 +1000,8 @@ void ServerEnvironment::step(float dtime)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_AVG);
|
ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_AVG);
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for(std::list<Player*>::iterator i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
|
|
||||||
@ -1027,10 +1025,10 @@ void ServerEnvironment::step(float dtime)
|
|||||||
/*
|
/*
|
||||||
Get player block positions
|
Get player block positions
|
||||||
*/
|
*/
|
||||||
core::list<v3s16> players_blockpos;
|
std::list<v3s16> players_blockpos;
|
||||||
for(core::list<Player*>::Iterator
|
for(std::list<Player*>::iterator
|
||||||
i = m_players.begin();
|
i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
// Ignore disconnected players
|
// Ignore disconnected players
|
||||||
@ -1045,8 +1043,8 @@ void ServerEnvironment::step(float dtime)
|
|||||||
Update list of active blocks, collecting changes
|
Update list of active blocks, collecting changes
|
||||||
*/
|
*/
|
||||||
const s16 active_block_range = g_settings->getS16("active_block_range");
|
const s16 active_block_range = g_settings->getS16("active_block_range");
|
||||||
core::map<v3s16, bool> blocks_removed;
|
std::set<v3s16> blocks_removed;
|
||||||
core::map<v3s16, bool> blocks_added;
|
std::set<v3s16> blocks_added;
|
||||||
m_active_blocks.update(players_blockpos, active_block_range,
|
m_active_blocks.update(players_blockpos, active_block_range,
|
||||||
blocks_removed, blocks_added);
|
blocks_removed, blocks_added);
|
||||||
|
|
||||||
@ -1057,11 +1055,11 @@ void ServerEnvironment::step(float dtime)
|
|||||||
// Convert active objects that are no more in active blocks to static
|
// Convert active objects that are no more in active blocks to static
|
||||||
deactivateFarObjects(false);
|
deactivateFarObjects(false);
|
||||||
|
|
||||||
for(core::map<v3s16, bool>::Iterator
|
for(std::set<v3s16>::iterator
|
||||||
i = blocks_removed.getIterator();
|
i = blocks_removed.begin();
|
||||||
i.atEnd()==false; i++)
|
i != blocks_removed.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = *i;
|
||||||
|
|
||||||
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
|
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
|
||||||
<<") became inactive"<<std::endl;*/
|
<<") became inactive"<<std::endl;*/
|
||||||
@ -1078,11 +1076,11 @@ void ServerEnvironment::step(float dtime)
|
|||||||
Handle added blocks
|
Handle added blocks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for(core::map<v3s16, bool>::Iterator
|
for(std::set<v3s16>::iterator
|
||||||
i = blocks_added.getIterator();
|
i = blocks_added.begin();
|
||||||
i.atEnd()==false; i++)
|
i != blocks_added.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = *i;
|
||||||
|
|
||||||
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
|
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
|
||||||
<<") became active"<<std::endl;*/
|
<<") became active"<<std::endl;*/
|
||||||
@ -1091,7 +1089,7 @@ void ServerEnvironment::step(float dtime)
|
|||||||
if(block==NULL){
|
if(block==NULL){
|
||||||
// Block needs to be fetched first
|
// Block needs to be fetched first
|
||||||
m_emerger->queueBlockEmerge(p, false);
|
m_emerger->queueBlockEmerge(p, false);
|
||||||
m_active_blocks.m_list.remove(p);
|
m_active_blocks.m_list.erase(p);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1108,11 +1106,11 @@ void ServerEnvironment::step(float dtime)
|
|||||||
|
|
||||||
float dtime = 1.0;
|
float dtime = 1.0;
|
||||||
|
|
||||||
for(core::map<v3s16, bool>::Iterator
|
for(std::set<v3s16>::iterator
|
||||||
i = m_active_blocks.m_list.getIterator();
|
i = m_active_blocks.m_list.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_blocks.m_list.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = *i;
|
||||||
|
|
||||||
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
|
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
|
||||||
<<") being handled"<<std::endl;*/
|
<<") being handled"<<std::endl;*/
|
||||||
@ -1163,11 +1161,11 @@ void ServerEnvironment::step(float dtime)
|
|||||||
// Initialize handling of ActiveBlockModifiers
|
// Initialize handling of ActiveBlockModifiers
|
||||||
ABMHandler abmhandler(m_abms, abm_interval, this, true);
|
ABMHandler abmhandler(m_abms, abm_interval, this, true);
|
||||||
|
|
||||||
for(core::map<v3s16, bool>::Iterator
|
for(std::set<v3s16>::iterator
|
||||||
i = m_active_blocks.m_list.getIterator();
|
i = m_active_blocks.m_list.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_blocks.m_list.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = *i;
|
||||||
|
|
||||||
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
|
/*infostream<<"Server: Block ("<<p.X<<","<<p.Y<<","<<p.Z
|
||||||
<<") being handled"<<std::endl;*/
|
<<") being handled"<<std::endl;*/
|
||||||
@ -1216,11 +1214,11 @@ void ServerEnvironment::step(float dtime)
|
|||||||
send_recommended = true;
|
send_recommended = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
for(std::map<u16, ServerActiveObject*>::iterator
|
||||||
i = m_active_objects.getIterator();
|
i = m_active_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
ServerActiveObject* obj = i.getNode()->getValue();
|
ServerActiveObject* obj = i->second;
|
||||||
// Remove non-peaceful mobs on peaceful mode
|
// Remove non-peaceful mobs on peaceful mode
|
||||||
if(g_settings->getBool("only_peaceful_mobs")){
|
if(g_settings->getBool("only_peaceful_mobs")){
|
||||||
if(!obj->isPeaceful())
|
if(!obj->isPeaceful())
|
||||||
@ -1232,7 +1230,7 @@ void ServerEnvironment::step(float dtime)
|
|||||||
// Step object
|
// Step object
|
||||||
obj->step(dtime, send_recommended);
|
obj->step(dtime, send_recommended);
|
||||||
// Read messages from object
|
// Read messages from object
|
||||||
while(obj->m_messages_out.size() > 0)
|
while(!obj->m_messages_out.empty())
|
||||||
{
|
{
|
||||||
m_active_object_messages.push_back(
|
m_active_object_messages.push_back(
|
||||||
obj->m_messages_out.pop_front());
|
obj->m_messages_out.pop_front());
|
||||||
@ -1255,31 +1253,24 @@ void ServerEnvironment::step(float dtime)
|
|||||||
|
|
||||||
ServerActiveObject* ServerEnvironment::getActiveObject(u16 id)
|
ServerActiveObject* ServerEnvironment::getActiveObject(u16 id)
|
||||||
{
|
{
|
||||||
core::map<u16, ServerActiveObject*>::Node *n;
|
std::map<u16, ServerActiveObject*>::iterator n;
|
||||||
n = m_active_objects.find(id);
|
n = m_active_objects.find(id);
|
||||||
if(n == NULL)
|
if(n == m_active_objects.end())
|
||||||
return NULL;
|
return NULL;
|
||||||
return n->getValue();
|
return n->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFreeServerActiveObjectId(u16 id,
|
bool isFreeServerActiveObjectId(u16 id,
|
||||||
core::map<u16, ServerActiveObject*> &objects)
|
std::map<u16, ServerActiveObject*> &objects)
|
||||||
{
|
{
|
||||||
if(id == 0)
|
if(id == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
return objects.find(id) == objects.end();
|
||||||
i = objects.getIterator();
|
|
||||||
i.atEnd()==false; i++)
|
|
||||||
{
|
|
||||||
if(i.getNode()->getKey() == id)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 getFreeServerActiveObjectId(
|
u16 getFreeServerActiveObjectId(
|
||||||
core::map<u16, ServerActiveObject*> &objects)
|
std::map<u16, ServerActiveObject*> &objects)
|
||||||
{
|
{
|
||||||
u16 new_id = 1;
|
u16 new_id = 1;
|
||||||
for(;;)
|
for(;;)
|
||||||
@ -1351,8 +1342,8 @@ bool ServerEnvironment::addActiveObjectAsStatic(ServerActiveObject *obj)
|
|||||||
inside a radius around a position
|
inside a radius around a position
|
||||||
*/
|
*/
|
||||||
void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
|
void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
|
||||||
core::map<u16, bool> ¤t_objects,
|
std::set<u16> ¤t_objects,
|
||||||
core::map<u16, bool> &added_objects)
|
std::set<u16> &added_objects)
|
||||||
{
|
{
|
||||||
v3f pos_f = intToFloat(pos, BS);
|
v3f pos_f = intToFloat(pos, BS);
|
||||||
f32 radius_f = radius * BS;
|
f32 radius_f = radius * BS;
|
||||||
@ -1363,13 +1354,13 @@ void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
|
|||||||
- discard objects that are found in current_objects.
|
- discard objects that are found in current_objects.
|
||||||
- add remaining objects to added_objects
|
- add remaining objects to added_objects
|
||||||
*/
|
*/
|
||||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
for(std::map<u16, ServerActiveObject*>::iterator
|
||||||
i = m_active_objects.getIterator();
|
i = m_active_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
u16 id = i.getNode()->getKey();
|
u16 id = i->first;
|
||||||
// Get object
|
// Get object
|
||||||
ServerActiveObject *object = i.getNode()->getValue();
|
ServerActiveObject *object = i->second;
|
||||||
if(object == NULL)
|
if(object == NULL)
|
||||||
continue;
|
continue;
|
||||||
// Discard if removed
|
// Discard if removed
|
||||||
@ -1382,12 +1373,12 @@ void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Discard if already on current_objects
|
// Discard if already on current_objects
|
||||||
core::map<u16, bool>::Node *n;
|
std::set<u16>::iterator n;
|
||||||
n = current_objects.find(id);
|
n = current_objects.find(id);
|
||||||
if(n != NULL)
|
if(n != current_objects.end())
|
||||||
continue;
|
continue;
|
||||||
// Add to added_objects
|
// Add to added_objects
|
||||||
added_objects.insert(id, false);
|
added_objects.insert(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1396,8 +1387,8 @@ void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
|
|||||||
inside a radius around a position
|
inside a radius around a position
|
||||||
*/
|
*/
|
||||||
void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
|
void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
|
||||||
core::map<u16, bool> ¤t_objects,
|
std::set<u16> ¤t_objects,
|
||||||
core::map<u16, bool> &removed_objects)
|
std::set<u16> &removed_objects)
|
||||||
{
|
{
|
||||||
v3f pos_f = intToFloat(pos, BS);
|
v3f pos_f = intToFloat(pos, BS);
|
||||||
f32 radius_f = radius * BS;
|
f32 radius_f = radius * BS;
|
||||||
@ -1409,23 +1400,23 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
|
|||||||
- object has m_removed=true, or
|
- object has m_removed=true, or
|
||||||
- object is too far away
|
- object is too far away
|
||||||
*/
|
*/
|
||||||
for(core::map<u16, bool>::Iterator
|
for(std::set<u16>::iterator
|
||||||
i = current_objects.getIterator();
|
i = current_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != current_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
u16 id = i.getNode()->getKey();
|
u16 id = *i;
|
||||||
ServerActiveObject *object = getActiveObject(id);
|
ServerActiveObject *object = getActiveObject(id);
|
||||||
|
|
||||||
if(object == NULL){
|
if(object == NULL){
|
||||||
infostream<<"ServerEnvironment::getRemovedActiveObjects():"
|
infostream<<"ServerEnvironment::getRemovedActiveObjects():"
|
||||||
<<" object in current_objects is NULL"<<std::endl;
|
<<" object in current_objects is NULL"<<std::endl;
|
||||||
removed_objects.insert(id, false);
|
removed_objects.insert(id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(object->m_removed)
|
if(object->m_removed)
|
||||||
{
|
{
|
||||||
removed_objects.insert(id, false);
|
removed_objects.insert(id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1437,7 +1428,7 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
|
|||||||
|
|
||||||
if(distance_f >= radius_f)
|
if(distance_f >= radius_f)
|
||||||
{
|
{
|
||||||
removed_objects.insert(id, false);
|
removed_objects.insert(id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1447,7 +1438,7 @@ void ServerEnvironment::getRemovedActiveObjects(v3s16 pos, s16 radius,
|
|||||||
|
|
||||||
ActiveObjectMessage ServerEnvironment::getActiveObjectMessage()
|
ActiveObjectMessage ServerEnvironment::getActiveObjectMessage()
|
||||||
{
|
{
|
||||||
if(m_active_object_messages.size() == 0)
|
if(m_active_object_messages.empty())
|
||||||
return ActiveObjectMessage(0);
|
return ActiveObjectMessage(0);
|
||||||
|
|
||||||
return m_active_object_messages.pop_front();
|
return m_active_object_messages.pop_front();
|
||||||
@ -1488,7 +1479,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
|
|||||||
/*infostream<<"ServerEnvironment::addActiveObjectRaw(): "
|
/*infostream<<"ServerEnvironment::addActiveObjectRaw(): "
|
||||||
<<"added (id="<<object->getId()<<")"<<std::endl;*/
|
<<"added (id="<<object->getId()<<")"<<std::endl;*/
|
||||||
|
|
||||||
m_active_objects.insert(object->getId(), object);
|
m_active_objects[object->getId()] = object;
|
||||||
|
|
||||||
verbosestream<<"ServerEnvironment::addActiveObjectRaw(): "
|
verbosestream<<"ServerEnvironment::addActiveObjectRaw(): "
|
||||||
<<"Added id="<<object->getId()<<"; there are now "
|
<<"Added id="<<object->getId()<<"; there are now "
|
||||||
@ -1512,7 +1503,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
|
|||||||
MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
|
MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
|
||||||
if(block)
|
if(block)
|
||||||
{
|
{
|
||||||
block->m_static_objects.m_active.insert(object->getId(), s_obj);
|
block->m_static_objects.m_active[object->getId()] = s_obj;
|
||||||
object->m_static_exists = true;
|
object->m_static_exists = true;
|
||||||
object->m_static_block = blockpos;
|
object->m_static_block = blockpos;
|
||||||
|
|
||||||
@ -1536,13 +1527,13 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
|
|||||||
*/
|
*/
|
||||||
void ServerEnvironment::removeRemovedObjects()
|
void ServerEnvironment::removeRemovedObjects()
|
||||||
{
|
{
|
||||||
core::list<u16> objects_to_remove;
|
std::list<u16> objects_to_remove;
|
||||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
for(std::map<u16, ServerActiveObject*>::iterator
|
||||||
i = m_active_objects.getIterator();
|
i = m_active_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
u16 id = i.getNode()->getKey();
|
u16 id = i->first;
|
||||||
ServerActiveObject* obj = i.getNode()->getValue();
|
ServerActiveObject* obj = i->second;
|
||||||
// This shouldn't happen but check it
|
// This shouldn't happen but check it
|
||||||
if(obj == NULL)
|
if(obj == NULL)
|
||||||
{
|
{
|
||||||
@ -1593,10 +1584,10 @@ void ServerEnvironment::removeRemovedObjects()
|
|||||||
objects_to_remove.push_back(id);
|
objects_to_remove.push_back(id);
|
||||||
}
|
}
|
||||||
// Remove references from m_active_objects
|
// Remove references from m_active_objects
|
||||||
for(core::list<u16>::Iterator i = objects_to_remove.begin();
|
for(std::list<u16>::iterator i = objects_to_remove.begin();
|
||||||
i != objects_to_remove.end(); i++)
|
i != objects_to_remove.end(); ++i)
|
||||||
{
|
{
|
||||||
m_active_objects.remove(*i);
|
m_active_objects.erase(*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1663,11 +1654,11 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
|
|||||||
}
|
}
|
||||||
// A list for objects that couldn't be converted to active for some
|
// A list for objects that couldn't be converted to active for some
|
||||||
// reason. They will be stored back.
|
// reason. They will be stored back.
|
||||||
core::list<StaticObject> new_stored;
|
std::list<StaticObject> new_stored;
|
||||||
// Loop through stored static objects
|
// Loop through stored static objects
|
||||||
for(core::list<StaticObject>::Iterator
|
for(std::list<StaticObject>::iterator
|
||||||
i = block->m_static_objects.m_stored.begin();
|
i = block->m_static_objects.m_stored.begin();
|
||||||
i != block->m_static_objects.m_stored.end(); i++)
|
i != block->m_static_objects.m_stored.end(); ++i)
|
||||||
{
|
{
|
||||||
/*infostream<<"Server: Creating an active object from "
|
/*infostream<<"Server: Creating an active object from "
|
||||||
<<"static data"<<std::endl;*/
|
<<"static data"<<std::endl;*/
|
||||||
@ -1696,9 +1687,9 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
|
|||||||
// Clear stored list
|
// Clear stored list
|
||||||
block->m_static_objects.m_stored.clear();
|
block->m_static_objects.m_stored.clear();
|
||||||
// Add leftover failed stuff to stored list
|
// Add leftover failed stuff to stored list
|
||||||
for(core::list<StaticObject>::Iterator
|
for(std::list<StaticObject>::iterator
|
||||||
i = new_stored.begin();
|
i = new_stored.begin();
|
||||||
i != new_stored.end(); i++)
|
i != new_stored.end(); ++i)
|
||||||
{
|
{
|
||||||
StaticObject &s_obj = *i;
|
StaticObject &s_obj = *i;
|
||||||
block->m_static_objects.m_stored.push_back(s_obj);
|
block->m_static_objects.m_stored.push_back(s_obj);
|
||||||
@ -1726,12 +1717,12 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
|
|||||||
*/
|
*/
|
||||||
void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
||||||
{
|
{
|
||||||
core::list<u16> objects_to_remove;
|
std::list<u16> objects_to_remove;
|
||||||
for(core::map<u16, ServerActiveObject*>::Iterator
|
for(std::map<u16, ServerActiveObject*>::iterator
|
||||||
i = m_active_objects.getIterator();
|
i = m_active_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
ServerActiveObject* obj = i.getNode()->getValue();
|
ServerActiveObject* obj = i->second;
|
||||||
assert(obj);
|
assert(obj);
|
||||||
|
|
||||||
// Do not deactivate if static data creation not allowed
|
// Do not deactivate if static data creation not allowed
|
||||||
@ -1742,7 +1733,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||||||
if(!force_delete && obj->m_pending_deactivation)
|
if(!force_delete && obj->m_pending_deactivation)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
u16 id = i.getNode()->getKey();
|
u16 id = i->first;
|
||||||
v3f objectpos = obj->getBasePosition();
|
v3f objectpos = obj->getBasePosition();
|
||||||
|
|
||||||
// The block in which the object resides in
|
// The block in which the object resides in
|
||||||
@ -1778,10 +1769,10 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||||||
|
|
||||||
MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
|
MapBlock *block = m_map->emergeBlock(obj->m_static_block, false);
|
||||||
|
|
||||||
core::map<u16, StaticObject>::Node *n =
|
std::map<u16, StaticObject>::iterator n =
|
||||||
block->m_static_objects.m_active.find(id);
|
block->m_static_objects.m_active.find(id);
|
||||||
if(n){
|
if(n != block->m_static_objects.m_active.end()){
|
||||||
StaticObject static_old = n->getValue();
|
StaticObject static_old = n->second;
|
||||||
|
|
||||||
float save_movem = obj->getMinimumSavedMovement();
|
float save_movem = obj->getMinimumSavedMovement();
|
||||||
|
|
||||||
@ -1840,7 +1831,7 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||||||
// This shouldn't happen, but happens rarely for some
|
// This shouldn't happen, but happens rarely for some
|
||||||
// unknown reason. Unsuccessful attempts have been made to
|
// unknown reason. Unsuccessful attempts have been made to
|
||||||
// find said reason.
|
// find said reason.
|
||||||
if(new_id && block->m_static_objects.m_active.find(new_id)){
|
if(new_id && block->m_static_objects.m_active.find(new_id) != block->m_static_objects.m_active.end()){
|
||||||
infostream<<"ServerEnv: WARNING: Performing hack #83274"
|
infostream<<"ServerEnv: WARNING: Performing hack #83274"
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
block->m_static_objects.remove(new_id);
|
block->m_static_objects.remove(new_id);
|
||||||
@ -1900,10 +1891,10 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove references from m_active_objects
|
// Remove references from m_active_objects
|
||||||
for(core::list<u16>::Iterator i = objects_to_remove.begin();
|
for(std::list<u16>::iterator i = objects_to_remove.begin();
|
||||||
i != objects_to_remove.end(); i++)
|
i != objects_to_remove.end(); ++i)
|
||||||
{
|
{
|
||||||
m_active_objects.remove(*i);
|
m_active_objects.erase(*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1930,15 +1921,15 @@ ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
|
|||||||
ClientEnvironment::~ClientEnvironment()
|
ClientEnvironment::~ClientEnvironment()
|
||||||
{
|
{
|
||||||
// delete active objects
|
// delete active objects
|
||||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
for(std::map<u16, ClientActiveObject*>::iterator
|
||||||
i = m_active_objects.getIterator();
|
i = m_active_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
delete i.getNode()->getValue();
|
delete i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(core::list<ClientSimpleObject*>::Iterator
|
for(std::list<ClientSimpleObject*>::iterator
|
||||||
i = m_simple_objects.begin(); i != m_simple_objects.end(); i++)
|
i = m_simple_objects.begin(); i != m_simple_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
delete *i;
|
delete *i;
|
||||||
}
|
}
|
||||||
@ -1971,8 +1962,8 @@ void ClientEnvironment::addPlayer(Player *player)
|
|||||||
|
|
||||||
LocalPlayer * ClientEnvironment::getLocalPlayer()
|
LocalPlayer * ClientEnvironment::getLocalPlayer()
|
||||||
{
|
{
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for(std::list<Player*>::iterator i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
if(player->isLocal())
|
if(player->isLocal())
|
||||||
@ -1996,7 +1987,7 @@ void ClientEnvironment::step(float dtime)
|
|||||||
LocalPlayer *lplayer = getLocalPlayer();
|
LocalPlayer *lplayer = getLocalPlayer();
|
||||||
assert(lplayer);
|
assert(lplayer);
|
||||||
// collision info queue
|
// collision info queue
|
||||||
core::list<CollisionInfo> player_collisions;
|
std::list<CollisionInfo> player_collisions;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get the speed the player is going
|
Get the speed the player is going
|
||||||
@ -2113,9 +2104,9 @@ void ClientEnvironment::step(float dtime)
|
|||||||
|
|
||||||
//std::cout<<"Looped "<<loopcount<<" times."<<std::endl;
|
//std::cout<<"Looped "<<loopcount<<" times."<<std::endl;
|
||||||
|
|
||||||
for(core::list<CollisionInfo>::Iterator
|
for(std::list<CollisionInfo>::iterator
|
||||||
i = player_collisions.begin();
|
i = player_collisions.begin();
|
||||||
i != player_collisions.end(); i++)
|
i != player_collisions.end(); ++i)
|
||||||
{
|
{
|
||||||
CollisionInfo &info = *i;
|
CollisionInfo &info = *i;
|
||||||
v3f speed_diff = info.new_speed - info.old_speed;;
|
v3f speed_diff = info.new_speed - info.old_speed;;
|
||||||
@ -2179,8 +2170,8 @@ void ClientEnvironment::step(float dtime)
|
|||||||
/*
|
/*
|
||||||
Stuff that can be done in an arbitarily large dtime
|
Stuff that can be done in an arbitarily large dtime
|
||||||
*/
|
*/
|
||||||
for(core::list<Player*>::Iterator i = m_players.begin();
|
for(std::list<Player*>::iterator i = m_players.begin();
|
||||||
i != m_players.end(); i++)
|
i != m_players.end(); ++i)
|
||||||
{
|
{
|
||||||
Player *player = *i;
|
Player *player = *i;
|
||||||
v3f playerpos = player->getPosition();
|
v3f playerpos = player->getPosition();
|
||||||
@ -2214,11 +2205,11 @@ void ClientEnvironment::step(float dtime)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
bool update_lighting = m_active_object_light_update_interval.step(dtime, 0.21);
|
bool update_lighting = m_active_object_light_update_interval.step(dtime, 0.21);
|
||||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
for(std::map<u16, ClientActiveObject*>::iterator
|
||||||
i = m_active_objects.getIterator();
|
i = m_active_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
ClientActiveObject* obj = i.getNode()->getValue();
|
ClientActiveObject* obj = i->second;
|
||||||
// Step object
|
// Step object
|
||||||
obj->step(dtime, this);
|
obj->step(dtime, this);
|
||||||
|
|
||||||
@ -2242,12 +2233,12 @@ void ClientEnvironment::step(float dtime)
|
|||||||
/*
|
/*
|
||||||
Step and handle simple objects
|
Step and handle simple objects
|
||||||
*/
|
*/
|
||||||
for(core::list<ClientSimpleObject*>::Iterator
|
for(std::list<ClientSimpleObject*>::iterator
|
||||||
i = m_simple_objects.begin(); i != m_simple_objects.end();)
|
i = m_simple_objects.begin(); i != m_simple_objects.end();)
|
||||||
{
|
{
|
||||||
ClientSimpleObject *simple = *i;
|
ClientSimpleObject *simple = *i;
|
||||||
core::list<ClientSimpleObject*>::Iterator cur = i;
|
std::list<ClientSimpleObject*>::iterator cur = i;
|
||||||
i++;
|
++i;
|
||||||
simple->step(dtime);
|
simple->step(dtime);
|
||||||
if(simple->m_to_be_removed){
|
if(simple->m_to_be_removed){
|
||||||
delete simple;
|
delete simple;
|
||||||
@ -2263,31 +2254,24 @@ void ClientEnvironment::addSimpleObject(ClientSimpleObject *simple)
|
|||||||
|
|
||||||
ClientActiveObject* ClientEnvironment::getActiveObject(u16 id)
|
ClientActiveObject* ClientEnvironment::getActiveObject(u16 id)
|
||||||
{
|
{
|
||||||
core::map<u16, ClientActiveObject*>::Node *n;
|
std::map<u16, ClientActiveObject*>::iterator n;
|
||||||
n = m_active_objects.find(id);
|
n = m_active_objects.find(id);
|
||||||
if(n == NULL)
|
if(n == m_active_objects.end())
|
||||||
return NULL;
|
return NULL;
|
||||||
return n->getValue();
|
return n->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFreeClientActiveObjectId(u16 id,
|
bool isFreeClientActiveObjectId(u16 id,
|
||||||
core::map<u16, ClientActiveObject*> &objects)
|
std::map<u16, ClientActiveObject*> &objects)
|
||||||
{
|
{
|
||||||
if(id == 0)
|
if(id == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
return objects.find(id) == objects.end();
|
||||||
i = objects.getIterator();
|
|
||||||
i.atEnd()==false; i++)
|
|
||||||
{
|
|
||||||
if(i.getNode()->getKey() == id)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 getFreeClientActiveObjectId(
|
u16 getFreeClientActiveObjectId(
|
||||||
core::map<u16, ClientActiveObject*> &objects)
|
std::map<u16, ClientActiveObject*> &objects)
|
||||||
{
|
{
|
||||||
u16 new_id = 1;
|
u16 new_id = 1;
|
||||||
for(;;)
|
for(;;)
|
||||||
@ -2326,7 +2310,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
|
|||||||
}
|
}
|
||||||
infostream<<"ClientEnvironment::addActiveObject(): "
|
infostream<<"ClientEnvironment::addActiveObject(): "
|
||||||
<<"added (id="<<object->getId()<<")"<<std::endl;
|
<<"added (id="<<object->getId()<<")"<<std::endl;
|
||||||
m_active_objects.insert(object->getId(), object);
|
m_active_objects[object->getId()] = object;
|
||||||
object->addToScene(m_smgr, m_texturesource, m_irr);
|
object->addToScene(m_smgr, m_texturesource, m_irr);
|
||||||
{ // Update lighting immediately
|
{ // Update lighting immediately
|
||||||
u8 light = 0;
|
u8 light = 0;
|
||||||
@ -2389,7 +2373,7 @@ void ClientEnvironment::removeActiveObject(u16 id)
|
|||||||
}
|
}
|
||||||
obj->removeFromScene(true);
|
obj->removeFromScene(true);
|
||||||
delete obj;
|
delete obj;
|
||||||
m_active_objects.remove(id);
|
m_active_objects.erase(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientEnvironment::processActiveObjectMessage(u16 id,
|
void ClientEnvironment::processActiveObjectMessage(u16 id,
|
||||||
@ -2445,13 +2429,13 @@ void ClientEnvironment::damageLocalPlayer(u8 damage, bool handle_hp)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void ClientEnvironment::getActiveObjects(v3f origin, f32 max_d,
|
void ClientEnvironment::getActiveObjects(v3f origin, f32 max_d,
|
||||||
core::array<DistanceSortedActiveObject> &dest)
|
std::vector<DistanceSortedActiveObject> &dest)
|
||||||
{
|
{
|
||||||
for(core::map<u16, ClientActiveObject*>::Iterator
|
for(std::map<u16, ClientActiveObject*>::iterator
|
||||||
i = m_active_objects.getIterator();
|
i = m_active_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
ClientActiveObject* obj = i.getNode()->getValue();
|
ClientActiveObject* obj = i->second;
|
||||||
|
|
||||||
f32 d = (obj->getPosition() - origin).getLength();
|
f32 d = (obj->getPosition() - origin).getLength();
|
||||||
|
|
||||||
@ -2466,7 +2450,7 @@ void ClientEnvironment::getActiveObjects(v3f origin, f32 max_d,
|
|||||||
|
|
||||||
ClientEnvEvent ClientEnvironment::getClientEvent()
|
ClientEnvEvent ClientEnvironment::getClientEvent()
|
||||||
{
|
{
|
||||||
if(m_client_event_queue.size() == 0)
|
if(m_client_event_queue.empty())
|
||||||
{
|
{
|
||||||
ClientEnvEvent event;
|
ClientEnvEvent event;
|
||||||
event.type = CEE_NONE;
|
event.type = CEE_NONE;
|
||||||
|
@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <list>
|
||||||
#include "irrlichttypes_extrabloated.h"
|
#include "irrlichttypes_extrabloated.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@ -73,8 +74,8 @@ public:
|
|||||||
Player * getPlayer(const char *name);
|
Player * getPlayer(const char *name);
|
||||||
Player * getRandomConnectedPlayer();
|
Player * getRandomConnectedPlayer();
|
||||||
Player * getNearestConnectedPlayer(v3f pos);
|
Player * getNearestConnectedPlayer(v3f pos);
|
||||||
core::list<Player*> getPlayers();
|
std::list<Player*> getPlayers();
|
||||||
core::list<Player*> getPlayers(bool ignore_disconnected);
|
std::list<Player*> getPlayers(bool ignore_disconnected);
|
||||||
void printPlayers(std::ostream &o);
|
void printPlayers(std::ostream &o);
|
||||||
|
|
||||||
u32 getDayNightRatio();
|
u32 getDayNightRatio();
|
||||||
@ -102,7 +103,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// peer_ids in here should be unique, except that there may be many 0s
|
// peer_ids in here should be unique, except that there may be many 0s
|
||||||
core::list<Player*> m_players;
|
std::list<Player*> m_players;
|
||||||
// Time of day in milli-hours (0-23999); determines day and night
|
// Time of day in milli-hours (0-23999); determines day and night
|
||||||
u32 m_time_of_day;
|
u32 m_time_of_day;
|
||||||
// Time of day in 0...1
|
// Time of day in 0...1
|
||||||
@ -156,20 +157,20 @@ struct ABMWithState
|
|||||||
class ActiveBlockList
|
class ActiveBlockList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void update(core::list<v3s16> &active_positions,
|
void update(std::list<v3s16> &active_positions,
|
||||||
s16 radius,
|
s16 radius,
|
||||||
core::map<v3s16, bool> &blocks_removed,
|
std::set<v3s16> &blocks_removed,
|
||||||
core::map<v3s16, bool> &blocks_added);
|
std::set<v3s16> &blocks_added);
|
||||||
|
|
||||||
bool contains(v3s16 p){
|
bool contains(v3s16 p){
|
||||||
return (m_list.find(p) != NULL);
|
return (m_list.find(p) != m_list.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear(){
|
void clear(){
|
||||||
m_list.clear();
|
m_list.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
core::map<v3s16, bool> m_list;
|
std::set<v3s16> m_list;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
@ -249,16 +250,16 @@ public:
|
|||||||
inside a radius around a position
|
inside a radius around a position
|
||||||
*/
|
*/
|
||||||
void getAddedActiveObjects(v3s16 pos, s16 radius,
|
void getAddedActiveObjects(v3s16 pos, s16 radius,
|
||||||
core::map<u16, bool> ¤t_objects,
|
std::set<u16> ¤t_objects,
|
||||||
core::map<u16, bool> &added_objects);
|
std::set<u16> &added_objects);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Find out what new objects have been removed from
|
Find out what new objects have been removed from
|
||||||
inside a radius around a position
|
inside a radius around a position
|
||||||
*/
|
*/
|
||||||
void getRemovedActiveObjects(v3s16 pos, s16 radius,
|
void getRemovedActiveObjects(v3s16 pos, s16 radius,
|
||||||
core::map<u16, bool> ¤t_objects,
|
std::set<u16> ¤t_objects,
|
||||||
core::map<u16, bool> &removed_objects);
|
std::set<u16> &removed_objects);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get the next message emitted by some active object.
|
Get the next message emitted by some active object.
|
||||||
@ -350,7 +351,7 @@ private:
|
|||||||
// Background block emerger (the server, in practice)
|
// Background block emerger (the server, in practice)
|
||||||
IBackgroundBlockEmerger *m_emerger;
|
IBackgroundBlockEmerger *m_emerger;
|
||||||
// Active object list
|
// Active object list
|
||||||
core::map<u16, ServerActiveObject*> m_active_objects;
|
std::map<u16, ServerActiveObject*> m_active_objects;
|
||||||
// Outgoing network message buffer for active objects
|
// Outgoing network message buffer for active objects
|
||||||
Queue<ActiveObjectMessage> m_active_object_messages;
|
Queue<ActiveObjectMessage> m_active_object_messages;
|
||||||
// Some timers
|
// Some timers
|
||||||
@ -368,7 +369,7 @@ private:
|
|||||||
u32 m_game_time;
|
u32 m_game_time;
|
||||||
// A helper variable for incrementing the latter
|
// A helper variable for incrementing the latter
|
||||||
float m_game_time_fraction_counter;
|
float m_game_time_fraction_counter;
|
||||||
core::list<ABMWithState> m_abms;
|
std::list<ABMWithState> m_abms;
|
||||||
// An interval for generally sending object positions and stuff
|
// An interval for generally sending object positions and stuff
|
||||||
float m_recommended_send_interval;
|
float m_recommended_send_interval;
|
||||||
};
|
};
|
||||||
@ -463,7 +464,7 @@ public:
|
|||||||
|
|
||||||
// Get all nearby objects
|
// Get all nearby objects
|
||||||
void getActiveObjects(v3f origin, f32 max_d,
|
void getActiveObjects(v3f origin, f32 max_d,
|
||||||
core::array<DistanceSortedActiveObject> &dest);
|
std::vector<DistanceSortedActiveObject> &dest);
|
||||||
|
|
||||||
// Get event from queue. CEE_NONE is returned if queue is empty.
|
// Get event from queue. CEE_NONE is returned if queue is empty.
|
||||||
ClientEnvEvent getClientEvent();
|
ClientEnvEvent getClientEvent();
|
||||||
@ -476,8 +477,8 @@ private:
|
|||||||
ITextureSource *m_texturesource;
|
ITextureSource *m_texturesource;
|
||||||
IGameDef *m_gamedef;
|
IGameDef *m_gamedef;
|
||||||
IrrlichtDevice *m_irr;
|
IrrlichtDevice *m_irr;
|
||||||
core::map<u16, ClientActiveObject*> m_active_objects;
|
std::map<u16, ClientActiveObject*> m_active_objects;
|
||||||
core::list<ClientSimpleObject*> m_simple_objects;
|
std::list<ClientSimpleObject*> m_simple_objects;
|
||||||
Queue<ClientEnvEvent> m_client_event_queue;
|
Queue<ClientEnvEvent> m_client_event_queue;
|
||||||
IntervalLimiter m_active_object_light_update_interval;
|
IntervalLimiter m_active_object_light_update_interval;
|
||||||
IntervalLimiter m_lava_hurt_interval;
|
IntervalLimiter m_lava_hurt_interval;
|
||||||
|
@ -112,13 +112,13 @@ struct HeightPoint
|
|||||||
float have_sand;
|
float have_sand;
|
||||||
float tree_amount;
|
float tree_amount;
|
||||||
};
|
};
|
||||||
core::map<v2s16, HeightPoint> g_heights;
|
std::map<v2s16, HeightPoint> g_heights;
|
||||||
|
|
||||||
HeightPoint ground_height(u64 seed, v2s16 p2d)
|
HeightPoint ground_height(u64 seed, v2s16 p2d)
|
||||||
{
|
{
|
||||||
core::map<v2s16, HeightPoint>::Node *n = g_heights.find(p2d);
|
std::map<v2s16, HeightPoint>::iterator n = g_heights.find(p2d);
|
||||||
if(n)
|
if(n != g_heights.end())
|
||||||
return n->getValue();
|
return n->second;
|
||||||
HeightPoint hp;
|
HeightPoint hp;
|
||||||
s16 level = Mapgen::find_ground_level_from_noise(seed, p2d, 3);
|
s16 level = Mapgen::find_ground_level_from_noise(seed, p2d, 3);
|
||||||
hp.gh = (level-4)*BS;
|
hp.gh = (level-4)*BS;
|
||||||
|
25
src/game.h
25
src/game.h
@ -23,17 +23,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "irrlichttypes_extrabloated.h"
|
#include "irrlichttypes_extrabloated.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
|
#include <list>
|
||||||
|
|
||||||
class KeyList : protected core::list<KeyPress>
|
class KeyList : protected std::list<KeyPress>
|
||||||
{
|
{
|
||||||
typedef core::list<KeyPress> super;
|
typedef std::list<KeyPress> super;
|
||||||
typedef super::Iterator Iterator;
|
typedef super::iterator iterator;
|
||||||
typedef super::ConstIterator ConstIterator;
|
typedef super::const_iterator const_iterator;
|
||||||
|
|
||||||
virtual ConstIterator find(const KeyPress &key) const
|
virtual const_iterator find(const KeyPress &key) const
|
||||||
{
|
{
|
||||||
ConstIterator f(begin());
|
const_iterator f(begin());
|
||||||
ConstIterator e(end());
|
const_iterator e(end());
|
||||||
while (f!=e) {
|
while (f!=e) {
|
||||||
if (*f == key)
|
if (*f == key)
|
||||||
return f;
|
return f;
|
||||||
@ -42,10 +43,10 @@ class KeyList : protected core::list<KeyPress>
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Iterator find(const KeyPress &key)
|
virtual iterator find(const KeyPress &key)
|
||||||
{
|
{
|
||||||
Iterator f(begin());
|
iterator f(begin());
|
||||||
Iterator e(end());
|
iterator e(end());
|
||||||
while (f!=e) {
|
while (f!=e) {
|
||||||
if (*f == key)
|
if (*f == key)
|
||||||
return f;
|
return f;
|
||||||
@ -65,14 +66,14 @@ public:
|
|||||||
|
|
||||||
void unset(const KeyPress &key)
|
void unset(const KeyPress &key)
|
||||||
{
|
{
|
||||||
Iterator p(find(key));
|
iterator p(find(key));
|
||||||
if (p != end())
|
if (p != end())
|
||||||
erase(p);
|
erase(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggle(const KeyPress &key)
|
void toggle(const KeyPress &key)
|
||||||
{
|
{
|
||||||
Iterator p(this->find(key));
|
iterator p(this->find(key));
|
||||||
if (p != end())
|
if (p != end())
|
||||||
erase(p);
|
erase(p);
|
||||||
else
|
else
|
||||||
|
@ -535,7 +535,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
|
|||||||
{
|
{
|
||||||
// Tab or Shift-Tab pressed
|
// Tab or Shift-Tab pressed
|
||||||
// Nick completion
|
// Nick completion
|
||||||
core::list<std::wstring> names = m_client->getConnectedPlayerNames();
|
std::list<std::wstring> names = m_client->getConnectedPlayerNames();
|
||||||
bool backwards = event.KeyInput.Shift;
|
bool backwards = event.KeyInput.Shift;
|
||||||
m_chat_backend->getPrompt().nickCompletion(names, backwards);
|
m_chat_backend->getPrompt().nickCompletion(names, backwards);
|
||||||
return true;
|
return true;
|
||||||
|
@ -209,11 +209,11 @@ protected:
|
|||||||
IFormSource *m_form_src;
|
IFormSource *m_form_src;
|
||||||
TextDest *m_text_dst;
|
TextDest *m_text_dst;
|
||||||
|
|
||||||
core::array<ListDrawSpec> m_inventorylists;
|
std::vector<ListDrawSpec> m_inventorylists;
|
||||||
core::array<ImageDrawSpec> m_backgrounds;
|
std::vector<ImageDrawSpec> m_backgrounds;
|
||||||
core::array<ImageDrawSpec> m_images;
|
std::vector<ImageDrawSpec> m_images;
|
||||||
core::array<ImageDrawSpec> m_itemimages;
|
std::vector<ImageDrawSpec> m_itemimages;
|
||||||
core::array<FieldSpec> m_fields;
|
std::vector<FieldSpec> m_fields;
|
||||||
|
|
||||||
ItemSpec *m_selected_item;
|
ItemSpec *m_selected_item;
|
||||||
u32 m_selected_amount;
|
u32 m_selected_amount;
|
||||||
|
@ -211,8 +211,8 @@ public:
|
|||||||
virtual ~CItemDefManager()
|
virtual ~CItemDefManager()
|
||||||
{
|
{
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
const core::list<ClientCached*> &values = m_clientcached.getValues();
|
const std::list<ClientCached*> &values = m_clientcached.getValues();
|
||||||
for(core::list<ClientCached*>::ConstIterator
|
for(std::list<ClientCached*>::const_iterator
|
||||||
i = values.begin(); i != values.end(); ++i)
|
i = values.begin(); i != values.end(); ++i)
|
||||||
{
|
{
|
||||||
ClientCached *cc = *i;
|
ClientCached *cc = *i;
|
||||||
@ -599,7 +599,7 @@ public:
|
|||||||
void processQueue(IGameDef *gamedef)
|
void processQueue(IGameDef *gamedef)
|
||||||
{
|
{
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
while(m_get_clientcached_queue.size() > 0)
|
while(!m_get_clientcached_queue.empty())
|
||||||
{
|
{
|
||||||
GetRequest<std::string, ClientCached*, u8, u8>
|
GetRequest<std::string, ClientCached*, u8, u8>
|
||||||
request = m_get_clientcached_queue.pop();
|
request = m_get_clientcached_queue.pop();
|
||||||
|
@ -345,17 +345,16 @@ const KeyPress NumberKey[] = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// A simple cache for quicker lookup
|
// A simple cache for quicker lookup
|
||||||
core::map<std::string, KeyPress> g_key_setting_cache;
|
std::map<std::string, KeyPress> g_key_setting_cache;
|
||||||
|
|
||||||
KeyPress getKeySetting(const char *settingname)
|
KeyPress getKeySetting(const char *settingname)
|
||||||
{
|
{
|
||||||
core::map<std::string, KeyPress>::Node *n;
|
std::map<std::string, KeyPress>::iterator n;
|
||||||
n = g_key_setting_cache.find(settingname);
|
n = g_key_setting_cache.find(settingname);
|
||||||
if(n)
|
if(n != g_key_setting_cache.end())
|
||||||
return n->getValue();
|
return n->second;
|
||||||
g_key_setting_cache.insert(settingname,
|
g_key_setting_cache[settingname] = g_settings->get(settingname).c_str();
|
||||||
g_settings->get(settingname).c_str());
|
return g_key_setting_cache.find(settingname)->second;
|
||||||
return g_key_setting_cache.find(settingname)->getValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearKeyCache()
|
void clearKeyCache()
|
||||||
|
@ -58,7 +58,7 @@ LocalPlayer::~LocalPlayer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
|
void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
|
||||||
core::list<CollisionInfo> *collision_info)
|
std::list<CollisionInfo> *collision_info)
|
||||||
{
|
{
|
||||||
INodeDefManager *nodemgr = m_gamedef->ndef();
|
INodeDefManager *nodemgr = m_gamedef->ndef();
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#define LOCALPLAYER_HEADER
|
#define LOCALPLAYER_HEADER
|
||||||
|
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include <list>
|
||||||
|
|
||||||
class LocalPlayer : public Player
|
class LocalPlayer : public Player
|
||||||
{
|
{
|
||||||
@ -38,7 +39,7 @@ public:
|
|||||||
v3f overridePosition;
|
v3f overridePosition;
|
||||||
|
|
||||||
void move(f32 dtime, Map &map, f32 pos_max_d,
|
void move(f32 dtime, Map &map, f32 pos_max_d,
|
||||||
core::list<CollisionInfo> *collision_info);
|
std::list<CollisionInfo> *collision_info);
|
||||||
void move(f32 dtime, Map &map, f32 pos_max_d);
|
void move(f32 dtime, Map &map, f32 pos_max_d);
|
||||||
|
|
||||||
void applyControl(float dtime);
|
void applyControl(float dtime);
|
||||||
|
104
src/main.cpp
104
src/main.cpp
@ -700,14 +700,14 @@ void SpeedTests()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
TimeTaker timer("Testing core::map speed");
|
TimeTaker timer("Testing std::map speed");
|
||||||
|
|
||||||
core::map<v2s16, f32> map1;
|
std::map<v2s16, f32> map1;
|
||||||
tempf = -324;
|
tempf = -324;
|
||||||
const s16 ii=300;
|
const s16 ii=300;
|
||||||
for(s16 y=0; y<ii; y++){
|
for(s16 y=0; y<ii; y++){
|
||||||
for(s16 x=0; x<ii; x++){
|
for(s16 x=0; x<ii; x++){
|
||||||
map1.insert(v2s16(x,y), tempf);
|
map1[v2s16(x,y)] = tempf;
|
||||||
tempf += 1;
|
tempf += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -788,48 +788,48 @@ int main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// List all allowed options
|
// List all allowed options
|
||||||
core::map<std::string, ValueSpec> allowed_options;
|
std::map<std::string, ValueSpec> allowed_options;
|
||||||
allowed_options.insert("help", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("help", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Show allowed options")));
|
_("Show allowed options"))));
|
||||||
allowed_options.insert("config", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("config", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Load configuration from specified file")));
|
_("Load configuration from specified file"))));
|
||||||
allowed_options.insert("port", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("port", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Set network port (UDP)")));
|
_("Set network port (UDP)"))));
|
||||||
allowed_options.insert("disable-unittests", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("disable-unittests", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Disable unit tests")));
|
_("Disable unit tests"))));
|
||||||
allowed_options.insert("enable-unittests", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("enable-unittests", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Enable unit tests")));
|
_("Enable unit tests"))));
|
||||||
allowed_options.insert("map-dir", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("map-dir", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Same as --world (deprecated)")));
|
_("Same as --world (deprecated)"))));
|
||||||
allowed_options.insert("world", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("world", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Set world path (implies local game) ('list' lists all)")));
|
_("Set world path (implies local game) ('list' lists all)"))));
|
||||||
allowed_options.insert("worldname", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("worldname", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Set world by name (implies local game)")));
|
_("Set world by name (implies local game)"))));
|
||||||
allowed_options.insert("info", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("info", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Print more information to console")));
|
_("Print more information to console"))));
|
||||||
allowed_options.insert("verbose", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("verbose", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Print even more information to console")));
|
_("Print even more information to console"))));
|
||||||
allowed_options.insert("trace", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("trace", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Print enormous amounts of information to log and console")));
|
_("Print enormous amounts of information to log and console"))));
|
||||||
allowed_options.insert("logfile", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("logfile", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Set logfile path ('' = no logging)")));
|
_("Set logfile path ('' = no logging)"))));
|
||||||
allowed_options.insert("gameid", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("gameid", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Set gameid (\"--gameid list\" prints available ones)")));
|
_("Set gameid (\"--gameid list\" prints available ones)"))));
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
allowed_options.insert("speedtests", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("speedtests", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Run speed tests")));
|
_("Run speed tests"))));
|
||||||
allowed_options.insert("address", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("address", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Address to connect to. ('' = local game)")));
|
_("Address to connect to. ('' = local game)"))));
|
||||||
allowed_options.insert("random-input", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("random-input", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Enable random user input, for testing")));
|
_("Enable random user input, for testing"))));
|
||||||
allowed_options.insert("server", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("server", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Run dedicated server")));
|
_("Run dedicated server"))));
|
||||||
allowed_options.insert("name", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("name", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Set player name")));
|
_("Set player name"))));
|
||||||
allowed_options.insert("password", ValueSpec(VALUETYPE_STRING,
|
allowed_options.insert(std::make_pair("password", ValueSpec(VALUETYPE_STRING,
|
||||||
_("Set password")));
|
_("Set password"))));
|
||||||
allowed_options.insert("go", ValueSpec(VALUETYPE_FLAG,
|
allowed_options.insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG,
|
||||||
_("Disable main menu")));
|
_("Disable main menu"))));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Settings cmd_args;
|
Settings cmd_args;
|
||||||
@ -839,20 +839,20 @@ int main(int argc, char *argv[])
|
|||||||
if(ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1"))
|
if(ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1"))
|
||||||
{
|
{
|
||||||
dstream<<_("Allowed options:")<<std::endl;
|
dstream<<_("Allowed options:")<<std::endl;
|
||||||
for(core::map<std::string, ValueSpec>::Iterator
|
for(std::map<std::string, ValueSpec>::iterator
|
||||||
i = allowed_options.getIterator();
|
i = allowed_options.begin();
|
||||||
i.atEnd() == false; i++)
|
i != allowed_options.end(); ++i)
|
||||||
{
|
{
|
||||||
std::ostringstream os1(std::ios::binary);
|
std::ostringstream os1(std::ios::binary);
|
||||||
os1<<" --"<<i.getNode()->getKey();
|
os1<<" --"<<i->first;
|
||||||
if(i.getNode()->getValue().type == VALUETYPE_FLAG)
|
if(i->second.type == VALUETYPE_FLAG)
|
||||||
{}
|
{}
|
||||||
else
|
else
|
||||||
os1<<_(" <value>");
|
os1<<_(" <value>");
|
||||||
dstream<<padStringRight(os1.str(), 24);
|
dstream<<padStringRight(os1.str(), 24);
|
||||||
|
|
||||||
if(i.getNode()->getValue().help != NULL)
|
if(i->second.help != NULL)
|
||||||
dstream<<i.getNode()->getValue().help;
|
dstream<<i->second.help;
|
||||||
dstream<<std::endl;
|
dstream<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -953,7 +953,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
core::array<std::string> filenames;
|
std::vector<std::string> filenames;
|
||||||
filenames.push_back(porting::path_user +
|
filenames.push_back(porting::path_user +
|
||||||
DIR_DELIM + "minetest.conf");
|
DIR_DELIM + "minetest.conf");
|
||||||
// Legacy configuration file location
|
// Legacy configuration file location
|
||||||
|
@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "debug.h" // assert
|
#include "debug.h" // assert
|
||||||
#include "modalMenu.h"
|
#include "modalMenu.h"
|
||||||
#include "guiPauseMenu.h" //For IGameCallback
|
#include "guiPauseMenu.h" //For IGameCallback
|
||||||
|
#include <list>
|
||||||
|
|
||||||
extern gui::IGUIEnvironment* guienv;
|
extern gui::IGUIEnvironment* guienv;
|
||||||
extern gui::IGUIStaticText *guiroot;
|
extern gui::IGUIStaticText *guiroot;
|
||||||
@ -37,15 +38,15 @@ class MainMenuManager : public IMenuManager
|
|||||||
public:
|
public:
|
||||||
virtual void createdMenu(GUIModalMenu *menu)
|
virtual void createdMenu(GUIModalMenu *menu)
|
||||||
{
|
{
|
||||||
for(core::list<GUIModalMenu*>::Iterator
|
for(std::list<GUIModalMenu*>::iterator
|
||||||
i = m_stack.begin();
|
i = m_stack.begin();
|
||||||
i != m_stack.end(); i++)
|
i != m_stack.end(); ++i)
|
||||||
{
|
{
|
||||||
assert(*i != menu);
|
assert(*i != menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_stack.size() != 0)
|
if(m_stack.size() != 0)
|
||||||
(*m_stack.getLast())->setVisible(false);
|
m_stack.back()->setVisible(false);
|
||||||
m_stack.push_back(menu);
|
m_stack.push_back(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,9 +56,9 @@ public:
|
|||||||
bool removed_entry;
|
bool removed_entry;
|
||||||
do{
|
do{
|
||||||
removed_entry = false;
|
removed_entry = false;
|
||||||
for(core::list<GUIModalMenu*>::Iterator
|
for(std::list<GUIModalMenu*>::iterator
|
||||||
i = m_stack.begin();
|
i = m_stack.begin();
|
||||||
i != m_stack.end(); i++)
|
i != m_stack.end(); ++i)
|
||||||
{
|
{
|
||||||
if(*i == menu)
|
if(*i == menu)
|
||||||
{
|
{
|
||||||
@ -73,7 +74,7 @@ public:
|
|||||||
m_stack.erase(i);*/
|
m_stack.erase(i);*/
|
||||||
|
|
||||||
if(m_stack.size() != 0)
|
if(m_stack.size() != 0)
|
||||||
(*m_stack.getLast())->setVisible(true);
|
m_stack.back()->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 menuCount()
|
u32 menuCount()
|
||||||
@ -81,7 +82,7 @@ public:
|
|||||||
return m_stack.size();
|
return m_stack.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<GUIModalMenu*> m_stack;
|
std::list<GUIModalMenu*> m_stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MainMenuManager g_menumgr;
|
extern MainMenuManager g_menumgr;
|
||||||
|
308
src/map.cpp
308
src/map.cpp
@ -73,34 +73,30 @@ Map::~Map()
|
|||||||
/*
|
/*
|
||||||
Free all MapSectors
|
Free all MapSectors
|
||||||
*/
|
*/
|
||||||
core::map<v2s16, MapSector*>::Iterator i = m_sectors.getIterator();
|
for(std::map<v2s16, MapSector*>::iterator i = m_sectors.begin();
|
||||||
for(; i.atEnd() == false; i++)
|
i != m_sectors.end(); ++i)
|
||||||
{
|
{
|
||||||
MapSector *sector = i.getNode()->getValue();
|
delete i->second;
|
||||||
delete sector;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::addEventReceiver(MapEventReceiver *event_receiver)
|
void Map::addEventReceiver(MapEventReceiver *event_receiver)
|
||||||
{
|
{
|
||||||
m_event_receivers.insert(event_receiver, false);
|
m_event_receivers.insert(event_receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::removeEventReceiver(MapEventReceiver *event_receiver)
|
void Map::removeEventReceiver(MapEventReceiver *event_receiver)
|
||||||
{
|
{
|
||||||
if(m_event_receivers.find(event_receiver) == NULL)
|
m_event_receivers.erase(event_receiver);
|
||||||
return;
|
|
||||||
m_event_receivers.remove(event_receiver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::dispatchEvent(MapEditEvent *event)
|
void Map::dispatchEvent(MapEditEvent *event)
|
||||||
{
|
{
|
||||||
for(core::map<MapEventReceiver*, bool>::Iterator
|
for(std::set<MapEventReceiver*>::iterator
|
||||||
i = m_event_receivers.getIterator();
|
i = m_event_receivers.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_event_receivers.end(); ++i)
|
||||||
{
|
{
|
||||||
MapEventReceiver* event_receiver = i.getNode()->getKey();
|
(*i)->onMapEditEvent(event);
|
||||||
event_receiver->onMapEditEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,12 +107,12 @@ MapSector * Map::getSectorNoGenerateNoExNoLock(v2s16 p)
|
|||||||
return sector;
|
return sector;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::map<v2s16, MapSector*>::Node *n = m_sectors.find(p);
|
std::map<v2s16, MapSector*>::iterator n = m_sectors.find(p);
|
||||||
|
|
||||||
if(n == NULL)
|
if(n == m_sectors.end())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
MapSector *sector = n->getValue();
|
MapSector *sector = n->second;
|
||||||
|
|
||||||
// Cache the last result
|
// Cache the last result
|
||||||
m_sector_cache_p = p;
|
m_sector_cache_p = p;
|
||||||
@ -236,9 +232,9 @@ void Map::setNode(v3s16 p, MapNode & n)
|
|||||||
values of from_nodes are lighting values.
|
values of from_nodes are lighting values.
|
||||||
*/
|
*/
|
||||||
void Map::unspreadLight(enum LightBank bank,
|
void Map::unspreadLight(enum LightBank bank,
|
||||||
core::map<v3s16, u8> & from_nodes,
|
std::map<v3s16, u8> & from_nodes,
|
||||||
core::map<v3s16, bool> & light_sources,
|
std::set<v3s16> & light_sources,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks)
|
std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
INodeDefManager *nodemgr = m_gamedef->ndef();
|
INodeDefManager *nodemgr = m_gamedef->ndef();
|
||||||
|
|
||||||
@ -256,9 +252,7 @@ void Map::unspreadLight(enum LightBank bank,
|
|||||||
|
|
||||||
u32 blockchangecount = 0;
|
u32 blockchangecount = 0;
|
||||||
|
|
||||||
core::map<v3s16, u8> unlighted_nodes;
|
std::map<v3s16, u8> unlighted_nodes;
|
||||||
core::map<v3s16, u8>::Iterator j;
|
|
||||||
j = from_nodes.getIterator();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Initialize block cache
|
Initialize block cache
|
||||||
@ -268,9 +262,10 @@ void Map::unspreadLight(enum LightBank bank,
|
|||||||
// Cache this a bit, too
|
// Cache this a bit, too
|
||||||
bool block_checked_in_modified = false;
|
bool block_checked_in_modified = false;
|
||||||
|
|
||||||
for(; j.atEnd() == false; j++)
|
for(std::map<v3s16, u8>::iterator j = from_nodes.begin();
|
||||||
|
j != from_nodes.end(); ++j)
|
||||||
{
|
{
|
||||||
v3s16 pos = j.getNode()->getKey();
|
v3s16 pos = j->first;
|
||||||
v3s16 blockpos = getNodeBlockPos(pos);
|
v3s16 blockpos = getNodeBlockPos(pos);
|
||||||
|
|
||||||
// Only fetch a new block if the block position has changed
|
// Only fetch a new block if the block position has changed
|
||||||
@ -297,7 +292,7 @@ void Map::unspreadLight(enum LightBank bank,
|
|||||||
// Get node straight from the block
|
// Get node straight from the block
|
||||||
MapNode n = block->getNode(relpos);
|
MapNode n = block->getNode(relpos);
|
||||||
|
|
||||||
u8 oldlight = j.getNode()->getValue();
|
u8 oldlight = j->second;
|
||||||
|
|
||||||
// Loop through 6 neighbors
|
// Loop through 6 neighbors
|
||||||
for(u16 i=0; i<6; i++)
|
for(u16 i=0; i<6; i++)
|
||||||
@ -354,7 +349,7 @@ void Map::unspreadLight(enum LightBank bank,
|
|||||||
n2.setLight(bank, 0, nodemgr);
|
n2.setLight(bank, 0, nodemgr);
|
||||||
block->setNode(relpos, n2);
|
block->setNode(relpos, n2);
|
||||||
|
|
||||||
unlighted_nodes.insert(n2pos, current_light);
|
unlighted_nodes[n2pos] = current_light;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -373,16 +368,16 @@ void Map::unspreadLight(enum LightBank bank,
|
|||||||
light_sources.remove(n2pos);*/
|
light_sources.remove(n2pos);*/
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
light_sources.insert(n2pos, true);
|
light_sources.insert(n2pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to modified_blocks
|
// Add to modified_blocks
|
||||||
if(changed == true && block_checked_in_modified == false)
|
if(changed == true && block_checked_in_modified == false)
|
||||||
{
|
{
|
||||||
// If the block is not found in modified_blocks, add.
|
// If the block is not found in modified_blocks, add.
|
||||||
if(modified_blocks.find(blockpos) == NULL)
|
if(modified_blocks.find(blockpos) == modified_blocks.end())
|
||||||
{
|
{
|
||||||
modified_blocks.insert(blockpos, block);
|
modified_blocks[blockpos] = block;
|
||||||
}
|
}
|
||||||
block_checked_in_modified = true;
|
block_checked_in_modified = true;
|
||||||
}
|
}
|
||||||
@ -408,11 +403,11 @@ void Map::unspreadLight(enum LightBank bank,
|
|||||||
*/
|
*/
|
||||||
void Map::unLightNeighbors(enum LightBank bank,
|
void Map::unLightNeighbors(enum LightBank bank,
|
||||||
v3s16 pos, u8 lightwas,
|
v3s16 pos, u8 lightwas,
|
||||||
core::map<v3s16, bool> & light_sources,
|
std::set<v3s16> & light_sources,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks)
|
std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
core::map<v3s16, u8> from_nodes;
|
std::map<v3s16, u8> from_nodes;
|
||||||
from_nodes.insert(pos, lightwas);
|
from_nodes[pos] = lightwas;
|
||||||
|
|
||||||
unspreadLight(bank, from_nodes, light_sources, modified_blocks);
|
unspreadLight(bank, from_nodes, light_sources, modified_blocks);
|
||||||
}
|
}
|
||||||
@ -422,8 +417,8 @@ void Map::unLightNeighbors(enum LightBank bank,
|
|||||||
goes on recursively.
|
goes on recursively.
|
||||||
*/
|
*/
|
||||||
void Map::spreadLight(enum LightBank bank,
|
void Map::spreadLight(enum LightBank bank,
|
||||||
core::map<v3s16, bool> & from_nodes,
|
std::set<v3s16> & from_nodes,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks)
|
std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
INodeDefManager *nodemgr = m_gamedef->ndef();
|
INodeDefManager *nodemgr = m_gamedef->ndef();
|
||||||
|
|
||||||
@ -441,9 +436,7 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
|
|
||||||
u32 blockchangecount = 0;
|
u32 blockchangecount = 0;
|
||||||
|
|
||||||
core::map<v3s16, bool> lighted_nodes;
|
std::set<v3s16> lighted_nodes;
|
||||||
core::map<v3s16, bool>::Iterator j;
|
|
||||||
j = from_nodes.getIterator();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Initialize block cache
|
Initialize block cache
|
||||||
@ -453,12 +446,10 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
// Cache this a bit, too
|
// Cache this a bit, too
|
||||||
bool block_checked_in_modified = false;
|
bool block_checked_in_modified = false;
|
||||||
|
|
||||||
for(; j.atEnd() == false; j++)
|
for(std::set<v3s16>::iterator j = from_nodes.begin();
|
||||||
//for(; j != from_nodes.end(); j++)
|
j != from_nodes.end(); ++j)
|
||||||
{
|
{
|
||||||
v3s16 pos = j.getNode()->getKey();
|
v3s16 pos = *j;
|
||||||
//v3s16 pos = *j;
|
|
||||||
//infostream<<"pos=("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")"<<std::endl;
|
|
||||||
v3s16 blockpos = getNodeBlockPos(pos);
|
v3s16 blockpos = getNodeBlockPos(pos);
|
||||||
|
|
||||||
// Only fetch a new block if the block position has changed
|
// Only fetch a new block if the block position has changed
|
||||||
@ -525,8 +516,7 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
*/
|
*/
|
||||||
if(n2.getLight(bank, nodemgr) > undiminish_light(oldlight))
|
if(n2.getLight(bank, nodemgr) > undiminish_light(oldlight))
|
||||||
{
|
{
|
||||||
lighted_nodes.insert(n2pos, true);
|
lighted_nodes.insert(n2pos);
|
||||||
//lighted_nodes.push_back(n2pos);
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -539,8 +529,7 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
{
|
{
|
||||||
n2.setLight(bank, newlight, nodemgr);
|
n2.setLight(bank, newlight, nodemgr);
|
||||||
block->setNode(relpos, n2);
|
block->setNode(relpos, n2);
|
||||||
lighted_nodes.insert(n2pos, true);
|
lighted_nodes.insert(n2pos);
|
||||||
//lighted_nodes.push_back(n2pos);
|
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -549,9 +538,9 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
if(changed == true && block_checked_in_modified == false)
|
if(changed == true && block_checked_in_modified == false)
|
||||||
{
|
{
|
||||||
// If the block is not found in modified_blocks, add.
|
// If the block is not found in modified_blocks, add.
|
||||||
if(modified_blocks.find(blockpos) == NULL)
|
if(modified_blocks.find(blockpos) == modified_blocks.end())
|
||||||
{
|
{
|
||||||
modified_blocks.insert(blockpos, block);
|
modified_blocks[blockpos] = block;
|
||||||
}
|
}
|
||||||
block_checked_in_modified = true;
|
block_checked_in_modified = true;
|
||||||
}
|
}
|
||||||
@ -577,10 +566,10 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
*/
|
*/
|
||||||
void Map::lightNeighbors(enum LightBank bank,
|
void Map::lightNeighbors(enum LightBank bank,
|
||||||
v3s16 pos,
|
v3s16 pos,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks)
|
std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> from_nodes;
|
std::set<v3s16> from_nodes;
|
||||||
from_nodes.insert(pos, true);
|
from_nodes.insert(pos);
|
||||||
spreadLight(bank, from_nodes, modified_blocks);
|
spreadLight(bank, from_nodes, modified_blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,7 +624,7 @@ v3s16 Map::getBrightestNeighbour(enum LightBank bank, v3s16 p)
|
|||||||
Mud is turned into grass in where the sunlight stops.
|
Mud is turned into grass in where the sunlight stops.
|
||||||
*/
|
*/
|
||||||
s16 Map::propagateSunlight(v3s16 start,
|
s16 Map::propagateSunlight(v3s16 start,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks)
|
std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
INodeDefManager *nodemgr = m_gamedef->ndef();
|
INodeDefManager *nodemgr = m_gamedef->ndef();
|
||||||
|
|
||||||
@ -662,7 +651,7 @@ s16 Map::propagateSunlight(v3s16 start,
|
|||||||
n.setLight(LIGHTBANK_DAY, LIGHT_SUN, nodemgr);
|
n.setLight(LIGHTBANK_DAY, LIGHT_SUN, nodemgr);
|
||||||
block->setNode(relpos, n);
|
block->setNode(relpos, n);
|
||||||
|
|
||||||
modified_blocks.insert(blockpos, block);
|
modified_blocks[blockpos] = block;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -674,8 +663,8 @@ s16 Map::propagateSunlight(v3s16 start,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Map::updateLighting(enum LightBank bank,
|
void Map::updateLighting(enum LightBank bank,
|
||||||
core::map<v3s16, MapBlock*> & a_blocks,
|
std::map<v3s16, MapBlock*> & a_blocks,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks)
|
std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
INodeDefManager *nodemgr = m_gamedef->ndef();
|
INodeDefManager *nodemgr = m_gamedef->ndef();
|
||||||
|
|
||||||
@ -688,22 +677,21 @@ void Map::updateLighting(enum LightBank bank,
|
|||||||
//bool debug=true;
|
//bool debug=true;
|
||||||
//u32 count_was = modified_blocks.size();
|
//u32 count_was = modified_blocks.size();
|
||||||
|
|
||||||
core::map<v3s16, MapBlock*> blocks_to_update;
|
std::map<v3s16, MapBlock*> blocks_to_update;
|
||||||
|
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
|
|
||||||
core::map<v3s16, u8> unlight_from;
|
std::map<v3s16, u8> unlight_from;
|
||||||
|
|
||||||
int num_bottom_invalid = 0;
|
int num_bottom_invalid = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
//TimeTaker t("first stuff");
|
//TimeTaker t("first stuff");
|
||||||
|
|
||||||
core::map<v3s16, MapBlock*>::Iterator i;
|
for(std::map<v3s16, MapBlock*>::iterator i = a_blocks.begin();
|
||||||
i = a_blocks.getIterator();
|
i != a_blocks.end(); ++i)
|
||||||
for(; i.atEnd() == false; i++)
|
|
||||||
{
|
{
|
||||||
MapBlock *block = i.getNode()->getValue();
|
MapBlock *block = i->second;
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
@ -713,9 +701,8 @@ void Map::updateLighting(enum LightBank bank,
|
|||||||
|
|
||||||
v3s16 pos = block->getPos();
|
v3s16 pos = block->getPos();
|
||||||
v3s16 posnodes = block->getPosRelative();
|
v3s16 posnodes = block->getPosRelative();
|
||||||
modified_blocks.insert(pos, block);
|
modified_blocks[pos] = block;
|
||||||
|
blocks_to_update[pos] = block;
|
||||||
blocks_to_update.insert(pos, block);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Clear all light from block
|
Clear all light from block
|
||||||
@ -735,7 +722,7 @@ void Map::updateLighting(enum LightBank bank,
|
|||||||
// If node sources light, add to list
|
// If node sources light, add to list
|
||||||
u8 source = nodemgr->get(n).light_source;
|
u8 source = nodemgr->get(n).light_source;
|
||||||
if(source != 0)
|
if(source != 0)
|
||||||
light_sources[p + posnodes] = true;
|
light_sources.insert(p + posnodes);
|
||||||
|
|
||||||
// Collect borders for unlighting
|
// Collect borders for unlighting
|
||||||
if((x==0 || x == MAP_BLOCKSIZE-1
|
if((x==0 || x == MAP_BLOCKSIZE-1
|
||||||
@ -744,7 +731,7 @@ void Map::updateLighting(enum LightBank bank,
|
|||||||
&& oldlight != 0)
|
&& oldlight != 0)
|
||||||
{
|
{
|
||||||
v3s16 p_map = p + posnodes;
|
v3s16 p_map = p + posnodes;
|
||||||
unlight_from.insert(p_map, oldlight);
|
unlight_from[p_map] = oldlight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e)
|
catch(InvalidPositionException &e)
|
||||||
@ -912,8 +899,8 @@ void Map::updateLighting(enum LightBank bank,
|
|||||||
//m_dout<<"Done ("<<getTimestamp()<<")"<<std::endl;
|
//m_dout<<"Done ("<<getTimestamp()<<")"<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
|
void Map::updateLighting(std::map<v3s16, MapBlock*> & a_blocks,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks)
|
std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
updateLighting(LIGHTBANK_DAY, a_blocks, modified_blocks);
|
updateLighting(LIGHTBANK_DAY, a_blocks, modified_blocks);
|
||||||
updateLighting(LIGHTBANK_NIGHT, a_blocks, modified_blocks);
|
updateLighting(LIGHTBANK_NIGHT, a_blocks, modified_blocks);
|
||||||
@ -921,11 +908,11 @@ void Map::updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
|
|||||||
/*
|
/*
|
||||||
Update information about whether day and night light differ
|
Update information about whether day and night light differ
|
||||||
*/
|
*/
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
MapBlock *block = i.getNode()->getValue();
|
MapBlock *block = i->second;
|
||||||
block->expireDayNightDiff();
|
block->expireDayNightDiff();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -933,7 +920,7 @@ void Map::updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
|
|||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
||||||
core::map<v3s16, MapBlock*> &modified_blocks)
|
std::map<v3s16, MapBlock*> &modified_blocks)
|
||||||
{
|
{
|
||||||
INodeDefManager *ndef = m_gamedef->ndef();
|
INodeDefManager *ndef = m_gamedef->ndef();
|
||||||
|
|
||||||
@ -952,7 +939,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
|||||||
v3s16 bottompos = p + v3s16(0,-1,0);
|
v3s16 bottompos = p + v3s16(0,-1,0);
|
||||||
|
|
||||||
bool node_under_sunlight = true;
|
bool node_under_sunlight = true;
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Collect old node for rollback
|
Collect old node for rollback
|
||||||
@ -994,7 +981,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
|||||||
v3s16 blockpos = getNodeBlockPos(p);
|
v3s16 blockpos = getNodeBlockPos(p);
|
||||||
MapBlock * block = getBlockNoCreate(blockpos);
|
MapBlock * block = getBlockNoCreate(blockpos);
|
||||||
assert(block != NULL);
|
assert(block != NULL);
|
||||||
modified_blocks.insert(blockpos, block);
|
modified_blocks[blockpos] = block;
|
||||||
|
|
||||||
assert(isValidPosition(p));
|
assert(isValidPosition(p));
|
||||||
|
|
||||||
@ -1078,12 +1065,11 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
|||||||
/*
|
/*
|
||||||
Update information about whether day and night light differ
|
Update information about whether day and night light differ
|
||||||
*/
|
*/
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
MapBlock *block = i.getNode()->getValue();
|
i->second->expireDayNightDiff();
|
||||||
block->expireDayNightDiff();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1132,7 +1118,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
|||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
void Map::removeNodeAndUpdate(v3s16 p,
|
void Map::removeNodeAndUpdate(v3s16 p,
|
||||||
core::map<v3s16, MapBlock*> &modified_blocks)
|
std::map<v3s16, MapBlock*> &modified_blocks)
|
||||||
{
|
{
|
||||||
INodeDefManager *ndef = m_gamedef->ndef();
|
INodeDefManager *ndef = m_gamedef->ndef();
|
||||||
|
|
||||||
@ -1166,7 +1152,7 @@ void Map::removeNodeAndUpdate(v3s16 p,
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
|
|
||||||
enum LightBank banks[] =
|
enum LightBank banks[] =
|
||||||
{
|
{
|
||||||
@ -1214,7 +1200,7 @@ void Map::removeNodeAndUpdate(v3s16 p,
|
|||||||
v3s16 blockpos = getNodeBlockPos(p);
|
v3s16 blockpos = getNodeBlockPos(p);
|
||||||
MapBlock * block = getBlockNoCreate(blockpos);
|
MapBlock * block = getBlockNoCreate(blockpos);
|
||||||
assert(block != NULL);
|
assert(block != NULL);
|
||||||
modified_blocks.insert(blockpos, block);
|
modified_blocks[blockpos] = block;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If the removed node was under sunlight, propagate the
|
If the removed node was under sunlight, propagate the
|
||||||
@ -1270,12 +1256,11 @@ void Map::removeNodeAndUpdate(v3s16 p,
|
|||||||
/*
|
/*
|
||||||
Update information about whether day and night light differ
|
Update information about whether day and night light differ
|
||||||
*/
|
*/
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
MapBlock *block = i.getNode()->getValue();
|
i->second->expireDayNightDiff();
|
||||||
block->expireDayNightDiff();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1330,15 +1315,15 @@ bool Map::addNodeWithEvent(v3s16 p, MapNode n)
|
|||||||
|
|
||||||
bool succeeded = true;
|
bool succeeded = true;
|
||||||
try{
|
try{
|
||||||
core::map<v3s16, MapBlock*> modified_blocks;
|
std::map<v3s16, MapBlock*> modified_blocks;
|
||||||
addNodeAndUpdate(p, n, modified_blocks);
|
addNodeAndUpdate(p, n, modified_blocks);
|
||||||
|
|
||||||
// Copy modified_blocks to event
|
// Copy modified_blocks to event
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd()==false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
event.modified_blocks.insert(i.getNode()->getKey(), false);
|
event.modified_blocks.erase(i->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e){
|
catch(InvalidPositionException &e){
|
||||||
@ -1358,15 +1343,15 @@ bool Map::removeNodeWithEvent(v3s16 p)
|
|||||||
|
|
||||||
bool succeeded = true;
|
bool succeeded = true;
|
||||||
try{
|
try{
|
||||||
core::map<v3s16, MapBlock*> modified_blocks;
|
std::map<v3s16, MapBlock*> modified_blocks;
|
||||||
removeNodeAndUpdate(p, modified_blocks);
|
removeNodeAndUpdate(p, modified_blocks);
|
||||||
|
|
||||||
// Copy modified_blocks to event
|
// Copy modified_blocks to event
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd()==false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
event.modified_blocks.insert(i.getNode()->getKey(), false);
|
event.modified_blocks.erase(i->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e){
|
catch(InvalidPositionException &e){
|
||||||
@ -1439,33 +1424,31 @@ bool Map::getDayNightDiff(v3s16 blockpos)
|
|||||||
Updates usage timers
|
Updates usage timers
|
||||||
*/
|
*/
|
||||||
void Map::timerUpdate(float dtime, float unload_timeout,
|
void Map::timerUpdate(float dtime, float unload_timeout,
|
||||||
core::list<v3s16> *unloaded_blocks)
|
std::list<v3s16> *unloaded_blocks)
|
||||||
{
|
{
|
||||||
bool save_before_unloading = (mapType() == MAPTYPE_SERVER);
|
bool save_before_unloading = (mapType() == MAPTYPE_SERVER);
|
||||||
|
|
||||||
// Profile modified reasons
|
// Profile modified reasons
|
||||||
Profiler modprofiler;
|
Profiler modprofiler;
|
||||||
|
|
||||||
core::list<v2s16> sector_deletion_queue;
|
std::list<v2s16> sector_deletion_queue;
|
||||||
u32 deleted_blocks_count = 0;
|
u32 deleted_blocks_count = 0;
|
||||||
u32 saved_blocks_count = 0;
|
u32 saved_blocks_count = 0;
|
||||||
u32 block_count_all = 0;
|
u32 block_count_all = 0;
|
||||||
|
|
||||||
core::map<v2s16, MapSector*>::Iterator si;
|
|
||||||
|
|
||||||
beginSave();
|
beginSave();
|
||||||
si = m_sectors.getIterator();
|
for(std::map<v2s16, MapSector*>::iterator si = m_sectors.begin();
|
||||||
for(; si.atEnd() == false; si++)
|
si != m_sectors.end(); ++si)
|
||||||
{
|
{
|
||||||
MapSector *sector = si.getNode()->getValue();
|
MapSector *sector = si->second;
|
||||||
|
|
||||||
bool all_blocks_deleted = true;
|
bool all_blocks_deleted = true;
|
||||||
|
|
||||||
core::list<MapBlock*> blocks;
|
std::list<MapBlock*> blocks;
|
||||||
sector->getBlocks(blocks);
|
sector->getBlocks(blocks);
|
||||||
|
|
||||||
for(core::list<MapBlock*>::Iterator i = blocks.begin();
|
for(std::list<MapBlock*>::iterator i = blocks.begin();
|
||||||
i != blocks.end(); i++)
|
i != blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
MapBlock *block = (*i);
|
MapBlock *block = (*i);
|
||||||
|
|
||||||
@ -1501,7 +1484,7 @@ void Map::timerUpdate(float dtime, float unload_timeout,
|
|||||||
|
|
||||||
if(all_blocks_deleted)
|
if(all_blocks_deleted)
|
||||||
{
|
{
|
||||||
sector_deletion_queue.push_back(si.getNode()->getKey());
|
sector_deletion_queue.push_back(si->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
endSave();
|
endSave();
|
||||||
@ -1526,17 +1509,17 @@ void Map::timerUpdate(float dtime, float unload_timeout,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::deleteSectors(core::list<v2s16> &list)
|
void Map::deleteSectors(std::list<v2s16> &list)
|
||||||
{
|
{
|
||||||
core::list<v2s16>::Iterator j;
|
for(std::list<v2s16>::iterator j = list.begin();
|
||||||
for(j=list.begin(); j!=list.end(); j++)
|
j != list.end(); ++j)
|
||||||
{
|
{
|
||||||
MapSector *sector = m_sectors[*j];
|
MapSector *sector = m_sectors[*j];
|
||||||
// If sector is in sector cache, remove it from there
|
// If sector is in sector cache, remove it from there
|
||||||
if(m_sector_cache == sector)
|
if(m_sector_cache == sector)
|
||||||
m_sector_cache = NULL;
|
m_sector_cache = NULL;
|
||||||
// Remove from map and delete
|
// Remove from map and delete
|
||||||
m_sectors.remove(*j);
|
m_sectors.erase(*j);
|
||||||
delete sector;
|
delete sector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1642,7 +1625,7 @@ const v3s16 g_7dirs[7] =
|
|||||||
#define D_TOP 6
|
#define D_TOP 6
|
||||||
#define D_SELF 1
|
#define D_SELF 1
|
||||||
|
|
||||||
void Map::transformLiquidsFinite(core::map<v3s16, MapBlock*> & modified_blocks)
|
void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
INodeDefManager *nodemgr = m_gamedef->ndef();
|
INodeDefManager *nodemgr = m_gamedef->ndef();
|
||||||
|
|
||||||
@ -1663,7 +1646,7 @@ void Map::transformLiquidsFinite(core::map<v3s16, MapBlock*> & modified_blocks)
|
|||||||
UniqueQueue<v3s16> must_reflow, must_reflow_second;
|
UniqueQueue<v3s16> must_reflow, must_reflow_second;
|
||||||
|
|
||||||
// List of MapBlocks that will require a lighting update (due to lava)
|
// List of MapBlocks that will require a lighting update (due to lava)
|
||||||
core::map<v3s16, MapBlock*> lighting_modified_blocks;
|
std::map<v3s16, MapBlock*> lighting_modified_blocks;
|
||||||
|
|
||||||
while(m_transforming_liquid.size() > 0)
|
while(m_transforming_liquid.size() > 0)
|
||||||
{
|
{
|
||||||
@ -1904,7 +1887,7 @@ void Map::transformLiquidsFinite(core::map<v3s16, MapBlock*> & modified_blocks)
|
|||||||
v3s16 blockpos = getNodeBlockPos(p0);
|
v3s16 blockpos = getNodeBlockPos(p0);
|
||||||
MapBlock *block = getBlockNoCreateNoEx(blockpos);
|
MapBlock *block = getBlockNoCreateNoEx(blockpos);
|
||||||
if(block != NULL) {
|
if(block != NULL) {
|
||||||
modified_blocks.insert(blockpos, block);
|
modified_blocks[blockpos] = block;
|
||||||
// If node emits light, MapBlock requires lighting update
|
// If node emits light, MapBlock requires lighting update
|
||||||
if(nodemgr->get(n0).light_source != 0)
|
if(nodemgr->get(n0).light_source != 0)
|
||||||
lighting_modified_blocks[block->getPos()] = block;
|
lighting_modified_blocks[block->getPos()] = block;
|
||||||
@ -1925,7 +1908,7 @@ void Map::transformLiquidsFinite(core::map<v3s16, MapBlock*> & modified_blocks)
|
|||||||
updateLighting(lighting_modified_blocks, modified_blocks);
|
updateLighting(lighting_modified_blocks, modified_blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
|
void Map::transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (g_settings->getBool("liquid_finite")) return Map::transformLiquidsFinite(modified_blocks);
|
if (g_settings->getBool("liquid_finite")) return Map::transformLiquidsFinite(modified_blocks);
|
||||||
@ -1945,7 +1928,7 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
|
|||||||
UniqueQueue<v3s16> must_reflow;
|
UniqueQueue<v3s16> must_reflow;
|
||||||
|
|
||||||
// List of MapBlocks that will require a lighting update (due to lava)
|
// List of MapBlocks that will require a lighting update (due to lava)
|
||||||
core::map<v3s16, MapBlock*> lighting_modified_blocks;
|
std::map<v3s16, MapBlock*> lighting_modified_blocks;
|
||||||
|
|
||||||
while(m_transforming_liquid.size() != 0)
|
while(m_transforming_liquid.size() != 0)
|
||||||
{
|
{
|
||||||
@ -2165,7 +2148,7 @@ void Map::transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks)
|
|||||||
v3s16 blockpos = getNodeBlockPos(p0);
|
v3s16 blockpos = getNodeBlockPos(p0);
|
||||||
MapBlock *block = getBlockNoCreateNoEx(blockpos);
|
MapBlock *block = getBlockNoCreateNoEx(blockpos);
|
||||||
if(block != NULL) {
|
if(block != NULL) {
|
||||||
modified_blocks.insert(blockpos, block);
|
modified_blocks[blockpos] = block;
|
||||||
// If node emits light, MapBlock requires lighting update
|
// If node emits light, MapBlock requires lighting update
|
||||||
if(nodemgr->get(n0).light_source != 0)
|
if(nodemgr->get(n0).light_source != 0)
|
||||||
lighting_modified_blocks[block->getPos()] = block;
|
lighting_modified_blocks[block->getPos()] = block;
|
||||||
@ -2571,7 +2554,7 @@ bool ServerMap::initBlockMake(BlockMakeData *data, v3s16 blockpos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
MapBlock* ServerMap::finishBlockMake(BlockMakeData *data,
|
MapBlock* ServerMap::finishBlockMake(BlockMakeData *data,
|
||||||
core::map<v3s16, MapBlock*> &changed_blocks)
|
std::map<v3s16, MapBlock*> &changed_blocks)
|
||||||
{
|
{
|
||||||
v3s16 blockpos_min = data->blockpos_min;
|
v3s16 blockpos_min = data->blockpos_min;
|
||||||
v3s16 blockpos_max = data->blockpos_max;
|
v3s16 blockpos_max = data->blockpos_max;
|
||||||
@ -2676,10 +2659,10 @@ MapBlock* ServerMap::finishBlockMake(BlockMakeData *data,
|
|||||||
/*
|
/*
|
||||||
Go through changed blocks
|
Go through changed blocks
|
||||||
*/
|
*/
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator i = changed_blocks.getIterator();
|
for(std::map<v3s16, MapBlock*>::iterator i = changed_blocks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != changed_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
MapBlock *block = i.getNode()->getValue();
|
MapBlock *block = i->second;
|
||||||
assert(block);
|
assert(block);
|
||||||
/*
|
/*
|
||||||
Update day/night difference cache of the MapBlocks
|
Update day/night difference cache of the MapBlocks
|
||||||
@ -2797,7 +2780,7 @@ ServerMapSector * ServerMap::createSector(v2s16 p2d)
|
|||||||
/*
|
/*
|
||||||
Insert to container
|
Insert to container
|
||||||
*/
|
*/
|
||||||
m_sectors.insert(p2d, sector);
|
m_sectors[p2d] = sector;
|
||||||
|
|
||||||
return sector;
|
return sector;
|
||||||
}
|
}
|
||||||
@ -2808,7 +2791,7 @@ ServerMapSector * ServerMap::createSector(v2s16 p2d)
|
|||||||
*/
|
*/
|
||||||
MapBlock * ServerMap::generateBlock(
|
MapBlock * ServerMap::generateBlock(
|
||||||
v3s16 p,
|
v3s16 p,
|
||||||
core::map<v3s16, MapBlock*> &modified_blocks
|
std::map<v3s16, MapBlock*> &modified_blocks
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DSTACKF("%s: p=(%d,%d,%d)", __FUNCTION_NAME, p.X, p.Y, p.Z);
|
DSTACKF("%s: p=(%d,%d,%d)", __FUNCTION_NAME, p.X, p.Y, p.Z);
|
||||||
@ -3008,7 +2991,7 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank)
|
|||||||
}
|
}
|
||||||
/*if(allow_generate)
|
/*if(allow_generate)
|
||||||
{
|
{
|
||||||
core::map<v3s16, MapBlock*> modified_blocks;
|
std::map<v3s16, MapBlock*> modified_blocks;
|
||||||
MapBlock *block = generateBlock(p, modified_blocks);
|
MapBlock *block = generateBlock(p, modified_blocks);
|
||||||
if(block)
|
if(block)
|
||||||
{
|
{
|
||||||
@ -3017,11 +3000,11 @@ MapBlock * ServerMap::emergeBlock(v3s16 p, bool create_blank)
|
|||||||
event.p = p;
|
event.p = p;
|
||||||
|
|
||||||
// Copy modified_blocks to event
|
// Copy modified_blocks to event
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd()==false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
event.modified_blocks.insert(i.getNode()->getKey(), false);
|
event.modified_blocks.erase(i->first);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queue event
|
// Queue event
|
||||||
@ -3262,10 +3245,10 @@ void ServerMap::save(ModifiedState save_level)
|
|||||||
// Don't do anything with sqlite unless something is really saved
|
// Don't do anything with sqlite unless something is really saved
|
||||||
bool save_started = false;
|
bool save_started = false;
|
||||||
|
|
||||||
core::map<v2s16, MapSector*>::Iterator i = m_sectors.getIterator();
|
for(std::map<v2s16, MapSector*>::iterator i = m_sectors.begin();
|
||||||
for(; i.atEnd() == false; i++)
|
i != m_sectors.end(); ++i)
|
||||||
{
|
{
|
||||||
ServerMapSector *sector = (ServerMapSector*)i.getNode()->getValue();
|
ServerMapSector *sector = (ServerMapSector*)i->second;
|
||||||
assert(sector->getId() == MAPSECTOR_SERVER);
|
assert(sector->getId() == MAPSECTOR_SERVER);
|
||||||
|
|
||||||
if(sector->differs_from_disk || save_level == MOD_STATE_CLEAN)
|
if(sector->differs_from_disk || save_level == MOD_STATE_CLEAN)
|
||||||
@ -3273,11 +3256,11 @@ void ServerMap::save(ModifiedState save_level)
|
|||||||
saveSectorMeta(sector);
|
saveSectorMeta(sector);
|
||||||
sector_meta_count++;
|
sector_meta_count++;
|
||||||
}
|
}
|
||||||
core::list<MapBlock*> blocks;
|
std::list<MapBlock*> blocks;
|
||||||
sector->getBlocks(blocks);
|
sector->getBlocks(blocks);
|
||||||
core::list<MapBlock*>::Iterator j;
|
|
||||||
|
|
||||||
for(j=blocks.begin(); j!=blocks.end(); j++)
|
for(std::list<MapBlock*>::iterator j = blocks.begin();
|
||||||
|
j != blocks.end(); ++j)
|
||||||
{
|
{
|
||||||
MapBlock *block = *j;
|
MapBlock *block = *j;
|
||||||
|
|
||||||
@ -3350,7 +3333,7 @@ v3s16 ServerMap::getIntegerAsBlock(sqlite3_int64 i)
|
|||||||
return v3s16(x,y,z);
|
return v3s16(x,y,z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerMap::listAllLoadableBlocks(core::list<v3s16> &dst)
|
void ServerMap::listAllLoadableBlocks(std::list<v3s16> &dst)
|
||||||
{
|
{
|
||||||
if(loadFromFolders()){
|
if(loadFromFolders()){
|
||||||
errorstream<<"Map::listAllLoadableBlocks(): Result will be missing "
|
errorstream<<"Map::listAllLoadableBlocks(): Result will be missing "
|
||||||
@ -3487,7 +3470,7 @@ MapSector* ServerMap::loadSectorMeta(std::string sectordir, bool save_after_load
|
|||||||
<<" Continuing with a sector with no metadata."
|
<<" Continuing with a sector with no metadata."
|
||||||
<<std::endl;*/
|
<<std::endl;*/
|
||||||
sector = new ServerMapSector(this, p2d, m_gamedef);
|
sector = new ServerMapSector(this, p2d, m_gamedef);
|
||||||
m_sectors.insert(p2d, sector);
|
m_sectors[p2d] = sector;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3987,9 +3970,9 @@ void MapVoxelManipulator::emerge(VoxelArea a, s32 caller_id)
|
|||||||
u8 flags = 0;
|
u8 flags = 0;
|
||||||
MapBlock *block;
|
MapBlock *block;
|
||||||
v3s16 p(x,y,z);
|
v3s16 p(x,y,z);
|
||||||
core::map<v3s16, u8>::Node *n;
|
std::map<v3s16, u8>::iterator n;
|
||||||
n = m_loaded_blocks.find(p);
|
n = m_loaded_blocks.find(p);
|
||||||
if(n != NULL)
|
if(n != m_loaded_blocks.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool block_data_inexistent = false;
|
bool block_data_inexistent = false;
|
||||||
@ -4033,7 +4016,7 @@ void MapVoxelManipulator::emerge(VoxelArea a, s32 caller_id)
|
|||||||
flags |= VMANIP_BLOCK_CONTAINS_CIGNORE;
|
flags |= VMANIP_BLOCK_CONTAINS_CIGNORE;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
m_loaded_blocks.insert(p, flags);
|
m_loaded_blocks[p] = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
//infostream<<"emerge done"<<std::endl;
|
//infostream<<"emerge done"<<std::endl;
|
||||||
@ -4045,7 +4028,7 @@ void MapVoxelManipulator::emerge(VoxelArea a, s32 caller_id)
|
|||||||
run on background.
|
run on background.
|
||||||
*/
|
*/
|
||||||
void MapVoxelManipulator::blitBack
|
void MapVoxelManipulator::blitBack
|
||||||
(core::map<v3s16, MapBlock*> & modified_blocks)
|
(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||||
{
|
{
|
||||||
if(m_area.getExtent() == v3s16(0,0,0))
|
if(m_area.getExtent() == v3s16(0,0,0))
|
||||||
return;
|
return;
|
||||||
@ -4156,9 +4139,9 @@ void ManualMapVoxelManipulator::initialEmerge(
|
|||||||
u8 flags = 0;
|
u8 flags = 0;
|
||||||
MapBlock *block;
|
MapBlock *block;
|
||||||
v3s16 p(x,y,z);
|
v3s16 p(x,y,z);
|
||||||
core::map<v3s16, u8>::Node *n;
|
std::map<v3s16, u8>::iterator n;
|
||||||
n = m_loaded_blocks.find(p);
|
n = m_loaded_blocks.find(p);
|
||||||
if(n != NULL)
|
if(n != m_loaded_blocks.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool block_data_inexistent = false;
|
bool block_data_inexistent = false;
|
||||||
@ -4199,12 +4182,12 @@ void ManualMapVoxelManipulator::initialEmerge(
|
|||||||
flags |= VMANIP_BLOCK_CONTAINS_CIGNORE;
|
flags |= VMANIP_BLOCK_CONTAINS_CIGNORE;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
m_loaded_blocks.insert(p, flags);
|
m_loaded_blocks[p] = flags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManualMapVoxelManipulator::blitBackAll(
|
void ManualMapVoxelManipulator::blitBackAll(
|
||||||
core::map<v3s16, MapBlock*> * modified_blocks)
|
std::map<v3s16, MapBlock*> * modified_blocks)
|
||||||
{
|
{
|
||||||
if(m_area.getExtent() == v3s16(0,0,0))
|
if(m_area.getExtent() == v3s16(0,0,0))
|
||||||
return;
|
return;
|
||||||
@ -4212,37 +4195,22 @@ void ManualMapVoxelManipulator::blitBackAll(
|
|||||||
/*
|
/*
|
||||||
Copy data of all blocks
|
Copy data of all blocks
|
||||||
*/
|
*/
|
||||||
for(core::map<v3s16, u8>::Iterator
|
for(std::map<v3s16, u8>::iterator
|
||||||
i = m_loaded_blocks.getIterator();
|
i = m_loaded_blocks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_loaded_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = i->first;
|
||||||
u8 flags = i.getNode()->getValue();
|
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
|
||||||
|
bool existed = !(i->second & VMANIP_BLOCK_DATA_INEXIST);
|
||||||
bool existed = !(flags & VMANIP_BLOCK_DATA_INEXIST);
|
|
||||||
if(existed == false)
|
if(existed == false)
|
||||||
{
|
{
|
||||||
// The Great Bug was found using this
|
|
||||||
/*infostream<<"ManualMapVoxelManipulator::blitBackAll: "
|
|
||||||
<<"Inexistent ("<<p.X<<","<<p.Y<<","<<p.Z<<")"
|
|
||||||
<<std::endl;*/
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
|
|
||||||
if(block == NULL)
|
|
||||||
{
|
|
||||||
infostream<<"WARNING: "<<__FUNCTION_NAME
|
|
||||||
<<": got NULL block "
|
|
||||||
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
|
|
||||||
<<std::endl;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
block->copyFrom(*this);
|
block->copyFrom(*this);
|
||||||
|
|
||||||
if(modified_blocks)
|
if(modified_blocks)
|
||||||
modified_blocks->insert(p, block);
|
(*modified_blocks)[p] = block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
90
src/map.h
90
src/map.h
@ -25,6 +25,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <jthread.h>
|
#include <jthread.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include "irrlichttypes_bloated.h"
|
#include "irrlichttypes_bloated.h"
|
||||||
#include "mapnode.h"
|
#include "mapnode.h"
|
||||||
@ -75,7 +78,7 @@ struct MapEditEvent
|
|||||||
MapEditEventType type;
|
MapEditEventType type;
|
||||||
v3s16 p;
|
v3s16 p;
|
||||||
MapNode n;
|
MapNode n;
|
||||||
core::map<v3s16, bool> modified_blocks;
|
std::set<v3s16> modified_blocks;
|
||||||
u16 already_known_by_peer;
|
u16 already_known_by_peer;
|
||||||
|
|
||||||
MapEditEvent():
|
MapEditEvent():
|
||||||
@ -90,14 +93,7 @@ struct MapEditEvent
|
|||||||
event->type = type;
|
event->type = type;
|
||||||
event->p = p;
|
event->p = p;
|
||||||
event->n = n;
|
event->n = n;
|
||||||
for(core::map<v3s16, bool>::Iterator
|
event->modified_blocks = modified_blocks;
|
||||||
i = modified_blocks.getIterator();
|
|
||||||
i.atEnd()==false; i++)
|
|
||||||
{
|
|
||||||
v3s16 p = i.getNode()->getKey();
|
|
||||||
bool v = i.getNode()->getValue();
|
|
||||||
event->modified_blocks.insert(p, v);
|
|
||||||
}
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,11 +113,11 @@ struct MapEditEvent
|
|||||||
case MEET_OTHER:
|
case MEET_OTHER:
|
||||||
{
|
{
|
||||||
VoxelArea a;
|
VoxelArea a;
|
||||||
for(core::map<v3s16, bool>::Iterator
|
for(std::set<v3s16>::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd()==false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = *i;
|
||||||
v3s16 np1 = p*MAP_BLOCKSIZE;
|
v3s16 np1 = p*MAP_BLOCKSIZE;
|
||||||
v3s16 np2 = np1 + v3s16(1,1,1)*MAP_BLOCKSIZE - v3s16(1,1,1);
|
v3s16 np2 = np1 + v3s16(1,1,1)*MAP_BLOCKSIZE - v3s16(1,1,1);
|
||||||
a.addPoint(np1);
|
a.addPoint(np1);
|
||||||
@ -186,7 +182,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual MapSector * emergeSector(v2s16 p){ return NULL; }
|
virtual MapSector * emergeSector(v2s16 p){ return NULL; }
|
||||||
virtual MapSector * emergeSector(v2s16 p,
|
virtual MapSector * emergeSector(v2s16 p,
|
||||||
core::map<v3s16, MapBlock*> &changed_blocks){ return NULL; }
|
std::map<v3s16, MapBlock*> &changed_blocks){ return NULL; }
|
||||||
|
|
||||||
// Returns InvalidPositionException if not found
|
// Returns InvalidPositionException if not found
|
||||||
MapBlock * getBlockNoCreate(v3s16 p);
|
MapBlock * getBlockNoCreate(v3s16 p);
|
||||||
@ -212,42 +208,42 @@ public:
|
|||||||
MapNode getNodeNoEx(v3s16 p);
|
MapNode getNodeNoEx(v3s16 p);
|
||||||
|
|
||||||
void unspreadLight(enum LightBank bank,
|
void unspreadLight(enum LightBank bank,
|
||||||
core::map<v3s16, u8> & from_nodes,
|
std::map<v3s16, u8> & from_nodes,
|
||||||
core::map<v3s16, bool> & light_sources,
|
std::set<v3s16> & light_sources,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks);
|
std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
|
|
||||||
void unLightNeighbors(enum LightBank bank,
|
void unLightNeighbors(enum LightBank bank,
|
||||||
v3s16 pos, u8 lightwas,
|
v3s16 pos, u8 lightwas,
|
||||||
core::map<v3s16, bool> & light_sources,
|
std::set<v3s16> & light_sources,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks);
|
std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
|
|
||||||
void spreadLight(enum LightBank bank,
|
void spreadLight(enum LightBank bank,
|
||||||
core::map<v3s16, bool> & from_nodes,
|
std::set<v3s16> & from_nodes,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks);
|
std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
|
|
||||||
void lightNeighbors(enum LightBank bank,
|
void lightNeighbors(enum LightBank bank,
|
||||||
v3s16 pos,
|
v3s16 pos,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks);
|
std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
|
|
||||||
v3s16 getBrightestNeighbour(enum LightBank bank, v3s16 p);
|
v3s16 getBrightestNeighbour(enum LightBank bank, v3s16 p);
|
||||||
|
|
||||||
s16 propagateSunlight(v3s16 start,
|
s16 propagateSunlight(v3s16 start,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks);
|
std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
|
|
||||||
void updateLighting(enum LightBank bank,
|
void updateLighting(enum LightBank bank,
|
||||||
core::map<v3s16, MapBlock*> & a_blocks,
|
std::map<v3s16, MapBlock*> & a_blocks,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks);
|
std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
|
|
||||||
void updateLighting(core::map<v3s16, MapBlock*> & a_blocks,
|
void updateLighting(std::map<v3s16, MapBlock*> & a_blocks,
|
||||||
core::map<v3s16, MapBlock*> & modified_blocks);
|
std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
These handle lighting but not faces.
|
These handle lighting but not faces.
|
||||||
*/
|
*/
|
||||||
void addNodeAndUpdate(v3s16 p, MapNode n,
|
void addNodeAndUpdate(v3s16 p, MapNode n,
|
||||||
core::map<v3s16, MapBlock*> &modified_blocks);
|
std::map<v3s16, MapBlock*> &modified_blocks);
|
||||||
void removeNodeAndUpdate(v3s16 p,
|
void removeNodeAndUpdate(v3s16 p,
|
||||||
core::map<v3s16, MapBlock*> &modified_blocks);
|
std::map<v3s16, MapBlock*> &modified_blocks);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Wrappers for the latter ones.
|
Wrappers for the latter ones.
|
||||||
@ -281,12 +277,12 @@ public:
|
|||||||
Saves modified blocks before unloading on MAPTYPE_SERVER.
|
Saves modified blocks before unloading on MAPTYPE_SERVER.
|
||||||
*/
|
*/
|
||||||
void timerUpdate(float dtime, float unload_timeout,
|
void timerUpdate(float dtime, float unload_timeout,
|
||||||
core::list<v3s16> *unloaded_blocks=NULL);
|
std::list<v3s16> *unloaded_blocks=NULL);
|
||||||
|
|
||||||
// Deletes sectors and their blocks from memory
|
// Deletes sectors and their blocks from memory
|
||||||
// Takes cache into account
|
// Takes cache into account
|
||||||
// If deleted sector is in sector cache, clears cache
|
// If deleted sector is in sector cache, clears cache
|
||||||
void deleteSectors(core::list<v2s16> &list);
|
void deleteSectors(std::list<v2s16> &list);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/*
|
/*
|
||||||
@ -301,8 +297,8 @@ public:
|
|||||||
// For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: "
|
// For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: "
|
||||||
virtual void PrintInfo(std::ostream &out);
|
virtual void PrintInfo(std::ostream &out);
|
||||||
|
|
||||||
void transformLiquids(core::map<v3s16, MapBlock*> & modified_blocks);
|
void transformLiquids(std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
void transformLiquidsFinite(core::map<v3s16, MapBlock*> & modified_blocks);
|
void transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Node metadata
|
Node metadata
|
||||||
@ -325,7 +321,7 @@ public:
|
|||||||
/*
|
/*
|
||||||
Misc.
|
Misc.
|
||||||
*/
|
*/
|
||||||
core::map<v2s16, MapSector*> *getSectorsPtr(){return &m_sectors;}
|
std::map<v2s16, MapSector*> *getSectorsPtr(){return &m_sectors;}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Variables
|
Variables
|
||||||
@ -340,9 +336,9 @@ protected:
|
|||||||
|
|
||||||
IGameDef *m_gamedef;
|
IGameDef *m_gamedef;
|
||||||
|
|
||||||
core::map<MapEventReceiver*, bool> m_event_receivers;
|
std::set<MapEventReceiver*> m_event_receivers;
|
||||||
|
|
||||||
core::map<v2s16, MapSector*> m_sectors;
|
std::map<v2s16, MapSector*> m_sectors;
|
||||||
|
|
||||||
// Be sure to set this to NULL when the cached sector is deleted
|
// Be sure to set this to NULL when the cached sector is deleted
|
||||||
MapSector *m_sector_cache;
|
MapSector *m_sector_cache;
|
||||||
@ -385,13 +381,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool initBlockMake(BlockMakeData *data, v3s16 blockpos);
|
bool initBlockMake(BlockMakeData *data, v3s16 blockpos);
|
||||||
MapBlock *finishBlockMake(BlockMakeData *data,
|
MapBlock *finishBlockMake(BlockMakeData *data,
|
||||||
core::map<v3s16, MapBlock*> &changed_blocks);
|
std::map<v3s16, MapBlock*> &changed_blocks);
|
||||||
|
|
||||||
// A non-threaded wrapper to the above - DEFUNCT
|
|
||||||
/* MapBlock * generateBlock(
|
|
||||||
v3s16 p,
|
|
||||||
core::map<v3s16, MapBlock*> &modified_blocks
|
|
||||||
);*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get a block from somewhere.
|
Get a block from somewhere.
|
||||||
@ -444,9 +434,7 @@ public:
|
|||||||
|
|
||||||
void save(ModifiedState save_level);
|
void save(ModifiedState save_level);
|
||||||
//void loadAll();
|
//void loadAll();
|
||||||
|
void listAllLoadableBlocks(std::list<v3s16> &dst);
|
||||||
void listAllLoadableBlocks(core::list<v3s16> &dst);
|
|
||||||
|
|
||||||
// Saves map seed and possibly other stuff
|
// Saves map seed and possibly other stuff
|
||||||
void saveMapMeta();
|
void saveMapMeta();
|
||||||
void loadMapMeta();
|
void loadMapMeta();
|
||||||
@ -538,15 +526,15 @@ public:
|
|||||||
|
|
||||||
virtual void emerge(VoxelArea a, s32 caller_id=-1);
|
virtual void emerge(VoxelArea a, s32 caller_id=-1);
|
||||||
|
|
||||||
void blitBack(core::map<v3s16, MapBlock*> & modified_blocks);
|
void blitBack(std::map<v3s16, MapBlock*> & modified_blocks);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Map *m_map;
|
||||||
/*
|
/*
|
||||||
key = blockpos
|
key = blockpos
|
||||||
value = flags describing the block
|
value = flags describing the block
|
||||||
*/
|
*/
|
||||||
core::map<v3s16, u8> m_loaded_blocks;
|
std::map<v3s16, u8> m_loaded_blocks;
|
||||||
protected:
|
|
||||||
Map *m_map;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ManualMapVoxelManipulator : public MapVoxelManipulator
|
class ManualMapVoxelManipulator : public MapVoxelManipulator
|
||||||
@ -563,7 +551,7 @@ public:
|
|||||||
void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max);
|
void initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max);
|
||||||
|
|
||||||
// This is much faster with big chunks of generated data
|
// This is much faster with big chunks of generated data
|
||||||
void blitBackAll(core::map<v3s16, MapBlock*> * modified_blocks);
|
void blitBackAll(std::map<v3s16, MapBlock*> * modified_blocks);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_create_area;
|
bool m_create_area;
|
||||||
|
@ -168,7 +168,7 @@ MapNode MapBlock::getNodeParentNoEx(v3s16 p)
|
|||||||
if black_air_left!=NULL, it is set to true if non-sunlighted
|
if black_air_left!=NULL, it is set to true if non-sunlighted
|
||||||
air is left in block.
|
air is left in block.
|
||||||
*/
|
*/
|
||||||
bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
|
bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
|
||||||
bool remove_light, bool *black_air_left)
|
bool remove_light, bool *black_air_left)
|
||||||
{
|
{
|
||||||
INodeDefManager *nodemgr = m_gamedef->ndef();
|
INodeDefManager *nodemgr = m_gamedef->ndef();
|
||||||
@ -287,7 +287,7 @@ bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
|
|||||||
|
|
||||||
if(diminish_light(current_light) != 0)
|
if(diminish_light(current_light) != 0)
|
||||||
{
|
{
|
||||||
light_sources.insert(pos_relative + pos, true);
|
light_sources.insert(pos_relative + pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(current_light == 0 && stopped_to_solid_object)
|
if(current_light == 0 && stopped_to_solid_object)
|
||||||
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <jmutex.h>
|
#include <jmutex.h>
|
||||||
#include <jmutexautolock.h>
|
#include <jmutexautolock.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <set>
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "irrlichttypes.h"
|
#include "irrlichttypes.h"
|
||||||
#include "irr_v3d.h"
|
#include "irr_v3d.h"
|
||||||
@ -352,7 +353,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// See comments in mapblock.cpp
|
// See comments in mapblock.cpp
|
||||||
bool propagateSunlight(core::map<v3s16, bool> & light_sources,
|
bool propagateSunlight(std::set<v3s16> & light_sources,
|
||||||
bool remove_light=false, bool *black_air_left=NULL);
|
bool remove_light=false, bool *black_air_left=NULL);
|
||||||
|
|
||||||
// Copies data to VoxelManipulator to getPosRelative()
|
// Copies data to VoxelManipulator to getPosRelative()
|
||||||
|
@ -445,7 +445,7 @@ struct FastFace
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
|
static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
|
||||||
v3f p, v3s16 dir, v3f scale, u8 light_source, core::array<FastFace> &dest)
|
v3f p, v3s16 dir, v3f scale, u8 light_source, std::vector<FastFace> &dest)
|
||||||
{
|
{
|
||||||
FastFace face;
|
FastFace face;
|
||||||
|
|
||||||
@ -745,7 +745,7 @@ static void updateFastFaceRow(
|
|||||||
v3f translate_dir_f,
|
v3f translate_dir_f,
|
||||||
v3s16 face_dir,
|
v3s16 face_dir,
|
||||||
v3f face_dir_f,
|
v3f face_dir_f,
|
||||||
core::array<FastFace> &dest)
|
std::vector<FastFace> &dest)
|
||||||
{
|
{
|
||||||
v3s16 p = startpos;
|
v3s16 p = startpos;
|
||||||
|
|
||||||
@ -897,7 +897,7 @@ static void updateFastFaceRow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void updateAllFastFaceRows(MeshMakeData *data,
|
static void updateAllFastFaceRows(MeshMakeData *data,
|
||||||
core::array<FastFace> &dest)
|
std::vector<FastFace> &dest)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Go through every y,z and get top(y+) faces in rows of x+
|
Go through every y,z and get top(y+) faces in rows of x+
|
||||||
@ -962,7 +962,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
|
|||||||
// 24-155ms for MAP_BLOCKSIZE=32 (NOTE: probably outdated)
|
// 24-155ms for MAP_BLOCKSIZE=32 (NOTE: probably outdated)
|
||||||
//TimeTaker timer1("MapBlockMesh()");
|
//TimeTaker timer1("MapBlockMesh()");
|
||||||
|
|
||||||
core::array<FastFace> fastfaces_new;
|
std::vector<FastFace> fastfaces_new;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We are including the faces of the trailing edges of the block.
|
We are including the faces of the trailing edges of the block.
|
||||||
@ -1124,8 +1124,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
|
|||||||
m_mesh->addMeshBuffer(buf);
|
m_mesh->addMeshBuffer(buf);
|
||||||
// Mesh grabbed it
|
// Mesh grabbed it
|
||||||
buf->drop();
|
buf->drop();
|
||||||
buf->append(p.vertices.pointer(), p.vertices.size(),
|
buf->append(&p.vertices[0], p.vertices.size(),
|
||||||
p.indices.pointer(), p.indices.size());
|
&p.indices[0], p.indices.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -143,13 +143,13 @@ private:
|
|||||||
struct PreMeshBuffer
|
struct PreMeshBuffer
|
||||||
{
|
{
|
||||||
TileSpec tile;
|
TileSpec tile;
|
||||||
core::array<u16> indices;
|
std::vector<u16> indices;
|
||||||
core::array<video::S3DVertex> vertices;
|
std::vector<video::S3DVertex> vertices;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MeshCollector
|
struct MeshCollector
|
||||||
{
|
{
|
||||||
core::array<PreMeshBuffer> prebuffers;
|
std::vector<PreMeshBuffer> prebuffers;
|
||||||
|
|
||||||
void append(const TileSpec &material,
|
void append(const TileSpec &material,
|
||||||
const video::S3DVertex *vertices, u32 numVertices,
|
const video::S3DVertex *vertices, u32 numVertices,
|
||||||
|
@ -2275,8 +2275,8 @@ void make_block(BlockMakeData *data)
|
|||||||
{
|
{
|
||||||
enum LightBank bank = banks[i];
|
enum LightBank bank = banks[i];
|
||||||
|
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
core::map<v3s16, u8> unlight_from;
|
std::map<v3s16, u8> unlight_from;
|
||||||
|
|
||||||
voxalgo::clearLightAndCollectSources(vmanip, a, bank, ndef,
|
voxalgo::clearLightAndCollectSources(vmanip, a, bank, ndef,
|
||||||
light_sources, unlight_from);
|
light_sources, unlight_from);
|
||||||
|
@ -1422,8 +1422,8 @@ void MapgenV6::makeChunk(BlockMakeData *data)
|
|||||||
{
|
{
|
||||||
enum LightBank bank = banks[i];
|
enum LightBank bank = banks[i];
|
||||||
|
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
core::map<v3s16, u8> unlight_from;
|
std::map<v3s16, u8> unlight_from;
|
||||||
|
|
||||||
voxalgo::clearLightAndCollectSources(vmanip, a, bank, ndef,
|
voxalgo::clearLightAndCollectSources(vmanip, a, bank, ndef,
|
||||||
light_sources, unlight_from);
|
light_sources, unlight_from);
|
||||||
|
@ -45,10 +45,10 @@ void MapSector::deleteBlocks()
|
|||||||
m_block_cache = NULL;
|
m_block_cache = NULL;
|
||||||
|
|
||||||
// Delete all
|
// Delete all
|
||||||
core::map<s16, MapBlock*>::Iterator i = m_blocks.getIterator();
|
for(std::map<s16, MapBlock*>::iterator i = m_blocks.begin();
|
||||||
for(; i.atEnd() == false; i++)
|
i != m_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
delete i.getNode()->getValue();
|
delete i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear container
|
// Clear container
|
||||||
@ -64,14 +64,14 @@ MapBlock * MapSector::getBlockBuffered(s16 y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If block doesn't exist, return NULL
|
// If block doesn't exist, return NULL
|
||||||
core::map<s16, MapBlock*>::Node *n = m_blocks.find(y);
|
std::map<s16, MapBlock*>::iterator n = m_blocks.find(y);
|
||||||
if(n == NULL)
|
if(n == m_blocks.end())
|
||||||
{
|
{
|
||||||
block = NULL;
|
block = NULL;
|
||||||
}
|
}
|
||||||
// If block exists, return it
|
// If block exists, return it
|
||||||
else{
|
else{
|
||||||
block = n->getValue();
|
block = n->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache the last result
|
// Cache the last result
|
||||||
@ -101,7 +101,7 @@ MapBlock * MapSector::createBlankBlock(s16 y)
|
|||||||
{
|
{
|
||||||
MapBlock *block = createBlankBlockNoInsert(y);
|
MapBlock *block = createBlankBlockNoInsert(y);
|
||||||
|
|
||||||
m_blocks.insert(y, block);
|
m_blocks[y] = block;
|
||||||
|
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ void MapSector::insertBlock(MapBlock *block)
|
|||||||
assert(p2d == m_pos);
|
assert(p2d == m_pos);
|
||||||
|
|
||||||
// Insert into container
|
// Insert into container
|
||||||
m_blocks.insert(block_y, block);
|
m_blocks[block_y] = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapSector::deleteBlock(MapBlock *block)
|
void MapSector::deleteBlock(MapBlock *block)
|
||||||
@ -130,23 +130,18 @@ void MapSector::deleteBlock(MapBlock *block)
|
|||||||
m_block_cache = NULL;
|
m_block_cache = NULL;
|
||||||
|
|
||||||
// Remove from container
|
// Remove from container
|
||||||
m_blocks.remove(block_y);
|
m_blocks.erase(block_y);
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
delete block;
|
delete block;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapSector::getBlocks(core::list<MapBlock*> &dest)
|
void MapSector::getBlocks(std::list<MapBlock*> &dest)
|
||||||
{
|
{
|
||||||
core::list<MapBlock*> ref_list;
|
for(std::map<s16, MapBlock*>::iterator bi = m_blocks.begin();
|
||||||
|
bi != m_blocks.end(); ++bi)
|
||||||
core::map<s16, MapBlock*>::Iterator bi;
|
|
||||||
|
|
||||||
bi = m_blocks.getIterator();
|
|
||||||
for(; bi.atEnd() == false; bi++)
|
|
||||||
{
|
{
|
||||||
MapBlock *b = bi.getNode()->getValue();
|
dest.push_back(bi->second);
|
||||||
dest.push_back(b);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +184,7 @@ ServerMapSector* ServerMapSector::deSerialize(
|
|||||||
std::istream &is,
|
std::istream &is,
|
||||||
Map *parent,
|
Map *parent,
|
||||||
v2s16 p2d,
|
v2s16 p2d,
|
||||||
core::map<v2s16, MapSector*> & sectors,
|
std::map<v2s16, MapSector*> & sectors,
|
||||||
IGameDef *gamedef
|
IGameDef *gamedef
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -219,22 +214,22 @@ ServerMapSector* ServerMapSector::deSerialize(
|
|||||||
|
|
||||||
ServerMapSector *sector = NULL;
|
ServerMapSector *sector = NULL;
|
||||||
|
|
||||||
core::map<v2s16, MapSector*>::Node *n = sectors.find(p2d);
|
std::map<v2s16, MapSector*>::iterator n = sectors.find(p2d);
|
||||||
|
|
||||||
if(n != NULL)
|
if(n != sectors.end())
|
||||||
{
|
{
|
||||||
dstream<<"WARNING: deSerializing existent sectors not supported "
|
dstream<<"WARNING: deSerializing existent sectors not supported "
|
||||||
"at the moment, because code hasn't been tested."
|
"at the moment, because code hasn't been tested."
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
|
|
||||||
MapSector *sector = n->getValue();
|
MapSector *sector = n->second;
|
||||||
assert(sector->getId() == MAPSECTOR_SERVER);
|
assert(sector->getId() == MAPSECTOR_SERVER);
|
||||||
return (ServerMapSector*)sector;
|
return (ServerMapSector*)sector;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sector = new ServerMapSector(parent, p2d, gamedef);
|
sector = new ServerMapSector(parent, p2d, gamedef);
|
||||||
sectors.insert(p2d, sector);
|
sectors[p2d] = sector;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "irrlichttypes_bloated.h"
|
#include "irrlichttypes_bloated.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
#include <map>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
class MapBlock;
|
class MapBlock;
|
||||||
class Map;
|
class Map;
|
||||||
@ -60,7 +62,7 @@ public:
|
|||||||
|
|
||||||
void deleteBlock(MapBlock *block);
|
void deleteBlock(MapBlock *block);
|
||||||
|
|
||||||
void getBlocks(core::list<MapBlock*> &dest);
|
void getBlocks(std::list<MapBlock*> &dest);
|
||||||
|
|
||||||
// Always false at the moment, because sector contains no metadata.
|
// Always false at the moment, because sector contains no metadata.
|
||||||
bool differs_from_disk;
|
bool differs_from_disk;
|
||||||
@ -68,7 +70,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
// The pile of MapBlocks
|
// The pile of MapBlocks
|
||||||
core::map<s16, MapBlock*> m_blocks;
|
std::map<s16, MapBlock*> m_blocks;
|
||||||
|
|
||||||
Map *m_parent;
|
Map *m_parent;
|
||||||
// Position on parent (in MapBlock widths)
|
// Position on parent (in MapBlock widths)
|
||||||
@ -110,7 +112,7 @@ public:
|
|||||||
std::istream &is,
|
std::istream &is,
|
||||||
Map *parent,
|
Map *parent,
|
||||||
v2s16 p2d,
|
v2s16 p2d,
|
||||||
core::map<v2s16, MapSector*> & sectors,
|
std::map<v2s16, MapSector*> & sectors,
|
||||||
IGameDef *gamedef
|
IGameDef *gamedef
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
class ModError : public std::exception
|
class ModError : public std::exception
|
||||||
{
|
{
|
||||||
@ -68,7 +69,6 @@ struct ModSpec
|
|||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
std::map<std::string,ModSpec> getModsInPath(std::string path);
|
std::map<std::string,ModSpec> getModsInPath(std::string path);
|
||||||
|
|
||||||
// expands modpack contents, but does not replace them.
|
// expands modpack contents, but does not replace them.
|
||||||
@ -140,6 +140,4 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "irrlichttypes_bloated.h"
|
#include "irrlichttypes_bloated.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct ObjectProperties
|
struct ObjectProperties
|
||||||
{
|
{
|
||||||
@ -35,8 +36,8 @@ struct ObjectProperties
|
|||||||
std::string visual;
|
std::string visual;
|
||||||
std::string mesh;
|
std::string mesh;
|
||||||
v2f visual_size;
|
v2f visual_size;
|
||||||
core::array<std::string> textures;
|
std::vector<std::string> textures;
|
||||||
core::array<video::SColor> colors;
|
std::vector<video::SColor> colors;
|
||||||
v2s16 spritediv;
|
v2s16 spritediv;
|
||||||
v2s16 initial_sprite_basepos;
|
v2s16 initial_sprite_basepos;
|
||||||
bool is_visible;
|
bool is_visible;
|
||||||
|
@ -45,21 +45,21 @@ public:
|
|||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
{
|
{
|
||||||
/* No average shall have been used; mark add used as -2 */
|
/* No average shall have been used; mark add used as -2 */
|
||||||
core::map<std::string, int>::Node *n = m_avgcounts.find(name);
|
std::map<std::string, int>::iterator n = m_avgcounts.find(name);
|
||||||
if(n == NULL)
|
if(n == m_avgcounts.end())
|
||||||
m_avgcounts[name] = -2;
|
m_avgcounts[name] = -2;
|
||||||
else{
|
else{
|
||||||
if(n->getValue() == -1)
|
if(n->second == -1)
|
||||||
n->setValue(-2);
|
n->second = -2;
|
||||||
assert(n->getValue() == -2);
|
assert(n->second == -2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::map<std::string, float>::Node *n = m_data.find(name);
|
std::map<std::string, float>::iterator n = m_data.find(name);
|
||||||
if(n == NULL)
|
if(n == m_data.end())
|
||||||
m_data[name] = value;
|
m_data[name] = value;
|
||||||
else
|
else
|
||||||
n->setValue(n->getValue() + value);
|
n->second += value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,35 +67,32 @@ public:
|
|||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
{
|
{
|
||||||
core::map<std::string, int>::Node *n = m_avgcounts.find(name);
|
std::map<std::string, int>::iterator n = m_avgcounts.find(name);
|
||||||
if(n == NULL)
|
if(n == m_avgcounts.end())
|
||||||
m_avgcounts[name] = 1;
|
m_avgcounts[name] = 1;
|
||||||
else{
|
else{
|
||||||
/* No add shall have been used */
|
/* No add shall have been used */
|
||||||
assert(n->getValue() != -2);
|
assert(n->second != -2);
|
||||||
if(n->getValue() <= 0)
|
n->second = std::max(n->second, 0) + 1;
|
||||||
n->setValue(1);
|
|
||||||
else
|
|
||||||
n->setValue(n->getValue() + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::map<std::string, float>::Node *n = m_data.find(name);
|
std::map<std::string, float>::iterator n = m_data.find(name);
|
||||||
if(n == NULL)
|
if(n == m_data.end())
|
||||||
m_data[name] = value;
|
m_data[name] = value;
|
||||||
else
|
else
|
||||||
n->setValue(n->getValue() + value);
|
n->second += value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
for(core::map<std::string, float>::Iterator
|
for(std::map<std::string, float>::iterator
|
||||||
i = m_data.getIterator();
|
i = m_data.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_data.end(); ++i)
|
||||||
{
|
{
|
||||||
i.getNode()->setValue(0);
|
i->second = 0;
|
||||||
}
|
}
|
||||||
m_avgcounts.clear();
|
m_avgcounts.clear();
|
||||||
}
|
}
|
||||||
@ -112,9 +109,9 @@ public:
|
|||||||
u32 minindex, maxindex;
|
u32 minindex, maxindex;
|
||||||
paging(m_data.size(), page, pagecount, minindex, maxindex);
|
paging(m_data.size(), page, pagecount, minindex, maxindex);
|
||||||
|
|
||||||
for(core::map<std::string, float>::Iterator
|
for(std::map<std::string, float>::iterator
|
||||||
i = m_data.getIterator();
|
i = m_data.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_data.end(); ++i)
|
||||||
{
|
{
|
||||||
if(maxindex == 0)
|
if(maxindex == 0)
|
||||||
break;
|
break;
|
||||||
@ -126,12 +123,12 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name = i.getNode()->getKey();
|
std::string name = i->first;
|
||||||
int avgcount = 1;
|
int avgcount = 1;
|
||||||
core::map<std::string, int>::Node *n = m_avgcounts.find(name);
|
std::map<std::string, int>::iterator n = m_avgcounts.find(name);
|
||||||
if(n){
|
if(n != m_avgcounts.end()){
|
||||||
if(n->getValue() >= 1)
|
if(n->second >= 1)
|
||||||
avgcount = n->getValue();
|
avgcount = n->second;
|
||||||
}
|
}
|
||||||
o<<" "<<name<<": ";
|
o<<" "<<name<<": ";
|
||||||
s32 clampsize = 40;
|
s32 clampsize = 40;
|
||||||
@ -143,7 +140,7 @@ public:
|
|||||||
else
|
else
|
||||||
o<<" ";
|
o<<" ";
|
||||||
}
|
}
|
||||||
o<<(i.getNode()->getValue() / avgcount);
|
o<<(i->second / avgcount);
|
||||||
o<<std::endl;
|
o<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,8 +166,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
JMutex m_mutex;
|
JMutex m_mutex;
|
||||||
core::map<std::string, float> m_data;
|
std::map<std::string, float> m_data;
|
||||||
core::map<std::string, int> m_avgcounts;
|
std::map<std::string, int> m_avgcounts;
|
||||||
std::map<std::string, float> m_graphvalues;
|
std::map<std::string, float> m_graphvalues;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -895,24 +895,24 @@ static int l_get_modpath(lua_State *L)
|
|||||||
static int l_get_modnames(lua_State *L)
|
static int l_get_modnames(lua_State *L)
|
||||||
{
|
{
|
||||||
// Get a list of mods
|
// Get a list of mods
|
||||||
core::list<std::string> mods_unsorted, mods_sorted;
|
std::list<std::string> mods_unsorted, mods_sorted;
|
||||||
get_server(L)->getModNames(mods_unsorted);
|
get_server(L)->getModNames(mods_unsorted);
|
||||||
|
|
||||||
// Take unsorted items from mods_unsorted and sort them into
|
// Take unsorted items from mods_unsorted and sort them into
|
||||||
// mods_sorted; not great performance but the number of mods on a
|
// mods_sorted; not great performance but the number of mods on a
|
||||||
// server will likely be small.
|
// server will likely be small.
|
||||||
for(core::list<std::string>::Iterator i = mods_unsorted.begin();
|
for(std::list<std::string>::iterator i = mods_unsorted.begin();
|
||||||
i != mods_unsorted.end(); i++)
|
i != mods_unsorted.end(); ++i)
|
||||||
{
|
{
|
||||||
bool added = false;
|
bool added = false;
|
||||||
for(core::list<std::string>::Iterator x = mods_sorted.begin();
|
for(std::list<std::string>::iterator x = mods_sorted.begin();
|
||||||
x != mods_unsorted.end(); x++)
|
x != mods_unsorted.end(); ++x)
|
||||||
{
|
{
|
||||||
// I doubt anybody using Minetest will be using
|
// I doubt anybody using Minetest will be using
|
||||||
// anything not ASCII based :)
|
// anything not ASCII based :)
|
||||||
if((*i).compare(*x) <= 0)
|
if((*i).compare(*x) <= 0)
|
||||||
{
|
{
|
||||||
mods_sorted.insert_before(x, *i);
|
mods_sorted.insert(x, *i);
|
||||||
added = true;
|
added = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -929,7 +929,7 @@ static int l_get_modnames(lua_State *L)
|
|||||||
// Package them up for Lua
|
// Package them up for Lua
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int new_table = lua_gettop(L);
|
int new_table = lua_gettop(L);
|
||||||
core::list<std::string>::Iterator i = mods_sorted.begin();
|
std::list<std::string>::iterator i = mods_sorted.begin();
|
||||||
while(i != mods_sorted.end())
|
while(i != mods_sorted.end())
|
||||||
{
|
{
|
||||||
lua_pushvalue(L, insertion_func);
|
lua_pushvalue(L, insertion_func);
|
||||||
@ -939,7 +939,7 @@ static int l_get_modnames(lua_State *L)
|
|||||||
{
|
{
|
||||||
script_error(L, "error: %s", lua_tostring(L, -1));
|
script_error(L, "error: %s", lua_tostring(L, -1));
|
||||||
}
|
}
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -532,10 +532,10 @@ int EnvRef::l_find_node_near(lua_State *L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(int d=1; d<=radius; d++){
|
for(int d=1; d<=radius; d++){
|
||||||
core::list<v3s16> list;
|
std::list<v3s16> list;
|
||||||
getFacePositions(list, d);
|
getFacePositions(list, d);
|
||||||
for(core::list<v3s16>::Iterator i = list.begin();
|
for(std::list<v3s16>::iterator i = list.begin();
|
||||||
i != list.end(); i++){
|
i != list.end(); ++i){
|
||||||
v3s16 p = pos + (*i);
|
v3s16 p = pos + (*i);
|
||||||
content_t c = env->getMap().getNodeNoEx(p).getContent();
|
content_t c = env->getMap().getNodeNoEx(p).getContent();
|
||||||
if(filter.count(c) != 0){
|
if(filter.count(c) != 0){
|
||||||
|
394
src/server.cpp
394
src/server.cpp
@ -126,7 +126,7 @@ v3f ServerSoundParams::getPos(ServerEnvironment *env, bool *pos_exists) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::GetNextBlocks(Server *server, float dtime,
|
void RemoteClient::GetNextBlocks(Server *server, float dtime,
|
||||||
core::array<PrioritySortedBlockTransfer> &dest)
|
std::vector<PrioritySortedBlockTransfer> &dest)
|
||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
|
|
||||||
@ -274,11 +274,11 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
|
|||||||
Get the border/face dot coordinates of a "d-radiused"
|
Get the border/face dot coordinates of a "d-radiused"
|
||||||
box
|
box
|
||||||
*/
|
*/
|
||||||
core::list<v3s16> list;
|
std::list<v3s16> list;
|
||||||
getFacePositions(list, d);
|
getFacePositions(list, d);
|
||||||
|
|
||||||
core::list<v3s16>::Iterator li;
|
std::list<v3s16>::iterator li;
|
||||||
for(li=list.begin(); li!=list.end(); li++)
|
for(li=list.begin(); li!=list.end(); ++li)
|
||||||
{
|
{
|
||||||
v3s16 p = *li + center;
|
v3s16 p = *li + center;
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't send blocks that are currently being transferred
|
// Don't send blocks that are currently being transferred
|
||||||
if(m_blocks_sending.find(p) != NULL)
|
if(m_blocks_sending.find(p) != m_blocks_sending.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -382,7 +382,7 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
|
|||||||
Don't send already sent blocks
|
Don't send already sent blocks
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
if(m_blocks_sent.find(p) != NULL)
|
if(m_blocks_sent.find(p) != m_blocks_sent.end())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -554,21 +554,21 @@ queue_full_break:
|
|||||||
|
|
||||||
void RemoteClient::GotBlock(v3s16 p)
|
void RemoteClient::GotBlock(v3s16 p)
|
||||||
{
|
{
|
||||||
if(m_blocks_sending.find(p) != NULL)
|
if(m_blocks_sending.find(p) != m_blocks_sending.end())
|
||||||
m_blocks_sending.remove(p);
|
m_blocks_sending.erase(p);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*infostream<<"RemoteClient::GotBlock(): Didn't find in"
|
/*infostream<<"RemoteClient::GotBlock(): Didn't find in"
|
||||||
" m_blocks_sending"<<std::endl;*/
|
" m_blocks_sending"<<std::endl;*/
|
||||||
m_excess_gotblocks++;
|
m_excess_gotblocks++;
|
||||||
}
|
}
|
||||||
m_blocks_sent.insert(p, true);
|
m_blocks_sent.insert(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::SentBlock(v3s16 p)
|
void RemoteClient::SentBlock(v3s16 p)
|
||||||
{
|
{
|
||||||
if(m_blocks_sending.find(p) == NULL)
|
if(m_blocks_sending.find(p) == m_blocks_sending.end())
|
||||||
m_blocks_sending.insert(p, 0.0);
|
m_blocks_sending[p] = 0.0;
|
||||||
else
|
else
|
||||||
infostream<<"RemoteClient::SentBlock(): Sent block"
|
infostream<<"RemoteClient::SentBlock(): Sent block"
|
||||||
" already in m_blocks_sending"<<std::endl;
|
" already in m_blocks_sending"<<std::endl;
|
||||||
@ -578,26 +578,26 @@ void RemoteClient::SetBlockNotSent(v3s16 p)
|
|||||||
{
|
{
|
||||||
m_nearest_unsent_d = 0;
|
m_nearest_unsent_d = 0;
|
||||||
|
|
||||||
if(m_blocks_sending.find(p) != NULL)
|
if(m_blocks_sending.find(p) != m_blocks_sending.end())
|
||||||
m_blocks_sending.remove(p);
|
m_blocks_sending.erase(p);
|
||||||
if(m_blocks_sent.find(p) != NULL)
|
if(m_blocks_sent.find(p) != m_blocks_sent.end())
|
||||||
m_blocks_sent.remove(p);
|
m_blocks_sent.erase(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::SetBlocksNotSent(core::map<v3s16, MapBlock*> &blocks)
|
void RemoteClient::SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks)
|
||||||
{
|
{
|
||||||
m_nearest_unsent_d = 0;
|
m_nearest_unsent_d = 0;
|
||||||
|
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = blocks.getIterator();
|
i = blocks.begin();
|
||||||
i.atEnd()==false; i++)
|
i != blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
v3s16 p = i->first;
|
||||||
|
|
||||||
if(m_blocks_sending.find(p) != NULL)
|
if(m_blocks_sending.find(p) != m_blocks_sending.end())
|
||||||
m_blocks_sending.remove(p);
|
m_blocks_sending.erase(p);
|
||||||
if(m_blocks_sent.find(p) != NULL)
|
if(m_blocks_sent.find(p) != m_blocks_sent.end())
|
||||||
m_blocks_sent.remove(p);
|
m_blocks_sent.erase(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -854,13 +854,13 @@ Server::~Server()
|
|||||||
/*
|
/*
|
||||||
Send the message to clients
|
Send the message to clients
|
||||||
*/
|
*/
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
// Get client and check that it is valid
|
// Get client and check that it is valid
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
assert(client->peer_id == i.getNode()->getKey());
|
assert(client->peer_id == i->first);
|
||||||
if(client->serialization_version == SER_FMT_VER_INVALID)
|
if(client->serialization_version == SER_FMT_VER_INVALID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -909,13 +909,13 @@ Server::~Server()
|
|||||||
{
|
{
|
||||||
JMutexAutoLock clientslock(m_con_mutex);
|
JMutexAutoLock clientslock(m_con_mutex);
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Delete client
|
// Delete client
|
||||||
delete i.getNode()->getValue();
|
delete i->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1073,11 +1073,11 @@ void Server::AsyncRunStep()
|
|||||||
//JMutexAutoLock envlock(m_env_mutex);
|
//JMutexAutoLock envlock(m_env_mutex);
|
||||||
JMutexAutoLock conlock(m_con_mutex);
|
JMutexAutoLock conlock(m_con_mutex);
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(
|
SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(
|
||||||
m_env->getTimeOfDay(), g_settings->getFloat("time_speed"));
|
m_env->getTimeOfDay(), g_settings->getFloat("time_speed"));
|
||||||
// Send as reliable
|
// Send as reliable
|
||||||
@ -1117,11 +1117,11 @@ void Server::AsyncRunStep()
|
|||||||
|
|
||||||
ScopeProfiler sp(g_profiler, "Server: handle players");
|
ScopeProfiler sp(g_profiler, "Server: handle players");
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
PlayerSAO *playersao = getPlayerSAO(client->peer_id);
|
PlayerSAO *playersao = getPlayerSAO(client->peer_id);
|
||||||
if(playersao == NULL)
|
if(playersao == NULL)
|
||||||
continue;
|
continue;
|
||||||
@ -1161,7 +1161,7 @@ void Server::AsyncRunStep()
|
|||||||
|
|
||||||
ScopeProfiler sp(g_profiler, "Server: liquid transform");
|
ScopeProfiler sp(g_profiler, "Server: liquid transform");
|
||||||
|
|
||||||
core::map<v3s16, MapBlock*> modified_blocks;
|
std::map<v3s16, MapBlock*> modified_blocks;
|
||||||
m_env->getMap().transformLiquids(modified_blocks);
|
m_env->getMap().transformLiquids(modified_blocks);
|
||||||
#if 0
|
#if 0
|
||||||
/*
|
/*
|
||||||
@ -1186,11 +1186,11 @@ void Server::AsyncRunStep()
|
|||||||
|
|
||||||
JMutexAutoLock lock2(m_con_mutex);
|
JMutexAutoLock lock2(m_con_mutex);
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
|
|
||||||
if(modified_blocks.size() > 0)
|
if(modified_blocks.size() > 0)
|
||||||
{
|
{
|
||||||
@ -1212,12 +1212,12 @@ void Server::AsyncRunStep()
|
|||||||
m_clients_number = 0;
|
m_clients_number = 0;
|
||||||
if(m_clients.size() != 0)
|
if(m_clients.size() != 0)
|
||||||
infostream<<"Players:"<<std::endl;
|
infostream<<"Players:"<<std::endl;
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
//u16 peer_id = i.getNode()->getKey();
|
//u16 peer_id = i.getNode()->getKey();
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
Player *player = m_env->getPlayer(client->peer_id);
|
Player *player = m_env->getPlayer(client->peer_id);
|
||||||
if(player==NULL)
|
if(player==NULL)
|
||||||
continue;
|
continue;
|
||||||
@ -1259,11 +1259,11 @@ void Server::AsyncRunStep()
|
|||||||
s16 radius = g_settings->getS16("active_object_send_range_blocks");
|
s16 radius = g_settings->getS16("active_object_send_range_blocks");
|
||||||
radius *= MAP_BLOCKSIZE;
|
radius *= MAP_BLOCKSIZE;
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
|
|
||||||
// If definitions and textures have not been sent, don't
|
// If definitions and textures have not been sent, don't
|
||||||
// send objects either
|
// send objects either
|
||||||
@ -1281,8 +1281,8 @@ void Server::AsyncRunStep()
|
|||||||
}
|
}
|
||||||
v3s16 pos = floatToInt(player->getPosition(), BS);
|
v3s16 pos = floatToInt(player->getPosition(), BS);
|
||||||
|
|
||||||
core::map<u16, bool> removed_objects;
|
std::set<u16> removed_objects;
|
||||||
core::map<u16, bool> added_objects;
|
std::set<u16> added_objects;
|
||||||
m_env->getRemovedActiveObjects(pos, radius,
|
m_env->getRemovedActiveObjects(pos, radius,
|
||||||
client->m_known_objects, removed_objects);
|
client->m_known_objects, removed_objects);
|
||||||
m_env->getAddedActiveObjects(pos, radius,
|
m_env->getAddedActiveObjects(pos, radius,
|
||||||
@ -1302,20 +1302,20 @@ void Server::AsyncRunStep()
|
|||||||
// Handle removed objects
|
// Handle removed objects
|
||||||
writeU16((u8*)buf, removed_objects.size());
|
writeU16((u8*)buf, removed_objects.size());
|
||||||
data_buffer.append(buf, 2);
|
data_buffer.append(buf, 2);
|
||||||
for(core::map<u16, bool>::Iterator
|
for(std::set<u16>::iterator
|
||||||
i = removed_objects.getIterator();
|
i = removed_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != removed_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
// Get object
|
// Get object
|
||||||
u16 id = i.getNode()->getKey();
|
u16 id = *i;
|
||||||
ServerActiveObject* obj = m_env->getActiveObject(id);
|
ServerActiveObject* obj = m_env->getActiveObject(id);
|
||||||
|
|
||||||
// Add to data buffer for sending
|
// Add to data buffer for sending
|
||||||
writeU16((u8*)buf, i.getNode()->getKey());
|
writeU16((u8*)buf, id);
|
||||||
data_buffer.append(buf, 2);
|
data_buffer.append(buf, 2);
|
||||||
|
|
||||||
// Remove from known objects
|
// Remove from known objects
|
||||||
client->m_known_objects.remove(i.getNode()->getKey());
|
client->m_known_objects.erase(id);
|
||||||
|
|
||||||
if(obj && obj->m_known_by_count > 0)
|
if(obj && obj->m_known_by_count > 0)
|
||||||
obj->m_known_by_count--;
|
obj->m_known_by_count--;
|
||||||
@ -1324,12 +1324,12 @@ void Server::AsyncRunStep()
|
|||||||
// Handle added objects
|
// Handle added objects
|
||||||
writeU16((u8*)buf, added_objects.size());
|
writeU16((u8*)buf, added_objects.size());
|
||||||
data_buffer.append(buf, 2);
|
data_buffer.append(buf, 2);
|
||||||
for(core::map<u16, bool>::Iterator
|
for(std::set<u16>::iterator
|
||||||
i = added_objects.getIterator();
|
i = added_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != added_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
// Get object
|
// Get object
|
||||||
u16 id = i.getNode()->getKey();
|
u16 id = *i;
|
||||||
ServerActiveObject* obj = m_env->getActiveObject(id);
|
ServerActiveObject* obj = m_env->getActiveObject(id);
|
||||||
|
|
||||||
// Get object type
|
// Get object type
|
||||||
@ -1353,7 +1353,7 @@ void Server::AsyncRunStep()
|
|||||||
data_buffer.append(serializeLongString(""));
|
data_buffer.append(serializeLongString(""));
|
||||||
|
|
||||||
// Add to known objects
|
// Add to known objects
|
||||||
client->m_known_objects.insert(i.getNode()->getKey(), false);
|
client->m_known_objects.insert(id);
|
||||||
|
|
||||||
if(obj)
|
if(obj)
|
||||||
obj->m_known_by_count++;
|
obj->m_known_by_count++;
|
||||||
@ -1412,7 +1412,7 @@ void Server::AsyncRunStep()
|
|||||||
|
|
||||||
// Key = object id
|
// Key = object id
|
||||||
// Value = data sent by object
|
// Value = data sent by object
|
||||||
core::map<u16, core::list<ActiveObjectMessage>* > buffered_messages;
|
std::map<u16, std::list<ActiveObjectMessage>* > buffered_messages;
|
||||||
|
|
||||||
// Get active object messages from environment
|
// Get active object messages from environment
|
||||||
for(;;)
|
for(;;)
|
||||||
@ -1421,43 +1421,43 @@ void Server::AsyncRunStep()
|
|||||||
if(aom.id == 0)
|
if(aom.id == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
core::list<ActiveObjectMessage>* message_list = NULL;
|
std::list<ActiveObjectMessage>* message_list = NULL;
|
||||||
core::map<u16, core::list<ActiveObjectMessage>* >::Node *n;
|
std::map<u16, std::list<ActiveObjectMessage>* >::iterator n;
|
||||||
n = buffered_messages.find(aom.id);
|
n = buffered_messages.find(aom.id);
|
||||||
if(n == NULL)
|
if(n == buffered_messages.end())
|
||||||
{
|
{
|
||||||
message_list = new core::list<ActiveObjectMessage>;
|
message_list = new std::list<ActiveObjectMessage>;
|
||||||
buffered_messages.insert(aom.id, message_list);
|
buffered_messages[aom.id] = message_list;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
message_list = n->getValue();
|
message_list = n->second;
|
||||||
}
|
}
|
||||||
message_list->push_back(aom);
|
message_list->push_back(aom);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route data to every client
|
// Route data to every client
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
std::string reliable_data;
|
std::string reliable_data;
|
||||||
std::string unreliable_data;
|
std::string unreliable_data;
|
||||||
// Go through all objects in message buffer
|
// Go through all objects in message buffer
|
||||||
for(core::map<u16, core::list<ActiveObjectMessage>* >::Iterator
|
for(std::map<u16, std::list<ActiveObjectMessage>* >::iterator
|
||||||
j = buffered_messages.getIterator();
|
j = buffered_messages.begin();
|
||||||
j.atEnd()==false; j++)
|
j != buffered_messages.end(); ++j)
|
||||||
{
|
{
|
||||||
// If object is not known by client, skip it
|
// If object is not known by client, skip it
|
||||||
u16 id = j.getNode()->getKey();
|
u16 id = j->first;
|
||||||
if(client->m_known_objects.find(id) == NULL)
|
if(client->m_known_objects.find(id) == client->m_known_objects.end())
|
||||||
continue;
|
continue;
|
||||||
// Get message list of object
|
// Get message list of object
|
||||||
core::list<ActiveObjectMessage>* list = j.getNode()->getValue();
|
std::list<ActiveObjectMessage>* list = j->second;
|
||||||
// Go through every message
|
// Go through every message
|
||||||
for(core::list<ActiveObjectMessage>::Iterator
|
for(std::list<ActiveObjectMessage>::iterator
|
||||||
k = list->begin(); k != list->end(); k++)
|
k = list->begin(); k != list->end(); ++k)
|
||||||
{
|
{
|
||||||
// Compose the full new data with header
|
// Compose the full new data with header
|
||||||
ActiveObjectMessage aom = *k;
|
ActiveObjectMessage aom = *k;
|
||||||
@ -1508,11 +1508,11 @@ void Server::AsyncRunStep()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear buffered_messages
|
// Clear buffered_messages
|
||||||
for(core::map<u16, core::list<ActiveObjectMessage>* >::Iterator
|
for(std::map<u16, std::list<ActiveObjectMessage>* >::iterator
|
||||||
i = buffered_messages.getIterator();
|
i = buffered_messages.begin();
|
||||||
i.atEnd()==false; i++)
|
i != buffered_messages.end(); ++i)
|
||||||
{
|
{
|
||||||
delete i.getNode()->getValue();
|
delete i->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1546,7 +1546,7 @@ void Server::AsyncRunStep()
|
|||||||
// Players far away from the change are stored here.
|
// Players far away from the change are stored here.
|
||||||
// Instead of sending the changes, MapBlocks are set not sent
|
// Instead of sending the changes, MapBlocks are set not sent
|
||||||
// for them.
|
// for them.
|
||||||
core::list<u16> far_players;
|
std::list<u16> far_players;
|
||||||
|
|
||||||
if(event->type == MEET_ADDNODE)
|
if(event->type == MEET_ADDNODE)
|
||||||
{
|
{
|
||||||
@ -1580,12 +1580,11 @@ void Server::AsyncRunStep()
|
|||||||
{
|
{
|
||||||
infostream<<"Server: MEET_OTHER"<<std::endl;
|
infostream<<"Server: MEET_OTHER"<<std::endl;
|
||||||
prof.add("MEET_OTHER", 1);
|
prof.add("MEET_OTHER", 1);
|
||||||
for(core::map<v3s16, bool>::Iterator
|
for(std::set<v3s16>::iterator
|
||||||
i = event->modified_blocks.getIterator();
|
i = event->modified_blocks.begin();
|
||||||
i.atEnd()==false; i++)
|
i != event->modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
setBlockNotSent(*i);
|
||||||
setBlockNotSent(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1601,19 +1600,18 @@ void Server::AsyncRunStep()
|
|||||||
if(far_players.size() > 0)
|
if(far_players.size() > 0)
|
||||||
{
|
{
|
||||||
// Convert list format to that wanted by SetBlocksNotSent
|
// Convert list format to that wanted by SetBlocksNotSent
|
||||||
core::map<v3s16, MapBlock*> modified_blocks2;
|
std::map<v3s16, MapBlock*> modified_blocks2;
|
||||||
for(core::map<v3s16, bool>::Iterator
|
for(std::set<v3s16>::iterator
|
||||||
i = event->modified_blocks.getIterator();
|
i = event->modified_blocks.begin();
|
||||||
i.atEnd()==false; i++)
|
i != event->modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
modified_blocks2[*i] =
|
||||||
modified_blocks2.insert(p,
|
m_env->getMap().getBlockNoCreateNoEx(*i);
|
||||||
m_env->getMap().getBlockNoCreateNoEx(p));
|
|
||||||
}
|
}
|
||||||
// Set blocks not sent
|
// Set blocks not sent
|
||||||
for(core::list<u16>::Iterator
|
for(std::list<u16>::iterator
|
||||||
i = far_players.begin();
|
i = far_players.begin();
|
||||||
i != far_players.end(); i++)
|
i != far_players.end(); ++i)
|
||||||
{
|
{
|
||||||
u16 peer_id = *i;
|
u16 peer_id = *i;
|
||||||
RemoteClient *client = getClient(peer_id);
|
RemoteClient *client = getClient(peer_id);
|
||||||
@ -1792,7 +1790,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
u8 client_max = data[2];
|
u8 client_max = data[2];
|
||||||
u8 our_max = SER_FMT_VER_HIGHEST;
|
u8 our_max = SER_FMT_VER_HIGHEST;
|
||||||
// Use the highest version supported by both
|
// Use the highest version supported by both
|
||||||
u8 deployed = core::min_(client_max, our_max);
|
u8 deployed = std::min(client_max, our_max);
|
||||||
// If it's lower than the lowest supported, give up.
|
// If it's lower than the lowest supported, give up.
|
||||||
if(deployed < SER_FMT_VER_LOWEST)
|
if(deployed < SER_FMT_VER_LOWEST)
|
||||||
deployed = SER_FMT_VER_INVALID;
|
deployed = SER_FMT_VER_INVALID;
|
||||||
@ -2143,12 +2141,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
std::ostringstream os(std::ios_base::binary);
|
std::ostringstream os(std::ios_base::binary);
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
assert(client->peer_id == i.getNode()->getKey());
|
assert(client->peer_id == i->first);
|
||||||
if(client->serialization_version == SER_FMT_VER_INVALID)
|
if(client->serialization_version == SER_FMT_VER_INVALID)
|
||||||
continue;
|
continue;
|
||||||
// Get player
|
// Get player
|
||||||
@ -2520,13 +2518,13 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
/*
|
/*
|
||||||
Send the message to clients
|
Send the message to clients
|
||||||
*/
|
*/
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
// Get client and check that it is valid
|
// Get client and check that it is valid
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
assert(client->peer_id == i.getNode()->getKey());
|
assert(client->peer_id == i->first);
|
||||||
if(client->serialization_version == SER_FMT_VER_INVALID)
|
if(client->serialization_version == SER_FMT_VER_INVALID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -2651,7 +2649,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
std::string datastring((char*)&data[2], datasize-2);
|
std::string datastring((char*)&data[2], datasize-2);
|
||||||
std::istringstream is(datastring, std::ios_base::binary);
|
std::istringstream is(datastring, std::ios_base::binary);
|
||||||
|
|
||||||
core::list<MediaRequest> tosend;
|
std::list<MediaRequest> tosend;
|
||||||
u16 numfiles = readU16(is);
|
u16 numfiles = readU16(is);
|
||||||
|
|
||||||
infostream<<"Sending "<<numfiles<<" files to "
|
infostream<<"Sending "<<numfiles<<" files to "
|
||||||
@ -3189,19 +3187,19 @@ void Server::setInventoryModified(const InventoryLocation &loc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<PlayerInfo> Server::getPlayerInfo()
|
std::list<PlayerInfo> Server::getPlayerInfo()
|
||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
JMutexAutoLock envlock(m_env_mutex);
|
JMutexAutoLock envlock(m_env_mutex);
|
||||||
JMutexAutoLock conlock(m_con_mutex);
|
JMutexAutoLock conlock(m_con_mutex);
|
||||||
|
|
||||||
core::list<PlayerInfo> list;
|
std::list<PlayerInfo> list;
|
||||||
|
|
||||||
core::list<Player*> players = m_env->getPlayers();
|
std::list<Player*> players = m_env->getPlayers();
|
||||||
|
|
||||||
core::list<Player*>::Iterator i;
|
std::list<Player*>::iterator i;
|
||||||
for(i = players.begin();
|
for(i = players.begin();
|
||||||
i != players.end(); i++)
|
i != players.end(); ++i)
|
||||||
{
|
{
|
||||||
PlayerInfo info;
|
PlayerInfo info;
|
||||||
|
|
||||||
@ -3470,13 +3468,13 @@ void Server::SendShowFormspecMessage(u16 peer_id, const std::string formspec, co
|
|||||||
|
|
||||||
void Server::BroadcastChatMessage(const std::wstring &message)
|
void Server::BroadcastChatMessage(const std::wstring &message)
|
||||||
{
|
{
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
// Get client and check that it is valid
|
// Get client and check that it is valid
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
assert(client->peer_id == i.getNode()->getKey());
|
assert(client->peer_id == i->first);
|
||||||
if(client->serialization_version == SER_FMT_VER_INVALID)
|
if(client->serialization_version == SER_FMT_VER_INVALID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -3595,10 +3593,10 @@ s32 Server::playSound(const SimpleSoundSpec &spec,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator(); i.atEnd() == false; i++)
|
i = m_clients.begin(); i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
Player *player = m_env->getPlayer(client->peer_id);
|
Player *player = m_env->getPlayer(client->peer_id);
|
||||||
if(!player)
|
if(!player)
|
||||||
continue;
|
continue;
|
||||||
@ -3668,7 +3666,7 @@ void Server::stopSound(s32 handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
||||||
core::list<u16> *far_players, float far_d_nodes)
|
std::list<u16> *far_players, float far_d_nodes)
|
||||||
{
|
{
|
||||||
float maxd = far_d_nodes*BS;
|
float maxd = far_d_nodes*BS;
|
||||||
v3f p_f = intToFloat(p, BS);
|
v3f p_f = intToFloat(p, BS);
|
||||||
@ -3681,13 +3679,13 @@ void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
|||||||
writeS16(&reply[4], p.Y);
|
writeS16(&reply[4], p.Y);
|
||||||
writeS16(&reply[6], p.Z);
|
writeS16(&reply[6], p.Z);
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
// Get client and check that it is valid
|
// Get client and check that it is valid
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
assert(client->peer_id == i.getNode()->getKey());
|
assert(client->peer_id == i->first);
|
||||||
if(client->serialization_version == SER_FMT_VER_INVALID)
|
if(client->serialization_version == SER_FMT_VER_INVALID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -3717,18 +3715,18 @@ void Server::sendRemoveNode(v3s16 p, u16 ignore_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
|
void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
|
||||||
core::list<u16> *far_players, float far_d_nodes)
|
std::list<u16> *far_players, float far_d_nodes)
|
||||||
{
|
{
|
||||||
float maxd = far_d_nodes*BS;
|
float maxd = far_d_nodes*BS;
|
||||||
v3f p_f = intToFloat(p, BS);
|
v3f p_f = intToFloat(p, BS);
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
// Get client and check that it is valid
|
// Get client and check that it is valid
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
assert(client->peer_id == i.getNode()->getKey());
|
assert(client->peer_id == i->first);
|
||||||
if(client->serialization_version == SER_FMT_VER_INVALID)
|
if(client->serialization_version == SER_FMT_VER_INVALID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -3768,11 +3766,11 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id,
|
|||||||
|
|
||||||
void Server::setBlockNotSent(v3s16 p)
|
void Server::setBlockNotSent(v3s16 p)
|
||||||
{
|
{
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
client->SetBlockNotSent(p);
|
client->SetBlockNotSent(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3839,19 +3837,19 @@ void Server::SendBlocks(float dtime)
|
|||||||
|
|
||||||
ScopeProfiler sp(g_profiler, "Server: sel and send blocks to clients");
|
ScopeProfiler sp(g_profiler, "Server: sel and send blocks to clients");
|
||||||
|
|
||||||
core::array<PrioritySortedBlockTransfer> queue;
|
std::vector<PrioritySortedBlockTransfer> queue;
|
||||||
|
|
||||||
s32 total_sending = 0;
|
s32 total_sending = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
ScopeProfiler sp(g_profiler, "Server: selecting blocks for sending");
|
ScopeProfiler sp(g_profiler, "Server: selecting blocks for sending");
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
assert(client->peer_id == i.getNode()->getKey());
|
assert(client->peer_id == i->first);
|
||||||
|
|
||||||
// If definitions and textures have not been sent, don't
|
// If definitions and textures have not been sent, don't
|
||||||
// send MapBlocks either
|
// send MapBlocks either
|
||||||
@ -3870,7 +3868,7 @@ void Server::SendBlocks(float dtime)
|
|||||||
// Sort.
|
// Sort.
|
||||||
// Lowest priority number comes first.
|
// Lowest priority number comes first.
|
||||||
// Lowest is most important.
|
// Lowest is most important.
|
||||||
queue.sort();
|
std::sort(queue.begin(), queue.end());
|
||||||
|
|
||||||
for(u32 i=0; i<queue.size(); i++)
|
for(u32 i=0; i<queue.size(); i++)
|
||||||
{
|
{
|
||||||
@ -4017,7 +4015,7 @@ void Server::sendMediaAnnouncement(u16 peer_id)
|
|||||||
verbosestream<<"Server: Announcing files to id("<<peer_id<<")"
|
verbosestream<<"Server: Announcing files to id("<<peer_id<<")"
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
|
|
||||||
core::list<SendableMediaAnnouncement> file_announcements;
|
std::list<SendableMediaAnnouncement> file_announcements;
|
||||||
|
|
||||||
for(std::map<std::string, MediaInfo>::iterator i = m_media.begin();
|
for(std::map<std::string, MediaInfo>::iterator i = m_media.begin();
|
||||||
i != m_media.end(); i++){
|
i != m_media.end(); i++){
|
||||||
@ -4043,9 +4041,9 @@ void Server::sendMediaAnnouncement(u16 peer_id)
|
|||||||
writeU16(os, TOCLIENT_ANNOUNCE_MEDIA);
|
writeU16(os, TOCLIENT_ANNOUNCE_MEDIA);
|
||||||
writeU16(os, file_announcements.size());
|
writeU16(os, file_announcements.size());
|
||||||
|
|
||||||
for(core::list<SendableMediaAnnouncement>::Iterator
|
for(std::list<SendableMediaAnnouncement>::iterator
|
||||||
j = file_announcements.begin();
|
j = file_announcements.begin();
|
||||||
j != file_announcements.end(); j++){
|
j != file_announcements.end(); ++j){
|
||||||
os<<serializeString(j->name);
|
os<<serializeString(j->name);
|
||||||
os<<serializeString(j->sha1_digest);
|
os<<serializeString(j->sha1_digest);
|
||||||
}
|
}
|
||||||
@ -4074,7 +4072,7 @@ struct SendableMedia
|
|||||||
};
|
};
|
||||||
|
|
||||||
void Server::sendRequestedMedia(u16 peer_id,
|
void Server::sendRequestedMedia(u16 peer_id,
|
||||||
const core::list<MediaRequest> &tosend)
|
const std::list<MediaRequest> &tosend)
|
||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
|
|
||||||
@ -4086,13 +4084,13 @@ void Server::sendRequestedMedia(u16 peer_id,
|
|||||||
// Put 5kB in one bunch (this is not accurate)
|
// Put 5kB in one bunch (this is not accurate)
|
||||||
u32 bytes_per_bunch = 5000;
|
u32 bytes_per_bunch = 5000;
|
||||||
|
|
||||||
core::array< core::list<SendableMedia> > file_bunches;
|
std::vector< std::list<SendableMedia> > file_bunches;
|
||||||
file_bunches.push_back(core::list<SendableMedia>());
|
file_bunches.push_back(std::list<SendableMedia>());
|
||||||
|
|
||||||
u32 file_size_bunch_total = 0;
|
u32 file_size_bunch_total = 0;
|
||||||
|
|
||||||
for(core::list<MediaRequest>::ConstIterator i = tosend.begin();
|
for(std::list<MediaRequest>::const_iterator i = tosend.begin();
|
||||||
i != tosend.end(); i++)
|
i != tosend.end(); ++i)
|
||||||
{
|
{
|
||||||
if(m_media.find(i->name) == m_media.end()){
|
if(m_media.find(i->name) == m_media.end()){
|
||||||
errorstream<<"Server::sendRequestedMedia(): Client asked for "
|
errorstream<<"Server::sendRequestedMedia(): Client asked for "
|
||||||
@ -4138,7 +4136,7 @@ void Server::sendRequestedMedia(u16 peer_id,
|
|||||||
|
|
||||||
// Start next bunch if got enough data
|
// Start next bunch if got enough data
|
||||||
if(file_size_bunch_total >= bytes_per_bunch){
|
if(file_size_bunch_total >= bytes_per_bunch){
|
||||||
file_bunches.push_back(core::list<SendableMedia>());
|
file_bunches.push_back(std::list<SendableMedia>());
|
||||||
file_size_bunch_total = 0;
|
file_size_bunch_total = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4169,9 +4167,9 @@ void Server::sendRequestedMedia(u16 peer_id,
|
|||||||
writeU16(os, i);
|
writeU16(os, i);
|
||||||
writeU32(os, file_bunches[i].size());
|
writeU32(os, file_bunches[i].size());
|
||||||
|
|
||||||
for(core::list<SendableMedia>::Iterator
|
for(std::list<SendableMedia>::iterator
|
||||||
j = file_bunches[i].begin();
|
j = file_bunches[i].begin();
|
||||||
j != file_bunches[i].end(); j++){
|
j != file_bunches[i].end(); ++j){
|
||||||
os<<serializeString(j->name);
|
os<<serializeString(j->name);
|
||||||
os<<serializeLongString(j->data);
|
os<<serializeLongString(j->data);
|
||||||
}
|
}
|
||||||
@ -4212,10 +4210,10 @@ void Server::sendDetachedInventoryToAll(const std::string &name)
|
|||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
|
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++){
|
i != m_clients.end(); ++i){
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
sendDetachedInventory(name, client->peer_id);
|
sendDetachedInventory(name, client->peer_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4299,11 +4297,11 @@ RemoteClient* Server::getClient(u16 peer_id)
|
|||||||
{
|
{
|
||||||
DSTACK(__FUNCTION_NAME);
|
DSTACK(__FUNCTION_NAME);
|
||||||
//JMutexAutoLock lock(m_con_mutex);
|
//JMutexAutoLock lock(m_con_mutex);
|
||||||
core::map<u16, RemoteClient*>::Node *n;
|
std::map<u16, RemoteClient*>::iterator n;
|
||||||
n = m_clients.find(peer_id);
|
n = m_clients.find(peer_id);
|
||||||
// A client should exist for all peers
|
// A client should exist for all peers
|
||||||
assert(n != NULL);
|
assert(n != m_clients.end());
|
||||||
return n->getValue();
|
return n->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring Server::getStatusString()
|
std::wstring Server::getStatusString()
|
||||||
@ -4315,15 +4313,15 @@ std::wstring Server::getStatusString()
|
|||||||
// Uptime
|
// Uptime
|
||||||
os<<L", uptime="<<m_uptime.get();
|
os<<L", uptime="<<m_uptime.get();
|
||||||
// Information about clients
|
// Information about clients
|
||||||
core::map<u16, RemoteClient*>::Iterator i;
|
std::map<u16, RemoteClient*>::iterator i;
|
||||||
bool first;
|
bool first;
|
||||||
os<<L", clients={";
|
os<<L", clients={";
|
||||||
for(i = m_clients.getIterator(), first = true;
|
for(i = m_clients.begin(), first = true;
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
// Get client and check that it is valid
|
// Get client and check that it is valid
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
assert(client->peer_id == i.getNode()->getKey());
|
assert(client->peer_id == i->first);
|
||||||
if(client->serialization_version == SER_FMT_VER_INVALID)
|
if(client->serialization_version == SER_FMT_VER_INVALID)
|
||||||
continue;
|
continue;
|
||||||
// Get player
|
// Get player
|
||||||
@ -4363,10 +4361,10 @@ bool Server::checkPriv(const std::string &name, const std::string &priv)
|
|||||||
void Server::reportPrivsModified(const std::string &name)
|
void Server::reportPrivsModified(const std::string &name)
|
||||||
{
|
{
|
||||||
if(name == ""){
|
if(name == ""){
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++){
|
i != m_clients.end(); ++i){
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
Player *player = m_env->getPlayer(client->peer_id);
|
Player *player = m_env->getPlayer(client->peer_id);
|
||||||
reportPrivsModified(player->getName());
|
reportPrivsModified(player->getName());
|
||||||
}
|
}
|
||||||
@ -4579,11 +4577,11 @@ const ModSpec* Server::getModSpec(const std::string &modname)
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
void Server::getModNames(core::list<std::string> &modlist)
|
void Server::getModNames(std::list<std::string> &modlist)
|
||||||
{
|
{
|
||||||
for(std::vector<ModSpec>::iterator i = m_mods.begin(); i != m_mods.end(); i++)
|
for(std::vector<ModSpec>::iterator i = m_mods.begin(); i != m_mods.end(); i++)
|
||||||
{
|
{
|
||||||
modlist.push_back((*i).name);
|
modlist.push_back(i->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string Server::getBuiltinLuaPath()
|
std::string Server::getBuiltinLuaPath()
|
||||||
@ -4733,15 +4731,15 @@ void Server::handlePeerChange(PeerChange &c)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Error check
|
// Error check
|
||||||
core::map<u16, RemoteClient*>::Node *n;
|
std::map<u16, RemoteClient*>::iterator n;
|
||||||
n = m_clients.find(c.peer_id);
|
n = m_clients.find(c.peer_id);
|
||||||
// The client shouldn't already exist
|
// The client shouldn't already exist
|
||||||
assert(n == NULL);
|
assert(n == m_clients.end());
|
||||||
|
|
||||||
// Create client
|
// Create client
|
||||||
RemoteClient *client = new RemoteClient();
|
RemoteClient *client = new RemoteClient();
|
||||||
client->peer_id = c.peer_id;
|
client->peer_id = c.peer_id;
|
||||||
m_clients.insert(client->peer_id, client);
|
m_clients[client->peer_id] = client;
|
||||||
|
|
||||||
} // PEER_ADDED
|
} // PEER_ADDED
|
||||||
else if(c.type == PEER_REMOVED)
|
else if(c.type == PEER_REMOVED)
|
||||||
@ -4751,22 +4749,22 @@ void Server::handlePeerChange(PeerChange &c)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Error check
|
// Error check
|
||||||
core::map<u16, RemoteClient*>::Node *n;
|
std::map<u16, RemoteClient*>::iterator n;
|
||||||
n = m_clients.find(c.peer_id);
|
n = m_clients.find(c.peer_id);
|
||||||
// The client should exist
|
// The client should exist
|
||||||
assert(n != NULL);
|
assert(n != m_clients.end());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Mark objects to be not known by the client
|
Mark objects to be not known by the client
|
||||||
*/
|
*/
|
||||||
RemoteClient *client = n->getValue();
|
RemoteClient *client = n->second;
|
||||||
// Handle objects
|
// Handle objects
|
||||||
for(core::map<u16, bool>::Iterator
|
for(std::set<u16>::iterator
|
||||||
i = client->m_known_objects.getIterator();
|
i = client->m_known_objects.begin();
|
||||||
i.atEnd()==false; i++)
|
i != client->m_known_objects.end(); ++i)
|
||||||
{
|
{
|
||||||
// Get object
|
// Get object
|
||||||
u16 id = i.getNode()->getKey();
|
u16 id = *i;
|
||||||
ServerActiveObject* obj = m_env->getActiveObject(id);
|
ServerActiveObject* obj = m_env->getActiveObject(id);
|
||||||
|
|
||||||
if(obj && obj->m_known_by_count > 0)
|
if(obj && obj->m_known_by_count > 0)
|
||||||
@ -4824,12 +4822,12 @@ void Server::handlePeerChange(PeerChange &c)
|
|||||||
if(player != NULL)
|
if(player != NULL)
|
||||||
{
|
{
|
||||||
std::ostringstream os(std::ios_base::binary);
|
std::ostringstream os(std::ios_base::binary);
|
||||||
for(core::map<u16, RemoteClient*>::Iterator
|
for(std::map<u16, RemoteClient*>::iterator
|
||||||
i = m_clients.getIterator();
|
i = m_clients.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_clients.end(); ++i)
|
||||||
{
|
{
|
||||||
RemoteClient *client = i.getNode()->getValue();
|
RemoteClient *client = i->second;
|
||||||
assert(client->peer_id == i.getNode()->getKey());
|
assert(client->peer_id == i->first);
|
||||||
if(client->serialization_version == SER_FMT_VER_INVALID)
|
if(client->serialization_version == SER_FMT_VER_INVALID)
|
||||||
continue;
|
continue;
|
||||||
// Get player
|
// Get player
|
||||||
@ -4849,7 +4847,7 @@ void Server::handlePeerChange(PeerChange &c)
|
|||||||
|
|
||||||
// Delete client
|
// Delete client
|
||||||
delete m_clients[c.peer_id];
|
delete m_clients[c.peer_id];
|
||||||
m_clients.remove(c.peer_id);
|
m_clients.erase(c.peer_id);
|
||||||
|
|
||||||
// Send player info to all remaining clients
|
// Send player info to all remaining clients
|
||||||
//SendPlayerInfos();
|
//SendPlayerInfos();
|
||||||
|
27
src/server.h
27
src/server.h
@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "rollback_interface.h" // Needed for rollbackRevertActions()
|
#include "rollback_interface.h" // Needed for rollbackRevertActions()
|
||||||
#include <list> // Needed for rollbackRevertActions()
|
#include <list> // Needed for rollbackRevertActions()
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
||||||
|
|
||||||
@ -166,7 +167,7 @@ struct PrioritySortedBlockTransfer
|
|||||||
pos = a_pos;
|
pos = a_pos;
|
||||||
peer_id = a_peer_id;
|
peer_id = a_peer_id;
|
||||||
}
|
}
|
||||||
bool operator < (PrioritySortedBlockTransfer &other)
|
bool operator < (const PrioritySortedBlockTransfer &other) const
|
||||||
{
|
{
|
||||||
return priority < other.priority;
|
return priority < other.priority;
|
||||||
}
|
}
|
||||||
@ -271,14 +272,14 @@ public:
|
|||||||
dtime is used for resetting send radius at slow interval
|
dtime is used for resetting send radius at slow interval
|
||||||
*/
|
*/
|
||||||
void GetNextBlocks(Server *server, float dtime,
|
void GetNextBlocks(Server *server, float dtime,
|
||||||
core::array<PrioritySortedBlockTransfer> &dest);
|
std::vector<PrioritySortedBlockTransfer> &dest);
|
||||||
|
|
||||||
void GotBlock(v3s16 p);
|
void GotBlock(v3s16 p);
|
||||||
|
|
||||||
void SentBlock(v3s16 p);
|
void SentBlock(v3s16 p);
|
||||||
|
|
||||||
void SetBlockNotSent(v3s16 p);
|
void SetBlockNotSent(v3s16 p);
|
||||||
void SetBlocksNotSent(core::map<v3s16, MapBlock*> &blocks);
|
void SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks);
|
||||||
|
|
||||||
s32 SendingCount()
|
s32 SendingCount()
|
||||||
{
|
{
|
||||||
@ -314,7 +315,7 @@ public:
|
|||||||
List of active objects that the client knows of.
|
List of active objects that the client knows of.
|
||||||
Value is dummy.
|
Value is dummy.
|
||||||
*/
|
*/
|
||||||
core::map<u16, bool> m_known_objects;
|
std::set<u16> m_known_objects;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*
|
/*
|
||||||
@ -326,7 +327,7 @@ private:
|
|||||||
Key is position, value is dummy.
|
Key is position, value is dummy.
|
||||||
No MapBlock* is stored here because the blocks can get deleted.
|
No MapBlock* is stored here because the blocks can get deleted.
|
||||||
*/
|
*/
|
||||||
core::map<v3s16, bool> m_blocks_sent;
|
std::set<v3s16> m_blocks_sent;
|
||||||
s16 m_nearest_unsent_d;
|
s16 m_nearest_unsent_d;
|
||||||
v3s16 m_last_center;
|
v3s16 m_last_center;
|
||||||
float m_nearest_unsent_reset_timer;
|
float m_nearest_unsent_reset_timer;
|
||||||
@ -339,7 +340,7 @@ private:
|
|||||||
Block is removed when GOTBLOCKS is received.
|
Block is removed when GOTBLOCKS is received.
|
||||||
Value is time from sending. (not used at the moment)
|
Value is time from sending. (not used at the moment)
|
||||||
*/
|
*/
|
||||||
core::map<v3s16, float> m_blocks_sending;
|
std::map<v3s16, float> m_blocks_sending;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Count of excess GotBlocks().
|
Count of excess GotBlocks().
|
||||||
@ -381,7 +382,7 @@ public:
|
|||||||
void Receive();
|
void Receive();
|
||||||
void ProcessData(u8 *data, u32 datasize, u16 peer_id);
|
void ProcessData(u8 *data, u32 datasize, u16 peer_id);
|
||||||
|
|
||||||
core::list<PlayerInfo> getPlayerInfo();
|
std::list<PlayerInfo> getPlayerInfo();
|
||||||
|
|
||||||
// Environment must be locked when called
|
// Environment must be locked when called
|
||||||
void setTimeOfDay(u32 time)
|
void setTimeOfDay(u32 time)
|
||||||
@ -494,7 +495,7 @@ public:
|
|||||||
IWritableCraftDefManager* getWritableCraftDefManager();
|
IWritableCraftDefManager* getWritableCraftDefManager();
|
||||||
|
|
||||||
const ModSpec* getModSpec(const std::string &modname);
|
const ModSpec* getModSpec(const std::string &modname);
|
||||||
void getModNames(core::list<std::string> &modlist);
|
void getModNames(std::list<std::string> &modlist);
|
||||||
std::string getBuiltinLuaPath();
|
std::string getBuiltinLuaPath();
|
||||||
|
|
||||||
std::string getWorldPath(){ return m_path_world; }
|
std::string getWorldPath(){ return m_path_world; }
|
||||||
@ -553,9 +554,9 @@ private:
|
|||||||
*/
|
*/
|
||||||
// Envlock and conlock should be locked when calling these
|
// Envlock and conlock should be locked when calling these
|
||||||
void sendRemoveNode(v3s16 p, u16 ignore_id=0,
|
void sendRemoveNode(v3s16 p, u16 ignore_id=0,
|
||||||
core::list<u16> *far_players=NULL, float far_d_nodes=100);
|
std::list<u16> *far_players=NULL, float far_d_nodes=100);
|
||||||
void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
|
void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
|
||||||
core::list<u16> *far_players=NULL, float far_d_nodes=100);
|
std::list<u16> *far_players=NULL, float far_d_nodes=100);
|
||||||
void setBlockNotSent(v3s16 p);
|
void setBlockNotSent(v3s16 p);
|
||||||
|
|
||||||
// Environment and Connection must be locked when called
|
// Environment and Connection must be locked when called
|
||||||
@ -567,7 +568,7 @@ private:
|
|||||||
void fillMediaCache();
|
void fillMediaCache();
|
||||||
void sendMediaAnnouncement(u16 peer_id);
|
void sendMediaAnnouncement(u16 peer_id);
|
||||||
void sendRequestedMedia(u16 peer_id,
|
void sendRequestedMedia(u16 peer_id,
|
||||||
const core::list<MediaRequest> &tosend);
|
const std::list<MediaRequest> &tosend);
|
||||||
|
|
||||||
void sendDetachedInventory(const std::string &name, u16 peer_id);
|
void sendDetachedInventory(const std::string &name, u16 peer_id);
|
||||||
void sendDetachedInventoryToAll(const std::string &name);
|
void sendDetachedInventoryToAll(const std::string &name);
|
||||||
@ -655,7 +656,7 @@ private:
|
|||||||
con::Connection m_con;
|
con::Connection m_con;
|
||||||
JMutex m_con_mutex;
|
JMutex m_con_mutex;
|
||||||
// Connected clients (behind the con mutex)
|
// Connected clients (behind the con mutex)
|
||||||
core::map<u16, RemoteClient*> m_clients;
|
std::map<u16, RemoteClient*> m_clients;
|
||||||
u16 m_clients_number; //for announcing masterserver
|
u16 m_clients_number; //for announcing masterserver
|
||||||
|
|
||||||
// Bann checking
|
// Bann checking
|
||||||
@ -735,7 +736,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Mod parent directory paths
|
// Mod parent directory paths
|
||||||
core::list<std::string> m_modspaths;
|
std::list<std::string> m_modspaths;
|
||||||
|
|
||||||
bool m_shutdown_requested;
|
bool m_shutdown_requested;
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ ServerActiveObject* ServerActiveObject::create(u8 type,
|
|||||||
const std::string &data)
|
const std::string &data)
|
||||||
{
|
{
|
||||||
// Find factory function
|
// Find factory function
|
||||||
core::map<u16, Factory>::Node *n;
|
std::map<u16, Factory>::iterator n;
|
||||||
n = m_types.find(type);
|
n = m_types.find(type);
|
||||||
if(n == NULL)
|
if(n == m_types.end())
|
||||||
{
|
{
|
||||||
// If factory is not found, just return.
|
// If factory is not found, just return.
|
||||||
dstream<<"WARNING: ServerActiveObject: No factory for type="
|
dstream<<"WARNING: ServerActiveObject: No factory for type="
|
||||||
@ -53,18 +53,18 @@ ServerActiveObject* ServerActiveObject::create(u8 type,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Factory f = n->getValue();
|
Factory f = n->second;
|
||||||
ServerActiveObject *object = (*f)(env, pos, data);
|
ServerActiveObject *object = (*f)(env, pos, data);
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerActiveObject::registerType(u16 type, Factory f)
|
void ServerActiveObject::registerType(u16 type, Factory f)
|
||||||
{
|
{
|
||||||
core::map<u16, Factory>::Node *n;
|
std::map<u16, Factory>::iterator n;
|
||||||
n = m_types.find(type);
|
n = m_types.find(type);
|
||||||
if(n)
|
if(n != m_types.end())
|
||||||
return;
|
return;
|
||||||
m_types.insert(type, f);
|
m_types[type] = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServerActiveObject::getMinimumSavedMovement()
|
float ServerActiveObject::getMinimumSavedMovement()
|
||||||
|
@ -235,7 +235,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Used for creating objects based on type
|
// Used for creating objects based on type
|
||||||
static core::map<u16, Factory> m_types;
|
static std::map<u16, Factory> m_types;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
113
src/settings.h
113
src/settings.h
@ -33,6 +33,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "porting.h"
|
#include "porting.h"
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
enum ValueType
|
enum ValueType
|
||||||
{
|
{
|
||||||
@ -63,12 +66,12 @@ public:
|
|||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
for(core::map<std::string, std::string>::Iterator
|
for(std::map<std::string, std::string>::iterator
|
||||||
i = m_settings.getIterator();
|
i = m_settings.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_settings.end(); ++i)
|
||||||
{
|
{
|
||||||
std::string name = i.getNode()->getKey();
|
std::string name = i->first;
|
||||||
std::string value = i.getNode()->getValue();
|
std::string value = i->second;
|
||||||
os<<name<<" = "<<value<<"\n";
|
os<<name<<" = "<<value<<"\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,12 +79,11 @@ public:
|
|||||||
// return all keys used
|
// return all keys used
|
||||||
std::vector<std::string> getNames(){
|
std::vector<std::string> getNames(){
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
for(core::map<std::string, std::string>::Iterator
|
for(std::map<std::string, std::string>::iterator
|
||||||
i = m_settings.getIterator();
|
i = m_settings.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_settings.end(); ++i)
|
||||||
{
|
{
|
||||||
std::string name = i.getNode()->getKey();
|
names.push_back(i->first);
|
||||||
names.push_back(name);
|
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
@ -89,7 +91,7 @@ public:
|
|||||||
// remove a setting
|
// remove a setting
|
||||||
bool remove(const std::string& name)
|
bool remove(const std::string& name)
|
||||||
{
|
{
|
||||||
return m_settings.remove(name);
|
return m_settings.erase(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -188,8 +190,8 @@ public:
|
|||||||
Returns false on EOF
|
Returns false on EOF
|
||||||
*/
|
*/
|
||||||
bool getUpdatedConfigObject(std::istream &is,
|
bool getUpdatedConfigObject(std::istream &is,
|
||||||
core::list<std::string> &dst,
|
std::list<std::string> &dst,
|
||||||
core::map<std::string, bool> &updated,
|
std::set<std::string> &updated,
|
||||||
bool &value_changed)
|
bool &value_changed)
|
||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
@ -228,7 +230,7 @@ public:
|
|||||||
std::string value = sf.next("\n");
|
std::string value = sf.next("\n");
|
||||||
value = trim(value);
|
value = trim(value);
|
||||||
|
|
||||||
if(m_settings.find(name))
|
if(m_settings.find(name) != m_settings.end())
|
||||||
{
|
{
|
||||||
std::string newvalue = m_settings[name];
|
std::string newvalue = m_settings[name];
|
||||||
|
|
||||||
@ -242,7 +244,7 @@ public:
|
|||||||
|
|
||||||
dst.push_back(name + " = " + newvalue + line_end);
|
dst.push_back(name + " = " + newvalue + line_end);
|
||||||
|
|
||||||
updated[name] = true;
|
updated.insert(name);
|
||||||
}
|
}
|
||||||
else //file contains a setting which is not in m_settings
|
else //file contains a setting which is not in m_settings
|
||||||
value_changed=true;
|
value_changed=true;
|
||||||
@ -260,8 +262,8 @@ public:
|
|||||||
infostream<<"Updating configuration file: \""
|
infostream<<"Updating configuration file: \""
|
||||||
<<filename<<"\""<<std::endl;
|
<<filename<<"\""<<std::endl;
|
||||||
|
|
||||||
core::list<std::string> objects;
|
std::list<std::string> objects;
|
||||||
core::map<std::string, bool> updated;
|
std::set<std::string> updated;
|
||||||
bool something_actually_changed = false;
|
bool something_actually_changed = false;
|
||||||
|
|
||||||
// Read and modify stuff
|
// Read and modify stuff
|
||||||
@ -286,11 +288,11 @@ public:
|
|||||||
// If something not yet determined to have been changed, check if
|
// If something not yet determined to have been changed, check if
|
||||||
// any new stuff was added
|
// any new stuff was added
|
||||||
if(!something_actually_changed){
|
if(!something_actually_changed){
|
||||||
for(core::map<std::string, std::string>::Iterator
|
for(std::map<std::string, std::string>::iterator
|
||||||
i = m_settings.getIterator();
|
i = m_settings.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_settings.end(); ++i)
|
||||||
{
|
{
|
||||||
if(updated.find(i.getNode()->getKey()))
|
if(updated.find(i->first) != updated.end())
|
||||||
continue;
|
continue;
|
||||||
something_actually_changed = true;
|
something_actually_changed = true;
|
||||||
break;
|
break;
|
||||||
@ -318,9 +320,9 @@ public:
|
|||||||
/*
|
/*
|
||||||
Write updated stuff
|
Write updated stuff
|
||||||
*/
|
*/
|
||||||
for(core::list<std::string>::Iterator
|
for(std::list<std::string>::iterator
|
||||||
i = objects.begin();
|
i = objects.begin();
|
||||||
i != objects.end(); i++)
|
i != objects.end(); ++i)
|
||||||
{
|
{
|
||||||
os<<(*i);
|
os<<(*i);
|
||||||
}
|
}
|
||||||
@ -328,14 +330,14 @@ public:
|
|||||||
/*
|
/*
|
||||||
Write stuff that was not already in the file
|
Write stuff that was not already in the file
|
||||||
*/
|
*/
|
||||||
for(core::map<std::string, std::string>::Iterator
|
for(std::map<std::string, std::string>::iterator
|
||||||
i = m_settings.getIterator();
|
i = m_settings.begin();
|
||||||
i.atEnd() == false; i++)
|
i != m_settings.end(); ++i)
|
||||||
{
|
{
|
||||||
if(updated.find(i.getNode()->getKey()))
|
if(updated.find(i->first) != updated.end())
|
||||||
continue;
|
continue;
|
||||||
std::string name = i.getNode()->getKey();
|
std::string name = i->first;
|
||||||
std::string value = i.getNode()->getValue();
|
std::string value = i->second;
|
||||||
infostream<<"Adding \""<<name<<"\" = \""<<value<<"\""
|
infostream<<"Adding \""<<name<<"\" = \""<<value<<"\""
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
os<<name<<" = "<<value<<"\n";
|
os<<name<<" = "<<value<<"\n";
|
||||||
@ -351,7 +353,7 @@ public:
|
|||||||
returns true on success
|
returns true on success
|
||||||
*/
|
*/
|
||||||
bool parseCommandLine(int argc, char *argv[],
|
bool parseCommandLine(int argc, char *argv[],
|
||||||
core::map<std::string, ValueSpec> &allowed_options)
|
std::map<std::string, ValueSpec> &allowed_options)
|
||||||
{
|
{
|
||||||
int nonopt_index = 0;
|
int nonopt_index = 0;
|
||||||
int i=1;
|
int i=1;
|
||||||
@ -379,16 +381,16 @@ public:
|
|||||||
|
|
||||||
std::string name = argname.substr(2);
|
std::string name = argname.substr(2);
|
||||||
|
|
||||||
core::map<std::string, ValueSpec>::Node *n;
|
std::map<std::string, ValueSpec>::iterator n;
|
||||||
n = allowed_options.find(name);
|
n = allowed_options.find(name);
|
||||||
if(n == NULL)
|
if(n == allowed_options.end())
|
||||||
{
|
{
|
||||||
errorstream<<"Unknown command-line parameter \""
|
errorstream<<"Unknown command-line parameter \""
|
||||||
<<argname<<"\""<<std::endl;
|
<<argname<<"\""<<std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueType type = n->getValue().type;
|
ValueType type = n->second.type;
|
||||||
|
|
||||||
std::string value = "";
|
std::string value = "";
|
||||||
|
|
||||||
@ -444,25 +446,25 @@ public:
|
|||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
return (m_settings.find(name) || m_defaults.find(name));
|
return (m_settings.find(name) != m_settings.end() || m_defaults.find(name) != m_defaults.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get(std::string name)
|
std::string get(std::string name)
|
||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
core::map<std::string, std::string>::Node *n;
|
std::map<std::string, std::string>::iterator n;
|
||||||
n = m_settings.find(name);
|
n = m_settings.find(name);
|
||||||
if(n == NULL)
|
if(n == m_settings.end())
|
||||||
{
|
{
|
||||||
n = m_defaults.find(name);
|
n = m_defaults.find(name);
|
||||||
if(n == NULL)
|
if(n == m_defaults.end())
|
||||||
{
|
{
|
||||||
throw SettingNotFoundException("Setting not found");
|
throw SettingNotFoundException("Setting not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return n->getValue();
|
return n->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getBool(std::string name)
|
bool getBool(std::string name)
|
||||||
@ -919,19 +921,8 @@ fail:
|
|||||||
if(&other == this)
|
if(&other == this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(core::map<std::string, std::string>::Iterator
|
m_settings.insert(other.m_settings.begin(), other.m_settings.end());
|
||||||
i = other.m_settings.getIterator();
|
m_defaults.insert(other.m_defaults.begin(), other.m_defaults.end());
|
||||||
i.atEnd() == false; i++)
|
|
||||||
{
|
|
||||||
m_settings[i.getNode()->getKey()] = i.getNode()->getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
for(core::map<std::string, std::string>::Iterator
|
|
||||||
i = other.m_defaults.getIterator();
|
|
||||||
i.atEnd() == false; i++)
|
|
||||||
{
|
|
||||||
m_defaults[i.getNode()->getKey()] = i.getNode()->getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -944,21 +935,7 @@ fail:
|
|||||||
if(&other == this)
|
if(&other == this)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
for(core::map<std::string, std::string>::Iterator
|
update(other);
|
||||||
i = other.m_settings.getIterator();
|
|
||||||
i.atEnd() == false; i++)
|
|
||||||
{
|
|
||||||
m_settings.insert(i.getNode()->getKey(),
|
|
||||||
i.getNode()->getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
for(core::map<std::string, std::string>::Iterator
|
|
||||||
i = other.m_defaults.getIterator();
|
|
||||||
i.atEnd() == false; i++)
|
|
||||||
{
|
|
||||||
m_defaults.insert(i.getNode()->getKey(),
|
|
||||||
i.getNode()->getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
@ -979,8 +956,8 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
core::map<std::string, std::string> m_settings;
|
std::map<std::string, std::string> m_settings;
|
||||||
core::map<std::string, std::string> m_defaults;
|
std::map<std::string, std::string> m_defaults;
|
||||||
// All methods that access m_settings/m_defaults directly should lock this.
|
// All methods that access m_settings/m_defaults directly should lock this.
|
||||||
JMutex m_mutex;
|
JMutex m_mutex;
|
||||||
};
|
};
|
||||||
|
@ -125,10 +125,10 @@ public:
|
|||||||
const std::string &filename)
|
const std::string &filename)
|
||||||
{
|
{
|
||||||
std::string combined = name_of_shader + DIR_DELIM + filename;
|
std::string combined = name_of_shader + DIR_DELIM + filename;
|
||||||
core::map<std::string, std::string>::Node *n;
|
std::map<std::string, std::string>::iterator n;
|
||||||
n = m_programs.find(combined);
|
n = m_programs.find(combined);
|
||||||
if(n)
|
if(n != m_programs.end())
|
||||||
return n->getValue();
|
return n->second;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
// Primarily fetches from cache, secondarily tries to read from filesystem
|
// Primarily fetches from cache, secondarily tries to read from filesystem
|
||||||
@ -136,10 +136,10 @@ public:
|
|||||||
const std::string &filename)
|
const std::string &filename)
|
||||||
{
|
{
|
||||||
std::string combined = name_of_shader + DIR_DELIM + filename;
|
std::string combined = name_of_shader + DIR_DELIM + filename;
|
||||||
core::map<std::string, std::string>::Node *n;
|
std::map<std::string, std::string>::iterator n;
|
||||||
n = m_programs.find(combined);
|
n = m_programs.find(combined);
|
||||||
if(n)
|
if(n != m_programs.end())
|
||||||
return n->getValue();
|
return n->second;
|
||||||
std::string path = getShaderPath(name_of_shader, filename);
|
std::string path = getShaderPath(name_of_shader, filename);
|
||||||
if(path == ""){
|
if(path == ""){
|
||||||
infostream<<"SourceShaderCache::getOrLoad(): No path found for \""
|
infostream<<"SourceShaderCache::getOrLoad(): No path found for \""
|
||||||
@ -156,7 +156,7 @@ public:
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
core::map<std::string, std::string> m_programs;
|
std::map<std::string, std::string> m_programs;
|
||||||
std::string readFile(const std::string &path)
|
std::string readFile(const std::string &path)
|
||||||
{
|
{
|
||||||
std::ifstream is(path.c_str(), std::ios::binary);
|
std::ifstream is(path.c_str(), std::ios::binary);
|
||||||
@ -332,9 +332,9 @@ private:
|
|||||||
|
|
||||||
// A shader id is index in this array.
|
// A shader id is index in this array.
|
||||||
// The first position contains a dummy shader.
|
// The first position contains a dummy shader.
|
||||||
core::array<ShaderInfo> m_shaderinfo_cache;
|
std::vector<ShaderInfo> m_shaderinfo_cache;
|
||||||
// Maps a shader name to an index in the former.
|
// Maps a shader name to an index in the former.
|
||||||
core::map<std::string, u32> m_name_to_id;
|
std::map<std::string, u32> m_name_to_id;
|
||||||
// The two former containers are behind this mutex
|
// The two former containers are behind this mutex
|
||||||
JMutex m_shaderinfo_cache_mutex;
|
JMutex m_shaderinfo_cache_mutex;
|
||||||
|
|
||||||
@ -343,7 +343,7 @@ private:
|
|||||||
|
|
||||||
// Global constant setters
|
// Global constant setters
|
||||||
// TODO: Delete these in the destructor
|
// TODO: Delete these in the destructor
|
||||||
core::array<IShaderConstantSetter*> m_global_setters;
|
std::vector<IShaderConstantSetter*> m_global_setters;
|
||||||
};
|
};
|
||||||
|
|
||||||
IWritableShaderSource* createShaderSource(IrrlichtDevice *device)
|
IWritableShaderSource* createShaderSource(IrrlichtDevice *device)
|
||||||
@ -399,10 +399,10 @@ u32 ShaderSource::getShaderId(const std::string &name)
|
|||||||
See if shader already exists
|
See if shader already exists
|
||||||
*/
|
*/
|
||||||
JMutexAutoLock lock(m_shaderinfo_cache_mutex);
|
JMutexAutoLock lock(m_shaderinfo_cache_mutex);
|
||||||
core::map<std::string, u32>::Node *n;
|
std::map<std::string, u32>::iterator n;
|
||||||
n = m_name_to_id.find(name);
|
n = m_name_to_id.find(name);
|
||||||
if(n != NULL)
|
if(n != m_name_to_id.end())
|
||||||
return n->getValue();
|
return n->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -471,12 +471,12 @@ u32 ShaderSource::getShaderIdDirect(const std::string &name)
|
|||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_shaderinfo_cache_mutex);
|
JMutexAutoLock lock(m_shaderinfo_cache_mutex);
|
||||||
|
|
||||||
core::map<std::string, u32>::Node *n;
|
std::map<std::string, u32>::iterator n;
|
||||||
n = m_name_to_id.find(name);
|
n = m_name_to_id.find(name);
|
||||||
if(n != NULL){
|
if(n != m_name_to_id.end()){
|
||||||
/*infostream<<"getShaderIdDirect(): \""<<name
|
/*infostream<<"getShaderIdDirect(): \""<<name
|
||||||
<<"\" found in cache"<<std::endl;*/
|
<<"\" found in cache"<<std::endl;*/
|
||||||
return n->getValue();
|
return n->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,7 +494,7 @@ u32 ShaderSource::getShaderIdDirect(const std::string &name)
|
|||||||
|
|
||||||
u32 id = m_shaderinfo_cache.size();
|
u32 id = m_shaderinfo_cache.size();
|
||||||
m_shaderinfo_cache.push_back(info);
|
m_shaderinfo_cache.push_back(info);
|
||||||
m_name_to_id.insert(name, id);
|
m_name_to_id[name] = id;
|
||||||
|
|
||||||
/*infostream<<"getShaderIdDirect(): "
|
/*infostream<<"getShaderIdDirect(): "
|
||||||
<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/
|
<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/
|
||||||
@ -531,7 +531,7 @@ void ShaderSource::processQueue()
|
|||||||
/*
|
/*
|
||||||
Fetch shaders
|
Fetch shaders
|
||||||
*/
|
*/
|
||||||
if(m_get_shader_queue.size() > 0){
|
if(!m_get_shader_queue.empty()){
|
||||||
GetRequest<std::string, u32, u8, u8>
|
GetRequest<std::string, u32, u8, u8>
|
||||||
request = m_get_shader_queue.pop();
|
request = m_get_shader_queue.pop();
|
||||||
|
|
||||||
|
@ -58,18 +58,18 @@ void StaticObjectList::serialize(std::ostream &os)
|
|||||||
u16 count = m_stored.size() + m_active.size();
|
u16 count = m_stored.size() + m_active.size();
|
||||||
writeU16((u8*)buf, count);
|
writeU16((u8*)buf, count);
|
||||||
os.write(buf, 2);
|
os.write(buf, 2);
|
||||||
for(core::list<StaticObject>::Iterator
|
for(std::list<StaticObject>::iterator
|
||||||
i = m_stored.begin();
|
i = m_stored.begin();
|
||||||
i != m_stored.end(); i++)
|
i != m_stored.end(); ++i)
|
||||||
{
|
{
|
||||||
StaticObject &s_obj = *i;
|
StaticObject &s_obj = *i;
|
||||||
s_obj.serialize(os);
|
s_obj.serialize(os);
|
||||||
}
|
}
|
||||||
for(core::map<u16, StaticObject>::Iterator
|
for(std::map<u16, StaticObject>::iterator
|
||||||
i = m_active.getIterator();
|
i = m_active.begin();
|
||||||
i.atEnd()==false; i++)
|
i != m_active.end(); ++i)
|
||||||
{
|
{
|
||||||
StaticObject s_obj = i.getNode()->getValue();
|
StaticObject s_obj = i->second;
|
||||||
s_obj.serialize(os);
|
s_obj.serialize(os);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "irrlichttypes_bloated.h"
|
#include "irrlichttypes_bloated.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <list>
|
||||||
|
#include <map>
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
struct StaticObject
|
struct StaticObject
|
||||||
@ -62,27 +64,27 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(m_active.find(id) != NULL)
|
if(m_active.find(id) != m_active.end())
|
||||||
{
|
{
|
||||||
dstream<<"ERROR: StaticObjectList::insert(): "
|
dstream<<"ERROR: StaticObjectList::insert(): "
|
||||||
<<"id already exists"<<std::endl;
|
<<"id already exists"<<std::endl;
|
||||||
assert(0);
|
assert(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_active.insert(id, obj);
|
m_active[id] = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove(u16 id)
|
void remove(u16 id)
|
||||||
{
|
{
|
||||||
assert(id != 0);
|
assert(id != 0);
|
||||||
if(m_active.find(id) == NULL)
|
if(m_active.find(id) == m_active.end())
|
||||||
{
|
{
|
||||||
dstream<<"WARNING: StaticObjectList::remove(): id="<<id
|
dstream<<"WARNING: StaticObjectList::remove(): id="<<id
|
||||||
<<" not found"<<std::endl;
|
<<" not found"<<std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_active.remove(id);
|
m_active.erase(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serialize(std::ostream &os);
|
void serialize(std::ostream &os);
|
||||||
@ -93,8 +95,8 @@ public:
|
|||||||
from m_stored and inserted to m_active.
|
from m_stored and inserted to m_active.
|
||||||
The caller directly manipulates these containers.
|
The caller directly manipulates these containers.
|
||||||
*/
|
*/
|
||||||
core::list<StaticObject> m_stored;
|
std::list<StaticObject> m_stored;
|
||||||
core::map<u16, StaticObject> m_active;
|
std::map<u16, StaticObject> m_active;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
43
src/test.cpp
43
src/test.cpp
@ -42,6 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "util/serialize.h"
|
#include "util/serialize.h"
|
||||||
#include "noise.h" // PseudoRandom used for random data for compression
|
#include "noise.h" // PseudoRandom used for random data for compression
|
||||||
#include "clientserver.h" // LATEST_PROTOCOL_VERSION
|
#include "clientserver.h" // LATEST_PROTOCOL_VERSION
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Asserts that the exception occurs
|
Asserts that the exception occurs
|
||||||
@ -508,26 +509,26 @@ struct TestVoxelManipulator: public TestBase
|
|||||||
// An area that is 1 bigger in x+ and z-
|
// An area that is 1 bigger in x+ and z-
|
||||||
VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2));
|
VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2));
|
||||||
|
|
||||||
core::list<VoxelArea> aa;
|
std::list<VoxelArea> aa;
|
||||||
d.diff(c, aa);
|
d.diff(c, aa);
|
||||||
|
|
||||||
// Correct results
|
// Correct results
|
||||||
core::array<VoxelArea> results;
|
std::vector<VoxelArea> results;
|
||||||
results.push_back(VoxelArea(v3s16(-2,-2,-3),v3s16(3,2,-3)));
|
results.push_back(VoxelArea(v3s16(-2,-2,-3),v3s16(3,2,-3)));
|
||||||
results.push_back(VoxelArea(v3s16(3,-2,-2),v3s16(3,2,2)));
|
results.push_back(VoxelArea(v3s16(3,-2,-2),v3s16(3,2,2)));
|
||||||
|
|
||||||
UASSERT(aa.size() == results.size());
|
UASSERT(aa.size() == results.size());
|
||||||
|
|
||||||
infostream<<"Result of diff:"<<std::endl;
|
infostream<<"Result of diff:"<<std::endl;
|
||||||
for(core::list<VoxelArea>::Iterator
|
for(std::list<VoxelArea>::const_iterator
|
||||||
i = aa.begin(); i != aa.end(); i++)
|
i = aa.begin(); i != aa.end(); ++i)
|
||||||
{
|
{
|
||||||
i->print(infostream);
|
i->print(infostream);
|
||||||
infostream<<std::endl;
|
infostream<<std::endl;
|
||||||
|
|
||||||
s32 j = results.linear_search(*i);
|
std::vector<VoxelArea>::iterator j = std::find(results.begin(), results.end(), *i);
|
||||||
UASSERT(j != -1);
|
UASSERT(j != results.end());
|
||||||
results.erase(j, 1);
|
results.erase(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -582,7 +583,7 @@ struct TestVoxelAlgorithms: public TestBase
|
|||||||
}
|
}
|
||||||
VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
|
VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, true, light_sources, ndef);
|
v, a, true, light_sources, ndef);
|
||||||
@ -593,7 +594,7 @@ struct TestVoxelAlgorithms: public TestBase
|
|||||||
}
|
}
|
||||||
v.setNodeNoRef(v3s16(0,0,0), MapNode(CONTENT_STONE));
|
v.setNodeNoRef(v3s16(0,0,0), MapNode(CONTENT_STONE));
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, true, light_sources, ndef);
|
v, a, true, light_sources, ndef);
|
||||||
@ -602,7 +603,7 @@ struct TestVoxelAlgorithms: public TestBase
|
|||||||
== LIGHT_SUN);
|
== LIGHT_SUN);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, false, light_sources, ndef);
|
v, a, false, light_sources, ndef);
|
||||||
@ -612,7 +613,7 @@ struct TestVoxelAlgorithms: public TestBase
|
|||||||
}
|
}
|
||||||
v.setNodeNoRef(v3s16(1,3,2), MapNode(CONTENT_STONE));
|
v.setNodeNoRef(v3s16(1,3,2), MapNode(CONTENT_STONE));
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, true, light_sources, ndef);
|
v, a, true, light_sources, ndef);
|
||||||
@ -621,7 +622,7 @@ struct TestVoxelAlgorithms: public TestBase
|
|||||||
== 0);
|
== 0);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, false, light_sources, ndef);
|
v, a, false, light_sources, ndef);
|
||||||
@ -635,14 +636,14 @@ struct TestVoxelAlgorithms: public TestBase
|
|||||||
v.setNodeNoRef(v3s16(1,-1,2), n);
|
v.setNodeNoRef(v3s16(1,-1,2), n);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, true, light_sources, ndef);
|
v, a, true, light_sources, ndef);
|
||||||
UASSERT(res.bottom_sunlight_valid == true);
|
UASSERT(res.bottom_sunlight_valid == true);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, false, light_sources, ndef);
|
v, a, false, light_sources, ndef);
|
||||||
@ -654,14 +655,14 @@ struct TestVoxelAlgorithms: public TestBase
|
|||||||
v.setNodeNoRef(v3s16(1,-1,2), n);
|
v.setNodeNoRef(v3s16(1,-1,2), n);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, true, light_sources, ndef);
|
v, a, true, light_sources, ndef);
|
||||||
UASSERT(res.bottom_sunlight_valid == false);
|
UASSERT(res.bottom_sunlight_valid == false);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, false, light_sources, ndef);
|
v, a, false, light_sources, ndef);
|
||||||
@ -669,7 +670,7 @@ struct TestVoxelAlgorithms: public TestBase
|
|||||||
}
|
}
|
||||||
v.setNodeNoRef(v3s16(1,3,2), MapNode(CONTENT_IGNORE));
|
v.setNodeNoRef(v3s16(1,3,2), MapNode(CONTENT_IGNORE));
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
voxalgo::setLight(v, a, 0, ndef);
|
voxalgo::setLight(v, a, 0, ndef);
|
||||||
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
|
||||||
v, a, true, light_sources, ndef);
|
v, a, true, light_sources, ndef);
|
||||||
@ -697,16 +698,16 @@ struct TestVoxelAlgorithms: public TestBase
|
|||||||
v.setNode(v3s16(1,1,2), n);
|
v.setNode(v3s16(1,1,2), n);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::map<v3s16, bool> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
core::map<v3s16, u8> unlight_from;
|
std::map<v3s16, u8> unlight_from;
|
||||||
voxalgo::clearLightAndCollectSources(v, a, LIGHTBANK_DAY,
|
voxalgo::clearLightAndCollectSources(v, a, LIGHTBANK_DAY,
|
||||||
ndef, light_sources, unlight_from);
|
ndef, light_sources, unlight_from);
|
||||||
//v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
|
//v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
|
||||||
UASSERT(v.getNode(v3s16(0,1,1)).getLight(LIGHTBANK_DAY, ndef)
|
UASSERT(v.getNode(v3s16(0,1,1)).getLight(LIGHTBANK_DAY, ndef)
|
||||||
== 0);
|
== 0);
|
||||||
UASSERT(light_sources.find(v3s16(1,1,1)) != NULL);
|
UASSERT(light_sources.find(v3s16(1,1,1)) != light_sources.end());
|
||||||
UASSERT(light_sources.size() == 1);
|
UASSERT(light_sources.size() == 1);
|
||||||
UASSERT(unlight_from.find(v3s16(1,1,2)) != NULL);
|
UASSERT(unlight_from.find(v3s16(1,1,2)) != unlight_from.end());
|
||||||
UASSERT(unlight_from.size() == 1);
|
UASSERT(unlight_from.size() == 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
78
src/tile.cpp
78
src/tile.cpp
@ -206,10 +206,10 @@ public:
|
|||||||
{
|
{
|
||||||
assert(img);
|
assert(img);
|
||||||
// Remove old image
|
// Remove old image
|
||||||
core::map<std::string, video::IImage*>::Node *n;
|
std::map<std::string, video::IImage*>::iterator n;
|
||||||
n = m_images.find(name);
|
n = m_images.find(name);
|
||||||
if(n){
|
if(n != m_images.end()){
|
||||||
video::IImage *oldimg = n->getValue();
|
video::IImage *oldimg = n->second;
|
||||||
if(oldimg)
|
if(oldimg)
|
||||||
oldimg->drop();
|
oldimg->drop();
|
||||||
}
|
}
|
||||||
@ -229,20 +229,20 @@ public:
|
|||||||
}
|
}
|
||||||
video::IImage* get(const std::string &name)
|
video::IImage* get(const std::string &name)
|
||||||
{
|
{
|
||||||
core::map<std::string, video::IImage*>::Node *n;
|
std::map<std::string, video::IImage*>::iterator n;
|
||||||
n = m_images.find(name);
|
n = m_images.find(name);
|
||||||
if(n)
|
if(n != m_images.end())
|
||||||
return n->getValue();
|
return n->second;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// Primarily fetches from cache, secondarily tries to read from filesystem
|
// Primarily fetches from cache, secondarily tries to read from filesystem
|
||||||
video::IImage* getOrLoad(const std::string &name, IrrlichtDevice *device)
|
video::IImage* getOrLoad(const std::string &name, IrrlichtDevice *device)
|
||||||
{
|
{
|
||||||
core::map<std::string, video::IImage*>::Node *n;
|
std::map<std::string, video::IImage*>::iterator n;
|
||||||
n = m_images.find(name);
|
n = m_images.find(name);
|
||||||
if(n){
|
if(n != m_images.end()){
|
||||||
n->getValue()->grab(); // Grab for caller
|
n->second->grab(); // Grab for caller
|
||||||
return n->getValue();
|
return n->second;
|
||||||
}
|
}
|
||||||
video::IVideoDriver* driver = device->getVideoDriver();
|
video::IVideoDriver* driver = device->getVideoDriver();
|
||||||
std::string path = getTexturePath(name.c_str());
|
std::string path = getTexturePath(name.c_str());
|
||||||
@ -263,7 +263,7 @@ public:
|
|||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
core::map<std::string, video::IImage*> m_images;
|
std::map<std::string, video::IImage*> m_images;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -417,9 +417,9 @@ private:
|
|||||||
|
|
||||||
// A texture id is index in this array.
|
// A texture id is index in this array.
|
||||||
// The first position contains a NULL texture.
|
// The first position contains a NULL texture.
|
||||||
core::array<SourceAtlasPointer> m_atlaspointer_cache;
|
std::vector<SourceAtlasPointer> m_atlaspointer_cache;
|
||||||
// Maps a texture name to an index in the former.
|
// Maps a texture name to an index in the former.
|
||||||
core::map<std::string, u32> m_name_to_id;
|
std::map<std::string, u32> m_name_to_id;
|
||||||
// The two former containers are behind this mutex
|
// The two former containers are behind this mutex
|
||||||
JMutex m_atlaspointer_cache_mutex;
|
JMutex m_atlaspointer_cache_mutex;
|
||||||
|
|
||||||
@ -465,11 +465,11 @@ u32 TextureSource::getTextureId(const std::string &name)
|
|||||||
See if texture already exists
|
See if texture already exists
|
||||||
*/
|
*/
|
||||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||||
core::map<std::string, u32>::Node *n;
|
std::map<std::string, u32>::iterator n;
|
||||||
n = m_name_to_id.find(name);
|
n = m_name_to_id.find(name);
|
||||||
if(n != NULL)
|
if(n != m_name_to_id.end())
|
||||||
{
|
{
|
||||||
return n->getValue();
|
return n->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,13 +579,13 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
|
||||||
|
|
||||||
core::map<std::string, u32>::Node *n;
|
std::map<std::string, u32>::iterator n;
|
||||||
n = m_name_to_id.find(name);
|
n = m_name_to_id.find(name);
|
||||||
if(n != NULL)
|
if(n != m_name_to_id.end())
|
||||||
{
|
{
|
||||||
/*infostream<<"getTextureIdDirect(): \""<<name
|
/*infostream<<"getTextureIdDirect(): \""<<name
|
||||||
<<"\" found in cache"<<std::endl;*/
|
<<"\" found in cache"<<std::endl;*/
|
||||||
return n->getValue();
|
return n->second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,7 +724,7 @@ u32 TextureSource::getTextureIdDirect(const std::string &name)
|
|||||||
baseimg_dim = baseimg->getDimension();
|
baseimg_dim = baseimg->getDimension();
|
||||||
SourceAtlasPointer nap(name, ap, baseimg, v2s32(0,0), baseimg_dim);
|
SourceAtlasPointer nap(name, ap, baseimg, v2s32(0,0), baseimg_dim);
|
||||||
m_atlaspointer_cache.push_back(nap);
|
m_atlaspointer_cache.push_back(nap);
|
||||||
m_name_to_id.insert(name, id);
|
m_name_to_id[name] = id;
|
||||||
|
|
||||||
/*infostream<<"getTextureIdDirect(): "
|
/*infostream<<"getTextureIdDirect(): "
|
||||||
<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/
|
<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/
|
||||||
@ -769,7 +769,7 @@ void TextureSource::processQueue()
|
|||||||
/*
|
/*
|
||||||
Fetch textures
|
Fetch textures
|
||||||
*/
|
*/
|
||||||
if(m_get_texture_queue.size() > 0)
|
if(!m_get_texture_queue.empty())
|
||||||
{
|
{
|
||||||
GetRequest<std::string, u32, u8, u8>
|
GetRequest<std::string, u32, u8, u8>
|
||||||
request = m_get_texture_queue.pop();
|
request = m_get_texture_queue.pop();
|
||||||
@ -872,7 +872,7 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef)
|
|||||||
main content features
|
main content features
|
||||||
*/
|
*/
|
||||||
|
|
||||||
core::map<std::string, bool> sourcelist;
|
std::set<std::string> sourcelist;
|
||||||
|
|
||||||
for(u16 j=0; j<MAX_CONTENT+1; j++)
|
for(u16 j=0; j<MAX_CONTENT+1; j++)
|
||||||
{
|
{
|
||||||
@ -882,16 +882,16 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef)
|
|||||||
for(u32 i=0; i<6; i++)
|
for(u32 i=0; i<6; i++)
|
||||||
{
|
{
|
||||||
std::string name = f.tiledef[i].name;
|
std::string name = f.tiledef[i].name;
|
||||||
sourcelist[name] = true;
|
sourcelist.insert(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
infostream<<"Creating texture atlas out of textures: ";
|
infostream<<"Creating texture atlas out of textures: ";
|
||||||
for(core::map<std::string, bool>::Iterator
|
for(std::set<std::string>::iterator
|
||||||
i = sourcelist.getIterator();
|
i = sourcelist.begin();
|
||||||
i.atEnd() == false; i++)
|
i != sourcelist.end(); ++i)
|
||||||
{
|
{
|
||||||
std::string name = i.getNode()->getKey();
|
std::string name = *i;
|
||||||
infostream<<"\""<<name<<"\" ";
|
infostream<<"\""<<name<<"\" ";
|
||||||
}
|
}
|
||||||
infostream<<std::endl;
|
infostream<<std::endl;
|
||||||
@ -910,11 +910,11 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef)
|
|||||||
pos_in_atlas.X = column_padding;
|
pos_in_atlas.X = column_padding;
|
||||||
pos_in_atlas.Y = padding;
|
pos_in_atlas.Y = padding;
|
||||||
|
|
||||||
for(core::map<std::string, bool>::Iterator
|
for(std::set<std::string>::iterator
|
||||||
i = sourcelist.getIterator();
|
i = sourcelist.begin();
|
||||||
i.atEnd() == false; i++)
|
i != sourcelist.end(); ++i)
|
||||||
{
|
{
|
||||||
std::string name = i.getNode()->getKey();
|
std::string name = *i;
|
||||||
|
|
||||||
// Generate image by name
|
// Generate image by name
|
||||||
video::IImage *img2 = generate_image_from_scratch(name, m_device,
|
video::IImage *img2 = generate_image_from_scratch(name, m_device,
|
||||||
@ -1026,11 +1026,11 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef)
|
|||||||
bool reuse_old_id = false;
|
bool reuse_old_id = false;
|
||||||
u32 id = m_atlaspointer_cache.size();
|
u32 id = m_atlaspointer_cache.size();
|
||||||
// Check old id without fetching a texture
|
// Check old id without fetching a texture
|
||||||
core::map<std::string, u32>::Node *n;
|
std::map<std::string, u32>::iterator n;
|
||||||
n = m_name_to_id.find(name);
|
n = m_name_to_id.find(name);
|
||||||
// If it exists, we will replace the old definition
|
// If it exists, we will replace the old definition
|
||||||
if(n){
|
if(n != m_name_to_id.end()){
|
||||||
id = n->getValue();
|
id = n->second;
|
||||||
reuse_old_id = true;
|
reuse_old_id = true;
|
||||||
/*infostream<<"TextureSource::buildMainAtlas(): "
|
/*infostream<<"TextureSource::buildMainAtlas(): "
|
||||||
<<"Replacing old AtlasPointer"<<std::endl;*/
|
<<"Replacing old AtlasPointer"<<std::endl;*/
|
||||||
@ -1066,12 +1066,12 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef)
|
|||||||
/*
|
/*
|
||||||
Second pass: set texture pointer in generated AtlasPointers
|
Second pass: set texture pointer in generated AtlasPointers
|
||||||
*/
|
*/
|
||||||
for(core::map<std::string, bool>::Iterator
|
for(std::set<std::string>::iterator
|
||||||
i = sourcelist.getIterator();
|
i = sourcelist.begin();
|
||||||
i.atEnd() == false; i++)
|
i != sourcelist.end(); ++i)
|
||||||
{
|
{
|
||||||
std::string name = i.getNode()->getKey();
|
std::string name = *i;
|
||||||
if(m_name_to_id.find(name) == NULL)
|
if(m_name_to_id.find(name) == m_name_to_id.end())
|
||||||
continue;
|
continue;
|
||||||
u32 id = m_name_to_id[name];
|
u32 id = m_name_to_id[name];
|
||||||
//infostream<<"id of name "<<name<<" is "<<id<<std::endl;
|
//infostream<<"id of name "<<name<<" is "<<id<<std::endl;
|
||||||
|
@ -114,7 +114,7 @@ void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0,
|
|||||||
void spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, TreeDef tree_definition)
|
void spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, TreeDef tree_definition)
|
||||||
{
|
{
|
||||||
ServerMap *map = &env->getServerMap();
|
ServerMap *map = &env->getServerMap();
|
||||||
core::map<v3s16, MapBlock*> modified_blocks;
|
std::map<v3s16, MapBlock*> modified_blocks;
|
||||||
ManualMapVoxelManipulator vmanip(map);
|
ManualMapVoxelManipulator vmanip(map);
|
||||||
v3s16 tree_blockp = getNodeBlockPos(p0);
|
v3s16 tree_blockp = getNodeBlockPos(p0);
|
||||||
vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,3,1));
|
vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,3,1));
|
||||||
@ -122,23 +122,17 @@ void spawn_ltree (ServerEnvironment *env, v3s16 p0, INodeDefManager *ndef, TreeD
|
|||||||
vmanip.blitBackAll(&modified_blocks);
|
vmanip.blitBackAll(&modified_blocks);
|
||||||
|
|
||||||
// update lighting
|
// update lighting
|
||||||
core::map<v3s16, MapBlock*> lighting_modified_blocks;
|
std::map<v3s16, MapBlock*> lighting_modified_blocks;
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end());
|
||||||
i = modified_blocks.getIterator();
|
|
||||||
i.atEnd() == false; i++)
|
|
||||||
{
|
|
||||||
lighting_modified_blocks.insert(i.getNode()->getKey(), i.getNode()->getValue());
|
|
||||||
}
|
|
||||||
map->updateLighting(lighting_modified_blocks, modified_blocks);
|
map->updateLighting(lighting_modified_blocks, modified_blocks);
|
||||||
// Send a MEET_OTHER event
|
// Send a MEET_OTHER event
|
||||||
MapEditEvent event;
|
MapEditEvent event;
|
||||||
event.type = MEET_OTHER;
|
event.type = MEET_OTHER;
|
||||||
for(core::map<v3s16, MapBlock*>::Iterator
|
for(std::map<v3s16, MapBlock*>::iterator
|
||||||
i = modified_blocks.getIterator();
|
i = modified_blocks.begin();
|
||||||
i.atEnd() == false; i++)
|
i != modified_blocks.end(); ++i)
|
||||||
{
|
{
|
||||||
v3s16 p = i.getNode()->getKey();
|
event.modified_blocks.insert(i->first);
|
||||||
event.modified_blocks.insert(p, true);
|
|
||||||
}
|
}
|
||||||
map->dispatchEvent(&event);
|
map->dispatchEvent(&event);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <jmutex.h>
|
#include <jmutex.h>
|
||||||
#include <jmutexautolock.h>
|
#include <jmutexautolock.h>
|
||||||
#include "../porting.h" // For sleep_ms
|
#include "../porting.h" // For sleep_ms
|
||||||
|
#include <list>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Queue with unique values with fast checking of value existence
|
Queue with unique values with fast checking of value existence
|
||||||
@ -43,11 +45,11 @@ public:
|
|||||||
bool push_back(Value value)
|
bool push_back(Value value)
|
||||||
{
|
{
|
||||||
// Check if already exists
|
// Check if already exists
|
||||||
if(m_map.find(value) != NULL)
|
if(m_map.find(value) != m_map.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Add
|
// Add
|
||||||
m_map.insert(value, 0);
|
m_map[value] = 0;
|
||||||
m_list.push_back(value);
|
m_list.push_back(value);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -55,22 +57,21 @@ public:
|
|||||||
|
|
||||||
Value pop_front()
|
Value pop_front()
|
||||||
{
|
{
|
||||||
typename core::list<Value>::Iterator i = m_list.begin();
|
typename std::list<Value>::iterator i = m_list.begin();
|
||||||
Value value = *i;
|
Value value = *i;
|
||||||
m_map.remove(value);
|
m_map.erase(value);
|
||||||
m_list.erase(i);
|
m_list.erase(i);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 size()
|
u32 size()
|
||||||
{
|
{
|
||||||
assert(m_list.size() == m_map.size());
|
return m_map.size();
|
||||||
return m_list.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
core::map<Value, u8> m_map;
|
std::map<Value, u8> m_map;
|
||||||
core::list<Value> m_list;
|
std::list<Value> m_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
@ -95,31 +96,31 @@ public:
|
|||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
typename core::map<Key, Value>::Node *n;
|
typename std::map<Key, Value>::iterator n;
|
||||||
n = m_values.find(name);
|
n = m_values.find(name);
|
||||||
|
|
||||||
if(n == NULL)
|
if(n == m_values.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(result != NULL)
|
if(result != NULL)
|
||||||
*result = n->getValue();
|
*result = n->second;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<Value> getValues()
|
std::list<Value> getValues()
|
||||||
{
|
{
|
||||||
core::list<Value> result;
|
std::list<Value> result;
|
||||||
for(typename core::map<Key, Value>::Iterator
|
for(typename std::map<Key, Value>::iterator
|
||||||
i = m_values.getIterator();
|
i = m_values.begin();
|
||||||
i.atEnd() == false; i++){
|
i != m_values.end(); ++i){
|
||||||
result.push_back(i.getNode()->getValue());
|
result.push_back(i->second);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
core::map<Key, Value> m_values;
|
std::map<Key, Value> m_values;
|
||||||
JMutex m_mutex;
|
JMutex m_mutex;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@ -163,10 +164,10 @@ public:
|
|||||||
u32 getId(const T &value)
|
u32 getId(const T &value)
|
||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
typename core::map<T, u32>::Node *n;
|
typename std::map<T, u32>::iterator n;
|
||||||
n = m_value_to_id.find(value);
|
n = m_value_to_id.find(value);
|
||||||
if(n != NULL)
|
if(n != m_value_to_id.end())
|
||||||
return n->getValue();
|
return n->second;
|
||||||
m_id_to_value.push_back(value);
|
m_id_to_value.push_back(value);
|
||||||
u32 new_id = m_id_to_value.size();
|
u32 new_id = m_id_to_value.size();
|
||||||
m_value_to_id.insert(value, new_id);
|
m_value_to_id.insert(value, new_id);
|
||||||
@ -176,8 +177,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
JMutex m_mutex;
|
JMutex m_mutex;
|
||||||
// Values are stored here at id-1 position (id 1 = [0])
|
// Values are stored here at id-1 position (id 1 = [0])
|
||||||
core::array<T> m_id_to_value;
|
std::vector<T> m_id_to_value;
|
||||||
core::map<T, u32> m_value_to_id;
|
std::map<T, u32> m_value_to_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -187,39 +188,52 @@ template<typename T>
|
|||||||
class Queue
|
class Queue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Queue():
|
||||||
|
m_list_size(0)
|
||||||
|
{}
|
||||||
|
|
||||||
void push_back(T t)
|
void push_back(T t)
|
||||||
{
|
{
|
||||||
m_list.push_back(t);
|
m_list.push_back(t);
|
||||||
|
++m_list_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
T pop_front()
|
T pop_front()
|
||||||
{
|
{
|
||||||
if(m_list.size() == 0)
|
if(m_list.empty())
|
||||||
throw ItemNotFoundException("Queue: queue is empty");
|
throw ItemNotFoundException("Queue: queue is empty");
|
||||||
|
|
||||||
typename core::list<T>::Iterator begin = m_list.begin();
|
typename std::list<T>::iterator begin = m_list.begin();
|
||||||
T t = *begin;
|
T t = *begin;
|
||||||
m_list.erase(begin);
|
m_list.erase(begin);
|
||||||
|
--m_list_size;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
T pop_back()
|
T pop_back()
|
||||||
{
|
{
|
||||||
if(m_list.size() == 0)
|
if(m_list.empty())
|
||||||
throw ItemNotFoundException("Queue: queue is empty");
|
throw ItemNotFoundException("Queue: queue is empty");
|
||||||
|
|
||||||
typename core::list<T>::Iterator last = m_list.getLast();
|
typename std::list<T>::iterator last = m_list.back();
|
||||||
T t = *last;
|
T t = *last;
|
||||||
m_list.erase(last);
|
m_list.erase(last);
|
||||||
|
--m_list_size;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 size()
|
u32 size()
|
||||||
{
|
{
|
||||||
return m_list.size();
|
return m_list_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty()
|
||||||
|
{
|
||||||
|
return m_list.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
core::list<T> m_list;
|
std::list<T> m_list;
|
||||||
|
u32 m_list_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -234,10 +248,10 @@ public:
|
|||||||
{
|
{
|
||||||
m_mutex.Init();
|
m_mutex.Init();
|
||||||
}
|
}
|
||||||
u32 size()
|
bool empty()
|
||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
return m_list.size();
|
return m_list.empty();
|
||||||
}
|
}
|
||||||
void push_back(T t)
|
void push_back(T t)
|
||||||
{
|
{
|
||||||
@ -253,9 +267,9 @@ public:
|
|||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
if(m_list.size() > 0)
|
if(!m_list.empty())
|
||||||
{
|
{
|
||||||
typename core::list<T>::Iterator begin = m_list.begin();
|
typename std::list<T>::iterator begin = m_list.begin();
|
||||||
T t = *begin;
|
T t = *begin;
|
||||||
m_list.erase(begin);
|
m_list.erase(begin);
|
||||||
return t;
|
return t;
|
||||||
@ -279,9 +293,9 @@ public:
|
|||||||
{
|
{
|
||||||
JMutexAutoLock lock(m_mutex);
|
JMutexAutoLock lock(m_mutex);
|
||||||
|
|
||||||
if(m_list.size() > 0)
|
if(!m_list.empty())
|
||||||
{
|
{
|
||||||
typename core::list<T>::Iterator last = m_list.getLast();
|
typename std::list<T>::iterator last = m_list.back();
|
||||||
T t = *last;
|
T t = *last;
|
||||||
m_list.erase(last);
|
m_list.erase(last);
|
||||||
return t;
|
return t;
|
||||||
@ -302,14 +316,14 @@ public:
|
|||||||
return m_mutex;
|
return m_mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
core::list<T> & getList()
|
std::list<T> & getList()
|
||||||
{
|
{
|
||||||
return m_list;
|
return m_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JMutex m_mutex;
|
JMutex m_mutex;
|
||||||
core::list<T> m_list;
|
std::list<T> m_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Calculate the borders of a "d-radius" cube
|
// Calculate the borders of a "d-radius" cube
|
||||||
void getFacePositions(core::list<v3s16> &list, u16 d)
|
void getFacePositions(std::list<v3s16> &list, u16 d)
|
||||||
{
|
{
|
||||||
if(d == 0)
|
if(d == 0)
|
||||||
{
|
{
|
||||||
|
@ -25,9 +25,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "../irr_v3d.h"
|
#include "../irr_v3d.h"
|
||||||
#include "../irr_aabb3d.h"
|
#include "../irr_aabb3d.h"
|
||||||
#include <irrList.h>
|
#include <irrList.h>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
// Calculate the borders of a "d-radius" cube
|
// Calculate the borders of a "d-radius" cube
|
||||||
void getFacePositions(core::list<v3s16> &list, u16 d);
|
void getFacePositions(std::list<v3s16> &list, u16 d);
|
||||||
|
|
||||||
class IndentationRaiser
|
class IndentationRaiser
|
||||||
{
|
{
|
||||||
|
@ -120,7 +120,7 @@ class GetResult
|
|||||||
public:
|
public:
|
||||||
Key key;
|
Key key;
|
||||||
T item;
|
T item;
|
||||||
core::list<CallerInfo<Caller, CallerData> > callers;
|
std::list<CallerInfo<Caller, CallerData> > callers;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Key, typename T, typename Caller, typename CallerData>
|
template<typename Key, typename T, typename Caller, typename CallerData>
|
||||||
@ -152,16 +152,16 @@ public:
|
|||||||
|
|
||||||
Key key;
|
Key key;
|
||||||
ResultQueue<Key, T, Caller, CallerData> *dest;
|
ResultQueue<Key, T, Caller, CallerData> *dest;
|
||||||
core::list<CallerInfo<Caller, CallerData> > callers;
|
std::list<CallerInfo<Caller, CallerData> > callers;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Key, typename T, typename Caller, typename CallerData>
|
template<typename Key, typename T, typename Caller, typename CallerData>
|
||||||
class RequestQueue
|
class RequestQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
u32 size()
|
bool empty()
|
||||||
{
|
{
|
||||||
return m_queue.size();
|
return m_queue.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(Key key, Caller caller, CallerData callerdata,
|
void add(Key key, Caller caller, CallerData callerdata,
|
||||||
@ -172,17 +172,17 @@ public:
|
|||||||
/*
|
/*
|
||||||
If the caller is already on the list, only update CallerData
|
If the caller is already on the list, only update CallerData
|
||||||
*/
|
*/
|
||||||
for(typename core::list< GetRequest<Key, T, Caller, CallerData> >::Iterator
|
for(typename std::list< GetRequest<Key, T, Caller, CallerData> >::iterator
|
||||||
i = m_queue.getList().begin();
|
i = m_queue.getList().begin();
|
||||||
i != m_queue.getList().end(); i++)
|
i != m_queue.getList().end(); ++i)
|
||||||
{
|
{
|
||||||
GetRequest<Key, T, Caller, CallerData> &request = *i;
|
GetRequest<Key, T, Caller, CallerData> &request = *i;
|
||||||
|
|
||||||
if(request.key == key)
|
if(request.key == key)
|
||||||
{
|
{
|
||||||
for(typename core::list< CallerInfo<Caller, CallerData> >::Iterator
|
for(typename std::list< CallerInfo<Caller, CallerData> >::iterator
|
||||||
i = request.callers.begin();
|
i = request.callers.begin();
|
||||||
i != request.callers.end(); i++)
|
i != request.callers.end(); ++i)
|
||||||
{
|
{
|
||||||
CallerInfo<Caller, CallerData> &ca = *i;
|
CallerInfo<Caller, CallerData> &ca = *i;
|
||||||
if(ca.caller == caller)
|
if(ca.caller == caller)
|
||||||
|
@ -302,7 +302,7 @@ void VoxelManipulator::clearFlag(u8 flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight,
|
void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight,
|
||||||
core::map<v3s16, bool> & light_sources, INodeDefManager *nodemgr)
|
std::set<v3s16> & light_sources, INodeDefManager *nodemgr)
|
||||||
{
|
{
|
||||||
v3s16 dirs[6] = {
|
v3s16 dirs[6] = {
|
||||||
v3s16(0,0,1), // back
|
v3s16(0,0,1), // back
|
||||||
@ -360,7 +360,7 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
light_sources.insert(n2pos, true);
|
light_sources.insert(n2pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -384,24 +384,16 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight,
|
|||||||
values of from_nodes are lighting values.
|
values of from_nodes are lighting values.
|
||||||
*/
|
*/
|
||||||
void VoxelManipulator::unspreadLight(enum LightBank bank,
|
void VoxelManipulator::unspreadLight(enum LightBank bank,
|
||||||
core::map<v3s16, u8> & from_nodes,
|
std::map<v3s16, u8> & from_nodes,
|
||||||
core::map<v3s16, bool> & light_sources, INodeDefManager *nodemgr)
|
std::set<v3s16> & light_sources, INodeDefManager *nodemgr)
|
||||||
{
|
{
|
||||||
if(from_nodes.size() == 0)
|
if(from_nodes.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
core::map<v3s16, u8>::Iterator j;
|
for(std::map<v3s16, u8>::iterator j = from_nodes.begin();
|
||||||
j = from_nodes.getIterator();
|
j != from_nodes.end(); ++j)
|
||||||
|
|
||||||
for(; j.atEnd() == false; j++)
|
|
||||||
{
|
{
|
||||||
v3s16 pos = j.getNode()->getKey();
|
unspreadLight(bank, j->first, j->second, light_sources, nodemgr);
|
||||||
|
|
||||||
//MapNode &n = m_data[m_area.index(pos)];
|
|
||||||
|
|
||||||
u8 oldlight = j.getNode()->getValue();
|
|
||||||
|
|
||||||
unspreadLight(bank, pos, oldlight, light_sources, nodemgr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -609,7 +601,7 @@ void VoxelManipulator::spreadLight(enum LightBank bank,
|
|||||||
goes on recursively.
|
goes on recursively.
|
||||||
*/
|
*/
|
||||||
void VoxelManipulator::spreadLight(enum LightBank bank,
|
void VoxelManipulator::spreadLight(enum LightBank bank,
|
||||||
core::map<v3s16, bool> & from_nodes, INodeDefManager *nodemgr)
|
std::set<v3s16> & from_nodes, INodeDefManager *nodemgr)
|
||||||
{
|
{
|
||||||
const v3s16 dirs[6] = {
|
const v3s16 dirs[6] = {
|
||||||
v3s16(0,0,1), // back
|
v3s16(0,0,1), // back
|
||||||
@ -623,13 +615,12 @@ void VoxelManipulator::spreadLight(enum LightBank bank,
|
|||||||
if(from_nodes.size() == 0)
|
if(from_nodes.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
core::map<v3s16, bool> lighted_nodes;
|
std::set<v3s16> lighted_nodes;
|
||||||
core::map<v3s16, bool>::Iterator j;
|
|
||||||
j = from_nodes.getIterator();
|
|
||||||
|
|
||||||
for(; j.atEnd() == false; j++)
|
for(std::set<v3s16>::iterator j = from_nodes.begin();
|
||||||
|
j != from_nodes.end(); ++j)
|
||||||
{
|
{
|
||||||
v3s16 pos = j.getNode()->getKey();
|
v3s16 pos = *j;
|
||||||
|
|
||||||
emerge(VoxelArea(pos - v3s16(1,1,1), pos + v3s16(1,1,1)));
|
emerge(VoxelArea(pos - v3s16(1,1,1), pos + v3s16(1,1,1)));
|
||||||
|
|
||||||
@ -666,7 +657,7 @@ void VoxelManipulator::spreadLight(enum LightBank bank,
|
|||||||
*/
|
*/
|
||||||
if(light2 > undiminish_light(oldlight))
|
if(light2 > undiminish_light(oldlight))
|
||||||
{
|
{
|
||||||
lighted_nodes.insert(n2pos, true);
|
lighted_nodes.insert(n2pos);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
If the neighbor is dimmer than how much light this node
|
If the neighbor is dimmer than how much light this node
|
||||||
@ -677,7 +668,7 @@ void VoxelManipulator::spreadLight(enum LightBank bank,
|
|||||||
if(nodemgr->get(n2).light_propagates)
|
if(nodemgr->get(n2).light_propagates)
|
||||||
{
|
{
|
||||||
n2.setLight(bank, newlight, nodemgr);
|
n2.setLight(bank, newlight, nodemgr);
|
||||||
lighted_nodes.insert(n2pos, true);
|
lighted_nodes.insert(n2pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/voxel.h
12
src/voxel.h
@ -26,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "mapnode.h"
|
#include "mapnode.h"
|
||||||
|
#include <set>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
class INodeDefManager;
|
class INodeDefManager;
|
||||||
|
|
||||||
@ -186,7 +188,7 @@ public:
|
|||||||
|
|
||||||
a: area inside *this
|
a: area inside *this
|
||||||
*/
|
*/
|
||||||
void diff(const VoxelArea &a, core::list<VoxelArea> &result)
|
void diff(const VoxelArea &a, std::list<VoxelArea> &result)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
This can result in a maximum of 6 areas
|
This can result in a maximum of 6 areas
|
||||||
@ -519,14 +521,14 @@ public:
|
|||||||
// TODO: Move to voxelalgorithms.h
|
// TODO: Move to voxelalgorithms.h
|
||||||
|
|
||||||
void unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight,
|
void unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight,
|
||||||
core::map<v3s16, bool> & light_sources, INodeDefManager *nodemgr);
|
std::set<v3s16> & light_sources, INodeDefManager *nodemgr);
|
||||||
void unspreadLight(enum LightBank bank,
|
void unspreadLight(enum LightBank bank,
|
||||||
core::map<v3s16, u8> & from_nodes,
|
std::map<v3s16, u8> & from_nodes,
|
||||||
core::map<v3s16, bool> & light_sources, INodeDefManager *nodemgr);
|
std::set<v3s16> & light_sources, INodeDefManager *nodemgr);
|
||||||
|
|
||||||
void spreadLight(enum LightBank bank, v3s16 p, INodeDefManager *nodemgr);
|
void spreadLight(enum LightBank bank, v3s16 p, INodeDefManager *nodemgr);
|
||||||
void spreadLight(enum LightBank bank,
|
void spreadLight(enum LightBank bank,
|
||||||
core::map<v3s16, bool> & from_nodes, INodeDefManager *nodemgr);
|
std::set<v3s16> & from_nodes, INodeDefManager *nodemgr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Virtual functions
|
Virtual functions
|
||||||
|
@ -39,8 +39,8 @@ void setLight(VoxelManipulator &v, VoxelArea a, u8 light,
|
|||||||
|
|
||||||
void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
|
void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
|
||||||
enum LightBank bank, INodeDefManager *ndef,
|
enum LightBank bank, INodeDefManager *ndef,
|
||||||
core::map<v3s16, bool> & light_sources,
|
std::set<v3s16> & light_sources,
|
||||||
core::map<v3s16, u8> & unlight_from)
|
std::map<v3s16, u8> & unlight_from)
|
||||||
{
|
{
|
||||||
// The full area we shall touch
|
// The full area we shall touch
|
||||||
VoxelArea required_a = a;
|
VoxelArea required_a = a;
|
||||||
@ -60,7 +60,7 @@ void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
|
|||||||
// If node sources light, add to list
|
// If node sources light, add to list
|
||||||
u8 source = ndef->get(n).light_source;
|
u8 source = ndef->get(n).light_source;
|
||||||
if(source != 0)
|
if(source != 0)
|
||||||
light_sources[p] = true;
|
light_sources.insert(p);
|
||||||
|
|
||||||
// Collect borders for unlighting
|
// Collect borders for unlighting
|
||||||
if((x==a.MinEdge.X || x == a.MaxEdge.X
|
if((x==a.MinEdge.X || x == a.MaxEdge.X
|
||||||
@ -68,14 +68,14 @@ void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
|
|||||||
|| z==a.MinEdge.Z || z == a.MaxEdge.Z)
|
|| z==a.MinEdge.Z || z == a.MaxEdge.Z)
|
||||||
&& oldlight != 0)
|
&& oldlight != 0)
|
||||||
{
|
{
|
||||||
unlight_from.insert(p, oldlight);
|
unlight_from[p] = oldlight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
|
SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
|
||||||
bool inexistent_top_provides_sunlight,
|
bool inexistent_top_provides_sunlight,
|
||||||
core::map<v3s16, bool> & light_sources,
|
std::set<v3s16> & light_sources,
|
||||||
INodeDefManager *ndef)
|
INodeDefManager *ndef)
|
||||||
{
|
{
|
||||||
// Return values
|
// Return values
|
||||||
@ -127,7 +127,7 @@ SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
|
|||||||
n.setLight(LIGHTBANK_DAY, incoming_light, ndef);
|
n.setLight(LIGHTBANK_DAY, incoming_light, ndef);
|
||||||
|
|
||||||
if(diminish_light(incoming_light) != 0)
|
if(diminish_light(incoming_light) != 0)
|
||||||
light_sources.insert(p, true);
|
light_sources.insert(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check validity of sunlight at top of block below if it
|
// Check validity of sunlight at top of block below if it
|
||||||
|
@ -22,6 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include "voxel.h"
|
#include "voxel.h"
|
||||||
#include "mapnode.h"
|
#include "mapnode.h"
|
||||||
|
#include <set>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace voxalgo
|
namespace voxalgo
|
||||||
{
|
{
|
||||||
@ -33,8 +35,8 @@ void setLight(VoxelManipulator &v, VoxelArea a, u8 light,
|
|||||||
|
|
||||||
void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
|
void clearLightAndCollectSources(VoxelManipulator &v, VoxelArea a,
|
||||||
enum LightBank bank, INodeDefManager *ndef,
|
enum LightBank bank, INodeDefManager *ndef,
|
||||||
core::map<v3s16, bool> & light_sources,
|
std::set<v3s16> & light_sources,
|
||||||
core::map<v3s16, u8> & unlight_from);
|
std::map<v3s16, u8> & unlight_from);
|
||||||
|
|
||||||
struct SunlightPropagateResult
|
struct SunlightPropagateResult
|
||||||
{
|
{
|
||||||
@ -47,7 +49,7 @@ struct SunlightPropagateResult
|
|||||||
|
|
||||||
SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
|
SunlightPropagateResult propagateSunlight(VoxelManipulator &v, VoxelArea a,
|
||||||
bool inexistent_top_provides_sunlight,
|
bool inexistent_top_provides_sunlight,
|
||||||
core::map<v3s16, bool> & light_sources,
|
std::set<v3s16> & light_sources,
|
||||||
INodeDefManager *ndef);
|
INodeDefManager *ndef);
|
||||||
|
|
||||||
} // namespace voxalgo
|
} // namespace voxalgo
|
||||||
|
Loading…
Reference in New Issue
Block a user