Skip to content

Commit

Permalink
Properly and efficiently use split utility headers
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron55 committed Jun 16, 2012
1 parent 1bc37d5 commit d0ea6f9
Show file tree
Hide file tree
Showing 73 changed files with 130 additions and 159 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ set(common_SRCS
mapsector.cpp
map.cpp
player.cpp
utility.cpp
test.cpp
sha1.cpp
base64.cpp
Expand Down
29 changes: 15 additions & 14 deletions src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gamedef.h"
#include "sound.h"
#include "event.h"
#include "util/numeric.h"

Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
IGameDef *gamedef):
Expand Down Expand Up @@ -234,17 +235,17 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,

#if 1
f32 bobknob = 1.2;
f32 bobtmp = sin(pow(bobfrac, bobknob) * PI);
//f32 bobtmp2 = cos(pow(bobfrac, bobknob) * PI);
f32 bobtmp = sin(pow(bobfrac, bobknob) * M_PI);
//f32 bobtmp2 = cos(pow(bobfrac, bobknob) * M_PI);

v3f bobvec = v3f(
0.3 * bobdir * sin(bobfrac * PI),
0.3 * bobdir * sin(bobfrac * M_PI),
-0.28 * bobtmp * bobtmp,
0.);

//rel_cam_pos += 0.2 * bobvec;
//rel_cam_target += 0.03 * bobvec;
//rel_cam_up.rotateXYBy(0.02 * bobdir * bobtmp * PI);
//rel_cam_up.rotateXYBy(0.02 * bobdir * bobtmp * M_PI);
float f = 1.0;
f *= g_settings->getFloat("view_bobbing_amount");
rel_cam_pos += bobvec * f;
Expand All @@ -253,10 +254,10 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
rel_cam_target.Z -= 0.005 * bobvec.Z * f;
//rel_cam_target.X -= 0.005 * bobvec.X * f;
//rel_cam_target.Y -= 0.005 * bobvec.Y * f;
rel_cam_up.rotateXYBy(-0.03 * bobdir * bobtmp * PI * f);
rel_cam_up.rotateXYBy(-0.03 * bobdir * bobtmp * M_PI * f);
#else
f32 angle_deg = 1 * bobdir * sin(bobfrac * PI);
f32 angle_rad = angle_deg * PI / 180;
f32 angle_deg = 1 * bobdir * sin(bobfrac * M_PI);
f32 angle_rad = angle_deg * M_PI / 180;
f32 r = 0.05;
v3f off = v3f(
r * sin(angle_rad),
Expand Down Expand Up @@ -289,7 +290,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,

// FOV and aspect ratio
m_aspect = (f32)screensize.X / (f32) screensize.Y;
m_fov_y = fov_degrees * PI / 180.0;
m_fov_y = fov_degrees * M_PI / 180.0;
// Increase vertical FOV on lower aspect ratios (<16:10)
m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect)));
// WTF is this? It can't be right
Expand Down Expand Up @@ -320,22 +321,22 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize,
if (m_digging_button != -1)
{
f32 digfrac = m_digging_anim;
wield_position.X -= 30 * sin(pow(digfrac, 0.8f) * PI);
wield_position.Y += 15 * sin(digfrac * 2 * PI);
wield_position.X -= 30 * sin(pow(digfrac, 0.8f) * M_PI);
wield_position.Y += 15 * sin(digfrac * 2 * M_PI);
wield_position.Z += 5 * digfrac;

// Euler angles are PURE EVIL, so why not use quaternions?
core::quaternion quat_begin(wield_rotation * core::DEGTORAD);
core::quaternion quat_end(v3f(90, -10, -130) * core::DEGTORAD);
core::quaternion quat_slerp;
quat_slerp.slerp(quat_begin, quat_end, sin(digfrac * PI));
quat_slerp.slerp(quat_begin, quat_end, sin(digfrac * M_PI));
quat_slerp.toEuler(wield_rotation);
wield_rotation *= core::RADTODEG;
}
else {
f32 bobfrac = my_modf(m_view_bobbing_anim);
wield_position.X -= sin(bobfrac*PI*2.0) * 3.0;
wield_position.Y += sin(my_modf(bobfrac*2.0)*PI) * 3.0;
wield_position.X -= sin(bobfrac*M_PI*2.0) * 3.0;
wield_position.Y += sin(my_modf(bobfrac*2.0)*M_PI) * 3.0;
}
m_wieldnode->setPosition(wield_position);
m_wieldnode->setRotation(wield_rotation);
Expand Down Expand Up @@ -538,7 +539,7 @@ void Camera::drawWieldedTool()
// Draw the wielded node (in a separate scene manager)
scene::ICameraSceneNode* cam = m_wieldmgr->getActiveCamera();
cam->setAspectRatio(m_cameranode->getAspectRatio());
cam->setFOV(72.0*PI/180.0);
cam->setFOV(72.0*M_PI/180.0);
cam->setNearValue(0.1);
cam->setFarValue(100);
m_wieldmgr->drawAll();
Expand Down
2 changes: 1 addition & 1 deletion src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "inventory.h"
#include "mesh.h"
#include "tile.h"
#include "utility.h"
#include "util/numeric.h"
#include <ICameraSceneNode.h>

class LocalPlayer;
Expand Down
3 changes: 2 additions & 1 deletion src/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "chat.h"
#include "debug.h"
#include "utility.h"
#include <cassert>
#include <cctype>
#include <sstream>
#include "util/string.h"
#include "util/numeric.h"

ChatBuffer::ChatBuffer(u32 scrollback):
m_scrollback(scrollback),
Expand Down
1 change: 0 additions & 1 deletion src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

#include "client.h"
#include "utility.h"
#include <iostream>
#include "clientserver.h"
#include "jmutexautolock.h"
Expand Down
2 changes: 1 addition & 1 deletion src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <set>
#include <vector>
#include "clientobject.h"
#include "utility.h" // For IntervalLimiter
#include "gamedef.h"
#include "inventorymanager.h"
#include "filesys.h"
#include "filecache.h"
#include "localplayer.h"
#include "util/pointedthing.h"

struct MeshMakeData;
class MapBlockMesh;
Expand Down
2 changes: 1 addition & 1 deletion src/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ClientMap::ClientMap(
m_control(control),
m_camera_position(0,0,0),
m_camera_direction(0,0,1),
m_camera_fov(PI)
m_camera_fov(M_PI)
{
m_camera_mutex.Init();
assert(m_camera_mutex.IsInitialized());
Expand Down
2 changes: 1 addition & 1 deletion src/clientserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef CLIENTSERVER_HEADER
#define CLIENTSERVER_HEADER

#include "utility.h"
#include "util/serialize.h"

/*
changes by PROTOCOL_VERSION:
Expand Down
12 changes: 12 additions & 0 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serialization.h"
#include "log.h"
#include "porting.h"
#include "util/serialize.h"
#include "util/numeric.h"
#include "util/string.h"

namespace con
{

static u16 readPeerId(u8 *packetdata)
{
return readU16(&packetdata[4]);
}
static u8 readChannel(u8 *packetdata)
{
return readU8(&packetdata[6]);
}

BufferedPacket makePacket(Address &address, u8 *data, u32 datasize,
u32 protocol_id, u16 sender_peer_id, u8 channel)
{
Expand Down
20 changes: 6 additions & 14 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef CONNECTION_HEADER
#define CONNECTION_HEADER

#include <iostream>
#include <fstream>
#include "debug.h"
#include "common_irrlicht.h"
#include "irrlichttypes.h"
#include "socket.h"
#include "utility.h"
#include "exceptions.h"
#include "constants.h"
#include "util/pointer.h"
#include "util/container.h"
#include "util/thread.h"
#include <iostream>
#include <fstream>

namespace con
{
Expand Down Expand Up @@ -107,15 +108,6 @@ class ProcessedSilentlyException : public BaseException
{}
};

inline u16 readPeerId(u8 *packetdata)
{
return readU16(&packetdata[4]);
}
inline u8 readChannel(u8 *packetdata)
{
return readU8(&packetdata[6]);
}

#define SEQNUM_MAX 65535
inline bool seqnum_higher(u16 higher, u16 lower)
{
Expand Down
2 changes: 0 additions & 2 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Some things here are legacy crap.
*/

#define PI 3.14159

/*
Connection
*/
Expand Down
8 changes: 5 additions & 3 deletions src/content_cao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clientobject.h"
#include "content_object.h"
#include "mesh.h"
#include "utility.h" // For IntervalLimiter
#include "itemdef.h"
#include "tool.h"
#include "content_cso.h"
#include "sound.h"
#include "nodedef.h"
#include "localplayer.h"
#include "util/numeric.h" // For IntervalLimiter
#include "util/serialize.h"

class Settings;
struct ToolCapabilities;

Expand Down Expand Up @@ -935,7 +937,7 @@ class GenericCAO : public ClientActiveObject
}
}
if(fabs(m_prop.automatic_rotate) > 0.001){
m_yaw += dtime * m_prop.automatic_rotate * 180 / PI;
m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI;
updateNodePos();
}
}
Expand All @@ -961,7 +963,7 @@ class GenericCAO : public ClientActiveObject
else if(cam_to_entity.Y < -0.75)
col += 4;
else{
float mob_dir = atan2(cam_to_entity.Z, cam_to_entity.X) / PI * 180.;
float mob_dir = atan2(cam_to_entity.Z, cam_to_entity.X) / M_PI * 180.;
float dir = mob_dir - m_yaw;
dir = wrapDegrees_180(dir);
//infostream<<"id="<<m_id<<" dir="<<dir<<std::endl;
Expand Down
3 changes: 3 additions & 0 deletions src/content_mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodedef.h"
#include "tile.h"
#include "gamedef.h"
#include "util/numeric.h"
#include "util/serialize.h"
#include "util/directiontables.h"

// Create a cuboid.
// collector - the MeshCollector for the resulting polygons
Expand Down
1 change: 0 additions & 1 deletion src/content_mapnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes.h"
#include "mapnode.h"
#include "nodedef.h"
#include "utility.h"
#include "nameidmapping.h"
#include <map>

Expand Down
4 changes: 3 additions & 1 deletion src/content_nodemeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_nodemeta.h"
#include "inventory.h"
#include "log.h"
#include "utility.h"
#include "util/serialize.h"
#include "util/string.h"
#include "constants.h" // MAP_BLOCKSIZE
#include <sstream>

#define NODEMETA_GENERIC 1
Expand Down
1 change: 1 addition & 0 deletions src/content_sao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "player.h"
#include "scriptapi.h"
#include "genericobject.h"
#include "util/serialize.h"

core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;

Expand Down
2 changes: 1 addition & 1 deletion src/craftdef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include <sstream>
#include <set>
#include "utility.h"
#include "gamedef.h"
#include "inventory.h"
#include "util/serialize.h"

// Check if input matches recipe
// Takes recipe groups into account
Expand Down
3 changes: 2 additions & 1 deletion src/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "player.h"
#include "map.h"
#include <ostream>
#include "utility.h"
#include "activeobject.h"
#include "util/container.h"
#include "util/numeric.h"

class Server;
class ServerEnvironment;
Expand Down
2 changes: 1 addition & 1 deletion src/filecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clientserver.h"
#include "log.h"
#include "filesys.h"
#include "utility.h"
#include "hex.h"
#include "sha1.h"
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>

bool FileCache::loadByPath(const std::string &path, std::ostream &os)
{
Expand Down
2 changes: 1 addition & 1 deletion src/genericobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

#include "genericobject.h"
#include "utility.h"
#include <sstream>
#include "util/serialize.h"

std::string gob_cmd_set_properties(const ObjectProperties &prop)
{
Expand Down
1 change: 0 additions & 1 deletion src/guiConfirmMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "common_irrlicht.h"
#include "modalMenu.h"
#include "utility.h"
#include <string>

struct ConfirmDest
Expand Down
2 changes: 1 addition & 1 deletion src/guiCreateWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include <IGUIListBox.h>

#include "gettext.h"
#include "util/string.h"

enum
{
Expand Down
1 change: 0 additions & 1 deletion src/guiCreateWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "common_irrlicht.h"
#include "modalMenu.h"
#include "utility.h"
#include <string>
#include "subgame.h"

Expand Down
1 change: 0 additions & 1 deletion src/guiDeathScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "common_irrlicht.h"
#include "modalMenu.h"
#include "utility.h"
#include <string>

class IRespawnInitiator
Expand Down
2 changes: 2 additions & 0 deletions src/guiInventoryMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <IGUIFont.h>
#include "log.h"
#include "tile.h" // ITextureSource
#include "util/string.h"
#include "util/numeric.h"

void drawItemStack(video::IVideoDriver *driver,
gui::IGUIFont *font,
Expand Down
1 change: 0 additions & 1 deletion src/guiInventoryMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common_irrlicht.h"
#include "inventory.h"
#include "inventorymanager.h"
#include "utility.h"
#include "modalMenu.h"

class IGameDef;
Expand Down
Loading

0 comments on commit d0ea6f9

Please sign in to comment.