Skip to content

Commit

Permalink
working time-of-day sending from server to client
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron55 committed Dec 20, 2010
1 parent ab7477c commit 5a36956
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 148 deletions.
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# It's usually sufficient to change just the target name and source file list
# and be sure that CXX is set to a valid compiler
TARGET = test
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
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
SOURCES = $(addprefix src/, $(SOURCE_FILES))
BUILD_DIR = build
BUILD_DIR = build/
OBJECTS = $(addprefix $(BUILD_DIR)/, $(SOURCE_FILES:.cpp=.o))
#OBJECTS = $(SOURCES:.cpp=.o)

FAST_TARGET = fasttest

SERVER_TARGET = server
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
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
SERVER_SOURCES = $(addprefix src/, $(SERVER_SOURCE_FILES))
SERVER_BUILD_DIR = serverbuild
SERVER_BUILD_DIR = serverbuild/
SERVER_OBJECTS = $(addprefix $(SERVER_BUILD_DIR)/, $(SERVER_SOURCE_FILES:.cpp=.o))
#SERVER_OBJECTS = $(SERVER_SOURCES:.cpp=.o)

Expand Down Expand Up @@ -57,13 +57,13 @@ SERVER_DESTPATH = bin/$(SERVER_TARGET)$(SUF)

# Build commands

all_linux all_win32: make_build_dir $(DESTPATH)
fast_linux: make_build_dir $(FAST_DESTPATH)
server_linux: make_server_build_dir $(SERVER_DESTPATH)
all_linux all_win32: $(BUILD_DIR) $(DESTPATH)
fast_linux: $(BUILD_DIR) $(FAST_DESTPATH)
server_linux: $(SERVER_BUILD_DIR) $(SERVER_DESTPATH)

make_build_dir:
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
make_server_build_dir:
$(SERVER_BUILD_DIR):
mkdir -p $(SERVER_BUILD_DIR)

$(DESTPATH): $(OBJECTS)
Expand Down
7 changes: 7 additions & 0 deletions minetest.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@
# 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

78 changes: 33 additions & 45 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ Client::Client(
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;
Expand Down Expand Up @@ -165,48 +162,29 @@ void Client::step(float dtime)
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);
}
}

Expand Down Expand Up @@ -1034,6 +1012,16 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)

} //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
{
Expand Down
5 changes: 2 additions & 3 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,8 @@ class Client : public con::PeerHandler

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;
Expand Down
17 changes: 15 additions & 2 deletions src/clientserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef CLIENTSERVER_HEADER
#define CLIENTSERVER_HEADER

#include "utility.h"

#define PROTOCOL_ID 0x4f457403

enum ToClientCommand
Expand Down Expand Up @@ -90,6 +92,12 @@ enum ToClientCommand
v3s16 blockpos
block objects
*/

TOCLIENT_TIME_OF_DAY = 0x29,
/*
u16 command
u16 time (0-23999)
*/
};

enum ToServerCommand
Expand Down Expand Up @@ -185,8 +193,13 @@ 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

60 changes: 60 additions & 0 deletions src/defaultsettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
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");
}

44 changes: 5 additions & 39 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ TODO: Check what goes wrong with caching map to disk (Kray)
TODO: Remove LazyMeshUpdater. It is not used as supposed.
TODO: Node cracking animation when digging
- TODO: A way to generate new textures by combining textures
- TODO: Mesh update to fetch cracked faces from the former
TODO: Add server unused sector deletion settings to settings
TODO: TOSERVER_LEAVE
Doing now:
======================================================================
TODO: Node cracking animation when digging
- TODO: A way to generate new textures by combining textures
- TODO: Mesh update to fetch cracked faces from the former
======================================================================
*/
Expand Down Expand Up @@ -298,41 +298,7 @@ bool g_viewing_range_all = false;

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();

/*
Random stuff
Expand Down
Loading

0 comments on commit 5a36956

Please sign in to comment.