Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into tcp_blocks_2

Conflicts:
	src/client.cpp
	src/clientserver.h
  • Loading branch information...
commit c101673bfb395170886f316effdbe0e54a200859 2 parents fc8a0f2 + 5c26972
@celeron55 authored
Showing with 1,999 additions and 472 deletions.
  1. +1 −1  CMakeLists.txt
  2. +2 −2 builtin/chatcommands.lua
  3. +5 −0 builtin/falling.lua
  4. +2 −0  builtin/misc_register.lua
  5. +20 −3 doc/lua_api.txt
  6. BIN  games/minimal/mods/default/textures/default_nc_back.png
  7. BIN  games/minimal/mods/default/textures/default_nc_front.png
  8. BIN  games/minimal/mods/default/textures/default_nc_rb.png
  9. BIN  games/minimal/mods/default/textures/default_nc_side.png
  10. +2 −2 minetest.conf.example
  11. +2 −0  src/CMakeLists.txt
  12. +6 −6 src/camera.cpp
  13. +46 −12 src/client.cpp
  14. +3 −0  src/client.h
  15. +9 −0 src/clientmap.cpp
  16. +1 −1  src/clientobject.cpp
  17. +7 −1 src/clientobject.h
  18. +31 −0 src/clientserver.cpp
  19. +21 −13 src/clientserver.h
  20. +623 −67 src/content_cao.cpp
  21. +0 −1  src/content_mapblock.cpp
  22. +337 −94 src/content_sao.cpp
  23. +40 −1 src/content_sao.h
  24. +6 −1 src/defaultsettings.cpp
  25. +12 −4 src/environment.cpp
  26. +5 −3 src/environment.h
  27. +16 −0 src/game.cpp
  28. +37 −0 src/genericobject.cpp
  29. +11 −2 src/genericobject.h
  30. +53 −9 src/guiFormSpecMenu.cpp
  31. +1 −0  src/guiFormSpecMenu.h
  32. +60 −0 src/guiMainMenu.cpp
  33. +4 −0 src/guiMainMenu.h
  34. +17 −1 src/localplayer.cpp
  35. +4 −50 src/localplayer.h
  36. +11 −3 src/main.cpp
  37. +2 −2 src/map.cpp
  38. +1 −0  src/mapblock.cpp
  39. +2 −2 src/mapblock_mesh.cpp
  40. +2 −1  src/mapgen.cpp
  41. +0 −3  src/mesh.cpp
  42. +114 −52 src/nodedef.cpp
  43. +2 −0  src/nodedef.h
  44. +74 −22 src/object_properties.cpp
  45. +4 −0 src/object_properties.h
  46. +66 −3 src/player.h
  47. +150 −1 src/scriptapi.cpp
  48. +38 −11 src/server.cpp
  49. +6 −0 src/serverobject.h
  50. +92 −0 src/staticobject.cpp
  51. +5 −69 src/staticobject.h
  52. +12 −28 src/tile.cpp
  53. +1 −1  src/util/pointer.h
  54. +33 −0 src/util/serialize.h
View
2  CMakeLists.txt
@@ -12,7 +12,7 @@ set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
# Also remember to set PROTOCOL_VERSION in clientserver.h when releasing
set(VERSION_MAJOR 0)
set(VERSION_MINOR 4)
-set(VERSION_PATCH 3)
+set(VERSION_PATCH 4)
if(VERSION_EXTRA)
set(VERSION_PATCH ${VERSION_PATCH}-${VERSION_EXTRA})
endif()
View
4 builtin/chatcommands.lua
@@ -215,8 +215,8 @@ minetest.register_chatcommand("clearpassword", {
privs = {password=true},
func = function(name, param)
toname = param
- if not toname then
- minetest.chat_send_player(toname, "Name field required")
+ if toname == "" then
+ minetest.chat_send_player(name, "Name field required")
return
end
minetest.set_player_password(toname, '')
View
5 builtin/falling.lua
@@ -111,6 +111,11 @@ function nodeupdate_single(p)
end
function nodeupdate(p)
+ -- Round p to prevent falling entities to get stuck
+ p.x = math.floor(p.x+0.5)
+ p.y = math.floor(p.y+0.5)
+ p.z = math.floor(p.z+0.5)
+
for x = -1,1 do
for y = -1,1 do
for z = -1,1 do
View
2  builtin/misc_register.lua
@@ -259,6 +259,7 @@ minetest.register_node(":air", {
diggable = false,
buildable_to = true,
air_equivalent = true,
+ drop = "",
groups = {not_in_creative_inventory=1},
})
@@ -274,6 +275,7 @@ minetest.register_node(":ignore", {
diggable = false,
buildable_to = true, -- A way to remove accidentally placed ignores
air_equivalent = true,
+ drop = "",
groups = {not_in_creative_inventory=1},
})
View
23 doc/lua_api.txt
@@ -1,4 +1,4 @@
-Minetest Lua Modding API Reference 0.4.0
+Minetest Lua Modding API Reference 0.4.4
==========================================
More information at http://c55.me/minetest/
@@ -694,6 +694,11 @@ image[<X>,<Y>;<W>,<H>;<texture name>]
^ Show an image
^ Position and size units are inventory slots
+background[<X>,<Y>;<W>,<H>;<texture name>]
+^ Use a background. Inventory rectangles are not drawn then.
+^ Position and size units are inventory slots
+^ Example for formspec 8x4 in 16x resolution: image shall be sized 8*16px x 4*16px
+
field[<X>,<Y>;<W>,<H>;<name>;<label>;<default>]
^ Textual field; will be sent to server when a button is clicked
^ x and y position the field relative to the top left of the menu
@@ -1098,6 +1103,10 @@ methods:
- get_wielded_item() -> ItemStack
- set_wielded_item(item): replaces the wielded item, returns true if successful
- set_armor_groups({group1=rating, group2=rating, ...})
+- set_animation({x=1,y=1}, frame_speed=15, frame_blend=0)
+- set_attach(parent, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
+- set_detach()
+- set_bone_position("", {x=0,y=0,z=0}, {x=0,y=0,z=0})
- set_properties(object property table)
LuaEntitySAO-only: (no-op for other objects)
- setvelocity({x=num, y=num, z=num})
@@ -1123,7 +1132,11 @@ Player-only: (no-op for other objects)
^ Redefine player's inventory form
^ Should usually be called in on_joinplayer
- get_inventory_formspec() -> formspec string
-
+- get_player_control(): returns table with player pressed keys
+ {jump=bool,right=bool,left=bool,LMB=bool,RMB=bool,sneak=bool,aux1=bool,down=bool,up=bool}
+- get_player_control_bits(): returns integer with bit packed player pressed keys
+ bit nr/meaning: 0/up ,1/down ,2/left ,3/right ,4/jump ,5/aux1 ,6/sneak ,7/LMB ,8/RMB
+
InvRef: Reference to an inventory
methods:
- is_empty(listname): return true if list is empty
@@ -1222,9 +1235,11 @@ Object Properties
physical = true,
weight = 5,
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
- visual = "cube"/"sprite"/"upright_sprite",
+ visual = "cube"/"sprite"/"upright_sprite"/"mesh",
visual_size = {x=1, y=1},
+ mesh = "model",
textures = {}, -- number of required textures depends on visual
+ colors = {}, -- number of required colors depends on visual
spritediv = {x=1, y=1},
initial_sprite_basepos = {x=0, y=0},
is_visible = true,
@@ -1347,6 +1362,8 @@ Node definition (register_node)
liquid_alternative_flowing = "", -- Flowing version of source liquid
liquid_alternative_source = "", -- Source version of flowing liquid
liquid_viscosity = 0, -- Higher viscosity = slower flow (max. 7)
+ liquid_renewable = true, -- Can new liquid source be created by placing
+ two or more sources nearly?
light_source = 0, -- Amount of light emitted by node
damage_per_second = 0, -- If player is inside node, this damage is caused
node_box = {type="regular"}, -- See "Node boxes"
View
BIN  games/minimal/mods/default/textures/default_nc_back.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  games/minimal/mods/default/textures/default_nc_front.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  games/minimal/mods/default/textures/default_nc_rb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  games/minimal/mods/default/textures/default_nc_side.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
4 minetest.conf.example
@@ -194,7 +194,7 @@
# To reduce lag, block transfers are slowed down when a player is building something.
# This determines how long they are slowed down after placing or removing a node.
#full_block_send_enable_min_time_from_building = 2.0
-# Length of a server tick in dedicated server
-#dedicated_server_step = 0.05
+# Length of a server tick and the interval at which objects are generally updated over network
+#dedicated_server_step = 0.1
# Can be set to true to disable shutting down on invalid world data
#ignore_world_load_errors = false
View
2  src/CMakeLists.txt
@@ -202,6 +202,8 @@ set(common_SRCS
sha1.cpp
base64.cpp
ban.cpp
+ clientserver.cpp
+ staticobject.cpp
util/serialize.cpp
util/directiontables.cpp
util/numeric.cpp
View
12 src/camera.cpp
@@ -189,7 +189,7 @@ void Camera::step(f32 dtime)
if (m_digging_button != -1)
{
- f32 offset = dtime * 3.5;
+ f32 offset = dtime * 4.5;
float m_digging_anim_was = m_digging_anim;
m_digging_anim += offset;
if (m_digging_anim >= 1)
@@ -336,13 +336,13 @@ 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) * M_PI);
- wield_position.Y += 15 * sin(digfrac * 2 * M_PI);
- wield_position.Z += 5 * digfrac;
-
+ wield_position.X -= 50 * sin(pow(digfrac, 0.8f) * M_PI);
+ wield_position.Y += 24 * sin(digfrac * 1.8 * M_PI);
+ wield_position.Z += 25 * 0.5;
+
// 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_end(v3f(80, 30, 100) * core::DEGTORAD);
core::quaternion quat_slerp;
quat_slerp.slerp(quat_begin, quat_end, sin(digfrac * M_PI));
quat_slerp.toEuler(wield_rotation);
View
58 src/client.cpp
@@ -41,6 +41,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sound.h"
#include "util/string.h"
#include "hex.h"
+#include "IMeshCache.h"
+#include "util/serialize.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@@ -266,6 +268,7 @@ Client::Client(
m_last_time_of_day_f(-1),
m_time_of_day_update_timer(0),
m_removed_sounds_check_timer(0),
+ m_recommended_send_interval(0.1),
m_dtime_avg(0.05)
{
m_packetcounter_timer = 0.0;
@@ -495,8 +498,9 @@ void Client::step(float dtime)
// [2] u8 SER_FMT_VER_HIGHEST
// [3] u8[20] player_name
// [23] u8[28] password (new in some version)
- // [51] u16 client network protocol version (new in some version)
- SharedBuffer<u8> data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2);
+ // [51] u16 minimum supported network protocol version (added sometime)
+ // [53] u16 maximum supported network protocol version (added later than the previous one)
+ SharedBuffer<u8> data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2+2);
writeU16(&data[0], TOSERVER_INIT);
writeU8(&data[2], SER_FMT_VER_HIGHEST);
@@ -509,8 +513,8 @@ void Client::step(float dtime)
memset((char*)&data[23], 0, PASSWORD_SIZE);
snprintf((char*)&data[23], PASSWORD_SIZE, "%s", m_password.c_str());
- // This should be incremented in each version
- writeU16(&data[51], PROTOCOL_VERSION);
+ writeU16(&data[51], CLIENT_PROTOCOL_VERSION_MIN);
+ writeU16(&data[53], CLIENT_PROTOCOL_VERSION_MAX);
// Send as unreliable
Send(0, data, false);
@@ -623,7 +627,7 @@ void Client::step(float dtime)
{
float &counter = m_playerpos_send_timer;
counter += dtime;
- if(counter >= 0.2)
+ if(counter >= m_recommended_send_interval)
{
counter = 0.0;
sendPlayerPos();
@@ -792,7 +796,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
if(name != "")
{
verbosestream<<"Client: Attempting to load image "
- <<"file \""<<filename<<"\""<<std::endl;
+ <<"file \""<<filename<<"\""<<std::endl;
io::IFileSystem *irrfs = m_device->getFileSystem();
video::IVideoDriver *vdrv = m_device->getVideoDriver();
@@ -826,11 +830,33 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
if(name != "")
{
verbosestream<<"Client: Attempting to load sound "
- <<"file \""<<filename<<"\""<<std::endl;
+ <<"file \""<<filename<<"\""<<std::endl;
m_sound->loadSoundData(name, data);
return true;
}
+ const char *model_ext[] = {
+ ".x", ".b3d", ".md2", ".obj",
+ NULL
+ };
+ name = removeStringEnd(filename, model_ext);
+ if(name != "")
+ {
+ verbosestream<<"Client: Storing model into Irrlicht: "
+ <<"\""<<filename<<"\""<<std::endl;
+
+ io::IFileSystem *irrfs = m_device->getFileSystem();
+ io::IReadFile *rfile = irrfs->createMemoryReadFile(
+ *data_rw, data_rw.getSize(), filename.c_str());
+ assert(rfile);
+
+ scene::ISceneManager *smgr = m_device->getSceneManager();
+ scene::IAnimatedMesh *mesh = smgr->getMesh(rfile);
+ smgr->getMeshCache()->addMesh(filename.c_str(), mesh);
+
+ return true;
+ }
+
errorstream<<"Client: Don't know how to load file \""
<<filename<<"\""<<std::endl;
return false;
@@ -968,6 +994,14 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
m_map_seed = readU64(&data[2+1+6]);
infostream<<"Client: received map seed: "<<m_map_seed<<std::endl;
}
+
+ if(datasize >= 2+1+6+8+4)
+ {
+ // Get map seed
+ m_recommended_send_interval = readF1000(&data[2+1+6+8]);
+ infostream<<"Client: received recommended send interval "
+ <<m_recommended_send_interval<<std::endl;
+ }
// Reply to server
u32 replysize = 2;
@@ -1926,7 +1960,7 @@ void Client::sendPlayerPos()
v3s32 speed(sf.X*100, sf.Y*100, sf.Z*100);
s32 pitch = myplayer->getPitch() * 100;
s32 yaw = myplayer->getYaw() * 100;
-
+ u32 keyPressed=myplayer->keyPressed;
/*
Format:
[0] u16 command
@@ -1934,15 +1968,15 @@ void Client::sendPlayerPos()
[2+12] v3s32 speed*100
[2+12+12] s32 pitch*100
[2+12+12+4] s32 yaw*100
+ [2+12+12+4+4] u32 keyPressed
*/
-
- SharedBuffer<u8> data(2+12+12+4+4);
+ SharedBuffer<u8> data(2+12+12+4+4+4);
writeU16(&data[0], TOSERVER_PLAYERPOS);
writeV3S32(&data[2], position);
writeV3S32(&data[2+12], speed);
writeS32(&data[2+12+12], pitch);
- writeS32(&data[2+12+12+4], yaw);
-
+ writeS32(&data[2+12+12+4], yaw);
+ writeU32(&data[2+12+12+4+4], keyPressed);
// Send as unreliable
Send(0, data, false);
}
View
3  src/client.h
@@ -401,6 +401,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
float m_last_time_of_day_f;
float m_time_of_day_update_timer;
+ // An interval for generally sending object positions and stuff
+ float m_recommended_send_interval;
+
// Sounds
float m_removed_sounds_check_timer;
// Mapping from server sound ids to our sound ids
View
9 src/clientmap.cpp
@@ -438,6 +438,10 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
m_last_drawn_sectors.clear();
}
+ bool use_trilinear_filter = g_settings->getBool("trilinear_filter");
+ bool use_bilinear_filter = g_settings->getBool("bilinear_filter");
+ bool use_anisotropic_filter = g_settings->getBool("anisotropic_filter");
+
/*
Get time for measuring timeout.
@@ -569,6 +573,11 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
for(u32 i=0; i<c; i++)
{
scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
+
+ buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
+
const video::SMaterial& material = buf->getMaterial();
video::IMaterialRenderer* rnd =
driver->getMaterialRenderer(material.MaterialType);
View
2  src/clientobject.cpp
@@ -36,7 +36,7 @@ ClientActiveObject::ClientActiveObject(u16 id, IGameDef *gamedef,
ClientActiveObject::~ClientActiveObject()
{
- removeFromScene();
+ removeFromScene(true);
}
ClientActiveObject* ClientActiveObject::create(u8 type, IGameDef *gamedef,
View
8 src/clientobject.h
@@ -49,13 +49,19 @@ class ClientActiveObject : public ActiveObject
virtual void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
IrrlichtDevice *irr){}
- virtual void removeFromScene(){}
+ virtual void removeFromScene(bool permanent){}
// 0 <= light_at_pos <= LIGHT_SUN
virtual void updateLight(u8 light_at_pos){}
virtual v3s16 getLightPosition(){return v3s16(0,0,0);}
virtual core::aabbox3d<f32>* getSelectionBox(){return NULL;}
virtual core::aabbox3d<f32>* getCollisionBox(){return NULL;}
virtual v3f getPosition(){return v3f(0,0,0);}
+ virtual scene::IMeshSceneNode *getMeshSceneNode(){return NULL;}
+ virtual scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode(){return NULL;}
+ virtual scene::IBillboardSceneNode *getSpriteSceneNode(){return NULL;}
+ virtual bool isPlayer(){return false;}
+ virtual bool isLocalPlayer(){return false;}
+ virtual void setAttachments(){}
virtual bool doShowSelectionBox(){return true;}
// Step object in time
View
31 src/clientserver.cpp
@@ -0,0 +1,31 @@
+/*
+Minetest-c55
+Copyright (C) 2010-2012 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 Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser 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 "clientserver.h"
+#include "util/serialize.h"
+
+SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed)
+{
+ SharedBuffer<u8> data(2+2+4);
+ writeU16(&data[0], TOCLIENT_TIME_OF_DAY);
+ writeU16(&data[2], time);
+ writeF1000(&data[4], time_speed);
+ return data;
+}
+
View
34 src/clientserver.h
@@ -1,6 +1,6 @@
/*
Minetest-c55
-Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2010-2012 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 Lesser General Public License as published by
@@ -20,7 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef CLIENTSERVER_HEADER
#define CLIENTSERVER_HEADER
-#include "util/serialize.h"
+#include "util/pointer.h"
+
+SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed);
/*
changes by PROTOCOL_VERSION:
@@ -68,12 +70,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
PROTOCOL_VERSION 13:
InventoryList field "Width" (deserialization fails with old versions)
PROTOCOL_VERSION 14:
+ Added transfer of player pressed keys to the server
+ Added new messages for mesh and bone animation, as well as attachments
+ GENERIC_CMD_SET_ANIMATION
+ GENERIC_CMD_SET_BONE_POSITION
+ GENERIC_CMD_SET_ATTACHMENT
+ PROTOCOL_VERSION 15:
TOSERVER_REQUEST_BLOCKS
Versioned block data
*/
-#define PROTOCOL_VERSION 14
+// Server always only supports one version
+#define SERVER_PROTOCOL_VERSION 15
+
+// Client can support older versions too
+#define CLIENT_PROTOCOL_VERSION_MIN 15
+#define CLIENT_PROTOCOL_VERSION_MAX SERVER_PROTOCOL_VERSION
+// Constant that differentiates the protocol from random data and other protocols
#define PROTOCOL_ID 0x4f457403
#define PASSWORD_SIZE 28 // Maximum password length. Allows for
@@ -92,6 +106,7 @@ enum ToClientCommand
[2] u8 deployed version
[3] v3s16 player's position + v3f(0,BS/2,0) floatToInt'd
[12] u64 map seed (new as of 2011-02-27)
+ [20] f1000 recommended send interval (in seconds) (new as of 14)
NOTE: The position in here is deprecated; position is
explicitly sent afterwards
@@ -354,7 +369,8 @@ enum ToServerCommand
[2] u8 SER_FMT_VER_HIGHEST
[3] u8[20] player_name
[23] u8[28] password (new in some version)
- [51] u16 client network protocol version (new in some version)
+ [51] u16 minimum supported network protocol version (added sometime)
+ [53] u16 maximum supported network protocol version (added later than the previous one)
*/
TOSERVER_INIT2 = 0x11,
@@ -386,6 +402,7 @@ enum ToServerCommand
[2+12] v3s32 speed*100
[2+12+12] s32 pitch*100
[2+12+12+4] s32 yaw*100
+ [2+12+12+4+4] u32 keyPressed
*/
TOSERVER_GOTBLOCKS = 0x24, // Obsolete
@@ -571,14 +588,5 @@ enum ToServerCommand
};
-inline SharedBuffer<u8> makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed)
-{
- SharedBuffer<u8> data(2+2+4);
- writeU16(&data[0], TOCLIENT_TIME_OF_DAY);
- writeU16(&data[2], time);
- writeF1000(&data[4], time_speed);
- return data;
-}
-
#endif
View
690 src/content_cao.cpp
@@ -40,7 +40,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/serialize.h"
#include "util/mathconstants.h"
#include "map.h"
+#include "main.h" // g_settings
#include <IMeshManipulator.h>
+#include <IAnimatedMeshSceneNode.h>
+#include <IBoneSceneNode.h>
class Settings;
struct ToolCapabilities;
@@ -552,7 +555,8 @@ class GenericCAO : public ClientActiveObject
// Only set at initialization
std::string m_name;
bool m_is_player;
- bool m_is_local_player; // determined locally
+ bool m_is_local_player;
+ int m_id;
// Property-ish things
ObjectProperties m_prop;
//
@@ -560,6 +564,7 @@ class GenericCAO : public ClientActiveObject
IrrlichtDevice *m_irr;
core::aabbox3d<f32> m_selection_box;
scene::IMeshSceneNode *m_meshnode;
+ scene::IAnimatedMeshSceneNode *m_animated_meshnode;
scene::IBillboardSceneNode *m_spritenode;
scene::ITextSceneNode* m_textnode;
v3f m_position;
@@ -573,6 +578,14 @@ class GenericCAO : public ClientActiveObject
v2s16 m_tx_basepos;
bool m_initial_tx_basepos_set;
bool m_tx_select_horiz_by_yawpitch;
+ v2f m_animation_range;
+ int m_animation_speed;
+ int m_animation_blend;
+ std::map<std::string, core::vector2d<v3f> > m_bone_position; // stores position and rotation for each bone name
+ std::string m_attachment_bone;
+ v3f m_attachment_position;
+ v3f m_attachment_rotation;
+ bool m_attached_to_local;
int m_anim_frame;
int m_anim_num_frames;
float m_anim_framelength;
@@ -582,6 +595,7 @@ class GenericCAO : public ClientActiveObject
bool m_visuals_expired;
float m_step_distance_counter;
u8 m_last_light;
+ bool m_is_visible;
public:
GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
@@ -589,11 +603,13 @@ class GenericCAO : public ClientActiveObject
//
m_is_player(false),
m_is_local_player(false),
+ m_id(0),
//
m_smgr(NULL),
m_irr(NULL),
m_selection_box(-BS/3.,-BS/3.,-BS/3., BS/3.,BS/3.,BS/3.),
m_meshnode(NULL),
+ m_animated_meshnode(NULL),
m_spritenode(NULL),
m_textnode(NULL),
m_position(v3f(0,10*BS,0)),
@@ -605,6 +621,14 @@ class GenericCAO : public ClientActiveObject
m_tx_basepos(0,0),
m_initial_tx_basepos_set(false),
m_tx_select_horiz_by_yawpitch(false),
+ m_animation_range(v2f(0,0)),
+ m_animation_speed(15),
+ m_animation_blend(0),
+ m_bone_position(std::map<std::string, core::vector2d<v3f> >()),
+ m_attachment_bone(""),
+ m_attachment_position(v3f(0,0,0)),
+ m_attachment_rotation(v3f(0,0,0)),
+ m_attached_to_local(false),
m_anim_frame(0),
m_anim_num_frames(1),
m_anim_framelength(0.2),
@@ -612,7 +636,8 @@ class GenericCAO : public ClientActiveObject
m_reset_textures_timer(-1),
m_visuals_expired(false),
m_step_distance_counter(0),
- m_last_light(255)
+ m_last_light(255),
+ m_is_visible(false)
{
if(gamedef == NULL)
ClientActiveObject::registerType(getType(), create);
@@ -622,21 +647,36 @@ class GenericCAO : public ClientActiveObject
{
infostream<<"GenericCAO: Got init data"<<std::endl;
std::istringstream is(data, std::ios::binary);
+ int num_messages = 0;
// version
u8 version = readU8(is);
// check version
- if(version != 0){
+ if(version == 1) // In PROTOCOL_VERSION 14
+ {
+ m_name = deSerializeString(is);
+ m_is_player = readU8(is);
+ m_id = readS16(is);
+ m_position = readV3F1000(is);
+ m_yaw = readF1000(is);
+ m_hp = readS16(is);
+ num_messages = readU8(is);
+ }
+ else if(version == 0) // In PROTOCOL_VERSION 13
+ {
+ m_name = deSerializeString(is);
+ m_is_player = readU8(is);
+ m_position = readV3F1000(is);
+ m_yaw = readF1000(is);
+ m_hp = readS16(is);
+ num_messages = readU8(is);
+ }
+ else
+ {
errorstream<<"GenericCAO: Unsupported init data version"
<<std::endl;
return;
}
- m_name = deSerializeString(is);
- m_is_player = readU8(is);
- m_position = readV3F1000(is);
- m_yaw = readF1000(is);
- m_hp = readS16(is);
-
- int num_messages = readU8(is);
+
for(int i=0; i<num_messages; i++){
std::string message = deSerializeLongString(is);
processMessage(message);
@@ -668,21 +708,113 @@ class GenericCAO : public ClientActiveObject
}
core::aabbox3d<f32>* getSelectionBox()
{
- if(!m_prop.is_visible || m_is_local_player)
+ if(!m_prop.is_visible || !m_is_visible || m_is_local_player || getParent() != NULL)
return NULL;
return &m_selection_box;
}
v3f getPosition()
{
+ if(getParent() != NULL){
+ if(m_meshnode)
+ return m_meshnode->getAbsolutePosition();
+ if(m_animated_meshnode)
+ return m_animated_meshnode->getAbsolutePosition();
+ if(m_spritenode)
+ return m_spritenode->getAbsolutePosition();
+ return m_position;
+ }
return pos_translator.vect_show;
}
- void removeFromScene()
+ scene::IMeshSceneNode *getMeshSceneNode()
+ {
+ if(m_meshnode)
+ return m_meshnode;
+ return NULL;
+ }
+
+ scene::IAnimatedMeshSceneNode *getAnimatedMeshSceneNode()
+ {
+ if(m_animated_meshnode)
+ return m_animated_meshnode;
+ return NULL;
+ }
+
+ scene::IBillboardSceneNode *getSpriteSceneNode()
+ {
+ if(m_spritenode)
+ return m_spritenode;
+ return NULL;
+ }
+
+ bool isPlayer()
+ {
+ return m_is_player;
+ }
+
+ bool isLocalPlayer()
+ {
+ return m_is_local_player;
+ }
+
+ void setAttachments()
+ {
+ updateAttachments();
+ }
+
+ ClientActiveObject *getParent()
{
+ ClientActiveObject *obj = NULL;
+ for(std::vector<core::vector2d<int> >::const_iterator cii = m_env->attachment_list.begin(); cii != m_env->attachment_list.end(); cii++)
+ {
+ if(cii->X == getId()){ // This ID is our child
+ if(cii->Y > 0){ // A parent ID exists for our child
+ if(cii->X != cii->Y){ // The parent and child ID are not the same
+ obj = m_env->getActiveObject(cii->Y);
+ }
+ }
+ break;
+ }
+ }
+ if(obj)
+ return obj;
+ return NULL;
+ }
+
+ void removeFromScene(bool permanent)
+ {
+ if(permanent) // Should be true when removing the object permanently and false when refreshing (eg: updating visuals)
+ {
+ // Detach this object's children
+ for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
+ {
+ if(ii->Y == getId()) // Is a child of our object
+ {
+ ii->Y = 0;
+ ClientActiveObject *obj = m_env->getActiveObject(ii->X); // Get the object of the child
+ if(obj)
+ obj->setAttachments();
+ }
+ }
+ // Delete this object from the attachments list
+ for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
+ {
+ if(ii->X == getId()) // Is our object
+ {
+ m_env->attachment_list.erase(ii);
+ break;
+ }
+ }
+ }
+
if(m_meshnode){
m_meshnode->remove();
m_meshnode = NULL;
}
+ if(m_animated_meshnode){
+ m_animated_meshnode->remove();
+ m_animated_meshnode = NULL;
+ }
if(m_spritenode){
m_spritenode->remove();
m_spritenode = NULL;
@@ -695,7 +827,7 @@ class GenericCAO : public ClientActiveObject
m_smgr = smgr;
m_irr = irr;
- if(m_meshnode != NULL || m_spritenode != NULL)
+ if(m_meshnode != NULL || m_animated_meshnode != NULL || m_spritenode != NULL)
return;
m_visuals_expired = false;
@@ -791,7 +923,34 @@ class GenericCAO : public ClientActiveObject
m_prop.visual_size.X));
u8 li = m_last_light;
setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
- } else if(m_prop.visual == "wielditem"){
+
+ m_meshnode->setMaterialFlag(video::EMF_LIGHTING, false);
+ m_meshnode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
+ m_meshnode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
+ m_meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
+ }
+ else if(m_prop.visual == "mesh"){
+ infostream<<"GenericCAO::addToScene(): mesh"<<std::endl;
+ scene::IAnimatedMesh *mesh = smgr->getMesh(m_prop.mesh.c_str());
+ if(mesh)
+ {
+ m_animated_meshnode = smgr->addAnimatedMeshSceneNode(mesh, NULL);
+ m_animated_meshnode->animateJoints(); // Needed for some animations
+ m_animated_meshnode->setScale(v3f(m_prop.visual_size.X,
+ m_prop.visual_size.Y,
+ m_prop.visual_size.X));
+ u8 li = m_last_light;
+ setMeshColor(m_animated_meshnode->getMesh(), video::SColor(255,li,li,li));
+
+ m_animated_meshnode->setMaterialFlag(video::EMF_LIGHTING, false);
+ m_animated_meshnode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
+ m_animated_meshnode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
+ m_animated_meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
+ }
+ else
+ errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl;
+ }
+ else if(m_prop.visual == "wielditem"){
infostream<<"GenericCAO::addToScene(): node"<<std::endl;
infostream<<"textures: "<<m_prop.textures.size()<<std::endl;
if(m_prop.textures.size() >= 1){
@@ -823,6 +982,8 @@ class GenericCAO : public ClientActiveObject
scene::ISceneNode *node = NULL;
if(m_spritenode)
node = m_spritenode;
+ else if(m_animated_meshnode)
+ node = m_animated_meshnode;
else if(m_meshnode)
node = m_meshnode;
if(node && m_is_player && !m_is_local_player){
@@ -833,8 +994,11 @@ class GenericCAO : public ClientActiveObject
wname.c_str(), video::SColor(255,255,255,255), node);
m_textnode->setPosition(v3f(0, BS*1.1, 0));
}
-
+
updateNodePos();
+ updateAnimation();
+ updateBonePosition();
+ updateAttachments();
}
void expireVisuals()
@@ -844,19 +1008,16 @@ class GenericCAO : public ClientActiveObject
void updateLight(u8 light_at_pos)
{
- bool is_visible = (m_hp != 0);
u8 li = decode_light(light_at_pos);
if(li != m_last_light){
m_last_light = li;
video::SColor color(255,li,li,li);
- if(m_meshnode){
+ if(m_meshnode)
setMeshColor(m_meshnode->getMesh(), color);
- m_meshnode->setVisible(is_visible);
- }
- if(m_spritenode){
+ if(m_animated_meshnode)
+ setMeshColor(m_animated_meshnode->getMesh(), color);
+ if(m_spritenode)
m_spritenode->setColor(color);
- m_spritenode->setVisible(is_visible);
- }
}
}
@@ -867,12 +1028,21 @@ class GenericCAO : public ClientActiveObject
void updateNodePos()
{
+ if(getParent() != NULL)
+ return;
+
if(m_meshnode){
m_meshnode->setPosition(pos_translator.vect_show);
v3f rot = m_meshnode->getRotation();
rot.Y = -m_yaw;
m_meshnode->setRotation(rot);
}
+ if(m_animated_meshnode){
+ m_animated_meshnode->setPosition(pos_translator.vect_show);
+ v3f rot = m_animated_meshnode->getRotation();
+ rot.Y = -m_yaw;
+ m_animated_meshnode->setRotation(rot);
+ }
if(m_spritenode){
m_spritenode->setPosition(pos_translator.vect_show);
}
@@ -880,56 +1050,116 @@ class GenericCAO : public ClientActiveObject
void step(float dtime, ClientEnvironment *env)
{
- v3f lastpos = pos_translator.vect_show;
-
if(m_visuals_expired && m_smgr && m_irr){
m_visuals_expired = false;
- removeFromScene();
+
+ // Attachments, part 1: All attached objects must be unparented first, or Irrlicht causes a segmentation fault
+ for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
+ {
+ if(ii->Y == getId()) // This is a child of our parent
+ {
+ ClientActiveObject *obj = m_env->getActiveObject(ii->X); // Get the object of the child
+ if(obj)
+ {
+ scene::IMeshSceneNode *m_child_meshnode = obj->getMeshSceneNode();
+ scene::IAnimatedMeshSceneNode *m_child_animated_meshnode = obj->getAnimatedMeshSceneNode();
+ scene::IBillboardSceneNode *m_child_spritenode = obj->getSpriteSceneNode();
+ if(m_child_meshnode)
+ m_child_meshnode->setParent(m_smgr->getRootSceneNode());
+ if(m_child_animated_meshnode)
+ m_child_animated_meshnode->setParent(m_smgr->getRootSceneNode());
+ if(m_child_spritenode)
+ m_child_spritenode->setParent(m_smgr->getRootSceneNode());
+ }
+ }
+ }
+
+ removeFromScene(false);
addToScene(m_smgr, m_gamedef->tsrc(), m_irr);
+
+ // Attachments, part 2: Now that the parent has been refreshed, put its attachments back
+ for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
+ {
+ if(ii->Y == getId()) // This is a child of our parent
+ {
+ ClientActiveObject *obj = m_env->getActiveObject(ii->X); // Get the object of the child
+ if(obj)
+ obj->setAttachments();
+ }
+ }
}
- if(m_prop.physical){
- core::aabbox3d<f32> box = m_prop.collisionbox;
- box.MinEdge *= BS;
- box.MaxEdge *= BS;
- collisionMoveResult moveresult;
- f32 pos_max_d = BS*0.125; // Distance per iteration
- f32 stepheight = 0;
- v3f p_pos = m_position;
- v3f p_velocity = m_velocity;
- v3f p_acceleration = m_acceleration;
- IGameDef *gamedef = env->getGameDef();
- moveresult = collisionMoveSimple(&env->getMap(), gamedef,
- pos_max_d, box, stepheight, dtime,
- p_pos, p_velocity, p_acceleration);
- // Apply results
- m_position = p_pos;
- m_velocity = p_velocity;
- m_acceleration = p_acceleration;
-
- bool is_end_position = moveresult.collides;
- pos_translator.update(m_position, is_end_position, dtime);
- pos_translator.translate(dtime);
- updateNodePos();
- } else {
- m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
- m_velocity += dtime * m_acceleration;
- pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
- pos_translator.translate(dtime);
- updateNodePos();
+ // Make sure m_is_visible is always applied
+ if(m_meshnode)
+ m_meshnode->setVisible(m_is_visible);
+ if(m_animated_meshnode)
+ m_animated_meshnode->setVisible(m_is_visible);
+ if(m_spritenode)
+ m_spritenode->setVisible(m_is_visible);
+ if(m_textnode)
+ m_textnode->setVisible(m_is_visible);
+
+ if(getParent() != NULL) // Attachments should be glued to their parent by Irrlicht
+ {
+ // Set these for later
+ m_position = getPosition();
+ m_velocity = v3f(0,0,0);
+ m_acceleration = v3f(0,0,0);
+ pos_translator.vect_show = m_position;
+
+ if(m_is_local_player) // Update local player attachment position
+ {
+ LocalPlayer *player = m_env->getLocalPlayer();
+ player->overridePosition = getParent()->getPosition();
+ }
}
+ else
+ {
+ v3f lastpos = pos_translator.vect_show;
+
+ if(m_prop.physical){
+ core::aabbox3d<f32> box = m_prop.collisionbox;
+ box.MinEdge *= BS;
+ box.MaxEdge *= BS;
+ collisionMoveResult moveresult;
+ f32 pos_max_d = BS*0.125; // Distance per iteration
+ f32 stepheight = 0;
+ v3f p_pos = m_position;
+ v3f p_velocity = m_velocity;
+ v3f p_acceleration = m_acceleration;
+ IGameDef *gamedef = env->getGameDef();
+ moveresult = collisionMoveSimple(&env->getMap(), gamedef,
+ pos_max_d, box, stepheight, dtime,
+ p_pos, p_velocity, p_acceleration);
+ // Apply results
+ m_position = p_pos;
+ m_velocity = p_velocity;
+ m_acceleration = p_acceleration;
+
+ bool is_end_position = moveresult.collides;
+ pos_translator.update(m_position, is_end_position, dtime);
+ pos_translator.translate(dtime);
+ updateNodePos();
+ } else {
+ m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
+ m_velocity += dtime * m_acceleration;
+ pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
+ pos_translator.translate(dtime);
+ updateNodePos();
+ }
- float moved = lastpos.getDistanceFrom(pos_translator.vect_show);
- m_step_distance_counter += moved;
- if(m_step_distance_counter > 1.5*BS){
- m_step_distance_counter = 0;
- if(!m_is_local_player && m_prop.makes_footstep_sound){
- INodeDefManager *ndef = m_gamedef->ndef();
- v3s16 p = floatToInt(getPosition() + v3f(0,
- (m_prop.collisionbox.MinEdge.Y-0.5)*BS, 0), BS);
- MapNode n = m_env->getMap().getNodeNoEx(p);
- SimpleSoundSpec spec = ndef->get(n).sound_footstep;
- m_gamedef->sound()->playSoundAt(spec, false, getPosition());
+ float moved = lastpos.getDistanceFrom(pos_translator.vect_show);
+ m_step_distance_counter += moved;
+ if(m_step_distance_counter > 1.5*BS){
+ m_step_distance_counter = 0;
+ if(!m_is_local_player && m_prop.makes_footstep_sound){
+ INodeDefManager *ndef = m_gamedef->ndef();
+ v3s16 p = floatToInt(getPosition() + v3f(0,
+ (m_prop.collisionbox.MinEdge.Y-0.5)*BS, 0), BS);
+ MapNode n = m_env->getMap().getNodeNoEx(p);
+ SimpleSoundSpec spec = ndef->get(n).sound_footstep;
+ m_gamedef->sound()->playSoundAt(spec, false, getPosition());
+ }
}
}
@@ -950,7 +1180,7 @@ class GenericCAO : public ClientActiveObject
updateTextures("");
}
}
- if(fabs(m_prop.automatic_rotate) > 0.001){
+ if(getParent() == NULL && fabs(m_prop.automatic_rotate) > 0.001){
m_yaw += dtime * m_prop.automatic_rotate * 180 / M_PI;
updateNodePos();
}
@@ -1008,6 +1238,10 @@ class GenericCAO : public ClientActiveObject
{
ITextureSource *tsrc = m_gamedef->tsrc();
+ bool use_trilinear_filter = g_settings->getBool("trilinear_filter");
+ bool use_bilinear_filter = g_settings->getBool("bilinear_filter");
+ bool use_anisotropic_filter = g_settings->getBool("anisotropic_filter");
+
if(m_spritenode)
{
if(m_prop.visual == "sprite")
@@ -1018,6 +1252,58 @@ class GenericCAO : public ClientActiveObject
texturestring += mod;
m_spritenode->setMaterialTexture(0,
tsrc->getTextureRaw(texturestring));
+
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ if(m_prop.colors.size() >= 1)
+ {
+ m_spritenode->getMaterial(0).AmbientColor = m_prop.colors[0];
+ m_spritenode->getMaterial(0).DiffuseColor = m_prop.colors[0];
+ m_spritenode->getMaterial(0).SpecularColor = m_prop.colors[0];
+ }
+
+ m_spritenode->getMaterial(0).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ m_spritenode->getMaterial(0).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ m_spritenode->getMaterial(0).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
+ }
+ }
+ if(m_animated_meshnode)
+ {
+ if(m_prop.visual == "mesh")
+ {
+ for (u32 i = 0; i < m_prop.textures.size() && i < m_animated_meshnode->getMaterialCount(); ++i)
+ {
+ std::string texturestring = m_prop.textures[i];
+ if(texturestring == "")
+ continue; // Empty texture string means don't modify that material
+ texturestring += mod;
+ video::ITexture* texture = tsrc->getTextureRaw(texturestring);
+ if(!texture)
+ {
+ errorstream<<"GenericCAO::updateTextures(): Could not load texture "<<texturestring<<std::endl;
+ continue;
+ }
+
+ // Set material flags and texture
+ m_animated_meshnode->setMaterialTexture(i, texture);
+ video::SMaterial& material = m_animated_meshnode->getMaterial(i);
+ material.setFlag(video::EMF_LIGHTING, false);
+ material.setFlag(video::EMF_BILINEAR_FILTER, false);
+
+ m_animated_meshnode->getMaterial(i).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ m_animated_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ m_animated_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
+ }
+ for (u32 i = 0; i < m_prop.colors.size() && i < m_animated_meshnode->getMaterialCount(); ++i)
+ {
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ m_animated_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
+ m_animated_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
+ m_animated_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
+ }
}
}
if(m_meshnode)
@@ -1044,6 +1330,20 @@ class GenericCAO : public ClientActiveObject
material.setTexture(0, atlas);
material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
+
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ if(m_prop.colors.size() > i)
+ {
+ m_meshnode->getMaterial(i).AmbientColor = m_prop.colors[i];
+ m_meshnode->getMaterial(i).DiffuseColor = m_prop.colors[i];
+ m_meshnode->getMaterial(i).SpecularColor = m_prop.colors[i];
+ }
+
+ m_meshnode->getMaterial(i).setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ m_meshnode->getMaterial(i).setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ m_meshnode->getMaterial(i).setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
}
}
else if(m_prop.visual == "upright_sprite")
@@ -1057,6 +1357,20 @@ class GenericCAO : public ClientActiveObject
scene::IMeshBuffer *buf = mesh->getMeshBuffer(0);
buf->getMaterial().setTexture(0,
tsrc->getTextureRaw(tname));
+
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ if(m_prop.colors.size() >= 1)
+ {
+ buf->getMaterial().AmbientColor = m_prop.colors[0];
+ buf->getMaterial().DiffuseColor = m_prop.colors[0];
+ buf->getMaterial().SpecularColor = m_prop.colors[0];
+ }
+
+ buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
}
{
std::string tname = "unknown_object.png";
@@ -1068,11 +1382,213 @@ class GenericCAO : public ClientActiveObject
scene::IMeshBuffer *buf = mesh->getMeshBuffer(1);
buf->getMaterial().setTexture(0,
tsrc->getTextureRaw(tname));
+
+ // This allows setting per-material colors. However, until a real lighting
+ // system is added, the code below will have no effect. Once MineTest
+ // has directional lighting, it should work automatically.
+ if(m_prop.colors.size() >= 2)
+ {
+ buf->getMaterial().AmbientColor = m_prop.colors[1];
+ buf->getMaterial().DiffuseColor = m_prop.colors[1];
+ buf->getMaterial().SpecularColor = m_prop.colors[1];
+ }
+ else if(m_prop.colors.size() >= 1)
+ {
+ buf->getMaterial().AmbientColor = m_prop.colors[0];
+ buf->getMaterial().DiffuseColor = m_prop.colors[0];
+ buf->getMaterial().SpecularColor = m_prop.colors[0];
+ }
+
+ buf->getMaterial().setFlag(video::EMF_TRILINEAR_FILTER, use_trilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, use_bilinear_filter);
+ buf->getMaterial().setFlag(video::EMF_ANISOTROPIC_FILTER, use_anisotropic_filter);
}
}
}
}
+ void updateAnimation()
+ {
+ if(m_animated_meshnode == NULL)
+ return;
+
+ m_animated_meshnode->setFrameLoop((int)m_animation_range.X, (int)m_animation_range.Y);
+ m_animated_meshnode->setAnimationSpeed(m_animation_speed);
+ m_animated_meshnode->setTransitionTime(m_animation_blend);
+ }
+
+ void updateBonePosition()
+ {
+ if(!m_bone_position.size() || m_animated_meshnode == NULL)
+ return;
+
+ m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
+ for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
+ std::string bone_name = (*ii).first;
+ v3f bone_pos = (*ii).second.X;
+ v3f bone_rot = (*ii).second.Y;
+ irr::scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str());
+ if(bone)
+ {
+ bone->setPosition(bone_pos);
+ bone->setRotation(bone_rot);
+ }
+ }
+ }
+
+ void updateAttachments()
+ {
+ m_attached_to_local = getParent() != NULL && getParent()->isLocalPlayer();
+ m_is_visible = !m_attached_to_local; // Objects attached to the local player should always be hidden
+
+ if(getParent() == NULL || m_attached_to_local) // Detach or don't attach
+ {
+ if(m_meshnode)
+ {
+ v3f old_position = m_meshnode->getAbsolutePosition();
+ v3f old_rotation = m_meshnode->getRotation();
+ m_meshnode->setParent(m_smgr->getRootSceneNode());
+ m_meshnode->setPosition(old_position);
+ m_meshnode->setRotation(old_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ if(m_animated_meshnode)
+ {
+ v3f old_position = m_animated_meshnode->getAbsolutePosition();
+ v3f old_rotation = m_animated_meshnode->getRotation();
+ m_animated_meshnode->setParent(m_smgr->getRootSceneNode());
+ m_animated_meshnode->setPosition(old_position);
+ m_animated_meshnode->setRotation(old_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ if(m_spritenode)
+ {
+ v3f old_position = m_spritenode->getAbsolutePosition();
+ v3f old_rotation = m_spritenode->getRotation();
+ m_spritenode->setParent(m_smgr->getRootSceneNode());
+ m_spritenode->setPosition(old_position);
+ m_spritenode->setRotation(old_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ if(m_is_local_player)
+ {
+ LocalPlayer *player = m_env->getLocalPlayer();
+ player->isAttached = false;
+ }
+ }
+ else // Attach
+ {
+ scene::IMeshSceneNode *parent_mesh = NULL;
+ if(getParent()->getMeshSceneNode())
+ parent_mesh = getParent()->getMeshSceneNode();
+ scene::IAnimatedMeshSceneNode *parent_animated_mesh = NULL;
+ if(getParent()->getAnimatedMeshSceneNode())
+ parent_animated_mesh = getParent()->getAnimatedMeshSceneNode();
+ scene::IBillboardSceneNode *parent_sprite = NULL;
+ if(getParent()->getSpriteSceneNode())
+ parent_sprite = getParent()->getSpriteSceneNode();
+
+ scene::IBoneSceneNode *parent_bone = NULL;
+ if(parent_animated_mesh && m_attachment_bone != "")
+ parent_bone = parent_animated_mesh->getJointNode(m_attachment_bone.c_str());
+
+ // The spaghetti code below makes sure attaching works if either the parent or child is a spritenode, meshnode, or animatedmeshnode
+ // TODO: Perhaps use polymorphism here to save code duplication
+ if(m_meshnode){
+ if(parent_bone){
+ m_meshnode->setParent(parent_bone);
+ m_meshnode->setPosition(m_attachment_position);
+ m_meshnode->setRotation(m_attachment_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ else
+ {
+ if(parent_mesh){
+ m_meshnode->setParent(parent_mesh);
+ m_meshnode->setPosition(m_attachment_position);
+ m_meshnode->setRotation(m_attachment_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ else if(parent_animated_mesh){
+ m_meshnode->setParent(parent_animated_mesh);
+ m_meshnode->setPosition(m_attachment_position);
+ m_meshnode->setRotation(m_attachment_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ else if(parent_sprite){
+ m_meshnode->setParent(parent_sprite);
+ m_meshnode->setPosition(m_attachment_position);
+ m_meshnode->setRotation(m_attachment_rotation);
+ m_meshnode->updateAbsolutePosition();
+ }
+ }
+ }
+ if(m_animated_meshnode){
+ if(parent_bone){
+ m_animated_meshnode->setParent(parent_bone);
+ m_animated_meshnode->setPosition(m_attachment_position);
+ m_animated_meshnode->setRotation(m_attachment_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ else
+ {
+ if(parent_mesh){
+ m_animated_meshnode->setParent(parent_mesh);
+ m_animated_meshnode->setPosition(m_attachment_position);
+ m_animated_meshnode->setRotation(m_attachment_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ else if(parent_animated_mesh){
+ m_animated_meshnode->setParent(parent_animated_mesh);
+ m_animated_meshnode->setPosition(m_attachment_position);
+ m_animated_meshnode->setRotation(m_attachment_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ else if(parent_sprite){
+ m_animated_meshnode->setParent(parent_sprite);
+ m_animated_meshnode->setPosition(m_attachment_position);
+ m_animated_meshnode->setRotation(m_attachment_rotation);
+ m_animated_meshnode->updateAbsolutePosition();
+ }
+ }
+ }
+ if(m_spritenode){
+ if(parent_bone){
+ m_spritenode->setParent(parent_bone);
+ m_spritenode->setPosition(m_attachment_position);
+ m_spritenode->setRotation(m_attachment_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ else
+ {
+ if(parent_mesh){
+ m_spritenode->setParent(parent_mesh);
+ m_spritenode->setPosition(m_attachment_position);
+ m_spritenode->setRotation(m_attachment_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ else if(parent_animated_mesh){
+ m_spritenode->setParent(parent_animated_mesh);
+ m_spritenode->setPosition(m_attachment_position);
+ m_spritenode->setRotation(m_attachment_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ else if(parent_sprite){
+ m_spritenode->setParent(parent_sprite);
+ m_spritenode->setPosition(m_attachment_position);
+ m_spritenode->setRotation(m_attachment_rotation);
+ m_spritenode->updateAbsolutePosition();
+ }
+ }
+ }
+ if(m_is_local_player)
+ {
+ LocalPlayer *player = m_env->getLocalPlayer();
+ player->isAttached = true;
+ }
+ }
+ }
+
void processMessage(const std::string &data)
{
//infostream<<"GenericCAO: Got message"<<std::endl;
@@ -1099,6 +1615,8 @@ class GenericCAO : public ClientActiveObject
}
else if(cmd == GENERIC_CMD_UPDATE_POSITION)
{
+ // Not sent by the server if this object is an attachment.
+ // We might however get here if the server notices the object being detached before the client.
m_position = readV3F1000(is);
m_velocity = readV3F1000(is);
m_acceleration = readV3F1000(is);
@@ -1112,7 +1630,10 @@ class GenericCAO : public ClientActiveObject
// the ground due to sucky collision detection...
if(m_prop.physical)
m_position += v3f(0,0.002,0);
-
+
+ if(getParent() != NULL) // Just in case
+ return;
+
if(do_interpolate){
if(!m_prop.physical)
pos_translator.update(m_position, is_end_position, update_interval);
@@ -1140,6 +1661,41 @@ class GenericCAO : public ClientActiveObject
updateTexturePos();
}
+ else if(cmd == GENERIC_CMD_SET_ANIMATION)
+ {
+ m_animation_range = readV2F1000(is);
+ m_animation_speed = readF1000(is);
+ m_animation_blend = readF1000(is);
+
+ updateAnimation();
+ }
+ else if(cmd == GENERIC_CMD_SET_BONE_POSITION)
+ {
+ std::string bone = deSerializeString(is);
+ v3f position = readV3F1000(is);
+ v3f rotation = readV3F1000(is);
+ m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
+
+ updateBonePosition();
+ }
+ else if(cmd == GENERIC_CMD_SET_ATTACHMENT)
+ {
+ // If an entry already exists for this object, delete it first to avoid duplicates
+ for(std::vector<core::vector2d<int> >::iterator ii = m_env->attachment_list.begin(); ii != m_env->attachment_list.end(); ii++)
+ {
+ if(ii->X == getId()) // This is the ID of our object
+ {
+ m_env->attachment_list.erase(ii);
+ break;
+ }
+ }
+ m_env->attachment_list.push_back(core::vector2d<int>(getId(), readS16(is)));
+ m_attachment_bone = deSerializeString(is);
+ m_attachment_position = readV3F1000(is);
+ m_attachment_rotation = readV3F1000(is);
+
+ updateAttachments();
+ }
else if(cmd == GENERIC_CMD_PUNCHED)
{
/*s16 damage =*/ readS16(is);
View
1  src/content_mapblock.cpp
@@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "tile.h"
#include "gamedef.h"
#include "util/numeric.h"
-#include "util/serialize.h"
#include "util/directiontables.h"
// Create a cuboid.
View
431 src/content_sao.cpp
@@ -355,7 +355,10 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
m_last_sent_velocity(0,0,0),
m_last_sent_position_timer(0),
m_last_sent_move_precision(0),
- m_armor_groups_sent(false)
+ m_armor_groups_sent(false),
+ m_animation_sent(false),
+ m_bone_position_sent(false),
+ m_attachment_sent(false)
{
// Only register type if no environment supplied
if(env == NULL){
@@ -429,6 +432,17 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
return sao;
}
+bool LuaEntitySAO::isAttached()
+{
+ if(!m_attachment_parent_id)
+ return false;
+ // Check if the parent still exists
+ ServerActiveObject *obj = m_env->getActiveObject(m_attachment_parent_id);
+ if(obj)
+ return true;
+ return false;
+}
+
void LuaEntitySAO::step(float dtime, bool send_recommended)
{
if(!m_properties_sent)
@@ -440,30 +454,52 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
m_messages_out.push_back(aom);
}
+ // If attached, check that our parent is still there. If it isn't, detach.
+ if(m_attachment_parent_id && !isAttached())
+ {
+ m_attachment_parent_id = 0;
+ m_attachment_bone = "";
+ m_attachment_position = v3f(0,0,0);
+ m_attachment_rotation = v3f(0,0,0);
+ sendPosition(false, true);
+ }
+
m_last_sent_position_timer += dtime;
-
- if(m_prop.physical){
- core::aabbox3d<f32> box = m_prop.collisionbox;
- box.MinEdge *= BS;
- box.MaxEdge *= BS;
- collisionMoveResult moveresult;
- f32 pos_max_d = BS*0.25; // Distance per iteration
- f32 stepheight = 0; // Maximum climbable step height
- v3f p_pos = m_base_position;
- v3f p_velocity = m_velocity;
- v3f p_acceleration = m_acceleration;
- IGameDef *gamedef = m_env->getGameDef();
- moveresult = collisionMoveSimple(&m_env->getMap(), gamedef,
- pos_max_d, box, stepheight, dtime,
- p_pos, p_velocity, p_acceleration);
- // Apply results
- m_base_position = p_pos;
- m_velocity = p_velocity;
- m_acceleration = p_acceleration;
- } else {
- m_base_position += dtime * m_velocity + 0.5 * dtime
- * dtime * m_acceleration;
- m_velocity += dtime * m_acceleration;
+
+ // Each frame, parent position is copied if the object is attached, otherwise it's calculated normally
+ // If the object gets detached this comes into effect automatically from the last known origin
+ if(isAttached())
+ {
+ v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
+ m_base_position = pos;
+ m_velocity = v3f(0,0,0);
+ m_acceleration = v3f(0,0,0);
+ }
+ else
+ {
+ if(m_prop.physical){
+ core::aabbox3d<f32> box = m_prop.collisionbox;
+ box.MinEdge *= BS;
+ box.MaxEdge *= BS;
+ collisionMoveResult moveresult;
+ f32 pos_max_d = BS*0.25; // Distance per iteration
+ f32 stepheight = 0; // Maximum climbable step height
+ v3f p_pos = m_base_position;
+ v3f p_velocity = m_velocity;
+ v3f p_acceleration = m_acceleration;
+ IGameDef *gamedef = m_env->getGameDef();
+ moveresult = collisionMoveSimple(&m_env->getMap(), gamedef,
+ pos_max_d, box, stepheight, dtime,
+ p_pos, p_velocity, p_acceleration);
+ // Apply results
+ m_base_position = p_pos;
+ m_velocity = p_velocity;
+ m_acceleration = p_acceleration;
+ } else {
+ m_base_position += dtime * m_velocity + 0.5 * dtime
+ * dtime * m_acceleration;
+ m_velocity += dtime * m_acceleration;
+ }
}
if(m_registered){
@@ -473,20 +509,23 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
if(send_recommended == false)
return;
-
- // TODO: force send when acceleration changes enough?
- float minchange = 0.2*BS;
- if(m_last_sent_position_timer > 1.0){
- minchange = 0.01*BS;
- } else if(m_last_sent_position_timer > 0.2){
- minchange = 0.05*BS;
- }
- float move_d = m_base_position.getDistanceFrom(m_last_sent_position);
- move_d += m_last_sent_move_precision;
- float vel_d = m_velocity.getDistanceFrom(m_last_sent_velocity);
- if(move_d > minchange || vel_d > minchange ||
- fabs(m_yaw - m_last_sent_yaw) > 1.0){
- sendPosition(true, false);
+
+ if(!isAttached())
+ {
+ // TODO: force send when acceleration changes enough?
+ float minchange = 0.2*BS;
+ if(m_last_sent_position_timer > 1.0){
+ minchange = 0.01*BS;
+ } else if(m_last_sent_position_timer > 0.2){
+ minchange = 0.05*BS;
+ }
+ float move_d = m_base_position.getDistanceFrom(m_last_sent_position);
+ move_d += m_last_sent_move_precision;
+ float vel_d = m_velocity.getDistanceFrom(m_last_sent_velocity);
+ if(move_d > minchange || vel_d > minchange ||
+ fabs(m_yaw - m_last_sent_yaw) > 1.0){
+ sendPosition(true, false);
+ }
}
if(m_armor_groups_sent == false){
@@ -497,20 +536,54 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
}
+
+ if(m_animation_sent == false){
+ m_animation_sent = true;
+ std::string str = gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push_back(aom);
+ }
+
+ if(m_bone_position_sent == false){
+ m_bone_position_sent = true;
+ for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
+ std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push_back(aom);
+ }
+ }
+
+ if(m_attachment_sent == false){
+ m_attachment_sent = true;
+ std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push_back(aom);
+ }
}
std::string LuaEntitySAO::getClientInitializationData()
{
std::ostringstream os(std::ios::binary);
- writeU8(os, 0); // version
+ writeU8(os, 1); // version
os<<serializeString(""); // name
writeU8(os, 0); // is_player
+ writeS16(os, getId()); //id
writeV3F1000(os, m_base_position);
writeF1000(os, m_yaw);
writeS16(os, m_hp);
- writeU8(os, 2); // number of messages stuffed in here
+
+ writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here
os<<serializeLongString(getPropertyPacket()); // message 1
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
+ os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3
+ for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
+ os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
+ }
+ os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
+
// return result
return os.str();
}
@@ -550,6 +623,10 @@ int LuaEntitySAO::punch(v3f dir,
m_removed = true;
return 0;
}
+
+ // It's best that attachments cannot be punched
+ if(isAttached())
+ return 0;
ItemStack *punchitem = NULL;
ItemStack punchitem_static;
@@ -594,18 +671,25 @@ void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
{
if(!m_registered)
return;
+ // It's best that attachments cannot be clicked
+ if(isAttached())
+ return;
lua_State *L = m_env->getLua();
scriptapi_luaentity_rightclick(L, m_id, clicker);
}
void LuaEntitySAO::setPos(v3f pos)
{
+ if(isAttached())
+ return;
m_base_position = pos;
sendPosition(false, true);
}
void LuaEntitySAO::moveTo(v3f pos, bool continuous)
{
+ if(isAttached())
+ return;
m_base_position = pos;
if(!continuous)
sendPosition(true, true);
@@ -644,6 +728,37 @@ void LuaEntitySAO::setArmorGroups(const ItemGroupList &armor_groups)
m_armor_groups_sent = false;
}
+void LuaEntitySAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend)
+{
+ m_animation_range = frame_range;
+ m_animation_speed = frame_speed;
+ m_animation_blend = frame_blend;
+ m_animation_sent = false;
+}
+
+void LuaEntitySAO::setBonePosition(std::string bone, v3f position, v3f rotation)
+{
+ m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
+ m_bone_position_sent = false;
+}
+
+void LuaEntitySAO::setAttachment(int parent_id, std::string bone, v3f position, v3f rotation)
+{
+ // Attachments need to be handled on both the server and client.
+ // If we just attach on the server, we can only copy the position of the parent. Attachments
+ // are still sent to clients at an interval so players might see them lagging, plus we can't
+ // read and attach to skeletal bones.
+ // If we just attach on the client, the server still sees the child at its original location.
+ // This breaks some things so we also give the server the most accurate representation
+ // even if players only see the client changes.
+
+ m_attachment_parent_id = parent_id;
+ m_attachment_bone = bone;
+ m_attachment_position = position;
+ m_attachment_rotation = rotation;
+ m_attachment_sent = false;
+}
+
ObjectProperties* LuaEntitySAO::accessObjectProperties()
{
return &m_prop;
@@ -718,6 +833,10 @@ std::string LuaEntitySAO::getPropertyPacket()
void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
{
+ // If the object is attached client-side, don't waste bandwidth sending its position to clients
+ if(isAttached())
+ return;
+
m_last_sent_move_precision = m_base_position.getDistanceFrom(
m_last_sent_position);
m_last_sent_position_timer = 0;
@@ -765,8 +884,11 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
m_properties_sent(true),
m_privs(privs),
m_is_singleplayer(is_singleplayer),
+ m_animation_sent(false),
+ m_bone_position_sent(false),
+ m_attachment_sent(false),
// public
- m_teleported(false),
+ m_moved(false),
m_inventory_not_sent(false),
m_hp_not_sent(false),
m_wielded_item_not_sent(false)
@@ -782,13 +904,17 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, Player *player_, u16 peer_id_,
m_prop.physical = false;
m_prop.weight = 75;
m_prop.collisionbox = core::aabbox3d<f32>(-1/3.,-1.0,-1/3., 1/3.,1.0,1/3.);
+ // start of default appearance, this should be overwritten by LUA
m_prop.visual = "upright_sprite";
m_prop.visual_size = v2f(1, 2);
m_prop.textures.clear();
m_prop.textures.push_back("player.png");
m_prop.textures.push_back("player_back.png");
+ m_prop.colors.clear();
+ m_prop.colors.push_back(video::SColor(255, 255, 255, 255));
m_prop.spritediv = v2s16(1,1);
- m_prop.is_visible = (getHP() != 0);
+ // end of default appearance
+ m_prop.is_visible = true;
m_prop.makes_footstep_sound = true;
}
@@ -839,15 +965,24 @@ bool PlayerSAO::unlimitedTransferDistance() const
std::string PlayerSAO::getClientInitializationData()
{
std::ostringstream os(std::ios::binary);
- writeU8(os, 0); // version
+ writeU8(os, 1); // version
os<<serializeString(m_player->getName()); // name
writeU8(os, 1); // is_player
+ writeS16(os, getId()); //id
writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0));
writeF1000(os, m_player->getYaw());
writeS16(os, getHP());
- writeU8(os, 2); // number of messages stuffed in here
+
+ writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here
os<<serializeLongString(getPropertyPacket()); // message 1
os<<serializeLongString(gob_cmd_update_armor_groups(m_armor_groups)); // 2
+ os<<serializeLongString(gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend)); // 3
+ for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
+ os<<serializeLongString(gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y)); // m_bone_position.size
+ }
+ os<<serializeLongString(gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation)); // 4
+
+ // return result
return os.str();
}
@@ -857,6 +992,17 @@ std::string PlayerSAO::getStaticData()
return "";
}
+bool PlayerSAO::isAttached()
+{
+ if(!m_attachment_parent_id)
+ return false;
+ // Check if the parent still exists
+ ServerActiveObject *obj = m_env->getActiveObject(m_attachment_parent_id);
+ if(obj)
+ return true;
+ return false;
+}
+
void PlayerSAO::step(float dtime, bool send_recommended)
{
if(!m_properties_sent)
@@ -868,73 +1014,102 @@ void PlayerSAO::step(float dtime, bool send_recommended)
m_messages_out.push_back(aom);
}
+ // If attached, check that our parent is still there. If it isn't, detach.
+ if(m_attachment_parent_id && !isAttached())
+ {
+ m_attachment_parent_id = 0;
+ m_attachment_bone = "";
+ m_attachment_position = v3f(0,0,0);
+ m_attachment_rotation = v3f(0,0,0);
+ m_player->setPosition(m_last_good_position);
+ m_moved = true;
+ }
+
m_time_from_last_punch += dtime;
m_nocheat_dig_time += dtime;
-
- if(m_is_singleplayer || g_settings->getBool("disable_anticheat"))
+
+ // Each frame, parent position is copied if the object is attached, otherwise it's calculated normally
+ // If the object gets detached this comes into effect automatically from the last known origin
+ if(isAttached())
{
- m_last_good_position = m_player->getPosition();
+ v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
+ m_last_good_position = pos;
m_last_good_position_age = 0;
+ m_player->setPosition(pos);
}
else
{
- /*
- Check player movements
-
- NOTE: Actually the server should handle player physics like the
- client does and compare player's position to what is calculated
- on our side. This is required when eg. players fly due to an
- explosion. Altough a node-based alternative might be possible
- too, and much more lightweight.
- */
-
- float player_max_speed = 0;
- float player_max_speed_up = 0;
- if(m_privs.count("fast") != 0){
- // Fast speed
- player_max_speed = BS * 20;
- player_max_speed_up = BS * 20;
- } else {
- // Normal speed
- player_max_speed = BS * 4.0;
- player_max_speed_up = BS * 4.0;
+ if(m_is_singleplayer || g_settings->getBool("disable_anticheat"))
+ {
+ m_last_good_position = m_player->getPosition();
+ m_last_good_position_age = 0;
}
- // Tolerance
- player_max_speed *= 2.5;
- player_max_speed_up *= 2.5;
-
- m_last_good_position_age += dtime;
- if(m_last_good_position_age >= 1.0){
- float age = m_last_good_position_age;
- v3f diff = (m_player->getPosition() - m_last_good_position);
- float d_vert = diff.Y;
- diff.Y = 0;
- float d_horiz = diff.getLength();
- /*infostream<<m_player->getName()<<"'s horizontal speed is "
- <<(d_horiz/age)<<std::endl;*/
- if(d_horiz <= age * player_max_speed &&
- (d_vert < 0 || d_vert < age * player_max_speed_up)){
- m_last_good_position = m_player->getPosition();
+ else
+ {
+ /*
+ Check player movements
+
+ NOTE: Actually the server should handle player physics like the
+ client does and compare player's position to what is calculated
+ on our side. This is required when eg. players fly due to an
+ explosion. Altough a node-based alternative might be possible
+ too, and much more lightweight.
+ */
+
+ float player_max_speed = 0;
+ float player_max_speed_up = 0;
+ if(m_privs.count("fast") != 0){
+ // Fast speed
+ player_max_speed = BS * 20;
+ player_max_speed_up = BS * 20;
} else {
- actionstream<<"Player "<<m_player->getName()
- <<" moved too fast; resetting position"
- <<std::endl;
- m_player->setPosition(m_last_good_position);
- m_teleported = true;
+ // Normal speed
+ player_max_speed = BS * 4.0;
+ player_max_speed_up = BS * 4.0;
+ }
+ // Tolerance
+ player_max_speed *= 2.5;
+ player_max_speed_up *= 2.5;
+
+ m_last_good_position_age += dtime;
+ if(m_last_good_position_age >= 1.0){
+ float age = m_last_good_position_age;
+ v3f diff = (m_player->getPosition() - m_last_good_position);
+ float d_vert = diff.Y;
+ diff.Y = 0;
+ float d_horiz = diff.getLength();
+ /*infostream<<m_player->getName()<<"'s horizontal speed is "
+ <<(d_horiz/age)<<std::endl;*/
+ if(d_horiz <= age * player_max_speed &&
+ (d_vert < 0 || d_vert < age * player_max_speed_up)){
+ m_last_good_position = m_player->getPosition();
+ } else {
+ actionstream<<"Player "<<m_player->getName()
+ <<" moved too fast; resetting position"
+ <<std::endl;
+ m_player->setPosition(m_last_good_position);
+ m_moved = true;
+ }
+ m_last_good_position_age = 0;
}
- m_last_good_position_age = 0;
}
}
if(send_recommended == false)
return;
- if(m_position_not_sent)
+ // If the object is attached client-side, don't waste bandwidth sending its position to clients
+ if(m_position_not_sent && !isAttached())
{
m_position_not_sent = false;
float update_interval = m_env->getSendRecommendedInterval();
+ v3f pos;
+ if(isAttached()) // Just in case we ever do send attachment position too
+ pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
+ else
+ pos = m_player->getPosition() + v3f(0,BS*1,0);
std::string str = gob_cmd_update_position(
- m_player->getPosition() + v3f(0,BS*1,0),
+ pos,
v3f(0,0,0),
v3f(0,0,0),
m_player->getYaw(),
@@ -961,32 +1136,63 @@ void PlayerSAO::step(float dtime, bool send_recommended)
ActiveObjectMessage aom(getId(), true, str);
m_messages_out.push_back(aom);
}
+
+ if(m_animation_sent == false){
+ m_animation_sent = true;
+ std::string str = gob_cmd_update_animation(m_animation_range, m_animation_speed, m_animation_blend);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push_back(aom);
+ }
+
+ if(m_bone_position_sent == false){
+ m_bone_position_sent = true;
+ for(std::map<std::string, core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){
+ std::string str = gob_cmd_update_bone_position((*ii).first, (*ii).second.X, (*ii).second.Y);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push_back(aom);
+ }
+ }
+
+ if(m_attachment_sent == false){
+ m_attachment_sent = true;
+ std::string str = gob_cmd_update_attachment(m_attachment_parent_id, m_attachment_bone, m_attachment_position, m_attachment_rotation);
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, str);
+ m_messages_out.push_back(aom);
+ }
}
void PlayerSAO::setBasePosition(const v3f &position)
{
+ // This needs to be ran for attachments too
ServerActiveObject::setBasePosition(position);
m_position_not_sent = true;
}
void PlayerSAO::setPos(v3f pos)
{
+ if(isAttached())
+ return;
m_player->setPosition(pos);
// Movement caused by this command is always valid
m_last_good_position = pos;
m_last_good_position_age = 0;
// Force position change on client
- m_teleported = true;
+ m_moved = true;
}
void PlayerSAO::moveTo(v3f pos, bool continuous)
{
+ if(isAttached())
+ return;
m_player->setPosition(pos);
// Movement caused by this command is always valid
m_last_good_position = pos;
m_last_good_position_age = 0;
// Force position change on client
- m_teleported = true;
+ m_moved = true;
}
int PlayerSAO::punch(v3f dir,
@@ -994,6 +1200,10 @@ int PlayerSAO::punch(v3f dir,
ServerActiveObject *puncher,
float time_from_last_punch)
{
+ // It's best that attachments cannot be punched
+ if(isAttached())
+ return 0;
+
if(!toolcap)
return 0;
@@ -1075,6 +1285,39 @@ void PlayerSAO::setArmorGroups(const ItemGroupList &armor_groups)
m_armor_groups_sent = false;
}
+void PlayerSAO::setAnimation(v2f frame_range, float frame_speed, float frame_blend)
+{
+ // store these so they can be updated to clients
+ m_animation_range = frame_range;
+ m_animation_speed = frame_speed;
+ m_animation_blend = frame_blend;
+ m_animation_sent = false;
+}
+
+void PlayerSAO::setBonePosition(std::string bone, v3f position, v3f rotation)
+{
+ // store these so they can be updated to clients
+ m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
+ m_bone_position_sent = false;
+}
+
+void PlayerSAO::setAttachment(int parent_id, std::string bone, v3f position, v3f rotation)
+{
+ // Attachments need to be handled on both the server and client.
+ // If we just attach on the server, we can only copy the position of the parent. Attachments
+ // are still sent to clients at an interval so players might see them lagging, plus we can't
+ // read and attach to skeletal bones.
+ // If we just attach on the client, the server still sees the child at its original location.
+ // This breaks some things so we also give the server the most accurate representation
+ // even if players only see the client changes.
+
+ m_attachment_parent_id = parent_id;
+ m_attachment_bone = bone;
+ m_attachment_position = position;
+ m_attachment_rotation = rotation;
+ m_attachment_sent = false;
+}
+
ObjectProperties* PlayerSAO::accessObjectProperties()
{
return &m_prop;
@@ -1138,7 +1381,7 @@ void PlayerSAO::disconnected()
std::string PlayerSAO::getPropertyPacket()
{
- m_prop.is_visible = (getHP() != 0);
+ m_prop.is_visible = (true);
return gob_cmd_set_properties(m_prop);
}
View
41 src/content_sao.h
@@ -46,6 +46,7 @@ class LuaEntitySAO : public ServerActiveObject
virtual void addedToEnvironment(u32 dtime_s);
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data);
+ bool isAttached();
void step(float dtime, bool send_recommended);
std::string getClientInitializationData();
std::string getStaticData();
@@ -61,6 +62,9 @@ class LuaEntitySAO : public ServerActiveObject
void setHP(s16 hp);
s16 getHP() const;
void setArmorGroups(const ItemGroupList &armor_groups);
+ void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
+ void setBonePosition(std::string bone, v3f position, v3f rotation);
+ void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
/* LuaEntitySAO-specific */
@@ -96,6 +100,20 @@ class LuaEntitySAO : public ServerActiveObject
float m_last_sent_position_timer;
float m_last_sent_move_precision;
bool m_armor_groups_sent;
+
+ v2f m_animation_range;
+ float m_animation_speed;
+ float m_animation_blend;
+ bool m_animation_sent;
+
+ std::map<std::string, core::vector2d<v3f> > m_bone_position;
+ bool m_bone_position_sent;
+
+ int m_attachment_parent_id;
+ std::string m_attachment_bone;
+ v3f m_attachment_position;
+ v3f m_attachment_rotation;
+ bool m_attachment_sent;
};
/*
@@ -124,6 +142,7 @@ class PlayerSAO : public ServerActiveObject
bool unlimitedTransferDistance() const;
std::string getClientInitializationData();
std::string getStaticData();
+ bool isAttached();
void step(float dtime, bool send_recommended);
void setBasePosition(const v3f &position);
void setPos(v3f pos);
@@ -142,6 +161,9 @@ class PlayerSAO : public ServerActiveObject
void setHP(s16 hp);
void setArmorGroups(const ItemGroupList &armor_groups);
+ void setAnimation(v2f frame_range, float frame_speed, float frame_blend);
+ void setBonePosition(std::string bone, v3f position, v3f rotation);
+ void setAttachment(int parent_id, std::string bone, v3f position, v3f rotation);
ObjectProperties* accessObjectProperties();
void notifyObjectPropertiesModified();
@@ -229,15 +251,32 @@ class PlayerSAO : public ServerActiveObject
bool m_position_not_sent;
ItemGroupList m_armor_groups;
bool m_armor_groups_sent;
+
+
+
bool m_properties_sent;
struct ObjectProperties m_prop;
// Cached privileges for enforcement
std::set<std::string> m_privs;
bool m_is_singleplayer;
+ v2f m_animation_range;
+ float m_animation_speed;
+ float m_animation_blend;
+ bool m_animation_sent;
+
+ std::map<std::string, core::vector2d<v3f> > m_bone_position; // Stores position and rotation for each bone name
+ bool m_bone_position_sent;
+
+ int m_attachment_parent_id;
+ std::string m_attachment_bone;
+ v3f m_attachment_position;
+ v3f m_attachment_rotation;
+ bool m_attachment_sent;
+
public:
// Some flags used by Server
- bool m_teleported;
+ bool m_moved;
bool m_inventory_not_sent;
bool m_hp_not_sent;
bool m_wielded_item_not_sent;
View
7 src/defaultsettings.cpp
@@ -141,7 +141,12 @@ void set_default_settings(Settings *settings)
settings->setDefault("server_unload_unused_data_timeout", "29");
settings->setDefault("server_map_save_interval", "5.3");
settings->setDefault("full_block_send_enable_min_time_from_building", "2.0");
- settings->setDefault("dedicated_server_step", "0.05");
+ settings->setDefault("dedicated_server_step", "0.1");
settings->setDefault("ignore_world_load_errors", "false");
+ settings->setDefault("mip_map", "false");
+ settings->setDefault("anisotropic_filter", "false");
+ settings->setDefault("bilinear_filter", "false");
+ settings->setDefault("trilinear_filter", "false");
+
}
View
16 src/environment.cpp
@@ -43,6 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif
#include "daynightratio.h"
#include "map.h"
+#include "util/serialize.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@@ -327,7 +328,8 @@ ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L,
m_send_recommended_timer(0),
m_active_block_interval_overload_skip(0),
m_game_time(0),
- m_game_time_fraction_counter(0)
+ m_game_time_fraction_counter(0),
+ m_recommended_send_interval(0.1)
{
}
@@ -938,6 +940,11 @@ void ServerEnvironment::step(float dtime)
/* Step time of day */
stepTimeOfDay(dtime);
+ // Update this one
+ // NOTE: This is kind of funny on a singleplayer game, but doesn't
+ // really matter that much.
+ m_recommended_send_interval = g_settings->getFloat("dedicated_server_step");
+
/*
Increment game time
*/
@@ -2294,8 +2301,9 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type,
{
errorstream<<"ClientEnvironment::addActiveObject():"
<<" id="<<id<<" type="<<type
- <<": SerializationError in initialize(),"
- <<" init_data="<<serializeJsonString(init_data)
+ <<": SerializationError in initialize(): "
+ <<e.what()
+ <<": init_data="<<serializeJsonString(init_data)
<<std::endl;
}
@@ -2313,7 +2321,7 @@ void ClientEnvironment::removeActiveObject(u16 id)
<<"id="<<id<<" not found"<<std::endl;
return;
}
- obj->removeFromScene();
+ obj->removeFromScene(true);
delete obj;
m_active_objects.remove(id);
}
View
8 src/environment.h
@@ -198,9 +198,7 @@ class ServerEnvironment : public Environment
{ return m_gamedef; }
float getSendRecommendedInterval()
- {
- return 0.10;
- }
+ { return m_recommended_send_interval; }
/*
Save players
@@ -358,6 +356,8 @@ class ServerEnvironment : public Environment
// A helper variable for incrementing the latter
float m_game_time_fraction_counter;
core::list<ABMWithState> m_abms;
+ // An interval for generally sending object positions and stuff
+ float m_recommended_send_interval;
};
#ifndef SERVER
@@ -454,6 +454,8 @@ class ClientEnvironment : public Environment
// Get event from queue. CEE_NONE is returned if queue is empty.