Skip to content

Commit

Permalink
Fix computation of viewing range (in blocks) sent to server (minetest…
Browse files Browse the repository at this point in the history
…#4882)

Fixes minetest#4878

Also remove an artificial viewing range reduction that
(presumably) was added to compensate for miscomputed
viewing ranges, and that doesn't seem to be needed any
more (thanks to lhofhansl).
  • Loading branch information
Rogier-5 authored and est31 committed Dec 11, 2016
1 parent 2886f0c commit 6077207
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <IFileSystem.h>
#include "threading/mutex_auto_lock.h"
#include "util/auth.h"
Expand Down Expand Up @@ -939,7 +940,7 @@ void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *
u32 keyPressed = myplayer->keyPressed;
// scaled by 80, so that pi can fit into a u8
u8 fov = clientMap->getCameraFov() * 80;
u8 wanted_range = clientMap->getControl().wanted_range / MAP_BLOCKSIZE;
u8 wanted_range = std::ceil(clientMap->getControl().wanted_range / MAP_BLOCKSIZE);

v3s32 position(pf.X, pf.Y, pf.Z);
v3s32 speed(sf.X, sf.Y, sf.Z);
Expand All @@ -952,7 +953,7 @@ void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *
[12+12+4] s32 yaw*100
[12+12+4+4] u32 keyPressed
[12+12+4+4+4] u8 fov*80
[12+12+4+4+4+1] u8 wanted_range / MAP_BLOCKSIZE
[12+12+4+4+4+1] u8 ceil(wanted_range / MAP_BLOCKSIZE)
*/
*pkt << position << speed << pitch << yaw << keyPressed;
*pkt << fov << wanted_range;
Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4214,7 +4214,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
if (draw_control->range_all) {
runData->fog_range = 100000 * BS;
} else {
runData->fog_range = 0.9 * draw_control->wanted_range * BS;
runData->fog_range = draw_control->wanted_range * BS;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/network/networkprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ enum ToServerCommand
[2+12+12+4] s32 yaw*100
[2+12+12+4+4] u32 keyPressed
[2+12+12+4+4+1] u8 fov*80
[2+12+12+4+4+4+1] u8 wanted_range / MAP_BLOCKSIZE
[2+12+12+4+4+4+1] u8 ceil(wanted_range / MAP_BLOCKSIZE)
*/

TOSERVER_GOTBLOCKS = 0x24,
Expand Down

0 comments on commit 6077207

Please sign in to comment.