Compare commits
21 Commits
0.4.dev-20
...
20120204_l
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0947644729 | ||
|
|
77df09540c | ||
|
|
a1eb2836c0 | ||
|
|
64af6d3afe | ||
|
|
365f7a5bfe | ||
|
|
796009ef21 | ||
|
|
b85b4ede82 | ||
|
|
2cb96d9d68 | ||
|
|
78bf92175a | ||
|
|
0c3d39357b | ||
|
|
0e8bd531c2 | ||
|
|
24b1008d56 | ||
|
|
a4340c330a | ||
|
|
2e8e9ee7f5 | ||
|
|
3454e67793 | ||
|
|
0c78767754 | ||
|
|
f0679969b2 | ||
|
|
285f5a0259 | ||
|
|
71186974fa | ||
|
|
525bc8855f | ||
|
|
de166e75a1 |
@@ -159,7 +159,6 @@ function minetest.get_node_drops(nodename, toolname)
|
||||
local drop = ItemStack({name=nodename}):get_definition().drop
|
||||
if drop == nil then
|
||||
-- default drop
|
||||
print("default drop: " .. nodename)
|
||||
return {ItemStack({name=nodename})}
|
||||
elseif type(drop) == "string" then
|
||||
-- itemstring drop
|
||||
|
||||
@@ -114,10 +114,10 @@
|
||||
-- minetest.chat_send_player(name, text)
|
||||
-- minetest.get_player_privs(name) -> set of privs
|
||||
-- minetest.get_inventory(location) -> InvRef
|
||||
-- minetest.get_current_modname() -> string
|
||||
-- minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
|
||||
-- ^ location = eg. {type="player", name="celeron55"}
|
||||
-- {type="node", pos={x=, y=, z=}}
|
||||
-- minetest.get_current_modname() -> string
|
||||
-- minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
|
||||
--
|
||||
-- minetest.debug(line)
|
||||
-- ^ Goes to dstream
|
||||
@@ -169,6 +169,8 @@
|
||||
-- - get_meta(pos) -- Get a NodeMetaRef at that position
|
||||
-- - get_player_by_name(name) -- Get an ObjectRef to a player
|
||||
-- - get_objects_inside_radius(pos, radius)
|
||||
-- - set_timeofday(val): val: 0...1; 0 = midnight, 0.5 = midday
|
||||
-- - get_timeofday()
|
||||
--
|
||||
-- NodeMetaRef (this stuff is subject to change in a future version)
|
||||
-- - get_type()
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
-- For testing random stuff
|
||||
|
||||
experimental = {}
|
||||
|
||||
function on_step(dtime)
|
||||
-- print("experimental on_step")
|
||||
--[[
|
||||
@@ -20,6 +22,26 @@ function on_step(dtime)
|
||||
end
|
||||
end
|
||||
--]]
|
||||
--[[
|
||||
if experimental.t1 == nil then
|
||||
experimental.t1 = 0
|
||||
end
|
||||
experimental.t1 = experimental.t1 + dtime
|
||||
if experimental.t1 >= 2 then
|
||||
experimental.t1 = experimental.t1 - 2
|
||||
minetest.log("time of day is "..minetest.env:get_timeofday())
|
||||
if experimental.day then
|
||||
minetest.log("forcing day->night")
|
||||
experimental.day = false
|
||||
minetest.env:set_timeofday(0.0)
|
||||
else
|
||||
minetest.log("forcing night->day")
|
||||
experimental.day = true
|
||||
minetest.env:set_timeofday(0.5)
|
||||
end
|
||||
minetest.log("time of day is "..minetest.env:get_timeofday())
|
||||
end
|
||||
--]]
|
||||
end
|
||||
minetest.register_globalstep(on_step)
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@ set(common_SRCS
|
||||
collision.cpp
|
||||
nodemetadata.cpp
|
||||
serverobject.cpp
|
||||
serverlinkableobject.cpp
|
||||
noise.cpp
|
||||
porting.cpp
|
||||
materials.cpp
|
||||
@@ -166,6 +167,7 @@ set(minetest_SRCS
|
||||
camera.cpp
|
||||
clouds.cpp
|
||||
clientobject.cpp
|
||||
clientlinkableobject.cpp
|
||||
guiMainMenu.cpp
|
||||
guiKeyChangeMenu.cpp
|
||||
guiMessageMenu.cpp
|
||||
|
||||
@@ -40,8 +40,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
|
||||
m_wieldlight(0),
|
||||
|
||||
m_draw_control(draw_control),
|
||||
m_viewing_range_min(5.0),
|
||||
m_viewing_range_max(5.0),
|
||||
|
||||
m_camera_position(0,0,0),
|
||||
m_camera_direction(0,0,0),
|
||||
@@ -50,7 +48,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
|
||||
m_fov_x(1.0),
|
||||
m_fov_y(1.0),
|
||||
|
||||
m_wanted_frametime(0.0),
|
||||
m_added_frametime(0),
|
||||
m_added_frames(0),
|
||||
m_range_old(0),
|
||||
@@ -79,8 +76,6 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control):
|
||||
m_wieldmgr = smgr->createNewSceneManager();
|
||||
m_wieldmgr->addCameraSceneNode();
|
||||
m_wieldnode = m_wieldmgr->addMeshSceneNode(createCubeMesh(v3f(1,1,1)), NULL); // need a dummy mesh
|
||||
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
Camera::~Camera()
|
||||
@@ -259,14 +254,17 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
|
||||
// *100.0 helps in large map coordinates
|
||||
m_cameranode->setTarget(m_camera_position + 100 * m_camera_direction);
|
||||
|
||||
// FOV and and aspect ratio
|
||||
// Get FOV setting
|
||||
f32 fov_degrees = g_settings->getFloat("fov");
|
||||
fov_degrees = MYMAX(fov_degrees, 10.0);
|
||||
fov_degrees = MYMIN(fov_degrees, 170.0);
|
||||
|
||||
// FOV and aspect ratio
|
||||
m_aspect = (f32)screensize.X / (f32) screensize.Y;
|
||||
m_fov_y = fov_degrees * PI / 180.0;
|
||||
m_fov_x = 2 * atan(0.5 * m_aspect * tan(m_fov_y));
|
||||
m_cameranode->setAspectRatio(m_aspect);
|
||||
m_cameranode->setFOV(m_fov_y);
|
||||
// Just so big a value that everything rendered is visible
|
||||
// Some more allowance that m_viewing_range_max * BS because of active objects etc.
|
||||
m_cameranode->setFarValue(m_viewing_range_max * BS * 10);
|
||||
|
||||
// Position the wielded item
|
||||
v3f wield_position = v3f(45, -35, 65);
|
||||
@@ -343,7 +341,18 @@ void Camera::updateViewingRange(f32 frametime_in)
|
||||
<<m_draw_control.blocks_would_have_drawn
|
||||
<<std::endl;*/
|
||||
|
||||
m_draw_control.wanted_min_range = m_viewing_range_min;
|
||||
// Get current viewing range and FPS settings
|
||||
f32 viewing_range_min = g_settings->getS16("viewing_range_nodes_min");
|
||||
viewing_range_min = MYMAX(5.0, viewing_range_min);
|
||||
|
||||
f32 viewing_range_max = g_settings->getS16("viewing_range_nodes_max");
|
||||
viewing_range_max = MYMAX(viewing_range_min, viewing_range_max);
|
||||
|
||||
f32 wanted_fps = g_settings->getFloat("wanted_fps");
|
||||
wanted_fps = MYMAX(wanted_fps, 1.0);
|
||||
f32 wanted_frametime = 1.0 / wanted_fps;
|
||||
|
||||
m_draw_control.wanted_min_range = viewing_range_min;
|
||||
m_draw_control.wanted_max_blocks = (2.0*m_draw_control.blocks_would_have_drawn)+1;
|
||||
if (m_draw_control.wanted_max_blocks < 10)
|
||||
m_draw_control.wanted_max_blocks = 10;
|
||||
@@ -362,13 +371,13 @@ void Camera::updateViewingRange(f32 frametime_in)
|
||||
m_added_frametime = 0.0;
|
||||
m_added_frames = 0;
|
||||
|
||||
f32 wanted_frametime_change = m_wanted_frametime - frametime;
|
||||
f32 wanted_frametime_change = wanted_frametime - frametime;
|
||||
//dstream<<"wanted_frametime_change="<<wanted_frametime_change<<std::endl;
|
||||
|
||||
// If needed frametime change is small, just return
|
||||
// This value was 0.4 for many months until 2011-10-18 by c55;
|
||||
// Let's see how this works out.
|
||||
if (fabs(wanted_frametime_change) < m_wanted_frametime*0.33)
|
||||
if (fabs(wanted_frametime_change) < wanted_frametime*0.33)
|
||||
{
|
||||
//dstream<<"ignoring small wanted_frametime_change"<<std::endl;
|
||||
return;
|
||||
@@ -421,8 +430,8 @@ void Camera::updateViewingRange(f32 frametime_in)
|
||||
new_range += wanted_range_change;
|
||||
|
||||
//f32 new_range_unclamped = new_range;
|
||||
new_range = MYMAX(new_range, m_viewing_range_min);
|
||||
new_range = MYMIN(new_range, m_viewing_range_max);
|
||||
new_range = MYMAX(new_range, viewing_range_min);
|
||||
new_range = MYMIN(new_range, viewing_range_max);
|
||||
/*dstream<<"new_range="<<new_range_unclamped
|
||||
<<", clamped to "<<new_range<<std::endl;*/
|
||||
|
||||
@@ -430,24 +439,11 @@ void Camera::updateViewingRange(f32 frametime_in)
|
||||
|
||||
m_range_old = new_range;
|
||||
m_frametime_old = frametime;
|
||||
}
|
||||
|
||||
void Camera::updateSettings()
|
||||
{
|
||||
m_viewing_range_min = g_settings->getS16("viewing_range_nodes_min");
|
||||
m_viewing_range_min = MYMAX(5.0, m_viewing_range_min);
|
||||
// Just so big a value that everything rendered is visible
|
||||
// Some more allowance than viewing_range_max * BS because of active objects etc.
|
||||
m_cameranode->setFarValue(viewing_range_max * BS * 10);
|
||||
|
||||
m_viewing_range_max = g_settings->getS16("viewing_range_nodes_max");
|
||||
m_viewing_range_max = MYMAX(m_viewing_range_min, m_viewing_range_max);
|
||||
|
||||
f32 fov_degrees = g_settings->getFloat("fov");
|
||||
fov_degrees = MYMAX(fov_degrees, 10.0);
|
||||
fov_degrees = MYMIN(fov_degrees, 170.0);
|
||||
m_fov_y = fov_degrees * PI / 180.0;
|
||||
|
||||
f32 wanted_fps = g_settings->getFloat("wanted_fps");
|
||||
wanted_fps = MYMAX(wanted_fps, 1.0);
|
||||
m_wanted_frametime = 1.0 / wanted_fps;
|
||||
}
|
||||
|
||||
void Camera::setDigging(s32 button)
|
||||
|
||||
@@ -110,9 +110,6 @@ class Camera
|
||||
// Render distance feedback loop
|
||||
void updateViewingRange(f32 frametime_in);
|
||||
|
||||
// Update settings from g_settings
|
||||
void updateSettings();
|
||||
|
||||
// Start digging animation
|
||||
// Pass 0 for left click, 1 for right click
|
||||
void setDigging(s32 button);
|
||||
@@ -139,11 +136,6 @@ class Camera
|
||||
// draw control
|
||||
MapDrawControl& m_draw_control;
|
||||
|
||||
// viewing_range_min_nodes setting
|
||||
f32 m_viewing_range_min;
|
||||
// viewing_range_max_nodes setting
|
||||
f32 m_viewing_range_max;
|
||||
|
||||
// Absolute camera position
|
||||
v3f m_camera_position;
|
||||
// Absolute camera direction
|
||||
@@ -155,7 +147,6 @@ class Camera
|
||||
f32 m_fov_y;
|
||||
|
||||
// Stuff for viewing range calculations
|
||||
f32 m_wanted_frametime;
|
||||
f32 m_added_frametime;
|
||||
s16 m_added_frames;
|
||||
f32 m_range_old;
|
||||
|
||||
123
src/clientlinkableobject.cpp
Normal file
123
src/clientlinkableobject.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
Copyright (C) 2012 sapier sapier at gmx dot net
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "clientlinkableobject.h"
|
||||
|
||||
ClientLinkableObject::ClientLinkableObject() {
|
||||
|
||||
this->m_Parent = NULL;
|
||||
}
|
||||
|
||||
ClientLinkableObject::~ClientLinkableObject() {
|
||||
if (this->isLinked())
|
||||
this->unlink(this);
|
||||
}
|
||||
|
||||
|
||||
void ClientLinkableObject::link(ClientLinkableObject* entity) {
|
||||
//TODO check if entity is already linkt (shouldn't be the case but just to be sure)
|
||||
this->m_LinkedObjects.push_back(entity);
|
||||
}
|
||||
|
||||
void ClientLinkableObject::unlink(ClientLinkableObject* entity) {
|
||||
this->m_LinkedObjects.remove(entity);
|
||||
}
|
||||
|
||||
|
||||
void ClientLinkableObject::stepLinkedObjects(v3f pos,float dtime) {
|
||||
for(std::list<ClientLinkableObject*>::iterator i = this->m_LinkedObjects.begin();
|
||||
i != this->m_LinkedObjects.end(); i++) {
|
||||
(*i)->setPosition(pos,dtime);
|
||||
}
|
||||
}
|
||||
|
||||
bool ClientLinkableObject::handleLinkUnlinkMessages(u8 cmd,std::istringstream* is,ClientEnvironment *m_env) {
|
||||
if(cmd == AO_Message_type::Link) // Link entity
|
||||
{
|
||||
//Object to link entity to
|
||||
u16 object_id = readU16(*is);
|
||||
//offset against linked object
|
||||
v3f offset = readV3F1000(*is);
|
||||
|
||||
ClientActiveObject* parent_cao = m_env->getActiveObject(object_id);
|
||||
|
||||
ClientLinkableObject* parent = dynamic_cast<ClientLinkableObject*>(parent_cao);
|
||||
|
||||
if (parent != NULL) {
|
||||
this->linkEntity(offset,parent);
|
||||
}
|
||||
else {
|
||||
errorstream << "Invalid object to link to!" << std::endl;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
else if(cmd == AO_Message_type::UnLink) // UnLink entity
|
||||
{
|
||||
if (this->m_Parent == NULL) {
|
||||
errorstream << "Unlinking object not linked!" << std::endl;
|
||||
}
|
||||
|
||||
this->unlinkEntity();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ClientLinkableObject::linkEntity(v3f offset, ClientLinkableObject* parent) {
|
||||
//already linked unlink first
|
||||
if (this->m_Parent != NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO add linkchain support
|
||||
if (this->m_LinkedObjects.size() > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parent->link(this);
|
||||
updateLinkState(true);
|
||||
this->m_linkOffset = offset;
|
||||
this->m_Parent = parent;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ClientLinkableObject::unlinkEntity() {
|
||||
if (this->m_Parent != NULL) {
|
||||
|
||||
updateLinkState(false);
|
||||
this->m_Parent->unlink(this);
|
||||
this->m_Parent = NULL;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ClientLinkableObject::isLinked() {
|
||||
if (this->m_Parent != NULL)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
80
src/clientlinkableobject.h
Normal file
80
src/clientlinkableobject.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
Copyright (C) 2012 sapier sapier at gmx dot net
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef CLIENTLINKABLEOBJECT_H_
|
||||
#define CLIENTLINKABLEOBJECT_H_
|
||||
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include <irrlichttypes.h>
|
||||
#include "clientobject.h"
|
||||
#include "environment.h"
|
||||
#include "content_object.h"
|
||||
#include "utility.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
//this ain't the right place to define this but until cao/sao split
|
||||
//is decided it'll have to stay here
|
||||
struct AO_Message_type {
|
||||
static const u8 SetPosition = 0x00;
|
||||
static const u8 SetTextureMod = 0x01;
|
||||
static const u8 SetSprite = 0x02;
|
||||
static const u8 Punched = 0x03;
|
||||
static const u8 TakeDamage = 0x04;
|
||||
static const u8 Shoot = 0x05;
|
||||
static const u8 Link = 0x06;
|
||||
static const u8 UnLink = 0x07;
|
||||
};
|
||||
|
||||
|
||||
class ClientLinkableObject {
|
||||
public:
|
||||
ClientLinkableObject();
|
||||
~ClientLinkableObject();
|
||||
//internal communication between entitys NOT to be used by user
|
||||
void link(ClientLinkableObject* entity);
|
||||
void unlink(ClientLinkableObject* entity);
|
||||
|
||||
virtual void setPosition(v3f toset, float dtime) = 0;
|
||||
virtual void updateLinkState(bool value) = 0;
|
||||
|
||||
protected:
|
||||
void stepLinkedObjects(v3f pos,float dtime);
|
||||
|
||||
bool handleLinkUnlinkMessages(u8 cmd,std::istringstream* is,ClientEnvironment *m_env);
|
||||
|
||||
|
||||
//user driven functions (exported by lua)
|
||||
bool linkEntity(v3f offset, ClientLinkableObject* parent);
|
||||
bool unlinkEntity();
|
||||
|
||||
bool isLinked();
|
||||
v3f m_linkOffset;
|
||||
|
||||
|
||||
private:
|
||||
ClientLinkableObject* m_Parent;
|
||||
|
||||
std::list<ClientLinkableObject*> m_LinkedObjects;
|
||||
};
|
||||
|
||||
|
||||
#endif /* CLIENTLINKABLEOBJECT_H_ */
|
||||
@@ -1815,6 +1815,33 @@ class LuaEntityCAO : public ClientActiveObject
|
||||
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
|
||||
mesh->drop();
|
||||
|
||||
m_meshnode->setScale(v3f(1));
|
||||
// Will be shown when we know the brightness
|
||||
m_meshnode->setVisible(false);
|
||||
} else if(m_prop->visual == "cube_allfaces"){
|
||||
infostream<<"LuaEntityCAO::addToScene(): cube_allfaces"<<std::endl;
|
||||
scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS),true);
|
||||
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
|
||||
mesh->drop();
|
||||
|
||||
m_meshnode->setScale(v3f(1));
|
||||
// Will be shown when we know the brightness
|
||||
m_meshnode->setVisible(false);
|
||||
} else if (m_prop->visual == "plant") {
|
||||
infostream<<"LuaEntityCAO::addToScene(): plant"<<std::endl;
|
||||
scene::IMesh *mesh = createPlantMesh(v3f(BS,BS,BS));
|
||||
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
|
||||
mesh->drop();
|
||||
|
||||
m_meshnode->setScale(v3f(1));
|
||||
// Will be shown when we know the brightness
|
||||
m_meshnode->setVisible(false);
|
||||
} else if (m_prop->visual == "cube_disorted") {
|
||||
infostream<<"LuaEntityCAO::addToScene(): irregular_cube"<<std::endl;
|
||||
scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS), m_prop->collisionbox);
|
||||
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
|
||||
mesh->drop();
|
||||
|
||||
m_meshnode->setScale(v3f(1));
|
||||
// Will be shown when we know the brightness
|
||||
m_meshnode->setVisible(false);
|
||||
@@ -1970,26 +1997,51 @@ class LuaEntityCAO : public ClientActiveObject
|
||||
tsrc->getTextureRaw(texturestring));
|
||||
}
|
||||
if(m_meshnode){
|
||||
for (u32 i = 0; i < 6; ++i)
|
||||
{
|
||||
std::string texturestring = "unknown_block.png";
|
||||
if(m_prop->textures.size() > i)
|
||||
texturestring = m_prop->textures[i];
|
||||
texturestring += mod;
|
||||
AtlasPointer ap = tsrc->getTexture(texturestring);
|
||||
if (m_prop->visual == "plant") {
|
||||
for (u32 i = 0; i < 4; ++i) {
|
||||
std::string texturestring = "unknown_block.png";
|
||||
if(m_prop->textures.size() > 0)
|
||||
texturestring = m_prop->textures[0];
|
||||
texturestring += mod;
|
||||
AtlasPointer ap = tsrc->getTexture(texturestring);
|
||||
|
||||
// Get the tile texture and atlas transformation
|
||||
video::ITexture* atlas = ap.atlas;
|
||||
v2f pos = ap.pos;
|
||||
v2f size = ap.size;
|
||||
// Get the tile texture and atlas transformation
|
||||
video::ITexture* atlas = ap.atlas;
|
||||
v2f pos = ap.pos;
|
||||
v2f size = ap.size;
|
||||
|
||||
// Set material flags and texture
|
||||
video::SMaterial& material = m_meshnode->getMaterial(i);
|
||||
material.setFlag(video::EMF_LIGHTING, false);
|
||||
material.setFlag(video::EMF_BILINEAR_FILTER, false);
|
||||
material.setTexture(0, atlas);
|
||||
material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
|
||||
material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
|
||||
// Set material flags and texture
|
||||
video::SMaterial& material = m_meshnode->getMaterial(i);
|
||||
material.setFlag(video::EMF_LIGHTING, false);
|
||||
material.setFlag(video::EMF_BILINEAR_FILTER, false);
|
||||
material.setTexture(0, atlas);
|
||||
material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
|
||||
material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
|
||||
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (u32 i = 0; i < 6; ++i) {
|
||||
std::string texturestring = "unknown_block.png";
|
||||
if(m_prop->textures.size() > i)
|
||||
texturestring = m_prop->textures[i];
|
||||
texturestring += mod;
|
||||
AtlasPointer ap = tsrc->getTexture(texturestring);
|
||||
|
||||
// Get the tile texture and atlas transformation
|
||||
video::ITexture* atlas = ap.atlas;
|
||||
v2f pos = ap.pos;
|
||||
v2f size = ap.size;
|
||||
|
||||
// Set material flags and texture
|
||||
video::SMaterial& material = m_meshnode->getMaterial(i);
|
||||
material.setFlag(video::EMF_LIGHTING, false);
|
||||
material.setFlag(video::EMF_BILINEAR_FILTER, false);
|
||||
material.setTexture(0, atlas);
|
||||
material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
|
||||
material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
|
||||
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,6 +441,10 @@ bool FurnaceNodeMetadata::step(float dtime)
|
||||
{
|
||||
if(dtime > 60.0)
|
||||
infostream<<"Furnace stepping a long time ("<<dtime<<")"<<std::endl;
|
||||
|
||||
InventoryList *dst_list = m_inventory->getList("dst");
|
||||
assert(dst_list);
|
||||
|
||||
// Update at a fixed frequency
|
||||
const float interval = 2.0;
|
||||
m_step_accumulator += dtime;
|
||||
@@ -452,8 +456,7 @@ bool FurnaceNodeMetadata::step(float dtime)
|
||||
|
||||
//infostream<<"Furnace step dtime="<<dtime<<std::endl;
|
||||
|
||||
InventoryList *dst_list = m_inventory->getList("dst");
|
||||
assert(dst_list);
|
||||
bool changed_this_loop = false;
|
||||
|
||||
// Check
|
||||
// 1. if the source item is cookable
|
||||
@@ -473,7 +476,7 @@ bool FurnaceNodeMetadata::step(float dtime)
|
||||
bool burning = (m_fuel_time < m_fuel_totaltime);
|
||||
if(burning)
|
||||
{
|
||||
changed = true;
|
||||
changed_this_loop = true;
|
||||
m_fuel_time += dtime;
|
||||
}
|
||||
|
||||
@@ -483,7 +486,7 @@ bool FurnaceNodeMetadata::step(float dtime)
|
||||
float burntime;
|
||||
if(burning)
|
||||
{
|
||||
changed = true;
|
||||
changed_this_loop = true;
|
||||
m_src_time += dtime;
|
||||
m_src_totaltime = cooktime;
|
||||
infotext = "Furnace is cooking";
|
||||
@@ -491,7 +494,7 @@ bool FurnaceNodeMetadata::step(float dtime)
|
||||
else if(getBurnResult(true, burntime))
|
||||
{
|
||||
// Fuel inserted
|
||||
changed = true;
|
||||
changed_this_loop = true;
|
||||
m_fuel_time = 0;
|
||||
m_fuel_totaltime = burntime;
|
||||
//m_src_time += dtime;
|
||||
@@ -507,7 +510,7 @@ bool FurnaceNodeMetadata::step(float dtime)
|
||||
if(m_src_totaltime > 0.001 && m_src_time >= m_src_totaltime)
|
||||
{
|
||||
// One item fully cooked
|
||||
changed = true;
|
||||
changed_this_loop = true;
|
||||
dst_list->addItem(cookresult_item);
|
||||
getCookResult(true, cookresult, cooktime); // decrement source
|
||||
m_src_totaltime = 0;
|
||||
@@ -541,7 +544,7 @@ bool FurnaceNodeMetadata::step(float dtime)
|
||||
if(infotext != m_infotext)
|
||||
{
|
||||
m_infotext = infotext;
|
||||
changed = true;
|
||||
changed_this_loop = true;
|
||||
}
|
||||
|
||||
if(burning && m_fuel_time >= m_fuel_totaltime)
|
||||
@@ -550,7 +553,11 @@ bool FurnaceNodeMetadata::step(float dtime)
|
||||
m_fuel_totaltime = 0;
|
||||
}
|
||||
|
||||
if(!changed)
|
||||
if(changed_this_loop)
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_step_accumulator = 0;
|
||||
break;
|
||||
|
||||
@@ -27,8 +27,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "materials.h" // For MaterialProperties and ToolDiggingProperties
|
||||
#include "gamedef.h"
|
||||
|
||||
core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
|
||||
|
||||
/* Some helper functions */
|
||||
|
||||
// Y is copied, X and Z change is limited
|
||||
|
||||
@@ -43,14 +43,25 @@ void set_default_settings(Settings *settings)
|
||||
settings->setDefault("keymap_rangeselect", "KEY_KEY_R");
|
||||
settings->setDefault("keymap_freemove", "KEY_KEY_K");
|
||||
settings->setDefault("keymap_fastmove", "KEY_KEY_J");
|
||||
settings->setDefault("keymap_frametime_graph", "KEY_F1");
|
||||
settings->setDefault("keymap_screenshot", "KEY_F12");
|
||||
settings->setDefault("keymap_toggle_profiler", "KEY_F2");
|
||||
settings->setDefault("keymap_toggle_hud", "KEY_F1");
|
||||
settings->setDefault("keymap_toggle_chat", "KEY_F2");
|
||||
settings->setDefault("keymap_toggle_force_fog_off", "KEY_F3");
|
||||
settings->setDefault("keymap_toggle_update_camera", "KEY_F4");
|
||||
settings->setDefault("keymap_toggle_debug", "KEY_F5");
|
||||
settings->setDefault("keymap_toggle_profiler", "KEY_F6");
|
||||
settings->setDefault("keymap_increase_viewing_range_min", "KEY_PRIOR");
|
||||
settings->setDefault("keymap_decrease_viewing_range_min", "KEY_NEXT");
|
||||
// Some (temporary) keys for debugging
|
||||
settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
|
||||
|
||||
// Show debug info by default?
|
||||
#ifdef NDEBUG
|
||||
settings->setDefault("show_debug", "false");
|
||||
#else
|
||||
settings->setDefault("show_debug", "true");
|
||||
#endif
|
||||
|
||||
settings->setDefault("wanted_fps", "30");
|
||||
settings->setDefault("fps_max", "60");
|
||||
settings->setDefault("viewing_range_nodes_max", "300");
|
||||
@@ -66,7 +77,6 @@ void set_default_settings(Settings *settings)
|
||||
settings->setDefault("new_style_water", "false");
|
||||
settings->setDefault("new_style_leaves", "false");
|
||||
settings->setDefault("smooth_lighting", "true");
|
||||
settings->setDefault("frametime_graph", "false");
|
||||
settings->setDefault("enable_texture_atlas", "true");
|
||||
settings->setDefault("texture_path", "");
|
||||
settings->setDefault("video_driver", "opengl");
|
||||
@@ -84,7 +94,7 @@ void set_default_settings(Settings *settings)
|
||||
// Server stuff
|
||||
// "map-dir" doesn't exist by default.
|
||||
settings->setDefault("motd", "");
|
||||
settings->setDefault("max_users", "20");
|
||||
settings->setDefault("max_users", "100");
|
||||
settings->setDefault("strict_protocol_version_checking", "true");
|
||||
settings->setDefault("creative_mode", "false");
|
||||
settings->setDefault("enable_damage", "true");
|
||||
|
||||
@@ -765,6 +765,21 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
|
||||
abmhandler.apply(block);
|
||||
}
|
||||
|
||||
core::list<MapNode> ServerEnvironment::getNodesInsideRadius(v3s16 pos, float radius)
|
||||
{
|
||||
core::list<MapNode> nodes;
|
||||
for (int i = pos.X - radius; i < pos.X + radius; i ++)
|
||||
for (int j = pos.Y - radius; j < pos.Y + radius; j ++)
|
||||
for (int k = pos.Z - radius; k < pos.Z + radius; k ++) {
|
||||
v3s16 current_pos = v3s16(i,j,k);
|
||||
if (current_pos.getDistanceFrom(pos) < radius) {
|
||||
MapNode n = m_map->getNodeNoEx(current_pos);
|
||||
nodes.push_back(n);
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
void ServerEnvironment::addActiveBlockModifier(ActiveBlockModifier *abm)
|
||||
{
|
||||
m_abms.push_back(ABMWithState(abm));
|
||||
|
||||
@@ -271,6 +271,9 @@ class ServerEnvironment : public Environment
|
||||
-------------------------------------------
|
||||
*/
|
||||
|
||||
// Find all nodes inside a radius around a point
|
||||
core::list<MapNode> getNodesInsideRadius(v3s16 pos, float radius);
|
||||
|
||||
// Find all active objects inside a radius around a point
|
||||
std::set<u16> getObjectsInsideRadius(v3f pos, float radius);
|
||||
|
||||
|
||||
378
src/game.cpp
378
src/game.cpp
@@ -634,6 +634,36 @@ void draw_load_screen(const std::wstring &text,
|
||||
//return guitext;
|
||||
}
|
||||
|
||||
/* Profiler display */
|
||||
|
||||
void update_profiler_gui(gui::IGUIStaticText *guitext_profiler,
|
||||
gui::IGUIFont *font, u32 text_height,
|
||||
u32 show_profiler, u32 show_profiler_max)
|
||||
{
|
||||
if(show_profiler == 0)
|
||||
{
|
||||
guitext_profiler->setVisible(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
g_profiler->printPage(os, show_profiler, show_profiler_max);
|
||||
std::wstring text = narrow_to_wide(os.str());
|
||||
guitext_profiler->setText(text.c_str());
|
||||
guitext_profiler->setVisible(true);
|
||||
|
||||
s32 w = font->getDimension(text.c_str()).Width;
|
||||
if(w < 400)
|
||||
w = 400;
|
||||
core::rect<s32> rect(6, 4+(text_height+5)*2, 12+w,
|
||||
8+(text_height+5)*2 +
|
||||
font->getDimension(text.c_str()).Height);
|
||||
guitext_profiler->setRelativePosition(rect);
|
||||
guitext_profiler->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
void the_game(
|
||||
bool &kill,
|
||||
bool random_input,
|
||||
@@ -932,6 +962,16 @@ void the_game(
|
||||
core::rect<s32>(0,0,400,text_height+5) + v2s32(100,200),
|
||||
false, false);
|
||||
|
||||
// Status text (displays info when showing and hiding GUI stuff, etc.)
|
||||
gui::IGUIStaticText *guitext_status = guienv->addStaticText(
|
||||
L"<Status>",
|
||||
core::rect<s32>(0,0,0,0),
|
||||
false, false);
|
||||
guitext_status->setVisible(false);
|
||||
|
||||
std::wstring statustext;
|
||||
float statustext_time = 0;
|
||||
|
||||
// Chat text
|
||||
gui::IGUIStaticText *guitext_chat = guienv->addStaticText(
|
||||
L"",
|
||||
@@ -944,8 +984,7 @@ void the_game(
|
||||
// Profiler text (size is updated when text is updated)
|
||||
gui::IGUIStaticText *guitext_profiler = guienv->addStaticText(
|
||||
L"<Profiler>",
|
||||
core::rect<s32>(6, 4+(text_height+5)*2, 400,
|
||||
(text_height+5)*2 + text_height*35),
|
||||
core::rect<s32>(0,0,0,0),
|
||||
false, false);
|
||||
guitext_profiler->setBackgroundColor(video::SColor(80,0,0,0));
|
||||
guitext_profiler->setVisible(false);
|
||||
@@ -968,11 +1007,6 @@ void the_game(
|
||||
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
|
||||
&g_menumgr))->drop();
|
||||
|
||||
// Enable texts
|
||||
/*guitext2->setVisible(true);
|
||||
guitext_info->setVisible(true);
|
||||
guitext_chat->setVisible(true);*/
|
||||
|
||||
//s32 guitext_chat_pad_bottom = 70;
|
||||
|
||||
/*
|
||||
@@ -1008,9 +1042,14 @@ void the_game(
|
||||
bool respawn_menu_active = false;
|
||||
bool update_wielded_item_trigger = false;
|
||||
|
||||
bool show_profiler = false;
|
||||
bool show_hud = true;
|
||||
bool show_chat = true;
|
||||
bool force_fog_off = false;
|
||||
bool disable_camera_update = false;
|
||||
bool show_debug = g_settings->getBool("show_debug");
|
||||
bool show_debug_frametime = false;
|
||||
u32 show_profiler = 0;
|
||||
u32 show_profiler_max = 3; // Number of pages
|
||||
|
||||
/*
|
||||
Main loop
|
||||
@@ -1247,20 +1286,10 @@ void the_game(
|
||||
g_profiler->print(infostream);
|
||||
}
|
||||
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
g_profiler->print(os);
|
||||
std::wstring text = narrow_to_wide(os.str());
|
||||
guitext_profiler->setText(text.c_str());
|
||||
update_profiler_gui(guitext_profiler, font, text_height,
|
||||
show_profiler, show_profiler_max);
|
||||
|
||||
g_profiler->clear();
|
||||
|
||||
s32 w = font->getDimension(text.c_str()).Width;
|
||||
if(w < 400)
|
||||
w = 400;
|
||||
core::rect<s32> rect(6, 4+(text_height+5)*2, 12+w,
|
||||
8+(text_height+5)*2 +
|
||||
font->getDimension(text.c_str()).Height);
|
||||
guitext_profiler->setRelativePosition(rect);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1349,12 +1378,14 @@ void the_game(
|
||||
if(g_settings->getBool("free_move"))
|
||||
{
|
||||
g_settings->set("free_move","false");
|
||||
chat_lines.push_back(ChatLine(L"free_move disabled"));
|
||||
statustext = L"free_move disabled";
|
||||
statustext_time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_settings->set("free_move","true");
|
||||
chat_lines.push_back(ChatLine(L"free_move enabled"));
|
||||
statustext = L"free_move enabled";
|
||||
statustext_time = 0;
|
||||
}
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
|
||||
@@ -1362,25 +1393,14 @@ void the_game(
|
||||
if(g_settings->getBool("fast_move"))
|
||||
{
|
||||
g_settings->set("fast_move","false");
|
||||
chat_lines.push_back(ChatLine(L"fast_move disabled"));
|
||||
statustext = L"fast_move disabled";
|
||||
statustext_time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_settings->set("fast_move","true");
|
||||
chat_lines.push_back(ChatLine(L"fast_move enabled"));
|
||||
}
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_frametime_graph")))
|
||||
{
|
||||
if(g_settings->getBool("frametime_graph"))
|
||||
{
|
||||
g_settings->set("frametime_graph","false");
|
||||
chat_lines.push_back(ChatLine(L"frametime_graph disabled"));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_settings->set("frametime_graph","true");
|
||||
chat_lines.push_back(ChatLine(L"frametime_graph enabled"));
|
||||
statustext = L"fast_move enabled";
|
||||
statustext_time = 0;
|
||||
}
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_screenshot")))
|
||||
@@ -1395,37 +1415,120 @@ void the_game(
|
||||
std::wstringstream sstr;
|
||||
sstr<<"Saved screenshot to '"<<filename<<"'";
|
||||
infostream<<"Saved screenshot to '"<<filename<<"'"<<std::endl;
|
||||
chat_lines.push_back(ChatLine(sstr.str()));
|
||||
statustext = sstr.str();
|
||||
statustext_time = 0;
|
||||
} else{
|
||||
infostream<<"Failed to save screenshot '"<<filename<<"'"<<std::endl;
|
||||
}
|
||||
image->drop();
|
||||
}
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_toggle_profiler")))
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_toggle_hud")))
|
||||
{
|
||||
show_profiler = !show_profiler;
|
||||
guitext_profiler->setVisible(show_profiler);
|
||||
if(show_profiler)
|
||||
chat_lines.push_back(ChatLine(L"Profiler disabled"));
|
||||
show_hud = !show_hud;
|
||||
if(show_hud)
|
||||
statustext = L"HUD shown";
|
||||
else
|
||||
chat_lines.push_back(ChatLine(L"Profiler enabled"));
|
||||
statustext = L"HUD hidden";
|
||||
statustext_time = 0;
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_toggle_chat")))
|
||||
{
|
||||
show_chat = !show_chat;
|
||||
if(show_chat)
|
||||
statustext = L"Chat shown";
|
||||
else
|
||||
statustext = L"Chat hidden";
|
||||
statustext_time = 0;
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_toggle_force_fog_off")))
|
||||
{
|
||||
force_fog_off = !force_fog_off;
|
||||
if(force_fog_off)
|
||||
chat_lines.push_back(ChatLine(L"Fog disabled"));
|
||||
statustext = L"Fog disabled";
|
||||
else
|
||||
chat_lines.push_back(ChatLine(L"Fog enabled"));
|
||||
statustext = L"Fog enabled";
|
||||
statustext_time = 0;
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_toggle_update_camera")))
|
||||
{
|
||||
disable_camera_update = !disable_camera_update;
|
||||
if(disable_camera_update)
|
||||
chat_lines.push_back(ChatLine(L"Camera update disabled"));
|
||||
statustext = L"Camera update disabled";
|
||||
else
|
||||
chat_lines.push_back(ChatLine(L"Camera update enabled"));
|
||||
statustext = L"Camera update enabled";
|
||||
statustext_time = 0;
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_toggle_debug")))
|
||||
{
|
||||
// Initial / 3x toggle: Chat only
|
||||
// 1x toggle: Debug text with chat
|
||||
// 2x toggle: Debug text with frametime
|
||||
if(!show_debug)
|
||||
{
|
||||
show_debug = true;
|
||||
show_debug_frametime = false;
|
||||
statustext = L"Debug info shown";
|
||||
statustext_time = 0;
|
||||
}
|
||||
else if(show_debug_frametime)
|
||||
{
|
||||
show_debug = false;
|
||||
show_debug_frametime = false;
|
||||
statustext = L"Debug info and frametime graph hidden";
|
||||
statustext_time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
show_debug_frametime = true;
|
||||
statustext = L"Frametime graph shown";
|
||||
statustext_time = 0;
|
||||
}
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_toggle_profiler")))
|
||||
{
|
||||
show_profiler = (show_profiler + 1) % (show_profiler_max + 1);
|
||||
|
||||
// FIXME: This updates the profiler with incomplete values
|
||||
update_profiler_gui(guitext_profiler, font, text_height,
|
||||
show_profiler, show_profiler_max);
|
||||
|
||||
if(show_profiler != 0)
|
||||
{
|
||||
std::wstringstream sstr;
|
||||
sstr<<"Profiler shown (page "<<show_profiler
|
||||
<<" of "<<show_profiler_max<<")";
|
||||
statustext = sstr.str();
|
||||
statustext_time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
statustext = L"Profiler hidden";
|
||||
statustext_time = 0;
|
||||
}
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_increase_viewing_range_min")))
|
||||
{
|
||||
s16 range = g_settings->getS16("viewing_range_nodes_min");
|
||||
s16 range_new = range + 10;
|
||||
g_settings->set("viewing_range_nodes_min", itos(range_new));
|
||||
statustext = narrow_to_wide(
|
||||
"Minimum viewing range changed to "
|
||||
+ itos(range_new));
|
||||
statustext_time = 0;
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_decrease_viewing_range_min")))
|
||||
{
|
||||
s16 range = g_settings->getS16("viewing_range_nodes_min");
|
||||
s16 range_new = range - 10;
|
||||
if(range_new < 0)
|
||||
range_new = range;
|
||||
g_settings->set("viewing_range_nodes_min",
|
||||
itos(range_new));
|
||||
statustext = narrow_to_wide(
|
||||
"Minimum viewing range changed to "
|
||||
+ itos(range_new));
|
||||
statustext_time = 0;
|
||||
}
|
||||
|
||||
// Item selection with mouse wheel
|
||||
@@ -1470,15 +1573,18 @@ void the_game(
|
||||
// Viewing range selection
|
||||
if(input->wasKeyDown(getKeySetting("keymap_rangeselect")))
|
||||
{
|
||||
draw_control.range_all = !draw_control.range_all;
|
||||
if(draw_control.range_all)
|
||||
{
|
||||
draw_control.range_all = false;
|
||||
infostream<<"Disabled full viewing range"<<std::endl;
|
||||
infostream<<"Enabled full viewing range"<<std::endl;
|
||||
statustext = L"Enabled full viewing range";
|
||||
statustext_time = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
draw_control.range_all = true;
|
||||
infostream<<"Enabled full viewing range"<<std::endl;
|
||||
infostream<<"Disabled full viewing range"<<std::endl;
|
||||
statustext = L"Disabled full viewing range";
|
||||
statustext_time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2105,55 +2211,110 @@ void the_game(
|
||||
|
||||
//TimeTaker guiupdatetimer("Gui updating");
|
||||
|
||||
const char program_name_and_version[] =
|
||||
"Minetest-c55 " VERSION_STRING;
|
||||
|
||||
if(show_debug)
|
||||
{
|
||||
static float drawtime_avg = 0;
|
||||
drawtime_avg = drawtime_avg * 0.95 + (float)drawtime*0.05;
|
||||
static float beginscenetime_avg = 0;
|
||||
/*static float beginscenetime_avg = 0;
|
||||
beginscenetime_avg = beginscenetime_avg * 0.95 + (float)beginscenetime*0.05;
|
||||
static float scenetime_avg = 0;
|
||||
scenetime_avg = scenetime_avg * 0.95 + (float)scenetime*0.05;
|
||||
static float endscenetime_avg = 0;
|
||||
endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;
|
||||
endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05;*/
|
||||
|
||||
char temptext[300];
|
||||
snprintf(temptext, 300, "Minetest-c55 %s ("
|
||||
snprintf(temptext, 300, "%s ("
|
||||
"R: range_all=%i"
|
||||
")"
|
||||
" drawtime=%.0f, beginscenetime=%.0f"
|
||||
", scenetime=%.0f, endscenetime=%.0f",
|
||||
VERSION_STRING,
|
||||
" drawtime=%.0f, dtime_jitter = % .1f %%"
|
||||
", v_range = %.1f, RTT = %.3f",
|
||||
program_name_and_version,
|
||||
draw_control.range_all,
|
||||
drawtime_avg,
|
||||
beginscenetime_avg,
|
||||
scenetime_avg,
|
||||
endscenetime_avg
|
||||
);
|
||||
|
||||
guitext->setText(narrow_to_wide(temptext).c_str());
|
||||
}
|
||||
|
||||
{
|
||||
char temptext[300];
|
||||
snprintf(temptext, 300,
|
||||
"(% .1f, % .1f, % .1f)"
|
||||
" (% .3f < btime_jitter < % .3f"
|
||||
", dtime_jitter = % .1f %%"
|
||||
", v_range = %.1f, RTT = %.3f)",
|
||||
player_position.X/BS,
|
||||
player_position.Y/BS,
|
||||
player_position.Z/BS,
|
||||
busytime_jitter1_min_sample,
|
||||
busytime_jitter1_max_sample,
|
||||
dtime_jitter1_max_fraction * 100.0,
|
||||
draw_control.wanted_range,
|
||||
client.getRTT()
|
||||
);
|
||||
|
||||
guitext->setText(narrow_to_wide(temptext).c_str());
|
||||
guitext->setVisible(true);
|
||||
}
|
||||
else if(show_hud || show_chat)
|
||||
{
|
||||
guitext->setText(narrow_to_wide(program_name_and_version).c_str());
|
||||
guitext->setVisible(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
guitext->setVisible(false);
|
||||
}
|
||||
|
||||
if(show_debug)
|
||||
{
|
||||
char temptext[300];
|
||||
snprintf(temptext, 300,
|
||||
"(% .1f, % .1f, % .1f)"
|
||||
" (yaw = %.1f)",
|
||||
player_position.X/BS,
|
||||
player_position.Y/BS,
|
||||
player_position.Z/BS,
|
||||
wrapDegrees_0_360(camera_yaw));
|
||||
|
||||
guitext2->setText(narrow_to_wide(temptext).c_str());
|
||||
guitext2->setVisible(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
guitext2->setVisible(false);
|
||||
}
|
||||
|
||||
{
|
||||
guitext_info->setText(infotext.c_str());
|
||||
guitext_info->setVisible(show_hud);
|
||||
}
|
||||
|
||||
{
|
||||
float statustext_time_max = 3.0;
|
||||
if(!statustext.empty())
|
||||
{
|
||||
statustext_time += dtime;
|
||||
if(statustext_time >= statustext_time_max)
|
||||
{
|
||||
statustext = L"";
|
||||
statustext_time = 0;
|
||||
}
|
||||
}
|
||||
guitext_status->setText(statustext.c_str());
|
||||
guitext_status->setVisible(!statustext.empty());
|
||||
|
||||
if(!statustext.empty())
|
||||
{
|
||||
s32 status_y = screensize.Y - 130;
|
||||
core::rect<s32> rect(
|
||||
10,
|
||||
status_y - guitext_status->getTextHeight(),
|
||||
screensize.X - 10,
|
||||
status_y
|
||||
);
|
||||
guitext_status->setRelativePosition(rect);
|
||||
|
||||
// Fade out
|
||||
video::SColor initial_color(255,0,0,0);
|
||||
if(guienv->getSkin())
|
||||
initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
|
||||
video::SColor final_color = initial_color;
|
||||
final_color.setAlpha(0);
|
||||
video::SColor fade_color =
|
||||
initial_color.getInterpolated_quadratic(
|
||||
initial_color,
|
||||
final_color,
|
||||
statustext_time / (float) statustext_time_max);
|
||||
guitext_status->setOverrideColor(fade_color);
|
||||
guitext_status->enableOverrideColor(true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2224,20 +2385,22 @@ void the_game(
|
||||
screensize.X - 10,
|
||||
screensize.Y - guitext_chat_pad_bottom
|
||||
);*/
|
||||
|
||||
s32 chat_y = 5+(text_height+5);
|
||||
if(show_debug)
|
||||
chat_y += (text_height+5);
|
||||
core::rect<s32> rect(
|
||||
10,
|
||||
50,
|
||||
chat_y,
|
||||
screensize.X - 10,
|
||||
50 + guitext_chat->getTextHeight()
|
||||
chat_y + guitext_chat->getTextHeight()
|
||||
);
|
||||
|
||||
guitext_chat->setRelativePosition(rect);
|
||||
|
||||
// Don't show chat if empty or profiler is enabled
|
||||
if(chat_lines.size() == 0 || show_profiler)
|
||||
guitext_chat->setVisible(false);
|
||||
else
|
||||
guitext_chat->setVisible(true);
|
||||
// Don't show chat if empty or profiler or debug is enabled
|
||||
guitext_chat->setVisible(chat_lines.size() != 0
|
||||
&& show_chat && show_profiler == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2275,7 +2438,7 @@ void the_game(
|
||||
|
||||
{
|
||||
TimeTaker timer("beginScene");
|
||||
driver->beginScene(true, true, bgcolor);
|
||||
driver->beginScene(false, true, bgcolor);
|
||||
//driver->beginScene(false, true, bgcolor);
|
||||
beginscenetime = timer.stop(true);
|
||||
}
|
||||
@@ -2305,20 +2468,24 @@ void the_game(
|
||||
|
||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||
|
||||
for(core::list< core::aabbox3d<f32> >::Iterator i=hilightboxes.begin();
|
||||
i != hilightboxes.end(); i++)
|
||||
if(show_hud)
|
||||
{
|
||||
/*infostream<<"hilightbox min="
|
||||
<<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
|
||||
<<" max="
|
||||
<<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
|
||||
<<std::endl;*/
|
||||
driver->draw3DBox(*i, video::SColor(255,0,0,0));
|
||||
for(core::list<aabb3f>::Iterator i=hilightboxes.begin();
|
||||
i != hilightboxes.end(); i++)
|
||||
{
|
||||
/*infostream<<"hilightbox min="
|
||||
<<"("<<i->MinEdge.X<<","<<i->MinEdge.Y<<","<<i->MinEdge.Z<<")"
|
||||
<<" max="
|
||||
<<"("<<i->MaxEdge.X<<","<<i->MaxEdge.Y<<","<<i->MaxEdge.Z<<")"
|
||||
<<std::endl;*/
|
||||
driver->draw3DBox(*i, video::SColor(255,0,0,0));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Wielded tool
|
||||
*/
|
||||
if(show_hud)
|
||||
{
|
||||
// Warning: This clears the Z buffer.
|
||||
camera.drawWieldedTool();
|
||||
@@ -2334,16 +2501,17 @@ void the_game(
|
||||
/*
|
||||
Frametime log
|
||||
*/
|
||||
if(g_settings->getBool("frametime_graph") == true)
|
||||
if(show_debug_frametime)
|
||||
{
|
||||
s32 x = 10;
|
||||
s32 y = screensize.Y - 10;
|
||||
for(core::list<float>::Iterator
|
||||
i = frametime_log.begin();
|
||||
i != frametime_log.end();
|
||||
i++)
|
||||
{
|
||||
driver->draw2DLine(v2s32(x,50),
|
||||
v2s32(x,50+(*i)*1000),
|
||||
driver->draw2DLine(v2s32(x,y),
|
||||
v2s32(x,y-(*i)*1000),
|
||||
video::SColor(255,255,255,255));
|
||||
x++;
|
||||
}
|
||||
@@ -2352,12 +2520,15 @@ void the_game(
|
||||
/*
|
||||
Draw crosshair
|
||||
*/
|
||||
driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
|
||||
displaycenter + core::vector2d<s32>(10,0),
|
||||
video::SColor(255,255,255,255));
|
||||
driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
|
||||
displaycenter + core::vector2d<s32>(0,10),
|
||||
video::SColor(255,255,255,255));
|
||||
if(show_hud)
|
||||
{
|
||||
driver->draw2DLine(displaycenter - core::vector2d<s32>(10,0),
|
||||
displaycenter + core::vector2d<s32>(10,0),
|
||||
video::SColor(255,255,255,255));
|
||||
driver->draw2DLine(displaycenter - core::vector2d<s32>(0,10),
|
||||
displaycenter + core::vector2d<s32>(0,10),
|
||||
video::SColor(255,255,255,255));
|
||||
}
|
||||
|
||||
} // timer
|
||||
|
||||
@@ -2373,6 +2544,7 @@ void the_game(
|
||||
/*
|
||||
Draw hotbar
|
||||
*/
|
||||
if(show_hud)
|
||||
{
|
||||
draw_hotbar(driver, font, gamedef,
|
||||
v2s32(displaycenter.X, screensize.Y),
|
||||
|
||||
@@ -103,6 +103,7 @@ struct InventoryAction
|
||||
virtual void apply(InventoryManager *mgr, ServerActiveObject *player,
|
||||
IGameDef *gamedef) = 0;
|
||||
virtual void clientApply(InventoryManager *mgr, IGameDef *gamedef) = 0;
|
||||
virtual ~InventoryAction() {};
|
||||
};
|
||||
|
||||
struct IMoveAction : public InventoryAction
|
||||
|
||||
@@ -20,6 +20,56 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "light.h"
|
||||
|
||||
#if 1
|
||||
/*
|
||||
Made using this and adding 230 as the second last one:
|
||||
|
||||
#!/usr/bin/python
|
||||
|
||||
from math import *
|
||||
from sys import stdout
|
||||
|
||||
# We want 0 at light=0 and 255 at light=LIGHT_MAX
|
||||
LIGHT_MAX = 14
|
||||
#FACTOR = 0.69
|
||||
#FACTOR = 0.75
|
||||
FACTOR = 0.83
|
||||
START_FROM_ZERO = False
|
||||
|
||||
L = []
|
||||
if START_FROM_ZERO:
|
||||
for i in range(1,LIGHT_MAX+1):
|
||||
L.append(int(round(255.0 * FACTOR ** (i-1))))
|
||||
L.append(0)
|
||||
else:
|
||||
for i in range(1,LIGHT_MAX+1):
|
||||
L.append(int(round(255.0 * FACTOR ** (i-1))))
|
||||
L.append(255)
|
||||
|
||||
L.reverse()
|
||||
for i in L:
|
||||
stdout.write(str(i)+",\n")
|
||||
*/
|
||||
u8 light_decode_table[LIGHT_MAX+1] =
|
||||
{
|
||||
23,
|
||||
27,
|
||||
33,
|
||||
40,
|
||||
48,
|
||||
57,
|
||||
69,
|
||||
83,
|
||||
100,
|
||||
121,
|
||||
146,
|
||||
176,
|
||||
212,
|
||||
230,
|
||||
255,
|
||||
};
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// This is good
|
||||
// a_n+1 = a_n * 0.786
|
||||
// Length of LIGHT_MAX+1 means LIGHT_MAX is the last value.
|
||||
@@ -42,7 +92,9 @@ u8 light_decode_table[LIGHT_MAX+1] =
|
||||
200,
|
||||
255,
|
||||
};
|
||||
#else
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// Use for debugging in dark
|
||||
u8 light_decode_table[LIGHT_MAX+1] =
|
||||
{
|
||||
|
||||
153
src/mesh.cpp
153
src/mesh.cpp
@@ -33,7 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#define MY_ETLM_READ_ONLY video::ETLM_READ_ONLY
|
||||
#endif
|
||||
|
||||
scene::IAnimatedMesh* createCubeMesh(v3f scale)
|
||||
scene::IAnimatedMesh* createCubeMesh(v3f scale,bool allfaces)
|
||||
{
|
||||
video::SColor c(255,255,255,255);
|
||||
video::S3DVertex vertices[24] =
|
||||
@@ -86,6 +86,157 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale)
|
||||
buf->drop();
|
||||
}
|
||||
|
||||
if (allfaces) {
|
||||
video::S3DVertex vertices[24] =
|
||||
{
|
||||
// Up
|
||||
video::S3DVertex(-0.5,-0.5,-0.5, 0,1,0, c, 0,1),
|
||||
video::S3DVertex(-0.5,-0.5,+0.5, 0,1,0, c, 0,0),
|
||||
video::S3DVertex(+0.5,-0.5,+0.5, 0,1,0, c, 1,0),
|
||||
video::S3DVertex(+0.5,-0.5,-0.5, 0,1,0, c, 1,1),
|
||||
// Down
|
||||
video::S3DVertex(-0.5,+0.5,-0.5, 0,-1,0, c, 0,0),
|
||||
video::S3DVertex(+0.5,+0.5,-0.5, 0,-1,0, c, 1,0),
|
||||
video::S3DVertex(+0.5,+0.5,+0.5, 0,-1,0, c, 1,1),
|
||||
video::S3DVertex(-0.5,+0.5,+0.5, 0,-1,0, c, 0,1),
|
||||
// Right
|
||||
video::S3DVertex(-0.5,-0.5,-0.5, 1,0,0, c, 0,1),
|
||||
video::S3DVertex(-0.5,+0.5,-0.5, 1,0,0, c, 0,0),
|
||||
video::S3DVertex(-0.5,+0.5,+0.5, 1,0,0, c, 1,0),
|
||||
video::S3DVertex(-0.5,-0.5,+0.5, 1,0,0, c, 1,1),
|
||||
// Left
|
||||
video::S3DVertex(+0.5,-0.5,-0.5, -1,0,0, c, 1,1),
|
||||
video::S3DVertex(+0.5,-0.5,+0.5, -1,0,0, c, 0,1),
|
||||
video::S3DVertex(+0.5,+0.5,+0.5, -1,0,0, c, 0,0),
|
||||
video::S3DVertex(+0.5,+0.5,-0.5, -1,0,0, c, 1,0),
|
||||
// Back
|
||||
video::S3DVertex(-0.5,-0.5,-0.5, 0,0,1, c, 1,1),
|
||||
video::S3DVertex(+0.5,-0.5,-0.5, 0,0,1, c, 0,1),
|
||||
video::S3DVertex(+0.5,+0.5,-0.5, 0,0,1, c, 0,0),
|
||||
video::S3DVertex(-0.5,+0.5,-0.5, 0,0,1, c, 1,0),
|
||||
// Front
|
||||
video::S3DVertex(-0.5,-0.5,+0.5, 0,0,-1, c, 0,1),
|
||||
video::S3DVertex(-0.5,+0.5,+0.5, 0,0,-1, c, 0,0),
|
||||
video::S3DVertex(+0.5,+0.5,+0.5, 0,0,-1, c, 1,0),
|
||||
video::S3DVertex(+0.5,-0.5,+0.5, 0,0,-1, c, 1,1),
|
||||
};
|
||||
|
||||
u16 indices[6] = {0,1,2,2,3,0};
|
||||
|
||||
for (u32 i=0; i<6; ++i)
|
||||
{
|
||||
scene::IMeshBuffer *buf = new scene::SMeshBuffer();
|
||||
buf->append(vertices + 4 * i, 4, indices, 6);
|
||||
// Set default material
|
||||
buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
|
||||
buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
|
||||
buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
|
||||
// Add mesh buffer to mesh
|
||||
mesh->addMeshBuffer(buf);
|
||||
buf->drop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
|
||||
mesh->drop();
|
||||
scaleMesh(anim_mesh, scale); // also recalculates bounding box
|
||||
return anim_mesh;
|
||||
}
|
||||
|
||||
scene::IAnimatedMesh* createCubeMesh(v3f scale,core::aabbox3d<f32> box)
|
||||
{
|
||||
video::SColor c(255,255,255,255);
|
||||
video::S3DVertex vertices[24] =
|
||||
{
|
||||
// Up
|
||||
video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,1,0, c, 0,1),
|
||||
video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,1,0, c, 0,0),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,1,0, c, 1,0),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,1,0, c, 1,1),
|
||||
// Down
|
||||
video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,-1,0, c, 0,0),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,-1,0, c, 1,0),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,-1,0, c, 1,1),
|
||||
video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,-1,0, c, 0,1),
|
||||
// Right
|
||||
video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MinEdge.Z, 1,0,0, c, 0,1),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 1,0,0, c, 0,0),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 1,0,0, c, 1,0),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 1,0,0, c, 1,1),
|
||||
// Left
|
||||
video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MinEdge.Z, -1,0,0, c, 1,1),
|
||||
video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MaxEdge.Z, -1,0,0, c, 0,1),
|
||||
video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, -1,0,0, c, 0,0),
|
||||
video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MinEdge.Z, -1,0,0, c, 1,0),
|
||||
// Back
|
||||
video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,0,1, c, 1,1),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,0,1, c, 0,1),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,0,1, c, 0,0),
|
||||
video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,0,1, c, 1,0),
|
||||
// Front
|
||||
video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,0,-1, c, 0,1),
|
||||
video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,0,-1, c, 0,0),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,0,-1, c, 1,0),
|
||||
video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,0,-1, c, 1,1),
|
||||
};
|
||||
|
||||
u16 indices[6] = {0,1,2,2,3,0};
|
||||
|
||||
scene::SMesh *mesh = new scene::SMesh();
|
||||
for (u32 i=0; i<6; ++i)
|
||||
{
|
||||
scene::IMeshBuffer *buf = new scene::SMeshBuffer();
|
||||
buf->append(vertices + 4 * i, 4, indices, 6);
|
||||
mesh->addMeshBuffer(buf);
|
||||
buf->drop();
|
||||
}
|
||||
scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
|
||||
mesh->drop();
|
||||
scaleMesh(anim_mesh, scale); // also recalculates bounding box
|
||||
return anim_mesh;
|
||||
}
|
||||
|
||||
scene::IAnimatedMesh* createPlantMesh(v3f scale)
|
||||
{
|
||||
video::SColor c(255,255,255,255);
|
||||
video::S3DVertex vertices[16] =
|
||||
{
|
||||
// Plane 1 Front
|
||||
video::S3DVertex(-0.5,-0.5,-0.5, 0.5,0,-0.5, c, 0,1),
|
||||
video::S3DVertex(-0.5,+0.5,-0.5, 0.5,0,-0.5, c, 0,0),
|
||||
video::S3DVertex(+0.5,+0.5,+0.5, 0.5,0,-0.5, c, 1,0),
|
||||
video::S3DVertex(+0.5,-0.5,+0.5, 0.5,0,-0.5, c, 1,1),
|
||||
// Plane 1 Back
|
||||
video::S3DVertex(+0.5,-0.5,+0.5, -0.5,0,0.5, c, 1,1),
|
||||
video::S3DVertex(+0.5,+0.5,+0.5, -0.5,0,0.5, c, 1,0),
|
||||
video::S3DVertex(-0.5,+0.5,-0.5, -0.5,0,0.5, c, 0,0),
|
||||
video::S3DVertex(-0.5,-0.5,-0.5, -0.5,0,0.5, c, 0,1),
|
||||
|
||||
// Plane 2 Front
|
||||
video::S3DVertex(-0.5,-0.5,+0.5, -0.5,0,-0.5, c, 1,1),
|
||||
video::S3DVertex(-0.5,+0.5,+0.5, -0.5,0,-0.5, c, 1,0),
|
||||
video::S3DVertex(+0.5,+0.5,-0.5, -0.5,0,-0.5, c, 0,0),
|
||||
video::S3DVertex(+0.5,-0.5,-0.5, -0.5,0,-0.5, c, 0,1),
|
||||
|
||||
// Plane 2 Back
|
||||
video::S3DVertex(+0.5,-0.5,-0.5, 0.5,0,0.5, c, 0,1),
|
||||
video::S3DVertex(+0.5,+0.5,-0.5, 0.5,0,0.5, c, 0,0),
|
||||
video::S3DVertex(-0.5,+0.5,+0.5, 0.5,0,0.5, c, 1,0),
|
||||
video::S3DVertex(-0.5,-0.5,+0.5, 0.5,0,0.5, c, 1,1)
|
||||
|
||||
};
|
||||
|
||||
u16 indices[6] = {0,1,2,2,3,0};
|
||||
|
||||
scene::SMesh *mesh = new scene::SMesh();
|
||||
for (u32 i=0; i<4; ++i)
|
||||
{
|
||||
scene::IMeshBuffer *buf = new scene::SMeshBuffer();
|
||||
buf->append(vertices + 4 * i, 4, indices, 6);
|
||||
mesh->addMeshBuffer(buf);
|
||||
buf->drop();
|
||||
}
|
||||
scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
|
||||
mesh->drop();
|
||||
scaleMesh(anim_mesh, scale); // also recalculates bounding box
|
||||
|
||||
21
src/mesh.h
21
src/mesh.h
@@ -30,7 +30,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
The resulting mesh has 6 materials (up, down, right, left, back, front)
|
||||
which must be defined by the caller.
|
||||
*/
|
||||
scene::IAnimatedMesh* createCubeMesh(v3f scale);
|
||||
scene::IAnimatedMesh* createCubeMesh(v3f scale, bool allfaces=false);
|
||||
|
||||
/*
|
||||
Create a new cube mesh not linked to mapnode size.
|
||||
Vertices are defined by given box.
|
||||
|
||||
The resulting mesh has 6 materials (up, down, right, left, back, front)
|
||||
which must be defined by the caller.
|
||||
*/
|
||||
scene::IAnimatedMesh* createCubeMesh(v3f scale,core::aabbox3d<f32> box);
|
||||
|
||||
/*
|
||||
Create a new extruded mesh from a texture.
|
||||
@@ -42,6 +51,16 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale);
|
||||
scene::IAnimatedMesh* createExtrudedMesh(video::ITexture *texture,
|
||||
video::IVideoDriver *driver, v3f scale);
|
||||
|
||||
|
||||
/*
|
||||
Create a new plant style mesh.
|
||||
Vertices are at (+-scale.X/2, +-scale.Y/2, +-scale.Z/2).
|
||||
|
||||
The resulting mesh has 4 materials (right, left, back, front)
|
||||
which must be defined by the caller.
|
||||
*/
|
||||
scene::IAnimatedMesh* createPlantMesh(v3f scale);
|
||||
|
||||
/*
|
||||
Multiplies each vertex coordinate by the specified scaling factors
|
||||
(componentwise vector multiplication).
|
||||
|
||||
@@ -156,10 +156,6 @@ void Player::deSerialize(std::istream &is)
|
||||
setPitch(args.getFloat("pitch"));
|
||||
setYaw(args.getFloat("yaw"));
|
||||
setPosition(args.getV3F("position"));
|
||||
bool craftresult_is_preview = true;
|
||||
try{
|
||||
craftresult_is_preview = args.getBool("craftresult_is_preview");
|
||||
}catch(SettingNotFoundException &e){}
|
||||
try{
|
||||
hp = args.getS32("hp");
|
||||
}catch(SettingNotFoundException &e){
|
||||
@@ -173,6 +169,9 @@ void Player::deSerialize(std::istream &is)
|
||||
// Convert players without craftpreview
|
||||
inventory.addList("craftpreview", 1);
|
||||
|
||||
bool craftresult_is_preview = true;
|
||||
if(args.exists("craftresult_is_preview"))
|
||||
craftresult_is_preview = args.getBool("craftresult_is_preview");
|
||||
if(craftresult_is_preview)
|
||||
{
|
||||
// Clear craftresult
|
||||
|
||||
@@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
class Map;
|
||||
class IGameDef;
|
||||
class CollisionInfo;
|
||||
struct CollisionInfo;
|
||||
|
||||
class Player
|
||||
{
|
||||
|
||||
@@ -99,12 +99,31 @@ class Profiler
|
||||
}
|
||||
|
||||
void print(std::ostream &o)
|
||||
{
|
||||
printPage(o, 1, 1);
|
||||
}
|
||||
|
||||
void printPage(std::ostream &o, u32 page, u32 pagecount)
|
||||
{
|
||||
JMutexAutoLock lock(m_mutex);
|
||||
|
||||
u32 minindex, maxindex;
|
||||
paging(m_data.size(), page, pagecount, minindex, maxindex);
|
||||
|
||||
for(core::map<std::string, float>::Iterator
|
||||
i = m_data.getIterator();
|
||||
i.atEnd() == false; i++)
|
||||
{
|
||||
if(maxindex == 0)
|
||||
break;
|
||||
maxindex--;
|
||||
|
||||
if(minindex != 0)
|
||||
{
|
||||
minindex--;
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string name = i.getNode()->getKey();
|
||||
int avgcount = 1;
|
||||
core::map<std::string, int>::Node *n = m_avgcounts.find(name);
|
||||
|
||||
@@ -45,6 +45,7 @@ extern "C" {
|
||||
#include "mapblock.h" // For getNodeBlockPos
|
||||
#include "content_nodemeta.h"
|
||||
#include "utility.h"
|
||||
#include "serverlinkableobject.h"
|
||||
|
||||
static void stackDump(lua_State *L, std::ostream &o)
|
||||
{
|
||||
@@ -2211,7 +2212,7 @@ class ObjectRef
|
||||
get_server(L)->SendMovePlayer(player);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// moveto(self, pos, continuous=false)
|
||||
static int l_moveto(lua_State *L)
|
||||
{
|
||||
@@ -2540,6 +2541,62 @@ class ObjectRef
|
||||
return 1;
|
||||
}
|
||||
|
||||
// link(parent, offset)
|
||||
static int l_link(lua_State *L)
|
||||
{
|
||||
ObjectRef *ref_child = checkobject(L, 1);
|
||||
ObjectRef *ref_parent = checkobject(L, 2);
|
||||
v3f offset = checkFloatPos(L, 3);
|
||||
|
||||
ServerActiveObject *child = getobject(ref_child);
|
||||
ServerActiveObject *parent = getobject(ref_parent);
|
||||
|
||||
if ((child == NULL) || (parent == NULL)) {
|
||||
errorstream << "LUA: link(): invalid parameters" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ServerLinkableObject* child_lua = dynamic_cast<ServerLinkableObject*>(child);
|
||||
ServerLinkableObject* parent_lua = dynamic_cast<ServerLinkableObject*>(parent);
|
||||
|
||||
if (child_lua == NULL) return 0;
|
||||
if (parent_lua == NULL) return 0;
|
||||
|
||||
if (child_lua->linkEntity(parent,offset)) {
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// unlink()
|
||||
static int l_unlink(lua_State *L)
|
||||
{
|
||||
ObjectRef *ref = checkobject(L, 1);
|
||||
|
||||
ServerActiveObject *obj = getobject(ref);
|
||||
|
||||
if (obj == NULL) {
|
||||
errorstream << "LUA: unlink(): invalid parameters" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ServerLinkableObject* tolink = dynamic_cast<ServerLinkableObject*>(obj);
|
||||
|
||||
if (tolink == NULL) return 0;
|
||||
|
||||
if (tolink->unlinkEntity()) {
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
ObjectRef(ServerActiveObject *object):
|
||||
m_object(object)
|
||||
@@ -2633,6 +2690,8 @@ const luaL_reg ObjectRef::methods[] = {
|
||||
method(ObjectRef, get_look_dir),
|
||||
method(ObjectRef, get_look_pitch),
|
||||
method(ObjectRef, get_look_yaw),
|
||||
method(ObjectRef, link),
|
||||
method(ObjectRef, unlink),
|
||||
{0,0}
|
||||
};
|
||||
|
||||
@@ -2913,6 +2972,67 @@ class EnvRef
|
||||
return 1;
|
||||
}
|
||||
|
||||
// EnvRef:get_objects_inside_radius(pos, radius)
|
||||
static int l_get_nodes_inside_radius(lua_State *L)
|
||||
{
|
||||
// Get the table insert function
|
||||
lua_getglobal(L, "table");
|
||||
lua_getfield(L, -1, "insert");
|
||||
int table_insert = lua_gettop(L);
|
||||
// Get environemnt
|
||||
EnvRef *o = checkobject(L, 1);
|
||||
ServerEnvironment *env = o->m_env;
|
||||
if(env == NULL) return 0;
|
||||
// Do it
|
||||
v3s16 pos = read_v3s16(L, 2);
|
||||
float radius = luaL_checknumber(L, 3);// * BS;
|
||||
core::list<MapNode> nodes = env->getNodesInsideRadius(pos, radius);
|
||||
lua_newtable(L);
|
||||
int table = lua_gettop(L);
|
||||
for(core::list<MapNode>::Iterator
|
||||
i = nodes.begin(); i != nodes.end(); i++){
|
||||
// Insert object reference into table
|
||||
lua_pushvalue(L, table_insert);
|
||||
lua_pushvalue(L, table);
|
||||
pushnode(L, *i, env->getGameDef()->ndef());
|
||||
if(lua_pcall(L, 2, 0, 0))
|
||||
script_error(L, "error: %s", lua_tostring(L, -1));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// EnvRef:set_timeofday(val)
|
||||
// val = 0...1
|
||||
static int l_set_timeofday(lua_State *L)
|
||||
{
|
||||
EnvRef *o = checkobject(L, 1);
|
||||
ServerEnvironment *env = o->m_env;
|
||||
if(env == NULL) return 0;
|
||||
// Do it
|
||||
float timeofday_f = luaL_checknumber(L, 2);
|
||||
assert(timeofday_f >= 0.0 && timeofday_f <= 1.0);
|
||||
int timeofday_mh = (int)(timeofday_f * 24000.0);
|
||||
// This should be set directly in the environment but currently
|
||||
// such changes aren't immediately sent to the clients, so call
|
||||
// the server instead.
|
||||
//env->setTimeOfDay(timeofday_mh);
|
||||
get_server(L)->setTimeOfDay(timeofday_mh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// EnvRef:get_timeofday() -> 0...1
|
||||
static int l_get_timeofday(lua_State *L)
|
||||
{
|
||||
EnvRef *o = checkobject(L, 1);
|
||||
ServerEnvironment *env = o->m_env;
|
||||
if(env == NULL) return 0;
|
||||
// Do it
|
||||
int timeofday_mh = env->getTimeOfDay();
|
||||
float timeofday_f = (float)timeofday_mh / 24000.0;
|
||||
lua_pushnumber(L, timeofday_f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int gc_object(lua_State *L) {
|
||||
EnvRef *o = *(EnvRef **)(lua_touserdata(L, 1));
|
||||
delete o;
|
||||
@@ -2990,6 +3110,9 @@ const luaL_reg EnvRef::methods[] = {
|
||||
method(EnvRef, get_meta),
|
||||
method(EnvRef, get_player_by_name),
|
||||
method(EnvRef, get_objects_inside_radius),
|
||||
method(EnvRef, get_nodes_inside_radius),
|
||||
method(EnvRef, set_timeofday),
|
||||
method(EnvRef, get_timeofday),
|
||||
{0,0}
|
||||
};
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class ServerActiveObject;
|
||||
class ServerRemotePlayer;
|
||||
typedef struct lua_State lua_State;
|
||||
struct LuaEntityProperties;
|
||||
class ItemStack;
|
||||
struct ItemStack;
|
||||
struct PointedThing;
|
||||
//class IGameDef;
|
||||
|
||||
|
||||
53
src/serverlinkableobject.cpp
Normal file
53
src/serverlinkableobject.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
Copyright (C) 2012 sapier sapier at gmx dot net
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "serverlinkableobject.h"
|
||||
|
||||
|
||||
ServerLinkableObject::ServerLinkableObject() {
|
||||
this->m_Linked = false;
|
||||
}
|
||||
|
||||
ServerLinkableObject::~ServerLinkableObject() {}
|
||||
|
||||
bool ServerLinkableObject::linkEntity(ServerActiveObject* parent,v3f offset) {
|
||||
//check if entity is in correct state
|
||||
if (this->m_Linked == true) {
|
||||
errorstream<<"ServerLinkableObject: link but object already linked!"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
this->m_Linked = true;
|
||||
|
||||
errorstream<<"ServerLinkableObject: try to send link message!"<<std::endl;
|
||||
return sendLinkMsg(parent,offset);
|
||||
}
|
||||
|
||||
bool ServerLinkableObject::unlinkEntity() {
|
||||
//check if entity is in correct state
|
||||
if (this->m_Linked == false) {
|
||||
errorstream<<"ServerLinkableObject: unlink but object not linked!"<<std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
this->m_Linked = false;
|
||||
|
||||
errorstream<<"ServerLinkableObject: try to send unlink message!"<<std::endl;
|
||||
return sendUnlinkMsg();
|
||||
}
|
||||
62
src/serverlinkableobject.h
Normal file
62
src/serverlinkableobject.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
Copyright (C) 2012 sapier sapier at gmx dot net
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef SERVERLINKABLEOBJECT_H_
|
||||
#define SERVERLINKABLEOBJECT_H_
|
||||
|
||||
#include <sstream>
|
||||
#include <irrlichttypes.h>
|
||||
#include "serverobject.h"
|
||||
#include "content_object.h"
|
||||
#include "log.h"
|
||||
|
||||
//this ain't the right place to define this but until cao/sao split
|
||||
//is decided it'll have to stay here
|
||||
struct AO_Message_type {
|
||||
static const u8 SetPosition = 0x00;
|
||||
static const u8 SetTextureMod = 0x01;
|
||||
static const u8 SetSprite = 0x02;
|
||||
static const u8 Punched = 0x03;
|
||||
static const u8 TakeDamage = 0x04;
|
||||
static const u8 Shoot = 0x05;
|
||||
static const u8 Link = 0x06;
|
||||
static const u8 UnLink = 0x07;
|
||||
};
|
||||
|
||||
class ServerLinkableObject {
|
||||
public:
|
||||
ServerLinkableObject();
|
||||
~ServerLinkableObject();
|
||||
|
||||
bool linkEntity(ServerActiveObject* parent,v3f offset);
|
||||
bool unlinkEntity();
|
||||
|
||||
virtual bool sendLinkMsg(ServerActiveObject* parent,v3f offset) = 0;
|
||||
virtual bool sendUnlinkMsg() = 0;
|
||||
|
||||
protected:
|
||||
inline bool isLinked() { return m_Linked; }
|
||||
|
||||
private:
|
||||
bool m_Linked;
|
||||
|
||||
};
|
||||
|
||||
#endif /* SERVERLINKABLEOBJECT_H_ */
|
||||
@@ -43,8 +43,8 @@ ServerActiveObject* ServerActiveObject::create(u8 type,
|
||||
const std::string &data)
|
||||
{
|
||||
// Find factory function
|
||||
core::map<u16, Factory>::Node *n;
|
||||
n = m_types.find(type);
|
||||
core::map<u8, Factory>::Node *n;
|
||||
n = ServerActiveObject::getTypes().find(type);
|
||||
if(n == NULL)
|
||||
{
|
||||
// If factory is not found, just return.
|
||||
@@ -58,13 +58,13 @@ ServerActiveObject* ServerActiveObject::create(u8 type,
|
||||
return object;
|
||||
}
|
||||
|
||||
void ServerActiveObject::registerType(u16 type, Factory f)
|
||||
void ServerActiveObject::registerType(u8 type, Factory f)
|
||||
{
|
||||
core::map<u16, Factory>::Node *n;
|
||||
n = m_types.find(type);
|
||||
core::map<u8, Factory>::Node *n;
|
||||
n = ServerActiveObject::getTypes().find(type);
|
||||
if(n)
|
||||
return;
|
||||
m_types.insert(type, f);
|
||||
ServerActiveObject::getTypes().insert(type, f);
|
||||
}
|
||||
|
||||
ItemStack ServerActiveObject::getWieldedItem() const
|
||||
|
||||
@@ -42,7 +42,7 @@ Some planning
|
||||
*/
|
||||
|
||||
class ServerEnvironment;
|
||||
class ItemStack;
|
||||
struct ItemStack;
|
||||
class Player;
|
||||
struct ToolDiggingProperties;
|
||||
|
||||
@@ -209,14 +209,17 @@ class ServerActiveObject : public ActiveObject
|
||||
typedef ServerActiveObject* (*Factory)
|
||||
(ServerEnvironment *env, v3f pos,
|
||||
const std::string &data);
|
||||
static void registerType(u16 type, Factory f);
|
||||
static void registerType(u8 type, Factory f);
|
||||
|
||||
ServerEnvironment *m_env;
|
||||
v3f m_base_position;
|
||||
|
||||
private:
|
||||
// Used for creating objects based on type
|
||||
static core::map<u16, Factory> m_types;
|
||||
static core::map<u8, Factory>& getTypes()
|
||||
{
|
||||
static core::map<u8, Factory> types;
|
||||
return types;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1201,7 +1201,7 @@ struct TestConnection
|
||||
|
||||
server.Send(peer_id_client, 0, data1, true);
|
||||
|
||||
sleep_ms(3000);
|
||||
//sleep_ms(3000);
|
||||
|
||||
SharedBuffer<u8> recvdata;
|
||||
infostream<<"** running client.Receive()"<<std::endl;
|
||||
@@ -1210,7 +1210,7 @@ struct TestConnection
|
||||
bool received = false;
|
||||
u32 timems0 = porting::getTimeMs();
|
||||
for(;;){
|
||||
if(porting::getTimeMs() - timems0 > 5000)
|
||||
if(porting::getTimeMs() - timems0 > 5000 || received)
|
||||
break;
|
||||
try{
|
||||
size = client.Receive(peer_id, recvdata);
|
||||
|
||||
@@ -1757,6 +1757,50 @@ class IntervalLimiter
|
||||
float m_accumulator;
|
||||
};
|
||||
|
||||
/*
|
||||
Splits a list into "pages". For example, the list [1,2,3,4,5] split
|
||||
into two pages would be [1,2,3],[4,5]. This function computes the
|
||||
minimum and maximum indices of a single page.
|
||||
|
||||
length: Length of the list that should be split
|
||||
page: Page number, 1 <= page <= pagecount
|
||||
pagecount: The number of pages, >= 1
|
||||
minindex: Receives the minimum index (inclusive).
|
||||
maxindex: Receives the maximum index (exclusive).
|
||||
|
||||
Ensures 0 <= minindex <= maxindex <= length.
|
||||
*/
|
||||
inline void paging(u32 length, u32 page, u32 pagecount, u32 &minindex, u32 &maxindex)
|
||||
{
|
||||
if(length < 1 || pagecount < 1 || page < 1 || page > pagecount)
|
||||
{
|
||||
// Special cases or invalid parameters
|
||||
minindex = maxindex = 0;
|
||||
}
|
||||
else if(pagecount <= length)
|
||||
{
|
||||
// Less pages than entries in the list:
|
||||
// Each page contains at least one entry
|
||||
minindex = (length * (page-1) + (pagecount-1)) / pagecount;
|
||||
maxindex = (length * page + (pagecount-1)) / pagecount;
|
||||
}
|
||||
else
|
||||
{
|
||||
// More pages than entries in the list:
|
||||
// Make sure the empty pages are at the end
|
||||
if(page < length)
|
||||
{
|
||||
minindex = page-1;
|
||||
maxindex = page;
|
||||
}
|
||||
else
|
||||
{
|
||||
minindex = 0;
|
||||
maxindex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string translatePassword(std::string playername, std::wstring password);
|
||||
|
||||
enum PointedThingType
|
||||
|
||||
Reference in New Issue
Block a user