advtrains.git, branch release-2.4.7Advtrains mod for minetest.https://git.bananach.space/advtrains.git/atom?h=release-2.4.72024-11-09T21:33:18+00:00Add setting to bypass coupler type checks when coupling2024-11-09T21:33:18+00:00Maverick2797git.maverick2797@gmail.com2024-11-02T07:36:34+00:00urn:sha1:3d2d19f6f7eba90f0d19b002824b2ff466567608
Allows a server to disable the coupler checks when multiple coupler types are present, making everything effectively a universal coupler
Discard running interrupt and schedule events when LuaATC components are removed2024-11-09T21:32:51+00:00Maverick2797git.maverick2797@gmail.com2024-10-31T10:06:33+00:00urn:sha1:19d8e8c1a7dc82fa0ca1f65f04936e22c8b6e2a7Add get_fc_index() fucntion2024-11-09T21:32:23+00:00Maverick2797git.maverick2797@gmail.com2024-10-30T13:06:29+00:00urn:sha1:715efe22939bbe472ba4a2c81c74e64c45726bc2Fix get_fc concat when fc = nil2024-11-09T21:31:56+00:00Maverick2797git.maverick2797@gmail.com2024-10-30T11:02:19+00:00urn:sha1:322fc31e74151a0ce6a14b49185b0ec9000ff5b2Add "New From Route" function into route editing form2024-11-09T21:18:14+00:001F616EMOroot@1f616emo.xyz2024-09-30T11:37:18+00:00urn:sha1:d83d06ecdd8a23e5c36826f150c72d0ff8b644f9
This patch allows creating new routes based on what was done on another route. This can be useful to fix minor mistakes on a route, or to create similar routes. Note that the route buffer created "steps back" one section, but with turnouts kept.
The new button is placed above the "Save ARS" button - I know it is ugly, so please suggest a better place for it.
Fix update_route receiving invalid route ID in after()2024-11-09T21:16:39+00:001F616EMOroot@1f616emo.xyz2024-09-28T22:43:27+00:00urn:sha1:8b9eb2a96d9c1c425ff9014fdf27c82526d8376bFix depercated functions2024-11-09T21:15:06+00:001F616EMOroot@1f616emo.xyz2024-09-28T22:37:40+00:00urn:sha1:e53670904127c8493e13b587e507407f2beac8b3Implement staticdata for trains2024-11-09T21:10:06+00:00Y. Wangy5nw@protonmail.com2024-09-20T12:45:20+00:00urn:sha1:b075d8e3336dfb2755dd1b9dc29c5320a155013b
This patch exposes train.staticdata that can be used by other modders to
save data in trains across restarts. It additionally exposes two new
APIs for modders where this is relevant:
* advtrains.te_register_on_couple(function(init_train, stat_train)):
registers a callback for train coupling, where stat_train is couple
into init_train and is subsequently removed. This callback is run
before the actual coupling takes place; in particular, it is run
before stat_train is removed.
* advtrains.te_register_on_decouple(function(train, newtrain, index)):
registers a callback for train decoupling, where newtrain is created
by splitting the train at the given index (the wagon at the index is
part of the new train). This callback is run after decoupling takes
place.
advtrains.te_register_on_decouple(function
Address wagon aliasing issues2024-11-09T21:09:00+00:00Y. Wangy5nw@protonmail.com2024-09-19T18:39:19+00:00urn:sha1:66868e2eefe97b7a6d35fa3fecc895b9c7bbc4cc
As it turns out, not fully testing new features is not necessarily a
good idea ...
This patch follows up 1F616EMO's patch by
* Making get_wagon_prototype return the resolved alias,
* Handling recursive wagon alises (in particular, loops), and
* Adding (partial) unittest for the wagon aliasing system. [v2]: The
testcases are complemented a bit more to cover situations where the
alias resolution system should return nil.
[v2]: This patch should hopefully also warn about not spawning wagons.
Note that this only warns about the missing wagon entity and does _not_
actually fix the issue.
How to test:
* In a world with both advtrains_train_subway and advtrains_train_japan
enabled, place a subway wagon, a Japanese engine, and a regular
Japanese wagon.
* Add the test mod to the world; do NOT remove advtrains_train_japan.
* Restart the world. Notice that the Japanese wagons still appear as
Japanese wagons despite being aliased to subway wagons.
* Restart the world without the advtrains_train_japan mod. Notice that
the engine appears as the subway wagon while the regular Japanese
wagon appears as the wagon placeholder. [v2]: Also note that the
warning message about the missing wagon prototype still mentions the
regular Japanese wagon.
* Restart the world again with the advtrains_train_japan mod. Notice
that both type of Japanese wagons reappear as Japanese wagons.
* Observe that unittests work.
Test mod:
advtrains.register_wagon_alias("advtrains:engine_japan", "advtrains:subway_wagon")
advtrains.register_wagon_alias("advtrains:wagon_japan", "advtrains:wagon_japan")
Fix crashing when train hitting objects without armor group2024-11-09T21:06:38+00:001F616EMOroot@1f616emo.xyz2024-09-13T23:36:45+00:00urn:sha1:86e80e4cfb0d7017ff962e40ab99a4ab6addf8f2
'>163
164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
/*Minetest-c55Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe 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 ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public License alongwith this program; if not, write to the Free Software Foundation, Inc.,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.*/#ifndef MAP_HEADER#define MAP_HEADER#include <jmutex.h>#include <jmutexautolock.h>#include <jthread.h>#include <iostream>#include <sstream>#include"common_irrlicht.h"#include"mapnode.h"#include"mapblock_nodemod.h"#include"constants.h"#include"voxel.h"extern"C"{#include"sqlite3.h"}class MapSector;class ServerMapSector;class ClientMapSector;class MapBlock;class NodeMetadata;namespace mapgen{struct BlockMakeData;};/* MapEditEvent*/#define MAPTYPE_BASE 0#define MAPTYPE_SERVER 1#define MAPTYPE_CLIENT 2enum MapEditEventType{// Node added (changed from air or something else to something)
MEET_ADDNODE,// Node removed (changed to air)
MEET_REMOVENODE,// Node metadata of block changed (not knowing which node exactly)// p stores block coordinate
MEET_BLOCK_NODE_METADATA_CHANGED,// Anything else (modified_blocks are set unsent)
MEET_OTHER
};struct MapEditEvent
{
MapEditEventType type;
v3s16 p;
MapNode n;core::map<v3s16,bool> modified_blocks;
u16 already_known_by_peer;MapEditEvent():type(MEET_OTHER),already_known_by_peer(0){}
MapEditEvent *clone(){
MapEditEvent *event =newMapEditEvent();
event->type = type;
event->p = p;
event->n = n;for(core::map<v3s16,bool>::Iterator
i = modified_blocks.getIterator();
i.atEnd()==false; i++){
v3s16 p = i.getNode()->getKey();bool v = i.getNode()->getValue();
event->modified_blocks.insert(p, v);}return event;}};class MapEventReceiver
{public:// event shall be deleted by caller after the call.virtualvoidonMapEditEvent(MapEditEvent *event) =0;};class Map /*: public NodeContainer*/{public:Map(std::ostream &dout);virtual~Map();/*virtual u16 nodeContainerId() const { return NODECONTAINER_ID_MAP; }*/virtual s32 mapType()const{return MAPTYPE_BASE;}/* Drop (client) or delete (server) the map. */virtualvoiddrop(){delete this;}voidaddEventReceiver(MapEventReceiver *event_receiver);voidremoveEventReceiver(MapEventReceiver *event_receiver);// event shall be deleted by caller after the call.voiddispatchEvent(MapEditEvent *event);// On failure returns NULL
MapSector *getSectorNoGenerateNoExNoLock(v2s16 p2d);// Same as the above (there exists no lock anymore)
MapSector *getSectorNoGenerateNoEx(v2s16 p2d);// On failure throws InvalidPositionException
MapSector *getSectorNoGenerate(v2s16 p2d);// Gets an existing sector or creates an empty one//MapSector * getSectorCreate(v2s16 p2d);/* This is overloaded by ClientMap and ServerMap to allow their differing fetch methods. */virtual MapSector *emergeSector(v2s16 p){return NULL; }virtual MapSector *emergeSector(v2s16 p,core::map<v3s16, MapBlock*> &changed_blocks){return NULL; }// Returns InvalidPositionException if not found
MapBlock *getBlockNoCreate(v3s16 p);// Returns NULL if not found
MapBlock *getBlockNoCreateNoEx(v3s16 p);// Returns InvalidPositionException if not foundboolisNodeUnderground(v3s16 p);boolisValidPosition(v3s16 p);// throws InvalidPositionException if not found
MapNode getNode(v3s16 p);// throws InvalidPositionException if not foundvoidsetNode(v3s16 p, MapNode & n);// Returns a CONTENT_IGNORE node if not found
MapNode getNodeNoEx(v3s16 p);voidunspreadLight(enum LightBank bank,core::map<v3s16, u8> & from_nodes,core::map<v3s16,bool> & light_sources,core::map<v3s16, MapBlock*> & modified_blocks);voidunLightNeighbors(enum LightBank bank,
v3s16 pos, u8 lightwas,core::map<v3s16,bool> & light_sources,core::map<v3s16, MapBlock*> & modified_blocks);voidspreadLight(enum LightBank bank,core::map<v3s16,bool> & from_nodes,core::map<v3s16, MapBlock*> & modified_blocks);voidlightNeighbors(enum LightBank bank,
v3s16 pos,core::map<v3s16, MapBlock*> & modified_blocks);
v3s16 getBrightestNeighbour(enum LightBank bank, v3s16 p);
s16 propagateSunlight(v3s16 start,core::map<v3s16, MapBlock*> & modified_blocks);voidupdateLighting(enum LightBank bank,core::map<v3s16, MapBlock*> & a_blocks,core::map<v3s16, MapBlock*> & modified_blocks);voidupdateLighting(core::map<v3s16, MapBlock*> & a_blocks,core::map<v3s16, MapBlock*> & modified_blocks);/* These handle lighting but not faces. */voidaddNodeAndUpdate(v3s16 p, MapNode n,core::map<v3s16, MapBlock*> &modified_blocks);voidremoveNodeAndUpdate(v3s16 p,core::map<v3s16, MapBlock*> &modified_blocks);/* Wrappers for the latter ones. These emit events. Return true if succeeded, false if not. */booladdNodeWithEvent(v3s16 p, MapNode n);boolremoveNodeWithEvent(v3s16 p);/* Takes the blocks at the edges into account */booldayNightDiffed(v3s16 blockpos);//core::aabbox3d<s16> getDisplayedBlockArea();//bool updateChangedVisibleArea();// Call these before and after saving of many blocksvirtualvoidbeginSave() {return;};virtualvoidendSave() {return;};virtualvoidsave(bool only_changed){assert(0);};// Server implements this.// Client leaves it as no-op.virtualvoidsaveBlock(MapBlock *block){};/* Updates usage timers and unloads unused blocks and sectors. Saves modified blocks before unloading on MAPTYPE_SERVER. */voidtimerUpdate(float dtime,float unload_timeout,core::list<v3s16> *unloaded_blocks=NULL);// Deletes sectors and their blocks from memory// Takes cache into account// If deleted sector is in sector cache, clears cachevoiddeleteSectors(core::list<v2s16> &list);#if 0/* Unload unused data = flush changed to disk and delete from memory, if usage timer of block is more than timeout */voidunloadUnusedData(float timeout,core::list<v3s16> *deleted_blocks=NULL);#endif// For debug printing. Prints "Map: ", "ServerMap: " or "ClientMap: "virtualvoidPrintInfo(std::ostream &out);voidtransformLiquids(core::map<v3s16, MapBlock*> & modified_blocks);/* Node metadata These are basically coordinate wrappers to MapBlock */
NodeMetadata*getNodeMetadata(v3s16 p);voidsetNodeMetadata(v3s16 p, NodeMetadata *meta);voidremoveNodeMetadata(v3s16 p);voidnodeMetadataStep(float dtime,core::map<v3s16, MapBlock*> &changed_blocks);/* Misc. */core::map<v2s16, MapSector*> *getSectorsPtr(){return&m_sectors;}/* Variables */protected:std::ostream &m_dout;core::map<MapEventReceiver*,bool> m_event_receivers;core::map<v2s16, MapSector*> m_sectors;// Be sure to set this to NULL when the cached sector is deleted
MapSector *m_sector_cache;
v2s16 m_sector_cache_p;// Queued transforming water nodes
UniqueQueue<v3s16> m_transforming_liquid;};/* ServerMap This is the only map class that is able to generate map.*/class ServerMap :public Map
{public:/* savedir: directory to which map data should be saved */ServerMap(std::string savedir);~ServerMap();
s32 mapType()const{return MAPTYPE_SERVER;}/* Get a sector from somewhere. - Check memory - Check disk (doesn't load blocks) - Create blank one */
ServerMapSector *createSector(v2s16 p);/* Blocks are generated by using these and makeBlock(). */voidinitBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos);
MapBlock*finishBlockMake(mapgen::BlockMakeData *data,core::map<v3s16, MapBlock*> &changed_blocks);// A non-threaded wrapper to the above
MapBlock *generateBlock(
v3s16 p,core::map<v3s16, MapBlock*> &modified_blocks
);/* Get a block from somewhere. - Memory - Create blank */
MapBlock *createBlock(v3s16 p);/* Forcefully get a block from somewhere. - Memory - Load from disk - Generate */
MapBlock *emergeBlock(v3s16 p,bool allow_generate=true);// Helper for placing objects on ground level
s16 findGroundLevel(v2s16 p2d);/* Misc. helper functions for fiddling with directory and file names when saving */voidcreateDirs(std::string path);// returns something like "map/sectors/xxxxxxxx"std::string getSectorDir(v2s16 pos,int layout =2);// dirname: final directory name
v2s16 getSectorPos(std::string dirname);
v3s16 getBlockPos(std::string sectordir,std::string blockfile);staticstd::string getBlockFilename(v3s16 p);/* Database functions */// Create the database structurevoidcreateDatabase();// Verify we can read/write to the databasevoidverifyDatabase();// Get an integer suitable for a blockstatic sqlite3_int64 getBlockAsInteger(const v3s16 pos);// Returns true if the database file does not existboolloadFromFolders();// Call these before and after saving of blocksvoidbeginSave();voidendSave();voidsave(bool only_changed);//void loadAll();// Saves map seed and possibly other stuffvoidsaveMapMeta();voidloadMapMeta();/*void saveChunkMeta(); void loadChunkMeta();*/// The sector mutex should be locked when calling most of these// This only saves sector-specific data such as the heightmap// (no MapBlocks)// DEPRECATED? Sectors have no metadata anymore.voidsaveSectorMeta(ServerMapSector *sector);
MapSector*loadSectorMeta(std::string dirname,bool save_after_load);boolloadSectorMeta(v2s16 p2d);// Full load of a sector including all blocks.// returns true on success, false on failure.boolloadSectorFull(v2s16 p2d);// If sector is not found in memory, try to load it from disk.// Returns true if sector now resides in memory//bool deFlushSector(v2s16 p2d);voidsaveBlock(MapBlock *block);// This will generate a sector with getSector if not found.voidloadBlock(std::string sectordir,std::string blockfile, MapSector *sector,bool save_after_load=false);
MapBlock*loadBlock(v3s16 p);// Database versionvoidloadBlock(std::string *blob, v3s16 p3d, MapSector *sector,bool save_after_load=false);// For debug printingvirtualvoidPrintInfo(std::ostream &out);boolisSavingEnabled(){return m_map_saving_enabled; }
u64 getSeed(){return m_seed; }private:// Seed used for all kinds of randomness
u64 m_seed;std::string m_savedir;bool m_map_saving_enabled;#if 0// Chunk size in MapSectors// If 0, chunks are disabled.
s16 m_chunksize;// Chunkscore::map<v2s16, MapChunk*> m_chunks;#endif/* Metadata is re-written on disk only if this is true. This is reset to false when written on disk. */bool m_map_metadata_changed;/* SQLite database and statements */
sqlite3 *m_database;
sqlite3_stmt *m_database_read;
sqlite3_stmt *m_database_write;};/* ClientMap stuff*/#ifndef SERVERstruct MapDrawControl
{MapDrawControl():range_all(false),wanted_range(50),wanted_max_blocks(0),wanted_min_range(0),blocks_drawn(0),blocks_would_have_drawn(0){}// Overrides limits by drawing everythingbool range_all;// Wanted drawing rangefloat wanted_range;// Maximum number of blocks to draw
u32 wanted_max_blocks;// Blocks in this range are drawn regardless of number of blocks drawnfloat wanted_min_range;// Number of blocks rendered is written here by the renderer
u32 blocks_drawn;// Number of blocks that would have been drawn in wanted_range
u32 blocks_would_have_drawn;};class Client;/* ClientMap This is the only map class that is able to render itself on screen.*/class ClientMap :public Map,public scene::ISceneNode
{public:ClientMap(
Client *client,
MapDrawControl &control,scene::ISceneNode* parent,scene::ISceneManager* mgr,
s32 id
);~ClientMap();
s32 mapType()const{return MAPTYPE_CLIENT;}voiddrop(){ISceneNode::drop();}voidupdateCamera(v3f pos, v3f dir, f32 fov){
JMutexAutoLock lock(m_camera_mutex);
m_camera_position = pos;
m_camera_direction = dir;
m_camera_fov = fov;}/* Forcefully get a sector from somewhere */
MapSector *emergeSector(v2s16 p);//void deSerializeSector(v2s16 p2d, std::istream &is);/* ISceneNode methods */virtualvoidOnRegisterSceneNode();virtualvoidrender(){video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);renderMap(driver, SceneManager->getSceneNodeRenderPass());}virtualconstcore::aabbox3d<f32>&getBoundingBox()const{return m_box;}voidrenderMap(video::IVideoDriver* driver, s32 pass);voidrenderPostFx();/* Methods for setting temporary modifications to nodes for drawing. Returns true if something changed. All blocks whose mesh could have been changed are inserted to affected_blocks. */boolsetTempMod(v3s16 p, NodeMod mod,core::map<v3s16, MapBlock*> *affected_blocks=NULL);boolclearTempMod(v3s16 p,core::map<v3s16, MapBlock*> *affected_blocks=NULL);// Efficient implementation needs a cache of TempMods//void clearTempMods();voidexpireMeshes(bool only_daynight_diffed);/* Update the faces of the given block and blocks on the leading edge. */voidupdateMeshes(v3s16 blockpos, u32 daynight_ratio);// Update meshes that touch the node//void updateNodeMeshes(v3s16 nodepos, u32 daynight_ratio);// For debug printingvirtualvoidPrintInfo(std::ostream &out);// Check if sector was drawn on last render()boolsectorWasDrawn(v2s16 p){return(m_last_drawn_sectors.find(p) != NULL);}private:
Client *m_client;core::aabbox3d<f32> m_box;// This is the master heightmap mesh//scene::SMesh *mesh;//JMutex mesh_mutex;
MapDrawControl &m_control;
v3f m_camera_position;
v3f m_camera_direction;
f32 m_camera_fov;
JMutex m_camera_mutex;core::map<v2s16,bool> m_last_drawn_sectors;};#endifclass MapVoxelManipulator :public VoxelManipulator
{public:MapVoxelManipulator(Map *map);virtual~MapVoxelManipulator();virtualvoidclear(){VoxelManipulator::clear();
m_loaded_blocks.clear();}virtualvoidemerge(VoxelArea a, s32 caller_id=-1);voidblitBack(core::map<v3s16, MapBlock*> & modified_blocks);protected:
Map *m_map;/* key = blockpos value = block existed when loaded */core::map<v3s16,bool> m_loaded_blocks;};class ManualMapVoxelManipulator :public MapVoxelManipulator
{public:ManualMapVoxelManipulator(Map *map);virtual~ManualMapVoxelManipulator();voidsetMap(Map *map){m_map = map;}virtualvoidemerge(VoxelArea a, s32 caller_id=-1);voidinitialEmerge(v3s16 blockpos_min, v3s16 blockpos_max);// This is much faster with big chunks of generated datavoidblitBackAll(core::map<v3s16, MapBlock*> * modified_blocks);protected:bool m_create_area;};#endif