# It's usually sufficient to change just the target name and source file list\r
# and be sure that CXX is set to a valid compiler\r
TARGET = test\r
-SOURCE_FILES = guiPauseMenu.cpp mapnode.cpp tile.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp client.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp main.cpp test.cpp\r
+SOURCE_FILES = guiPauseMenu.cpp defaultsettings.cpp mapnode.cpp tile.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp client.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp main.cpp test.cpp\r
SOURCES = $(addprefix src/, $(SOURCE_FILES))\r
-BUILD_DIR = build\r
+BUILD_DIR = build/\r
OBJECTS = $(addprefix $(BUILD_DIR)/, $(SOURCE_FILES:.cpp=.o))\r
#OBJECTS = $(SOURCES:.cpp=.o)\r
\r
FAST_TARGET = fasttest\r
\r
SERVER_TARGET = server\r
-SERVER_SOURCE_FILES = mapnode.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp servermain.cpp test.cpp\r
+SERVER_SOURCE_FILES = defaultsettings.cpp mapnode.cpp voxel.cpp mapblockobject.cpp inventory.cpp debug.cpp serialization.cpp light.cpp filesys.cpp connection.cpp environment.cpp server.cpp socket.cpp mapblock.cpp mapsector.cpp heightmap.cpp map.cpp player.cpp utility.cpp servermain.cpp test.cpp\r
SERVER_SOURCES = $(addprefix src/, $(SERVER_SOURCE_FILES))\r
-SERVER_BUILD_DIR = serverbuild\r
+SERVER_BUILD_DIR = serverbuild/\r
SERVER_OBJECTS = $(addprefix $(SERVER_BUILD_DIR)/, $(SERVER_SOURCE_FILES:.cpp=.o))\r
#SERVER_OBJECTS = $(SERVER_SOURCES:.cpp=.o)\r
\r
\r
# Build commands\r
\r
-all_linux all_win32: make_build_dir $(DESTPATH)\r
-fast_linux: make_build_dir $(FAST_DESTPATH)\r
-server_linux: make_server_build_dir $(SERVER_DESTPATH)\r
+all_linux all_win32: $(BUILD_DIR) $(DESTPATH)\r
+fast_linux: $(BUILD_DIR) $(FAST_DESTPATH)\r
+server_linux: $(SERVER_BUILD_DIR) $(SERVER_DESTPATH)\r
\r
-make_build_dir:\r
+$(BUILD_DIR):\r
mkdir -p $(BUILD_DIR)\r
-make_server_build_dir:\r
+$(SERVER_BUILD_DIR):\r
mkdir -p $(SERVER_BUILD_DIR)\r
\r
$(DESTPATH): $(OBJECTS)\r
# Note that this gets applied at map generation time
#endless_water = true
+# 20 min/day
+#time_speed = 72
+# 1 min/day
+#time_speed = 1440
+
+#time_send_interval = 5
+
m_server_ser_ver(SER_FMT_VER_INVALID),
m_step_dtime(0.0),
m_inventory_updated(false),
- m_time(0),
- m_time_counter(0.0)
- //m_daynight_i(0)
- //m_daynight_ratio(1000)
+ m_time_of_day(0)
{
m_packetcounter_timer = 0.0;
m_delete_unused_sectors_timer = 0.0;
Day/night
*/
{
- m_time_counter += dtime;
- int seconds = (int)m_time_counter;
- m_time_counter -= (float)seconds;
- m_time += seconds;
- if(seconds > 0)
+ s32 d = 8;
+ s32 t = (((m_time_of_day.get() + 24000/d/2)%24000)/(24000/d));
+ s32 dn = 0;
+ if(t == d/4 || t == (d-d/4))
+ dn = 1;
+ else if(t < d/4 || t > (d-d/4))
+ dn = 2;
+ else
+ dn = 0;
+
+ u32 dr = 1000;
+ if(dn == 0)
+ dr = 1000;
+ if(dn == 1)
+ dr = 600;
+ if(dn == 2)
+ dr = 300;
+
+ if(dr != m_env.getDayNightRatio())
{
- //dstream<<"m_time="<<m_time<<std::endl;
- /*JMutexAutoLock envlock(m_env_mutex);
- u32 dr = 500+500*sin((float)((m_time/10)%7)/7.*2.*PI);
- if(dr != m_env.getDayNightRatio())
- {
- dstream<<"dr="<<dr<<std::endl;
- m_env.setDayNightRatio(dr);
- m_env.expireMeshes();
- }*/
-#if 1
- s32 d = 4;
- s32 t = (m_time/10)%d;
- s32 dn = 0;
- if(t == d/2-1 || t == d-1)
- dn = 1;
- else if(t < d/2-1)
- dn = 0;
- else
- dn = 2;
-
- u32 dr = 1000;
- if(dn == 0)
- dr = 1000;
- if(dn == 1)
- dr = 600;
- if(dn == 2)
- dr = 300;
-#else
- u32 dr = 1000;
-#endif
- if(dr != m_env.getDayNightRatio())
- {
- dstream<<"dr="<<dr<<std::endl;
- m_env.setDayNightRatio(dr);
- m_env.expireMeshes(true);
- }
+ //dstream<<"dr="<<dr<<std::endl;
+ m_env.setDayNightRatio(dr);
+ m_env.expireMeshes(true);
}
}
} //envlock
}
+ else if(command == TOCLIENT_TIME_OF_DAY)
+ {
+ if(datasize < 4)
+ return;
+
+ u16 time = readU16(&data[2]);
+ time = time % 24000;
+ m_time_of_day.set(time);
+ //dstream<<"Client: time="<<time<<std::endl;
+ }
// Default to queueing it (for slow commands)
else
{
PacketCounter m_packetcounter;
- // Access these only in main thread.
- u32 m_time;
- float m_time_counter;
+ // Received from the server. 0-23999
+ MutexedVariable<u32> m_time_of_day;
// 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT
//s32 m_daynight_i;
#ifndef CLIENTSERVER_HEADER
#define CLIENTSERVER_HEADER
+#include "utility.h"
+
#define PROTOCOL_ID 0x4f457403
enum ToClientCommand
v3s16 blockpos
block objects
*/
+
+ TOCLIENT_TIME_OF_DAY = 0x29,
+ /*
+ u16 command
+ u16 time (0-23999)
+ */
};
enum ToServerCommand
*/
};
-// Flags for TOSERVER_GETBLOCK
-#define TOSERVER_GETBLOCK_FLAG_OPTIONAL (1<<0)
+inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time)
+{
+ SharedBuffer<u8> data(2+2);
+ writeU16(&data[0], TOCLIENT_TIME_OF_DAY);
+ writeU16(&data[2], time);
+ return data;
+}
#endif
--- /dev/null
+/*
+Minetest-c55
+Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "utility.h"
+
+extern Settings g_settings;
+
+void set_default_settings()
+{
+ // Client stuff
+ g_settings.setDefault("wanted_fps", "30");
+ g_settings.setDefault("fps_max", "60");
+ g_settings.setDefault("viewing_range_nodes_max", "300");
+ g_settings.setDefault("viewing_range_nodes_min", "35");
+ g_settings.setDefault("screenW", "");
+ g_settings.setDefault("screenH", "");
+ g_settings.setDefault("host_game", "");
+ g_settings.setDefault("port", "");
+ g_settings.setDefault("address", "");
+ g_settings.setDefault("name", "");
+ g_settings.setDefault("random_input", "false");
+ g_settings.setDefault("client_delete_unused_sectors_timeout", "1200");
+ g_settings.setDefault("enable_fog", "true");
+
+ // Server stuff
+ g_settings.setDefault("creative_mode", "false");
+ g_settings.setDefault("heightmap_blocksize", "32");
+ g_settings.setDefault("height_randmax", "constant 50.0");
+ g_settings.setDefault("height_randfactor", "constant 0.6");
+ g_settings.setDefault("height_base", "linear 0 0 0");
+ g_settings.setDefault("plants_amount", "1.0");
+ g_settings.setDefault("ravines_amount", "1.0");
+ g_settings.setDefault("objectdata_interval", "0.2");
+ g_settings.setDefault("active_object_range", "2");
+ g_settings.setDefault("max_simultaneous_block_sends_per_client", "1");
+ g_settings.setDefault("max_simultaneous_block_sends_server_total", "4");
+ g_settings.setDefault("disable_water_climb", "true");
+ g_settings.setDefault("endless_water", "true");
+ g_settings.setDefault("max_block_send_distance", "5");
+ g_settings.setDefault("max_block_generate_distance", "4");
+ g_settings.setDefault("time_send_interval", "20");
+ g_settings.setDefault("time_speed", "144");
+}
+
\r
TODO: Remove LazyMeshUpdater. It is not used as supposed.\r
\r
-TODO: Node cracking animation when digging\r
- - TODO: A way to generate new textures by combining textures\r
- - TODO: Mesh update to fetch cracked faces from the former\r
-\r
TODO: Add server unused sector deletion settings to settings\r
\r
TODO: TOSERVER_LEAVE\r
Doing now:\r
======================================================================\r
\r
+TODO: Node cracking animation when digging\r
+ - TODO: A way to generate new textures by combining textures\r
+ - TODO: Mesh update to fetch cracked faces from the former\r
+\r
======================================================================\r
\r
*/\r
\r
Settings g_settings;\r
\r
-// Sets default settings\r
-void set_default_settings()\r
-{\r
- // Client stuff\r
- g_settings.setDefault("wanted_fps", "30");\r
- g_settings.setDefault("fps_max", "60");\r
- g_settings.setDefault("viewing_range_nodes_max", "300");\r
- g_settings.setDefault("viewing_range_nodes_min", "35");\r
- g_settings.setDefault("screenW", "");\r
- g_settings.setDefault("screenH", "");\r
- g_settings.setDefault("host_game", "");\r
- g_settings.setDefault("port", "");\r
- g_settings.setDefault("address", "");\r
- g_settings.setDefault("name", "");\r
- g_settings.setDefault("random_input", "false");\r
- g_settings.setDefault("client_delete_unused_sectors_timeout", "1200");\r
- g_settings.setDefault("enable_fog", "true");\r
-\r
- // Server stuff\r
- g_settings.setDefault("creative_mode", "false");\r
- g_settings.setDefault("heightmap_blocksize", "32");\r
- g_settings.setDefault("height_randmax", "constant 50.0");\r
- g_settings.setDefault("height_randfactor", "constant 0.6");\r
- g_settings.setDefault("height_base", "linear 0 0 0");\r
- g_settings.setDefault("plants_amount", "1.0");\r
- g_settings.setDefault("ravines_amount", "1.0");\r
- g_settings.setDefault("objectdata_interval", "0.2");\r
- g_settings.setDefault("active_object_range", "2");\r
- g_settings.setDefault("max_simultaneous_block_sends_per_client", "1");\r
- g_settings.setDefault("max_simultaneous_block_sends_server_total", "4");\r
- g_settings.setDefault("disable_water_climb", "true");\r
- g_settings.setDefault("endless_water", "true");\r
- g_settings.setDefault("max_block_send_distance", "5");\r
- g_settings.setDefault("max_block_generate_distance", "4");\r
-}\r
+extern void set_default_settings();\r
\r
/*\r
Random stuff\r
#include "constants.h"
#include "voxel.h"
+#define BLOCK_EMERGE_FLAG_FROMDISK (1<<0)
+
void * ServerThread::Thread()
{
ThreadStarted();
// Check flags
u8 flags = i.getNode()->getValue();
- if((flags & TOSERVER_GETBLOCK_FLAG_OPTIONAL) == false)
+ if((flags & BLOCK_EMERGE_FLAG_FROMDISK) == false)
optional = false;
}
u8 flags = 0;
if(generate == false)
- flags |= TOSERVER_GETBLOCK_FLAG_OPTIONAL;
+ flags |= BLOCK_EMERGE_FLAG_FROMDISK;
server->m_emerge_queue.addBlock(peer_id, p, flags);
server->m_emergethread.trigger();
m_num_blocks_in_emerge_queue.m_value++;*/
// Add to queue as an anonymous fetch from disk
- u8 flags = TOSERVER_GETBLOCK_FLAG_OPTIONAL;
+ u8 flags = BLOCK_EMERGE_FLAG_FROMDISK;
server->m_emerge_queue.addBlock(0, p, flags);
server->m_emergethread.trigger();
}
m_env(new ServerMap(mapsavedir, hm_params, map_params), dout_server),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_thread(this),
- m_emergethread(this)
+ m_emergethread(this),
+ m_time_of_day(12000),
+ m_time_counter(0),
+ m_time_of_day_send_timer(0)
{
m_flowwater_timer = 0.0;
m_print_info_timer = 0.0;
JMutexAutoLock lock1(m_step_dtime_mutex);
m_step_dtime -= dtime;
}
+
+ /*
+ Update m_time_of_day
+ */
+ {
+ m_time_counter += dtime;
+ f32 speed = g_settings.getFloat("time_speed") * 24000./(24.*3600);
+ u32 units = (u32)(m_time_counter*speed);
+ m_time_counter -= (f32)units / speed;
+ m_time_of_day.set((m_time_of_day.get() + units) % 24000);
+
+ //dstream<<"Server: m_time_of_day = "<<m_time_of_day.get()<<std::endl;
+
+ /*
+ Send to clients at constant intervals
+ */
+
+ m_time_of_day_send_timer -= dtime;
+ if(m_time_of_day_send_timer < 0.0)
+ {
+ m_time_of_day_send_timer = g_settings.getFloat("time_send_interval");
+
+ //JMutexAutoLock envlock(m_env_mutex);
+ JMutexAutoLock conlock(m_con_mutex);
+
+ for(core::map<u16, RemoteClient*>::Iterator
+ i = m_clients.getIterator();
+ i.atEnd() == false; i++)
+ {
+ RemoteClient *client = i.getNode()->getValue();
+ //Player *player = m_env.getPlayer(client->peer_id);
+
+ SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(
+ m_time_of_day.get());
+ // Send as reliable
+ m_con.Send(client->peer_id, 0, data, true);
+ }
+ }
+ }
//dstream<<"Server steps "<<dtime<<std::endl;
// Send inventory to player
SendInventory(peer->id);
+
+ // Send time of day
+ {
+ SharedBuffer<u8> data = makePacket_TOCLIENT_TIME_OF_DAY(
+ m_time_of_day.get());
+ m_con.Send(peer->id, 0, data, true);
+ }
return;
}
void GetNextBlocks(Server *server, float dtime,
core::array<PrioritySortedBlockTransfer> &dest);
- // Connection and environment should be locked when this is called
- // steps() objects of blocks not found in active_blocks, then
- // adds those blocks to active_blocks
+ /*
+ Connection and environment should be locked when this is called.
+ steps() objects of blocks not found in active_blocks, then
+ adds those blocks to active_blocks
+ */
void SendObjectData(
Server *server,
float dtime,
void SetBlockNotSent(v3s16 p);
void SetBlocksNotSent(core::map<v3s16, MapBlock*> &blocks);
- //void BlockEmerged();
-
- /*bool IsSendingBlock(v3s16 p)
- {
- JMutexAutoLock lock(m_blocks_sending_mutex);
- return (m_blocks_sending.find(p) != NULL);
- }*/
-
s32 SendingCount()
{
JMutexAutoLock lock(m_blocks_sending_mutex);
// Nodes that are destinations of flowing liquid at the moment
core::map<v3s16, u8> m_flow_active_nodes;
+
+ // 0-23999
+ MutexedVariable<u32> m_time_of_day;
+ // Used to buffer dtime for adding to m_time_of_day
+ float m_time_counter;
+ float m_time_of_day_send_timer;
friend class EmergeThread;
friend class RemoteClient;
Settings g_settings;
-// Sets default settings
-void set_default_settings()
-{
- // Client stuff
- g_settings.setDefault("wanted_fps", "30");
- g_settings.setDefault("fps_max", "60");
- g_settings.setDefault("viewing_range_nodes_max", "300");
- g_settings.setDefault("viewing_range_nodes_min", "35");
- g_settings.setDefault("screenW", "");
- g_settings.setDefault("screenH", "");
- g_settings.setDefault("host_game", "");
- g_settings.setDefault("port", "");
- g_settings.setDefault("address", "");
- g_settings.setDefault("name", "");
- g_settings.setDefault("random_input", "false");
- g_settings.setDefault("client_delete_unused_sectors_timeout", "1200");
- g_settings.setDefault("enable_fog", "true");
-
- // Server stuff
- g_settings.setDefault("creative_mode", "false");
- g_settings.setDefault("heightmap_blocksize", "32");
- g_settings.setDefault("height_randmax", "constant 50.0");
- g_settings.setDefault("height_randfactor", "constant 0.6");
- g_settings.setDefault("height_base", "linear 0 0 0");
- g_settings.setDefault("plants_amount", "1.0");
- g_settings.setDefault("ravines_amount", "1.0");
- g_settings.setDefault("objectdata_interval", "0.2");
- g_settings.setDefault("active_object_range", "2");
- g_settings.setDefault("max_simultaneous_block_sends_per_client", "1");
- g_settings.setDefault("max_simultaneous_block_sends_server_total", "4");
- g_settings.setDefault("disable_water_climb", "true");
- g_settings.setDefault("endless_water", "true");
- g_settings.setDefault("max_block_send_distance", "5");
- g_settings.setDefault("max_block_generate_distance", "4");
-}
+extern void set_default_settings();
/*
Debug streams