Compare commits
9 Commits
5.11.0-rc1
...
20120204_l
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0947644729 | ||
|
|
77df09540c | ||
|
|
3454e67793 | ||
|
|
0c78767754 | ||
|
|
f0679969b2 | ||
|
|
285f5a0259 | ||
|
|
71186974fa | ||
|
|
525bc8855f | ||
|
|
de166e75a1 |
@@ -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
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
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).
|
||||
|
||||
@@ -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,35 @@ 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)
|
||||
@@ -3022,6 +3110,7 @@ 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}
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user