aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAge
...
* | | try to make engine animation workorwell962016-10-19
|/ /
* | some smaller slopesorwell962016-10-06
| |
* | add japanese wagon and engineorwell962016-10-06
|/
* add acceleration calculationorwell962016-09-29
|
* fix train entities moving with wrong speedorwell962016-09-29
|
* add owner system to prevent random train destroyingorwell962016-09-29
|
* destructed wagons in survival give only steel back, user confirmation addedorwell962016-09-28
|
* adding ability for custom on_step/destroy functions in wagon definitionorwell962016-09-28
|
* add 45 degrees vertical railsorwell962016-09-18
|
* add more crafting recipes and a manualorwell962016-09-17
|
* add some items to the not-blocking-trains grouporwell962016-09-15
|
* wtf did this file in here?orwell962016-09-15
|
* relicensing under CC-BY-NC-SA and updationg readme.orwell962016-09-15
|
* various improvements on signals and bumpersorwell962016-09-13
|
* make switches not switchable when train is on it, and do neccessary stuff on ↵orwell962016-09-13
| | | | switching
* add electric signal and rotate signals for better placementorwell962016-09-13
|
* add mesecon support for switches and signalsorwell962016-09-13
|
* adding a signal.orwell962016-09-12
| | | | it is controllable by mesecons and by right click. it does not influence trains
* adding mbb's new texturesorwell962016-09-12
|
* Adding crafting recipesorwell962016-09-12
|
* fix item drops on rails, and throw bumpers out of the trackplacer tables, ↵orwell962016-09-12
| | | | because it caused confusion
* add bumpersorwell962016-09-12
|
* Fix two trackplacer issuesorwell962016-08-30
| | | | | 1. you can't place tracks on non-walkable nodes 2. in certain situations no rail was placed at all
* removed 2 very annoying debug messages that should not go with 1.0orwell962016-08-29
|
* Updating readme, and branching to v1.0orwell962016-08-29
|
* implement track placing algorithm betterorwell962016-08-29
|
* correcting an error that caused a crashorwell962016-08-28
|
* correct wrongly rotated texture for subwayorwell962016-08-28
|
* Add a subway train (and fix spelling mistake resulting in collision not workingorwell962016-08-28
|
* Add a platform node, make some nodes (esp. fences) not blocking trains, ↵orwell962016-08-28
| | | | implement benchmarking better and optimize some things
* Fixing inventory and inventory imagesorwell962016-08-28
|
* Making everything visible in creative inventory, since the code that should ↵orwell962016-08-28
| | | | do that does not work.
* Re-implement collision in a less resource-intensive way that I should have ↵orwell962016-08-27
| | | | used on from the beginning (ad fix some logical mistakes)
* Creating new switches, and adding lbms to finally abandon old railsorwell962016-08-26
|
* Tidy up the workspaceorwell962016-08-25
|
* Fix shadow bug on some rail modelsorwell962016-08-23
|
* finally fix train collisions (please work now)orwell962016-08-22
|
* tidying up the tracks and trackworker/placer code and making rail ↵orwell962016-08-22
| | | | registration a lot more modular
* repairing the trackworkerorwell962016-08-21
|
* add new-style vertical tracksorwell962016-08-21
|
* fix error in real train index calculationorwell962016-08-21
|
* removing unused debug itemsorwell962016-08-21
|
* Extending to 30deg rails, creating and adding the modelsorwell962016-08-21
|
* integrating the new rails (currently no verticals and switches) (fix mistake)orwell962016-07-04
|
* integrating the new rails (currently no verticals and switches)orwell962016-07-04
|
* adding some dummy textures (dtrack) for new anglesorwell962016-07-04
|
* Screwing everything up in order to extend to 16 possible directions with 1/8 ↵orwell962016-07-04
| | | | precision
* delete a commentorwell962016-07-04
|
* Hopefully fix collision finally (fix mistake)orwell962016-07-04
|
* Hopefully fix collision finallyorwell962016-07-04
|
701'>701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "mapblock.h"

#include <sstream>
#include "map.h"
#include "light.h"
#include "nodedef.h"
#include "nodemetadata.h"
#include "gamedef.h"
#include "log.h"
#include "nameidmapping.h"
#include "content_mapnode.h" // For legacy name-id mapping
#include "content_nodemeta.h" // For legacy deserialization
#include "serialization.h"
#ifndef SERVER
#include "client/mapblock_mesh.h"
#endif
#include "porting.h"
#include "util/string.h"
#include "util/serialize.h"
#include "util/basic_macros.h"

static const char *modified_reason_strings[] = {
	"initial",
	"reallocate",
	"setIsUnderground",
	"setLightingExpired",
	"setGenerated",
	"setNode",
	"setNodeNoCheck",
	"setTimestamp",
	"NodeMetaRef::reportMetadataChange",
	"clearAllObjects",
	"Timestamp expired (step)",
	"addActiveObjectRaw",
	"removeRemovedObjects/remove",
	"removeRemovedObjects/deactivate",
	"Stored list cleared in activateObjects due to overflow",
	"deactivateFarObjects: Static data moved in",
	"deactivateFarObjects: Static data moved out",
	"deactivateFarObjects: Static data changed considerably",
	"finishBlockMake: expireDayNightDiff",
	"unknown",
};


/*
	MapBlock
*/

MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
		m_parent(parent),
		m_pos(pos),
		m_pos_relative(pos * MAP_BLOCKSIZE),
		m_gamedef(gamedef)
{
	if (!dummy)
		reallocate();
}

MapBlock::~MapBlock()
{
#ifndef SERVER
	{
		delete mesh;
		mesh = nullptr;
	}
#endif

	delete[] data;
}

bool MapBlock::isValidPositionParent(v3s16 p)
{
	if (isValidPosition(p)) {
		return true;
	}

	return m_parent->isValidPosition(getPosRelative() + p);
}

MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position)
{
	if (!isValidPosition(p))
		return m_parent->getNode(getPosRelative() + p, is_valid_position);

	if (!data) {
		if (is_valid_position)
			*is_valid_position = false;
		return {CONTENT_IGNORE};
	}
	if (is_valid_position)
		*is_valid_position = true;
	return data[p.Z * zstride + p.Y * ystride + p.X];
}

std::string MapBlock::getModifiedReasonString()
{
	std::string reason;

	const u32 ubound = MYMIN(sizeof(m_modified_reason) * CHAR_BIT,
		ARRLEN(modified_reason_strings));

	for (u32 i = 0; i != ubound; i++) {
		if ((m_modified_reason & (1 << i)) == 0)
			continue;

		reason += modified_reason_strings[i];
		reason += ", ";
	}

	if (reason.length() > 2)
		reason.resize(reason.length() - 2);

	return reason;
}


void MapBlock::copyTo(VoxelManipulator &dst)
{
	v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
	VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1));

	// Copy from data to VoxelManipulator
	dst.copyFrom(data, data_area, v3s16(0,0,0),
			getPosRelative(), data_size);
}

void MapBlock::copyFrom(VoxelManipulator &dst)
{
	v3s16 data_size(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
	VoxelArea data_area(v3s16(0,0,0), data_size - v3s16(1,1,1));

	// Copy from VoxelManipulator to data
	dst.copyTo(data, data_area, v3s16(0,0,0),
			getPosRelative(), data_size);